aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2010-08-16 17:09:34 -0400
committerDavid S. Miller <davem@davemloft.net>2010-08-16 17:09:34 -0400
commit300a103d1504134f8c4a7e831f995e917ea9b1e4 (patch)
tree7f94d5fff513d132bd0b57a9e3bd96c4cc80d707 /drivers
parent0a492896ac07336c98f37ad7fab4a6387b6ada78 (diff)
parentda5cabf80e2433131bf0ed8993abc0f7ea618c73 (diff)
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
Diffstat (limited to 'drivers')
-rw-r--r--drivers/acpi/Kconfig11
-rw-r--r--drivers/acpi/Makefile5
-rw-r--r--drivers/acpi/acpica/acevents.h4
-rw-r--r--drivers/acpi/acpica/acglobal.h2
-rw-r--r--drivers/acpi/acpica/aclocal.h1
-rw-r--r--drivers/acpi/acpica/evgpe.c73
-rw-r--r--drivers/acpi/acpica/evxface.c77
-rw-r--r--drivers/acpi/acpica/evxfevnt.c62
-rw-r--r--drivers/acpi/acpica/utmutex.c5
-rw-r--r--drivers/acpi/apei/Kconfig9
-rw-r--r--drivers/acpi/apei/Makefile1
-rw-r--r--drivers/acpi/apei/apei-base.c4
-rw-r--r--drivers/acpi/apei/erst-dbg.c207
-rw-r--r--drivers/acpi/apei/erst.c1
-rw-r--r--drivers/acpi/apei/ghes.c172
-rw-r--r--drivers/acpi/apei/hest.c76
-rw-r--r--drivers/acpi/bus.c4
-rw-r--r--drivers/acpi/debug.c406
-rw-r--r--drivers/acpi/debugfs.c93
-rw-r--r--drivers/acpi/glue.c3
-rw-r--r--drivers/acpi/internal.h8
-rw-r--r--drivers/acpi/numa.c4
-rw-r--r--drivers/acpi/osl.c7
-rw-r--r--drivers/acpi/power.c129
-rw-r--r--drivers/acpi/proc.c70
-rw-r--r--drivers/acpi/processor_driver.c85
-rw-r--r--drivers/acpi/processor_idle.c102
-rw-r--r--drivers/acpi/processor_thermal.c83
-rw-r--r--drivers/acpi/processor_throttling.c2
-rw-r--r--drivers/acpi/sleep.c60
-rw-r--r--drivers/acpi/sleep.h5
-rw-r--r--drivers/acpi/sysfs.c (renamed from drivers/acpi/system.c)466
-rw-r--r--drivers/acpi/thermal.c86
-rw-r--r--drivers/acpi/video.c141
-rw-r--r--drivers/acpi/wakeup.c48
-rw-r--r--drivers/ata/Kconfig11
-rw-r--r--drivers/ata/Makefile2
-rw-r--r--drivers/ata/libata-acpi.c6
-rw-r--r--drivers/ata/libata-core.c2
-rw-r--r--drivers/ata/libata-scsi.c4
-rw-r--r--drivers/ata/pata_mpc52xx.c8
-rw-r--r--drivers/ata/pata_of_platform.c4
-rw-r--r--drivers/ata/pata_pxa.c411
-rw-r--r--drivers/ata/sata_fsl.c8
-rw-r--r--drivers/atm/fore200e.c26
-rw-r--r--drivers/atm/solos-pci.c7
-rw-r--r--drivers/base/node.c46
-rw-r--r--drivers/block/DAC960.c13
-rw-r--r--drivers/block/amiflop.c29
-rw-r--r--drivers/block/aoe/aoeblk.c6
-rw-r--r--drivers/block/ataflop.c32
-rw-r--r--drivers/block/brd.c9
-rw-r--r--drivers/block/cciss.c2165
-rw-r--r--drivers/block/cciss.h135
-rw-r--r--drivers/block/cciss_cmd.h36
-rw-r--r--drivers/block/cciss_scsi.c670
-rw-r--r--drivers/block/cpqarray.c78
-rw-r--r--drivers/block/drbd/drbd_actlog.c8
-rw-r--r--drivers/block/drbd/drbd_int.h16
-rw-r--r--drivers/block/drbd/drbd_main.c102
-rw-r--r--drivers/block/drbd/drbd_nl.c4
-rw-r--r--drivers/block/drbd/drbd_proc.c19
-rw-r--r--drivers/block/drbd/drbd_receiver.c135
-rw-r--r--drivers/block/drbd/drbd_req.c2
-rw-r--r--drivers/block/drbd/drbd_worker.c15
-rw-r--r--drivers/block/floppy.c182
-rw-r--r--drivers/block/hd.c2
-rw-r--r--drivers/block/loop.c9
-rw-r--r--drivers/block/mg_disk.c4
-rw-r--r--drivers/block/nbd.c7
-rw-r--r--drivers/block/osdblk.c15
-rw-r--r--drivers/block/paride/pcd.c21
-rw-r--r--drivers/block/paride/pd.c11
-rw-r--r--drivers/block/paride/pf.c26
-rw-r--r--drivers/block/pktcdvd.c20
-rw-r--r--drivers/block/ps3disk.c25
-rw-r--r--drivers/block/swim.c20
-rw-r--r--drivers/block/swim3.c32
-rw-r--r--drivers/block/ub.c35
-rw-r--r--drivers/block/umem.c2
-rw-r--r--drivers/block/viodasd.c21
-rw-r--r--drivers/block/virtio_blk.c88
-rw-r--r--drivers/block/xd.c19
-rw-r--r--drivers/block/xen-blkfront.c403
-rw-r--r--drivers/block/xsysace.c12
-rw-r--r--drivers/block/z2ram.c13
-rw-r--r--drivers/cdrom/cdrom.c46
-rw-r--r--drivers/cdrom/gdrom.c48
-rw-r--r--drivers/cdrom/viocd.c106
-rw-r--r--drivers/char/Kconfig2
-rw-r--r--drivers/char/Makefile2
-rw-r--r--drivers/char/amiserial.c25
-rw-r--r--drivers/char/briq_panel.c6
-rw-r--r--drivers/char/cyclades.c22
-rw-r--r--drivers/char/epca.c4
-rw-r--r--drivers/char/hvc_iucv.c9
-rw-r--r--drivers/char/hvc_tile.c67
-rw-r--r--drivers/char/hw_random/n2-drv.c4
-rw-r--r--drivers/char/hw_random/n2rng.h2
-rw-r--r--drivers/char/hw_random/pasemi-rng.c4
-rw-r--r--drivers/char/ip2/ip2main.c4
-rw-r--r--drivers/char/ipmi/ipmi_si_intf.c69
-rw-r--r--drivers/char/ipmi/ipmi_watchdog.c42
-rw-r--r--drivers/char/isicom.c13
-rw-r--r--drivers/char/istallion.c68
-rw-r--r--drivers/char/keyboard.c10
-rw-r--r--drivers/char/misc.c2
-rw-r--r--drivers/char/mxser.c2
-rw-r--r--drivers/char/n_gsm.c3
-rw-r--r--drivers/char/n_hdlc.c16
-rw-r--r--drivers/char/n_r3964.c10
-rw-r--r--drivers/char/n_tty.c17
-rw-r--r--drivers/char/nozomi.c7
-rw-r--r--drivers/char/pcmcia/ipwireless/network.c2
-rw-r--r--drivers/char/pty.c47
-rw-r--r--drivers/char/riscom8.c14
-rw-r--r--drivers/char/rocket.c28
-rw-r--r--drivers/char/rtc.c2
-rw-r--r--drivers/char/selection.c13
-rw-r--r--drivers/char/serial167.c8
-rw-r--r--drivers/char/specialix.c13
-rw-r--r--drivers/char/stallion.c20
-rw-r--r--drivers/char/sx.c12
-rw-r--r--drivers/char/synclink.c21
-rw-r--r--drivers/char/synclink_gt.c92
-rw-r--r--drivers/char/synclinkmp.c43
-rw-r--r--drivers/char/tty_io.c150
-rw-r--r--drivers/char/tty_ioctl.c18
-rw-r--r--drivers/char/tty_ldisc.c43
-rw-r--r--drivers/char/tty_mutex.c47
-rw-r--r--drivers/char/tty_port.c4
-rw-r--r--drivers/char/vc_screen.c4
-rw-r--r--drivers/char/vt.c43
-rw-r--r--drivers/char/vt_ioctl.c17
-rw-r--r--drivers/char/xilinx_hwicap/xilinx_hwicap.c4
-rw-r--r--drivers/cpuidle/cpuidle.c31
-rw-r--r--drivers/cpuidle/governors/menu.c23
-rw-r--r--drivers/crypto/Kconfig2
-rw-r--r--drivers/crypto/amcc/crypto4xx_core.c4
-rw-r--r--drivers/crypto/amcc/crypto4xx_core.h2
-rw-r--r--drivers/crypto/ixp4xx_crypto.c21
-rw-r--r--drivers/crypto/n2_core.c26
-rw-r--r--drivers/crypto/talitos.c6
-rw-r--r--drivers/dma/Kconfig22
-rw-r--r--drivers/dma/Makefile2
-rw-r--r--drivers/dma/at_hdmac.c4
-rw-r--r--drivers/dma/coh901318.c169
-rw-r--r--drivers/dma/dmatest.c2
-rw-r--r--drivers/dma/fsldma.c4
-rw-r--r--drivers/dma/intel_mid_dma.c1143
-rw-r--r--drivers/dma/intel_mid_dma_regs.h260
-rw-r--r--drivers/dma/ioat/dma.h1
-rw-r--r--drivers/dma/ioat/dma_v2.c24
-rw-r--r--drivers/dma/ioat/dma_v3.c5
-rw-r--r--drivers/dma/mpc512x_dma.c4
-rw-r--r--drivers/dma/pch_dma.c957
-rw-r--r--drivers/dma/ppc4xx/adma.c8
-rw-r--r--drivers/dma/shdma.c8
-rw-r--r--drivers/dma/ste_dma40.c860
-rw-r--r--drivers/dma/ste_dma40_ll.c40
-rw-r--r--drivers/dma/ste_dma40_ll.h15
-rw-r--r--drivers/dma/timb_dma.c8
-rw-r--r--drivers/edac/i5000_edac.c2
-rw-r--r--drivers/edac/i5400_edac.c2
-rw-r--r--drivers/edac/mpc85xx_edac.c28
-rw-r--r--drivers/edac/ppc4xx_edac.c12
-rw-r--r--drivers/firmware/Kconfig10
-rw-r--r--drivers/firmware/Makefile1
-rw-r--r--drivers/firmware/edd.c20
-rw-r--r--drivers/firmware/iscsi_ibft.c6
-rw-r--r--drivers/gpio/Kconfig18
-rw-r--r--drivers/gpio/Makefile2
-rw-r--r--drivers/gpio/gpiolib.c96
-rw-r--r--drivers/gpio/max730x.c22
-rw-r--r--drivers/gpio/pcf857x.c9
-rw-r--r--drivers/gpio/stmpe-gpio.c399
-rw-r--r--drivers/gpio/sx150x.c645
-rw-r--r--drivers/gpio/wm831x-gpio.c32
-rw-r--r--drivers/gpu/drm/ati_pcigart.c2
-rw-r--r--drivers/gpu/drm/drm_bufs.c33
-rw-r--r--drivers/gpu/drm/drm_crtc.c6
-rw-r--r--drivers/gpu/drm/drm_crtc_helper.c26
-rw-r--r--drivers/gpu/drm/drm_edid.c840
-rw-r--r--drivers/gpu/drm/drm_edid_modes.h380
-rw-r--r--drivers/gpu/drm/drm_fops.c16
-rw-r--r--drivers/gpu/drm/drm_gem.c2
-rw-r--r--drivers/gpu/drm/drm_ioctl.c1
-rw-r--r--drivers/gpu/drm/i2c/ch7006_drv.c1
-rw-r--r--drivers/gpu/drm/i2c/ch7006_mode.c5
-rw-r--r--drivers/gpu/drm/i2c/ch7006_priv.h1
-rw-r--r--drivers/gpu/drm/i915/i915_gem.c26
-rw-r--r--drivers/gpu/drm/i915/i915_gem_tiling.c4
-rw-r--r--drivers/gpu/drm/i915/i915_opregion.c1
-rw-r--r--drivers/gpu/drm/i915/intel_display.c15
-rw-r--r--drivers/gpu/drm/i915/intel_fb.c8
-rw-r--r--drivers/gpu/drm/nouveau/Makefile8
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_bios.c194
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_bios.h1
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_bo.c6
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_connector.c19
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_display.c6
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_dp.c87
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_drv.h45
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_encoder.h6
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_fbcon.c3
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_gem.c8
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_hw.c11
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_i2c.c41
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_i2c.h8
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_irq.c6
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_mem.c15
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_reg.h18
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_state.c91
-rw-r--r--drivers/gpu/drm/nouveau/nv04_crtc.c15
-rw-r--r--drivers/gpu/drm/nouveau/nv04_dfp.c73
-rw-r--r--drivers/gpu/drm/nouveau/nv04_tv.c10
-rw-r--r--drivers/gpu/drm/nouveau/nv10_graph.c175
-rw-r--r--drivers/gpu/drm/nouveau/nv30_fb.c24
-rw-r--r--drivers/gpu/drm/nouveau/nv50_crtc.c34
-rw-r--r--drivers/gpu/drm/nouveau/nv50_display.c5
-rw-r--r--drivers/gpu/drm/nouveau/nvc0_fb.c38
-rw-r--r--drivers/gpu/drm/nouveau/nvc0_fifo.c96
-rw-r--r--drivers/gpu/drm/nouveau/nvc0_graph.c75
-rw-r--r--drivers/gpu/drm/nouveau/nvc0_instmem.c232
-rw-r--r--drivers/gpu/drm/radeon/r600_cp.c2
-rw-r--r--drivers/gpu/drm/radeon/r600_cs.c33
-rw-r--r--drivers/gpu/drm/radeon/radeon.h2
-rw-r--r--drivers/gpu/drm/radeon/radeon_atombios.c180
-rw-r--r--drivers/gpu/drm/radeon/radeon_clocks.c81
-rw-r--r--drivers/gpu/drm/radeon/radeon_combios.c388
-rw-r--r--drivers/gpu/drm/radeon/radeon_connectors.c45
-rw-r--r--drivers/gpu/drm/radeon/radeon_cs.c2
-rw-r--r--drivers/gpu/drm/radeon/radeon_cursor.c2
-rw-r--r--drivers/gpu/drm/radeon/radeon_device.c3
-rw-r--r--drivers/gpu/drm/radeon/radeon_display.c34
-rw-r--r--drivers/gpu/drm/radeon/radeon_fb.c2
-rw-r--r--drivers/gpu/drm/radeon/radeon_gem.c12
-rw-r--r--drivers/gpu/drm/radeon/radeon_i2c.c82
-rw-r--r--drivers/gpu/drm/radeon/radeon_kms.c28
-rw-r--r--drivers/gpu/drm/radeon/radeon_mode.h24
-rw-r--r--drivers/gpu/drm/radeon/radeon_pm.c24
-rw-r--r--drivers/gpu/drm/radeon/reg_srcs/rv5151
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_kms.c8
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c2
-rw-r--r--drivers/hid/hid-wacom.c49
-rw-r--r--drivers/hwmon/Kconfig48
-rw-r--r--drivers/hwmon/Makefile3
-rw-r--r--drivers/hwmon/ams/ams.h2
-rw-r--r--drivers/hwmon/asc7621.c9
-rw-r--r--drivers/hwmon/coretemp.c23
-rw-r--r--drivers/hwmon/emc1403.c33
-rw-r--r--drivers/hwmon/emc2103.c740
-rw-r--r--drivers/hwmon/f71882fg.c83
-rw-r--r--drivers/hwmon/hdaps.c1
-rw-r--r--drivers/hwmon/it87.c46
-rw-r--r--drivers/hwmon/jc42.c593
-rw-r--r--drivers/hwmon/k8temp.c3
-rw-r--r--drivers/hwmon/lm75.c39
-rw-r--r--drivers/hwmon/lm75.h1
-rw-r--r--drivers/hwmon/ltc4245.c177
-rw-r--r--drivers/hwmon/mc13783-adc.c17
-rw-r--r--drivers/hwmon/pc87360.c31
-rw-r--r--drivers/hwmon/pc87427.c862
-rw-r--r--drivers/hwmon/smm665.c743
-rw-r--r--drivers/hwmon/ultra45_env.c4
-rw-r--r--drivers/hwmon/via-cputemp.c2
-rw-r--r--drivers/hwmon/w83627ehf.c97
-rw-r--r--drivers/i2c/Kconfig13
-rw-r--r--drivers/i2c/Makefile3
-rw-r--r--drivers/i2c/busses/Kconfig24
-rw-r--r--drivers/i2c/busses/Makefile1
-rw-r--r--drivers/i2c/busses/i2c-cpm.c8
-rw-r--r--drivers/i2c/busses/i2c-davinci.c314
-rw-r--r--drivers/i2c/busses/i2c-ibm_iic.c6
-rw-r--r--drivers/i2c/busses/i2c-mpc.c4
-rw-r--r--drivers/i2c/busses/i2c-nuc900.c709
-rw-r--r--drivers/i2c/busses/i2c-pxa.c2
-rw-r--r--drivers/i2c/busses/i2c-sh_mobile.c121
-rw-r--r--drivers/i2c/i2c-core.c158
-rw-r--r--drivers/i2c/i2c-dev.c66
-rw-r--r--drivers/i2c/i2c-mux.c165
-rw-r--r--drivers/i2c/muxes/Kconfig18
-rw-r--r--drivers/i2c/muxes/Makefile8
-rw-r--r--drivers/i2c/muxes/pca954x.c301
-rw-r--r--drivers/ide/ide-atapi.c17
-rw-r--r--drivers/ide/ide-cd.c112
-rw-r--r--drivers/ide/ide-cd_ioctl.c2
-rw-r--r--drivers/ide/ide-disk.c18
-rw-r--r--drivers/ide/ide-disk_ioctl.c9
-rw-r--r--drivers/ide/ide-eh.c5
-rw-r--r--drivers/ide/ide-floppy.c27
-rw-r--r--drivers/ide/ide-floppy_ioctl.c12
-rw-r--r--drivers/ide/ide-gd.c19
-rw-r--r--drivers/ide/ide-io.c8
-rw-r--r--drivers/ide/ide-pm.c8
-rw-r--r--drivers/ide/ide-tape.c22
-rw-r--r--drivers/ide/ide-taskfile.c10
-rw-r--r--drivers/ide/ide.c20
-rw-r--r--drivers/ide/tx4938ide.c2
-rw-r--r--drivers/ide/tx4939ide.c2
-rw-r--r--drivers/ide/via82cxxx.c2
-rw-r--r--drivers/idle/Kconfig3
-rwxr-xr-xdrivers/idle/intel_idle.c61
-rw-r--r--drivers/infiniband/hw/cxgb4/device.c9
-rw-r--r--drivers/infiniband/hw/cxgb4/resource.c7
-rw-r--r--drivers/infiniband/hw/cxgb4/t4.h2
-rw-r--r--drivers/infiniband/hw/ehca/ehca_classes.h2
-rw-r--r--drivers/infiniband/hw/ehca/ehca_main.c4
-rw-r--r--drivers/input/evdev.c152
-rw-r--r--drivers/input/input.c46
-rw-r--r--drivers/input/joydev.c31
-rw-r--r--drivers/input/joystick/a3d.c3
-rw-r--r--drivers/input/joystick/adi.c2
-rw-r--r--drivers/input/joystick/amijoy.c4
-rw-r--r--drivers/input/joystick/gf2k.c20
-rw-r--r--drivers/input/joystick/interact.c14
-rw-r--r--drivers/input/joystick/sidewinder.c18
-rw-r--r--drivers/input/joystick/xpad.c1
-rw-r--r--drivers/input/keyboard/Kconfig10
-rw-r--r--drivers/input/keyboard/Makefile1
-rw-r--r--drivers/input/keyboard/gpio_keys.c22
-rw-r--r--drivers/input/keyboard/hil_kbd.c21
-rw-r--r--drivers/input/keyboard/stmpe-keypad.c386
-rw-r--r--drivers/input/misc/adxl34x.c1
-rw-r--r--drivers/input/misc/ati_remote2.c26
-rw-r--r--drivers/input/misc/sparcspkr.c10
-rw-r--r--drivers/input/misc/uinput.c29
-rw-r--r--drivers/input/mouse/appletouch.c6
-rw-r--r--drivers/input/mouse/elantech.c31
-rw-r--r--drivers/input/mouse/elantech.h7
-rw-r--r--drivers/input/mouse/pc110pad.c4
-rw-r--r--drivers/input/mouse/psmouse-base.c14
-rw-r--r--drivers/input/mouse/synaptics.c4
-rw-r--r--drivers/input/mousedev.c44
-rw-r--r--drivers/input/serio/i8042-sparcio.h8
-rw-r--r--drivers/input/serio/i8042.c25
-rw-r--r--drivers/input/serio/xilinx_ps2.c4
-rw-r--r--drivers/input/tablet/aiptek.c15
-rw-r--r--drivers/input/tablet/wacom_wac.c4
-rw-r--r--drivers/input/touchscreen/Kconfig10
-rw-r--r--drivers/input/touchscreen/Makefile1
-rw-r--r--drivers/input/touchscreen/cy8ctmg110_ts.c6
-rw-r--r--drivers/input/touchscreen/stmpe-ts.c397
-rw-r--r--drivers/isdn/gigaset/bas-gigaset.c6
-rw-r--r--drivers/isdn/gigaset/capi.c1
-rw-r--r--drivers/isdn/hardware/avm/c4.c1
-rw-r--r--drivers/isdn/hardware/avm/t1pci.c1
-rw-r--r--drivers/isdn/hardware/mISDN/mISDNinfineon.c5
-rw-r--r--drivers/isdn/sc/ioctl.c10
-rw-r--r--drivers/leds/leds-gpio.c4
-rw-r--r--drivers/macintosh/macio_sysfs.c6
-rw-r--r--drivers/macintosh/smu.c6
-rw-r--r--drivers/macintosh/therm_adt746x.c2
-rw-r--r--drivers/macintosh/therm_pm72.c6
-rw-r--r--drivers/macintosh/therm_windtunnel.c10
-rw-r--r--drivers/md/Kconfig18
-rw-r--r--drivers/md/Makefile77
-rw-r--r--drivers/md/bitmap.c508
-rw-r--r--drivers/md/bitmap.h6
-rw-r--r--drivers/md/dm-crypt.c342
-rw-r--r--drivers/md/dm-delay.c6
-rw-r--r--drivers/md/dm-exception-store.c4
-rw-r--r--drivers/md/dm-exception-store.h3
-rw-r--r--drivers/md/dm-io.c12
-rw-r--r--drivers/md/dm-ioctl.c207
-rw-r--r--drivers/md/dm-kcopyd.c2
-rw-r--r--drivers/md/dm-linear.c3
-rw-r--r--drivers/md/dm-mpath.c11
-rw-r--r--drivers/md/dm-raid1.c4
-rw-r--r--drivers/md/dm-snap-persistent.c6
-rw-r--r--drivers/md/dm-snap.c62
-rw-r--r--drivers/md/dm-stripe.c89
-rw-r--r--drivers/md/dm-table.c99
-rw-r--r--drivers/md/dm-target.c5
-rw-r--r--drivers/md/dm-zero.c5
-rw-r--r--drivers/md/dm.c374
-rw-r--r--drivers/md/dm.h14
-rw-r--r--drivers/md/linear.c2
-rw-r--r--drivers/md/md.c302
-rw-r--r--drivers/md/md.h59
-rw-r--r--drivers/md/mktables.c132
-rw-r--r--drivers/md/multipath.c8
-rw-r--r--drivers/md/raid0.c2
-rw-r--r--drivers/md/raid1.c22
-rw-r--r--drivers/md/raid10.c30
-rw-r--r--drivers/md/raid5.c170
-rw-r--r--drivers/md/raid5.h9
-rw-r--r--drivers/md/raid6algos.c154
-rw-r--r--drivers/md/raid6altivec.uc130
-rw-r--r--drivers/md/raid6int.uc117
-rw-r--r--drivers/md/raid6mmx.c142
-rw-r--r--drivers/md/raid6recov.c132
-rw-r--r--drivers/md/raid6sse1.c162
-rw-r--r--drivers/md/raid6sse2.c262
-rw-r--r--drivers/md/raid6test/Makefile75
-rw-r--r--drivers/md/raid6test/test.c124
-rw-r--r--drivers/md/raid6x86.h61
-rw-r--r--drivers/md/unroll.awk20
-rw-r--r--drivers/media/IR/Kconfig43
-rw-r--r--drivers/media/IR/Makefile2
-rw-r--r--drivers/media/IR/ene_ir.c1023
-rw-r--r--drivers/media/IR/ene_ir.h235
-rw-r--r--drivers/media/IR/imon.c20
-rw-r--r--drivers/media/IR/ir-core-priv.h13
-rw-r--r--drivers/media/IR/ir-jvc-decoder.c14
-rw-r--r--drivers/media/IR/ir-keytable.c13
-rw-r--r--drivers/media/IR/ir-lirc-codec.c124
-rw-r--r--drivers/media/IR/ir-nec-decoder.c25
-rw-r--r--drivers/media/IR/ir-raw-event.c159
-rw-r--r--drivers/media/IR/ir-sysfs.c2
-rw-r--r--drivers/media/IR/keymaps/Makefile2
-rw-r--r--drivers/media/IR/keymaps/rc-empty.c44
-rw-r--r--drivers/media/IR/keymaps/rc-rc5-streamzap.c81
-rw-r--r--drivers/media/IR/keymaps/rc-rc6-mce.c2
-rw-r--r--drivers/media/IR/mceusb.c21
-rw-r--r--drivers/media/IR/rc-map.c23
-rw-r--r--drivers/media/IR/streamzap.c741
-rw-r--r--drivers/media/common/tuners/Kconfig2
-rw-r--r--drivers/media/dvb/bt8xx/dst.c10
-rw-r--r--drivers/media/dvb/dm1105/Kconfig2
-rw-r--r--drivers/media/dvb/dvb-usb/Kconfig2
-rw-r--r--drivers/media/dvb/frontends/Kconfig2
-rw-r--r--drivers/media/dvb/siano/Kconfig2
-rw-r--r--drivers/media/dvb/siano/smscoreapi.c6
-rw-r--r--drivers/media/dvb/ttpci/Kconfig2
-rw-r--r--drivers/media/video/Kconfig16
-rw-r--r--drivers/media/video/Makefile3
-rw-r--r--drivers/media/video/bt8xx/Kconfig2
-rw-r--r--drivers/media/video/bt8xx/bttv-i2c.c2
-rw-r--r--drivers/media/video/cs53l32a.c107
-rw-r--r--drivers/media/video/cx18/Kconfig2
-rw-r--r--drivers/media/video/cx18/cx18-i2c.c3
-rw-r--r--drivers/media/video/cx231xx/Kconfig2
-rw-r--r--drivers/media/video/cx2341x.c747
-rw-r--r--drivers/media/video/cx23885/Kconfig2
-rw-r--r--drivers/media/video/cx23885/Makefile5
-rw-r--r--drivers/media/video/cx23885/cx23885-av.c35
-rw-r--r--drivers/media/video/cx23885/cx23885-av.h27
-rw-r--r--drivers/media/video/cx23885/cx23885-cards.c114
-rw-r--r--drivers/media/video/cx23885/cx23885-core.c124
-rw-r--r--drivers/media/video/cx23885/cx23885-i2c.c42
-rw-r--r--drivers/media/video/cx23885/cx23885-input.c72
-rw-r--r--drivers/media/video/cx23885/cx23885-ir.c24
-rw-r--r--drivers/media/video/cx23885/cx23885-reg.h1
-rw-r--r--drivers/media/video/cx23885/cx23885-vbi.c2
-rw-r--r--drivers/media/video/cx23885/cx23885-video.c23
-rw-r--r--drivers/media/video/cx23885/cx23885.h9
-rw-r--r--drivers/media/video/cx23885/cx23888-ir.c142
-rw-r--r--drivers/media/video/cx25840/Makefile2
-rw-r--r--drivers/media/video/cx25840/cx25840-audio.c144
-rw-r--r--drivers/media/video/cx25840/cx25840-core.c540
-rw-r--r--drivers/media/video/cx25840/cx25840-core.h52
-rw-r--r--drivers/media/video/cx25840/cx25840-ir.c1279
-rw-r--r--drivers/media/video/cx88/Kconfig2
-rw-r--r--drivers/media/video/cx88/cx88-i2c.c19
-rw-r--r--drivers/media/video/em28xx/Kconfig2
-rw-r--r--drivers/media/video/em28xx/em28xx-cards.c2
-rw-r--r--drivers/media/video/fsl-viu.c8
-rw-r--r--drivers/media/video/gspca/gspca.c21
-rw-r--r--drivers/media/video/gspca/sonixj.c10
-rw-r--r--drivers/media/video/gspca/sq930x.c347
-rw-r--r--drivers/media/video/gspca/t613.c4
-rw-r--r--drivers/media/video/gspca/vc032x.c360
-rw-r--r--drivers/media/video/gspca/zc3xx.c1715
-rw-r--r--drivers/media/video/ivtv/Kconfig2
-rw-r--r--drivers/media/video/ivtv/ivtv-controls.c276
-rw-r--r--drivers/media/video/ivtv/ivtv-controls.h6
-rw-r--r--drivers/media/video/ivtv/ivtv-driver.c26
-rw-r--r--drivers/media/video/ivtv/ivtv-driver.h4
-rw-r--r--drivers/media/video/ivtv/ivtv-fileops.c23
-rw-r--r--drivers/media/video/ivtv/ivtv-firmware.c6
-rw-r--r--drivers/media/video/ivtv/ivtv-gpio.c77
-rw-r--r--drivers/media/video/ivtv/ivtv-i2c.c16
-rw-r--r--drivers/media/video/ivtv/ivtv-ioctl.c31
-rw-r--r--drivers/media/video/ivtv/ivtv-streams.c24
-rw-r--r--drivers/media/video/msp3400-driver.c248
-rw-r--r--drivers/media/video/msp3400-driver.h18
-rw-r--r--drivers/media/video/msp3400-kthreads.c16
-rw-r--r--drivers/media/video/mt9m111.c40
-rw-r--r--drivers/media/video/mx2_camera.c4
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-debugifc.c14
-rw-r--r--drivers/media/video/s5p-fimc/Makefile3
-rw-r--r--drivers/media/video/s5p-fimc/fimc-core.c1586
-rw-r--r--drivers/media/video/s5p-fimc/fimc-core.h471
-rw-r--r--drivers/media/video/s5p-fimc/fimc-reg.c527
-rw-r--r--drivers/media/video/s5p-fimc/regs-fimc.h293
-rw-r--r--drivers/media/video/saa7115.c183
-rw-r--r--drivers/media/video/saa7134/Kconfig2
-rw-r--r--drivers/media/video/saa717x.c323
-rw-r--r--drivers/media/video/soc_camera.c9
-rw-r--r--drivers/media/video/tlg2300/Kconfig2
-rw-r--r--drivers/media/video/tvp7002.c10
-rw-r--r--drivers/media/video/usbvideo/usbvideo.c12
-rw-r--r--drivers/media/video/uvc/uvc_driver.c9
-rw-r--r--drivers/media/video/uvc/uvc_queue.c13
-rw-r--r--drivers/media/video/uvc/uvc_video.c19
-rw-r--r--drivers/media/video/uvc/uvcvideo.h5
-rw-r--r--drivers/media/video/v4l2-common.c482
-rw-r--r--drivers/media/video/v4l2-compat-ioctl32.c7
-rw-r--r--drivers/media/video/v4l2-ctrls.c1852
-rw-r--r--drivers/media/video/v4l2-dev.c60
-rw-r--r--drivers/media/video/v4l2-device.c7
-rw-r--r--drivers/media/video/v4l2-ioctl.c46
-rw-r--r--drivers/media/video/wm8739.c179
-rw-r--r--drivers/media/video/wm8775.c79
-rw-r--r--drivers/memstick/core/mspro_block.c18
-rw-r--r--drivers/message/fusion/mptbase.c247
-rw-r--r--drivers/message/fusion/mptbase.h25
-rw-r--r--drivers/message/i2o/exec-osm.c8
-rw-r--r--drivers/message/i2o/i2o_block.c33
-rw-r--r--drivers/message/i2o/i2o_config.c18
-rw-r--r--drivers/message/i2o/i2o_scsi.c3
-rw-r--r--drivers/mfd/88pm860x-core.c84
-rw-r--r--drivers/mfd/Kconfig75
-rw-r--r--drivers/mfd/Makefile5
-rw-r--r--drivers/mfd/ab3100-otp.c16
-rw-r--r--drivers/mfd/ab3550-core.c23
-rw-r--r--drivers/mfd/ab8500-core.c4
-rw-r--r--drivers/mfd/ab8500-spi.c7
-rw-r--r--drivers/mfd/abx500-core.c2
-rw-r--r--drivers/mfd/davinci_voicecodec.c6
-rw-r--r--drivers/mfd/janz-cmodio.c1
-rw-r--r--drivers/mfd/jz4740-adc.c394
-rw-r--r--drivers/mfd/max8925-core.c27
-rw-r--r--drivers/mfd/max8998.c158
-rw-r--r--drivers/mfd/mc13783-core.c30
-rw-r--r--drivers/mfd/menelaus.c75
-rw-r--r--drivers/mfd/mfd-core.c4
-rw-r--r--drivers/mfd/stmpe.c985
-rw-r--r--drivers/mfd/stmpe.h183
-rw-r--r--drivers/mfd/t7l66xb.c3
-rw-r--r--drivers/mfd/tc6387xb.c16
-rw-r--r--drivers/mfd/tc6393xb.c4
-rw-r--r--drivers/mfd/tps6507x.c4
-rw-r--r--drivers/mfd/tps6586x.c375
-rw-r--r--drivers/mfd/twl6030-pwm.c163
-rw-r--r--drivers/mfd/ucb1400_core.c2
-rw-r--r--drivers/mfd/wm831x-core.c18
-rw-r--r--drivers/mfd/wm8350-core.c6
-rw-r--r--drivers/mfd/wm8994-core.c8
-rw-r--r--drivers/misc/Kconfig27
-rw-r--r--drivers/misc/Makefile3
-rw-r--r--drivers/misc/bh1780gli.c273
-rw-r--r--drivers/misc/bmp085.c482
-rw-r--r--drivers/misc/cs5535-mfgpt.c11
-rw-r--r--drivers/misc/hmc6352.c166
-rw-r--r--drivers/misc/hpilo.c17
-rw-r--r--drivers/misc/hpilo.h8
-rw-r--r--drivers/misc/lkdtm.c4
-rw-r--r--drivers/mmc/card/block.c87
-rw-r--r--drivers/mmc/card/mmc_test.c811
-rw-r--r--drivers/mmc/card/queue.c21
-rw-r--r--drivers/mmc/core/bus.c9
-rw-r--r--drivers/mmc/core/core.c441
-rw-r--r--drivers/mmc/core/core.h2
-rw-r--r--drivers/mmc/core/host.c4
-rw-r--r--drivers/mmc/core/mmc.c75
-rw-r--r--drivers/mmc/core/sd.c331
-rw-r--r--drivers/mmc/core/sd.h17
-rw-r--r--drivers/mmc/core/sd_ops.c48
-rw-r--r--drivers/mmc/core/sd_ops.h1
-rw-r--r--drivers/mmc/core/sdio.c210
-rw-r--r--drivers/mmc/host/Kconfig18
-rw-r--r--drivers/mmc/host/Makefile7
-rw-r--r--drivers/mmc/host/mmc_spi.c60
-rw-r--r--drivers/mmc/host/msm_sdcc.c62
-rw-r--r--drivers/mmc/host/msm_sdcc.h6
-rw-r--r--drivers/mmc/host/omap_hsmmc.c47
-rw-r--r--drivers/mmc/host/sdhci-cns3xxx.c97
-rw-r--r--drivers/mmc/host/sdhci-of-core.c12
-rw-r--r--drivers/mmc/host/sdhci-pci.c49
-rw-r--r--drivers/mmc/host/sdhci-pltfm.c17
-rw-r--r--drivers/mmc/host/sdhci-pltfm.h18
-rw-r--r--drivers/mmc/host/sdhci-s3c.c123
-rw-r--r--drivers/mmc/host/sdhci.c53
-rw-r--r--drivers/mmc/host/sdhci.h10
-rw-r--r--drivers/mtd/Kconfig12
-rw-r--r--drivers/mtd/afs.c2
-rw-r--r--drivers/mtd/chips/cfi_cmdset_0001.c31
-rw-r--r--drivers/mtd/chips/cfi_cmdset_0002.c17
-rw-r--r--drivers/mtd/chips/cfi_cmdset_0020.c1
-rw-r--r--drivers/mtd/chips/cfi_probe.c4
-rw-r--r--drivers/mtd/chips/cfi_util.c1
-rw-r--r--drivers/mtd/chips/chipreg.c1
-rw-r--r--drivers/mtd/chips/map_absent.c1
-rw-r--r--drivers/mtd/chips/map_ram.c1
-rw-r--r--drivers/mtd/chips/map_rom.c1
-rw-r--r--drivers/mtd/cmdlinepart.c17
-rw-r--r--drivers/mtd/devices/docecc.c1
-rw-r--r--drivers/mtd/devices/docprobe.c1
-rw-r--r--drivers/mtd/devices/m25p80.c57
-rw-r--r--drivers/mtd/devices/mtd_dataflash.c12
-rw-r--r--drivers/mtd/devices/mtdram.c1
-rw-r--r--drivers/mtd/devices/pmc551.c1
-rw-r--r--drivers/mtd/devices/sst25l.c2
-rw-r--r--drivers/mtd/ftl.c2
-rw-r--r--drivers/mtd/inftlcore.c6
-rw-r--r--drivers/mtd/inftlmount.c5
-rw-r--r--drivers/mtd/lpddr/lpddr_cmds.c20
-rw-r--r--drivers/mtd/maps/Kconfig8
-rw-r--r--drivers/mtd/maps/Makefile1
-rw-r--r--drivers/mtd/maps/ixp4xx.c35
-rw-r--r--drivers/mtd/maps/physmap.c14
-rw-r--r--drivers/mtd/maps/physmap_of.c14
-rw-r--r--drivers/mtd/maps/redwood.c131
-rw-r--r--drivers/mtd/maps/sun_uflash.c6
-rw-r--r--drivers/mtd/mtd_blkdevs.c41
-rw-r--r--drivers/mtd/mtdblock.c19
-rw-r--r--drivers/mtd/mtdblock_ro.c19
-rw-r--r--drivers/mtd/mtdchar.c59
-rw-r--r--drivers/mtd/mtdconcat.c38
-rw-r--r--drivers/mtd/mtdcore.c21
-rw-r--r--drivers/mtd/mtdoops.c2
-rw-r--r--drivers/mtd/mtdpart.c31
-rw-r--r--drivers/mtd/mtdsuper.c2
-rw-r--r--drivers/mtd/nand/Kconfig33
-rw-r--r--drivers/mtd/nand/atmel_nand.c2
-rw-r--r--drivers/mtd/nand/bf5xx_nand.c117
-rw-r--r--drivers/mtd/nand/davinci_nand.c17
-rw-r--r--drivers/mtd/nand/denali.c1597
-rw-r--r--drivers/mtd/nand/denali.h148
-rw-r--r--drivers/mtd/nand/diskonchip.c6
-rw-r--r--drivers/mtd/nand/fsl_elbc_nand.c4
-rw-r--r--drivers/mtd/nand/fsl_upm.c4
-rw-r--r--drivers/mtd/nand/mpc5121_nfc.c4
-rw-r--r--drivers/mtd/nand/mxc_nand.c600
-rw-r--r--drivers/mtd/nand/nand_base.c118
-rw-r--r--drivers/mtd/nand/nand_bbt.c103
-rw-r--r--drivers/mtd/nand/nand_ids.c4
-rw-r--r--drivers/mtd/nand/nandsim.c14
-rw-r--r--drivers/mtd/nand/ndfc.c6
-rw-r--r--drivers/mtd/nand/omap2.c218
-rw-r--r--drivers/mtd/nand/pasemi_nand.c4
-rw-r--r--drivers/mtd/nand/plat_nand.c7
-rw-r--r--drivers/mtd/nand/r852.c6
-rw-r--r--drivers/mtd/nand/rtc_from4.c1
-rw-r--r--drivers/mtd/nand/s3c2410.c15
-rw-r--r--drivers/mtd/nand/sm_common.c2
-rw-r--r--drivers/mtd/nand/socrates_nand.c4
-rw-r--r--drivers/mtd/nftlcore.c25
-rw-r--r--drivers/mtd/nftlmount.c3
-rw-r--r--drivers/mtd/ofpart.c4
-rw-r--r--drivers/mtd/onenand/Kconfig4
-rw-r--r--drivers/mtd/onenand/onenand_base.c49
-rw-r--r--drivers/mtd/onenand/onenand_bbt.c1
-rw-r--r--drivers/mtd/onenand/samsung.c21
-rw-r--r--drivers/mtd/redboot.c18
-rw-r--r--drivers/mtd/rfd_ftl.c2
-rw-r--r--drivers/mtd/ssfdc.c2
-rw-r--r--drivers/mtd/tests/mtd_pagetest.c9
-rw-r--r--drivers/net/arm/ixp4xx_eth.c2
-rw-r--r--drivers/net/caif/caif_spi_slave.c4
-rw-r--r--drivers/net/can/mscan/mpc5xxx_can.c18
-rw-r--r--drivers/net/can/sja1000/sja1000_of_platform.c4
-rw-r--r--drivers/net/cxgb3/cxgb3_main.c25
-rw-r--r--drivers/net/cxgb4vf/cxgb4vf_main.c31
-rw-r--r--drivers/net/davinci_emac.c2
-rw-r--r--drivers/net/e100.c2
-rw-r--r--drivers/net/e1000/e1000_main.c3
-rw-r--r--drivers/net/e1000e/netdev.c4
-rw-r--r--drivers/net/ehea/ehea.h4
-rw-r--r--drivers/net/ehea/ehea_main.c12
-rw-r--r--drivers/net/enic/enic_main.c17
-rw-r--r--drivers/net/fec_mpc52xx.c8
-rw-r--r--drivers/net/fec_mpc52xx_phy.c4
-rw-r--r--drivers/net/fs_enet/fs_enet-main.c4
-rw-r--r--drivers/net/fs_enet/mac-fcc.c2
-rw-r--r--drivers/net/fs_enet/mac-fec.c2
-rw-r--r--drivers/net/fs_enet/mac-scc.c2
-rw-r--r--drivers/net/fs_enet/mii-bitbang.c4
-rw-r--r--drivers/net/fs_enet/mii-fec.c4
-rw-r--r--drivers/net/fsl_pq_mdio.c4
-rw-r--r--drivers/net/gianfar.c10
-rw-r--r--drivers/net/gianfar.h2
-rw-r--r--drivers/net/greth.c6
-rw-r--r--drivers/net/greth.h2
-rw-r--r--drivers/net/ibm_newemac/core.c6
-rw-r--r--drivers/net/ibm_newemac/core.h12
-rw-r--r--drivers/net/ibm_newemac/mal.c4
-rw-r--r--drivers/net/ibm_newemac/mal.h2
-rw-r--r--drivers/net/ibm_newemac/rgmii.c18
-rw-r--r--drivers/net/ibm_newemac/rgmii.h16
-rw-r--r--drivers/net/ibm_newemac/tah.c14
-rw-r--r--drivers/net/ibm_newemac/tah.h12
-rw-r--r--drivers/net/ibm_newemac/zmii.c18
-rw-r--r--drivers/net/ibm_newemac/zmii.h16
-rw-r--r--drivers/net/igb/igb_main.c2
-rw-r--r--drivers/net/igbvf/netdev.c2
-rw-r--r--drivers/net/irda/sh_irda.c6
-rw-r--r--drivers/net/ixgb/ixgb_main.c2
-rw-r--r--drivers/net/ixgbe/ixgbe_main.c15
-rw-r--r--drivers/net/ixgbevf/ixgbevf_main.c2
-rw-r--r--drivers/net/ll_temac_main.c8
-rw-r--r--drivers/net/myri10ge/myri10ge.c54
-rw-r--r--drivers/net/myri_sbus.c4
-rw-r--r--drivers/net/myri_sbus.h2
-rw-r--r--drivers/net/netxen/netxen_nic_main.c15
-rw-r--r--drivers/net/niu.c8
-rw-r--r--drivers/net/pcmcia/xirc2ps_cs.c2
-rw-r--r--drivers/net/phy/Kconfig2
-rw-r--r--drivers/net/phy/mdio-gpio.c4
-rw-r--r--drivers/net/phy/phy.c2
-rw-r--r--drivers/net/ppp_async.c6
-rw-r--r--drivers/net/ppp_synctty.c6
-rw-r--r--drivers/net/pppoe.c4
-rw-r--r--drivers/net/qlcnic/qlcnic_main.c72
-rw-r--r--drivers/net/sunbmac.c18
-rw-r--r--drivers/net/sunbmac.h4
-rw-r--r--drivers/net/sunhme.c22
-rw-r--r--drivers/net/sunhme.h2
-rw-r--r--drivers/net/sunlance.c20
-rw-r--r--drivers/net/sunqe.c16
-rw-r--r--drivers/net/sunqe.h4
-rw-r--r--drivers/net/ucc_geth.c8
-rw-r--r--drivers/net/usb/usbnet.c23
-rw-r--r--drivers/net/via-velocity.c4
-rw-r--r--drivers/net/virtio_net.c14
-rw-r--r--drivers/net/wan/farsync.c15
-rw-r--r--drivers/net/wan/ixp4xx_hss.c2
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9002_calib.c43
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9003_calib.c18
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9003_eeprom.c388
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9003_paprd.c17
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9003_phy.c6
-rw-r--r--drivers/net/wireless/ath/ath9k/ath9k.h3
-rw-r--r--drivers/net/wireless/ath/ath9k/calib.c118
-rw-r--r--drivers/net/wireless/ath/ath9k/calib.h8
-rw-r--r--drivers/net/wireless/ath/ath9k/htc.h2
-rw-r--r--drivers/net/wireless/ath/ath9k/htc_drv_main.c10
-rw-r--r--drivers/net/wireless/ath/ath9k/hw.c25
-rw-r--r--drivers/net/wireless/ath/ath9k/hw.h25
-rw-r--r--drivers/net/wireless/ath/ath9k/main.c104
-rw-r--r--drivers/net/wireless/ath/ath9k/recv.c10
-rw-r--r--drivers/net/wireless/ath/ath9k/xmit.c36
-rw-r--r--drivers/net/wireless/ipw2x00/ipw2100.c4
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-1000.c2
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-3945.c18
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-4965.c2
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-5000.c10
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-6000.c16
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn-debugfs.c2
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn-hcmd.c19
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn-lib.c2
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn-rs.c11
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn-tx.c31
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn.c85
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-core.c35
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-core.h14
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-debug.h2
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-devtrace.h2
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-scan.c2
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-sta.c6
-rw-r--r--drivers/net/wireless/iwlwifi/iwl3945-base.c5
-rw-r--r--drivers/net/wireless/libertas/cfg.c217
-rw-r--r--drivers/net/wireless/libertas/dev.h5
-rw-r--r--drivers/net/wireless/libertas/if_sdio.c32
-rw-r--r--drivers/net/wireless/libertas/if_usb.c3
-rw-r--r--drivers/net/wireless/libertas/main.c1
-rw-r--r--drivers/net/wireless/libertas_tf/if_usb.c3
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00pci.c21
-rw-r--r--drivers/net/wireless/rtl818x/rtl8180_dev.c2
-rw-r--r--drivers/net/wireless/wl12xx/wl1271_spi.c3
-rw-r--r--drivers/net/xilinx_emaclite.c6
-rw-r--r--drivers/of/device.c2
-rw-r--r--drivers/parport/parport_serial.c1
-rw-r--r--drivers/parport/parport_sunbpp.c4
-rw-r--r--drivers/pci/intel-iommu.c30
-rw-r--r--drivers/pci/intr_remapping.c20
-rw-r--r--drivers/pcmcia/Kconfig2
-rw-r--r--drivers/pcmcia/Makefile1
-rw-r--r--drivers/pcmcia/electra_cf.c6
-rw-r--r--drivers/pcmcia/m8xx_pcmcia.c4
-rw-r--r--drivers/pcmcia/pxa2xx_balloon3.c158
-rw-r--r--drivers/platform/x86/Kconfig7
-rw-r--r--drivers/platform/x86/Makefile1
-rw-r--r--drivers/platform/x86/ideapad_acpi.c306
-rw-r--r--drivers/power/Kconfig13
-rw-r--r--drivers/power/Makefile2
-rw-r--r--drivers/power/intel_mid_battery.c799
-rw-r--r--drivers/power/olpc_battery.c3
-rw-r--r--drivers/power/s3c_adc_battery.c431
-rw-r--r--drivers/power/wm97xx_battery.c16
-rw-r--r--drivers/regulator/Kconfig34
-rw-r--r--drivers/regulator/Makefile5
-rw-r--r--drivers/regulator/ab8500.c427
-rw-r--r--drivers/regulator/ad5398.c288
-rw-r--r--drivers/regulator/isl6271a-regulator.c236
-rw-r--r--drivers/regulator/lp3971.c10
-rw-r--r--drivers/regulator/max1586.c10
-rw-r--r--drivers/regulator/max8660.c10
-rw-r--r--drivers/regulator/max8998.c635
-rw-r--r--drivers/regulator/tps65023-regulator.c2
-rw-r--r--drivers/regulator/tps6507x-regulator.c1
-rw-r--r--drivers/regulator/tps6586x-regulator.c396
-rw-r--r--drivers/regulator/wm8994-regulator.c5
-rw-r--r--drivers/rtc/Kconfig38
-rw-r--r--drivers/rtc/Makefile3
-rw-r--r--drivers/rtc/rtc-cmos.c6
-rw-r--r--drivers/rtc/rtc-ds3232.c326
-rw-r--r--drivers/rtc/rtc-fm3130.c181
-rw-r--r--drivers/rtc/rtc-imxdi.c519
-rw-r--r--drivers/rtc/rtc-isl12022.c327
-rw-r--r--drivers/rtc/rtc-m41t80.c4
-rw-r--r--drivers/rtc/rtc-m48t59.c5
-rw-r--r--drivers/rtc/rtc-m48t86.c2
-rw-r--r--drivers/rtc/rtc-max6900.c2
-rw-r--r--drivers/rtc/rtc-mpc5121.c4
-rw-r--r--drivers/rtc/rtc-mxc.c6
-rw-r--r--drivers/rtc/rtc-nuc900.c64
-rw-r--r--drivers/rtc/rtc-pcf8563.c8
-rw-r--r--drivers/rtc/rtc-pl031.c1
-rw-r--r--drivers/rtc/rtc-pxa.c42
-rw-r--r--drivers/rtc/rtc-rp5c01.c89
-rw-r--r--drivers/rtc/rtc-s3c.c44
-rw-r--r--drivers/s390/block/dasd.c12
-rw-r--r--drivers/s390/block/dasd_devmap.c44
-rw-r--r--drivers/s390/block/dasd_diag.c6
-rw-r--r--drivers/s390/block/dasd_eckd.c94
-rw-r--r--drivers/s390/block/dasd_eckd.h7
-rw-r--r--drivers/s390/block/dasd_eer.c2
-rw-r--r--drivers/s390/block/dasd_fba.c4
-rw-r--r--drivers/s390/block/dasd_int.h8
-rw-r--r--drivers/s390/block/dcssblk.c5
-rw-r--r--drivers/s390/char/monreader.c2
-rw-r--r--drivers/s390/char/monwriter.c2
-rw-r--r--drivers/s390/char/tape_block.c8
-rw-r--r--drivers/s390/cio/ccwreq.c16
-rw-r--r--drivers/s390/cio/chsc.c48
-rw-r--r--drivers/s390/cio/chsc.h2
-rw-r--r--drivers/s390/cio/device.c47
-rw-r--r--drivers/s390/cio/device_pgid.c3
-rw-r--r--drivers/s390/cio/io_sch.h10
-rw-r--r--drivers/s390/net/claw.c118
-rw-r--r--drivers/s390/net/claw.h4
-rw-r--r--drivers/s390/net/ctcm_fsms.c60
-rw-r--r--drivers/s390/net/ctcm_main.c80
-rw-r--r--drivers/s390/net/ctcm_main.h4
-rw-r--r--drivers/s390/net/ctcm_mpc.c64
-rw-r--r--drivers/s390/net/ctcm_sysfs.c20
-rw-r--r--drivers/s390/net/smsgiucv_app.c7
-rw-r--r--drivers/sbus/char/bbc_envctrl.c6
-rw-r--r--drivers/sbus/char/bbc_i2c.c18
-rw-r--r--drivers/sbus/char/bbc_i2c.h10
-rw-r--r--drivers/sbus/char/display7seg.c4
-rw-r--r--drivers/sbus/char/envctrl.c4
-rw-r--r--drivers/sbus/char/flash.c4
-rw-r--r--drivers/sbus/char/uctrl.c4
-rw-r--r--drivers/scsi/53c700.c3
-rw-r--r--drivers/scsi/Kconfig10
-rw-r--r--drivers/scsi/Makefile1
-rw-r--r--drivers/scsi/NCR5380.c4
-rw-r--r--drivers/scsi/aacraid/rx.c5
-rw-r--r--drivers/scsi/aha1542.c25
-rw-r--r--drivers/scsi/aic94xx/aic94xx_init.c4
-rw-r--r--drivers/scsi/be2iscsi/Kconfig1
-rw-r--r--drivers/scsi/be2iscsi/be_cmds.h147
-rw-r--r--drivers/scsi/be2iscsi/be_iscsi.c76
-rw-r--r--drivers/scsi/be2iscsi/be_iscsi.h2
-rw-r--r--drivers/scsi/be2iscsi/be_main.c311
-rw-r--r--drivers/scsi/be2iscsi/be_main.h7
-rw-r--r--drivers/scsi/be2iscsi/be_mgmt.c71
-rw-r--r--drivers/scsi/bfa/bfa_fcport.c2
-rw-r--r--drivers/scsi/bfa/bfad.c2
-rw-r--r--drivers/scsi/bfa/bfad_im.c4
-rw-r--r--drivers/scsi/bfa/include/protocol/fcp.h4
-rw-r--r--drivers/scsi/bnx2i/Kconfig3
-rw-r--r--drivers/scsi/ch.c89
-rw-r--r--drivers/scsi/dc395x.c2
-rw-r--r--drivers/scsi/fnic/fnic.h2
-rw-r--r--drivers/scsi/g_NCR5380.c47
-rw-r--r--drivers/scsi/g_NCR5380.h6
-rw-r--r--drivers/scsi/gdth.c2
-rw-r--r--drivers/scsi/ibmvscsi/ibmvfc.c380
-rw-r--r--drivers/scsi/ibmvscsi/ibmvfc.h6
-rw-r--r--drivers/scsi/initio.c1
-rw-r--r--drivers/scsi/iscsi_boot_sysfs.c (renamed from drivers/firmware/iscsi_boot_sysfs.c)0
-rw-r--r--drivers/scsi/libfc/fc_fcp.c4
-rw-r--r--drivers/scsi/lpfc/lpfc.h3
-rw-r--r--drivers/scsi/lpfc/lpfc_attr.c69
-rw-r--r--drivers/scsi/lpfc/lpfc_bsg.c9
-rw-r--r--drivers/scsi/lpfc/lpfc_compat.h3
-rw-r--r--drivers/scsi/lpfc/lpfc_els.c76
-rw-r--r--drivers/scsi/lpfc/lpfc_hbadisc.c17
-rw-r--r--drivers/scsi/lpfc/lpfc_hw.h32
-rw-r--r--drivers/scsi/lpfc/lpfc_init.c132
-rw-r--r--drivers/scsi/lpfc/lpfc_mbox.c8
-rw-r--r--drivers/scsi/lpfc/lpfc_scsi.c8
-rw-r--r--drivers/scsi/lpfc/lpfc_sli.c36
-rw-r--r--drivers/scsi/lpfc/lpfc_version.h2
-rw-r--r--drivers/scsi/osd/osd_initiator.c8
-rw-r--r--drivers/scsi/osst.c3
-rw-r--r--drivers/scsi/pm8001/pm8001_hwi.c13
-rw-r--r--drivers/scsi/qla2xxx/qla_os.c4
-rw-r--r--drivers/scsi/qla4xxx/ql4_def.h36
-rw-r--r--drivers/scsi/qla4xxx/ql4_fw.h20
-rw-r--r--drivers/scsi/qla4xxx/ql4_glbl.h2
-rw-r--r--drivers/scsi/qla4xxx/ql4_init.c14
-rw-r--r--drivers/scsi/qla4xxx/ql4_iocb.c2
-rw-r--r--drivers/scsi/qla4xxx/ql4_isr.c3
-rw-r--r--drivers/scsi/qla4xxx/ql4_mbx.c48
-rw-r--r--drivers/scsi/qla4xxx/ql4_nx.c17
-rw-r--r--drivers/scsi/qla4xxx/ql4_os.c315
-rw-r--r--drivers/scsi/qla4xxx/ql4_version.h2
-rw-r--r--drivers/scsi/qlogicpti.c14
-rw-r--r--drivers/scsi/qlogicpti.h2
-rw-r--r--drivers/scsi/scsi_error.c23
-rw-r--r--drivers/scsi/scsi_lib.c20
-rw-r--r--drivers/scsi/scsi_tgt_lib.c1
-rw-r--r--drivers/scsi/scsi_transport_fc.c12
-rw-r--r--drivers/scsi/sd.c138
-rw-r--r--drivers/scsi/sd.h2
-rw-r--r--drivers/scsi/sg.c11
-rw-r--r--drivers/scsi/sr.c25
-rw-r--r--drivers/scsi/sun3_NCR5380.c2
-rw-r--r--drivers/scsi/sun3_scsi.c2
-rw-r--r--drivers/scsi/sun3_scsi_vme.c2
-rw-r--r--drivers/scsi/sun_esp.c44
-rw-r--r--drivers/serial/21285.c10
-rw-r--r--drivers/serial/68328serial.c26
-rw-r--r--drivers/serial/68360serial.c4
-rw-r--r--drivers/serial/8250.c46
-rw-r--r--drivers/serial/8250_early.c57
-rw-r--r--drivers/serial/8250_pci.c13
-rw-r--r--drivers/serial/Kconfig48
-rw-r--r--drivers/serial/Makefile4
-rw-r--r--drivers/serial/altera_uart.c2
-rw-r--r--drivers/serial/apbuart.c2
-rw-r--r--drivers/serial/atmel_serial.c11
-rw-r--r--drivers/serial/bfin_5xx.c7
-rw-r--r--drivers/serial/cpm_uart/cpm_uart_core.c4
-rw-r--r--drivers/serial/crisv10.c23
-rw-r--r--drivers/serial/imx.c10
-rw-r--r--drivers/serial/ioc3_serial.c9
-rw-r--r--drivers/serial/ioc4_serial.c9
-rw-r--r--drivers/serial/max3100.c7
-rw-r--r--drivers/serial/max3107-aava.c344
-rw-r--r--drivers/serial/max3107.c1197
-rw-r--r--drivers/serial/max3107.h441
-rw-r--r--drivers/serial/mcf.c31
-rw-r--r--drivers/serial/mfd.c1498
-rw-r--r--drivers/serial/mpc52xx_uart.c8
-rw-r--r--drivers/serial/mrst_max3110.c844
-rw-r--r--drivers/serial/mrst_max3110.h59
-rw-r--r--drivers/serial/nwpserial.c2
-rw-r--r--drivers/serial/of_serial.c6
-rw-r--r--drivers/serial/s5pv210.c8
-rw-r--r--drivers/serial/samsung.c9
-rw-r--r--drivers/serial/serial_core.c288
-rw-r--r--drivers/serial/sh-sci.c42
-rw-r--r--drivers/serial/sh-sci.h29
-rw-r--r--drivers/serial/sunhv.c4
-rw-r--r--drivers/serial/sunsab.c8
-rw-r--r--drivers/serial/sunsu.c8
-rw-r--r--drivers/serial/sunzilog.c6
-rw-r--r--drivers/serial/timbuart.c6
-rw-r--r--drivers/serial/uartlite.c4
-rw-r--r--drivers/serial/ucc_uart.c4
-rw-r--r--drivers/sh/Makefile5
-rw-r--r--drivers/sh/clk-cpg.c58
-rw-r--r--drivers/spi/amba-pl022.c6
-rw-r--r--drivers/spi/mpc512x_psc_spi.c16
-rw-r--r--drivers/spi/mpc52xx_psc_spi.c4
-rw-r--r--drivers/spi/mpc52xx_spi.c4
-rw-r--r--drivers/spi/omap_spi_100k.c23
-rw-r--r--drivers/spi/spi.c225
-rw-r--r--drivers/spi/spi_bitbang.c9
-rw-r--r--drivers/spi/spi_bitbang_txrx.h16
-rw-r--r--drivers/spi/spi_butterfly.c2
-rw-r--r--drivers/spi/spi_gpio.c109
-rw-r--r--drivers/spi/spi_lm70llp.c2
-rw-r--r--drivers/spi/spi_mpc8xxx.c4
-rw-r--r--drivers/spi/spi_ppc4xx.c6
-rw-r--r--drivers/spi/spi_s3c24xx_gpio.c8
-rw-r--r--drivers/spi/spi_sh_sci.c8
-rw-r--r--drivers/spi/xilinx_spi_of.c6
-rw-r--r--drivers/staging/easycap/easycap.h8
-rw-r--r--drivers/staging/easycap/easycap_ioctl.c52
-rw-r--r--drivers/staging/easycap/easycap_main.c38
-rw-r--r--drivers/staging/hv/blkvsc_drv.c13
-rw-r--r--drivers/staging/lirc/Kconfig29
-rw-r--r--drivers/staging/lirc/Makefile2
-rw-r--r--drivers/staging/lirc/lirc_ene0100.c646
-rw-r--r--drivers/staging/lirc/lirc_it87.c9
-rw-r--r--drivers/staging/lirc/lirc_parallel.c4
-rw-r--r--drivers/staging/lirc/lirc_streamzap.c821
-rw-r--r--drivers/staging/pohmelfs/inode.c18
-rw-r--r--drivers/staging/rtl8187se/r8180_core.c6
-rw-r--r--drivers/staging/rtl8192e/r8192E_core.c6
-rw-r--r--drivers/staging/rtl8192su/r8192U_core.c6
-rw-r--r--drivers/staging/usbip/vhci_hcd.c6
-rw-r--r--drivers/usb/Makefile2
-rw-r--r--drivers/usb/atm/cxacru.c11
-rw-r--r--drivers/usb/atm/speedtch.c10
-rw-r--r--drivers/usb/atm/ueagle-atm.c7
-rw-r--r--drivers/usb/atm/usbatm.c23
-rw-r--r--drivers/usb/atm/usbatm.h22
-rw-r--r--drivers/usb/atm/xusbatm.c10
-rw-r--r--drivers/usb/c67x00/c67x00-hcd.c4
-rw-r--r--drivers/usb/class/cdc-acm.c12
-rw-r--r--drivers/usb/class/usblp.c371
-rw-r--r--drivers/usb/core/devio.c7
-rw-r--r--drivers/usb/core/driver.c11
-rw-r--r--drivers/usb/core/endpoint.c9
-rw-r--r--drivers/usb/core/generic.c4
-rw-r--r--drivers/usb/core/hcd-pci.c202
-rw-r--r--drivers/usb/core/hcd.c79
-rw-r--r--drivers/usb/core/hub.c13
-rw-r--r--drivers/usb/core/inode.c4
-rw-r--r--drivers/usb/core/quirks.c3
-rw-r--r--drivers/usb/core/urb.c50
-rw-r--r--drivers/usb/core/usb.c6
-rw-r--r--drivers/usb/gadget/Kconfig52
-rw-r--r--drivers/usb/gadget/Makefile3
-rw-r--r--drivers/usb/gadget/audio.c4
-rw-r--r--drivers/usb/gadget/cdc2.c4
-rw-r--r--drivers/usb/gadget/composite.c73
-rw-r--r--drivers/usb/gadget/dbgp.c434
-rw-r--r--drivers/usb/gadget/dummy_hcd.c6
-rw-r--r--drivers/usb/gadget/ether.c6
-rw-r--r--drivers/usb/gadget/f_fs.c38
-rw-r--r--drivers/usb/gadget/f_hid.c6
-rw-r--r--drivers/usb/gadget/f_loopback.c4
-rw-r--r--drivers/usb/gadget/f_mass_storage.c125
-rw-r--r--drivers/usb/gadget/f_sourcesink.c2
-rw-r--r--drivers/usb/gadget/file_storage.c104
-rw-r--r--drivers/usb/gadget/fsl_qe_udc.c10
-rw-r--r--drivers/usb/gadget/g_ffs.c176
-rw-r--r--drivers/usb/gadget/gmidi.c2
-rw-r--r--drivers/usb/gadget/hid.c4
-rw-r--r--drivers/usb/gadget/inode.c16
-rw-r--r--drivers/usb/gadget/langwell_udc.c6
-rw-r--r--drivers/usb/gadget/mass_storage.c24
-rw-r--r--drivers/usb/gadget/multi.c262
-rw-r--r--drivers/usb/gadget/printer.c9
-rw-r--r--drivers/usb/gadget/s3c-hsotg.c153
-rw-r--r--drivers/usb/gadget/serial.c4
-rw-r--r--drivers/usb/gadget/storage_common.c105
-rw-r--r--drivers/usb/gadget/u_ether.c15
-rw-r--r--drivers/usb/gadget/u_serial.c1
-rw-r--r--drivers/usb/gadget/webcam.c4
-rw-r--r--drivers/usb/gadget/zero.c2
-rw-r--r--drivers/usb/host/Kconfig11
-rw-r--r--drivers/usb/host/ehci-au1xxx.c2
-rw-r--r--drivers/usb/host/ehci-dbg.c196
-rw-r--r--drivers/usb/host/ehci-fsl.c3
-rw-r--r--drivers/usb/host/ehci-hcd.c49
-rw-r--r--drivers/usb/host/ehci-hub.c25
-rw-r--r--drivers/usb/host/ehci-lpm.c83
-rw-r--r--drivers/usb/host/ehci-omap.c36
-rw-r--r--drivers/usb/host/ehci-pci.c26
-rw-r--r--drivers/usb/host/ehci-ppc-of.c6
-rw-r--r--drivers/usb/host/ehci-q.c3
-rw-r--r--drivers/usb/host/ehci-sched.c182
-rw-r--r--drivers/usb/host/ehci-xilinx-of.c12
-rw-r--r--drivers/usb/host/ehci.h18
-rw-r--r--drivers/usb/host/fhci-hcd.c4
-rw-r--r--drivers/usb/host/hwa-hc.c4
-rw-r--r--drivers/usb/host/imx21-hcd.c2
-rw-r--r--drivers/usb/host/isp1362.h24
-rw-r--r--drivers/usb/host/isp1760-hcd.c3
-rw-r--r--drivers/usb/host/isp1760-if.c4
-rw-r--r--drivers/usb/host/ohci-dbg.c4
-rw-r--r--drivers/usb/host/ohci-hcd.c6
-rw-r--r--drivers/usb/host/ohci-hub.c23
-rw-r--r--drivers/usb/host/ohci-pci.c2
-rw-r--r--drivers/usb/host/ohci-pnx4008.c2
-rw-r--r--drivers/usb/host/ohci-ppc-of.c6
-rw-r--r--drivers/usb/host/ohci-ssb.c52
-rw-r--r--drivers/usb/host/oxu210hp-hcd.c7
-rw-r--r--drivers/usb/host/sl811-hcd.c5
-rw-r--r--drivers/usb/host/uhci-debug.c23
-rw-r--r--drivers/usb/host/uhci-hcd.c87
-rw-r--r--drivers/usb/host/uhci-hcd.h7
-rw-r--r--drivers/usb/host/uhci-hub.c6
-rw-r--r--drivers/usb/host/uhci-q.c4
-rw-r--r--drivers/usb/host/whci/hcd.c2
-rw-r--r--drivers/usb/host/whci/qset.c2
-rw-r--r--drivers/usb/host/xhci-mem.c101
-rw-r--r--drivers/usb/host/xhci-pci.c9
-rw-r--r--drivers/usb/host/xhci-ring.c1332
-rw-r--r--drivers/usb/host/xhci.c344
-rw-r--r--drivers/usb/host/xhci.h30
-rw-r--r--drivers/usb/misc/ftdi-elan.c4
-rw-r--r--drivers/usb/misc/iowarrior.c23
-rw-r--r--drivers/usb/misc/legousbtower.c6
-rw-r--r--drivers/usb/misc/rio500.c15
-rw-r--r--drivers/usb/misc/sisusbvga/sisusb.c10
-rw-r--r--drivers/usb/misc/usblcd.c24
-rw-r--r--drivers/usb/misc/usbtest.c14
-rw-r--r--drivers/usb/mon/mon_bin.c24
-rw-r--r--drivers/usb/musb/musb_core.c7
-rw-r--r--drivers/usb/musb/musb_debugfs.c32
-rw-r--r--drivers/usb/musb/musb_gadget_ep0.c3
-rw-r--r--drivers/usb/musb/musb_virthub.c2
-rw-r--r--drivers/usb/musb/musbhsdma.c5
-rw-r--r--drivers/usb/musb/omap2430.c6
-rw-r--r--drivers/usb/otg/Kconfig2
-rw-r--r--drivers/usb/otg/ulpi.c134
-rw-r--r--drivers/usb/serial/Kconfig9
-rw-r--r--drivers/usb/serial/Makefile1
-rw-r--r--drivers/usb/serial/cp210x.c4
-rw-r--r--drivers/usb/serial/digi_acceleport.c14
-rw-r--r--drivers/usb/serial/ftdi_sio.c4
-rw-r--r--drivers/usb/serial/ftdi_sio_ids.h10
-rw-r--r--drivers/usb/serial/generic.c15
-rw-r--r--drivers/usb/serial/io_ti.c4
-rw-r--r--drivers/usb/serial/ipaq.c1
-rw-r--r--drivers/usb/serial/iuu_phoenix.c54
-rw-r--r--drivers/usb/serial/option.c17
-rw-r--r--drivers/usb/serial/ssu100.c698
-rw-r--r--drivers/usb/serial/usb-serial.c32
-rw-r--r--drivers/usb/storage/freecom.c23
-rw-r--r--drivers/usb/storage/isd200.c3
-rw-r--r--drivers/usb/storage/usb.c4
-rw-r--r--drivers/usb/usb-skeleton.c8
-rw-r--r--drivers/video/Kconfig19
-rw-r--r--drivers/video/Makefile2
-rw-r--r--drivers/video/bw2.c4
-rw-r--r--drivers/video/cg14.c6
-rw-r--r--drivers/video/cg3.c4
-rw-r--r--drivers/video/cg6.c6
-rw-r--r--drivers/video/console/Kconfig2
-rw-r--r--drivers/video/console/bitblit.c2
-rw-r--r--drivers/video/console/fbcon.c6
-rw-r--r--drivers/video/console/fbcon_ccw.c2
-rw-r--r--drivers/video/console/fbcon_cw.c2
-rw-r--r--drivers/video/console/fbcon_ud.c2
-rw-r--r--drivers/video/console/vgacon.c2
-rw-r--r--drivers/video/efifb.c8
-rw-r--r--drivers/video/fbmem.c6
-rw-r--r--drivers/video/ffb.c4
-rw-r--r--drivers/video/fsl-diu-fb.c8
-rw-r--r--drivers/video/igafb.c5
-rw-r--r--drivers/video/imxfb.c19
-rw-r--r--drivers/video/leo.c6
-rw-r--r--drivers/video/matrox/i2c-matroxfb.c2
-rw-r--r--drivers/video/mb862xx/mb862xxfb.c4
-rw-r--r--drivers/video/msm/mddi.c4
-rw-r--r--drivers/video/msm/mdp.c1
-rw-r--r--drivers/video/omap/lcd_apollon.c3
-rw-r--r--drivers/video/omap2/displays/panel-taal.c567
-rw-r--r--drivers/video/omap2/displays/panel-toppoly-tdo35s.c8
-rw-r--r--drivers/video/omap2/dss/dispc.c16
-rw-r--r--drivers/video/omap2/dss/display.c4
-rw-r--r--drivers/video/omap2/dss/dsi.c463
-rw-r--r--drivers/video/omap2/dss/dss.c6
-rw-r--r--drivers/video/omap2/dss/dss.h11
-rw-r--r--drivers/video/omap2/dss/manager.c204
-rw-r--r--drivers/video/omap2/dss/overlay.c2
-rw-r--r--drivers/video/omap2/dss/rfbi.c2
-rw-r--r--drivers/video/omap2/omapfb/omapfb-ioctl.c188
-rw-r--r--drivers/video/omap2/omapfb/omapfb-main.c229
-rw-r--r--drivers/video/omap2/omapfb/omapfb-sysfs.c70
-rw-r--r--drivers/video/omap2/omapfb/omapfb.h29
-rw-r--r--drivers/video/p9100.c4
-rw-r--r--drivers/video/platinumfb.c4
-rw-r--r--drivers/video/s3c-fb.c811
-rw-r--r--drivers/video/sh_mipi_dsi.c505
-rw-r--r--drivers/video/sh_mobile_hdmi.c1028
-rw-r--r--drivers/video/sh_mobile_lcdcfb.c196
-rw-r--r--drivers/video/sunxvr1000.c4
-rw-r--r--drivers/video/tcx.c6
-rw-r--r--drivers/video/uvesafb.c7
-rw-r--r--drivers/video/via/chip.h1
-rw-r--r--drivers/video/via/hw.c587
-rw-r--r--drivers/video/via/hw.h14
-rw-r--r--drivers/video/via/ioctl.h3
-rw-r--r--drivers/video/via/lcd.c117
-rw-r--r--drivers/video/via/lcd.h5
-rw-r--r--drivers/video/via/share.h309
-rw-r--r--drivers/video/via/via-core.c22
-rw-r--r--drivers/video/via/via-gpio.c2
-rw-r--r--drivers/video/via/viafbdev.c284
-rw-r--r--drivers/video/vt8623fb.c2
-rw-r--r--drivers/video/w100fb.c4
-rw-r--r--drivers/video/xilinxfb.c4
-rw-r--r--drivers/watchdog/Kconfig37
-rw-r--r--drivers/watchdog/Makefile2
-rw-r--r--drivers/watchdog/cpwd.c4
-rw-r--r--drivers/watchdog/f71808e_wdt.c768
-rw-r--r--drivers/watchdog/gef_wdt.c2
-rw-r--r--drivers/watchdog/hpwdt.c310
-rw-r--r--drivers/watchdog/mpc8xxx_wdt.c4
-rw-r--r--drivers/watchdog/riowd.c4
-rw-r--r--drivers/watchdog/s3c2410_wdt.c17
-rw-r--r--drivers/watchdog/sch311x_wdt.c4
-rw-r--r--drivers/watchdog/sp805_wdt.c387
-rw-r--r--drivers/watchdog/wdt_pci.c15
-rw-r--r--drivers/xen/Kconfig5
-rw-r--r--drivers/xen/Makefile1
-rw-r--r--drivers/xen/balloon.c15
-rw-r--r--drivers/xen/swiotlb-xen.c515
-rw-r--r--drivers/xen/xenbus/xenbus_client.c90
-rw-r--r--drivers/zorro/proc.c17
1194 files changed, 64897 insertions, 22433 deletions
diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig
index 08e0140920e1..b811f2173f6f 100644
--- a/drivers/acpi/Kconfig
+++ b/drivers/acpi/Kconfig
@@ -54,17 +54,10 @@ config ACPI_PROCFS
54 they have been replaced by functions in /sys. 54 they have been replaced by functions in /sys.
55 The deprecated files (and their replacements) include: 55 The deprecated files (and their replacements) include:
56 56
57 /proc/acpi/sleep (/sys/power/state)
58 /proc/acpi/info (/sys/module/acpi/parameters/acpica_version)
59 /proc/acpi/dsdt (/sys/firmware/acpi/tables/DSDT)
60 /proc/acpi/fadt (/sys/firmware/acpi/tables/FACP)
61 /proc/acpi/debug_layer (/sys/module/acpi/parameters/debug_layer)
62 /proc/acpi/debug_level (/sys/module/acpi/parameters/debug_level)
63 /proc/acpi/processor/*/power (/sys/devices/system/cpu/*/cpuidle/*)
64 /proc/acpi/processor/*/performance (/sys/devices/system/cpu/*/
65 cpufreq/*)
66 /proc/acpi/processor/*/throttling (/sys/class/thermal/ 57 /proc/acpi/processor/*/throttling (/sys/class/thermal/
67 cooling_device*/*) 58 cooling_device*/*)
59 /proc/acpi/video/*/brightness (/sys/class/backlight/)
60 /proc/acpi/thermal_zone/*/* (/sys/class/thermal/)
68 This option has no effect on /proc/acpi/ files 61 This option has no effect on /proc/acpi/ files
69 and functions which do not yet exist in /sys. 62 and functions which do not yet exist in /sys.
70 63
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index 833b582d1762..3d031d02e54b 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -37,8 +37,9 @@ acpi-y += ec.o
37acpi-$(CONFIG_ACPI_DOCK) += dock.o 37acpi-$(CONFIG_ACPI_DOCK) += dock.o
38acpi-y += pci_root.o pci_link.o pci_irq.o pci_bind.o 38acpi-y += pci_root.o pci_link.o pci_irq.o pci_bind.o
39acpi-y += power.o 39acpi-y += power.o
40acpi-y += system.o event.o 40acpi-y += event.o
41acpi-$(CONFIG_ACPI_DEBUG) += debug.o 41acpi-y += sysfs.o
42acpi-$(CONFIG_DEBUG_FS) += debugfs.o
42acpi-$(CONFIG_ACPI_NUMA) += numa.o 43acpi-$(CONFIG_ACPI_NUMA) += numa.o
43acpi-$(CONFIG_ACPI_PROCFS_POWER) += cm_sbs.o 44acpi-$(CONFIG_ACPI_PROCFS_POWER) += cm_sbs.o
44ifdef CONFIG_ACPI_VIDEO 45ifdef CONFIG_ACPI_VIDEO
diff --git a/drivers/acpi/acpica/acevents.h b/drivers/acpi/acpica/acevents.h
index e0e6affb0d80..36867cd70eac 100644
--- a/drivers/acpi/acpica/acevents.h
+++ b/drivers/acpi/acpica/acevents.h
@@ -82,6 +82,10 @@ acpi_ev_update_gpe_enable_mask(struct acpi_gpe_event_info *gpe_event_info);
82 82
83acpi_status acpi_ev_enable_gpe(struct acpi_gpe_event_info *gpe_event_info); 83acpi_status acpi_ev_enable_gpe(struct acpi_gpe_event_info *gpe_event_info);
84 84
85acpi_status acpi_raw_enable_gpe(struct acpi_gpe_event_info *gpe_event_info);
86
87acpi_status acpi_raw_disable_gpe(struct acpi_gpe_event_info *gpe_event_info);
88
85struct acpi_gpe_event_info *acpi_ev_get_gpe_event_info(acpi_handle gpe_device, 89struct acpi_gpe_event_info *acpi_ev_get_gpe_event_info(acpi_handle gpe_device,
86 u32 gpe_number); 90 u32 gpe_number);
87 91
diff --git a/drivers/acpi/acpica/acglobal.h b/drivers/acpi/acpica/acglobal.h
index 18e796fe4295..1d192142c691 100644
--- a/drivers/acpi/acpica/acglobal.h
+++ b/drivers/acpi/acpica/acglobal.h
@@ -108,7 +108,7 @@ u8 ACPI_INIT_GLOBAL(acpi_gbl_use_default_register_widths, TRUE);
108/* 108/*
109 * Optionally enable output from the AML Debug Object. 109 * Optionally enable output from the AML Debug Object.
110 */ 110 */
111u8 ACPI_INIT_GLOBAL(acpi_gbl_enable_aml_debug_object, FALSE); 111u32 ACPI_INIT_GLOBAL(acpi_gbl_enable_aml_debug_object, FALSE);
112 112
113/* 113/*
114 * Optionally copy the entire DSDT to local memory (instead of simply 114 * Optionally copy the entire DSDT to local memory (instead of simply
diff --git a/drivers/acpi/acpica/aclocal.h b/drivers/acpi/acpica/aclocal.h
index 1ee0bcf399aa..df85b53a674f 100644
--- a/drivers/acpi/acpica/aclocal.h
+++ b/drivers/acpi/acpica/aclocal.h
@@ -412,6 +412,7 @@ struct acpi_handler_info {
412 acpi_event_handler address; /* Address of handler, if any */ 412 acpi_event_handler address; /* Address of handler, if any */
413 void *context; /* Context to be passed to handler */ 413 void *context; /* Context to be passed to handler */
414 struct acpi_namespace_node *method_node; /* Method node for this GPE level (saved) */ 414 struct acpi_namespace_node *method_node; /* Method node for this GPE level (saved) */
415 u8 orig_flags; /* Original misc info about this GPE */
415}; 416};
416 417
417union acpi_gpe_dispatch_info { 418union acpi_gpe_dispatch_info {
diff --git a/drivers/acpi/acpica/evgpe.c b/drivers/acpi/acpica/evgpe.c
index 7a6a3e6f4be0..f226eac314db 100644
--- a/drivers/acpi/acpica/evgpe.c
+++ b/drivers/acpi/acpica/evgpe.c
@@ -137,6 +137,79 @@ acpi_ev_enable_gpe(struct acpi_gpe_event_info *gpe_event_info)
137 137
138/******************************************************************************* 138/*******************************************************************************
139 * 139 *
140 * FUNCTION: acpi_raw_enable_gpe
141 *
142 * PARAMETERS: gpe_event_info - GPE to enable
143 *
144 * RETURN: Status
145 *
146 * DESCRIPTION: Add a reference to a GPE. On the first reference, the GPE is
147 * hardware-enabled.
148 *
149 ******************************************************************************/
150
151acpi_status acpi_raw_enable_gpe(struct acpi_gpe_event_info *gpe_event_info)
152{
153 acpi_status status = AE_OK;
154
155 if (gpe_event_info->runtime_count == ACPI_UINT8_MAX) {
156 return_ACPI_STATUS(AE_LIMIT);
157 }
158
159 gpe_event_info->runtime_count++;
160 if (gpe_event_info->runtime_count == 1) {
161 status = acpi_ev_update_gpe_enable_mask(gpe_event_info);
162 if (ACPI_SUCCESS(status)) {
163 status = acpi_ev_enable_gpe(gpe_event_info);
164 }
165
166 if (ACPI_FAILURE(status)) {
167 gpe_event_info->runtime_count--;
168 }
169 }
170
171 return_ACPI_STATUS(status);
172}
173
174/*******************************************************************************
175 *
176 * FUNCTION: acpi_raw_disable_gpe
177 *
178 * PARAMETERS: gpe_event_info - GPE to disable
179 *
180 * RETURN: Status
181 *
182 * DESCRIPTION: Remove a reference to a GPE. When the last reference is
183 * removed, the GPE is hardware-disabled.
184 *
185 ******************************************************************************/
186
187acpi_status acpi_raw_disable_gpe(struct acpi_gpe_event_info *gpe_event_info)
188{
189 acpi_status status = AE_OK;
190
191 if (!gpe_event_info->runtime_count) {
192 return_ACPI_STATUS(AE_LIMIT);
193 }
194
195 gpe_event_info->runtime_count--;
196 if (!gpe_event_info->runtime_count) {
197 status = acpi_ev_update_gpe_enable_mask(gpe_event_info);
198 if (ACPI_SUCCESS(status)) {
199 status = acpi_hw_low_set_gpe(gpe_event_info,
200 ACPI_GPE_DISABLE);
201 }
202
203 if (ACPI_FAILURE(status)) {
204 gpe_event_info->runtime_count++;
205 }
206 }
207
208 return_ACPI_STATUS(status);
209}
210
211/*******************************************************************************
212 *
140 * FUNCTION: acpi_ev_low_get_gpe_info 213 * FUNCTION: acpi_ev_low_get_gpe_info
141 * 214 *
142 * PARAMETERS: gpe_number - Raw GPE number 215 * PARAMETERS: gpe_number - Raw GPE number
diff --git a/drivers/acpi/acpica/evxface.c b/drivers/acpi/acpica/evxface.c
index 4a531cdf7942..14e48add32fa 100644
--- a/drivers/acpi/acpica/evxface.c
+++ b/drivers/acpi/acpica/evxface.c
@@ -691,12 +691,22 @@ acpi_install_gpe_handler(acpi_handle gpe_device,
691 return_ACPI_STATUS(status); 691 return_ACPI_STATUS(status);
692 } 692 }
693 693
694 /* Allocate memory for the handler object */
695
696 handler = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_handler_info));
697 if (!handler) {
698 status = AE_NO_MEMORY;
699 goto unlock_and_exit;
700 }
701
702 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
703
694 /* Ensure that we have a valid GPE number */ 704 /* Ensure that we have a valid GPE number */
695 705
696 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number); 706 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
697 if (!gpe_event_info) { 707 if (!gpe_event_info) {
698 status = AE_BAD_PARAMETER; 708 status = AE_BAD_PARAMETER;
699 goto unlock_and_exit; 709 goto free_and_exit;
700 } 710 }
701 711
702 /* Make sure that there isn't a handler there already */ 712 /* Make sure that there isn't a handler there already */
@@ -704,24 +714,30 @@ acpi_install_gpe_handler(acpi_handle gpe_device,
704 if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) == 714 if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) ==
705 ACPI_GPE_DISPATCH_HANDLER) { 715 ACPI_GPE_DISPATCH_HANDLER) {
706 status = AE_ALREADY_EXISTS; 716 status = AE_ALREADY_EXISTS;
707 goto unlock_and_exit; 717 goto free_and_exit;
708 } 718 }
709 719
710 /* Allocate and init handler object */ 720 /* Allocate and init handler object */
711 721
712 handler = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_handler_info));
713 if (!handler) {
714 status = AE_NO_MEMORY;
715 goto unlock_and_exit;
716 }
717
718 handler->address = address; 722 handler->address = address;
719 handler->context = context; 723 handler->context = context;
720 handler->method_node = gpe_event_info->dispatch.method_node; 724 handler->method_node = gpe_event_info->dispatch.method_node;
725 handler->orig_flags = gpe_event_info->flags &
726 (ACPI_GPE_XRUPT_TYPE_MASK | ACPI_GPE_DISPATCH_MASK);
727
728 /*
729 * If the GPE is associated with a method and it cannot wake up the
730 * system from sleep states, it was enabled automatically during
731 * initialization, so it has to be disabled now to avoid spurious
732 * execution of the handler.
733 */
734
735 if ((handler->orig_flags & ACPI_GPE_DISPATCH_METHOD)
736 && !(gpe_event_info->flags & ACPI_GPE_CAN_WAKE))
737 (void)acpi_raw_disable_gpe(gpe_event_info);
721 738
722 /* Install the handler */ 739 /* Install the handler */
723 740
724 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
725 gpe_event_info->dispatch.handler = handler; 741 gpe_event_info->dispatch.handler = handler;
726 742
727 /* Setup up dispatch flags to indicate handler (vs. method) */ 743 /* Setup up dispatch flags to indicate handler (vs. method) */
@@ -735,6 +751,11 @@ acpi_install_gpe_handler(acpi_handle gpe_device,
735unlock_and_exit: 751unlock_and_exit:
736 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); 752 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
737 return_ACPI_STATUS(status); 753 return_ACPI_STATUS(status);
754
755free_and_exit:
756 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
757 ACPI_FREE(handler);
758 goto unlock_and_exit;
738} 759}
739 760
740ACPI_EXPORT_SYMBOL(acpi_install_gpe_handler) 761ACPI_EXPORT_SYMBOL(acpi_install_gpe_handler)
@@ -770,11 +791,17 @@ acpi_remove_gpe_handler(acpi_handle gpe_device,
770 return_ACPI_STATUS(AE_BAD_PARAMETER); 791 return_ACPI_STATUS(AE_BAD_PARAMETER);
771 } 792 }
772 793
794 /* Make sure all deferred tasks are completed */
795
796 acpi_os_wait_events_complete(NULL);
797
773 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS); 798 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
774 if (ACPI_FAILURE(status)) { 799 if (ACPI_FAILURE(status)) {
775 return_ACPI_STATUS(status); 800 return_ACPI_STATUS(status);
776 } 801 }
777 802
803 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
804
778 /* Ensure that we have a valid GPE number */ 805 /* Ensure that we have a valid GPE number */
779 806
780 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number); 807 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
@@ -798,34 +825,34 @@ acpi_remove_gpe_handler(acpi_handle gpe_device,
798 goto unlock_and_exit; 825 goto unlock_and_exit;
799 } 826 }
800 827
801 /* Make sure all deferred tasks are completed */
802
803 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
804 acpi_os_wait_events_complete(NULL);
805 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
806 if (ACPI_FAILURE(status)) {
807 return_ACPI_STATUS(status);
808 }
809
810 /* Remove the handler */ 828 /* Remove the handler */
811 829
812 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
813 handler = gpe_event_info->dispatch.handler; 830 handler = gpe_event_info->dispatch.handler;
814 831
815 /* Restore Method node (if any), set dispatch flags */ 832 /* Restore Method node (if any), set dispatch flags */
816 833
817 gpe_event_info->dispatch.method_node = handler->method_node; 834 gpe_event_info->dispatch.method_node = handler->method_node;
818 gpe_event_info->flags &= ~ACPI_GPE_DISPATCH_MASK; /* Clear bits */ 835 gpe_event_info->flags &=
819 if (handler->method_node) { 836 ~(ACPI_GPE_XRUPT_TYPE_MASK | ACPI_GPE_DISPATCH_MASK);
820 gpe_event_info->flags |= ACPI_GPE_DISPATCH_METHOD; 837 gpe_event_info->flags |= handler->orig_flags;
821 } 838
822 acpi_os_release_lock(acpi_gbl_gpe_lock, flags); 839 /*
840 * If the GPE was previously associated with a method and it cannot wake
841 * up the system from sleep states, it should be enabled at this point
842 * to restore the post-initialization configuration.
843 */
844
845 if ((handler->orig_flags & ACPI_GPE_DISPATCH_METHOD)
846 && !(gpe_event_info->flags & ACPI_GPE_CAN_WAKE))
847 (void)acpi_raw_enable_gpe(gpe_event_info);
823 848
824 /* Now we can free the handler object */ 849 /* Now we can free the handler object */
825 850
826 ACPI_FREE(handler); 851 ACPI_FREE(handler);
827 852
828 unlock_and_exit: 853unlock_and_exit:
854 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
855
829 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); 856 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
830 return_ACPI_STATUS(status); 857 return_ACPI_STATUS(status);
831} 858}
diff --git a/drivers/acpi/acpica/evxfevnt.c b/drivers/acpi/acpica/evxfevnt.c
index 0ec900da5794..304825528d48 100644
--- a/drivers/acpi/acpica/evxfevnt.c
+++ b/drivers/acpi/acpica/evxfevnt.c
@@ -294,7 +294,7 @@ ACPI_EXPORT_SYMBOL(acpi_gpe_wakeup)
294 ******************************************************************************/ 294 ******************************************************************************/
295acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number) 295acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number)
296{ 296{
297 acpi_status status = AE_OK; 297 acpi_status status = AE_BAD_PARAMETER;
298 struct acpi_gpe_event_info *gpe_event_info; 298 struct acpi_gpe_event_info *gpe_event_info;
299 acpi_cpu_flags flags; 299 acpi_cpu_flags flags;
300 300
@@ -305,28 +305,10 @@ acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number)
305 /* Ensure that we have a valid GPE number */ 305 /* Ensure that we have a valid GPE number */
306 306
307 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number); 307 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
308 if (!gpe_event_info) { 308 if (gpe_event_info) {
309 status = AE_BAD_PARAMETER; 309 status = acpi_raw_enable_gpe(gpe_event_info);
310 goto unlock_and_exit;
311 } 310 }
312 311
313 if (gpe_event_info->runtime_count == ACPI_UINT8_MAX) {
314 status = AE_LIMIT; /* Too many references */
315 goto unlock_and_exit;
316 }
317
318 gpe_event_info->runtime_count++;
319 if (gpe_event_info->runtime_count == 1) {
320 status = acpi_ev_update_gpe_enable_mask(gpe_event_info);
321 if (ACPI_SUCCESS(status)) {
322 status = acpi_ev_enable_gpe(gpe_event_info);
323 }
324 if (ACPI_FAILURE(status)) {
325 gpe_event_info->runtime_count--;
326 }
327 }
328
329unlock_and_exit:
330 acpi_os_release_lock(acpi_gbl_gpe_lock, flags); 312 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
331 return_ACPI_STATUS(status); 313 return_ACPI_STATUS(status);
332} 314}
@@ -348,7 +330,7 @@ ACPI_EXPORT_SYMBOL(acpi_enable_gpe)
348 ******************************************************************************/ 330 ******************************************************************************/
349acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number) 331acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number)
350{ 332{
351 acpi_status status = AE_OK; 333 acpi_status status = AE_BAD_PARAMETER;
352 struct acpi_gpe_event_info *gpe_event_info; 334 struct acpi_gpe_event_info *gpe_event_info;
353 acpi_cpu_flags flags; 335 acpi_cpu_flags flags;
354 336
@@ -359,32 +341,10 @@ acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number)
359 /* Ensure that we have a valid GPE number */ 341 /* Ensure that we have a valid GPE number */
360 342
361 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number); 343 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
362 if (!gpe_event_info) { 344 if (gpe_event_info) {
363 status = AE_BAD_PARAMETER; 345 status = acpi_raw_disable_gpe(gpe_event_info) ;
364 goto unlock_and_exit;
365 }
366
367 /* Hardware-disable a runtime GPE on removal of the last reference */
368
369 if (!gpe_event_info->runtime_count) {
370 status = AE_LIMIT; /* There are no references to remove */
371 goto unlock_and_exit;
372 } 346 }
373 347
374 gpe_event_info->runtime_count--;
375 if (!gpe_event_info->runtime_count) {
376 status = acpi_ev_update_gpe_enable_mask(gpe_event_info);
377 if (ACPI_SUCCESS(status)) {
378 status =
379 acpi_hw_low_set_gpe(gpe_event_info,
380 ACPI_GPE_DISABLE);
381 }
382 if (ACPI_FAILURE(status)) {
383 gpe_event_info->runtime_count++;
384 }
385 }
386
387unlock_and_exit:
388 acpi_os_release_lock(acpi_gbl_gpe_lock, flags); 348 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
389 return_ACPI_STATUS(status); 349 return_ACPI_STATUS(status);
390} 350}
@@ -411,7 +371,6 @@ acpi_status acpi_gpe_can_wake(acpi_handle gpe_device, u32 gpe_number)
411 acpi_status status = AE_OK; 371 acpi_status status = AE_OK;
412 struct acpi_gpe_event_info *gpe_event_info; 372 struct acpi_gpe_event_info *gpe_event_info;
413 acpi_cpu_flags flags; 373 acpi_cpu_flags flags;
414 u8 disable = 0;
415 374
416 ACPI_FUNCTION_TRACE(acpi_gpe_can_wake); 375 ACPI_FUNCTION_TRACE(acpi_gpe_can_wake);
417 376
@@ -430,15 +389,12 @@ acpi_status acpi_gpe_can_wake(acpi_handle gpe_device, u32 gpe_number)
430 } 389 }
431 390
432 gpe_event_info->flags |= ACPI_GPE_CAN_WAKE; 391 gpe_event_info->flags |= ACPI_GPE_CAN_WAKE;
433 disable = (gpe_event_info->flags & ACPI_GPE_DISPATCH_METHOD) 392 if (gpe_event_info->flags & ACPI_GPE_DISPATCH_METHOD) {
434 && gpe_event_info->runtime_count; 393 (void)acpi_raw_disable_gpe(gpe_event_info);
394 }
435 395
436unlock_and_exit: 396unlock_and_exit:
437 acpi_os_release_lock(acpi_gbl_gpe_lock, flags); 397 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
438
439 if (disable)
440 status = acpi_disable_gpe(gpe_device, gpe_number);
441
442 return_ACPI_STATUS(status); 398 return_ACPI_STATUS(status);
443} 399}
444ACPI_EXPORT_SYMBOL(acpi_gpe_can_wake) 400ACPI_EXPORT_SYMBOL(acpi_gpe_can_wake)
diff --git a/drivers/acpi/acpica/utmutex.c b/drivers/acpi/acpica/utmutex.c
index 058b3df48271..f5cca3a1300c 100644
--- a/drivers/acpi/acpica/utmutex.c
+++ b/drivers/acpi/acpica/utmutex.c
@@ -279,13 +279,10 @@ acpi_status acpi_ut_acquire_mutex(acpi_mutex_handle mutex_id)
279 279
280acpi_status acpi_ut_release_mutex(acpi_mutex_handle mutex_id) 280acpi_status acpi_ut_release_mutex(acpi_mutex_handle mutex_id)
281{ 281{
282 acpi_thread_id this_thread_id;
283
284 ACPI_FUNCTION_NAME(ut_release_mutex); 282 ACPI_FUNCTION_NAME(ut_release_mutex);
285 283
286 this_thread_id = acpi_os_get_thread_id();
287 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Thread %p releasing Mutex [%s]\n", 284 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Thread %p releasing Mutex [%s]\n",
288 ACPI_CAST_PTR(void, this_thread_id), 285 ACPI_CAST_PTR(void, acpi_os_get_thread_id()),
289 acpi_ut_get_mutex_name(mutex_id))); 286 acpi_ut_get_mutex_name(mutex_id)));
290 287
291 if (mutex_id > ACPI_MAX_MUTEX) { 288 if (mutex_id > ACPI_MAX_MUTEX) {
diff --git a/drivers/acpi/apei/Kconfig b/drivers/acpi/apei/Kconfig
index f8c668f27b5a..907e350f1c7d 100644
--- a/drivers/acpi/apei/Kconfig
+++ b/drivers/acpi/apei/Kconfig
@@ -28,3 +28,12 @@ config ACPI_APEI_EINJ
28 EINJ provides a hardware error injection mechanism, it is 28 EINJ provides a hardware error injection mechanism, it is
29 mainly used for debugging and testing the other parts of 29 mainly used for debugging and testing the other parts of
30 APEI and some other RAS features. 30 APEI and some other RAS features.
31
32config ACPI_APEI_ERST_DEBUG
33 tristate "APEI Error Record Serialization Table (ERST) Debug Support"
34 depends on ACPI_APEI
35 help
36 ERST is a way provided by APEI to save and retrieve hardware
37 error infomation to and from a persistent store. Enable this
38 if you want to debugging and testing the ERST kernel support
39 and firmware implementation.
diff --git a/drivers/acpi/apei/Makefile b/drivers/acpi/apei/Makefile
index b13b03a17789..d1d1bc0a4ee1 100644
--- a/drivers/acpi/apei/Makefile
+++ b/drivers/acpi/apei/Makefile
@@ -1,5 +1,6 @@
1obj-$(CONFIG_ACPI_APEI) += apei.o 1obj-$(CONFIG_ACPI_APEI) += apei.o
2obj-$(CONFIG_ACPI_APEI_GHES) += ghes.o 2obj-$(CONFIG_ACPI_APEI_GHES) += ghes.o
3obj-$(CONFIG_ACPI_APEI_EINJ) += einj.o 3obj-$(CONFIG_ACPI_APEI_EINJ) += einj.o
4obj-$(CONFIG_ACPI_APEI_ERST_DEBUG) += erst-dbg.o
4 5
5apei-y := apei-base.o hest.o cper.o erst.o 6apei-y := apei-base.o hest.o cper.o erst.o
diff --git a/drivers/acpi/apei/apei-base.c b/drivers/acpi/apei/apei-base.c
index 216e1e948ff6..73fd0c7487c1 100644
--- a/drivers/acpi/apei/apei-base.c
+++ b/drivers/acpi/apei/apei-base.c
@@ -482,14 +482,14 @@ err_unmap_ioport:
482 list_for_each_entry(res, &resources->ioport, list) { 482 list_for_each_entry(res, &resources->ioport, list) {
483 if (res == res_bak) 483 if (res == res_bak)
484 break; 484 break;
485 release_mem_region(res->start, res->end - res->start); 485 release_region(res->start, res->end - res->start);
486 } 486 }
487 res_bak = NULL; 487 res_bak = NULL;
488err_unmap_iomem: 488err_unmap_iomem:
489 list_for_each_entry(res, &resources->iomem, list) { 489 list_for_each_entry(res, &resources->iomem, list) {
490 if (res == res_bak) 490 if (res == res_bak)
491 break; 491 break;
492 release_region(res->start, res->end - res->start); 492 release_mem_region(res->start, res->end - res->start);
493 } 493 }
494 return -EINVAL; 494 return -EINVAL;
495} 495}
diff --git a/drivers/acpi/apei/erst-dbg.c b/drivers/acpi/apei/erst-dbg.c
new file mode 100644
index 000000000000..5281ddda2777
--- /dev/null
+++ b/drivers/acpi/apei/erst-dbg.c
@@ -0,0 +1,207 @@
1/*
2 * APEI Error Record Serialization Table debug support
3 *
4 * ERST is a way provided by APEI to save and retrieve hardware error
5 * infomation to and from a persistent store. This file provide the
6 * debugging/testing support for ERST kernel support and firmware
7 * implementation.
8 *
9 * Copyright 2010 Intel Corp.
10 * Author: Huang Ying <ying.huang@intel.com>
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License version
14 * 2 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 * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */
25
26#include <linux/kernel.h>
27#include <linux/module.h>
28#include <linux/uaccess.h>
29#include <acpi/apei.h>
30#include <linux/miscdevice.h>
31
32#include "apei-internal.h"
33
34#define ERST_DBG_PFX "ERST DBG: "
35
36#define ERST_DBG_RECORD_LEN_MAX 4096
37
38static void *erst_dbg_buf;
39static unsigned int erst_dbg_buf_len;
40
41/* Prevent erst_dbg_read/write from being invoked concurrently */
42static DEFINE_MUTEX(erst_dbg_mutex);
43
44static int erst_dbg_open(struct inode *inode, struct file *file)
45{
46 if (erst_disable)
47 return -ENODEV;
48
49 return nonseekable_open(inode, file);
50}
51
52static long erst_dbg_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
53{
54 int rc;
55 u64 record_id;
56 u32 record_count;
57
58 switch (cmd) {
59 case APEI_ERST_CLEAR_RECORD:
60 rc = copy_from_user(&record_id, (void __user *)arg,
61 sizeof(record_id));
62 if (rc)
63 return -EFAULT;
64 return erst_clear(record_id);
65 case APEI_ERST_GET_RECORD_COUNT:
66 rc = erst_get_record_count();
67 if (rc < 0)
68 return rc;
69 record_count = rc;
70 rc = put_user(record_count, (u32 __user *)arg);
71 if (rc)
72 return rc;
73 return 0;
74 default:
75 return -ENOTTY;
76 }
77}
78
79static ssize_t erst_dbg_read(struct file *filp, char __user *ubuf,
80 size_t usize, loff_t *off)
81{
82 int rc;
83 ssize_t len = 0;
84 u64 id;
85
86 if (*off != 0)
87 return -EINVAL;
88
89 if (mutex_lock_interruptible(&erst_dbg_mutex) != 0)
90 return -EINTR;
91
92retry_next:
93 rc = erst_get_next_record_id(&id);
94 if (rc)
95 goto out;
96 /* no more record */
97 if (id == APEI_ERST_INVALID_RECORD_ID)
98 goto out;
99retry:
100 rc = len = erst_read(id, erst_dbg_buf, erst_dbg_buf_len);
101 /* The record may be cleared by others, try read next record */
102 if (rc == -ENOENT)
103 goto retry_next;
104 if (rc < 0)
105 goto out;
106 if (len > ERST_DBG_RECORD_LEN_MAX) {
107 pr_warning(ERST_DBG_PFX
108 "Record (ID: 0x%llx) length is too long: %zd\n",
109 id, len);
110 rc = -EIO;
111 goto out;
112 }
113 if (len > erst_dbg_buf_len) {
114 kfree(erst_dbg_buf);
115 rc = -ENOMEM;
116 erst_dbg_buf = kmalloc(len, GFP_KERNEL);
117 if (!erst_dbg_buf)
118 goto out;
119 erst_dbg_buf_len = len;
120 goto retry;
121 }
122
123 rc = -EINVAL;
124 if (len > usize)
125 goto out;
126
127 rc = -EFAULT;
128 if (copy_to_user(ubuf, erst_dbg_buf, len))
129 goto out;
130 rc = 0;
131out:
132 mutex_unlock(&erst_dbg_mutex);
133 return rc ? rc : len;
134}
135
136static ssize_t erst_dbg_write(struct file *filp, const char __user *ubuf,
137 size_t usize, loff_t *off)
138{
139 int rc;
140 struct cper_record_header *rcd;
141
142 if (!capable(CAP_SYS_ADMIN))
143 return -EPERM;
144
145 if (usize > ERST_DBG_RECORD_LEN_MAX) {
146 pr_err(ERST_DBG_PFX "Too long record to be written\n");
147 return -EINVAL;
148 }
149
150 if (mutex_lock_interruptible(&erst_dbg_mutex))
151 return -EINTR;
152 if (usize > erst_dbg_buf_len) {
153 kfree(erst_dbg_buf);
154 rc = -ENOMEM;
155 erst_dbg_buf = kmalloc(usize, GFP_KERNEL);
156 if (!erst_dbg_buf)
157 goto out;
158 erst_dbg_buf_len = usize;
159 }
160 rc = copy_from_user(erst_dbg_buf, ubuf, usize);
161 if (rc) {
162 rc = -EFAULT;
163 goto out;
164 }
165 rcd = erst_dbg_buf;
166 rc = -EINVAL;
167 if (rcd->record_length != usize)
168 goto out;
169
170 rc = erst_write(erst_dbg_buf);
171
172out:
173 mutex_unlock(&erst_dbg_mutex);
174 return rc < 0 ? rc : usize;
175}
176
177static const struct file_operations erst_dbg_ops = {
178 .owner = THIS_MODULE,
179 .open = erst_dbg_open,
180 .read = erst_dbg_read,
181 .write = erst_dbg_write,
182 .unlocked_ioctl = erst_dbg_ioctl,
183};
184
185static struct miscdevice erst_dbg_dev = {
186 .minor = MISC_DYNAMIC_MINOR,
187 .name = "erst_dbg",
188 .fops = &erst_dbg_ops,
189};
190
191static __init int erst_dbg_init(void)
192{
193 return misc_register(&erst_dbg_dev);
194}
195
196static __exit void erst_dbg_exit(void)
197{
198 misc_deregister(&erst_dbg_dev);
199 kfree(erst_dbg_buf);
200}
201
202module_init(erst_dbg_init);
203module_exit(erst_dbg_exit);
204
205MODULE_AUTHOR("Huang Ying");
206MODULE_DESCRIPTION("APEI Error Record Serialization Table debug support");
207MODULE_LICENSE("GPL");
diff --git a/drivers/acpi/apei/erst.c b/drivers/acpi/apei/erst.c
index 864dd46c346f..18645f4e83cd 100644
--- a/drivers/acpi/apei/erst.c
+++ b/drivers/acpi/apei/erst.c
@@ -33,6 +33,7 @@
33#include <linux/uaccess.h> 33#include <linux/uaccess.h>
34#include <linux/cper.h> 34#include <linux/cper.h>
35#include <linux/nmi.h> 35#include <linux/nmi.h>
36#include <linux/hardirq.h>
36#include <acpi/apei.h> 37#include <acpi/apei.h>
37 38
38#include "apei-internal.h" 39#include "apei-internal.h"
diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
index fd0cc016a099..385a6059714a 100644
--- a/drivers/acpi/apei/ghes.c
+++ b/drivers/acpi/apei/ghes.c
@@ -41,6 +41,8 @@
41#include <linux/interrupt.h> 41#include <linux/interrupt.h>
42#include <linux/cper.h> 42#include <linux/cper.h>
43#include <linux/kdebug.h> 43#include <linux/kdebug.h>
44#include <linux/platform_device.h>
45#include <linux/mutex.h>
44#include <acpi/apei.h> 46#include <acpi/apei.h>
45#include <acpi/atomicio.h> 47#include <acpi/atomicio.h>
46#include <acpi/hed.h> 48#include <acpi/hed.h>
@@ -87,6 +89,7 @@ struct ghes {
87 * used for that. 89 * used for that.
88 */ 90 */
89static LIST_HEAD(ghes_sci); 91static LIST_HEAD(ghes_sci);
92static DEFINE_MUTEX(ghes_list_mutex);
90 93
91static struct ghes *ghes_new(struct acpi_hest_generic *generic) 94static struct ghes *ghes_new(struct acpi_hest_generic *generic)
92{ 95{
@@ -132,26 +135,26 @@ static void ghes_fini(struct ghes *ghes)
132} 135}
133 136
134enum { 137enum {
135 GHES_SER_NO = 0x0, 138 GHES_SEV_NO = 0x0,
136 GHES_SER_CORRECTED = 0x1, 139 GHES_SEV_CORRECTED = 0x1,
137 GHES_SER_RECOVERABLE = 0x2, 140 GHES_SEV_RECOVERABLE = 0x2,
138 GHES_SER_PANIC = 0x3, 141 GHES_SEV_PANIC = 0x3,
139}; 142};
140 143
141static inline int ghes_severity(int severity) 144static inline int ghes_severity(int severity)
142{ 145{
143 switch (severity) { 146 switch (severity) {
144 case CPER_SER_INFORMATIONAL: 147 case CPER_SEV_INFORMATIONAL:
145 return GHES_SER_NO; 148 return GHES_SEV_NO;
146 case CPER_SER_CORRECTED: 149 case CPER_SEV_CORRECTED:
147 return GHES_SER_CORRECTED; 150 return GHES_SEV_CORRECTED;
148 case CPER_SER_RECOVERABLE: 151 case CPER_SEV_RECOVERABLE:
149 return GHES_SER_RECOVERABLE; 152 return GHES_SEV_RECOVERABLE;
150 case CPER_SER_FATAL: 153 case CPER_SEV_FATAL:
151 return GHES_SER_PANIC; 154 return GHES_SEV_PANIC;
152 default: 155 default:
153 /* Unkown, go panic */ 156 /* Unkown, go panic */
154 return GHES_SER_PANIC; 157 return GHES_SEV_PANIC;
155 } 158 }
156} 159}
157 160
@@ -237,16 +240,16 @@ static void ghes_clear_estatus(struct ghes *ghes)
237 240
238static void ghes_do_proc(struct ghes *ghes) 241static void ghes_do_proc(struct ghes *ghes)
239{ 242{
240 int ser, processed = 0; 243 int sev, processed = 0;
241 struct acpi_hest_generic_data *gdata; 244 struct acpi_hest_generic_data *gdata;
242 245
243 ser = ghes_severity(ghes->estatus->error_severity); 246 sev = ghes_severity(ghes->estatus->error_severity);
244 apei_estatus_for_each_section(ghes->estatus, gdata) { 247 apei_estatus_for_each_section(ghes->estatus, gdata) {
245#ifdef CONFIG_X86_MCE 248#ifdef CONFIG_X86_MCE
246 if (!uuid_le_cmp(*(uuid_le *)gdata->section_type, 249 if (!uuid_le_cmp(*(uuid_le *)gdata->section_type,
247 CPER_SEC_PLATFORM_MEM)) { 250 CPER_SEC_PLATFORM_MEM)) {
248 apei_mce_report_mem_error( 251 apei_mce_report_mem_error(
249 ser == GHES_SER_CORRECTED, 252 sev == GHES_SEV_CORRECTED,
250 (struct cper_sec_mem_err *)(gdata+1)); 253 (struct cper_sec_mem_err *)(gdata+1));
251 processed = 1; 254 processed = 1;
252 } 255 }
@@ -293,18 +296,15 @@ static struct notifier_block ghes_notifier_sci = {
293 .notifier_call = ghes_notify_sci, 296 .notifier_call = ghes_notify_sci,
294}; 297};
295 298
296static int hest_ghes_parse(struct acpi_hest_header *hest_hdr, void *data) 299static int __devinit ghes_probe(struct platform_device *ghes_dev)
297{ 300{
298 struct acpi_hest_generic *generic; 301 struct acpi_hest_generic *generic;
299 struct ghes *ghes = NULL; 302 struct ghes *ghes = NULL;
300 int rc = 0; 303 int rc = -EINVAL;
301 304
302 if (hest_hdr->type != ACPI_HEST_TYPE_GENERIC_ERROR) 305 generic = ghes_dev->dev.platform_data;
303 return 0;
304
305 generic = (struct acpi_hest_generic *)hest_hdr;
306 if (!generic->enabled) 306 if (!generic->enabled)
307 return 0; 307 return -ENODEV;
308 308
309 if (generic->error_block_length < 309 if (generic->error_block_length <
310 sizeof(struct acpi_hest_generic_status)) { 310 sizeof(struct acpi_hest_generic_status)) {
@@ -327,62 +327,91 @@ static int hest_ghes_parse(struct acpi_hest_header *hest_hdr, void *data)
327 ghes = NULL; 327 ghes = NULL;
328 goto err; 328 goto err;
329 } 329 }
330 switch (generic->notify.type) { 330 if (generic->notify.type == ACPI_HEST_NOTIFY_SCI) {
331 case ACPI_HEST_NOTIFY_POLLED: 331 mutex_lock(&ghes_list_mutex);
332 pr_warning(GHES_PFX
333"Generic hardware error source: %d notified via POLL is not supported!\n",
334 generic->header.source_id);
335 break;
336 case ACPI_HEST_NOTIFY_EXTERNAL:
337 case ACPI_HEST_NOTIFY_LOCAL:
338 pr_warning(GHES_PFX
339"Generic hardware error source: %d notified via IRQ is not supported!\n",
340 generic->header.source_id);
341 break;
342 case ACPI_HEST_NOTIFY_SCI:
343 if (list_empty(&ghes_sci)) 332 if (list_empty(&ghes_sci))
344 register_acpi_hed_notifier(&ghes_notifier_sci); 333 register_acpi_hed_notifier(&ghes_notifier_sci);
345 list_add_rcu(&ghes->list, &ghes_sci); 334 list_add_rcu(&ghes->list, &ghes_sci);
346 break; 335 mutex_unlock(&ghes_list_mutex);
347 case ACPI_HEST_NOTIFY_NMI: 336 } else {
348 pr_warning(GHES_PFX 337 unsigned char *notify = NULL;
349"Generic hardware error source: %d notified via NMI is not supported!\n", 338
350 generic->header.source_id); 339 switch (generic->notify.type) {
351 break; 340 case ACPI_HEST_NOTIFY_POLLED:
352 default: 341 notify = "POLL";
353 pr_warning(FW_WARN GHES_PFX 342 break;
354 "Unknown notification type: %u for generic hardware error source: %d\n", 343 case ACPI_HEST_NOTIFY_EXTERNAL:
355 generic->notify.type, generic->header.source_id); 344 case ACPI_HEST_NOTIFY_LOCAL:
356 break; 345 notify = "IRQ";
346 break;
347 case ACPI_HEST_NOTIFY_NMI:
348 notify = "NMI";
349 break;
350 }
351 if (notify) {
352 pr_warning(GHES_PFX
353"Generic hardware error source: %d notified via %s is not supported!\n",
354 generic->header.source_id, notify);
355 } else {
356 pr_warning(FW_WARN GHES_PFX
357"Unknown notification type: %u for generic hardware error source: %d\n",
358 generic->notify.type, generic->header.source_id);
359 }
360 rc = -ENODEV;
361 goto err;
357 } 362 }
363 platform_set_drvdata(ghes_dev, ghes);
358 364
359 return 0; 365 return 0;
360err: 366err:
361 if (ghes) 367 if (ghes) {
362 ghes_fini(ghes); 368 ghes_fini(ghes);
369 kfree(ghes);
370 }
363 return rc; 371 return rc;
364} 372}
365 373
366static void ghes_cleanup(void) 374static int __devexit ghes_remove(struct platform_device *ghes_dev)
367{ 375{
368 struct ghes *ghes, *nghes; 376 struct ghes *ghes;
377 struct acpi_hest_generic *generic;
369 378
370 if (!list_empty(&ghes_sci)) 379 ghes = platform_get_drvdata(ghes_dev);
371 unregister_acpi_hed_notifier(&ghes_notifier_sci); 380 generic = ghes->generic;
381
382 switch (generic->notify.type) {
383 case ACPI_HEST_NOTIFY_SCI:
384 mutex_lock(&ghes_list_mutex);
385 list_del_rcu(&ghes->list);
386 if (list_empty(&ghes_sci))
387 unregister_acpi_hed_notifier(&ghes_notifier_sci);
388 mutex_unlock(&ghes_list_mutex);
389 break;
390 default:
391 BUG();
392 break;
393 }
372 394
373 synchronize_rcu(); 395 synchronize_rcu();
396 ghes_fini(ghes);
397 kfree(ghes);
374 398
375 list_for_each_entry_safe(ghes, nghes, &ghes_sci, list) { 399 platform_set_drvdata(ghes_dev, NULL);
376 list_del(&ghes->list); 400
377 ghes_fini(ghes); 401 return 0;
378 kfree(ghes);
379 }
380} 402}
381 403
404static struct platform_driver ghes_platform_driver = {
405 .driver = {
406 .name = "GHES",
407 .owner = THIS_MODULE,
408 },
409 .probe = ghes_probe,
410 .remove = ghes_remove,
411};
412
382static int __init ghes_init(void) 413static int __init ghes_init(void)
383{ 414{
384 int rc;
385
386 if (acpi_disabled) 415 if (acpi_disabled)
387 return -ENODEV; 416 return -ENODEV;
388 417
@@ -391,32 +420,12 @@ static int __init ghes_init(void)
391 return -EINVAL; 420 return -EINVAL;
392 } 421 }
393 422
394 rc = apei_hest_parse(hest_ghes_parse, NULL); 423 return platform_driver_register(&ghes_platform_driver);
395 if (rc) {
396 pr_err(GHES_PFX
397 "Error during parsing HEST generic hardware error sources.\n");
398 goto err_cleanup;
399 }
400
401 if (list_empty(&ghes_sci)) {
402 pr_info(GHES_PFX
403 "No functional generic hardware error sources.\n");
404 rc = -ENODEV;
405 goto err_cleanup;
406 }
407
408 pr_info(GHES_PFX
409 "Generic Hardware Error Source support is initialized.\n");
410
411 return 0;
412err_cleanup:
413 ghes_cleanup();
414 return rc;
415} 424}
416 425
417static void __exit ghes_exit(void) 426static void __exit ghes_exit(void)
418{ 427{
419 ghes_cleanup(); 428 platform_driver_unregister(&ghes_platform_driver);
420} 429}
421 430
422module_init(ghes_init); 431module_init(ghes_init);
@@ -425,3 +434,4 @@ module_exit(ghes_exit);
425MODULE_AUTHOR("Huang Ying"); 434MODULE_AUTHOR("Huang Ying");
426MODULE_DESCRIPTION("APEI Generic Hardware Error Source support"); 435MODULE_DESCRIPTION("APEI Generic Hardware Error Source support");
427MODULE_LICENSE("GPL"); 436MODULE_LICENSE("GPL");
437MODULE_ALIAS("platform:GHES");
diff --git a/drivers/acpi/apei/hest.c b/drivers/acpi/apei/hest.c
index e7f40d362cb3..343168d18266 100644
--- a/drivers/acpi/apei/hest.c
+++ b/drivers/acpi/apei/hest.c
@@ -34,6 +34,7 @@
34#include <linux/kdebug.h> 34#include <linux/kdebug.h>
35#include <linux/highmem.h> 35#include <linux/highmem.h>
36#include <linux/io.h> 36#include <linux/io.h>
37#include <linux/platform_device.h>
37#include <acpi/apei.h> 38#include <acpi/apei.h>
38 39
39#include "apei-internal.h" 40#include "apei-internal.h"
@@ -47,11 +48,6 @@ EXPORT_SYMBOL_GPL(hest_disable);
47 48
48static struct acpi_table_hest *hest_tab; 49static struct acpi_table_hest *hest_tab;
49 50
50static int hest_void_parse(struct acpi_hest_header *hest_hdr, void *data)
51{
52 return 0;
53}
54
55static int hest_esrc_len_tab[ACPI_HEST_TYPE_RESERVED] = { 51static int hest_esrc_len_tab[ACPI_HEST_TYPE_RESERVED] = {
56 [ACPI_HEST_TYPE_IA32_CHECK] = -1, /* need further calculation */ 52 [ACPI_HEST_TYPE_IA32_CHECK] = -1, /* need further calculation */
57 [ACPI_HEST_TYPE_IA32_CORRECTED_CHECK] = -1, 53 [ACPI_HEST_TYPE_IA32_CORRECTED_CHECK] = -1,
@@ -125,6 +121,69 @@ int apei_hest_parse(apei_hest_func_t func, void *data)
125} 121}
126EXPORT_SYMBOL_GPL(apei_hest_parse); 122EXPORT_SYMBOL_GPL(apei_hest_parse);
127 123
124struct ghes_arr {
125 struct platform_device **ghes_devs;
126 unsigned int count;
127};
128
129static int hest_parse_ghes_count(struct acpi_hest_header *hest_hdr, void *data)
130{
131 int *count = data;
132
133 if (hest_hdr->type == ACPI_HEST_TYPE_GENERIC_ERROR)
134 (*count)++;
135 return 0;
136}
137
138static int hest_parse_ghes(struct acpi_hest_header *hest_hdr, void *data)
139{
140 struct acpi_hest_generic *generic;
141 struct platform_device *ghes_dev;
142 struct ghes_arr *ghes_arr = data;
143 int rc;
144
145 if (hest_hdr->type != ACPI_HEST_TYPE_GENERIC_ERROR)
146 return 0;
147 generic = (struct acpi_hest_generic *)hest_hdr;
148 if (!generic->enabled)
149 return 0;
150 ghes_dev = platform_device_alloc("GHES", hest_hdr->source_id);
151 if (!ghes_dev)
152 return -ENOMEM;
153 ghes_dev->dev.platform_data = generic;
154 rc = platform_device_add(ghes_dev);
155 if (rc)
156 goto err;
157 ghes_arr->ghes_devs[ghes_arr->count++] = ghes_dev;
158
159 return 0;
160err:
161 platform_device_put(ghes_dev);
162 return rc;
163}
164
165static int hest_ghes_dev_register(unsigned int ghes_count)
166{
167 int rc, i;
168 struct ghes_arr ghes_arr;
169
170 ghes_arr.count = 0;
171 ghes_arr.ghes_devs = kmalloc(sizeof(void *) * ghes_count, GFP_KERNEL);
172 if (!ghes_arr.ghes_devs)
173 return -ENOMEM;
174
175 rc = apei_hest_parse(hest_parse_ghes, &ghes_arr);
176 if (rc)
177 goto err;
178out:
179 kfree(ghes_arr.ghes_devs);
180 return rc;
181err:
182 for (i = 0; i < ghes_arr.count; i++)
183 platform_device_unregister(ghes_arr.ghes_devs[i]);
184 goto out;
185}
186
128static int __init setup_hest_disable(char *str) 187static int __init setup_hest_disable(char *str)
129{ 188{
130 hest_disable = 1; 189 hest_disable = 1;
@@ -137,6 +196,7 @@ static int __init hest_init(void)
137{ 196{
138 acpi_status status; 197 acpi_status status;
139 int rc = -ENODEV; 198 int rc = -ENODEV;
199 unsigned int ghes_count = 0;
140 200
141 if (acpi_disabled) 201 if (acpi_disabled)
142 goto err; 202 goto err;
@@ -158,7 +218,11 @@ static int __init hest_init(void)
158 goto err; 218 goto err;
159 } 219 }
160 220
161 rc = apei_hest_parse(hest_void_parse, NULL); 221 rc = apei_hest_parse(hest_parse_ghes_count, &ghes_count);
222 if (rc)
223 goto err;
224
225 rc = hest_ghes_dev_register(ghes_count);
162 if (rc) 226 if (rc)
163 goto err; 227 goto err;
164 228
diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
index c1d23cd71652..5c221ab535d5 100644
--- a/drivers/acpi/bus.c
+++ b/drivers/acpi/bus.c
@@ -1034,8 +1034,8 @@ static int __init acpi_init(void)
1034 acpi_scan_init(); 1034 acpi_scan_init();
1035 acpi_ec_init(); 1035 acpi_ec_init();
1036 acpi_power_init(); 1036 acpi_power_init();
1037 acpi_system_init(); 1037 acpi_sysfs_init();
1038 acpi_debug_init(); 1038 acpi_debugfs_init();
1039 acpi_sleep_proc_init(); 1039 acpi_sleep_proc_init();
1040 acpi_wakeup_device_init(); 1040 acpi_wakeup_device_init();
1041 return result; 1041 return result;
diff --git a/drivers/acpi/debug.c b/drivers/acpi/debug.c
deleted file mode 100644
index 146135e7a6a1..000000000000
--- a/drivers/acpi/debug.c
+++ /dev/null
@@ -1,406 +0,0 @@
1/*
2 * debug.c - ACPI debug interface to userspace.
3 */
4
5#include <linux/proc_fs.h>
6#include <linux/seq_file.h>
7#include <linux/init.h>
8#include <linux/module.h>
9#include <linux/kernel.h>
10#include <linux/moduleparam.h>
11#include <linux/debugfs.h>
12#include <linux/slab.h>
13#include <asm/uaccess.h>
14#include <acpi/acpi_drivers.h>
15
16#define _COMPONENT ACPI_SYSTEM_COMPONENT
17ACPI_MODULE_NAME("debug");
18
19struct acpi_dlayer {
20 const char *name;
21 unsigned long value;
22};
23struct acpi_dlevel {
24 const char *name;
25 unsigned long value;
26};
27#define ACPI_DEBUG_INIT(v) { .name = #v, .value = v }
28
29static const struct acpi_dlayer acpi_debug_layers[] = {
30 ACPI_DEBUG_INIT(ACPI_UTILITIES),
31 ACPI_DEBUG_INIT(ACPI_HARDWARE),
32 ACPI_DEBUG_INIT(ACPI_EVENTS),
33 ACPI_DEBUG_INIT(ACPI_TABLES),
34 ACPI_DEBUG_INIT(ACPI_NAMESPACE),
35 ACPI_DEBUG_INIT(ACPI_PARSER),
36 ACPI_DEBUG_INIT(ACPI_DISPATCHER),
37 ACPI_DEBUG_INIT(ACPI_EXECUTER),
38 ACPI_DEBUG_INIT(ACPI_RESOURCES),
39 ACPI_DEBUG_INIT(ACPI_CA_DEBUGGER),
40 ACPI_DEBUG_INIT(ACPI_OS_SERVICES),
41 ACPI_DEBUG_INIT(ACPI_CA_DISASSEMBLER),
42 ACPI_DEBUG_INIT(ACPI_COMPILER),
43 ACPI_DEBUG_INIT(ACPI_TOOLS),
44
45 ACPI_DEBUG_INIT(ACPI_BUS_COMPONENT),
46 ACPI_DEBUG_INIT(ACPI_AC_COMPONENT),
47 ACPI_DEBUG_INIT(ACPI_BATTERY_COMPONENT),
48 ACPI_DEBUG_INIT(ACPI_BUTTON_COMPONENT),
49 ACPI_DEBUG_INIT(ACPI_SBS_COMPONENT),
50 ACPI_DEBUG_INIT(ACPI_FAN_COMPONENT),
51 ACPI_DEBUG_INIT(ACPI_PCI_COMPONENT),
52 ACPI_DEBUG_INIT(ACPI_POWER_COMPONENT),
53 ACPI_DEBUG_INIT(ACPI_CONTAINER_COMPONENT),
54 ACPI_DEBUG_INIT(ACPI_SYSTEM_COMPONENT),
55 ACPI_DEBUG_INIT(ACPI_THERMAL_COMPONENT),
56 ACPI_DEBUG_INIT(ACPI_MEMORY_DEVICE_COMPONENT),
57 ACPI_DEBUG_INIT(ACPI_VIDEO_COMPONENT),
58 ACPI_DEBUG_INIT(ACPI_PROCESSOR_COMPONENT),
59};
60
61static const struct acpi_dlevel acpi_debug_levels[] = {
62 ACPI_DEBUG_INIT(ACPI_LV_INIT),
63 ACPI_DEBUG_INIT(ACPI_LV_DEBUG_OBJECT),
64 ACPI_DEBUG_INIT(ACPI_LV_INFO),
65
66 ACPI_DEBUG_INIT(ACPI_LV_INIT_NAMES),
67 ACPI_DEBUG_INIT(ACPI_LV_PARSE),
68 ACPI_DEBUG_INIT(ACPI_LV_LOAD),
69 ACPI_DEBUG_INIT(ACPI_LV_DISPATCH),
70 ACPI_DEBUG_INIT(ACPI_LV_EXEC),
71 ACPI_DEBUG_INIT(ACPI_LV_NAMES),
72 ACPI_DEBUG_INIT(ACPI_LV_OPREGION),
73 ACPI_DEBUG_INIT(ACPI_LV_BFIELD),
74 ACPI_DEBUG_INIT(ACPI_LV_TABLES),
75 ACPI_DEBUG_INIT(ACPI_LV_VALUES),
76 ACPI_DEBUG_INIT(ACPI_LV_OBJECTS),
77 ACPI_DEBUG_INIT(ACPI_LV_RESOURCES),
78 ACPI_DEBUG_INIT(ACPI_LV_USER_REQUESTS),
79 ACPI_DEBUG_INIT(ACPI_LV_PACKAGE),
80
81 ACPI_DEBUG_INIT(ACPI_LV_ALLOCATIONS),
82 ACPI_DEBUG_INIT(ACPI_LV_FUNCTIONS),
83 ACPI_DEBUG_INIT(ACPI_LV_OPTIMIZATIONS),
84
85 ACPI_DEBUG_INIT(ACPI_LV_MUTEX),
86 ACPI_DEBUG_INIT(ACPI_LV_THREADS),
87 ACPI_DEBUG_INIT(ACPI_LV_IO),
88 ACPI_DEBUG_INIT(ACPI_LV_INTERRUPTS),
89
90 ACPI_DEBUG_INIT(ACPI_LV_AML_DISASSEMBLE),
91 ACPI_DEBUG_INIT(ACPI_LV_VERBOSE_INFO),
92 ACPI_DEBUG_INIT(ACPI_LV_FULL_TABLES),
93 ACPI_DEBUG_INIT(ACPI_LV_EVENTS),
94};
95
96/* --------------------------------------------------------------------------
97 FS Interface (/sys)
98 -------------------------------------------------------------------------- */
99static int param_get_debug_layer(char *buffer, struct kernel_param *kp) {
100 int result = 0;
101 int i;
102
103 result = sprintf(buffer, "%-25s\tHex SET\n", "Description");
104
105 for(i = 0; i <ARRAY_SIZE(acpi_debug_layers); i++) {
106 result += sprintf(buffer+result, "%-25s\t0x%08lX [%c]\n",
107 acpi_debug_layers[i].name,
108 acpi_debug_layers[i].value,
109 (acpi_dbg_layer & acpi_debug_layers[i].value) ? '*' : ' ');
110 }
111 result += sprintf(buffer+result, "%-25s\t0x%08X [%c]\n", "ACPI_ALL_DRIVERS",
112 ACPI_ALL_DRIVERS,
113 (acpi_dbg_layer & ACPI_ALL_DRIVERS) ==
114 ACPI_ALL_DRIVERS ? '*' : (acpi_dbg_layer &
115 ACPI_ALL_DRIVERS) == 0 ? ' ' : '-');
116 result += sprintf(buffer+result, "--\ndebug_layer = 0x%08X ( * = enabled)\n", acpi_dbg_layer);
117
118 return result;
119}
120
121static int param_get_debug_level(char *buffer, struct kernel_param *kp) {
122 int result = 0;
123 int i;
124
125 result = sprintf(buffer, "%-25s\tHex SET\n", "Description");
126
127 for (i = 0; i < ARRAY_SIZE(acpi_debug_levels); i++) {
128 result += sprintf(buffer+result, "%-25s\t0x%08lX [%c]\n",
129 acpi_debug_levels[i].name,
130 acpi_debug_levels[i].value,
131 (acpi_dbg_level & acpi_debug_levels[i].
132 value) ? '*' : ' ');
133 }
134 result += sprintf(buffer+result, "--\ndebug_level = 0x%08X (* = enabled)\n",
135 acpi_dbg_level);
136
137 return result;
138}
139
140module_param_call(debug_layer, param_set_uint, param_get_debug_layer, &acpi_dbg_layer, 0644);
141module_param_call(debug_level, param_set_uint, param_get_debug_level, &acpi_dbg_level, 0644);
142
143static char trace_method_name[6];
144module_param_string(trace_method_name, trace_method_name, 6, 0644);
145static unsigned int trace_debug_layer;
146module_param(trace_debug_layer, uint, 0644);
147static unsigned int trace_debug_level;
148module_param(trace_debug_level, uint, 0644);
149
150static int param_set_trace_state(const char *val, struct kernel_param *kp)
151{
152 int result = 0;
153
154 if (!strncmp(val, "enable", strlen("enable") - 1)) {
155 result = acpi_debug_trace(trace_method_name, trace_debug_level,
156 trace_debug_layer, 0);
157 if (result)
158 result = -EBUSY;
159 goto exit;
160 }
161
162 if (!strncmp(val, "disable", strlen("disable") - 1)) {
163 int name = 0;
164 result = acpi_debug_trace((char *)&name, trace_debug_level,
165 trace_debug_layer, 0);
166 if (result)
167 result = -EBUSY;
168 goto exit;
169 }
170
171 if (!strncmp(val, "1", 1)) {
172 result = acpi_debug_trace(trace_method_name, trace_debug_level,
173 trace_debug_layer, 1);
174 if (result)
175 result = -EBUSY;
176 goto exit;
177 }
178
179 result = -EINVAL;
180exit:
181 return result;
182}
183
184static int param_get_trace_state(char *buffer, struct kernel_param *kp)
185{
186 if (!acpi_gbl_trace_method_name)
187 return sprintf(buffer, "disable");
188 else {
189 if (acpi_gbl_trace_flags & 1)
190 return sprintf(buffer, "1");
191 else
192 return sprintf(buffer, "enable");
193 }
194 return 0;
195}
196
197module_param_call(trace_state, param_set_trace_state, param_get_trace_state,
198 NULL, 0644);
199
200/* --------------------------------------------------------------------------
201 DebugFS Interface
202 -------------------------------------------------------------------------- */
203
204static ssize_t cm_write(struct file *file, const char __user *user_buf,
205 size_t count, loff_t *ppos)
206{
207 static char *buf;
208 static int uncopied_bytes;
209 struct acpi_table_header table;
210 acpi_status status;
211
212 if (!(*ppos)) {
213 /* parse the table header to get the table length */
214 if (count <= sizeof(struct acpi_table_header))
215 return -EINVAL;
216 if (copy_from_user(&table, user_buf,
217 sizeof(struct acpi_table_header)))
218 return -EFAULT;
219 uncopied_bytes = table.length;
220 buf = kzalloc(uncopied_bytes, GFP_KERNEL);
221 if (!buf)
222 return -ENOMEM;
223 }
224
225 if (uncopied_bytes < count) {
226 kfree(buf);
227 return -EINVAL;
228 }
229
230 if (copy_from_user(buf + (*ppos), user_buf, count)) {
231 kfree(buf);
232 return -EFAULT;
233 }
234
235 uncopied_bytes -= count;
236 *ppos += count;
237
238 if (!uncopied_bytes) {
239 status = acpi_install_method(buf);
240 kfree(buf);
241 if (ACPI_FAILURE(status))
242 return -EINVAL;
243 add_taint(TAINT_OVERRIDDEN_ACPI_TABLE);
244 }
245
246 return count;
247}
248
249static const struct file_operations cm_fops = {
250 .write = cm_write,
251};
252
253static int acpi_debugfs_init(void)
254{
255 struct dentry *acpi_dir, *cm_dentry;
256
257 acpi_dir = debugfs_create_dir("acpi", NULL);
258 if (!acpi_dir)
259 goto err;
260
261 cm_dentry = debugfs_create_file("custom_method", S_IWUGO,
262 acpi_dir, NULL, &cm_fops);
263 if (!cm_dentry)
264 goto err;
265
266 return 0;
267
268err:
269 if (acpi_dir)
270 debugfs_remove(acpi_dir);
271 return -EINVAL;
272}
273
274/* --------------------------------------------------------------------------
275 FS Interface (/proc)
276 -------------------------------------------------------------------------- */
277#ifdef CONFIG_ACPI_PROCFS
278#define ACPI_SYSTEM_FILE_DEBUG_LAYER "debug_layer"
279#define ACPI_SYSTEM_FILE_DEBUG_LEVEL "debug_level"
280
281static int acpi_system_debug_proc_show(struct seq_file *m, void *v)
282{
283 unsigned int i;
284
285 seq_printf(m, "%-25s\tHex SET\n", "Description");
286
287 switch ((unsigned long)m->private) {
288 case 0:
289 for (i = 0; i < ARRAY_SIZE(acpi_debug_layers); i++) {
290 seq_printf(m, "%-25s\t0x%08lX [%c]\n",
291 acpi_debug_layers[i].name,
292 acpi_debug_layers[i].value,
293 (acpi_dbg_layer & acpi_debug_layers[i].
294 value) ? '*' : ' ');
295 }
296 seq_printf(m, "%-25s\t0x%08X [%c]\n", "ACPI_ALL_DRIVERS",
297 ACPI_ALL_DRIVERS,
298 (acpi_dbg_layer & ACPI_ALL_DRIVERS) ==
299 ACPI_ALL_DRIVERS ? '*' : (acpi_dbg_layer &
300 ACPI_ALL_DRIVERS) ==
301 0 ? ' ' : '-');
302 seq_printf(m,
303 "--\ndebug_layer = 0x%08X (* = enabled, - = partial)\n",
304 acpi_dbg_layer);
305 break;
306 case 1:
307 for (i = 0; i < ARRAY_SIZE(acpi_debug_levels); i++) {
308 seq_printf(m, "%-25s\t0x%08lX [%c]\n",
309 acpi_debug_levels[i].name,
310 acpi_debug_levels[i].value,
311 (acpi_dbg_level & acpi_debug_levels[i].
312 value) ? '*' : ' ');
313 }
314 seq_printf(m, "--\ndebug_level = 0x%08X (* = enabled)\n",
315 acpi_dbg_level);
316 break;
317 }
318 return 0;
319}
320
321static int acpi_system_debug_proc_open(struct inode *inode, struct file *file)
322{
323 return single_open(file, acpi_system_debug_proc_show, PDE(inode)->data);
324}
325
326static ssize_t acpi_system_debug_proc_write(struct file *file,
327 const char __user * buffer,
328 size_t count, loff_t *pos)
329{
330 char debug_string[12] = { '\0' };
331
332
333 if (count > sizeof(debug_string) - 1)
334 return -EINVAL;
335
336 if (copy_from_user(debug_string, buffer, count))
337 return -EFAULT;
338
339 debug_string[count] = '\0';
340
341 switch ((unsigned long)PDE(file->f_path.dentry->d_inode)->data) {
342 case 0:
343 acpi_dbg_layer = simple_strtoul(debug_string, NULL, 0);
344 break;
345 case 1:
346 acpi_dbg_level = simple_strtoul(debug_string, NULL, 0);
347 break;
348 default:
349 return -EINVAL;
350 }
351
352 return count;
353}
354
355static const struct file_operations acpi_system_debug_proc_fops = {
356 .owner = THIS_MODULE,
357 .open = acpi_system_debug_proc_open,
358 .read = seq_read,
359 .llseek = seq_lseek,
360 .release = single_release,
361 .write = acpi_system_debug_proc_write,
362};
363#endif
364
365int __init acpi_procfs_init(void)
366{
367#ifdef CONFIG_ACPI_PROCFS
368 struct proc_dir_entry *entry;
369 int error = 0;
370 char *name;
371
372 /* 'debug_layer' [R/W] */
373 name = ACPI_SYSTEM_FILE_DEBUG_LAYER;
374 entry = proc_create_data(name, S_IFREG | S_IRUGO | S_IWUSR,
375 acpi_root_dir, &acpi_system_debug_proc_fops,
376 (void *)0);
377 if (!entry)
378 goto Error;
379
380 /* 'debug_level' [R/W] */
381 name = ACPI_SYSTEM_FILE_DEBUG_LEVEL;
382 entry = proc_create_data(name, S_IFREG | S_IRUGO | S_IWUSR,
383 acpi_root_dir, &acpi_system_debug_proc_fops,
384 (void *)1);
385 if (!entry)
386 goto Error;
387
388 Done:
389 return error;
390
391 Error:
392 remove_proc_entry(ACPI_SYSTEM_FILE_DEBUG_LEVEL, acpi_root_dir);
393 remove_proc_entry(ACPI_SYSTEM_FILE_DEBUG_LAYER, acpi_root_dir);
394 error = -ENODEV;
395 goto Done;
396#else
397 return 0;
398#endif
399}
400
401int __init acpi_debug_init(void)
402{
403 acpi_debugfs_init();
404 acpi_procfs_init();
405 return 0;
406}
diff --git a/drivers/acpi/debugfs.c b/drivers/acpi/debugfs.c
new file mode 100644
index 000000000000..7de27d49c4b9
--- /dev/null
+++ b/drivers/acpi/debugfs.c
@@ -0,0 +1,93 @@
1/*
2 * debugfs.c - ACPI debugfs interface to userspace.
3 */
4
5#include <linux/init.h>
6#include <linux/module.h>
7#include <linux/kernel.h>
8#include <linux/uaccess.h>
9#include <linux/debugfs.h>
10#include <acpi/acpi_drivers.h>
11
12#define _COMPONENT ACPI_SYSTEM_COMPONENT
13ACPI_MODULE_NAME("debugfs");
14
15
16/* /sys/modules/acpi/parameters/aml_debug_output */
17
18module_param_named(aml_debug_output, acpi_gbl_enable_aml_debug_object,
19 bool, 0644);
20MODULE_PARM_DESC(aml_debug_output,
21 "To enable/disable the ACPI Debug Object output.");
22
23/* /sys/kernel/debug/acpi/custom_method */
24
25static ssize_t cm_write(struct file *file, const char __user * user_buf,
26 size_t count, loff_t *ppos)
27{
28 static char *buf;
29 static int uncopied_bytes;
30 struct acpi_table_header table;
31 acpi_status status;
32
33 if (!(*ppos)) {
34 /* parse the table header to get the table length */
35 if (count <= sizeof(struct acpi_table_header))
36 return -EINVAL;
37 if (copy_from_user(&table, user_buf,
38 sizeof(struct acpi_table_header)))
39 return -EFAULT;
40 uncopied_bytes = table.length;
41 buf = kzalloc(uncopied_bytes, GFP_KERNEL);
42 if (!buf)
43 return -ENOMEM;
44 }
45
46 if (uncopied_bytes < count) {
47 kfree(buf);
48 return -EINVAL;
49 }
50
51 if (copy_from_user(buf + (*ppos), user_buf, count)) {
52 kfree(buf);
53 return -EFAULT;
54 }
55
56 uncopied_bytes -= count;
57 *ppos += count;
58
59 if (!uncopied_bytes) {
60 status = acpi_install_method(buf);
61 kfree(buf);
62 if (ACPI_FAILURE(status))
63 return -EINVAL;
64 add_taint(TAINT_OVERRIDDEN_ACPI_TABLE);
65 }
66
67 return count;
68}
69
70static const struct file_operations cm_fops = {
71 .write = cm_write,
72};
73
74int __init acpi_debugfs_init(void)
75{
76 struct dentry *acpi_dir, *cm_dentry;
77
78 acpi_dir = debugfs_create_dir("acpi", NULL);
79 if (!acpi_dir)
80 goto err;
81
82 cm_dentry = debugfs_create_file("custom_method", S_IWUGO,
83 acpi_dir, NULL, &cm_fops);
84 if (!cm_dentry)
85 goto err;
86
87 return 0;
88
89err:
90 if (acpi_dir)
91 debugfs_remove(acpi_dir);
92 return -EINVAL;
93}
diff --git a/drivers/acpi/glue.c b/drivers/acpi/glue.c
index 4af6301601e7..78b0164c35b2 100644
--- a/drivers/acpi/glue.c
+++ b/drivers/acpi/glue.c
@@ -100,7 +100,8 @@ do_acpi_find_child(acpi_handle handle, u32 lvl, void *context, void **rv)
100 100
101 status = acpi_get_object_info(handle, &info); 101 status = acpi_get_object_info(handle, &info);
102 if (ACPI_SUCCESS(status)) { 102 if (ACPI_SUCCESS(status)) {
103 if (info->address == find->address) 103 if ((info->address == find->address)
104 && (info->valid & ACPI_VALID_ADR))
104 find->handle = handle; 105 find->handle = handle;
105 kfree(info); 106 kfree(info);
106 } 107 }
diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h
index 8ae27264a00e..a212bfeddf8c 100644
--- a/drivers/acpi/internal.h
+++ b/drivers/acpi/internal.h
@@ -27,12 +27,12 @@
27 27
28int init_acpi_device_notify(void); 28int init_acpi_device_notify(void);
29int acpi_scan_init(void); 29int acpi_scan_init(void);
30int acpi_system_init(void); 30int acpi_sysfs_init(void);
31 31
32#ifdef CONFIG_ACPI_DEBUG 32#ifdef CONFIG_DEBUG_FS
33int acpi_debug_init(void); 33int acpi_debugfs_init(void);
34#else 34#else
35static inline int acpi_debug_init(void) { return 0; } 35static inline int acpi_debugfs_init(void) { return 0; }
36#endif 36#endif
37 37
38/* -------------------------------------------------------------------------- 38/* --------------------------------------------------------------------------
diff --git a/drivers/acpi/numa.c b/drivers/acpi/numa.c
index b0337d314604..5718566e00f9 100644
--- a/drivers/acpi/numa.c
+++ b/drivers/acpi/numa.c
@@ -255,12 +255,10 @@ acpi_parse_memory_affinity(struct acpi_subtable_header * header,
255 255
256static int __init acpi_parse_srat(struct acpi_table_header *table) 256static int __init acpi_parse_srat(struct acpi_table_header *table)
257{ 257{
258 struct acpi_table_srat *srat;
259
260 if (!table) 258 if (!table)
261 return -EINVAL; 259 return -EINVAL;
262 260
263 srat = (struct acpi_table_srat *)table; 261 /* Real work done in acpi_table_parse_srat below. */
264 262
265 return 0; 263 return 0;
266} 264}
diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c
index f14d3f251d26..65b25a303b86 100644
--- a/drivers/acpi/osl.c
+++ b/drivers/acpi/osl.c
@@ -141,15 +141,14 @@ static struct osi_linux {
141static void __init acpi_request_region (struct acpi_generic_address *addr, 141static void __init acpi_request_region (struct acpi_generic_address *addr,
142 unsigned int length, char *desc) 142 unsigned int length, char *desc)
143{ 143{
144 struct resource *res;
145
146 if (!addr->address || !length) 144 if (!addr->address || !length)
147 return; 145 return;
148 146
147 /* Resources are never freed */
149 if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_IO) 148 if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_IO)
150 res = request_region(addr->address, length, desc); 149 request_region(addr->address, length, desc);
151 else if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) 150 else if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY)
152 res = request_mem_region(addr->address, length, desc); 151 request_mem_region(addr->address, length, desc);
153} 152}
154 153
155static int __init acpi_reserve_resources(void) 154static int __init acpi_reserve_resources(void)
diff --git a/drivers/acpi/power.c b/drivers/acpi/power.c
index f74d3b31e5c9..844c155aeb0f 100644
--- a/drivers/acpi/power.c
+++ b/drivers/acpi/power.c
@@ -40,8 +40,6 @@
40#include <linux/init.h> 40#include <linux/init.h>
41#include <linux/types.h> 41#include <linux/types.h>
42#include <linux/slab.h> 42#include <linux/slab.h>
43#include <linux/proc_fs.h>
44#include <linux/seq_file.h>
45#include <acpi/acpi_bus.h> 43#include <acpi/acpi_bus.h>
46#include <acpi/acpi_drivers.h> 44#include <acpi/acpi_drivers.h>
47#include "sleep.h" 45#include "sleep.h"
@@ -64,7 +62,6 @@ module_param_named(power_nocheck, acpi_power_nocheck, bool, 000);
64static int acpi_power_add(struct acpi_device *device); 62static int acpi_power_add(struct acpi_device *device);
65static int acpi_power_remove(struct acpi_device *device, int type); 63static int acpi_power_remove(struct acpi_device *device, int type);
66static int acpi_power_resume(struct acpi_device *device); 64static int acpi_power_resume(struct acpi_device *device);
67static int acpi_power_open_fs(struct inode *inode, struct file *file);
68 65
69static const struct acpi_device_id power_device_ids[] = { 66static const struct acpi_device_id power_device_ids[] = {
70 {ACPI_POWER_HID, 0}, 67 {ACPI_POWER_HID, 0},
@@ -99,14 +96,6 @@ struct acpi_power_resource {
99 96
100static struct list_head acpi_power_resource_list; 97static struct list_head acpi_power_resource_list;
101 98
102static const struct file_operations acpi_power_fops = {
103 .owner = THIS_MODULE,
104 .open = acpi_power_open_fs,
105 .read = seq_read,
106 .llseek = seq_lseek,
107 .release = single_release,
108};
109
110/* -------------------------------------------------------------------------- 99/* --------------------------------------------------------------------------
111 Power Resource Management 100 Power Resource Management
112 -------------------------------------------------------------------------- */ 101 -------------------------------------------------------------------------- */
@@ -255,7 +244,6 @@ static int acpi_power_off_device(acpi_handle handle, struct acpi_device *dev)
255 struct list_head *node, *next; 244 struct list_head *node, *next;
256 struct acpi_power_reference *ref; 245 struct acpi_power_reference *ref;
257 246
258
259 result = acpi_power_get_context(handle, &resource); 247 result = acpi_power_get_context(handle, &resource);
260 if (result) 248 if (result)
261 return result; 249 return result;
@@ -542,102 +530,6 @@ int acpi_power_transition(struct acpi_device *device, int state)
542} 530}
543 531
544/* -------------------------------------------------------------------------- 532/* --------------------------------------------------------------------------
545 FS Interface (/proc)
546 -------------------------------------------------------------------------- */
547
548static struct proc_dir_entry *acpi_power_dir;
549
550static int acpi_power_seq_show(struct seq_file *seq, void *offset)
551{
552 int count = 0;
553 int result = 0, state;
554 struct acpi_power_resource *resource = NULL;
555 struct list_head *node, *next;
556 struct acpi_power_reference *ref;
557
558
559 resource = seq->private;
560
561 if (!resource)
562 goto end;
563
564 result = acpi_power_get_state(resource->device->handle, &state);
565 if (result)
566 goto end;
567
568 seq_puts(seq, "state: ");
569 switch (state) {
570 case ACPI_POWER_RESOURCE_STATE_ON:
571 seq_puts(seq, "on\n");
572 break;
573 case ACPI_POWER_RESOURCE_STATE_OFF:
574 seq_puts(seq, "off\n");
575 break;
576 default:
577 seq_puts(seq, "unknown\n");
578 break;
579 }
580
581 mutex_lock(&resource->resource_lock);
582 list_for_each_safe(node, next, &resource->reference) {
583 ref = container_of(node, struct acpi_power_reference, node);
584 count++;
585 }
586 mutex_unlock(&resource->resource_lock);
587
588 seq_printf(seq, "system level: S%d\n"
589 "order: %d\n"
590 "reference count: %d\n",
591 resource->system_level,
592 resource->order, count);
593
594 end:
595 return 0;
596}
597
598static int acpi_power_open_fs(struct inode *inode, struct file *file)
599{
600 return single_open(file, acpi_power_seq_show, PDE(inode)->data);
601}
602
603static int acpi_power_add_fs(struct acpi_device *device)
604{
605 struct proc_dir_entry *entry = NULL;
606
607
608 if (!device)
609 return -EINVAL;
610
611 if (!acpi_device_dir(device)) {
612 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
613 acpi_power_dir);
614 if (!acpi_device_dir(device))
615 return -ENODEV;
616 }
617
618 /* 'status' [R] */
619 entry = proc_create_data(ACPI_POWER_FILE_STATUS,
620 S_IRUGO, acpi_device_dir(device),
621 &acpi_power_fops, acpi_driver_data(device));
622 if (!entry)
623 return -EIO;
624 return 0;
625}
626
627static int acpi_power_remove_fs(struct acpi_device *device)
628{
629
630 if (acpi_device_dir(device)) {
631 remove_proc_entry(ACPI_POWER_FILE_STATUS,
632 acpi_device_dir(device));
633 remove_proc_entry(acpi_device_bid(device), acpi_power_dir);
634 acpi_device_dir(device) = NULL;
635 }
636
637 return 0;
638}
639
640/* --------------------------------------------------------------------------
641 Driver Interface 533 Driver Interface
642 -------------------------------------------------------------------------- */ 534 -------------------------------------------------------------------------- */
643 535
@@ -690,10 +582,6 @@ static int acpi_power_add(struct acpi_device *device)
690 break; 582 break;
691 } 583 }
692 584
693 result = acpi_power_add_fs(device);
694 if (result)
695 goto end;
696
697 printk(KERN_INFO PREFIX "%s [%s] (%s)\n", acpi_device_name(device), 585 printk(KERN_INFO PREFIX "%s [%s] (%s)\n", acpi_device_name(device),
698 acpi_device_bid(device), state ? "on" : "off"); 586 acpi_device_bid(device), state ? "on" : "off");
699 587
@@ -715,8 +603,6 @@ static int acpi_power_remove(struct acpi_device *device, int type)
715 603
716 resource = acpi_driver_data(device); 604 resource = acpi_driver_data(device);
717 605
718 acpi_power_remove_fs(device);
719
720 mutex_lock(&resource->resource_lock); 606 mutex_lock(&resource->resource_lock);
721 list_for_each_safe(node, next, &resource->reference) { 607 list_for_each_safe(node, next, &resource->reference) {
722 struct acpi_power_reference *ref = container_of(node, struct acpi_power_reference, node); 608 struct acpi_power_reference *ref = container_of(node, struct acpi_power_reference, node);
@@ -760,19 +646,6 @@ static int acpi_power_resume(struct acpi_device *device)
760 646
761int __init acpi_power_init(void) 647int __init acpi_power_init(void)
762{ 648{
763 int result = 0;
764
765 INIT_LIST_HEAD(&acpi_power_resource_list); 649 INIT_LIST_HEAD(&acpi_power_resource_list);
766 650 return acpi_bus_register_driver(&acpi_power_driver);
767 acpi_power_dir = proc_mkdir(ACPI_POWER_CLASS, acpi_root_dir);
768 if (!acpi_power_dir)
769 return -ENODEV;
770
771 result = acpi_bus_register_driver(&acpi_power_driver);
772 if (result < 0) {
773 remove_proc_entry(ACPI_POWER_CLASS, acpi_root_dir);
774 return -ENODEV;
775 }
776
777 return 0;
778} 651}
diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
index 1ac678d2c51c..afad67769db6 100644
--- a/drivers/acpi/proc.c
+++ b/drivers/acpi/proc.c
@@ -17,64 +17,11 @@
17 17
18/* 18/*
19 * this file provides support for: 19 * this file provides support for:
20 * /proc/acpi/sleep
21 * /proc/acpi/alarm 20 * /proc/acpi/alarm
22 * /proc/acpi/wakeup 21 * /proc/acpi/wakeup
23 */ 22 */
24 23
25ACPI_MODULE_NAME("sleep") 24ACPI_MODULE_NAME("sleep")
26#ifdef CONFIG_ACPI_PROCFS
27static int acpi_system_sleep_seq_show(struct seq_file *seq, void *offset)
28{
29 int i;
30
31 for (i = 0; i <= ACPI_STATE_S5; i++) {
32 if (sleep_states[i]) {
33 seq_printf(seq, "S%d ", i);
34 }
35 }
36
37 seq_puts(seq, "\n");
38
39 return 0;
40}
41
42static int acpi_system_sleep_open_fs(struct inode *inode, struct file *file)
43{
44 return single_open(file, acpi_system_sleep_seq_show, PDE(inode)->data);
45}
46
47static ssize_t
48acpi_system_write_sleep(struct file *file,
49 const char __user * buffer, size_t count, loff_t * ppos)
50{
51 char str[12];
52 u32 state = 0;
53 int error = 0;
54
55 if (count > sizeof(str) - 1)
56 goto Done;
57 memset(str, 0, sizeof(str));
58 if (copy_from_user(str, buffer, count))
59 return -EFAULT;
60
61 /* Check for S4 bios request */
62 if (!strcmp(str, "4b")) {
63 error = acpi_suspend(4);
64 goto Done;
65 }
66 state = simple_strtoul(str, NULL, 0);
67#ifdef CONFIG_HIBERNATION
68 if (state == 4) {
69 error = hibernate();
70 goto Done;
71 }
72#endif
73 error = acpi_suspend(state);
74 Done:
75 return error ? error : count;
76}
77#endif /* CONFIG_ACPI_PROCFS */
78 25
79#if defined(CONFIG_RTC_DRV_CMOS) || defined(CONFIG_RTC_DRV_CMOS_MODULE) || !defined(CONFIG_X86) 26#if defined(CONFIG_RTC_DRV_CMOS) || defined(CONFIG_RTC_DRV_CMOS_MODULE) || !defined(CONFIG_X86)
80/* use /sys/class/rtc/rtcX/wakealarm instead; it's not ACPI-specific */ 27/* use /sys/class/rtc/rtcX/wakealarm instead; it's not ACPI-specific */
@@ -463,17 +410,6 @@ static const struct file_operations acpi_system_wakeup_device_fops = {
463 .release = single_release, 410 .release = single_release,
464}; 411};
465 412
466#ifdef CONFIG_ACPI_PROCFS
467static const struct file_operations acpi_system_sleep_fops = {
468 .owner = THIS_MODULE,
469 .open = acpi_system_sleep_open_fs,
470 .read = seq_read,
471 .write = acpi_system_write_sleep,
472 .llseek = seq_lseek,
473 .release = single_release,
474};
475#endif /* CONFIG_ACPI_PROCFS */
476
477#ifdef HAVE_ACPI_LEGACY_ALARM 413#ifdef HAVE_ACPI_LEGACY_ALARM
478static const struct file_operations acpi_system_alarm_fops = { 414static const struct file_operations acpi_system_alarm_fops = {
479 .owner = THIS_MODULE, 415 .owner = THIS_MODULE,
@@ -495,12 +431,6 @@ static u32 rtc_handler(void *context)
495 431
496int __init acpi_sleep_proc_init(void) 432int __init acpi_sleep_proc_init(void)
497{ 433{
498#ifdef CONFIG_ACPI_PROCFS
499 /* 'sleep' [R/W] */
500 proc_create("sleep", S_IFREG | S_IRUGO | S_IWUSR,
501 acpi_root_dir, &acpi_system_sleep_fops);
502#endif /* CONFIG_ACPI_PROCFS */
503
504#ifdef HAVE_ACPI_LEGACY_ALARM 434#ifdef HAVE_ACPI_LEGACY_ALARM
505 /* 'alarm' [R/W] */ 435 /* 'alarm' [R/W] */
506 proc_create("alarm", S_IFREG | S_IRUGO | S_IWUSR, 436 proc_create("alarm", S_IFREG | S_IRUGO | S_IWUSR,
diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
index 38ea0cc6dc49..156021892389 100644
--- a/drivers/acpi/processor_driver.c
+++ b/drivers/acpi/processor_driver.c
@@ -83,9 +83,6 @@ MODULE_LICENSE("GPL");
83 83
84static int acpi_processor_add(struct acpi_device *device); 84static int acpi_processor_add(struct acpi_device *device);
85static int acpi_processor_remove(struct acpi_device *device, int type); 85static int acpi_processor_remove(struct acpi_device *device, int type);
86#ifdef CONFIG_ACPI_PROCFS
87static int acpi_processor_info_open_fs(struct inode *inode, struct file *file);
88#endif
89static void acpi_processor_notify(struct acpi_device *device, u32 event); 86static void acpi_processor_notify(struct acpi_device *device, u32 event);
90static acpi_status acpi_processor_hotadd_init(acpi_handle handle, int *p_cpu); 87static acpi_status acpi_processor_hotadd_init(acpi_handle handle, int *p_cpu);
91static int acpi_processor_handle_eject(struct acpi_processor *pr); 88static int acpi_processor_handle_eject(struct acpi_processor *pr);
@@ -113,15 +110,6 @@ static struct acpi_driver acpi_processor_driver = {
113 110
114#define INSTALL_NOTIFY_HANDLER 1 111#define INSTALL_NOTIFY_HANDLER 1
115#define UNINSTALL_NOTIFY_HANDLER 2 112#define UNINSTALL_NOTIFY_HANDLER 2
116#ifdef CONFIG_ACPI_PROCFS
117static const struct file_operations acpi_processor_info_fops = {
118 .owner = THIS_MODULE,
119 .open = acpi_processor_info_open_fs,
120 .read = seq_read,
121 .llseek = seq_lseek,
122 .release = single_release,
123};
124#endif
125 113
126DEFINE_PER_CPU(struct acpi_processor *, processors); 114DEFINE_PER_CPU(struct acpi_processor *, processors);
127EXPORT_PER_CPU_SYMBOL(processors); 115EXPORT_PER_CPU_SYMBOL(processors);
@@ -256,44 +244,8 @@ static int acpi_processor_errata(struct acpi_processor *pr)
256 return result; 244 return result;
257} 245}
258 246
259/* --------------------------------------------------------------------------
260 FS Interface (/proc)
261 -------------------------------------------------------------------------- */
262
263#ifdef CONFIG_ACPI_PROCFS
264static struct proc_dir_entry *acpi_processor_dir = NULL; 247static struct proc_dir_entry *acpi_processor_dir = NULL;
265 248
266static int acpi_processor_info_seq_show(struct seq_file *seq, void *offset)
267{
268 struct acpi_processor *pr = seq->private;
269
270
271 if (!pr)
272 goto end;
273
274 seq_printf(seq, "processor id: %d\n"
275 "acpi id: %d\n"
276 "bus mastering control: %s\n"
277 "power management: %s\n"
278 "throttling control: %s\n"
279 "limit interface: %s\n",
280 pr->id,
281 pr->acpi_id,
282 pr->flags.bm_control ? "yes" : "no",
283 pr->flags.power ? "yes" : "no",
284 pr->flags.throttling ? "yes" : "no",
285 pr->flags.limit ? "yes" : "no");
286
287 end:
288 return 0;
289}
290
291static int acpi_processor_info_open_fs(struct inode *inode, struct file *file)
292{
293 return single_open(file, acpi_processor_info_seq_show,
294 PDE(inode)->data);
295}
296
297static int __cpuinit acpi_processor_add_fs(struct acpi_device *device) 249static int __cpuinit acpi_processor_add_fs(struct acpi_device *device)
298{ 250{
299 struct proc_dir_entry *entry = NULL; 251 struct proc_dir_entry *entry = NULL;
@@ -306,14 +258,6 @@ static int __cpuinit acpi_processor_add_fs(struct acpi_device *device)
306 return -ENODEV; 258 return -ENODEV;
307 } 259 }
308 260
309 /* 'info' [R] */
310 entry = proc_create_data(ACPI_PROCESSOR_FILE_INFO,
311 S_IRUGO, acpi_device_dir(device),
312 &acpi_processor_info_fops,
313 acpi_driver_data(device));
314 if (!entry)
315 return -EIO;
316
317 /* 'throttling' [R/W] */ 261 /* 'throttling' [R/W] */
318 entry = proc_create_data(ACPI_PROCESSOR_FILE_THROTTLING, 262 entry = proc_create_data(ACPI_PROCESSOR_FILE_THROTTLING,
319 S_IFREG | S_IRUGO | S_IWUSR, 263 S_IFREG | S_IRUGO | S_IWUSR,
@@ -322,43 +266,20 @@ static int __cpuinit acpi_processor_add_fs(struct acpi_device *device)
322 acpi_driver_data(device)); 266 acpi_driver_data(device));
323 if (!entry) 267 if (!entry)
324 return -EIO; 268 return -EIO;
325
326 /* 'limit' [R/W] */
327 entry = proc_create_data(ACPI_PROCESSOR_FILE_LIMIT,
328 S_IFREG | S_IRUGO | S_IWUSR,
329 acpi_device_dir(device),
330 &acpi_processor_limit_fops,
331 acpi_driver_data(device));
332 if (!entry)
333 return -EIO;
334 return 0; 269 return 0;
335} 270}
336static int acpi_processor_remove_fs(struct acpi_device *device) 271static int acpi_processor_remove_fs(struct acpi_device *device)
337{ 272{
338 273
339 if (acpi_device_dir(device)) { 274 if (acpi_device_dir(device)) {
340 remove_proc_entry(ACPI_PROCESSOR_FILE_INFO,
341 acpi_device_dir(device));
342 remove_proc_entry(ACPI_PROCESSOR_FILE_THROTTLING, 275 remove_proc_entry(ACPI_PROCESSOR_FILE_THROTTLING,
343 acpi_device_dir(device)); 276 acpi_device_dir(device));
344 remove_proc_entry(ACPI_PROCESSOR_FILE_LIMIT,
345 acpi_device_dir(device));
346 remove_proc_entry(acpi_device_bid(device), acpi_processor_dir); 277 remove_proc_entry(acpi_device_bid(device), acpi_processor_dir);
347 acpi_device_dir(device) = NULL; 278 acpi_device_dir(device) = NULL;
348 } 279 }
349 280
350 return 0; 281 return 0;
351} 282}
352#else
353static inline int acpi_processor_add_fs(struct acpi_device *device)
354{
355 return 0;
356}
357static inline int acpi_processor_remove_fs(struct acpi_device *device)
358{
359 return 0;
360}
361#endif
362 283
363/* -------------------------------------------------------------------------- 284/* --------------------------------------------------------------------------
364 Driver Interface 285 Driver Interface
@@ -921,11 +842,9 @@ static int __init acpi_processor_init(void)
921 842
922 memset(&errata, 0, sizeof(errata)); 843 memset(&errata, 0, sizeof(errata));
923 844
924#ifdef CONFIG_ACPI_PROCFS
925 acpi_processor_dir = proc_mkdir(ACPI_PROCESSOR_CLASS, acpi_root_dir); 845 acpi_processor_dir = proc_mkdir(ACPI_PROCESSOR_CLASS, acpi_root_dir);
926 if (!acpi_processor_dir) 846 if (!acpi_processor_dir)
927 return -ENOMEM; 847 return -ENOMEM;
928#endif
929 848
930 if (!cpuidle_register_driver(&acpi_idle_driver)) { 849 if (!cpuidle_register_driver(&acpi_idle_driver)) {
931 printk(KERN_DEBUG "ACPI: %s registered with cpuidle\n", 850 printk(KERN_DEBUG "ACPI: %s registered with cpuidle\n",
@@ -952,9 +871,7 @@ static int __init acpi_processor_init(void)
952out_cpuidle: 871out_cpuidle:
953 cpuidle_unregister_driver(&acpi_idle_driver); 872 cpuidle_unregister_driver(&acpi_idle_driver);
954 873
955#ifdef CONFIG_ACPI_PROCFS
956 remove_proc_entry(ACPI_PROCESSOR_CLASS, acpi_root_dir); 874 remove_proc_entry(ACPI_PROCESSOR_CLASS, acpi_root_dir);
957#endif
958 875
959 return result; 876 return result;
960} 877}
@@ -974,9 +891,7 @@ static void __exit acpi_processor_exit(void)
974 891
975 cpuidle_unregister_driver(&acpi_idle_driver); 892 cpuidle_unregister_driver(&acpi_idle_driver);
976 893
977#ifdef CONFIG_ACPI_PROCFS
978 remove_proc_entry(ACPI_PROCESSOR_CLASS, acpi_root_dir); 894 remove_proc_entry(ACPI_PROCESSOR_CLASS, acpi_root_dir);
979#endif
980 895
981 return; 896 return;
982} 897}
diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
index b4c2f3bdadeb..f4428e82b352 100644
--- a/drivers/acpi/processor_idle.c
+++ b/drivers/acpi/processor_idle.c
@@ -33,8 +33,6 @@
33#include <linux/init.h> 33#include <linux/init.h>
34#include <linux/cpufreq.h> 34#include <linux/cpufreq.h>
35#include <linux/slab.h> 35#include <linux/slab.h>
36#include <linux/proc_fs.h>
37#include <linux/seq_file.h>
38#include <linux/acpi.h> 36#include <linux/acpi.h>
39#include <linux/dmi.h> 37#include <linux/dmi.h>
40#include <linux/moduleparam.h> 38#include <linux/moduleparam.h>
@@ -82,13 +80,6 @@ module_param(bm_check_disable, uint, 0000);
82static unsigned int latency_factor __read_mostly = 2; 80static unsigned int latency_factor __read_mostly = 2;
83module_param(latency_factor, uint, 0644); 81module_param(latency_factor, uint, 0644);
84 82
85#ifdef CONFIG_ACPI_PROCFS
86static u64 us_to_pm_timer_ticks(s64 t)
87{
88 return div64_u64(t * PM_TIMER_FREQUENCY, 1000000);
89}
90#endif
91
92/* 83/*
93 * IBM ThinkPad R40e crashes mysteriously when going into C2 or C3. 84 * IBM ThinkPad R40e crashes mysteriously when going into C2 or C3.
94 * For now disable this. Probably a bug somewhere else. 85 * For now disable this. Probably a bug somewhere else.
@@ -689,78 +680,6 @@ static int acpi_processor_get_power_info(struct acpi_processor *pr)
689 return 0; 680 return 0;
690} 681}
691 682
692#ifdef CONFIG_ACPI_PROCFS
693static int acpi_processor_power_seq_show(struct seq_file *seq, void *offset)
694{
695 struct acpi_processor *pr = seq->private;
696 unsigned int i;
697
698
699 if (!pr)
700 goto end;
701
702 seq_printf(seq, "active state: C%zd\n"
703 "max_cstate: C%d\n"
704 "maximum allowed latency: %d usec\n",
705 pr->power.state ? pr->power.state - pr->power.states : 0,
706 max_cstate, pm_qos_request(PM_QOS_CPU_DMA_LATENCY));
707
708 seq_puts(seq, "states:\n");
709
710 for (i = 1; i <= pr->power.count; i++) {
711 seq_printf(seq, " %cC%d: ",
712 (&pr->power.states[i] ==
713 pr->power.state ? '*' : ' '), i);
714
715 if (!pr->power.states[i].valid) {
716 seq_puts(seq, "<not supported>\n");
717 continue;
718 }
719
720 switch (pr->power.states[i].type) {
721 case ACPI_STATE_C1:
722 seq_printf(seq, "type[C1] ");
723 break;
724 case ACPI_STATE_C2:
725 seq_printf(seq, "type[C2] ");
726 break;
727 case ACPI_STATE_C3:
728 seq_printf(seq, "type[C3] ");
729 break;
730 default:
731 seq_printf(seq, "type[--] ");
732 break;
733 }
734
735 seq_puts(seq, "promotion[--] ");
736
737 seq_puts(seq, "demotion[--] ");
738
739 seq_printf(seq, "latency[%03d] usage[%08d] duration[%020Lu]\n",
740 pr->power.states[i].latency,
741 pr->power.states[i].usage,
742 us_to_pm_timer_ticks(pr->power.states[i].time));
743 }
744
745 end:
746 return 0;
747}
748
749static int acpi_processor_power_open_fs(struct inode *inode, struct file *file)
750{
751 return single_open(file, acpi_processor_power_seq_show,
752 PDE(inode)->data);
753}
754
755static const struct file_operations acpi_processor_power_fops = {
756 .owner = THIS_MODULE,
757 .open = acpi_processor_power_open_fs,
758 .read = seq_read,
759 .llseek = seq_lseek,
760 .release = single_release,
761};
762#endif
763
764/** 683/**
765 * acpi_idle_bm_check - checks if bus master activity was detected 684 * acpi_idle_bm_check - checks if bus master activity was detected
766 */ 685 */
@@ -803,13 +722,12 @@ static inline void acpi_idle_do_entry(struct acpi_processor_cx *cx)
803 } else if (cx->entry_method == ACPI_CSTATE_HALT) { 722 } else if (cx->entry_method == ACPI_CSTATE_HALT) {
804 acpi_safe_halt(); 723 acpi_safe_halt();
805 } else { 724 } else {
806 int unused;
807 /* IO port based C-state */ 725 /* IO port based C-state */
808 inb(cx->address); 726 inb(cx->address);
809 /* Dummy wait op - must do something useless after P_LVL2 read 727 /* Dummy wait op - must do something useless after P_LVL2 read
810 because chipsets cannot guarantee that STPCLK# signal 728 because chipsets cannot guarantee that STPCLK# signal
811 gets asserted in time to freeze execution properly. */ 729 gets asserted in time to freeze execution properly. */
812 unused = inl(acpi_gbl_FADT.xpm_timer_block.address); 730 inl(acpi_gbl_FADT.xpm_timer_block.address);
813 } 731 }
814 start_critical_timings(); 732 start_critical_timings();
815} 733}
@@ -1172,9 +1090,6 @@ int __cpuinit acpi_processor_power_init(struct acpi_processor *pr,
1172{ 1090{
1173 acpi_status status = 0; 1091 acpi_status status = 0;
1174 static int first_run; 1092 static int first_run;
1175#ifdef CONFIG_ACPI_PROCFS
1176 struct proc_dir_entry *entry = NULL;
1177#endif
1178 1093
1179 if (boot_option_idle_override) 1094 if (boot_option_idle_override)
1180 return 0; 1095 return 0;
@@ -1223,15 +1138,6 @@ int __cpuinit acpi_processor_power_init(struct acpi_processor *pr,
1223 if (cpuidle_register_device(&pr->power.dev)) 1138 if (cpuidle_register_device(&pr->power.dev))
1224 return -EIO; 1139 return -EIO;
1225 } 1140 }
1226#ifdef CONFIG_ACPI_PROCFS
1227 /* 'power' [R] */
1228 entry = proc_create_data(ACPI_PROCESSOR_FILE_POWER,
1229 S_IRUGO, acpi_device_dir(device),
1230 &acpi_processor_power_fops,
1231 acpi_driver_data(device));
1232 if (!entry)
1233 return -EIO;
1234#endif
1235 return 0; 1141 return 0;
1236} 1142}
1237 1143
@@ -1244,11 +1150,5 @@ int acpi_processor_power_exit(struct acpi_processor *pr,
1244 cpuidle_unregister_device(&pr->power.dev); 1150 cpuidle_unregister_device(&pr->power.dev);
1245 pr->flags.power_setup_done = 0; 1151 pr->flags.power_setup_done = 0;
1246 1152
1247#ifdef CONFIG_ACPI_PROCFS
1248 if (acpi_device_dir(device))
1249 remove_proc_entry(ACPI_PROCESSOR_FILE_POWER,
1250 acpi_device_dir(device));
1251#endif
1252
1253 return 0; 1153 return 0;
1254} 1154}
diff --git a/drivers/acpi/processor_thermal.c b/drivers/acpi/processor_thermal.c
index 6deafb4aa0da..953b25fb9869 100644
--- a/drivers/acpi/processor_thermal.c
+++ b/drivers/acpi/processor_thermal.c
@@ -30,8 +30,6 @@
30#include <linux/module.h> 30#include <linux/module.h>
31#include <linux/init.h> 31#include <linux/init.h>
32#include <linux/cpufreq.h> 32#include <linux/cpufreq.h>
33#include <linux/proc_fs.h>
34#include <linux/seq_file.h>
35#include <linux/sysdev.h> 33#include <linux/sysdev.h>
36 34
37#include <asm/uaccess.h> 35#include <asm/uaccess.h>
@@ -438,84 +436,3 @@ struct thermal_cooling_device_ops processor_cooling_ops = {
438 .get_cur_state = processor_get_cur_state, 436 .get_cur_state = processor_get_cur_state,
439 .set_cur_state = processor_set_cur_state, 437 .set_cur_state = processor_set_cur_state,
440}; 438};
441
442/* /proc interface */
443#ifdef CONFIG_ACPI_PROCFS
444static int acpi_processor_limit_seq_show(struct seq_file *seq, void *offset)
445{
446 struct acpi_processor *pr = seq->private;
447
448 if (!pr)
449 goto end;
450
451 if (!pr->flags.limit) {
452 seq_puts(seq, "<not supported>\n");
453 goto end;
454 }
455
456 seq_printf(seq, "active limit: P%d:T%d\n"
457 "user limit: P%d:T%d\n"
458 "thermal limit: P%d:T%d\n",
459 pr->limit.state.px, pr->limit.state.tx,
460 pr->limit.user.px, pr->limit.user.tx,
461 pr->limit.thermal.px, pr->limit.thermal.tx);
462
463 end:
464 return 0;
465}
466
467static int acpi_processor_limit_open_fs(struct inode *inode, struct file *file)
468{
469 return single_open(file, acpi_processor_limit_seq_show,
470 PDE(inode)->data);
471}
472
473static ssize_t acpi_processor_write_limit(struct file * file,
474 const char __user * buffer,
475 size_t count, loff_t * data)
476{
477 int result = 0;
478 struct seq_file *m = file->private_data;
479 struct acpi_processor *pr = m->private;
480 char limit_string[25] = { '\0' };
481 int px = 0;
482 int tx = 0;
483
484
485 if (!pr || (count > sizeof(limit_string) - 1)) {
486 return -EINVAL;
487 }
488
489 if (copy_from_user(limit_string, buffer, count)) {
490 return -EFAULT;
491 }
492
493 limit_string[count] = '\0';
494
495 if (sscanf(limit_string, "%d:%d", &px, &tx) != 2) {
496 printk(KERN_ERR PREFIX "Invalid data format\n");
497 return -EINVAL;
498 }
499
500 if (pr->flags.throttling) {
501 if ((tx < 0) || (tx > (pr->throttling.state_count - 1))) {
502 printk(KERN_ERR PREFIX "Invalid tx\n");
503 return -EINVAL;
504 }
505 pr->limit.user.tx = tx;
506 }
507
508 result = acpi_processor_apply_limit(pr);
509
510 return count;
511}
512
513const struct file_operations acpi_processor_limit_fops = {
514 .owner = THIS_MODULE,
515 .open = acpi_processor_limit_open_fs,
516 .read = seq_read,
517 .write = acpi_processor_write_limit,
518 .llseek = seq_lseek,
519 .release = single_release,
520};
521#endif
diff --git a/drivers/acpi/processor_throttling.c b/drivers/acpi/processor_throttling.c
index 9ade1a5b32ed..730863855ed5 100644
--- a/drivers/acpi/processor_throttling.c
+++ b/drivers/acpi/processor_throttling.c
@@ -1215,7 +1215,6 @@ int acpi_processor_get_throttling_info(struct acpi_processor *pr)
1215} 1215}
1216 1216
1217/* proc interface */ 1217/* proc interface */
1218#ifdef CONFIG_ACPI_PROCFS
1219static int acpi_processor_throttling_seq_show(struct seq_file *seq, 1218static int acpi_processor_throttling_seq_show(struct seq_file *seq,
1220 void *offset) 1219 void *offset)
1221{ 1220{
@@ -1323,4 +1322,3 @@ const struct file_operations acpi_processor_throttling_fops = {
1323 .llseek = seq_lseek, 1322 .llseek = seq_lseek,
1324 .release = single_release, 1323 .release = single_release,
1325}; 1324};
1326#endif
diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c
index e143203254a4..cf82989ae756 100644
--- a/drivers/acpi/sleep.c
+++ b/drivers/acpi/sleep.c
@@ -70,10 +70,10 @@ static int acpi_sleep_prepare(u32 acpi_state)
70 70
71 } 71 }
72 ACPI_FLUSH_CPU_CACHE(); 72 ACPI_FLUSH_CPU_CACHE();
73 acpi_enable_wakeup_device_prep(acpi_state);
74#endif 73#endif
75 printk(KERN_INFO PREFIX "Preparing to enter system sleep state S%d\n", 74 printk(KERN_INFO PREFIX "Preparing to enter system sleep state S%d\n",
76 acpi_state); 75 acpi_state);
76 acpi_enable_wakeup_devices(acpi_state);
77 acpi_enter_sleep_state_prep(acpi_state); 77 acpi_enter_sleep_state_prep(acpi_state);
78 return 0; 78 return 0;
79} 79}
@@ -119,6 +119,16 @@ static int acpi_pm_freeze(void)
119} 119}
120 120
121/** 121/**
122 * acpi_pre_suspend - Enable wakeup devices, "freeze" EC and save NVS.
123 */
124static int acpi_pm_pre_suspend(void)
125{
126 acpi_pm_freeze();
127 suspend_nvs_save();
128 return 0;
129}
130
131/**
122 * __acpi_pm_prepare - Prepare the platform to enter the target state. 132 * __acpi_pm_prepare - Prepare the platform to enter the target state.
123 * 133 *
124 * If necessary, set the firmware waking vector and do arch-specific 134 * If necessary, set the firmware waking vector and do arch-specific
@@ -127,11 +137,9 @@ static int acpi_pm_freeze(void)
127static int __acpi_pm_prepare(void) 137static int __acpi_pm_prepare(void)
128{ 138{
129 int error = acpi_sleep_prepare(acpi_target_sleep_state); 139 int error = acpi_sleep_prepare(acpi_target_sleep_state);
130
131 suspend_nvs_save();
132
133 if (error) 140 if (error)
134 acpi_target_sleep_state = ACPI_STATE_S0; 141 acpi_target_sleep_state = ACPI_STATE_S0;
142
135 return error; 143 return error;
136} 144}
137 145
@@ -142,9 +150,8 @@ static int __acpi_pm_prepare(void)
142static int acpi_pm_prepare(void) 150static int acpi_pm_prepare(void)
143{ 151{
144 int error = __acpi_pm_prepare(); 152 int error = __acpi_pm_prepare();
145
146 if (!error) 153 if (!error)
147 acpi_pm_freeze(); 154 acpi_pm_pre_suspend();
148 155
149 return error; 156 return error;
150} 157}
@@ -159,7 +166,6 @@ static void acpi_pm_finish(void)
159{ 166{
160 u32 acpi_state = acpi_target_sleep_state; 167 u32 acpi_state = acpi_target_sleep_state;
161 168
162 suspend_nvs_free();
163 acpi_ec_unblock_transactions(); 169 acpi_ec_unblock_transactions();
164 170
165 if (acpi_state == ACPI_STATE_S0) 171 if (acpi_state == ACPI_STATE_S0)
@@ -167,7 +173,7 @@ static void acpi_pm_finish(void)
167 173
168 printk(KERN_INFO PREFIX "Waking up from system sleep state S%d\n", 174 printk(KERN_INFO PREFIX "Waking up from system sleep state S%d\n",
169 acpi_state); 175 acpi_state);
170 acpi_disable_wakeup_device(acpi_state); 176 acpi_disable_wakeup_devices(acpi_state);
171 acpi_leave_sleep_state(acpi_state); 177 acpi_leave_sleep_state(acpi_state);
172 178
173 /* reset firmware waking vector */ 179 /* reset firmware waking vector */
@@ -181,6 +187,7 @@ static void acpi_pm_finish(void)
181 */ 187 */
182static void acpi_pm_end(void) 188static void acpi_pm_end(void)
183{ 189{
190 suspend_nvs_free();
184 /* 191 /*
185 * This is necessary in case acpi_pm_finish() is not called during a 192 * This is necessary in case acpi_pm_finish() is not called during a
186 * failing transition to a sleep state. 193 * failing transition to a sleep state.
@@ -251,7 +258,6 @@ static int acpi_suspend_enter(suspend_state_t pm_state)
251 } 258 }
252 259
253 local_irq_save(flags); 260 local_irq_save(flags);
254 acpi_enable_wakeup_device(acpi_state);
255 switch (acpi_state) { 261 switch (acpi_state) {
256 case ACPI_STATE_S1: 262 case ACPI_STATE_S1:
257 barrier(); 263 barrier();
@@ -297,11 +303,6 @@ static int acpi_suspend_enter(suspend_state_t pm_state)
297 return ACPI_SUCCESS(status) ? 0 : -EFAULT; 303 return ACPI_SUCCESS(status) ? 0 : -EFAULT;
298} 304}
299 305
300static void acpi_suspend_finish(void)
301{
302 acpi_pm_finish();
303}
304
305static int acpi_suspend_state_valid(suspend_state_t pm_state) 306static int acpi_suspend_state_valid(suspend_state_t pm_state)
306{ 307{
307 u32 acpi_state; 308 u32 acpi_state;
@@ -323,7 +324,7 @@ static struct platform_suspend_ops acpi_suspend_ops = {
323 .begin = acpi_suspend_begin, 324 .begin = acpi_suspend_begin,
324 .prepare_late = acpi_pm_prepare, 325 .prepare_late = acpi_pm_prepare,
325 .enter = acpi_suspend_enter, 326 .enter = acpi_suspend_enter,
326 .wake = acpi_suspend_finish, 327 .wake = acpi_pm_finish,
327 .end = acpi_pm_end, 328 .end = acpi_pm_end,
328}; 329};
329 330
@@ -336,9 +337,9 @@ static struct platform_suspend_ops acpi_suspend_ops = {
336static int acpi_suspend_begin_old(suspend_state_t pm_state) 337static int acpi_suspend_begin_old(suspend_state_t pm_state)
337{ 338{
338 int error = acpi_suspend_begin(pm_state); 339 int error = acpi_suspend_begin(pm_state);
339
340 if (!error) 340 if (!error)
341 error = __acpi_pm_prepare(); 341 error = __acpi_pm_prepare();
342
342 return error; 343 return error;
343} 344}
344 345
@@ -349,9 +350,9 @@ static int acpi_suspend_begin_old(suspend_state_t pm_state)
349static struct platform_suspend_ops acpi_suspend_ops_old = { 350static struct platform_suspend_ops acpi_suspend_ops_old = {
350 .valid = acpi_suspend_state_valid, 351 .valid = acpi_suspend_state_valid,
351 .begin = acpi_suspend_begin_old, 352 .begin = acpi_suspend_begin_old,
352 .prepare_late = acpi_pm_freeze, 353 .prepare_late = acpi_pm_pre_suspend,
353 .enter = acpi_suspend_enter, 354 .enter = acpi_suspend_enter,
354 .wake = acpi_suspend_finish, 355 .wake = acpi_pm_finish,
355 .end = acpi_pm_end, 356 .end = acpi_pm_end,
356 .recover = acpi_pm_finish, 357 .recover = acpi_pm_finish,
357}; 358};
@@ -423,16 +424,6 @@ static int acpi_hibernation_begin(void)
423 return error; 424 return error;
424} 425}
425 426
426static int acpi_hibernation_pre_snapshot(void)
427{
428 int error = acpi_pm_prepare();
429
430 if (!error)
431 suspend_nvs_save();
432
433 return error;
434}
435
436static int acpi_hibernation_enter(void) 427static int acpi_hibernation_enter(void)
437{ 428{
438 acpi_status status = AE_OK; 429 acpi_status status = AE_OK;
@@ -441,7 +432,6 @@ static int acpi_hibernation_enter(void)
441 ACPI_FLUSH_CPU_CACHE(); 432 ACPI_FLUSH_CPU_CACHE();
442 433
443 local_irq_save(flags); 434 local_irq_save(flags);
444 acpi_enable_wakeup_device(ACPI_STATE_S4);
445 /* This shouldn't return. If it returns, we have a problem */ 435 /* This shouldn't return. If it returns, we have a problem */
446 status = acpi_enter_sleep_state(ACPI_STATE_S4); 436 status = acpi_enter_sleep_state(ACPI_STATE_S4);
447 /* Reprogram control registers and execute _BFS */ 437 /* Reprogram control registers and execute _BFS */
@@ -481,7 +471,7 @@ static void acpi_pm_thaw(void)
481static struct platform_hibernation_ops acpi_hibernation_ops = { 471static struct platform_hibernation_ops acpi_hibernation_ops = {
482 .begin = acpi_hibernation_begin, 472 .begin = acpi_hibernation_begin,
483 .end = acpi_pm_end, 473 .end = acpi_pm_end,
484 .pre_snapshot = acpi_hibernation_pre_snapshot, 474 .pre_snapshot = acpi_pm_prepare,
485 .finish = acpi_pm_finish, 475 .finish = acpi_pm_finish,
486 .prepare = acpi_pm_prepare, 476 .prepare = acpi_pm_prepare,
487 .enter = acpi_hibernation_enter, 477 .enter = acpi_hibernation_enter,
@@ -517,13 +507,6 @@ static int acpi_hibernation_begin_old(void)
517 return error; 507 return error;
518} 508}
519 509
520static int acpi_hibernation_pre_snapshot_old(void)
521{
522 acpi_pm_freeze();
523 suspend_nvs_save();
524 return 0;
525}
526
527/* 510/*
528 * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has 511 * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
529 * been requested. 512 * been requested.
@@ -531,7 +514,7 @@ static int acpi_hibernation_pre_snapshot_old(void)
531static struct platform_hibernation_ops acpi_hibernation_ops_old = { 514static struct platform_hibernation_ops acpi_hibernation_ops_old = {
532 .begin = acpi_hibernation_begin_old, 515 .begin = acpi_hibernation_begin_old,
533 .end = acpi_pm_end, 516 .end = acpi_pm_end,
534 .pre_snapshot = acpi_hibernation_pre_snapshot_old, 517 .pre_snapshot = acpi_pm_pre_suspend,
535 .prepare = acpi_pm_freeze, 518 .prepare = acpi_pm_freeze,
536 .finish = acpi_pm_finish, 519 .finish = acpi_pm_finish,
537 .enter = acpi_hibernation_enter, 520 .enter = acpi_hibernation_enter,
@@ -686,7 +669,6 @@ static void acpi_power_off(void)
686 /* acpi_sleep_prepare(ACPI_STATE_S5) should have already been called */ 669 /* acpi_sleep_prepare(ACPI_STATE_S5) should have already been called */
687 printk(KERN_DEBUG "%s called\n", __func__); 670 printk(KERN_DEBUG "%s called\n", __func__);
688 local_irq_disable(); 671 local_irq_disable();
689 acpi_enable_wakeup_device(ACPI_STATE_S5);
690 acpi_enter_sleep_state(ACPI_STATE_S5); 672 acpi_enter_sleep_state(ACPI_STATE_S5);
691} 673}
692 674
diff --git a/drivers/acpi/sleep.h b/drivers/acpi/sleep.h
index 25b8bd149284..d8821805c3bc 100644
--- a/drivers/acpi/sleep.h
+++ b/drivers/acpi/sleep.h
@@ -2,9 +2,8 @@
2extern u8 sleep_states[]; 2extern u8 sleep_states[];
3extern int acpi_suspend(u32 state); 3extern int acpi_suspend(u32 state);
4 4
5extern void acpi_enable_wakeup_device_prep(u8 sleep_state); 5extern void acpi_enable_wakeup_devices(u8 sleep_state);
6extern void acpi_enable_wakeup_device(u8 sleep_state); 6extern void acpi_disable_wakeup_devices(u8 sleep_state);
7extern void acpi_disable_wakeup_device(u8 sleep_state);
8 7
9extern struct list_head acpi_wakeup_device_list; 8extern struct list_head acpi_wakeup_device_list;
10extern struct mutex acpi_device_lock; 9extern struct mutex acpi_device_lock;
diff --git a/drivers/acpi/system.c b/drivers/acpi/sysfs.c
index 5981bd07e20e..68e2e4582fa2 100644
--- a/drivers/acpi/system.c
+++ b/drivers/acpi/sysfs.c
@@ -1,51 +1,218 @@
1/* 1/*
2 * acpi_system.c - ACPI System Driver ($Revision: 63 $) 2 * sysfs.c - ACPI sysfs interface to userspace.
3 *
4 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
5 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
6 *
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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 (at
12 * your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
22 *
23 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
24 */ 3 */
25 4
26#include <linux/proc_fs.h>
27#include <linux/seq_file.h>
28#include <linux/slab.h>
29#include <linux/init.h> 5#include <linux/init.h>
30#include <linux/string.h> 6#include <linux/kernel.h>
31#include <asm/uaccess.h> 7#include <linux/moduleparam.h>
32
33#include <acpi/acpi_drivers.h> 8#include <acpi/acpi_drivers.h>
34 9
35#define PREFIX "ACPI: "
36
37#define _COMPONENT ACPI_SYSTEM_COMPONENT 10#define _COMPONENT ACPI_SYSTEM_COMPONENT
38ACPI_MODULE_NAME("system"); 11ACPI_MODULE_NAME("sysfs");
39
40#define ACPI_SYSTEM_CLASS "system"
41#define ACPI_SYSTEM_DEVICE_NAME "System"
42 12
43u32 acpi_irq_handled; 13#define PREFIX "ACPI: "
44u32 acpi_irq_not_handled;
45 14
15#ifdef CONFIG_ACPI_DEBUG
46/* 16/*
47 * Make ACPICA version work as module param 17 * ACPI debug sysfs I/F, including:
18 * /sys/modules/acpi/parameters/debug_layer
19 * /sys/modules/acpi/parameters/debug_level
20 * /sys/modules/acpi/parameters/trace_method_name
21 * /sys/modules/acpi/parameters/trace_state
22 * /sys/modules/acpi/parameters/trace_debug_layer
23 * /sys/modules/acpi/parameters/trace_debug_level
48 */ 24 */
25
26struct acpi_dlayer {
27 const char *name;
28 unsigned long value;
29};
30struct acpi_dlevel {
31 const char *name;
32 unsigned long value;
33};
34#define ACPI_DEBUG_INIT(v) { .name = #v, .value = v }
35
36static const struct acpi_dlayer acpi_debug_layers[] = {
37 ACPI_DEBUG_INIT(ACPI_UTILITIES),
38 ACPI_DEBUG_INIT(ACPI_HARDWARE),
39 ACPI_DEBUG_INIT(ACPI_EVENTS),
40 ACPI_DEBUG_INIT(ACPI_TABLES),
41 ACPI_DEBUG_INIT(ACPI_NAMESPACE),
42 ACPI_DEBUG_INIT(ACPI_PARSER),
43 ACPI_DEBUG_INIT(ACPI_DISPATCHER),
44 ACPI_DEBUG_INIT(ACPI_EXECUTER),
45 ACPI_DEBUG_INIT(ACPI_RESOURCES),
46 ACPI_DEBUG_INIT(ACPI_CA_DEBUGGER),
47 ACPI_DEBUG_INIT(ACPI_OS_SERVICES),
48 ACPI_DEBUG_INIT(ACPI_CA_DISASSEMBLER),
49 ACPI_DEBUG_INIT(ACPI_COMPILER),
50 ACPI_DEBUG_INIT(ACPI_TOOLS),
51
52 ACPI_DEBUG_INIT(ACPI_BUS_COMPONENT),
53 ACPI_DEBUG_INIT(ACPI_AC_COMPONENT),
54 ACPI_DEBUG_INIT(ACPI_BATTERY_COMPONENT),
55 ACPI_DEBUG_INIT(ACPI_BUTTON_COMPONENT),
56 ACPI_DEBUG_INIT(ACPI_SBS_COMPONENT),
57 ACPI_DEBUG_INIT(ACPI_FAN_COMPONENT),
58 ACPI_DEBUG_INIT(ACPI_PCI_COMPONENT),
59 ACPI_DEBUG_INIT(ACPI_POWER_COMPONENT),
60 ACPI_DEBUG_INIT(ACPI_CONTAINER_COMPONENT),
61 ACPI_DEBUG_INIT(ACPI_SYSTEM_COMPONENT),
62 ACPI_DEBUG_INIT(ACPI_THERMAL_COMPONENT),
63 ACPI_DEBUG_INIT(ACPI_MEMORY_DEVICE_COMPONENT),
64 ACPI_DEBUG_INIT(ACPI_VIDEO_COMPONENT),
65 ACPI_DEBUG_INIT(ACPI_PROCESSOR_COMPONENT),
66};
67
68static const struct acpi_dlevel acpi_debug_levels[] = {
69 ACPI_DEBUG_INIT(ACPI_LV_INIT),
70 ACPI_DEBUG_INIT(ACPI_LV_DEBUG_OBJECT),
71 ACPI_DEBUG_INIT(ACPI_LV_INFO),
72
73 ACPI_DEBUG_INIT(ACPI_LV_INIT_NAMES),
74 ACPI_DEBUG_INIT(ACPI_LV_PARSE),
75 ACPI_DEBUG_INIT(ACPI_LV_LOAD),
76 ACPI_DEBUG_INIT(ACPI_LV_DISPATCH),
77 ACPI_DEBUG_INIT(ACPI_LV_EXEC),
78 ACPI_DEBUG_INIT(ACPI_LV_NAMES),
79 ACPI_DEBUG_INIT(ACPI_LV_OPREGION),
80 ACPI_DEBUG_INIT(ACPI_LV_BFIELD),
81 ACPI_DEBUG_INIT(ACPI_LV_TABLES),
82 ACPI_DEBUG_INIT(ACPI_LV_VALUES),
83 ACPI_DEBUG_INIT(ACPI_LV_OBJECTS),
84 ACPI_DEBUG_INIT(ACPI_LV_RESOURCES),
85 ACPI_DEBUG_INIT(ACPI_LV_USER_REQUESTS),
86 ACPI_DEBUG_INIT(ACPI_LV_PACKAGE),
87
88 ACPI_DEBUG_INIT(ACPI_LV_ALLOCATIONS),
89 ACPI_DEBUG_INIT(ACPI_LV_FUNCTIONS),
90 ACPI_DEBUG_INIT(ACPI_LV_OPTIMIZATIONS),
91
92 ACPI_DEBUG_INIT(ACPI_LV_MUTEX),
93 ACPI_DEBUG_INIT(ACPI_LV_THREADS),
94 ACPI_DEBUG_INIT(ACPI_LV_IO),
95 ACPI_DEBUG_INIT(ACPI_LV_INTERRUPTS),
96
97 ACPI_DEBUG_INIT(ACPI_LV_AML_DISASSEMBLE),
98 ACPI_DEBUG_INIT(ACPI_LV_VERBOSE_INFO),
99 ACPI_DEBUG_INIT(ACPI_LV_FULL_TABLES),
100 ACPI_DEBUG_INIT(ACPI_LV_EVENTS),
101};
102
103static int param_get_debug_layer(char *buffer, struct kernel_param *kp)
104{
105 int result = 0;
106 int i;
107
108 result = sprintf(buffer, "%-25s\tHex SET\n", "Description");
109
110 for (i = 0; i < ARRAY_SIZE(acpi_debug_layers); i++) {
111 result += sprintf(buffer + result, "%-25s\t0x%08lX [%c]\n",
112 acpi_debug_layers[i].name,
113 acpi_debug_layers[i].value,
114 (acpi_dbg_layer & acpi_debug_layers[i].value)
115 ? '*' : ' ');
116 }
117 result +=
118 sprintf(buffer + result, "%-25s\t0x%08X [%c]\n", "ACPI_ALL_DRIVERS",
119 ACPI_ALL_DRIVERS,
120 (acpi_dbg_layer & ACPI_ALL_DRIVERS) ==
121 ACPI_ALL_DRIVERS ? '*' : (acpi_dbg_layer & ACPI_ALL_DRIVERS)
122 == 0 ? ' ' : '-');
123 result +=
124 sprintf(buffer + result,
125 "--\ndebug_layer = 0x%08X ( * = enabled)\n",
126 acpi_dbg_layer);
127
128 return result;
129}
130
131static int param_get_debug_level(char *buffer, struct kernel_param *kp)
132{
133 int result = 0;
134 int i;
135
136 result = sprintf(buffer, "%-25s\tHex SET\n", "Description");
137
138 for (i = 0; i < ARRAY_SIZE(acpi_debug_levels); i++) {
139 result += sprintf(buffer + result, "%-25s\t0x%08lX [%c]\n",
140 acpi_debug_levels[i].name,
141 acpi_debug_levels[i].value,
142 (acpi_dbg_level & acpi_debug_levels[i].value)
143 ? '*' : ' ');
144 }
145 result +=
146 sprintf(buffer + result, "--\ndebug_level = 0x%08X (* = enabled)\n",
147 acpi_dbg_level);
148
149 return result;
150}
151
152module_param_call(debug_layer, param_set_uint, param_get_debug_layer,
153 &acpi_dbg_layer, 0644);
154module_param_call(debug_level, param_set_uint, param_get_debug_level,
155 &acpi_dbg_level, 0644);
156
157static char trace_method_name[6];
158module_param_string(trace_method_name, trace_method_name, 6, 0644);
159static unsigned int trace_debug_layer;
160module_param(trace_debug_layer, uint, 0644);
161static unsigned int trace_debug_level;
162module_param(trace_debug_level, uint, 0644);
163
164static int param_set_trace_state(const char *val, struct kernel_param *kp)
165{
166 int result = 0;
167
168 if (!strncmp(val, "enable", strlen("enable") - 1)) {
169 result = acpi_debug_trace(trace_method_name, trace_debug_level,
170 trace_debug_layer, 0);
171 if (result)
172 result = -EBUSY;
173 goto exit;
174 }
175
176 if (!strncmp(val, "disable", strlen("disable") - 1)) {
177 int name = 0;
178 result = acpi_debug_trace((char *)&name, trace_debug_level,
179 trace_debug_layer, 0);
180 if (result)
181 result = -EBUSY;
182 goto exit;
183 }
184
185 if (!strncmp(val, "1", 1)) {
186 result = acpi_debug_trace(trace_method_name, trace_debug_level,
187 trace_debug_layer, 1);
188 if (result)
189 result = -EBUSY;
190 goto exit;
191 }
192
193 result = -EINVAL;
194exit:
195 return result;
196}
197
198static int param_get_trace_state(char *buffer, struct kernel_param *kp)
199{
200 if (!acpi_gbl_trace_method_name)
201 return sprintf(buffer, "disable");
202 else {
203 if (acpi_gbl_trace_flags & 1)
204 return sprintf(buffer, "1");
205 else
206 return sprintf(buffer, "enable");
207 }
208 return 0;
209}
210
211module_param_call(trace_state, param_set_trace_state, param_get_trace_state,
212 NULL, 0644);
213#endif /* CONFIG_ACPI_DEBUG */
214
215/* /sys/module/acpi/parameters/acpica_version */
49static int param_get_acpica_version(char *buffer, struct kernel_param *kp) 216static int param_get_acpica_version(char *buffer, struct kernel_param *kp)
50{ 217{
51 int result; 218 int result;
@@ -57,9 +224,12 @@ static int param_get_acpica_version(char *buffer, struct kernel_param *kp)
57 224
58module_param_call(acpica_version, NULL, param_get_acpica_version, NULL, 0444); 225module_param_call(acpica_version, NULL, param_get_acpica_version, NULL, 0444);
59 226
60/* -------------------------------------------------------------------------- 227/*
61 FS Interface (/sys) 228 * ACPI table sysfs I/F:
62 -------------------------------------------------------------------------- */ 229 * /sys/firmware/acpi/tables/
230 * /sys/firmware/acpi/tables/dynamic/
231 */
232
63static LIST_HEAD(acpi_table_attr_list); 233static LIST_HEAD(acpi_table_attr_list);
64static struct kobject *tables_kobj; 234static struct kobject *tables_kobj;
65static struct kobject *dynamic_tables_kobj; 235static struct kobject *dynamic_tables_kobj;
@@ -86,14 +256,12 @@ static ssize_t acpi_table_show(struct file *filp, struct kobject *kobj,
86 else 256 else
87 memcpy(name, "\0\0\0\0", 4); 257 memcpy(name, "\0\0\0\0", 4);
88 258
89 status = 259 status = acpi_get_table(name, table_attr->instance, &table_header);
90 acpi_get_table(name, table_attr->instance,
91 &table_header);
92 if (ACPI_FAILURE(status)) 260 if (ACPI_FAILURE(status))
93 return -ENODEV; 261 return -ENODEV;
94 262
95 return memory_read_from_buffer(buf, count, &offset, 263 return memory_read_from_buffer(buf, count, &offset,
96 table_header, table_header->length); 264 table_header, table_header->length);
97} 265}
98 266
99static void acpi_table_attr_init(struct acpi_table_attr *table_attr, 267static void acpi_table_attr_init(struct acpi_table_attr *table_attr,
@@ -105,7 +273,7 @@ static void acpi_table_attr_init(struct acpi_table_attr *table_attr,
105 sysfs_attr_init(&table_attr->attr.attr); 273 sysfs_attr_init(&table_attr->attr.attr);
106 if (table_header->signature[0] != '\0') 274 if (table_header->signature[0] != '\0')
107 memcpy(table_attr->name, table_header->signature, 275 memcpy(table_attr->name, table_header->signature,
108 ACPI_NAME_SIZE); 276 ACPI_NAME_SIZE);
109 else 277 else
110 memcpy(table_attr->name, "NULL", 4); 278 memcpy(table_attr->name, "NULL", 4);
111 279
@@ -117,8 +285,8 @@ static void acpi_table_attr_init(struct acpi_table_attr *table_attr,
117 table_attr->instance++; 285 table_attr->instance++;
118 286
119 if (table_attr->instance > 1 || (table_attr->instance == 1 && 287 if (table_attr->instance > 1 || (table_attr->instance == 1 &&
120 !acpi_get_table 288 !acpi_get_table
121 (table_header->signature, 2, &header))) 289 (table_header->signature, 2, &header)))
122 sprintf(table_attr->name + ACPI_NAME_SIZE, "%d", 290 sprintf(table_attr->name + ACPI_NAME_SIZE, "%d",
123 table_attr->instance); 291 table_attr->instance);
124 292
@@ -138,18 +306,17 @@ acpi_sysfs_table_handler(u32 event, void *table, void *context)
138 switch (event) { 306 switch (event) {
139 case ACPI_TABLE_EVENT_LOAD: 307 case ACPI_TABLE_EVENT_LOAD:
140 table_attr = 308 table_attr =
141 kzalloc(sizeof(struct acpi_table_attr), GFP_KERNEL); 309 kzalloc(sizeof(struct acpi_table_attr), GFP_KERNEL);
142 if (!table_attr) 310 if (!table_attr)
143 return AE_NO_MEMORY; 311 return AE_NO_MEMORY;
144 312
145 acpi_table_attr_init(table_attr, table); 313 acpi_table_attr_init(table_attr, table);
146 if (sysfs_create_bin_file(dynamic_tables_kobj, 314 if (sysfs_create_bin_file(dynamic_tables_kobj,
147 &table_attr->attr)) { 315 &table_attr->attr)) {
148 kfree(table_attr); 316 kfree(table_attr);
149 return AE_ERROR; 317 return AE_ERROR;
150 } else 318 } else
151 list_add_tail(&table_attr->node, 319 list_add_tail(&table_attr->node, &acpi_table_attr_list);
152 &acpi_table_attr_list);
153 break; 320 break;
154 case ACPI_TABLE_EVENT_UNLOAD: 321 case ACPI_TABLE_EVENT_UNLOAD:
155 /* 322 /*
@@ -164,7 +331,7 @@ acpi_sysfs_table_handler(u32 event, void *table, void *context)
164 return AE_OK; 331 return AE_OK;
165} 332}
166 333
167static int acpi_system_sysfs_init(void) 334static int acpi_tables_sysfs_init(void)
168{ 335{
169 struct acpi_table_attr *table_attr; 336 struct acpi_table_attr *table_attr;
170 struct acpi_table_header *table_header = NULL; 337 struct acpi_table_header *table_header = NULL;
@@ -213,14 +380,17 @@ err:
213} 380}
214 381
215/* 382/*
216 * Detailed ACPI IRQ counters in /sys/firmware/acpi/interrupts/ 383 * Detailed ACPI IRQ counters:
217 * See Documentation/ABI/testing/sysfs-firmware-acpi 384 * /sys/firmware/acpi/interrupts/
218 */ 385 */
219 386
387u32 acpi_irq_handled;
388u32 acpi_irq_not_handled;
389
220#define COUNT_GPE 0 390#define COUNT_GPE 0
221#define COUNT_SCI 1 /* acpi_irq_handled */ 391#define COUNT_SCI 1 /* acpi_irq_handled */
222#define COUNT_SCI_NOT 2 /* acpi_irq_not_handled */ 392#define COUNT_SCI_NOT 2 /* acpi_irq_not_handled */
223#define COUNT_ERROR 3 /* other */ 393#define COUNT_ERROR 3 /* other */
224#define NUM_COUNTERS_EXTRA 4 394#define NUM_COUNTERS_EXTRA 4
225 395
226struct event_counter { 396struct event_counter {
@@ -237,6 +407,7 @@ static u32 acpi_gpe_count;
237static struct attribute_group interrupt_stats_attr_group = { 407static struct attribute_group interrupt_stats_attr_group = {
238 .name = "interrupts", 408 .name = "interrupts",
239}; 409};
410
240static struct kobj_attribute *counter_attrs; 411static struct kobj_attribute *counter_attrs;
241 412
242static void delete_gpe_attr_array(void) 413static void delete_gpe_attr_array(void)
@@ -269,8 +440,8 @@ void acpi_os_gpe_count(u32 gpe_number)
269 if (gpe_number < num_gpes) 440 if (gpe_number < num_gpes)
270 all_counters[gpe_number].count++; 441 all_counters[gpe_number].count++;
271 else 442 else
272 all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_ERROR]. 443 all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS +
273 count++; 444 COUNT_ERROR].count++;
274 445
275 return; 446 return;
276} 447}
@@ -283,13 +454,14 @@ void acpi_os_fixed_event_count(u32 event_number)
283 if (event_number < ACPI_NUM_FIXED_EVENTS) 454 if (event_number < ACPI_NUM_FIXED_EVENTS)
284 all_counters[num_gpes + event_number].count++; 455 all_counters[num_gpes + event_number].count++;
285 else 456 else
286 all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_ERROR]. 457 all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS +
287 count++; 458 COUNT_ERROR].count++;
288 459
289 return; 460 return;
290} 461}
291 462
292static int get_status(u32 index, acpi_event_status *status, acpi_handle *handle) 463static int get_status(u32 index, acpi_event_status *status,
464 acpi_handle *handle)
293{ 465{
294 int result = 0; 466 int result = 0;
295 467
@@ -300,7 +472,7 @@ static int get_status(u32 index, acpi_event_status *status, acpi_handle *handle)
300 result = acpi_get_gpe_device(index, handle); 472 result = acpi_get_gpe_device(index, handle);
301 if (result) { 473 if (result) {
302 ACPI_EXCEPTION((AE_INFO, AE_NOT_FOUND, 474 ACPI_EXCEPTION((AE_INFO, AE_NOT_FOUND,
303 "Invalid GPE 0x%x\n", index)); 475 "Invalid GPE 0x%x\n", index));
304 goto end; 476 goto end;
305 } 477 }
306 result = acpi_get_gpe_status(*handle, index, status); 478 result = acpi_get_gpe_status(*handle, index, status);
@@ -312,7 +484,7 @@ end:
312} 484}
313 485
314static ssize_t counter_show(struct kobject *kobj, 486static ssize_t counter_show(struct kobject *kobj,
315 struct kobj_attribute *attr, char *buf) 487 struct kobj_attribute *attr, char *buf)
316{ 488{
317 int index = attr - counter_attrs; 489 int index = attr - counter_attrs;
318 int size; 490 int size;
@@ -321,12 +493,11 @@ static ssize_t counter_show(struct kobject *kobj,
321 int result = 0; 493 int result = 0;
322 494
323 all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI].count = 495 all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI].count =
324 acpi_irq_handled; 496 acpi_irq_handled;
325 all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI_NOT].count = 497 all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI_NOT].count =
326 acpi_irq_not_handled; 498 acpi_irq_not_handled;
327 all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_GPE].count = 499 all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_GPE].count =
328 acpi_gpe_count; 500 acpi_gpe_count;
329
330 size = sprintf(buf, "%8d", all_counters[index].count); 501 size = sprintf(buf, "%8d", all_counters[index].count);
331 502
332 /* "gpe_all" or "sci" */ 503 /* "gpe_all" or "sci" */
@@ -338,13 +509,13 @@ static ssize_t counter_show(struct kobject *kobj,
338 goto end; 509 goto end;
339 510
340 if (!(status & ACPI_EVENT_FLAG_HANDLE)) 511 if (!(status & ACPI_EVENT_FLAG_HANDLE))
341 size += sprintf(buf + size, " invalid"); 512 size += sprintf(buf + size, " invalid");
342 else if (status & ACPI_EVENT_FLAG_ENABLED) 513 else if (status & ACPI_EVENT_FLAG_ENABLED)
343 size += sprintf(buf + size, " enabled"); 514 size += sprintf(buf + size, " enabled");
344 else if (status & ACPI_EVENT_FLAG_WAKE_ENABLED) 515 else if (status & ACPI_EVENT_FLAG_WAKE_ENABLED)
345 size += sprintf(buf + size, " wake_enabled"); 516 size += sprintf(buf + size, " wake_enabled");
346 else 517 else
347 size += sprintf(buf + size, " disabled"); 518 size += sprintf(buf + size, " disabled");
348 519
349end: 520end:
350 size += sprintf(buf + size, "\n"); 521 size += sprintf(buf + size, "\n");
@@ -357,7 +528,8 @@ end:
357 * enable/disable/clear a gpe/fixed event in user space. 528 * enable/disable/clear a gpe/fixed event in user space.
358 */ 529 */
359static ssize_t counter_set(struct kobject *kobj, 530static ssize_t counter_set(struct kobject *kobj,
360 struct kobj_attribute *attr, const char *buf, size_t size) 531 struct kobj_attribute *attr, const char *buf,
532 size_t size)
361{ 533{
362 int index = attr - counter_attrs; 534 int index = attr - counter_attrs;
363 acpi_event_status status; 535 acpi_event_status status;
@@ -381,32 +553,32 @@ static ssize_t counter_set(struct kobject *kobj,
381 553
382 if (!(status & ACPI_EVENT_FLAG_HANDLE)) { 554 if (!(status & ACPI_EVENT_FLAG_HANDLE)) {
383 printk(KERN_WARNING PREFIX 555 printk(KERN_WARNING PREFIX
384 "Can not change Invalid GPE/Fixed Event status\n"); 556 "Can not change Invalid GPE/Fixed Event status\n");
385 return -EINVAL; 557 return -EINVAL;
386 } 558 }
387 559
388 if (index < num_gpes) { 560 if (index < num_gpes) {
389 if (!strcmp(buf, "disable\n") && 561 if (!strcmp(buf, "disable\n") &&
390 (status & ACPI_EVENT_FLAG_ENABLED)) 562 (status & ACPI_EVENT_FLAG_ENABLED))
391 result = acpi_disable_gpe(handle, index); 563 result = acpi_disable_gpe(handle, index);
392 else if (!strcmp(buf, "enable\n") && 564 else if (!strcmp(buf, "enable\n") &&
393 !(status & ACPI_EVENT_FLAG_ENABLED)) 565 !(status & ACPI_EVENT_FLAG_ENABLED))
394 result = acpi_enable_gpe(handle, index); 566 result = acpi_enable_gpe(handle, index);
395 else if (!strcmp(buf, "clear\n") && 567 else if (!strcmp(buf, "clear\n") &&
396 (status & ACPI_EVENT_FLAG_SET)) 568 (status & ACPI_EVENT_FLAG_SET))
397 result = acpi_clear_gpe(handle, index); 569 result = acpi_clear_gpe(handle, index);
398 else 570 else
399 all_counters[index].count = strtoul(buf, NULL, 0); 571 all_counters[index].count = strtoul(buf, NULL, 0);
400 } else if (index < num_gpes + ACPI_NUM_FIXED_EVENTS) { 572 } else if (index < num_gpes + ACPI_NUM_FIXED_EVENTS) {
401 int event = index - num_gpes; 573 int event = index - num_gpes;
402 if (!strcmp(buf, "disable\n") && 574 if (!strcmp(buf, "disable\n") &&
403 (status & ACPI_EVENT_FLAG_ENABLED)) 575 (status & ACPI_EVENT_FLAG_ENABLED))
404 result = acpi_disable_event(event, ACPI_NOT_ISR); 576 result = acpi_disable_event(event, ACPI_NOT_ISR);
405 else if (!strcmp(buf, "enable\n") && 577 else if (!strcmp(buf, "enable\n") &&
406 !(status & ACPI_EVENT_FLAG_ENABLED)) 578 !(status & ACPI_EVENT_FLAG_ENABLED))
407 result = acpi_enable_event(event, ACPI_NOT_ISR); 579 result = acpi_enable_event(event, ACPI_NOT_ISR);
408 else if (!strcmp(buf, "clear\n") && 580 else if (!strcmp(buf, "clear\n") &&
409 (status & ACPI_EVENT_FLAG_SET)) 581 (status & ACPI_EVENT_FLAG_SET))
410 result = acpi_clear_event(event); 582 result = acpi_clear_event(event);
411 else 583 else
412 all_counters[index].count = strtoul(buf, NULL, 0); 584 all_counters[index].count = strtoul(buf, NULL, 0);
@@ -430,17 +602,17 @@ void acpi_irq_stats_init(void)
430 num_counters = num_gpes + ACPI_NUM_FIXED_EVENTS + NUM_COUNTERS_EXTRA; 602 num_counters = num_gpes + ACPI_NUM_FIXED_EVENTS + NUM_COUNTERS_EXTRA;
431 603
432 all_attrs = kzalloc(sizeof(struct attribute *) * (num_counters + 1), 604 all_attrs = kzalloc(sizeof(struct attribute *) * (num_counters + 1),
433 GFP_KERNEL); 605 GFP_KERNEL);
434 if (all_attrs == NULL) 606 if (all_attrs == NULL)
435 return; 607 return;
436 608
437 all_counters = kzalloc(sizeof(struct event_counter) * (num_counters), 609 all_counters = kzalloc(sizeof(struct event_counter) * (num_counters),
438 GFP_KERNEL); 610 GFP_KERNEL);
439 if (all_counters == NULL) 611 if (all_counters == NULL)
440 goto fail; 612 goto fail;
441 613
442 counter_attrs = kzalloc(sizeof(struct kobj_attribute) * (num_counters), 614 counter_attrs = kzalloc(sizeof(struct kobj_attribute) * (num_counters),
443 GFP_KERNEL); 615 GFP_KERNEL);
444 if (counter_attrs == NULL) 616 if (counter_attrs == NULL)
445 goto fail; 617 goto fail;
446 618
@@ -503,135 +675,11 @@ static void __exit interrupt_stats_exit(void)
503 return; 675 return;
504} 676}
505 677
506/* -------------------------------------------------------------------------- 678int __init acpi_sysfs_init(void)
507 FS Interface (/proc)
508 -------------------------------------------------------------------------- */
509#ifdef CONFIG_ACPI_PROCFS
510#define ACPI_SYSTEM_FILE_INFO "info"
511#define ACPI_SYSTEM_FILE_EVENT "event"
512#define ACPI_SYSTEM_FILE_DSDT "dsdt"
513#define ACPI_SYSTEM_FILE_FADT "fadt"
514
515static int acpi_system_read_info(struct seq_file *seq, void *offset)
516{
517
518 seq_printf(seq, "version: %x\n", ACPI_CA_VERSION);
519 return 0;
520}
521
522static int acpi_system_info_open_fs(struct inode *inode, struct file *file)
523{
524 return single_open(file, acpi_system_read_info, PDE(inode)->data);
525}
526
527static const struct file_operations acpi_system_info_ops = {
528 .owner = THIS_MODULE,
529 .open = acpi_system_info_open_fs,
530 .read = seq_read,
531 .llseek = seq_lseek,
532 .release = single_release,
533};
534
535static ssize_t acpi_system_read_dsdt(struct file *, char __user *, size_t,
536 loff_t *);
537
538static const struct file_operations acpi_system_dsdt_ops = {
539 .owner = THIS_MODULE,
540 .read = acpi_system_read_dsdt,
541};
542
543static ssize_t
544acpi_system_read_dsdt(struct file *file,
545 char __user * buffer, size_t count, loff_t * ppos)
546{
547 acpi_status status = AE_OK;
548 struct acpi_table_header *dsdt = NULL;
549 ssize_t res;
550
551 status = acpi_get_table(ACPI_SIG_DSDT, 1, &dsdt);
552 if (ACPI_FAILURE(status))
553 return -ENODEV;
554
555 res = simple_read_from_buffer(buffer, count, ppos, dsdt, dsdt->length);
556
557 return res;
558}
559
560static ssize_t acpi_system_read_fadt(struct file *, char __user *, size_t,
561 loff_t *);
562
563static const struct file_operations acpi_system_fadt_ops = {
564 .owner = THIS_MODULE,
565 .read = acpi_system_read_fadt,
566};
567
568static ssize_t
569acpi_system_read_fadt(struct file *file,
570 char __user * buffer, size_t count, loff_t * ppos)
571{
572 acpi_status status = AE_OK;
573 struct acpi_table_header *fadt = NULL;
574 ssize_t res;
575
576 status = acpi_get_table(ACPI_SIG_FADT, 1, &fadt);
577 if (ACPI_FAILURE(status))
578 return -ENODEV;
579
580 res = simple_read_from_buffer(buffer, count, ppos, fadt, fadt->length);
581
582 return res;
583}
584
585static int acpi_system_procfs_init(void)
586{
587 struct proc_dir_entry *entry;
588 int error = 0;
589
590 /* 'info' [R] */
591 entry = proc_create(ACPI_SYSTEM_FILE_INFO, S_IRUGO, acpi_root_dir,
592 &acpi_system_info_ops);
593 if (!entry)
594 goto Error;
595
596 /* 'dsdt' [R] */
597 entry = proc_create(ACPI_SYSTEM_FILE_DSDT, S_IRUSR, acpi_root_dir,
598 &acpi_system_dsdt_ops);
599 if (!entry)
600 goto Error;
601
602 /* 'fadt' [R] */
603 entry = proc_create(ACPI_SYSTEM_FILE_FADT, S_IRUSR, acpi_root_dir,
604 &acpi_system_fadt_ops);
605 if (!entry)
606 goto Error;
607
608 Done:
609 return error;
610
611 Error:
612 remove_proc_entry(ACPI_SYSTEM_FILE_FADT, acpi_root_dir);
613 remove_proc_entry(ACPI_SYSTEM_FILE_DSDT, acpi_root_dir);
614 remove_proc_entry(ACPI_SYSTEM_FILE_INFO, acpi_root_dir);
615
616 error = -EFAULT;
617 goto Done;
618}
619#else
620static int acpi_system_procfs_init(void)
621{
622 return 0;
623}
624#endif
625
626int __init acpi_system_init(void)
627{ 679{
628 int result; 680 int result;
629 681
630 result = acpi_system_procfs_init(); 682 result = acpi_tables_sysfs_init();
631 if (result)
632 return result;
633
634 result = acpi_system_sysfs_init();
635 683
636 return result; 684 return result;
637} 685}
diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c
index efad1f33aeb5..2f8f17131d9f 100644
--- a/drivers/acpi/thermal.c
+++ b/drivers/acpi/thermal.c
@@ -37,10 +37,14 @@
37#include <linux/init.h> 37#include <linux/init.h>
38#include <linux/slab.h> 38#include <linux/slab.h>
39#include <linux/types.h> 39#include <linux/types.h>
40
41#ifdef CONFIG_ACPI_PROCFS
40#include <linux/proc_fs.h> 42#include <linux/proc_fs.h>
43#include <linux/seq_file.h>
44#endif
45
41#include <linux/jiffies.h> 46#include <linux/jiffies.h>
42#include <linux/kmod.h> 47#include <linux/kmod.h>
43#include <linux/seq_file.h>
44#include <linux/reboot.h> 48#include <linux/reboot.h>
45#include <linux/device.h> 49#include <linux/device.h>
46#include <asm/uaccess.h> 50#include <asm/uaccess.h>
@@ -102,16 +106,6 @@ static int acpi_thermal_add(struct acpi_device *device);
102static int acpi_thermal_remove(struct acpi_device *device, int type); 106static int acpi_thermal_remove(struct acpi_device *device, int type);
103static int acpi_thermal_resume(struct acpi_device *device); 107static int acpi_thermal_resume(struct acpi_device *device);
104static void acpi_thermal_notify(struct acpi_device *device, u32 event); 108static void acpi_thermal_notify(struct acpi_device *device, u32 event);
105static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file);
106static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file);
107static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file);
108static int acpi_thermal_cooling_open_fs(struct inode *inode, struct file *file);
109static ssize_t acpi_thermal_write_cooling_mode(struct file *,
110 const char __user *, size_t,
111 loff_t *);
112static int acpi_thermal_polling_open_fs(struct inode *inode, struct file *file);
113static ssize_t acpi_thermal_write_polling(struct file *, const char __user *,
114 size_t, loff_t *);
115 109
116static const struct acpi_device_id thermal_device_ids[] = { 110static const struct acpi_device_id thermal_device_ids[] = {
117 {ACPI_THERMAL_HID, 0}, 111 {ACPI_THERMAL_HID, 0},
@@ -201,6 +195,18 @@ struct acpi_thermal {
201 struct mutex lock; 195 struct mutex lock;
202}; 196};
203 197
198#ifdef CONFIG_ACPI_PROCFS
199static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file);
200static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file);
201static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file);
202static int acpi_thermal_cooling_open_fs(struct inode *inode, struct file *file);
203static ssize_t acpi_thermal_write_cooling_mode(struct file *,
204 const char __user *, size_t,
205 loff_t *);
206static int acpi_thermal_polling_open_fs(struct inode *inode, struct file *file);
207static ssize_t acpi_thermal_write_polling(struct file *, const char __user *,
208 size_t, loff_t *);
209
204static const struct file_operations acpi_thermal_state_fops = { 210static const struct file_operations acpi_thermal_state_fops = {
205 .owner = THIS_MODULE, 211 .owner = THIS_MODULE,
206 .open = acpi_thermal_state_open_fs, 212 .open = acpi_thermal_state_open_fs,
@@ -242,6 +248,7 @@ static const struct file_operations acpi_thermal_polling_fops = {
242 .llseek = seq_lseek, 248 .llseek = seq_lseek,
243 .release = single_release, 249 .release = single_release,
244}; 250};
251#endif /* CONFIG_ACPI_PROCFS*/
245 252
246/* -------------------------------------------------------------------------- 253/* --------------------------------------------------------------------------
247 Thermal Zone Management 254 Thermal Zone Management
@@ -287,26 +294,6 @@ static int acpi_thermal_get_polling_frequency(struct acpi_thermal *tz)
287 return 0; 294 return 0;
288} 295}
289 296
290static int acpi_thermal_set_polling(struct acpi_thermal *tz, int seconds)
291{
292
293 if (!tz)
294 return -EINVAL;
295
296 tz->polling_frequency = seconds * 10; /* Convert value to deci-seconds */
297
298 tz->thermal_zone->polling_delay = seconds * 1000;
299
300 if (tz->tz_enabled)
301 thermal_zone_device_update(tz->thermal_zone);
302
303 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
304 "Polling frequency set to %lu seconds\n",
305 tz->polling_frequency/10));
306
307 return 0;
308}
309
310static int acpi_thermal_set_cooling_mode(struct acpi_thermal *tz, int mode) 297static int acpi_thermal_set_cooling_mode(struct acpi_thermal *tz, int mode)
311{ 298{
312 acpi_status status = AE_OK; 299 acpi_status status = AE_OK;
@@ -973,7 +960,7 @@ static void acpi_thermal_unregister_thermal_zone(struct acpi_thermal *tz)
973/* -------------------------------------------------------------------------- 960/* --------------------------------------------------------------------------
974 FS Interface (/proc) 961 FS Interface (/proc)
975 -------------------------------------------------------------------------- */ 962 -------------------------------------------------------------------------- */
976 963#ifdef CONFIG_ACPI_PROCFS
977static struct proc_dir_entry *acpi_thermal_dir; 964static struct proc_dir_entry *acpi_thermal_dir;
978 965
979static int acpi_thermal_state_seq_show(struct seq_file *seq, void *offset) 966static int acpi_thermal_state_seq_show(struct seq_file *seq, void *offset)
@@ -1187,6 +1174,26 @@ static int acpi_thermal_polling_open_fs(struct inode *inode, struct file *file)
1187 PDE(inode)->data); 1174 PDE(inode)->data);
1188} 1175}
1189 1176
1177static int acpi_thermal_set_polling(struct acpi_thermal *tz, int seconds)
1178{
1179 if (!tz)
1180 return -EINVAL;
1181
1182 /* Convert value to deci-seconds */
1183 tz->polling_frequency = seconds * 10;
1184
1185 tz->thermal_zone->polling_delay = seconds * 1000;
1186
1187 if (tz->tz_enabled)
1188 thermal_zone_device_update(tz->thermal_zone);
1189
1190 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1191 "Polling frequency set to %lu seconds\n",
1192 tz->polling_frequency/10));
1193
1194 return 0;
1195}
1196
1190static ssize_t 1197static ssize_t
1191acpi_thermal_write_polling(struct file *file, 1198acpi_thermal_write_polling(struct file *file,
1192 const char __user * buffer, 1199 const char __user * buffer,
@@ -1295,7 +1302,13 @@ static int acpi_thermal_remove_fs(struct acpi_device *device)
1295 1302
1296 return 0; 1303 return 0;
1297} 1304}
1298 1305#else
1306static inline int acpi_thermal_add_fs(struct acpi_device *device) { return 0; }
1307static inline int acpi_thermal_remove_fs(struct acpi_device *device)
1308{
1309 return 0;
1310}
1311#endif /* CONFIG_ACPI_PROCFS */
1299/* -------------------------------------------------------------------------- 1312/* --------------------------------------------------------------------------
1300 Driver Interface 1313 Driver Interface
1301 -------------------------------------------------------------------------- */ 1314 -------------------------------------------------------------------------- */
@@ -1566,13 +1579,18 @@ static int __init acpi_thermal_init(void)
1566 printk(KERN_NOTICE "ACPI: thermal control disabled\n"); 1579 printk(KERN_NOTICE "ACPI: thermal control disabled\n");
1567 return -ENODEV; 1580 return -ENODEV;
1568 } 1581 }
1582
1583#ifdef CONFIG_ACPI_PROCFS
1569 acpi_thermal_dir = proc_mkdir(ACPI_THERMAL_CLASS, acpi_root_dir); 1584 acpi_thermal_dir = proc_mkdir(ACPI_THERMAL_CLASS, acpi_root_dir);
1570 if (!acpi_thermal_dir) 1585 if (!acpi_thermal_dir)
1571 return -ENODEV; 1586 return -ENODEV;
1587#endif
1572 1588
1573 result = acpi_bus_register_driver(&acpi_thermal_driver); 1589 result = acpi_bus_register_driver(&acpi_thermal_driver);
1574 if (result < 0) { 1590 if (result < 0) {
1591#ifdef CONFIG_ACPI_PROCFS
1575 remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir); 1592 remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir);
1593#endif
1576 return -ENODEV; 1594 return -ENODEV;
1577 } 1595 }
1578 1596
@@ -1584,7 +1602,9 @@ static void __exit acpi_thermal_exit(void)
1584 1602
1585 acpi_bus_unregister_driver(&acpi_thermal_driver); 1603 acpi_bus_unregister_driver(&acpi_thermal_driver);
1586 1604
1605#ifdef CONFIG_ACPI_PROCFS
1587 remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir); 1606 remove_proc_entry(ACPI_THERMAL_CLASS, acpi_root_dir);
1607#endif
1588 1608
1589 return; 1609 return;
1590} 1610}
diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c
index 9865d46f49a8..67dec0c675aa 100644
--- a/drivers/acpi/video.c
+++ b/drivers/acpi/video.c
@@ -152,7 +152,9 @@ struct acpi_video_bus {
152 struct acpi_video_bus_flags flags; 152 struct acpi_video_bus_flags flags;
153 struct list_head video_device_list; 153 struct list_head video_device_list;
154 struct mutex device_list_lock; /* protects video_device_list */ 154 struct mutex device_list_lock; /* protects video_device_list */
155#ifdef CONFIG_ACPI_PROCFS
155 struct proc_dir_entry *dir; 156 struct proc_dir_entry *dir;
157#endif
156 struct input_dev *input; 158 struct input_dev *input;
157 char phys[32]; /* for input device */ 159 char phys[32]; /* for input device */
158 struct notifier_block pm_nb; 160 struct notifier_block pm_nb;
@@ -208,6 +210,7 @@ struct acpi_video_device {
208 struct output_device *output_dev; 210 struct output_device *output_dev;
209}; 211};
210 212
213#ifdef CONFIG_ACPI_PROCFS
211/* bus */ 214/* bus */
212static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file); 215static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file);
213static const struct file_operations acpi_video_bus_info_fops = { 216static const struct file_operations acpi_video_bus_info_fops = {
@@ -307,6 +310,7 @@ static const struct file_operations acpi_video_device_EDID_fops = {
307 .llseek = seq_lseek, 310 .llseek = seq_lseek,
308 .release = single_release, 311 .release = single_release,
309}; 312};
313#endif /* CONFIG_ACPI_PROCFS */
310 314
311static const char device_decode[][30] = { 315static const char device_decode[][30] = {
312 "motherboard VGA device", 316 "motherboard VGA device",
@@ -450,16 +454,6 @@ static struct thermal_cooling_device_ops video_cooling_ops = {
450/* device */ 454/* device */
451 455
452static int 456static int
453acpi_video_device_query(struct acpi_video_device *device, unsigned long long *state)
454{
455 int status;
456
457 status = acpi_evaluate_integer(device->dev->handle, "_DGS", NULL, state);
458
459 return status;
460}
461
462static int
463acpi_video_device_get_state(struct acpi_video_device *device, 457acpi_video_device_get_state(struct acpi_video_device *device,
464 unsigned long long *state) 458 unsigned long long *state)
465{ 459{
@@ -698,46 +692,6 @@ acpi_video_device_EDID(struct acpi_video_device *device,
698 692
699/* bus */ 693/* bus */
700 694
701static int
702acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option)
703{
704 int status;
705 unsigned long long tmp;
706 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
707 struct acpi_object_list args = { 1, &arg0 };
708
709
710 arg0.integer.value = option;
711
712 status = acpi_evaluate_integer(video->device->handle, "_SPD", &args, &tmp);
713 if (ACPI_SUCCESS(status))
714 status = tmp ? (-EINVAL) : (AE_OK);
715
716 return status;
717}
718
719static int
720acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long long *id)
721{
722 int status;
723
724 status = acpi_evaluate_integer(video->device->handle, "_GPD", NULL, id);
725
726 return status;
727}
728
729static int
730acpi_video_bus_POST_options(struct acpi_video_bus *video,
731 unsigned long long *options)
732{
733 int status;
734
735 status = acpi_evaluate_integer(video->device->handle, "_VPO", NULL, options);
736 *options &= 3;
737
738 return status;
739}
740
741/* 695/*
742 * Arg: 696 * Arg:
743 * video : video bus device pointer 697 * video : video bus device pointer
@@ -1159,6 +1113,7 @@ static int acpi_video_bus_check(struct acpi_video_bus *video)
1159/* -------------------------------------------------------------------------- 1113/* --------------------------------------------------------------------------
1160 FS Interface (/proc) 1114 FS Interface (/proc)
1161 -------------------------------------------------------------------------- */ 1115 -------------------------------------------------------------------------- */
1116#ifdef CONFIG_ACPI_PROCFS
1162 1117
1163static struct proc_dir_entry *acpi_video_dir; 1118static struct proc_dir_entry *acpi_video_dir;
1164 1119
@@ -1198,6 +1153,18 @@ acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
1198 PDE(inode)->data); 1153 PDE(inode)->data);
1199} 1154}
1200 1155
1156static int
1157acpi_video_device_query(struct acpi_video_device *device,
1158 unsigned long long *state)
1159{
1160 int status;
1161
1162 status = acpi_evaluate_integer(device->dev->handle, "_DGS",
1163 NULL, state);
1164
1165 return status;
1166}
1167
1201static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset) 1168static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
1202{ 1169{
1203 int status; 1170 int status;
@@ -1492,6 +1459,19 @@ static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
1492 return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data); 1459 return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
1493} 1460}
1494 1461
1462static int
1463acpi_video_bus_POST_options(struct acpi_video_bus *video,
1464 unsigned long long *options)
1465{
1466 int status;
1467
1468 status = acpi_evaluate_integer(video->device->handle, "_VPO",
1469 NULL, options);
1470 *options &= 3;
1471
1472 return status;
1473}
1474
1495static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset) 1475static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
1496{ 1476{
1497 struct acpi_video_bus *video = seq->private; 1477 struct acpi_video_bus *video = seq->private;
@@ -1530,6 +1510,16 @@ acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
1530 PDE(inode)->data); 1510 PDE(inode)->data);
1531} 1511}
1532 1512
1513static int
1514acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long long *id)
1515{
1516 int status;
1517
1518 status = acpi_evaluate_integer(video->device->handle, "_GPD", NULL, id);
1519
1520 return status;
1521}
1522
1533static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset) 1523static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
1534{ 1524{
1535 struct acpi_video_bus *video = seq->private; 1525 struct acpi_video_bus *video = seq->private;
@@ -1572,6 +1562,25 @@ static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
1572 return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data); 1562 return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
1573} 1563}
1574 1564
1565static int
1566acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option)
1567{
1568 int status;
1569 unsigned long long tmp;
1570 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
1571 struct acpi_object_list args = { 1, &arg0 };
1572
1573
1574 arg0.integer.value = option;
1575
1576 status = acpi_evaluate_integer(video->device->handle, "_SPD",
1577 &args, &tmp);
1578 if (ACPI_SUCCESS(status))
1579 status = tmp ? (-EINVAL) : (AE_OK);
1580
1581 return status;
1582}
1583
1575static ssize_t 1584static ssize_t
1576acpi_video_bus_write_POST(struct file *file, 1585acpi_video_bus_write_POST(struct file *file,
1577 const char __user * buffer, 1586 const char __user * buffer,
@@ -1722,6 +1731,24 @@ static int acpi_video_bus_remove_fs(struct acpi_device *device)
1722 1731
1723 return 0; 1732 return 0;
1724} 1733}
1734#else
1735static inline int acpi_video_device_add_fs(struct acpi_device *device)
1736{
1737 return 0;
1738}
1739static inline int acpi_video_device_remove_fs(struct acpi_device *device)
1740{
1741 return 0;
1742}
1743static inline int acpi_video_bus_add_fs(struct acpi_device *device)
1744{
1745 return 0;
1746}
1747static inline int acpi_video_bus_remove_fs(struct acpi_device *device)
1748{
1749 return 0;
1750}
1751#endif /* CONFIG_ACPI_PROCFS */
1725 1752
1726/* -------------------------------------------------------------------------- 1753/* --------------------------------------------------------------------------
1727 Driver Interface 1754 Driver Interface
@@ -2140,7 +2167,7 @@ acpi_video_bus_get_devices(struct acpi_video_bus *video,
2140 status = acpi_video_bus_get_one_device(dev, video); 2167 status = acpi_video_bus_get_one_device(dev, video);
2141 if (ACPI_FAILURE(status)) { 2168 if (ACPI_FAILURE(status)) {
2142 printk(KERN_WARNING PREFIX 2169 printk(KERN_WARNING PREFIX
2143 "Cant attach device"); 2170 "Cant attach device\n");
2144 continue; 2171 continue;
2145 } 2172 }
2146 } 2173 }
@@ -2150,19 +2177,19 @@ acpi_video_bus_get_devices(struct acpi_video_bus *video,
2150static int acpi_video_bus_put_one_device(struct acpi_video_device *device) 2177static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
2151{ 2178{
2152 acpi_status status; 2179 acpi_status status;
2153 struct acpi_video_bus *video;
2154
2155 2180
2156 if (!device || !device->video) 2181 if (!device || !device->video)
2157 return -ENOENT; 2182 return -ENOENT;
2158 2183
2159 video = device->video;
2160
2161 acpi_video_device_remove_fs(device->dev); 2184 acpi_video_device_remove_fs(device->dev);
2162 2185
2163 status = acpi_remove_notify_handler(device->dev->handle, 2186 status = acpi_remove_notify_handler(device->dev->handle,
2164 ACPI_DEVICE_NOTIFY, 2187 ACPI_DEVICE_NOTIFY,
2165 acpi_video_device_notify); 2188 acpi_video_device_notify);
2189 if (ACPI_FAILURE(status)) {
2190 printk(KERN_WARNING PREFIX
2191 "Cant remove video notify handler\n");
2192 }
2166 if (device->backlight) { 2193 if (device->backlight) {
2167 sysfs_remove_link(&device->backlight->dev.kobj, "device"); 2194 sysfs_remove_link(&device->backlight->dev.kobj, "device");
2168 backlight_device_unregister(device->backlight); 2195 backlight_device_unregister(device->backlight);
@@ -2557,9 +2584,11 @@ int acpi_video_register(void)
2557 return 0; 2584 return 0;
2558 } 2585 }
2559 2586
2587#ifdef CONFIG_ACPI_PROCFS
2560 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir); 2588 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
2561 if (!acpi_video_dir) 2589 if (!acpi_video_dir)
2562 return -ENODEV; 2590 return -ENODEV;
2591#endif
2563 2592
2564 result = acpi_bus_register_driver(&acpi_video_bus); 2593 result = acpi_bus_register_driver(&acpi_video_bus);
2565 if (result < 0) { 2594 if (result < 0) {
@@ -2588,7 +2617,9 @@ void acpi_video_unregister(void)
2588 } 2617 }
2589 acpi_bus_unregister_driver(&acpi_video_bus); 2618 acpi_bus_unregister_driver(&acpi_video_bus);
2590 2619
2620#ifdef CONFIG_ACPI_PROCFS
2591 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir); 2621 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2622#endif
2592 2623
2593 register_count = 0; 2624 register_count = 0;
2594 2625
diff --git a/drivers/acpi/wakeup.c b/drivers/acpi/wakeup.c
index c80537bc3234..f62a50c3ed34 100644
--- a/drivers/acpi/wakeup.c
+++ b/drivers/acpi/wakeup.c
@@ -21,46 +21,18 @@
21ACPI_MODULE_NAME("wakeup_devices") 21ACPI_MODULE_NAME("wakeup_devices")
22 22
23/** 23/**
24 * acpi_enable_wakeup_device_prep - Prepare wake-up devices. 24 * acpi_enable_wakeup_devices - Enable wake-up device GPEs.
25 * @sleep_state: ACPI system sleep state. 25 * @sleep_state: ACPI system sleep state.
26 * 26 *
27 * Enable all wake-up devices' power, unless the requested system sleep state is 27 * Enable wakeup device power of devices with the state.enable flag set and set
28 * too deep. 28 * the wakeup enable mask bits in the GPE registers that correspond to wakeup
29 * devices.
29 */ 30 */
30void acpi_enable_wakeup_device_prep(u8 sleep_state) 31void acpi_enable_wakeup_devices(u8 sleep_state)
31{ 32{
32 struct list_head *node, *next; 33 struct list_head *node, *next;
33 34
34 list_for_each_safe(node, next, &acpi_wakeup_device_list) { 35 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
35 struct acpi_device *dev = container_of(node,
36 struct acpi_device,
37 wakeup_list);
38
39 if (!dev->wakeup.flags.valid || !dev->wakeup.state.enabled
40 || (sleep_state > (u32) dev->wakeup.sleep_state))
41 continue;
42
43 acpi_enable_wakeup_device_power(dev, sleep_state);
44 }
45}
46
47/**
48 * acpi_enable_wakeup_device - Enable wake-up device GPEs.
49 * @sleep_state: ACPI system sleep state.
50 *
51 * Enable all wake-up devices' GPEs, with the assumption that
52 * acpi_disable_all_gpes() was executed before, so we don't need to disable any
53 * GPEs here.
54 */
55void acpi_enable_wakeup_device(u8 sleep_state)
56{
57 struct list_head *node, *next;
58
59 /*
60 * Caution: this routine must be invoked when interrupt is disabled
61 * Refer ACPI2.0: P212
62 */
63 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
64 struct acpi_device *dev = 36 struct acpi_device *dev =
65 container_of(node, struct acpi_device, wakeup_list); 37 container_of(node, struct acpi_device, wakeup_list);
66 38
@@ -69,6 +41,9 @@ void acpi_enable_wakeup_device(u8 sleep_state)
69 || sleep_state > (u32) dev->wakeup.sleep_state) 41 || sleep_state > (u32) dev->wakeup.sleep_state)
70 continue; 42 continue;
71 43
44 if (dev->wakeup.state.enabled)
45 acpi_enable_wakeup_device_power(dev, sleep_state);
46
72 /* The wake-up power should have been enabled already. */ 47 /* The wake-up power should have been enabled already. */
73 acpi_gpe_wakeup(dev->wakeup.gpe_device, dev->wakeup.gpe_number, 48 acpi_gpe_wakeup(dev->wakeup.gpe_device, dev->wakeup.gpe_number,
74 ACPI_GPE_ENABLE); 49 ACPI_GPE_ENABLE);
@@ -76,13 +51,10 @@ void acpi_enable_wakeup_device(u8 sleep_state)
76} 51}
77 52
78/** 53/**
79 * acpi_disable_wakeup_device - Disable devices' wakeup capability. 54 * acpi_disable_wakeup_devices - Disable devices' wakeup capability.
80 * @sleep_state: ACPI system sleep state. 55 * @sleep_state: ACPI system sleep state.
81 *
82 * This function only affects devices with wakeup.state.enabled set, which means
83 * that it reverses the changes made by acpi_enable_wakeup_device_prep().
84 */ 56 */
85void acpi_disable_wakeup_device(u8 sleep_state) 57void acpi_disable_wakeup_devices(u8 sleep_state)
86{ 58{
87 struct list_head *node, *next; 59 struct list_head *node, *next;
88 60
diff --git a/drivers/ata/Kconfig b/drivers/ata/Kconfig
index 8fae6afd6a3d..65e3e2708371 100644
--- a/drivers/ata/Kconfig
+++ b/drivers/ata/Kconfig
@@ -651,6 +651,17 @@ config PATA_VIA
651 651
652 If unsure, say N. 652 If unsure, say N.
653 653
654config PATA_PXA
655 tristate "PXA DMA-capable PATA support"
656 depends on ARCH_PXA
657 help
658 This option enables support for harddrive attached to PXA CPU's bus.
659
660 NOTE: This driver utilizes PXA DMA controller, in case your hardware
661 is not capable of doing MWDMA, use pata_platform instead.
662
663 If unsure, say N.
664
654config PATA_WINBOND 665config PATA_WINBOND
655 tristate "Winbond SL82C105 PATA support" 666 tristate "Winbond SL82C105 PATA support"
656 depends on PCI 667 depends on PCI
diff --git a/drivers/ata/Makefile b/drivers/ata/Makefile
index 6540632bda08..158eaa961b1e 100644
--- a/drivers/ata/Makefile
+++ b/drivers/ata/Makefile
@@ -91,6 +91,8 @@ obj-$(CONFIG_PATA_RZ1000) += pata_rz1000.o
91obj-$(CONFIG_PATA_SAMSUNG_CF) += pata_samsung_cf.o 91obj-$(CONFIG_PATA_SAMSUNG_CF) += pata_samsung_cf.o
92obj-$(CONFIG_PATA_WINBOND_VLB) += pata_winbond.o 92obj-$(CONFIG_PATA_WINBOND_VLB) += pata_winbond.o
93 93
94obj-$(CONFIG_PATA_PXA) += pata_pxa.o
95
94# Should be last but two libata driver 96# Should be last but two libata driver
95obj-$(CONFIG_PATA_ACPI) += pata_acpi.o 97obj-$(CONFIG_PATA_ACPI) += pata_acpi.o
96# Should be last but one libata driver 98# Should be last but one libata driver
diff --git a/drivers/ata/libata-acpi.c b/drivers/ata/libata-acpi.c
index 7b5eea7e01dc..8b5ea399a4f4 100644
--- a/drivers/ata/libata-acpi.c
+++ b/drivers/ata/libata-acpi.c
@@ -145,12 +145,6 @@ static void ata_acpi_handle_hotplug(struct ata_port *ap, struct ata_device *dev,
145 struct ata_eh_info *ehi = &ap->link.eh_info; 145 struct ata_eh_info *ehi = &ap->link.eh_info;
146 int wait = 0; 146 int wait = 0;
147 unsigned long flags; 147 unsigned long flags;
148 acpi_handle handle;
149
150 if (dev)
151 handle = dev->acpi_handle;
152 else
153 handle = ap->acpi_handle;
154 148
155 spin_lock_irqsave(ap->lock, flags); 149 spin_lock_irqsave(ap->lock, flags);
156 /* 150 /*
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index 4972fdf4bd31..7ef7c4f216fa 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -4281,7 +4281,7 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = {
4281 * The special characters ?, [, -, or *, can be matched using a set, eg. [*] 4281 * The special characters ?, [, -, or *, can be matched using a set, eg. [*]
4282 * Behaviour with malformed patterns is undefined, though generally reasonable. 4282 * Behaviour with malformed patterns is undefined, though generally reasonable.
4283 * 4283 *
4284 * Example patterns: "SD1?", "SD1[0-5]", "*R0", SD*1?[012]*xx" 4284 * Sample patterns: "SD1?", "SD1[0-5]", "*R0", "SD*1?[012]*xx"
4285 * 4285 *
4286 * This function uses one level of recursion per '*' in pattern. 4286 * This function uses one level of recursion per '*' in pattern.
4287 * Since it calls _nothing_ else, and has _no_ explicit local variables, 4287 * Since it calls _nothing_ else, and has _no_ explicit local variables,
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index d75c9c479d1a..a89172c100f5 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -1111,10 +1111,10 @@ static void ata_scsi_sdev_config(struct scsi_device *sdev)
1111 */ 1111 */
1112static int atapi_drain_needed(struct request *rq) 1112static int atapi_drain_needed(struct request *rq)
1113{ 1113{
1114 if (likely(!blk_pc_request(rq))) 1114 if (likely(rq->cmd_type != REQ_TYPE_BLOCK_PC))
1115 return 0; 1115 return 0;
1116 1116
1117 if (!blk_rq_bytes(rq) || (rq->cmd_flags & REQ_RW)) 1117 if (!blk_rq_bytes(rq) || (rq->cmd_flags & REQ_WRITE))
1118 return 0; 1118 return 0;
1119 1119
1120 return atapi_cmd_type(rq->cmd[0]) == ATAPI_MISC; 1120 return atapi_cmd_type(rq->cmd[0]) == ATAPI_MISC;
diff --git a/drivers/ata/pata_mpc52xx.c b/drivers/ata/pata_mpc52xx.c
index f087ab55b1df..8cc536e49a0a 100644
--- a/drivers/ata/pata_mpc52xx.c
+++ b/drivers/ata/pata_mpc52xx.c
@@ -680,7 +680,7 @@ mpc52xx_ata_remove_one(struct device *dev)
680/* ======================================================================== */ 680/* ======================================================================== */
681 681
682static int __devinit 682static int __devinit
683mpc52xx_ata_probe(struct of_device *op, const struct of_device_id *match) 683mpc52xx_ata_probe(struct platform_device *op, const struct of_device_id *match)
684{ 684{
685 unsigned int ipb_freq; 685 unsigned int ipb_freq;
686 struct resource res_mem; 686 struct resource res_mem;
@@ -821,7 +821,7 @@ mpc52xx_ata_probe(struct of_device *op, const struct of_device_id *match)
821} 821}
822 822
823static int 823static int
824mpc52xx_ata_remove(struct of_device *op) 824mpc52xx_ata_remove(struct platform_device *op)
825{ 825{
826 struct mpc52xx_ata_priv *priv; 826 struct mpc52xx_ata_priv *priv;
827 int task_irq; 827 int task_irq;
@@ -848,7 +848,7 @@ mpc52xx_ata_remove(struct of_device *op)
848#ifdef CONFIG_PM 848#ifdef CONFIG_PM
849 849
850static int 850static int
851mpc52xx_ata_suspend(struct of_device *op, pm_message_t state) 851mpc52xx_ata_suspend(struct platform_device *op, pm_message_t state)
852{ 852{
853 struct ata_host *host = dev_get_drvdata(&op->dev); 853 struct ata_host *host = dev_get_drvdata(&op->dev);
854 854
@@ -856,7 +856,7 @@ mpc52xx_ata_suspend(struct of_device *op, pm_message_t state)
856} 856}
857 857
858static int 858static int
859mpc52xx_ata_resume(struct of_device *op) 859mpc52xx_ata_resume(struct platform_device *op)
860{ 860{
861 struct ata_host *host = dev_get_drvdata(&op->dev); 861 struct ata_host *host = dev_get_drvdata(&op->dev);
862 struct mpc52xx_ata_priv *priv = host->private_data; 862 struct mpc52xx_ata_priv *priv = host->private_data;
diff --git a/drivers/ata/pata_of_platform.c b/drivers/ata/pata_of_platform.c
index 5a1b82c08be9..480e043ce6b8 100644
--- a/drivers/ata/pata_of_platform.c
+++ b/drivers/ata/pata_of_platform.c
@@ -14,7 +14,7 @@
14#include <linux/of_platform.h> 14#include <linux/of_platform.h>
15#include <linux/ata_platform.h> 15#include <linux/ata_platform.h>
16 16
17static int __devinit pata_of_platform_probe(struct of_device *ofdev, 17static int __devinit pata_of_platform_probe(struct platform_device *ofdev,
18 const struct of_device_id *match) 18 const struct of_device_id *match)
19{ 19{
20 int ret; 20 int ret;
@@ -78,7 +78,7 @@ static int __devinit pata_of_platform_probe(struct of_device *ofdev,
78 reg_shift, pio_mask); 78 reg_shift, pio_mask);
79} 79}
80 80
81static int __devexit pata_of_platform_remove(struct of_device *ofdev) 81static int __devexit pata_of_platform_remove(struct platform_device *ofdev)
82{ 82{
83 return __pata_platform_remove(&ofdev->dev); 83 return __pata_platform_remove(&ofdev->dev);
84} 84}
diff --git a/drivers/ata/pata_pxa.c b/drivers/ata/pata_pxa.c
new file mode 100644
index 000000000000..1898c6ed4b4e
--- /dev/null
+++ b/drivers/ata/pata_pxa.c
@@ -0,0 +1,411 @@
1/*
2 * Generic PXA PATA driver
3 *
4 * Copyright (C) 2010 Marek Vasut <marek.vasut@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
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; see the file COPYING. If not, write to
18 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21#include <linux/kernel.h>
22#include <linux/module.h>
23#include <linux/init.h>
24#include <linux/blkdev.h>
25#include <linux/ata.h>
26#include <linux/libata.h>
27#include <linux/platform_device.h>
28#include <linux/gpio.h>
29#include <linux/slab.h>
30#include <linux/completion.h>
31
32#include <scsi/scsi_host.h>
33
34#include <mach/pxa2xx-regs.h>
35#include <mach/pata_pxa.h>
36#include <mach/dma.h>
37
38#define DRV_NAME "pata_pxa"
39#define DRV_VERSION "0.1"
40
41struct pata_pxa_data {
42 uint32_t dma_channel;
43 struct pxa_dma_desc *dma_desc;
44 dma_addr_t dma_desc_addr;
45 uint32_t dma_desc_id;
46
47 /* DMA IO physical address */
48 uint32_t dma_io_addr;
49 /* PXA DREQ<0:2> pin selector */
50 uint32_t dma_dreq;
51 /* DMA DCSR register value */
52 uint32_t dma_dcsr;
53
54 struct completion dma_done;
55};
56
57/*
58 * Setup the DMA descriptors. The size is transfer capped at 4k per descriptor,
59 * if the transfer is longer, it is split into multiple chained descriptors.
60 */
61static void pxa_load_dmac(struct scatterlist *sg, struct ata_queued_cmd *qc)
62{
63 struct pata_pxa_data *pd = qc->ap->private_data;
64
65 uint32_t cpu_len, seg_len;
66 dma_addr_t cpu_addr;
67
68 cpu_addr = sg_dma_address(sg);
69 cpu_len = sg_dma_len(sg);
70
71 do {
72 seg_len = (cpu_len > 0x1000) ? 0x1000 : cpu_len;
73
74 pd->dma_desc[pd->dma_desc_id].ddadr = pd->dma_desc_addr +
75 ((pd->dma_desc_id + 1) * sizeof(struct pxa_dma_desc));
76
77 pd->dma_desc[pd->dma_desc_id].dcmd = DCMD_BURST32 |
78 DCMD_WIDTH2 | (DCMD_LENGTH & seg_len);
79
80 if (qc->tf.flags & ATA_TFLAG_WRITE) {
81 pd->dma_desc[pd->dma_desc_id].dsadr = cpu_addr;
82 pd->dma_desc[pd->dma_desc_id].dtadr = pd->dma_io_addr;
83 pd->dma_desc[pd->dma_desc_id].dcmd |= DCMD_INCSRCADDR |
84 DCMD_FLOWTRG;
85 } else {
86 pd->dma_desc[pd->dma_desc_id].dsadr = pd->dma_io_addr;
87 pd->dma_desc[pd->dma_desc_id].dtadr = cpu_addr;
88 pd->dma_desc[pd->dma_desc_id].dcmd |= DCMD_INCTRGADDR |
89 DCMD_FLOWSRC;
90 }
91
92 cpu_len -= seg_len;
93 cpu_addr += seg_len;
94 pd->dma_desc_id++;
95
96 } while (cpu_len);
97
98 /* Should not happen */
99 if (seg_len & 0x1f)
100 DALGN |= (1 << pd->dma_dreq);
101}
102
103/*
104 * Prepare taskfile for submission.
105 */
106static void pxa_qc_prep(struct ata_queued_cmd *qc)
107{
108 struct pata_pxa_data *pd = qc->ap->private_data;
109 int si = 0;
110 struct scatterlist *sg;
111
112 if (!(qc->flags & ATA_QCFLAG_DMAMAP))
113 return;
114
115 pd->dma_desc_id = 0;
116
117 DCSR(pd->dma_channel) = 0;
118 DALGN &= ~(1 << pd->dma_dreq);
119
120 for_each_sg(qc->sg, sg, qc->n_elem, si)
121 pxa_load_dmac(sg, qc);
122
123 pd->dma_desc[pd->dma_desc_id - 1].ddadr = DDADR_STOP;
124
125 /* Fire IRQ only at the end of last block */
126 pd->dma_desc[pd->dma_desc_id - 1].dcmd |= DCMD_ENDIRQEN;
127
128 DDADR(pd->dma_channel) = pd->dma_desc_addr;
129 DRCMR(pd->dma_dreq) = DRCMR_MAPVLD | pd->dma_channel;
130
131}
132
133/*
134 * Configure the DMA controller, load the DMA descriptors, but don't start the
135 * DMA controller yet. Only issue the ATA command.
136 */
137static void pxa_bmdma_setup(struct ata_queued_cmd *qc)
138{
139 qc->ap->ops->sff_exec_command(qc->ap, &qc->tf);
140}
141
142/*
143 * Execute the DMA transfer.
144 */
145static void pxa_bmdma_start(struct ata_queued_cmd *qc)
146{
147 struct pata_pxa_data *pd = qc->ap->private_data;
148 init_completion(&pd->dma_done);
149 DCSR(pd->dma_channel) = DCSR_RUN;
150}
151
152/*
153 * Wait until the DMA transfer completes, then stop the DMA controller.
154 */
155static void pxa_bmdma_stop(struct ata_queued_cmd *qc)
156{
157 struct pata_pxa_data *pd = qc->ap->private_data;
158
159 if ((DCSR(pd->dma_channel) & DCSR_RUN) &&
160 wait_for_completion_timeout(&pd->dma_done, HZ))
161 dev_err(qc->ap->dev, "Timeout waiting for DMA completion!");
162
163 DCSR(pd->dma_channel) = 0;
164}
165
166/*
167 * Read DMA status. The bmdma_stop() will take care of properly finishing the
168 * DMA transfer so we always have DMA-complete interrupt here.
169 */
170static unsigned char pxa_bmdma_status(struct ata_port *ap)
171{
172 struct pata_pxa_data *pd = ap->private_data;
173 unsigned char ret = ATA_DMA_INTR;
174
175 if (pd->dma_dcsr & DCSR_BUSERR)
176 ret |= ATA_DMA_ERR;
177
178 return ret;
179}
180
181/*
182 * No IRQ register present so we do nothing.
183 */
184static void pxa_irq_clear(struct ata_port *ap)
185{
186}
187
188/*
189 * Check for ATAPI DMA. ATAPI DMA is unsupported by this driver. It's still
190 * unclear why ATAPI has DMA issues.
191 */
192static int pxa_check_atapi_dma(struct ata_queued_cmd *qc)
193{
194 return -EOPNOTSUPP;
195}
196
197static struct scsi_host_template pxa_ata_sht = {
198 ATA_BMDMA_SHT(DRV_NAME),
199};
200
201static struct ata_port_operations pxa_ata_port_ops = {
202 .inherits = &ata_bmdma_port_ops,
203 .cable_detect = ata_cable_40wire,
204
205 .bmdma_setup = pxa_bmdma_setup,
206 .bmdma_start = pxa_bmdma_start,
207 .bmdma_stop = pxa_bmdma_stop,
208 .bmdma_status = pxa_bmdma_status,
209
210 .check_atapi_dma = pxa_check_atapi_dma,
211
212 .sff_irq_clear = pxa_irq_clear,
213
214 .qc_prep = pxa_qc_prep,
215};
216
217/*
218 * DMA interrupt handler.
219 */
220static void pxa_ata_dma_irq(int dma, void *port)
221{
222 struct ata_port *ap = port;
223 struct pata_pxa_data *pd = ap->private_data;
224
225 pd->dma_dcsr = DCSR(dma);
226 DCSR(dma) = pd->dma_dcsr;
227
228 if (pd->dma_dcsr & DCSR_STOPSTATE)
229 complete(&pd->dma_done);
230}
231
232static int __devinit pxa_ata_probe(struct platform_device *pdev)
233{
234 struct ata_host *host;
235 struct ata_port *ap;
236 struct pata_pxa_data *data;
237 struct resource *cmd_res;
238 struct resource *ctl_res;
239 struct resource *dma_res;
240 struct resource *irq_res;
241 struct pata_pxa_pdata *pdata = pdev->dev.platform_data;
242 int ret = 0;
243
244 /*
245 * Resource validation, three resources are needed:
246 * - CMD port base address
247 * - CTL port base address
248 * - DMA port base address
249 * - IRQ pin
250 */
251 if (pdev->num_resources != 4) {
252 dev_err(&pdev->dev, "invalid number of resources\n");
253 return -EINVAL;
254 }
255
256 /*
257 * CMD port base address
258 */
259 cmd_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
260 if (unlikely(cmd_res == NULL))
261 return -EINVAL;
262
263 /*
264 * CTL port base address
265 */
266 ctl_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
267 if (unlikely(ctl_res == NULL))
268 return -EINVAL;
269
270 /*
271 * DMA port base address
272 */
273 dma_res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
274 if (unlikely(dma_res == NULL))
275 return -EINVAL;
276
277 /*
278 * IRQ pin
279 */
280 irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
281 if (unlikely(irq_res == NULL))
282 return -EINVAL;
283
284 /*
285 * Allocate the host
286 */
287 host = ata_host_alloc(&pdev->dev, 1);
288 if (!host)
289 return -ENOMEM;
290
291 ap = host->ports[0];
292 ap->ops = &pxa_ata_port_ops;
293 ap->pio_mask = ATA_PIO4;
294 ap->mwdma_mask = ATA_MWDMA2;
295 ap->flags = ATA_FLAG_MMIO;
296
297 ap->ioaddr.cmd_addr = devm_ioremap(&pdev->dev, cmd_res->start,
298 resource_size(cmd_res));
299 ap->ioaddr.ctl_addr = devm_ioremap(&pdev->dev, ctl_res->start,
300 resource_size(ctl_res));
301 ap->ioaddr.bmdma_addr = devm_ioremap(&pdev->dev, dma_res->start,
302 resource_size(dma_res));
303
304 /*
305 * Adjust register offsets
306 */
307 ap->ioaddr.altstatus_addr = ap->ioaddr.ctl_addr;
308 ap->ioaddr.data_addr = ap->ioaddr.cmd_addr +
309 (ATA_REG_DATA << pdata->reg_shift);
310 ap->ioaddr.error_addr = ap->ioaddr.cmd_addr +
311 (ATA_REG_ERR << pdata->reg_shift);
312 ap->ioaddr.feature_addr = ap->ioaddr.cmd_addr +
313 (ATA_REG_FEATURE << pdata->reg_shift);
314 ap->ioaddr.nsect_addr = ap->ioaddr.cmd_addr +
315 (ATA_REG_NSECT << pdata->reg_shift);
316 ap->ioaddr.lbal_addr = ap->ioaddr.cmd_addr +
317 (ATA_REG_LBAL << pdata->reg_shift);
318 ap->ioaddr.lbam_addr = ap->ioaddr.cmd_addr +
319 (ATA_REG_LBAM << pdata->reg_shift);
320 ap->ioaddr.lbah_addr = ap->ioaddr.cmd_addr +
321 (ATA_REG_LBAH << pdata->reg_shift);
322 ap->ioaddr.device_addr = ap->ioaddr.cmd_addr +
323 (ATA_REG_DEVICE << pdata->reg_shift);
324 ap->ioaddr.status_addr = ap->ioaddr.cmd_addr +
325 (ATA_REG_STATUS << pdata->reg_shift);
326 ap->ioaddr.command_addr = ap->ioaddr.cmd_addr +
327 (ATA_REG_CMD << pdata->reg_shift);
328
329 /*
330 * Allocate and load driver's internal data structure
331 */
332 data = devm_kzalloc(&pdev->dev, sizeof(struct pata_pxa_data),
333 GFP_KERNEL);
334 if (!data)
335 return -ENOMEM;
336
337 ap->private_data = data;
338 data->dma_dreq = pdata->dma_dreq;
339 data->dma_io_addr = dma_res->start;
340
341 /*
342 * Allocate space for the DMA descriptors
343 */
344 data->dma_desc = dmam_alloc_coherent(&pdev->dev, PAGE_SIZE,
345 &data->dma_desc_addr, GFP_KERNEL);
346 if (!data->dma_desc)
347 return -EINVAL;
348
349 /*
350 * Request the DMA channel
351 */
352 data->dma_channel = pxa_request_dma(DRV_NAME, DMA_PRIO_LOW,
353 pxa_ata_dma_irq, ap);
354 if (data->dma_channel < 0)
355 return -EBUSY;
356
357 /*
358 * Stop and clear the DMA channel
359 */
360 DCSR(data->dma_channel) = 0;
361
362 /*
363 * Activate the ATA host
364 */
365 ret = ata_host_activate(host, irq_res->start, ata_sff_interrupt,
366 pdata->irq_flags, &pxa_ata_sht);
367 if (ret)
368 pxa_free_dma(data->dma_channel);
369
370 return ret;
371}
372
373static int __devexit pxa_ata_remove(struct platform_device *pdev)
374{
375 struct ata_host *host = dev_get_drvdata(&pdev->dev);
376 struct pata_pxa_data *data = host->ports[0]->private_data;
377
378 pxa_free_dma(data->dma_channel);
379
380 ata_host_detach(host);
381
382 return 0;
383}
384
385static struct platform_driver pxa_ata_driver = {
386 .probe = pxa_ata_probe,
387 .remove = __devexit_p(pxa_ata_remove),
388 .driver = {
389 .name = DRV_NAME,
390 .owner = THIS_MODULE,
391 },
392};
393
394static int __init pxa_ata_init(void)
395{
396 return platform_driver_register(&pxa_ata_driver);
397}
398
399static void __exit pxa_ata_exit(void)
400{
401 platform_driver_unregister(&pxa_ata_driver);
402}
403
404module_init(pxa_ata_init);
405module_exit(pxa_ata_exit);
406
407MODULE_AUTHOR("Marek Vasut <marek.vasut@gmail.com>");
408MODULE_DESCRIPTION("DMA-capable driver for PATA on PXA CPU");
409MODULE_LICENSE("GPL");
410MODULE_VERSION(DRV_VERSION);
411MODULE_ALIAS("platform:" DRV_NAME);
diff --git a/drivers/ata/sata_fsl.c b/drivers/ata/sata_fsl.c
index 18c986dbb7f1..7325f77480dc 100644
--- a/drivers/ata/sata_fsl.c
+++ b/drivers/ata/sata_fsl.c
@@ -1296,7 +1296,7 @@ static const struct ata_port_info sata_fsl_port_info[] = {
1296 }, 1296 },
1297}; 1297};
1298 1298
1299static int sata_fsl_probe(struct of_device *ofdev, 1299static int sata_fsl_probe(struct platform_device *ofdev,
1300 const struct of_device_id *match) 1300 const struct of_device_id *match)
1301{ 1301{
1302 int retval = -ENXIO; 1302 int retval = -ENXIO;
@@ -1370,7 +1370,7 @@ error_exit_with_cleanup:
1370 return retval; 1370 return retval;
1371} 1371}
1372 1372
1373static int sata_fsl_remove(struct of_device *ofdev) 1373static int sata_fsl_remove(struct platform_device *ofdev)
1374{ 1374{
1375 struct ata_host *host = dev_get_drvdata(&ofdev->dev); 1375 struct ata_host *host = dev_get_drvdata(&ofdev->dev);
1376 struct sata_fsl_host_priv *host_priv = host->private_data; 1376 struct sata_fsl_host_priv *host_priv = host->private_data;
@@ -1387,13 +1387,13 @@ static int sata_fsl_remove(struct of_device *ofdev)
1387} 1387}
1388 1388
1389#ifdef CONFIG_PM 1389#ifdef CONFIG_PM
1390static int sata_fsl_suspend(struct of_device *op, pm_message_t state) 1390static int sata_fsl_suspend(struct platform_device *op, pm_message_t state)
1391{ 1391{
1392 struct ata_host *host = dev_get_drvdata(&op->dev); 1392 struct ata_host *host = dev_get_drvdata(&op->dev);
1393 return ata_host_suspend(host, state); 1393 return ata_host_suspend(host, state);
1394} 1394}
1395 1395
1396static int sata_fsl_resume(struct of_device *op) 1396static int sata_fsl_resume(struct platform_device *op)
1397{ 1397{
1398 struct ata_host *host = dev_get_drvdata(&op->dev); 1398 struct ata_host *host = dev_get_drvdata(&op->dev);
1399 struct sata_fsl_host_priv *host_priv = host->private_data; 1399 struct sata_fsl_host_priv *host_priv = host->private_data;
diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
index b7385e077717..c8fc69c85a06 100644
--- a/drivers/atm/fore200e.c
+++ b/drivers/atm/fore200e.c
@@ -674,7 +674,7 @@ static void fore200e_sba_write(u32 val, volatile u32 __iomem *addr)
674 674
675static u32 fore200e_sba_dma_map(struct fore200e *fore200e, void* virt_addr, int size, int direction) 675static u32 fore200e_sba_dma_map(struct fore200e *fore200e, void* virt_addr, int size, int direction)
676{ 676{
677 struct of_device *op = fore200e->bus_dev; 677 struct platform_device *op = fore200e->bus_dev;
678 u32 dma_addr; 678 u32 dma_addr;
679 679
680 dma_addr = dma_map_single(&op->dev, virt_addr, size, direction); 680 dma_addr = dma_map_single(&op->dev, virt_addr, size, direction);
@@ -687,7 +687,7 @@ static u32 fore200e_sba_dma_map(struct fore200e *fore200e, void* virt_addr, int
687 687
688static void fore200e_sba_dma_unmap(struct fore200e *fore200e, u32 dma_addr, int size, int direction) 688static void fore200e_sba_dma_unmap(struct fore200e *fore200e, u32 dma_addr, int size, int direction)
689{ 689{
690 struct of_device *op = fore200e->bus_dev; 690 struct platform_device *op = fore200e->bus_dev;
691 691
692 DPRINTK(3, "SBUS DVMA unmapping: dma_addr = 0x%08x, size = %d, direction = %d,\n", 692 DPRINTK(3, "SBUS DVMA unmapping: dma_addr = 0x%08x, size = %d, direction = %d,\n",
693 dma_addr, size, direction); 693 dma_addr, size, direction);
@@ -697,7 +697,7 @@ static void fore200e_sba_dma_unmap(struct fore200e *fore200e, u32 dma_addr, int
697 697
698static void fore200e_sba_dma_sync_for_cpu(struct fore200e *fore200e, u32 dma_addr, int size, int direction) 698static void fore200e_sba_dma_sync_for_cpu(struct fore200e *fore200e, u32 dma_addr, int size, int direction)
699{ 699{
700 struct of_device *op = fore200e->bus_dev; 700 struct platform_device *op = fore200e->bus_dev;
701 701
702 DPRINTK(3, "SBUS DVMA sync: dma_addr = 0x%08x, size = %d, direction = %d\n", dma_addr, size, direction); 702 DPRINTK(3, "SBUS DVMA sync: dma_addr = 0x%08x, size = %d, direction = %d\n", dma_addr, size, direction);
703 703
@@ -706,7 +706,7 @@ static void fore200e_sba_dma_sync_for_cpu(struct fore200e *fore200e, u32 dma_add
706 706
707static void fore200e_sba_dma_sync_for_device(struct fore200e *fore200e, u32 dma_addr, int size, int direction) 707static void fore200e_sba_dma_sync_for_device(struct fore200e *fore200e, u32 dma_addr, int size, int direction)
708{ 708{
709 struct of_device *op = fore200e->bus_dev; 709 struct platform_device *op = fore200e->bus_dev;
710 710
711 DPRINTK(3, "SBUS DVMA sync: dma_addr = 0x%08x, size = %d, direction = %d\n", dma_addr, size, direction); 711 DPRINTK(3, "SBUS DVMA sync: dma_addr = 0x%08x, size = %d, direction = %d\n", dma_addr, size, direction);
712 712
@@ -719,7 +719,7 @@ static void fore200e_sba_dma_sync_for_device(struct fore200e *fore200e, u32 dma_
719static int fore200e_sba_dma_chunk_alloc(struct fore200e *fore200e, struct chunk *chunk, 719static int fore200e_sba_dma_chunk_alloc(struct fore200e *fore200e, struct chunk *chunk,
720 int size, int nbr, int alignment) 720 int size, int nbr, int alignment)
721{ 721{
722 struct of_device *op = fore200e->bus_dev; 722 struct platform_device *op = fore200e->bus_dev;
723 723
724 chunk->alloc_size = chunk->align_size = size * nbr; 724 chunk->alloc_size = chunk->align_size = size * nbr;
725 725
@@ -738,7 +738,7 @@ static int fore200e_sba_dma_chunk_alloc(struct fore200e *fore200e, struct chunk
738/* free a DVMA consistent chunk of memory */ 738/* free a DVMA consistent chunk of memory */
739static void fore200e_sba_dma_chunk_free(struct fore200e *fore200e, struct chunk *chunk) 739static void fore200e_sba_dma_chunk_free(struct fore200e *fore200e, struct chunk *chunk)
740{ 740{
741 struct of_device *op = fore200e->bus_dev; 741 struct platform_device *op = fore200e->bus_dev;
742 742
743 dma_free_coherent(&op->dev, chunk->alloc_size, 743 dma_free_coherent(&op->dev, chunk->alloc_size,
744 chunk->alloc_addr, chunk->dma_addr); 744 chunk->alloc_addr, chunk->dma_addr);
@@ -770,7 +770,7 @@ static void fore200e_sba_reset(struct fore200e *fore200e)
770 770
771static int __init fore200e_sba_map(struct fore200e *fore200e) 771static int __init fore200e_sba_map(struct fore200e *fore200e)
772{ 772{
773 struct of_device *op = fore200e->bus_dev; 773 struct platform_device *op = fore200e->bus_dev;
774 unsigned int bursts; 774 unsigned int bursts;
775 775
776 /* gain access to the SBA specific registers */ 776 /* gain access to the SBA specific registers */
@@ -800,7 +800,7 @@ static int __init fore200e_sba_map(struct fore200e *fore200e)
800 800
801static void fore200e_sba_unmap(struct fore200e *fore200e) 801static void fore200e_sba_unmap(struct fore200e *fore200e)
802{ 802{
803 struct of_device *op = fore200e->bus_dev; 803 struct platform_device *op = fore200e->bus_dev;
804 804
805 of_iounmap(&op->resource[0], fore200e->regs.sba.hcr, SBA200E_HCR_LENGTH); 805 of_iounmap(&op->resource[0], fore200e->regs.sba.hcr, SBA200E_HCR_LENGTH);
806 of_iounmap(&op->resource[1], fore200e->regs.sba.bsr, SBA200E_BSR_LENGTH); 806 of_iounmap(&op->resource[1], fore200e->regs.sba.bsr, SBA200E_BSR_LENGTH);
@@ -816,7 +816,7 @@ static int __init fore200e_sba_configure(struct fore200e *fore200e)
816 816
817static int __init fore200e_sba_prom_read(struct fore200e *fore200e, struct prom_data *prom) 817static int __init fore200e_sba_prom_read(struct fore200e *fore200e, struct prom_data *prom)
818{ 818{
819 struct of_device *op = fore200e->bus_dev; 819 struct platform_device *op = fore200e->bus_dev;
820 const u8 *prop; 820 const u8 *prop;
821 int len; 821 int len;
822 822
@@ -840,7 +840,7 @@ static int __init fore200e_sba_prom_read(struct fore200e *fore200e, struct prom_
840 840
841static int fore200e_sba_proc_read(struct fore200e *fore200e, char *page) 841static int fore200e_sba_proc_read(struct fore200e *fore200e, char *page)
842{ 842{
843 struct of_device *op = fore200e->bus_dev; 843 struct platform_device *op = fore200e->bus_dev;
844 const struct linux_prom_registers *regs; 844 const struct linux_prom_registers *regs;
845 845
846 regs = of_get_property(op->dev.of_node, "reg", NULL); 846 regs = of_get_property(op->dev.of_node, "reg", NULL);
@@ -2513,7 +2513,7 @@ fore200e_load_and_start_fw(struct fore200e* fore200e)
2513 device = &((struct pci_dev *) fore200e->bus_dev)->dev; 2513 device = &((struct pci_dev *) fore200e->bus_dev)->dev;
2514#ifdef CONFIG_SBUS 2514#ifdef CONFIG_SBUS
2515 else if (strcmp(fore200e->bus->model_name, "SBA-200E") == 0) 2515 else if (strcmp(fore200e->bus->model_name, "SBA-200E") == 0)
2516 device = &((struct of_device *) fore200e->bus_dev)->dev; 2516 device = &((struct platform_device *) fore200e->bus_dev)->dev;
2517#endif 2517#endif
2518 else 2518 else
2519 return err; 2519 return err;
@@ -2643,7 +2643,7 @@ fore200e_init(struct fore200e* fore200e)
2643} 2643}
2644 2644
2645#ifdef CONFIG_SBUS 2645#ifdef CONFIG_SBUS
2646static int __devinit fore200e_sba_probe(struct of_device *op, 2646static int __devinit fore200e_sba_probe(struct platform_device *op,
2647 const struct of_device_id *match) 2647 const struct of_device_id *match)
2648{ 2648{
2649 const struct fore200e_bus *bus = match->data; 2649 const struct fore200e_bus *bus = match->data;
@@ -2675,7 +2675,7 @@ static int __devinit fore200e_sba_probe(struct of_device *op,
2675 return 0; 2675 return 0;
2676} 2676}
2677 2677
2678static int __devexit fore200e_sba_remove(struct of_device *op) 2678static int __devexit fore200e_sba_remove(struct platform_device *op)
2679{ 2679{
2680 struct fore200e *fore200e = dev_get_drvdata(&op->dev); 2680 struct fore200e *fore200e = dev_get_drvdata(&op->dev);
2681 2681
diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
index 6174965d9a4d..f916ddf63938 100644
--- a/drivers/atm/solos-pci.c
+++ b/drivers/atm/solos-pci.c
@@ -781,7 +781,8 @@ static struct atm_vcc *find_vcc(struct atm_dev *dev, short vpi, int vci)
781 sk_for_each(s, node, head) { 781 sk_for_each(s, node, head) {
782 vcc = atm_sk(s); 782 vcc = atm_sk(s);
783 if (vcc->dev == dev && vcc->vci == vci && 783 if (vcc->dev == dev && vcc->vci == vci &&
784 vcc->vpi == vpi && vcc->qos.rxtp.traffic_class != ATM_NONE) 784 vcc->vpi == vpi && vcc->qos.rxtp.traffic_class != ATM_NONE &&
785 test_bit(ATM_VF_READY, &vcc->flags))
785 goto out; 786 goto out;
786 } 787 }
787 vcc = NULL; 788 vcc = NULL;
@@ -907,6 +908,10 @@ static void pclose(struct atm_vcc *vcc)
907 clear_bit(ATM_VF_ADDR, &vcc->flags); 908 clear_bit(ATM_VF_ADDR, &vcc->flags);
908 clear_bit(ATM_VF_READY, &vcc->flags); 909 clear_bit(ATM_VF_READY, &vcc->flags);
909 910
911 /* Hold up vcc_destroy_socket() (our caller) until solos_bh() in the
912 tasklet has finished processing any incoming packets (and, more to
913 the point, using the vcc pointer). */
914 tasklet_unlock_wait(&card->tlet);
910 return; 915 return;
911} 916}
912 917
diff --git a/drivers/base/node.c b/drivers/base/node.c
index 2bdd8a94ec94..2872e86837b2 100644
--- a/drivers/base/node.c
+++ b/drivers/base/node.c
@@ -66,8 +66,7 @@ static ssize_t node_read_meminfo(struct sys_device * dev,
66 struct sysinfo i; 66 struct sysinfo i;
67 67
68 si_meminfo_node(&i, nid); 68 si_meminfo_node(&i, nid);
69 69 n = sprintf(buf,
70 n = sprintf(buf, "\n"
71 "Node %d MemTotal: %8lu kB\n" 70 "Node %d MemTotal: %8lu kB\n"
72 "Node %d MemFree: %8lu kB\n" 71 "Node %d MemFree: %8lu kB\n"
73 "Node %d MemUsed: %8lu kB\n" 72 "Node %d MemUsed: %8lu kB\n"
@@ -78,13 +77,33 @@ static ssize_t node_read_meminfo(struct sys_device * dev,
78 "Node %d Active(file): %8lu kB\n" 77 "Node %d Active(file): %8lu kB\n"
79 "Node %d Inactive(file): %8lu kB\n" 78 "Node %d Inactive(file): %8lu kB\n"
80 "Node %d Unevictable: %8lu kB\n" 79 "Node %d Unevictable: %8lu kB\n"
81 "Node %d Mlocked: %8lu kB\n" 80 "Node %d Mlocked: %8lu kB\n",
81 nid, K(i.totalram),
82 nid, K(i.freeram),
83 nid, K(i.totalram - i.freeram),
84 nid, K(node_page_state(nid, NR_ACTIVE_ANON) +
85 node_page_state(nid, NR_ACTIVE_FILE)),
86 nid, K(node_page_state(nid, NR_INACTIVE_ANON) +
87 node_page_state(nid, NR_INACTIVE_FILE)),
88 nid, K(node_page_state(nid, NR_ACTIVE_ANON)),
89 nid, K(node_page_state(nid, NR_INACTIVE_ANON)),
90 nid, K(node_page_state(nid, NR_ACTIVE_FILE)),
91 nid, K(node_page_state(nid, NR_INACTIVE_FILE)),
92 nid, K(node_page_state(nid, NR_UNEVICTABLE)),
93 nid, K(node_page_state(nid, NR_MLOCK)));
94
82#ifdef CONFIG_HIGHMEM 95#ifdef CONFIG_HIGHMEM
96 n += sprintf(buf + n,
83 "Node %d HighTotal: %8lu kB\n" 97 "Node %d HighTotal: %8lu kB\n"
84 "Node %d HighFree: %8lu kB\n" 98 "Node %d HighFree: %8lu kB\n"
85 "Node %d LowTotal: %8lu kB\n" 99 "Node %d LowTotal: %8lu kB\n"
86 "Node %d LowFree: %8lu kB\n" 100 "Node %d LowFree: %8lu kB\n",
101 nid, K(i.totalhigh),
102 nid, K(i.freehigh),
103 nid, K(i.totalram - i.totalhigh),
104 nid, K(i.freeram - i.freehigh));
87#endif 105#endif
106 n += sprintf(buf + n,
88 "Node %d Dirty: %8lu kB\n" 107 "Node %d Dirty: %8lu kB\n"
89 "Node %d Writeback: %8lu kB\n" 108 "Node %d Writeback: %8lu kB\n"
90 "Node %d FilePages: %8lu kB\n" 109 "Node %d FilePages: %8lu kB\n"
@@ -99,25 +118,6 @@ static ssize_t node_read_meminfo(struct sys_device * dev,
99 "Node %d Slab: %8lu kB\n" 118 "Node %d Slab: %8lu kB\n"
100 "Node %d SReclaimable: %8lu kB\n" 119 "Node %d SReclaimable: %8lu kB\n"
101 "Node %d SUnreclaim: %8lu kB\n", 120 "Node %d SUnreclaim: %8lu kB\n",
102 nid, K(i.totalram),
103 nid, K(i.freeram),
104 nid, K(i.totalram - i.freeram),
105 nid, K(node_page_state(nid, NR_ACTIVE_ANON) +
106 node_page_state(nid, NR_ACTIVE_FILE)),
107 nid, K(node_page_state(nid, NR_INACTIVE_ANON) +
108 node_page_state(nid, NR_INACTIVE_FILE)),
109 nid, K(node_page_state(nid, NR_ACTIVE_ANON)),
110 nid, K(node_page_state(nid, NR_INACTIVE_ANON)),
111 nid, K(node_page_state(nid, NR_ACTIVE_FILE)),
112 nid, K(node_page_state(nid, NR_INACTIVE_FILE)),
113 nid, K(node_page_state(nid, NR_UNEVICTABLE)),
114 nid, K(node_page_state(nid, NR_MLOCK)),
115#ifdef CONFIG_HIGHMEM
116 nid, K(i.totalhigh),
117 nid, K(i.freehigh),
118 nid, K(i.totalram - i.totalhigh),
119 nid, K(i.freeram - i.freehigh),
120#endif
121 nid, K(node_page_state(nid, NR_FILE_DIRTY)), 121 nid, K(node_page_state(nid, NR_FILE_DIRTY)),
122 nid, K(node_page_state(nid, NR_WRITEBACK)), 122 nid, K(node_page_state(nid, NR_WRITEBACK)),
123 nid, K(node_page_state(nid, NR_FILE_PAGES)), 123 nid, K(node_page_state(nid, NR_FILE_PAGES)),
diff --git a/drivers/block/DAC960.c b/drivers/block/DAC960.c
index c5f22bb0a48e..4e2c367fec11 100644
--- a/drivers/block/DAC960.c
+++ b/drivers/block/DAC960.c
@@ -79,23 +79,28 @@ static int DAC960_open(struct block_device *bdev, fmode_t mode)
79 struct gendisk *disk = bdev->bd_disk; 79 struct gendisk *disk = bdev->bd_disk;
80 DAC960_Controller_T *p = disk->queue->queuedata; 80 DAC960_Controller_T *p = disk->queue->queuedata;
81 int drive_nr = (long)disk->private_data; 81 int drive_nr = (long)disk->private_data;
82 int ret = -ENXIO;
82 83
84 lock_kernel();
83 if (p->FirmwareType == DAC960_V1_Controller) { 85 if (p->FirmwareType == DAC960_V1_Controller) {
84 if (p->V1.LogicalDriveInformation[drive_nr]. 86 if (p->V1.LogicalDriveInformation[drive_nr].
85 LogicalDriveState == DAC960_V1_LogicalDrive_Offline) 87 LogicalDriveState == DAC960_V1_LogicalDrive_Offline)
86 return -ENXIO; 88 goto out;
87 } else { 89 } else {
88 DAC960_V2_LogicalDeviceInfo_T *i = 90 DAC960_V2_LogicalDeviceInfo_T *i =
89 p->V2.LogicalDeviceInformation[drive_nr]; 91 p->V2.LogicalDeviceInformation[drive_nr];
90 if (!i || i->LogicalDeviceState == DAC960_V2_LogicalDevice_Offline) 92 if (!i || i->LogicalDeviceState == DAC960_V2_LogicalDevice_Offline)
91 return -ENXIO; 93 goto out;
92 } 94 }
93 95
94 check_disk_change(bdev); 96 check_disk_change(bdev);
95 97
96 if (!get_capacity(p->disks[drive_nr])) 98 if (!get_capacity(p->disks[drive_nr]))
97 return -ENXIO; 99 goto out;
98 return 0; 100 ret = 0;
101out:
102 unlock_kernel();
103 return ret;
99} 104}
100 105
101static int DAC960_getgeo(struct block_device *bdev, struct hd_geometry *geo) 106static int DAC960_getgeo(struct block_device *bdev, struct hd_geometry *geo)
diff --git a/drivers/block/amiflop.c b/drivers/block/amiflop.c
index 832798aa14f6..76f114f0bba3 100644
--- a/drivers/block/amiflop.c
+++ b/drivers/block/amiflop.c
@@ -60,6 +60,7 @@
60#include <linux/hdreg.h> 60#include <linux/hdreg.h>
61#include <linux/delay.h> 61#include <linux/delay.h>
62#include <linux/init.h> 62#include <linux/init.h>
63#include <linux/smp_lock.h>
63#include <linux/amifdreg.h> 64#include <linux/amifdreg.h>
64#include <linux/amifd.h> 65#include <linux/amifd.h>
65#include <linux/buffer_head.h> 66#include <linux/buffer_head.h>
@@ -1423,7 +1424,7 @@ static int fd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
1423 return 0; 1424 return 0;
1424} 1425}
1425 1426
1426static int fd_ioctl(struct block_device *bdev, fmode_t mode, 1427static int fd_locked_ioctl(struct block_device *bdev, fmode_t mode,
1427 unsigned int cmd, unsigned long param) 1428 unsigned int cmd, unsigned long param)
1428{ 1429{
1429 struct amiga_floppy_struct *p = bdev->bd_disk->private_data; 1430 struct amiga_floppy_struct *p = bdev->bd_disk->private_data;
@@ -1500,6 +1501,18 @@ static int fd_ioctl(struct block_device *bdev, fmode_t mode,
1500 return 0; 1501 return 0;
1501} 1502}
1502 1503
1504static int fd_ioctl(struct block_device *bdev, fmode_t mode,
1505 unsigned int cmd, unsigned long param)
1506{
1507 int ret;
1508
1509 lock_kernel();
1510 ret = fd_locked_ioctl(bdev, mode, cmd, param);
1511 unlock_kernel();
1512
1513 return ret;
1514}
1515
1503static void fd_probe(int dev) 1516static void fd_probe(int dev)
1504{ 1517{
1505 unsigned long code; 1518 unsigned long code;
@@ -1542,10 +1555,13 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
1542 int old_dev; 1555 int old_dev;
1543 unsigned long flags; 1556 unsigned long flags;
1544 1557
1558 lock_kernel();
1545 old_dev = fd_device[drive]; 1559 old_dev = fd_device[drive];
1546 1560
1547 if (fd_ref[drive] && old_dev != system) 1561 if (fd_ref[drive] && old_dev != system) {
1562 unlock_kernel();
1548 return -EBUSY; 1563 return -EBUSY;
1564 }
1549 1565
1550 if (mode & (FMODE_READ|FMODE_WRITE)) { 1566 if (mode & (FMODE_READ|FMODE_WRITE)) {
1551 check_disk_change(bdev); 1567 check_disk_change(bdev);
@@ -1558,8 +1574,10 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
1558 fd_deselect (drive); 1574 fd_deselect (drive);
1559 rel_fdc(); 1575 rel_fdc();
1560 1576
1561 if (wrprot) 1577 if (wrprot) {
1578 unlock_kernel();
1562 return -EROFS; 1579 return -EROFS;
1580 }
1563 } 1581 }
1564 } 1582 }
1565 1583
@@ -1576,6 +1594,7 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
1576 printk(KERN_INFO "fd%d: accessing %s-disk with %s-layout\n",drive, 1594 printk(KERN_INFO "fd%d: accessing %s-disk with %s-layout\n",drive,
1577 unit[drive].type->name, data_types[system].name); 1595 unit[drive].type->name, data_types[system].name);
1578 1596
1597 unlock_kernel();
1579 return 0; 1598 return 0;
1580} 1599}
1581 1600
@@ -1584,6 +1603,7 @@ static int floppy_release(struct gendisk *disk, fmode_t mode)
1584 struct amiga_floppy_struct *p = disk->private_data; 1603 struct amiga_floppy_struct *p = disk->private_data;
1585 int drive = p - unit; 1604 int drive = p - unit;
1586 1605
1606 lock_kernel();
1587 if (unit[drive].dirty == 1) { 1607 if (unit[drive].dirty == 1) {
1588 del_timer (flush_track_timer + drive); 1608 del_timer (flush_track_timer + drive);
1589 non_int_flush_track (drive); 1609 non_int_flush_track (drive);
@@ -1597,6 +1617,7 @@ static int floppy_release(struct gendisk *disk, fmode_t mode)
1597/* the mod_use counter is handled this way */ 1617/* the mod_use counter is handled this way */
1598 floppy_off (drive | 0x40000000); 1618 floppy_off (drive | 0x40000000);
1599#endif 1619#endif
1620 unlock_kernel();
1600 return 0; 1621 return 0;
1601} 1622}
1602 1623
@@ -1638,7 +1659,7 @@ static const struct block_device_operations floppy_fops = {
1638 .owner = THIS_MODULE, 1659 .owner = THIS_MODULE,
1639 .open = floppy_open, 1660 .open = floppy_open,
1640 .release = floppy_release, 1661 .release = floppy_release,
1641 .locked_ioctl = fd_ioctl, 1662 .ioctl = fd_ioctl,
1642 .getgeo = fd_getgeo, 1663 .getgeo = fd_getgeo,
1643 .media_changed = amiga_floppy_change, 1664 .media_changed = amiga_floppy_change,
1644}; 1665};
diff --git a/drivers/block/aoe/aoeblk.c b/drivers/block/aoe/aoeblk.c
index 035cefe4045a..a946929735a5 100644
--- a/drivers/block/aoe/aoeblk.c
+++ b/drivers/block/aoe/aoeblk.c
@@ -12,6 +12,7 @@
12#include <linux/slab.h> 12#include <linux/slab.h>
13#include <linux/genhd.h> 13#include <linux/genhd.h>
14#include <linux/netdevice.h> 14#include <linux/netdevice.h>
15#include <linux/smp_lock.h>
15#include "aoe.h" 16#include "aoe.h"
16 17
17static struct kmem_cache *buf_pool_cache; 18static struct kmem_cache *buf_pool_cache;
@@ -124,13 +125,16 @@ aoeblk_open(struct block_device *bdev, fmode_t mode)
124 struct aoedev *d = bdev->bd_disk->private_data; 125 struct aoedev *d = bdev->bd_disk->private_data;
125 ulong flags; 126 ulong flags;
126 127
128 lock_kernel();
127 spin_lock_irqsave(&d->lock, flags); 129 spin_lock_irqsave(&d->lock, flags);
128 if (d->flags & DEVFL_UP) { 130 if (d->flags & DEVFL_UP) {
129 d->nopen++; 131 d->nopen++;
130 spin_unlock_irqrestore(&d->lock, flags); 132 spin_unlock_irqrestore(&d->lock, flags);
133 unlock_kernel();
131 return 0; 134 return 0;
132 } 135 }
133 spin_unlock_irqrestore(&d->lock, flags); 136 spin_unlock_irqrestore(&d->lock, flags);
137 unlock_kernel();
134 return -ENODEV; 138 return -ENODEV;
135} 139}
136 140
@@ -173,7 +177,7 @@ aoeblk_make_request(struct request_queue *q, struct bio *bio)
173 BUG(); 177 BUG();
174 bio_endio(bio, -ENXIO); 178 bio_endio(bio, -ENXIO);
175 return 0; 179 return 0;
176 } else if (bio_rw_flagged(bio, BIO_RW_BARRIER)) { 180 } else if (bio->bi_rw & REQ_HARDBARRIER) {
177 bio_endio(bio, -EOPNOTSUPP); 181 bio_endio(bio, -EOPNOTSUPP);
178 return 0; 182 return 0;
179 } else if (bio->bi_io_vec == NULL) { 183 } else if (bio->bi_io_vec == NULL) {
diff --git a/drivers/block/ataflop.c b/drivers/block/ataflop.c
index e35cf59cbfde..aceb96476524 100644
--- a/drivers/block/ataflop.c
+++ b/drivers/block/ataflop.c
@@ -67,6 +67,7 @@
67#include <linux/delay.h> 67#include <linux/delay.h>
68#include <linux/init.h> 68#include <linux/init.h>
69#include <linux/blkdev.h> 69#include <linux/blkdev.h>
70#include <linux/smp_lock.h>
70 71
71#include <asm/atafd.h> 72#include <asm/atafd.h>
72#include <asm/atafdreg.h> 73#include <asm/atafdreg.h>
@@ -359,7 +360,7 @@ static void finish_fdc( void );
359static void finish_fdc_done( int dummy ); 360static void finish_fdc_done( int dummy );
360static void setup_req_params( int drive ); 361static void setup_req_params( int drive );
361static void redo_fd_request( void); 362static void redo_fd_request( void);
362static int fd_ioctl(struct block_device *bdev, fmode_t mode, unsigned int 363static int fd_locked_ioctl(struct block_device *bdev, fmode_t mode, unsigned int
363 cmd, unsigned long param); 364 cmd, unsigned long param);
364static void fd_probe( int drive ); 365static void fd_probe( int drive );
365static int fd_test_drive_present( int drive ); 366static int fd_test_drive_present( int drive );
@@ -1480,7 +1481,7 @@ void do_fd_request(struct request_queue * q)
1480 atari_enable_irq( IRQ_MFP_FDC ); 1481 atari_enable_irq( IRQ_MFP_FDC );
1481} 1482}
1482 1483
1483static int fd_ioctl(struct block_device *bdev, fmode_t mode, 1484static int fd_locked_ioctl(struct block_device *bdev, fmode_t mode,
1484 unsigned int cmd, unsigned long param) 1485 unsigned int cmd, unsigned long param)
1485{ 1486{
1486 struct gendisk *disk = bdev->bd_disk; 1487 struct gendisk *disk = bdev->bd_disk;
@@ -1665,6 +1666,17 @@ static int fd_ioctl(struct block_device *bdev, fmode_t mode,
1665 } 1666 }
1666} 1667}
1667 1668
1669static int fd_ioctl(struct block_device *bdev, fmode_t mode,
1670 unsigned int cmd, unsigned long arg)
1671{
1672 int ret;
1673
1674 lock_kernel();
1675 ret = fd_locked_ioctl(bdev, mode, cmd, arg);
1676 unlock_kernel();
1677
1678 return ret;
1679}
1668 1680
1669/* Initialize the 'unit' variable for drive 'drive' */ 1681/* Initialize the 'unit' variable for drive 'drive' */
1670 1682
@@ -1838,24 +1850,36 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
1838 return 0; 1850 return 0;
1839} 1851}
1840 1852
1853static int floppy_unlocked_open(struct block_device *bdev, fmode_t mode)
1854{
1855 int ret;
1856
1857 lock_kernel();
1858 ret = floppy_open(bdev, mode);
1859 unlock_kernel();
1860
1861 return ret;
1862}
1841 1863
1842static int floppy_release(struct gendisk *disk, fmode_t mode) 1864static int floppy_release(struct gendisk *disk, fmode_t mode)
1843{ 1865{
1844 struct atari_floppy_struct *p = disk->private_data; 1866 struct atari_floppy_struct *p = disk->private_data;
1867 lock_kernel();
1845 if (p->ref < 0) 1868 if (p->ref < 0)
1846 p->ref = 0; 1869 p->ref = 0;
1847 else if (!p->ref--) { 1870 else if (!p->ref--) {
1848 printk(KERN_ERR "floppy_release with fd_ref == 0"); 1871 printk(KERN_ERR "floppy_release with fd_ref == 0");
1849 p->ref = 0; 1872 p->ref = 0;
1850 } 1873 }
1874 unlock_kernel();
1851 return 0; 1875 return 0;
1852} 1876}
1853 1877
1854static const struct block_device_operations floppy_fops = { 1878static const struct block_device_operations floppy_fops = {
1855 .owner = THIS_MODULE, 1879 .owner = THIS_MODULE,
1856 .open = floppy_open, 1880 .open = floppy_unlocked_open,
1857 .release = floppy_release, 1881 .release = floppy_release,
1858 .locked_ioctl = fd_ioctl, 1882 .ioctl = fd_ioctl,
1859 .media_changed = check_floppy_change, 1883 .media_changed = check_floppy_change,
1860 .revalidate_disk= floppy_revalidate, 1884 .revalidate_disk= floppy_revalidate,
1861}; 1885};
diff --git a/drivers/block/brd.c b/drivers/block/brd.c
index f1bf79d9bc0a..1c7f63792ff8 100644
--- a/drivers/block/brd.c
+++ b/drivers/block/brd.c
@@ -15,6 +15,7 @@
15#include <linux/blkdev.h> 15#include <linux/blkdev.h>
16#include <linux/bio.h> 16#include <linux/bio.h>
17#include <linux/highmem.h> 17#include <linux/highmem.h>
18#include <linux/smp_lock.h>
18#include <linux/radix-tree.h> 19#include <linux/radix-tree.h>
19#include <linux/buffer_head.h> /* invalidate_bh_lrus() */ 20#include <linux/buffer_head.h> /* invalidate_bh_lrus() */
20#include <linux/slab.h> 21#include <linux/slab.h>
@@ -340,7 +341,7 @@ static int brd_make_request(struct request_queue *q, struct bio *bio)
340 get_capacity(bdev->bd_disk)) 341 get_capacity(bdev->bd_disk))
341 goto out; 342 goto out;
342 343
343 if (unlikely(bio_rw_flagged(bio, BIO_RW_DISCARD))) { 344 if (unlikely(bio->bi_rw & REQ_DISCARD)) {
344 err = 0; 345 err = 0;
345 discard_from_brd(brd, sector, bio->bi_size); 346 discard_from_brd(brd, sector, bio->bi_size);
346 goto out; 347 goto out;
@@ -401,6 +402,7 @@ static int brd_ioctl(struct block_device *bdev, fmode_t mode,
401 * ram device BLKFLSBUF has special semantics, we want to actually 402 * ram device BLKFLSBUF has special semantics, we want to actually
402 * release and destroy the ramdisk data. 403 * release and destroy the ramdisk data.
403 */ 404 */
405 lock_kernel();
404 mutex_lock(&bdev->bd_mutex); 406 mutex_lock(&bdev->bd_mutex);
405 error = -EBUSY; 407 error = -EBUSY;
406 if (bdev->bd_openers <= 1) { 408 if (bdev->bd_openers <= 1) {
@@ -417,13 +419,14 @@ static int brd_ioctl(struct block_device *bdev, fmode_t mode,
417 error = 0; 419 error = 0;
418 } 420 }
419 mutex_unlock(&bdev->bd_mutex); 421 mutex_unlock(&bdev->bd_mutex);
422 unlock_kernel();
420 423
421 return error; 424 return error;
422} 425}
423 426
424static const struct block_device_operations brd_fops = { 427static const struct block_device_operations brd_fops = {
425 .owner = THIS_MODULE, 428 .owner = THIS_MODULE,
426 .locked_ioctl = brd_ioctl, 429 .ioctl = brd_ioctl,
427#ifdef CONFIG_BLK_DEV_XIP 430#ifdef CONFIG_BLK_DEV_XIP
428 .direct_access = brd_direct_access, 431 .direct_access = brd_direct_access,
429#endif 432#endif
@@ -479,7 +482,7 @@ static struct brd_device *brd_alloc(int i)
479 if (!brd->brd_queue) 482 if (!brd->brd_queue)
480 goto out_free_dev; 483 goto out_free_dev;
481 blk_queue_make_request(brd->brd_queue, brd_make_request); 484 blk_queue_make_request(brd->brd_queue, brd_make_request);
482 blk_queue_ordered(brd->brd_queue, QUEUE_ORDERED_TAG, NULL); 485 blk_queue_ordered(brd->brd_queue, QUEUE_ORDERED_TAG);
483 blk_queue_max_hw_sectors(brd->brd_queue, 1024); 486 blk_queue_max_hw_sectors(brd->brd_queue, 1024);
484 blk_queue_bounce_limit(brd->brd_queue, BLK_BOUNCE_ANY); 487 blk_queue_bounce_limit(brd->brd_queue, BLK_BOUNCE_ANY);
485 488
diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
index e1e7143ca1e3..31064df1370a 100644
--- a/drivers/block/cciss.c
+++ b/drivers/block/cciss.c
@@ -56,16 +56,14 @@
56#include <linux/kthread.h> 56#include <linux/kthread.h>
57 57
58#define CCISS_DRIVER_VERSION(maj,min,submin) ((maj<<16)|(min<<8)|(submin)) 58#define CCISS_DRIVER_VERSION(maj,min,submin) ((maj<<16)|(min<<8)|(submin))
59#define DRIVER_NAME "HP CISS Driver (v 3.6.20)" 59#define DRIVER_NAME "HP CISS Driver (v 3.6.26)"
60#define DRIVER_VERSION CCISS_DRIVER_VERSION(3, 6, 20) 60#define DRIVER_VERSION CCISS_DRIVER_VERSION(3, 6, 26)
61 61
62/* Embedded module documentation macros - see modules.h */ 62/* Embedded module documentation macros - see modules.h */
63MODULE_AUTHOR("Hewlett-Packard Company"); 63MODULE_AUTHOR("Hewlett-Packard Company");
64MODULE_DESCRIPTION("Driver for HP Smart Array Controllers"); 64MODULE_DESCRIPTION("Driver for HP Smart Array Controllers");
65MODULE_SUPPORTED_DEVICE("HP SA5i SA5i+ SA532 SA5300 SA5312 SA641 SA642 SA6400" 65MODULE_SUPPORTED_DEVICE("HP Smart Array Controllers");
66 " SA6i P600 P800 P400 P400i E200 E200i E500 P700m" 66MODULE_VERSION("3.6.26");
67 " Smart Array G2 Series SAS/SATA Controllers");
68MODULE_VERSION("3.6.20");
69MODULE_LICENSE("GPL"); 67MODULE_LICENSE("GPL");
70 68
71static int cciss_allow_hpsa; 69static int cciss_allow_hpsa;
@@ -107,6 +105,11 @@ static const struct pci_device_id cciss_pci_device_id[] = {
107 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3249}, 105 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3249},
108 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x324A}, 106 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x324A},
109 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x324B}, 107 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x324B},
108 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3250},
109 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3251},
110 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3252},
111 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3253},
112 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3254},
110 {0,} 113 {0,}
111}; 114};
112 115
@@ -146,6 +149,11 @@ static struct board_type products[] = {
146 {0x3249103C, "Smart Array P812", &SA5_access}, 149 {0x3249103C, "Smart Array P812", &SA5_access},
147 {0x324A103C, "Smart Array P712m", &SA5_access}, 150 {0x324A103C, "Smart Array P712m", &SA5_access},
148 {0x324B103C, "Smart Array P711m", &SA5_access}, 151 {0x324B103C, "Smart Array P711m", &SA5_access},
152 {0x3250103C, "Smart Array", &SA5_access},
153 {0x3251103C, "Smart Array", &SA5_access},
154 {0x3252103C, "Smart Array", &SA5_access},
155 {0x3253103C, "Smart Array", &SA5_access},
156 {0x3254103C, "Smart Array", &SA5_access},
149}; 157};
150 158
151/* How long to wait (in milliseconds) for board to go into simple mode */ 159/* How long to wait (in milliseconds) for board to go into simple mode */
@@ -167,9 +175,13 @@ static DEFINE_MUTEX(scan_mutex);
167static LIST_HEAD(scan_q); 175static LIST_HEAD(scan_q);
168 176
169static void do_cciss_request(struct request_queue *q); 177static void do_cciss_request(struct request_queue *q);
170static irqreturn_t do_cciss_intr(int irq, void *dev_id); 178static irqreturn_t do_cciss_intx(int irq, void *dev_id);
179static irqreturn_t do_cciss_msix_intr(int irq, void *dev_id);
171static int cciss_open(struct block_device *bdev, fmode_t mode); 180static int cciss_open(struct block_device *bdev, fmode_t mode);
181static int cciss_unlocked_open(struct block_device *bdev, fmode_t mode);
172static int cciss_release(struct gendisk *disk, fmode_t mode); 182static int cciss_release(struct gendisk *disk, fmode_t mode);
183static int do_ioctl(struct block_device *bdev, fmode_t mode,
184 unsigned int cmd, unsigned long arg);
173static int cciss_ioctl(struct block_device *bdev, fmode_t mode, 185static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
174 unsigned int cmd, unsigned long arg); 186 unsigned int cmd, unsigned long arg);
175static int cciss_getgeo(struct block_device *bdev, struct hd_geometry *geo); 187static int cciss_getgeo(struct block_device *bdev, struct hd_geometry *geo);
@@ -179,25 +191,23 @@ static int rebuild_lun_table(ctlr_info_t *h, int first_time, int via_ioctl);
179static int deregister_disk(ctlr_info_t *h, int drv_index, 191static int deregister_disk(ctlr_info_t *h, int drv_index,
180 int clear_all, int via_ioctl); 192 int clear_all, int via_ioctl);
181 193
182static void cciss_read_capacity(int ctlr, int logvol, 194static void cciss_read_capacity(ctlr_info_t *h, int logvol,
183 sector_t *total_size, unsigned int *block_size); 195 sector_t *total_size, unsigned int *block_size);
184static void cciss_read_capacity_16(int ctlr, int logvol, 196static void cciss_read_capacity_16(ctlr_info_t *h, int logvol,
185 sector_t *total_size, unsigned int *block_size); 197 sector_t *total_size, unsigned int *block_size);
186static void cciss_geometry_inquiry(int ctlr, int logvol, 198static void cciss_geometry_inquiry(ctlr_info_t *h, int logvol,
187 sector_t total_size, 199 sector_t total_size,
188 unsigned int block_size, InquiryData_struct *inq_buff, 200 unsigned int block_size, InquiryData_struct *inq_buff,
189 drive_info_struct *drv); 201 drive_info_struct *drv);
190static void __devinit cciss_interrupt_mode(ctlr_info_t *, struct pci_dev *, 202static void __devinit cciss_interrupt_mode(ctlr_info_t *);
191 __u32);
192static void start_io(ctlr_info_t *h); 203static void start_io(ctlr_info_t *h);
193static int sendcmd_withirq(__u8 cmd, int ctlr, void *buff, size_t size, 204static int sendcmd_withirq(ctlr_info_t *h, __u8 cmd, void *buff, size_t size,
194 __u8 page_code, unsigned char scsi3addr[], 205 __u8 page_code, unsigned char scsi3addr[],
195 int cmd_type); 206 int cmd_type);
196static int sendcmd_withirq_core(ctlr_info_t *h, CommandList_struct *c, 207static int sendcmd_withirq_core(ctlr_info_t *h, CommandList_struct *c,
197 int attempt_retry); 208 int attempt_retry);
198static int process_sendcmd_error(ctlr_info_t *h, CommandList_struct *c); 209static int process_sendcmd_error(ctlr_info_t *h, CommandList_struct *c);
199 210
200static void fail_all_cmds(unsigned long ctlr);
201static int add_to_scan_list(struct ctlr_info *h); 211static int add_to_scan_list(struct ctlr_info *h);
202static int scan_thread(void *data); 212static int scan_thread(void *data);
203static int check_for_unit_attention(ctlr_info_t *h, CommandList_struct *c); 213static int check_for_unit_attention(ctlr_info_t *h, CommandList_struct *c);
@@ -205,11 +215,23 @@ static void cciss_hba_release(struct device *dev);
205static void cciss_device_release(struct device *dev); 215static void cciss_device_release(struct device *dev);
206static void cciss_free_gendisk(ctlr_info_t *h, int drv_index); 216static void cciss_free_gendisk(ctlr_info_t *h, int drv_index);
207static void cciss_free_drive_info(ctlr_info_t *h, int drv_index); 217static void cciss_free_drive_info(ctlr_info_t *h, int drv_index);
218static inline u32 next_command(ctlr_info_t *h);
219static int __devinit cciss_find_cfg_addrs(struct pci_dev *pdev,
220 void __iomem *vaddr, u32 *cfg_base_addr, u64 *cfg_base_addr_index,
221 u64 *cfg_offset);
222static int __devinit cciss_pci_find_memory_BAR(struct pci_dev *pdev,
223 unsigned long *memory_bar);
224
225
226/* performant mode helper functions */
227static void calc_bucket_map(int *bucket, int num_buckets, int nsgs,
228 int *bucket_map);
229static void cciss_put_controller_into_performant_mode(ctlr_info_t *h);
208 230
209#ifdef CONFIG_PROC_FS 231#ifdef CONFIG_PROC_FS
210static void cciss_procinit(int i); 232static void cciss_procinit(ctlr_info_t *h);
211#else 233#else
212static void cciss_procinit(int i) 234static void cciss_procinit(ctlr_info_t *h)
213{ 235{
214} 236}
215#endif /* CONFIG_PROC_FS */ 237#endif /* CONFIG_PROC_FS */
@@ -221,9 +243,9 @@ static int cciss_compat_ioctl(struct block_device *, fmode_t,
221 243
222static const struct block_device_operations cciss_fops = { 244static const struct block_device_operations cciss_fops = {
223 .owner = THIS_MODULE, 245 .owner = THIS_MODULE,
224 .open = cciss_open, 246 .open = cciss_unlocked_open,
225 .release = cciss_release, 247 .release = cciss_release,
226 .locked_ioctl = cciss_ioctl, 248 .ioctl = do_ioctl,
227 .getgeo = cciss_getgeo, 249 .getgeo = cciss_getgeo,
228#ifdef CONFIG_COMPAT 250#ifdef CONFIG_COMPAT
229 .compat_ioctl = cciss_compat_ioctl, 251 .compat_ioctl = cciss_compat_ioctl,
@@ -231,6 +253,16 @@ static const struct block_device_operations cciss_fops = {
231 .revalidate_disk = cciss_revalidate, 253 .revalidate_disk = cciss_revalidate,
232}; 254};
233 255
256/* set_performant_mode: Modify the tag for cciss performant
257 * set bit 0 for pull model, bits 3-1 for block fetch
258 * register number
259 */
260static void set_performant_mode(ctlr_info_t *h, CommandList_struct *c)
261{
262 if (likely(h->transMethod == CFGTBL_Trans_Performant))
263 c->busaddr |= 1 | (h->blockFetchTable[c->Header.SGList] << 1);
264}
265
234/* 266/*
235 * Enqueuing and dequeuing functions for cmdlists. 267 * Enqueuing and dequeuing functions for cmdlists.
236 */ 268 */
@@ -257,6 +289,18 @@ static inline void removeQ(CommandList_struct *c)
257 hlist_del_init(&c->list); 289 hlist_del_init(&c->list);
258} 290}
259 291
292static void enqueue_cmd_and_start_io(ctlr_info_t *h,
293 CommandList_struct *c)
294{
295 unsigned long flags;
296 set_performant_mode(h, c);
297 spin_lock_irqsave(&h->lock, flags);
298 addQ(&h->reqQ, c);
299 h->Qdepth++;
300 start_io(h);
301 spin_unlock_irqrestore(&h->lock, flags);
302}
303
260static void cciss_free_sg_chain_blocks(SGDescriptor_struct **cmd_sg_list, 304static void cciss_free_sg_chain_blocks(SGDescriptor_struct **cmd_sg_list,
261 int nr_cmds) 305 int nr_cmds)
262{ 306{
@@ -366,32 +410,31 @@ static void cciss_seq_show_header(struct seq_file *seq)
366 h->product_name, 410 h->product_name,
367 (unsigned long)h->board_id, 411 (unsigned long)h->board_id,
368 h->firm_ver[0], h->firm_ver[1], h->firm_ver[2], 412 h->firm_ver[0], h->firm_ver[1], h->firm_ver[2],
369 h->firm_ver[3], (unsigned int)h->intr[SIMPLE_MODE_INT], 413 h->firm_ver[3], (unsigned int)h->intr[PERF_MODE_INT],
370 h->num_luns, 414 h->num_luns,
371 h->Qdepth, h->commands_outstanding, 415 h->Qdepth, h->commands_outstanding,
372 h->maxQsinceinit, h->max_outstanding, h->maxSG); 416 h->maxQsinceinit, h->max_outstanding, h->maxSG);
373 417
374#ifdef CONFIG_CISS_SCSI_TAPE 418#ifdef CONFIG_CISS_SCSI_TAPE
375 cciss_seq_tape_report(seq, h->ctlr); 419 cciss_seq_tape_report(seq, h);
376#endif /* CONFIG_CISS_SCSI_TAPE */ 420#endif /* CONFIG_CISS_SCSI_TAPE */
377} 421}
378 422
379static void *cciss_seq_start(struct seq_file *seq, loff_t *pos) 423static void *cciss_seq_start(struct seq_file *seq, loff_t *pos)
380{ 424{
381 ctlr_info_t *h = seq->private; 425 ctlr_info_t *h = seq->private;
382 unsigned ctlr = h->ctlr;
383 unsigned long flags; 426 unsigned long flags;
384 427
385 /* prevent displaying bogus info during configuration 428 /* prevent displaying bogus info during configuration
386 * or deconfiguration of a logical volume 429 * or deconfiguration of a logical volume
387 */ 430 */
388 spin_lock_irqsave(CCISS_LOCK(ctlr), flags); 431 spin_lock_irqsave(&h->lock, flags);
389 if (h->busy_configuring) { 432 if (h->busy_configuring) {
390 spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags); 433 spin_unlock_irqrestore(&h->lock, flags);
391 return ERR_PTR(-EBUSY); 434 return ERR_PTR(-EBUSY);
392 } 435 }
393 h->busy_configuring = 1; 436 h->busy_configuring = 1;
394 spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags); 437 spin_unlock_irqrestore(&h->lock, flags);
395 438
396 if (*pos == 0) 439 if (*pos == 0)
397 cciss_seq_show_header(seq); 440 cciss_seq_show_header(seq);
@@ -499,7 +542,7 @@ cciss_proc_write(struct file *file, const char __user *buf,
499 struct seq_file *seq = file->private_data; 542 struct seq_file *seq = file->private_data;
500 ctlr_info_t *h = seq->private; 543 ctlr_info_t *h = seq->private;
501 544
502 err = cciss_engage_scsi(h->ctlr); 545 err = cciss_engage_scsi(h);
503 if (err == 0) 546 if (err == 0)
504 err = length; 547 err = length;
505 } else 548 } else
@@ -522,7 +565,7 @@ static const struct file_operations cciss_proc_fops = {
522 .write = cciss_proc_write, 565 .write = cciss_proc_write,
523}; 566};
524 567
525static void __devinit cciss_procinit(int i) 568static void __devinit cciss_procinit(ctlr_info_t *h)
526{ 569{
527 struct proc_dir_entry *pde; 570 struct proc_dir_entry *pde;
528 571
@@ -530,9 +573,9 @@ static void __devinit cciss_procinit(int i)
530 proc_cciss = proc_mkdir("driver/cciss", NULL); 573 proc_cciss = proc_mkdir("driver/cciss", NULL);
531 if (!proc_cciss) 574 if (!proc_cciss)
532 return; 575 return;
533 pde = proc_create_data(hba[i]->devname, S_IWUSR | S_IRUSR | S_IRGRP | 576 pde = proc_create_data(h->devname, S_IWUSR | S_IRUSR | S_IRGRP |
534 S_IROTH, proc_cciss, 577 S_IROTH, proc_cciss,
535 &cciss_proc_fops, hba[i]); 578 &cciss_proc_fops, h);
536} 579}
537#endif /* CONFIG_PROC_FS */ 580#endif /* CONFIG_PROC_FS */
538 581
@@ -565,12 +608,12 @@ static ssize_t dev_show_unique_id(struct device *dev,
565 unsigned long flags; 608 unsigned long flags;
566 int ret = 0; 609 int ret = 0;
567 610
568 spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags); 611 spin_lock_irqsave(&h->lock, flags);
569 if (h->busy_configuring) 612 if (h->busy_configuring)
570 ret = -EBUSY; 613 ret = -EBUSY;
571 else 614 else
572 memcpy(sn, drv->serial_no, sizeof(sn)); 615 memcpy(sn, drv->serial_no, sizeof(sn));
573 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); 616 spin_unlock_irqrestore(&h->lock, flags);
574 617
575 if (ret) 618 if (ret)
576 return ret; 619 return ret;
@@ -595,12 +638,12 @@ static ssize_t dev_show_vendor(struct device *dev,
595 unsigned long flags; 638 unsigned long flags;
596 int ret = 0; 639 int ret = 0;
597 640
598 spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags); 641 spin_lock_irqsave(&h->lock, flags);
599 if (h->busy_configuring) 642 if (h->busy_configuring)
600 ret = -EBUSY; 643 ret = -EBUSY;
601 else 644 else
602 memcpy(vendor, drv->vendor, VENDOR_LEN + 1); 645 memcpy(vendor, drv->vendor, VENDOR_LEN + 1);
603 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); 646 spin_unlock_irqrestore(&h->lock, flags);
604 647
605 if (ret) 648 if (ret)
606 return ret; 649 return ret;
@@ -619,12 +662,12 @@ static ssize_t dev_show_model(struct device *dev,
619 unsigned long flags; 662 unsigned long flags;
620 int ret = 0; 663 int ret = 0;
621 664
622 spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags); 665 spin_lock_irqsave(&h->lock, flags);
623 if (h->busy_configuring) 666 if (h->busy_configuring)
624 ret = -EBUSY; 667 ret = -EBUSY;
625 else 668 else
626 memcpy(model, drv->model, MODEL_LEN + 1); 669 memcpy(model, drv->model, MODEL_LEN + 1);
627 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); 670 spin_unlock_irqrestore(&h->lock, flags);
628 671
629 if (ret) 672 if (ret)
630 return ret; 673 return ret;
@@ -643,12 +686,12 @@ static ssize_t dev_show_rev(struct device *dev,
643 unsigned long flags; 686 unsigned long flags;
644 int ret = 0; 687 int ret = 0;
645 688
646 spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags); 689 spin_lock_irqsave(&h->lock, flags);
647 if (h->busy_configuring) 690 if (h->busy_configuring)
648 ret = -EBUSY; 691 ret = -EBUSY;
649 else 692 else
650 memcpy(rev, drv->rev, REV_LEN + 1); 693 memcpy(rev, drv->rev, REV_LEN + 1);
651 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); 694 spin_unlock_irqrestore(&h->lock, flags);
652 695
653 if (ret) 696 if (ret)
654 return ret; 697 return ret;
@@ -665,17 +708,17 @@ static ssize_t cciss_show_lunid(struct device *dev,
665 unsigned long flags; 708 unsigned long flags;
666 unsigned char lunid[8]; 709 unsigned char lunid[8];
667 710
668 spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags); 711 spin_lock_irqsave(&h->lock, flags);
669 if (h->busy_configuring) { 712 if (h->busy_configuring) {
670 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); 713 spin_unlock_irqrestore(&h->lock, flags);
671 return -EBUSY; 714 return -EBUSY;
672 } 715 }
673 if (!drv->heads) { 716 if (!drv->heads) {
674 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); 717 spin_unlock_irqrestore(&h->lock, flags);
675 return -ENOTTY; 718 return -ENOTTY;
676 } 719 }
677 memcpy(lunid, drv->LunID, sizeof(lunid)); 720 memcpy(lunid, drv->LunID, sizeof(lunid));
678 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); 721 spin_unlock_irqrestore(&h->lock, flags);
679 return snprintf(buf, 20, "0x%02x%02x%02x%02x%02x%02x%02x%02x\n", 722 return snprintf(buf, 20, "0x%02x%02x%02x%02x%02x%02x%02x%02x\n",
680 lunid[0], lunid[1], lunid[2], lunid[3], 723 lunid[0], lunid[1], lunid[2], lunid[3],
681 lunid[4], lunid[5], lunid[6], lunid[7]); 724 lunid[4], lunid[5], lunid[6], lunid[7]);
@@ -690,13 +733,13 @@ static ssize_t cciss_show_raid_level(struct device *dev,
690 int raid; 733 int raid;
691 unsigned long flags; 734 unsigned long flags;
692 735
693 spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags); 736 spin_lock_irqsave(&h->lock, flags);
694 if (h->busy_configuring) { 737 if (h->busy_configuring) {
695 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); 738 spin_unlock_irqrestore(&h->lock, flags);
696 return -EBUSY; 739 return -EBUSY;
697 } 740 }
698 raid = drv->raid_level; 741 raid = drv->raid_level;
699 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); 742 spin_unlock_irqrestore(&h->lock, flags);
700 if (raid < 0 || raid > RAID_UNKNOWN) 743 if (raid < 0 || raid > RAID_UNKNOWN)
701 raid = RAID_UNKNOWN; 744 raid = RAID_UNKNOWN;
702 745
@@ -713,13 +756,13 @@ static ssize_t cciss_show_usage_count(struct device *dev,
713 unsigned long flags; 756 unsigned long flags;
714 int count; 757 int count;
715 758
716 spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags); 759 spin_lock_irqsave(&h->lock, flags);
717 if (h->busy_configuring) { 760 if (h->busy_configuring) {
718 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); 761 spin_unlock_irqrestore(&h->lock, flags);
719 return -EBUSY; 762 return -EBUSY;
720 } 763 }
721 count = drv->usage_count; 764 count = drv->usage_count;
722 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); 765 spin_unlock_irqrestore(&h->lock, flags);
723 return snprintf(buf, 20, "%d\n", count); 766 return snprintf(buf, 20, "%d\n", count);
724} 767}
725static DEVICE_ATTR(usage_count, S_IRUGO, cciss_show_usage_count, NULL); 768static DEVICE_ATTR(usage_count, S_IRUGO, cciss_show_usage_count, NULL);
@@ -864,60 +907,70 @@ static void cciss_destroy_ld_sysfs_entry(struct ctlr_info *h, int drv_index,
864/* 907/*
865 * For operations that cannot sleep, a command block is allocated at init, 908 * For operations that cannot sleep, a command block is allocated at init,
866 * and managed by cmd_alloc() and cmd_free() using a simple bitmap to track 909 * and managed by cmd_alloc() and cmd_free() using a simple bitmap to track
867 * which ones are free or in use. For operations that can wait for kmalloc 910 * which ones are free or in use.
868 * to possible sleep, this routine can be called with get_from_pool set to 0.
869 * cmd_free() MUST be called with a got_from_pool set to 0 if cmd_alloc was.
870 */ 911 */
871static CommandList_struct *cmd_alloc(ctlr_info_t *h, int get_from_pool) 912static CommandList_struct *cmd_alloc(ctlr_info_t *h)
872{ 913{
873 CommandList_struct *c; 914 CommandList_struct *c;
874 int i; 915 int i;
875 u64bit temp64; 916 u64bit temp64;
876 dma_addr_t cmd_dma_handle, err_dma_handle; 917 dma_addr_t cmd_dma_handle, err_dma_handle;
877 918
878 if (!get_from_pool) { 919 do {
879 c = (CommandList_struct *) pci_alloc_consistent(h->pdev, 920 i = find_first_zero_bit(h->cmd_pool_bits, h->nr_cmds);
880 sizeof(CommandList_struct), &cmd_dma_handle); 921 if (i == h->nr_cmds)
881 if (c == NULL)
882 return NULL; 922 return NULL;
883 memset(c, 0, sizeof(CommandList_struct)); 923 } while (test_and_set_bit(i & (BITS_PER_LONG - 1),
924 h->cmd_pool_bits + (i / BITS_PER_LONG)) != 0);
925 c = h->cmd_pool + i;
926 memset(c, 0, sizeof(CommandList_struct));
927 cmd_dma_handle = h->cmd_pool_dhandle + i * sizeof(CommandList_struct);
928 c->err_info = h->errinfo_pool + i;
929 memset(c->err_info, 0, sizeof(ErrorInfo_struct));
930 err_dma_handle = h->errinfo_pool_dhandle
931 + i * sizeof(ErrorInfo_struct);
932 h->nr_allocs++;
884 933
885 c->cmdindex = -1; 934 c->cmdindex = i;
886 935
887 c->err_info = (ErrorInfo_struct *) 936 INIT_HLIST_NODE(&c->list);
888 pci_alloc_consistent(h->pdev, sizeof(ErrorInfo_struct), 937 c->busaddr = (__u32) cmd_dma_handle;
889 &err_dma_handle); 938 temp64.val = (__u64) err_dma_handle;
939 c->ErrDesc.Addr.lower = temp64.val32.lower;
940 c->ErrDesc.Addr.upper = temp64.val32.upper;
941 c->ErrDesc.Len = sizeof(ErrorInfo_struct);
890 942
891 if (c->err_info == NULL) { 943 c->ctlr = h->ctlr;
892 pci_free_consistent(h->pdev, 944 return c;
893 sizeof(CommandList_struct), c, cmd_dma_handle); 945}
894 return NULL;
895 }
896 memset(c->err_info, 0, sizeof(ErrorInfo_struct));
897 } else { /* get it out of the controllers pool */
898
899 do {
900 i = find_first_zero_bit(h->cmd_pool_bits, h->nr_cmds);
901 if (i == h->nr_cmds)
902 return NULL;
903 } while (test_and_set_bit
904 (i & (BITS_PER_LONG - 1),
905 h->cmd_pool_bits + (i / BITS_PER_LONG)) != 0);
906#ifdef CCISS_DEBUG
907 printk(KERN_DEBUG "cciss: using command buffer %d\n", i);
908#endif
909 c = h->cmd_pool + i;
910 memset(c, 0, sizeof(CommandList_struct));
911 cmd_dma_handle = h->cmd_pool_dhandle
912 + i * sizeof(CommandList_struct);
913 c->err_info = h->errinfo_pool + i;
914 memset(c->err_info, 0, sizeof(ErrorInfo_struct));
915 err_dma_handle = h->errinfo_pool_dhandle
916 + i * sizeof(ErrorInfo_struct);
917 h->nr_allocs++;
918 946
919 c->cmdindex = i; 947/* allocate a command using pci_alloc_consistent, used for ioctls,
948 * etc., not for the main i/o path.
949 */
950static CommandList_struct *cmd_special_alloc(ctlr_info_t *h)
951{
952 CommandList_struct *c;
953 u64bit temp64;
954 dma_addr_t cmd_dma_handle, err_dma_handle;
955
956 c = (CommandList_struct *) pci_alloc_consistent(h->pdev,
957 sizeof(CommandList_struct), &cmd_dma_handle);
958 if (c == NULL)
959 return NULL;
960 memset(c, 0, sizeof(CommandList_struct));
961
962 c->cmdindex = -1;
963
964 c->err_info = (ErrorInfo_struct *)
965 pci_alloc_consistent(h->pdev, sizeof(ErrorInfo_struct),
966 &err_dma_handle);
967
968 if (c->err_info == NULL) {
969 pci_free_consistent(h->pdev,
970 sizeof(CommandList_struct), c, cmd_dma_handle);
971 return NULL;
920 } 972 }
973 memset(c->err_info, 0, sizeof(ErrorInfo_struct));
921 974
922 INIT_HLIST_NODE(&c->list); 975 INIT_HLIST_NODE(&c->list);
923 c->busaddr = (__u32) cmd_dma_handle; 976 c->busaddr = (__u32) cmd_dma_handle;
@@ -930,27 +983,26 @@ static CommandList_struct *cmd_alloc(ctlr_info_t *h, int get_from_pool)
930 return c; 983 return c;
931} 984}
932 985
933/* 986static void cmd_free(ctlr_info_t *h, CommandList_struct *c)
934 * Frees a command block that was previously allocated with cmd_alloc().
935 */
936static void cmd_free(ctlr_info_t *h, CommandList_struct *c, int got_from_pool)
937{ 987{
938 int i; 988 int i;
989
990 i = c - h->cmd_pool;
991 clear_bit(i & (BITS_PER_LONG - 1),
992 h->cmd_pool_bits + (i / BITS_PER_LONG));
993 h->nr_frees++;
994}
995
996static void cmd_special_free(ctlr_info_t *h, CommandList_struct *c)
997{
939 u64bit temp64; 998 u64bit temp64;
940 999
941 if (!got_from_pool) { 1000 temp64.val32.lower = c->ErrDesc.Addr.lower;
942 temp64.val32.lower = c->ErrDesc.Addr.lower; 1001 temp64.val32.upper = c->ErrDesc.Addr.upper;
943 temp64.val32.upper = c->ErrDesc.Addr.upper; 1002 pci_free_consistent(h->pdev, sizeof(ErrorInfo_struct),
944 pci_free_consistent(h->pdev, sizeof(ErrorInfo_struct), 1003 c->err_info, (dma_addr_t) temp64.val);
945 c->err_info, (dma_addr_t) temp64.val); 1004 pci_free_consistent(h->pdev, sizeof(CommandList_struct),
946 pci_free_consistent(h->pdev, sizeof(CommandList_struct), 1005 c, (dma_addr_t) c->busaddr);
947 c, (dma_addr_t) c->busaddr);
948 } else {
949 i = c - h->cmd_pool;
950 clear_bit(i & (BITS_PER_LONG - 1),
951 h->cmd_pool_bits + (i / BITS_PER_LONG));
952 h->nr_frees++;
953 }
954} 1006}
955 1007
956static inline ctlr_info_t *get_host(struct gendisk *disk) 1008static inline ctlr_info_t *get_host(struct gendisk *disk)
@@ -968,13 +1020,10 @@ static inline drive_info_struct *get_drv(struct gendisk *disk)
968 */ 1020 */
969static int cciss_open(struct block_device *bdev, fmode_t mode) 1021static int cciss_open(struct block_device *bdev, fmode_t mode)
970{ 1022{
971 ctlr_info_t *host = get_host(bdev->bd_disk); 1023 ctlr_info_t *h = get_host(bdev->bd_disk);
972 drive_info_struct *drv = get_drv(bdev->bd_disk); 1024 drive_info_struct *drv = get_drv(bdev->bd_disk);
973 1025
974#ifdef CCISS_DEBUG 1026 dev_dbg(&h->pdev->dev, "cciss_open %s\n", bdev->bd_disk->disk_name);
975 printk(KERN_DEBUG "cciss_open %s\n", bdev->bd_disk->disk_name);
976#endif /* CCISS_DEBUG */
977
978 if (drv->busy_configuring) 1027 if (drv->busy_configuring)
979 return -EBUSY; 1028 return -EBUSY;
980 /* 1029 /*
@@ -1000,29 +1049,39 @@ static int cciss_open(struct block_device *bdev, fmode_t mode)
1000 return -EPERM; 1049 return -EPERM;
1001 } 1050 }
1002 drv->usage_count++; 1051 drv->usage_count++;
1003 host->usage_count++; 1052 h->usage_count++;
1004 return 0; 1053 return 0;
1005} 1054}
1006 1055
1056static int cciss_unlocked_open(struct block_device *bdev, fmode_t mode)
1057{
1058 int ret;
1059
1060 lock_kernel();
1061 ret = cciss_open(bdev, mode);
1062 unlock_kernel();
1063
1064 return ret;
1065}
1066
1007/* 1067/*
1008 * Close. Sync first. 1068 * Close. Sync first.
1009 */ 1069 */
1010static int cciss_release(struct gendisk *disk, fmode_t mode) 1070static int cciss_release(struct gendisk *disk, fmode_t mode)
1011{ 1071{
1012 ctlr_info_t *host = get_host(disk); 1072 ctlr_info_t *h;
1013 drive_info_struct *drv = get_drv(disk); 1073 drive_info_struct *drv;
1014
1015#ifdef CCISS_DEBUG
1016 printk(KERN_DEBUG "cciss_release %s\n", disk->disk_name);
1017#endif /* CCISS_DEBUG */
1018 1074
1075 lock_kernel();
1076 h = get_host(disk);
1077 drv = get_drv(disk);
1078 dev_dbg(&h->pdev->dev, "cciss_release %s\n", disk->disk_name);
1019 drv->usage_count--; 1079 drv->usage_count--;
1020 host->usage_count--; 1080 h->usage_count--;
1081 unlock_kernel();
1021 return 0; 1082 return 0;
1022} 1083}
1023 1084
1024#ifdef CONFIG_COMPAT
1025
1026static int do_ioctl(struct block_device *bdev, fmode_t mode, 1085static int do_ioctl(struct block_device *bdev, fmode_t mode,
1027 unsigned cmd, unsigned long arg) 1086 unsigned cmd, unsigned long arg)
1028{ 1087{
@@ -1033,6 +1092,8 @@ static int do_ioctl(struct block_device *bdev, fmode_t mode,
1033 return ret; 1092 return ret;
1034} 1093}
1035 1094
1095#ifdef CONFIG_COMPAT
1096
1036static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode, 1097static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
1037 unsigned cmd, unsigned long arg); 1098 unsigned cmd, unsigned long arg);
1038static int cciss_ioctl32_big_passthru(struct block_device *bdev, fmode_t mode, 1099static int cciss_ioctl32_big_passthru(struct block_device *bdev, fmode_t mode,
@@ -1163,11 +1224,11 @@ static int cciss_getgeo(struct block_device *bdev, struct hd_geometry *geo)
1163 return 0; 1224 return 0;
1164} 1225}
1165 1226
1166static void check_ioctl_unit_attention(ctlr_info_t *host, CommandList_struct *c) 1227static void check_ioctl_unit_attention(ctlr_info_t *h, CommandList_struct *c)
1167{ 1228{
1168 if (c->err_info->CommandStatus == CMD_TARGET_STATUS && 1229 if (c->err_info->CommandStatus == CMD_TARGET_STATUS &&
1169 c->err_info->ScsiStatus != SAM_STAT_CHECK_CONDITION) 1230 c->err_info->ScsiStatus != SAM_STAT_CHECK_CONDITION)
1170 (void)check_for_unit_attention(host, c); 1231 (void)check_for_unit_attention(h, c);
1171} 1232}
1172/* 1233/*
1173 * ioctl 1234 * ioctl
@@ -1176,15 +1237,12 @@ static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
1176 unsigned int cmd, unsigned long arg) 1237 unsigned int cmd, unsigned long arg)
1177{ 1238{
1178 struct gendisk *disk = bdev->bd_disk; 1239 struct gendisk *disk = bdev->bd_disk;
1179 ctlr_info_t *host = get_host(disk); 1240 ctlr_info_t *h = get_host(disk);
1180 drive_info_struct *drv = get_drv(disk); 1241 drive_info_struct *drv = get_drv(disk);
1181 int ctlr = host->ctlr;
1182 void __user *argp = (void __user *)arg; 1242 void __user *argp = (void __user *)arg;
1183 1243
1184#ifdef CCISS_DEBUG 1244 dev_dbg(&h->pdev->dev, "cciss_ioctl: Called with cmd=%x %lx\n",
1185 printk(KERN_DEBUG "cciss_ioctl: Called with cmd=%x %lx\n", cmd, arg); 1245 cmd, arg);
1186#endif /* CCISS_DEBUG */
1187
1188 switch (cmd) { 1246 switch (cmd) {
1189 case CCISS_GETPCIINFO: 1247 case CCISS_GETPCIINFO:
1190 { 1248 {
@@ -1192,10 +1250,10 @@ static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
1192 1250
1193 if (!arg) 1251 if (!arg)
1194 return -EINVAL; 1252 return -EINVAL;
1195 pciinfo.domain = pci_domain_nr(host->pdev->bus); 1253 pciinfo.domain = pci_domain_nr(h->pdev->bus);
1196 pciinfo.bus = host->pdev->bus->number; 1254 pciinfo.bus = h->pdev->bus->number;
1197 pciinfo.dev_fn = host->pdev->devfn; 1255 pciinfo.dev_fn = h->pdev->devfn;
1198 pciinfo.board_id = host->board_id; 1256 pciinfo.board_id = h->board_id;
1199 if (copy_to_user 1257 if (copy_to_user
1200 (argp, &pciinfo, sizeof(cciss_pci_info_struct))) 1258 (argp, &pciinfo, sizeof(cciss_pci_info_struct)))
1201 return -EFAULT; 1259 return -EFAULT;
@@ -1207,9 +1265,9 @@ static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
1207 if (!arg) 1265 if (!arg)
1208 return -EINVAL; 1266 return -EINVAL;
1209 intinfo.delay = 1267 intinfo.delay =
1210 readl(&host->cfgtable->HostWrite.CoalIntDelay); 1268 readl(&h->cfgtable->HostWrite.CoalIntDelay);
1211 intinfo.count = 1269 intinfo.count =
1212 readl(&host->cfgtable->HostWrite.CoalIntCount); 1270 readl(&h->cfgtable->HostWrite.CoalIntCount);
1213 if (copy_to_user 1271 if (copy_to_user
1214 (argp, &intinfo, sizeof(cciss_coalint_struct))) 1272 (argp, &intinfo, sizeof(cciss_coalint_struct)))
1215 return -EFAULT; 1273 return -EFAULT;
@@ -1229,26 +1287,23 @@ static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
1229 (&intinfo, argp, sizeof(cciss_coalint_struct))) 1287 (&intinfo, argp, sizeof(cciss_coalint_struct)))
1230 return -EFAULT; 1288 return -EFAULT;
1231 if ((intinfo.delay == 0) && (intinfo.count == 0)) 1289 if ((intinfo.delay == 0) && (intinfo.count == 0))
1232 {
1233// printk("cciss_ioctl: delay and count cannot be 0\n");
1234 return -EINVAL; 1290 return -EINVAL;
1235 } 1291 spin_lock_irqsave(&h->lock, flags);
1236 spin_lock_irqsave(CCISS_LOCK(ctlr), flags);
1237 /* Update the field, and then ring the doorbell */ 1292 /* Update the field, and then ring the doorbell */
1238 writel(intinfo.delay, 1293 writel(intinfo.delay,
1239 &(host->cfgtable->HostWrite.CoalIntDelay)); 1294 &(h->cfgtable->HostWrite.CoalIntDelay));
1240 writel(intinfo.count, 1295 writel(intinfo.count,
1241 &(host->cfgtable->HostWrite.CoalIntCount)); 1296 &(h->cfgtable->HostWrite.CoalIntCount));
1242 writel(CFGTBL_ChangeReq, host->vaddr + SA5_DOORBELL); 1297 writel(CFGTBL_ChangeReq, h->vaddr + SA5_DOORBELL);
1243 1298
1244 for (i = 0; i < MAX_IOCTL_CONFIG_WAIT; i++) { 1299 for (i = 0; i < MAX_IOCTL_CONFIG_WAIT; i++) {
1245 if (!(readl(host->vaddr + SA5_DOORBELL) 1300 if (!(readl(h->vaddr + SA5_DOORBELL)
1246 & CFGTBL_ChangeReq)) 1301 & CFGTBL_ChangeReq))
1247 break; 1302 break;
1248 /* delay and try again */ 1303 /* delay and try again */
1249 udelay(1000); 1304 udelay(1000);
1250 } 1305 }
1251 spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags); 1306 spin_unlock_irqrestore(&h->lock, flags);
1252 if (i >= MAX_IOCTL_CONFIG_WAIT) 1307 if (i >= MAX_IOCTL_CONFIG_WAIT)
1253 return -EAGAIN; 1308 return -EAGAIN;
1254 return 0; 1309 return 0;
@@ -1262,7 +1317,7 @@ static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
1262 return -EINVAL; 1317 return -EINVAL;
1263 for (i = 0; i < 16; i++) 1318 for (i = 0; i < 16; i++)
1264 NodeName[i] = 1319 NodeName[i] =
1265 readb(&host->cfgtable->ServerName[i]); 1320 readb(&h->cfgtable->ServerName[i]);
1266 if (copy_to_user(argp, NodeName, sizeof(NodeName_type))) 1321 if (copy_to_user(argp, NodeName, sizeof(NodeName_type)))
1267 return -EFAULT; 1322 return -EFAULT;
1268 return 0; 1323 return 0;
@@ -1282,23 +1337,23 @@ static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
1282 (NodeName, argp, sizeof(NodeName_type))) 1337 (NodeName, argp, sizeof(NodeName_type)))
1283 return -EFAULT; 1338 return -EFAULT;
1284 1339
1285 spin_lock_irqsave(CCISS_LOCK(ctlr), flags); 1340 spin_lock_irqsave(&h->lock, flags);
1286 1341
1287 /* Update the field, and then ring the doorbell */ 1342 /* Update the field, and then ring the doorbell */
1288 for (i = 0; i < 16; i++) 1343 for (i = 0; i < 16; i++)
1289 writeb(NodeName[i], 1344 writeb(NodeName[i],
1290 &host->cfgtable->ServerName[i]); 1345 &h->cfgtable->ServerName[i]);
1291 1346
1292 writel(CFGTBL_ChangeReq, host->vaddr + SA5_DOORBELL); 1347 writel(CFGTBL_ChangeReq, h->vaddr + SA5_DOORBELL);
1293 1348
1294 for (i = 0; i < MAX_IOCTL_CONFIG_WAIT; i++) { 1349 for (i = 0; i < MAX_IOCTL_CONFIG_WAIT; i++) {
1295 if (!(readl(host->vaddr + SA5_DOORBELL) 1350 if (!(readl(h->vaddr + SA5_DOORBELL)
1296 & CFGTBL_ChangeReq)) 1351 & CFGTBL_ChangeReq))
1297 break; 1352 break;
1298 /* delay and try again */ 1353 /* delay and try again */
1299 udelay(1000); 1354 udelay(1000);
1300 } 1355 }
1301 spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags); 1356 spin_unlock_irqrestore(&h->lock, flags);
1302 if (i >= MAX_IOCTL_CONFIG_WAIT) 1357 if (i >= MAX_IOCTL_CONFIG_WAIT)
1303 return -EAGAIN; 1358 return -EAGAIN;
1304 return 0; 1359 return 0;
@@ -1310,7 +1365,7 @@ static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
1310 1365
1311 if (!arg) 1366 if (!arg)
1312 return -EINVAL; 1367 return -EINVAL;
1313 heartbeat = readl(&host->cfgtable->HeartBeat); 1368 heartbeat = readl(&h->cfgtable->HeartBeat);
1314 if (copy_to_user 1369 if (copy_to_user
1315 (argp, &heartbeat, sizeof(Heartbeat_type))) 1370 (argp, &heartbeat, sizeof(Heartbeat_type)))
1316 return -EFAULT; 1371 return -EFAULT;
@@ -1322,7 +1377,7 @@ static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
1322 1377
1323 if (!arg) 1378 if (!arg)
1324 return -EINVAL; 1379 return -EINVAL;
1325 BusTypes = readl(&host->cfgtable->BusTypes); 1380 BusTypes = readl(&h->cfgtable->BusTypes);
1326 if (copy_to_user 1381 if (copy_to_user
1327 (argp, &BusTypes, sizeof(BusTypes_type))) 1382 (argp, &BusTypes, sizeof(BusTypes_type)))
1328 return -EFAULT; 1383 return -EFAULT;
@@ -1334,7 +1389,7 @@ static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
1334 1389
1335 if (!arg) 1390 if (!arg)
1336 return -EINVAL; 1391 return -EINVAL;
1337 memcpy(firmware, host->firm_ver, 4); 1392 memcpy(firmware, h->firm_ver, 4);
1338 1393
1339 if (copy_to_user 1394 if (copy_to_user
1340 (argp, firmware, sizeof(FirmwareVer_type))) 1395 (argp, firmware, sizeof(FirmwareVer_type)))
@@ -1357,7 +1412,7 @@ static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
1357 case CCISS_DEREGDISK: 1412 case CCISS_DEREGDISK:
1358 case CCISS_REGNEWD: 1413 case CCISS_REGNEWD:
1359 case CCISS_REVALIDVOLS: 1414 case CCISS_REVALIDVOLS:
1360 return rebuild_lun_table(host, 0, 1); 1415 return rebuild_lun_table(h, 0, 1);
1361 1416
1362 case CCISS_GETLUNINFO:{ 1417 case CCISS_GETLUNINFO:{
1363 LogvolInfo_struct luninfo; 1418 LogvolInfo_struct luninfo;
@@ -1377,7 +1432,6 @@ static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
1377 CommandList_struct *c; 1432 CommandList_struct *c;
1378 char *buff = NULL; 1433 char *buff = NULL;
1379 u64bit temp64; 1434 u64bit temp64;
1380 unsigned long flags;
1381 DECLARE_COMPLETION_ONSTACK(wait); 1435 DECLARE_COMPLETION_ONSTACK(wait);
1382 1436
1383 if (!arg) 1437 if (!arg)
@@ -1413,7 +1467,8 @@ static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
1413 } else { 1467 } else {
1414 memset(buff, 0, iocommand.buf_size); 1468 memset(buff, 0, iocommand.buf_size);
1415 } 1469 }
1416 if ((c = cmd_alloc(host, 0)) == NULL) { 1470 c = cmd_special_alloc(h);
1471 if (!c) {
1417 kfree(buff); 1472 kfree(buff);
1418 return -ENOMEM; 1473 return -ENOMEM;
1419 } 1474 }
@@ -1439,7 +1494,7 @@ static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
1439 1494
1440 /* Fill in the scatter gather information */ 1495 /* Fill in the scatter gather information */
1441 if (iocommand.buf_size > 0) { 1496 if (iocommand.buf_size > 0) {
1442 temp64.val = pci_map_single(host->pdev, buff, 1497 temp64.val = pci_map_single(h->pdev, buff,
1443 iocommand.buf_size, 1498 iocommand.buf_size,
1444 PCI_DMA_BIDIRECTIONAL); 1499 PCI_DMA_BIDIRECTIONAL);
1445 c->SG[0].Addr.lower = temp64.val32.lower; 1500 c->SG[0].Addr.lower = temp64.val32.lower;
@@ -1449,30 +1504,24 @@ static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
1449 } 1504 }
1450 c->waiting = &wait; 1505 c->waiting = &wait;
1451 1506
1452 /* Put the request on the tail of the request queue */ 1507 enqueue_cmd_and_start_io(h, c);
1453 spin_lock_irqsave(CCISS_LOCK(ctlr), flags);
1454 addQ(&host->reqQ, c);
1455 host->Qdepth++;
1456 start_io(host);
1457 spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags);
1458
1459 wait_for_completion(&wait); 1508 wait_for_completion(&wait);
1460 1509
1461 /* unlock the buffers from DMA */ 1510 /* unlock the buffers from DMA */
1462 temp64.val32.lower = c->SG[0].Addr.lower; 1511 temp64.val32.lower = c->SG[0].Addr.lower;
1463 temp64.val32.upper = c->SG[0].Addr.upper; 1512 temp64.val32.upper = c->SG[0].Addr.upper;
1464 pci_unmap_single(host->pdev, (dma_addr_t) temp64.val, 1513 pci_unmap_single(h->pdev, (dma_addr_t) temp64.val,
1465 iocommand.buf_size, 1514 iocommand.buf_size,
1466 PCI_DMA_BIDIRECTIONAL); 1515 PCI_DMA_BIDIRECTIONAL);
1467 1516
1468 check_ioctl_unit_attention(host, c); 1517 check_ioctl_unit_attention(h, c);
1469 1518
1470 /* Copy the error information out */ 1519 /* Copy the error information out */
1471 iocommand.error_info = *(c->err_info); 1520 iocommand.error_info = *(c->err_info);
1472 if (copy_to_user 1521 if (copy_to_user
1473 (argp, &iocommand, sizeof(IOCTL_Command_struct))) { 1522 (argp, &iocommand, sizeof(IOCTL_Command_struct))) {
1474 kfree(buff); 1523 kfree(buff);
1475 cmd_free(host, c, 0); 1524 cmd_special_free(h, c);
1476 return -EFAULT; 1525 return -EFAULT;
1477 } 1526 }
1478 1527
@@ -1481,12 +1530,12 @@ static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
1481 if (copy_to_user 1530 if (copy_to_user
1482 (iocommand.buf, buff, iocommand.buf_size)) { 1531 (iocommand.buf, buff, iocommand.buf_size)) {
1483 kfree(buff); 1532 kfree(buff);
1484 cmd_free(host, c, 0); 1533 cmd_special_free(h, c);
1485 return -EFAULT; 1534 return -EFAULT;
1486 } 1535 }
1487 } 1536 }
1488 kfree(buff); 1537 kfree(buff);
1489 cmd_free(host, c, 0); 1538 cmd_special_free(h, c);
1490 return 0; 1539 return 0;
1491 } 1540 }
1492 case CCISS_BIG_PASSTHRU:{ 1541 case CCISS_BIG_PASSTHRU:{
@@ -1495,7 +1544,6 @@ static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
1495 unsigned char **buff = NULL; 1544 unsigned char **buff = NULL;
1496 int *buff_size = NULL; 1545 int *buff_size = NULL;
1497 u64bit temp64; 1546 u64bit temp64;
1498 unsigned long flags;
1499 BYTE sg_used = 0; 1547 BYTE sg_used = 0;
1500 int status = 0; 1548 int status = 0;
1501 int i; 1549 int i;
@@ -1569,7 +1617,8 @@ static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
1569 data_ptr += sz; 1617 data_ptr += sz;
1570 sg_used++; 1618 sg_used++;
1571 } 1619 }
1572 if ((c = cmd_alloc(host, 0)) == NULL) { 1620 c = cmd_special_alloc(h);
1621 if (!c) {
1573 status = -ENOMEM; 1622 status = -ENOMEM;
1574 goto cleanup1; 1623 goto cleanup1;
1575 } 1624 }
@@ -1590,7 +1639,7 @@ static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
1590 if (ioc->buf_size > 0) { 1639 if (ioc->buf_size > 0) {
1591 for (i = 0; i < sg_used; i++) { 1640 for (i = 0; i < sg_used; i++) {
1592 temp64.val = 1641 temp64.val =
1593 pci_map_single(host->pdev, buff[i], 1642 pci_map_single(h->pdev, buff[i],
1594 buff_size[i], 1643 buff_size[i],
1595 PCI_DMA_BIDIRECTIONAL); 1644 PCI_DMA_BIDIRECTIONAL);
1596 c->SG[i].Addr.lower = 1645 c->SG[i].Addr.lower =
@@ -1602,26 +1651,21 @@ static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
1602 } 1651 }
1603 } 1652 }
1604 c->waiting = &wait; 1653 c->waiting = &wait;
1605 /* Put the request on the tail of the request queue */ 1654 enqueue_cmd_and_start_io(h, c);
1606 spin_lock_irqsave(CCISS_LOCK(ctlr), flags);
1607 addQ(&host->reqQ, c);
1608 host->Qdepth++;
1609 start_io(host);
1610 spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags);
1611 wait_for_completion(&wait); 1655 wait_for_completion(&wait);
1612 /* unlock the buffers from DMA */ 1656 /* unlock the buffers from DMA */
1613 for (i = 0; i < sg_used; i++) { 1657 for (i = 0; i < sg_used; i++) {
1614 temp64.val32.lower = c->SG[i].Addr.lower; 1658 temp64.val32.lower = c->SG[i].Addr.lower;
1615 temp64.val32.upper = c->SG[i].Addr.upper; 1659 temp64.val32.upper = c->SG[i].Addr.upper;
1616 pci_unmap_single(host->pdev, 1660 pci_unmap_single(h->pdev,
1617 (dma_addr_t) temp64.val, buff_size[i], 1661 (dma_addr_t) temp64.val, buff_size[i],
1618 PCI_DMA_BIDIRECTIONAL); 1662 PCI_DMA_BIDIRECTIONAL);
1619 } 1663 }
1620 check_ioctl_unit_attention(host, c); 1664 check_ioctl_unit_attention(h, c);
1621 /* Copy the error information out */ 1665 /* Copy the error information out */
1622 ioc->error_info = *(c->err_info); 1666 ioc->error_info = *(c->err_info);
1623 if (copy_to_user(argp, ioc, sizeof(*ioc))) { 1667 if (copy_to_user(argp, ioc, sizeof(*ioc))) {
1624 cmd_free(host, c, 0); 1668 cmd_special_free(h, c);
1625 status = -EFAULT; 1669 status = -EFAULT;
1626 goto cleanup1; 1670 goto cleanup1;
1627 } 1671 }
@@ -1631,14 +1675,14 @@ static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
1631 for (i = 0; i < sg_used; i++) { 1675 for (i = 0; i < sg_used; i++) {
1632 if (copy_to_user 1676 if (copy_to_user
1633 (ptr, buff[i], buff_size[i])) { 1677 (ptr, buff[i], buff_size[i])) {
1634 cmd_free(host, c, 0); 1678 cmd_special_free(h, c);
1635 status = -EFAULT; 1679 status = -EFAULT;
1636 goto cleanup1; 1680 goto cleanup1;
1637 } 1681 }
1638 ptr += buff_size[i]; 1682 ptr += buff_size[i];
1639 } 1683 }
1640 } 1684 }
1641 cmd_free(host, c, 0); 1685 cmd_special_free(h, c);
1642 status = 0; 1686 status = 0;
1643 cleanup1: 1687 cleanup1:
1644 if (buff) { 1688 if (buff) {
@@ -1726,26 +1770,26 @@ static void cciss_check_queues(ctlr_info_t *h)
1726 1770
1727static void cciss_softirq_done(struct request *rq) 1771static void cciss_softirq_done(struct request *rq)
1728{ 1772{
1729 CommandList_struct *cmd = rq->completion_data; 1773 CommandList_struct *c = rq->completion_data;
1730 ctlr_info_t *h = hba[cmd->ctlr]; 1774 ctlr_info_t *h = hba[c->ctlr];
1731 SGDescriptor_struct *curr_sg = cmd->SG; 1775 SGDescriptor_struct *curr_sg = c->SG;
1732 unsigned long flags;
1733 u64bit temp64; 1776 u64bit temp64;
1777 unsigned long flags;
1734 int i, ddir; 1778 int i, ddir;
1735 int sg_index = 0; 1779 int sg_index = 0;
1736 1780
1737 if (cmd->Request.Type.Direction == XFER_READ) 1781 if (c->Request.Type.Direction == XFER_READ)
1738 ddir = PCI_DMA_FROMDEVICE; 1782 ddir = PCI_DMA_FROMDEVICE;
1739 else 1783 else
1740 ddir = PCI_DMA_TODEVICE; 1784 ddir = PCI_DMA_TODEVICE;
1741 1785
1742 /* command did not need to be retried */ 1786 /* command did not need to be retried */
1743 /* unmap the DMA mapping for all the scatter gather elements */ 1787 /* unmap the DMA mapping for all the scatter gather elements */
1744 for (i = 0; i < cmd->Header.SGList; i++) { 1788 for (i = 0; i < c->Header.SGList; i++) {
1745 if (curr_sg[sg_index].Ext == CCISS_SG_CHAIN) { 1789 if (curr_sg[sg_index].Ext == CCISS_SG_CHAIN) {
1746 cciss_unmap_sg_chain_block(h, cmd); 1790 cciss_unmap_sg_chain_block(h, c);
1747 /* Point to the next block */ 1791 /* Point to the next block */
1748 curr_sg = h->cmd_sg_list[cmd->cmdindex]; 1792 curr_sg = h->cmd_sg_list[c->cmdindex];
1749 sg_index = 0; 1793 sg_index = 0;
1750 } 1794 }
1751 temp64.val32.lower = curr_sg[sg_index].Addr.lower; 1795 temp64.val32.lower = curr_sg[sg_index].Addr.lower;
@@ -1755,18 +1799,16 @@ static void cciss_softirq_done(struct request *rq)
1755 ++sg_index; 1799 ++sg_index;
1756 } 1800 }
1757 1801
1758#ifdef CCISS_DEBUG 1802 dev_dbg(&h->pdev->dev, "Done with %p\n", rq);
1759 printk("Done with %p\n", rq);
1760#endif /* CCISS_DEBUG */
1761 1803
1762 /* set the residual count for pc requests */ 1804 /* set the residual count for pc requests */
1763 if (blk_pc_request(rq)) 1805 if (rq->cmd_type == REQ_TYPE_BLOCK_PC)
1764 rq->resid_len = cmd->err_info->ResidualCnt; 1806 rq->resid_len = c->err_info->ResidualCnt;
1765 1807
1766 blk_end_request_all(rq, (rq->errors == 0) ? 0 : -EIO); 1808 blk_end_request_all(rq, (rq->errors == 0) ? 0 : -EIO);
1767 1809
1768 spin_lock_irqsave(&h->lock, flags); 1810 spin_lock_irqsave(&h->lock, flags);
1769 cmd_free(h, cmd, 1); 1811 cmd_free(h, c);
1770 cciss_check_queues(h); 1812 cciss_check_queues(h);
1771 spin_unlock_irqrestore(&h->lock, flags); 1813 spin_unlock_irqrestore(&h->lock, flags);
1772} 1814}
@@ -1782,7 +1824,7 @@ static inline void log_unit_to_scsi3addr(ctlr_info_t *h,
1782 * via the inquiry page 0. Model, vendor, and rev are set to empty strings if 1824 * via the inquiry page 0. Model, vendor, and rev are set to empty strings if
1783 * they cannot be read. 1825 * they cannot be read.
1784 */ 1826 */
1785static void cciss_get_device_descr(int ctlr, int logvol, 1827static void cciss_get_device_descr(ctlr_info_t *h, int logvol,
1786 char *vendor, char *model, char *rev) 1828 char *vendor, char *model, char *rev)
1787{ 1829{
1788 int rc; 1830 int rc;
@@ -1797,8 +1839,8 @@ static void cciss_get_device_descr(int ctlr, int logvol,
1797 if (!inq_buf) 1839 if (!inq_buf)
1798 return; 1840 return;
1799 1841
1800 log_unit_to_scsi3addr(hba[ctlr], scsi3addr, logvol); 1842 log_unit_to_scsi3addr(h, scsi3addr, logvol);
1801 rc = sendcmd_withirq(CISS_INQUIRY, ctlr, inq_buf, sizeof(*inq_buf), 0, 1843 rc = sendcmd_withirq(h, CISS_INQUIRY, inq_buf, sizeof(*inq_buf), 0,
1802 scsi3addr, TYPE_CMD); 1844 scsi3addr, TYPE_CMD);
1803 if (rc == IO_OK) { 1845 if (rc == IO_OK) {
1804 memcpy(vendor, &inq_buf->data_byte[8], VENDOR_LEN); 1846 memcpy(vendor, &inq_buf->data_byte[8], VENDOR_LEN);
@@ -1818,7 +1860,7 @@ static void cciss_get_device_descr(int ctlr, int logvol,
1818 * number cannot be had, for whatever reason, 16 bytes of 0xff 1860 * number cannot be had, for whatever reason, 16 bytes of 0xff
1819 * are returned instead. 1861 * are returned instead.
1820 */ 1862 */
1821static void cciss_get_serial_no(int ctlr, int logvol, 1863static void cciss_get_serial_no(ctlr_info_t *h, int logvol,
1822 unsigned char *serial_no, int buflen) 1864 unsigned char *serial_no, int buflen)
1823{ 1865{
1824#define PAGE_83_INQ_BYTES 64 1866#define PAGE_83_INQ_BYTES 64
@@ -1833,8 +1875,8 @@ static void cciss_get_serial_no(int ctlr, int logvol,
1833 if (!buf) 1875 if (!buf)
1834 return; 1876 return;
1835 memset(serial_no, 0, buflen); 1877 memset(serial_no, 0, buflen);
1836 log_unit_to_scsi3addr(hba[ctlr], scsi3addr, logvol); 1878 log_unit_to_scsi3addr(h, scsi3addr, logvol);
1837 rc = sendcmd_withirq(CISS_INQUIRY, ctlr, buf, 1879 rc = sendcmd_withirq(h, CISS_INQUIRY, buf,
1838 PAGE_83_INQ_BYTES, 0x83, scsi3addr, TYPE_CMD); 1880 PAGE_83_INQ_BYTES, 0x83, scsi3addr, TYPE_CMD);
1839 if (rc == IO_OK) 1881 if (rc == IO_OK)
1840 memcpy(serial_no, &buf[8], buflen); 1882 memcpy(serial_no, &buf[8], buflen);
@@ -1900,10 +1942,9 @@ init_queue_failure:
1900 * is also the controller node. Any changes to disk 0 will show up on 1942 * is also the controller node. Any changes to disk 0 will show up on
1901 * the next reboot. 1943 * the next reboot.
1902 */ 1944 */
1903static void cciss_update_drive_info(int ctlr, int drv_index, int first_time, 1945static void cciss_update_drive_info(ctlr_info_t *h, int drv_index,
1904 int via_ioctl) 1946 int first_time, int via_ioctl)
1905{ 1947{
1906 ctlr_info_t *h = hba[ctlr];
1907 struct gendisk *disk; 1948 struct gendisk *disk;
1908 InquiryData_struct *inq_buff = NULL; 1949 InquiryData_struct *inq_buff = NULL;
1909 unsigned int block_size; 1950 unsigned int block_size;
@@ -1920,16 +1961,16 @@ static void cciss_update_drive_info(int ctlr, int drv_index, int first_time,
1920 1961
1921 /* testing to see if 16-byte CDBs are already being used */ 1962 /* testing to see if 16-byte CDBs are already being used */
1922 if (h->cciss_read == CCISS_READ_16) { 1963 if (h->cciss_read == CCISS_READ_16) {
1923 cciss_read_capacity_16(h->ctlr, drv_index, 1964 cciss_read_capacity_16(h, drv_index,
1924 &total_size, &block_size); 1965 &total_size, &block_size);
1925 1966
1926 } else { 1967 } else {
1927 cciss_read_capacity(ctlr, drv_index, &total_size, &block_size); 1968 cciss_read_capacity(h, drv_index, &total_size, &block_size);
1928 /* if read_capacity returns all F's this volume is >2TB */ 1969 /* if read_capacity returns all F's this volume is >2TB */
1929 /* in size so we switch to 16-byte CDB's for all */ 1970 /* in size so we switch to 16-byte CDB's for all */
1930 /* read/write ops */ 1971 /* read/write ops */
1931 if (total_size == 0xFFFFFFFFULL) { 1972 if (total_size == 0xFFFFFFFFULL) {
1932 cciss_read_capacity_16(ctlr, drv_index, 1973 cciss_read_capacity_16(h, drv_index,
1933 &total_size, &block_size); 1974 &total_size, &block_size);
1934 h->cciss_read = CCISS_READ_16; 1975 h->cciss_read = CCISS_READ_16;
1935 h->cciss_write = CCISS_WRITE_16; 1976 h->cciss_write = CCISS_WRITE_16;
@@ -1939,14 +1980,14 @@ static void cciss_update_drive_info(int ctlr, int drv_index, int first_time,
1939 } 1980 }
1940 } 1981 }
1941 1982
1942 cciss_geometry_inquiry(ctlr, drv_index, total_size, block_size, 1983 cciss_geometry_inquiry(h, drv_index, total_size, block_size,
1943 inq_buff, drvinfo); 1984 inq_buff, drvinfo);
1944 drvinfo->block_size = block_size; 1985 drvinfo->block_size = block_size;
1945 drvinfo->nr_blocks = total_size + 1; 1986 drvinfo->nr_blocks = total_size + 1;
1946 1987
1947 cciss_get_device_descr(ctlr, drv_index, drvinfo->vendor, 1988 cciss_get_device_descr(h, drv_index, drvinfo->vendor,
1948 drvinfo->model, drvinfo->rev); 1989 drvinfo->model, drvinfo->rev);
1949 cciss_get_serial_no(ctlr, drv_index, drvinfo->serial_no, 1990 cciss_get_serial_no(h, drv_index, drvinfo->serial_no,
1950 sizeof(drvinfo->serial_no)); 1991 sizeof(drvinfo->serial_no));
1951 /* Save the lunid in case we deregister the disk, below. */ 1992 /* Save the lunid in case we deregister the disk, below. */
1952 memcpy(drvinfo->LunID, h->drv[drv_index]->LunID, 1993 memcpy(drvinfo->LunID, h->drv[drv_index]->LunID,
@@ -1971,10 +2012,10 @@ static void cciss_update_drive_info(int ctlr, int drv_index, int first_time,
1971 * (unless it's the first disk (for the controller node). 2012 * (unless it's the first disk (for the controller node).
1972 */ 2013 */
1973 if (h->drv[drv_index]->raid_level != -1 && drv_index != 0) { 2014 if (h->drv[drv_index]->raid_level != -1 && drv_index != 0) {
1974 printk(KERN_WARNING "disk %d has changed.\n", drv_index); 2015 dev_warn(&h->pdev->dev, "disk %d has changed.\n", drv_index);
1975 spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags); 2016 spin_lock_irqsave(&h->lock, flags);
1976 h->drv[drv_index]->busy_configuring = 1; 2017 h->drv[drv_index]->busy_configuring = 1;
1977 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); 2018 spin_unlock_irqrestore(&h->lock, flags);
1978 2019
1979 /* deregister_disk sets h->drv[drv_index]->queue = NULL 2020 /* deregister_disk sets h->drv[drv_index]->queue = NULL
1980 * which keeps the interrupt handler from starting 2021 * which keeps the interrupt handler from starting
@@ -2024,8 +2065,8 @@ static void cciss_update_drive_info(int ctlr, int drv_index, int first_time,
2024 if (cciss_add_disk(h, disk, drv_index) != 0) { 2065 if (cciss_add_disk(h, disk, drv_index) != 0) {
2025 cciss_free_gendisk(h, drv_index); 2066 cciss_free_gendisk(h, drv_index);
2026 cciss_free_drive_info(h, drv_index); 2067 cciss_free_drive_info(h, drv_index);
2027 printk(KERN_WARNING "cciss:%d could not update " 2068 dev_warn(&h->pdev->dev, "could not update disk %d\n",
2028 "disk %d\n", h->ctlr, drv_index); 2069 drv_index);
2029 --h->num_luns; 2070 --h->num_luns;
2030 } 2071 }
2031 } 2072 }
@@ -2035,7 +2076,7 @@ freeret:
2035 kfree(drvinfo); 2076 kfree(drvinfo);
2036 return; 2077 return;
2037mem_msg: 2078mem_msg:
2038 printk(KERN_ERR "cciss: out of memory\n"); 2079 dev_err(&h->pdev->dev, "out of memory\n");
2039 goto freeret; 2080 goto freeret;
2040} 2081}
2041 2082
@@ -2127,9 +2168,9 @@ static int cciss_add_gendisk(ctlr_info_t *h, unsigned char lunid[],
2127 h->gendisk[drv_index] = 2168 h->gendisk[drv_index] =
2128 alloc_disk(1 << NWD_SHIFT); 2169 alloc_disk(1 << NWD_SHIFT);
2129 if (!h->gendisk[drv_index]) { 2170 if (!h->gendisk[drv_index]) {
2130 printk(KERN_ERR "cciss%d: could not " 2171 dev_err(&h->pdev->dev,
2131 "allocate a new disk %d\n", 2172 "could not allocate a new disk %d\n",
2132 h->ctlr, drv_index); 2173 drv_index);
2133 goto err_free_drive_info; 2174 goto err_free_drive_info;
2134 } 2175 }
2135 } 2176 }
@@ -2180,8 +2221,7 @@ static void cciss_add_controller_node(ctlr_info_t *h)
2180 cciss_free_gendisk(h, drv_index); 2221 cciss_free_gendisk(h, drv_index);
2181 cciss_free_drive_info(h, drv_index); 2222 cciss_free_drive_info(h, drv_index);
2182error: 2223error:
2183 printk(KERN_WARNING "cciss%d: could not " 2224 dev_warn(&h->pdev->dev, "could not add disk 0.\n");
2184 "add disk 0.\n", h->ctlr);
2185 return; 2225 return;
2186} 2226}
2187 2227
@@ -2196,7 +2236,6 @@ error:
2196static int rebuild_lun_table(ctlr_info_t *h, int first_time, 2236static int rebuild_lun_table(ctlr_info_t *h, int first_time,
2197 int via_ioctl) 2237 int via_ioctl)
2198{ 2238{
2199 int ctlr = h->ctlr;
2200 int num_luns; 2239 int num_luns;
2201 ReportLunData_struct *ld_buff = NULL; 2240 ReportLunData_struct *ld_buff = NULL;
2202 int return_code; 2241 int return_code;
@@ -2211,27 +2250,27 @@ static int rebuild_lun_table(ctlr_info_t *h, int first_time,
2211 return -EPERM; 2250 return -EPERM;
2212 2251
2213 /* Set busy_configuring flag for this operation */ 2252 /* Set busy_configuring flag for this operation */
2214 spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags); 2253 spin_lock_irqsave(&h->lock, flags);
2215 if (h->busy_configuring) { 2254 if (h->busy_configuring) {
2216 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); 2255 spin_unlock_irqrestore(&h->lock, flags);
2217 return -EBUSY; 2256 return -EBUSY;
2218 } 2257 }
2219 h->busy_configuring = 1; 2258 h->busy_configuring = 1;
2220 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); 2259 spin_unlock_irqrestore(&h->lock, flags);
2221 2260
2222 ld_buff = kzalloc(sizeof(ReportLunData_struct), GFP_KERNEL); 2261 ld_buff = kzalloc(sizeof(ReportLunData_struct), GFP_KERNEL);
2223 if (ld_buff == NULL) 2262 if (ld_buff == NULL)
2224 goto mem_msg; 2263 goto mem_msg;
2225 2264
2226 return_code = sendcmd_withirq(CISS_REPORT_LOG, ctlr, ld_buff, 2265 return_code = sendcmd_withirq(h, CISS_REPORT_LOG, ld_buff,
2227 sizeof(ReportLunData_struct), 2266 sizeof(ReportLunData_struct),
2228 0, CTLR_LUNID, TYPE_CMD); 2267 0, CTLR_LUNID, TYPE_CMD);
2229 2268
2230 if (return_code == IO_OK) 2269 if (return_code == IO_OK)
2231 listlength = be32_to_cpu(*(__be32 *) ld_buff->LUNListLength); 2270 listlength = be32_to_cpu(*(__be32 *) ld_buff->LUNListLength);
2232 else { /* reading number of logical volumes failed */ 2271 else { /* reading number of logical volumes failed */
2233 printk(KERN_WARNING "cciss: report logical volume" 2272 dev_warn(&h->pdev->dev,
2234 " command failed\n"); 2273 "report logical volume command failed\n");
2235 listlength = 0; 2274 listlength = 0;
2236 goto freeret; 2275 goto freeret;
2237 } 2276 }
@@ -2239,7 +2278,7 @@ static int rebuild_lun_table(ctlr_info_t *h, int first_time,
2239 num_luns = listlength / 8; /* 8 bytes per entry */ 2278 num_luns = listlength / 8; /* 8 bytes per entry */
2240 if (num_luns > CISS_MAX_LUN) { 2279 if (num_luns > CISS_MAX_LUN) {
2241 num_luns = CISS_MAX_LUN; 2280 num_luns = CISS_MAX_LUN;
2242 printk(KERN_WARNING "cciss: more luns configured" 2281 dev_warn(&h->pdev->dev, "more luns configured"
2243 " on controller than can be handled by" 2282 " on controller than can be handled by"
2244 " this driver.\n"); 2283 " this driver.\n");
2245 } 2284 }
@@ -2270,9 +2309,9 @@ static int rebuild_lun_table(ctlr_info_t *h, int first_time,
2270 } 2309 }
2271 if (!drv_found) { 2310 if (!drv_found) {
2272 /* Deregister it from the OS, it's gone. */ 2311 /* Deregister it from the OS, it's gone. */
2273 spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags); 2312 spin_lock_irqsave(&h->lock, flags);
2274 h->drv[i]->busy_configuring = 1; 2313 h->drv[i]->busy_configuring = 1;
2275 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); 2314 spin_unlock_irqrestore(&h->lock, flags);
2276 return_code = deregister_disk(h, i, 1, via_ioctl); 2315 return_code = deregister_disk(h, i, 1, via_ioctl);
2277 if (h->drv[i] != NULL) 2316 if (h->drv[i] != NULL)
2278 h->drv[i]->busy_configuring = 0; 2317 h->drv[i]->busy_configuring = 0;
@@ -2311,8 +2350,7 @@ static int rebuild_lun_table(ctlr_info_t *h, int first_time,
2311 if (drv_index == -1) 2350 if (drv_index == -1)
2312 goto freeret; 2351 goto freeret;
2313 } 2352 }
2314 cciss_update_drive_info(ctlr, drv_index, first_time, 2353 cciss_update_drive_info(h, drv_index, first_time, via_ioctl);
2315 via_ioctl);
2316 } /* end for */ 2354 } /* end for */
2317 2355
2318freeret: 2356freeret:
@@ -2324,7 +2362,7 @@ freeret:
2324 */ 2362 */
2325 return -1; 2363 return -1;
2326mem_msg: 2364mem_msg:
2327 printk(KERN_ERR "cciss: out of memory\n"); 2365 dev_err(&h->pdev->dev, "out of memory\n");
2328 h->busy_configuring = 0; 2366 h->busy_configuring = 0;
2329 goto freeret; 2367 goto freeret;
2330} 2368}
@@ -2444,11 +2482,10 @@ static int deregister_disk(ctlr_info_t *h, int drv_index,
2444 return 0; 2482 return 0;
2445} 2483}
2446 2484
2447static int fill_cmd(CommandList_struct *c, __u8 cmd, int ctlr, void *buff, 2485static int fill_cmd(ctlr_info_t *h, CommandList_struct *c, __u8 cmd, void *buff,
2448 size_t size, __u8 page_code, unsigned char *scsi3addr, 2486 size_t size, __u8 page_code, unsigned char *scsi3addr,
2449 int cmd_type) 2487 int cmd_type)
2450{ 2488{
2451 ctlr_info_t *h = hba[ctlr];
2452 u64bit buff_dma_handle; 2489 u64bit buff_dma_handle;
2453 int status = IO_OK; 2490 int status = IO_OK;
2454 2491
@@ -2532,8 +2569,7 @@ static int fill_cmd(CommandList_struct *c, __u8 cmd, int ctlr, void *buff,
2532 c->Request.Timeout = 0; 2569 c->Request.Timeout = 0;
2533 break; 2570 break;
2534 default: 2571 default:
2535 printk(KERN_WARNING 2572 dev_warn(&h->pdev->dev, "Unknown Command 0x%c\n", cmd);
2536 "cciss%d: Unknown Command 0x%c\n", ctlr, cmd);
2537 return IO_ERROR; 2573 return IO_ERROR;
2538 } 2574 }
2539 } else if (cmd_type == TYPE_MSG) { 2575 } else if (cmd_type == TYPE_MSG) {
@@ -2565,13 +2601,12 @@ static int fill_cmd(CommandList_struct *c, __u8 cmd, int ctlr, void *buff,
2565 c->Request.CDB[0] = cmd; 2601 c->Request.CDB[0] = cmd;
2566 break; 2602 break;
2567 default: 2603 default:
2568 printk(KERN_WARNING 2604 dev_warn(&h->pdev->dev,
2569 "cciss%d: unknown message type %d\n", ctlr, cmd); 2605 "unknown message type %d\n", cmd);
2570 return IO_ERROR; 2606 return IO_ERROR;
2571 } 2607 }
2572 } else { 2608 } else {
2573 printk(KERN_WARNING 2609 dev_warn(&h->pdev->dev, "unknown command type %d\n", cmd_type);
2574 "cciss%d: unknown command type %d\n", ctlr, cmd_type);
2575 return IO_ERROR; 2610 return IO_ERROR;
2576 } 2611 }
2577 /* Fill in the scatter gather information */ 2612 /* Fill in the scatter gather information */
@@ -2599,15 +2634,14 @@ static int check_target_status(ctlr_info_t *h, CommandList_struct *c)
2599 default: 2634 default:
2600 if (check_for_unit_attention(h, c)) 2635 if (check_for_unit_attention(h, c))
2601 return IO_NEEDS_RETRY; 2636 return IO_NEEDS_RETRY;
2602 printk(KERN_WARNING "cciss%d: cmd 0x%02x " 2637 dev_warn(&h->pdev->dev, "cmd 0x%02x "
2603 "check condition, sense key = 0x%02x\n", 2638 "check condition, sense key = 0x%02x\n",
2604 h->ctlr, c->Request.CDB[0], 2639 c->Request.CDB[0], c->err_info->SenseInfo[2]);
2605 c->err_info->SenseInfo[2]);
2606 } 2640 }
2607 break; 2641 break;
2608 default: 2642 default:
2609 printk(KERN_WARNING "cciss%d: cmd 0x%02x" 2643 dev_warn(&h->pdev->dev, "cmd 0x%02x"
2610 "scsi status = 0x%02x\n", h->ctlr, 2644 "scsi status = 0x%02x\n",
2611 c->Request.CDB[0], c->err_info->ScsiStatus); 2645 c->Request.CDB[0], c->err_info->ScsiStatus);
2612 break; 2646 break;
2613 } 2647 }
@@ -2630,43 +2664,42 @@ static int process_sendcmd_error(ctlr_info_t *h, CommandList_struct *c)
2630 /* expected for inquiry and report lun commands */ 2664 /* expected for inquiry and report lun commands */
2631 break; 2665 break;
2632 case CMD_INVALID: 2666 case CMD_INVALID:
2633 printk(KERN_WARNING "cciss: cmd 0x%02x is " 2667 dev_warn(&h->pdev->dev, "cmd 0x%02x is "
2634 "reported invalid\n", c->Request.CDB[0]); 2668 "reported invalid\n", c->Request.CDB[0]);
2635 return_status = IO_ERROR; 2669 return_status = IO_ERROR;
2636 break; 2670 break;
2637 case CMD_PROTOCOL_ERR: 2671 case CMD_PROTOCOL_ERR:
2638 printk(KERN_WARNING "cciss: cmd 0x%02x has " 2672 dev_warn(&h->pdev->dev, "cmd 0x%02x has "
2639 "protocol error \n", c->Request.CDB[0]); 2673 "protocol error\n", c->Request.CDB[0]);
2640 return_status = IO_ERROR; 2674 return_status = IO_ERROR;
2641 break; 2675 break;
2642 case CMD_HARDWARE_ERR: 2676 case CMD_HARDWARE_ERR:
2643 printk(KERN_WARNING "cciss: cmd 0x%02x had " 2677 dev_warn(&h->pdev->dev, "cmd 0x%02x had "
2644 " hardware error\n", c->Request.CDB[0]); 2678 " hardware error\n", c->Request.CDB[0]);
2645 return_status = IO_ERROR; 2679 return_status = IO_ERROR;
2646 break; 2680 break;
2647 case CMD_CONNECTION_LOST: 2681 case CMD_CONNECTION_LOST:
2648 printk(KERN_WARNING "cciss: cmd 0x%02x had " 2682 dev_warn(&h->pdev->dev, "cmd 0x%02x had "
2649 "connection lost\n", c->Request.CDB[0]); 2683 "connection lost\n", c->Request.CDB[0]);
2650 return_status = IO_ERROR; 2684 return_status = IO_ERROR;
2651 break; 2685 break;
2652 case CMD_ABORTED: 2686 case CMD_ABORTED:
2653 printk(KERN_WARNING "cciss: cmd 0x%02x was " 2687 dev_warn(&h->pdev->dev, "cmd 0x%02x was "
2654 "aborted\n", c->Request.CDB[0]); 2688 "aborted\n", c->Request.CDB[0]);
2655 return_status = IO_ERROR; 2689 return_status = IO_ERROR;
2656 break; 2690 break;
2657 case CMD_ABORT_FAILED: 2691 case CMD_ABORT_FAILED:
2658 printk(KERN_WARNING "cciss: cmd 0x%02x reports " 2692 dev_warn(&h->pdev->dev, "cmd 0x%02x reports "
2659 "abort failed\n", c->Request.CDB[0]); 2693 "abort failed\n", c->Request.CDB[0]);
2660 return_status = IO_ERROR; 2694 return_status = IO_ERROR;
2661 break; 2695 break;
2662 case CMD_UNSOLICITED_ABORT: 2696 case CMD_UNSOLICITED_ABORT:
2663 printk(KERN_WARNING 2697 dev_warn(&h->pdev->dev, "unsolicited abort 0x%02x\n",
2664 "cciss%d: unsolicited abort 0x%02x\n", h->ctlr,
2665 c->Request.CDB[0]); 2698 c->Request.CDB[0]);
2666 return_status = IO_NEEDS_RETRY; 2699 return_status = IO_NEEDS_RETRY;
2667 break; 2700 break;
2668 default: 2701 default:
2669 printk(KERN_WARNING "cciss: cmd 0x%02x returned " 2702 dev_warn(&h->pdev->dev, "cmd 0x%02x returned "
2670 "unknown status %x\n", c->Request.CDB[0], 2703 "unknown status %x\n", c->Request.CDB[0],
2671 c->err_info->CommandStatus); 2704 c->err_info->CommandStatus);
2672 return_status = IO_ERROR; 2705 return_status = IO_ERROR;
@@ -2679,17 +2712,11 @@ static int sendcmd_withirq_core(ctlr_info_t *h, CommandList_struct *c,
2679{ 2712{
2680 DECLARE_COMPLETION_ONSTACK(wait); 2713 DECLARE_COMPLETION_ONSTACK(wait);
2681 u64bit buff_dma_handle; 2714 u64bit buff_dma_handle;
2682 unsigned long flags;
2683 int return_status = IO_OK; 2715 int return_status = IO_OK;
2684 2716
2685resend_cmd2: 2717resend_cmd2:
2686 c->waiting = &wait; 2718 c->waiting = &wait;
2687 /* Put the request on the tail of the queue and send it */ 2719 enqueue_cmd_and_start_io(h, c);
2688 spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags);
2689 addQ(&h->reqQ, c);
2690 h->Qdepth++;
2691 start_io(h);
2692 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
2693 2720
2694 wait_for_completion(&wait); 2721 wait_for_completion(&wait);
2695 2722
@@ -2700,7 +2727,7 @@ resend_cmd2:
2700 2727
2701 if (return_status == IO_NEEDS_RETRY && 2728 if (return_status == IO_NEEDS_RETRY &&
2702 c->retry_count < MAX_CMD_RETRIES) { 2729 c->retry_count < MAX_CMD_RETRIES) {
2703 printk(KERN_WARNING "cciss%d: retrying 0x%02x\n", h->ctlr, 2730 dev_warn(&h->pdev->dev, "retrying 0x%02x\n",
2704 c->Request.CDB[0]); 2731 c->Request.CDB[0]);
2705 c->retry_count++; 2732 c->retry_count++;
2706 /* erase the old error information */ 2733 /* erase the old error information */
@@ -2719,27 +2746,26 @@ command_done:
2719 return return_status; 2746 return return_status;
2720} 2747}
2721 2748
2722static int sendcmd_withirq(__u8 cmd, int ctlr, void *buff, size_t size, 2749static int sendcmd_withirq(ctlr_info_t *h, __u8 cmd, void *buff, size_t size,
2723 __u8 page_code, unsigned char scsi3addr[], 2750 __u8 page_code, unsigned char scsi3addr[],
2724 int cmd_type) 2751 int cmd_type)
2725{ 2752{
2726 ctlr_info_t *h = hba[ctlr];
2727 CommandList_struct *c; 2753 CommandList_struct *c;
2728 int return_status; 2754 int return_status;
2729 2755
2730 c = cmd_alloc(h, 0); 2756 c = cmd_special_alloc(h);
2731 if (!c) 2757 if (!c)
2732 return -ENOMEM; 2758 return -ENOMEM;
2733 return_status = fill_cmd(c, cmd, ctlr, buff, size, page_code, 2759 return_status = fill_cmd(h, c, cmd, buff, size, page_code,
2734 scsi3addr, cmd_type); 2760 scsi3addr, cmd_type);
2735 if (return_status == IO_OK) 2761 if (return_status == IO_OK)
2736 return_status = sendcmd_withirq_core(h, c, 1); 2762 return_status = sendcmd_withirq_core(h, c, 1);
2737 2763
2738 cmd_free(h, c, 0); 2764 cmd_special_free(h, c);
2739 return return_status; 2765 return return_status;
2740} 2766}
2741 2767
2742static void cciss_geometry_inquiry(int ctlr, int logvol, 2768static void cciss_geometry_inquiry(ctlr_info_t *h, int logvol,
2743 sector_t total_size, 2769 sector_t total_size,
2744 unsigned int block_size, 2770 unsigned int block_size,
2745 InquiryData_struct *inq_buff, 2771 InquiryData_struct *inq_buff,
@@ -2750,13 +2776,13 @@ static void cciss_geometry_inquiry(int ctlr, int logvol,
2750 unsigned char scsi3addr[8]; 2776 unsigned char scsi3addr[8];
2751 2777
2752 memset(inq_buff, 0, sizeof(InquiryData_struct)); 2778 memset(inq_buff, 0, sizeof(InquiryData_struct));
2753 log_unit_to_scsi3addr(hba[ctlr], scsi3addr, logvol); 2779 log_unit_to_scsi3addr(h, scsi3addr, logvol);
2754 return_code = sendcmd_withirq(CISS_INQUIRY, ctlr, inq_buff, 2780 return_code = sendcmd_withirq(h, CISS_INQUIRY, inq_buff,
2755 sizeof(*inq_buff), 0xC1, scsi3addr, TYPE_CMD); 2781 sizeof(*inq_buff), 0xC1, scsi3addr, TYPE_CMD);
2756 if (return_code == IO_OK) { 2782 if (return_code == IO_OK) {
2757 if (inq_buff->data_byte[8] == 0xFF) { 2783 if (inq_buff->data_byte[8] == 0xFF) {
2758 printk(KERN_WARNING 2784 dev_warn(&h->pdev->dev,
2759 "cciss: reading geometry failed, volume " 2785 "reading geometry failed, volume "
2760 "does not support reading geometry\n"); 2786 "does not support reading geometry\n");
2761 drv->heads = 255; 2787 drv->heads = 255;
2762 drv->sectors = 32; /* Sectors per track */ 2788 drv->sectors = 32; /* Sectors per track */
@@ -2780,12 +2806,12 @@ static void cciss_geometry_inquiry(int ctlr, int logvol,
2780 drv->cylinders = real_size; 2806 drv->cylinders = real_size;
2781 } 2807 }
2782 } else { /* Get geometry failed */ 2808 } else { /* Get geometry failed */
2783 printk(KERN_WARNING "cciss: reading geometry failed\n"); 2809 dev_warn(&h->pdev->dev, "reading geometry failed\n");
2784 } 2810 }
2785} 2811}
2786 2812
2787static void 2813static void
2788cciss_read_capacity(int ctlr, int logvol, sector_t *total_size, 2814cciss_read_capacity(ctlr_info_t *h, int logvol, sector_t *total_size,
2789 unsigned int *block_size) 2815 unsigned int *block_size)
2790{ 2816{
2791 ReadCapdata_struct *buf; 2817 ReadCapdata_struct *buf;
@@ -2794,25 +2820,25 @@ cciss_read_capacity(int ctlr, int logvol, sector_t *total_size,
2794 2820
2795 buf = kzalloc(sizeof(ReadCapdata_struct), GFP_KERNEL); 2821 buf = kzalloc(sizeof(ReadCapdata_struct), GFP_KERNEL);
2796 if (!buf) { 2822 if (!buf) {
2797 printk(KERN_WARNING "cciss: out of memory\n"); 2823 dev_warn(&h->pdev->dev, "out of memory\n");
2798 return; 2824 return;
2799 } 2825 }
2800 2826
2801 log_unit_to_scsi3addr(hba[ctlr], scsi3addr, logvol); 2827 log_unit_to_scsi3addr(h, scsi3addr, logvol);
2802 return_code = sendcmd_withirq(CCISS_READ_CAPACITY, ctlr, buf, 2828 return_code = sendcmd_withirq(h, CCISS_READ_CAPACITY, buf,
2803 sizeof(ReadCapdata_struct), 0, scsi3addr, TYPE_CMD); 2829 sizeof(ReadCapdata_struct), 0, scsi3addr, TYPE_CMD);
2804 if (return_code == IO_OK) { 2830 if (return_code == IO_OK) {
2805 *total_size = be32_to_cpu(*(__be32 *) buf->total_size); 2831 *total_size = be32_to_cpu(*(__be32 *) buf->total_size);
2806 *block_size = be32_to_cpu(*(__be32 *) buf->block_size); 2832 *block_size = be32_to_cpu(*(__be32 *) buf->block_size);
2807 } else { /* read capacity command failed */ 2833 } else { /* read capacity command failed */
2808 printk(KERN_WARNING "cciss: read capacity failed\n"); 2834 dev_warn(&h->pdev->dev, "read capacity failed\n");
2809 *total_size = 0; 2835 *total_size = 0;
2810 *block_size = BLOCK_SIZE; 2836 *block_size = BLOCK_SIZE;
2811 } 2837 }
2812 kfree(buf); 2838 kfree(buf);
2813} 2839}
2814 2840
2815static void cciss_read_capacity_16(int ctlr, int logvol, 2841static void cciss_read_capacity_16(ctlr_info_t *h, int logvol,
2816 sector_t *total_size, unsigned int *block_size) 2842 sector_t *total_size, unsigned int *block_size)
2817{ 2843{
2818 ReadCapdata_struct_16 *buf; 2844 ReadCapdata_struct_16 *buf;
@@ -2821,23 +2847,23 @@ static void cciss_read_capacity_16(int ctlr, int logvol,
2821 2847
2822 buf = kzalloc(sizeof(ReadCapdata_struct_16), GFP_KERNEL); 2848 buf = kzalloc(sizeof(ReadCapdata_struct_16), GFP_KERNEL);
2823 if (!buf) { 2849 if (!buf) {
2824 printk(KERN_WARNING "cciss: out of memory\n"); 2850 dev_warn(&h->pdev->dev, "out of memory\n");
2825 return; 2851 return;
2826 } 2852 }
2827 2853
2828 log_unit_to_scsi3addr(hba[ctlr], scsi3addr, logvol); 2854 log_unit_to_scsi3addr(h, scsi3addr, logvol);
2829 return_code = sendcmd_withirq(CCISS_READ_CAPACITY_16, 2855 return_code = sendcmd_withirq(h, CCISS_READ_CAPACITY_16,
2830 ctlr, buf, sizeof(ReadCapdata_struct_16), 2856 buf, sizeof(ReadCapdata_struct_16),
2831 0, scsi3addr, TYPE_CMD); 2857 0, scsi3addr, TYPE_CMD);
2832 if (return_code == IO_OK) { 2858 if (return_code == IO_OK) {
2833 *total_size = be64_to_cpu(*(__be64 *) buf->total_size); 2859 *total_size = be64_to_cpu(*(__be64 *) buf->total_size);
2834 *block_size = be32_to_cpu(*(__be32 *) buf->block_size); 2860 *block_size = be32_to_cpu(*(__be32 *) buf->block_size);
2835 } else { /* read capacity command failed */ 2861 } else { /* read capacity command failed */
2836 printk(KERN_WARNING "cciss: read capacity failed\n"); 2862 dev_warn(&h->pdev->dev, "read capacity failed\n");
2837 *total_size = 0; 2863 *total_size = 0;
2838 *block_size = BLOCK_SIZE; 2864 *block_size = BLOCK_SIZE;
2839 } 2865 }
2840 printk(KERN_INFO " blocks= %llu block_size= %d\n", 2866 dev_info(&h->pdev->dev, " blocks= %llu block_size= %d\n",
2841 (unsigned long long)*total_size+1, *block_size); 2867 (unsigned long long)*total_size+1, *block_size);
2842 kfree(buf); 2868 kfree(buf);
2843} 2869}
@@ -2865,17 +2891,17 @@ static int cciss_revalidate(struct gendisk *disk)
2865 2891
2866 inq_buff = kmalloc(sizeof(InquiryData_struct), GFP_KERNEL); 2892 inq_buff = kmalloc(sizeof(InquiryData_struct), GFP_KERNEL);
2867 if (inq_buff == NULL) { 2893 if (inq_buff == NULL) {
2868 printk(KERN_WARNING "cciss: out of memory\n"); 2894 dev_warn(&h->pdev->dev, "out of memory\n");
2869 return 1; 2895 return 1;
2870 } 2896 }
2871 if (h->cciss_read == CCISS_READ_10) { 2897 if (h->cciss_read == CCISS_READ_10) {
2872 cciss_read_capacity(h->ctlr, logvol, 2898 cciss_read_capacity(h, logvol,
2873 &total_size, &block_size); 2899 &total_size, &block_size);
2874 } else { 2900 } else {
2875 cciss_read_capacity_16(h->ctlr, logvol, 2901 cciss_read_capacity_16(h, logvol,
2876 &total_size, &block_size); 2902 &total_size, &block_size);
2877 } 2903 }
2878 cciss_geometry_inquiry(h->ctlr, logvol, total_size, block_size, 2904 cciss_geometry_inquiry(h, logvol, total_size, block_size,
2879 inq_buff, drv); 2905 inq_buff, drv);
2880 2906
2881 blk_queue_logical_block_size(drv->queue, drv->block_size); 2907 blk_queue_logical_block_size(drv->queue, drv->block_size);
@@ -2909,7 +2935,7 @@ static void start_io(ctlr_info_t *h)
2909 c = hlist_entry(h->reqQ.first, CommandList_struct, list); 2935 c = hlist_entry(h->reqQ.first, CommandList_struct, list);
2910 /* can't do anything if fifo is full */ 2936 /* can't do anything if fifo is full */
2911 if ((h->access.fifo_full(h))) { 2937 if ((h->access.fifo_full(h))) {
2912 printk(KERN_WARNING "cciss: fifo full\n"); 2938 dev_warn(&h->pdev->dev, "fifo full\n");
2913 break; 2939 break;
2914 } 2940 }
2915 2941
@@ -2925,7 +2951,7 @@ static void start_io(ctlr_info_t *h)
2925 } 2951 }
2926} 2952}
2927 2953
2928/* Assumes that CCISS_LOCK(h->ctlr) is held. */ 2954/* Assumes that h->lock is held. */
2929/* Zeros out the error record and then resends the command back */ 2955/* Zeros out the error record and then resends the command back */
2930/* to the controller */ 2956/* to the controller */
2931static inline void resend_cciss_cmd(ctlr_info_t *h, CommandList_struct *c) 2957static inline void resend_cciss_cmd(ctlr_info_t *h, CommandList_struct *c)
@@ -2966,7 +2992,7 @@ static inline int evaluate_target_status(ctlr_info_t *h,
2966 driver_byte = DRIVER_OK; 2992 driver_byte = DRIVER_OK;
2967 msg_byte = cmd->err_info->CommandStatus; /* correct? seems too device specific */ 2993 msg_byte = cmd->err_info->CommandStatus; /* correct? seems too device specific */
2968 2994
2969 if (blk_pc_request(cmd->rq)) 2995 if (cmd->rq->cmd_type == REQ_TYPE_BLOCK_PC)
2970 host_byte = DID_PASSTHROUGH; 2996 host_byte = DID_PASSTHROUGH;
2971 else 2997 else
2972 host_byte = DID_OK; 2998 host_byte = DID_OK;
@@ -2975,8 +3001,8 @@ static inline int evaluate_target_status(ctlr_info_t *h,
2975 host_byte, driver_byte); 3001 host_byte, driver_byte);
2976 3002
2977 if (cmd->err_info->ScsiStatus != SAM_STAT_CHECK_CONDITION) { 3003 if (cmd->err_info->ScsiStatus != SAM_STAT_CHECK_CONDITION) {
2978 if (!blk_pc_request(cmd->rq)) 3004 if (cmd->rq->cmd_type != REQ_TYPE_BLOCK_PC)
2979 printk(KERN_WARNING "cciss: cmd %p " 3005 dev_warn(&h->pdev->dev, "cmd %p "
2980 "has SCSI Status 0x%x\n", 3006 "has SCSI Status 0x%x\n",
2981 cmd, cmd->err_info->ScsiStatus); 3007 cmd, cmd->err_info->ScsiStatus);
2982 return error_value; 3008 return error_value;
@@ -2985,17 +3011,19 @@ static inline int evaluate_target_status(ctlr_info_t *h,
2985 /* check the sense key */ 3011 /* check the sense key */
2986 sense_key = 0xf & cmd->err_info->SenseInfo[2]; 3012 sense_key = 0xf & cmd->err_info->SenseInfo[2];
2987 /* no status or recovered error */ 3013 /* no status or recovered error */
2988 if (((sense_key == 0x0) || (sense_key == 0x1)) && !blk_pc_request(cmd->rq)) 3014 if (((sense_key == 0x0) || (sense_key == 0x1)) &&
3015 (cmd->rq->cmd_type != REQ_TYPE_BLOCK_PC))
2989 error_value = 0; 3016 error_value = 0;
2990 3017
2991 if (check_for_unit_attention(h, cmd)) { 3018 if (check_for_unit_attention(h, cmd)) {
2992 *retry_cmd = !blk_pc_request(cmd->rq); 3019 *retry_cmd = !(cmd->rq->cmd_type == REQ_TYPE_BLOCK_PC);
2993 return 0; 3020 return 0;
2994 } 3021 }
2995 3022
2996 if (!blk_pc_request(cmd->rq)) { /* Not SG_IO or similar? */ 3023 /* Not SG_IO or similar? */
3024 if (cmd->rq->cmd_type != REQ_TYPE_BLOCK_PC) {
2997 if (error_value != 0) 3025 if (error_value != 0)
2998 printk(KERN_WARNING "cciss: cmd %p has CHECK CONDITION" 3026 dev_warn(&h->pdev->dev, "cmd %p has CHECK CONDITION"
2999 " sense key = 0x%x\n", cmd, sense_key); 3027 " sense key = 0x%x\n", cmd, sense_key);
3000 return error_value; 3028 return error_value;
3001 } 3029 }
@@ -3035,90 +3063,97 @@ static inline void complete_command(ctlr_info_t *h, CommandList_struct *cmd,
3035 rq->errors = evaluate_target_status(h, cmd, &retry_cmd); 3063 rq->errors = evaluate_target_status(h, cmd, &retry_cmd);
3036 break; 3064 break;
3037 case CMD_DATA_UNDERRUN: 3065 case CMD_DATA_UNDERRUN:
3038 if (blk_fs_request(cmd->rq)) { 3066 if (cmd->rq->cmd_type == REQ_TYPE_FS) {
3039 printk(KERN_WARNING "cciss: cmd %p has" 3067 dev_warn(&h->pdev->dev, "cmd %p has"
3040 " completed with data underrun " 3068 " completed with data underrun "
3041 "reported\n", cmd); 3069 "reported\n", cmd);
3042 cmd->rq->resid_len = cmd->err_info->ResidualCnt; 3070 cmd->rq->resid_len = cmd->err_info->ResidualCnt;
3043 } 3071 }
3044 break; 3072 break;
3045 case CMD_DATA_OVERRUN: 3073 case CMD_DATA_OVERRUN:
3046 if (blk_fs_request(cmd->rq)) 3074 if (cmd->rq->cmd_type == REQ_TYPE_FS)
3047 printk(KERN_WARNING "cciss: cmd %p has" 3075 dev_warn(&h->pdev->dev, "cciss: cmd %p has"
3048 " completed with data overrun " 3076 " completed with data overrun "
3049 "reported\n", cmd); 3077 "reported\n", cmd);
3050 break; 3078 break;
3051 case CMD_INVALID: 3079 case CMD_INVALID:
3052 printk(KERN_WARNING "cciss: cmd %p is " 3080 dev_warn(&h->pdev->dev, "cciss: cmd %p is "
3053 "reported invalid\n", cmd); 3081 "reported invalid\n", cmd);
3054 rq->errors = make_status_bytes(SAM_STAT_GOOD, 3082 rq->errors = make_status_bytes(SAM_STAT_GOOD,
3055 cmd->err_info->CommandStatus, DRIVER_OK, 3083 cmd->err_info->CommandStatus, DRIVER_OK,
3056 blk_pc_request(cmd->rq) ? DID_PASSTHROUGH : DID_ERROR); 3084 (cmd->rq->cmd_type == REQ_TYPE_BLOCK_PC) ?
3085 DID_PASSTHROUGH : DID_ERROR);
3057 break; 3086 break;
3058 case CMD_PROTOCOL_ERR: 3087 case CMD_PROTOCOL_ERR:
3059 printk(KERN_WARNING "cciss: cmd %p has " 3088 dev_warn(&h->pdev->dev, "cciss: cmd %p has "
3060 "protocol error \n", cmd); 3089 "protocol error\n", cmd);
3061 rq->errors = make_status_bytes(SAM_STAT_GOOD, 3090 rq->errors = make_status_bytes(SAM_STAT_GOOD,
3062 cmd->err_info->CommandStatus, DRIVER_OK, 3091 cmd->err_info->CommandStatus, DRIVER_OK,
3063 blk_pc_request(cmd->rq) ? DID_PASSTHROUGH : DID_ERROR); 3092 (cmd->rq->cmd_type == REQ_TYPE_BLOCK_PC) ?
3093 DID_PASSTHROUGH : DID_ERROR);
3064 break; 3094 break;
3065 case CMD_HARDWARE_ERR: 3095 case CMD_HARDWARE_ERR:
3066 printk(KERN_WARNING "cciss: cmd %p had " 3096 dev_warn(&h->pdev->dev, "cciss: cmd %p had "
3067 " hardware error\n", cmd); 3097 " hardware error\n", cmd);
3068 rq->errors = make_status_bytes(SAM_STAT_GOOD, 3098 rq->errors = make_status_bytes(SAM_STAT_GOOD,
3069 cmd->err_info->CommandStatus, DRIVER_OK, 3099 cmd->err_info->CommandStatus, DRIVER_OK,
3070 blk_pc_request(cmd->rq) ? DID_PASSTHROUGH : DID_ERROR); 3100 (cmd->rq->cmd_type == REQ_TYPE_BLOCK_PC) ?
3101 DID_PASSTHROUGH : DID_ERROR);
3071 break; 3102 break;
3072 case CMD_CONNECTION_LOST: 3103 case CMD_CONNECTION_LOST:
3073 printk(KERN_WARNING "cciss: cmd %p had " 3104 dev_warn(&h->pdev->dev, "cciss: cmd %p had "
3074 "connection lost\n", cmd); 3105 "connection lost\n", cmd);
3075 rq->errors = make_status_bytes(SAM_STAT_GOOD, 3106 rq->errors = make_status_bytes(SAM_STAT_GOOD,
3076 cmd->err_info->CommandStatus, DRIVER_OK, 3107 cmd->err_info->CommandStatus, DRIVER_OK,
3077 blk_pc_request(cmd->rq) ? DID_PASSTHROUGH : DID_ERROR); 3108 (cmd->rq->cmd_type == REQ_TYPE_BLOCK_PC) ?
3109 DID_PASSTHROUGH : DID_ERROR);
3078 break; 3110 break;
3079 case CMD_ABORTED: 3111 case CMD_ABORTED:
3080 printk(KERN_WARNING "cciss: cmd %p was " 3112 dev_warn(&h->pdev->dev, "cciss: cmd %p was "
3081 "aborted\n", cmd); 3113 "aborted\n", cmd);
3082 rq->errors = make_status_bytes(SAM_STAT_GOOD, 3114 rq->errors = make_status_bytes(SAM_STAT_GOOD,
3083 cmd->err_info->CommandStatus, DRIVER_OK, 3115 cmd->err_info->CommandStatus, DRIVER_OK,
3084 blk_pc_request(cmd->rq) ? DID_PASSTHROUGH : DID_ABORT); 3116 (cmd->rq->cmd_type == REQ_TYPE_BLOCK_PC) ?
3117 DID_PASSTHROUGH : DID_ABORT);
3085 break; 3118 break;
3086 case CMD_ABORT_FAILED: 3119 case CMD_ABORT_FAILED:
3087 printk(KERN_WARNING "cciss: cmd %p reports " 3120 dev_warn(&h->pdev->dev, "cciss: cmd %p reports "
3088 "abort failed\n", cmd); 3121 "abort failed\n", cmd);
3089 rq->errors = make_status_bytes(SAM_STAT_GOOD, 3122 rq->errors = make_status_bytes(SAM_STAT_GOOD,
3090 cmd->err_info->CommandStatus, DRIVER_OK, 3123 cmd->err_info->CommandStatus, DRIVER_OK,
3091 blk_pc_request(cmd->rq) ? DID_PASSTHROUGH : DID_ERROR); 3124 (cmd->rq->cmd_type == REQ_TYPE_BLOCK_PC) ?
3125 DID_PASSTHROUGH : DID_ERROR);
3092 break; 3126 break;
3093 case CMD_UNSOLICITED_ABORT: 3127 case CMD_UNSOLICITED_ABORT:
3094 printk(KERN_WARNING "cciss%d: unsolicited " 3128 dev_warn(&h->pdev->dev, "cciss%d: unsolicited "
3095 "abort %p\n", h->ctlr, cmd); 3129 "abort %p\n", h->ctlr, cmd);
3096 if (cmd->retry_count < MAX_CMD_RETRIES) { 3130 if (cmd->retry_count < MAX_CMD_RETRIES) {
3097 retry_cmd = 1; 3131 retry_cmd = 1;
3098 printk(KERN_WARNING 3132 dev_warn(&h->pdev->dev, "retrying %p\n", cmd);
3099 "cciss%d: retrying %p\n", h->ctlr, cmd);
3100 cmd->retry_count++; 3133 cmd->retry_count++;
3101 } else 3134 } else
3102 printk(KERN_WARNING 3135 dev_warn(&h->pdev->dev,
3103 "cciss%d: %p retried too " 3136 "%p retried too many times\n", cmd);
3104 "many times\n", h->ctlr, cmd);
3105 rq->errors = make_status_bytes(SAM_STAT_GOOD, 3137 rq->errors = make_status_bytes(SAM_STAT_GOOD,
3106 cmd->err_info->CommandStatus, DRIVER_OK, 3138 cmd->err_info->CommandStatus, DRIVER_OK,
3107 blk_pc_request(cmd->rq) ? DID_PASSTHROUGH : DID_ABORT); 3139 (cmd->rq->cmd_type == REQ_TYPE_BLOCK_PC) ?
3140 DID_PASSTHROUGH : DID_ABORT);
3108 break; 3141 break;
3109 case CMD_TIMEOUT: 3142 case CMD_TIMEOUT:
3110 printk(KERN_WARNING "cciss: cmd %p timedout\n", cmd); 3143 dev_warn(&h->pdev->dev, "cmd %p timedout\n", cmd);
3111 rq->errors = make_status_bytes(SAM_STAT_GOOD, 3144 rq->errors = make_status_bytes(SAM_STAT_GOOD,
3112 cmd->err_info->CommandStatus, DRIVER_OK, 3145 cmd->err_info->CommandStatus, DRIVER_OK,
3113 blk_pc_request(cmd->rq) ? DID_PASSTHROUGH : DID_ERROR); 3146 (cmd->rq->cmd_type == REQ_TYPE_BLOCK_PC) ?
3147 DID_PASSTHROUGH : DID_ERROR);
3114 break; 3148 break;
3115 default: 3149 default:
3116 printk(KERN_WARNING "cciss: cmd %p returned " 3150 dev_warn(&h->pdev->dev, "cmd %p returned "
3117 "unknown status %x\n", cmd, 3151 "unknown status %x\n", cmd,
3118 cmd->err_info->CommandStatus); 3152 cmd->err_info->CommandStatus);
3119 rq->errors = make_status_bytes(SAM_STAT_GOOD, 3153 rq->errors = make_status_bytes(SAM_STAT_GOOD,
3120 cmd->err_info->CommandStatus, DRIVER_OK, 3154 cmd->err_info->CommandStatus, DRIVER_OK,
3121 blk_pc_request(cmd->rq) ? DID_PASSTHROUGH : DID_ERROR); 3155 (cmd->rq->cmd_type == REQ_TYPE_BLOCK_PC) ?
3156 DID_PASSTHROUGH : DID_ERROR);
3122 } 3157 }
3123 3158
3124after_error_processing: 3159after_error_processing:
@@ -3132,6 +3167,34 @@ after_error_processing:
3132 blk_complete_request(cmd->rq); 3167 blk_complete_request(cmd->rq);
3133} 3168}
3134 3169
3170static inline u32 cciss_tag_contains_index(u32 tag)
3171{
3172#define DIRECT_LOOKUP_BIT 0x10
3173 return tag & DIRECT_LOOKUP_BIT;
3174}
3175
3176static inline u32 cciss_tag_to_index(u32 tag)
3177{
3178#define DIRECT_LOOKUP_SHIFT 5
3179 return tag >> DIRECT_LOOKUP_SHIFT;
3180}
3181
3182static inline u32 cciss_tag_discard_error_bits(u32 tag)
3183{
3184#define CCISS_ERROR_BITS 0x03
3185 return tag & ~CCISS_ERROR_BITS;
3186}
3187
3188static inline void cciss_mark_tag_indexed(u32 *tag)
3189{
3190 *tag |= DIRECT_LOOKUP_BIT;
3191}
3192
3193static inline void cciss_set_tag_index(u32 *tag, u32 index)
3194{
3195 *tag |= (index << DIRECT_LOOKUP_SHIFT);
3196}
3197
3135/* 3198/*
3136 * Get a request and submit it to the controller. 3199 * Get a request and submit it to the controller.
3137 */ 3200 */
@@ -3163,7 +3226,8 @@ static void do_cciss_request(struct request_queue *q)
3163 3226
3164 BUG_ON(creq->nr_phys_segments > h->maxsgentries); 3227 BUG_ON(creq->nr_phys_segments > h->maxsgentries);
3165 3228
3166 if ((c = cmd_alloc(h, 1)) == NULL) 3229 c = cmd_alloc(h);
3230 if (!c)
3167 goto full; 3231 goto full;
3168 3232
3169 blk_start_request(creq); 3233 blk_start_request(creq);
@@ -3180,8 +3244,8 @@ static void do_cciss_request(struct request_queue *q)
3180 /* got command from pool, so use the command block index instead */ 3244 /* got command from pool, so use the command block index instead */
3181 /* for direct lookups. */ 3245 /* for direct lookups. */
3182 /* The first 2 bits are reserved for controller error reporting. */ 3246 /* The first 2 bits are reserved for controller error reporting. */
3183 c->Header.Tag.lower = (c->cmdindex << 3); 3247 cciss_set_tag_index(&c->Header.Tag.lower, c->cmdindex);
3184 c->Header.Tag.lower |= 0x04; /* flag for direct lookup. */ 3248 cciss_mark_tag_indexed(&c->Header.Tag.lower);
3185 memcpy(&c->Header.LUN, drv->LunID, sizeof(drv->LunID)); 3249 memcpy(&c->Header.LUN, drv->LunID, sizeof(drv->LunID));
3186 c->Request.CDBLen = 10; /* 12 byte commands not in FW yet; */ 3250 c->Request.CDBLen = 10; /* 12 byte commands not in FW yet; */
3187 c->Request.Type.Type = TYPE_CMD; /* It is a command. */ 3251 c->Request.Type.Type = TYPE_CMD; /* It is a command. */
@@ -3192,11 +3256,8 @@ static void do_cciss_request(struct request_queue *q)
3192 c->Request.CDB[0] = 3256 c->Request.CDB[0] =
3193 (rq_data_dir(creq) == READ) ? h->cciss_read : h->cciss_write; 3257 (rq_data_dir(creq) == READ) ? h->cciss_read : h->cciss_write;
3194 start_blk = blk_rq_pos(creq); 3258 start_blk = blk_rq_pos(creq);
3195#ifdef CCISS_DEBUG 3259 dev_dbg(&h->pdev->dev, "sector =%d nr_sectors=%d\n",
3196 printk(KERN_DEBUG "ciss: sector =%d nr_sectors=%d\n",
3197 (int)blk_rq_pos(creq), (int)blk_rq_sectors(creq)); 3260 (int)blk_rq_pos(creq), (int)blk_rq_sectors(creq));
3198#endif /* CCISS_DEBUG */
3199
3200 sg_init_table(tmp_sg, h->maxsgentries); 3261 sg_init_table(tmp_sg, h->maxsgentries);
3201 seg = blk_rq_map_sg(q, creq, tmp_sg); 3262 seg = blk_rq_map_sg(q, creq, tmp_sg);
3202 3263
@@ -3236,17 +3297,18 @@ static void do_cciss_request(struct request_queue *q)
3236 if (seg > h->maxSG) 3297 if (seg > h->maxSG)
3237 h->maxSG = seg; 3298 h->maxSG = seg;
3238 3299
3239#ifdef CCISS_DEBUG 3300 dev_dbg(&h->pdev->dev, "Submitting %u sectors in %d segments "
3240 printk(KERN_DEBUG "cciss: Submitting %ld sectors in %d segments "
3241 "chained[%d]\n", 3301 "chained[%d]\n",
3242 blk_rq_sectors(creq), seg, chained); 3302 blk_rq_sectors(creq), seg, chained);
3243#endif /* CCISS_DEBUG */
3244 3303
3245 c->Header.SGList = c->Header.SGTotal = seg + chained; 3304 c->Header.SGTotal = seg + chained;
3246 if (seg > h->max_cmd_sgentries) 3305 if (seg <= h->max_cmd_sgentries)
3306 c->Header.SGList = c->Header.SGTotal;
3307 else
3247 c->Header.SGList = h->max_cmd_sgentries; 3308 c->Header.SGList = h->max_cmd_sgentries;
3309 set_performant_mode(h, c);
3248 3310
3249 if (likely(blk_fs_request(creq))) { 3311 if (likely(creq->cmd_type == REQ_TYPE_FS)) {
3250 if(h->cciss_read == CCISS_READ_10) { 3312 if(h->cciss_read == CCISS_READ_10) {
3251 c->Request.CDB[1] = 0; 3313 c->Request.CDB[1] = 0;
3252 c->Request.CDB[2] = (start_blk >> 24) & 0xff; /* MSB */ 3314 c->Request.CDB[2] = (start_blk >> 24) & 0xff; /* MSB */
@@ -3276,11 +3338,12 @@ static void do_cciss_request(struct request_queue *q)
3276 c->Request.CDB[13]= blk_rq_sectors(creq) & 0xff; 3338 c->Request.CDB[13]= blk_rq_sectors(creq) & 0xff;
3277 c->Request.CDB[14] = c->Request.CDB[15] = 0; 3339 c->Request.CDB[14] = c->Request.CDB[15] = 0;
3278 } 3340 }
3279 } else if (blk_pc_request(creq)) { 3341 } else if (creq->cmd_type == REQ_TYPE_BLOCK_PC) {
3280 c->Request.CDBLen = creq->cmd_len; 3342 c->Request.CDBLen = creq->cmd_len;
3281 memcpy(c->Request.CDB, creq->cmd, BLK_MAX_CDB); 3343 memcpy(c->Request.CDB, creq->cmd, BLK_MAX_CDB);
3282 } else { 3344 } else {
3283 printk(KERN_WARNING "cciss%d: bad request type %d\n", h->ctlr, creq->cmd_type); 3345 dev_warn(&h->pdev->dev, "bad request type %d\n",
3346 creq->cmd_type);
3284 BUG(); 3347 BUG();
3285 } 3348 }
3286 3349
@@ -3313,72 +3376,131 @@ static inline int interrupt_pending(ctlr_info_t *h)
3313 3376
3314static inline long interrupt_not_for_us(ctlr_info_t *h) 3377static inline long interrupt_not_for_us(ctlr_info_t *h)
3315{ 3378{
3316 return (((h->access.intr_pending(h) == 0) || 3379 return ((h->access.intr_pending(h) == 0) ||
3317 (h->interrupts_enabled == 0))); 3380 (h->interrupts_enabled == 0));
3318} 3381}
3319 3382
3320static irqreturn_t do_cciss_intr(int irq, void *dev_id) 3383static inline int bad_tag(ctlr_info_t *h, u32 tag_index,
3384 u32 raw_tag)
3321{ 3385{
3322 ctlr_info_t *h = dev_id; 3386 if (unlikely(tag_index >= h->nr_cmds)) {
3387 dev_warn(&h->pdev->dev, "bad tag 0x%08x ignored.\n", raw_tag);
3388 return 1;
3389 }
3390 return 0;
3391}
3392
3393static inline void finish_cmd(ctlr_info_t *h, CommandList_struct *c,
3394 u32 raw_tag)
3395{
3396 removeQ(c);
3397 if (likely(c->cmd_type == CMD_RWREQ))
3398 complete_command(h, c, 0);
3399 else if (c->cmd_type == CMD_IOCTL_PEND)
3400 complete(c->waiting);
3401#ifdef CONFIG_CISS_SCSI_TAPE
3402 else if (c->cmd_type == CMD_SCSI)
3403 complete_scsi_command(c, 0, raw_tag);
3404#endif
3405}
3406
3407static inline u32 next_command(ctlr_info_t *h)
3408{
3409 u32 a;
3410
3411 if (unlikely(h->transMethod != CFGTBL_Trans_Performant))
3412 return h->access.command_completed(h);
3413
3414 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
3415 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
3416 (h->reply_pool_head)++;
3417 h->commands_outstanding--;
3418 } else {
3419 a = FIFO_EMPTY;
3420 }
3421 /* Check for wraparound */
3422 if (h->reply_pool_head == (h->reply_pool + h->max_commands)) {
3423 h->reply_pool_head = h->reply_pool;
3424 h->reply_pool_wraparound ^= 1;
3425 }
3426 return a;
3427}
3428
3429/* process completion of an indexed ("direct lookup") command */
3430static inline u32 process_indexed_cmd(ctlr_info_t *h, u32 raw_tag)
3431{
3432 u32 tag_index;
3323 CommandList_struct *c; 3433 CommandList_struct *c;
3434
3435 tag_index = cciss_tag_to_index(raw_tag);
3436 if (bad_tag(h, tag_index, raw_tag))
3437 return next_command(h);
3438 c = h->cmd_pool + tag_index;
3439 finish_cmd(h, c, raw_tag);
3440 return next_command(h);
3441}
3442
3443/* process completion of a non-indexed command */
3444static inline u32 process_nonindexed_cmd(ctlr_info_t *h, u32 raw_tag)
3445{
3446 u32 tag;
3447 CommandList_struct *c = NULL;
3448 struct hlist_node *tmp;
3449 __u32 busaddr_masked, tag_masked;
3450
3451 tag = cciss_tag_discard_error_bits(raw_tag);
3452 hlist_for_each_entry(c, tmp, &h->cmpQ, list) {
3453 busaddr_masked = cciss_tag_discard_error_bits(c->busaddr);
3454 tag_masked = cciss_tag_discard_error_bits(tag);
3455 if (busaddr_masked == tag_masked) {
3456 finish_cmd(h, c, raw_tag);
3457 return next_command(h);
3458 }
3459 }
3460 bad_tag(h, h->nr_cmds + 1, raw_tag);
3461 return next_command(h);
3462}
3463
3464static irqreturn_t do_cciss_intx(int irq, void *dev_id)
3465{
3466 ctlr_info_t *h = dev_id;
3324 unsigned long flags; 3467 unsigned long flags;
3325 __u32 a, a1, a2; 3468 u32 raw_tag;
3326 3469
3327 if (interrupt_not_for_us(h)) 3470 if (interrupt_not_for_us(h))
3328 return IRQ_NONE; 3471 return IRQ_NONE;
3329 /* 3472 spin_lock_irqsave(&h->lock, flags);
3330 * If there are completed commands in the completion queue,
3331 * we had better do something about it.
3332 */
3333 spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags);
3334 while (interrupt_pending(h)) { 3473 while (interrupt_pending(h)) {
3335 while ((a = get_next_completion(h)) != FIFO_EMPTY) { 3474 raw_tag = get_next_completion(h);
3336 a1 = a; 3475 while (raw_tag != FIFO_EMPTY) {
3337 if ((a & 0x04)) { 3476 if (cciss_tag_contains_index(raw_tag))
3338 a2 = (a >> 3); 3477 raw_tag = process_indexed_cmd(h, raw_tag);
3339 if (a2 >= h->nr_cmds) { 3478 else
3340 printk(KERN_WARNING 3479 raw_tag = process_nonindexed_cmd(h, raw_tag);
3341 "cciss: controller cciss%d failed, stopping.\n",
3342 h->ctlr);
3343 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
3344 fail_all_cmds(h->ctlr);
3345 return IRQ_HANDLED;
3346 }
3347
3348 c = h->cmd_pool + a2;
3349 a = c->busaddr;
3350
3351 } else {
3352 struct hlist_node *tmp;
3353
3354 a &= ~3;
3355 c = NULL;
3356 hlist_for_each_entry(c, tmp, &h->cmpQ, list) {
3357 if (c->busaddr == a)
3358 break;
3359 }
3360 }
3361 /*
3362 * If we've found the command, take it off the
3363 * completion Q and free it
3364 */
3365 if (c && c->busaddr == a) {
3366 removeQ(c);
3367 if (c->cmd_type == CMD_RWREQ) {
3368 complete_command(h, c, 0);
3369 } else if (c->cmd_type == CMD_IOCTL_PEND) {
3370 complete(c->waiting);
3371 }
3372# ifdef CONFIG_CISS_SCSI_TAPE
3373 else if (c->cmd_type == CMD_SCSI)
3374 complete_scsi_command(c, 0, a1);
3375# endif
3376 continue;
3377 }
3378 } 3480 }
3379 } 3481 }
3482 spin_unlock_irqrestore(&h->lock, flags);
3483 return IRQ_HANDLED;
3484}
3380 3485
3381 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); 3486/* Add a second interrupt handler for MSI/MSI-X mode. In this mode we never
3487 * check the interrupt pending register because it is not set.
3488 */
3489static irqreturn_t do_cciss_msix_intr(int irq, void *dev_id)
3490{
3491 ctlr_info_t *h = dev_id;
3492 unsigned long flags;
3493 u32 raw_tag;
3494
3495 spin_lock_irqsave(&h->lock, flags);
3496 raw_tag = get_next_completion(h);
3497 while (raw_tag != FIFO_EMPTY) {
3498 if (cciss_tag_contains_index(raw_tag))
3499 raw_tag = process_indexed_cmd(h, raw_tag);
3500 else
3501 raw_tag = process_nonindexed_cmd(h, raw_tag);
3502 }
3503 spin_unlock_irqrestore(&h->lock, flags);
3382 return IRQ_HANDLED; 3504 return IRQ_HANDLED;
3383} 3505}
3384 3506
@@ -3510,18 +3632,17 @@ static int check_for_unit_attention(ctlr_info_t *h, CommandList_struct *c)
3510 3632
3511 switch (c->err_info->SenseInfo[12]) { 3633 switch (c->err_info->SenseInfo[12]) {
3512 case STATE_CHANGED: 3634 case STATE_CHANGED:
3513 printk(KERN_WARNING "cciss%d: a state change " 3635 dev_warn(&h->pdev->dev, "a state change "
3514 "detected, command retried\n", h->ctlr); 3636 "detected, command retried\n");
3515 return 1; 3637 return 1;
3516 break; 3638 break;
3517 case LUN_FAILED: 3639 case LUN_FAILED:
3518 printk(KERN_WARNING "cciss%d: LUN failure " 3640 dev_warn(&h->pdev->dev, "LUN failure "
3519 "detected, action required\n", h->ctlr); 3641 "detected, action required\n");
3520 return 1; 3642 return 1;
3521 break; 3643 break;
3522 case REPORT_LUNS_CHANGED: 3644 case REPORT_LUNS_CHANGED:
3523 printk(KERN_WARNING "cciss%d: report LUN data " 3645 dev_warn(&h->pdev->dev, "report LUN data changed\n");
3524 "changed\n", h->ctlr);
3525 /* 3646 /*
3526 * Here, we could call add_to_scan_list and wake up the scan thread, 3647 * Here, we could call add_to_scan_list and wake up the scan thread,
3527 * except that it's quite likely that we will get more than one 3648 * except that it's quite likely that we will get more than one
@@ -3541,19 +3662,18 @@ static int check_for_unit_attention(ctlr_info_t *h, CommandList_struct *c)
3541 return 1; 3662 return 1;
3542 break; 3663 break;
3543 case POWER_OR_RESET: 3664 case POWER_OR_RESET:
3544 printk(KERN_WARNING "cciss%d: a power on " 3665 dev_warn(&h->pdev->dev,
3545 "or device reset detected\n", h->ctlr); 3666 "a power on or device reset detected\n");
3546 return 1; 3667 return 1;
3547 break; 3668 break;
3548 case UNIT_ATTENTION_CLEARED: 3669 case UNIT_ATTENTION_CLEARED:
3549 printk(KERN_WARNING "cciss%d: unit attention " 3670 dev_warn(&h->pdev->dev,
3550 "cleared by another initiator\n", h->ctlr); 3671 "unit attention cleared by another initiator\n");
3551 return 1; 3672 return 1;
3552 break; 3673 break;
3553 default: 3674 default:
3554 printk(KERN_WARNING "cciss%d: unknown " 3675 dev_warn(&h->pdev->dev, "unknown unit attention detected\n");
3555 "unit attention detected\n", h->ctlr); 3676 return 1;
3556 return 1;
3557 } 3677 }
3558} 3678}
3559 3679
@@ -3562,39 +3682,41 @@ static int check_for_unit_attention(ctlr_info_t *h, CommandList_struct *c)
3562 * the io functions. 3682 * the io functions.
3563 * This is for debug only. 3683 * This is for debug only.
3564 */ 3684 */
3565#ifdef CCISS_DEBUG 3685static void print_cfg_table(ctlr_info_t *h)
3566static void print_cfg_table(CfgTable_struct *tb)
3567{ 3686{
3568 int i; 3687 int i;
3569 char temp_name[17]; 3688 char temp_name[17];
3689 CfgTable_struct *tb = h->cfgtable;
3570 3690
3571 printk("Controller Configuration information\n"); 3691 dev_dbg(&h->pdev->dev, "Controller Configuration information\n");
3572 printk("------------------------------------\n"); 3692 dev_dbg(&h->pdev->dev, "------------------------------------\n");
3573 for (i = 0; i < 4; i++) 3693 for (i = 0; i < 4; i++)
3574 temp_name[i] = readb(&(tb->Signature[i])); 3694 temp_name[i] = readb(&(tb->Signature[i]));
3575 temp_name[4] = '\0'; 3695 temp_name[4] = '\0';
3576 printk(" Signature = %s\n", temp_name); 3696 dev_dbg(&h->pdev->dev, " Signature = %s\n", temp_name);
3577 printk(" Spec Number = %d\n", readl(&(tb->SpecValence))); 3697 dev_dbg(&h->pdev->dev, " Spec Number = %d\n",
3578 printk(" Transport methods supported = 0x%x\n", 3698 readl(&(tb->SpecValence)));
3699 dev_dbg(&h->pdev->dev, " Transport methods supported = 0x%x\n",
3579 readl(&(tb->TransportSupport))); 3700 readl(&(tb->TransportSupport)));
3580 printk(" Transport methods active = 0x%x\n", 3701 dev_dbg(&h->pdev->dev, " Transport methods active = 0x%x\n",
3581 readl(&(tb->TransportActive))); 3702 readl(&(tb->TransportActive)));
3582 printk(" Requested transport Method = 0x%x\n", 3703 dev_dbg(&h->pdev->dev, " Requested transport Method = 0x%x\n",
3583 readl(&(tb->HostWrite.TransportRequest))); 3704 readl(&(tb->HostWrite.TransportRequest)));
3584 printk(" Coalesce Interrupt Delay = 0x%x\n", 3705 dev_dbg(&h->pdev->dev, " Coalesce Interrupt Delay = 0x%x\n",
3585 readl(&(tb->HostWrite.CoalIntDelay))); 3706 readl(&(tb->HostWrite.CoalIntDelay)));
3586 printk(" Coalesce Interrupt Count = 0x%x\n", 3707 dev_dbg(&h->pdev->dev, " Coalesce Interrupt Count = 0x%x\n",
3587 readl(&(tb->HostWrite.CoalIntCount))); 3708 readl(&(tb->HostWrite.CoalIntCount)));
3588 printk(" Max outstanding commands = 0x%d\n", 3709 dev_dbg(&h->pdev->dev, " Max outstanding commands = 0x%d\n",
3589 readl(&(tb->CmdsOutMax))); 3710 readl(&(tb->CmdsOutMax)));
3590 printk(" Bus Types = 0x%x\n", readl(&(tb->BusTypes))); 3711 dev_dbg(&h->pdev->dev, " Bus Types = 0x%x\n",
3712 readl(&(tb->BusTypes)));
3591 for (i = 0; i < 16; i++) 3713 for (i = 0; i < 16; i++)
3592 temp_name[i] = readb(&(tb->ServerName[i])); 3714 temp_name[i] = readb(&(tb->ServerName[i]));
3593 temp_name[16] = '\0'; 3715 temp_name[16] = '\0';
3594 printk(" Server Name = %s\n", temp_name); 3716 dev_dbg(&h->pdev->dev, " Server Name = %s\n", temp_name);
3595 printk(" Heartbeat Counter = 0x%x\n\n\n", readl(&(tb->HeartBeat))); 3717 dev_dbg(&h->pdev->dev, " Heartbeat Counter = 0x%x\n\n\n",
3718 readl(&(tb->HeartBeat)));
3596} 3719}
3597#endif /* CCISS_DEBUG */
3598 3720
3599static int find_PCI_BAR_index(struct pci_dev *pdev, unsigned long pci_bar_addr) 3721static int find_PCI_BAR_index(struct pci_dev *pdev, unsigned long pci_bar_addr)
3600{ 3722{
@@ -3618,7 +3740,7 @@ static int find_PCI_BAR_index(struct pci_dev *pdev, unsigned long pci_bar_addr)
3618 offset += 8; 3740 offset += 8;
3619 break; 3741 break;
3620 default: /* reserved in PCI 2.2 */ 3742 default: /* reserved in PCI 2.2 */
3621 printk(KERN_WARNING 3743 dev_warn(&pdev->dev,
3622 "Base address is invalid\n"); 3744 "Base address is invalid\n");
3623 return -1; 3745 return -1;
3624 break; 3746 break;
@@ -3630,12 +3752,182 @@ static int find_PCI_BAR_index(struct pci_dev *pdev, unsigned long pci_bar_addr)
3630 return -1; 3752 return -1;
3631} 3753}
3632 3754
3755/* Fill in bucket_map[], given nsgs (the max number of
3756 * scatter gather elements supported) and bucket[],
3757 * which is an array of 8 integers. The bucket[] array
3758 * contains 8 different DMA transfer sizes (in 16
3759 * byte increments) which the controller uses to fetch
3760 * commands. This function fills in bucket_map[], which
3761 * maps a given number of scatter gather elements to one of
3762 * the 8 DMA transfer sizes. The point of it is to allow the
3763 * controller to only do as much DMA as needed to fetch the
3764 * command, with the DMA transfer size encoded in the lower
3765 * bits of the command address.
3766 */
3767static void calc_bucket_map(int bucket[], int num_buckets,
3768 int nsgs, int *bucket_map)
3769{
3770 int i, j, b, size;
3771
3772 /* even a command with 0 SGs requires 4 blocks */
3773#define MINIMUM_TRANSFER_BLOCKS 4
3774#define NUM_BUCKETS 8
3775 /* Note, bucket_map must have nsgs+1 entries. */
3776 for (i = 0; i <= nsgs; i++) {
3777 /* Compute size of a command with i SG entries */
3778 size = i + MINIMUM_TRANSFER_BLOCKS;
3779 b = num_buckets; /* Assume the biggest bucket */
3780 /* Find the bucket that is just big enough */
3781 for (j = 0; j < 8; j++) {
3782 if (bucket[j] >= size) {
3783 b = j;
3784 break;
3785 }
3786 }
3787 /* for a command with i SG entries, use bucket b. */
3788 bucket_map[i] = b;
3789 }
3790}
3791
3792static void __devinit cciss_wait_for_mode_change_ack(ctlr_info_t *h)
3793{
3794 int i;
3795
3796 /* under certain very rare conditions, this can take awhile.
3797 * (e.g.: hot replace a failed 144GB drive in a RAID 5 set right
3798 * as we enter this code.) */
3799 for (i = 0; i < MAX_CONFIG_WAIT; i++) {
3800 if (!(readl(h->vaddr + SA5_DOORBELL) & CFGTBL_ChangeReq))
3801 break;
3802 msleep(10);
3803 }
3804}
3805
3806static __devinit void cciss_enter_performant_mode(ctlr_info_t *h)
3807{
3808 /* This is a bit complicated. There are 8 registers on
3809 * the controller which we write to to tell it 8 different
3810 * sizes of commands which there may be. It's a way of
3811 * reducing the DMA done to fetch each command. Encoded into
3812 * each command's tag are 3 bits which communicate to the controller
3813 * which of the eight sizes that command fits within. The size of
3814 * each command depends on how many scatter gather entries there are.
3815 * Each SG entry requires 16 bytes. The eight registers are programmed
3816 * with the number of 16-byte blocks a command of that size requires.
3817 * The smallest command possible requires 5 such 16 byte blocks.
3818 * the largest command possible requires MAXSGENTRIES + 4 16-byte
3819 * blocks. Note, this only extends to the SG entries contained
3820 * within the command block, and does not extend to chained blocks
3821 * of SG elements. bft[] contains the eight values we write to
3822 * the registers. They are not evenly distributed, but have more
3823 * sizes for small commands, and fewer sizes for larger commands.
3824 */
3825 __u32 trans_offset;
3826 int bft[8] = { 5, 6, 8, 10, 12, 20, 28, MAXSGENTRIES + 4};
3827 /*
3828 * 5 = 1 s/g entry or 4k
3829 * 6 = 2 s/g entry or 8k
3830 * 8 = 4 s/g entry or 16k
3831 * 10 = 6 s/g entry or 24k
3832 */
3833 unsigned long register_value;
3834 BUILD_BUG_ON(28 > MAXSGENTRIES + 4);
3835
3836 h->reply_pool_wraparound = 1; /* spec: init to 1 */
3837
3838 /* Controller spec: zero out this buffer. */
3839 memset(h->reply_pool, 0, h->max_commands * sizeof(__u64));
3840 h->reply_pool_head = h->reply_pool;
3841
3842 trans_offset = readl(&(h->cfgtable->TransMethodOffset));
3843 calc_bucket_map(bft, ARRAY_SIZE(bft), h->maxsgentries,
3844 h->blockFetchTable);
3845 writel(bft[0], &h->transtable->BlockFetch0);
3846 writel(bft[1], &h->transtable->BlockFetch1);
3847 writel(bft[2], &h->transtable->BlockFetch2);
3848 writel(bft[3], &h->transtable->BlockFetch3);
3849 writel(bft[4], &h->transtable->BlockFetch4);
3850 writel(bft[5], &h->transtable->BlockFetch5);
3851 writel(bft[6], &h->transtable->BlockFetch6);
3852 writel(bft[7], &h->transtable->BlockFetch7);
3853
3854 /* size of controller ring buffer */
3855 writel(h->max_commands, &h->transtable->RepQSize);
3856 writel(1, &h->transtable->RepQCount);
3857 writel(0, &h->transtable->RepQCtrAddrLow32);
3858 writel(0, &h->transtable->RepQCtrAddrHigh32);
3859 writel(h->reply_pool_dhandle, &h->transtable->RepQAddr0Low32);
3860 writel(0, &h->transtable->RepQAddr0High32);
3861 writel(CFGTBL_Trans_Performant,
3862 &(h->cfgtable->HostWrite.TransportRequest));
3863
3864 writel(CFGTBL_ChangeReq, h->vaddr + SA5_DOORBELL);
3865 cciss_wait_for_mode_change_ack(h);
3866 register_value = readl(&(h->cfgtable->TransportActive));
3867 if (!(register_value & CFGTBL_Trans_Performant))
3868 dev_warn(&h->pdev->dev, "cciss: unable to get board into"
3869 " performant mode\n");
3870}
3871
3872static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
3873{
3874 __u32 trans_support;
3875
3876 dev_dbg(&h->pdev->dev, "Trying to put board into Performant mode\n");
3877 /* Attempt to put controller into performant mode if supported */
3878 /* Does board support performant mode? */
3879 trans_support = readl(&(h->cfgtable->TransportSupport));
3880 if (!(trans_support & PERFORMANT_MODE))
3881 return;
3882
3883 dev_dbg(&h->pdev->dev, "Placing controller into performant mode\n");
3884 /* Performant mode demands commands on a 32 byte boundary
3885 * pci_alloc_consistent aligns on page boundarys already.
3886 * Just need to check if divisible by 32
3887 */
3888 if ((sizeof(CommandList_struct) % 32) != 0) {
3889 dev_warn(&h->pdev->dev, "%s %d %s\n",
3890 "cciss info: command size[",
3891 (int)sizeof(CommandList_struct),
3892 "] not divisible by 32, no performant mode..\n");
3893 return;
3894 }
3895
3896 /* Performant mode ring buffer and supporting data structures */
3897 h->reply_pool = (__u64 *)pci_alloc_consistent(
3898 h->pdev, h->max_commands * sizeof(__u64),
3899 &(h->reply_pool_dhandle));
3900
3901 /* Need a block fetch table for performant mode */
3902 h->blockFetchTable = kmalloc(((h->maxsgentries+1) *
3903 sizeof(__u32)), GFP_KERNEL);
3904
3905 if ((h->reply_pool == NULL) || (h->blockFetchTable == NULL))
3906 goto clean_up;
3907
3908 cciss_enter_performant_mode(h);
3909
3910 /* Change the access methods to the performant access methods */
3911 h->access = SA5_performant_access;
3912 h->transMethod = CFGTBL_Trans_Performant;
3913
3914 return;
3915clean_up:
3916 kfree(h->blockFetchTable);
3917 if (h->reply_pool)
3918 pci_free_consistent(h->pdev,
3919 h->max_commands * sizeof(__u64),
3920 h->reply_pool,
3921 h->reply_pool_dhandle);
3922 return;
3923
3924} /* cciss_put_controller_into_performant_mode */
3925
3633/* If MSI/MSI-X is supported by the kernel we will try to enable it on 3926/* If MSI/MSI-X is supported by the kernel we will try to enable it on
3634 * controllers that are capable. If not, we use IO-APIC mode. 3927 * controllers that are capable. If not, we use IO-APIC mode.
3635 */ 3928 */
3636 3929
3637static void __devinit cciss_interrupt_mode(ctlr_info_t *c, 3930static void __devinit cciss_interrupt_mode(ctlr_info_t *h)
3638 struct pci_dev *pdev, __u32 board_id)
3639{ 3931{
3640#ifdef CONFIG_PCI_MSI 3932#ifdef CONFIG_PCI_MSI
3641 int err; 3933 int err;
@@ -3644,268 +3936,283 @@ static void __devinit cciss_interrupt_mode(ctlr_info_t *c,
3644 }; 3936 };
3645 3937
3646 /* Some boards advertise MSI but don't really support it */ 3938 /* Some boards advertise MSI but don't really support it */
3647 if ((board_id == 0x40700E11) || 3939 if ((h->board_id == 0x40700E11) || (h->board_id == 0x40800E11) ||
3648 (board_id == 0x40800E11) || 3940 (h->board_id == 0x40820E11) || (h->board_id == 0x40830E11))
3649 (board_id == 0x40820E11) || (board_id == 0x40830E11))
3650 goto default_int_mode; 3941 goto default_int_mode;
3651 3942
3652 if (pci_find_capability(pdev, PCI_CAP_ID_MSIX)) { 3943 if (pci_find_capability(h->pdev, PCI_CAP_ID_MSIX)) {
3653 err = pci_enable_msix(pdev, cciss_msix_entries, 4); 3944 err = pci_enable_msix(h->pdev, cciss_msix_entries, 4);
3654 if (!err) { 3945 if (!err) {
3655 c->intr[0] = cciss_msix_entries[0].vector; 3946 h->intr[0] = cciss_msix_entries[0].vector;
3656 c->intr[1] = cciss_msix_entries[1].vector; 3947 h->intr[1] = cciss_msix_entries[1].vector;
3657 c->intr[2] = cciss_msix_entries[2].vector; 3948 h->intr[2] = cciss_msix_entries[2].vector;
3658 c->intr[3] = cciss_msix_entries[3].vector; 3949 h->intr[3] = cciss_msix_entries[3].vector;
3659 c->msix_vector = 1; 3950 h->msix_vector = 1;
3660 return; 3951 return;
3661 } 3952 }
3662 if (err > 0) { 3953 if (err > 0) {
3663 printk(KERN_WARNING "cciss: only %d MSI-X vectors " 3954 dev_warn(&h->pdev->dev,
3664 "available\n", err); 3955 "only %d MSI-X vectors available\n", err);
3665 goto default_int_mode; 3956 goto default_int_mode;
3666 } else { 3957 } else {
3667 printk(KERN_WARNING "cciss: MSI-X init failed %d\n", 3958 dev_warn(&h->pdev->dev,
3668 err); 3959 "MSI-X init failed %d\n", err);
3669 goto default_int_mode; 3960 goto default_int_mode;
3670 } 3961 }
3671 } 3962 }
3672 if (pci_find_capability(pdev, PCI_CAP_ID_MSI)) { 3963 if (pci_find_capability(h->pdev, PCI_CAP_ID_MSI)) {
3673 if (!pci_enable_msi(pdev)) { 3964 if (!pci_enable_msi(h->pdev))
3674 c->msi_vector = 1; 3965 h->msi_vector = 1;
3675 } else { 3966 else
3676 printk(KERN_WARNING "cciss: MSI init failed\n"); 3967 dev_warn(&h->pdev->dev, "MSI init failed\n");
3677 }
3678 } 3968 }
3679default_int_mode: 3969default_int_mode:
3680#endif /* CONFIG_PCI_MSI */ 3970#endif /* CONFIG_PCI_MSI */
3681 /* if we get here we're going to use the default interrupt mode */ 3971 /* if we get here we're going to use the default interrupt mode */
3682 c->intr[SIMPLE_MODE_INT] = pdev->irq; 3972 h->intr[PERF_MODE_INT] = h->pdev->irq;
3683 return; 3973 return;
3684} 3974}
3685 3975
3686static int __devinit cciss_pci_init(ctlr_info_t *c, struct pci_dev *pdev) 3976static int __devinit cciss_lookup_board_id(struct pci_dev *pdev, u32 *board_id)
3687{ 3977{
3688 ushort subsystem_vendor_id, subsystem_device_id, command; 3978 int i;
3689 __u32 board_id, scratchpad = 0; 3979 u32 subsystem_vendor_id, subsystem_device_id;
3690 __u64 cfg_offset;
3691 __u32 cfg_base_addr;
3692 __u64 cfg_base_addr_index;
3693 int i, prod_index, err;
3694 3980
3695 subsystem_vendor_id = pdev->subsystem_vendor; 3981 subsystem_vendor_id = pdev->subsystem_vendor;
3696 subsystem_device_id = pdev->subsystem_device; 3982 subsystem_device_id = pdev->subsystem_device;
3697 board_id = (((__u32) (subsystem_device_id << 16) & 0xffff0000) | 3983 *board_id = ((subsystem_device_id << 16) & 0xffff0000) |
3698 subsystem_vendor_id); 3984 subsystem_vendor_id;
3699 3985
3700 for (i = 0; i < ARRAY_SIZE(products); i++) { 3986 for (i = 0; i < ARRAY_SIZE(products); i++) {
3701 /* Stand aside for hpsa driver on request */ 3987 /* Stand aside for hpsa driver on request */
3702 if (cciss_allow_hpsa && products[i].board_id == HPSA_BOUNDARY) 3988 if (cciss_allow_hpsa && products[i].board_id == HPSA_BOUNDARY)
3703 return -ENODEV; 3989 return -ENODEV;
3704 if (board_id == products[i].board_id) 3990 if (*board_id == products[i].board_id)
3705 break; 3991 return i;
3706 }
3707 prod_index = i;
3708 if (prod_index == ARRAY_SIZE(products)) {
3709 dev_warn(&pdev->dev,
3710 "unrecognized board ID: 0x%08lx, ignoring.\n",
3711 (unsigned long) board_id);
3712 return -ENODEV;
3713 } 3992 }
3993 dev_warn(&pdev->dev, "unrecognized board ID: 0x%08x, ignoring.\n",
3994 *board_id);
3995 return -ENODEV;
3996}
3714 3997
3715 /* check to see if controller has been disabled */ 3998static inline bool cciss_board_disabled(ctlr_info_t *h)
3716 /* BEFORE trying to enable it */ 3999{
3717 (void)pci_read_config_word(pdev, PCI_COMMAND, &command); 4000 u16 command;
3718 if (!(command & 0x02)) {
3719 printk(KERN_WARNING
3720 "cciss: controller appears to be disabled\n");
3721 return -ENODEV;
3722 }
3723 4001
3724 err = pci_enable_device(pdev); 4002 (void) pci_read_config_word(h->pdev, PCI_COMMAND, &command);
3725 if (err) { 4003 return ((command & PCI_COMMAND_MEMORY) == 0);
3726 printk(KERN_ERR "cciss: Unable to Enable PCI device\n"); 4004}
3727 return err;
3728 }
3729 4005
3730 err = pci_request_regions(pdev, "cciss"); 4006static int __devinit cciss_pci_find_memory_BAR(struct pci_dev *pdev,
3731 if (err) { 4007 unsigned long *memory_bar)
3732 printk(KERN_ERR "cciss: Cannot obtain PCI resources, " 4008{
3733 "aborting\n"); 4009 int i;
3734 return err;
3735 }
3736 4010
3737#ifdef CCISS_DEBUG 4011 for (i = 0; i < DEVICE_COUNT_RESOURCE; i++)
3738 printk("command = %x\n", command); 4012 if (pci_resource_flags(pdev, i) & IORESOURCE_MEM) {
3739 printk("irq = %x\n", pdev->irq); 4013 /* addressing mode bits already removed */
3740 printk("board_id = %x\n", board_id); 4014 *memory_bar = pci_resource_start(pdev, i);
3741#endif /* CCISS_DEBUG */ 4015 dev_dbg(&pdev->dev, "memory BAR = %lx\n",
4016 *memory_bar);
4017 return 0;
4018 }
4019 dev_warn(&pdev->dev, "no memory BAR found\n");
4020 return -ENODEV;
4021}
3742 4022
3743/* If the kernel supports MSI/MSI-X we will try to enable that functionality, 4023static int __devinit cciss_wait_for_board_ready(ctlr_info_t *h)
3744 * else we use the IO-APIC interrupt assigned to us by system ROM. 4024{
3745 */ 4025 int i;
3746 cciss_interrupt_mode(c, pdev, board_id); 4026 u32 scratchpad;
3747 4027
3748 /* find the memory BAR */ 4028 for (i = 0; i < CCISS_BOARD_READY_ITERATIONS; i++) {
3749 for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) { 4029 scratchpad = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
3750 if (pci_resource_flags(pdev, i) & IORESOURCE_MEM) 4030 if (scratchpad == CCISS_FIRMWARE_READY)
3751 break; 4031 return 0;
3752 } 4032 msleep(CCISS_BOARD_READY_POLL_INTERVAL_MSECS);
3753 if (i == DEVICE_COUNT_RESOURCE) {
3754 printk(KERN_WARNING "cciss: No memory BAR found\n");
3755 err = -ENODEV;
3756 goto err_out_free_res;
3757 } 4033 }
4034 dev_warn(&h->pdev->dev, "board not ready, timed out.\n");
4035 return -ENODEV;
4036}
3758 4037
3759 c->paddr = pci_resource_start(pdev, i); /* addressing mode bits 4038static int __devinit cciss_find_cfg_addrs(struct pci_dev *pdev,
3760 * already removed 4039 void __iomem *vaddr, u32 *cfg_base_addr, u64 *cfg_base_addr_index,
3761 */ 4040 u64 *cfg_offset)
4041{
4042 *cfg_base_addr = readl(vaddr + SA5_CTCFG_OFFSET);
4043 *cfg_offset = readl(vaddr + SA5_CTMEM_OFFSET);
4044 *cfg_base_addr &= (u32) 0x0000ffff;
4045 *cfg_base_addr_index = find_PCI_BAR_index(pdev, *cfg_base_addr);
4046 if (*cfg_base_addr_index == -1) {
4047 dev_warn(&pdev->dev, "cannot find cfg_base_addr_index, "
4048 "*cfg_base_addr = 0x%08x\n", *cfg_base_addr);
4049 return -ENODEV;
4050 }
4051 return 0;
4052}
3762 4053
3763#ifdef CCISS_DEBUG 4054static int __devinit cciss_find_cfgtables(ctlr_info_t *h)
3764 printk("address 0 = %lx\n", c->paddr); 4055{
3765#endif /* CCISS_DEBUG */ 4056 u64 cfg_offset;
3766 c->vaddr = remap_pci_mem(c->paddr, 0x250); 4057 u32 cfg_base_addr;
4058 u64 cfg_base_addr_index;
4059 u32 trans_offset;
4060 int rc;
3767 4061
3768 /* Wait for the board to become ready. (PCI hotplug needs this.) 4062 rc = cciss_find_cfg_addrs(h->pdev, h->vaddr, &cfg_base_addr,
3769 * We poll for up to 120 secs, once per 100ms. */ 4063 &cfg_base_addr_index, &cfg_offset);
3770 for (i = 0; i < 1200; i++) { 4064 if (rc)
3771 scratchpad = readl(c->vaddr + SA5_SCRATCHPAD_OFFSET); 4065 return rc;
3772 if (scratchpad == CCISS_FIRMWARE_READY) 4066 h->cfgtable = remap_pci_mem(pci_resource_start(h->pdev,
3773 break; 4067 cfg_base_addr_index) + cfg_offset, sizeof(h->cfgtable));
3774 set_current_state(TASK_INTERRUPTIBLE); 4068 if (!h->cfgtable)
3775 schedule_timeout(msecs_to_jiffies(100)); /* wait 100ms */ 4069 return -ENOMEM;
3776 } 4070 /* Find performant mode table. */
3777 if (scratchpad != CCISS_FIRMWARE_READY) { 4071 trans_offset = readl(&h->cfgtable->TransMethodOffset);
3778 printk(KERN_WARNING "cciss: Board not ready. Timed out.\n"); 4072 h->transtable = remap_pci_mem(pci_resource_start(h->pdev,
3779 err = -ENODEV; 4073 cfg_base_addr_index)+cfg_offset+trans_offset,
3780 goto err_out_free_res; 4074 sizeof(*h->transtable));
3781 } 4075 if (!h->transtable)
4076 return -ENOMEM;
4077 return 0;
4078}
3782 4079
3783 /* get the address index number */ 4080static void __devinit cciss_get_max_perf_mode_cmds(struct ctlr_info *h)
3784 cfg_base_addr = readl(c->vaddr + SA5_CTCFG_OFFSET); 4081{
3785 cfg_base_addr &= (__u32) 0x0000ffff; 4082 h->max_commands = readl(&(h->cfgtable->MaxPerformantModeCommands));
3786#ifdef CCISS_DEBUG 4083 if (h->max_commands < 16) {
3787 printk("cfg base address = %x\n", cfg_base_addr); 4084 dev_warn(&h->pdev->dev, "Controller reports "
3788#endif /* CCISS_DEBUG */ 4085 "max supported commands of %d, an obvious lie. "
3789 cfg_base_addr_index = find_PCI_BAR_index(pdev, cfg_base_addr); 4086 "Using 16. Ensure that firmware is up to date.\n",
3790#ifdef CCISS_DEBUG 4087 h->max_commands);
3791 printk("cfg base address index = %llx\n", 4088 h->max_commands = 16;
3792 (unsigned long long)cfg_base_addr_index);
3793#endif /* CCISS_DEBUG */
3794 if (cfg_base_addr_index == -1) {
3795 printk(KERN_WARNING "cciss: Cannot find cfg_base_addr_index\n");
3796 err = -ENODEV;
3797 goto err_out_free_res;
3798 } 4089 }
4090}
3799 4091
3800 cfg_offset = readl(c->vaddr + SA5_CTMEM_OFFSET); 4092/* Interrogate the hardware for some limits:
3801#ifdef CCISS_DEBUG 4093 * max commands, max SG elements without chaining, and with chaining,
3802 printk("cfg offset = %llx\n", (unsigned long long)cfg_offset); 4094 * SG chain block size, etc.
3803#endif /* CCISS_DEBUG */ 4095 */
3804 c->cfgtable = remap_pci_mem(pci_resource_start(pdev, 4096static void __devinit cciss_find_board_params(ctlr_info_t *h)
3805 cfg_base_addr_index) + 4097{
3806 cfg_offset, sizeof(CfgTable_struct)); 4098 cciss_get_max_perf_mode_cmds(h);
3807 c->board_id = board_id; 4099 h->nr_cmds = h->max_commands - 4; /* Allow room for some ioctls */
3808 4100 h->maxsgentries = readl(&(h->cfgtable->MaxSGElements));
3809#ifdef CCISS_DEBUG
3810 print_cfg_table(c->cfgtable);
3811#endif /* CCISS_DEBUG */
3812
3813 /* Some controllers support Zero Memory Raid (ZMR).
3814 * When configured in ZMR mode the number of supported
3815 * commands drops to 64. So instead of just setting an
3816 * arbitrary value we make the driver a little smarter.
3817 * We read the config table to tell us how many commands
3818 * are supported on the controller then subtract 4 to
3819 * leave a little room for ioctl calls.
3820 */
3821 c->max_commands = readl(&(c->cfgtable->CmdsOutMax));
3822 c->maxsgentries = readl(&(c->cfgtable->MaxSGElements));
3823
3824 /* 4101 /*
3825 * Limit native command to 32 s/g elements to save dma'able memory. 4102 * Limit in-command s/g elements to 32 save dma'able memory.
3826 * Howvever spec says if 0, use 31 4103 * Howvever spec says if 0, use 31
3827 */ 4104 */
3828 4105 h->max_cmd_sgentries = 31;
3829 c->max_cmd_sgentries = 31; 4106 if (h->maxsgentries > 512) {
3830 if (c->maxsgentries > 512) { 4107 h->max_cmd_sgentries = 32;
3831 c->max_cmd_sgentries = 32; 4108 h->chainsize = h->maxsgentries - h->max_cmd_sgentries + 1;
3832 c->chainsize = c->maxsgentries - c->max_cmd_sgentries + 1; 4109 h->maxsgentries--; /* save one for chain pointer */
3833 c->maxsgentries -= 1; /* account for chain pointer */
3834 } else { 4110 } else {
3835 c->maxsgentries = 31; /* Default to traditional value */ 4111 h->maxsgentries = 31; /* default to traditional values */
3836 c->chainsize = 0; /* traditional */ 4112 h->chainsize = 0;
3837 } 4113 }
4114}
3838 4115
3839 c->product_name = products[prod_index].product_name; 4116static inline bool CISS_signature_present(ctlr_info_t *h)
3840 c->access = *(products[prod_index].access); 4117{
3841 c->nr_cmds = c->max_commands - 4; 4118 if ((readb(&h->cfgtable->Signature[0]) != 'C') ||
3842 if ((readb(&c->cfgtable->Signature[0]) != 'C') || 4119 (readb(&h->cfgtable->Signature[1]) != 'I') ||
3843 (readb(&c->cfgtable->Signature[1]) != 'I') || 4120 (readb(&h->cfgtable->Signature[2]) != 'S') ||
3844 (readb(&c->cfgtable->Signature[2]) != 'S') || 4121 (readb(&h->cfgtable->Signature[3]) != 'S')) {
3845 (readb(&c->cfgtable->Signature[3]) != 'S')) { 4122 dev_warn(&h->pdev->dev, "not a valid CISS config table\n");
3846 printk("Does not appear to be a valid CISS config table\n"); 4123 return false;
3847 err = -ENODEV;
3848 goto err_out_free_res;
3849 } 4124 }
4125 return true;
4126}
4127
4128/* Need to enable prefetch in the SCSI core for 6400 in x86 */
4129static inline void cciss_enable_scsi_prefetch(ctlr_info_t *h)
4130{
3850#ifdef CONFIG_X86 4131#ifdef CONFIG_X86
3851 { 4132 u32 prefetch;
3852 /* Need to enable prefetch in the SCSI core for 6400 in x86 */ 4133
3853 __u32 prefetch; 4134 prefetch = readl(&(h->cfgtable->SCSI_Prefetch));
3854 prefetch = readl(&(c->cfgtable->SCSI_Prefetch)); 4135 prefetch |= 0x100;
3855 prefetch |= 0x100; 4136 writel(prefetch, &(h->cfgtable->SCSI_Prefetch));
3856 writel(prefetch, &(c->cfgtable->SCSI_Prefetch));
3857 }
3858#endif 4137#endif
4138}
3859 4139
3860 /* Disabling DMA prefetch and refetch for the P600. 4140/* Disable DMA prefetch for the P600. Otherwise an ASIC bug may result
3861 * An ASIC bug may result in accesses to invalid memory addresses. 4141 * in a prefetch beyond physical memory.
3862 * We've disabled prefetch for some time now. Testing with XEN 4142 */
3863 * kernels revealed a bug in the refetch if dom0 resides on a P600. 4143static inline void cciss_p600_dma_prefetch_quirk(ctlr_info_t *h)
3864 */ 4144{
3865 if(board_id == 0x3225103C) { 4145 u32 dma_prefetch;
3866 __u32 dma_prefetch; 4146 __u32 dma_refetch;
3867 __u32 dma_refetch; 4147
3868 dma_prefetch = readl(c->vaddr + I2O_DMA1_CFG); 4148 if (h->board_id != 0x3225103C)
3869 dma_prefetch |= 0x8000; 4149 return;
3870 writel(dma_prefetch, c->vaddr + I2O_DMA1_CFG); 4150 dma_prefetch = readl(h->vaddr + I2O_DMA1_CFG);
3871 pci_read_config_dword(pdev, PCI_COMMAND_PARITY, &dma_refetch); 4151 dma_prefetch |= 0x8000;
3872 dma_refetch |= 0x1; 4152 writel(dma_prefetch, h->vaddr + I2O_DMA1_CFG);
3873 pci_write_config_dword(pdev, PCI_COMMAND_PARITY, dma_refetch); 4153 pci_read_config_dword(h->pdev, PCI_COMMAND_PARITY, &dma_refetch);
4154 dma_refetch |= 0x1;
4155 pci_write_config_dword(h->pdev, PCI_COMMAND_PARITY, dma_refetch);
4156}
4157
4158static int __devinit cciss_pci_init(ctlr_info_t *h)
4159{
4160 int prod_index, err;
4161
4162 prod_index = cciss_lookup_board_id(h->pdev, &h->board_id);
4163 if (prod_index < 0)
4164 return -ENODEV;
4165 h->product_name = products[prod_index].product_name;
4166 h->access = *(products[prod_index].access);
4167
4168 if (cciss_board_disabled(h)) {
4169 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
4170 return -ENODEV;
4171 }
4172 err = pci_enable_device(h->pdev);
4173 if (err) {
4174 dev_warn(&h->pdev->dev, "Unable to Enable PCI device\n");
4175 return err;
3874 } 4176 }
3875 4177
3876#ifdef CCISS_DEBUG 4178 err = pci_request_regions(h->pdev, "cciss");
3877 printk("Trying to put board into Simple mode\n"); 4179 if (err) {
3878#endif /* CCISS_DEBUG */ 4180 dev_warn(&h->pdev->dev,
3879 c->max_commands = readl(&(c->cfgtable->CmdsOutMax)); 4181 "Cannot obtain PCI resources, aborting\n");
3880 /* Update the field, and then ring the doorbell */ 4182 return err;
3881 writel(CFGTBL_Trans_Simple, &(c->cfgtable->HostWrite.TransportRequest)); 4183 }
3882 writel(CFGTBL_ChangeReq, c->vaddr + SA5_DOORBELL);
3883 4184
3884 /* under certain very rare conditions, this can take awhile. 4185 dev_dbg(&h->pdev->dev, "irq = %x\n", h->pdev->irq);
3885 * (e.g.: hot replace a failed 144GB drive in a RAID 5 set right 4186 dev_dbg(&h->pdev->dev, "board_id = %x\n", h->board_id);
3886 * as we enter this code.) */ 4187
3887 for (i = 0; i < MAX_CONFIG_WAIT; i++) { 4188/* If the kernel supports MSI/MSI-X we will try to enable that functionality,
3888 if (!(readl(c->vaddr + SA5_DOORBELL) & CFGTBL_ChangeReq)) 4189 * else we use the IO-APIC interrupt assigned to us by system ROM.
3889 break; 4190 */
3890 /* delay and try again */ 4191 cciss_interrupt_mode(h);
3891 set_current_state(TASK_INTERRUPTIBLE); 4192 err = cciss_pci_find_memory_BAR(h->pdev, &h->paddr);
3892 schedule_timeout(msecs_to_jiffies(1)); 4193 if (err)
4194 goto err_out_free_res;
4195 h->vaddr = remap_pci_mem(h->paddr, 0x250);
4196 if (!h->vaddr) {
4197 err = -ENOMEM;
4198 goto err_out_free_res;
3893 } 4199 }
4200 err = cciss_wait_for_board_ready(h);
4201 if (err)
4202 goto err_out_free_res;
4203 err = cciss_find_cfgtables(h);
4204 if (err)
4205 goto err_out_free_res;
4206 print_cfg_table(h);
4207 cciss_find_board_params(h);
3894 4208
3895#ifdef CCISS_DEBUG 4209 if (!CISS_signature_present(h)) {
3896 printk(KERN_DEBUG "I counter got to %d %x\n", i,
3897 readl(c->vaddr + SA5_DOORBELL));
3898#endif /* CCISS_DEBUG */
3899#ifdef CCISS_DEBUG
3900 print_cfg_table(c->cfgtable);
3901#endif /* CCISS_DEBUG */
3902
3903 if (!(readl(&(c->cfgtable->TransportActive)) & CFGTBL_Trans_Simple)) {
3904 printk(KERN_WARNING "cciss: unable to get board into"
3905 " simple mode\n");
3906 err = -ENODEV; 4210 err = -ENODEV;
3907 goto err_out_free_res; 4211 goto err_out_free_res;
3908 } 4212 }
4213 cciss_enable_scsi_prefetch(h);
4214 cciss_p600_dma_prefetch_quirk(h);
4215 cciss_put_controller_into_performant_mode(h);
3909 return 0; 4216 return 0;
3910 4217
3911err_out_free_res: 4218err_out_free_res:
@@ -3913,42 +4220,47 @@ err_out_free_res:
3913 * Deliberately omit pci_disable_device(): it does something nasty to 4220 * Deliberately omit pci_disable_device(): it does something nasty to
3914 * Smart Array controllers that pci_enable_device does not undo 4221 * Smart Array controllers that pci_enable_device does not undo
3915 */ 4222 */
3916 pci_release_regions(pdev); 4223 if (h->transtable)
4224 iounmap(h->transtable);
4225 if (h->cfgtable)
4226 iounmap(h->cfgtable);
4227 if (h->vaddr)
4228 iounmap(h->vaddr);
4229 pci_release_regions(h->pdev);
3917 return err; 4230 return err;
3918} 4231}
3919 4232
3920/* Function to find the first free pointer into our hba[] array 4233/* Function to find the first free pointer into our hba[] array
3921 * Returns -1 if no free entries are left. 4234 * Returns -1 if no free entries are left.
3922 */ 4235 */
3923static int alloc_cciss_hba(void) 4236static int alloc_cciss_hba(struct pci_dev *pdev)
3924{ 4237{
3925 int i; 4238 int i;
3926 4239
3927 for (i = 0; i < MAX_CTLR; i++) { 4240 for (i = 0; i < MAX_CTLR; i++) {
3928 if (!hba[i]) { 4241 if (!hba[i]) {
3929 ctlr_info_t *p; 4242 ctlr_info_t *h;
3930 4243
3931 p = kzalloc(sizeof(ctlr_info_t), GFP_KERNEL); 4244 h = kzalloc(sizeof(ctlr_info_t), GFP_KERNEL);
3932 if (!p) 4245 if (!h)
3933 goto Enomem; 4246 goto Enomem;
3934 hba[i] = p; 4247 hba[i] = h;
3935 return i; 4248 return i;
3936 } 4249 }
3937 } 4250 }
3938 printk(KERN_WARNING "cciss: This driver supports a maximum" 4251 dev_warn(&pdev->dev, "This driver supports a maximum"
3939 " of %d controllers.\n", MAX_CTLR); 4252 " of %d controllers.\n", MAX_CTLR);
3940 return -1; 4253 return -1;
3941Enomem: 4254Enomem:
3942 printk(KERN_ERR "cciss: out of memory.\n"); 4255 dev_warn(&pdev->dev, "out of memory.\n");
3943 return -1; 4256 return -1;
3944} 4257}
3945 4258
3946static void free_hba(int n) 4259static void free_hba(ctlr_info_t *h)
3947{ 4260{
3948 ctlr_info_t *h = hba[n];
3949 int i; 4261 int i;
3950 4262
3951 hba[n] = NULL; 4263 hba[h->ctlr] = NULL;
3952 for (i = 0; i < h->highest_lun + 1; i++) 4264 for (i = 0; i < h->highest_lun + 1; i++)
3953 if (h->gendisk[i] != NULL) 4265 if (h->gendisk[i] != NULL)
3954 put_disk(h->gendisk[i]); 4266 put_disk(h->gendisk[i]);
@@ -4028,7 +4340,8 @@ static __devinit int cciss_message(struct pci_dev *pdev, unsigned char opcode, u
4028 /* we leak the DMA buffer here ... no choice since the controller could 4340 /* we leak the DMA buffer here ... no choice since the controller could
4029 still complete the command. */ 4341 still complete the command. */
4030 if (i == 10) { 4342 if (i == 10) {
4031 printk(KERN_ERR "cciss: controller message %02x:%02x timed out\n", 4343 dev_err(&pdev->dev,
4344 "controller message %02x:%02x timed out\n",
4032 opcode, type); 4345 opcode, type);
4033 return -ETIMEDOUT; 4346 return -ETIMEDOUT;
4034 } 4347 }
@@ -4036,12 +4349,12 @@ static __devinit int cciss_message(struct pci_dev *pdev, unsigned char opcode, u
4036 pci_free_consistent(pdev, cmd_sz, cmd, paddr64); 4349 pci_free_consistent(pdev, cmd_sz, cmd, paddr64);
4037 4350
4038 if (tag & 2) { 4351 if (tag & 2) {
4039 printk(KERN_ERR "cciss: controller message %02x:%02x failed\n", 4352 dev_err(&pdev->dev, "controller message %02x:%02x failed\n",
4040 opcode, type); 4353 opcode, type);
4041 return -EIO; 4354 return -EIO;
4042 } 4355 }
4043 4356
4044 printk(KERN_INFO "cciss: controller message %02x:%02x succeeded\n", 4357 dev_info(&pdev->dev, "controller message %02x:%02x succeeded\n",
4045 opcode, type); 4358 opcode, type);
4046 return 0; 4359 return 0;
4047} 4360}
@@ -4062,7 +4375,7 @@ static __devinit int cciss_reset_msi(struct pci_dev *pdev)
4062 if (pos) { 4375 if (pos) {
4063 pci_read_config_word(pdev, msi_control_reg(pos), &control); 4376 pci_read_config_word(pdev, msi_control_reg(pos), &control);
4064 if (control & PCI_MSI_FLAGS_ENABLE) { 4377 if (control & PCI_MSI_FLAGS_ENABLE) {
4065 printk(KERN_INFO "cciss: resetting MSI\n"); 4378 dev_info(&pdev->dev, "resetting MSI\n");
4066 pci_write_config_word(pdev, msi_control_reg(pos), control & ~PCI_MSI_FLAGS_ENABLE); 4379 pci_write_config_word(pdev, msi_control_reg(pos), control & ~PCI_MSI_FLAGS_ENABLE);
4067 } 4380 }
4068 } 4381 }
@@ -4071,7 +4384,7 @@ static __devinit int cciss_reset_msi(struct pci_dev *pdev)
4071 if (pos) { 4384 if (pos) {
4072 pci_read_config_word(pdev, msi_control_reg(pos), &control); 4385 pci_read_config_word(pdev, msi_control_reg(pos), &control);
4073 if (control & PCI_MSIX_FLAGS_ENABLE) { 4386 if (control & PCI_MSIX_FLAGS_ENABLE) {
4074 printk(KERN_INFO "cciss: resetting MSI-X\n"); 4387 dev_info(&pdev->dev, "resetting MSI-X\n");
4075 pci_write_config_word(pdev, msi_control_reg(pos), control & ~PCI_MSIX_FLAGS_ENABLE); 4388 pci_write_config_word(pdev, msi_control_reg(pos), control & ~PCI_MSIX_FLAGS_ENABLE);
4076 } 4389 }
4077 } 4390 }
@@ -4079,68 +4392,144 @@ static __devinit int cciss_reset_msi(struct pci_dev *pdev)
4079 return 0; 4392 return 0;
4080} 4393}
4081 4394
4082/* This does a hard reset of the controller using PCI power management 4395static int cciss_controller_hard_reset(struct pci_dev *pdev,
4083 * states. */ 4396 void * __iomem vaddr, bool use_doorbell)
4084static __devinit int cciss_hard_reset_controller(struct pci_dev *pdev)
4085{ 4397{
4086 u16 pmcsr, saved_config_space[32]; 4398 u16 pmcsr;
4087 int i, pos; 4399 int pos;
4088 4400
4089 printk(KERN_INFO "cciss: using PCI PM to reset controller\n"); 4401 if (use_doorbell) {
4402 /* For everything after the P600, the PCI power state method
4403 * of resetting the controller doesn't work, so we have this
4404 * other way using the doorbell register.
4405 */
4406 dev_info(&pdev->dev, "using doorbell to reset controller\n");
4407 writel(DOORBELL_CTLR_RESET, vaddr + SA5_DOORBELL);
4408 msleep(1000);
4409 } else { /* Try to do it the PCI power state way */
4410
4411 /* Quoting from the Open CISS Specification: "The Power
4412 * Management Control/Status Register (CSR) controls the power
4413 * state of the device. The normal operating state is D0,
4414 * CSR=00h. The software off state is D3, CSR=03h. To reset
4415 * the controller, place the interface device in D3 then to D0,
4416 * this causes a secondary PCI reset which will reset the
4417 * controller." */
4418
4419 pos = pci_find_capability(pdev, PCI_CAP_ID_PM);
4420 if (pos == 0) {
4421 dev_err(&pdev->dev,
4422 "cciss_controller_hard_reset: "
4423 "PCI PM not supported\n");
4424 return -ENODEV;
4425 }
4426 dev_info(&pdev->dev, "using PCI PM to reset controller\n");
4427 /* enter the D3hot power management state */
4428 pci_read_config_word(pdev, pos + PCI_PM_CTRL, &pmcsr);
4429 pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
4430 pmcsr |= PCI_D3hot;
4431 pci_write_config_word(pdev, pos + PCI_PM_CTRL, pmcsr);
4090 4432
4091 /* This is very nearly the same thing as 4433 msleep(500);
4092 4434
4093 pci_save_state(pci_dev); 4435 /* enter the D0 power management state */
4094 pci_set_power_state(pci_dev, PCI_D3hot); 4436 pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
4095 pci_set_power_state(pci_dev, PCI_D0); 4437 pmcsr |= PCI_D0;
4096 pci_restore_state(pci_dev); 4438 pci_write_config_word(pdev, pos + PCI_PM_CTRL, pmcsr);
4097 4439
4098 but we can't use these nice canned kernel routines on 4440 msleep(500);
4099 kexec, because they also check the MSI/MSI-X state in PCI 4441 }
4100 configuration space and do the wrong thing when it is 4442 return 0;
4101 set/cleared. Also, the pci_save/restore_state functions 4443}
4102 violate the ordering requirements for restoring the
4103 configuration space from the CCISS document (see the
4104 comment below). So we roll our own .... */
4105 4444
4106 for (i = 0; i < 32; i++) 4445/* This does a hard reset of the controller using PCI power management
4107 pci_read_config_word(pdev, 2*i, &saved_config_space[i]); 4446 * states or using the doorbell register. */
4447static __devinit int cciss_kdump_hard_reset_controller(struct pci_dev *pdev)
4448{
4449 u16 saved_config_space[32];
4450 u64 cfg_offset;
4451 u32 cfg_base_addr;
4452 u64 cfg_base_addr_index;
4453 void __iomem *vaddr;
4454 unsigned long paddr;
4455 u32 misc_fw_support, active_transport;
4456 int rc, i;
4457 CfgTable_struct __iomem *cfgtable;
4458 bool use_doorbell;
4459 u32 board_id;
4460
4461 /* For controllers as old a the p600, this is very nearly
4462 * the same thing as
4463 *
4464 * pci_save_state(pci_dev);
4465 * pci_set_power_state(pci_dev, PCI_D3hot);
4466 * pci_set_power_state(pci_dev, PCI_D0);
4467 * pci_restore_state(pci_dev);
4468 *
4469 * but we can't use these nice canned kernel routines on
4470 * kexec, because they also check the MSI/MSI-X state in PCI
4471 * configuration space and do the wrong thing when it is
4472 * set/cleared. Also, the pci_save/restore_state functions
4473 * violate the ordering requirements for restoring the
4474 * configuration space from the CCISS document (see the
4475 * comment below). So we roll our own ....
4476 *
4477 * For controllers newer than the P600, the pci power state
4478 * method of resetting doesn't work so we have another way
4479 * using the doorbell register.
4480 */
4108 4481
4109 pos = pci_find_capability(pdev, PCI_CAP_ID_PM); 4482 /* Exclude 640x boards. These are two pci devices in one slot
4110 if (pos == 0) { 4483 * which share a battery backed cache module. One controls the
4111 printk(KERN_ERR "cciss_reset_controller: PCI PM not supported\n"); 4484 * cache, the other accesses the cache through the one that controls
4485 * it. If we reset the one controlling the cache, the other will
4486 * likely not be happy. Just forbid resetting this conjoined mess.
4487 */
4488 cciss_lookup_board_id(pdev, &board_id);
4489 if (board_id == 0x409C0E11 || board_id == 0x409D0E11) {
4490 dev_warn(&pdev->dev, "Cannot reset Smart Array 640x "
4491 "due to shared cache module.");
4112 return -ENODEV; 4492 return -ENODEV;
4113 } 4493 }
4114 4494
4115 /* Quoting from the Open CISS Specification: "The Power 4495 for (i = 0; i < 32; i++)
4116 * Management Control/Status Register (CSR) controls the power 4496 pci_read_config_word(pdev, 2*i, &saved_config_space[i]);
4117 * state of the device. The normal operating state is D0,
4118 * CSR=00h. The software off state is D3, CSR=03h. To reset
4119 * the controller, place the interface device in D3 then to
4120 * D0, this causes a secondary PCI reset which will reset the
4121 * controller." */
4122 4497
4123 /* enter the D3hot power management state */ 4498 /* find the first memory BAR, so we can find the cfg table */
4124 pci_read_config_word(pdev, pos + PCI_PM_CTRL, &pmcsr); 4499 rc = cciss_pci_find_memory_BAR(pdev, &paddr);
4125 pmcsr &= ~PCI_PM_CTRL_STATE_MASK; 4500 if (rc)
4126 pmcsr |= PCI_D3hot; 4501 return rc;
4127 pci_write_config_word(pdev, pos + PCI_PM_CTRL, pmcsr); 4502 vaddr = remap_pci_mem(paddr, 0x250);
4503 if (!vaddr)
4504 return -ENOMEM;
4128 4505
4129 schedule_timeout_uninterruptible(HZ >> 1); 4506 /* find cfgtable in order to check if reset via doorbell is supported */
4507 rc = cciss_find_cfg_addrs(pdev, vaddr, &cfg_base_addr,
4508 &cfg_base_addr_index, &cfg_offset);
4509 if (rc)
4510 goto unmap_vaddr;
4511 cfgtable = remap_pci_mem(pci_resource_start(pdev,
4512 cfg_base_addr_index) + cfg_offset, sizeof(*cfgtable));
4513 if (!cfgtable) {
4514 rc = -ENOMEM;
4515 goto unmap_vaddr;
4516 }
4130 4517
4131 /* enter the D0 power management state */ 4518 /* If reset via doorbell register is supported, use that. */
4132 pmcsr &= ~PCI_PM_CTRL_STATE_MASK; 4519 misc_fw_support = readl(&cfgtable->misc_fw_support);
4133 pmcsr |= PCI_D0; 4520 use_doorbell = misc_fw_support & MISC_FW_DOORBELL_RESET;
4134 pci_write_config_word(pdev, pos + PCI_PM_CTRL, pmcsr);
4135 4521
4136 schedule_timeout_uninterruptible(HZ >> 1); 4522 rc = cciss_controller_hard_reset(pdev, vaddr, use_doorbell);
4523 if (rc)
4524 goto unmap_cfgtable;
4137 4525
4138 /* Restore the PCI configuration space. The Open CISS 4526 /* Restore the PCI configuration space. The Open CISS
4139 * Specification says, "Restore the PCI Configuration 4527 * Specification says, "Restore the PCI Configuration
4140 * Registers, offsets 00h through 60h. It is important to 4528 * Registers, offsets 00h through 60h. It is important to
4141 * restore the command register, 16-bits at offset 04h, 4529 * restore the command register, 16-bits at offset 04h,
4142 * last. Do not restore the configuration status register, 4530 * last. Do not restore the configuration status register,
4143 * 16-bits at offset 06h." Note that the offset is 2*i. */ 4531 * 16-bits at offset 06h." Note that the offset is 2*i.
4532 */
4144 for (i = 0; i < 32; i++) { 4533 for (i = 0; i < 32; i++) {
4145 if (i == 2 || i == 3) 4534 if (i == 2 || i == 3)
4146 continue; 4535 continue;
@@ -4149,6 +4538,63 @@ static __devinit int cciss_hard_reset_controller(struct pci_dev *pdev)
4149 wmb(); 4538 wmb();
4150 pci_write_config_word(pdev, 4, saved_config_space[2]); 4539 pci_write_config_word(pdev, 4, saved_config_space[2]);
4151 4540
4541 /* Some devices (notably the HP Smart Array 5i Controller)
4542 need a little pause here */
4543 msleep(CCISS_POST_RESET_PAUSE_MSECS);
4544
4545 /* Controller should be in simple mode at this point. If it's not,
4546 * It means we're on one of those controllers which doesn't support
4547 * the doorbell reset method and on which the PCI power management reset
4548 * method doesn't work (P800, for example.)
4549 * In those cases, don't try to proceed, as it generally doesn't work.
4550 */
4551 active_transport = readl(&cfgtable->TransportActive);
4552 if (active_transport & PERFORMANT_MODE) {
4553 dev_warn(&pdev->dev, "Unable to successfully reset controller,"
4554 " Ignoring controller.\n");
4555 rc = -ENODEV;
4556 }
4557
4558unmap_cfgtable:
4559 iounmap(cfgtable);
4560
4561unmap_vaddr:
4562 iounmap(vaddr);
4563 return rc;
4564}
4565
4566static __devinit int cciss_init_reset_devices(struct pci_dev *pdev)
4567{
4568 int rc, i;
4569
4570 if (!reset_devices)
4571 return 0;
4572
4573 /* Reset the controller with a PCI power-cycle or via doorbell */
4574 rc = cciss_kdump_hard_reset_controller(pdev);
4575
4576 /* -ENOTSUPP here means we cannot reset the controller
4577 * but it's already (and still) up and running in
4578 * "performant mode". Or, it might be 640x, which can't reset
4579 * due to concerns about shared bbwc between 6402/6404 pair.
4580 */
4581 if (rc == -ENOTSUPP)
4582 return 0; /* just try to do the kdump anyhow. */
4583 if (rc)
4584 return -ENODEV;
4585 if (cciss_reset_msi(pdev))
4586 return -ENODEV;
4587
4588 /* Now try to get the controller to respond to a no-op */
4589 for (i = 0; i < CCISS_POST_RESET_NOOP_RETRIES; i++) {
4590 if (cciss_noop(pdev) == 0)
4591 break;
4592 else
4593 dev_warn(&pdev->dev, "no-op failed%s\n",
4594 (i < CCISS_POST_RESET_NOOP_RETRIES - 1 ?
4595 "; re-trying" : ""));
4596 msleep(CCISS_POST_RESET_NOOP_INTERVAL_MSECS);
4597 }
4152 return 0; 4598 return 0;
4153} 4599}
4154 4600
@@ -4166,46 +4612,31 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
4166 int rc; 4612 int rc;
4167 int dac, return_code; 4613 int dac, return_code;
4168 InquiryData_struct *inq_buff; 4614 InquiryData_struct *inq_buff;
4615 ctlr_info_t *h;
4169 4616
4170 if (reset_devices) { 4617 rc = cciss_init_reset_devices(pdev);
4171 /* Reset the controller with a PCI power-cycle */ 4618 if (rc)
4172 if (cciss_hard_reset_controller(pdev) || cciss_reset_msi(pdev)) 4619 return rc;
4173 return -ENODEV; 4620 i = alloc_cciss_hba(pdev);
4174
4175 /* Now try to get the controller to respond to a no-op. Some
4176 devices (notably the HP Smart Array 5i Controller) need
4177 up to 30 seconds to respond. */
4178 for (i=0; i<30; i++) {
4179 if (cciss_noop(pdev) == 0)
4180 break;
4181
4182 schedule_timeout_uninterruptible(HZ);
4183 }
4184 if (i == 30) {
4185 printk(KERN_ERR "cciss: controller seems dead\n");
4186 return -EBUSY;
4187 }
4188 }
4189
4190 i = alloc_cciss_hba();
4191 if (i < 0) 4621 if (i < 0)
4192 return -1; 4622 return -1;
4193 4623
4194 hba[i]->busy_initializing = 1; 4624 h = hba[i];
4195 INIT_HLIST_HEAD(&hba[i]->cmpQ); 4625 h->pdev = pdev;
4196 INIT_HLIST_HEAD(&hba[i]->reqQ); 4626 h->busy_initializing = 1;
4197 mutex_init(&hba[i]->busy_shutting_down); 4627 INIT_HLIST_HEAD(&h->cmpQ);
4628 INIT_HLIST_HEAD(&h->reqQ);
4629 mutex_init(&h->busy_shutting_down);
4198 4630
4199 if (cciss_pci_init(hba[i], pdev) != 0) 4631 if (cciss_pci_init(h) != 0)
4200 goto clean_no_release_regions; 4632 goto clean_no_release_regions;
4201 4633
4202 sprintf(hba[i]->devname, "cciss%d", i); 4634 sprintf(h->devname, "cciss%d", i);
4203 hba[i]->ctlr = i; 4635 h->ctlr = i;
4204 hba[i]->pdev = pdev;
4205 4636
4206 init_completion(&hba[i]->scan_wait); 4637 init_completion(&h->scan_wait);
4207 4638
4208 if (cciss_create_hba_sysfs_entry(hba[i])) 4639 if (cciss_create_hba_sysfs_entry(h))
4209 goto clean0; 4640 goto clean0;
4210 4641
4211 /* configure PCI DMA stuff */ 4642 /* configure PCI DMA stuff */
@@ -4214,7 +4645,7 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
4214 else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) 4645 else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32)))
4215 dac = 0; 4646 dac = 0;
4216 else { 4647 else {
4217 printk(KERN_ERR "cciss: no suitable DMA available\n"); 4648 dev_err(&h->pdev->dev, "no suitable DMA available\n");
4218 goto clean1; 4649 goto clean1;
4219 } 4650 }
4220 4651
@@ -4224,151 +4655,161 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
4224 * 8 controller support. 4655 * 8 controller support.
4225 */ 4656 */
4226 if (i < MAX_CTLR_ORIG) 4657 if (i < MAX_CTLR_ORIG)
4227 hba[i]->major = COMPAQ_CISS_MAJOR + i; 4658 h->major = COMPAQ_CISS_MAJOR + i;
4228 rc = register_blkdev(hba[i]->major, hba[i]->devname); 4659 rc = register_blkdev(h->major, h->devname);
4229 if (rc == -EBUSY || rc == -EINVAL) { 4660 if (rc == -EBUSY || rc == -EINVAL) {
4230 printk(KERN_ERR 4661 dev_err(&h->pdev->dev,
4231 "cciss: Unable to get major number %d for %s " 4662 "Unable to get major number %d for %s "
4232 "on hba %d\n", hba[i]->major, hba[i]->devname, i); 4663 "on hba %d\n", h->major, h->devname, i);
4233 goto clean1; 4664 goto clean1;
4234 } else { 4665 } else {
4235 if (i >= MAX_CTLR_ORIG) 4666 if (i >= MAX_CTLR_ORIG)
4236 hba[i]->major = rc; 4667 h->major = rc;
4237 } 4668 }
4238 4669
4239 /* make sure the board interrupts are off */ 4670 /* make sure the board interrupts are off */
4240 hba[i]->access.set_intr_mask(hba[i], CCISS_INTR_OFF); 4671 h->access.set_intr_mask(h, CCISS_INTR_OFF);
4241 if (request_irq(hba[i]->intr[SIMPLE_MODE_INT], do_cciss_intr, 4672 if (h->msi_vector || h->msix_vector) {
4242 IRQF_DISABLED | IRQF_SHARED, hba[i]->devname, hba[i])) { 4673 if (request_irq(h->intr[PERF_MODE_INT],
4243 printk(KERN_ERR "cciss: Unable to get irq %d for %s\n", 4674 do_cciss_msix_intr,
4244 hba[i]->intr[SIMPLE_MODE_INT], hba[i]->devname); 4675 IRQF_DISABLED, h->devname, h)) {
4245 goto clean2; 4676 dev_err(&h->pdev->dev, "Unable to get irq %d for %s\n",
4677 h->intr[PERF_MODE_INT], h->devname);
4678 goto clean2;
4679 }
4680 } else {
4681 if (request_irq(h->intr[PERF_MODE_INT], do_cciss_intx,
4682 IRQF_DISABLED, h->devname, h)) {
4683 dev_err(&h->pdev->dev, "Unable to get irq %d for %s\n",
4684 h->intr[PERF_MODE_INT], h->devname);
4685 goto clean2;
4686 }
4246 } 4687 }
4247 4688
4248 printk(KERN_INFO "%s: <0x%x> at PCI %s IRQ %d%s using DAC\n", 4689 dev_info(&h->pdev->dev, "%s: <0x%x> at PCI %s IRQ %d%s using DAC\n",
4249 hba[i]->devname, pdev->device, pci_name(pdev), 4690 h->devname, pdev->device, pci_name(pdev),
4250 hba[i]->intr[SIMPLE_MODE_INT], dac ? "" : " not"); 4691 h->intr[PERF_MODE_INT], dac ? "" : " not");
4251 4692
4252 hba[i]->cmd_pool_bits = 4693 h->cmd_pool_bits =
4253 kmalloc(DIV_ROUND_UP(hba[i]->nr_cmds, BITS_PER_LONG) 4694 kmalloc(DIV_ROUND_UP(h->nr_cmds, BITS_PER_LONG)
4254 * sizeof(unsigned long), GFP_KERNEL); 4695 * sizeof(unsigned long), GFP_KERNEL);
4255 hba[i]->cmd_pool = (CommandList_struct *) 4696 h->cmd_pool = (CommandList_struct *)
4256 pci_alloc_consistent(hba[i]->pdev, 4697 pci_alloc_consistent(h->pdev,
4257 hba[i]->nr_cmds * sizeof(CommandList_struct), 4698 h->nr_cmds * sizeof(CommandList_struct),
4258 &(hba[i]->cmd_pool_dhandle)); 4699 &(h->cmd_pool_dhandle));
4259 hba[i]->errinfo_pool = (ErrorInfo_struct *) 4700 h->errinfo_pool = (ErrorInfo_struct *)
4260 pci_alloc_consistent(hba[i]->pdev, 4701 pci_alloc_consistent(h->pdev,
4261 hba[i]->nr_cmds * sizeof(ErrorInfo_struct), 4702 h->nr_cmds * sizeof(ErrorInfo_struct),
4262 &(hba[i]->errinfo_pool_dhandle)); 4703 &(h->errinfo_pool_dhandle));
4263 if ((hba[i]->cmd_pool_bits == NULL) 4704 if ((h->cmd_pool_bits == NULL)
4264 || (hba[i]->cmd_pool == NULL) 4705 || (h->cmd_pool == NULL)
4265 || (hba[i]->errinfo_pool == NULL)) { 4706 || (h->errinfo_pool == NULL)) {
4266 printk(KERN_ERR "cciss: out of memory"); 4707 dev_err(&h->pdev->dev, "out of memory");
4267 goto clean4; 4708 goto clean4;
4268 } 4709 }
4269 4710
4270 /* Need space for temp scatter list */ 4711 /* Need space for temp scatter list */
4271 hba[i]->scatter_list = kmalloc(hba[i]->max_commands * 4712 h->scatter_list = kmalloc(h->max_commands *
4272 sizeof(struct scatterlist *), 4713 sizeof(struct scatterlist *),
4273 GFP_KERNEL); 4714 GFP_KERNEL);
4274 for (k = 0; k < hba[i]->nr_cmds; k++) { 4715 for (k = 0; k < h->nr_cmds; k++) {
4275 hba[i]->scatter_list[k] = kmalloc(sizeof(struct scatterlist) * 4716 h->scatter_list[k] = kmalloc(sizeof(struct scatterlist) *
4276 hba[i]->maxsgentries, 4717 h->maxsgentries,
4277 GFP_KERNEL); 4718 GFP_KERNEL);
4278 if (hba[i]->scatter_list[k] == NULL) { 4719 if (h->scatter_list[k] == NULL) {
4279 printk(KERN_ERR "cciss%d: could not allocate " 4720 dev_err(&h->pdev->dev,
4280 "s/g lists\n", i); 4721 "could not allocate s/g lists\n");
4281 goto clean4; 4722 goto clean4;
4282 } 4723 }
4283 } 4724 }
4284 hba[i]->cmd_sg_list = cciss_allocate_sg_chain_blocks(hba[i], 4725 h->cmd_sg_list = cciss_allocate_sg_chain_blocks(h,
4285 hba[i]->chainsize, hba[i]->nr_cmds); 4726 h->chainsize, h->nr_cmds);
4286 if (!hba[i]->cmd_sg_list && hba[i]->chainsize > 0) 4727 if (!h->cmd_sg_list && h->chainsize > 0)
4287 goto clean4; 4728 goto clean4;
4288 4729
4289 spin_lock_init(&hba[i]->lock); 4730 spin_lock_init(&h->lock);
4290 4731
4291 /* Initialize the pdev driver private data. 4732 /* Initialize the pdev driver private data.
4292 have it point to hba[i]. */ 4733 have it point to h. */
4293 pci_set_drvdata(pdev, hba[i]); 4734 pci_set_drvdata(pdev, h);
4294 /* command and error info recs zeroed out before 4735 /* command and error info recs zeroed out before
4295 they are used */ 4736 they are used */
4296 memset(hba[i]->cmd_pool_bits, 0, 4737 memset(h->cmd_pool_bits, 0,
4297 DIV_ROUND_UP(hba[i]->nr_cmds, BITS_PER_LONG) 4738 DIV_ROUND_UP(h->nr_cmds, BITS_PER_LONG)
4298 * sizeof(unsigned long)); 4739 * sizeof(unsigned long));
4299 4740
4300 hba[i]->num_luns = 0; 4741 h->num_luns = 0;
4301 hba[i]->highest_lun = -1; 4742 h->highest_lun = -1;
4302 for (j = 0; j < CISS_MAX_LUN; j++) { 4743 for (j = 0; j < CISS_MAX_LUN; j++) {
4303 hba[i]->drv[j] = NULL; 4744 h->drv[j] = NULL;
4304 hba[i]->gendisk[j] = NULL; 4745 h->gendisk[j] = NULL;
4305 } 4746 }
4306 4747
4307 cciss_scsi_setup(i); 4748 cciss_scsi_setup(h);
4308 4749
4309 /* Turn the interrupts on so we can service requests */ 4750 /* Turn the interrupts on so we can service requests */
4310 hba[i]->access.set_intr_mask(hba[i], CCISS_INTR_ON); 4751 h->access.set_intr_mask(h, CCISS_INTR_ON);
4311 4752
4312 /* Get the firmware version */ 4753 /* Get the firmware version */
4313 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL); 4754 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
4314 if (inq_buff == NULL) { 4755 if (inq_buff == NULL) {
4315 printk(KERN_ERR "cciss: out of memory\n"); 4756 dev_err(&h->pdev->dev, "out of memory\n");
4316 goto clean4; 4757 goto clean4;
4317 } 4758 }
4318 4759
4319 return_code = sendcmd_withirq(CISS_INQUIRY, i, inq_buff, 4760 return_code = sendcmd_withirq(h, CISS_INQUIRY, inq_buff,
4320 sizeof(InquiryData_struct), 0, CTLR_LUNID, TYPE_CMD); 4761 sizeof(InquiryData_struct), 0, CTLR_LUNID, TYPE_CMD);
4321 if (return_code == IO_OK) { 4762 if (return_code == IO_OK) {
4322 hba[i]->firm_ver[0] = inq_buff->data_byte[32]; 4763 h->firm_ver[0] = inq_buff->data_byte[32];
4323 hba[i]->firm_ver[1] = inq_buff->data_byte[33]; 4764 h->firm_ver[1] = inq_buff->data_byte[33];
4324 hba[i]->firm_ver[2] = inq_buff->data_byte[34]; 4765 h->firm_ver[2] = inq_buff->data_byte[34];
4325 hba[i]->firm_ver[3] = inq_buff->data_byte[35]; 4766 h->firm_ver[3] = inq_buff->data_byte[35];
4326 } else { /* send command failed */ 4767 } else { /* send command failed */
4327 printk(KERN_WARNING "cciss: unable to determine firmware" 4768 dev_warn(&h->pdev->dev, "unable to determine firmware"
4328 " version of controller\n"); 4769 " version of controller\n");
4329 } 4770 }
4330 kfree(inq_buff); 4771 kfree(inq_buff);
4331 4772
4332 cciss_procinit(i); 4773 cciss_procinit(h);
4333 4774
4334 hba[i]->cciss_max_sectors = 8192; 4775 h->cciss_max_sectors = 8192;
4335 4776
4336 rebuild_lun_table(hba[i], 1, 0); 4777 rebuild_lun_table(h, 1, 0);
4337 hba[i]->busy_initializing = 0; 4778 h->busy_initializing = 0;
4338 return 1; 4779 return 1;
4339 4780
4340clean4: 4781clean4:
4341 kfree(hba[i]->cmd_pool_bits); 4782 kfree(h->cmd_pool_bits);
4342 /* Free up sg elements */ 4783 /* Free up sg elements */
4343 for (k = 0; k < hba[i]->nr_cmds; k++) 4784 for (k = 0; k < h->nr_cmds; k++)
4344 kfree(hba[i]->scatter_list[k]); 4785 kfree(h->scatter_list[k]);
4345 kfree(hba[i]->scatter_list); 4786 kfree(h->scatter_list);
4346 cciss_free_sg_chain_blocks(hba[i]->cmd_sg_list, hba[i]->nr_cmds); 4787 cciss_free_sg_chain_blocks(h->cmd_sg_list, h->nr_cmds);
4347 if (hba[i]->cmd_pool) 4788 if (h->cmd_pool)
4348 pci_free_consistent(hba[i]->pdev, 4789 pci_free_consistent(h->pdev,
4349 hba[i]->nr_cmds * sizeof(CommandList_struct), 4790 h->nr_cmds * sizeof(CommandList_struct),
4350 hba[i]->cmd_pool, hba[i]->cmd_pool_dhandle); 4791 h->cmd_pool, h->cmd_pool_dhandle);
4351 if (hba[i]->errinfo_pool) 4792 if (h->errinfo_pool)
4352 pci_free_consistent(hba[i]->pdev, 4793 pci_free_consistent(h->pdev,
4353 hba[i]->nr_cmds * sizeof(ErrorInfo_struct), 4794 h->nr_cmds * sizeof(ErrorInfo_struct),
4354 hba[i]->errinfo_pool, 4795 h->errinfo_pool,
4355 hba[i]->errinfo_pool_dhandle); 4796 h->errinfo_pool_dhandle);
4356 free_irq(hba[i]->intr[SIMPLE_MODE_INT], hba[i]); 4797 free_irq(h->intr[PERF_MODE_INT], h);
4357clean2: 4798clean2:
4358 unregister_blkdev(hba[i]->major, hba[i]->devname); 4799 unregister_blkdev(h->major, h->devname);
4359clean1: 4800clean1:
4360 cciss_destroy_hba_sysfs_entry(hba[i]); 4801 cciss_destroy_hba_sysfs_entry(h);
4361clean0: 4802clean0:
4362 pci_release_regions(pdev); 4803 pci_release_regions(pdev);
4363clean_no_release_regions: 4804clean_no_release_regions:
4364 hba[i]->busy_initializing = 0; 4805 h->busy_initializing = 0;
4365 4806
4366 /* 4807 /*
4367 * Deliberately omit pci_disable_device(): it does something nasty to 4808 * Deliberately omit pci_disable_device(): it does something nasty to
4368 * Smart Array controllers that pci_enable_device does not undo 4809 * Smart Array controllers that pci_enable_device does not undo
4369 */ 4810 */
4370 pci_set_drvdata(pdev, NULL); 4811 pci_set_drvdata(pdev, NULL);
4371 free_hba(i); 4812 free_hba(h);
4372 return -1; 4813 return -1;
4373} 4814}
4374 4815
@@ -4381,55 +4822,51 @@ static void cciss_shutdown(struct pci_dev *pdev)
4381 h = pci_get_drvdata(pdev); 4822 h = pci_get_drvdata(pdev);
4382 flush_buf = kzalloc(4, GFP_KERNEL); 4823 flush_buf = kzalloc(4, GFP_KERNEL);
4383 if (!flush_buf) { 4824 if (!flush_buf) {
4384 printk(KERN_WARNING 4825 dev_warn(&h->pdev->dev, "cache not flushed, out of memory.\n");
4385 "cciss:%d cache not flushed, out of memory.\n",
4386 h->ctlr);
4387 return; 4826 return;
4388 } 4827 }
4389 /* write all data in the battery backed cache to disk */ 4828 /* write all data in the battery backed cache to disk */
4390 memset(flush_buf, 0, 4); 4829 memset(flush_buf, 0, 4);
4391 return_code = sendcmd_withirq(CCISS_CACHE_FLUSH, h->ctlr, flush_buf, 4830 return_code = sendcmd_withirq(h, CCISS_CACHE_FLUSH, flush_buf,
4392 4, 0, CTLR_LUNID, TYPE_CMD); 4831 4, 0, CTLR_LUNID, TYPE_CMD);
4393 kfree(flush_buf); 4832 kfree(flush_buf);
4394 if (return_code != IO_OK) 4833 if (return_code != IO_OK)
4395 printk(KERN_WARNING "cciss%d: Error flushing cache\n", 4834 dev_warn(&h->pdev->dev, "Error flushing cache\n");
4396 h->ctlr);
4397 h->access.set_intr_mask(h, CCISS_INTR_OFF); 4835 h->access.set_intr_mask(h, CCISS_INTR_OFF);
4398 free_irq(h->intr[2], h); 4836 free_irq(h->intr[PERF_MODE_INT], h);
4399} 4837}
4400 4838
4401static void __devexit cciss_remove_one(struct pci_dev *pdev) 4839static void __devexit cciss_remove_one(struct pci_dev *pdev)
4402{ 4840{
4403 ctlr_info_t *tmp_ptr; 4841 ctlr_info_t *h;
4404 int i, j; 4842 int i, j;
4405 4843
4406 if (pci_get_drvdata(pdev) == NULL) { 4844 if (pci_get_drvdata(pdev) == NULL) {
4407 printk(KERN_ERR "cciss: Unable to remove device \n"); 4845 dev_err(&pdev->dev, "Unable to remove device\n");
4408 return; 4846 return;
4409 } 4847 }
4410 4848
4411 tmp_ptr = pci_get_drvdata(pdev); 4849 h = pci_get_drvdata(pdev);
4412 i = tmp_ptr->ctlr; 4850 i = h->ctlr;
4413 if (hba[i] == NULL) { 4851 if (hba[i] == NULL) {
4414 printk(KERN_ERR "cciss: device appears to " 4852 dev_err(&pdev->dev, "device appears to already be removed\n");
4415 "already be removed \n");
4416 return; 4853 return;
4417 } 4854 }
4418 4855
4419 mutex_lock(&hba[i]->busy_shutting_down); 4856 mutex_lock(&h->busy_shutting_down);
4420 4857
4421 remove_from_scan_list(hba[i]); 4858 remove_from_scan_list(h);
4422 remove_proc_entry(hba[i]->devname, proc_cciss); 4859 remove_proc_entry(h->devname, proc_cciss);
4423 unregister_blkdev(hba[i]->major, hba[i]->devname); 4860 unregister_blkdev(h->major, h->devname);
4424 4861
4425 /* remove it from the disk list */ 4862 /* remove it from the disk list */
4426 for (j = 0; j < CISS_MAX_LUN; j++) { 4863 for (j = 0; j < CISS_MAX_LUN; j++) {
4427 struct gendisk *disk = hba[i]->gendisk[j]; 4864 struct gendisk *disk = h->gendisk[j];
4428 if (disk) { 4865 if (disk) {
4429 struct request_queue *q = disk->queue; 4866 struct request_queue *q = disk->queue;
4430 4867
4431 if (disk->flags & GENHD_FL_UP) { 4868 if (disk->flags & GENHD_FL_UP) {
4432 cciss_destroy_ld_sysfs_entry(hba[i], j, 1); 4869 cciss_destroy_ld_sysfs_entry(h, j, 1);
4433 del_gendisk(disk); 4870 del_gendisk(disk);
4434 } 4871 }
4435 if (q) 4872 if (q)
@@ -4438,39 +4875,41 @@ static void __devexit cciss_remove_one(struct pci_dev *pdev)
4438 } 4875 }
4439 4876
4440#ifdef CONFIG_CISS_SCSI_TAPE 4877#ifdef CONFIG_CISS_SCSI_TAPE
4441 cciss_unregister_scsi(i); /* unhook from SCSI subsystem */ 4878 cciss_unregister_scsi(h); /* unhook from SCSI subsystem */
4442#endif 4879#endif
4443 4880
4444 cciss_shutdown(pdev); 4881 cciss_shutdown(pdev);
4445 4882
4446#ifdef CONFIG_PCI_MSI 4883#ifdef CONFIG_PCI_MSI
4447 if (hba[i]->msix_vector) 4884 if (h->msix_vector)
4448 pci_disable_msix(hba[i]->pdev); 4885 pci_disable_msix(h->pdev);
4449 else if (hba[i]->msi_vector) 4886 else if (h->msi_vector)
4450 pci_disable_msi(hba[i]->pdev); 4887 pci_disable_msi(h->pdev);
4451#endif /* CONFIG_PCI_MSI */ 4888#endif /* CONFIG_PCI_MSI */
4452 4889
4453 iounmap(hba[i]->vaddr); 4890 iounmap(h->transtable);
4891 iounmap(h->cfgtable);
4892 iounmap(h->vaddr);
4454 4893
4455 pci_free_consistent(hba[i]->pdev, hba[i]->nr_cmds * sizeof(CommandList_struct), 4894 pci_free_consistent(h->pdev, h->nr_cmds * sizeof(CommandList_struct),
4456 hba[i]->cmd_pool, hba[i]->cmd_pool_dhandle); 4895 h->cmd_pool, h->cmd_pool_dhandle);
4457 pci_free_consistent(hba[i]->pdev, hba[i]->nr_cmds * sizeof(ErrorInfo_struct), 4896 pci_free_consistent(h->pdev, h->nr_cmds * sizeof(ErrorInfo_struct),
4458 hba[i]->errinfo_pool, hba[i]->errinfo_pool_dhandle); 4897 h->errinfo_pool, h->errinfo_pool_dhandle);
4459 kfree(hba[i]->cmd_pool_bits); 4898 kfree(h->cmd_pool_bits);
4460 /* Free up sg elements */ 4899 /* Free up sg elements */
4461 for (j = 0; j < hba[i]->nr_cmds; j++) 4900 for (j = 0; j < h->nr_cmds; j++)
4462 kfree(hba[i]->scatter_list[j]); 4901 kfree(h->scatter_list[j]);
4463 kfree(hba[i]->scatter_list); 4902 kfree(h->scatter_list);
4464 cciss_free_sg_chain_blocks(hba[i]->cmd_sg_list, hba[i]->nr_cmds); 4903 cciss_free_sg_chain_blocks(h->cmd_sg_list, h->nr_cmds);
4465 /* 4904 /*
4466 * Deliberately omit pci_disable_device(): it does something nasty to 4905 * Deliberately omit pci_disable_device(): it does something nasty to
4467 * Smart Array controllers that pci_enable_device does not undo 4906 * Smart Array controllers that pci_enable_device does not undo
4468 */ 4907 */
4469 pci_release_regions(pdev); 4908 pci_release_regions(pdev);
4470 pci_set_drvdata(pdev, NULL); 4909 pci_set_drvdata(pdev, NULL);
4471 cciss_destroy_hba_sysfs_entry(hba[i]); 4910 cciss_destroy_hba_sysfs_entry(h);
4472 mutex_unlock(&hba[i]->busy_shutting_down); 4911 mutex_unlock(&h->busy_shutting_down);
4473 free_hba(i); 4912 free_hba(h);
4474} 4913}
4475 4914
4476static struct pci_driver cciss_pci_driver = { 4915static struct pci_driver cciss_pci_driver = {
@@ -4495,7 +4934,6 @@ static int __init cciss_init(void)
4495 * array of them, the size must be a multiple of 8 bytes. 4934 * array of them, the size must be a multiple of 8 bytes.
4496 */ 4935 */
4497 BUILD_BUG_ON(sizeof(CommandList_struct) % COMMANDLIST_ALIGNMENT); 4936 BUILD_BUG_ON(sizeof(CommandList_struct) % COMMANDLIST_ALIGNMENT);
4498
4499 printk(KERN_INFO DRIVER_NAME "\n"); 4937 printk(KERN_INFO DRIVER_NAME "\n");
4500 4938
4501 err = bus_register(&cciss_bus_type); 4939 err = bus_register(&cciss_bus_type);
@@ -4532,8 +4970,8 @@ static void __exit cciss_cleanup(void)
4532 /* double check that all controller entrys have been removed */ 4970 /* double check that all controller entrys have been removed */
4533 for (i = 0; i < MAX_CTLR; i++) { 4971 for (i = 0; i < MAX_CTLR; i++) {
4534 if (hba[i] != NULL) { 4972 if (hba[i] != NULL) {
4535 printk(KERN_WARNING "cciss: had to remove" 4973 dev_warn(&hba[i]->pdev->dev,
4536 " controller %d\n", i); 4974 "had to remove controller\n");
4537 cciss_remove_one(hba[i]->pdev); 4975 cciss_remove_one(hba[i]->pdev);
4538 } 4976 }
4539 } 4977 }
@@ -4542,46 +4980,5 @@ static void __exit cciss_cleanup(void)
4542 bus_unregister(&cciss_bus_type); 4980 bus_unregister(&cciss_bus_type);
4543} 4981}
4544 4982
4545static void fail_all_cmds(unsigned long ctlr)
4546{
4547 /* If we get here, the board is apparently dead. */
4548 ctlr_info_t *h = hba[ctlr];
4549 CommandList_struct *c;
4550 unsigned long flags;
4551
4552 printk(KERN_WARNING "cciss%d: controller not responding.\n", h->ctlr);
4553 h->alive = 0; /* the controller apparently died... */
4554
4555 spin_lock_irqsave(CCISS_LOCK(ctlr), flags);
4556
4557 pci_disable_device(h->pdev); /* Make sure it is really dead. */
4558
4559 /* move everything off the request queue onto the completed queue */
4560 while (!hlist_empty(&h->reqQ)) {
4561 c = hlist_entry(h->reqQ.first, CommandList_struct, list);
4562 removeQ(c);
4563 h->Qdepth--;
4564 addQ(&h->cmpQ, c);
4565 }
4566
4567 /* Now, fail everything on the completed queue with a HW error */
4568 while (!hlist_empty(&h->cmpQ)) {
4569 c = hlist_entry(h->cmpQ.first, CommandList_struct, list);
4570 removeQ(c);
4571 if (c->cmd_type != CMD_MSG_STALE)
4572 c->err_info->CommandStatus = CMD_HARDWARE_ERR;
4573 if (c->cmd_type == CMD_RWREQ) {
4574 complete_command(h, c, 0);
4575 } else if (c->cmd_type == CMD_IOCTL_PEND)
4576 complete(c->waiting);
4577#ifdef CONFIG_CISS_SCSI_TAPE
4578 else if (c->cmd_type == CMD_SCSI)
4579 complete_scsi_command(c, 0, 0);
4580#endif
4581 }
4582 spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags);
4583 return;
4584}
4585
4586module_init(cciss_init); 4983module_init(cciss_init);
4587module_exit(cciss_cleanup); 4984module_exit(cciss_cleanup);
diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
index c5d411174db0..ae340ffc8f81 100644
--- a/drivers/block/cciss.h
+++ b/drivers/block/cciss.h
@@ -25,7 +25,7 @@ struct access_method {
25 void (*submit_command)(ctlr_info_t *h, CommandList_struct *c); 25 void (*submit_command)(ctlr_info_t *h, CommandList_struct *c);
26 void (*set_intr_mask)(ctlr_info_t *h, unsigned long val); 26 void (*set_intr_mask)(ctlr_info_t *h, unsigned long val);
27 unsigned long (*fifo_full)(ctlr_info_t *h); 27 unsigned long (*fifo_full)(ctlr_info_t *h);
28 unsigned long (*intr_pending)(ctlr_info_t *h); 28 bool (*intr_pending)(ctlr_info_t *h);
29 unsigned long (*command_completed)(ctlr_info_t *h); 29 unsigned long (*command_completed)(ctlr_info_t *h);
30}; 30};
31typedef struct _drive_info_struct 31typedef struct _drive_info_struct
@@ -85,8 +85,8 @@ struct ctlr_info
85 int max_cmd_sgentries; 85 int max_cmd_sgentries;
86 SGDescriptor_struct **cmd_sg_list; 86 SGDescriptor_struct **cmd_sg_list;
87 87
88# define DOORBELL_INT 0 88# define PERF_MODE_INT 0
89# define PERF_MODE_INT 1 89# define DOORBELL_INT 1
90# define SIMPLE_MODE_INT 2 90# define SIMPLE_MODE_INT 2
91# define MEMQ_MODE_INT 3 91# define MEMQ_MODE_INT 3
92 unsigned int intr[4]; 92 unsigned int intr[4];
@@ -137,10 +137,27 @@ struct ctlr_info
137 struct list_head scan_list; 137 struct list_head scan_list;
138 struct completion scan_wait; 138 struct completion scan_wait;
139 struct device dev; 139 struct device dev;
140 /*
141 * Performant mode tables.
142 */
143 u32 trans_support;
144 u32 trans_offset;
145 struct TransTable_struct *transtable;
146 unsigned long transMethod;
147
148 /*
149 * Performant mode completion buffer
150 */
151 u64 *reply_pool;
152 dma_addr_t reply_pool_dhandle;
153 u64 *reply_pool_head;
154 size_t reply_pool_size;
155 unsigned char reply_pool_wraparound;
156 u32 *blockFetchTable;
140}; 157};
141 158
142/* Defining the diffent access_menthods */ 159/* Defining the diffent access_methods
143/* 160 *
144 * Memory mapped FIFO interface (SMART 53xx cards) 161 * Memory mapped FIFO interface (SMART 53xx cards)
145 */ 162 */
146#define SA5_DOORBELL 0x20 163#define SA5_DOORBELL 0x20
@@ -159,19 +176,47 @@ struct ctlr_info
159#define SA5B_INTR_PENDING 0x04 176#define SA5B_INTR_PENDING 0x04
160#define FIFO_EMPTY 0xffffffff 177#define FIFO_EMPTY 0xffffffff
161#define CCISS_FIRMWARE_READY 0xffff0000 /* value in scratchpad register */ 178#define CCISS_FIRMWARE_READY 0xffff0000 /* value in scratchpad register */
179/* Perf. mode flags */
180#define SA5_PERF_INTR_PENDING 0x04
181#define SA5_PERF_INTR_OFF 0x05
182#define SA5_OUTDB_STATUS_PERF_BIT 0x01
183#define SA5_OUTDB_CLEAR_PERF_BIT 0x01
184#define SA5_OUTDB_CLEAR 0xA0
185#define SA5_OUTDB_CLEAR_PERF_BIT 0x01
186#define SA5_OUTDB_STATUS 0x9C
187
162 188
163#define CISS_ERROR_BIT 0x02 189#define CISS_ERROR_BIT 0x02
164 190
165#define CCISS_INTR_ON 1 191#define CCISS_INTR_ON 1
166#define CCISS_INTR_OFF 0 192#define CCISS_INTR_OFF 0
193
194
195/* CCISS_BOARD_READY_WAIT_SECS is how long to wait for a board
196 * to become ready, in seconds, before giving up on it.
197 * CCISS_BOARD_READY_POLL_INTERVAL_MSECS * is how long to wait
198 * between polling the board to see if it is ready, in
199 * milliseconds. CCISS_BOARD_READY_ITERATIONS is derived
200 * the above.
201 */
202#define CCISS_BOARD_READY_WAIT_SECS (120)
203#define CCISS_BOARD_READY_POLL_INTERVAL_MSECS (100)
204#define CCISS_BOARD_READY_ITERATIONS \
205 ((CCISS_BOARD_READY_WAIT_SECS * 1000) / \
206 CCISS_BOARD_READY_POLL_INTERVAL_MSECS)
207#define CCISS_POST_RESET_PAUSE_MSECS (3000)
208#define CCISS_POST_RESET_NOOP_INTERVAL_MSECS (1000)
209#define CCISS_POST_RESET_NOOP_RETRIES (12)
210
167/* 211/*
168 Send the command to the hardware 212 Send the command to the hardware
169*/ 213*/
170static void SA5_submit_command( ctlr_info_t *h, CommandList_struct *c) 214static void SA5_submit_command( ctlr_info_t *h, CommandList_struct *c)
171{ 215{
172#ifdef CCISS_DEBUG 216#ifdef CCISS_DEBUG
173 printk("Sending %x - down to controller\n", c->busaddr ); 217 printk(KERN_WARNING "cciss%d: Sending %08x - down to controller\n",
174#endif /* CCISS_DEBUG */ 218 h->ctlr, c->busaddr);
219#endif /* CCISS_DEBUG */
175 writel(c->busaddr, h->vaddr + SA5_REQUEST_PORT_OFFSET); 220 writel(c->busaddr, h->vaddr + SA5_REQUEST_PORT_OFFSET);
176 h->commands_outstanding++; 221 h->commands_outstanding++;
177 if ( h->commands_outstanding > h->max_outstanding) 222 if ( h->commands_outstanding > h->max_outstanding)
@@ -214,6 +259,20 @@ static void SA5B_intr_mask(ctlr_info_t *h, unsigned long val)
214 h->vaddr + SA5_REPLY_INTR_MASK_OFFSET); 259 h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
215 } 260 }
216} 261}
262
263/* Performant mode intr_mask */
264static void SA5_performant_intr_mask(ctlr_info_t *h, unsigned long val)
265{
266 if (val) { /* turn on interrupts */
267 h->interrupts_enabled = 1;
268 writel(0, h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
269 } else {
270 h->interrupts_enabled = 0;
271 writel(SA5_PERF_INTR_OFF,
272 h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
273 }
274}
275
217/* 276/*
218 * Returns true if fifo is full. 277 * Returns true if fifo is full.
219 * 278 *
@@ -250,10 +309,44 @@ static unsigned long SA5_completed(ctlr_info_t *h)
250 return ( register_value); 309 return ( register_value);
251 310
252} 311}
312
313/* Performant mode command completed */
314static unsigned long SA5_performant_completed(ctlr_info_t *h)
315{
316 unsigned long register_value = FIFO_EMPTY;
317
318 /* flush the controller write of the reply queue by reading
319 * outbound doorbell status register.
320 */
321 register_value = readl(h->vaddr + SA5_OUTDB_STATUS);
322 /* msi auto clears the interrupt pending bit. */
323 if (!(h->msi_vector || h->msix_vector)) {
324 writel(SA5_OUTDB_CLEAR_PERF_BIT, h->vaddr + SA5_OUTDB_CLEAR);
325 /* Do a read in order to flush the write to the controller
326 * (as per spec.)
327 */
328 register_value = readl(h->vaddr + SA5_OUTDB_STATUS);
329 }
330
331 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
332 register_value = *(h->reply_pool_head);
333 (h->reply_pool_head)++;
334 h->commands_outstanding--;
335 } else {
336 register_value = FIFO_EMPTY;
337 }
338 /* Check for wraparound */
339 if (h->reply_pool_head == (h->reply_pool + h->max_commands)) {
340 h->reply_pool_head = h->reply_pool;
341 h->reply_pool_wraparound ^= 1;
342 }
343
344 return register_value;
345}
253/* 346/*
254 * Returns true if an interrupt is pending.. 347 * Returns true if an interrupt is pending..
255 */ 348 */
256static unsigned long SA5_intr_pending(ctlr_info_t *h) 349static bool SA5_intr_pending(ctlr_info_t *h)
257{ 350{
258 unsigned long register_value = 351 unsigned long register_value =
259 readl(h->vaddr + SA5_INTR_STATUS); 352 readl(h->vaddr + SA5_INTR_STATUS);
@@ -268,7 +361,7 @@ static unsigned long SA5_intr_pending(ctlr_info_t *h)
268/* 361/*
269 * Returns true if an interrupt is pending.. 362 * Returns true if an interrupt is pending..
270 */ 363 */
271static unsigned long SA5B_intr_pending(ctlr_info_t *h) 364static bool SA5B_intr_pending(ctlr_info_t *h)
272{ 365{
273 unsigned long register_value = 366 unsigned long register_value =
274 readl(h->vaddr + SA5_INTR_STATUS); 367 readl(h->vaddr + SA5_INTR_STATUS);
@@ -280,6 +373,20 @@ static unsigned long SA5B_intr_pending(ctlr_info_t *h)
280 return 0 ; 373 return 0 ;
281} 374}
282 375
376static bool SA5_performant_intr_pending(ctlr_info_t *h)
377{
378 unsigned long register_value = readl(h->vaddr + SA5_INTR_STATUS);
379
380 if (!register_value)
381 return false;
382
383 if (h->msi_vector || h->msix_vector)
384 return true;
385
386 /* Read outbound doorbell to flush */
387 register_value = readl(h->vaddr + SA5_OUTDB_STATUS);
388 return register_value & SA5_OUTDB_STATUS_PERF_BIT;
389}
283 390
284static struct access_method SA5_access = { 391static struct access_method SA5_access = {
285 SA5_submit_command, 392 SA5_submit_command,
@@ -297,6 +404,14 @@ static struct access_method SA5B_access = {
297 SA5_completed, 404 SA5_completed,
298}; 405};
299 406
407static struct access_method SA5_performant_access = {
408 SA5_submit_command,
409 SA5_performant_intr_mask,
410 SA5_fifo_full,
411 SA5_performant_intr_pending,
412 SA5_performant_completed,
413};
414
300struct board_type { 415struct board_type {
301 __u32 board_id; 416 __u32 board_id;
302 char *product_name; 417 char *product_name;
@@ -304,6 +419,4 @@ struct board_type {
304 int nr_cmds; /* Max cmds this kind of ctlr can handle. */ 419 int nr_cmds; /* Max cmds this kind of ctlr can handle. */
305}; 420};
306 421
307#define CCISS_LOCK(i) (&hba[i]->lock)
308
309#endif /* CCISS_H */ 422#endif /* CCISS_H */
diff --git a/drivers/block/cciss_cmd.h b/drivers/block/cciss_cmd.h
index e624ff959cb6..eb060f1b00b6 100644
--- a/drivers/block/cciss_cmd.h
+++ b/drivers/block/cciss_cmd.h
@@ -52,8 +52,10 @@
52/* Configuration Table */ 52/* Configuration Table */
53#define CFGTBL_ChangeReq 0x00000001l 53#define CFGTBL_ChangeReq 0x00000001l
54#define CFGTBL_AccCmds 0x00000001l 54#define CFGTBL_AccCmds 0x00000001l
55#define DOORBELL_CTLR_RESET 0x00000004l
55 56
56#define CFGTBL_Trans_Simple 0x00000002l 57#define CFGTBL_Trans_Simple 0x00000002l
58#define CFGTBL_Trans_Performant 0x00000004l
57 59
58#define CFGTBL_BusType_Ultra2 0x00000001l 60#define CFGTBL_BusType_Ultra2 0x00000001l
59#define CFGTBL_BusType_Ultra3 0x00000002l 61#define CFGTBL_BusType_Ultra3 0x00000002l
@@ -173,12 +175,15 @@ typedef struct _SGDescriptor_struct {
173 * PAD_64 can be adjusted independently as needed for 32-bit 175 * PAD_64 can be adjusted independently as needed for 32-bit
174 * and 64-bits systems. 176 * and 64-bits systems.
175 */ 177 */
176#define COMMANDLIST_ALIGNMENT (8) 178#define COMMANDLIST_ALIGNMENT (32)
177#define IS_64_BIT ((sizeof(long) - 4)/4) 179#define IS_64_BIT ((sizeof(long) - 4)/4)
178#define IS_32_BIT (!IS_64_BIT) 180#define IS_32_BIT (!IS_64_BIT)
179#define PAD_32 (0) 181#define PAD_32 (0)
180#define PAD_64 (4) 182#define PAD_64 (4)
181#define PADSIZE (IS_32_BIT * PAD_32 + IS_64_BIT * PAD_64) 183#define PADSIZE (IS_32_BIT * PAD_32 + IS_64_BIT * PAD_64)
184#define DIRECT_LOOKUP_BIT 0x10
185#define DIRECT_LOOKUP_SHIFT 5
186
182typedef struct _CommandList_struct { 187typedef struct _CommandList_struct {
183 CommandListHeader_struct Header; 188 CommandListHeader_struct Header;
184 RequestBlock_struct Request; 189 RequestBlock_struct Request;
@@ -195,7 +200,7 @@ typedef struct _CommandList_struct {
195 struct completion *waiting; 200 struct completion *waiting;
196 int retry_count; 201 int retry_count;
197 void * scsi_cmd; 202 void * scsi_cmd;
198 char pad[PADSIZE]; 203 char pad[PADSIZE];
199} CommandList_struct; 204} CommandList_struct;
200 205
201/* Configuration Table Structure */ 206/* Configuration Table Structure */
@@ -209,12 +214,15 @@ typedef struct _HostWrite_struct {
209typedef struct _CfgTable_struct { 214typedef struct _CfgTable_struct {
210 BYTE Signature[4]; 215 BYTE Signature[4];
211 DWORD SpecValence; 216 DWORD SpecValence;
217#define SIMPLE_MODE 0x02
218#define PERFORMANT_MODE 0x04
219#define MEMQ_MODE 0x08
212 DWORD TransportSupport; 220 DWORD TransportSupport;
213 DWORD TransportActive; 221 DWORD TransportActive;
214 HostWrite_struct HostWrite; 222 HostWrite_struct HostWrite;
215 DWORD CmdsOutMax; 223 DWORD CmdsOutMax;
216 DWORD BusTypes; 224 DWORD BusTypes;
217 DWORD Reserved; 225 DWORD TransMethodOffset;
218 BYTE ServerName[16]; 226 BYTE ServerName[16];
219 DWORD HeartBeat; 227 DWORD HeartBeat;
220 DWORD SCSI_Prefetch; 228 DWORD SCSI_Prefetch;
@@ -222,6 +230,28 @@ typedef struct _CfgTable_struct {
222 DWORD MaxLogicalUnits; 230 DWORD MaxLogicalUnits;
223 DWORD MaxPhysicalDrives; 231 DWORD MaxPhysicalDrives;
224 DWORD MaxPhysicalDrivesPerLogicalUnit; 232 DWORD MaxPhysicalDrivesPerLogicalUnit;
233 DWORD MaxPerformantModeCommands;
234 u8 reserved[0x78 - 0x58];
235 u32 misc_fw_support; /* offset 0x78 */
236#define MISC_FW_DOORBELL_RESET (0x02)
225} CfgTable_struct; 237} CfgTable_struct;
238
239struct TransTable_struct {
240 u32 BlockFetch0;
241 u32 BlockFetch1;
242 u32 BlockFetch2;
243 u32 BlockFetch3;
244 u32 BlockFetch4;
245 u32 BlockFetch5;
246 u32 BlockFetch6;
247 u32 BlockFetch7;
248 u32 RepQSize;
249 u32 RepQCount;
250 u32 RepQCtrAddrLow32;
251 u32 RepQCtrAddrHigh32;
252 u32 RepQAddr0Low32;
253 u32 RepQAddr0High32;
254};
255
226#pragma pack() 256#pragma pack()
227#endif /* CCISS_CMD_H */ 257#endif /* CCISS_CMD_H */
diff --git a/drivers/block/cciss_scsi.c b/drivers/block/cciss_scsi.c
index 72dae92f3cab..575495f3c4b8 100644
--- a/drivers/block/cciss_scsi.c
+++ b/drivers/block/cciss_scsi.c
@@ -44,13 +44,15 @@
44#define CCISS_ABORT_MSG 0x00 44#define CCISS_ABORT_MSG 0x00
45#define CCISS_RESET_MSG 0x01 45#define CCISS_RESET_MSG 0x01
46 46
47static int fill_cmd(CommandList_struct *c, __u8 cmd, int ctlr, void *buff, 47static int fill_cmd(ctlr_info_t *h, CommandList_struct *c, __u8 cmd, void *buff,
48 size_t size, 48 size_t size,
49 __u8 page_code, unsigned char *scsi3addr, 49 __u8 page_code, unsigned char *scsi3addr,
50 int cmd_type); 50 int cmd_type);
51 51
52static CommandList_struct *cmd_alloc(ctlr_info_t *h, int get_from_pool); 52static CommandList_struct *cmd_alloc(ctlr_info_t *h);
53static void cmd_free(ctlr_info_t *h, CommandList_struct *c, int got_from_pool); 53static CommandList_struct *cmd_special_alloc(ctlr_info_t *h);
54static void cmd_free(ctlr_info_t *h, CommandList_struct *c);
55static void cmd_special_free(ctlr_info_t *h, CommandList_struct *c);
54 56
55static int cciss_scsi_proc_info( 57static int cciss_scsi_proc_info(
56 struct Scsi_Host *sh, 58 struct Scsi_Host *sh,
@@ -93,8 +95,8 @@ static struct scsi_host_template cciss_driver_template = {
93 95
94#pragma pack(1) 96#pragma pack(1)
95 97
96#define SCSI_PAD_32 0 98#define SCSI_PAD_32 8
97#define SCSI_PAD_64 0 99#define SCSI_PAD_64 8
98 100
99struct cciss_scsi_cmd_stack_elem_t { 101struct cciss_scsi_cmd_stack_elem_t {
100 CommandList_struct cmd; 102 CommandList_struct cmd;
@@ -127,16 +129,16 @@ struct cciss_scsi_adapter_data_t {
127 spinlock_t lock; // to protect ccissscsi[ctlr]; 129 spinlock_t lock; // to protect ccissscsi[ctlr];
128}; 130};
129 131
130#define CPQ_TAPE_LOCK(ctlr, flags) spin_lock_irqsave( \ 132#define CPQ_TAPE_LOCK(h, flags) spin_lock_irqsave( \
131 &hba[ctlr]->scsi_ctlr->lock, flags); 133 &h->scsi_ctlr->lock, flags);
132#define CPQ_TAPE_UNLOCK(ctlr, flags) spin_unlock_irqrestore( \ 134#define CPQ_TAPE_UNLOCK(h, flags) spin_unlock_irqrestore( \
133 &hba[ctlr]->scsi_ctlr->lock, flags); 135 &h->scsi_ctlr->lock, flags);
134 136
135static CommandList_struct * 137static CommandList_struct *
136scsi_cmd_alloc(ctlr_info_t *h) 138scsi_cmd_alloc(ctlr_info_t *h)
137{ 139{
138 /* assume only one process in here at a time, locking done by caller. */ 140 /* assume only one process in here at a time, locking done by caller. */
139 /* use CCISS_LOCK(ctlr) */ 141 /* use h->lock */
140 /* might be better to rewrite how we allocate scsi commands in a way that */ 142 /* might be better to rewrite how we allocate scsi commands in a way that */
141 /* needs no locking at all. */ 143 /* needs no locking at all. */
142 144
@@ -177,10 +179,10 @@ scsi_cmd_alloc(ctlr_info_t *h)
177} 179}
178 180
179static void 181static void
180scsi_cmd_free(ctlr_info_t *h, CommandList_struct *cmd) 182scsi_cmd_free(ctlr_info_t *h, CommandList_struct *c)
181{ 183{
182 /* assume only one process in here at a time, locking done by caller. */ 184 /* assume only one process in here at a time, locking done by caller. */
183 /* use CCISS_LOCK(ctlr) */ 185 /* use h->lock */
184 /* drop the free memory chunk on top of the stack. */ 186 /* drop the free memory chunk on top of the stack. */
185 187
186 struct cciss_scsi_adapter_data_t *sa; 188 struct cciss_scsi_adapter_data_t *sa;
@@ -190,22 +192,23 @@ scsi_cmd_free(ctlr_info_t *h, CommandList_struct *cmd)
190 stk = &sa->cmd_stack; 192 stk = &sa->cmd_stack;
191 stk->top++; 193 stk->top++;
192 if (stk->top >= CMD_STACK_SIZE) { 194 if (stk->top >= CMD_STACK_SIZE) {
193 printk("cciss: scsi_cmd_free called too many times.\n"); 195 dev_err(&h->pdev->dev,
196 "scsi_cmd_free called too many times.\n");
194 BUG(); 197 BUG();
195 } 198 }
196 stk->elem[stk->top] = (struct cciss_scsi_cmd_stack_elem_t *) cmd; 199 stk->elem[stk->top] = (struct cciss_scsi_cmd_stack_elem_t *) c;
197} 200}
198 201
199static int 202static int
200scsi_cmd_stack_setup(int ctlr, struct cciss_scsi_adapter_data_t *sa) 203scsi_cmd_stack_setup(ctlr_info_t *h, struct cciss_scsi_adapter_data_t *sa)
201{ 204{
202 int i; 205 int i;
203 struct cciss_scsi_cmd_stack_t *stk; 206 struct cciss_scsi_cmd_stack_t *stk;
204 size_t size; 207 size_t size;
205 208
206 sa->cmd_sg_list = cciss_allocate_sg_chain_blocks(hba[ctlr], 209 sa->cmd_sg_list = cciss_allocate_sg_chain_blocks(h,
207 hba[ctlr]->chainsize, CMD_STACK_SIZE); 210 h->chainsize, CMD_STACK_SIZE);
208 if (!sa->cmd_sg_list && hba[ctlr]->chainsize > 0) 211 if (!sa->cmd_sg_list && h->chainsize > 0)
209 return -ENOMEM; 212 return -ENOMEM;
210 213
211 stk = &sa->cmd_stack; 214 stk = &sa->cmd_stack;
@@ -215,7 +218,7 @@ scsi_cmd_stack_setup(int ctlr, struct cciss_scsi_adapter_data_t *sa)
215 BUILD_BUG_ON((sizeof(*stk->pool) % COMMANDLIST_ALIGNMENT) != 0); 218 BUILD_BUG_ON((sizeof(*stk->pool) % COMMANDLIST_ALIGNMENT) != 0);
216 /* pci_alloc_consistent guarantees 32-bit DMA address will be used */ 219 /* pci_alloc_consistent guarantees 32-bit DMA address will be used */
217 stk->pool = (struct cciss_scsi_cmd_stack_elem_t *) 220 stk->pool = (struct cciss_scsi_cmd_stack_elem_t *)
218 pci_alloc_consistent(hba[ctlr]->pdev, size, &stk->cmd_pool_handle); 221 pci_alloc_consistent(h->pdev, size, &stk->cmd_pool_handle);
219 222
220 if (stk->pool == NULL) { 223 if (stk->pool == NULL) {
221 cciss_free_sg_chain_blocks(sa->cmd_sg_list, CMD_STACK_SIZE); 224 cciss_free_sg_chain_blocks(sa->cmd_sg_list, CMD_STACK_SIZE);
@@ -234,23 +237,22 @@ scsi_cmd_stack_setup(int ctlr, struct cciss_scsi_adapter_data_t *sa)
234} 237}
235 238
236static void 239static void
237scsi_cmd_stack_free(int ctlr) 240scsi_cmd_stack_free(ctlr_info_t *h)
238{ 241{
239 struct cciss_scsi_adapter_data_t *sa; 242 struct cciss_scsi_adapter_data_t *sa;
240 struct cciss_scsi_cmd_stack_t *stk; 243 struct cciss_scsi_cmd_stack_t *stk;
241 size_t size; 244 size_t size;
242 245
243 sa = hba[ctlr]->scsi_ctlr; 246 sa = h->scsi_ctlr;
244 stk = &sa->cmd_stack; 247 stk = &sa->cmd_stack;
245 if (stk->top != CMD_STACK_SIZE-1) { 248 if (stk->top != CMD_STACK_SIZE-1) {
246 printk( "cciss: %d scsi commands are still outstanding.\n", 249 dev_warn(&h->pdev->dev,
250 "bug: %d scsi commands are still outstanding.\n",
247 CMD_STACK_SIZE - stk->top); 251 CMD_STACK_SIZE - stk->top);
248 // BUG();
249 printk("WE HAVE A BUG HERE!!! stk=0x%p\n", stk);
250 } 252 }
251 size = sizeof(struct cciss_scsi_cmd_stack_elem_t) * CMD_STACK_SIZE; 253 size = sizeof(struct cciss_scsi_cmd_stack_elem_t) * CMD_STACK_SIZE;
252 254
253 pci_free_consistent(hba[ctlr]->pdev, size, stk->pool, stk->cmd_pool_handle); 255 pci_free_consistent(h->pdev, size, stk->pool, stk->cmd_pool_handle);
254 stk->pool = NULL; 256 stk->pool = NULL;
255 cciss_free_sg_chain_blocks(sa->cmd_sg_list, CMD_STACK_SIZE); 257 cciss_free_sg_chain_blocks(sa->cmd_sg_list, CMD_STACK_SIZE);
256} 258}
@@ -342,20 +344,20 @@ print_cmd(CommandList_struct *cp)
342#endif 344#endif
343 345
344static int 346static int
345find_bus_target_lun(int ctlr, int *bus, int *target, int *lun) 347find_bus_target_lun(ctlr_info_t *h, int *bus, int *target, int *lun)
346{ 348{
347 /* finds an unused bus, target, lun for a new device */ 349 /* finds an unused bus, target, lun for a new device */
348 /* assumes hba[ctlr]->scsi_ctlr->lock is held */ 350 /* assumes h->scsi_ctlr->lock is held */
349 int i, found=0; 351 int i, found=0;
350 unsigned char target_taken[CCISS_MAX_SCSI_DEVS_PER_HBA]; 352 unsigned char target_taken[CCISS_MAX_SCSI_DEVS_PER_HBA];
351 353
352 memset(&target_taken[0], 0, CCISS_MAX_SCSI_DEVS_PER_HBA); 354 memset(&target_taken[0], 0, CCISS_MAX_SCSI_DEVS_PER_HBA);
353 355
354 target_taken[SELF_SCSI_ID] = 1; 356 target_taken[SELF_SCSI_ID] = 1;
355 for (i=0;i<ccissscsi[ctlr].ndevices;i++) 357 for (i = 0; i < ccissscsi[h->ctlr].ndevices; i++)
356 target_taken[ccissscsi[ctlr].dev[i].target] = 1; 358 target_taken[ccissscsi[h->ctlr].dev[i].target] = 1;
357 359
358 for (i=0;i<CCISS_MAX_SCSI_DEVS_PER_HBA;i++) { 360 for (i = 0; i < CCISS_MAX_SCSI_DEVS_PER_HBA; i++) {
359 if (!target_taken[i]) { 361 if (!target_taken[i]) {
360 *bus = 0; *target=i; *lun = 0; found=1; 362 *bus = 0; *target=i; *lun = 0; found=1;
361 break; 363 break;
@@ -369,19 +371,19 @@ struct scsi2map {
369}; 371};
370 372
371static int 373static int
372cciss_scsi_add_entry(int ctlr, int hostno, 374cciss_scsi_add_entry(ctlr_info_t *h, int hostno,
373 struct cciss_scsi_dev_t *device, 375 struct cciss_scsi_dev_t *device,
374 struct scsi2map *added, int *nadded) 376 struct scsi2map *added, int *nadded)
375{ 377{
376 /* assumes hba[ctlr]->scsi_ctlr->lock is held */ 378 /* assumes h->scsi_ctlr->lock is held */
377 int n = ccissscsi[ctlr].ndevices; 379 int n = ccissscsi[h->ctlr].ndevices;
378 struct cciss_scsi_dev_t *sd; 380 struct cciss_scsi_dev_t *sd;
379 int i, bus, target, lun; 381 int i, bus, target, lun;
380 unsigned char addr1[8], addr2[8]; 382 unsigned char addr1[8], addr2[8];
381 383
382 if (n >= CCISS_MAX_SCSI_DEVS_PER_HBA) { 384 if (n >= CCISS_MAX_SCSI_DEVS_PER_HBA) {
383 printk("cciss%d: Too many devices, " 385 dev_warn(&h->pdev->dev, "Too many devices, "
384 "some will be inaccessible.\n", ctlr); 386 "some will be inaccessible.\n");
385 return -1; 387 return -1;
386 } 388 }
387 389
@@ -397,7 +399,7 @@ cciss_scsi_add_entry(int ctlr, int hostno,
397 memcpy(addr1, device->scsi3addr, 8); 399 memcpy(addr1, device->scsi3addr, 8);
398 addr1[4] = 0; 400 addr1[4] = 0;
399 for (i = 0; i < n; i++) { 401 for (i = 0; i < n; i++) {
400 sd = &ccissscsi[ctlr].dev[i]; 402 sd = &ccissscsi[h->ctlr].dev[i];
401 memcpy(addr2, sd->scsi3addr, 8); 403 memcpy(addr2, sd->scsi3addr, 8);
402 addr2[4] = 0; 404 addr2[4] = 0;
403 /* differ only in byte 4? */ 405 /* differ only in byte 4? */
@@ -410,9 +412,9 @@ cciss_scsi_add_entry(int ctlr, int hostno,
410 } 412 }
411 } 413 }
412 414
413 sd = &ccissscsi[ctlr].dev[n]; 415 sd = &ccissscsi[h->ctlr].dev[n];
414 if (lun == 0) { 416 if (lun == 0) {
415 if (find_bus_target_lun(ctlr, 417 if (find_bus_target_lun(h,
416 &sd->bus, &sd->target, &sd->lun) != 0) 418 &sd->bus, &sd->target, &sd->lun) != 0)
417 return -1; 419 return -1;
418 } else { 420 } else {
@@ -431,37 +433,37 @@ cciss_scsi_add_entry(int ctlr, int hostno,
431 memcpy(sd->device_id, device->device_id, sizeof(sd->device_id)); 433 memcpy(sd->device_id, device->device_id, sizeof(sd->device_id));
432 sd->devtype = device->devtype; 434 sd->devtype = device->devtype;
433 435
434 ccissscsi[ctlr].ndevices++; 436 ccissscsi[h->ctlr].ndevices++;
435 437
436 /* initially, (before registering with scsi layer) we don't 438 /* initially, (before registering with scsi layer) we don't
437 know our hostno and we don't want to print anything first 439 know our hostno and we don't want to print anything first
438 time anyway (the scsi layer's inquiries will show that info) */ 440 time anyway (the scsi layer's inquiries will show that info) */
439 if (hostno != -1) 441 if (hostno != -1)
440 printk("cciss%d: %s device c%db%dt%dl%d added.\n", 442 dev_info(&h->pdev->dev, "%s device c%db%dt%dl%d added.\n",
441 ctlr, scsi_device_type(sd->devtype), hostno, 443 scsi_device_type(sd->devtype), hostno,
442 sd->bus, sd->target, sd->lun); 444 sd->bus, sd->target, sd->lun);
443 return 0; 445 return 0;
444} 446}
445 447
446static void 448static void
447cciss_scsi_remove_entry(int ctlr, int hostno, int entry, 449cciss_scsi_remove_entry(ctlr_info_t *h, int hostno, int entry,
448 struct scsi2map *removed, int *nremoved) 450 struct scsi2map *removed, int *nremoved)
449{ 451{
450 /* assumes hba[ctlr]->scsi_ctlr->lock is held */ 452 /* assumes h->ctlr]->scsi_ctlr->lock is held */
451 int i; 453 int i;
452 struct cciss_scsi_dev_t sd; 454 struct cciss_scsi_dev_t sd;
453 455
454 if (entry < 0 || entry >= CCISS_MAX_SCSI_DEVS_PER_HBA) return; 456 if (entry < 0 || entry >= CCISS_MAX_SCSI_DEVS_PER_HBA) return;
455 sd = ccissscsi[ctlr].dev[entry]; 457 sd = ccissscsi[h->ctlr].dev[entry];
456 removed[*nremoved].bus = sd.bus; 458 removed[*nremoved].bus = sd.bus;
457 removed[*nremoved].target = sd.target; 459 removed[*nremoved].target = sd.target;
458 removed[*nremoved].lun = sd.lun; 460 removed[*nremoved].lun = sd.lun;
459 (*nremoved)++; 461 (*nremoved)++;
460 for (i=entry;i<ccissscsi[ctlr].ndevices-1;i++) 462 for (i = entry; i < ccissscsi[h->ctlr].ndevices-1; i++)
461 ccissscsi[ctlr].dev[i] = ccissscsi[ctlr].dev[i+1]; 463 ccissscsi[h->ctlr].dev[i] = ccissscsi[h->ctlr].dev[i+1];
462 ccissscsi[ctlr].ndevices--; 464 ccissscsi[h->ctlr].ndevices--;
463 printk("cciss%d: %s device c%db%dt%dl%d removed.\n", 465 dev_info(&h->pdev->dev, "%s device c%db%dt%dl%d removed.\n",
464 ctlr, scsi_device_type(sd.devtype), hostno, 466 scsi_device_type(sd.devtype), hostno,
465 sd.bus, sd.target, sd.lun); 467 sd.bus, sd.target, sd.lun);
466} 468}
467 469
@@ -476,24 +478,24 @@ cciss_scsi_remove_entry(int ctlr, int hostno, int entry,
476 (a)[1] == (b)[1] && \ 478 (a)[1] == (b)[1] && \
477 (a)[0] == (b)[0]) 479 (a)[0] == (b)[0])
478 480
479static void fixup_botched_add(int ctlr, char *scsi3addr) 481static void fixup_botched_add(ctlr_info_t *h, char *scsi3addr)
480{ 482{
481 /* called when scsi_add_device fails in order to re-adjust */ 483 /* called when scsi_add_device fails in order to re-adjust */
482 /* ccissscsi[] to match the mid layer's view. */ 484 /* ccissscsi[] to match the mid layer's view. */
483 unsigned long flags; 485 unsigned long flags;
484 int i, j; 486 int i, j;
485 CPQ_TAPE_LOCK(ctlr, flags); 487 CPQ_TAPE_LOCK(h, flags);
486 for (i = 0; i < ccissscsi[ctlr].ndevices; i++) { 488 for (i = 0; i < ccissscsi[h->ctlr].ndevices; i++) {
487 if (memcmp(scsi3addr, 489 if (memcmp(scsi3addr,
488 ccissscsi[ctlr].dev[i].scsi3addr, 8) == 0) { 490 ccissscsi[h->ctlr].dev[i].scsi3addr, 8) == 0) {
489 for (j = i; j < ccissscsi[ctlr].ndevices-1; j++) 491 for (j = i; j < ccissscsi[h->ctlr].ndevices-1; j++)
490 ccissscsi[ctlr].dev[j] = 492 ccissscsi[h->ctlr].dev[j] =
491 ccissscsi[ctlr].dev[j+1]; 493 ccissscsi[h->ctlr].dev[j+1];
492 ccissscsi[ctlr].ndevices--; 494 ccissscsi[h->ctlr].ndevices--;
493 break; 495 break;
494 } 496 }
495 } 497 }
496 CPQ_TAPE_UNLOCK(ctlr, flags); 498 CPQ_TAPE_UNLOCK(h, flags);
497} 499}
498 500
499static int device_is_the_same(struct cciss_scsi_dev_t *dev1, 501static int device_is_the_same(struct cciss_scsi_dev_t *dev1,
@@ -513,7 +515,7 @@ static int device_is_the_same(struct cciss_scsi_dev_t *dev1,
513} 515}
514 516
515static int 517static int
516adjust_cciss_scsi_table(int ctlr, int hostno, 518adjust_cciss_scsi_table(ctlr_info_t *h, int hostno,
517 struct cciss_scsi_dev_t sd[], int nsds) 519 struct cciss_scsi_dev_t sd[], int nsds)
518{ 520{
519 /* sd contains scsi3 addresses and devtypes, but 521 /* sd contains scsi3 addresses and devtypes, but
@@ -534,15 +536,15 @@ adjust_cciss_scsi_table(int ctlr, int hostno,
534 GFP_KERNEL); 536 GFP_KERNEL);
535 537
536 if (!added || !removed) { 538 if (!added || !removed) {
537 printk(KERN_WARNING "cciss%d: Out of memory in " 539 dev_warn(&h->pdev->dev,
538 "adjust_cciss_scsi_table\n", ctlr); 540 "Out of memory in adjust_cciss_scsi_table\n");
539 goto free_and_out; 541 goto free_and_out;
540 } 542 }
541 543
542 CPQ_TAPE_LOCK(ctlr, flags); 544 CPQ_TAPE_LOCK(h, flags);
543 545
544 if (hostno != -1) /* if it's not the first time... */ 546 if (hostno != -1) /* if it's not the first time... */
545 sh = hba[ctlr]->scsi_ctlr->scsi_host; 547 sh = h->scsi_ctlr->scsi_host;
546 548
547 /* find any devices in ccissscsi[] that are not in 549 /* find any devices in ccissscsi[] that are not in
548 sd[] and remove them from ccissscsi[] */ 550 sd[] and remove them from ccissscsi[] */
@@ -550,8 +552,8 @@ adjust_cciss_scsi_table(int ctlr, int hostno,
550 i = 0; 552 i = 0;
551 nremoved = 0; 553 nremoved = 0;
552 nadded = 0; 554 nadded = 0;
553 while(i<ccissscsi[ctlr].ndevices) { 555 while (i < ccissscsi[h->ctlr].ndevices) {
554 csd = &ccissscsi[ctlr].dev[i]; 556 csd = &ccissscsi[h->ctlr].dev[i];
555 found=0; 557 found=0;
556 for (j=0;j<nsds;j++) { 558 for (j=0;j<nsds;j++) {
557 if (SCSI3ADDR_EQ(sd[j].scsi3addr, 559 if (SCSI3ADDR_EQ(sd[j].scsi3addr,
@@ -566,20 +568,18 @@ adjust_cciss_scsi_table(int ctlr, int hostno,
566 568
567 if (found == 0) { /* device no longer present. */ 569 if (found == 0) { /* device no longer present. */
568 changes++; 570 changes++;
569 /* printk("cciss%d: %s device c%db%dt%dl%d removed.\n", 571 cciss_scsi_remove_entry(h, hostno, i,
570 ctlr, scsi_device_type(csd->devtype), hostno,
571 csd->bus, csd->target, csd->lun); */
572 cciss_scsi_remove_entry(ctlr, hostno, i,
573 removed, &nremoved); 572 removed, &nremoved);
574 /* remove ^^^, hence i not incremented */ 573 /* remove ^^^, hence i not incremented */
575 } else if (found == 1) { /* device is different in some way */ 574 } else if (found == 1) { /* device is different in some way */
576 changes++; 575 changes++;
577 printk("cciss%d: device c%db%dt%dl%d has changed.\n", 576 dev_info(&h->pdev->dev,
578 ctlr, hostno, csd->bus, csd->target, csd->lun); 577 "device c%db%dt%dl%d has changed.\n",
579 cciss_scsi_remove_entry(ctlr, hostno, i, 578 hostno, csd->bus, csd->target, csd->lun);
579 cciss_scsi_remove_entry(h, hostno, i,
580 removed, &nremoved); 580 removed, &nremoved);
581 /* remove ^^^, hence i not incremented */ 581 /* remove ^^^, hence i not incremented */
582 if (cciss_scsi_add_entry(ctlr, hostno, &sd[j], 582 if (cciss_scsi_add_entry(h, hostno, &sd[j],
583 added, &nadded) != 0) 583 added, &nadded) != 0)
584 /* we just removed one, so add can't fail. */ 584 /* we just removed one, so add can't fail. */
585 BUG(); 585 BUG();
@@ -601,8 +601,8 @@ adjust_cciss_scsi_table(int ctlr, int hostno,
601 601
602 for (i=0;i<nsds;i++) { 602 for (i=0;i<nsds;i++) {
603 found=0; 603 found=0;
604 for (j=0;j<ccissscsi[ctlr].ndevices;j++) { 604 for (j = 0; j < ccissscsi[h->ctlr].ndevices; j++) {
605 csd = &ccissscsi[ctlr].dev[j]; 605 csd = &ccissscsi[h->ctlr].dev[j];
606 if (SCSI3ADDR_EQ(sd[i].scsi3addr, 606 if (SCSI3ADDR_EQ(sd[i].scsi3addr,
607 csd->scsi3addr)) { 607 csd->scsi3addr)) {
608 if (device_is_the_same(&sd[i], csd)) 608 if (device_is_the_same(&sd[i], csd))
@@ -614,18 +614,18 @@ adjust_cciss_scsi_table(int ctlr, int hostno,
614 } 614 }
615 if (!found) { 615 if (!found) {
616 changes++; 616 changes++;
617 if (cciss_scsi_add_entry(ctlr, hostno, &sd[i], 617 if (cciss_scsi_add_entry(h, hostno, &sd[i],
618 added, &nadded) != 0) 618 added, &nadded) != 0)
619 break; 619 break;
620 } else if (found == 1) { 620 } else if (found == 1) {
621 /* should never happen... */ 621 /* should never happen... */
622 changes++; 622 changes++;
623 printk(KERN_WARNING "cciss%d: device " 623 dev_warn(&h->pdev->dev,
624 "unexpectedly changed\n", ctlr); 624 "device unexpectedly changed\n");
625 /* but if it does happen, we just ignore that device */ 625 /* but if it does happen, we just ignore that device */
626 } 626 }
627 } 627 }
628 CPQ_TAPE_UNLOCK(ctlr, flags); 628 CPQ_TAPE_UNLOCK(h, flags);
629 629
630 /* Don't notify scsi mid layer of any changes the first time through */ 630 /* Don't notify scsi mid layer of any changes the first time through */
631 /* (or if there are no changes) scsi_scan_host will do it later the */ 631 /* (or if there are no changes) scsi_scan_host will do it later the */
@@ -645,9 +645,9 @@ adjust_cciss_scsi_table(int ctlr, int hostno,
645 /* We don't expect to get here. */ 645 /* We don't expect to get here. */
646 /* future cmds to this device will get selection */ 646 /* future cmds to this device will get selection */
647 /* timeout as if the device was gone. */ 647 /* timeout as if the device was gone. */
648 printk(KERN_WARNING "cciss%d: didn't find " 648 dev_warn(&h->pdev->dev, "didn't find "
649 "c%db%dt%dl%d\n for removal.", 649 "c%db%dt%dl%d\n for removal.",
650 ctlr, hostno, removed[i].bus, 650 hostno, removed[i].bus,
651 removed[i].target, removed[i].lun); 651 removed[i].target, removed[i].lun);
652 } 652 }
653 } 653 }
@@ -659,13 +659,12 @@ adjust_cciss_scsi_table(int ctlr, int hostno,
659 added[i].target, added[i].lun); 659 added[i].target, added[i].lun);
660 if (rc == 0) 660 if (rc == 0)
661 continue; 661 continue;
662 printk(KERN_WARNING "cciss%d: scsi_add_device " 662 dev_warn(&h->pdev->dev, "scsi_add_device "
663 "c%db%dt%dl%d failed, device not added.\n", 663 "c%db%dt%dl%d failed, device not added.\n",
664 ctlr, hostno, 664 hostno, added[i].bus, added[i].target, added[i].lun);
665 added[i].bus, added[i].target, added[i].lun);
666 /* now we have to remove it from ccissscsi, */ 665 /* now we have to remove it from ccissscsi, */
667 /* since it didn't get added to scsi mid layer */ 666 /* since it didn't get added to scsi mid layer */
668 fixup_botched_add(ctlr, added[i].scsi3addr); 667 fixup_botched_add(h, added[i].scsi3addr);
669 } 668 }
670 669
671free_and_out: 670free_and_out:
@@ -675,33 +674,33 @@ free_and_out:
675} 674}
676 675
677static int 676static int
678lookup_scsi3addr(int ctlr, int bus, int target, int lun, char *scsi3addr) 677lookup_scsi3addr(ctlr_info_t *h, int bus, int target, int lun, char *scsi3addr)
679{ 678{
680 int i; 679 int i;
681 struct cciss_scsi_dev_t *sd; 680 struct cciss_scsi_dev_t *sd;
682 unsigned long flags; 681 unsigned long flags;
683 682
684 CPQ_TAPE_LOCK(ctlr, flags); 683 CPQ_TAPE_LOCK(h, flags);
685 for (i=0;i<ccissscsi[ctlr].ndevices;i++) { 684 for (i = 0; i < ccissscsi[h->ctlr].ndevices; i++) {
686 sd = &ccissscsi[ctlr].dev[i]; 685 sd = &ccissscsi[h->ctlr].dev[i];
687 if (sd->bus == bus && 686 if (sd->bus == bus &&
688 sd->target == target && 687 sd->target == target &&
689 sd->lun == lun) { 688 sd->lun == lun) {
690 memcpy(scsi3addr, &sd->scsi3addr[0], 8); 689 memcpy(scsi3addr, &sd->scsi3addr[0], 8);
691 CPQ_TAPE_UNLOCK(ctlr, flags); 690 CPQ_TAPE_UNLOCK(h, flags);
692 return 0; 691 return 0;
693 } 692 }
694 } 693 }
695 CPQ_TAPE_UNLOCK(ctlr, flags); 694 CPQ_TAPE_UNLOCK(h, flags);
696 return -1; 695 return -1;
697} 696}
698 697
699static void 698static void
700cciss_scsi_setup(int cntl_num) 699cciss_scsi_setup(ctlr_info_t *h)
701{ 700{
702 struct cciss_scsi_adapter_data_t * shba; 701 struct cciss_scsi_adapter_data_t * shba;
703 702
704 ccissscsi[cntl_num].ndevices = 0; 703 ccissscsi[h->ctlr].ndevices = 0;
705 shba = (struct cciss_scsi_adapter_data_t *) 704 shba = (struct cciss_scsi_adapter_data_t *)
706 kmalloc(sizeof(*shba), GFP_KERNEL); 705 kmalloc(sizeof(*shba), GFP_KERNEL);
707 if (shba == NULL) 706 if (shba == NULL)
@@ -709,35 +708,35 @@ cciss_scsi_setup(int cntl_num)
709 shba->scsi_host = NULL; 708 shba->scsi_host = NULL;
710 spin_lock_init(&shba->lock); 709 spin_lock_init(&shba->lock);
711 shba->registered = 0; 710 shba->registered = 0;
712 if (scsi_cmd_stack_setup(cntl_num, shba) != 0) { 711 if (scsi_cmd_stack_setup(h, shba) != 0) {
713 kfree(shba); 712 kfree(shba);
714 shba = NULL; 713 shba = NULL;
715 } 714 }
716 hba[cntl_num]->scsi_ctlr = shba; 715 h->scsi_ctlr = shba;
717 return; 716 return;
718} 717}
719 718
720static void 719static void complete_scsi_command(CommandList_struct *c, int timeout,
721complete_scsi_command( CommandList_struct *cp, int timeout, __u32 tag) 720 __u32 tag)
722{ 721{
723 struct scsi_cmnd *cmd; 722 struct scsi_cmnd *cmd;
724 ctlr_info_t *ctlr; 723 ctlr_info_t *h;
725 ErrorInfo_struct *ei; 724 ErrorInfo_struct *ei;
726 725
727 ei = cp->err_info; 726 ei = c->err_info;
728 727
729 /* First, see if it was a message rather than a command */ 728 /* First, see if it was a message rather than a command */
730 if (cp->Request.Type.Type == TYPE_MSG) { 729 if (c->Request.Type.Type == TYPE_MSG) {
731 cp->cmd_type = CMD_MSG_DONE; 730 c->cmd_type = CMD_MSG_DONE;
732 return; 731 return;
733 } 732 }
734 733
735 cmd = (struct scsi_cmnd *) cp->scsi_cmd; 734 cmd = (struct scsi_cmnd *) c->scsi_cmd;
736 ctlr = hba[cp->ctlr]; 735 h = hba[c->ctlr];
737 736
738 scsi_dma_unmap(cmd); 737 scsi_dma_unmap(cmd);
739 if (cp->Header.SGTotal > ctlr->max_cmd_sgentries) 738 if (c->Header.SGTotal > h->max_cmd_sgentries)
740 cciss_unmap_sg_chain_block(ctlr, cp); 739 cciss_unmap_sg_chain_block(h, c);
741 740
742 cmd->result = (DID_OK << 16); /* host byte */ 741 cmd->result = (DID_OK << 16); /* host byte */
743 cmd->result |= (COMMAND_COMPLETE << 8); /* msg byte */ 742 cmd->result |= (COMMAND_COMPLETE << 8); /* msg byte */
@@ -764,9 +763,8 @@ complete_scsi_command( CommandList_struct *cp, int timeout, __u32 tag)
764 { 763 {
765#if 0 764#if 0
766 printk(KERN_WARNING "cciss: cmd %p " 765 printk(KERN_WARNING "cciss: cmd %p "
767 "has SCSI Status = %x\n", 766 "has SCSI Status = %x\n",
768 cp, 767 c, ei->ScsiStatus);
769 ei->ScsiStatus);
770#endif 768#endif
771 cmd->result |= (ei->ScsiStatus << 1); 769 cmd->result |= (ei->ScsiStatus << 1);
772 } 770 }
@@ -786,13 +784,13 @@ complete_scsi_command( CommandList_struct *cp, int timeout, __u32 tag)
786 case CMD_DATA_UNDERRUN: /* let mid layer handle it. */ 784 case CMD_DATA_UNDERRUN: /* let mid layer handle it. */
787 break; 785 break;
788 case CMD_DATA_OVERRUN: 786 case CMD_DATA_OVERRUN:
789 printk(KERN_WARNING "cciss: cp %p has" 787 dev_warn(&h->pdev->dev, "%p has"
790 " completed with data overrun " 788 " completed with data overrun "
791 "reported\n", cp); 789 "reported\n", c);
792 break; 790 break;
793 case CMD_INVALID: { 791 case CMD_INVALID: {
794 /* print_bytes(cp, sizeof(*cp), 1, 0); 792 /* print_bytes(c, sizeof(*c), 1, 0);
795 print_cmd(cp); */ 793 print_cmd(c); */
796 /* We get CMD_INVALID if you address a non-existent tape drive instead 794 /* We get CMD_INVALID if you address a non-existent tape drive instead
797 of a selection timeout (no response). You will see this if you yank 795 of a selection timeout (no response). You will see this if you yank
798 out a tape drive, then try to access it. This is kind of a shame 796 out a tape drive, then try to access it. This is kind of a shame
@@ -802,54 +800,50 @@ complete_scsi_command( CommandList_struct *cp, int timeout, __u32 tag)
802 } 800 }
803 break; 801 break;
804 case CMD_PROTOCOL_ERR: 802 case CMD_PROTOCOL_ERR:
805 printk(KERN_WARNING "cciss: cp %p has " 803 dev_warn(&h->pdev->dev,
806 "protocol error \n", cp); 804 "%p has protocol error\n", c);
807 break; 805 break;
808 case CMD_HARDWARE_ERR: 806 case CMD_HARDWARE_ERR:
809 cmd->result = DID_ERROR << 16; 807 cmd->result = DID_ERROR << 16;
810 printk(KERN_WARNING "cciss: cp %p had " 808 dev_warn(&h->pdev->dev,
811 " hardware error\n", cp); 809 "%p had hardware error\n", c);
812 break; 810 break;
813 case CMD_CONNECTION_LOST: 811 case CMD_CONNECTION_LOST:
814 cmd->result = DID_ERROR << 16; 812 cmd->result = DID_ERROR << 16;
815 printk(KERN_WARNING "cciss: cp %p had " 813 dev_warn(&h->pdev->dev,
816 "connection lost\n", cp); 814 "%p had connection lost\n", c);
817 break; 815 break;
818 case CMD_ABORTED: 816 case CMD_ABORTED:
819 cmd->result = DID_ABORT << 16; 817 cmd->result = DID_ABORT << 16;
820 printk(KERN_WARNING "cciss: cp %p was " 818 dev_warn(&h->pdev->dev, "%p was aborted\n", c);
821 "aborted\n", cp);
822 break; 819 break;
823 case CMD_ABORT_FAILED: 820 case CMD_ABORT_FAILED:
824 cmd->result = DID_ERROR << 16; 821 cmd->result = DID_ERROR << 16;
825 printk(KERN_WARNING "cciss: cp %p reports " 822 dev_warn(&h->pdev->dev,
826 "abort failed\n", cp); 823 "%p reports abort failed\n", c);
827 break; 824 break;
828 case CMD_UNSOLICITED_ABORT: 825 case CMD_UNSOLICITED_ABORT:
829 cmd->result = DID_ABORT << 16; 826 cmd->result = DID_ABORT << 16;
830 printk(KERN_WARNING "cciss: cp %p aborted " 827 dev_warn(&h->pdev->dev, "%p aborted do to an "
831 "do to an unsolicited abort\n", cp); 828 "unsolicited abort\n", c);
832 break; 829 break;
833 case CMD_TIMEOUT: 830 case CMD_TIMEOUT:
834 cmd->result = DID_TIME_OUT << 16; 831 cmd->result = DID_TIME_OUT << 16;
835 printk(KERN_WARNING "cciss: cp %p timedout\n", 832 dev_warn(&h->pdev->dev, "%p timedout\n", c);
836 cp);
837 break; 833 break;
838 default: 834 default:
839 cmd->result = DID_ERROR << 16; 835 cmd->result = DID_ERROR << 16;
840 printk(KERN_WARNING "cciss: cp %p returned " 836 dev_warn(&h->pdev->dev,
841 "unknown status %x\n", cp, 837 "%p returned unknown status %x\n", c,
842 ei->CommandStatus); 838 ei->CommandStatus);
843 } 839 }
844 } 840 }
845 // printk("c:%p:c%db%dt%dl%d ", cmd, ctlr->ctlr, cmd->channel,
846 // cmd->target, cmd->lun);
847 cmd->scsi_done(cmd); 841 cmd->scsi_done(cmd);
848 scsi_cmd_free(ctlr, cp); 842 scsi_cmd_free(h, c);
849} 843}
850 844
851static int 845static int
852cciss_scsi_detect(int ctlr) 846cciss_scsi_detect(ctlr_info_t *h)
853{ 847{
854 struct Scsi_Host *sh; 848 struct Scsi_Host *sh;
855 int error; 849 int error;
@@ -860,15 +854,15 @@ cciss_scsi_detect(int ctlr)
860 sh->io_port = 0; // good enough? FIXME, 854 sh->io_port = 0; // good enough? FIXME,
861 sh->n_io_port = 0; // I don't think we use these two... 855 sh->n_io_port = 0; // I don't think we use these two...
862 sh->this_id = SELF_SCSI_ID; 856 sh->this_id = SELF_SCSI_ID;
863 sh->sg_tablesize = hba[ctlr]->maxsgentries; 857 sh->sg_tablesize = h->maxsgentries;
864 sh->max_cmd_len = MAX_COMMAND_SIZE; 858 sh->max_cmd_len = MAX_COMMAND_SIZE;
865 859
866 ((struct cciss_scsi_adapter_data_t *) 860 ((struct cciss_scsi_adapter_data_t *)
867 hba[ctlr]->scsi_ctlr)->scsi_host = sh; 861 h->scsi_ctlr)->scsi_host = sh;
868 sh->hostdata[0] = (unsigned long) hba[ctlr]; 862 sh->hostdata[0] = (unsigned long) h;
869 sh->irq = hba[ctlr]->intr[SIMPLE_MODE_INT]; 863 sh->irq = h->intr[SIMPLE_MODE_INT];
870 sh->unique_id = sh->irq; 864 sh->unique_id = sh->irq;
871 error = scsi_add_host(sh, &hba[ctlr]->pdev->dev); 865 error = scsi_add_host(sh, &h->pdev->dev);
872 if (error) 866 if (error)
873 goto fail_host_put; 867 goto fail_host_put;
874 scsi_scan_host(sh); 868 scsi_scan_host(sh);
@@ -882,20 +876,20 @@ cciss_scsi_detect(int ctlr)
882 876
883static void 877static void
884cciss_unmap_one(struct pci_dev *pdev, 878cciss_unmap_one(struct pci_dev *pdev,
885 CommandList_struct *cp, 879 CommandList_struct *c,
886 size_t buflen, 880 size_t buflen,
887 int data_direction) 881 int data_direction)
888{ 882{
889 u64bit addr64; 883 u64bit addr64;
890 884
891 addr64.val32.lower = cp->SG[0].Addr.lower; 885 addr64.val32.lower = c->SG[0].Addr.lower;
892 addr64.val32.upper = cp->SG[0].Addr.upper; 886 addr64.val32.upper = c->SG[0].Addr.upper;
893 pci_unmap_single(pdev, (dma_addr_t) addr64.val, buflen, data_direction); 887 pci_unmap_single(pdev, (dma_addr_t) addr64.val, buflen, data_direction);
894} 888}
895 889
896static void 890static void
897cciss_map_one(struct pci_dev *pdev, 891cciss_map_one(struct pci_dev *pdev,
898 CommandList_struct *cp, 892 CommandList_struct *c,
899 unsigned char *buf, 893 unsigned char *buf,
900 size_t buflen, 894 size_t buflen,
901 int data_direction) 895 int data_direction)
@@ -903,164 +897,149 @@ cciss_map_one(struct pci_dev *pdev,
903 __u64 addr64; 897 __u64 addr64;
904 898
905 addr64 = (__u64) pci_map_single(pdev, buf, buflen, data_direction); 899 addr64 = (__u64) pci_map_single(pdev, buf, buflen, data_direction);
906 cp->SG[0].Addr.lower = 900 c->SG[0].Addr.lower =
907 (__u32) (addr64 & (__u64) 0x00000000FFFFFFFF); 901 (__u32) (addr64 & (__u64) 0x00000000FFFFFFFF);
908 cp->SG[0].Addr.upper = 902 c->SG[0].Addr.upper =
909 (__u32) ((addr64 >> 32) & (__u64) 0x00000000FFFFFFFF); 903 (__u32) ((addr64 >> 32) & (__u64) 0x00000000FFFFFFFF);
910 cp->SG[0].Len = buflen; 904 c->SG[0].Len = buflen;
911 cp->Header.SGList = (__u8) 1; /* no. SGs contig in this cmd */ 905 c->Header.SGList = (__u8) 1; /* no. SGs contig in this cmd */
912 cp->Header.SGTotal = (__u16) 1; /* total sgs in this cmd list */ 906 c->Header.SGTotal = (__u16) 1; /* total sgs in this cmd list */
913} 907}
914 908
915static int 909static int
916cciss_scsi_do_simple_cmd(ctlr_info_t *c, 910cciss_scsi_do_simple_cmd(ctlr_info_t *h,
917 CommandList_struct *cp, 911 CommandList_struct *c,
918 unsigned char *scsi3addr, 912 unsigned char *scsi3addr,
919 unsigned char *cdb, 913 unsigned char *cdb,
920 unsigned char cdblen, 914 unsigned char cdblen,
921 unsigned char *buf, int bufsize, 915 unsigned char *buf, int bufsize,
922 int direction) 916 int direction)
923{ 917{
924 unsigned long flags;
925 DECLARE_COMPLETION_ONSTACK(wait); 918 DECLARE_COMPLETION_ONSTACK(wait);
926 919
927 cp->cmd_type = CMD_IOCTL_PEND; // treat this like an ioctl 920 c->cmd_type = CMD_IOCTL_PEND; /* treat this like an ioctl */
928 cp->scsi_cmd = NULL; 921 c->scsi_cmd = NULL;
929 cp->Header.ReplyQueue = 0; // unused in simple mode 922 c->Header.ReplyQueue = 0; /* unused in simple mode */
930 memcpy(&cp->Header.LUN, scsi3addr, sizeof(cp->Header.LUN)); 923 memcpy(&c->Header.LUN, scsi3addr, sizeof(c->Header.LUN));
931 cp->Header.Tag.lower = cp->busaddr; // Use k. address of cmd as tag 924 c->Header.Tag.lower = c->busaddr; /* Use k. address of cmd as tag */
932 // Fill in the request block... 925 // Fill in the request block...
933 926
934 /* printk("Using scsi3addr 0x%02x%0x2%0x2%0x2%0x2%0x2%0x2%0x2\n", 927 /* printk("Using scsi3addr 0x%02x%0x2%0x2%0x2%0x2%0x2%0x2%0x2\n",
935 scsi3addr[0], scsi3addr[1], scsi3addr[2], scsi3addr[3], 928 scsi3addr[0], scsi3addr[1], scsi3addr[2], scsi3addr[3],
936 scsi3addr[4], scsi3addr[5], scsi3addr[6], scsi3addr[7]); */ 929 scsi3addr[4], scsi3addr[5], scsi3addr[6], scsi3addr[7]); */
937 930
938 memset(cp->Request.CDB, 0, sizeof(cp->Request.CDB)); 931 memset(c->Request.CDB, 0, sizeof(c->Request.CDB));
939 memcpy(cp->Request.CDB, cdb, cdblen); 932 memcpy(c->Request.CDB, cdb, cdblen);
940 cp->Request.Timeout = 0; 933 c->Request.Timeout = 0;
941 cp->Request.CDBLen = cdblen; 934 c->Request.CDBLen = cdblen;
942 cp->Request.Type.Type = TYPE_CMD; 935 c->Request.Type.Type = TYPE_CMD;
943 cp->Request.Type.Attribute = ATTR_SIMPLE; 936 c->Request.Type.Attribute = ATTR_SIMPLE;
944 cp->Request.Type.Direction = direction; 937 c->Request.Type.Direction = direction;
945 938
946 /* Fill in the SG list and do dma mapping */ 939 /* Fill in the SG list and do dma mapping */
947 cciss_map_one(c->pdev, cp, (unsigned char *) buf, 940 cciss_map_one(h->pdev, c, (unsigned char *) buf,
948 bufsize, DMA_FROM_DEVICE); 941 bufsize, DMA_FROM_DEVICE);
949 942
950 cp->waiting = &wait; 943 c->waiting = &wait;
951 944 enqueue_cmd_and_start_io(h, c);
952 /* Put the request on the tail of the request queue */
953 spin_lock_irqsave(CCISS_LOCK(c->ctlr), flags);
954 addQ(&c->reqQ, cp);
955 c->Qdepth++;
956 start_io(c);
957 spin_unlock_irqrestore(CCISS_LOCK(c->ctlr), flags);
958
959 wait_for_completion(&wait); 945 wait_for_completion(&wait);
960 946
961 /* undo the dma mapping */ 947 /* undo the dma mapping */
962 cciss_unmap_one(c->pdev, cp, bufsize, DMA_FROM_DEVICE); 948 cciss_unmap_one(h->pdev, c, bufsize, DMA_FROM_DEVICE);
963 return(0); 949 return(0);
964} 950}
965 951
966static void 952static void
967cciss_scsi_interpret_error(CommandList_struct *cp) 953cciss_scsi_interpret_error(ctlr_info_t *h, CommandList_struct *c)
968{ 954{
969 ErrorInfo_struct *ei; 955 ErrorInfo_struct *ei;
970 956
971 ei = cp->err_info; 957 ei = c->err_info;
972 switch(ei->CommandStatus) 958 switch(ei->CommandStatus)
973 { 959 {
974 case CMD_TARGET_STATUS: 960 case CMD_TARGET_STATUS:
975 printk(KERN_WARNING "cciss: cmd %p has " 961 dev_warn(&h->pdev->dev,
976 "completed with errors\n", cp); 962 "cmd %p has completed with errors\n", c);
977 printk(KERN_WARNING "cciss: cmd %p " 963 dev_warn(&h->pdev->dev,
978 "has SCSI Status = %x\n", 964 "cmd %p has SCSI Status = %x\n",
979 cp, 965 c, ei->ScsiStatus);
980 ei->ScsiStatus);
981 if (ei->ScsiStatus == 0) 966 if (ei->ScsiStatus == 0)
982 printk(KERN_WARNING 967 dev_warn(&h->pdev->dev,
983 "cciss:SCSI status is abnormally zero. " 968 "SCSI status is abnormally zero. "
984 "(probably indicates selection timeout " 969 "(probably indicates selection timeout "
985 "reported incorrectly due to a known " 970 "reported incorrectly due to a known "
986 "firmware bug, circa July, 2001.)\n"); 971 "firmware bug, circa July, 2001.)\n");
987 break; 972 break;
988 case CMD_DATA_UNDERRUN: /* let mid layer handle it. */ 973 case CMD_DATA_UNDERRUN: /* let mid layer handle it. */
989 printk("UNDERRUN\n"); 974 dev_info(&h->pdev->dev, "UNDERRUN\n");
990 break; 975 break;
991 case CMD_DATA_OVERRUN: 976 case CMD_DATA_OVERRUN:
992 printk(KERN_WARNING "cciss: cp %p has" 977 dev_warn(&h->pdev->dev, "%p has"
993 " completed with data overrun " 978 " completed with data overrun "
994 "reported\n", cp); 979 "reported\n", c);
995 break; 980 break;
996 case CMD_INVALID: { 981 case CMD_INVALID: {
997 /* controller unfortunately reports SCSI passthru's */ 982 /* controller unfortunately reports SCSI passthru's */
998 /* to non-existent targets as invalid commands. */ 983 /* to non-existent targets as invalid commands. */
999 printk(KERN_WARNING "cciss: cp %p is " 984 dev_warn(&h->pdev->dev,
1000 "reported invalid (probably means " 985 "%p is reported invalid (probably means "
1001 "target device no longer present)\n", 986 "target device no longer present)\n", c);
1002 cp); 987 /* print_bytes((unsigned char *) c, sizeof(*c), 1, 0);
1003 /* print_bytes((unsigned char *) cp, sizeof(*cp), 1, 0); 988 print_cmd(c); */
1004 print_cmd(cp); */
1005 } 989 }
1006 break; 990 break;
1007 case CMD_PROTOCOL_ERR: 991 case CMD_PROTOCOL_ERR:
1008 printk(KERN_WARNING "cciss: cp %p has " 992 dev_warn(&h->pdev->dev, "%p has protocol error\n", c);
1009 "protocol error \n", cp);
1010 break; 993 break;
1011 case CMD_HARDWARE_ERR: 994 case CMD_HARDWARE_ERR:
1012 /* cmd->result = DID_ERROR << 16; */ 995 /* cmd->result = DID_ERROR << 16; */
1013 printk(KERN_WARNING "cciss: cp %p had " 996 dev_warn(&h->pdev->dev, "%p had hardware error\n", c);
1014 " hardware error\n", cp);
1015 break; 997 break;
1016 case CMD_CONNECTION_LOST: 998 case CMD_CONNECTION_LOST:
1017 printk(KERN_WARNING "cciss: cp %p had " 999 dev_warn(&h->pdev->dev, "%p had connection lost\n", c);
1018 "connection lost\n", cp);
1019 break; 1000 break;
1020 case CMD_ABORTED: 1001 case CMD_ABORTED:
1021 printk(KERN_WARNING "cciss: cp %p was " 1002 dev_warn(&h->pdev->dev, "%p was aborted\n", c);
1022 "aborted\n", cp);
1023 break; 1003 break;
1024 case CMD_ABORT_FAILED: 1004 case CMD_ABORT_FAILED:
1025 printk(KERN_WARNING "cciss: cp %p reports " 1005 dev_warn(&h->pdev->dev,
1026 "abort failed\n", cp); 1006 "%p reports abort failed\n", c);
1027 break; 1007 break;
1028 case CMD_UNSOLICITED_ABORT: 1008 case CMD_UNSOLICITED_ABORT:
1029 printk(KERN_WARNING "cciss: cp %p aborted " 1009 dev_warn(&h->pdev->dev,
1030 "do to an unsolicited abort\n", cp); 1010 "%p aborted do to an unsolicited abort\n", c);
1031 break; 1011 break;
1032 case CMD_TIMEOUT: 1012 case CMD_TIMEOUT:
1033 printk(KERN_WARNING "cciss: cp %p timedout\n", 1013 dev_warn(&h->pdev->dev, "%p timedout\n", c);
1034 cp);
1035 break; 1014 break;
1036 default: 1015 default:
1037 printk(KERN_WARNING "cciss: cp %p returned " 1016 dev_warn(&h->pdev->dev,
1038 "unknown status %x\n", cp, 1017 "%p returned unknown status %x\n",
1039 ei->CommandStatus); 1018 c, ei->CommandStatus);
1040 } 1019 }
1041} 1020}
1042 1021
1043static int 1022static int
1044cciss_scsi_do_inquiry(ctlr_info_t *c, unsigned char *scsi3addr, 1023cciss_scsi_do_inquiry(ctlr_info_t *h, unsigned char *scsi3addr,
1045 unsigned char page, unsigned char *buf, 1024 unsigned char page, unsigned char *buf,
1046 unsigned char bufsize) 1025 unsigned char bufsize)
1047{ 1026{
1048 int rc; 1027 int rc;
1049 CommandList_struct *cp; 1028 CommandList_struct *c;
1050 char cdb[6]; 1029 char cdb[6];
1051 ErrorInfo_struct *ei; 1030 ErrorInfo_struct *ei;
1052 unsigned long flags; 1031 unsigned long flags;
1053 1032
1054 spin_lock_irqsave(CCISS_LOCK(c->ctlr), flags); 1033 spin_lock_irqsave(&h->lock, flags);
1055 cp = scsi_cmd_alloc(c); 1034 c = scsi_cmd_alloc(h);
1056 spin_unlock_irqrestore(CCISS_LOCK(c->ctlr), flags); 1035 spin_unlock_irqrestore(&h->lock, flags);
1057 1036
1058 if (cp == NULL) { /* trouble... */ 1037 if (c == NULL) { /* trouble... */
1059 printk("cmd_alloc returned NULL!\n"); 1038 printk("cmd_alloc returned NULL!\n");
1060 return -1; 1039 return -1;
1061 } 1040 }
1062 1041
1063 ei = cp->err_info; 1042 ei = c->err_info;
1064 1043
1065 cdb[0] = CISS_INQUIRY; 1044 cdb[0] = CISS_INQUIRY;
1066 cdb[1] = (page != 0); 1045 cdb[1] = (page != 0);
@@ -1068,24 +1047,24 @@ cciss_scsi_do_inquiry(ctlr_info_t *c, unsigned char *scsi3addr,
1068 cdb[3] = 0; 1047 cdb[3] = 0;
1069 cdb[4] = bufsize; 1048 cdb[4] = bufsize;
1070 cdb[5] = 0; 1049 cdb[5] = 0;
1071 rc = cciss_scsi_do_simple_cmd(c, cp, scsi3addr, cdb, 1050 rc = cciss_scsi_do_simple_cmd(h, c, scsi3addr, cdb,
1072 6, buf, bufsize, XFER_READ); 1051 6, buf, bufsize, XFER_READ);
1073 1052
1074 if (rc != 0) return rc; /* something went wrong */ 1053 if (rc != 0) return rc; /* something went wrong */
1075 1054
1076 if (ei->CommandStatus != 0 && 1055 if (ei->CommandStatus != 0 &&
1077 ei->CommandStatus != CMD_DATA_UNDERRUN) { 1056 ei->CommandStatus != CMD_DATA_UNDERRUN) {
1078 cciss_scsi_interpret_error(cp); 1057 cciss_scsi_interpret_error(h, c);
1079 rc = -1; 1058 rc = -1;
1080 } 1059 }
1081 spin_lock_irqsave(CCISS_LOCK(c->ctlr), flags); 1060 spin_lock_irqsave(&h->lock, flags);
1082 scsi_cmd_free(c, cp); 1061 scsi_cmd_free(h, c);
1083 spin_unlock_irqrestore(CCISS_LOCK(c->ctlr), flags); 1062 spin_unlock_irqrestore(&h->lock, flags);
1084 return rc; 1063 return rc;
1085} 1064}
1086 1065
1087/* Get the device id from inquiry page 0x83 */ 1066/* Get the device id from inquiry page 0x83 */
1088static int cciss_scsi_get_device_id(ctlr_info_t *c, unsigned char *scsi3addr, 1067static int cciss_scsi_get_device_id(ctlr_info_t *h, unsigned char *scsi3addr,
1089 unsigned char *device_id, int buflen) 1068 unsigned char *device_id, int buflen)
1090{ 1069{
1091 int rc; 1070 int rc;
@@ -1096,7 +1075,7 @@ static int cciss_scsi_get_device_id(ctlr_info_t *c, unsigned char *scsi3addr,
1096 buf = kzalloc(64, GFP_KERNEL); 1075 buf = kzalloc(64, GFP_KERNEL);
1097 if (!buf) 1076 if (!buf)
1098 return -1; 1077 return -1;
1099 rc = cciss_scsi_do_inquiry(c, scsi3addr, 0x83, buf, 64); 1078 rc = cciss_scsi_do_inquiry(h, scsi3addr, 0x83, buf, 64);
1100 if (rc == 0) 1079 if (rc == 0)
1101 memcpy(device_id, &buf[8], buflen); 1080 memcpy(device_id, &buf[8], buflen);
1102 kfree(buf); 1081 kfree(buf);
@@ -1104,20 +1083,20 @@ static int cciss_scsi_get_device_id(ctlr_info_t *c, unsigned char *scsi3addr,
1104} 1083}
1105 1084
1106static int 1085static int
1107cciss_scsi_do_report_phys_luns(ctlr_info_t *c, 1086cciss_scsi_do_report_phys_luns(ctlr_info_t *h,
1108 ReportLunData_struct *buf, int bufsize) 1087 ReportLunData_struct *buf, int bufsize)
1109{ 1088{
1110 int rc; 1089 int rc;
1111 CommandList_struct *cp; 1090 CommandList_struct *c;
1112 unsigned char cdb[12]; 1091 unsigned char cdb[12];
1113 unsigned char scsi3addr[8]; 1092 unsigned char scsi3addr[8];
1114 ErrorInfo_struct *ei; 1093 ErrorInfo_struct *ei;
1115 unsigned long flags; 1094 unsigned long flags;
1116 1095
1117 spin_lock_irqsave(CCISS_LOCK(c->ctlr), flags); 1096 spin_lock_irqsave(&h->lock, flags);
1118 cp = scsi_cmd_alloc(c); 1097 c = scsi_cmd_alloc(h);
1119 spin_unlock_irqrestore(CCISS_LOCK(c->ctlr), flags); 1098 spin_unlock_irqrestore(&h->lock, flags);
1120 if (cp == NULL) { /* trouble... */ 1099 if (c == NULL) { /* trouble... */
1121 printk("cmd_alloc returned NULL!\n"); 1100 printk("cmd_alloc returned NULL!\n");
1122 return -1; 1101 return -1;
1123 } 1102 }
@@ -1136,27 +1115,27 @@ cciss_scsi_do_report_phys_luns(ctlr_info_t *c,
1136 cdb[10] = 0; 1115 cdb[10] = 0;
1137 cdb[11] = 0; 1116 cdb[11] = 0;
1138 1117
1139 rc = cciss_scsi_do_simple_cmd(c, cp, scsi3addr, 1118 rc = cciss_scsi_do_simple_cmd(h, c, scsi3addr,
1140 cdb, 12, 1119 cdb, 12,
1141 (unsigned char *) buf, 1120 (unsigned char *) buf,
1142 bufsize, XFER_READ); 1121 bufsize, XFER_READ);
1143 1122
1144 if (rc != 0) return rc; /* something went wrong */ 1123 if (rc != 0) return rc; /* something went wrong */
1145 1124
1146 ei = cp->err_info; 1125 ei = c->err_info;
1147 if (ei->CommandStatus != 0 && 1126 if (ei->CommandStatus != 0 &&
1148 ei->CommandStatus != CMD_DATA_UNDERRUN) { 1127 ei->CommandStatus != CMD_DATA_UNDERRUN) {
1149 cciss_scsi_interpret_error(cp); 1128 cciss_scsi_interpret_error(h, c);
1150 rc = -1; 1129 rc = -1;
1151 } 1130 }
1152 spin_lock_irqsave(CCISS_LOCK(c->ctlr), flags); 1131 spin_lock_irqsave(&h->lock, flags);
1153 scsi_cmd_free(c, cp); 1132 scsi_cmd_free(h, c);
1154 spin_unlock_irqrestore(CCISS_LOCK(c->ctlr), flags); 1133 spin_unlock_irqrestore(&h->lock, flags);
1155 return rc; 1134 return rc;
1156} 1135}
1157 1136
1158static void 1137static void
1159cciss_update_non_disk_devices(int cntl_num, int hostno) 1138cciss_update_non_disk_devices(ctlr_info_t *h, int hostno)
1160{ 1139{
1161 /* the idea here is we could get notified from /proc 1140 /* the idea here is we could get notified from /proc
1162 that some devices have changed, so we do a report 1141 that some devices have changed, so we do a report
@@ -1189,7 +1168,6 @@ cciss_update_non_disk_devices(int cntl_num, int hostno)
1189 ReportLunData_struct *ld_buff; 1168 ReportLunData_struct *ld_buff;
1190 unsigned char *inq_buff; 1169 unsigned char *inq_buff;
1191 unsigned char scsi3addr[8]; 1170 unsigned char scsi3addr[8];
1192 ctlr_info_t *c;
1193 __u32 num_luns=0; 1171 __u32 num_luns=0;
1194 unsigned char *ch; 1172 unsigned char *ch;
1195 struct cciss_scsi_dev_t *currentsd, *this_device; 1173 struct cciss_scsi_dev_t *currentsd, *this_device;
@@ -1197,7 +1175,6 @@ cciss_update_non_disk_devices(int cntl_num, int hostno)
1197 int reportlunsize = sizeof(*ld_buff) + CISS_MAX_PHYS_LUN * 8; 1175 int reportlunsize = sizeof(*ld_buff) + CISS_MAX_PHYS_LUN * 8;
1198 int i; 1176 int i;
1199 1177
1200 c = (ctlr_info_t *) hba[cntl_num];
1201 ld_buff = kzalloc(reportlunsize, GFP_KERNEL); 1178 ld_buff = kzalloc(reportlunsize, GFP_KERNEL);
1202 inq_buff = kmalloc(OBDR_TAPE_INQ_SIZE, GFP_KERNEL); 1179 inq_buff = kmalloc(OBDR_TAPE_INQ_SIZE, GFP_KERNEL);
1203 currentsd = kzalloc(sizeof(*currentsd) * 1180 currentsd = kzalloc(sizeof(*currentsd) *
@@ -1207,7 +1184,7 @@ cciss_update_non_disk_devices(int cntl_num, int hostno)
1207 goto out; 1184 goto out;
1208 } 1185 }
1209 this_device = &currentsd[CCISS_MAX_SCSI_DEVS_PER_HBA]; 1186 this_device = &currentsd[CCISS_MAX_SCSI_DEVS_PER_HBA];
1210 if (cciss_scsi_do_report_phys_luns(c, ld_buff, reportlunsize) == 0) { 1187 if (cciss_scsi_do_report_phys_luns(h, ld_buff, reportlunsize) == 0) {
1211 ch = &ld_buff->LUNListLength[0]; 1188 ch = &ld_buff->LUNListLength[0];
1212 num_luns = ((ch[0]<<24) | (ch[1]<<16) | (ch[2]<<8) | ch[3]) / 8; 1189 num_luns = ((ch[0]<<24) | (ch[1]<<16) | (ch[2]<<8) | ch[3]) / 8;
1213 if (num_luns > CISS_MAX_PHYS_LUN) { 1190 if (num_luns > CISS_MAX_PHYS_LUN) {
@@ -1231,7 +1208,7 @@ cciss_update_non_disk_devices(int cntl_num, int hostno)
1231 memset(inq_buff, 0, OBDR_TAPE_INQ_SIZE); 1208 memset(inq_buff, 0, OBDR_TAPE_INQ_SIZE);
1232 memcpy(&scsi3addr[0], &ld_buff->LUN[i][0], 8); 1209 memcpy(&scsi3addr[0], &ld_buff->LUN[i][0], 8);
1233 1210
1234 if (cciss_scsi_do_inquiry(hba[cntl_num], scsi3addr, 0, inq_buff, 1211 if (cciss_scsi_do_inquiry(h, scsi3addr, 0, inq_buff,
1235 (unsigned char) OBDR_TAPE_INQ_SIZE) != 0) 1212 (unsigned char) OBDR_TAPE_INQ_SIZE) != 0)
1236 /* Inquiry failed (msg printed already) */ 1213 /* Inquiry failed (msg printed already) */
1237 continue; /* so we will skip this device. */ 1214 continue; /* so we will skip this device. */
@@ -1249,7 +1226,7 @@ cciss_update_non_disk_devices(int cntl_num, int hostno)
1249 sizeof(this_device->revision)); 1226 sizeof(this_device->revision));
1250 memset(this_device->device_id, 0, 1227 memset(this_device->device_id, 0,
1251 sizeof(this_device->device_id)); 1228 sizeof(this_device->device_id));
1252 cciss_scsi_get_device_id(hba[cntl_num], scsi3addr, 1229 cciss_scsi_get_device_id(h, scsi3addr,
1253 this_device->device_id, sizeof(this_device->device_id)); 1230 this_device->device_id, sizeof(this_device->device_id));
1254 1231
1255 switch (this_device->devtype) 1232 switch (this_device->devtype)
@@ -1276,7 +1253,7 @@ cciss_update_non_disk_devices(int cntl_num, int hostno)
1276 case 0x08: /* medium changer */ 1253 case 0x08: /* medium changer */
1277 if (ncurrent >= CCISS_MAX_SCSI_DEVS_PER_HBA) { 1254 if (ncurrent >= CCISS_MAX_SCSI_DEVS_PER_HBA) {
1278 printk(KERN_INFO "cciss%d: %s ignored, " 1255 printk(KERN_INFO "cciss%d: %s ignored, "
1279 "too many devices.\n", cntl_num, 1256 "too many devices.\n", h->ctlr,
1280 scsi_device_type(this_device->devtype)); 1257 scsi_device_type(this_device->devtype));
1281 break; 1258 break;
1282 } 1259 }
@@ -1288,7 +1265,7 @@ cciss_update_non_disk_devices(int cntl_num, int hostno)
1288 } 1265 }
1289 } 1266 }
1290 1267
1291 adjust_cciss_scsi_table(cntl_num, hostno, currentsd, ncurrent); 1268 adjust_cciss_scsi_table(h, hostno, currentsd, ncurrent);
1292out: 1269out:
1293 kfree(inq_buff); 1270 kfree(inq_buff);
1294 kfree(ld_buff); 1271 kfree(ld_buff);
@@ -1307,12 +1284,12 @@ is_keyword(char *ptr, int len, char *verb) // Thanks to ncr53c8xx.c
1307} 1284}
1308 1285
1309static int 1286static int
1310cciss_scsi_user_command(int ctlr, int hostno, char *buffer, int length) 1287cciss_scsi_user_command(ctlr_info_t *h, int hostno, char *buffer, int length)
1311{ 1288{
1312 int arg_len; 1289 int arg_len;
1313 1290
1314 if ((arg_len = is_keyword(buffer, length, "rescan")) != 0) 1291 if ((arg_len = is_keyword(buffer, length, "rescan")) != 0)
1315 cciss_update_non_disk_devices(ctlr, hostno); 1292 cciss_update_non_disk_devices(h, hostno);
1316 else 1293 else
1317 return -EINVAL; 1294 return -EINVAL;
1318 return length; 1295 return length;
@@ -1329,20 +1306,16 @@ cciss_scsi_proc_info(struct Scsi_Host *sh,
1329{ 1306{
1330 1307
1331 int buflen, datalen; 1308 int buflen, datalen;
1332 ctlr_info_t *ci; 1309 ctlr_info_t *h;
1333 int i; 1310 int i;
1334 int cntl_num;
1335
1336 1311
1337 ci = (ctlr_info_t *) sh->hostdata[0]; 1312 h = (ctlr_info_t *) sh->hostdata[0];
1338 if (ci == NULL) /* This really shouldn't ever happen. */ 1313 if (h == NULL) /* This really shouldn't ever happen. */
1339 return -EINVAL; 1314 return -EINVAL;
1340 1315
1341 cntl_num = ci->ctlr; /* Get our index into the hba[] array */
1342
1343 if (func == 0) { /* User is reading from /proc/scsi/ciss*?/?* */ 1316 if (func == 0) { /* User is reading from /proc/scsi/ciss*?/?* */
1344 buflen = sprintf(buffer, "cciss%d: SCSI host: %d\n", 1317 buflen = sprintf(buffer, "cciss%d: SCSI host: %d\n",
1345 cntl_num, sh->host_no); 1318 h->ctlr, sh->host_no);
1346 1319
1347 /* this information is needed by apps to know which cciss 1320 /* this information is needed by apps to know which cciss
1348 device corresponds to which scsi host number without 1321 device corresponds to which scsi host number without
@@ -1352,8 +1325,9 @@ cciss_scsi_proc_info(struct Scsi_Host *sh,
1352 this info is for an app to be able to use to know how to 1325 this info is for an app to be able to use to know how to
1353 get them back in sync. */ 1326 get them back in sync. */
1354 1327
1355 for (i=0;i<ccissscsi[cntl_num].ndevices;i++) { 1328 for (i = 0; i < ccissscsi[h->ctlr].ndevices; i++) {
1356 struct cciss_scsi_dev_t *sd = &ccissscsi[cntl_num].dev[i]; 1329 struct cciss_scsi_dev_t *sd =
1330 &ccissscsi[h->ctlr].dev[i];
1357 buflen += sprintf(&buffer[buflen], "c%db%dt%dl%d %02d " 1331 buflen += sprintf(&buffer[buflen], "c%db%dt%dl%d %02d "
1358 "0x%02x%02x%02x%02x%02x%02x%02x%02x\n", 1332 "0x%02x%02x%02x%02x%02x%02x%02x%02x\n",
1359 sh->host_no, sd->bus, sd->target, sd->lun, 1333 sh->host_no, sd->bus, sd->target, sd->lun,
@@ -1371,15 +1345,15 @@ cciss_scsi_proc_info(struct Scsi_Host *sh,
1371 *start = buffer + offset; 1345 *start = buffer + offset;
1372 return(datalen); 1346 return(datalen);
1373 } else /* User is writing to /proc/scsi/cciss*?/?* ... */ 1347 } else /* User is writing to /proc/scsi/cciss*?/?* ... */
1374 return cciss_scsi_user_command(cntl_num, sh->host_no, 1348 return cciss_scsi_user_command(h, sh->host_no,
1375 buffer, length); 1349 buffer, length);
1376} 1350}
1377 1351
1378/* cciss_scatter_gather takes a struct scsi_cmnd, (cmd), and does the pci 1352/* cciss_scatter_gather takes a struct scsi_cmnd, (cmd), and does the pci
1379 dma mapping and fills in the scatter gather entries of the 1353 dma mapping and fills in the scatter gather entries of the
1380 cciss command, cp. */ 1354 cciss command, c. */
1381 1355
1382static void cciss_scatter_gather(ctlr_info_t *h, CommandList_struct *cp, 1356static void cciss_scatter_gather(ctlr_info_t *h, CommandList_struct *c,
1383 struct scsi_cmnd *cmd) 1357 struct scsi_cmnd *cmd)
1384{ 1358{
1385 unsigned int len; 1359 unsigned int len;
@@ -1393,7 +1367,7 @@ static void cciss_scatter_gather(ctlr_info_t *h, CommandList_struct *cp,
1393 1367
1394 chained = 0; 1368 chained = 0;
1395 sg_index = 0; 1369 sg_index = 0;
1396 curr_sg = cp->SG; 1370 curr_sg = c->SG;
1397 request_nsgs = scsi_dma_map(cmd); 1371 request_nsgs = scsi_dma_map(cmd);
1398 if (request_nsgs) { 1372 if (request_nsgs) {
1399 scsi_for_each_sg(cmd, sg, request_nsgs, i) { 1373 scsi_for_each_sg(cmd, sg, request_nsgs, i) {
@@ -1401,7 +1375,7 @@ static void cciss_scatter_gather(ctlr_info_t *h, CommandList_struct *cp,
1401 !chained && request_nsgs - i > 1) { 1375 !chained && request_nsgs - i > 1) {
1402 chained = 1; 1376 chained = 1;
1403 sg_index = 0; 1377 sg_index = 0;
1404 curr_sg = sa->cmd_sg_list[cp->cmdindex]; 1378 curr_sg = sa->cmd_sg_list[c->cmdindex];
1405 } 1379 }
1406 addr64 = (__u64) sg_dma_address(sg); 1380 addr64 = (__u64) sg_dma_address(sg);
1407 len = sg_dma_len(sg); 1381 len = sg_dma_len(sg);
@@ -1414,19 +1388,19 @@ static void cciss_scatter_gather(ctlr_info_t *h, CommandList_struct *cp,
1414 ++sg_index; 1388 ++sg_index;
1415 } 1389 }
1416 if (chained) 1390 if (chained)
1417 cciss_map_sg_chain_block(h, cp, 1391 cciss_map_sg_chain_block(h, c,
1418 sa->cmd_sg_list[cp->cmdindex], 1392 sa->cmd_sg_list[c->cmdindex],
1419 (request_nsgs - (h->max_cmd_sgentries - 1)) * 1393 (request_nsgs - (h->max_cmd_sgentries - 1)) *
1420 sizeof(SGDescriptor_struct)); 1394 sizeof(SGDescriptor_struct));
1421 } 1395 }
1422 /* track how many SG entries we are using */ 1396 /* track how many SG entries we are using */
1423 if (request_nsgs > h->maxSG) 1397 if (request_nsgs > h->maxSG)
1424 h->maxSG = request_nsgs; 1398 h->maxSG = request_nsgs;
1425 cp->Header.SGTotal = (__u8) request_nsgs + chained; 1399 c->Header.SGTotal = (__u8) request_nsgs + chained;
1426 if (request_nsgs > h->max_cmd_sgentries) 1400 if (request_nsgs > h->max_cmd_sgentries)
1427 cp->Header.SGList = h->max_cmd_sgentries; 1401 c->Header.SGList = h->max_cmd_sgentries;
1428 else 1402 else
1429 cp->Header.SGList = cp->Header.SGTotal; 1403 c->Header.SGList = c->Header.SGTotal;
1430 return; 1404 return;
1431} 1405}
1432 1406
@@ -1434,18 +1408,17 @@ static void cciss_scatter_gather(ctlr_info_t *h, CommandList_struct *cp,
1434static int 1408static int
1435cciss_scsi_queue_command (struct scsi_cmnd *cmd, void (* done)(struct scsi_cmnd *)) 1409cciss_scsi_queue_command (struct scsi_cmnd *cmd, void (* done)(struct scsi_cmnd *))
1436{ 1410{
1437 ctlr_info_t *c; 1411 ctlr_info_t *h;
1438 int ctlr, rc; 1412 int rc;
1439 unsigned char scsi3addr[8]; 1413 unsigned char scsi3addr[8];
1440 CommandList_struct *cp; 1414 CommandList_struct *c;
1441 unsigned long flags; 1415 unsigned long flags;
1442 1416
1443 // Get the ptr to our adapter structure (hba[i]) out of cmd->host. 1417 // Get the ptr to our adapter structure (hba[i]) out of cmd->host.
1444 // We violate cmd->host privacy here. (Is there another way?) 1418 // We violate cmd->host privacy here. (Is there another way?)
1445 c = (ctlr_info_t *) cmd->device->host->hostdata[0]; 1419 h = (ctlr_info_t *) cmd->device->host->hostdata[0];
1446 ctlr = c->ctlr;
1447 1420
1448 rc = lookup_scsi3addr(ctlr, cmd->device->channel, cmd->device->id, 1421 rc = lookup_scsi3addr(h, cmd->device->channel, cmd->device->id,
1449 cmd->device->lun, scsi3addr); 1422 cmd->device->lun, scsi3addr);
1450 if (rc != 0) { 1423 if (rc != 0) {
1451 /* the scsi nexus does not match any that we presented... */ 1424 /* the scsi nexus does not match any that we presented... */
@@ -1457,19 +1430,14 @@ cciss_scsi_queue_command (struct scsi_cmnd *cmd, void (* done)(struct scsi_cmnd
1457 return 0; 1430 return 0;
1458 } 1431 }
1459 1432
1460 /* printk("cciss_queue_command, p=%p, cmd=0x%02x, c%db%dt%dl%d\n",
1461 cmd, cmd->cmnd[0], ctlr, cmd->channel, cmd->target, cmd->lun);*/
1462 // printk("q:%p:c%db%dt%dl%d ", cmd, ctlr, cmd->channel,
1463 // cmd->target, cmd->lun);
1464
1465 /* Ok, we have a reasonable scsi nexus, so send the cmd down, and 1433 /* Ok, we have a reasonable scsi nexus, so send the cmd down, and
1466 see what the device thinks of it. */ 1434 see what the device thinks of it. */
1467 1435
1468 spin_lock_irqsave(CCISS_LOCK(ctlr), flags); 1436 spin_lock_irqsave(&h->lock, flags);
1469 cp = scsi_cmd_alloc(c); 1437 c = scsi_cmd_alloc(h);
1470 spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags); 1438 spin_unlock_irqrestore(&h->lock, flags);
1471 if (cp == NULL) { /* trouble... */ 1439 if (c == NULL) { /* trouble... */
1472 printk("scsi_cmd_alloc returned NULL!\n"); 1440 dev_warn(&h->pdev->dev, "scsi_cmd_alloc returned NULL!\n");
1473 /* FIXME: next 3 lines are -> BAD! <- */ 1441 /* FIXME: next 3 lines are -> BAD! <- */
1474 cmd->result = DID_NO_CONNECT << 16; 1442 cmd->result = DID_NO_CONNECT << 16;
1475 done(cmd); 1443 done(cmd);
@@ -1480,35 +1448,41 @@ cciss_scsi_queue_command (struct scsi_cmnd *cmd, void (* done)(struct scsi_cmnd
1480 1448
1481 cmd->scsi_done = done; // save this for use by completion code 1449 cmd->scsi_done = done; // save this for use by completion code
1482 1450
1483 // save cp in case we have to abort it 1451 /* save c in case we have to abort it */
1484 cmd->host_scribble = (unsigned char *) cp; 1452 cmd->host_scribble = (unsigned char *) c;
1485 1453
1486 cp->cmd_type = CMD_SCSI; 1454 c->cmd_type = CMD_SCSI;
1487 cp->scsi_cmd = cmd; 1455 c->scsi_cmd = cmd;
1488 cp->Header.ReplyQueue = 0; // unused in simple mode 1456 c->Header.ReplyQueue = 0; /* unused in simple mode */
1489 memcpy(&cp->Header.LUN.LunAddrBytes[0], &scsi3addr[0], 8); 1457 memcpy(&c->Header.LUN.LunAddrBytes[0], &scsi3addr[0], 8);
1490 cp->Header.Tag.lower = cp->busaddr; // Use k. address of cmd as tag 1458 c->Header.Tag.lower = c->busaddr; /* Use k. address of cmd as tag */
1491 1459
1492 // Fill in the request block... 1460 // Fill in the request block...
1493 1461
1494 cp->Request.Timeout = 0; 1462 c->Request.Timeout = 0;
1495 memset(cp->Request.CDB, 0, sizeof(cp->Request.CDB)); 1463 memset(c->Request.CDB, 0, sizeof(c->Request.CDB));
1496 BUG_ON(cmd->cmd_len > sizeof(cp->Request.CDB)); 1464 BUG_ON(cmd->cmd_len > sizeof(c->Request.CDB));
1497 cp->Request.CDBLen = cmd->cmd_len; 1465 c->Request.CDBLen = cmd->cmd_len;
1498 memcpy(cp->Request.CDB, cmd->cmnd, cmd->cmd_len); 1466 memcpy(c->Request.CDB, cmd->cmnd, cmd->cmd_len);
1499 cp->Request.Type.Type = TYPE_CMD; 1467 c->Request.Type.Type = TYPE_CMD;
1500 cp->Request.Type.Attribute = ATTR_SIMPLE; 1468 c->Request.Type.Attribute = ATTR_SIMPLE;
1501 switch(cmd->sc_data_direction) 1469 switch(cmd->sc_data_direction)
1502 { 1470 {
1503 case DMA_TO_DEVICE: cp->Request.Type.Direction = XFER_WRITE; break; 1471 case DMA_TO_DEVICE:
1504 case DMA_FROM_DEVICE: cp->Request.Type.Direction = XFER_READ; break; 1472 c->Request.Type.Direction = XFER_WRITE;
1505 case DMA_NONE: cp->Request.Type.Direction = XFER_NONE; break; 1473 break;
1474 case DMA_FROM_DEVICE:
1475 c->Request.Type.Direction = XFER_READ;
1476 break;
1477 case DMA_NONE:
1478 c->Request.Type.Direction = XFER_NONE;
1479 break;
1506 case DMA_BIDIRECTIONAL: 1480 case DMA_BIDIRECTIONAL:
1507 // This can happen if a buggy application does a scsi passthru 1481 // This can happen if a buggy application does a scsi passthru
1508 // and sets both inlen and outlen to non-zero. ( see 1482 // and sets both inlen and outlen to non-zero. ( see
1509 // ../scsi/scsi_ioctl.c:scsi_ioctl_send_command() ) 1483 // ../scsi/scsi_ioctl.c:scsi_ioctl_send_command() )
1510 1484
1511 cp->Request.Type.Direction = XFER_RSVD; 1485 c->Request.Type.Direction = XFER_RSVD;
1512 // This is technically wrong, and cciss controllers should 1486 // This is technically wrong, and cciss controllers should
1513 // reject it with CMD_INVALID, which is the most correct 1487 // reject it with CMD_INVALID, which is the most correct
1514 // response, but non-fibre backends appear to let it 1488 // response, but non-fibre backends appear to let it
@@ -1519,27 +1493,18 @@ cciss_scsi_queue_command (struct scsi_cmnd *cmd, void (* done)(struct scsi_cmnd
1519 break; 1493 break;
1520 1494
1521 default: 1495 default:
1522 printk("cciss: unknown data direction: %d\n", 1496 dev_warn(&h->pdev->dev, "unknown data direction: %d\n",
1523 cmd->sc_data_direction); 1497 cmd->sc_data_direction);
1524 BUG(); 1498 BUG();
1525 break; 1499 break;
1526 } 1500 }
1527 cciss_scatter_gather(c, cp, cmd); 1501 cciss_scatter_gather(h, c, cmd);
1528 1502 enqueue_cmd_and_start_io(h, c);
1529 /* Put the request on the tail of the request queue */
1530
1531 spin_lock_irqsave(CCISS_LOCK(ctlr), flags);
1532 addQ(&c->reqQ, cp);
1533 c->Qdepth++;
1534 start_io(c);
1535 spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags);
1536
1537 /* the cmd'll come back via intr handler in complete_scsi_command() */ 1503 /* the cmd'll come back via intr handler in complete_scsi_command() */
1538 return 0; 1504 return 0;
1539} 1505}
1540 1506
1541static void 1507static void cciss_unregister_scsi(ctlr_info_t *h)
1542cciss_unregister_scsi(int ctlr)
1543{ 1508{
1544 struct cciss_scsi_adapter_data_t *sa; 1509 struct cciss_scsi_adapter_data_t *sa;
1545 struct cciss_scsi_cmd_stack_t *stk; 1510 struct cciss_scsi_cmd_stack_t *stk;
@@ -1547,59 +1512,58 @@ cciss_unregister_scsi(int ctlr)
1547 1512
1548 /* we are being forcibly unloaded, and may not refuse. */ 1513 /* we are being forcibly unloaded, and may not refuse. */
1549 1514
1550 spin_lock_irqsave(CCISS_LOCK(ctlr), flags); 1515 spin_lock_irqsave(&h->lock, flags);
1551 sa = hba[ctlr]->scsi_ctlr; 1516 sa = h->scsi_ctlr;
1552 stk = &sa->cmd_stack; 1517 stk = &sa->cmd_stack;
1553 1518
1554 /* if we weren't ever actually registered, don't unregister */ 1519 /* if we weren't ever actually registered, don't unregister */
1555 if (sa->registered) { 1520 if (sa->registered) {
1556 spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags); 1521 spin_unlock_irqrestore(&h->lock, flags);
1557 scsi_remove_host(sa->scsi_host); 1522 scsi_remove_host(sa->scsi_host);
1558 scsi_host_put(sa->scsi_host); 1523 scsi_host_put(sa->scsi_host);
1559 spin_lock_irqsave(CCISS_LOCK(ctlr), flags); 1524 spin_lock_irqsave(&h->lock, flags);
1560 } 1525 }
1561 1526
1562 /* set scsi_host to NULL so our detect routine will 1527 /* set scsi_host to NULL so our detect routine will
1563 find us on register */ 1528 find us on register */
1564 sa->scsi_host = NULL; 1529 sa->scsi_host = NULL;
1565 spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags); 1530 spin_unlock_irqrestore(&h->lock, flags);
1566 scsi_cmd_stack_free(ctlr); 1531 scsi_cmd_stack_free(h);
1567 kfree(sa); 1532 kfree(sa);
1568} 1533}
1569 1534
1570static int 1535static int cciss_engage_scsi(ctlr_info_t *h)
1571cciss_engage_scsi(int ctlr)
1572{ 1536{
1573 struct cciss_scsi_adapter_data_t *sa; 1537 struct cciss_scsi_adapter_data_t *sa;
1574 struct cciss_scsi_cmd_stack_t *stk; 1538 struct cciss_scsi_cmd_stack_t *stk;
1575 unsigned long flags; 1539 unsigned long flags;
1576 1540
1577 spin_lock_irqsave(CCISS_LOCK(ctlr), flags); 1541 spin_lock_irqsave(&h->lock, flags);
1578 sa = hba[ctlr]->scsi_ctlr; 1542 sa = h->scsi_ctlr;
1579 stk = &sa->cmd_stack; 1543 stk = &sa->cmd_stack;
1580 1544
1581 if (sa->registered) { 1545 if (sa->registered) {
1582 printk("cciss%d: SCSI subsystem already engaged.\n", ctlr); 1546 dev_info(&h->pdev->dev, "SCSI subsystem already engaged.\n");
1583 spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags); 1547 spin_unlock_irqrestore(&h->lock, flags);
1584 return -ENXIO; 1548 return -ENXIO;
1585 } 1549 }
1586 sa->registered = 1; 1550 sa->registered = 1;
1587 spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags); 1551 spin_unlock_irqrestore(&h->lock, flags);
1588 cciss_update_non_disk_devices(ctlr, -1); 1552 cciss_update_non_disk_devices(h, -1);
1589 cciss_scsi_detect(ctlr); 1553 cciss_scsi_detect(h);
1590 return 0; 1554 return 0;
1591} 1555}
1592 1556
1593static void 1557static void
1594cciss_seq_tape_report(struct seq_file *seq, int ctlr) 1558cciss_seq_tape_report(struct seq_file *seq, ctlr_info_t *h)
1595{ 1559{
1596 unsigned long flags; 1560 unsigned long flags;
1597 1561
1598 CPQ_TAPE_LOCK(ctlr, flags); 1562 CPQ_TAPE_LOCK(h, flags);
1599 seq_printf(seq, 1563 seq_printf(seq,
1600 "Sequential access devices: %d\n\n", 1564 "Sequential access devices: %d\n\n",
1601 ccissscsi[ctlr].ndevices); 1565 ccissscsi[h->ctlr].ndevices);
1602 CPQ_TAPE_UNLOCK(ctlr, flags); 1566 CPQ_TAPE_UNLOCK(h, flags);
1603} 1567}
1604 1568
1605static int wait_for_device_to_become_ready(ctlr_info_t *h, 1569static int wait_for_device_to_become_ready(ctlr_info_t *h,
@@ -1610,10 +1574,10 @@ static int wait_for_device_to_become_ready(ctlr_info_t *h,
1610 int waittime = HZ; 1574 int waittime = HZ;
1611 CommandList_struct *c; 1575 CommandList_struct *c;
1612 1576
1613 c = cmd_alloc(h, 1); 1577 c = cmd_alloc(h);
1614 if (!c) { 1578 if (!c) {
1615 printk(KERN_WARNING "cciss%d: out of memory in " 1579 dev_warn(&h->pdev->dev, "out of memory in "
1616 "wait_for_device_to_become_ready.\n", h->ctlr); 1580 "wait_for_device_to_become_ready.\n");
1617 return IO_ERROR; 1581 return IO_ERROR;
1618 } 1582 }
1619 1583
@@ -1631,7 +1595,7 @@ static int wait_for_device_to_become_ready(ctlr_info_t *h,
1631 waittime = waittime * 2; 1595 waittime = waittime * 2;
1632 1596
1633 /* Send the Test Unit Ready */ 1597 /* Send the Test Unit Ready */
1634 rc = fill_cmd(c, TEST_UNIT_READY, h->ctlr, NULL, 0, 0, 1598 rc = fill_cmd(h, c, TEST_UNIT_READY, NULL, 0, 0,
1635 lunaddr, TYPE_CMD); 1599 lunaddr, TYPE_CMD);
1636 if (rc == 0) 1600 if (rc == 0)
1637 rc = sendcmd_withirq_core(h, c, 0); 1601 rc = sendcmd_withirq_core(h, c, 0);
@@ -1657,18 +1621,18 @@ static int wait_for_device_to_become_ready(ctlr_info_t *h,
1657 } 1621 }
1658 } 1622 }
1659retry_tur: 1623retry_tur:
1660 printk(KERN_WARNING "cciss%d: Waiting %d secs " 1624 dev_warn(&h->pdev->dev, "Waiting %d secs "
1661 "for device to become ready.\n", 1625 "for device to become ready.\n",
1662 h->ctlr, waittime / HZ); 1626 waittime / HZ);
1663 rc = 1; /* device not ready. */ 1627 rc = 1; /* device not ready. */
1664 } 1628 }
1665 1629
1666 if (rc) 1630 if (rc)
1667 printk("cciss%d: giving up on device.\n", h->ctlr); 1631 dev_warn(&h->pdev->dev, "giving up on device.\n");
1668 else 1632 else
1669 printk(KERN_WARNING "cciss%d: device is ready.\n", h->ctlr); 1633 dev_warn(&h->pdev->dev, "device is ready.\n");
1670 1634
1671 cmd_free(h, c, 1); 1635 cmd_free(h, c);
1672 return rc; 1636 return rc;
1673} 1637}
1674 1638
@@ -1688,26 +1652,24 @@ static int cciss_eh_device_reset_handler(struct scsi_cmnd *scsicmd)
1688 int rc; 1652 int rc;
1689 CommandList_struct *cmd_in_trouble; 1653 CommandList_struct *cmd_in_trouble;
1690 unsigned char lunaddr[8]; 1654 unsigned char lunaddr[8];
1691 ctlr_info_t *c; 1655 ctlr_info_t *h;
1692 int ctlr;
1693 1656
1694 /* find the controller to which the command to be aborted was sent */ 1657 /* find the controller to which the command to be aborted was sent */
1695 c = (ctlr_info_t *) scsicmd->device->host->hostdata[0]; 1658 h = (ctlr_info_t *) scsicmd->device->host->hostdata[0];
1696 if (c == NULL) /* paranoia */ 1659 if (h == NULL) /* paranoia */
1697 return FAILED; 1660 return FAILED;
1698 ctlr = c->ctlr; 1661 dev_warn(&h->pdev->dev, "resetting tape drive or medium changer.\n");
1699 printk(KERN_WARNING "cciss%d: resetting tape drive or medium changer.\n", ctlr);
1700 /* find the command that's giving us trouble */ 1662 /* find the command that's giving us trouble */
1701 cmd_in_trouble = (CommandList_struct *) scsicmd->host_scribble; 1663 cmd_in_trouble = (CommandList_struct *) scsicmd->host_scribble;
1702 if (cmd_in_trouble == NULL) /* paranoia */ 1664 if (cmd_in_trouble == NULL) /* paranoia */
1703 return FAILED; 1665 return FAILED;
1704 memcpy(lunaddr, &cmd_in_trouble->Header.LUN.LunAddrBytes[0], 8); 1666 memcpy(lunaddr, &cmd_in_trouble->Header.LUN.LunAddrBytes[0], 8);
1705 /* send a reset to the SCSI LUN which the command was sent to */ 1667 /* send a reset to the SCSI LUN which the command was sent to */
1706 rc = sendcmd_withirq(CCISS_RESET_MSG, ctlr, NULL, 0, 0, lunaddr, 1668 rc = sendcmd_withirq(h, CCISS_RESET_MSG, NULL, 0, 0, lunaddr,
1707 TYPE_MSG); 1669 TYPE_MSG);
1708 if (rc == 0 && wait_for_device_to_become_ready(c, lunaddr) == 0) 1670 if (rc == 0 && wait_for_device_to_become_ready(h, lunaddr) == 0)
1709 return SUCCESS; 1671 return SUCCESS;
1710 printk(KERN_WARNING "cciss%d: resetting device failed.\n", ctlr); 1672 dev_warn(&h->pdev->dev, "resetting device failed.\n");
1711 return FAILED; 1673 return FAILED;
1712} 1674}
1713 1675
@@ -1716,22 +1678,20 @@ static int cciss_eh_abort_handler(struct scsi_cmnd *scsicmd)
1716 int rc; 1678 int rc;
1717 CommandList_struct *cmd_to_abort; 1679 CommandList_struct *cmd_to_abort;
1718 unsigned char lunaddr[8]; 1680 unsigned char lunaddr[8];
1719 ctlr_info_t *c; 1681 ctlr_info_t *h;
1720 int ctlr;
1721 1682
1722 /* find the controller to which the command to be aborted was sent */ 1683 /* find the controller to which the command to be aborted was sent */
1723 c = (ctlr_info_t *) scsicmd->device->host->hostdata[0]; 1684 h = (ctlr_info_t *) scsicmd->device->host->hostdata[0];
1724 if (c == NULL) /* paranoia */ 1685 if (h == NULL) /* paranoia */
1725 return FAILED; 1686 return FAILED;
1726 ctlr = c->ctlr; 1687 dev_warn(&h->pdev->dev, "aborting tardy SCSI cmd\n");
1727 printk(KERN_WARNING "cciss%d: aborting tardy SCSI cmd\n", ctlr);
1728 1688
1729 /* find the command to be aborted */ 1689 /* find the command to be aborted */
1730 cmd_to_abort = (CommandList_struct *) scsicmd->host_scribble; 1690 cmd_to_abort = (CommandList_struct *) scsicmd->host_scribble;
1731 if (cmd_to_abort == NULL) /* paranoia */ 1691 if (cmd_to_abort == NULL) /* paranoia */
1732 return FAILED; 1692 return FAILED;
1733 memcpy(lunaddr, &cmd_to_abort->Header.LUN.LunAddrBytes[0], 8); 1693 memcpy(lunaddr, &cmd_to_abort->Header.LUN.LunAddrBytes[0], 8);
1734 rc = sendcmd_withirq(CCISS_ABORT_MSG, ctlr, &cmd_to_abort->Header.Tag, 1694 rc = sendcmd_withirq(h, CCISS_ABORT_MSG, &cmd_to_abort->Header.Tag,
1735 0, 0, lunaddr, TYPE_MSG); 1695 0, 0, lunaddr, TYPE_MSG);
1736 if (rc == 0) 1696 if (rc == 0)
1737 return SUCCESS; 1697 return SUCCESS;
diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
index abb4ec6690fc..d53b0291c44b 100644
--- a/drivers/block/cpqarray.c
+++ b/drivers/block/cpqarray.c
@@ -35,6 +35,7 @@
35#include <linux/seq_file.h> 35#include <linux/seq_file.h>
36#include <linux/init.h> 36#include <linux/init.h>
37#include <linux/hdreg.h> 37#include <linux/hdreg.h>
38#include <linux/smp_lock.h>
38#include <linux/spinlock.h> 39#include <linux/spinlock.h>
39#include <linux/blkdev.h> 40#include <linux/blkdev.h>
40#include <linux/genhd.h> 41#include <linux/genhd.h>
@@ -157,7 +158,7 @@ static int sendcmd(
157 unsigned int blkcnt, 158 unsigned int blkcnt,
158 unsigned int log_unit ); 159 unsigned int log_unit );
159 160
160static int ida_open(struct block_device *bdev, fmode_t mode); 161static int ida_unlocked_open(struct block_device *bdev, fmode_t mode);
161static int ida_release(struct gendisk *disk, fmode_t mode); 162static int ida_release(struct gendisk *disk, fmode_t mode);
162static int ida_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, unsigned long arg); 163static int ida_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, unsigned long arg);
163static int ida_getgeo(struct block_device *bdev, struct hd_geometry *geo); 164static int ida_getgeo(struct block_device *bdev, struct hd_geometry *geo);
@@ -195,9 +196,9 @@ static inline ctlr_info_t *get_host(struct gendisk *disk)
195 196
196static const struct block_device_operations ida_fops = { 197static const struct block_device_operations ida_fops = {
197 .owner = THIS_MODULE, 198 .owner = THIS_MODULE,
198 .open = ida_open, 199 .open = ida_unlocked_open,
199 .release = ida_release, 200 .release = ida_release,
200 .locked_ioctl = ida_ioctl, 201 .ioctl = ida_ioctl,
201 .getgeo = ida_getgeo, 202 .getgeo = ida_getgeo,
202 .revalidate_disk= ida_revalidate, 203 .revalidate_disk= ida_revalidate,
203}; 204};
@@ -840,13 +841,29 @@ static int ida_open(struct block_device *bdev, fmode_t mode)
840 return 0; 841 return 0;
841} 842}
842 843
844static int ida_unlocked_open(struct block_device *bdev, fmode_t mode)
845{
846 int ret;
847
848 lock_kernel();
849 ret = ida_open(bdev, mode);
850 unlock_kernel();
851
852 return ret;
853}
854
843/* 855/*
844 * Close. Sync first. 856 * Close. Sync first.
845 */ 857 */
846static int ida_release(struct gendisk *disk, fmode_t mode) 858static int ida_release(struct gendisk *disk, fmode_t mode)
847{ 859{
848 ctlr_info_t *host = get_host(disk); 860 ctlr_info_t *host;
861
862 lock_kernel();
863 host = get_host(disk);
849 host->usage_count--; 864 host->usage_count--;
865 unlock_kernel();
866
850 return 0; 867 return 0;
851} 868}
852 869
@@ -1128,7 +1145,7 @@ static int ida_getgeo(struct block_device *bdev, struct hd_geometry *geo)
1128 * ida_ioctl does some miscellaneous stuff like reporting drive geometry, 1145 * ida_ioctl does some miscellaneous stuff like reporting drive geometry,
1129 * setting readahead and submitting commands from userspace to the controller. 1146 * setting readahead and submitting commands from userspace to the controller.
1130 */ 1147 */
1131static int ida_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, unsigned long arg) 1148static int ida_locked_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, unsigned long arg)
1132{ 1149{
1133 drv_info_t *drv = get_drv(bdev->bd_disk); 1150 drv_info_t *drv = get_drv(bdev->bd_disk);
1134 ctlr_info_t *host = get_host(bdev->bd_disk); 1151 ctlr_info_t *host = get_host(bdev->bd_disk);
@@ -1162,7 +1179,8 @@ out_passthru:
1162 return error; 1179 return error;
1163 case IDAGETCTLRSIG: 1180 case IDAGETCTLRSIG:
1164 if (!arg) return -EINVAL; 1181 if (!arg) return -EINVAL;
1165 put_user(host->ctlr_sig, (int __user *)arg); 1182 if (put_user(host->ctlr_sig, (int __user *)arg))
1183 return -EFAULT;
1166 return 0; 1184 return 0;
1167 case IDAREVALIDATEVOLS: 1185 case IDAREVALIDATEVOLS:
1168 if (MINOR(bdev->bd_dev) != 0) 1186 if (MINOR(bdev->bd_dev) != 0)
@@ -1170,7 +1188,8 @@ out_passthru:
1170 return revalidate_allvol(host); 1188 return revalidate_allvol(host);
1171 case IDADRIVERVERSION: 1189 case IDADRIVERVERSION:
1172 if (!arg) return -EINVAL; 1190 if (!arg) return -EINVAL;
1173 put_user(DRIVER_VERSION, (unsigned long __user *)arg); 1191 if (put_user(DRIVER_VERSION, (unsigned long __user *)arg))
1192 return -EFAULT;
1174 return 0; 1193 return 0;
1175 case IDAGETPCIINFO: 1194 case IDAGETPCIINFO:
1176 { 1195 {
@@ -1192,6 +1211,19 @@ out_passthru:
1192 } 1211 }
1193 1212
1194} 1213}
1214
1215static int ida_ioctl(struct block_device *bdev, fmode_t mode,
1216 unsigned int cmd, unsigned long param)
1217{
1218 int ret;
1219
1220 lock_kernel();
1221 ret = ida_locked_ioctl(bdev, mode, cmd, param);
1222 unlock_kernel();
1223
1224 return ret;
1225}
1226
1195/* 1227/*
1196 * ida_ctlr_ioctl is for passing commands to the controller from userspace. 1228 * ida_ctlr_ioctl is for passing commands to the controller from userspace.
1197 * The command block (io) has already been copied to kernel space for us, 1229 * The command block (io) has already been copied to kernel space for us,
@@ -1225,17 +1257,11 @@ static int ida_ctlr_ioctl(ctlr_info_t *h, int dsk, ida_ioctl_t *io)
1225 /* Pre submit processing */ 1257 /* Pre submit processing */
1226 switch(io->cmd) { 1258 switch(io->cmd) {
1227 case PASSTHRU_A: 1259 case PASSTHRU_A:
1228 p = kmalloc(io->sg[0].size, GFP_KERNEL); 1260 p = memdup_user(io->sg[0].addr, io->sg[0].size);
1229 if (!p) 1261 if (IS_ERR(p)) {
1230 { 1262 error = PTR_ERR(p);
1231 error = -ENOMEM; 1263 cmd_free(h, c, 0);
1232 cmd_free(h, c, 0); 1264 return error;
1233 return(error);
1234 }
1235 if (copy_from_user(p, io->sg[0].addr, io->sg[0].size)) {
1236 kfree(p);
1237 cmd_free(h, c, 0);
1238 return -EFAULT;
1239 } 1265 }
1240 c->req.hdr.blk = pci_map_single(h->pci_dev, &(io->c), 1266 c->req.hdr.blk = pci_map_single(h->pci_dev, &(io->c),
1241 sizeof(ida_ioctl_t), 1267 sizeof(ida_ioctl_t),
@@ -1266,18 +1292,12 @@ static int ida_ctlr_ioctl(ctlr_info_t *h, int dsk, ida_ioctl_t *io)
1266 case DIAG_PASS_THRU: 1292 case DIAG_PASS_THRU:
1267 case COLLECT_BUFFER: 1293 case COLLECT_BUFFER:
1268 case WRITE_FLASH_ROM: 1294 case WRITE_FLASH_ROM:
1269 p = kmalloc(io->sg[0].size, GFP_KERNEL); 1295 p = memdup_user(io->sg[0].addr, io->sg[0].size);
1270 if (!p) 1296 if (IS_ERR(p)) {
1271 { 1297 error = PTR_ERR(p);
1272 error = -ENOMEM; 1298 cmd_free(h, c, 0);
1273 cmd_free(h, c, 0); 1299 return error;
1274 return(error);
1275 } 1300 }
1276 if (copy_from_user(p, io->sg[0].addr, io->sg[0].size)) {
1277 kfree(p);
1278 cmd_free(h, c, 0);
1279 return -EFAULT;
1280 }
1281 c->req.sg[0].size = io->sg[0].size; 1301 c->req.sg[0].size = io->sg[0].size;
1282 c->req.sg[0].addr = pci_map_single(h->pci_dev, p, 1302 c->req.sg[0].addr = pci_map_single(h->pci_dev, p,
1283 c->req.sg[0].size, PCI_DMA_BIDIRECTIONAL); 1303 c->req.sg[0].size, PCI_DMA_BIDIRECTIONAL);
diff --git a/drivers/block/drbd/drbd_actlog.c b/drivers/block/drbd/drbd_actlog.c
index df018990c422..9400845d602e 100644
--- a/drivers/block/drbd/drbd_actlog.c
+++ b/drivers/block/drbd/drbd_actlog.c
@@ -79,8 +79,8 @@ static int _drbd_md_sync_page_io(struct drbd_conf *mdev,
79 md_io.error = 0; 79 md_io.error = 0;
80 80
81 if ((rw & WRITE) && !test_bit(MD_NO_BARRIER, &mdev->flags)) 81 if ((rw & WRITE) && !test_bit(MD_NO_BARRIER, &mdev->flags))
82 rw |= (1 << BIO_RW_BARRIER); 82 rw |= REQ_HARDBARRIER;
83 rw |= ((1<<BIO_RW_UNPLUG) | (1<<BIO_RW_SYNCIO)); 83 rw |= REQ_UNPLUG | REQ_SYNC;
84 84
85 retry: 85 retry:
86 bio = bio_alloc(GFP_NOIO, 1); 86 bio = bio_alloc(GFP_NOIO, 1);
@@ -103,11 +103,11 @@ static int _drbd_md_sync_page_io(struct drbd_conf *mdev,
103 /* check for unsupported barrier op. 103 /* check for unsupported barrier op.
104 * would rather check on EOPNOTSUPP, but that is not reliable. 104 * would rather check on EOPNOTSUPP, but that is not reliable.
105 * don't try again for ANY return value != 0 */ 105 * don't try again for ANY return value != 0 */
106 if (unlikely(bio_rw_flagged(bio, BIO_RW_BARRIER) && !ok)) { 106 if (unlikely((bio->bi_rw & REQ_HARDBARRIER) && !ok)) {
107 /* Try again with no barrier */ 107 /* Try again with no barrier */
108 dev_warn(DEV, "Barriers not supported on meta data device - disabling\n"); 108 dev_warn(DEV, "Barriers not supported on meta data device - disabling\n");
109 set_bit(MD_NO_BARRIER, &mdev->flags); 109 set_bit(MD_NO_BARRIER, &mdev->flags);
110 rw &= ~(1 << BIO_RW_BARRIER); 110 rw &= ~REQ_HARDBARRIER;
111 bio_put(bio); 111 bio_put(bio);
112 goto retry; 112 goto retry;
113 } 113 }
diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
index 485ed8c7d623..352441b0f92f 100644
--- a/drivers/block/drbd/drbd_int.h
+++ b/drivers/block/drbd/drbd_int.h
@@ -550,12 +550,6 @@ struct p_delay_probe {
550 u32 offset; /* usecs the probe got sent after the reference time point */ 550 u32 offset; /* usecs the probe got sent after the reference time point */
551} __packed; 551} __packed;
552 552
553struct delay_probe {
554 struct list_head list;
555 unsigned int seq_num;
556 struct timeval time;
557};
558
559/* DCBP: Drbd Compressed Bitmap Packet ... */ 553/* DCBP: Drbd Compressed Bitmap Packet ... */
560static inline enum drbd_bitmap_code 554static inline enum drbd_bitmap_code
561DCBP_get_code(struct p_compressed_bm *p) 555DCBP_get_code(struct p_compressed_bm *p)
@@ -942,11 +936,9 @@ struct drbd_conf {
942 unsigned int ko_count; 936 unsigned int ko_count;
943 struct drbd_work resync_work, 937 struct drbd_work resync_work,
944 unplug_work, 938 unplug_work,
945 md_sync_work, 939 md_sync_work;
946 delay_probe_work;
947 struct timer_list resync_timer; 940 struct timer_list resync_timer;
948 struct timer_list md_sync_timer; 941 struct timer_list md_sync_timer;
949 struct timer_list delay_probe_timer;
950 942
951 /* Used after attach while negotiating new disk state. */ 943 /* Used after attach while negotiating new disk state. */
952 union drbd_state new_state_tmp; 944 union drbd_state new_state_tmp;
@@ -1062,12 +1054,6 @@ struct drbd_conf {
1062 u64 ed_uuid; /* UUID of the exposed data */ 1054 u64 ed_uuid; /* UUID of the exposed data */
1063 struct mutex state_mutex; 1055 struct mutex state_mutex;
1064 char congestion_reason; /* Why we where congested... */ 1056 char congestion_reason; /* Why we where congested... */
1065 struct list_head delay_probes; /* protected by peer_seq_lock */
1066 int data_delay; /* Delay of packets on the data-sock behind meta-sock */
1067 unsigned int delay_seq; /* To generate sequence numbers of delay probes */
1068 struct timeval dps_time; /* delay-probes-start-time */
1069 unsigned int dp_volume_last; /* send_cnt of last delay probe */
1070 int c_sync_rate; /* current resync rate after delay_probe magic */
1071}; 1057};
1072 1058
1073static inline struct drbd_conf *minor_to_mdev(unsigned int minor) 1059static inline struct drbd_conf *minor_to_mdev(unsigned int minor)
diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
index 7258c95e895e..fa650dd85b90 100644
--- a/drivers/block/drbd/drbd_main.c
+++ b/drivers/block/drbd/drbd_main.c
@@ -2184,43 +2184,6 @@ int drbd_send_ov_request(struct drbd_conf *mdev, sector_t sector, int size)
2184 return ok; 2184 return ok;
2185} 2185}
2186 2186
2187static int drbd_send_delay_probe(struct drbd_conf *mdev, struct drbd_socket *ds)
2188{
2189 struct p_delay_probe dp;
2190 int offset, ok = 0;
2191 struct timeval now;
2192
2193 mutex_lock(&ds->mutex);
2194 if (likely(ds->socket)) {
2195 do_gettimeofday(&now);
2196 offset = now.tv_usec - mdev->dps_time.tv_usec +
2197 (now.tv_sec - mdev->dps_time.tv_sec) * 1000000;
2198 dp.seq_num = cpu_to_be32(mdev->delay_seq);
2199 dp.offset = cpu_to_be32(offset);
2200
2201 ok = _drbd_send_cmd(mdev, ds->socket, P_DELAY_PROBE,
2202 (struct p_header *)&dp, sizeof(dp), 0);
2203 }
2204 mutex_unlock(&ds->mutex);
2205
2206 return ok;
2207}
2208
2209static int drbd_send_delay_probes(struct drbd_conf *mdev)
2210{
2211 int ok;
2212
2213 mdev->delay_seq++;
2214 do_gettimeofday(&mdev->dps_time);
2215 ok = drbd_send_delay_probe(mdev, &mdev->meta);
2216 ok = ok && drbd_send_delay_probe(mdev, &mdev->data);
2217
2218 mdev->dp_volume_last = mdev->send_cnt;
2219 mod_timer(&mdev->delay_probe_timer, jiffies + mdev->sync_conf.dp_interval * HZ / 10);
2220
2221 return ok;
2222}
2223
2224/* called on sndtimeo 2187/* called on sndtimeo
2225 * returns FALSE if we should retry, 2188 * returns FALSE if we should retry,
2226 * TRUE if we think connection is dead 2189 * TRUE if we think connection is dead
@@ -2369,31 +2332,6 @@ static int _drbd_send_zc_ee(struct drbd_conf *mdev, struct drbd_epoch_entry *e)
2369 return 1; 2332 return 1;
2370} 2333}
2371 2334
2372static void consider_delay_probes(struct drbd_conf *mdev)
2373{
2374 if (mdev->state.conn != C_SYNC_SOURCE || mdev->agreed_pro_version < 93)
2375 return;
2376
2377 if (mdev->dp_volume_last + mdev->sync_conf.dp_volume * 2 < mdev->send_cnt)
2378 drbd_send_delay_probes(mdev);
2379}
2380
2381static int w_delay_probes(struct drbd_conf *mdev, struct drbd_work *w, int cancel)
2382{
2383 if (!cancel && mdev->state.conn == C_SYNC_SOURCE)
2384 drbd_send_delay_probes(mdev);
2385
2386 return 1;
2387}
2388
2389static void delay_probe_timer_fn(unsigned long data)
2390{
2391 struct drbd_conf *mdev = (struct drbd_conf *) data;
2392
2393 if (list_empty(&mdev->delay_probe_work.list))
2394 drbd_queue_work(&mdev->data.work, &mdev->delay_probe_work);
2395}
2396
2397/* Used to send write requests 2335/* Used to send write requests
2398 * R_PRIMARY -> Peer (P_DATA) 2336 * R_PRIMARY -> Peer (P_DATA)
2399 */ 2337 */
@@ -2425,15 +2363,15 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
2425 /* NOTE: no need to check if barriers supported here as we would 2363 /* NOTE: no need to check if barriers supported here as we would
2426 * not pass the test in make_request_common in that case 2364 * not pass the test in make_request_common in that case
2427 */ 2365 */
2428 if (bio_rw_flagged(req->master_bio, BIO_RW_BARRIER)) { 2366 if (req->master_bio->bi_rw & REQ_HARDBARRIER) {
2429 dev_err(DEV, "ASSERT FAILED would have set DP_HARDBARRIER\n"); 2367 dev_err(DEV, "ASSERT FAILED would have set DP_HARDBARRIER\n");
2430 /* dp_flags |= DP_HARDBARRIER; */ 2368 /* dp_flags |= DP_HARDBARRIER; */
2431 } 2369 }
2432 if (bio_rw_flagged(req->master_bio, BIO_RW_SYNCIO)) 2370 if (req->master_bio->bi_rw & REQ_SYNC)
2433 dp_flags |= DP_RW_SYNC; 2371 dp_flags |= DP_RW_SYNC;
2434 /* for now handle SYNCIO and UNPLUG 2372 /* for now handle SYNCIO and UNPLUG
2435 * as if they still were one and the same flag */ 2373 * as if they still were one and the same flag */
2436 if (bio_rw_flagged(req->master_bio, BIO_RW_UNPLUG)) 2374 if (req->master_bio->bi_rw & REQ_UNPLUG)
2437 dp_flags |= DP_RW_SYNC; 2375 dp_flags |= DP_RW_SYNC;
2438 if (mdev->state.conn >= C_SYNC_SOURCE && 2376 if (mdev->state.conn >= C_SYNC_SOURCE &&
2439 mdev->state.conn <= C_PAUSED_SYNC_T) 2377 mdev->state.conn <= C_PAUSED_SYNC_T)
@@ -2457,9 +2395,6 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
2457 2395
2458 drbd_put_data_sock(mdev); 2396 drbd_put_data_sock(mdev);
2459 2397
2460 if (ok)
2461 consider_delay_probes(mdev);
2462
2463 return ok; 2398 return ok;
2464} 2399}
2465 2400
@@ -2506,9 +2441,6 @@ int drbd_send_block(struct drbd_conf *mdev, enum drbd_packets cmd,
2506 2441
2507 drbd_put_data_sock(mdev); 2442 drbd_put_data_sock(mdev);
2508 2443
2509 if (ok)
2510 consider_delay_probes(mdev);
2511
2512 return ok; 2444 return ok;
2513} 2445}
2514 2446
@@ -2604,6 +2536,7 @@ static int drbd_open(struct block_device *bdev, fmode_t mode)
2604 unsigned long flags; 2536 unsigned long flags;
2605 int rv = 0; 2537 int rv = 0;
2606 2538
2539 lock_kernel();
2607 spin_lock_irqsave(&mdev->req_lock, flags); 2540 spin_lock_irqsave(&mdev->req_lock, flags);
2608 /* to have a stable mdev->state.role 2541 /* to have a stable mdev->state.role
2609 * and no race with updating open_cnt */ 2542 * and no race with updating open_cnt */
@@ -2618,6 +2551,7 @@ static int drbd_open(struct block_device *bdev, fmode_t mode)
2618 if (!rv) 2551 if (!rv)
2619 mdev->open_cnt++; 2552 mdev->open_cnt++;
2620 spin_unlock_irqrestore(&mdev->req_lock, flags); 2553 spin_unlock_irqrestore(&mdev->req_lock, flags);
2554 unlock_kernel();
2621 2555
2622 return rv; 2556 return rv;
2623} 2557}
@@ -2625,7 +2559,9 @@ static int drbd_open(struct block_device *bdev, fmode_t mode)
2625static int drbd_release(struct gendisk *gd, fmode_t mode) 2559static int drbd_release(struct gendisk *gd, fmode_t mode)
2626{ 2560{
2627 struct drbd_conf *mdev = gd->private_data; 2561 struct drbd_conf *mdev = gd->private_data;
2562 lock_kernel();
2628 mdev->open_cnt--; 2563 mdev->open_cnt--;
2564 unlock_kernel();
2629 return 0; 2565 return 0;
2630} 2566}
2631 2567
@@ -2660,9 +2596,20 @@ static void drbd_unplug_fn(struct request_queue *q)
2660 2596
2661static void drbd_set_defaults(struct drbd_conf *mdev) 2597static void drbd_set_defaults(struct drbd_conf *mdev)
2662{ 2598{
2663 mdev->sync_conf.after = DRBD_AFTER_DEF; 2599 /* This way we get a compile error when sync_conf grows,
2664 mdev->sync_conf.rate = DRBD_RATE_DEF; 2600 and we forgot to initialize it here */
2665 mdev->sync_conf.al_extents = DRBD_AL_EXTENTS_DEF; 2601 mdev->sync_conf = (struct syncer_conf) {
2602 /* .rate = */ DRBD_RATE_DEF,
2603 /* .after = */ DRBD_AFTER_DEF,
2604 /* .al_extents = */ DRBD_AL_EXTENTS_DEF,
2605 /* .verify_alg = */ {}, 0,
2606 /* .cpu_mask = */ {}, 0,
2607 /* .csums_alg = */ {}, 0,
2608 /* .use_rle = */ 0
2609 };
2610
2611 /* Have to use that way, because the layout differs between
2612 big endian and little endian */
2666 mdev->state = (union drbd_state) { 2613 mdev->state = (union drbd_state) {
2667 { .role = R_SECONDARY, 2614 { .role = R_SECONDARY,
2668 .peer = R_UNKNOWN, 2615 .peer = R_UNKNOWN,
@@ -2721,24 +2668,17 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
2721 INIT_LIST_HEAD(&mdev->unplug_work.list); 2668 INIT_LIST_HEAD(&mdev->unplug_work.list);
2722 INIT_LIST_HEAD(&mdev->md_sync_work.list); 2669 INIT_LIST_HEAD(&mdev->md_sync_work.list);
2723 INIT_LIST_HEAD(&mdev->bm_io_work.w.list); 2670 INIT_LIST_HEAD(&mdev->bm_io_work.w.list);
2724 INIT_LIST_HEAD(&mdev->delay_probes);
2725 INIT_LIST_HEAD(&mdev->delay_probe_work.list);
2726 2671
2727 mdev->resync_work.cb = w_resync_inactive; 2672 mdev->resync_work.cb = w_resync_inactive;
2728 mdev->unplug_work.cb = w_send_write_hint; 2673 mdev->unplug_work.cb = w_send_write_hint;
2729 mdev->md_sync_work.cb = w_md_sync; 2674 mdev->md_sync_work.cb = w_md_sync;
2730 mdev->bm_io_work.w.cb = w_bitmap_io; 2675 mdev->bm_io_work.w.cb = w_bitmap_io;
2731 mdev->delay_probe_work.cb = w_delay_probes;
2732 init_timer(&mdev->resync_timer); 2676 init_timer(&mdev->resync_timer);
2733 init_timer(&mdev->md_sync_timer); 2677 init_timer(&mdev->md_sync_timer);
2734 init_timer(&mdev->delay_probe_timer);
2735 mdev->resync_timer.function = resync_timer_fn; 2678 mdev->resync_timer.function = resync_timer_fn;
2736 mdev->resync_timer.data = (unsigned long) mdev; 2679 mdev->resync_timer.data = (unsigned long) mdev;
2737 mdev->md_sync_timer.function = md_sync_timer_fn; 2680 mdev->md_sync_timer.function = md_sync_timer_fn;
2738 mdev->md_sync_timer.data = (unsigned long) mdev; 2681 mdev->md_sync_timer.data = (unsigned long) mdev;
2739 mdev->delay_probe_timer.function = delay_probe_timer_fn;
2740 mdev->delay_probe_timer.data = (unsigned long) mdev;
2741
2742 2682
2743 init_waitqueue_head(&mdev->misc_wait); 2683 init_waitqueue_head(&mdev->misc_wait);
2744 init_waitqueue_head(&mdev->state_wait); 2684 init_waitqueue_head(&mdev->state_wait);
diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
index 2151f18b21de..73131c5ae339 100644
--- a/drivers/block/drbd/drbd_nl.c
+++ b/drivers/block/drbd/drbd_nl.c
@@ -1557,10 +1557,6 @@ static int drbd_nl_syncer_conf(struct drbd_conf *mdev, struct drbd_nl_cfg_req *n
1557 sc.rate = DRBD_RATE_DEF; 1557 sc.rate = DRBD_RATE_DEF;
1558 sc.after = DRBD_AFTER_DEF; 1558 sc.after = DRBD_AFTER_DEF;
1559 sc.al_extents = DRBD_AL_EXTENTS_DEF; 1559 sc.al_extents = DRBD_AL_EXTENTS_DEF;
1560 sc.dp_volume = DRBD_DP_VOLUME_DEF;
1561 sc.dp_interval = DRBD_DP_INTERVAL_DEF;
1562 sc.throttle_th = DRBD_RS_THROTTLE_TH_DEF;
1563 sc.hold_off_th = DRBD_RS_HOLD_OFF_TH_DEF;
1564 } else 1560 } else
1565 memcpy(&sc, &mdev->sync_conf, sizeof(struct syncer_conf)); 1561 memcpy(&sc, &mdev->sync_conf, sizeof(struct syncer_conf));
1566 1562
diff --git a/drivers/block/drbd/drbd_proc.c b/drivers/block/drbd/drbd_proc.c
index d0f1767ea4c3..be3374b68460 100644
--- a/drivers/block/drbd/drbd_proc.c
+++ b/drivers/block/drbd/drbd_proc.c
@@ -73,21 +73,14 @@ static void drbd_syncer_progress(struct drbd_conf *mdev, struct seq_file *seq)
73 seq_printf(seq, "sync'ed:%3u.%u%% ", res / 10, res % 10); 73 seq_printf(seq, "sync'ed:%3u.%u%% ", res / 10, res % 10);
74 /* if more than 1 GB display in MB */ 74 /* if more than 1 GB display in MB */
75 if (mdev->rs_total > 0x100000L) 75 if (mdev->rs_total > 0x100000L)
76 seq_printf(seq, "(%lu/%lu)M", 76 seq_printf(seq, "(%lu/%lu)M\n\t",
77 (unsigned long) Bit2KB(rs_left >> 10), 77 (unsigned long) Bit2KB(rs_left >> 10),
78 (unsigned long) Bit2KB(mdev->rs_total >> 10)); 78 (unsigned long) Bit2KB(mdev->rs_total >> 10));
79 else 79 else
80 seq_printf(seq, "(%lu/%lu)K", 80 seq_printf(seq, "(%lu/%lu)K\n\t",
81 (unsigned long) Bit2KB(rs_left), 81 (unsigned long) Bit2KB(rs_left),
82 (unsigned long) Bit2KB(mdev->rs_total)); 82 (unsigned long) Bit2KB(mdev->rs_total));
83 83
84 if (mdev->state.conn == C_SYNC_TARGET)
85 seq_printf(seq, " queue_delay: %d.%d ms\n\t",
86 mdev->data_delay / 1000,
87 (mdev->data_delay % 1000) / 100);
88 else if (mdev->state.conn == C_SYNC_SOURCE)
89 seq_printf(seq, " delay_probe: %u\n\t", mdev->delay_seq);
90
91 /* see drivers/md/md.c 84 /* see drivers/md/md.c
92 * We do not want to overflow, so the order of operands and 85 * We do not want to overflow, so the order of operands and
93 * the * 100 / 100 trick are important. We do a +1 to be 86 * the * 100 / 100 trick are important. We do a +1 to be
@@ -135,14 +128,6 @@ static void drbd_syncer_progress(struct drbd_conf *mdev, struct seq_file *seq)
135 else 128 else
136 seq_printf(seq, " (%ld)", dbdt); 129 seq_printf(seq, " (%ld)", dbdt);
137 130
138 if (mdev->state.conn == C_SYNC_TARGET) {
139 if (mdev->c_sync_rate > 1000)
140 seq_printf(seq, " want: %d,%03d",
141 mdev->c_sync_rate / 1000, mdev->c_sync_rate % 1000);
142 else
143 seq_printf(seq, " want: %d", mdev->c_sync_rate);
144 }
145
146 seq_printf(seq, " K/sec\n"); 131 seq_printf(seq, " K/sec\n");
147} 132}
148 133
diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
index ec1711f7c5c5..081522d3c742 100644
--- a/drivers/block/drbd/drbd_receiver.c
+++ b/drivers/block/drbd/drbd_receiver.c
@@ -1180,7 +1180,7 @@ next_bio:
1180 bio->bi_sector = sector; 1180 bio->bi_sector = sector;
1181 bio->bi_bdev = mdev->ldev->backing_bdev; 1181 bio->bi_bdev = mdev->ldev->backing_bdev;
1182 /* we special case some flags in the multi-bio case, see below 1182 /* we special case some flags in the multi-bio case, see below
1183 * (BIO_RW_UNPLUG, BIO_RW_BARRIER) */ 1183 * (REQ_UNPLUG, REQ_HARDBARRIER) */
1184 bio->bi_rw = rw; 1184 bio->bi_rw = rw;
1185 bio->bi_private = e; 1185 bio->bi_private = e;
1186 bio->bi_end_io = drbd_endio_sec; 1186 bio->bi_end_io = drbd_endio_sec;
@@ -1209,16 +1209,16 @@ next_bio:
1209 bios = bios->bi_next; 1209 bios = bios->bi_next;
1210 bio->bi_next = NULL; 1210 bio->bi_next = NULL;
1211 1211
1212 /* strip off BIO_RW_UNPLUG unless it is the last bio */ 1212 /* strip off REQ_UNPLUG unless it is the last bio */
1213 if (bios) 1213 if (bios)
1214 bio->bi_rw &= ~(1<<BIO_RW_UNPLUG); 1214 bio->bi_rw &= ~REQ_UNPLUG;
1215 1215
1216 drbd_generic_make_request(mdev, fault_type, bio); 1216 drbd_generic_make_request(mdev, fault_type, bio);
1217 1217
1218 /* strip off BIO_RW_BARRIER, 1218 /* strip off REQ_HARDBARRIER,
1219 * unless it is the first or last bio */ 1219 * unless it is the first or last bio */
1220 if (bios && bios->bi_next) 1220 if (bios && bios->bi_next)
1221 bios->bi_rw &= ~(1<<BIO_RW_BARRIER); 1221 bios->bi_rw &= ~REQ_HARDBARRIER;
1222 } while (bios); 1222 } while (bios);
1223 maybe_kick_lo(mdev); 1223 maybe_kick_lo(mdev);
1224 return 0; 1224 return 0;
@@ -1233,7 +1233,7 @@ fail:
1233} 1233}
1234 1234
1235/** 1235/**
1236 * w_e_reissue() - Worker callback; Resubmit a bio, without BIO_RW_BARRIER set 1236 * w_e_reissue() - Worker callback; Resubmit a bio, without REQ_HARDBARRIER set
1237 * @mdev: DRBD device. 1237 * @mdev: DRBD device.
1238 * @w: work object. 1238 * @w: work object.
1239 * @cancel: The connection will be closed anyways (unused in this callback) 1239 * @cancel: The connection will be closed anyways (unused in this callback)
@@ -1245,7 +1245,7 @@ int w_e_reissue(struct drbd_conf *mdev, struct drbd_work *w, int cancel) __relea
1245 (and DE_BARRIER_IN_NEXT_EPOCH_ISSUED in the previous Epoch) 1245 (and DE_BARRIER_IN_NEXT_EPOCH_ISSUED in the previous Epoch)
1246 so that we can finish that epoch in drbd_may_finish_epoch(). 1246 so that we can finish that epoch in drbd_may_finish_epoch().
1247 That is necessary if we already have a long chain of Epochs, before 1247 That is necessary if we already have a long chain of Epochs, before
1248 we realize that BIO_RW_BARRIER is actually not supported */ 1248 we realize that REQ_HARDBARRIER is actually not supported */
1249 1249
1250 /* As long as the -ENOTSUPP on the barrier is reported immediately 1250 /* As long as the -ENOTSUPP on the barrier is reported immediately
1251 that will never trigger. If it is reported late, we will just 1251 that will never trigger. If it is reported late, we will just
@@ -1824,14 +1824,14 @@ static int receive_Data(struct drbd_conf *mdev, struct p_header *h)
1824 epoch = list_entry(e->epoch->list.prev, struct drbd_epoch, list); 1824 epoch = list_entry(e->epoch->list.prev, struct drbd_epoch, list);
1825 if (epoch == e->epoch) { 1825 if (epoch == e->epoch) {
1826 set_bit(DE_CONTAINS_A_BARRIER, &e->epoch->flags); 1826 set_bit(DE_CONTAINS_A_BARRIER, &e->epoch->flags);
1827 rw |= (1<<BIO_RW_BARRIER); 1827 rw |= REQ_HARDBARRIER;
1828 e->flags |= EE_IS_BARRIER; 1828 e->flags |= EE_IS_BARRIER;
1829 } else { 1829 } else {
1830 if (atomic_read(&epoch->epoch_size) > 1 || 1830 if (atomic_read(&epoch->epoch_size) > 1 ||
1831 !test_bit(DE_CONTAINS_A_BARRIER, &epoch->flags)) { 1831 !test_bit(DE_CONTAINS_A_BARRIER, &epoch->flags)) {
1832 set_bit(DE_BARRIER_IN_NEXT_EPOCH_ISSUED, &epoch->flags); 1832 set_bit(DE_BARRIER_IN_NEXT_EPOCH_ISSUED, &epoch->flags);
1833 set_bit(DE_CONTAINS_A_BARRIER, &e->epoch->flags); 1833 set_bit(DE_CONTAINS_A_BARRIER, &e->epoch->flags);
1834 rw |= (1<<BIO_RW_BARRIER); 1834 rw |= REQ_HARDBARRIER;
1835 e->flags |= EE_IS_BARRIER; 1835 e->flags |= EE_IS_BARRIER;
1836 } 1836 }
1837 } 1837 }
@@ -1841,10 +1841,10 @@ static int receive_Data(struct drbd_conf *mdev, struct p_header *h)
1841 dp_flags = be32_to_cpu(p->dp_flags); 1841 dp_flags = be32_to_cpu(p->dp_flags);
1842 if (dp_flags & DP_HARDBARRIER) { 1842 if (dp_flags & DP_HARDBARRIER) {
1843 dev_err(DEV, "ASSERT FAILED would have submitted barrier request\n"); 1843 dev_err(DEV, "ASSERT FAILED would have submitted barrier request\n");
1844 /* rw |= (1<<BIO_RW_BARRIER); */ 1844 /* rw |= REQ_HARDBARRIER; */
1845 } 1845 }
1846 if (dp_flags & DP_RW_SYNC) 1846 if (dp_flags & DP_RW_SYNC)
1847 rw |= (1<<BIO_RW_SYNCIO) | (1<<BIO_RW_UNPLUG); 1847 rw |= REQ_SYNC | REQ_UNPLUG;
1848 if (dp_flags & DP_MAY_SET_IN_SYNC) 1848 if (dp_flags & DP_MAY_SET_IN_SYNC)
1849 e->flags |= EE_MAY_SET_IN_SYNC; 1849 e->flags |= EE_MAY_SET_IN_SYNC;
1850 1850
@@ -3555,14 +3555,15 @@ static int receive_bitmap(struct drbd_conf *mdev, struct p_header *h)
3555 return ok; 3555 return ok;
3556} 3556}
3557 3557
3558static int receive_skip(struct drbd_conf *mdev, struct p_header *h) 3558static int receive_skip_(struct drbd_conf *mdev, struct p_header *h, int silent)
3559{ 3559{
3560 /* TODO zero copy sink :) */ 3560 /* TODO zero copy sink :) */
3561 static char sink[128]; 3561 static char sink[128];
3562 int size, want, r; 3562 int size, want, r;
3563 3563
3564 dev_warn(DEV, "skipping unknown optional packet type %d, l: %d!\n", 3564 if (!silent)
3565 h->command, h->length); 3565 dev_warn(DEV, "skipping unknown optional packet type %d, l: %d!\n",
3566 h->command, h->length);
3566 3567
3567 size = h->length; 3568 size = h->length;
3568 while (size > 0) { 3569 while (size > 0) {
@@ -3574,101 +3575,25 @@ static int receive_skip(struct drbd_conf *mdev, struct p_header *h)
3574 return size == 0; 3575 return size == 0;
3575} 3576}
3576 3577
3577static int receive_UnplugRemote(struct drbd_conf *mdev, struct p_header *h) 3578static int receive_skip(struct drbd_conf *mdev, struct p_header *h)
3578{
3579 if (mdev->state.disk >= D_INCONSISTENT)
3580 drbd_kick_lo(mdev);
3581
3582 /* Make sure we've acked all the TCP data associated
3583 * with the data requests being unplugged */
3584 drbd_tcp_quickack(mdev->data.socket);
3585
3586 return TRUE;
3587}
3588
3589static void timeval_sub_us(struct timeval* tv, unsigned int us)
3590{ 3579{
3591 tv->tv_sec -= us / 1000000; 3580 return receive_skip_(mdev, h, 0);
3592 us = us % 1000000;
3593 if (tv->tv_usec > us) {
3594 tv->tv_usec += 1000000;
3595 tv->tv_sec--;
3596 }
3597 tv->tv_usec -= us;
3598} 3581}
3599 3582
3600static void got_delay_probe(struct drbd_conf *mdev, int from, struct p_delay_probe *p) 3583static int receive_skip_silent(struct drbd_conf *mdev, struct p_header *h)
3601{ 3584{
3602 struct delay_probe *dp; 3585 return receive_skip_(mdev, h, 1);
3603 struct list_head *le;
3604 struct timeval now;
3605 int seq_num;
3606 int offset;
3607 int data_delay;
3608
3609 seq_num = be32_to_cpu(p->seq_num);
3610 offset = be32_to_cpu(p->offset);
3611
3612 spin_lock(&mdev->peer_seq_lock);
3613 if (!list_empty(&mdev->delay_probes)) {
3614 if (from == USE_DATA_SOCKET)
3615 le = mdev->delay_probes.next;
3616 else
3617 le = mdev->delay_probes.prev;
3618
3619 dp = list_entry(le, struct delay_probe, list);
3620
3621 if (dp->seq_num == seq_num) {
3622 list_del(le);
3623 spin_unlock(&mdev->peer_seq_lock);
3624 do_gettimeofday(&now);
3625 timeval_sub_us(&now, offset);
3626 data_delay =
3627 now.tv_usec - dp->time.tv_usec +
3628 (now.tv_sec - dp->time.tv_sec) * 1000000;
3629
3630 if (data_delay > 0)
3631 mdev->data_delay = data_delay;
3632
3633 kfree(dp);
3634 return;
3635 }
3636
3637 if (dp->seq_num > seq_num) {
3638 spin_unlock(&mdev->peer_seq_lock);
3639 dev_warn(DEV, "Previous allocation failure of struct delay_probe?\n");
3640 return; /* Do not alloca a struct delay_probe.... */
3641 }
3642 }
3643 spin_unlock(&mdev->peer_seq_lock);
3644
3645 dp = kmalloc(sizeof(struct delay_probe), GFP_NOIO);
3646 if (!dp) {
3647 dev_warn(DEV, "Failed to allocate a struct delay_probe, do not worry.\n");
3648 return;
3649 }
3650
3651 dp->seq_num = seq_num;
3652 do_gettimeofday(&dp->time);
3653 timeval_sub_us(&dp->time, offset);
3654
3655 spin_lock(&mdev->peer_seq_lock);
3656 if (from == USE_DATA_SOCKET)
3657 list_add(&dp->list, &mdev->delay_probes);
3658 else
3659 list_add_tail(&dp->list, &mdev->delay_probes);
3660 spin_unlock(&mdev->peer_seq_lock);
3661} 3586}
3662 3587
3663static int receive_delay_probe(struct drbd_conf *mdev, struct p_header *h) 3588static int receive_UnplugRemote(struct drbd_conf *mdev, struct p_header *h)
3664{ 3589{
3665 struct p_delay_probe *p = (struct p_delay_probe *)h; 3590 if (mdev->state.disk >= D_INCONSISTENT)
3591 drbd_kick_lo(mdev);
3666 3592
3667 ERR_IF(h->length != (sizeof(*p)-sizeof(*h))) return FALSE; 3593 /* Make sure we've acked all the TCP data associated
3668 if (drbd_recv(mdev, h->payload, h->length) != h->length) 3594 * with the data requests being unplugged */
3669 return FALSE; 3595 drbd_tcp_quickack(mdev->data.socket);
3670 3596
3671 got_delay_probe(mdev, USE_DATA_SOCKET, p);
3672 return TRUE; 3597 return TRUE;
3673} 3598}
3674 3599
@@ -3695,7 +3620,7 @@ static drbd_cmd_handler_f drbd_default_handler[] = {
3695 [P_OV_REQUEST] = receive_DataRequest, 3620 [P_OV_REQUEST] = receive_DataRequest,
3696 [P_OV_REPLY] = receive_DataRequest, 3621 [P_OV_REPLY] = receive_DataRequest,
3697 [P_CSUM_RS_REQUEST] = receive_DataRequest, 3622 [P_CSUM_RS_REQUEST] = receive_DataRequest,
3698 [P_DELAY_PROBE] = receive_delay_probe, 3623 [P_DELAY_PROBE] = receive_skip_silent,
3699 /* anything missing from this table is in 3624 /* anything missing from this table is in
3700 * the asender_tbl, see get_asender_cmd */ 3625 * the asender_tbl, see get_asender_cmd */
3701 [P_MAX_CMD] = NULL, 3626 [P_MAX_CMD] = NULL,
@@ -4472,11 +4397,9 @@ static int got_OVResult(struct drbd_conf *mdev, struct p_header *h)
4472 return TRUE; 4397 return TRUE;
4473} 4398}
4474 4399
4475static int got_delay_probe_m(struct drbd_conf *mdev, struct p_header *h) 4400static int got_something_to_ignore_m(struct drbd_conf *mdev, struct p_header *h)
4476{ 4401{
4477 struct p_delay_probe *p = (struct p_delay_probe *)h; 4402 /* IGNORE */
4478
4479 got_delay_probe(mdev, USE_META_SOCKET, p);
4480 return TRUE; 4403 return TRUE;
4481} 4404}
4482 4405
@@ -4504,7 +4427,7 @@ static struct asender_cmd *get_asender_cmd(int cmd)
4504 [P_BARRIER_ACK] = { sizeof(struct p_barrier_ack), got_BarrierAck }, 4427 [P_BARRIER_ACK] = { sizeof(struct p_barrier_ack), got_BarrierAck },
4505 [P_STATE_CHG_REPLY] = { sizeof(struct p_req_state_reply), got_RqSReply }, 4428 [P_STATE_CHG_REPLY] = { sizeof(struct p_req_state_reply), got_RqSReply },
4506 [P_RS_IS_IN_SYNC] = { sizeof(struct p_block_ack), got_IsInSync }, 4429 [P_RS_IS_IN_SYNC] = { sizeof(struct p_block_ack), got_IsInSync },
4507 [P_DELAY_PROBE] = { sizeof(struct p_delay_probe), got_delay_probe_m }, 4430 [P_DELAY_PROBE] = { sizeof(struct p_delay_probe), got_something_to_ignore_m },
4508 [P_MAX_CMD] = { 0, NULL }, 4431 [P_MAX_CMD] = { 0, NULL },
4509 }; 4432 };
4510 if (cmd > P_MAX_CMD || asender_tbl[cmd].process == NULL) 4433 if (cmd > P_MAX_CMD || asender_tbl[cmd].process == NULL)
diff --git a/drivers/block/drbd/drbd_req.c b/drivers/block/drbd/drbd_req.c
index 654f1ef5cbb0..f761d98a4e90 100644
--- a/drivers/block/drbd/drbd_req.c
+++ b/drivers/block/drbd/drbd_req.c
@@ -997,7 +997,7 @@ int drbd_make_request_26(struct request_queue *q, struct bio *bio)
997 * because of those XXX, this is not yet enabled, 997 * because of those XXX, this is not yet enabled,
998 * i.e. in drbd_init_set_defaults we set the NO_BARRIER_SUPP bit. 998 * i.e. in drbd_init_set_defaults we set the NO_BARRIER_SUPP bit.
999 */ 999 */
1000 if (unlikely(bio_rw_flagged(bio, BIO_RW_BARRIER) && test_bit(NO_BARRIER_SUPP, &mdev->flags))) { 1000 if (unlikely(bio->bi_rw & REQ_HARDBARRIER) && test_bit(NO_BARRIER_SUPP, &mdev->flags)) {
1001 /* dev_warn(DEV, "Rejecting barrier request as underlying device does not support\n"); */ 1001 /* dev_warn(DEV, "Rejecting barrier request as underlying device does not support\n"); */
1002 bio_endio(bio, -EOPNOTSUPP); 1002 bio_endio(bio, -EOPNOTSUPP);
1003 return 0; 1003 return 0;
diff --git a/drivers/block/drbd/drbd_worker.c b/drivers/block/drbd/drbd_worker.c
index b623ceee2a4a..ca4a16cea2d8 100644
--- a/drivers/block/drbd/drbd_worker.c
+++ b/drivers/block/drbd/drbd_worker.c
@@ -424,18 +424,6 @@ void resync_timer_fn(unsigned long data)
424 drbd_queue_work(&mdev->data.work, &mdev->resync_work); 424 drbd_queue_work(&mdev->data.work, &mdev->resync_work);
425} 425}
426 426
427static int calc_resync_rate(struct drbd_conf *mdev)
428{
429 int d = mdev->data_delay / 1000; /* us -> ms */
430 int td = mdev->sync_conf.throttle_th * 100; /* 0.1s -> ms */
431 int hd = mdev->sync_conf.hold_off_th * 100; /* 0.1s -> ms */
432 int cr = mdev->sync_conf.rate;
433
434 return d <= td ? cr :
435 d >= hd ? 0 :
436 cr + (cr * (td - d) / (hd - td));
437}
438
439int w_make_resync_request(struct drbd_conf *mdev, 427int w_make_resync_request(struct drbd_conf *mdev,
440 struct drbd_work *w, int cancel) 428 struct drbd_work *w, int cancel)
441{ 429{
@@ -473,8 +461,7 @@ int w_make_resync_request(struct drbd_conf *mdev,
473 max_segment_size = mdev->agreed_pro_version < 94 ? 461 max_segment_size = mdev->agreed_pro_version < 94 ?
474 queue_max_segment_size(mdev->rq_queue) : DRBD_MAX_SEGMENT_SIZE; 462 queue_max_segment_size(mdev->rq_queue) : DRBD_MAX_SEGMENT_SIZE;
475 463
476 mdev->c_sync_rate = calc_resync_rate(mdev); 464 number = SLEEP_TIME * mdev->sync_conf.rate / ((BM_BLOCK_SIZE / 1024) * HZ);
477 number = SLEEP_TIME * mdev->c_sync_rate / ((BM_BLOCK_SIZE / 1024) * HZ);
478 pe = atomic_read(&mdev->rs_pending_cnt); 465 pe = atomic_read(&mdev->rs_pending_cnt);
479 466
480 mutex_lock(&mdev->data.mutex); 467 mutex_lock(&mdev->data.mutex);
diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index 90c4038702da..cf04c1b234ed 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -178,6 +178,7 @@ static int print_unex = 1;
178#include <linux/slab.h> 178#include <linux/slab.h>
179#include <linux/mm.h> 179#include <linux/mm.h>
180#include <linux/bio.h> 180#include <linux/bio.h>
181#include <linux/smp_lock.h>
181#include <linux/string.h> 182#include <linux/string.h>
182#include <linux/jiffies.h> 183#include <linux/jiffies.h>
183#include <linux/fcntl.h> 184#include <linux/fcntl.h>
@@ -514,8 +515,6 @@ static unsigned long fdc_busy;
514static DECLARE_WAIT_QUEUE_HEAD(fdc_wait); 515static DECLARE_WAIT_QUEUE_HEAD(fdc_wait);
515static DECLARE_WAIT_QUEUE_HEAD(command_done); 516static DECLARE_WAIT_QUEUE_HEAD(command_done);
516 517
517#define NO_SIGNAL (!interruptible || !signal_pending(current))
518
519/* Errors during formatting are counted here. */ 518/* Errors during formatting are counted here. */
520static int format_errors; 519static int format_errors;
521 520
@@ -539,7 +538,7 @@ static int max_buffer_sectors;
539 538
540static int *errors; 539static int *errors;
541typedef void (*done_f)(int); 540typedef void (*done_f)(int);
542static struct cont_t { 541static const struct cont_t {
543 void (*interrupt)(void); 542 void (*interrupt)(void);
544 /* this is called after the interrupt of the 543 /* this is called after the interrupt of the
545 * main command */ 544 * main command */
@@ -578,7 +577,7 @@ static void reset_fdc(void);
578#define NEED_1_RECAL -2 577#define NEED_1_RECAL -2
579#define NEED_2_RECAL -3 578#define NEED_2_RECAL -3
580 579
581static int usage_count; 580static atomic_t usage_count = ATOMIC_INIT(0);
582 581
583/* buffer related variables */ 582/* buffer related variables */
584static int buffer_track = -1; 583static int buffer_track = -1;
@@ -858,36 +857,15 @@ static void set_fdc(int drive)
858} 857}
859 858
860/* locks the driver */ 859/* locks the driver */
861static int _lock_fdc(int drive, bool interruptible, int line) 860static int lock_fdc(int drive, bool interruptible)
862{ 861{
863 if (!usage_count) { 862 if (WARN(atomic_read(&usage_count) == 0,
864 pr_err("Trying to lock fdc while usage count=0 at line %d\n", 863 "Trying to lock fdc while usage count=0\n"))
865 line);
866 return -1; 864 return -1;
867 }
868
869 if (test_and_set_bit(0, &fdc_busy)) {
870 DECLARE_WAITQUEUE(wait, current);
871 add_wait_queue(&fdc_wait, &wait);
872
873 for (;;) {
874 set_current_state(TASK_INTERRUPTIBLE);
875
876 if (!test_and_set_bit(0, &fdc_busy))
877 break;
878 865
879 schedule(); 866 if (wait_event_interruptible(fdc_wait, !test_and_set_bit(0, &fdc_busy)))
880 867 return -EINTR;
881 if (!NO_SIGNAL) {
882 remove_wait_queue(&fdc_wait, &wait);
883 return -EINTR;
884 }
885 }
886 868
887 set_current_state(TASK_RUNNING);
888 remove_wait_queue(&fdc_wait, &wait);
889 flush_scheduled_work();
890 }
891 command_status = FD_COMMAND_NONE; 869 command_status = FD_COMMAND_NONE;
892 870
893 __reschedule_timeout(drive, "lock fdc"); 871 __reschedule_timeout(drive, "lock fdc");
@@ -895,11 +873,8 @@ static int _lock_fdc(int drive, bool interruptible, int line)
895 return 0; 873 return 0;
896} 874}
897 875
898#define lock_fdc(drive, interruptible) \
899 _lock_fdc(drive, interruptible, __LINE__)
900
901/* unlocks the driver */ 876/* unlocks the driver */
902static inline void unlock_fdc(void) 877static void unlock_fdc(void)
903{ 878{
904 unsigned long flags; 879 unsigned long flags;
905 880
@@ -1224,7 +1199,7 @@ static int need_more_output(void)
1224/* Set perpendicular mode as required, based on data rate, if supported. 1199/* Set perpendicular mode as required, based on data rate, if supported.
1225 * 82077 Now tested. 1Mbps data rate only possible with 82077-1. 1200 * 82077 Now tested. 1Mbps data rate only possible with 82077-1.
1226 */ 1201 */
1227static inline void perpendicular_mode(void) 1202static void perpendicular_mode(void)
1228{ 1203{
1229 unsigned char perp_mode; 1204 unsigned char perp_mode;
1230 1205
@@ -1995,14 +1970,14 @@ static void do_wakeup(void)
1995 wake_up(&command_done); 1970 wake_up(&command_done);
1996} 1971}
1997 1972
1998static struct cont_t wakeup_cont = { 1973static const struct cont_t wakeup_cont = {
1999 .interrupt = empty, 1974 .interrupt = empty,
2000 .redo = do_wakeup, 1975 .redo = do_wakeup,
2001 .error = empty, 1976 .error = empty,
2002 .done = (done_f)empty 1977 .done = (done_f)empty
2003}; 1978};
2004 1979
2005static struct cont_t intr_cont = { 1980static const struct cont_t intr_cont = {
2006 .interrupt = empty, 1981 .interrupt = empty,
2007 .redo = process_fd_request, 1982 .redo = process_fd_request,
2008 .error = empty, 1983 .error = empty,
@@ -2015,25 +1990,10 @@ static int wait_til_done(void (*handler)(void), bool interruptible)
2015 1990
2016 schedule_bh(handler); 1991 schedule_bh(handler);
2017 1992
2018 if (command_status < 2 && NO_SIGNAL) { 1993 if (interruptible)
2019 DECLARE_WAITQUEUE(wait, current); 1994 wait_event_interruptible(command_done, command_status >= 2);
2020 1995 else
2021 add_wait_queue(&command_done, &wait); 1996 wait_event(command_done, command_status >= 2);
2022 for (;;) {
2023 set_current_state(interruptible ?
2024 TASK_INTERRUPTIBLE :
2025 TASK_UNINTERRUPTIBLE);
2026
2027 if (command_status >= 2 || !NO_SIGNAL)
2028 break;
2029
2030 is_alive(__func__, "");
2031 schedule();
2032 }
2033
2034 set_current_state(TASK_RUNNING);
2035 remove_wait_queue(&command_done, &wait);
2036 }
2037 1997
2038 if (command_status < 2) { 1998 if (command_status < 2) {
2039 cancel_activity(); 1999 cancel_activity();
@@ -2223,7 +2183,7 @@ static void redo_format(void)
2223 debugt(__func__, "queue format request"); 2183 debugt(__func__, "queue format request");
2224} 2184}
2225 2185
2226static struct cont_t format_cont = { 2186static const struct cont_t format_cont = {
2227 .interrupt = format_interrupt, 2187 .interrupt = format_interrupt,
2228 .redo = redo_format, 2188 .redo = redo_format,
2229 .error = bad_flp_intr, 2189 .error = bad_flp_intr,
@@ -2583,10 +2543,8 @@ static int make_raw_rw_request(void)
2583 int tracksize; 2543 int tracksize;
2584 int ssize; 2544 int ssize;
2585 2545
2586 if (max_buffer_sectors == 0) { 2546 if (WARN(max_buffer_sectors == 0, "VFS: Block I/O scheduled on unopened device\n"))
2587 pr_info("VFS: Block I/O scheduled on unopened device\n");
2588 return 0; 2547 return 0;
2589 }
2590 2548
2591 set_fdc((long)current_req->rq_disk->private_data); 2549 set_fdc((long)current_req->rq_disk->private_data);
2592 2550
@@ -2921,7 +2879,7 @@ do_request:
2921 return; 2879 return;
2922} 2880}
2923 2881
2924static struct cont_t rw_cont = { 2882static const struct cont_t rw_cont = {
2925 .interrupt = rw_interrupt, 2883 .interrupt = rw_interrupt,
2926 .redo = redo_fd_request, 2884 .redo = redo_fd_request,
2927 .error = bad_flp_intr, 2885 .error = bad_flp_intr,
@@ -2936,19 +2894,16 @@ static void process_fd_request(void)
2936 2894
2937static void do_fd_request(struct request_queue *q) 2895static void do_fd_request(struct request_queue *q)
2938{ 2896{
2939 if (max_buffer_sectors == 0) { 2897 if (WARN(max_buffer_sectors == 0,
2940 pr_info("VFS: %s called on non-open device\n", __func__); 2898 "VFS: %s called on non-open device\n", __func__))
2941 return; 2899 return;
2942 }
2943 2900
2944 if (usage_count == 0) { 2901 if (WARN(atomic_read(&usage_count) == 0,
2945 pr_info("warning: usage count=0, current_req=%p exiting\n", 2902 "warning: usage count=0, current_req=%p sect=%ld type=%x flags=%x\n",
2946 current_req); 2903 current_req, (long)blk_rq_pos(current_req), current_req->cmd_type,
2947 pr_info("sect=%ld type=%x flags=%x\n", 2904 current_req->cmd_flags))
2948 (long)blk_rq_pos(current_req), current_req->cmd_type,
2949 current_req->cmd_flags);
2950 return; 2905 return;
2951 } 2906
2952 if (test_bit(0, &fdc_busy)) { 2907 if (test_bit(0, &fdc_busy)) {
2953 /* fdc busy, this new request will be treated when the 2908 /* fdc busy, this new request will be treated when the
2954 current one is done */ 2909 current one is done */
@@ -2960,7 +2915,7 @@ static void do_fd_request(struct request_queue *q)
2960 is_alive(__func__, ""); 2915 is_alive(__func__, "");
2961} 2916}
2962 2917
2963static struct cont_t poll_cont = { 2918static const struct cont_t poll_cont = {
2964 .interrupt = success_and_wakeup, 2919 .interrupt = success_and_wakeup,
2965 .redo = floppy_ready, 2920 .redo = floppy_ready,
2966 .error = generic_failure, 2921 .error = generic_failure,
@@ -2991,7 +2946,7 @@ static void reset_intr(void)
2991 pr_info("weird, reset interrupt called\n"); 2946 pr_info("weird, reset interrupt called\n");
2992} 2947}
2993 2948
2994static struct cont_t reset_cont = { 2949static const struct cont_t reset_cont = {
2995 .interrupt = reset_intr, 2950 .interrupt = reset_intr,
2996 .redo = success_and_wakeup, 2951 .redo = success_and_wakeup,
2997 .error = generic_failure, 2952 .error = generic_failure,
@@ -3033,7 +2988,7 @@ static inline int fd_copyin(void __user *param, void *address,
3033 return copy_from_user(address, param, size) ? -EFAULT : 0; 2988 return copy_from_user(address, param, size) ? -EFAULT : 0;
3034} 2989}
3035 2990
3036static inline const char *drive_name(int type, int drive) 2991static const char *drive_name(int type, int drive)
3037{ 2992{
3038 struct floppy_struct *floppy; 2993 struct floppy_struct *floppy;
3039 2994
@@ -3096,14 +3051,14 @@ static void raw_cmd_done(int flag)
3096 generic_done(flag); 3051 generic_done(flag);
3097} 3052}
3098 3053
3099static struct cont_t raw_cmd_cont = { 3054static const struct cont_t raw_cmd_cont = {
3100 .interrupt = success_and_wakeup, 3055 .interrupt = success_and_wakeup,
3101 .redo = floppy_start, 3056 .redo = floppy_start,
3102 .error = generic_failure, 3057 .error = generic_failure,
3103 .done = raw_cmd_done 3058 .done = raw_cmd_done
3104}; 3059};
3105 3060
3106static inline int raw_cmd_copyout(int cmd, void __user *param, 3061static int raw_cmd_copyout(int cmd, void __user *param,
3107 struct floppy_raw_cmd *ptr) 3062 struct floppy_raw_cmd *ptr)
3108{ 3063{
3109 int ret; 3064 int ret;
@@ -3148,7 +3103,7 @@ static void raw_cmd_free(struct floppy_raw_cmd **ptr)
3148 } 3103 }
3149} 3104}
3150 3105
3151static inline int raw_cmd_copyin(int cmd, void __user *param, 3106static int raw_cmd_copyin(int cmd, void __user *param,
3152 struct floppy_raw_cmd **rcmd) 3107 struct floppy_raw_cmd **rcmd)
3153{ 3108{
3154 struct floppy_raw_cmd *ptr; 3109 struct floppy_raw_cmd *ptr;
@@ -3266,7 +3221,7 @@ static int invalidate_drive(struct block_device *bdev)
3266 return 0; 3221 return 0;
3267} 3222}
3268 3223
3269static inline int set_geometry(unsigned int cmd, struct floppy_struct *g, 3224static int set_geometry(unsigned int cmd, struct floppy_struct *g,
3270 int drive, int type, struct block_device *bdev) 3225 int drive, int type, struct block_device *bdev)
3271{ 3226{
3272 int cnt; 3227 int cnt;
@@ -3337,7 +3292,7 @@ static inline int set_geometry(unsigned int cmd, struct floppy_struct *g,
3337} 3292}
3338 3293
3339/* handle obsolete ioctl's */ 3294/* handle obsolete ioctl's */
3340static int ioctl_table[] = { 3295static unsigned int ioctl_table[] = {
3341 FDCLRPRM, 3296 FDCLRPRM,
3342 FDSETPRM, 3297 FDSETPRM,
3343 FDDEFPRM, 3298 FDDEFPRM,
@@ -3365,7 +3320,7 @@ static int ioctl_table[] = {
3365 FDTWADDLE 3320 FDTWADDLE
3366}; 3321};
3367 3322
3368static inline int normalize_ioctl(int *cmd, int *size) 3323static int normalize_ioctl(unsigned int *cmd, int *size)
3369{ 3324{
3370 int i; 3325 int i;
3371 3326
@@ -3417,7 +3372,7 @@ static int fd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
3417 return 0; 3372 return 0;
3418} 3373}
3419 3374
3420static int fd_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, 3375static int fd_locked_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
3421 unsigned long param) 3376 unsigned long param)
3422{ 3377{
3423 int drive = (long)bdev->bd_disk->private_data; 3378 int drive = (long)bdev->bd_disk->private_data;
@@ -3593,6 +3548,18 @@ static int fd_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
3593 return 0; 3548 return 0;
3594} 3549}
3595 3550
3551static int fd_ioctl(struct block_device *bdev, fmode_t mode,
3552 unsigned int cmd, unsigned long param)
3553{
3554 int ret;
3555
3556 lock_kernel();
3557 ret = fd_locked_ioctl(bdev, mode, cmd, param);
3558 unlock_kernel();
3559
3560 return ret;
3561}
3562
3596static void __init config_types(void) 3563static void __init config_types(void)
3597{ 3564{
3598 bool has_drive = false; 3565 bool has_drive = false;
@@ -3649,6 +3616,7 @@ static int floppy_release(struct gendisk *disk, fmode_t mode)
3649{ 3616{
3650 int drive = (long)disk->private_data; 3617 int drive = (long)disk->private_data;
3651 3618
3619 lock_kernel();
3652 mutex_lock(&open_lock); 3620 mutex_lock(&open_lock);
3653 if (UDRS->fd_ref < 0) 3621 if (UDRS->fd_ref < 0)
3654 UDRS->fd_ref = 0; 3622 UDRS->fd_ref = 0;
@@ -3659,6 +3627,7 @@ static int floppy_release(struct gendisk *disk, fmode_t mode)
3659 if (!UDRS->fd_ref) 3627 if (!UDRS->fd_ref)
3660 opened_bdev[drive] = NULL; 3628 opened_bdev[drive] = NULL;
3661 mutex_unlock(&open_lock); 3629 mutex_unlock(&open_lock);
3630 unlock_kernel();
3662 3631
3663 return 0; 3632 return 0;
3664} 3633}
@@ -3676,6 +3645,7 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
3676 int res = -EBUSY; 3645 int res = -EBUSY;
3677 char *tmp; 3646 char *tmp;
3678 3647
3648 lock_kernel();
3679 mutex_lock(&open_lock); 3649 mutex_lock(&open_lock);
3680 old_dev = UDRS->fd_device; 3650 old_dev = UDRS->fd_device;
3681 if (opened_bdev[drive] && opened_bdev[drive] != bdev) 3651 if (opened_bdev[drive] && opened_bdev[drive] != bdev)
@@ -3752,6 +3722,7 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
3752 goto out; 3722 goto out;
3753 } 3723 }
3754 mutex_unlock(&open_lock); 3724 mutex_unlock(&open_lock);
3725 unlock_kernel();
3755 return 0; 3726 return 0;
3756out: 3727out:
3757 if (UDRS->fd_ref < 0) 3728 if (UDRS->fd_ref < 0)
@@ -3762,6 +3733,7 @@ out:
3762 opened_bdev[drive] = NULL; 3733 opened_bdev[drive] = NULL;
3763out2: 3734out2:
3764 mutex_unlock(&open_lock); 3735 mutex_unlock(&open_lock);
3736 unlock_kernel();
3765 return res; 3737 return res;
3766} 3738}
3767 3739
@@ -3829,6 +3801,7 @@ static int __floppy_read_block_0(struct block_device *bdev)
3829 bio.bi_size = size; 3801 bio.bi_size = size;
3830 bio.bi_bdev = bdev; 3802 bio.bi_bdev = bdev;
3831 bio.bi_sector = 0; 3803 bio.bi_sector = 0;
3804 bio.bi_flags = BIO_QUIET;
3832 init_completion(&complete); 3805 init_completion(&complete);
3833 bio.bi_private = &complete; 3806 bio.bi_private = &complete;
3834 bio.bi_end_io = floppy_rb0_complete; 3807 bio.bi_end_io = floppy_rb0_complete;
@@ -3857,10 +3830,10 @@ static int floppy_revalidate(struct gendisk *disk)
3857 if (test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags) || 3830 if (test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags) ||
3858 test_bit(FD_VERIFY_BIT, &UDRS->flags) || 3831 test_bit(FD_VERIFY_BIT, &UDRS->flags) ||
3859 test_bit(drive, &fake_change) || NO_GEOM) { 3832 test_bit(drive, &fake_change) || NO_GEOM) {
3860 if (usage_count == 0) { 3833 if (WARN(atomic_read(&usage_count) == 0,
3861 pr_info("VFS: revalidate called on non-open device.\n"); 3834 "VFS: revalidate called on non-open device.\n"))
3862 return -EFAULT; 3835 return -EFAULT;
3863 } 3836
3864 lock_fdc(drive, false); 3837 lock_fdc(drive, false);
3865 cf = (test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags) || 3838 cf = (test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags) ||
3866 test_bit(FD_VERIFY_BIT, &UDRS->flags)); 3839 test_bit(FD_VERIFY_BIT, &UDRS->flags));
@@ -3893,7 +3866,7 @@ static const struct block_device_operations floppy_fops = {
3893 .owner = THIS_MODULE, 3866 .owner = THIS_MODULE,
3894 .open = floppy_open, 3867 .open = floppy_open,
3895 .release = floppy_release, 3868 .release = floppy_release,
3896 .locked_ioctl = fd_ioctl, 3869 .ioctl = fd_ioctl,
3897 .getgeo = fd_getgeo, 3870 .getgeo = fd_getgeo,
3898 .media_changed = check_floppy_change, 3871 .media_changed = check_floppy_change,
3899 .revalidate_disk = floppy_revalidate, 3872 .revalidate_disk = floppy_revalidate,
@@ -4126,7 +4099,7 @@ static ssize_t floppy_cmos_show(struct device *dev,
4126 return sprintf(buf, "%X\n", UDP->cmos); 4099 return sprintf(buf, "%X\n", UDP->cmos);
4127} 4100}
4128 4101
4129DEVICE_ATTR(cmos, S_IRUGO, floppy_cmos_show, NULL); 4102static DEVICE_ATTR(cmos, S_IRUGO, floppy_cmos_show, NULL);
4130 4103
4131static void floppy_device_release(struct device *dev) 4104static void floppy_device_release(struct device *dev)
4132{ 4105{
@@ -4175,6 +4148,9 @@ static int __init floppy_init(void)
4175 int i, unit, drive; 4148 int i, unit, drive;
4176 int err, dr; 4149 int err, dr;
4177 4150
4151 set_debugt();
4152 interruptjiffies = resultjiffies = jiffies;
4153
4178#if defined(CONFIG_PPC) 4154#if defined(CONFIG_PPC)
4179 if (check_legacy_ioport(FDC1)) 4155 if (check_legacy_ioport(FDC1))
4180 return -ENODEV; 4156 return -ENODEV;
@@ -4353,7 +4329,7 @@ out_unreg_platform_dev:
4353 platform_device_unregister(&floppy_device[drive]); 4329 platform_device_unregister(&floppy_device[drive]);
4354out_flush_work: 4330out_flush_work:
4355 flush_scheduled_work(); 4331 flush_scheduled_work();
4356 if (usage_count) 4332 if (atomic_read(&usage_count))
4357 floppy_release_irq_and_dma(); 4333 floppy_release_irq_and_dma();
4358out_unreg_region: 4334out_unreg_region:
4359 blk_unregister_region(MKDEV(FLOPPY_MAJOR, 0), 256); 4335 blk_unregister_region(MKDEV(FLOPPY_MAJOR, 0), 256);
@@ -4370,8 +4346,6 @@ out_put_disk:
4370 return err; 4346 return err;
4371} 4347}
4372 4348
4373static DEFINE_SPINLOCK(floppy_usage_lock);
4374
4375static const struct io_region { 4349static const struct io_region {
4376 int offset; 4350 int offset;
4377 int size; 4351 int size;
@@ -4417,14 +4391,8 @@ static void floppy_release_regions(int fdc)
4417 4391
4418static int floppy_grab_irq_and_dma(void) 4392static int floppy_grab_irq_and_dma(void)
4419{ 4393{
4420 unsigned long flags; 4394 if (atomic_inc_return(&usage_count) > 1)
4421
4422 spin_lock_irqsave(&floppy_usage_lock, flags);
4423 if (usage_count++) {
4424 spin_unlock_irqrestore(&floppy_usage_lock, flags);
4425 return 0; 4395 return 0;
4426 }
4427 spin_unlock_irqrestore(&floppy_usage_lock, flags);
4428 4396
4429 /* 4397 /*
4430 * We might have scheduled a free_irq(), wait it to 4398 * We might have scheduled a free_irq(), wait it to
@@ -4435,9 +4403,7 @@ static int floppy_grab_irq_and_dma(void)
4435 if (fd_request_irq()) { 4403 if (fd_request_irq()) {
4436 DPRINT("Unable to grab IRQ%d for the floppy driver\n", 4404 DPRINT("Unable to grab IRQ%d for the floppy driver\n",
4437 FLOPPY_IRQ); 4405 FLOPPY_IRQ);
4438 spin_lock_irqsave(&floppy_usage_lock, flags); 4406 atomic_dec(&usage_count);
4439 usage_count--;
4440 spin_unlock_irqrestore(&floppy_usage_lock, flags);
4441 return -1; 4407 return -1;
4442 } 4408 }
4443 if (fd_request_dma()) { 4409 if (fd_request_dma()) {
@@ -4447,9 +4413,7 @@ static int floppy_grab_irq_and_dma(void)
4447 use_virtual_dma = can_use_virtual_dma = 1; 4413 use_virtual_dma = can_use_virtual_dma = 1;
4448 if (!(can_use_virtual_dma & 1)) { 4414 if (!(can_use_virtual_dma & 1)) {
4449 fd_free_irq(); 4415 fd_free_irq();
4450 spin_lock_irqsave(&floppy_usage_lock, flags); 4416 atomic_dec(&usage_count);
4451 usage_count--;
4452 spin_unlock_irqrestore(&floppy_usage_lock, flags);
4453 return -1; 4417 return -1;
4454 } 4418 }
4455 } 4419 }
@@ -4484,9 +4448,7 @@ cleanup:
4484 fd_free_dma(); 4448 fd_free_dma();
4485 while (--fdc >= 0) 4449 while (--fdc >= 0)
4486 floppy_release_regions(fdc); 4450 floppy_release_regions(fdc);
4487 spin_lock_irqsave(&floppy_usage_lock, flags); 4451 atomic_dec(&usage_count);
4488 usage_count--;
4489 spin_unlock_irqrestore(&floppy_usage_lock, flags);
4490 return -1; 4452 return -1;
4491} 4453}
4492 4454
@@ -4498,14 +4460,10 @@ static void floppy_release_irq_and_dma(void)
4498#endif 4460#endif
4499 long tmpsize; 4461 long tmpsize;
4500 unsigned long tmpaddr; 4462 unsigned long tmpaddr;
4501 unsigned long flags;
4502 4463
4503 spin_lock_irqsave(&floppy_usage_lock, flags); 4464 if (!atomic_dec_and_test(&usage_count))
4504 if (--usage_count) {
4505 spin_unlock_irqrestore(&floppy_usage_lock, flags);
4506 return; 4465 return;
4507 } 4466
4508 spin_unlock_irqrestore(&floppy_usage_lock, flags);
4509 if (irqdma_allocated) { 4467 if (irqdma_allocated) {
4510 fd_disable_dma(); 4468 fd_disable_dma();
4511 fd_free_dma(); 4469 fd_free_dma();
@@ -4598,7 +4556,7 @@ static void __exit floppy_module_exit(void)
4598 del_timer_sync(&fd_timer); 4556 del_timer_sync(&fd_timer);
4599 blk_cleanup_queue(floppy_queue); 4557 blk_cleanup_queue(floppy_queue);
4600 4558
4601 if (usage_count) 4559 if (atomic_read(&usage_count))
4602 floppy_release_irq_and_dma(); 4560 floppy_release_irq_and_dma();
4603 4561
4604 /* eject disk, if any */ 4562 /* eject disk, if any */
diff --git a/drivers/block/hd.c b/drivers/block/hd.c
index 81c78b3ce2df..30ec6b37424e 100644
--- a/drivers/block/hd.c
+++ b/drivers/block/hd.c
@@ -627,7 +627,7 @@ repeat:
627 req_data_dir(req) == READ ? "read" : "writ", 627 req_data_dir(req) == READ ? "read" : "writ",
628 cyl, head, sec, nsect, req->buffer); 628 cyl, head, sec, nsect, req->buffer);
629#endif 629#endif
630 if (blk_fs_request(req)) { 630 if (req->cmd_type == REQ_TYPE_FS) {
631 switch (rq_data_dir(req)) { 631 switch (rq_data_dir(req)) {
632 case READ: 632 case READ:
633 hd_out(disk, nsect, sec, head, cyl, ATA_CMD_PIO_READ, 633 hd_out(disk, nsect, sec, head, cyl, ATA_CMD_PIO_READ,
diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index 6120922f459f..f3c636d23718 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -67,6 +67,7 @@
67#include <linux/compat.h> 67#include <linux/compat.h>
68#include <linux/suspend.h> 68#include <linux/suspend.h>
69#include <linux/freezer.h> 69#include <linux/freezer.h>
70#include <linux/smp_lock.h>
70#include <linux/writeback.h> 71#include <linux/writeback.h>
71#include <linux/buffer_head.h> /* for invalidate_bdev() */ 72#include <linux/buffer_head.h> /* for invalidate_bdev() */
72#include <linux/completion.h> 73#include <linux/completion.h>
@@ -476,7 +477,7 @@ static int do_bio_filebacked(struct loop_device *lo, struct bio *bio)
476 pos = ((loff_t) bio->bi_sector << 9) + lo->lo_offset; 477 pos = ((loff_t) bio->bi_sector << 9) + lo->lo_offset;
477 478
478 if (bio_rw(bio) == WRITE) { 479 if (bio_rw(bio) == WRITE) {
479 bool barrier = bio_rw_flagged(bio, BIO_RW_BARRIER); 480 bool barrier = (bio->bi_rw & REQ_HARDBARRIER);
480 struct file *file = lo->lo_backing_file; 481 struct file *file = lo->lo_backing_file;
481 482
482 if (barrier) { 483 if (barrier) {
@@ -831,7 +832,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
831 lo->lo_queue->unplug_fn = loop_unplug; 832 lo->lo_queue->unplug_fn = loop_unplug;
832 833
833 if (!(lo_flags & LO_FLAGS_READ_ONLY) && file->f_op->fsync) 834 if (!(lo_flags & LO_FLAGS_READ_ONLY) && file->f_op->fsync)
834 blk_queue_ordered(lo->lo_queue, QUEUE_ORDERED_DRAIN, NULL); 835 blk_queue_ordered(lo->lo_queue, QUEUE_ORDERED_DRAIN);
835 836
836 set_capacity(lo->lo_disk, size); 837 set_capacity(lo->lo_disk, size);
837 bd_set_size(bdev, size << 9); 838 bd_set_size(bdev, size << 9);
@@ -1408,9 +1409,11 @@ static int lo_open(struct block_device *bdev, fmode_t mode)
1408{ 1409{
1409 struct loop_device *lo = bdev->bd_disk->private_data; 1410 struct loop_device *lo = bdev->bd_disk->private_data;
1410 1411
1412 lock_kernel();
1411 mutex_lock(&lo->lo_ctl_mutex); 1413 mutex_lock(&lo->lo_ctl_mutex);
1412 lo->lo_refcnt++; 1414 lo->lo_refcnt++;
1413 mutex_unlock(&lo->lo_ctl_mutex); 1415 mutex_unlock(&lo->lo_ctl_mutex);
1416 unlock_kernel();
1414 1417
1415 return 0; 1418 return 0;
1416} 1419}
@@ -1420,6 +1423,7 @@ static int lo_release(struct gendisk *disk, fmode_t mode)
1420 struct loop_device *lo = disk->private_data; 1423 struct loop_device *lo = disk->private_data;
1421 int err; 1424 int err;
1422 1425
1426 lock_kernel();
1423 mutex_lock(&lo->lo_ctl_mutex); 1427 mutex_lock(&lo->lo_ctl_mutex);
1424 1428
1425 if (--lo->lo_refcnt) 1429 if (--lo->lo_refcnt)
@@ -1444,6 +1448,7 @@ static int lo_release(struct gendisk *disk, fmode_t mode)
1444out: 1448out:
1445 mutex_unlock(&lo->lo_ctl_mutex); 1449 mutex_unlock(&lo->lo_ctl_mutex);
1446out_unlocked: 1450out_unlocked:
1451 lock_kernel();
1447 return 0; 1452 return 0;
1448} 1453}
1449 1454
diff --git a/drivers/block/mg_disk.c b/drivers/block/mg_disk.c
index 28db925dbdad..b82c5ce5e9df 100644
--- a/drivers/block/mg_disk.c
+++ b/drivers/block/mg_disk.c
@@ -670,7 +670,7 @@ static void mg_request_poll(struct request_queue *q)
670 break; 670 break;
671 } 671 }
672 672
673 if (unlikely(!blk_fs_request(host->req))) { 673 if (unlikely(host->req->cmd_type != REQ_TYPE_FS)) {
674 mg_end_request_cur(host, -EIO); 674 mg_end_request_cur(host, -EIO);
675 continue; 675 continue;
676 } 676 }
@@ -756,7 +756,7 @@ static void mg_request(struct request_queue *q)
756 continue; 756 continue;
757 } 757 }
758 758
759 if (unlikely(!blk_fs_request(req))) { 759 if (unlikely(req->cmd_type != REQ_TYPE_FS)) {
760 mg_end_request_cur(host, -EIO); 760 mg_end_request_cur(host, -EIO);
761 continue; 761 continue;
762 } 762 }
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 16c3c8613cd3..0daa422aa281 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -24,6 +24,7 @@
24#include <linux/errno.h> 24#include <linux/errno.h>
25#include <linux/file.h> 25#include <linux/file.h>
26#include <linux/ioctl.h> 26#include <linux/ioctl.h>
27#include <linux/smp_lock.h>
27#include <linux/compiler.h> 28#include <linux/compiler.h>
28#include <linux/err.h> 29#include <linux/err.h>
29#include <linux/kernel.h> 30#include <linux/kernel.h>
@@ -448,7 +449,7 @@ static void nbd_clear_que(struct nbd_device *lo)
448 449
449static void nbd_handle_req(struct nbd_device *lo, struct request *req) 450static void nbd_handle_req(struct nbd_device *lo, struct request *req)
450{ 451{
451 if (!blk_fs_request(req)) 452 if (req->cmd_type != REQ_TYPE_FS)
452 goto error_out; 453 goto error_out;
453 454
454 nbd_cmd(req) = NBD_CMD_READ; 455 nbd_cmd(req) = NBD_CMD_READ;
@@ -716,9 +717,11 @@ static int nbd_ioctl(struct block_device *bdev, fmode_t mode,
716 dprintk(DBG_IOCTL, "%s: nbd_ioctl cmd=%s(0x%x) arg=%lu\n", 717 dprintk(DBG_IOCTL, "%s: nbd_ioctl cmd=%s(0x%x) arg=%lu\n",
717 lo->disk->disk_name, ioctl_cmd_to_ascii(cmd), cmd, arg); 718 lo->disk->disk_name, ioctl_cmd_to_ascii(cmd), cmd, arg);
718 719
720 lock_kernel();
719 mutex_lock(&lo->tx_lock); 721 mutex_lock(&lo->tx_lock);
720 error = __nbd_ioctl(bdev, lo, cmd, arg); 722 error = __nbd_ioctl(bdev, lo, cmd, arg);
721 mutex_unlock(&lo->tx_lock); 723 mutex_unlock(&lo->tx_lock);
724 unlock_kernel();
722 725
723 return error; 726 return error;
724} 727}
@@ -726,7 +729,7 @@ static int nbd_ioctl(struct block_device *bdev, fmode_t mode,
726static const struct block_device_operations nbd_fops = 729static const struct block_device_operations nbd_fops =
727{ 730{
728 .owner = THIS_MODULE, 731 .owner = THIS_MODULE,
729 .locked_ioctl = nbd_ioctl, 732 .ioctl = nbd_ioctl,
730}; 733};
731 734
732/* 735/*
diff --git a/drivers/block/osdblk.c b/drivers/block/osdblk.c
index 6cd8b705b11b..2284b4f05c62 100644
--- a/drivers/block/osdblk.c
+++ b/drivers/block/osdblk.c
@@ -310,7 +310,8 @@ static void osdblk_rq_fn(struct request_queue *q)
310 break; 310 break;
311 311
312 /* filter out block requests we don't understand */ 312 /* filter out block requests we don't understand */
313 if (!blk_fs_request(rq) && !blk_barrier_rq(rq)) { 313 if (rq->cmd_type != REQ_TYPE_FS &&
314 !(rq->cmd_flags & REQ_HARDBARRIER)) {
314 blk_end_request_all(rq, 0); 315 blk_end_request_all(rq, 0);
315 continue; 316 continue;
316 } 317 }
@@ -322,7 +323,7 @@ static void osdblk_rq_fn(struct request_queue *q)
322 * driver-specific, etc. 323 * driver-specific, etc.
323 */ 324 */
324 325
325 do_flush = (rq->special == (void *) 0xdeadbeefUL); 326 do_flush = rq->cmd_flags & REQ_FLUSH;
326 do_write = (rq_data_dir(rq) == WRITE); 327 do_write = (rq_data_dir(rq) == WRITE);
327 328
328 if (!do_flush) { /* osd_flush does not use a bio */ 329 if (!do_flush) { /* osd_flush does not use a bio */
@@ -379,14 +380,6 @@ static void osdblk_rq_fn(struct request_queue *q)
379 } 380 }
380} 381}
381 382
382static void osdblk_prepare_flush(struct request_queue *q, struct request *rq)
383{
384 /* add driver-specific marker, to indicate that this request
385 * is a flush command
386 */
387 rq->special = (void *) 0xdeadbeefUL;
388}
389
390static void osdblk_free_disk(struct osdblk_device *osdev) 383static void osdblk_free_disk(struct osdblk_device *osdev)
391{ 384{
392 struct gendisk *disk = osdev->disk; 385 struct gendisk *disk = osdev->disk;
@@ -446,7 +439,7 @@ static int osdblk_init_disk(struct osdblk_device *osdev)
446 blk_queue_stack_limits(q, osd_request_queue(osdev->osd)); 439 blk_queue_stack_limits(q, osd_request_queue(osdev->osd));
447 440
448 blk_queue_prep_rq(q, blk_queue_start_tag); 441 blk_queue_prep_rq(q, blk_queue_start_tag);
449 blk_queue_ordered(q, QUEUE_ORDERED_DRAIN_FLUSH, osdblk_prepare_flush); 442 blk_queue_ordered(q, QUEUE_ORDERED_DRAIN_FLUSH);
450 443
451 disk->queue = q; 444 disk->queue = q;
452 445
diff --git a/drivers/block/paride/pcd.c b/drivers/block/paride/pcd.c
index 71acf4e53356..76f8565e1e8d 100644
--- a/drivers/block/paride/pcd.c
+++ b/drivers/block/paride/pcd.c
@@ -138,6 +138,7 @@ enum {D_PRT, D_PRO, D_UNI, D_MOD, D_SLV, D_DLY};
138#include <linux/cdrom.h> 138#include <linux/cdrom.h>
139#include <linux/spinlock.h> 139#include <linux/spinlock.h>
140#include <linux/blkdev.h> 140#include <linux/blkdev.h>
141#include <linux/smp_lock.h>
141#include <asm/uaccess.h> 142#include <asm/uaccess.h>
142 143
143static DEFINE_SPINLOCK(pcd_lock); 144static DEFINE_SPINLOCK(pcd_lock);
@@ -224,13 +225,21 @@ static char *pcd_buf; /* buffer for request in progress */
224static int pcd_block_open(struct block_device *bdev, fmode_t mode) 225static int pcd_block_open(struct block_device *bdev, fmode_t mode)
225{ 226{
226 struct pcd_unit *cd = bdev->bd_disk->private_data; 227 struct pcd_unit *cd = bdev->bd_disk->private_data;
227 return cdrom_open(&cd->info, bdev, mode); 228 int ret;
229
230 lock_kernel();
231 ret = cdrom_open(&cd->info, bdev, mode);
232 unlock_kernel();
233
234 return ret;
228} 235}
229 236
230static int pcd_block_release(struct gendisk *disk, fmode_t mode) 237static int pcd_block_release(struct gendisk *disk, fmode_t mode)
231{ 238{
232 struct pcd_unit *cd = disk->private_data; 239 struct pcd_unit *cd = disk->private_data;
240 lock_kernel();
233 cdrom_release(&cd->info, mode); 241 cdrom_release(&cd->info, mode);
242 unlock_kernel();
234 return 0; 243 return 0;
235} 244}
236 245
@@ -238,7 +247,13 @@ static int pcd_block_ioctl(struct block_device *bdev, fmode_t mode,
238 unsigned cmd, unsigned long arg) 247 unsigned cmd, unsigned long arg)
239{ 248{
240 struct pcd_unit *cd = bdev->bd_disk->private_data; 249 struct pcd_unit *cd = bdev->bd_disk->private_data;
241 return cdrom_ioctl(&cd->info, bdev, mode, cmd, arg); 250 int ret;
251
252 lock_kernel();
253 ret = cdrom_ioctl(&cd->info, bdev, mode, cmd, arg);
254 unlock_kernel();
255
256 return ret;
242} 257}
243 258
244static int pcd_block_media_changed(struct gendisk *disk) 259static int pcd_block_media_changed(struct gendisk *disk)
@@ -251,7 +266,7 @@ static const struct block_device_operations pcd_bdops = {
251 .owner = THIS_MODULE, 266 .owner = THIS_MODULE,
252 .open = pcd_block_open, 267 .open = pcd_block_open,
253 .release = pcd_block_release, 268 .release = pcd_block_release,
254 .locked_ioctl = pcd_block_ioctl, 269 .ioctl = pcd_block_ioctl,
255 .media_changed = pcd_block_media_changed, 270 .media_changed = pcd_block_media_changed,
256}; 271};
257 272
diff --git a/drivers/block/paride/pd.c b/drivers/block/paride/pd.c
index c1e5cd029b23..985f0d4f1d1e 100644
--- a/drivers/block/paride/pd.c
+++ b/drivers/block/paride/pd.c
@@ -153,6 +153,7 @@ enum {D_PRT, D_PRO, D_UNI, D_MOD, D_GEO, D_SBY, D_DLY, D_SLV};
153#include <linux/blkdev.h> 153#include <linux/blkdev.h>
154#include <linux/blkpg.h> 154#include <linux/blkpg.h>
155#include <linux/kernel.h> 155#include <linux/kernel.h>
156#include <linux/smp_lock.h>
156#include <asm/uaccess.h> 157#include <asm/uaccess.h>
157#include <linux/workqueue.h> 158#include <linux/workqueue.h>
158 159
@@ -439,7 +440,7 @@ static char *pd_buf; /* buffer for request in progress */
439 440
440static enum action do_pd_io_start(void) 441static enum action do_pd_io_start(void)
441{ 442{
442 if (blk_special_request(pd_req)) { 443 if (pd_req->cmd_type == REQ_TYPE_SPECIAL) {
443 phase = pd_special; 444 phase = pd_special;
444 return pd_special(); 445 return pd_special();
445 } 446 }
@@ -735,12 +736,14 @@ static int pd_open(struct block_device *bdev, fmode_t mode)
735{ 736{
736 struct pd_unit *disk = bdev->bd_disk->private_data; 737 struct pd_unit *disk = bdev->bd_disk->private_data;
737 738
739 lock_kernel();
738 disk->access++; 740 disk->access++;
739 741
740 if (disk->removable) { 742 if (disk->removable) {
741 pd_special_command(disk, pd_media_check); 743 pd_special_command(disk, pd_media_check);
742 pd_special_command(disk, pd_door_lock); 744 pd_special_command(disk, pd_door_lock);
743 } 745 }
746 unlock_kernel();
744 return 0; 747 return 0;
745} 748}
746 749
@@ -768,8 +771,10 @@ static int pd_ioctl(struct block_device *bdev, fmode_t mode,
768 771
769 switch (cmd) { 772 switch (cmd) {
770 case CDROMEJECT: 773 case CDROMEJECT:
774 lock_kernel();
771 if (disk->access == 1) 775 if (disk->access == 1)
772 pd_special_command(disk, pd_eject); 776 pd_special_command(disk, pd_eject);
777 unlock_kernel();
773 return 0; 778 return 0;
774 default: 779 default:
775 return -EINVAL; 780 return -EINVAL;
@@ -780,8 +785,10 @@ static int pd_release(struct gendisk *p, fmode_t mode)
780{ 785{
781 struct pd_unit *disk = p->private_data; 786 struct pd_unit *disk = p->private_data;
782 787
788 lock_kernel();
783 if (!--disk->access && disk->removable) 789 if (!--disk->access && disk->removable)
784 pd_special_command(disk, pd_door_unlock); 790 pd_special_command(disk, pd_door_unlock);
791 unlock_kernel();
785 792
786 return 0; 793 return 0;
787} 794}
@@ -812,7 +819,7 @@ static const struct block_device_operations pd_fops = {
812 .owner = THIS_MODULE, 819 .owner = THIS_MODULE,
813 .open = pd_open, 820 .open = pd_open,
814 .release = pd_release, 821 .release = pd_release,
815 .locked_ioctl = pd_ioctl, 822 .ioctl = pd_ioctl,
816 .getgeo = pd_getgeo, 823 .getgeo = pd_getgeo,
817 .media_changed = pd_check_media, 824 .media_changed = pd_check_media,
818 .revalidate_disk= pd_revalidate 825 .revalidate_disk= pd_revalidate
diff --git a/drivers/block/paride/pf.c b/drivers/block/paride/pf.c
index c059aab3006b..4457b494882a 100644
--- a/drivers/block/paride/pf.c
+++ b/drivers/block/paride/pf.c
@@ -152,6 +152,7 @@ enum {D_PRT, D_PRO, D_UNI, D_MOD, D_SLV, D_LUN, D_DLY};
152#include <linux/spinlock.h> 152#include <linux/spinlock.h>
153#include <linux/blkdev.h> 153#include <linux/blkdev.h>
154#include <linux/blkpg.h> 154#include <linux/blkpg.h>
155#include <linux/smp_lock.h>
155#include <asm/uaccess.h> 156#include <asm/uaccess.h>
156 157
157static DEFINE_SPINLOCK(pf_spin_lock); 158static DEFINE_SPINLOCK(pf_spin_lock);
@@ -266,7 +267,7 @@ static const struct block_device_operations pf_fops = {
266 .owner = THIS_MODULE, 267 .owner = THIS_MODULE,
267 .open = pf_open, 268 .open = pf_open,
268 .release = pf_release, 269 .release = pf_release,
269 .locked_ioctl = pf_ioctl, 270 .ioctl = pf_ioctl,
270 .getgeo = pf_getgeo, 271 .getgeo = pf_getgeo,
271 .media_changed = pf_check_media, 272 .media_changed = pf_check_media,
272}; 273};
@@ -299,20 +300,26 @@ static void __init pf_init_units(void)
299static int pf_open(struct block_device *bdev, fmode_t mode) 300static int pf_open(struct block_device *bdev, fmode_t mode)
300{ 301{
301 struct pf_unit *pf = bdev->bd_disk->private_data; 302 struct pf_unit *pf = bdev->bd_disk->private_data;
303 int ret;
302 304
305 lock_kernel();
303 pf_identify(pf); 306 pf_identify(pf);
304 307
308 ret = -ENODEV;
305 if (pf->media_status == PF_NM) 309 if (pf->media_status == PF_NM)
306 return -ENODEV; 310 goto out;
307 311
312 ret = -EROFS;
308 if ((pf->media_status == PF_RO) && (mode & FMODE_WRITE)) 313 if ((pf->media_status == PF_RO) && (mode & FMODE_WRITE))
309 return -EROFS; 314 goto out;
310 315
316 ret = 0;
311 pf->access++; 317 pf->access++;
312 if (pf->removable) 318 if (pf->removable)
313 pf_lock(pf, 1); 319 pf_lock(pf, 1);
314 320out:
315 return 0; 321 unlock_kernel();
322 return ret;
316} 323}
317 324
318static int pf_getgeo(struct block_device *bdev, struct hd_geometry *geo) 325static int pf_getgeo(struct block_device *bdev, struct hd_geometry *geo)
@@ -342,7 +349,10 @@ static int pf_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, u
342 349
343 if (pf->access != 1) 350 if (pf->access != 1)
344 return -EBUSY; 351 return -EBUSY;
352 lock_kernel();
345 pf_eject(pf); 353 pf_eject(pf);
354 unlock_kernel();
355
346 return 0; 356 return 0;
347} 357}
348 358
@@ -350,14 +360,18 @@ static int pf_release(struct gendisk *disk, fmode_t mode)
350{ 360{
351 struct pf_unit *pf = disk->private_data; 361 struct pf_unit *pf = disk->private_data;
352 362
353 if (pf->access <= 0) 363 lock_kernel();
364 if (pf->access <= 0) {
365 unlock_kernel();
354 return -EINVAL; 366 return -EINVAL;
367 }
355 368
356 pf->access--; 369 pf->access--;
357 370
358 if (!pf->access && pf->removable) 371 if (!pf->access && pf->removable)
359 pf_lock(pf, 0); 372 pf_lock(pf, 0);
360 373
374 unlock_kernel();
361 return 0; 375 return 0;
362 376
363} 377}
diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
index 8a549db2aa78..b1cbeb59bb76 100644
--- a/drivers/block/pktcdvd.c
+++ b/drivers/block/pktcdvd.c
@@ -57,6 +57,7 @@
57#include <linux/seq_file.h> 57#include <linux/seq_file.h>
58#include <linux/miscdevice.h> 58#include <linux/miscdevice.h>
59#include <linux/freezer.h> 59#include <linux/freezer.h>
60#include <linux/smp_lock.h>
60#include <linux/mutex.h> 61#include <linux/mutex.h>
61#include <linux/slab.h> 62#include <linux/slab.h>
62#include <scsi/scsi_cmnd.h> 63#include <scsi/scsi_cmnd.h>
@@ -1221,7 +1222,7 @@ static int pkt_start_recovery(struct packet_data *pkt)
1221 pkt->bio->bi_flags = 1 << BIO_UPTODATE; 1222 pkt->bio->bi_flags = 1 << BIO_UPTODATE;
1222 pkt->bio->bi_idx = 0; 1223 pkt->bio->bi_idx = 0;
1223 1224
1224 BUG_ON(pkt->bio->bi_rw != (1 << BIO_RW)); 1225 BUG_ON(pkt->bio->bi_rw != REQ_WRITE);
1225 BUG_ON(pkt->bio->bi_vcnt != pkt->frames); 1226 BUG_ON(pkt->bio->bi_vcnt != pkt->frames);
1226 BUG_ON(pkt->bio->bi_size != pkt->frames * CD_FRAMESIZE); 1227 BUG_ON(pkt->bio->bi_size != pkt->frames * CD_FRAMESIZE);
1227 BUG_ON(pkt->bio->bi_end_io != pkt_end_io_packet_write); 1228 BUG_ON(pkt->bio->bi_end_io != pkt_end_io_packet_write);
@@ -2382,6 +2383,7 @@ static int pkt_open(struct block_device *bdev, fmode_t mode)
2382 2383
2383 VPRINTK(DRIVER_NAME": entering open\n"); 2384 VPRINTK(DRIVER_NAME": entering open\n");
2384 2385
2386 lock_kernel();
2385 mutex_lock(&ctl_mutex); 2387 mutex_lock(&ctl_mutex);
2386 pd = pkt_find_dev_from_minor(MINOR(bdev->bd_dev)); 2388 pd = pkt_find_dev_from_minor(MINOR(bdev->bd_dev));
2387 if (!pd) { 2389 if (!pd) {
@@ -2409,6 +2411,7 @@ static int pkt_open(struct block_device *bdev, fmode_t mode)
2409 } 2411 }
2410 2412
2411 mutex_unlock(&ctl_mutex); 2413 mutex_unlock(&ctl_mutex);
2414 unlock_kernel();
2412 return 0; 2415 return 0;
2413 2416
2414out_dec: 2417out_dec:
@@ -2416,6 +2419,7 @@ out_dec:
2416out: 2419out:
2417 VPRINTK(DRIVER_NAME": failed open (%d)\n", ret); 2420 VPRINTK(DRIVER_NAME": failed open (%d)\n", ret);
2418 mutex_unlock(&ctl_mutex); 2421 mutex_unlock(&ctl_mutex);
2422 unlock_kernel();
2419 return ret; 2423 return ret;
2420} 2424}
2421 2425
@@ -2424,6 +2428,7 @@ static int pkt_close(struct gendisk *disk, fmode_t mode)
2424 struct pktcdvd_device *pd = disk->private_data; 2428 struct pktcdvd_device *pd = disk->private_data;
2425 int ret = 0; 2429 int ret = 0;
2426 2430
2431 lock_kernel();
2427 mutex_lock(&ctl_mutex); 2432 mutex_lock(&ctl_mutex);
2428 pd->refcnt--; 2433 pd->refcnt--;
2429 BUG_ON(pd->refcnt < 0); 2434 BUG_ON(pd->refcnt < 0);
@@ -2432,6 +2437,7 @@ static int pkt_close(struct gendisk *disk, fmode_t mode)
2432 pkt_release_dev(pd, flush); 2437 pkt_release_dev(pd, flush);
2433 } 2438 }
2434 mutex_unlock(&ctl_mutex); 2439 mutex_unlock(&ctl_mutex);
2440 unlock_kernel();
2435 return ret; 2441 return ret;
2436} 2442}
2437 2443
@@ -2762,10 +2768,12 @@ out_mem:
2762static int pkt_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, unsigned long arg) 2768static int pkt_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, unsigned long arg)
2763{ 2769{
2764 struct pktcdvd_device *pd = bdev->bd_disk->private_data; 2770 struct pktcdvd_device *pd = bdev->bd_disk->private_data;
2771 int ret;
2765 2772
2766 VPRINTK("pkt_ioctl: cmd %x, dev %d:%d\n", cmd, 2773 VPRINTK("pkt_ioctl: cmd %x, dev %d:%d\n", cmd,
2767 MAJOR(bdev->bd_dev), MINOR(bdev->bd_dev)); 2774 MAJOR(bdev->bd_dev), MINOR(bdev->bd_dev));
2768 2775
2776 lock_kernel();
2769 switch (cmd) { 2777 switch (cmd) {
2770 case CDROMEJECT: 2778 case CDROMEJECT:
2771 /* 2779 /*
@@ -2783,14 +2791,16 @@ static int pkt_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
2783 case CDROM_LAST_WRITTEN: 2791 case CDROM_LAST_WRITTEN:
2784 case CDROM_SEND_PACKET: 2792 case CDROM_SEND_PACKET:
2785 case SCSI_IOCTL_SEND_COMMAND: 2793 case SCSI_IOCTL_SEND_COMMAND:
2786 return __blkdev_driver_ioctl(pd->bdev, mode, cmd, arg); 2794 ret = __blkdev_driver_ioctl(pd->bdev, mode, cmd, arg);
2795 break;
2787 2796
2788 default: 2797 default:
2789 VPRINTK(DRIVER_NAME": Unknown ioctl for %s (%x)\n", pd->name, cmd); 2798 VPRINTK(DRIVER_NAME": Unknown ioctl for %s (%x)\n", pd->name, cmd);
2790 return -ENOTTY; 2799 ret = -ENOTTY;
2791 } 2800 }
2801 unlock_kernel();
2792 2802
2793 return 0; 2803 return ret;
2794} 2804}
2795 2805
2796static int pkt_media_changed(struct gendisk *disk) 2806static int pkt_media_changed(struct gendisk *disk)
@@ -2812,7 +2822,7 @@ static const struct block_device_operations pktcdvd_ops = {
2812 .owner = THIS_MODULE, 2822 .owner = THIS_MODULE,
2813 .open = pkt_open, 2823 .open = pkt_open,
2814 .release = pkt_close, 2824 .release = pkt_close,
2815 .locked_ioctl = pkt_ioctl, 2825 .ioctl = pkt_ioctl,
2816 .media_changed = pkt_media_changed, 2826 .media_changed = pkt_media_changed,
2817}; 2827};
2818 2828
diff --git a/drivers/block/ps3disk.c b/drivers/block/ps3disk.c
index 3b419e3fffa1..e9da874d0419 100644
--- a/drivers/block/ps3disk.c
+++ b/drivers/block/ps3disk.c
@@ -196,13 +196,12 @@ static void ps3disk_do_request(struct ps3_storage_device *dev,
196 dev_dbg(&dev->sbd.core, "%s:%u\n", __func__, __LINE__); 196 dev_dbg(&dev->sbd.core, "%s:%u\n", __func__, __LINE__);
197 197
198 while ((req = blk_fetch_request(q))) { 198 while ((req = blk_fetch_request(q))) {
199 if (blk_fs_request(req)) { 199 if (req->cmd_flags & REQ_FLUSH) {
200 if (ps3disk_submit_request_sg(dev, req))
201 break;
202 } else if (req->cmd_type == REQ_TYPE_LINUX_BLOCK &&
203 req->cmd[0] == REQ_LB_OP_FLUSH) {
204 if (ps3disk_submit_flush_request(dev, req)) 200 if (ps3disk_submit_flush_request(dev, req))
205 break; 201 break;
202 } else if (req->cmd_type == REQ_TYPE_FS) {
203 if (ps3disk_submit_request_sg(dev, req))
204 break;
206 } else { 205 } else {
207 blk_dump_rq_flags(req, DEVICE_NAME " bad request"); 206 blk_dump_rq_flags(req, DEVICE_NAME " bad request");
208 __blk_end_request_all(req, -EIO); 207 __blk_end_request_all(req, -EIO);
@@ -257,8 +256,7 @@ static irqreturn_t ps3disk_interrupt(int irq, void *data)
257 return IRQ_HANDLED; 256 return IRQ_HANDLED;
258 } 257 }
259 258
260 if (req->cmd_type == REQ_TYPE_LINUX_BLOCK && 259 if (req->cmd_flags & REQ_FLUSH) {
261 req->cmd[0] == REQ_LB_OP_FLUSH) {
262 read = 0; 260 read = 0;
263 op = "flush"; 261 op = "flush";
264 } else { 262 } else {
@@ -398,16 +396,6 @@ static int ps3disk_identify(struct ps3_storage_device *dev)
398 return 0; 396 return 0;
399} 397}
400 398
401static void ps3disk_prepare_flush(struct request_queue *q, struct request *req)
402{
403 struct ps3_storage_device *dev = q->queuedata;
404
405 dev_dbg(&dev->sbd.core, "%s:%u\n", __func__, __LINE__);
406
407 req->cmd_type = REQ_TYPE_LINUX_BLOCK;
408 req->cmd[0] = REQ_LB_OP_FLUSH;
409}
410
411static unsigned long ps3disk_mask; 399static unsigned long ps3disk_mask;
412 400
413static DEFINE_MUTEX(ps3disk_mask_mutex); 401static DEFINE_MUTEX(ps3disk_mask_mutex);
@@ -480,8 +468,7 @@ static int __devinit ps3disk_probe(struct ps3_system_bus_device *_dev)
480 blk_queue_dma_alignment(queue, dev->blk_size-1); 468 blk_queue_dma_alignment(queue, dev->blk_size-1);
481 blk_queue_logical_block_size(queue, dev->blk_size); 469 blk_queue_logical_block_size(queue, dev->blk_size);
482 470
483 blk_queue_ordered(queue, QUEUE_ORDERED_DRAIN_FLUSH, 471 blk_queue_ordered(queue, QUEUE_ORDERED_DRAIN_FLUSH);
484 ps3disk_prepare_flush);
485 472
486 blk_queue_max_segments(queue, -1); 473 blk_queue_max_segments(queue, -1);
487 blk_queue_max_segment_size(queue, dev->bounce_size); 474 blk_queue_max_segment_size(queue, dev->bounce_size);
diff --git a/drivers/block/swim.c b/drivers/block/swim.c
index e463657569ff..2e46815876df 100644
--- a/drivers/block/swim.c
+++ b/drivers/block/swim.c
@@ -20,6 +20,7 @@
20#include <linux/fd.h> 20#include <linux/fd.h>
21#include <linux/slab.h> 21#include <linux/slab.h>
22#include <linux/blkdev.h> 22#include <linux/blkdev.h>
23#include <linux/smp_lock.h>
23#include <linux/hdreg.h> 24#include <linux/hdreg.h>
24#include <linux/kernel.h> 25#include <linux/kernel.h>
25#include <linux/delay.h> 26#include <linux/delay.h>
@@ -661,11 +662,23 @@ out:
661 return err; 662 return err;
662} 663}
663 664
665static int floppy_unlocked_open(struct block_device *bdev, fmode_t mode)
666{
667 int ret;
668
669 lock_kernel();
670 ret = floppy_open(bdev, mode);
671 unlock_kernel();
672
673 return ret;
674}
675
664static int floppy_release(struct gendisk *disk, fmode_t mode) 676static int floppy_release(struct gendisk *disk, fmode_t mode)
665{ 677{
666 struct floppy_state *fs = disk->private_data; 678 struct floppy_state *fs = disk->private_data;
667 struct swim __iomem *base = fs->swd->base; 679 struct swim __iomem *base = fs->swd->base;
668 680
681 lock_kernel();
669 if (fs->ref_count < 0) 682 if (fs->ref_count < 0)
670 fs->ref_count = 0; 683 fs->ref_count = 0;
671 else if (fs->ref_count > 0) 684 else if (fs->ref_count > 0)
@@ -673,6 +686,7 @@ static int floppy_release(struct gendisk *disk, fmode_t mode)
673 686
674 if (fs->ref_count == 0) 687 if (fs->ref_count == 0)
675 swim_motor(base, OFF); 688 swim_motor(base, OFF);
689 unlock_kernel();
676 690
677 return 0; 691 return 0;
678} 692}
@@ -690,7 +704,9 @@ static int floppy_ioctl(struct block_device *bdev, fmode_t mode,
690 case FDEJECT: 704 case FDEJECT:
691 if (fs->ref_count != 1) 705 if (fs->ref_count != 1)
692 return -EBUSY; 706 return -EBUSY;
707 lock_kernel();
693 err = floppy_eject(fs); 708 err = floppy_eject(fs);
709 unlock_kernel();
694 return err; 710 return err;
695 711
696 case FDGETPRM: 712 case FDGETPRM:
@@ -751,9 +767,9 @@ static int floppy_revalidate(struct gendisk *disk)
751 767
752static const struct block_device_operations floppy_fops = { 768static const struct block_device_operations floppy_fops = {
753 .owner = THIS_MODULE, 769 .owner = THIS_MODULE,
754 .open = floppy_open, 770 .open = floppy_unlocked_open,
755 .release = floppy_release, 771 .release = floppy_release,
756 .locked_ioctl = floppy_ioctl, 772 .ioctl = floppy_ioctl,
757 .getgeo = floppy_getgeo, 773 .getgeo = floppy_getgeo,
758 .media_changed = floppy_check_change, 774 .media_changed = floppy_check_change,
759 .revalidate_disk = floppy_revalidate, 775 .revalidate_disk = floppy_revalidate,
diff --git a/drivers/block/swim3.c b/drivers/block/swim3.c
index ed6fb91123ab..cc6a3864822c 100644
--- a/drivers/block/swim3.c
+++ b/drivers/block/swim3.c
@@ -25,6 +25,7 @@
25#include <linux/ioctl.h> 25#include <linux/ioctl.h>
26#include <linux/blkdev.h> 26#include <linux/blkdev.h>
27#include <linux/interrupt.h> 27#include <linux/interrupt.h>
28#include <linux/smp_lock.h>
28#include <linux/module.h> 29#include <linux/module.h>
29#include <linux/spinlock.h> 30#include <linux/spinlock.h>
30#include <asm/io.h> 31#include <asm/io.h>
@@ -839,7 +840,7 @@ static int fd_eject(struct floppy_state *fs)
839static struct floppy_struct floppy_type = 840static struct floppy_struct floppy_type =
840 { 2880,18,2,80,0,0x1B,0x00,0xCF,0x6C,NULL }; /* 7 1.44MB 3.5" */ 841 { 2880,18,2,80,0,0x1B,0x00,0xCF,0x6C,NULL }; /* 7 1.44MB 3.5" */
841 842
842static int floppy_ioctl(struct block_device *bdev, fmode_t mode, 843static int floppy_locked_ioctl(struct block_device *bdev, fmode_t mode,
843 unsigned int cmd, unsigned long param) 844 unsigned int cmd, unsigned long param)
844{ 845{
845 struct floppy_state *fs = bdev->bd_disk->private_data; 846 struct floppy_state *fs = bdev->bd_disk->private_data;
@@ -867,6 +868,18 @@ static int floppy_ioctl(struct block_device *bdev, fmode_t mode,
867 return -ENOTTY; 868 return -ENOTTY;
868} 869}
869 870
871static int floppy_ioctl(struct block_device *bdev, fmode_t mode,
872 unsigned int cmd, unsigned long param)
873{
874 int ret;
875
876 lock_kernel();
877 ret = floppy_locked_ioctl(bdev, mode, cmd, param);
878 unlock_kernel();
879
880 return ret;
881}
882
870static int floppy_open(struct block_device *bdev, fmode_t mode) 883static int floppy_open(struct block_device *bdev, fmode_t mode)
871{ 884{
872 struct floppy_state *fs = bdev->bd_disk->private_data; 885 struct floppy_state *fs = bdev->bd_disk->private_data;
@@ -936,15 +949,28 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
936 return 0; 949 return 0;
937} 950}
938 951
952static int floppy_unlocked_open(struct block_device *bdev, fmode_t mode)
953{
954 int ret;
955
956 lock_kernel();
957 ret = floppy_open(bdev, mode);
958 unlock_kernel();
959
960 return ret;
961}
962
939static int floppy_release(struct gendisk *disk, fmode_t mode) 963static int floppy_release(struct gendisk *disk, fmode_t mode)
940{ 964{
941 struct floppy_state *fs = disk->private_data; 965 struct floppy_state *fs = disk->private_data;
942 struct swim3 __iomem *sw = fs->swim3; 966 struct swim3 __iomem *sw = fs->swim3;
967 lock_kernel();
943 if (fs->ref_count > 0 && --fs->ref_count == 0) { 968 if (fs->ref_count > 0 && --fs->ref_count == 0) {
944 swim3_action(fs, MOTOR_OFF); 969 swim3_action(fs, MOTOR_OFF);
945 out_8(&sw->control_bic, 0xff); 970 out_8(&sw->control_bic, 0xff);
946 swim3_select(fs, RELAX); 971 swim3_select(fs, RELAX);
947 } 972 }
973 unlock_kernel();
948 return 0; 974 return 0;
949} 975}
950 976
@@ -995,9 +1021,9 @@ static int floppy_revalidate(struct gendisk *disk)
995} 1021}
996 1022
997static const struct block_device_operations floppy_fops = { 1023static const struct block_device_operations floppy_fops = {
998 .open = floppy_open, 1024 .open = floppy_unlocked_open,
999 .release = floppy_release, 1025 .release = floppy_release,
1000 .locked_ioctl = floppy_ioctl, 1026 .ioctl = floppy_ioctl,
1001 .media_changed = floppy_check_change, 1027 .media_changed = floppy_check_change,
1002 .revalidate_disk= floppy_revalidate, 1028 .revalidate_disk= floppy_revalidate,
1003}; 1029};
diff --git a/drivers/block/ub.c b/drivers/block/ub.c
index 0536b5b29adc..c48e14878582 100644
--- a/drivers/block/ub.c
+++ b/drivers/block/ub.c
@@ -28,6 +28,7 @@
28#include <linux/timer.h> 28#include <linux/timer.h>
29#include <linux/scatterlist.h> 29#include <linux/scatterlist.h>
30#include <linux/slab.h> 30#include <linux/slab.h>
31#include <linux/smp_lock.h>
31#include <scsi/scsi.h> 32#include <scsi/scsi.h>
32 33
33#define DRV_NAME "ub" 34#define DRV_NAME "ub"
@@ -648,7 +649,7 @@ static int ub_request_fn_1(struct ub_lun *lun, struct request *rq)
648 return 0; 649 return 0;
649 } 650 }
650 651
651 if (lun->changed && !blk_pc_request(rq)) { 652 if (lun->changed && rq->cmd_type != REQ_TYPE_BLOCK_PC) {
652 blk_start_request(rq); 653 blk_start_request(rq);
653 ub_end_rq(rq, SAM_STAT_CHECK_CONDITION); 654 ub_end_rq(rq, SAM_STAT_CHECK_CONDITION);
654 return 0; 655 return 0;
@@ -684,7 +685,7 @@ static int ub_request_fn_1(struct ub_lun *lun, struct request *rq)
684 } 685 }
685 urq->nsg = n_elem; 686 urq->nsg = n_elem;
686 687
687 if (blk_pc_request(rq)) { 688 if (rq->cmd_type == REQ_TYPE_BLOCK_PC) {
688 ub_cmd_build_packet(sc, lun, cmd, urq); 689 ub_cmd_build_packet(sc, lun, cmd, urq);
689 } else { 690 } else {
690 ub_cmd_build_block(sc, lun, cmd, urq); 691 ub_cmd_build_block(sc, lun, cmd, urq);
@@ -781,7 +782,7 @@ static void ub_rw_cmd_done(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
781 rq = urq->rq; 782 rq = urq->rq;
782 783
783 if (cmd->error == 0) { 784 if (cmd->error == 0) {
784 if (blk_pc_request(rq)) { 785 if (rq->cmd_type == REQ_TYPE_BLOCK_PC) {
785 if (cmd->act_len >= rq->resid_len) 786 if (cmd->act_len >= rq->resid_len)
786 rq->resid_len = 0; 787 rq->resid_len = 0;
787 else 788 else
@@ -795,7 +796,7 @@ static void ub_rw_cmd_done(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
795 } 796 }
796 } 797 }
797 } else { 798 } else {
798 if (blk_pc_request(rq)) { 799 if (rq->cmd_type == REQ_TYPE_BLOCK_PC) {
799 /* UB_SENSE_SIZE is smaller than SCSI_SENSE_BUFFERSIZE */ 800 /* UB_SENSE_SIZE is smaller than SCSI_SENSE_BUFFERSIZE */
800 memcpy(rq->sense, sc->top_sense, UB_SENSE_SIZE); 801 memcpy(rq->sense, sc->top_sense, UB_SENSE_SIZE);
801 rq->sense_len = UB_SENSE_SIZE; 802 rq->sense_len = UB_SENSE_SIZE;
@@ -1710,6 +1711,18 @@ err_open:
1710 return rc; 1711 return rc;
1711} 1712}
1712 1713
1714static int ub_bd_unlocked_open(struct block_device *bdev, fmode_t mode)
1715{
1716 int ret;
1717
1718 lock_kernel();
1719 ret = ub_bd_open(bdev, mode);
1720 unlock_kernel();
1721
1722 return ret;
1723}
1724
1725
1713/* 1726/*
1714 */ 1727 */
1715static int ub_bd_release(struct gendisk *disk, fmode_t mode) 1728static int ub_bd_release(struct gendisk *disk, fmode_t mode)
@@ -1717,7 +1730,10 @@ static int ub_bd_release(struct gendisk *disk, fmode_t mode)
1717 struct ub_lun *lun = disk->private_data; 1730 struct ub_lun *lun = disk->private_data;
1718 struct ub_dev *sc = lun->udev; 1731 struct ub_dev *sc = lun->udev;
1719 1732
1733 lock_kernel();
1720 ub_put(sc); 1734 ub_put(sc);
1735 unlock_kernel();
1736
1721 return 0; 1737 return 0;
1722} 1738}
1723 1739
@@ -1729,8 +1745,13 @@ static int ub_bd_ioctl(struct block_device *bdev, fmode_t mode,
1729{ 1745{
1730 struct gendisk *disk = bdev->bd_disk; 1746 struct gendisk *disk = bdev->bd_disk;
1731 void __user *usermem = (void __user *) arg; 1747 void __user *usermem = (void __user *) arg;
1748 int ret;
1749
1750 lock_kernel();
1751 ret = scsi_cmd_ioctl(disk->queue, disk, mode, cmd, usermem);
1752 unlock_kernel();
1732 1753
1733 return scsi_cmd_ioctl(disk->queue, disk, mode, cmd, usermem); 1754 return ret;
1734} 1755}
1735 1756
1736/* 1757/*
@@ -1792,9 +1813,9 @@ static int ub_bd_media_changed(struct gendisk *disk)
1792 1813
1793static const struct block_device_operations ub_bd_fops = { 1814static const struct block_device_operations ub_bd_fops = {
1794 .owner = THIS_MODULE, 1815 .owner = THIS_MODULE,
1795 .open = ub_bd_open, 1816 .open = ub_bd_unlocked_open,
1796 .release = ub_bd_release, 1817 .release = ub_bd_release,
1797 .locked_ioctl = ub_bd_ioctl, 1818 .ioctl = ub_bd_ioctl,
1798 .media_changed = ub_bd_media_changed, 1819 .media_changed = ub_bd_media_changed,
1799 .revalidate_disk = ub_bd_revalidate, 1820 .revalidate_disk = ub_bd_revalidate,
1800}; 1821};
diff --git a/drivers/block/umem.c b/drivers/block/umem.c
index 2f9470ff8f7c..8be57151f5d6 100644
--- a/drivers/block/umem.c
+++ b/drivers/block/umem.c
@@ -478,7 +478,7 @@ static void process_page(unsigned long data)
478 le32_to_cpu(desc->local_addr)>>9, 478 le32_to_cpu(desc->local_addr)>>9,
479 le32_to_cpu(desc->transfer_size)); 479 le32_to_cpu(desc->transfer_size));
480 dump_dmastat(card, control); 480 dump_dmastat(card, control);
481 } else if (test_bit(BIO_RW, &bio->bi_rw) && 481 } else if ((bio->bi_rw & REQ_WRITE) &&
482 le32_to_cpu(desc->local_addr) >> 9 == 482 le32_to_cpu(desc->local_addr) >> 9 ==
483 card->init_size) { 483 card->init_size) {
484 card->init_size += le32_to_cpu(desc->transfer_size) >> 9; 484 card->init_size += le32_to_cpu(desc->transfer_size) >> 9;
diff --git a/drivers/block/viodasd.c b/drivers/block/viodasd.c
index 788d93882ab9..f651e51a3319 100644
--- a/drivers/block/viodasd.c
+++ b/drivers/block/viodasd.c
@@ -41,6 +41,7 @@
41#include <linux/errno.h> 41#include <linux/errno.h>
42#include <linux/init.h> 42#include <linux/init.h>
43#include <linux/string.h> 43#include <linux/string.h>
44#include <linux/smp_lock.h>
44#include <linux/dma-mapping.h> 45#include <linux/dma-mapping.h>
45#include <linux/completion.h> 46#include <linux/completion.h>
46#include <linux/device.h> 47#include <linux/device.h>
@@ -175,6 +176,18 @@ static int viodasd_open(struct block_device *bdev, fmode_t mode)
175 return 0; 176 return 0;
176} 177}
177 178
179static int viodasd_unlocked_open(struct block_device *bdev, fmode_t mode)
180{
181 int ret;
182
183 lock_kernel();
184 ret = viodasd_open(bdev, mode);
185 unlock_kernel();
186
187 return ret;
188}
189
190
178/* 191/*
179 * External release entry point. 192 * External release entry point.
180 */ 193 */
@@ -183,6 +196,7 @@ static int viodasd_release(struct gendisk *disk, fmode_t mode)
183 struct viodasd_device *d = disk->private_data; 196 struct viodasd_device *d = disk->private_data;
184 HvLpEvent_Rc hvrc; 197 HvLpEvent_Rc hvrc;
185 198
199 lock_kernel();
186 /* Send the event to OS/400. We DON'T expect a response */ 200 /* Send the event to OS/400. We DON'T expect a response */
187 hvrc = HvCallEvent_signalLpEventFast(viopath_hostLp, 201 hvrc = HvCallEvent_signalLpEventFast(viopath_hostLp,
188 HvLpEvent_Type_VirtualIo, 202 HvLpEvent_Type_VirtualIo,
@@ -195,6 +209,9 @@ static int viodasd_release(struct gendisk *disk, fmode_t mode)
195 0, 0, 0); 209 0, 0, 0);
196 if (hvrc != 0) 210 if (hvrc != 0)
197 pr_warning("HV close call failed %d\n", (int)hvrc); 211 pr_warning("HV close call failed %d\n", (int)hvrc);
212
213 unlock_kernel();
214
198 return 0; 215 return 0;
199} 216}
200 217
@@ -219,7 +236,7 @@ static int viodasd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
219 */ 236 */
220static const struct block_device_operations viodasd_fops = { 237static const struct block_device_operations viodasd_fops = {
221 .owner = THIS_MODULE, 238 .owner = THIS_MODULE,
222 .open = viodasd_open, 239 .open = viodasd_unlocked_open,
223 .release = viodasd_release, 240 .release = viodasd_release,
224 .getgeo = viodasd_getgeo, 241 .getgeo = viodasd_getgeo,
225}; 242};
@@ -361,7 +378,7 @@ static void do_viodasd_request(struct request_queue *q)
361 if (req == NULL) 378 if (req == NULL)
362 return; 379 return;
363 /* check that request contains a valid command */ 380 /* check that request contains a valid command */
364 if (!blk_fs_request(req)) { 381 if (req->cmd_type != REQ_TYPE_FS) {
365 viodasd_end_request(req, -EIO, blk_rq_sectors(req)); 382 viodasd_end_request(req, -EIO, blk_rq_sectors(req));
366 continue; 383 continue;
367 } 384 }
diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 23b7c48df843..2aafafca2b13 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -2,6 +2,7 @@
2#include <linux/spinlock.h> 2#include <linux/spinlock.h>
3#include <linux/slab.h> 3#include <linux/slab.h>
4#include <linux/blkdev.h> 4#include <linux/blkdev.h>
5#include <linux/smp_lock.h>
5#include <linux/hdreg.h> 6#include <linux/hdreg.h>
6#include <linux/virtio.h> 7#include <linux/virtio.h>
7#include <linux/virtio_blk.h> 8#include <linux/virtio_blk.h>
@@ -65,13 +66,18 @@ static void blk_done(struct virtqueue *vq)
65 break; 66 break;
66 } 67 }
67 68
68 if (blk_pc_request(vbr->req)) { 69 switch (vbr->req->cmd_type) {
70 case REQ_TYPE_BLOCK_PC:
69 vbr->req->resid_len = vbr->in_hdr.residual; 71 vbr->req->resid_len = vbr->in_hdr.residual;
70 vbr->req->sense_len = vbr->in_hdr.sense_len; 72 vbr->req->sense_len = vbr->in_hdr.sense_len;
71 vbr->req->errors = vbr->in_hdr.errors; 73 vbr->req->errors = vbr->in_hdr.errors;
72 } 74 break;
73 if (blk_special_request(vbr->req)) 75 case REQ_TYPE_SPECIAL:
74 vbr->req->errors = (error != 0); 76 vbr->req->errors = (error != 0);
77 break;
78 default:
79 break;
80 }
75 81
76 __blk_end_request_all(vbr->req, error); 82 __blk_end_request_all(vbr->req, error);
77 list_del(&vbr->list); 83 list_del(&vbr->list);
@@ -94,36 +100,35 @@ static bool do_req(struct request_queue *q, struct virtio_blk *vblk,
94 return false; 100 return false;
95 101
96 vbr->req = req; 102 vbr->req = req;
97 switch (req->cmd_type) { 103
98 case REQ_TYPE_FS: 104 if (req->cmd_flags & REQ_FLUSH) {
99 vbr->out_hdr.type = 0; 105 vbr->out_hdr.type = VIRTIO_BLK_T_FLUSH;
100 vbr->out_hdr.sector = blk_rq_pos(vbr->req);
101 vbr->out_hdr.ioprio = req_get_ioprio(vbr->req);
102 break;
103 case REQ_TYPE_BLOCK_PC:
104 vbr->out_hdr.type = VIRTIO_BLK_T_SCSI_CMD;
105 vbr->out_hdr.sector = 0;
106 vbr->out_hdr.ioprio = req_get_ioprio(vbr->req);
107 break;
108 case REQ_TYPE_SPECIAL:
109 vbr->out_hdr.type = VIRTIO_BLK_T_GET_ID;
110 vbr->out_hdr.sector = 0; 106 vbr->out_hdr.sector = 0;
111 vbr->out_hdr.ioprio = req_get_ioprio(vbr->req); 107 vbr->out_hdr.ioprio = req_get_ioprio(vbr->req);
112 break; 108 } else {
113 case REQ_TYPE_LINUX_BLOCK: 109 switch (req->cmd_type) {
114 if (req->cmd[0] == REQ_LB_OP_FLUSH) { 110 case REQ_TYPE_FS:
115 vbr->out_hdr.type = VIRTIO_BLK_T_FLUSH; 111 vbr->out_hdr.type = 0;
112 vbr->out_hdr.sector = blk_rq_pos(vbr->req);
113 vbr->out_hdr.ioprio = req_get_ioprio(vbr->req);
114 break;
115 case REQ_TYPE_BLOCK_PC:
116 vbr->out_hdr.type = VIRTIO_BLK_T_SCSI_CMD;
116 vbr->out_hdr.sector = 0; 117 vbr->out_hdr.sector = 0;
117 vbr->out_hdr.ioprio = req_get_ioprio(vbr->req); 118 vbr->out_hdr.ioprio = req_get_ioprio(vbr->req);
118 break; 119 break;
120 case REQ_TYPE_SPECIAL:
121 vbr->out_hdr.type = VIRTIO_BLK_T_GET_ID;
122 vbr->out_hdr.sector = 0;
123 vbr->out_hdr.ioprio = req_get_ioprio(vbr->req);
124 break;
125 default:
126 /* We don't put anything else in the queue. */
127 BUG();
119 } 128 }
120 /*FALLTHRU*/
121 default:
122 /* We don't put anything else in the queue. */
123 BUG();
124 } 129 }
125 130
126 if (blk_barrier_rq(vbr->req)) 131 if (vbr->req->cmd_flags & REQ_HARDBARRIER)
127 vbr->out_hdr.type |= VIRTIO_BLK_T_BARRIER; 132 vbr->out_hdr.type |= VIRTIO_BLK_T_BARRIER;
128 133
129 sg_set_buf(&vblk->sg[out++], &vbr->out_hdr, sizeof(vbr->out_hdr)); 134 sg_set_buf(&vblk->sg[out++], &vbr->out_hdr, sizeof(vbr->out_hdr));
@@ -134,12 +139,12 @@ static bool do_req(struct request_queue *q, struct virtio_blk *vblk,
134 * block, and before the normal inhdr we put the sense data and the 139 * block, and before the normal inhdr we put the sense data and the
135 * inhdr with additional status information before the normal inhdr. 140 * inhdr with additional status information before the normal inhdr.
136 */ 141 */
137 if (blk_pc_request(vbr->req)) 142 if (vbr->req->cmd_type == REQ_TYPE_BLOCK_PC)
138 sg_set_buf(&vblk->sg[out++], vbr->req->cmd, vbr->req->cmd_len); 143 sg_set_buf(&vblk->sg[out++], vbr->req->cmd, vbr->req->cmd_len);
139 144
140 num = blk_rq_map_sg(q, vbr->req, vblk->sg + out); 145 num = blk_rq_map_sg(q, vbr->req, vblk->sg + out);
141 146
142 if (blk_pc_request(vbr->req)) { 147 if (vbr->req->cmd_type == REQ_TYPE_BLOCK_PC) {
143 sg_set_buf(&vblk->sg[num + out + in++], vbr->req->sense, 96); 148 sg_set_buf(&vblk->sg[num + out + in++], vbr->req->sense, 96);
144 sg_set_buf(&vblk->sg[num + out + in++], &vbr->in_hdr, 149 sg_set_buf(&vblk->sg[num + out + in++], &vbr->in_hdr,
145 sizeof(vbr->in_hdr)); 150 sizeof(vbr->in_hdr));
@@ -190,12 +195,6 @@ static void do_virtblk_request(struct request_queue *q)
190 virtqueue_kick(vblk->vq); 195 virtqueue_kick(vblk->vq);
191} 196}
192 197
193static void virtblk_prepare_flush(struct request_queue *q, struct request *req)
194{
195 req->cmd_type = REQ_TYPE_LINUX_BLOCK;
196 req->cmd[0] = REQ_LB_OP_FLUSH;
197}
198
199/* return id (s/n) string for *disk to *id_str 198/* return id (s/n) string for *disk to *id_str
200 */ 199 */
201static int virtblk_get_id(struct gendisk *disk, char *id_str) 200static int virtblk_get_id(struct gendisk *disk, char *id_str)
@@ -219,7 +218,7 @@ static int virtblk_get_id(struct gendisk *disk, char *id_str)
219 return blk_execute_rq(vblk->disk->queue, vblk->disk, req, false); 218 return blk_execute_rq(vblk->disk->queue, vblk->disk, req, false);
220} 219}
221 220
222static int virtblk_ioctl(struct block_device *bdev, fmode_t mode, 221static int virtblk_locked_ioctl(struct block_device *bdev, fmode_t mode,
223 unsigned cmd, unsigned long data) 222 unsigned cmd, unsigned long data)
224{ 223{
225 struct gendisk *disk = bdev->bd_disk; 224 struct gendisk *disk = bdev->bd_disk;
@@ -235,6 +234,18 @@ static int virtblk_ioctl(struct block_device *bdev, fmode_t mode,
235 (void __user *)data); 234 (void __user *)data);
236} 235}
237 236
237static int virtblk_ioctl(struct block_device *bdev, fmode_t mode,
238 unsigned int cmd, unsigned long param)
239{
240 int ret;
241
242 lock_kernel();
243 ret = virtblk_locked_ioctl(bdev, mode, cmd, param);
244 unlock_kernel();
245
246 return ret;
247}
248
238/* We provide getgeo only to please some old bootloader/partitioning tools */ 249/* We provide getgeo only to please some old bootloader/partitioning tools */
239static int virtblk_getgeo(struct block_device *bd, struct hd_geometry *geo) 250static int virtblk_getgeo(struct block_device *bd, struct hd_geometry *geo)
240{ 251{
@@ -261,7 +272,7 @@ static int virtblk_getgeo(struct block_device *bd, struct hd_geometry *geo)
261} 272}
262 273
263static const struct block_device_operations virtblk_fops = { 274static const struct block_device_operations virtblk_fops = {
264 .locked_ioctl = virtblk_ioctl, 275 .ioctl = virtblk_ioctl,
265 .owner = THIS_MODULE, 276 .owner = THIS_MODULE,
266 .getgeo = virtblk_getgeo, 277 .getgeo = virtblk_getgeo,
267}; 278};
@@ -383,8 +394,7 @@ static int __devinit virtblk_probe(struct virtio_device *vdev)
383 * flushing a volatile write cache on the host. Use that 394 * flushing a volatile write cache on the host. Use that
384 * to implement write barrier support. 395 * to implement write barrier support.
385 */ 396 */
386 blk_queue_ordered(q, QUEUE_ORDERED_DRAIN_FLUSH, 397 blk_queue_ordered(q, QUEUE_ORDERED_DRAIN_FLUSH);
387 virtblk_prepare_flush);
388 } else if (virtio_has_feature(vdev, VIRTIO_BLK_F_BARRIER)) { 398 } else if (virtio_has_feature(vdev, VIRTIO_BLK_F_BARRIER)) {
389 /* 399 /*
390 * If the BARRIER feature is supported the host expects us 400 * If the BARRIER feature is supported the host expects us
@@ -393,7 +403,7 @@ static int __devinit virtblk_probe(struct virtio_device *vdev)
393 * never re-orders outstanding I/O. This feature is not 403 * never re-orders outstanding I/O. This feature is not
394 * useful for real life scenarious and deprecated. 404 * useful for real life scenarious and deprecated.
395 */ 405 */
396 blk_queue_ordered(q, QUEUE_ORDERED_TAG, NULL); 406 blk_queue_ordered(q, QUEUE_ORDERED_TAG);
397 } else { 407 } else {
398 /* 408 /*
399 * If the FLUSH feature is not supported we must assume that 409 * If the FLUSH feature is not supported we must assume that
@@ -401,7 +411,7 @@ static int __devinit virtblk_probe(struct virtio_device *vdev)
401 * caching. We still need to drain the queue to provider 411 * caching. We still need to drain the queue to provider
402 * proper barrier semantics. 412 * proper barrier semantics.
403 */ 413 */
404 blk_queue_ordered(q, QUEUE_ORDERED_DRAIN, NULL); 414 blk_queue_ordered(q, QUEUE_ORDERED_DRAIN);
405 } 415 }
406 416
407 /* If disk is read-only in the host, the guest should obey */ 417 /* If disk is read-only in the host, the guest should obey */
diff --git a/drivers/block/xd.c b/drivers/block/xd.c
index 18a80ff57ce8..d5a3cd750561 100644
--- a/drivers/block/xd.c
+++ b/drivers/block/xd.c
@@ -46,6 +46,7 @@
46#include <linux/init.h> 46#include <linux/init.h>
47#include <linux/wait.h> 47#include <linux/wait.h>
48#include <linux/blkdev.h> 48#include <linux/blkdev.h>
49#include <linux/smp_lock.h>
49#include <linux/blkpg.h> 50#include <linux/blkpg.h>
50#include <linux/delay.h> 51#include <linux/delay.h>
51#include <linux/io.h> 52#include <linux/io.h>
@@ -133,7 +134,7 @@ static int xd_getgeo(struct block_device *bdev, struct hd_geometry *geo);
133 134
134static const struct block_device_operations xd_fops = { 135static const struct block_device_operations xd_fops = {
135 .owner = THIS_MODULE, 136 .owner = THIS_MODULE,
136 .locked_ioctl = xd_ioctl, 137 .ioctl = xd_ioctl,
137 .getgeo = xd_getgeo, 138 .getgeo = xd_getgeo,
138}; 139};
139static DECLARE_WAIT_QUEUE_HEAD(xd_wait_int); 140static DECLARE_WAIT_QUEUE_HEAD(xd_wait_int);
@@ -322,7 +323,7 @@ static void do_xd_request (struct request_queue * q)
322 int res = -EIO; 323 int res = -EIO;
323 int retry; 324 int retry;
324 325
325 if (!blk_fs_request(req)) 326 if (req->cmd_type != REQ_TYPE_FS)
326 goto done; 327 goto done;
327 if (block + count > get_capacity(req->rq_disk)) 328 if (block + count > get_capacity(req->rq_disk))
328 goto done; 329 goto done;
@@ -347,7 +348,7 @@ static int xd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
347} 348}
348 349
349/* xd_ioctl: handle device ioctl's */ 350/* xd_ioctl: handle device ioctl's */
350static int xd_ioctl(struct block_device *bdev, fmode_t mode, u_int cmd, u_long arg) 351static int xd_locked_ioctl(struct block_device *bdev, fmode_t mode, u_int cmd, u_long arg)
351{ 352{
352 switch (cmd) { 353 switch (cmd) {
353 case HDIO_SET_DMA: 354 case HDIO_SET_DMA:
@@ -375,6 +376,18 @@ static int xd_ioctl(struct block_device *bdev, fmode_t mode, u_int cmd, u_long a
375 } 376 }
376} 377}
377 378
379static int xd_ioctl(struct block_device *bdev, fmode_t mode,
380 unsigned int cmd, unsigned long param)
381{
382 int ret;
383
384 lock_kernel();
385 ret = xd_locked_ioctl(bdev, mode, cmd, param);
386 unlock_kernel();
387
388 return ret;
389}
390
378/* xd_readwrite: handle a read/write request */ 391/* xd_readwrite: handle a read/write request */
379static int xd_readwrite (u_char operation,XD_INFO *p,char *buffer,u_int block,u_int count) 392static int xd_readwrite (u_char operation,XD_INFO *p,char *buffer,u_int block,u_int count)
380{ 393{
diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c
index f63ac3d1f8a4..ac1b682edecb 100644
--- a/drivers/block/xen-blkfront.c
+++ b/drivers/block/xen-blkfront.c
@@ -41,6 +41,7 @@
41#include <linux/cdrom.h> 41#include <linux/cdrom.h>
42#include <linux/module.h> 42#include <linux/module.h>
43#include <linux/slab.h> 43#include <linux/slab.h>
44#include <linux/smp_lock.h>
44#include <linux/scatterlist.h> 45#include <linux/scatterlist.h>
45 46
46#include <xen/xen.h> 47#include <xen/xen.h>
@@ -79,6 +80,7 @@ static const struct block_device_operations xlvbd_block_fops;
79 */ 80 */
80struct blkfront_info 81struct blkfront_info
81{ 82{
83 struct mutex mutex;
82 struct xenbus_device *xbdev; 84 struct xenbus_device *xbdev;
83 struct gendisk *gd; 85 struct gendisk *gd;
84 int vdevice; 86 int vdevice;
@@ -95,16 +97,14 @@ struct blkfront_info
95 unsigned long shadow_free; 97 unsigned long shadow_free;
96 int feature_barrier; 98 int feature_barrier;
97 int is_ready; 99 int is_ready;
98
99 /**
100 * The number of people holding this device open. We won't allow a
101 * hot-unplug unless this is 0.
102 */
103 int users;
104}; 100};
105 101
106static DEFINE_SPINLOCK(blkif_io_lock); 102static DEFINE_SPINLOCK(blkif_io_lock);
107 103
104static unsigned int nr_minors;
105static unsigned long *minors;
106static DEFINE_SPINLOCK(minor_lock);
107
108#define MAXIMUM_OUTSTANDING_BLOCK_REQS \ 108#define MAXIMUM_OUTSTANDING_BLOCK_REQS \
109 (BLKIF_MAX_SEGMENTS_PER_REQUEST * BLK_RING_SIZE) 109 (BLKIF_MAX_SEGMENTS_PER_REQUEST * BLK_RING_SIZE)
110#define GRANT_INVALID_REF 0 110#define GRANT_INVALID_REF 0
@@ -139,6 +139,55 @@ static void add_id_to_freelist(struct blkfront_info *info,
139 info->shadow_free = id; 139 info->shadow_free = id;
140} 140}
141 141
142static int xlbd_reserve_minors(unsigned int minor, unsigned int nr)
143{
144 unsigned int end = minor + nr;
145 int rc;
146
147 if (end > nr_minors) {
148 unsigned long *bitmap, *old;
149
150 bitmap = kzalloc(BITS_TO_LONGS(end) * sizeof(*bitmap),
151 GFP_KERNEL);
152 if (bitmap == NULL)
153 return -ENOMEM;
154
155 spin_lock(&minor_lock);
156 if (end > nr_minors) {
157 old = minors;
158 memcpy(bitmap, minors,
159 BITS_TO_LONGS(nr_minors) * sizeof(*bitmap));
160 minors = bitmap;
161 nr_minors = BITS_TO_LONGS(end) * BITS_PER_LONG;
162 } else
163 old = bitmap;
164 spin_unlock(&minor_lock);
165 kfree(old);
166 }
167
168 spin_lock(&minor_lock);
169 if (find_next_bit(minors, end, minor) >= end) {
170 for (; minor < end; ++minor)
171 __set_bit(minor, minors);
172 rc = 0;
173 } else
174 rc = -EBUSY;
175 spin_unlock(&minor_lock);
176
177 return rc;
178}
179
180static void xlbd_release_minors(unsigned int minor, unsigned int nr)
181{
182 unsigned int end = minor + nr;
183
184 BUG_ON(end > nr_minors);
185 spin_lock(&minor_lock);
186 for (; minor < end; ++minor)
187 __clear_bit(minor, minors);
188 spin_unlock(&minor_lock);
189}
190
142static void blkif_restart_queue_callback(void *arg) 191static void blkif_restart_queue_callback(void *arg)
143{ 192{
144 struct blkfront_info *info = (struct blkfront_info *)arg; 193 struct blkfront_info *info = (struct blkfront_info *)arg;
@@ -239,7 +288,7 @@ static int blkif_queue_request(struct request *req)
239 288
240 ring_req->operation = rq_data_dir(req) ? 289 ring_req->operation = rq_data_dir(req) ?
241 BLKIF_OP_WRITE : BLKIF_OP_READ; 290 BLKIF_OP_WRITE : BLKIF_OP_READ;
242 if (blk_barrier_rq(req)) 291 if (req->cmd_flags & REQ_HARDBARRIER)
243 ring_req->operation = BLKIF_OP_WRITE_BARRIER; 292 ring_req->operation = BLKIF_OP_WRITE_BARRIER;
244 293
245 ring_req->nr_segments = blk_rq_map_sg(req->q, req, info->sg); 294 ring_req->nr_segments = blk_rq_map_sg(req->q, req, info->sg);
@@ -310,7 +359,7 @@ static void do_blkif_request(struct request_queue *rq)
310 359
311 blk_start_request(req); 360 blk_start_request(req);
312 361
313 if (!blk_fs_request(req)) { 362 if (req->cmd_type != REQ_TYPE_FS) {
314 __blk_end_request_all(req, -EIO); 363 __blk_end_request_all(req, -EIO);
315 continue; 364 continue;
316 } 365 }
@@ -372,17 +421,22 @@ static int xlvbd_init_blk_queue(struct gendisk *gd, u16 sector_size)
372static int xlvbd_barrier(struct blkfront_info *info) 421static int xlvbd_barrier(struct blkfront_info *info)
373{ 422{
374 int err; 423 int err;
424 const char *barrier;
375 425
376 err = blk_queue_ordered(info->rq, 426 switch (info->feature_barrier) {
377 info->feature_barrier ? QUEUE_ORDERED_DRAIN : QUEUE_ORDERED_NONE, 427 case QUEUE_ORDERED_DRAIN: barrier = "enabled (drain)"; break;
378 NULL); 428 case QUEUE_ORDERED_TAG: barrier = "enabled (tag)"; break;
429 case QUEUE_ORDERED_NONE: barrier = "disabled"; break;
430 default: return -EINVAL;
431 }
432
433 err = blk_queue_ordered(info->rq, info->feature_barrier);
379 434
380 if (err) 435 if (err)
381 return err; 436 return err;
382 437
383 printk(KERN_INFO "blkfront: %s: barriers %s\n", 438 printk(KERN_INFO "blkfront: %s: barriers %s\n",
384 info->gd->disk_name, 439 info->gd->disk_name, barrier);
385 info->feature_barrier ? "enabled" : "disabled");
386 return 0; 440 return 0;
387} 441}
388 442
@@ -418,9 +472,14 @@ static int xlvbd_alloc_gendisk(blkif_sector_t capacity,
418 if ((minor % nr_parts) == 0) 472 if ((minor % nr_parts) == 0)
419 nr_minors = nr_parts; 473 nr_minors = nr_parts;
420 474
475 err = xlbd_reserve_minors(minor, nr_minors);
476 if (err)
477 goto out;
478 err = -ENODEV;
479
421 gd = alloc_disk(nr_minors); 480 gd = alloc_disk(nr_minors);
422 if (gd == NULL) 481 if (gd == NULL)
423 goto out; 482 goto release;
424 483
425 offset = minor / nr_parts; 484 offset = minor / nr_parts;
426 485
@@ -451,14 +510,13 @@ static int xlvbd_alloc_gendisk(blkif_sector_t capacity,
451 510
452 if (xlvbd_init_blk_queue(gd, sector_size)) { 511 if (xlvbd_init_blk_queue(gd, sector_size)) {
453 del_gendisk(gd); 512 del_gendisk(gd);
454 goto out; 513 goto release;
455 } 514 }
456 515
457 info->rq = gd->queue; 516 info->rq = gd->queue;
458 info->gd = gd; 517 info->gd = gd;
459 518
460 if (info->feature_barrier) 519 xlvbd_barrier(info);
461 xlvbd_barrier(info);
462 520
463 if (vdisk_info & VDISK_READONLY) 521 if (vdisk_info & VDISK_READONLY)
464 set_disk_ro(gd, 1); 522 set_disk_ro(gd, 1);
@@ -471,10 +529,45 @@ static int xlvbd_alloc_gendisk(blkif_sector_t capacity,
471 529
472 return 0; 530 return 0;
473 531
532 release:
533 xlbd_release_minors(minor, nr_minors);
474 out: 534 out:
475 return err; 535 return err;
476} 536}
477 537
538static void xlvbd_release_gendisk(struct blkfront_info *info)
539{
540 unsigned int minor, nr_minors;
541 unsigned long flags;
542
543 if (info->rq == NULL)
544 return;
545
546 spin_lock_irqsave(&blkif_io_lock, flags);
547
548 /* No more blkif_request(). */
549 blk_stop_queue(info->rq);
550
551 /* No more gnttab callback work. */
552 gnttab_cancel_free_callback(&info->callback);
553 spin_unlock_irqrestore(&blkif_io_lock, flags);
554
555 /* Flush gnttab callback work. Must be done with no locks held. */
556 flush_scheduled_work();
557
558 del_gendisk(info->gd);
559
560 minor = info->gd->first_minor;
561 nr_minors = info->gd->minors;
562 xlbd_release_minors(minor, nr_minors);
563
564 blk_cleanup_queue(info->rq);
565 info->rq = NULL;
566
567 put_disk(info->gd);
568 info->gd = NULL;
569}
570
478static void kick_pending_request_queues(struct blkfront_info *info) 571static void kick_pending_request_queues(struct blkfront_info *info)
479{ 572{
480 if (!RING_FULL(&info->ring)) { 573 if (!RING_FULL(&info->ring)) {
@@ -569,7 +662,7 @@ static irqreturn_t blkif_interrupt(int irq, void *dev_id)
569 printk(KERN_WARNING "blkfront: %s: write barrier op failed\n", 662 printk(KERN_WARNING "blkfront: %s: write barrier op failed\n",
570 info->gd->disk_name); 663 info->gd->disk_name);
571 error = -EOPNOTSUPP; 664 error = -EOPNOTSUPP;
572 info->feature_barrier = 0; 665 info->feature_barrier = QUEUE_ORDERED_NONE;
573 xlvbd_barrier(info); 666 xlvbd_barrier(info);
574 } 667 }
575 /* fall through */ 668 /* fall through */
@@ -652,7 +745,7 @@ fail:
652 745
653 746
654/* Common code used when first setting up, and when resuming. */ 747/* Common code used when first setting up, and when resuming. */
655static int talk_to_backend(struct xenbus_device *dev, 748static int talk_to_blkback(struct xenbus_device *dev,
656 struct blkfront_info *info) 749 struct blkfront_info *info)
657{ 750{
658 const char *message = NULL; 751 const char *message = NULL;
@@ -712,7 +805,6 @@ again:
712 return err; 805 return err;
713} 806}
714 807
715
716/** 808/**
717 * Entry point to this code when a new device is created. Allocate the basic 809 * Entry point to this code when a new device is created. Allocate the basic
718 * structures and the ring buffer for communication with the backend, and 810 * structures and the ring buffer for communication with the backend, and
@@ -773,6 +865,7 @@ static int blkfront_probe(struct xenbus_device *dev,
773 return -ENOMEM; 865 return -ENOMEM;
774 } 866 }
775 867
868 mutex_init(&info->mutex);
776 info->xbdev = dev; 869 info->xbdev = dev;
777 info->vdevice = vdevice; 870 info->vdevice = vdevice;
778 info->connected = BLKIF_STATE_DISCONNECTED; 871 info->connected = BLKIF_STATE_DISCONNECTED;
@@ -786,7 +879,7 @@ static int blkfront_probe(struct xenbus_device *dev,
786 info->handle = simple_strtoul(strrchr(dev->nodename, '/')+1, NULL, 0); 879 info->handle = simple_strtoul(strrchr(dev->nodename, '/')+1, NULL, 0);
787 dev_set_drvdata(&dev->dev, info); 880 dev_set_drvdata(&dev->dev, info);
788 881
789 err = talk_to_backend(dev, info); 882 err = talk_to_blkback(dev, info);
790 if (err) { 883 if (err) {
791 kfree(info); 884 kfree(info);
792 dev_set_drvdata(&dev->dev, NULL); 885 dev_set_drvdata(&dev->dev, NULL);
@@ -881,13 +974,50 @@ static int blkfront_resume(struct xenbus_device *dev)
881 974
882 blkif_free(info, info->connected == BLKIF_STATE_CONNECTED); 975 blkif_free(info, info->connected == BLKIF_STATE_CONNECTED);
883 976
884 err = talk_to_backend(dev, info); 977 err = talk_to_blkback(dev, info);
885 if (info->connected == BLKIF_STATE_SUSPENDED && !err) 978 if (info->connected == BLKIF_STATE_SUSPENDED && !err)
886 err = blkif_recover(info); 979 err = blkif_recover(info);
887 980
888 return err; 981 return err;
889} 982}
890 983
984static void
985blkfront_closing(struct blkfront_info *info)
986{
987 struct xenbus_device *xbdev = info->xbdev;
988 struct block_device *bdev = NULL;
989
990 mutex_lock(&info->mutex);
991
992 if (xbdev->state == XenbusStateClosing) {
993 mutex_unlock(&info->mutex);
994 return;
995 }
996
997 if (info->gd)
998 bdev = bdget_disk(info->gd, 0);
999
1000 mutex_unlock(&info->mutex);
1001
1002 if (!bdev) {
1003 xenbus_frontend_closed(xbdev);
1004 return;
1005 }
1006
1007 mutex_lock(&bdev->bd_mutex);
1008
1009 if (bdev->bd_openers) {
1010 xenbus_dev_error(xbdev, -EBUSY,
1011 "Device in use; refusing to close");
1012 xenbus_switch_state(xbdev, XenbusStateClosing);
1013 } else {
1014 xlvbd_release_gendisk(info);
1015 xenbus_frontend_closed(xbdev);
1016 }
1017
1018 mutex_unlock(&bdev->bd_mutex);
1019 bdput(bdev);
1020}
891 1021
892/* 1022/*
893 * Invoked when the backend is finally 'ready' (and has told produced 1023 * Invoked when the backend is finally 'ready' (and has told produced
@@ -899,11 +1029,31 @@ static void blkfront_connect(struct blkfront_info *info)
899 unsigned long sector_size; 1029 unsigned long sector_size;
900 unsigned int binfo; 1030 unsigned int binfo;
901 int err; 1031 int err;
902 1032 int barrier;
903 if ((info->connected == BLKIF_STATE_CONNECTED) || 1033
904 (info->connected == BLKIF_STATE_SUSPENDED) ) 1034 switch (info->connected) {
1035 case BLKIF_STATE_CONNECTED:
1036 /*
1037 * Potentially, the back-end may be signalling
1038 * a capacity change; update the capacity.
1039 */
1040 err = xenbus_scanf(XBT_NIL, info->xbdev->otherend,
1041 "sectors", "%Lu", &sectors);
1042 if (XENBUS_EXIST_ERR(err))
1043 return;
1044 printk(KERN_INFO "Setting capacity to %Lu\n",
1045 sectors);
1046 set_capacity(info->gd, sectors);
1047 revalidate_disk(info->gd);
1048
1049 /* fall through */
1050 case BLKIF_STATE_SUSPENDED:
905 return; 1051 return;
906 1052
1053 default:
1054 break;
1055 }
1056
907 dev_dbg(&info->xbdev->dev, "%s:%s.\n", 1057 dev_dbg(&info->xbdev->dev, "%s:%s.\n",
908 __func__, info->xbdev->otherend); 1058 __func__, info->xbdev->otherend);
909 1059
@@ -920,10 +1070,26 @@ static void blkfront_connect(struct blkfront_info *info)
920 } 1070 }
921 1071
922 err = xenbus_gather(XBT_NIL, info->xbdev->otherend, 1072 err = xenbus_gather(XBT_NIL, info->xbdev->otherend,
923 "feature-barrier", "%lu", &info->feature_barrier, 1073 "feature-barrier", "%lu", &barrier,
924 NULL); 1074 NULL);
1075
1076 /*
1077 * If there's no "feature-barrier" defined, then it means
1078 * we're dealing with a very old backend which writes
1079 * synchronously; draining will do what needs to get done.
1080 *
1081 * If there are barriers, then we can do full queued writes
1082 * with tagged barriers.
1083 *
1084 * If barriers are not supported, then there's no much we can
1085 * do, so just set ordering to NONE.
1086 */
925 if (err) 1087 if (err)
926 info->feature_barrier = 0; 1088 info->feature_barrier = QUEUE_ORDERED_DRAIN;
1089 else if (barrier)
1090 info->feature_barrier = QUEUE_ORDERED_TAG;
1091 else
1092 info->feature_barrier = QUEUE_ORDERED_NONE;
927 1093
928 err = xlvbd_alloc_gendisk(sectors, info, binfo, sector_size); 1094 err = xlvbd_alloc_gendisk(sectors, info, binfo, sector_size);
929 if (err) { 1095 if (err) {
@@ -946,52 +1112,14 @@ static void blkfront_connect(struct blkfront_info *info)
946} 1112}
947 1113
948/** 1114/**
949 * Handle the change of state of the backend to Closing. We must delete our
950 * device-layer structures now, to ensure that writes are flushed through to
951 * the backend. Once is this done, we can switch to Closed in
952 * acknowledgement.
953 */
954static void blkfront_closing(struct xenbus_device *dev)
955{
956 struct blkfront_info *info = dev_get_drvdata(&dev->dev);
957 unsigned long flags;
958
959 dev_dbg(&dev->dev, "blkfront_closing: %s removed\n", dev->nodename);
960
961 if (info->rq == NULL)
962 goto out;
963
964 spin_lock_irqsave(&blkif_io_lock, flags);
965
966 /* No more blkif_request(). */
967 blk_stop_queue(info->rq);
968
969 /* No more gnttab callback work. */
970 gnttab_cancel_free_callback(&info->callback);
971 spin_unlock_irqrestore(&blkif_io_lock, flags);
972
973 /* Flush gnttab callback work. Must be done with no locks held. */
974 flush_scheduled_work();
975
976 blk_cleanup_queue(info->rq);
977 info->rq = NULL;
978
979 del_gendisk(info->gd);
980
981 out:
982 xenbus_frontend_closed(dev);
983}
984
985/**
986 * Callback received when the backend's state changes. 1115 * Callback received when the backend's state changes.
987 */ 1116 */
988static void backend_changed(struct xenbus_device *dev, 1117static void blkback_changed(struct xenbus_device *dev,
989 enum xenbus_state backend_state) 1118 enum xenbus_state backend_state)
990{ 1119{
991 struct blkfront_info *info = dev_get_drvdata(&dev->dev); 1120 struct blkfront_info *info = dev_get_drvdata(&dev->dev);
992 struct block_device *bd;
993 1121
994 dev_dbg(&dev->dev, "blkfront:backend_changed.\n"); 1122 dev_dbg(&dev->dev, "blkfront:blkback_changed to state %d.\n", backend_state);
995 1123
996 switch (backend_state) { 1124 switch (backend_state) {
997 case XenbusStateInitialising: 1125 case XenbusStateInitialising:
@@ -1006,35 +1134,56 @@ static void backend_changed(struct xenbus_device *dev,
1006 break; 1134 break;
1007 1135
1008 case XenbusStateClosing: 1136 case XenbusStateClosing:
1009 if (info->gd == NULL) { 1137 blkfront_closing(info);
1010 xenbus_frontend_closed(dev);
1011 break;
1012 }
1013 bd = bdget_disk(info->gd, 0);
1014 if (bd == NULL)
1015 xenbus_dev_fatal(dev, -ENODEV, "bdget failed");
1016
1017 mutex_lock(&bd->bd_mutex);
1018 if (info->users > 0)
1019 xenbus_dev_error(dev, -EBUSY,
1020 "Device in use; refusing to close");
1021 else
1022 blkfront_closing(dev);
1023 mutex_unlock(&bd->bd_mutex);
1024 bdput(bd);
1025 break; 1138 break;
1026 } 1139 }
1027} 1140}
1028 1141
1029static int blkfront_remove(struct xenbus_device *dev) 1142static int blkfront_remove(struct xenbus_device *xbdev)
1030{ 1143{
1031 struct blkfront_info *info = dev_get_drvdata(&dev->dev); 1144 struct blkfront_info *info = dev_get_drvdata(&xbdev->dev);
1145 struct block_device *bdev = NULL;
1146 struct gendisk *disk;
1032 1147
1033 dev_dbg(&dev->dev, "blkfront_remove: %s removed\n", dev->nodename); 1148 dev_dbg(&xbdev->dev, "%s removed", xbdev->nodename);
1034 1149
1035 blkif_free(info, 0); 1150 blkif_free(info, 0);
1036 1151
1037 kfree(info); 1152 mutex_lock(&info->mutex);
1153
1154 disk = info->gd;
1155 if (disk)
1156 bdev = bdget_disk(disk, 0);
1157
1158 info->xbdev = NULL;
1159 mutex_unlock(&info->mutex);
1160
1161 if (!bdev) {
1162 kfree(info);
1163 return 0;
1164 }
1165
1166 /*
1167 * The xbdev was removed before we reached the Closed
1168 * state. See if it's safe to remove the disk. If the bdev
1169 * isn't closed yet, we let release take care of it.
1170 */
1171
1172 mutex_lock(&bdev->bd_mutex);
1173 info = disk->private_data;
1174
1175 dev_warn(disk_to_dev(disk),
1176 "%s was hot-unplugged, %d stale handles\n",
1177 xbdev->nodename, bdev->bd_openers);
1178
1179 if (info && !bdev->bd_openers) {
1180 xlvbd_release_gendisk(info);
1181 disk->private_data = NULL;
1182 kfree(info);
1183 }
1184
1185 mutex_unlock(&bdev->bd_mutex);
1186 bdput(bdev);
1038 1187
1039 return 0; 1188 return 0;
1040} 1189}
@@ -1043,30 +1192,78 @@ static int blkfront_is_ready(struct xenbus_device *dev)
1043{ 1192{
1044 struct blkfront_info *info = dev_get_drvdata(&dev->dev); 1193 struct blkfront_info *info = dev_get_drvdata(&dev->dev);
1045 1194
1046 return info->is_ready; 1195 return info->is_ready && info->xbdev;
1047} 1196}
1048 1197
1049static int blkif_open(struct block_device *bdev, fmode_t mode) 1198static int blkif_open(struct block_device *bdev, fmode_t mode)
1050{ 1199{
1051 struct blkfront_info *info = bdev->bd_disk->private_data; 1200 struct gendisk *disk = bdev->bd_disk;
1052 info->users++; 1201 struct blkfront_info *info;
1053 return 0; 1202 int err = 0;
1203
1204 lock_kernel();
1205
1206 info = disk->private_data;
1207 if (!info) {
1208 /* xbdev gone */
1209 err = -ERESTARTSYS;
1210 goto out;
1211 }
1212
1213 mutex_lock(&info->mutex);
1214
1215 if (!info->gd)
1216 /* xbdev is closed */
1217 err = -ERESTARTSYS;
1218
1219 mutex_unlock(&info->mutex);
1220
1221out:
1222 unlock_kernel();
1223 return err;
1054} 1224}
1055 1225
1056static int blkif_release(struct gendisk *disk, fmode_t mode) 1226static int blkif_release(struct gendisk *disk, fmode_t mode)
1057{ 1227{
1058 struct blkfront_info *info = disk->private_data; 1228 struct blkfront_info *info = disk->private_data;
1059 info->users--; 1229 struct block_device *bdev;
1060 if (info->users == 0) { 1230 struct xenbus_device *xbdev;
1061 /* Check whether we have been instructed to close. We will 1231
1062 have ignored this request initially, as the device was 1232 lock_kernel();
1063 still mounted. */ 1233
1064 struct xenbus_device *dev = info->xbdev; 1234 bdev = bdget_disk(disk, 0);
1065 enum xenbus_state state = xenbus_read_driver_state(dev->otherend); 1235 bdput(bdev);
1066 1236
1067 if (state == XenbusStateClosing && info->is_ready) 1237 if (bdev->bd_openers)
1068 blkfront_closing(dev); 1238 goto out;
1239
1240 /*
1241 * Check if we have been instructed to close. We will have
1242 * deferred this request, because the bdev was still open.
1243 */
1244
1245 mutex_lock(&info->mutex);
1246 xbdev = info->xbdev;
1247
1248 if (xbdev && xbdev->state == XenbusStateClosing) {
1249 /* pending switch to state closed */
1250 dev_info(disk_to_dev(bdev->bd_disk), "releasing disk\n");
1251 xlvbd_release_gendisk(info);
1252 xenbus_frontend_closed(info->xbdev);
1253 }
1254
1255 mutex_unlock(&info->mutex);
1256
1257 if (!xbdev) {
1258 /* sudden device removal */
1259 dev_info(disk_to_dev(bdev->bd_disk), "releasing disk\n");
1260 xlvbd_release_gendisk(info);
1261 disk->private_data = NULL;
1262 kfree(info);
1069 } 1263 }
1264
1265out:
1266 unlock_kernel();
1070 return 0; 1267 return 0;
1071} 1268}
1072 1269
@@ -1076,7 +1273,7 @@ static const struct block_device_operations xlvbd_block_fops =
1076 .open = blkif_open, 1273 .open = blkif_open,
1077 .release = blkif_release, 1274 .release = blkif_release,
1078 .getgeo = blkif_getgeo, 1275 .getgeo = blkif_getgeo,
1079 .locked_ioctl = blkif_ioctl, 1276 .ioctl = blkif_ioctl,
1080}; 1277};
1081 1278
1082 1279
@@ -1092,7 +1289,7 @@ static struct xenbus_driver blkfront = {
1092 .probe = blkfront_probe, 1289 .probe = blkfront_probe,
1093 .remove = blkfront_remove, 1290 .remove = blkfront_remove,
1094 .resume = blkfront_resume, 1291 .resume = blkfront_resume,
1095 .otherend_changed = backend_changed, 1292 .otherend_changed = blkback_changed,
1096 .is_ready = blkfront_is_ready, 1293 .is_ready = blkfront_is_ready,
1097}; 1294};
1098 1295
diff --git a/drivers/block/xsysace.c b/drivers/block/xsysace.c
index a7b83c0a7eb5..2982b3ee9465 100644
--- a/drivers/block/xsysace.c
+++ b/drivers/block/xsysace.c
@@ -89,6 +89,7 @@
89#include <linux/delay.h> 89#include <linux/delay.h>
90#include <linux/slab.h> 90#include <linux/slab.h>
91#include <linux/blkdev.h> 91#include <linux/blkdev.h>
92#include <linux/smp_lock.h>
92#include <linux/ata.h> 93#include <linux/ata.h>
93#include <linux/hdreg.h> 94#include <linux/hdreg.h>
94#include <linux/platform_device.h> 95#include <linux/platform_device.h>
@@ -465,7 +466,7 @@ struct request *ace_get_next_request(struct request_queue * q)
465 struct request *req; 466 struct request *req;
466 467
467 while ((req = blk_peek_request(q)) != NULL) { 468 while ((req = blk_peek_request(q)) != NULL) {
468 if (blk_fs_request(req)) 469 if (req->cmd_type == REQ_TYPE_FS)
469 break; 470 break;
470 blk_start_request(req); 471 blk_start_request(req);
471 __blk_end_request_all(req, -EIO); 472 __blk_end_request_all(req, -EIO);
@@ -901,11 +902,14 @@ static int ace_open(struct block_device *bdev, fmode_t mode)
901 902
902 dev_dbg(ace->dev, "ace_open() users=%i\n", ace->users + 1); 903 dev_dbg(ace->dev, "ace_open() users=%i\n", ace->users + 1);
903 904
905 lock_kernel();
904 spin_lock_irqsave(&ace->lock, flags); 906 spin_lock_irqsave(&ace->lock, flags);
905 ace->users++; 907 ace->users++;
906 spin_unlock_irqrestore(&ace->lock, flags); 908 spin_unlock_irqrestore(&ace->lock, flags);
907 909
908 check_disk_change(bdev); 910 check_disk_change(bdev);
911 unlock_kernel();
912
909 return 0; 913 return 0;
910} 914}
911 915
@@ -917,6 +921,7 @@ static int ace_release(struct gendisk *disk, fmode_t mode)
917 921
918 dev_dbg(ace->dev, "ace_release() users=%i\n", ace->users - 1); 922 dev_dbg(ace->dev, "ace_release() users=%i\n", ace->users - 1);
919 923
924 lock_kernel();
920 spin_lock_irqsave(&ace->lock, flags); 925 spin_lock_irqsave(&ace->lock, flags);
921 ace->users--; 926 ace->users--;
922 if (ace->users == 0) { 927 if (ace->users == 0) {
@@ -924,6 +929,7 @@ static int ace_release(struct gendisk *disk, fmode_t mode)
924 ace_out(ace, ACE_CTRL, val & ~ACE_CTRL_LOCKREQ); 929 ace_out(ace, ACE_CTRL, val & ~ACE_CTRL_LOCKREQ);
925 } 930 }
926 spin_unlock_irqrestore(&ace->lock, flags); 931 spin_unlock_irqrestore(&ace->lock, flags);
932 unlock_kernel();
927 return 0; 933 return 0;
928} 934}
929 935
@@ -1188,7 +1194,7 @@ static struct platform_driver ace_platform_driver = {
1188 1194
1189#if defined(CONFIG_OF) 1195#if defined(CONFIG_OF)
1190static int __devinit 1196static int __devinit
1191ace_of_probe(struct of_device *op, const struct of_device_id *match) 1197ace_of_probe(struct platform_device *op, const struct of_device_id *match)
1192{ 1198{
1193 struct resource res; 1199 struct resource res;
1194 resource_size_t physaddr; 1200 resource_size_t physaddr;
@@ -1220,7 +1226,7 @@ ace_of_probe(struct of_device *op, const struct of_device_id *match)
1220 return ace_alloc(&op->dev, id ? *id : 0, physaddr, irq, bus_width); 1226 return ace_alloc(&op->dev, id ? *id : 0, physaddr, irq, bus_width);
1221} 1227}
1222 1228
1223static int __devexit ace_of_remove(struct of_device *op) 1229static int __devexit ace_of_remove(struct platform_device *op)
1224{ 1230{
1225 ace_free(&op->dev); 1231 ace_free(&op->dev);
1226 return 0; 1232 return 0;
diff --git a/drivers/block/z2ram.c b/drivers/block/z2ram.c
index 9114654b54d9..d75b2bb601ad 100644
--- a/drivers/block/z2ram.c
+++ b/drivers/block/z2ram.c
@@ -33,6 +33,7 @@
33#include <linux/module.h> 33#include <linux/module.h>
34#include <linux/blkdev.h> 34#include <linux/blkdev.h>
35#include <linux/bitops.h> 35#include <linux/bitops.h>
36#include <linux/smp_lock.h>
36#include <linux/slab.h> 37#include <linux/slab.h>
37 38
38#include <asm/setup.h> 39#include <asm/setup.h>
@@ -153,6 +154,7 @@ static int z2_open(struct block_device *bdev, fmode_t mode)
153 154
154 device = MINOR(bdev->bd_dev); 155 device = MINOR(bdev->bd_dev);
155 156
157 lock_kernel();
156 if ( current_device != -1 && current_device != device ) 158 if ( current_device != -1 && current_device != device )
157 { 159 {
158 rc = -EBUSY; 160 rc = -EBUSY;
@@ -294,20 +296,25 @@ static int z2_open(struct block_device *bdev, fmode_t mode)
294 set_capacity(z2ram_gendisk, z2ram_size >> 9); 296 set_capacity(z2ram_gendisk, z2ram_size >> 9);
295 } 297 }
296 298
299 unlock_kernel();
297 return 0; 300 return 0;
298 301
299err_out_kfree: 302err_out_kfree:
300 kfree(z2ram_map); 303 kfree(z2ram_map);
301err_out: 304err_out:
305 unlock_kernel();
302 return rc; 306 return rc;
303} 307}
304 308
305static int 309static int
306z2_release(struct gendisk *disk, fmode_t mode) 310z2_release(struct gendisk *disk, fmode_t mode)
307{ 311{
308 if ( current_device == -1 ) 312 lock_kernel();
309 return 0; 313 if ( current_device == -1 ) {
310 314 unlock_kernel();
315 return 0;
316 }
317 unlock_kernel();
311 /* 318 /*
312 * FIXME: unmap memory 319 * FIXME: unmap memory
313 */ 320 */
diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
index e3749d0ba68b..af13c62dc473 100644
--- a/drivers/cdrom/cdrom.c
+++ b/drivers/cdrom/cdrom.c
@@ -242,6 +242,8 @@
242 242
243-------------------------------------------------------------------------*/ 243-------------------------------------------------------------------------*/
244 244
245#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
246
245#define REVISION "Revision: 3.20" 247#define REVISION "Revision: 3.20"
246#define VERSION "Id: cdrom.c 3.20 2003/12/17" 248#define VERSION "Id: cdrom.c 3.20 2003/12/17"
247 249
@@ -314,11 +316,17 @@ static const char *mrw_format_status[] = {
314static const char *mrw_address_space[] = { "DMA", "GAA" }; 316static const char *mrw_address_space[] = { "DMA", "GAA" };
315 317
316#if (ERRLOGMASK!=CD_NOTHING) 318#if (ERRLOGMASK!=CD_NOTHING)
317#define cdinfo(type, fmt, args...) \ 319#define cdinfo(type, fmt, args...) \
318 if ((ERRLOGMASK & type) || debug==1 ) \ 320do { \
319 printk(KERN_INFO "cdrom: " fmt, ## args) 321 if ((ERRLOGMASK & type) || debug == 1) \
322 pr_info(fmt, ##args); \
323} while (0)
320#else 324#else
321#define cdinfo(type, fmt, args...) 325#define cdinfo(type, fmt, args...) \
326do { \
327 if (0 && (ERRLOGMASK & type) || debug == 1) \
328 pr_info(fmt, ##args); \
329} while (0)
322#endif 330#endif
323 331
324/* These are used to simplify getting data in from and back to user land */ 332/* These are used to simplify getting data in from and back to user land */
@@ -395,7 +403,7 @@ int register_cdrom(struct cdrom_device_info *cdi)
395 if (cdo->open == NULL || cdo->release == NULL) 403 if (cdo->open == NULL || cdo->release == NULL)
396 return -EINVAL; 404 return -EINVAL;
397 if (!banner_printed) { 405 if (!banner_printed) {
398 printk(KERN_INFO "Uniform CD-ROM driver " REVISION "\n"); 406 pr_info("Uniform CD-ROM driver " REVISION "\n");
399 banner_printed = 1; 407 banner_printed = 1;
400 cdrom_sysctl_register(); 408 cdrom_sysctl_register();
401 } 409 }
@@ -546,7 +554,7 @@ static int cdrom_mrw_bgformat(struct cdrom_device_info *cdi, int cont)
546 unsigned char buffer[12]; 554 unsigned char buffer[12];
547 int ret; 555 int ret;
548 556
549 printk(KERN_INFO "cdrom: %sstarting format\n", cont ? "Re" : ""); 557 pr_info("%sstarting format\n", cont ? "Re" : "");
550 558
551 /* 559 /*
552 * FmtData bit set (bit 4), format type is 1 560 * FmtData bit set (bit 4), format type is 1
@@ -576,7 +584,7 @@ static int cdrom_mrw_bgformat(struct cdrom_device_info *cdi, int cont)
576 584
577 ret = cdi->ops->generic_packet(cdi, &cgc); 585 ret = cdi->ops->generic_packet(cdi, &cgc);
578 if (ret) 586 if (ret)
579 printk(KERN_INFO "cdrom: bgformat failed\n"); 587 pr_info("bgformat failed\n");
580 588
581 return ret; 589 return ret;
582} 590}
@@ -622,8 +630,7 @@ static int cdrom_mrw_exit(struct cdrom_device_info *cdi)
622 630
623 ret = 0; 631 ret = 0;
624 if (di.mrw_status == CDM_MRW_BGFORMAT_ACTIVE) { 632 if (di.mrw_status == CDM_MRW_BGFORMAT_ACTIVE) {
625 printk(KERN_INFO "cdrom: issuing MRW back ground " 633 pr_info("issuing MRW background format suspend\n");
626 "format suspend\n");
627 ret = cdrom_mrw_bgformat_susp(cdi, 0); 634 ret = cdrom_mrw_bgformat_susp(cdi, 0);
628 } 635 }
629 636
@@ -658,7 +665,8 @@ static int cdrom_mrw_set_lba_space(struct cdrom_device_info *cdi, int space)
658 if ((ret = cdrom_mode_select(cdi, &cgc))) 665 if ((ret = cdrom_mode_select(cdi, &cgc)))
659 return ret; 666 return ret;
660 667
661 printk(KERN_INFO "cdrom: %s: mrw address space %s selected\n", cdi->name, mrw_address_space[space]); 668 pr_info("%s: mrw address space %s selected\n",
669 cdi->name, mrw_address_space[space]);
662 return 0; 670 return 0;
663} 671}
664 672
@@ -762,7 +770,7 @@ static int cdrom_mrw_open_write(struct cdrom_device_info *cdi)
762 * always reset to DMA lba space on open 770 * always reset to DMA lba space on open
763 */ 771 */
764 if (cdrom_mrw_set_lba_space(cdi, MRW_LBA_DMA)) { 772 if (cdrom_mrw_set_lba_space(cdi, MRW_LBA_DMA)) {
765 printk(KERN_ERR "cdrom: failed setting lba address space\n"); 773 pr_err("failed setting lba address space\n");
766 return 1; 774 return 1;
767 } 775 }
768 776
@@ -781,8 +789,7 @@ static int cdrom_mrw_open_write(struct cdrom_device_info *cdi)
781 * 3 - MRW formatting complete 789 * 3 - MRW formatting complete
782 */ 790 */
783 ret = 0; 791 ret = 0;
784 printk(KERN_INFO "cdrom open: mrw_status '%s'\n", 792 pr_info("open: mrw_status '%s'\n", mrw_format_status[di.mrw_status]);
785 mrw_format_status[di.mrw_status]);
786 if (!di.mrw_status) 793 if (!di.mrw_status)
787 ret = 1; 794 ret = 1;
788 else if (di.mrw_status == CDM_MRW_BGFORMAT_INACTIVE && 795 else if (di.mrw_status == CDM_MRW_BGFORMAT_INACTIVE &&
@@ -932,8 +939,7 @@ static void cdrom_dvd_rw_close_write(struct cdrom_device_info *cdi)
932 return; 939 return;
933 } 940 }
934 941
935 printk(KERN_INFO "cdrom: %s: dirty DVD+RW media, \"finalizing\"\n", 942 pr_info("%s: dirty DVD+RW media, \"finalizing\"\n", cdi->name);
936 cdi->name);
937 943
938 init_cdrom_command(&cgc, NULL, 0, CGC_DATA_NONE); 944 init_cdrom_command(&cgc, NULL, 0, CGC_DATA_NONE);
939 cgc.cmd[0] = GPCMD_FLUSH_CACHE; 945 cgc.cmd[0] = GPCMD_FLUSH_CACHE;
@@ -2176,7 +2182,7 @@ retry:
2176 * frame dma, so drop to single frame dma if we need to 2182 * frame dma, so drop to single frame dma if we need to
2177 */ 2183 */
2178 if (cdi->cdda_method == CDDA_BPC_FULL && nframes > 1) { 2184 if (cdi->cdda_method == CDDA_BPC_FULL && nframes > 1) {
2179 printk("cdrom: dropping to single frame dma\n"); 2185 pr_info("dropping to single frame dma\n");
2180 cdi->cdda_method = CDDA_BPC_SINGLE; 2186 cdi->cdda_method = CDDA_BPC_SINGLE;
2181 goto retry; 2187 goto retry;
2182 } 2188 }
@@ -2189,7 +2195,7 @@ retry:
2189 if (cdi->last_sense != 0x04 && cdi->last_sense != 0x0b) 2195 if (cdi->last_sense != 0x04 && cdi->last_sense != 0x0b)
2190 return ret; 2196 return ret;
2191 2197
2192 printk("cdrom: dropping to old style cdda (sense=%x)\n", cdi->last_sense); 2198 pr_info("dropping to old style cdda (sense=%x)\n", cdi->last_sense);
2193 cdi->cdda_method = CDDA_OLD; 2199 cdi->cdda_method = CDDA_OLD;
2194 return cdrom_read_cdda_old(cdi, ubuf, lba, nframes); 2200 return cdrom_read_cdda_old(cdi, ubuf, lba, nframes);
2195} 2201}
@@ -3401,7 +3407,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
3401 "\t%d", CDROM_CAN(val) != 0); 3407 "\t%d", CDROM_CAN(val) != 0);
3402 break; 3408 break;
3403 default: 3409 default:
3404 printk(KERN_INFO "cdrom: invalid option%d\n", option); 3410 pr_info("invalid option%d\n", option);
3405 return 1; 3411 return 1;
3406 } 3412 }
3407 if (!ret) 3413 if (!ret)
@@ -3491,7 +3497,7 @@ doit:
3491 mutex_unlock(&cdrom_mutex); 3497 mutex_unlock(&cdrom_mutex);
3492 return proc_dostring(ctl, write, buffer, lenp, ppos); 3498 return proc_dostring(ctl, write, buffer, lenp, ppos);
3493done: 3499done:
3494 printk(KERN_INFO "cdrom: info buffer too small\n"); 3500 pr_info("info buffer too small\n");
3495 goto doit; 3501 goto doit;
3496} 3502}
3497 3503
@@ -3665,7 +3671,7 @@ static int __init cdrom_init(void)
3665 3671
3666static void __exit cdrom_exit(void) 3672static void __exit cdrom_exit(void)
3667{ 3673{
3668 printk(KERN_INFO "Uniform CD-ROM driver unloaded\n"); 3674 pr_info("Uniform CD-ROM driver unloaded\n");
3669 cdrom_sysctl_unregister(); 3675 cdrom_sysctl_unregister();
3670} 3676}
3671 3677
diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
index 03c71f7698cb..261107d1457c 100644
--- a/drivers/cdrom/gdrom.c
+++ b/drivers/cdrom/gdrom.c
@@ -19,6 +19,8 @@
19 * 19 *
20 */ 20 */
21 21
22#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
23
22#include <linux/init.h> 24#include <linux/init.h>
23#include <linux/module.h> 25#include <linux/module.h>
24#include <linux/fs.h> 26#include <linux/fs.h>
@@ -32,6 +34,7 @@
32#include <linux/blkdev.h> 34#include <linux/blkdev.h>
33#include <linux/interrupt.h> 35#include <linux/interrupt.h>
34#include <linux/device.h> 36#include <linux/device.h>
37#include <linux/smp_lock.h>
35#include <linux/wait.h> 38#include <linux/wait.h>
36#include <linux/workqueue.h> 39#include <linux/workqueue.h>
37#include <linux/platform_device.h> 40#include <linux/platform_device.h>
@@ -339,8 +342,7 @@ static int gdrom_get_last_session(struct cdrom_device_info *cd_info,
339 tocuse = 0; 342 tocuse = 0;
340 err = gdrom_readtoc_cmd(gd.toc, 0); 343 err = gdrom_readtoc_cmd(gd.toc, 0);
341 if (err) { 344 if (err) {
342 printk(KERN_INFO "GDROM: Could not get CD " 345 pr_info("Could not get CD table of contents\n");
343 "table of contents\n");
344 return -ENXIO; 346 return -ENXIO;
345 } 347 }
346 } 348 }
@@ -357,8 +359,7 @@ static int gdrom_get_last_session(struct cdrom_device_info *cd_info,
357 } while (track >= fentry); 359 } while (track >= fentry);
358 360
359 if ((track > 100) || (track < get_entry_track(gd.toc->first))) { 361 if ((track > 100) || (track < get_entry_track(gd.toc->first))) {
360 printk(KERN_INFO "GDROM: No data on the last " 362 pr_info("No data on the last session of the CD\n");
361 "session of the CD\n");
362 gdrom_getsense(NULL); 363 gdrom_getsense(NULL);
363 return -ENXIO; 364 return -ENXIO;
364 } 365 }
@@ -451,14 +452,14 @@ static int gdrom_getsense(short *bufstring)
451 goto cleanup_sense; 452 goto cleanup_sense;
452 insw(GDROM_DATA_REG, &sense, sense_command->buflen/2); 453 insw(GDROM_DATA_REG, &sense, sense_command->buflen/2);
453 if (sense[1] & 40) { 454 if (sense[1] & 40) {
454 printk(KERN_INFO "GDROM: Drive not ready - command aborted\n"); 455 pr_info("Drive not ready - command aborted\n");
455 goto cleanup_sense; 456 goto cleanup_sense;
456 } 457 }
457 sense_key = sense[1] & 0x0F; 458 sense_key = sense[1] & 0x0F;
458 if (sense_key < ARRAY_SIZE(sense_texts)) 459 if (sense_key < ARRAY_SIZE(sense_texts))
459 printk(KERN_INFO "GDROM: %s\n", sense_texts[sense_key].text); 460 pr_info("%s\n", sense_texts[sense_key].text);
460 else 461 else
461 printk(KERN_ERR "GDROM: Unknown sense key: %d\n", sense_key); 462 pr_err("Unknown sense key: %d\n", sense_key);
462 if (bufstring) /* return addional sense data */ 463 if (bufstring) /* return addional sense data */
463 memcpy(bufstring, &sense[4], 2); 464 memcpy(bufstring, &sense[4], 2);
464 if (sense_key < 2) 465 if (sense_key < 2)
@@ -492,12 +493,18 @@ static struct cdrom_device_ops gdrom_ops = {
492 493
493static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode) 494static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
494{ 495{
495 return cdrom_open(gd.cd_info, bdev, mode); 496 int ret;
497 lock_kernel();
498 ret = cdrom_open(gd.cd_info, bdev, mode);
499 unlock_kernel();
500 return ret;
496} 501}
497 502
498static int gdrom_bdops_release(struct gendisk *disk, fmode_t mode) 503static int gdrom_bdops_release(struct gendisk *disk, fmode_t mode)
499{ 504{
505 lock_kernel();
500 cdrom_release(gd.cd_info, mode); 506 cdrom_release(gd.cd_info, mode);
507 unlock_kernel();
501 return 0; 508 return 0;
502} 509}
503 510
@@ -509,7 +516,13 @@ static int gdrom_bdops_mediachanged(struct gendisk *disk)
509static int gdrom_bdops_ioctl(struct block_device *bdev, fmode_t mode, 516static int gdrom_bdops_ioctl(struct block_device *bdev, fmode_t mode,
510 unsigned cmd, unsigned long arg) 517 unsigned cmd, unsigned long arg)
511{ 518{
512 return cdrom_ioctl(gd.cd_info, bdev, mode, cmd, arg); 519 int ret;
520
521 lock_kernel();
522 ret = cdrom_ioctl(gd.cd_info, bdev, mode, cmd, arg);
523 unlock_kernel();
524
525 return ret;
513} 526}
514 527
515static const struct block_device_operations gdrom_bdops = { 528static const struct block_device_operations gdrom_bdops = {
@@ -517,7 +530,7 @@ static const struct block_device_operations gdrom_bdops = {
517 .open = gdrom_bdops_open, 530 .open = gdrom_bdops_open,
518 .release = gdrom_bdops_release, 531 .release = gdrom_bdops_release,
519 .media_changed = gdrom_bdops_mediachanged, 532 .media_changed = gdrom_bdops_mediachanged,
520 .locked_ioctl = gdrom_bdops_ioctl, 533 .ioctl = gdrom_bdops_ioctl,
521}; 534};
522 535
523static irqreturn_t gdrom_command_interrupt(int irq, void *dev_id) 536static irqreturn_t gdrom_command_interrupt(int irq, void *dev_id)
@@ -643,14 +656,13 @@ static void gdrom_request(struct request_queue *rq)
643 struct request *req; 656 struct request *req;
644 657
645 while ((req = blk_fetch_request(rq)) != NULL) { 658 while ((req = blk_fetch_request(rq)) != NULL) {
646 if (!blk_fs_request(req)) { 659 if (req->cmd_type != REQ_TYPE_FS) {
647 printk(KERN_DEBUG "GDROM: Non-fs request ignored\n"); 660 printk(KERN_DEBUG "gdrom: Non-fs request ignored\n");
648 __blk_end_request_all(req, -EIO); 661 __blk_end_request_all(req, -EIO);
649 continue; 662 continue;
650 } 663 }
651 if (rq_data_dir(req) != READ) { 664 if (rq_data_dir(req) != READ) {
652 printk(KERN_NOTICE "GDROM: Read only device -"); 665 pr_notice("Read only device - write request ignored\n");
653 printk(" write request ignored\n");
654 __blk_end_request_all(req, -EIO); 666 __blk_end_request_all(req, -EIO);
655 continue; 667 continue;
656 } 668 }
@@ -685,7 +697,7 @@ static int __devinit gdrom_outputversion(void)
685 firmw_ver = kstrndup(id->firmver, 16, GFP_KERNEL); 697 firmw_ver = kstrndup(id->firmver, 16, GFP_KERNEL);
686 if (!firmw_ver) 698 if (!firmw_ver)
687 goto free_manuf_name; 699 goto free_manuf_name;
688 printk(KERN_INFO "GDROM: %s from %s with firmware %s\n", 700 pr_info("%s from %s with firmware %s\n",
689 model_name, manuf_name, firmw_ver); 701 model_name, manuf_name, firmw_ver);
690 err = 0; 702 err = 0;
691 kfree(firmw_ver); 703 kfree(firmw_ver);
@@ -757,7 +769,7 @@ static int __devinit probe_gdrom(struct platform_device *devptr)
757 int err; 769 int err;
758 /* Start the device */ 770 /* Start the device */
759 if (gdrom_execute_diagnostic() != 1) { 771 if (gdrom_execute_diagnostic() != 1) {
760 printk(KERN_WARNING "GDROM: ATA Probe for GDROM failed.\n"); 772 pr_warning("ATA Probe for GDROM failed\n");
761 return -ENODEV; 773 return -ENODEV;
762 } 774 }
763 /* Print out firmware ID */ 775 /* Print out firmware ID */
@@ -767,7 +779,7 @@ static int __devinit probe_gdrom(struct platform_device *devptr)
767 gdrom_major = register_blkdev(0, GDROM_DEV_NAME); 779 gdrom_major = register_blkdev(0, GDROM_DEV_NAME);
768 if (gdrom_major <= 0) 780 if (gdrom_major <= 0)
769 return gdrom_major; 781 return gdrom_major;
770 printk(KERN_INFO "GDROM: Registered with major number %d\n", 782 pr_info("Registered with major number %d\n",
771 gdrom_major); 783 gdrom_major);
772 /* Specify basic properties of drive */ 784 /* Specify basic properties of drive */
773 gd.cd_info = kzalloc(sizeof(struct cdrom_device_info), GFP_KERNEL); 785 gd.cd_info = kzalloc(sizeof(struct cdrom_device_info), GFP_KERNEL);
@@ -818,7 +830,7 @@ probe_fail_no_disk:
818 unregister_blkdev(gdrom_major, GDROM_DEV_NAME); 830 unregister_blkdev(gdrom_major, GDROM_DEV_NAME);
819 gdrom_major = 0; 831 gdrom_major = 0;
820probe_fail_no_mem: 832probe_fail_no_mem:
821 printk(KERN_WARNING "GDROM: Probe failed - error is 0x%X\n", err); 833 pr_warning("Probe failed - error is 0x%X\n", err);
822 return err; 834 return err;
823} 835}
824 836
diff --git a/drivers/cdrom/viocd.c b/drivers/cdrom/viocd.c
index 451cd7071b1d..56bf9f44700c 100644
--- a/drivers/cdrom/viocd.c
+++ b/drivers/cdrom/viocd.c
@@ -31,6 +31,8 @@
31 * the OS/400 partition. 31 * the OS/400 partition.
32 */ 32 */
33 33
34#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
35
34#include <linux/major.h> 36#include <linux/major.h>
35#include <linux/blkdev.h> 37#include <linux/blkdev.h>
36#include <linux/cdrom.h> 38#include <linux/cdrom.h>
@@ -40,6 +42,7 @@
40#include <linux/module.h> 42#include <linux/module.h>
41#include <linux/completion.h> 43#include <linux/completion.h>
42#include <linux/proc_fs.h> 44#include <linux/proc_fs.h>
45#include <linux/smp_lock.h>
43#include <linux/seq_file.h> 46#include <linux/seq_file.h>
44#include <linux/scatterlist.h> 47#include <linux/scatterlist.h>
45 48
@@ -53,9 +56,6 @@
53 56
54#define VIOCD_VERS "1.06" 57#define VIOCD_VERS "1.06"
55 58
56#define VIOCD_KERN_WARNING KERN_WARNING "viocd: "
57#define VIOCD_KERN_INFO KERN_INFO "viocd: "
58
59/* 59/*
60 * Should probably make this a module parameter....sigh 60 * Should probably make this a module parameter....sigh
61 */ 61 */
@@ -154,13 +154,21 @@ static const struct file_operations proc_viocd_operations = {
154static int viocd_blk_open(struct block_device *bdev, fmode_t mode) 154static int viocd_blk_open(struct block_device *bdev, fmode_t mode)
155{ 155{
156 struct disk_info *di = bdev->bd_disk->private_data; 156 struct disk_info *di = bdev->bd_disk->private_data;
157 return cdrom_open(&di->viocd_info, bdev, mode); 157 int ret;
158
159 lock_kernel();
160 ret = cdrom_open(&di->viocd_info, bdev, mode);
161 unlock_kernel();
162
163 return ret;
158} 164}
159 165
160static int viocd_blk_release(struct gendisk *disk, fmode_t mode) 166static int viocd_blk_release(struct gendisk *disk, fmode_t mode)
161{ 167{
162 struct disk_info *di = disk->private_data; 168 struct disk_info *di = disk->private_data;
169 lock_kernel();
163 cdrom_release(&di->viocd_info, mode); 170 cdrom_release(&di->viocd_info, mode);
171 unlock_kernel();
164 return 0; 172 return 0;
165} 173}
166 174
@@ -168,7 +176,13 @@ static int viocd_blk_ioctl(struct block_device *bdev, fmode_t mode,
168 unsigned cmd, unsigned long arg) 176 unsigned cmd, unsigned long arg)
169{ 177{
170 struct disk_info *di = bdev->bd_disk->private_data; 178 struct disk_info *di = bdev->bd_disk->private_data;
171 return cdrom_ioctl(&di->viocd_info, bdev, mode, cmd, arg); 179 int ret;
180
181 lock_kernel();
182 ret = cdrom_ioctl(&di->viocd_info, bdev, mode, cmd, arg);
183 unlock_kernel();
184
185 return ret;
172} 186}
173 187
174static int viocd_blk_media_changed(struct gendisk *disk) 188static int viocd_blk_media_changed(struct gendisk *disk)
@@ -181,7 +195,7 @@ static const struct block_device_operations viocd_fops = {
181 .owner = THIS_MODULE, 195 .owner = THIS_MODULE,
182 .open = viocd_blk_open, 196 .open = viocd_blk_open,
183 .release = viocd_blk_release, 197 .release = viocd_blk_release,
184 .locked_ioctl = viocd_blk_ioctl, 198 .ioctl = viocd_blk_ioctl,
185 .media_changed = viocd_blk_media_changed, 199 .media_changed = viocd_blk_media_changed,
186}; 200};
187 201
@@ -202,9 +216,8 @@ static int viocd_open(struct cdrom_device_info *cdi, int purpose)
202 (u64)&we, VIOVERSION << 16, ((u64)device_no << 48), 216 (u64)&we, VIOVERSION << 16, ((u64)device_no << 48),
203 0, 0, 0); 217 0, 0, 0);
204 if (hvrc != 0) { 218 if (hvrc != 0) {
205 printk(VIOCD_KERN_WARNING 219 pr_warning("bad rc on HvCallEvent_signalLpEventFast %d\n",
206 "bad rc on HvCallEvent_signalLpEventFast %d\n", 220 (int)hvrc);
207 (int)hvrc);
208 return -EIO; 221 return -EIO;
209 } 222 }
210 223
@@ -213,8 +226,8 @@ static int viocd_open(struct cdrom_device_info *cdi, int purpose)
213 if (we.rc) { 226 if (we.rc) {
214 const struct vio_error_entry *err = 227 const struct vio_error_entry *err =
215 vio_lookup_rc(viocd_err_table, we.sub_result); 228 vio_lookup_rc(viocd_err_table, we.sub_result);
216 printk(VIOCD_KERN_WARNING "bad rc %d:0x%04X on open: %s\n", 229 pr_warning("bad rc %d:0x%04X on open: %s\n",
217 we.rc, we.sub_result, err->msg); 230 we.rc, we.sub_result, err->msg);
218 return -err->errno; 231 return -err->errno;
219 } 232 }
220 233
@@ -234,9 +247,8 @@ static void viocd_release(struct cdrom_device_info *cdi)
234 viopath_targetinst(viopath_hostLp), 0, 247 viopath_targetinst(viopath_hostLp), 0,
235 VIOVERSION << 16, ((u64)device_no << 48), 0, 0, 0); 248 VIOVERSION << 16, ((u64)device_no << 48), 0, 0, 0);
236 if (hvrc != 0) 249 if (hvrc != 0)
237 printk(VIOCD_KERN_WARNING 250 pr_warning("bad rc on HvCallEvent_signalLpEventFast %d\n",
238 "bad rc on HvCallEvent_signalLpEventFast %d\n", 251 (int)hvrc);
239 (int)hvrc);
240} 252}
241 253
242/* Send a read or write request to OS/400 */ 254/* Send a read or write request to OS/400 */
@@ -262,13 +274,12 @@ static int send_request(struct request *req)
262 274
263 sg_init_table(&sg, 1); 275 sg_init_table(&sg, 1);
264 if (blk_rq_map_sg(req->q, req, &sg) == 0) { 276 if (blk_rq_map_sg(req->q, req, &sg) == 0) {
265 printk(VIOCD_KERN_WARNING 277 pr_warning("error setting up scatter/gather list\n");
266 "error setting up scatter/gather list\n");
267 return -1; 278 return -1;
268 } 279 }
269 280
270 if (dma_map_sg(diskinfo->dev, &sg, 1, direction) == 0) { 281 if (dma_map_sg(diskinfo->dev, &sg, 1, direction) == 0) {
271 printk(VIOCD_KERN_WARNING "error allocating sg tce\n"); 282 pr_warning("error allocating sg tce\n");
272 return -1; 283 return -1;
273 } 284 }
274 dmaaddr = sg_dma_address(&sg); 285 dmaaddr = sg_dma_address(&sg);
@@ -284,7 +295,7 @@ static int send_request(struct request *req)
284 ((u64)DEVICE_NR(diskinfo) << 48) | dmaaddr, 295 ((u64)DEVICE_NR(diskinfo) << 48) | dmaaddr,
285 (u64)blk_rq_pos(req) * 512, len, 0); 296 (u64)blk_rq_pos(req) * 512, len, 0);
286 if (hvrc != HvLpEvent_Rc_Good) { 297 if (hvrc != HvLpEvent_Rc_Good) {
287 printk(VIOCD_KERN_WARNING "hv error on op %d\n", (int)hvrc); 298 pr_warning("hv error on op %d\n", (int)hvrc);
288 return -1; 299 return -1;
289 } 300 }
290 301
@@ -298,11 +309,10 @@ static void do_viocd_request(struct request_queue *q)
298 struct request *req; 309 struct request *req;
299 310
300 while ((rwreq == 0) && ((req = blk_fetch_request(q)) != NULL)) { 311 while ((rwreq == 0) && ((req = blk_fetch_request(q)) != NULL)) {
301 if (!blk_fs_request(req)) 312 if (req->cmd_type != REQ_TYPE_FS)
302 __blk_end_request_all(req, -EIO); 313 __blk_end_request_all(req, -EIO);
303 else if (send_request(req) < 0) { 314 else if (send_request(req) < 0) {
304 printk(VIOCD_KERN_WARNING 315 pr_warning("unable to send message to OS/400!\n");
305 "unable to send message to OS/400!");
306 __blk_end_request_all(req, -EIO); 316 __blk_end_request_all(req, -EIO);
307 } else 317 } else
308 rwreq++; 318 rwreq++;
@@ -327,8 +337,8 @@ static int viocd_media_changed(struct cdrom_device_info *cdi, int disc_nr)
327 (u64)&we, VIOVERSION << 16, ((u64)device_no << 48), 337 (u64)&we, VIOVERSION << 16, ((u64)device_no << 48),
328 0, 0, 0); 338 0, 0, 0);
329 if (hvrc != 0) { 339 if (hvrc != 0) {
330 printk(VIOCD_KERN_WARNING "bad rc on HvCallEvent_signalLpEventFast %d\n", 340 pr_warning("bad rc on HvCallEvent_signalLpEventFast %d\n",
331 (int)hvrc); 341 (int)hvrc);
332 return -EIO; 342 return -EIO;
333 } 343 }
334 344
@@ -338,9 +348,8 @@ static int viocd_media_changed(struct cdrom_device_info *cdi, int disc_nr)
338 if (we.rc) { 348 if (we.rc) {
339 const struct vio_error_entry *err = 349 const struct vio_error_entry *err =
340 vio_lookup_rc(viocd_err_table, we.sub_result); 350 vio_lookup_rc(viocd_err_table, we.sub_result);
341 printk(VIOCD_KERN_WARNING 351 pr_warning("bad rc %d:0x%04X on check_change: %s; Assuming no change\n",
342 "bad rc %d:0x%04X on check_change: %s; Assuming no change\n", 352 we.rc, we.sub_result, err->msg);
343 we.rc, we.sub_result, err->msg);
344 return 0; 353 return 0;
345 } 354 }
346 355
@@ -367,8 +376,8 @@ static int viocd_lock_door(struct cdrom_device_info *cdi, int locking)
367 (u64)&we, VIOVERSION << 16, 376 (u64)&we, VIOVERSION << 16,
368 (device_no << 48) | (flags << 32), 0, 0, 0); 377 (device_no << 48) | (flags << 32), 0, 0, 0);
369 if (hvrc != 0) { 378 if (hvrc != 0) {
370 printk(VIOCD_KERN_WARNING "bad rc on HvCallEvent_signalLpEventFast %d\n", 379 pr_warning("bad rc on HvCallEvent_signalLpEventFast %d\n",
371 (int)hvrc); 380 (int)hvrc);
372 return -EIO; 381 return -EIO;
373 } 382 }
374 383
@@ -455,8 +464,7 @@ static void vio_handle_cd_event(struct HvLpEvent *event)
455 return; 464 return;
456 /* First, we should NEVER get an int here...only acks */ 465 /* First, we should NEVER get an int here...only acks */
457 if (hvlpevent_is_int(event)) { 466 if (hvlpevent_is_int(event)) {
458 printk(VIOCD_KERN_WARNING 467 pr_warning("Yikes! got an int in viocd event handler!\n");
459 "Yikes! got an int in viocd event handler!\n");
460 if (hvlpevent_need_ack(event)) { 468 if (hvlpevent_need_ack(event)) {
461 event->xRc = HvLpEvent_Rc_InvalidSubtype; 469 event->xRc = HvLpEvent_Rc_InvalidSubtype;
462 HvCallEvent_ackLpEvent(event); 470 HvCallEvent_ackLpEvent(event);
@@ -510,10 +518,9 @@ return_complete:
510 const struct vio_error_entry *err = 518 const struct vio_error_entry *err =
511 vio_lookup_rc(viocd_err_table, 519 vio_lookup_rc(viocd_err_table,
512 bevent->sub_result); 520 bevent->sub_result);
513 printk(VIOCD_KERN_WARNING "request %p failed " 521 pr_warning("request %p failed with rc %d:0x%04X: %s\n",
514 "with rc %d:0x%04X: %s\n", 522 req, event->xRc,
515 req, event->xRc, 523 bevent->sub_result, err->msg);
516 bevent->sub_result, err->msg);
517 __blk_end_request_all(req, -EIO); 524 __blk_end_request_all(req, -EIO);
518 } else 525 } else
519 __blk_end_request_all(req, 0); 526 __blk_end_request_all(req, 0);
@@ -524,9 +531,8 @@ return_complete:
524 break; 531 break;
525 532
526 default: 533 default:
527 printk(VIOCD_KERN_WARNING 534 pr_warning("message with invalid subtype %0x04X!\n",
528 "message with invalid subtype %0x04X!\n", 535 event->xSubtype & VIOMINOR_SUBTYPE_MASK);
529 event->xSubtype & VIOMINOR_SUBTYPE_MASK);
530 if (hvlpevent_need_ack(event)) { 536 if (hvlpevent_need_ack(event)) {
531 event->xRc = HvLpEvent_Rc_InvalidSubtype; 537 event->xRc = HvLpEvent_Rc_InvalidSubtype;
532 HvCallEvent_ackLpEvent(event); 538 HvCallEvent_ackLpEvent(event);
@@ -593,23 +599,19 @@ static int viocd_probe(struct vio_dev *vdev, const struct vio_device_id *id)
593 sprintf(c->name, VIOCD_DEVICE "%c", 'a' + deviceno); 599 sprintf(c->name, VIOCD_DEVICE "%c", 'a' + deviceno);
594 600
595 if (register_cdrom(c) != 0) { 601 if (register_cdrom(c) != 0) {
596 printk(VIOCD_KERN_WARNING "Cannot register viocd CD-ROM %s!\n", 602 pr_warning("Cannot register viocd CD-ROM %s!\n", c->name);
597 c->name);
598 goto out; 603 goto out;
599 } 604 }
600 printk(VIOCD_KERN_INFO "cd %s is iSeries resource %10.10s " 605 pr_info("cd %s is iSeries resource %10.10s type %4.4s, model %3.3s\n",
601 "type %4.4s, model %3.3s\n", 606 c->name, d->rsrcname, d->type, d->model);
602 c->name, d->rsrcname, d->type, d->model);
603 q = blk_init_queue(do_viocd_request, &viocd_reqlock); 607 q = blk_init_queue(do_viocd_request, &viocd_reqlock);
604 if (q == NULL) { 608 if (q == NULL) {
605 printk(VIOCD_KERN_WARNING "Cannot allocate queue for %s!\n", 609 pr_warning("Cannot allocate queue for %s!\n", c->name);
606 c->name);
607 goto out_unregister_cdrom; 610 goto out_unregister_cdrom;
608 } 611 }
609 gendisk = alloc_disk(1); 612 gendisk = alloc_disk(1);
610 if (gendisk == NULL) { 613 if (gendisk == NULL) {
611 printk(VIOCD_KERN_WARNING "Cannot create gendisk for %s!\n", 614 pr_warning("Cannot create gendisk for %s!\n", c->name);
612 c->name);
613 goto out_cleanup_queue; 615 goto out_cleanup_queue;
614 } 616 }
615 gendisk->major = VIOCD_MAJOR; 617 gendisk->major = VIOCD_MAJOR;
@@ -682,21 +684,19 @@ static int __init viocd_init(void)
682 return -ENODEV; 684 return -ENODEV;
683 } 685 }
684 686
685 printk(VIOCD_KERN_INFO "vers " VIOCD_VERS ", hosting partition %d\n", 687 pr_info("vers " VIOCD_VERS ", hosting partition %d\n", viopath_hostLp);
686 viopath_hostLp);
687 688
688 if (register_blkdev(VIOCD_MAJOR, VIOCD_DEVICE) != 0) { 689 if (register_blkdev(VIOCD_MAJOR, VIOCD_DEVICE) != 0) {
689 printk(VIOCD_KERN_WARNING "Unable to get major %d for %s\n", 690 pr_warning("Unable to get major %d for %s\n",
690 VIOCD_MAJOR, VIOCD_DEVICE); 691 VIOCD_MAJOR, VIOCD_DEVICE);
691 return -EIO; 692 return -EIO;
692 } 693 }
693 694
694 ret = viopath_open(viopath_hostLp, viomajorsubtype_cdio, 695 ret = viopath_open(viopath_hostLp, viomajorsubtype_cdio,
695 MAX_CD_REQ + 2); 696 MAX_CD_REQ + 2);
696 if (ret) { 697 if (ret) {
697 printk(VIOCD_KERN_WARNING 698 pr_warning("error opening path to host partition %d\n",
698 "error opening path to host partition %d\n", 699 viopath_hostLp);
699 viopath_hostLp);
700 goto out_unregister; 700 goto out_unregister;
701 } 701 }
702 702
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index 7cfcc629a7fd..3d44ec724c17 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -1002,7 +1002,7 @@ config SCx200_GPIO
1002 1002
1003config PC8736x_GPIO 1003config PC8736x_GPIO
1004 tristate "NatSemi PC8736x GPIO Support" 1004 tristate "NatSemi PC8736x GPIO Support"
1005 depends on X86 1005 depends on X86_32
1006 default SCx200_GPIO # mostly N 1006 default SCx200_GPIO # mostly N
1007 select NSC_GPIO # needed for support routines 1007 select NSC_GPIO # needed for support routines
1008 help 1008 help
diff --git a/drivers/char/Makefile b/drivers/char/Makefile
index 88d6eac69754..dc9641660605 100644
--- a/drivers/char/Makefile
+++ b/drivers/char/Makefile
@@ -9,6 +9,7 @@ FONTMAPFILE = cp437.uni
9 9
10obj-y += mem.o random.o tty_io.o n_tty.o tty_ioctl.o tty_ldisc.o tty_buffer.o tty_port.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-y += tty_mutex.o
12obj-$(CONFIG_LEGACY_PTYS) += pty.o 13obj-$(CONFIG_LEGACY_PTYS) += pty.o
13obj-$(CONFIG_UNIX98_PTYS) += pty.o 14obj-$(CONFIG_UNIX98_PTYS) += pty.o
14obj-y += misc.o 15obj-y += misc.o
@@ -47,6 +48,7 @@ obj-$(CONFIG_RIO) += rio/ generic_serial.o
47obj-$(CONFIG_HVC_CONSOLE) += hvc_vio.o hvsi.o 48obj-$(CONFIG_HVC_CONSOLE) += hvc_vio.o hvsi.o
48obj-$(CONFIG_HVC_ISERIES) += hvc_iseries.o 49obj-$(CONFIG_HVC_ISERIES) += hvc_iseries.o
49obj-$(CONFIG_HVC_RTAS) += hvc_rtas.o 50obj-$(CONFIG_HVC_RTAS) += hvc_rtas.o
51obj-$(CONFIG_HVC_TILE) += hvc_tile.o
50obj-$(CONFIG_HVC_BEAT) += hvc_beat.o 52obj-$(CONFIG_HVC_BEAT) += hvc_beat.o
51obj-$(CONFIG_HVC_DRIVER) += hvc_console.o 53obj-$(CONFIG_HVC_DRIVER) += hvc_console.o
52obj-$(CONFIG_HVC_IRQ) += hvc_irq.o 54obj-$(CONFIG_HVC_IRQ) += hvc_irq.o
diff --git a/drivers/char/amiserial.c b/drivers/char/amiserial.c
index 4f8d60c25a98..a11c8c9ca3d4 100644
--- a/drivers/char/amiserial.c
+++ b/drivers/char/amiserial.c
@@ -1072,7 +1072,7 @@ static int get_serial_info(struct async_struct * info,
1072 if (!retinfo) 1072 if (!retinfo)
1073 return -EFAULT; 1073 return -EFAULT;
1074 memset(&tmp, 0, sizeof(tmp)); 1074 memset(&tmp, 0, sizeof(tmp));
1075 lock_kernel(); 1075 tty_lock();
1076 tmp.type = state->type; 1076 tmp.type = state->type;
1077 tmp.line = state->line; 1077 tmp.line = state->line;
1078 tmp.port = state->port; 1078 tmp.port = state->port;
@@ -1083,7 +1083,7 @@ static int get_serial_info(struct async_struct * info,
1083 tmp.close_delay = state->close_delay; 1083 tmp.close_delay = state->close_delay;
1084 tmp.closing_wait = state->closing_wait; 1084 tmp.closing_wait = state->closing_wait;
1085 tmp.custom_divisor = state->custom_divisor; 1085 tmp.custom_divisor = state->custom_divisor;
1086 unlock_kernel(); 1086 tty_unlock();
1087 if (copy_to_user(retinfo,&tmp,sizeof(*retinfo))) 1087 if (copy_to_user(retinfo,&tmp,sizeof(*retinfo)))
1088 return -EFAULT; 1088 return -EFAULT;
1089 return 0; 1089 return 0;
@@ -1100,14 +1100,14 @@ static int set_serial_info(struct async_struct * info,
1100 if (copy_from_user(&new_serial,new_info,sizeof(new_serial))) 1100 if (copy_from_user(&new_serial,new_info,sizeof(new_serial)))
1101 return -EFAULT; 1101 return -EFAULT;
1102 1102
1103 lock_kernel(); 1103 tty_lock();
1104 state = info->state; 1104 state = info->state;
1105 old_state = *state; 1105 old_state = *state;
1106 1106
1107 change_irq = new_serial.irq != state->irq; 1107 change_irq = new_serial.irq != state->irq;
1108 change_port = (new_serial.port != state->port); 1108 change_port = (new_serial.port != state->port);
1109 if(change_irq || change_port || (new_serial.xmit_fifo_size != state->xmit_fifo_size)) { 1109 if(change_irq || change_port || (new_serial.xmit_fifo_size != state->xmit_fifo_size)) {
1110 unlock_kernel(); 1110 tty_unlock();
1111 return -EINVAL; 1111 return -EINVAL;
1112 } 1112 }
1113 1113
@@ -1127,7 +1127,7 @@ static int set_serial_info(struct async_struct * info,
1127 } 1127 }
1128 1128
1129 if (new_serial.baud_base < 9600) { 1129 if (new_serial.baud_base < 9600) {
1130 unlock_kernel(); 1130 tty_unlock();
1131 return -EINVAL; 1131 return -EINVAL;
1132 } 1132 }
1133 1133
@@ -1163,7 +1163,7 @@ check_and_exit:
1163 } 1163 }
1164 } else 1164 } else
1165 retval = startup(info); 1165 retval = startup(info);
1166 unlock_kernel(); 1166 tty_unlock();
1167 return retval; 1167 return retval;
1168} 1168}
1169 1169
@@ -1528,6 +1528,7 @@ static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
1528{ 1528{
1529 struct async_struct * info = tty->driver_data; 1529 struct async_struct * info = tty->driver_data;
1530 unsigned long orig_jiffies, char_time; 1530 unsigned long orig_jiffies, char_time;
1531 int tty_was_locked = tty_locked();
1531 int lsr; 1532 int lsr;
1532 1533
1533 if (serial_paranoia_check(info, tty->name, "rs_wait_until_sent")) 1534 if (serial_paranoia_check(info, tty->name, "rs_wait_until_sent"))
@@ -1538,7 +1539,12 @@ static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
1538 1539
1539 orig_jiffies = jiffies; 1540 orig_jiffies = jiffies;
1540 1541
1541 lock_kernel(); 1542 /*
1543 * tty_wait_until_sent is called from lots of places,
1544 * with or without the BTM.
1545 */
1546 if (!tty_was_locked)
1547 tty_lock();
1542 /* 1548 /*
1543 * Set the check interval to be 1/5 of the estimated time to 1549 * Set the check interval to be 1/5 of the estimated time to
1544 * send a single character, and make it at least 1. The check 1550 * send a single character, and make it at least 1. The check
@@ -1579,7 +1585,8 @@ static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
1579 break; 1585 break;
1580 } 1586 }
1581 __set_current_state(TASK_RUNNING); 1587 __set_current_state(TASK_RUNNING);
1582 unlock_kernel(); 1588 if (!tty_was_locked)
1589 tty_unlock();
1583#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT 1590#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1584 printk("lsr = %d (jiff=%lu)...done\n", lsr, jiffies); 1591 printk("lsr = %d (jiff=%lu)...done\n", lsr, jiffies);
1585#endif 1592#endif
@@ -1703,7 +1710,9 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
1703 printk("block_til_ready blocking: ttys%d, count = %d\n", 1710 printk("block_til_ready blocking: ttys%d, count = %d\n",
1704 info->line, state->count); 1711 info->line, state->count);
1705#endif 1712#endif
1713 tty_unlock();
1706 schedule(); 1714 schedule();
1715 tty_lock();
1707 } 1716 }
1708 __set_current_state(TASK_RUNNING); 1717 __set_current_state(TASK_RUNNING);
1709 remove_wait_queue(&info->open_wait, &wait); 1718 remove_wait_queue(&info->open_wait, &wait);
diff --git a/drivers/char/briq_panel.c b/drivers/char/briq_panel.c
index 555cd93c2ee5..d5fa113afe37 100644
--- a/drivers/char/briq_panel.c
+++ b/drivers/char/briq_panel.c
@@ -67,15 +67,15 @@ static void set_led(char state)
67 67
68static int briq_panel_open(struct inode *ino, struct file *filep) 68static int briq_panel_open(struct inode *ino, struct file *filep)
69{ 69{
70 lock_kernel(); 70 tty_lock();
71 /* enforce single access, vfd_is_open is protected by BKL */ 71 /* enforce single access, vfd_is_open is protected by BKL */
72 if (vfd_is_open) { 72 if (vfd_is_open) {
73 unlock_kernel(); 73 tty_unlock();
74 return -EBUSY; 74 return -EBUSY;
75 } 75 }
76 vfd_is_open = 1; 76 vfd_is_open = 1;
77 77
78 unlock_kernel(); 78 tty_unlock();
79 return 0; 79 return 0;
80} 80}
81 81
diff --git a/drivers/char/cyclades.c b/drivers/char/cyclades.c
index 9824b4162904..27aad9422332 100644
--- a/drivers/char/cyclades.c
+++ b/drivers/char/cyclades.c
@@ -65,7 +65,6 @@
65#include <linux/tty.h> 65#include <linux/tty.h>
66#include <linux/tty_flip.h> 66#include <linux/tty_flip.h>
67#include <linux/serial.h> 67#include <linux/serial.h>
68#include <linux/smp_lock.h>
69#include <linux/major.h> 68#include <linux/major.h>
70#include <linux/string.h> 69#include <linux/string.h>
71#include <linux/fcntl.h> 70#include <linux/fcntl.h>
@@ -1608,7 +1607,7 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
1608 * If the port is the middle of closing, bail out now 1607 * If the port is the middle of closing, bail out now
1609 */ 1608 */
1610 if (tty_hung_up_p(filp) || (info->port.flags & ASYNC_CLOSING)) { 1609 if (tty_hung_up_p(filp) || (info->port.flags & ASYNC_CLOSING)) {
1611 wait_event_interruptible(info->port.close_wait, 1610 wait_event_interruptible_tty(info->port.close_wait,
1612 !(info->port.flags & ASYNC_CLOSING)); 1611 !(info->port.flags & ASYNC_CLOSING));
1613 return (info->port.flags & ASYNC_HUP_NOTIFY) ? -EAGAIN: -ERESTARTSYS; 1612 return (info->port.flags & ASYNC_HUP_NOTIFY) ? -EAGAIN: -ERESTARTSYS;
1614 } 1613 }
@@ -1655,7 +1654,6 @@ static void cy_wait_until_sent(struct tty_struct *tty, int timeout)
1655 return; /* Just in case.... */ 1654 return; /* Just in case.... */
1656 1655
1657 orig_jiffies = jiffies; 1656 orig_jiffies = jiffies;
1658 lock_kernel();
1659 /* 1657 /*
1660 * Set the check interval to be 1/5 of the estimated time to 1658 * Set the check interval to be 1/5 of the estimated time to
1661 * send a single character, and make it at least 1. The check 1659 * send a single character, and make it at least 1. The check
@@ -1702,7 +1700,6 @@ static void cy_wait_until_sent(struct tty_struct *tty, int timeout)
1702 } 1700 }
1703 /* Run one more char cycle */ 1701 /* Run one more char cycle */
1704 msleep_interruptible(jiffies_to_msecs(char_time * 5)); 1702 msleep_interruptible(jiffies_to_msecs(char_time * 5));
1705 unlock_kernel();
1706#ifdef CY_DEBUG_WAIT_UNTIL_SENT 1703#ifdef CY_DEBUG_WAIT_UNTIL_SENT
1707 printk(KERN_DEBUG "Clean (jiff=%lu)...done\n", jiffies); 1704 printk(KERN_DEBUG "Clean (jiff=%lu)...done\n", jiffies);
1708#endif 1705#endif
@@ -1959,7 +1956,6 @@ static int cy_chars_in_buffer(struct tty_struct *tty)
1959 int char_count; 1956 int char_count;
1960 __u32 tx_put, tx_get, tx_bufsize; 1957 __u32 tx_put, tx_get, tx_bufsize;
1961 1958
1962 lock_kernel();
1963 tx_get = readl(&buf_ctrl->tx_get); 1959 tx_get = readl(&buf_ctrl->tx_get);
1964 tx_put = readl(&buf_ctrl->tx_put); 1960 tx_put = readl(&buf_ctrl->tx_put);
1965 tx_bufsize = readl(&buf_ctrl->tx_bufsize); 1961 tx_bufsize = readl(&buf_ctrl->tx_bufsize);
@@ -1971,7 +1967,6 @@ static int cy_chars_in_buffer(struct tty_struct *tty)
1971 printk(KERN_DEBUG "cyc:cy_chars_in_buffer ttyC%d %d\n", 1967 printk(KERN_DEBUG "cyc:cy_chars_in_buffer ttyC%d %d\n",
1972 info->line, info->xmit_cnt + char_count); 1968 info->line, info->xmit_cnt + char_count);
1973#endif 1969#endif
1974 unlock_kernel();
1975 return info->xmit_cnt + char_count; 1970 return info->xmit_cnt + char_count;
1976 } 1971 }
1977#endif /* Z_EXT_CHARS_IN_BUFFER */ 1972#endif /* Z_EXT_CHARS_IN_BUFFER */
@@ -2359,17 +2354,22 @@ cy_set_serial_info(struct cyclades_port *info, struct tty_struct *tty,
2359 struct serial_struct __user *new_info) 2354 struct serial_struct __user *new_info)
2360{ 2355{
2361 struct serial_struct new_serial; 2356 struct serial_struct new_serial;
2357 int ret;
2362 2358
2363 if (copy_from_user(&new_serial, new_info, sizeof(new_serial))) 2359 if (copy_from_user(&new_serial, new_info, sizeof(new_serial)))
2364 return -EFAULT; 2360 return -EFAULT;
2365 2361
2362 mutex_lock(&info->port.mutex);
2366 if (!capable(CAP_SYS_ADMIN)) { 2363 if (!capable(CAP_SYS_ADMIN)) {
2367 if (new_serial.close_delay != info->port.close_delay || 2364 if (new_serial.close_delay != info->port.close_delay ||
2368 new_serial.baud_base != info->baud || 2365 new_serial.baud_base != info->baud ||
2369 (new_serial.flags & ASYNC_FLAGS & 2366 (new_serial.flags & ASYNC_FLAGS &
2370 ~ASYNC_USR_MASK) != 2367 ~ASYNC_USR_MASK) !=
2371 (info->port.flags & ASYNC_FLAGS & ~ASYNC_USR_MASK)) 2368 (info->port.flags & ASYNC_FLAGS & ~ASYNC_USR_MASK))
2369 {
2370 mutex_unlock(&info->port.mutex);
2372 return -EPERM; 2371 return -EPERM;
2372 }
2373 info->port.flags = (info->port.flags & ~ASYNC_USR_MASK) | 2373 info->port.flags = (info->port.flags & ~ASYNC_USR_MASK) |
2374 (new_serial.flags & ASYNC_USR_MASK); 2374 (new_serial.flags & ASYNC_USR_MASK);
2375 info->baud = new_serial.baud_base; 2375 info->baud = new_serial.baud_base;
@@ -2392,10 +2392,12 @@ cy_set_serial_info(struct cyclades_port *info, struct tty_struct *tty,
2392check_and_exit: 2392check_and_exit:
2393 if (info->port.flags & ASYNC_INITIALIZED) { 2393 if (info->port.flags & ASYNC_INITIALIZED) {
2394 cy_set_line_char(info, tty); 2394 cy_set_line_char(info, tty);
2395 return 0; 2395 ret = 0;
2396 } else { 2396 } else {
2397 return cy_startup(info, tty); 2397 ret = cy_startup(info, tty);
2398 } 2398 }
2399 mutex_unlock(&info->port.mutex);
2400 return ret;
2399} /* set_serial_info */ 2401} /* set_serial_info */
2400 2402
2401/* 2403/*
@@ -2438,7 +2440,6 @@ static int cy_tiocmget(struct tty_struct *tty, struct file *file)
2438 2440
2439 card = info->card; 2441 card = info->card;
2440 2442
2441 lock_kernel();
2442 if (!cy_is_Z(card)) { 2443 if (!cy_is_Z(card)) {
2443 unsigned long flags; 2444 unsigned long flags;
2444 int channel = info->line - card->first_line; 2445 int channel = info->line - card->first_line;
@@ -2478,7 +2479,6 @@ static int cy_tiocmget(struct tty_struct *tty, struct file *file)
2478 ((lstatus & C_RS_CTS) ? TIOCM_CTS : 0); 2479 ((lstatus & C_RS_CTS) ? TIOCM_CTS : 0);
2479 } 2480 }
2480end: 2481end:
2481 unlock_kernel();
2482 return result; 2482 return result;
2483} /* cy_tiomget */ 2483} /* cy_tiomget */
2484 2484
@@ -2696,7 +2696,6 @@ cy_ioctl(struct tty_struct *tty, struct file *file,
2696 printk(KERN_DEBUG "cyc:cy_ioctl ttyC%d, cmd = %x arg = %lx\n", 2696 printk(KERN_DEBUG "cyc:cy_ioctl ttyC%d, cmd = %x arg = %lx\n",
2697 info->line, cmd, arg); 2697 info->line, cmd, arg);
2698#endif 2698#endif
2699 lock_kernel();
2700 2699
2701 switch (cmd) { 2700 switch (cmd) {
2702 case CYGETMON: 2701 case CYGETMON:
@@ -2817,7 +2816,6 @@ cy_ioctl(struct tty_struct *tty, struct file *file,
2817 default: 2816 default:
2818 ret_val = -ENOIOCTLCMD; 2817 ret_val = -ENOIOCTLCMD;
2819 } 2818 }
2820 unlock_kernel();
2821 2819
2822#ifdef CY_DEBUG_OTHER 2820#ifdef CY_DEBUG_OTHER
2823 printk(KERN_DEBUG "cyc:cy_ioctl done\n"); 2821 printk(KERN_DEBUG "cyc:cy_ioctl done\n");
diff --git a/drivers/char/epca.c b/drivers/char/epca.c
index 6f5ffe1320f7..d9df46aa0fba 100644
--- a/drivers/char/epca.c
+++ b/drivers/char/epca.c
@@ -36,7 +36,7 @@
36#include <linux/ctype.h> 36#include <linux/ctype.h>
37#include <linux/tty.h> 37#include <linux/tty.h>
38#include <linux/tty_flip.h> 38#include <linux/tty_flip.h>
39#include <linux/smp_lock.h> 39#include <linux/slab.h>
40#include <linux/ioport.h> 40#include <linux/ioport.h>
41#include <linux/interrupt.h> 41#include <linux/interrupt.h>
42#include <linux/uaccess.h> 42#include <linux/uaccess.h>
@@ -2105,7 +2105,6 @@ static int pc_ioctl(struct tty_struct *tty, struct file *file,
2105 break; 2105 break;
2106 case DIGI_SETAW: 2106 case DIGI_SETAW:
2107 case DIGI_SETAF: 2107 case DIGI_SETAF:
2108 lock_kernel();
2109 if (cmd == DIGI_SETAW) { 2108 if (cmd == DIGI_SETAW) {
2110 /* Setup an event to indicate when the transmit 2109 /* Setup an event to indicate when the transmit
2111 buffer empties */ 2110 buffer empties */
@@ -2118,7 +2117,6 @@ static int pc_ioctl(struct tty_struct *tty, struct file *file,
2118 if (tty->ldisc->ops->flush_buffer) 2117 if (tty->ldisc->ops->flush_buffer)
2119 tty->ldisc->ops->flush_buffer(tty); 2118 tty->ldisc->ops->flush_buffer(tty);
2120 } 2119 }
2121 unlock_kernel();
2122 /* Fall Thru */ 2120 /* Fall Thru */
2123 case DIGI_SETA: 2121 case DIGI_SETA:
2124 if (copy_from_user(&ch->digiext, argp, sizeof(digi_t))) 2122 if (copy_from_user(&ch->digiext, argp, sizeof(digi_t)))
diff --git a/drivers/char/hvc_iucv.c b/drivers/char/hvc_iucv.c
index 5a80ad68ef22..7b01bc609de3 100644
--- a/drivers/char/hvc_iucv.c
+++ b/drivers/char/hvc_iucv.c
@@ -1149,7 +1149,7 @@ out_err:
1149 * Note: If it is called early in the boot process, @val is stored and 1149 * Note: If it is called early in the boot process, @val is stored and
1150 * parsed later in hvc_iucv_init(). 1150 * parsed later in hvc_iucv_init().
1151 */ 1151 */
1152static int param_set_vmidfilter(const char *val, struct kernel_param *kp) 1152static int param_set_vmidfilter(const char *val, const struct kernel_param *kp)
1153{ 1153{
1154 int rc; 1154 int rc;
1155 1155
@@ -1176,7 +1176,7 @@ static int param_set_vmidfilter(const char *val, struct kernel_param *kp)
1176 * The function stores the filter as a comma-separated list of z/VM user IDs 1176 * The function stores the filter as a comma-separated list of z/VM user IDs
1177 * in @buffer. Typically, sysfs routines call this function for attr show. 1177 * in @buffer. Typically, sysfs routines call this function for attr show.
1178 */ 1178 */
1179static int param_get_vmidfilter(char *buffer, struct kernel_param *kp) 1179static int param_get_vmidfilter(char *buffer, const struct kernel_param *kp)
1180{ 1180{
1181 int rc; 1181 int rc;
1182 size_t index, len; 1182 size_t index, len;
@@ -1203,6 +1203,11 @@ static int param_get_vmidfilter(char *buffer, struct kernel_param *kp)
1203 1203
1204#define param_check_vmidfilter(name, p) __param_check(name, p, void) 1204#define param_check_vmidfilter(name, p) __param_check(name, p, void)
1205 1205
1206static struct kernel_param_ops param_ops_vmidfilter = {
1207 .set = param_set_vmidfilter,
1208 .get = param_get_vmidfilter,
1209};
1210
1206/** 1211/**
1207 * hvc_iucv_init() - z/VM IUCV HVC device driver initialization 1212 * hvc_iucv_init() - z/VM IUCV HVC device driver initialization
1208 */ 1213 */
diff --git a/drivers/char/hvc_tile.c b/drivers/char/hvc_tile.c
new file mode 100644
index 000000000000..c4efb55cbc03
--- /dev/null
+++ b/drivers/char/hvc_tile.c
@@ -0,0 +1,67 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 * Tilera TILE Processor hypervisor console
15 */
16
17#include <linux/console.h>
18#include <linux/delay.h>
19#include <linux/err.h>
20#include <linux/init.h>
21#include <linux/moduleparam.h>
22#include <linux/types.h>
23
24#include <hv/hypervisor.h>
25
26#include "hvc_console.h"
27
28static int hvc_tile_put_chars(uint32_t vt, const char *buf, int count)
29{
30 return hv_console_write((HV_VirtAddr)buf, count);
31}
32
33static int hvc_tile_get_chars(uint32_t vt, char *buf, int count)
34{
35 int i, c;
36
37 for (i = 0; i < count; ++i) {
38 c = hv_console_read_if_ready();
39 if (c < 0)
40 break;
41 buf[i] = c;
42 }
43
44 return i;
45}
46
47static const struct hv_ops hvc_tile_get_put_ops = {
48 .get_chars = hvc_tile_get_chars,
49 .put_chars = hvc_tile_put_chars,
50};
51
52static int __init hvc_tile_console_init(void)
53{
54 extern void disable_early_printk(void);
55 hvc_instantiate(0, 0, &hvc_tile_get_put_ops);
56 add_preferred_console("hvc", 0, NULL);
57 disable_early_printk();
58 return 0;
59}
60console_initcall(hvc_tile_console_init);
61
62static int __init hvc_tile_init(void)
63{
64 hvc_alloc(0, 0, &hvc_tile_get_put_ops, 128);
65 return 0;
66}
67device_initcall(hvc_tile_init);
diff --git a/drivers/char/hw_random/n2-drv.c b/drivers/char/hw_random/n2-drv.c
index 7a4f080f8356..1acdb2509511 100644
--- a/drivers/char/hw_random/n2-drv.c
+++ b/drivers/char/hw_random/n2-drv.c
@@ -619,7 +619,7 @@ static void __devinit n2rng_driver_version(void)
619 pr_info("%s", version); 619 pr_info("%s", version);
620} 620}
621 621
622static int __devinit n2rng_probe(struct of_device *op, 622static int __devinit n2rng_probe(struct platform_device *op,
623 const struct of_device_id *match) 623 const struct of_device_id *match)
624{ 624{
625 int victoria_falls = (match->data != NULL); 625 int victoria_falls = (match->data != NULL);
@@ -714,7 +714,7 @@ out:
714 return err; 714 return err;
715} 715}
716 716
717static int __devexit n2rng_remove(struct of_device *op) 717static int __devexit n2rng_remove(struct platform_device *op)
718{ 718{
719 struct n2rng *np = dev_get_drvdata(&op->dev); 719 struct n2rng *np = dev_get_drvdata(&op->dev);
720 720
diff --git a/drivers/char/hw_random/n2rng.h b/drivers/char/hw_random/n2rng.h
index a2b81e7bfc18..4bea07f30978 100644
--- a/drivers/char/hw_random/n2rng.h
+++ b/drivers/char/hw_random/n2rng.h
@@ -65,7 +65,7 @@ struct n2rng_unit {
65}; 65};
66 66
67struct n2rng { 67struct n2rng {
68 struct of_device *op; 68 struct platform_device *op;
69 69
70 unsigned long flags; 70 unsigned long flags;
71#define N2RNG_FLAG_VF 0x00000001 /* Victoria Falls RNG, else N2 */ 71#define N2RNG_FLAG_VF 0x00000001 /* Victoria Falls RNG, else N2 */
diff --git a/drivers/char/hw_random/pasemi-rng.c b/drivers/char/hw_random/pasemi-rng.c
index 261ba8f22b8b..a31c830ca8cd 100644
--- a/drivers/char/hw_random/pasemi-rng.c
+++ b/drivers/char/hw_random/pasemi-rng.c
@@ -94,7 +94,7 @@ static struct hwrng pasemi_rng = {
94 .data_read = pasemi_rng_data_read, 94 .data_read = pasemi_rng_data_read,
95}; 95};
96 96
97static int __devinit rng_probe(struct of_device *ofdev, 97static int __devinit rng_probe(struct platform_device *ofdev,
98 const struct of_device_id *match) 98 const struct of_device_id *match)
99{ 99{
100 void __iomem *rng_regs; 100 void __iomem *rng_regs;
@@ -123,7 +123,7 @@ static int __devinit rng_probe(struct of_device *ofdev,
123 return err; 123 return err;
124} 124}
125 125
126static int __devexit rng_remove(struct of_device *dev) 126static int __devexit rng_remove(struct platform_device *dev)
127{ 127{
128 void __iomem *rng_regs = (void __iomem *)pasemi_rng.priv; 128 void __iomem *rng_regs = (void __iomem *)pasemi_rng.priv;
129 129
diff --git a/drivers/char/ip2/ip2main.c b/drivers/char/ip2/ip2main.c
index 911e1da6def2..07f3ea38b582 100644
--- a/drivers/char/ip2/ip2main.c
+++ b/drivers/char/ip2/ip2main.c
@@ -1486,7 +1486,9 @@ ip2_open( PTTY tty, struct file *pFile )
1486 1486
1487 if ( tty_hung_up_p(pFile) || ( pCh->flags & ASYNC_CLOSING )) { 1487 if ( tty_hung_up_p(pFile) || ( pCh->flags & ASYNC_CLOSING )) {
1488 if ( pCh->flags & ASYNC_CLOSING ) { 1488 if ( pCh->flags & ASYNC_CLOSING ) {
1489 tty_unlock();
1489 schedule(); 1490 schedule();
1491 tty_lock();
1490 } 1492 }
1491 if ( tty_hung_up_p(pFile) ) { 1493 if ( tty_hung_up_p(pFile) ) {
1492 set_current_state( TASK_RUNNING ); 1494 set_current_state( TASK_RUNNING );
@@ -1548,7 +1550,9 @@ ip2_open( PTTY tty, struct file *pFile )
1548 rc = (( pCh->flags & ASYNC_HUP_NOTIFY ) ? -EAGAIN : -ERESTARTSYS); 1550 rc = (( pCh->flags & ASYNC_HUP_NOTIFY ) ? -EAGAIN : -ERESTARTSYS);
1549 break; 1551 break;
1550 } 1552 }
1553 tty_unlock();
1551 schedule(); 1554 schedule();
1555 tty_lock();
1552 } 1556 }
1553 set_current_state( TASK_RUNNING ); 1557 set_current_state( TASK_RUNNING );
1554 remove_wait_queue(&pCh->open_wait, &wait); 1558 remove_wait_queue(&pCh->open_wait, &wait);
diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
index 094bdc355b1f..3822b4f49c84 100644
--- a/drivers/char/ipmi/ipmi_si_intf.c
+++ b/drivers/char/ipmi/ipmi_si_intf.c
@@ -1804,9 +1804,12 @@ static int hotmod_handler(const char *val, struct kernel_param *kp)
1804 info->irq_setup = std_irq_setup; 1804 info->irq_setup = std_irq_setup;
1805 info->slave_addr = ipmb; 1805 info->slave_addr = ipmb;
1806 1806
1807 if (!add_smi(info)) 1807 if (!add_smi(info)) {
1808 if (try_smi_init(info)) 1808 if (try_smi_init(info))
1809 cleanup_one_si(info); 1809 cleanup_one_si(info);
1810 } else {
1811 kfree(info);
1812 }
1810 } else { 1813 } else {
1811 /* remove */ 1814 /* remove */
1812 struct smi_info *e, *tmp_e; 1815 struct smi_info *e, *tmp_e;
@@ -1890,9 +1893,12 @@ static __devinit void hardcode_find_bmc(void)
1890 info->irq_setup = std_irq_setup; 1893 info->irq_setup = std_irq_setup;
1891 info->slave_addr = slave_addrs[i]; 1894 info->slave_addr = slave_addrs[i];
1892 1895
1893 if (!add_smi(info)) 1896 if (!add_smi(info)) {
1894 if (try_smi_init(info)) 1897 if (try_smi_init(info))
1895 cleanup_one_si(info); 1898 cleanup_one_si(info);
1899 } else {
1900 kfree(info);
1901 }
1896 } 1902 }
1897} 1903}
1898 1904
@@ -1965,8 +1971,8 @@ static int acpi_gpe_irq_setup(struct smi_info *info)
1965 1971
1966/* 1972/*
1967 * Defined at 1973 * Defined at
1968 * http://h21007.www2.hp.com/dspp/files/unprotected/devresource/ 1974 * http://h21007.www2.hp.com/portal/download/files
1969 * Docs/TechPapers/IA64/hpspmi.pdf 1975 * /unprot/hpspmi.pdf
1970 */ 1976 */
1971struct SPMITable { 1977struct SPMITable {
1972 s8 Signature[4]; 1978 s8 Signature[4];
@@ -2013,18 +2019,12 @@ struct SPMITable {
2013static __devinit int try_init_spmi(struct SPMITable *spmi) 2019static __devinit int try_init_spmi(struct SPMITable *spmi)
2014{ 2020{
2015 struct smi_info *info; 2021 struct smi_info *info;
2016 u8 addr_space;
2017 2022
2018 if (spmi->IPMIlegacy != 1) { 2023 if (spmi->IPMIlegacy != 1) {
2019 printk(KERN_INFO PFX "Bad SPMI legacy %d\n", spmi->IPMIlegacy); 2024 printk(KERN_INFO PFX "Bad SPMI legacy %d\n", spmi->IPMIlegacy);
2020 return -ENODEV; 2025 return -ENODEV;
2021 } 2026 }
2022 2027
2023 if (spmi->addr.space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY)
2024 addr_space = IPMI_MEM_ADDR_SPACE;
2025 else
2026 addr_space = IPMI_IO_ADDR_SPACE;
2027
2028 info = kzalloc(sizeof(*info), GFP_KERNEL); 2028 info = kzalloc(sizeof(*info), GFP_KERNEL);
2029 if (!info) { 2029 if (!info) {
2030 printk(KERN_ERR PFX "Could not allocate SI data (3)\n"); 2030 printk(KERN_ERR PFX "Could not allocate SI data (3)\n");
@@ -2088,7 +2088,13 @@ static __devinit int try_init_spmi(struct SPMITable *spmi)
2088 } 2088 }
2089 info->io.addr_data = spmi->addr.address; 2089 info->io.addr_data = spmi->addr.address;
2090 2090
2091 add_smi(info); 2091 pr_info("ipmi_si: SPMI: %s %#lx regsize %d spacing %d irq %d\n",
2092 (info->io.addr_type == IPMI_IO_ADDR_SPACE) ? "io" : "mem",
2093 info->io.addr_data, info->io.regsize, info->io.regspacing,
2094 info->irq);
2095
2096 if (add_smi(info))
2097 kfree(info);
2092 2098
2093 return 0; 2099 return 0;
2094} 2100}
@@ -2176,6 +2182,14 @@ static int __devinit ipmi_pnp_probe(struct pnp_dev *dev,
2176 info->io.addr_data = res->start; 2182 info->io.addr_data = res->start;
2177 2183
2178 info->io.regspacing = DEFAULT_REGSPACING; 2184 info->io.regspacing = DEFAULT_REGSPACING;
2185 res = pnp_get_resource(dev,
2186 (info->io.addr_type == IPMI_IO_ADDR_SPACE) ?
2187 IORESOURCE_IO : IORESOURCE_MEM,
2188 1);
2189 if (res) {
2190 if (res->start > info->io.addr_data)
2191 info->io.regspacing = res->start - info->io.addr_data;
2192 }
2179 info->io.regsize = DEFAULT_REGSPACING; 2193 info->io.regsize = DEFAULT_REGSPACING;
2180 info->io.regshift = 0; 2194 info->io.regshift = 0;
2181 2195
@@ -2196,7 +2210,10 @@ static int __devinit ipmi_pnp_probe(struct pnp_dev *dev,
2196 res, info->io.regsize, info->io.regspacing, 2210 res, info->io.regsize, info->io.regspacing,
2197 info->irq); 2211 info->irq);
2198 2212
2199 return add_smi(info); 2213 if (add_smi(info))
2214 goto err_free;
2215
2216 return 0;
2200 2217
2201err_free: 2218err_free:
2202 kfree(info); 2219 kfree(info);
@@ -2354,7 +2371,13 @@ static __devinit void try_init_dmi(struct dmi_ipmi_data *ipmi_data)
2354 if (info->irq) 2371 if (info->irq)
2355 info->irq_setup = std_irq_setup; 2372 info->irq_setup = std_irq_setup;
2356 2373
2357 add_smi(info); 2374 pr_info("ipmi_si: SMBIOS: %s %#lx regsize %d spacing %d irq %d\n",
2375 (info->io.addr_type == IPMI_IO_ADDR_SPACE) ? "io" : "mem",
2376 info->io.addr_data, info->io.regsize, info->io.regspacing,
2377 info->irq);
2378
2379 if (add_smi(info))
2380 kfree(info);
2358} 2381}
2359 2382
2360static void __devinit dmi_find_bmc(void) 2383static void __devinit dmi_find_bmc(void)
@@ -2460,7 +2483,10 @@ static int __devinit ipmi_pci_probe(struct pci_dev *pdev,
2460 &pdev->resource[0], info->io.regsize, info->io.regspacing, 2483 &pdev->resource[0], info->io.regsize, info->io.regspacing,
2461 info->irq); 2484 info->irq);
2462 2485
2463 return add_smi(info); 2486 if (add_smi(info))
2487 kfree(info);
2488
2489 return 0;
2464} 2490}
2465 2491
2466static void __devexit ipmi_pci_remove(struct pci_dev *pdev) 2492static void __devexit ipmi_pci_remove(struct pci_dev *pdev)
@@ -2502,7 +2528,7 @@ static struct pci_driver ipmi_pci_driver = {
2502 2528
2503 2529
2504#ifdef CONFIG_PPC_OF 2530#ifdef CONFIG_PPC_OF
2505static int __devinit ipmi_of_probe(struct of_device *dev, 2531static int __devinit ipmi_of_probe(struct platform_device *dev,
2506 const struct of_device_id *match) 2532 const struct of_device_id *match)
2507{ 2533{
2508 struct smi_info *info; 2534 struct smi_info *info;
@@ -2573,10 +2599,15 @@ static int __devinit ipmi_of_probe(struct of_device *dev,
2573 2599
2574 dev_set_drvdata(&dev->dev, info); 2600 dev_set_drvdata(&dev->dev, info);
2575 2601
2576 return add_smi(info); 2602 if (add_smi(info)) {
2603 kfree(info);
2604 return -EBUSY;
2605 }
2606
2607 return 0;
2577} 2608}
2578 2609
2579static int __devexit ipmi_of_remove(struct of_device *dev) 2610static int __devexit ipmi_of_remove(struct platform_device *dev)
2580{ 2611{
2581 cleanup_one_si(dev_get_drvdata(&dev->dev)); 2612 cleanup_one_si(dev_get_drvdata(&dev->dev));
2582 return 0; 2613 return 0;
@@ -3006,6 +3037,8 @@ static __devinit void default_find_bmc(void)
3006 info->io.addr_data); 3037 info->io.addr_data);
3007 } else 3038 } else
3008 cleanup_one_si(info); 3039 cleanup_one_si(info);
3040 } else {
3041 kfree(info);
3009 } 3042 }
3010 } 3043 }
3011} 3044}
@@ -3033,7 +3066,7 @@ static int add_smi(struct smi_info *new_smi)
3033 si_to_str[new_smi->si_type]); 3066 si_to_str[new_smi->si_type]);
3034 mutex_lock(&smi_infos_lock); 3067 mutex_lock(&smi_infos_lock);
3035 if (!is_new_interface(new_smi)) { 3068 if (!is_new_interface(new_smi)) {
3036 printk(KERN_CONT PFX "duplicate interface\n"); 3069 printk(KERN_CONT " duplicate interface\n");
3037 rv = -EBUSY; 3070 rv = -EBUSY;
3038 goto out_err; 3071 goto out_err;
3039 } 3072 }
diff --git a/drivers/char/ipmi/ipmi_watchdog.c b/drivers/char/ipmi/ipmi_watchdog.c
index 82bcdb262a3a..654d566ca57c 100644
--- a/drivers/char/ipmi/ipmi_watchdog.c
+++ b/drivers/char/ipmi/ipmi_watchdog.c
@@ -196,7 +196,7 @@ static void ipmi_unregister_watchdog(int ipmi_intf);
196 */ 196 */
197static int start_now; 197static int start_now;
198 198
199static int set_param_int(const char *val, struct kernel_param *kp) 199static int set_param_timeout(const char *val, const struct kernel_param *kp)
200{ 200{
201 char *endp; 201 char *endp;
202 int l; 202 int l;
@@ -215,10 +215,11 @@ static int set_param_int(const char *val, struct kernel_param *kp)
215 return rv; 215 return rv;
216} 216}
217 217
218static int get_param_int(char *buffer, struct kernel_param *kp) 218static struct kernel_param_ops param_ops_timeout = {
219{ 219 .set = set_param_timeout,
220 return sprintf(buffer, "%i", *((int *)kp->arg)); 220 .get = param_get_int,
221} 221};
222#define param_check_timeout param_check_int
222 223
223typedef int (*action_fn)(const char *intval, char *outval); 224typedef int (*action_fn)(const char *intval, char *outval);
224 225
@@ -227,7 +228,7 @@ static int preaction_op(const char *inval, char *outval);
227static int preop_op(const char *inval, char *outval); 228static int preop_op(const char *inval, char *outval);
228static void check_parms(void); 229static void check_parms(void);
229 230
230static int set_param_str(const char *val, struct kernel_param *kp) 231static int set_param_str(const char *val, const struct kernel_param *kp)
231{ 232{
232 action_fn fn = (action_fn) kp->arg; 233 action_fn fn = (action_fn) kp->arg;
233 int rv = 0; 234 int rv = 0;
@@ -251,7 +252,7 @@ static int set_param_str(const char *val, struct kernel_param *kp)
251 return rv; 252 return rv;
252} 253}
253 254
254static int get_param_str(char *buffer, struct kernel_param *kp) 255static int get_param_str(char *buffer, const struct kernel_param *kp)
255{ 256{
256 action_fn fn = (action_fn) kp->arg; 257 action_fn fn = (action_fn) kp->arg;
257 int rv; 258 int rv;
@@ -263,7 +264,7 @@ static int get_param_str(char *buffer, struct kernel_param *kp)
263} 264}
264 265
265 266
266static int set_param_wdog_ifnum(const char *val, struct kernel_param *kp) 267static int set_param_wdog_ifnum(const char *val, const struct kernel_param *kp)
267{ 268{
268 int rv = param_set_int(val, kp); 269 int rv = param_set_int(val, kp);
269 if (rv) 270 if (rv)
@@ -276,27 +277,38 @@ static int set_param_wdog_ifnum(const char *val, struct kernel_param *kp)
276 return 0; 277 return 0;
277} 278}
278 279
279module_param_call(ifnum_to_use, set_param_wdog_ifnum, get_param_int, 280static struct kernel_param_ops param_ops_wdog_ifnum = {
280 &ifnum_to_use, 0644); 281 .set = set_param_wdog_ifnum,
282 .get = param_get_int,
283};
284
285#define param_check_wdog_ifnum param_check_int
286
287static struct kernel_param_ops param_ops_str = {
288 .set = set_param_str,
289 .get = get_param_str,
290};
291
292module_param(ifnum_to_use, wdog_ifnum, 0644);
281MODULE_PARM_DESC(ifnum_to_use, "The interface number to use for the watchdog " 293MODULE_PARM_DESC(ifnum_to_use, "The interface number to use for the watchdog "
282 "timer. Setting to -1 defaults to the first registered " 294 "timer. Setting to -1 defaults to the first registered "
283 "interface"); 295 "interface");
284 296
285module_param_call(timeout, set_param_int, get_param_int, &timeout, 0644); 297module_param(timeout, timeout, 0644);
286MODULE_PARM_DESC(timeout, "Timeout value in seconds."); 298MODULE_PARM_DESC(timeout, "Timeout value in seconds.");
287 299
288module_param_call(pretimeout, set_param_int, get_param_int, &pretimeout, 0644); 300module_param(pretimeout, timeout, 0644);
289MODULE_PARM_DESC(pretimeout, "Pretimeout value in seconds."); 301MODULE_PARM_DESC(pretimeout, "Pretimeout value in seconds.");
290 302
291module_param_call(action, set_param_str, get_param_str, action_op, 0644); 303module_param_cb(action, &param_ops_str, action_op, 0644);
292MODULE_PARM_DESC(action, "Timeout action. One of: " 304MODULE_PARM_DESC(action, "Timeout action. One of: "
293 "reset, none, power_cycle, power_off."); 305 "reset, none, power_cycle, power_off.");
294 306
295module_param_call(preaction, set_param_str, get_param_str, preaction_op, 0644); 307module_param_cb(preaction, &param_ops_str, preaction_op, 0644);
296MODULE_PARM_DESC(preaction, "Pretimeout action. One of: " 308MODULE_PARM_DESC(preaction, "Pretimeout action. One of: "
297 "pre_none, pre_smi, pre_nmi, pre_int."); 309 "pre_none, pre_smi, pre_nmi, pre_int.");
298 310
299module_param_call(preop, set_param_str, get_param_str, preop_op, 0644); 311module_param_cb(preop, &param_ops_str, preop_op, 0644);
300MODULE_PARM_DESC(preop, "Pretimeout driver operation. One of: " 312MODULE_PARM_DESC(preop, "Pretimeout driver operation. One of: "
301 "preop_none, preop_panic, preop_give_data."); 313 "preop_none, preop_panic, preop_give_data.");
302 314
diff --git a/drivers/char/isicom.c b/drivers/char/isicom.c
index 98310e1aae30..c27e9d21fea9 100644
--- a/drivers/char/isicom.c
+++ b/drivers/char/isicom.c
@@ -124,7 +124,6 @@
124#include <linux/fs.h> 124#include <linux/fs.h>
125#include <linux/sched.h> 125#include <linux/sched.h>
126#include <linux/serial.h> 126#include <linux/serial.h>
127#include <linux/smp_lock.h>
128#include <linux/mm.h> 127#include <linux/mm.h>
129#include <linux/interrupt.h> 128#include <linux/interrupt.h>
130#include <linux/timer.h> 129#include <linux/timer.h>
@@ -872,7 +871,6 @@ static struct tty_port *isicom_find_port(struct tty_struct *tty)
872static int isicom_open(struct tty_struct *tty, struct file *filp) 871static int isicom_open(struct tty_struct *tty, struct file *filp)
873{ 872{
874 struct isi_port *port; 873 struct isi_port *port;
875 struct isi_board *card;
876 struct tty_port *tport; 874 struct tty_port *tport;
877 875
878 tport = isicom_find_port(tty); 876 tport = isicom_find_port(tty);
@@ -1118,8 +1116,7 @@ static int isicom_set_serial_info(struct tty_struct *tty,
1118 if (copy_from_user(&newinfo, info, sizeof(newinfo))) 1116 if (copy_from_user(&newinfo, info, sizeof(newinfo)))
1119 return -EFAULT; 1117 return -EFAULT;
1120 1118
1121 lock_kernel(); 1119 mutex_lock(&port->port.mutex);
1122
1123 reconfig_port = ((port->port.flags & ASYNC_SPD_MASK) != 1120 reconfig_port = ((port->port.flags & ASYNC_SPD_MASK) !=
1124 (newinfo.flags & ASYNC_SPD_MASK)); 1121 (newinfo.flags & ASYNC_SPD_MASK));
1125 1122
@@ -1128,7 +1125,7 @@ static int isicom_set_serial_info(struct tty_struct *tty,
1128 (newinfo.closing_wait != port->port.closing_wait) || 1125 (newinfo.closing_wait != port->port.closing_wait) ||
1129 ((newinfo.flags & ~ASYNC_USR_MASK) != 1126 ((newinfo.flags & ~ASYNC_USR_MASK) !=
1130 (port->port.flags & ~ASYNC_USR_MASK))) { 1127 (port->port.flags & ~ASYNC_USR_MASK))) {
1131 unlock_kernel(); 1128 mutex_unlock(&port->port.mutex);
1132 return -EPERM; 1129 return -EPERM;
1133 } 1130 }
1134 port->port.flags = ((port->port.flags & ~ASYNC_USR_MASK) | 1131 port->port.flags = ((port->port.flags & ~ASYNC_USR_MASK) |
@@ -1145,7 +1142,7 @@ static int isicom_set_serial_info(struct tty_struct *tty,
1145 isicom_config_port(tty); 1142 isicom_config_port(tty);
1146 spin_unlock_irqrestore(&port->card->card_lock, flags); 1143 spin_unlock_irqrestore(&port->card->card_lock, flags);
1147 } 1144 }
1148 unlock_kernel(); 1145 mutex_unlock(&port->port.mutex);
1149 return 0; 1146 return 0;
1150} 1147}
1151 1148
@@ -1154,7 +1151,7 @@ static int isicom_get_serial_info(struct isi_port *port,
1154{ 1151{
1155 struct serial_struct out_info; 1152 struct serial_struct out_info;
1156 1153
1157 lock_kernel(); 1154 mutex_lock(&port->port.mutex);
1158 memset(&out_info, 0, sizeof(out_info)); 1155 memset(&out_info, 0, sizeof(out_info));
1159/* out_info.type = ? */ 1156/* out_info.type = ? */
1160 out_info.line = port - isi_ports; 1157 out_info.line = port - isi_ports;
@@ -1164,7 +1161,7 @@ static int isicom_get_serial_info(struct isi_port *port,
1164/* out_info.baud_base = ? */ 1161/* out_info.baud_base = ? */
1165 out_info.close_delay = port->port.close_delay; 1162 out_info.close_delay = port->port.close_delay;
1166 out_info.closing_wait = port->port.closing_wait; 1163 out_info.closing_wait = port->port.closing_wait;
1167 unlock_kernel(); 1164 mutex_unlock(&port->port.mutex);
1168 if (copy_to_user(info, &out_info, sizeof(out_info))) 1165 if (copy_to_user(info, &out_info, sizeof(out_info)))
1169 return -EFAULT; 1166 return -EFAULT;
1170 return 0; 1167 return 0;
diff --git a/drivers/char/istallion.c b/drivers/char/istallion.c
index 4e395c956a09..be28391adb79 100644
--- a/drivers/char/istallion.c
+++ b/drivers/char/istallion.c
@@ -203,9 +203,9 @@ static int stli_shared;
203 * the board has been detected, and whether it is actually running a slave 203 * the board has been detected, and whether it is actually running a slave
204 * or not. 204 * or not.
205 */ 205 */
206#define BST_FOUND 0x1 206#define BST_FOUND 0
207#define BST_STARTED 0x2 207#define BST_STARTED 1
208#define BST_PROBED 0x4 208#define BST_PROBED 2
209 209
210/* 210/*
211 * Define the set of port state flags. These are marked for internal 211 * Define the set of port state flags. These are marked for internal
@@ -816,7 +816,7 @@ static int stli_open(struct tty_struct *tty, struct file *filp)
816 brdp = stli_brds[brdnr]; 816 brdp = stli_brds[brdnr];
817 if (brdp == NULL) 817 if (brdp == NULL)
818 return -ENODEV; 818 return -ENODEV;
819 if ((brdp->state & BST_STARTED) == 0) 819 if (!test_bit(BST_STARTED, &brdp->state))
820 return -ENODEV; 820 return -ENODEV;
821 portnr = MINOR2PORT(minordev); 821 portnr = MINOR2PORT(minordev);
822 if (portnr > brdp->nrports) 822 if (portnr > brdp->nrports)
@@ -954,7 +954,7 @@ static int stli_rawopen(struct stlibrd *brdp, struct stliport *portp, unsigned l
954 * order of opens and closes may not be preserved across shared 954 * order of opens and closes may not be preserved across shared
955 * memory, so we must wait until it is complete. 955 * memory, so we must wait until it is complete.
956 */ 956 */
957 wait_event_interruptible(portp->raw_wait, 957 wait_event_interruptible_tty(portp->raw_wait,
958 !test_bit(ST_CLOSING, &portp->state)); 958 !test_bit(ST_CLOSING, &portp->state));
959 if (signal_pending(current)) { 959 if (signal_pending(current)) {
960 return -ERESTARTSYS; 960 return -ERESTARTSYS;
@@ -989,7 +989,7 @@ static int stli_rawopen(struct stlibrd *brdp, struct stliport *portp, unsigned l
989 set_bit(ST_OPENING, &portp->state); 989 set_bit(ST_OPENING, &portp->state);
990 spin_unlock_irqrestore(&brd_lock, flags); 990 spin_unlock_irqrestore(&brd_lock, flags);
991 991
992 wait_event_interruptible(portp->raw_wait, 992 wait_event_interruptible_tty(portp->raw_wait,
993 !test_bit(ST_OPENING, &portp->state)); 993 !test_bit(ST_OPENING, &portp->state));
994 if (signal_pending(current)) 994 if (signal_pending(current))
995 rc = -ERESTARTSYS; 995 rc = -ERESTARTSYS;
@@ -1020,7 +1020,7 @@ static int stli_rawclose(struct stlibrd *brdp, struct stliport *portp, unsigned
1020 * occurs on this port. 1020 * occurs on this port.
1021 */ 1021 */
1022 if (wait) { 1022 if (wait) {
1023 wait_event_interruptible(portp->raw_wait, 1023 wait_event_interruptible_tty(portp->raw_wait,
1024 !test_bit(ST_CLOSING, &portp->state)); 1024 !test_bit(ST_CLOSING, &portp->state));
1025 if (signal_pending(current)) { 1025 if (signal_pending(current)) {
1026 return -ERESTARTSYS; 1026 return -ERESTARTSYS;
@@ -1052,7 +1052,7 @@ static int stli_rawclose(struct stlibrd *brdp, struct stliport *portp, unsigned
1052 * to come back. 1052 * to come back.
1053 */ 1053 */
1054 rc = 0; 1054 rc = 0;
1055 wait_event_interruptible(portp->raw_wait, 1055 wait_event_interruptible_tty(portp->raw_wait,
1056 !test_bit(ST_CLOSING, &portp->state)); 1056 !test_bit(ST_CLOSING, &portp->state));
1057 if (signal_pending(current)) 1057 if (signal_pending(current))
1058 rc = -ERESTARTSYS; 1058 rc = -ERESTARTSYS;
@@ -1073,6 +1073,10 @@ static int stli_rawclose(struct stlibrd *brdp, struct stliport *portp, unsigned
1073 1073
1074static int stli_cmdwait(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback) 1074static int stli_cmdwait(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback)
1075{ 1075{
1076 /*
1077 * no need for wait_event_tty because clearing ST_CMDING cannot block
1078 * on BTM
1079 */
1076 wait_event_interruptible(portp->raw_wait, 1080 wait_event_interruptible(portp->raw_wait,
1077 !test_bit(ST_CMDING, &portp->state)); 1081 !test_bit(ST_CMDING, &portp->state));
1078 if (signal_pending(current)) 1082 if (signal_pending(current))
@@ -1846,7 +1850,7 @@ static void stli_portinfo(struct seq_file *m, struct stlibrd *brdp, struct stlip
1846 rc = stli_portcmdstats(NULL, portp); 1850 rc = stli_portcmdstats(NULL, portp);
1847 1851
1848 uart = "UNKNOWN"; 1852 uart = "UNKNOWN";
1849 if (brdp->state & BST_STARTED) { 1853 if (test_bit(BST_STARTED, &brdp->state)) {
1850 switch (stli_comstats.hwid) { 1854 switch (stli_comstats.hwid) {
1851 case 0: uart = "2681"; break; 1855 case 0: uart = "2681"; break;
1852 case 1: uart = "SC26198"; break; 1856 case 1: uart = "SC26198"; break;
@@ -1855,7 +1859,7 @@ static void stli_portinfo(struct seq_file *m, struct stlibrd *brdp, struct stlip
1855 } 1859 }
1856 seq_printf(m, "%d: uart:%s ", portnr, uart); 1860 seq_printf(m, "%d: uart:%s ", portnr, uart);
1857 1861
1858 if ((brdp->state & BST_STARTED) && (rc >= 0)) { 1862 if (test_bit(BST_STARTED, &brdp->state) && rc >= 0) {
1859 char sep; 1863 char sep;
1860 1864
1861 seq_printf(m, "tx:%d rx:%d", (int) stli_comstats.txtotal, 1865 seq_printf(m, "tx:%d rx:%d", (int) stli_comstats.txtotal,
@@ -2355,7 +2359,7 @@ static void stli_poll(unsigned long arg)
2355 brdp = stli_brds[brdnr]; 2359 brdp = stli_brds[brdnr];
2356 if (brdp == NULL) 2360 if (brdp == NULL)
2357 continue; 2361 continue;
2358 if ((brdp->state & BST_STARTED) == 0) 2362 if (!test_bit(BST_STARTED, &brdp->state))
2359 continue; 2363 continue;
2360 2364
2361 spin_lock(&brd_lock); 2365 spin_lock(&brd_lock);
@@ -3140,7 +3144,7 @@ static int stli_initecp(struct stlibrd *brdp)
3140 } 3144 }
3141 3145
3142 3146
3143 brdp->state |= BST_FOUND; 3147 set_bit(BST_FOUND, &brdp->state);
3144 return 0; 3148 return 0;
3145err_unmap: 3149err_unmap:
3146 iounmap(brdp->membase); 3150 iounmap(brdp->membase);
@@ -3297,7 +3301,7 @@ static int stli_initonb(struct stlibrd *brdp)
3297 brdp->panels[0] = brdp->nrports; 3301 brdp->panels[0] = brdp->nrports;
3298 3302
3299 3303
3300 brdp->state |= BST_FOUND; 3304 set_bit(BST_FOUND, &brdp->state);
3301 return 0; 3305 return 0;
3302err_unmap: 3306err_unmap:
3303 iounmap(brdp->membase); 3307 iounmap(brdp->membase);
@@ -3407,7 +3411,7 @@ stli_donestartup:
3407 spin_unlock_irqrestore(&brd_lock, flags); 3411 spin_unlock_irqrestore(&brd_lock, flags);
3408 3412
3409 if (rc == 0) 3413 if (rc == 0)
3410 brdp->state |= BST_STARTED; 3414 set_bit(BST_STARTED, &brdp->state);
3411 3415
3412 if (! stli_timeron) { 3416 if (! stli_timeron) {
3413 stli_timeron++; 3417 stli_timeron++;
@@ -3710,7 +3714,7 @@ static int __devinit stli_pciprobe(struct pci_dev *pdev,
3710 if (retval) 3714 if (retval)
3711 goto err_null; 3715 goto err_null;
3712 3716
3713 brdp->state |= BST_PROBED; 3717 set_bit(BST_PROBED, &brdp->state);
3714 pci_set_drvdata(pdev, brdp); 3718 pci_set_drvdata(pdev, brdp);
3715 3719
3716 EBRDENABLE(brdp); 3720 EBRDENABLE(brdp);
@@ -3841,7 +3845,7 @@ static int __init stli_initbrds(void)
3841 brdp = stli_brds[i]; 3845 brdp = stli_brds[i];
3842 if (brdp == NULL) 3846 if (brdp == NULL)
3843 continue; 3847 continue;
3844 if (brdp->state & BST_FOUND) { 3848 if (test_bit(BST_FOUND, &brdp->state)) {
3845 EBRDENABLE(brdp); 3849 EBRDENABLE(brdp);
3846 brdp->enable = NULL; 3850 brdp->enable = NULL;
3847 brdp->disable = NULL; 3851 brdp->disable = NULL;
@@ -4011,6 +4015,7 @@ static int stli_getbrdstats(combrd_t __user *bp)
4011 return -ENODEV; 4015 return -ENODEV;
4012 4016
4013 memset(&stli_brdstats, 0, sizeof(combrd_t)); 4017 memset(&stli_brdstats, 0, sizeof(combrd_t));
4018
4014 stli_brdstats.brd = brdp->brdnr; 4019 stli_brdstats.brd = brdp->brdnr;
4015 stli_brdstats.type = brdp->brdtype; 4020 stli_brdstats.type = brdp->brdtype;
4016 stli_brdstats.hwid = 0; 4021 stli_brdstats.hwid = 0;
@@ -4076,10 +4081,13 @@ static int stli_portcmdstats(struct tty_struct *tty, struct stliport *portp)
4076 if (brdp == NULL) 4081 if (brdp == NULL)
4077 return -ENODEV; 4082 return -ENODEV;
4078 4083
4079 if (brdp->state & BST_STARTED) { 4084 mutex_lock(&portp->port.mutex);
4085 if (test_bit(BST_STARTED, &brdp->state)) {
4080 if ((rc = stli_cmdwait(brdp, portp, A_GETSTATS, 4086 if ((rc = stli_cmdwait(brdp, portp, A_GETSTATS,
4081 &stli_cdkstats, sizeof(asystats_t), 1)) < 0) 4087 &stli_cdkstats, sizeof(asystats_t), 1)) < 0) {
4088 mutex_unlock(&portp->port.mutex);
4082 return rc; 4089 return rc;
4090 }
4083 } else { 4091 } else {
4084 memset(&stli_cdkstats, 0, sizeof(asystats_t)); 4092 memset(&stli_cdkstats, 0, sizeof(asystats_t));
4085 } 4093 }
@@ -4124,6 +4132,7 @@ static int stli_portcmdstats(struct tty_struct *tty, struct stliport *portp)
4124 stli_comstats.modem = stli_cdkstats.dcdcnt; 4132 stli_comstats.modem = stli_cdkstats.dcdcnt;
4125 stli_comstats.hwid = stli_cdkstats.hwid; 4133 stli_comstats.hwid = stli_cdkstats.hwid;
4126 stli_comstats.signals = stli_mktiocm(stli_cdkstats.signals); 4134 stli_comstats.signals = stli_mktiocm(stli_cdkstats.signals);
4135 mutex_unlock(&portp->port.mutex);
4127 4136
4128 return 0; 4137 return 0;
4129} 4138}
@@ -4186,15 +4195,20 @@ static int stli_clrportstats(struct stliport *portp, comstats_t __user *cp)
4186 if (!brdp) 4195 if (!brdp)
4187 return -ENODEV; 4196 return -ENODEV;
4188 4197
4189 if (brdp->state & BST_STARTED) { 4198 mutex_lock(&portp->port.mutex);
4190 if ((rc = stli_cmdwait(brdp, portp, A_CLEARSTATS, NULL, 0, 0)) < 0) 4199
4200 if (test_bit(BST_STARTED, &brdp->state)) {
4201 if ((rc = stli_cmdwait(brdp, portp, A_CLEARSTATS, NULL, 0, 0)) < 0) {
4202 mutex_unlock(&portp->port.mutex);
4191 return rc; 4203 return rc;
4204 }
4192 } 4205 }
4193 4206
4194 memset(&stli_comstats, 0, sizeof(comstats_t)); 4207 memset(&stli_comstats, 0, sizeof(comstats_t));
4195 stli_comstats.brd = portp->brdnr; 4208 stli_comstats.brd = portp->brdnr;
4196 stli_comstats.panel = portp->panelnr; 4209 stli_comstats.panel = portp->panelnr;
4197 stli_comstats.port = portp->portnr; 4210 stli_comstats.port = portp->portnr;
4211 mutex_unlock(&portp->port.mutex);
4198 4212
4199 if (copy_to_user(cp, &stli_comstats, sizeof(comstats_t))) 4213 if (copy_to_user(cp, &stli_comstats, sizeof(comstats_t)))
4200 return -EFAULT; 4214 return -EFAULT;
@@ -4266,8 +4280,6 @@ static long stli_memioctl(struct file *fp, unsigned int cmd, unsigned long arg)
4266 done = 0; 4280 done = 0;
4267 rc = 0; 4281 rc = 0;
4268 4282
4269 lock_kernel();
4270
4271 switch (cmd) { 4283 switch (cmd) {
4272 case COM_GETPORTSTATS: 4284 case COM_GETPORTSTATS:
4273 rc = stli_getportstats(NULL, NULL, argp); 4285 rc = stli_getportstats(NULL, NULL, argp);
@@ -4290,8 +4302,6 @@ static long stli_memioctl(struct file *fp, unsigned int cmd, unsigned long arg)
4290 done++; 4302 done++;
4291 break; 4303 break;
4292 } 4304 }
4293 unlock_kernel();
4294
4295 if (done) 4305 if (done)
4296 return rc; 4306 return rc;
4297 4307
@@ -4308,8 +4318,6 @@ static long stli_memioctl(struct file *fp, unsigned int cmd, unsigned long arg)
4308 if (brdp->state == 0) 4318 if (brdp->state == 0)
4309 return -ENODEV; 4319 return -ENODEV;
4310 4320
4311 lock_kernel();
4312
4313 switch (cmd) { 4321 switch (cmd) {
4314 case STL_BINTR: 4322 case STL_BINTR:
4315 EBRDINTR(brdp); 4323 EBRDINTR(brdp);
@@ -4318,10 +4326,10 @@ static long stli_memioctl(struct file *fp, unsigned int cmd, unsigned long arg)
4318 rc = stli_startbrd(brdp); 4326 rc = stli_startbrd(brdp);
4319 break; 4327 break;
4320 case STL_BSTOP: 4328 case STL_BSTOP:
4321 brdp->state &= ~BST_STARTED; 4329 clear_bit(BST_STARTED, &brdp->state);
4322 break; 4330 break;
4323 case STL_BRESET: 4331 case STL_BRESET:
4324 brdp->state &= ~BST_STARTED; 4332 clear_bit(BST_STARTED, &brdp->state);
4325 EBRDRESET(brdp); 4333 EBRDRESET(brdp);
4326 if (stli_shared == 0) { 4334 if (stli_shared == 0) {
4327 if (brdp->reenable != NULL) 4335 if (brdp->reenable != NULL)
@@ -4332,7 +4340,6 @@ static long stli_memioctl(struct file *fp, unsigned int cmd, unsigned long arg)
4332 rc = -ENOIOCTLCMD; 4340 rc = -ENOIOCTLCMD;
4333 break; 4341 break;
4334 } 4342 }
4335 unlock_kernel();
4336 return rc; 4343 return rc;
4337} 4344}
4338 4345
@@ -4378,7 +4385,8 @@ static void istallion_cleanup_isa(void)
4378 unsigned int j; 4385 unsigned int j;
4379 4386
4380 for (j = 0; (j < stli_nrbrds); j++) { 4387 for (j = 0; (j < stli_nrbrds); j++) {
4381 if ((brdp = stli_brds[j]) == NULL || (brdp->state & BST_PROBED)) 4388 if ((brdp = stli_brds[j]) == NULL ||
4389 test_bit(BST_PROBED, &brdp->state))
4382 continue; 4390 continue;
4383 4391
4384 stli_cleanup_ports(brdp); 4392 stli_cleanup_ports(brdp);
diff --git a/drivers/char/keyboard.c b/drivers/char/keyboard.c
index 25be2102a60a..a7ca75212bfe 100644
--- a/drivers/char/keyboard.c
+++ b/drivers/char/keyboard.c
@@ -299,7 +299,7 @@ int kbd_rate(struct kbd_repeat *rep)
299 */ 299 */
300static void put_queue(struct vc_data *vc, int ch) 300static void put_queue(struct vc_data *vc, int ch)
301{ 301{
302 struct tty_struct *tty = vc->vc_tty; 302 struct tty_struct *tty = vc->port.tty;
303 303
304 if (tty) { 304 if (tty) {
305 tty_insert_flip_char(tty, ch, 0); 305 tty_insert_flip_char(tty, ch, 0);
@@ -309,7 +309,7 @@ static void put_queue(struct vc_data *vc, int ch)
309 309
310static void puts_queue(struct vc_data *vc, char *cp) 310static void puts_queue(struct vc_data *vc, char *cp)
311{ 311{
312 struct tty_struct *tty = vc->vc_tty; 312 struct tty_struct *tty = vc->port.tty;
313 313
314 if (!tty) 314 if (!tty)
315 return; 315 return;
@@ -485,7 +485,7 @@ static void fn_show_ptregs(struct vc_data *vc)
485 485
486static void fn_hold(struct vc_data *vc) 486static void fn_hold(struct vc_data *vc)
487{ 487{
488 struct tty_struct *tty = vc->vc_tty; 488 struct tty_struct *tty = vc->port.tty;
489 489
490 if (rep || !tty) 490 if (rep || !tty)
491 return; 491 return;
@@ -563,7 +563,7 @@ static void fn_inc_console(struct vc_data *vc)
563 563
564static void fn_send_intr(struct vc_data *vc) 564static void fn_send_intr(struct vc_data *vc)
565{ 565{
566 struct tty_struct *tty = vc->vc_tty; 566 struct tty_struct *tty = vc->port.tty;
567 567
568 if (!tty) 568 if (!tty)
569 return; 569 return;
@@ -1162,7 +1162,7 @@ static void kbd_keycode(unsigned int keycode, int down, int hw_raw)
1162 struct keyboard_notifier_param param = { .vc = vc, .value = keycode, .down = down }; 1162 struct keyboard_notifier_param param = { .vc = vc, .value = keycode, .down = down };
1163 int rc; 1163 int rc;
1164 1164
1165 tty = vc->vc_tty; 1165 tty = vc->port.tty;
1166 1166
1167 if (tty && (!tty->driver_data)) { 1167 if (tty && (!tty->driver_data)) {
1168 /* No driver data? Strange. Okay we fix it then. */ 1168 /* No driver data? Strange. Okay we fix it then. */
diff --git a/drivers/char/misc.c b/drivers/char/misc.c
index cd650ca8c679..abdafd488980 100644
--- a/drivers/char/misc.c
+++ b/drivers/char/misc.c
@@ -242,7 +242,7 @@ int misc_deregister(struct miscdevice *misc)
242{ 242{
243 int i = DYNAMIC_MINORS - misc->minor - 1; 243 int i = DYNAMIC_MINORS - misc->minor - 1;
244 244
245 if (list_empty(&misc->list)) 245 if (WARN_ON(list_empty(&misc->list)))
246 return -EINVAL; 246 return -EINVAL;
247 247
248 mutex_lock(&misc_mtx); 248 mutex_lock(&misc_mtx);
diff --git a/drivers/char/mxser.c b/drivers/char/mxser.c
index d2692d443f7b..3fc89da856ae 100644
--- a/drivers/char/mxser.c
+++ b/drivers/char/mxser.c
@@ -2193,7 +2193,7 @@ static void mxser_transmit_chars(struct tty_struct *tty, struct mxser_port *port
2193 port->mon_data.up_txcnt += (cnt - port->xmit_cnt); 2193 port->mon_data.up_txcnt += (cnt - port->xmit_cnt);
2194 port->icount.tx += (cnt - port->xmit_cnt); 2194 port->icount.tx += (cnt - port->xmit_cnt);
2195 2195
2196 if (port->xmit_cnt < WAKEUP_CHARS && tty) 2196 if (port->xmit_cnt < WAKEUP_CHARS)
2197 tty_wakeup(tty); 2197 tty_wakeup(tty);
2198 2198
2199 if (port->xmit_cnt <= 0) { 2199 if (port->xmit_cnt <= 0) {
diff --git a/drivers/char/n_gsm.c b/drivers/char/n_gsm.c
index e4089c432f15..04ef3ef0a422 100644
--- a/drivers/char/n_gsm.c
+++ b/drivers/char/n_gsm.c
@@ -43,7 +43,6 @@
43#include <linux/sched.h> 43#include <linux/sched.h>
44#include <linux/interrupt.h> 44#include <linux/interrupt.h>
45#include <linux/tty.h> 45#include <linux/tty.h>
46#include <linux/timer.h>
47#include <linux/ctype.h> 46#include <linux/ctype.h>
48#include <linux/mm.h> 47#include <linux/mm.h>
49#include <linux/string.h> 48#include <linux/string.h>
@@ -920,7 +919,7 @@ static void gsm_dlci_data_sweep(struct gsm_mux *gsm)
920 else 919 else
921 len = gsm_dlci_data_output_framed(gsm, dlci); 920 len = gsm_dlci_data_output_framed(gsm, dlci);
922 if (len < 0) 921 if (len < 0)
923 return; 922 break;
924 /* DLCI empty - try the next */ 923 /* DLCI empty - try the next */
925 if (len == 0) 924 if (len == 0)
926 i++; 925 i++;
diff --git a/drivers/char/n_hdlc.c b/drivers/char/n_hdlc.c
index c68118efad84..47d32281032c 100644
--- a/drivers/char/n_hdlc.c
+++ b/drivers/char/n_hdlc.c
@@ -598,18 +598,18 @@ static ssize_t n_hdlc_tty_read(struct tty_struct *tty, struct file *file,
598 return -EFAULT; 598 return -EFAULT;
599 } 599 }
600 600
601 lock_kernel(); 601 tty_lock();
602 602
603 for (;;) { 603 for (;;) {
604 if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) { 604 if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) {
605 unlock_kernel(); 605 tty_unlock();
606 return -EIO; 606 return -EIO;
607 } 607 }
608 608
609 n_hdlc = tty2n_hdlc (tty); 609 n_hdlc = tty2n_hdlc (tty);
610 if (!n_hdlc || n_hdlc->magic != HDLC_MAGIC || 610 if (!n_hdlc || n_hdlc->magic != HDLC_MAGIC ||
611 tty != n_hdlc->tty) { 611 tty != n_hdlc->tty) {
612 unlock_kernel(); 612 tty_unlock();
613 return 0; 613 return 0;
614 } 614 }
615 615
@@ -619,13 +619,13 @@ static ssize_t n_hdlc_tty_read(struct tty_struct *tty, struct file *file,
619 619
620 /* no data */ 620 /* no data */
621 if (file->f_flags & O_NONBLOCK) { 621 if (file->f_flags & O_NONBLOCK) {
622 unlock_kernel(); 622 tty_unlock();
623 return -EAGAIN; 623 return -EAGAIN;
624 } 624 }
625 625
626 interruptible_sleep_on (&tty->read_wait); 626 interruptible_sleep_on (&tty->read_wait);
627 if (signal_pending(current)) { 627 if (signal_pending(current)) {
628 unlock_kernel(); 628 tty_unlock();
629 return -EINTR; 629 return -EINTR;
630 } 630 }
631 } 631 }
@@ -648,7 +648,7 @@ static ssize_t n_hdlc_tty_read(struct tty_struct *tty, struct file *file,
648 kfree(rbuf); 648 kfree(rbuf);
649 else 649 else
650 n_hdlc_buf_put(&n_hdlc->rx_free_buf_list,rbuf); 650 n_hdlc_buf_put(&n_hdlc->rx_free_buf_list,rbuf);
651 unlock_kernel(); 651 tty_unlock();
652 return ret; 652 return ret;
653 653
654} /* end of n_hdlc_tty_read() */ 654} /* end of n_hdlc_tty_read() */
@@ -691,7 +691,7 @@ static ssize_t n_hdlc_tty_write(struct tty_struct *tty, struct file *file,
691 count = maxframe; 691 count = maxframe;
692 } 692 }
693 693
694 lock_kernel(); 694 tty_lock();
695 695
696 add_wait_queue(&tty->write_wait, &wait); 696 add_wait_queue(&tty->write_wait, &wait);
697 set_current_state(TASK_INTERRUPTIBLE); 697 set_current_state(TASK_INTERRUPTIBLE);
@@ -731,7 +731,7 @@ static ssize_t n_hdlc_tty_write(struct tty_struct *tty, struct file *file,
731 n_hdlc_buf_put(&n_hdlc->tx_buf_list,tbuf); 731 n_hdlc_buf_put(&n_hdlc->tx_buf_list,tbuf);
732 n_hdlc_send_frames(n_hdlc,tty); 732 n_hdlc_send_frames(n_hdlc,tty);
733 } 733 }
734 unlock_kernel(); 734 tty_unlock();
735 return error; 735 return error;
736 736
737} /* end of n_hdlc_tty_write() */ 737} /* end of n_hdlc_tty_write() */
diff --git a/drivers/char/n_r3964.c b/drivers/char/n_r3964.c
index c1d8b54c816d..a98290d7a2c5 100644
--- a/drivers/char/n_r3964.c
+++ b/drivers/char/n_r3964.c
@@ -1067,7 +1067,7 @@ static ssize_t r3964_read(struct tty_struct *tty, struct file *file,
1067 1067
1068 TRACE_L("read()"); 1068 TRACE_L("read()");
1069 1069
1070 lock_kernel(); 1070 tty_lock();
1071 1071
1072 pClient = findClient(pInfo, task_pid(current)); 1072 pClient = findClient(pInfo, task_pid(current));
1073 if (pClient) { 1073 if (pClient) {
@@ -1079,7 +1079,7 @@ static ssize_t r3964_read(struct tty_struct *tty, struct file *file,
1079 goto unlock; 1079 goto unlock;
1080 } 1080 }
1081 /* block until there is a message: */ 1081 /* block until there is a message: */
1082 wait_event_interruptible(pInfo->read_wait, 1082 wait_event_interruptible_tty(pInfo->read_wait,
1083 (pMsg = remove_msg(pInfo, pClient))); 1083 (pMsg = remove_msg(pInfo, pClient)));
1084 } 1084 }
1085 1085
@@ -1109,7 +1109,7 @@ static ssize_t r3964_read(struct tty_struct *tty, struct file *file,
1109 } 1109 }
1110 ret = -EPERM; 1110 ret = -EPERM;
1111unlock: 1111unlock:
1112 unlock_kernel(); 1112 tty_unlock();
1113 return ret; 1113 return ret;
1114} 1114}
1115 1115
@@ -1158,7 +1158,7 @@ static ssize_t r3964_write(struct tty_struct *tty, struct file *file,
1158 pHeader->locks = 0; 1158 pHeader->locks = 0;
1159 pHeader->owner = NULL; 1159 pHeader->owner = NULL;
1160 1160
1161 lock_kernel(); 1161 tty_lock();
1162 1162
1163 pClient = findClient(pInfo, task_pid(current)); 1163 pClient = findClient(pInfo, task_pid(current));
1164 if (pClient) { 1164 if (pClient) {
@@ -1177,7 +1177,7 @@ static ssize_t r3964_write(struct tty_struct *tty, struct file *file,
1177 add_tx_queue(pInfo, pHeader); 1177 add_tx_queue(pInfo, pHeader);
1178 trigger_transmit(pInfo); 1178 trigger_transmit(pInfo);
1179 1179
1180 unlock_kernel(); 1180 tty_unlock();
1181 1181
1182 return 0; 1182 return 0;
1183} 1183}
diff --git a/drivers/char/n_tty.c b/drivers/char/n_tty.c
index bdae8327143c..428f4fe0b5f7 100644
--- a/drivers/char/n_tty.c
+++ b/drivers/char/n_tty.c
@@ -1102,6 +1102,11 @@ static inline void n_tty_receive_char(struct tty_struct *tty, unsigned char c)
1102 if (I_IUCLC(tty) && L_IEXTEN(tty)) 1102 if (I_IUCLC(tty) && L_IEXTEN(tty))
1103 c = tolower(c); 1103 c = tolower(c);
1104 1104
1105 if (L_EXTPROC(tty)) {
1106 put_tty_queue(c, tty);
1107 return;
1108 }
1109
1105 if (tty->stopped && !tty->flow_stopped && I_IXON(tty) && 1110 if (tty->stopped && !tty->flow_stopped && I_IXON(tty) &&
1106 I_IXANY(tty) && c != START_CHAR(tty) && c != STOP_CHAR(tty) && 1111 I_IXANY(tty) && c != START_CHAR(tty) && c != STOP_CHAR(tty) &&
1107 c != INTR_CHAR(tty) && c != QUIT_CHAR(tty) && c != SUSP_CHAR(tty)) { 1112 c != INTR_CHAR(tty) && c != QUIT_CHAR(tty) && c != SUSP_CHAR(tty)) {
@@ -1409,7 +1414,8 @@ static void n_tty_receive_buf(struct tty_struct *tty, const unsigned char *cp,
1409 1414
1410 n_tty_set_room(tty); 1415 n_tty_set_room(tty);
1411 1416
1412 if (!tty->icanon && (tty->read_cnt >= tty->minimum_to_wake)) { 1417 if ((!tty->icanon && (tty->read_cnt >= tty->minimum_to_wake)) ||
1418 L_EXTPROC(tty)) {
1413 kill_fasync(&tty->fasync, SIGIO, POLL_IN); 1419 kill_fasync(&tty->fasync, SIGIO, POLL_IN);
1414 if (waitqueue_active(&tty->read_wait)) 1420 if (waitqueue_active(&tty->read_wait))
1415 wake_up_interruptible(&tty->read_wait); 1421 wake_up_interruptible(&tty->read_wait);
@@ -1585,7 +1591,7 @@ static int n_tty_open(struct tty_struct *tty)
1585static inline int input_available_p(struct tty_struct *tty, int amt) 1591static inline int input_available_p(struct tty_struct *tty, int amt)
1586{ 1592{
1587 tty_flush_to_ldisc(tty); 1593 tty_flush_to_ldisc(tty);
1588 if (tty->icanon) { 1594 if (tty->icanon && !L_EXTPROC(tty)) {
1589 if (tty->canon_data) 1595 if (tty->canon_data)
1590 return 1; 1596 return 1;
1591 } else if (tty->read_cnt >= (amt ? amt : 1)) 1597 } else if (tty->read_cnt >= (amt ? amt : 1))
@@ -1632,6 +1638,11 @@ static int copy_from_read_buf(struct tty_struct *tty,
1632 spin_lock_irqsave(&tty->read_lock, flags); 1638 spin_lock_irqsave(&tty->read_lock, flags);
1633 tty->read_tail = (tty->read_tail + n) & (N_TTY_BUF_SIZE-1); 1639 tty->read_tail = (tty->read_tail + n) & (N_TTY_BUF_SIZE-1);
1634 tty->read_cnt -= n; 1640 tty->read_cnt -= n;
1641 /* Turn single EOF into zero-length read */
1642 if (L_EXTPROC(tty) && tty->icanon && n == 1) {
1643 if (!tty->read_cnt && (*b)[n-1] == EOF_CHAR(tty))
1644 n--;
1645 }
1635 spin_unlock_irqrestore(&tty->read_lock, flags); 1646 spin_unlock_irqrestore(&tty->read_lock, flags);
1636 *b += n; 1647 *b += n;
1637 *nr -= n; 1648 *nr -= n;
@@ -1812,7 +1823,7 @@ do_it_again:
1812 nr--; 1823 nr--;
1813 } 1824 }
1814 1825
1815 if (tty->icanon) { 1826 if (tty->icanon && !L_EXTPROC(tty)) {
1816 /* N.B. avoid overrun if nr == 0 */ 1827 /* N.B. avoid overrun if nr == 0 */
1817 while (nr && tty->read_cnt) { 1828 while (nr && tty->read_cnt) {
1818 int eol; 1829 int eol;
diff --git a/drivers/char/nozomi.c b/drivers/char/nozomi.c
index a6638003f530..817169cbb245 100644
--- a/drivers/char/nozomi.c
+++ b/drivers/char/nozomi.c
@@ -1611,6 +1611,8 @@ static int ntty_install(struct tty_driver *driver, struct tty_struct *tty)
1611 ret = tty_init_termios(tty); 1611 ret = tty_init_termios(tty);
1612 if (ret == 0) { 1612 if (ret == 0) {
1613 tty_driver_kref_get(driver); 1613 tty_driver_kref_get(driver);
1614 tty->count++;
1615 tty->driver_data = port;
1614 driver->ttys[tty->index] = tty; 1616 driver->ttys[tty->index] = tty;
1615 } 1617 }
1616 return ret; 1618 return ret;
@@ -1639,7 +1641,7 @@ static int ntty_activate(struct tty_port *tport, struct tty_struct *tty)
1639 1641
1640static int ntty_open(struct tty_struct *tty, struct file *filp) 1642static int ntty_open(struct tty_struct *tty, struct file *filp)
1641{ 1643{
1642 struct port *port = get_port_by_tty(tty); 1644 struct port *port = tty->driver_data;
1643 return tty_port_open(&port->port, tty, filp); 1645 return tty_port_open(&port->port, tty, filp);
1644} 1646}
1645 1647
@@ -1741,8 +1743,7 @@ static int ntty_write_room(struct tty_struct *tty)
1741 if (dc) { 1743 if (dc) {
1742 mutex_lock(&port->tty_sem); 1744 mutex_lock(&port->tty_sem);
1743 if (port->port.count) 1745 if (port->port.count)
1744 room = port->fifo_ul.size - 1746 room = kfifo_avail(&port->fifo_ul);
1745 kfifo_len(&port->fifo_ul);
1746 mutex_unlock(&port->tty_sem); 1747 mutex_unlock(&port->tty_sem);
1747 } 1748 }
1748 return room; 1749 return room;
diff --git a/drivers/char/pcmcia/ipwireless/network.c b/drivers/char/pcmcia/ipwireless/network.c
index 65920163f53d..9fe538347932 100644
--- a/drivers/char/pcmcia/ipwireless/network.c
+++ b/drivers/char/pcmcia/ipwireless/network.c
@@ -239,7 +239,7 @@ static int ipwireless_ppp_ioctl(struct ppp_channel *ppp_channel,
239 return err; 239 return err;
240} 240}
241 241
242static struct ppp_channel_ops ipwireless_ppp_channel_ops = { 242static const struct ppp_channel_ops ipwireless_ppp_channel_ops = {
243 .start_xmit = ipwireless_ppp_start_xmit, 243 .start_xmit = ipwireless_ppp_start_xmit,
244 .ioctl = ipwireless_ppp_ioctl 244 .ioctl = ipwireless_ppp_ioctl
245}; 245};
diff --git a/drivers/char/pty.c b/drivers/char/pty.c
index d83a43130df4..ad46eae1f9bb 100644
--- a/drivers/char/pty.c
+++ b/drivers/char/pty.c
@@ -62,7 +62,9 @@ static void pty_close(struct tty_struct *tty, struct file *filp)
62 if (tty->driver == ptm_driver) 62 if (tty->driver == ptm_driver)
63 devpts_pty_kill(tty->link); 63 devpts_pty_kill(tty->link);
64#endif 64#endif
65 tty_unlock();
65 tty_vhangup(tty->link); 66 tty_vhangup(tty->link);
67 tty_lock();
66 } 68 }
67} 69}
68 70
@@ -171,6 +173,23 @@ static int pty_set_lock(struct tty_struct *tty, int __user *arg)
171 return 0; 173 return 0;
172} 174}
173 175
176/* Send a signal to the slave */
177static int pty_signal(struct tty_struct *tty, int sig)
178{
179 unsigned long flags;
180 struct pid *pgrp;
181
182 if (tty->link) {
183 spin_lock_irqsave(&tty->link->ctrl_lock, flags);
184 pgrp = get_pid(tty->link->pgrp);
185 spin_unlock_irqrestore(&tty->link->ctrl_lock, flags);
186
187 kill_pgrp(pgrp, sig, 1);
188 put_pid(pgrp);
189 }
190 return 0;
191}
192
174static void pty_flush_buffer(struct tty_struct *tty) 193static void pty_flush_buffer(struct tty_struct *tty)
175{ 194{
176 struct tty_struct *to = tty->link; 195 struct tty_struct *to = tty->link;
@@ -321,6 +340,8 @@ static int pty_bsd_ioctl(struct tty_struct *tty, struct file *file,
321 switch (cmd) { 340 switch (cmd) {
322 case TIOCSPTLCK: /* Set PT Lock (disallow slave open) */ 341 case TIOCSPTLCK: /* Set PT Lock (disallow slave open) */
323 return pty_set_lock(tty, (int __user *) arg); 342 return pty_set_lock(tty, (int __user *) arg);
343 case TIOCSIG: /* Send signal to other side of pty */
344 return pty_signal(tty, (int) arg);
324 } 345 }
325 return -ENOIOCTLCMD; 346 return -ENOIOCTLCMD;
326} 347}
@@ -476,6 +497,8 @@ static int pty_unix98_ioctl(struct tty_struct *tty, struct file *file,
476 return pty_set_lock(tty, (int __user *)arg); 497 return pty_set_lock(tty, (int __user *)arg);
477 case TIOCGPTN: /* Get PT Number */ 498 case TIOCGPTN: /* Get PT Number */
478 return put_user(tty->index, (unsigned int __user *)arg); 499 return put_user(tty->index, (unsigned int __user *)arg);
500 case TIOCSIG: /* Send signal to other side of pty */
501 return pty_signal(tty, (int) arg);
479 } 502 }
480 503
481 return -ENOIOCTLCMD; 504 return -ENOIOCTLCMD;
@@ -626,7 +649,7 @@ static const struct tty_operations pty_unix98_ops = {
626 * allocated_ptys_lock handles the list of free pty numbers 649 * allocated_ptys_lock handles the list of free pty numbers
627 */ 650 */
628 651
629static int __ptmx_open(struct inode *inode, struct file *filp) 652static int ptmx_open(struct inode *inode, struct file *filp)
630{ 653{
631 struct tty_struct *tty; 654 struct tty_struct *tty;
632 int retval; 655 int retval;
@@ -635,11 +658,14 @@ static int __ptmx_open(struct inode *inode, struct file *filp)
635 nonseekable_open(inode, filp); 658 nonseekable_open(inode, filp);
636 659
637 /* find a device that is not in use. */ 660 /* find a device that is not in use. */
661 tty_lock();
638 index = devpts_new_index(inode); 662 index = devpts_new_index(inode);
663 tty_unlock();
639 if (index < 0) 664 if (index < 0)
640 return index; 665 return index;
641 666
642 mutex_lock(&tty_mutex); 667 mutex_lock(&tty_mutex);
668 tty_lock();
643 tty = tty_init_dev(ptm_driver, index, 1); 669 tty = tty_init_dev(ptm_driver, index, 1);
644 mutex_unlock(&tty_mutex); 670 mutex_unlock(&tty_mutex);
645 671
@@ -657,26 +683,21 @@ static int __ptmx_open(struct inode *inode, struct file *filp)
657 goto out1; 683 goto out1;
658 684
659 retval = ptm_driver->ops->open(tty, filp); 685 retval = ptm_driver->ops->open(tty, filp);
660 if (!retval) 686 if (retval)
661 return 0; 687 goto out2;
662out1: 688out1:
689 tty_unlock();
690 return retval;
691out2:
692 tty_unlock();
663 tty_release(inode, filp); 693 tty_release(inode, filp);
664 return retval; 694 return retval;
665out: 695out:
666 devpts_kill_index(inode, index); 696 devpts_kill_index(inode, index);
697 tty_unlock();
667 return retval; 698 return retval;
668} 699}
669 700
670static int ptmx_open(struct inode *inode, struct file *filp)
671{
672 int ret;
673
674 lock_kernel();
675 ret = __ptmx_open(inode, filp);
676 unlock_kernel();
677 return ret;
678}
679
680static struct file_operations ptmx_fops; 701static struct file_operations ptmx_fops;
681 702
682static void __init unix98_pty_init(void) 703static void __init unix98_pty_init(void)
diff --git a/drivers/char/riscom8.c b/drivers/char/riscom8.c
index b02332a5412f..af4de1fe8445 100644
--- a/drivers/char/riscom8.c
+++ b/drivers/char/riscom8.c
@@ -47,7 +47,6 @@
47#include <linux/init.h> 47#include <linux/init.h>
48#include <linux/delay.h> 48#include <linux/delay.h>
49#include <linux/tty_flip.h> 49#include <linux/tty_flip.h>
50#include <linux/smp_lock.h>
51#include <linux/spinlock.h> 50#include <linux/spinlock.h>
52#include <linux/device.h> 51#include <linux/device.h>
53 52
@@ -1184,6 +1183,7 @@ static int rc_set_serial_info(struct tty_struct *tty, struct riscom_port *port,
1184 if (copy_from_user(&tmp, newinfo, sizeof(tmp))) 1183 if (copy_from_user(&tmp, newinfo, sizeof(tmp)))
1185 return -EFAULT; 1184 return -EFAULT;
1186 1185
1186 mutex_lock(&port->port.mutex);
1187 change_speed = ((port->port.flags & ASYNC_SPD_MASK) != 1187 change_speed = ((port->port.flags & ASYNC_SPD_MASK) !=
1188 (tmp.flags & ASYNC_SPD_MASK)); 1188 (tmp.flags & ASYNC_SPD_MASK));
1189 1189
@@ -1191,8 +1191,10 @@ static int rc_set_serial_info(struct tty_struct *tty, struct riscom_port *port,
1191 if ((tmp.close_delay != port->port.close_delay) || 1191 if ((tmp.close_delay != port->port.close_delay) ||
1192 (tmp.closing_wait != port->port.closing_wait) || 1192 (tmp.closing_wait != port->port.closing_wait) ||
1193 ((tmp.flags & ~ASYNC_USR_MASK) != 1193 ((tmp.flags & ~ASYNC_USR_MASK) !=
1194 (port->port.flags & ~ASYNC_USR_MASK))) 1194 (port->port.flags & ~ASYNC_USR_MASK))) {
1195 mutex_unlock(&port->port.mutex);
1195 return -EPERM; 1196 return -EPERM;
1197 }
1196 port->port.flags = ((port->port.flags & ~ASYNC_USR_MASK) | 1198 port->port.flags = ((port->port.flags & ~ASYNC_USR_MASK) |
1197 (tmp.flags & ASYNC_USR_MASK)); 1199 (tmp.flags & ASYNC_USR_MASK));
1198 } else { 1200 } else {
@@ -1208,6 +1210,7 @@ static int rc_set_serial_info(struct tty_struct *tty, struct riscom_port *port,
1208 rc_change_speed(tty, bp, port); 1210 rc_change_speed(tty, bp, port);
1209 spin_unlock_irqrestore(&riscom_lock, flags); 1211 spin_unlock_irqrestore(&riscom_lock, flags);
1210 } 1212 }
1213 mutex_unlock(&port->port.mutex);
1211 return 0; 1214 return 0;
1212} 1215}
1213 1216
@@ -1220,12 +1223,15 @@ static int rc_get_serial_info(struct riscom_port *port,
1220 memset(&tmp, 0, sizeof(tmp)); 1223 memset(&tmp, 0, sizeof(tmp));
1221 tmp.type = PORT_CIRRUS; 1224 tmp.type = PORT_CIRRUS;
1222 tmp.line = port - rc_port; 1225 tmp.line = port - rc_port;
1226
1227 mutex_lock(&port->port.mutex);
1223 tmp.port = bp->base; 1228 tmp.port = bp->base;
1224 tmp.irq = bp->irq; 1229 tmp.irq = bp->irq;
1225 tmp.flags = port->port.flags; 1230 tmp.flags = port->port.flags;
1226 tmp.baud_base = (RC_OSCFREQ + CD180_TPC/2) / CD180_TPC; 1231 tmp.baud_base = (RC_OSCFREQ + CD180_TPC/2) / CD180_TPC;
1227 tmp.close_delay = port->port.close_delay * HZ/100; 1232 tmp.close_delay = port->port.close_delay * HZ/100;
1228 tmp.closing_wait = port->port.closing_wait * HZ/100; 1233 tmp.closing_wait = port->port.closing_wait * HZ/100;
1234 mutex_unlock(&port->port.mutex);
1229 tmp.xmit_fifo_size = CD180_NFIFO; 1235 tmp.xmit_fifo_size = CD180_NFIFO;
1230 return copy_to_user(retinfo, &tmp, sizeof(tmp)) ? -EFAULT : 0; 1236 return copy_to_user(retinfo, &tmp, sizeof(tmp)) ? -EFAULT : 0;
1231} 1237}
@@ -1242,14 +1248,10 @@ static int rc_ioctl(struct tty_struct *tty, struct file *filp,
1242 1248
1243 switch (cmd) { 1249 switch (cmd) {
1244 case TIOCGSERIAL: 1250 case TIOCGSERIAL:
1245 lock_kernel();
1246 retval = rc_get_serial_info(port, argp); 1251 retval = rc_get_serial_info(port, argp);
1247 unlock_kernel();
1248 break; 1252 break;
1249 case TIOCSSERIAL: 1253 case TIOCSSERIAL:
1250 lock_kernel();
1251 retval = rc_set_serial_info(tty, port, argp); 1254 retval = rc_set_serial_info(tty, port, argp);
1252 unlock_kernel();
1253 break; 1255 break;
1254 default: 1256 default:
1255 retval = -ENOIOCTLCMD; 1257 retval = -ENOIOCTLCMD;
diff --git a/drivers/char/rocket.c b/drivers/char/rocket.c
index 0e29a23ec4c5..79c3bc69165a 100644
--- a/drivers/char/rocket.c
+++ b/drivers/char/rocket.c
@@ -73,7 +73,6 @@
73#include <linux/tty_driver.h> 73#include <linux/tty_driver.h>
74#include <linux/tty_flip.h> 74#include <linux/tty_flip.h>
75#include <linux/serial.h> 75#include <linux/serial.h>
76#include <linux/smp_lock.h>
77#include <linux/string.h> 76#include <linux/string.h>
78#include <linux/fcntl.h> 77#include <linux/fcntl.h>
79#include <linux/ptrace.h> 78#include <linux/ptrace.h>
@@ -1017,6 +1016,7 @@ static void rp_close(struct tty_struct *tty, struct file *filp)
1017 if (tty_port_close_start(port, tty, filp) == 0) 1016 if (tty_port_close_start(port, tty, filp) == 0)
1018 return; 1017 return;
1019 1018
1019 mutex_lock(&port->mutex);
1020 cp = &info->channel; 1020 cp = &info->channel;
1021 /* 1021 /*
1022 * Before we drop DTR, make sure the UART transmitter 1022 * Before we drop DTR, make sure the UART transmitter
@@ -1060,9 +1060,13 @@ static void rp_close(struct tty_struct *tty, struct file *filp)
1060 info->xmit_buf = NULL; 1060 info->xmit_buf = NULL;
1061 } 1061 }
1062 } 1062 }
1063 spin_lock_irq(&port->lock);
1063 info->port.flags &= ~(ASYNC_INITIALIZED | ASYNC_CLOSING | ASYNC_NORMAL_ACTIVE); 1064 info->port.flags &= ~(ASYNC_INITIALIZED | ASYNC_CLOSING | ASYNC_NORMAL_ACTIVE);
1064 tty->closing = 0; 1065 tty->closing = 0;
1066 spin_unlock_irq(&port->lock);
1067 mutex_unlock(&port->mutex);
1065 tty_port_tty_set(port, NULL); 1068 tty_port_tty_set(port, NULL);
1069
1066 wake_up_interruptible(&port->close_wait); 1070 wake_up_interruptible(&port->close_wait);
1067 complete_all(&info->close_wait); 1071 complete_all(&info->close_wait);
1068 atomic_dec(&rp_num_ports_open); 1072 atomic_dec(&rp_num_ports_open);
@@ -1210,11 +1214,13 @@ static int get_config(struct r_port *info, struct rocket_config __user *retinfo)
1210 if (!retinfo) 1214 if (!retinfo)
1211 return -EFAULT; 1215 return -EFAULT;
1212 memset(&tmp, 0, sizeof (tmp)); 1216 memset(&tmp, 0, sizeof (tmp));
1217 mutex_lock(&info->port.mutex);
1213 tmp.line = info->line; 1218 tmp.line = info->line;
1214 tmp.flags = info->flags; 1219 tmp.flags = info->flags;
1215 tmp.close_delay = info->port.close_delay; 1220 tmp.close_delay = info->port.close_delay;
1216 tmp.closing_wait = info->port.closing_wait; 1221 tmp.closing_wait = info->port.closing_wait;
1217 tmp.port = rcktpt_io_addr[(info->line >> 5) & 3]; 1222 tmp.port = rcktpt_io_addr[(info->line >> 5) & 3];
1223 mutex_unlock(&info->port.mutex);
1218 1224
1219 if (copy_to_user(retinfo, &tmp, sizeof (*retinfo))) 1225 if (copy_to_user(retinfo, &tmp, sizeof (*retinfo)))
1220 return -EFAULT; 1226 return -EFAULT;
@@ -1229,10 +1235,13 @@ static int set_config(struct tty_struct *tty, struct r_port *info,
1229 if (copy_from_user(&new_serial, new_info, sizeof (new_serial))) 1235 if (copy_from_user(&new_serial, new_info, sizeof (new_serial)))
1230 return -EFAULT; 1236 return -EFAULT;
1231 1237
1238 mutex_lock(&info->port.mutex);
1232 if (!capable(CAP_SYS_ADMIN)) 1239 if (!capable(CAP_SYS_ADMIN))
1233 { 1240 {
1234 if ((new_serial.flags & ~ROCKET_USR_MASK) != (info->flags & ~ROCKET_USR_MASK)) 1241 if ((new_serial.flags & ~ROCKET_USR_MASK) != (info->flags & ~ROCKET_USR_MASK)) {
1242 mutex_unlock(&info->port.mutex);
1235 return -EPERM; 1243 return -EPERM;
1244 }
1236 info->flags = ((info->flags & ~ROCKET_USR_MASK) | (new_serial.flags & ROCKET_USR_MASK)); 1245 info->flags = ((info->flags & ~ROCKET_USR_MASK) | (new_serial.flags & ROCKET_USR_MASK));
1237 configure_r_port(tty, info, NULL); 1246 configure_r_port(tty, info, NULL);
1238 return 0; 1247 return 0;
@@ -1250,6 +1259,7 @@ static int set_config(struct tty_struct *tty, struct r_port *info,
1250 tty->alt_speed = 230400; 1259 tty->alt_speed = 230400;
1251 if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_WARP) 1260 if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_WARP)
1252 tty->alt_speed = 460800; 1261 tty->alt_speed = 460800;
1262 mutex_unlock(&info->port.mutex);
1253 1263
1254 configure_r_port(tty, info, NULL); 1264 configure_r_port(tty, info, NULL);
1255 return 0; 1265 return 0;
@@ -1325,8 +1335,6 @@ static int rp_ioctl(struct tty_struct *tty, struct file *file,
1325 if (cmd != RCKP_GET_PORTS && rocket_paranoia_check(info, "rp_ioctl")) 1335 if (cmd != RCKP_GET_PORTS && rocket_paranoia_check(info, "rp_ioctl"))
1326 return -ENXIO; 1336 return -ENXIO;
1327 1337
1328 lock_kernel();
1329
1330 switch (cmd) { 1338 switch (cmd) {
1331 case RCKP_GET_STRUCT: 1339 case RCKP_GET_STRUCT:
1332 if (copy_to_user(argp, info, sizeof (struct r_port))) 1340 if (copy_to_user(argp, info, sizeof (struct r_port)))
@@ -1350,7 +1358,6 @@ static int rp_ioctl(struct tty_struct *tty, struct file *file,
1350 default: 1358 default:
1351 ret = -ENOIOCTLCMD; 1359 ret = -ENOIOCTLCMD;
1352 } 1360 }
1353 unlock_kernel();
1354 return ret; 1361 return ret;
1355} 1362}
1356 1363
@@ -1471,7 +1478,6 @@ static void rp_wait_until_sent(struct tty_struct *tty, int timeout)
1471 jiffies); 1478 jiffies);
1472 printk(KERN_INFO "cps=%d...\n", info->cps); 1479 printk(KERN_INFO "cps=%d...\n", info->cps);
1473#endif 1480#endif
1474 lock_kernel();
1475 while (1) { 1481 while (1) {
1476 txcnt = sGetTxCnt(cp); 1482 txcnt = sGetTxCnt(cp);
1477 if (!txcnt) { 1483 if (!txcnt) {
@@ -1499,7 +1505,6 @@ static void rp_wait_until_sent(struct tty_struct *tty, int timeout)
1499 break; 1505 break;
1500 } 1506 }
1501 __set_current_state(TASK_RUNNING); 1507 __set_current_state(TASK_RUNNING);
1502 unlock_kernel();
1503#ifdef ROCKET_DEBUG_WAIT_UNTIL_SENT 1508#ifdef ROCKET_DEBUG_WAIT_UNTIL_SENT
1504 printk(KERN_INFO "txcnt = %d (jiff=%lu)...done\n", txcnt, jiffies); 1509 printk(KERN_INFO "txcnt = %d (jiff=%lu)...done\n", txcnt, jiffies);
1505#endif 1510#endif
@@ -1512,6 +1517,7 @@ static void rp_hangup(struct tty_struct *tty)
1512{ 1517{
1513 CHANNEL_t *cp; 1518 CHANNEL_t *cp;
1514 struct r_port *info = tty->driver_data; 1519 struct r_port *info = tty->driver_data;
1520 unsigned long flags;
1515 1521
1516 if (rocket_paranoia_check(info, "rp_hangup")) 1522 if (rocket_paranoia_check(info, "rp_hangup"))
1517 return; 1523 return;
@@ -1520,11 +1526,15 @@ static void rp_hangup(struct tty_struct *tty)
1520 printk(KERN_INFO "rp_hangup of ttyR%d...\n", info->line); 1526 printk(KERN_INFO "rp_hangup of ttyR%d...\n", info->line);
1521#endif 1527#endif
1522 rp_flush_buffer(tty); 1528 rp_flush_buffer(tty);
1523 if (info->port.flags & ASYNC_CLOSING) 1529 spin_lock_irqsave(&info->port.lock, flags);
1530 if (info->port.flags & ASYNC_CLOSING) {
1531 spin_unlock_irqrestore(&info->port.lock, flags);
1524 return; 1532 return;
1533 }
1525 if (info->port.count) 1534 if (info->port.count)
1526 atomic_dec(&rp_num_ports_open); 1535 atomic_dec(&rp_num_ports_open);
1527 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]); 1536 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
1537 spin_unlock_irqrestore(&info->port.lock, flags);
1528 1538
1529 tty_port_hangup(&info->port); 1539 tty_port_hangup(&info->port);
1530 1540
@@ -1535,7 +1545,7 @@ static void rp_hangup(struct tty_struct *tty)
1535 sDisCTSFlowCtl(cp); 1545 sDisCTSFlowCtl(cp);
1536 sDisTxSoftFlowCtl(cp); 1546 sDisTxSoftFlowCtl(cp);
1537 sClrTxXOFF(cp); 1547 sClrTxXOFF(cp);
1538 info->port.flags &= ~ASYNC_INITIALIZED; 1548 clear_bit(ASYNCB_INITIALIZED, &info->port.flags);
1539 1549
1540 wake_up_interruptible(&info->port.open_wait); 1550 wake_up_interruptible(&info->port.open_wait);
1541} 1551}
diff --git a/drivers/char/rtc.c b/drivers/char/rtc.c
index 95acb8c880f4..dfa8b3062fda 100644
--- a/drivers/char/rtc.c
+++ b/drivers/char/rtc.c
@@ -961,7 +961,7 @@ static int __init rtc_init(void)
961#endif 961#endif
962#ifdef CONFIG_SPARC32 962#ifdef CONFIG_SPARC32
963 struct device_node *ebus_dp; 963 struct device_node *ebus_dp;
964 struct of_device *op; 964 struct platform_device *op;
965#else 965#else
966 void *r; 966 void *r;
967#ifdef RTC_IRQ 967#ifdef RTC_IRQ
diff --git a/drivers/char/selection.c b/drivers/char/selection.c
index f97b9e848064..ebae344ce910 100644
--- a/drivers/char/selection.c
+++ b/drivers/char/selection.c
@@ -26,6 +26,7 @@
26#include <linux/selection.h> 26#include <linux/selection.h>
27#include <linux/tiocl.h> 27#include <linux/tiocl.h>
28#include <linux/console.h> 28#include <linux/console.h>
29#include <linux/smp_lock.h>
29 30
30/* Don't take this from <ctype.h>: 011-015 on the screen aren't spaces */ 31/* Don't take this from <ctype.h>: 011-015 on the screen aren't spaces */
31#define isspace(c) ((c) == ' ') 32#define isspace(c) ((c) == ' ')
@@ -312,12 +313,20 @@ int paste_selection(struct tty_struct *tty)
312 struct tty_ldisc *ld; 313 struct tty_ldisc *ld;
313 DECLARE_WAITQUEUE(wait, current); 314 DECLARE_WAITQUEUE(wait, current);
314 315
316 /* always called with BTM from vt_ioctl */
317 WARN_ON(!tty_locked());
318
315 acquire_console_sem(); 319 acquire_console_sem();
316 poke_blanked_console(); 320 poke_blanked_console();
317 release_console_sem(); 321 release_console_sem();
318 322
319 ld = tty_ldisc_ref_wait(tty); 323 ld = tty_ldisc_ref(tty);
320 324 if (!ld) {
325 tty_unlock();
326 ld = tty_ldisc_ref_wait(tty);
327 tty_lock();
328 }
329
321 add_wait_queue(&vc->paste_wait, &wait); 330 add_wait_queue(&vc->paste_wait, &wait);
322 while (sel_buffer && sel_buffer_lth > pasted) { 331 while (sel_buffer && sel_buffer_lth > pasted) {
323 set_current_state(TASK_INTERRUPTIBLE); 332 set_current_state(TASK_INTERRUPTIBLE);
diff --git a/drivers/char/serial167.c b/drivers/char/serial167.c
index ecbe479c7d68..f646725bd567 100644
--- a/drivers/char/serial167.c
+++ b/drivers/char/serial167.c
@@ -1505,7 +1505,7 @@ cy_ioctl(struct tty_struct *tty, struct file *file,
1505 printk("cy_ioctl %s, cmd = %x arg = %lx\n", tty->name, cmd, arg); /* */ 1505 printk("cy_ioctl %s, cmd = %x arg = %lx\n", tty->name, cmd, arg); /* */
1506#endif 1506#endif
1507 1507
1508 lock_kernel(); 1508 tty_lock();
1509 1509
1510 switch (cmd) { 1510 switch (cmd) {
1511 case CYGETMON: 1511 case CYGETMON:
@@ -1561,7 +1561,7 @@ cy_ioctl(struct tty_struct *tty, struct file *file,
1561 default: 1561 default:
1562 ret_val = -ENOIOCTLCMD; 1562 ret_val = -ENOIOCTLCMD;
1563 } 1563 }
1564 unlock_kernel(); 1564 tty_unlock();
1565 1565
1566#ifdef SERIAL_DEBUG_OTHER 1566#ifdef SERIAL_DEBUG_OTHER
1567 printk("cy_ioctl done\n"); 1567 printk("cy_ioctl done\n");
@@ -1786,7 +1786,9 @@ block_til_ready(struct tty_struct *tty, struct file *filp,
1786 tty->name, info->count); 1786 tty->name, info->count);
1787 /**/ 1787 /**/
1788#endif 1788#endif
1789 schedule(); 1789 tty_unlock();
1790 schedule();
1791 tty_lock();
1790 } 1792 }
1791 __set_current_state(TASK_RUNNING); 1793 __set_current_state(TASK_RUNNING);
1792 remove_wait_queue(&info->open_wait, &wait); 1794 remove_wait_queue(&info->open_wait, &wait);
diff --git a/drivers/char/specialix.c b/drivers/char/specialix.c
index 2c24fcdc722a..9f8495b4fc8f 100644
--- a/drivers/char/specialix.c
+++ b/drivers/char/specialix.c
@@ -1365,7 +1365,9 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
1365 retval = -ERESTARTSYS; 1365 retval = -ERESTARTSYS;
1366 break; 1366 break;
1367 } 1367 }
1368 tty_unlock();
1368 schedule(); 1369 schedule();
1370 tty_lock();
1369 } 1371 }
1370 1372
1371 set_current_state(TASK_RUNNING); 1373 set_current_state(TASK_RUNNING);
@@ -1863,8 +1865,7 @@ static int sx_set_serial_info(struct specialix_port *port,
1863 return -EFAULT; 1865 return -EFAULT;
1864 } 1866 }
1865 1867
1866 lock_kernel(); 1868 mutex_lock(&port->port.mutex);
1867
1868 change_speed = ((port->port.flags & ASYNC_SPD_MASK) != 1869 change_speed = ((port->port.flags & ASYNC_SPD_MASK) !=
1869 (tmp.flags & ASYNC_SPD_MASK)); 1870 (tmp.flags & ASYNC_SPD_MASK));
1870 change_speed |= (tmp.custom_divisor != port->custom_divisor); 1871 change_speed |= (tmp.custom_divisor != port->custom_divisor);
@@ -1875,7 +1876,7 @@ static int sx_set_serial_info(struct specialix_port *port,
1875 ((tmp.flags & ~ASYNC_USR_MASK) != 1876 ((tmp.flags & ~ASYNC_USR_MASK) !=
1876 (port->port.flags & ~ASYNC_USR_MASK))) { 1877 (port->port.flags & ~ASYNC_USR_MASK))) {
1877 func_exit(); 1878 func_exit();
1878 unlock_kernel(); 1879 mutex_unlock(&port->port.mutex);
1879 return -EPERM; 1880 return -EPERM;
1880 } 1881 }
1881 port->port.flags = ((port->port.flags & ~ASYNC_USR_MASK) | 1882 port->port.flags = ((port->port.flags & ~ASYNC_USR_MASK) |
@@ -1892,7 +1893,7 @@ static int sx_set_serial_info(struct specialix_port *port,
1892 sx_change_speed(bp, port); 1893 sx_change_speed(bp, port);
1893 1894
1894 func_exit(); 1895 func_exit();
1895 unlock_kernel(); 1896 mutex_unlock(&port->port.mutex);
1896 return 0; 1897 return 0;
1897} 1898}
1898 1899
@@ -1906,7 +1907,7 @@ static int sx_get_serial_info(struct specialix_port *port,
1906 func_enter(); 1907 func_enter();
1907 1908
1908 memset(&tmp, 0, sizeof(tmp)); 1909 memset(&tmp, 0, sizeof(tmp));
1909 lock_kernel(); 1910 mutex_lock(&port->port.mutex);
1910 tmp.type = PORT_CIRRUS; 1911 tmp.type = PORT_CIRRUS;
1911 tmp.line = port - sx_port; 1912 tmp.line = port - sx_port;
1912 tmp.port = bp->base; 1913 tmp.port = bp->base;
@@ -1917,7 +1918,7 @@ static int sx_get_serial_info(struct specialix_port *port,
1917 tmp.closing_wait = port->port.closing_wait * HZ/100; 1918 tmp.closing_wait = port->port.closing_wait * HZ/100;
1918 tmp.custom_divisor = port->custom_divisor; 1919 tmp.custom_divisor = port->custom_divisor;
1919 tmp.xmit_fifo_size = CD186x_NFIFO; 1920 tmp.xmit_fifo_size = CD186x_NFIFO;
1920 unlock_kernel(); 1921 mutex_unlock(&port->port.mutex);
1921 if (copy_to_user(retinfo, &tmp, sizeof(tmp))) { 1922 if (copy_to_user(retinfo, &tmp, sizeof(tmp))) {
1922 func_exit(); 1923 func_exit();
1923 return -EFAULT; 1924 return -EFAULT;
diff --git a/drivers/char/stallion.c b/drivers/char/stallion.c
index 6049fd731924..f2167f8e5aab 100644
--- a/drivers/char/stallion.c
+++ b/drivers/char/stallion.c
@@ -807,7 +807,6 @@ static void stl_waituntilsent(struct tty_struct *tty, int timeout)
807 timeout = HZ; 807 timeout = HZ;
808 tend = jiffies + timeout; 808 tend = jiffies + timeout;
809 809
810 lock_kernel();
811 while (stl_datastate(portp)) { 810 while (stl_datastate(portp)) {
812 if (signal_pending(current)) 811 if (signal_pending(current))
813 break; 812 break;
@@ -815,7 +814,6 @@ static void stl_waituntilsent(struct tty_struct *tty, int timeout)
815 if (time_after_eq(jiffies, tend)) 814 if (time_after_eq(jiffies, tend))
816 break; 815 break;
817 } 816 }
818 unlock_kernel();
819} 817}
820 818
821/*****************************************************************************/ 819/*****************************************************************************/
@@ -1029,6 +1027,8 @@ static int stl_getserial(struct stlport *portp, struct serial_struct __user *sp)
1029 pr_debug("stl_getserial(portp=%p,sp=%p)\n", portp, sp); 1027 pr_debug("stl_getserial(portp=%p,sp=%p)\n", portp, sp);
1030 1028
1031 memset(&sio, 0, sizeof(struct serial_struct)); 1029 memset(&sio, 0, sizeof(struct serial_struct));
1030
1031 mutex_lock(&portp->port.mutex);
1032 sio.line = portp->portnr; 1032 sio.line = portp->portnr;
1033 sio.port = portp->ioaddr; 1033 sio.port = portp->ioaddr;
1034 sio.flags = portp->port.flags; 1034 sio.flags = portp->port.flags;
@@ -1048,6 +1048,7 @@ static int stl_getserial(struct stlport *portp, struct serial_struct __user *sp)
1048 brdp = stl_brds[portp->brdnr]; 1048 brdp = stl_brds[portp->brdnr];
1049 if (brdp != NULL) 1049 if (brdp != NULL)
1050 sio.irq = brdp->irq; 1050 sio.irq = brdp->irq;
1051 mutex_unlock(&portp->port.mutex);
1051 1052
1052 return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ? -EFAULT : 0; 1053 return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ? -EFAULT : 0;
1053} 1054}
@@ -1069,12 +1070,15 @@ static int stl_setserial(struct tty_struct *tty, struct serial_struct __user *sp
1069 1070
1070 if (copy_from_user(&sio, sp, sizeof(struct serial_struct))) 1071 if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
1071 return -EFAULT; 1072 return -EFAULT;
1073 mutex_lock(&portp->port.mutex);
1072 if (!capable(CAP_SYS_ADMIN)) { 1074 if (!capable(CAP_SYS_ADMIN)) {
1073 if ((sio.baud_base != portp->baud_base) || 1075 if ((sio.baud_base != portp->baud_base) ||
1074 (sio.close_delay != portp->close_delay) || 1076 (sio.close_delay != portp->close_delay) ||
1075 ((sio.flags & ~ASYNC_USR_MASK) != 1077 ((sio.flags & ~ASYNC_USR_MASK) !=
1076 (portp->port.flags & ~ASYNC_USR_MASK))) 1078 (portp->port.flags & ~ASYNC_USR_MASK))) {
1079 mutex_unlock(&portp->port.mutex);
1077 return -EPERM; 1080 return -EPERM;
1081 }
1078 } 1082 }
1079 1083
1080 portp->port.flags = (portp->port.flags & ~ASYNC_USR_MASK) | 1084 portp->port.flags = (portp->port.flags & ~ASYNC_USR_MASK) |
@@ -1083,6 +1087,7 @@ static int stl_setserial(struct tty_struct *tty, struct serial_struct __user *sp
1083 portp->close_delay = sio.close_delay; 1087 portp->close_delay = sio.close_delay;
1084 portp->closing_wait = sio.closing_wait; 1088 portp->closing_wait = sio.closing_wait;
1085 portp->custom_divisor = sio.custom_divisor; 1089 portp->custom_divisor = sio.custom_divisor;
1090 mutex_unlock(&portp->port.mutex);
1086 stl_setport(portp, tty->termios); 1091 stl_setport(portp, tty->termios);
1087 return 0; 1092 return 0;
1088} 1093}
@@ -1147,8 +1152,6 @@ static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd
1147 1152
1148 rc = 0; 1153 rc = 0;
1149 1154
1150 lock_kernel();
1151
1152 switch (cmd) { 1155 switch (cmd) {
1153 case TIOCGSERIAL: 1156 case TIOCGSERIAL:
1154 rc = stl_getserial(portp, argp); 1157 rc = stl_getserial(portp, argp);
@@ -1173,7 +1176,6 @@ static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd
1173 rc = -ENOIOCTLCMD; 1176 rc = -ENOIOCTLCMD;
1174 break; 1177 break;
1175 } 1178 }
1176 unlock_kernel();
1177 return rc; 1179 return rc;
1178} 1180}
1179 1181
@@ -2327,6 +2329,7 @@ static int stl_getportstats(struct tty_struct *tty, struct stlport *portp, comst
2327 return -ENODEV; 2329 return -ENODEV;
2328 } 2330 }
2329 2331
2332 mutex_lock(&portp->port.mutex);
2330 portp->stats.state = portp->istate; 2333 portp->stats.state = portp->istate;
2331 portp->stats.flags = portp->port.flags; 2334 portp->stats.flags = portp->port.flags;
2332 portp->stats.hwid = portp->hwid; 2335 portp->stats.hwid = portp->hwid;
@@ -2358,6 +2361,7 @@ static int stl_getportstats(struct tty_struct *tty, struct stlport *portp, comst
2358 (STL_TXBUFSIZE - (tail - head)); 2361 (STL_TXBUFSIZE - (tail - head));
2359 2362
2360 portp->stats.signals = (unsigned long) stl_getsignals(portp); 2363 portp->stats.signals = (unsigned long) stl_getsignals(portp);
2364 mutex_unlock(&portp->port.mutex);
2361 2365
2362 return copy_to_user(cp, &portp->stats, 2366 return copy_to_user(cp, &portp->stats,
2363 sizeof(comstats_t)) ? -EFAULT : 0; 2367 sizeof(comstats_t)) ? -EFAULT : 0;
@@ -2382,10 +2386,12 @@ static int stl_clrportstats(struct stlport *portp, comstats_t __user *cp)
2382 return -ENODEV; 2386 return -ENODEV;
2383 } 2387 }
2384 2388
2389 mutex_lock(&portp->port.mutex);
2385 memset(&portp->stats, 0, sizeof(comstats_t)); 2390 memset(&portp->stats, 0, sizeof(comstats_t));
2386 portp->stats.brd = portp->brdnr; 2391 portp->stats.brd = portp->brdnr;
2387 portp->stats.panel = portp->panelnr; 2392 portp->stats.panel = portp->panelnr;
2388 portp->stats.port = portp->portnr; 2393 portp->stats.port = portp->portnr;
2394 mutex_unlock(&portp->port.mutex);
2389 return copy_to_user(cp, &portp->stats, 2395 return copy_to_user(cp, &portp->stats,
2390 sizeof(comstats_t)) ? -EFAULT : 0; 2396 sizeof(comstats_t)) ? -EFAULT : 0;
2391} 2397}
@@ -2451,7 +2457,6 @@ static long stl_memioctl(struct file *fp, unsigned int cmd, unsigned long arg)
2451 return -ENODEV; 2457 return -ENODEV;
2452 rc = 0; 2458 rc = 0;
2453 2459
2454 lock_kernel();
2455 switch (cmd) { 2460 switch (cmd) {
2456 case COM_GETPORTSTATS: 2461 case COM_GETPORTSTATS:
2457 rc = stl_getportstats(NULL, NULL, argp); 2462 rc = stl_getportstats(NULL, NULL, argp);
@@ -2472,7 +2477,6 @@ static long stl_memioctl(struct file *fp, unsigned int cmd, unsigned long arg)
2472 rc = -ENOIOCTLCMD; 2477 rc = -ENOIOCTLCMD;
2473 break; 2478 break;
2474 } 2479 }
2475 unlock_kernel();
2476 return rc; 2480 return rc;
2477} 2481}
2478 2482
diff --git a/drivers/char/sx.c b/drivers/char/sx.c
index a81ec4fcf6ff..5b24db4ff7f1 100644
--- a/drivers/char/sx.c
+++ b/drivers/char/sx.c
@@ -1699,7 +1699,7 @@ static long sx_fw_ioctl(struct file *filp, unsigned int cmd,
1699 if (!capable(CAP_SYS_RAWIO)) 1699 if (!capable(CAP_SYS_RAWIO))
1700 return -EPERM; 1700 return -EPERM;
1701 1701
1702 lock_kernel(); 1702 tty_lock();
1703 1703
1704 sx_dprintk(SX_DEBUG_FIRMWARE, "IOCTL %x: %lx\n", cmd, arg); 1704 sx_dprintk(SX_DEBUG_FIRMWARE, "IOCTL %x: %lx\n", cmd, arg);
1705 1705
@@ -1848,7 +1848,7 @@ static long sx_fw_ioctl(struct file *filp, unsigned int cmd,
1848 break; 1848 break;
1849 } 1849 }
1850out: 1850out:
1851 unlock_kernel(); 1851 tty_unlock();
1852 func_exit(); 1852 func_exit();
1853 return rc; 1853 return rc;
1854} 1854}
@@ -1859,7 +1859,7 @@ static int sx_break(struct tty_struct *tty, int flag)
1859 int rv; 1859 int rv;
1860 1860
1861 func_enter(); 1861 func_enter();
1862 lock_kernel(); 1862 tty_lock();
1863 1863
1864 if (flag) 1864 if (flag)
1865 rv = sx_send_command(port, HS_START, -1, HS_IDLE_BREAK); 1865 rv = sx_send_command(port, HS_START, -1, HS_IDLE_BREAK);
@@ -1868,7 +1868,7 @@ static int sx_break(struct tty_struct *tty, int flag)
1868 if (rv != 1) 1868 if (rv != 1)
1869 printk(KERN_ERR "sx: couldn't send break (%x).\n", 1869 printk(KERN_ERR "sx: couldn't send break (%x).\n",
1870 read_sx_byte(port->board, CHAN_OFFSET(port, hi_hstat))); 1870 read_sx_byte(port->board, CHAN_OFFSET(port, hi_hstat)));
1871 unlock_kernel(); 1871 tty_unlock();
1872 func_exit(); 1872 func_exit();
1873 return 0; 1873 return 0;
1874} 1874}
@@ -1909,7 +1909,7 @@ static int sx_ioctl(struct tty_struct *tty, struct file *filp,
1909 /* func_enter2(); */ 1909 /* func_enter2(); */
1910 1910
1911 rc = 0; 1911 rc = 0;
1912 lock_kernel(); 1912 tty_lock();
1913 switch (cmd) { 1913 switch (cmd) {
1914 case TIOCGSERIAL: 1914 case TIOCGSERIAL:
1915 rc = gs_getserial(&port->gs, argp); 1915 rc = gs_getserial(&port->gs, argp);
@@ -1921,7 +1921,7 @@ static int sx_ioctl(struct tty_struct *tty, struct file *filp,
1921 rc = -ENOIOCTLCMD; 1921 rc = -ENOIOCTLCMD;
1922 break; 1922 break;
1923 } 1923 }
1924 unlock_kernel(); 1924 tty_unlock();
1925 1925
1926 /* func_exit(); */ 1926 /* func_exit(); */
1927 return rc; 1927 return rc;
diff --git a/drivers/char/synclink.c b/drivers/char/synclink.c
index 0658fc548222..a2a58004e188 100644
--- a/drivers/char/synclink.c
+++ b/drivers/char/synclink.c
@@ -81,7 +81,6 @@
81#include <linux/mm.h> 81#include <linux/mm.h>
82#include <linux/seq_file.h> 82#include <linux/seq_file.h>
83#include <linux/slab.h> 83#include <linux/slab.h>
84#include <linux/smp_lock.h>
85#include <linux/delay.h> 84#include <linux/delay.h>
86#include <linux/netdevice.h> 85#include <linux/netdevice.h>
87#include <linux/vmalloc.h> 86#include <linux/vmalloc.h>
@@ -2436,7 +2435,9 @@ static int mgsl_get_stats(struct mgsl_struct * info, struct mgsl_icount __user *
2436 if (!user_icount) { 2435 if (!user_icount) {
2437 memset(&info->icount, 0, sizeof(info->icount)); 2436 memset(&info->icount, 0, sizeof(info->icount));
2438 } else { 2437 } else {
2438 mutex_lock(&info->port.mutex);
2439 COPY_TO_USER(err, user_icount, &info->icount, sizeof(struct mgsl_icount)); 2439 COPY_TO_USER(err, user_icount, &info->icount, sizeof(struct mgsl_icount));
2440 mutex_unlock(&info->port.mutex);
2440 if (err) 2441 if (err)
2441 return -EFAULT; 2442 return -EFAULT;
2442 } 2443 }
@@ -2461,7 +2462,9 @@ static int mgsl_get_params(struct mgsl_struct * info, MGSL_PARAMS __user *user_p
2461 printk("%s(%d):mgsl_get_params(%s)\n", 2462 printk("%s(%d):mgsl_get_params(%s)\n",
2462 __FILE__,__LINE__, info->device_name); 2463 __FILE__,__LINE__, info->device_name);
2463 2464
2465 mutex_lock(&info->port.mutex);
2464 COPY_TO_USER(err,user_params, &info->params, sizeof(MGSL_PARAMS)); 2466 COPY_TO_USER(err,user_params, &info->params, sizeof(MGSL_PARAMS));
2467 mutex_unlock(&info->port.mutex);
2465 if (err) { 2468 if (err) {
2466 if ( debug_level >= DEBUG_LEVEL_INFO ) 2469 if ( debug_level >= DEBUG_LEVEL_INFO )
2467 printk( "%s(%d):mgsl_get_params(%s) user buffer copy failed\n", 2470 printk( "%s(%d):mgsl_get_params(%s) user buffer copy failed\n",
@@ -2501,11 +2504,13 @@ static int mgsl_set_params(struct mgsl_struct * info, MGSL_PARAMS __user *new_pa
2501 return -EFAULT; 2504 return -EFAULT;
2502 } 2505 }
2503 2506
2507 mutex_lock(&info->port.mutex);
2504 spin_lock_irqsave(&info->irq_spinlock,flags); 2508 spin_lock_irqsave(&info->irq_spinlock,flags);
2505 memcpy(&info->params,&tmp_params,sizeof(MGSL_PARAMS)); 2509 memcpy(&info->params,&tmp_params,sizeof(MGSL_PARAMS));
2506 spin_unlock_irqrestore(&info->irq_spinlock,flags); 2510 spin_unlock_irqrestore(&info->irq_spinlock,flags);
2507 2511
2508 mgsl_change_params(info); 2512 mgsl_change_params(info);
2513 mutex_unlock(&info->port.mutex);
2509 2514
2510 return 0; 2515 return 0;
2511 2516
@@ -2935,7 +2940,6 @@ static int mgsl_ioctl(struct tty_struct *tty, struct file * file,
2935 unsigned int cmd, unsigned long arg) 2940 unsigned int cmd, unsigned long arg)
2936{ 2941{
2937 struct mgsl_struct * info = tty->driver_data; 2942 struct mgsl_struct * info = tty->driver_data;
2938 int ret;
2939 2943
2940 if (debug_level >= DEBUG_LEVEL_INFO) 2944 if (debug_level >= DEBUG_LEVEL_INFO)
2941 printk("%s(%d):mgsl_ioctl %s cmd=%08X\n", __FILE__,__LINE__, 2945 printk("%s(%d):mgsl_ioctl %s cmd=%08X\n", __FILE__,__LINE__,
@@ -2950,10 +2954,7 @@ static int mgsl_ioctl(struct tty_struct *tty, struct file * file,
2950 return -EIO; 2954 return -EIO;
2951 } 2955 }
2952 2956
2953 lock_kernel(); 2957 return mgsl_ioctl_common(info, cmd, arg);
2954 ret = mgsl_ioctl_common(info, cmd, arg);
2955 unlock_kernel();
2956 return ret;
2957} 2958}
2958 2959
2959static int mgsl_ioctl_common(struct mgsl_struct *info, unsigned int cmd, unsigned long arg) 2960static int mgsl_ioctl_common(struct mgsl_struct *info, unsigned int cmd, unsigned long arg)
@@ -3109,12 +3110,14 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
3109 3110
3110 if (tty_port_close_start(&info->port, tty, filp) == 0) 3111 if (tty_port_close_start(&info->port, tty, filp) == 0)
3111 goto cleanup; 3112 goto cleanup;
3112 3113
3114 mutex_lock(&info->port.mutex);
3113 if (info->port.flags & ASYNC_INITIALIZED) 3115 if (info->port.flags & ASYNC_INITIALIZED)
3114 mgsl_wait_until_sent(tty, info->timeout); 3116 mgsl_wait_until_sent(tty, info->timeout);
3115 mgsl_flush_buffer(tty); 3117 mgsl_flush_buffer(tty);
3116 tty_ldisc_flush(tty); 3118 tty_ldisc_flush(tty);
3117 shutdown(info); 3119 shutdown(info);
3120 mutex_unlock(&info->port.mutex);
3118 3121
3119 tty_port_close_end(&info->port, tty); 3122 tty_port_close_end(&info->port, tty);
3120 info->port.tty = NULL; 3123 info->port.tty = NULL;
@@ -3162,7 +3165,6 @@ static void mgsl_wait_until_sent(struct tty_struct *tty, int timeout)
3162 * Note: use tight timings here to satisfy the NIST-PCTS. 3165 * Note: use tight timings here to satisfy the NIST-PCTS.
3163 */ 3166 */
3164 3167
3165 lock_kernel();
3166 if ( info->params.data_rate ) { 3168 if ( info->params.data_rate ) {
3167 char_time = info->timeout/(32 * 5); 3169 char_time = info->timeout/(32 * 5);
3168 if (!char_time) 3170 if (!char_time)
@@ -3192,7 +3194,6 @@ static void mgsl_wait_until_sent(struct tty_struct *tty, int timeout)
3192 break; 3194 break;
3193 } 3195 }
3194 } 3196 }
3195 unlock_kernel();
3196 3197
3197exit: 3198exit:
3198 if (debug_level >= DEBUG_LEVEL_INFO) 3199 if (debug_level >= DEBUG_LEVEL_INFO)
@@ -3348,7 +3349,9 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
3348 printk("%s(%d):block_til_ready blocking on %s count=%d\n", 3349 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
3349 __FILE__,__LINE__, tty->driver->name, port->count ); 3350 __FILE__,__LINE__, tty->driver->name, port->count );
3350 3351
3352 tty_unlock();
3351 schedule(); 3353 schedule();
3354 tty_lock();
3352 } 3355 }
3353 3356
3354 set_current_state(TASK_RUNNING); 3357 set_current_state(TASK_RUNNING);
diff --git a/drivers/char/synclink_gt.c b/drivers/char/synclink_gt.c
index 334cf5c8c8b6..fef80cfcab5c 100644
--- a/drivers/char/synclink_gt.c
+++ b/drivers/char/synclink_gt.c
@@ -40,8 +40,8 @@
40#define DBGBH(fmt) if (debug_level >= DEBUG_LEVEL_BH) printk fmt 40#define DBGBH(fmt) if (debug_level >= DEBUG_LEVEL_BH) printk fmt
41#define DBGISR(fmt) if (debug_level >= DEBUG_LEVEL_ISR) printk fmt 41#define DBGISR(fmt) if (debug_level >= DEBUG_LEVEL_ISR) printk fmt
42#define DBGDATA(info, buf, size, label) if (debug_level >= DEBUG_LEVEL_DATA) trace_block((info), (buf), (size), (label)) 42#define DBGDATA(info, buf, size, label) if (debug_level >= DEBUG_LEVEL_DATA) trace_block((info), (buf), (size), (label))
43//#define DBGTBUF(info) dump_tbufs(info) 43/*#define DBGTBUF(info) dump_tbufs(info)*/
44//#define DBGRBUF(info) dump_rbufs(info) 44/*#define DBGRBUF(info) dump_rbufs(info)*/
45 45
46 46
47#include <linux/module.h> 47#include <linux/module.h>
@@ -62,7 +62,6 @@
62#include <linux/mm.h> 62#include <linux/mm.h>
63#include <linux/seq_file.h> 63#include <linux/seq_file.h>
64#include <linux/slab.h> 64#include <linux/slab.h>
65#include <linux/smp_lock.h>
66#include <linux/netdevice.h> 65#include <linux/netdevice.h>
67#include <linux/vmalloc.h> 66#include <linux/vmalloc.h>
68#include <linux/init.h> 67#include <linux/init.h>
@@ -676,12 +675,14 @@ static int open(struct tty_struct *tty, struct file *filp)
676 goto cleanup; 675 goto cleanup;
677 } 676 }
678 677
678 mutex_lock(&info->port.mutex);
679 info->port.tty->low_latency = (info->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0; 679 info->port.tty->low_latency = (info->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
680 680
681 spin_lock_irqsave(&info->netlock, flags); 681 spin_lock_irqsave(&info->netlock, flags);
682 if (info->netcount) { 682 if (info->netcount) {
683 retval = -EBUSY; 683 retval = -EBUSY;
684 spin_unlock_irqrestore(&info->netlock, flags); 684 spin_unlock_irqrestore(&info->netlock, flags);
685 mutex_unlock(&info->port.mutex);
685 goto cleanup; 686 goto cleanup;
686 } 687 }
687 info->port.count++; 688 info->port.count++;
@@ -693,7 +694,7 @@ static int open(struct tty_struct *tty, struct file *filp)
693 if (retval < 0) 694 if (retval < 0)
694 goto cleanup; 695 goto cleanup;
695 } 696 }
696 697 mutex_unlock(&info->port.mutex);
697 retval = block_til_ready(tty, filp, info); 698 retval = block_til_ready(tty, filp, info);
698 if (retval) { 699 if (retval) {
699 DBGINFO(("%s block_til_ready rc=%d\n", info->device_name, retval)); 700 DBGINFO(("%s block_til_ready rc=%d\n", info->device_name, retval));
@@ -725,12 +726,14 @@ static void close(struct tty_struct *tty, struct file *filp)
725 if (tty_port_close_start(&info->port, tty, filp) == 0) 726 if (tty_port_close_start(&info->port, tty, filp) == 0)
726 goto cleanup; 727 goto cleanup;
727 728
729 mutex_lock(&info->port.mutex);
728 if (info->port.flags & ASYNC_INITIALIZED) 730 if (info->port.flags & ASYNC_INITIALIZED)
729 wait_until_sent(tty, info->timeout); 731 wait_until_sent(tty, info->timeout);
730 flush_buffer(tty); 732 flush_buffer(tty);
731 tty_ldisc_flush(tty); 733 tty_ldisc_flush(tty);
732 734
733 shutdown(info); 735 shutdown(info);
736 mutex_unlock(&info->port.mutex);
734 737
735 tty_port_close_end(&info->port, tty); 738 tty_port_close_end(&info->port, tty);
736 info->port.tty = NULL; 739 info->port.tty = NULL;
@@ -741,17 +744,23 @@ cleanup:
741static void hangup(struct tty_struct *tty) 744static void hangup(struct tty_struct *tty)
742{ 745{
743 struct slgt_info *info = tty->driver_data; 746 struct slgt_info *info = tty->driver_data;
747 unsigned long flags;
744 748
745 if (sanity_check(info, tty->name, "hangup")) 749 if (sanity_check(info, tty->name, "hangup"))
746 return; 750 return;
747 DBGINFO(("%s hangup\n", info->device_name)); 751 DBGINFO(("%s hangup\n", info->device_name));
748 752
749 flush_buffer(tty); 753 flush_buffer(tty);
754
755 mutex_lock(&info->port.mutex);
750 shutdown(info); 756 shutdown(info);
751 757
758 spin_lock_irqsave(&info->port.lock, flags);
752 info->port.count = 0; 759 info->port.count = 0;
753 info->port.flags &= ~ASYNC_NORMAL_ACTIVE; 760 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
754 info->port.tty = NULL; 761 info->port.tty = NULL;
762 spin_unlock_irqrestore(&info->port.lock, flags);
763 mutex_unlock(&info->port.mutex);
755 764
756 wake_up_interruptible(&info->port.open_wait); 765 wake_up_interruptible(&info->port.open_wait);
757} 766}
@@ -901,8 +910,6 @@ static void wait_until_sent(struct tty_struct *tty, int timeout)
901 * Note: use tight timings here to satisfy the NIST-PCTS. 910 * Note: use tight timings here to satisfy the NIST-PCTS.
902 */ 911 */
903 912
904 lock_kernel();
905
906 if (info->params.data_rate) { 913 if (info->params.data_rate) {
907 char_time = info->timeout/(32 * 5); 914 char_time = info->timeout/(32 * 5);
908 if (!char_time) 915 if (!char_time)
@@ -920,8 +927,6 @@ static void wait_until_sent(struct tty_struct *tty, int timeout)
920 if (timeout && time_after(jiffies, orig_jiffies + timeout)) 927 if (timeout && time_after(jiffies, orig_jiffies + timeout))
921 break; 928 break;
922 } 929 }
923 unlock_kernel();
924
925exit: 930exit:
926 DBGINFO(("%s wait_until_sent exit\n", info->device_name)); 931 DBGINFO(("%s wait_until_sent exit\n", info->device_name));
927} 932}
@@ -1041,8 +1046,37 @@ static int ioctl(struct tty_struct *tty, struct file *file,
1041 return -EIO; 1046 return -EIO;
1042 } 1047 }
1043 1048
1044 lock_kernel(); 1049 switch (cmd) {
1045 1050 case MGSL_IOCWAITEVENT:
1051 return wait_mgsl_event(info, argp);
1052 case TIOCMIWAIT:
1053 return modem_input_wait(info,(int)arg);
1054 case TIOCGICOUNT:
1055 spin_lock_irqsave(&info->lock,flags);
1056 cnow = info->icount;
1057 spin_unlock_irqrestore(&info->lock,flags);
1058 p_cuser = argp;
1059 if (put_user(cnow.cts, &p_cuser->cts) ||
1060 put_user(cnow.dsr, &p_cuser->dsr) ||
1061 put_user(cnow.rng, &p_cuser->rng) ||
1062 put_user(cnow.dcd, &p_cuser->dcd) ||
1063 put_user(cnow.rx, &p_cuser->rx) ||
1064 put_user(cnow.tx, &p_cuser->tx) ||
1065 put_user(cnow.frame, &p_cuser->frame) ||
1066 put_user(cnow.overrun, &p_cuser->overrun) ||
1067 put_user(cnow.parity, &p_cuser->parity) ||
1068 put_user(cnow.brk, &p_cuser->brk) ||
1069 put_user(cnow.buf_overrun, &p_cuser->buf_overrun))
1070 return -EFAULT;
1071 return 0;
1072 case MGSL_IOCSGPIO:
1073 return set_gpio(info, argp);
1074 case MGSL_IOCGGPIO:
1075 return get_gpio(info, argp);
1076 case MGSL_IOCWAITGPIO:
1077 return wait_gpio(info, argp);
1078 }
1079 mutex_lock(&info->port.mutex);
1046 switch (cmd) { 1080 switch (cmd) {
1047 case MGSL_IOCGPARAMS: 1081 case MGSL_IOCGPARAMS:
1048 ret = get_params(info, argp); 1082 ret = get_params(info, argp);
@@ -1068,50 +1102,16 @@ static int ioctl(struct tty_struct *tty, struct file *file,
1068 case MGSL_IOCGSTATS: 1102 case MGSL_IOCGSTATS:
1069 ret = get_stats(info, argp); 1103 ret = get_stats(info, argp);
1070 break; 1104 break;
1071 case MGSL_IOCWAITEVENT:
1072 ret = wait_mgsl_event(info, argp);
1073 break;
1074 case TIOCMIWAIT:
1075 ret = modem_input_wait(info,(int)arg);
1076 break;
1077 case MGSL_IOCGIF: 1105 case MGSL_IOCGIF:
1078 ret = get_interface(info, argp); 1106 ret = get_interface(info, argp);
1079 break; 1107 break;
1080 case MGSL_IOCSIF: 1108 case MGSL_IOCSIF:
1081 ret = set_interface(info,(int)arg); 1109 ret = set_interface(info,(int)arg);
1082 break; 1110 break;
1083 case MGSL_IOCSGPIO:
1084 ret = set_gpio(info, argp);
1085 break;
1086 case MGSL_IOCGGPIO:
1087 ret = get_gpio(info, argp);
1088 break;
1089 case MGSL_IOCWAITGPIO:
1090 ret = wait_gpio(info, argp);
1091 break;
1092 case TIOCGICOUNT:
1093 spin_lock_irqsave(&info->lock,flags);
1094 cnow = info->icount;
1095 spin_unlock_irqrestore(&info->lock,flags);
1096 p_cuser = argp;
1097 if (put_user(cnow.cts, &p_cuser->cts) ||
1098 put_user(cnow.dsr, &p_cuser->dsr) ||
1099 put_user(cnow.rng, &p_cuser->rng) ||
1100 put_user(cnow.dcd, &p_cuser->dcd) ||
1101 put_user(cnow.rx, &p_cuser->rx) ||
1102 put_user(cnow.tx, &p_cuser->tx) ||
1103 put_user(cnow.frame, &p_cuser->frame) ||
1104 put_user(cnow.overrun, &p_cuser->overrun) ||
1105 put_user(cnow.parity, &p_cuser->parity) ||
1106 put_user(cnow.brk, &p_cuser->brk) ||
1107 put_user(cnow.buf_overrun, &p_cuser->buf_overrun))
1108 ret = -EFAULT;
1109 ret = 0;
1110 break;
1111 default: 1111 default:
1112 ret = -ENOIOCTLCMD; 1112 ret = -ENOIOCTLCMD;
1113 } 1113 }
1114 unlock_kernel(); 1114 mutex_unlock(&info->port.mutex);
1115 return ret; 1115 return ret;
1116} 1116}
1117 1117
@@ -3244,7 +3244,9 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
3244 } 3244 }
3245 3245
3246 DBGINFO(("%s block_til_ready wait\n", tty->driver->name)); 3246 DBGINFO(("%s block_til_ready wait\n", tty->driver->name));
3247 tty_unlock();
3247 schedule(); 3248 schedule();
3249 tty_lock();
3248 } 3250 }
3249 3251
3250 set_current_state(TASK_RUNNING); 3252 set_current_state(TASK_RUNNING);
diff --git a/drivers/char/synclinkmp.c b/drivers/char/synclinkmp.c
index 2b18adc4ee19..e56caf7d82aa 100644
--- a/drivers/char/synclinkmp.c
+++ b/drivers/char/synclinkmp.c
@@ -52,7 +52,6 @@
52#include <linux/mm.h> 52#include <linux/mm.h>
53#include <linux/seq_file.h> 53#include <linux/seq_file.h>
54#include <linux/slab.h> 54#include <linux/slab.h>
55#include <linux/smp_lock.h>
56#include <linux/netdevice.h> 55#include <linux/netdevice.h>
57#include <linux/vmalloc.h> 56#include <linux/vmalloc.h>
58#include <linux/init.h> 57#include <linux/init.h>
@@ -813,13 +812,15 @@ static void close(struct tty_struct *tty, struct file *filp)
813 812
814 if (tty_port_close_start(&info->port, tty, filp) == 0) 813 if (tty_port_close_start(&info->port, tty, filp) == 0)
815 goto cleanup; 814 goto cleanup;
816 815
816 mutex_lock(&info->port.mutex);
817 if (info->port.flags & ASYNC_INITIALIZED) 817 if (info->port.flags & ASYNC_INITIALIZED)
818 wait_until_sent(tty, info->timeout); 818 wait_until_sent(tty, info->timeout);
819 819
820 flush_buffer(tty); 820 flush_buffer(tty);
821 tty_ldisc_flush(tty); 821 tty_ldisc_flush(tty);
822 shutdown(info); 822 shutdown(info);
823 mutex_unlock(&info->port.mutex);
823 824
824 tty_port_close_end(&info->port, tty); 825 tty_port_close_end(&info->port, tty);
825 info->port.tty = NULL; 826 info->port.tty = NULL;
@@ -835,6 +836,7 @@ cleanup:
835static void hangup(struct tty_struct *tty) 836static void hangup(struct tty_struct *tty)
836{ 837{
837 SLMP_INFO *info = tty->driver_data; 838 SLMP_INFO *info = tty->driver_data;
839 unsigned long flags;
838 840
839 if (debug_level >= DEBUG_LEVEL_INFO) 841 if (debug_level >= DEBUG_LEVEL_INFO)
840 printk("%s(%d):%s hangup()\n", 842 printk("%s(%d):%s hangup()\n",
@@ -843,12 +845,16 @@ static void hangup(struct tty_struct *tty)
843 if (sanity_check(info, tty->name, "hangup")) 845 if (sanity_check(info, tty->name, "hangup"))
844 return; 846 return;
845 847
848 mutex_lock(&info->port.mutex);
846 flush_buffer(tty); 849 flush_buffer(tty);
847 shutdown(info); 850 shutdown(info);
848 851
852 spin_lock_irqsave(&info->port.lock, flags);
849 info->port.count = 0; 853 info->port.count = 0;
850 info->port.flags &= ~ASYNC_NORMAL_ACTIVE; 854 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
851 info->port.tty = NULL; 855 info->port.tty = NULL;
856 spin_unlock_irqrestore(&info->port.lock, flags);
857 mutex_unlock(&info->port.mutex);
852 858
853 wake_up_interruptible(&info->port.open_wait); 859 wake_up_interruptible(&info->port.open_wait);
854} 860}
@@ -1062,9 +1068,7 @@ static void wait_until_sent(struct tty_struct *tty, int timeout)
1062 if (sanity_check(info, tty->name, "wait_until_sent")) 1068 if (sanity_check(info, tty->name, "wait_until_sent"))
1063 return; 1069 return;
1064 1070
1065 lock_kernel(); 1071 if (!test_bit(ASYNCB_INITIALIZED, &info->port.flags))
1066
1067 if (!(info->port.flags & ASYNC_INITIALIZED))
1068 goto exit; 1072 goto exit;
1069 1073
1070 orig_jiffies = jiffies; 1074 orig_jiffies = jiffies;
@@ -1094,8 +1098,10 @@ static void wait_until_sent(struct tty_struct *tty, int timeout)
1094 break; 1098 break;
1095 } 1099 }
1096 } else { 1100 } else {
1097 //TODO: determine if there is something similar to USC16C32 1101 /*
1098 // TXSTATUS_ALL_SENT status 1102 * TODO: determine if there is something similar to USC16C32
1103 * TXSTATUS_ALL_SENT status
1104 */
1099 while ( info->tx_active && info->tx_enabled) { 1105 while ( info->tx_active && info->tx_enabled) {
1100 msleep_interruptible(jiffies_to_msecs(char_time)); 1106 msleep_interruptible(jiffies_to_msecs(char_time));
1101 if (signal_pending(current)) 1107 if (signal_pending(current))
@@ -1106,7 +1112,6 @@ static void wait_until_sent(struct tty_struct *tty, int timeout)
1106 } 1112 }
1107 1113
1108exit: 1114exit:
1109 unlock_kernel();
1110 if (debug_level >= DEBUG_LEVEL_INFO) 1115 if (debug_level >= DEBUG_LEVEL_INFO)
1111 printk("%s(%d):%s wait_until_sent() exit\n", 1116 printk("%s(%d):%s wait_until_sent() exit\n",
1112 __FILE__,__LINE__, info->device_name ); 1117 __FILE__,__LINE__, info->device_name );
@@ -1122,7 +1127,6 @@ static int write_room(struct tty_struct *tty)
1122 if (sanity_check(info, tty->name, "write_room")) 1127 if (sanity_check(info, tty->name, "write_room"))
1123 return 0; 1128 return 0;
1124 1129
1125 lock_kernel();
1126 if (info->params.mode == MGSL_MODE_HDLC) { 1130 if (info->params.mode == MGSL_MODE_HDLC) {
1127 ret = (info->tx_active) ? 0 : HDLC_MAX_FRAME_SIZE; 1131 ret = (info->tx_active) ? 0 : HDLC_MAX_FRAME_SIZE;
1128 } else { 1132 } else {
@@ -1130,7 +1134,6 @@ static int write_room(struct tty_struct *tty)
1130 if (ret < 0) 1134 if (ret < 0)
1131 ret = 0; 1135 ret = 0;
1132 } 1136 }
1133 unlock_kernel();
1134 1137
1135 if (debug_level >= DEBUG_LEVEL_INFO) 1138 if (debug_level >= DEBUG_LEVEL_INFO)
1136 printk("%s(%d):%s write_room()=%d\n", 1139 printk("%s(%d):%s write_room()=%d\n",
@@ -1251,7 +1254,7 @@ static void tx_release(struct tty_struct *tty)
1251 * 1254 *
1252 * Return Value: 0 if success, otherwise error code 1255 * Return Value: 0 if success, otherwise error code
1253 */ 1256 */
1254static int do_ioctl(struct tty_struct *tty, struct file *file, 1257static int ioctl(struct tty_struct *tty, struct file *file,
1255 unsigned int cmd, unsigned long arg) 1258 unsigned int cmd, unsigned long arg)
1256{ 1259{
1257 SLMP_INFO *info = tty->driver_data; 1260 SLMP_INFO *info = tty->driver_data;
@@ -1341,16 +1344,6 @@ static int do_ioctl(struct tty_struct *tty, struct file *file,
1341 return 0; 1344 return 0;
1342} 1345}
1343 1346
1344static int ioctl(struct tty_struct *tty, struct file *file,
1345 unsigned int cmd, unsigned long arg)
1346{
1347 int ret;
1348 lock_kernel();
1349 ret = do_ioctl(tty, file, cmd, arg);
1350 unlock_kernel();
1351 return ret;
1352}
1353
1354/* 1347/*
1355 * /proc fs routines.... 1348 * /proc fs routines....
1356 */ 1349 */
@@ -2883,7 +2876,9 @@ static int get_stats(SLMP_INFO * info, struct mgsl_icount __user *user_icount)
2883 if (!user_icount) { 2876 if (!user_icount) {
2884 memset(&info->icount, 0, sizeof(info->icount)); 2877 memset(&info->icount, 0, sizeof(info->icount));
2885 } else { 2878 } else {
2879 mutex_lock(&info->port.mutex);
2886 COPY_TO_USER(err, user_icount, &info->icount, sizeof(struct mgsl_icount)); 2880 COPY_TO_USER(err, user_icount, &info->icount, sizeof(struct mgsl_icount));
2881 mutex_unlock(&info->port.mutex);
2887 if (err) 2882 if (err)
2888 return -EFAULT; 2883 return -EFAULT;
2889 } 2884 }
@@ -2898,7 +2893,9 @@ static int get_params(SLMP_INFO * info, MGSL_PARAMS __user *user_params)
2898 printk("%s(%d):%s get_params()\n", 2893 printk("%s(%d):%s get_params()\n",
2899 __FILE__,__LINE__, info->device_name); 2894 __FILE__,__LINE__, info->device_name);
2900 2895
2896 mutex_lock(&info->port.mutex);
2901 COPY_TO_USER(err,user_params, &info->params, sizeof(MGSL_PARAMS)); 2897 COPY_TO_USER(err,user_params, &info->params, sizeof(MGSL_PARAMS));
2898 mutex_unlock(&info->port.mutex);
2902 if (err) { 2899 if (err) {
2903 if ( debug_level >= DEBUG_LEVEL_INFO ) 2900 if ( debug_level >= DEBUG_LEVEL_INFO )
2904 printk( "%s(%d):%s get_params() user buffer copy failed\n", 2901 printk( "%s(%d):%s get_params() user buffer copy failed\n",
@@ -2926,11 +2923,13 @@ static int set_params(SLMP_INFO * info, MGSL_PARAMS __user *new_params)
2926 return -EFAULT; 2923 return -EFAULT;
2927 } 2924 }
2928 2925
2926 mutex_lock(&info->port.mutex);
2929 spin_lock_irqsave(&info->lock,flags); 2927 spin_lock_irqsave(&info->lock,flags);
2930 memcpy(&info->params,&tmp_params,sizeof(MGSL_PARAMS)); 2928 memcpy(&info->params,&tmp_params,sizeof(MGSL_PARAMS));
2931 spin_unlock_irqrestore(&info->lock,flags); 2929 spin_unlock_irqrestore(&info->lock,flags);
2932 2930
2933 change_params(info); 2931 change_params(info);
2932 mutex_unlock(&info->port.mutex);
2934 2933
2935 return 0; 2934 return 0;
2936} 2935}
@@ -3366,7 +3365,9 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
3366 printk("%s(%d):%s block_til_ready() count=%d\n", 3365 printk("%s(%d):%s block_til_ready() count=%d\n",
3367 __FILE__,__LINE__, tty->driver->name, port->count ); 3366 __FILE__,__LINE__, tty->driver->name, port->count );
3368 3367
3368 tty_unlock();
3369 schedule(); 3369 schedule();
3370 tty_lock();
3370 } 3371 }
3371 3372
3372 set_current_state(TASK_RUNNING); 3373 set_current_state(TASK_RUNNING);
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index 507441ac6edb..0350c42375a2 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -149,6 +149,7 @@ static long tty_compat_ioctl(struct file *file, unsigned int cmd,
149#else 149#else
150#define tty_compat_ioctl NULL 150#define tty_compat_ioctl NULL
151#endif 151#endif
152static int __tty_fasync(int fd, struct file *filp, int on);
152static int tty_fasync(int fd, struct file *filp, int on); 153static int tty_fasync(int fd, struct file *filp, int on);
153static void release_tty(struct tty_struct *tty, int idx); 154static void release_tty(struct tty_struct *tty, int idx);
154static void __proc_set_tty(struct task_struct *tsk, struct tty_struct *tty); 155static void __proc_set_tty(struct task_struct *tsk, struct tty_struct *tty);
@@ -470,7 +471,7 @@ void tty_wakeup(struct tty_struct *tty)
470EXPORT_SYMBOL_GPL(tty_wakeup); 471EXPORT_SYMBOL_GPL(tty_wakeup);
471 472
472/** 473/**
473 * do_tty_hangup - actual handler for hangup events 474 * __tty_hangup - actual handler for hangup events
474 * @work: tty device 475 * @work: tty device
475 * 476 *
476 * This can be called by the "eventd" kernel thread. That is process 477 * This can be called by the "eventd" kernel thread. That is process
@@ -483,7 +484,7 @@ EXPORT_SYMBOL_GPL(tty_wakeup);
483 * remains intact. 484 * remains intact.
484 * 485 *
485 * Locking: 486 * Locking:
486 * BKL 487 * BTM
487 * redirect lock for undoing redirection 488 * redirect lock for undoing redirection
488 * file list lock for manipulating list of ttys 489 * file list lock for manipulating list of ttys
489 * tty_ldisc_lock from called functions 490 * tty_ldisc_lock from called functions
@@ -491,10 +492,8 @@ EXPORT_SYMBOL_GPL(tty_wakeup);
491 * tasklist_lock to walk task list for hangup event 492 * tasklist_lock to walk task list for hangup event
492 * ->siglock to protect ->signal/->sighand 493 * ->siglock to protect ->signal/->sighand
493 */ 494 */
494static void do_tty_hangup(struct work_struct *work) 495void __tty_hangup(struct tty_struct *tty)
495{ 496{
496 struct tty_struct *tty =
497 container_of(work, struct tty_struct, hangup_work);
498 struct file *cons_filp = NULL; 497 struct file *cons_filp = NULL;
499 struct file *filp, *f = NULL; 498 struct file *filp, *f = NULL;
500 struct task_struct *p; 499 struct task_struct *p;
@@ -513,9 +512,12 @@ static void do_tty_hangup(struct work_struct *work)
513 } 512 }
514 spin_unlock(&redirect_lock); 513 spin_unlock(&redirect_lock);
515 514
516 /* inuse_filps is protected by the single kernel lock */ 515 tty_lock();
517 lock_kernel(); 516
518 check_tty_count(tty, "do_tty_hangup"); 517 /* inuse_filps is protected by the single tty lock,
518 this really needs to change if we want to flush the
519 workqueue with the lock held */
520 check_tty_count(tty, "tty_hangup");
519 521
520 file_list_lock(); 522 file_list_lock();
521 /* This breaks for file handles being sent over AF_UNIX sockets ? */ 523 /* This breaks for file handles being sent over AF_UNIX sockets ? */
@@ -525,7 +527,7 @@ static void do_tty_hangup(struct work_struct *work)
525 if (filp->f_op->write != tty_write) 527 if (filp->f_op->write != tty_write)
526 continue; 528 continue;
527 closecount++; 529 closecount++;
528 tty_fasync(-1, filp, 0); /* can't block */ 530 __tty_fasync(-1, filp, 0); /* can't block */
529 filp->f_op = &hung_up_tty_fops; 531 filp->f_op = &hung_up_tty_fops;
530 } 532 }
531 file_list_unlock(); 533 file_list_unlock();
@@ -594,11 +596,21 @@ static void do_tty_hangup(struct work_struct *work)
594 */ 596 */
595 set_bit(TTY_HUPPED, &tty->flags); 597 set_bit(TTY_HUPPED, &tty->flags);
596 tty_ldisc_enable(tty); 598 tty_ldisc_enable(tty);
597 unlock_kernel(); 599
600 tty_unlock();
601
598 if (f) 602 if (f)
599 fput(f); 603 fput(f);
600} 604}
601 605
606static void do_tty_hangup(struct work_struct *work)
607{
608 struct tty_struct *tty =
609 container_of(work, struct tty_struct, hangup_work);
610
611 __tty_hangup(tty);
612}
613
602/** 614/**
603 * tty_hangup - trigger a hangup event 615 * tty_hangup - trigger a hangup event
604 * @tty: tty to hangup 616 * @tty: tty to hangup
@@ -634,11 +646,12 @@ void tty_vhangup(struct tty_struct *tty)
634 646
635 printk(KERN_DEBUG "%s vhangup...\n", tty_name(tty, buf)); 647 printk(KERN_DEBUG "%s vhangup...\n", tty_name(tty, buf));
636#endif 648#endif
637 do_tty_hangup(&tty->hangup_work); 649 __tty_hangup(tty);
638} 650}
639 651
640EXPORT_SYMBOL(tty_vhangup); 652EXPORT_SYMBOL(tty_vhangup);
641 653
654
642/** 655/**
643 * tty_vhangup_self - process vhangup for own ctty 656 * tty_vhangup_self - process vhangup for own ctty
644 * 657 *
@@ -696,7 +709,8 @@ static void session_clear_tty(struct pid *session)
696 * exiting; it is 0 if called by the ioctl TIOCNOTTY. 709 * exiting; it is 0 if called by the ioctl TIOCNOTTY.
697 * 710 *
698 * Locking: 711 * Locking:
699 * BKL is taken for hysterical raisins 712 * BTM is taken for hysterical raisins, and held when
713 * called from no_tty().
700 * tty_mutex is taken to protect tty 714 * tty_mutex is taken to protect tty
701 * ->siglock is taken to protect ->signal/->sighand 715 * ->siglock is taken to protect ->signal/->sighand
702 * tasklist_lock is taken to walk process list for sessions 716 * tasklist_lock is taken to walk process list for sessions
@@ -714,10 +728,10 @@ void disassociate_ctty(int on_exit)
714 tty = get_current_tty(); 728 tty = get_current_tty();
715 if (tty) { 729 if (tty) {
716 tty_pgrp = get_pid(tty->pgrp); 730 tty_pgrp = get_pid(tty->pgrp);
717 lock_kernel(); 731 if (on_exit) {
718 if (on_exit && tty->driver->type != TTY_DRIVER_TYPE_PTY) 732 if (tty->driver->type != TTY_DRIVER_TYPE_PTY)
719 tty_vhangup(tty); 733 tty_vhangup(tty);
720 unlock_kernel(); 734 }
721 tty_kref_put(tty); 735 tty_kref_put(tty);
722 } else if (on_exit) { 736 } else if (on_exit) {
723 struct pid *old_pgrp; 737 struct pid *old_pgrp;
@@ -774,9 +788,9 @@ void disassociate_ctty(int on_exit)
774void no_tty(void) 788void no_tty(void)
775{ 789{
776 struct task_struct *tsk = current; 790 struct task_struct *tsk = current;
777 lock_kernel(); 791 tty_lock();
778 disassociate_ctty(0); 792 disassociate_ctty(0);
779 unlock_kernel(); 793 tty_unlock();
780 proc_clear_tty(tsk); 794 proc_clear_tty(tsk);
781} 795}
782 796
@@ -879,7 +893,7 @@ static ssize_t tty_read(struct file *file, char __user *buf, size_t count,
879 struct inode *inode; 893 struct inode *inode;
880 struct tty_ldisc *ld; 894 struct tty_ldisc *ld;
881 895
882 tty = (struct tty_struct *)file->private_data; 896 tty = file->private_data;
883 inode = file->f_path.dentry->d_inode; 897 inode = file->f_path.dentry->d_inode;
884 if (tty_paranoia_check(tty, inode, "tty_read")) 898 if (tty_paranoia_check(tty, inode, "tty_read"))
885 return -EIO; 899 return -EIO;
@@ -1013,19 +1027,19 @@ out:
1013 * We don't put it into the syslog queue right now maybe in the future if 1027 * We don't put it into the syslog queue right now maybe in the future if
1014 * really needed. 1028 * really needed.
1015 * 1029 *
1016 * We must still hold the BKL and test the CLOSING flag for the moment. 1030 * We must still hold the BTM and test the CLOSING flag for the moment.
1017 */ 1031 */
1018 1032
1019void tty_write_message(struct tty_struct *tty, char *msg) 1033void tty_write_message(struct tty_struct *tty, char *msg)
1020{ 1034{
1021 if (tty) { 1035 if (tty) {
1022 mutex_lock(&tty->atomic_write_lock); 1036 mutex_lock(&tty->atomic_write_lock);
1023 lock_kernel(); 1037 tty_lock();
1024 if (tty->ops->write && !test_bit(TTY_CLOSING, &tty->flags)) { 1038 if (tty->ops->write && !test_bit(TTY_CLOSING, &tty->flags)) {
1025 unlock_kernel(); 1039 tty_unlock();
1026 tty->ops->write(tty, msg, strlen(msg)); 1040 tty->ops->write(tty, msg, strlen(msg));
1027 } else 1041 } else
1028 unlock_kernel(); 1042 tty_unlock();
1029 tty_write_unlock(tty); 1043 tty_write_unlock(tty);
1030 } 1044 }
1031 return; 1045 return;
@@ -1056,7 +1070,7 @@ static ssize_t tty_write(struct file *file, const char __user *buf,
1056 ssize_t ret; 1070 ssize_t ret;
1057 struct tty_ldisc *ld; 1071 struct tty_ldisc *ld;
1058 1072
1059 tty = (struct tty_struct *)file->private_data; 1073 tty = file->private_data;
1060 if (tty_paranoia_check(tty, inode, "tty_write")) 1074 if (tty_paranoia_check(tty, inode, "tty_write"))
1061 return -EIO; 1075 return -EIO;
1062 if (!tty || !tty->ops->write || 1076 if (!tty || !tty->ops->write ||
@@ -1208,18 +1222,14 @@ static int tty_driver_install_tty(struct tty_driver *driver,
1208 int ret; 1222 int ret;
1209 1223
1210 if (driver->ops->install) { 1224 if (driver->ops->install) {
1211 lock_kernel();
1212 ret = driver->ops->install(driver, tty); 1225 ret = driver->ops->install(driver, tty);
1213 unlock_kernel();
1214 return ret; 1226 return ret;
1215 } 1227 }
1216 1228
1217 if (tty_init_termios(tty) == 0) { 1229 if (tty_init_termios(tty) == 0) {
1218 lock_kernel();
1219 tty_driver_kref_get(driver); 1230 tty_driver_kref_get(driver);
1220 tty->count++; 1231 tty->count++;
1221 driver->ttys[idx] = tty; 1232 driver->ttys[idx] = tty;
1222 unlock_kernel();
1223 return 0; 1233 return 0;
1224 } 1234 }
1225 return -ENOMEM; 1235 return -ENOMEM;
@@ -1312,14 +1322,11 @@ struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx,
1312 struct tty_struct *tty; 1322 struct tty_struct *tty;
1313 int retval; 1323 int retval;
1314 1324
1315 lock_kernel();
1316 /* Check if pty master is being opened multiple times */ 1325 /* Check if pty master is being opened multiple times */
1317 if (driver->subtype == PTY_TYPE_MASTER && 1326 if (driver->subtype == PTY_TYPE_MASTER &&
1318 (driver->flags & TTY_DRIVER_DEVPTS_MEM) && !first_ok) { 1327 (driver->flags & TTY_DRIVER_DEVPTS_MEM) && !first_ok) {
1319 unlock_kernel();
1320 return ERR_PTR(-EIO); 1328 return ERR_PTR(-EIO);
1321 } 1329 }
1322 unlock_kernel();
1323 1330
1324 /* 1331 /*
1325 * First time open is complex, especially for PTY devices. 1332 * First time open is complex, especially for PTY devices.
@@ -1363,9 +1370,7 @@ release_mem_out:
1363 if (printk_ratelimit()) 1370 if (printk_ratelimit())
1364 printk(KERN_INFO "tty_init_dev: ldisc open failed, " 1371 printk(KERN_INFO "tty_init_dev: ldisc open failed, "
1365 "clearing slot %d\n", idx); 1372 "clearing slot %d\n", idx);
1366 lock_kernel();
1367 release_tty(tty, idx); 1373 release_tty(tty, idx);
1368 unlock_kernel();
1369 return ERR_PTR(retval); 1374 return ERR_PTR(retval);
1370} 1375}
1371 1376
@@ -1508,14 +1513,14 @@ int tty_release(struct inode *inode, struct file *filp)
1508 int idx; 1513 int idx;
1509 char buf[64]; 1514 char buf[64];
1510 1515
1511 tty = (struct tty_struct *)filp->private_data; 1516 tty = filp->private_data;
1512 if (tty_paranoia_check(tty, inode, "tty_release_dev")) 1517 if (tty_paranoia_check(tty, inode, "tty_release_dev"))
1513 return 0; 1518 return 0;
1514 1519
1515 lock_kernel(); 1520 tty_lock();
1516 check_tty_count(tty, "tty_release_dev"); 1521 check_tty_count(tty, "tty_release_dev");
1517 1522
1518 tty_fasync(-1, filp, 0); 1523 __tty_fasync(-1, filp, 0);
1519 1524
1520 idx = tty->index; 1525 idx = tty->index;
1521 pty_master = (tty->driver->type == TTY_DRIVER_TYPE_PTY && 1526 pty_master = (tty->driver->type == TTY_DRIVER_TYPE_PTY &&
@@ -1527,18 +1532,18 @@ int tty_release(struct inode *inode, struct file *filp)
1527 if (idx < 0 || idx >= tty->driver->num) { 1532 if (idx < 0 || idx >= tty->driver->num) {
1528 printk(KERN_DEBUG "tty_release_dev: bad idx when trying to " 1533 printk(KERN_DEBUG "tty_release_dev: bad idx when trying to "
1529 "free (%s)\n", tty->name); 1534 "free (%s)\n", tty->name);
1530 unlock_kernel(); 1535 tty_unlock();
1531 return 0; 1536 return 0;
1532 } 1537 }
1533 if (!devpts) { 1538 if (!devpts) {
1534 if (tty != tty->driver->ttys[idx]) { 1539 if (tty != tty->driver->ttys[idx]) {
1535 unlock_kernel(); 1540 tty_unlock();
1536 printk(KERN_DEBUG "tty_release_dev: driver.table[%d] not tty " 1541 printk(KERN_DEBUG "tty_release_dev: driver.table[%d] not tty "
1537 "for (%s)\n", idx, tty->name); 1542 "for (%s)\n", idx, tty->name);
1538 return 0; 1543 return 0;
1539 } 1544 }
1540 if (tty->termios != tty->driver->termios[idx]) { 1545 if (tty->termios != tty->driver->termios[idx]) {
1541 unlock_kernel(); 1546 tty_unlock();
1542 printk(KERN_DEBUG "tty_release_dev: driver.termios[%d] not termios " 1547 printk(KERN_DEBUG "tty_release_dev: driver.termios[%d] not termios "
1543 "for (%s)\n", 1548 "for (%s)\n",
1544 idx, tty->name); 1549 idx, tty->name);
@@ -1556,21 +1561,21 @@ int tty_release(struct inode *inode, struct file *filp)
1556 if (tty->driver->other && 1561 if (tty->driver->other &&
1557 !(tty->driver->flags & TTY_DRIVER_DEVPTS_MEM)) { 1562 !(tty->driver->flags & TTY_DRIVER_DEVPTS_MEM)) {
1558 if (o_tty != tty->driver->other->ttys[idx]) { 1563 if (o_tty != tty->driver->other->ttys[idx]) {
1559 unlock_kernel(); 1564 tty_unlock();
1560 printk(KERN_DEBUG "tty_release_dev: other->table[%d] " 1565 printk(KERN_DEBUG "tty_release_dev: other->table[%d] "
1561 "not o_tty for (%s)\n", 1566 "not o_tty for (%s)\n",
1562 idx, tty->name); 1567 idx, tty->name);
1563 return 0 ; 1568 return 0 ;
1564 } 1569 }
1565 if (o_tty->termios != tty->driver->other->termios[idx]) { 1570 if (o_tty->termios != tty->driver->other->termios[idx]) {
1566 unlock_kernel(); 1571 tty_unlock();
1567 printk(KERN_DEBUG "tty_release_dev: other->termios[%d] " 1572 printk(KERN_DEBUG "tty_release_dev: other->termios[%d] "
1568 "not o_termios for (%s)\n", 1573 "not o_termios for (%s)\n",
1569 idx, tty->name); 1574 idx, tty->name);
1570 return 0; 1575 return 0;
1571 } 1576 }
1572 if (o_tty->link != tty) { 1577 if (o_tty->link != tty) {
1573 unlock_kernel(); 1578 tty_unlock();
1574 printk(KERN_DEBUG "tty_release_dev: bad pty pointers\n"); 1579 printk(KERN_DEBUG "tty_release_dev: bad pty pointers\n");
1575 return 0; 1580 return 0;
1576 } 1581 }
@@ -1579,7 +1584,7 @@ int tty_release(struct inode *inode, struct file *filp)
1579 if (tty->ops->close) 1584 if (tty->ops->close)
1580 tty->ops->close(tty, filp); 1585 tty->ops->close(tty, filp);
1581 1586
1582 unlock_kernel(); 1587 tty_unlock();
1583 /* 1588 /*
1584 * Sanity check: if tty->count is going to zero, there shouldn't be 1589 * Sanity check: if tty->count is going to zero, there shouldn't be
1585 * any waiters on tty->read_wait or tty->write_wait. We test the 1590 * any waiters on tty->read_wait or tty->write_wait. We test the
@@ -1602,7 +1607,7 @@ int tty_release(struct inode *inode, struct file *filp)
1602 opens on /dev/tty */ 1607 opens on /dev/tty */
1603 1608
1604 mutex_lock(&tty_mutex); 1609 mutex_lock(&tty_mutex);
1605 lock_kernel(); 1610 tty_lock();
1606 tty_closing = tty->count <= 1; 1611 tty_closing = tty->count <= 1;
1607 o_tty_closing = o_tty && 1612 o_tty_closing = o_tty &&
1608 (o_tty->count <= (pty_master ? 1 : 0)); 1613 (o_tty->count <= (pty_master ? 1 : 0));
@@ -1633,7 +1638,7 @@ int tty_release(struct inode *inode, struct file *filp)
1633 1638
1634 printk(KERN_WARNING "tty_release_dev: %s: read/write wait queue " 1639 printk(KERN_WARNING "tty_release_dev: %s: read/write wait queue "
1635 "active!\n", tty_name(tty, buf)); 1640 "active!\n", tty_name(tty, buf));
1636 unlock_kernel(); 1641 tty_unlock();
1637 mutex_unlock(&tty_mutex); 1642 mutex_unlock(&tty_mutex);
1638 schedule(); 1643 schedule();
1639 } 1644 }
@@ -1698,7 +1703,7 @@ int tty_release(struct inode *inode, struct file *filp)
1698 1703
1699 /* check whether both sides are closing ... */ 1704 /* check whether both sides are closing ... */
1700 if (!tty_closing || (o_tty && !o_tty_closing)) { 1705 if (!tty_closing || (o_tty && !o_tty_closing)) {
1701 unlock_kernel(); 1706 tty_unlock();
1702 return 0; 1707 return 0;
1703 } 1708 }
1704 1709
@@ -1718,7 +1723,7 @@ int tty_release(struct inode *inode, struct file *filp)
1718 /* Make this pty number available for reallocation */ 1723 /* Make this pty number available for reallocation */
1719 if (devpts) 1724 if (devpts)
1720 devpts_kill_index(inode, idx); 1725 devpts_kill_index(inode, idx);
1721 unlock_kernel(); 1726 tty_unlock();
1722 return 0; 1727 return 0;
1723} 1728}
1724 1729
@@ -1760,12 +1765,12 @@ retry_open:
1760 retval = 0; 1765 retval = 0;
1761 1766
1762 mutex_lock(&tty_mutex); 1767 mutex_lock(&tty_mutex);
1763 lock_kernel(); 1768 tty_lock();
1764 1769
1765 if (device == MKDEV(TTYAUX_MAJOR, 0)) { 1770 if (device == MKDEV(TTYAUX_MAJOR, 0)) {
1766 tty = get_current_tty(); 1771 tty = get_current_tty();
1767 if (!tty) { 1772 if (!tty) {
1768 unlock_kernel(); 1773 tty_unlock();
1769 mutex_unlock(&tty_mutex); 1774 mutex_unlock(&tty_mutex);
1770 return -ENXIO; 1775 return -ENXIO;
1771 } 1776 }
@@ -1797,14 +1802,14 @@ retry_open:
1797 goto got_driver; 1802 goto got_driver;
1798 } 1803 }
1799 } 1804 }
1800 unlock_kernel(); 1805 tty_unlock();
1801 mutex_unlock(&tty_mutex); 1806 mutex_unlock(&tty_mutex);
1802 return -ENODEV; 1807 return -ENODEV;
1803 } 1808 }
1804 1809
1805 driver = get_tty_driver(device, &index); 1810 driver = get_tty_driver(device, &index);
1806 if (!driver) { 1811 if (!driver) {
1807 unlock_kernel(); 1812 tty_unlock();
1808 mutex_unlock(&tty_mutex); 1813 mutex_unlock(&tty_mutex);
1809 return -ENODEV; 1814 return -ENODEV;
1810 } 1815 }
@@ -1814,7 +1819,7 @@ got_driver:
1814 tty = tty_driver_lookup_tty(driver, inode, index); 1819 tty = tty_driver_lookup_tty(driver, inode, index);
1815 1820
1816 if (IS_ERR(tty)) { 1821 if (IS_ERR(tty)) {
1817 unlock_kernel(); 1822 tty_unlock();
1818 mutex_unlock(&tty_mutex); 1823 mutex_unlock(&tty_mutex);
1819 return PTR_ERR(tty); 1824 return PTR_ERR(tty);
1820 } 1825 }
@@ -1830,7 +1835,7 @@ got_driver:
1830 mutex_unlock(&tty_mutex); 1835 mutex_unlock(&tty_mutex);
1831 tty_driver_kref_put(driver); 1836 tty_driver_kref_put(driver);
1832 if (IS_ERR(tty)) { 1837 if (IS_ERR(tty)) {
1833 unlock_kernel(); 1838 tty_unlock();
1834 return PTR_ERR(tty); 1839 return PTR_ERR(tty);
1835 } 1840 }
1836 1841
@@ -1860,29 +1865,29 @@ got_driver:
1860 printk(KERN_DEBUG "error %d in opening %s...", retval, 1865 printk(KERN_DEBUG "error %d in opening %s...", retval,
1861 tty->name); 1866 tty->name);
1862#endif 1867#endif
1868 tty_unlock(); /* need to call tty_release without BTM */
1863 tty_release(inode, filp); 1869 tty_release(inode, filp);
1864 if (retval != -ERESTARTSYS) { 1870 if (retval != -ERESTARTSYS)
1865 unlock_kernel();
1866 return retval; 1871 return retval;
1867 } 1872
1868 if (signal_pending(current)) { 1873 if (signal_pending(current))
1869 unlock_kernel();
1870 return retval; 1874 return retval;
1871 } 1875
1872 schedule(); 1876 schedule();
1873 /* 1877 /*
1874 * Need to reset f_op in case a hangup happened. 1878 * Need to reset f_op in case a hangup happened.
1875 */ 1879 */
1880 tty_lock();
1876 if (filp->f_op == &hung_up_tty_fops) 1881 if (filp->f_op == &hung_up_tty_fops)
1877 filp->f_op = &tty_fops; 1882 filp->f_op = &tty_fops;
1878 unlock_kernel(); 1883 tty_unlock();
1879 goto retry_open; 1884 goto retry_open;
1880 } 1885 }
1881 unlock_kernel(); 1886 tty_unlock();
1882 1887
1883 1888
1884 mutex_lock(&tty_mutex); 1889 mutex_lock(&tty_mutex);
1885 lock_kernel(); 1890 tty_lock();
1886 spin_lock_irq(&current->sighand->siglock); 1891 spin_lock_irq(&current->sighand->siglock);
1887 if (!noctty && 1892 if (!noctty &&
1888 current->signal->leader && 1893 current->signal->leader &&
@@ -1890,7 +1895,7 @@ got_driver:
1890 tty->session == NULL) 1895 tty->session == NULL)
1891 __proc_set_tty(current, tty); 1896 __proc_set_tty(current, tty);
1892 spin_unlock_irq(&current->sighand->siglock); 1897 spin_unlock_irq(&current->sighand->siglock);
1893 unlock_kernel(); 1898 tty_unlock();
1894 mutex_unlock(&tty_mutex); 1899 mutex_unlock(&tty_mutex);
1895 return 0; 1900 return 0;
1896} 1901}
@@ -1915,7 +1920,7 @@ static unsigned int tty_poll(struct file *filp, poll_table *wait)
1915 struct tty_ldisc *ld; 1920 struct tty_ldisc *ld;
1916 int ret = 0; 1921 int ret = 0;
1917 1922
1918 tty = (struct tty_struct *)filp->private_data; 1923 tty = filp->private_data;
1919 if (tty_paranoia_check(tty, filp->f_path.dentry->d_inode, "tty_poll")) 1924 if (tty_paranoia_check(tty, filp->f_path.dentry->d_inode, "tty_poll"))
1920 return 0; 1925 return 0;
1921 1926
@@ -1926,14 +1931,13 @@ static unsigned int tty_poll(struct file *filp, poll_table *wait)
1926 return ret; 1931 return ret;
1927} 1932}
1928 1933
1929static int tty_fasync(int fd, struct file *filp, int on) 1934static int __tty_fasync(int fd, struct file *filp, int on)
1930{ 1935{
1931 struct tty_struct *tty; 1936 struct tty_struct *tty;
1932 unsigned long flags; 1937 unsigned long flags;
1933 int retval = 0; 1938 int retval = 0;
1934 1939
1935 lock_kernel(); 1940 tty = filp->private_data;
1936 tty = (struct tty_struct *)filp->private_data;
1937 if (tty_paranoia_check(tty, filp->f_path.dentry->d_inode, "tty_fasync")) 1941 if (tty_paranoia_check(tty, filp->f_path.dentry->d_inode, "tty_fasync"))
1938 goto out; 1942 goto out;
1939 1943
@@ -1966,7 +1970,15 @@ static int tty_fasync(int fd, struct file *filp, int on)
1966 } 1970 }
1967 retval = 0; 1971 retval = 0;
1968out: 1972out:
1969 unlock_kernel(); 1973 return retval;
1974}
1975
1976static int tty_fasync(int fd, struct file *filp, int on)
1977{
1978 int retval;
1979 tty_lock();
1980 retval = __tty_fasync(fd, filp, on);
1981 tty_unlock();
1970 return retval; 1982 return retval;
1971} 1983}
1972 1984
@@ -2485,7 +2497,7 @@ long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
2485 struct tty_ldisc *ld; 2497 struct tty_ldisc *ld;
2486 struct inode *inode = file->f_dentry->d_inode; 2498 struct inode *inode = file->f_dentry->d_inode;
2487 2499
2488 tty = (struct tty_struct *)file->private_data; 2500 tty = file->private_data;
2489 if (tty_paranoia_check(tty, inode, "tty_ioctl")) 2501 if (tty_paranoia_check(tty, inode, "tty_ioctl"))
2490 return -EINVAL; 2502 return -EINVAL;
2491 2503
diff --git a/drivers/char/tty_ioctl.c b/drivers/char/tty_ioctl.c
index 6bd5f8866c74..0c1889971459 100644
--- a/drivers/char/tty_ioctl.c
+++ b/drivers/char/tty_ioctl.c
@@ -517,19 +517,25 @@ static void change_termios(struct tty_struct *tty, struct ktermios *new_termios)
517 517
518 /* See if packet mode change of state. */ 518 /* See if packet mode change of state. */
519 if (tty->link && tty->link->packet) { 519 if (tty->link && tty->link->packet) {
520 int extproc = (old_termios.c_lflag & EXTPROC) |
521 (tty->termios->c_lflag & EXTPROC);
520 int old_flow = ((old_termios.c_iflag & IXON) && 522 int old_flow = ((old_termios.c_iflag & IXON) &&
521 (old_termios.c_cc[VSTOP] == '\023') && 523 (old_termios.c_cc[VSTOP] == '\023') &&
522 (old_termios.c_cc[VSTART] == '\021')); 524 (old_termios.c_cc[VSTART] == '\021'));
523 int new_flow = (I_IXON(tty) && 525 int new_flow = (I_IXON(tty) &&
524 STOP_CHAR(tty) == '\023' && 526 STOP_CHAR(tty) == '\023' &&
525 START_CHAR(tty) == '\021'); 527 START_CHAR(tty) == '\021');
526 if (old_flow != new_flow) { 528 if ((old_flow != new_flow) || extproc) {
527 spin_lock_irqsave(&tty->ctrl_lock, flags); 529 spin_lock_irqsave(&tty->ctrl_lock, flags);
528 tty->ctrl_status &= ~(TIOCPKT_DOSTOP | TIOCPKT_NOSTOP); 530 if (old_flow != new_flow) {
529 if (new_flow) 531 tty->ctrl_status &= ~(TIOCPKT_DOSTOP | TIOCPKT_NOSTOP);
530 tty->ctrl_status |= TIOCPKT_DOSTOP; 532 if (new_flow)
531 else 533 tty->ctrl_status |= TIOCPKT_DOSTOP;
532 tty->ctrl_status |= TIOCPKT_NOSTOP; 534 else
535 tty->ctrl_status |= TIOCPKT_NOSTOP;
536 }
537 if (extproc)
538 tty->ctrl_status |= TIOCPKT_IOCTL;
533 spin_unlock_irqrestore(&tty->ctrl_lock, flags); 539 spin_unlock_irqrestore(&tty->ctrl_lock, flags);
534 wake_up_interruptible(&tty->link->read_wait); 540 wake_up_interruptible(&tty->link->read_wait);
535 } 541 }
diff --git a/drivers/char/tty_ldisc.c b/drivers/char/tty_ldisc.c
index 500e740ec5e4..412f9775d19c 100644
--- a/drivers/char/tty_ldisc.c
+++ b/drivers/char/tty_ldisc.c
@@ -440,6 +440,8 @@ static void tty_set_termios_ldisc(struct tty_struct *tty, int num)
440 * 440 *
441 * A helper opening method. Also a convenient debugging and check 441 * A helper opening method. Also a convenient debugging and check
442 * point. 442 * point.
443 *
444 * Locking: always called with BTM already held.
443 */ 445 */
444 446
445static int tty_ldisc_open(struct tty_struct *tty, struct tty_ldisc *ld) 447static int tty_ldisc_open(struct tty_struct *tty, struct tty_ldisc *ld)
@@ -447,10 +449,9 @@ static int tty_ldisc_open(struct tty_struct *tty, struct tty_ldisc *ld)
447 WARN_ON(test_and_set_bit(TTY_LDISC_OPEN, &tty->flags)); 449 WARN_ON(test_and_set_bit(TTY_LDISC_OPEN, &tty->flags));
448 if (ld->ops->open) { 450 if (ld->ops->open) {
449 int ret; 451 int ret;
450 /* BKL here locks verus a hangup event */ 452 /* BTM here locks versus a hangup event */
451 lock_kernel(); 453 WARN_ON(!tty_locked());
452 ret = ld->ops->open(tty); 454 ret = ld->ops->open(tty);
453 unlock_kernel();
454 return ret; 455 return ret;
455 } 456 }
456 return 0; 457 return 0;
@@ -553,7 +554,7 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
553 if (IS_ERR(new_ldisc)) 554 if (IS_ERR(new_ldisc))
554 return PTR_ERR(new_ldisc); 555 return PTR_ERR(new_ldisc);
555 556
556 lock_kernel(); 557 tty_lock();
557 /* 558 /*
558 * We need to look at the tty locking here for pty/tty pairs 559 * We need to look at the tty locking here for pty/tty pairs
559 * when both sides try to change in parallel. 560 * when both sides try to change in parallel.
@@ -567,12 +568,12 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
567 */ 568 */
568 569
569 if (tty->ldisc->ops->num == ldisc) { 570 if (tty->ldisc->ops->num == ldisc) {
570 unlock_kernel(); 571 tty_unlock();
571 tty_ldisc_put(new_ldisc); 572 tty_ldisc_put(new_ldisc);
572 return 0; 573 return 0;
573 } 574 }
574 575
575 unlock_kernel(); 576 tty_unlock();
576 /* 577 /*
577 * Problem: What do we do if this blocks ? 578 * Problem: What do we do if this blocks ?
578 * We could deadlock here 579 * We could deadlock here
@@ -580,6 +581,7 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
580 581
581 tty_wait_until_sent(tty, 0); 582 tty_wait_until_sent(tty, 0);
582 583
584 tty_lock();
583 mutex_lock(&tty->ldisc_mutex); 585 mutex_lock(&tty->ldisc_mutex);
584 586
585 /* 587 /*
@@ -589,13 +591,13 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
589 591
590 while (test_bit(TTY_LDISC_CHANGING, &tty->flags)) { 592 while (test_bit(TTY_LDISC_CHANGING, &tty->flags)) {
591 mutex_unlock(&tty->ldisc_mutex); 593 mutex_unlock(&tty->ldisc_mutex);
594 tty_unlock();
592 wait_event(tty_ldisc_wait, 595 wait_event(tty_ldisc_wait,
593 test_bit(TTY_LDISC_CHANGING, &tty->flags) == 0); 596 test_bit(TTY_LDISC_CHANGING, &tty->flags) == 0);
597 tty_lock();
594 mutex_lock(&tty->ldisc_mutex); 598 mutex_lock(&tty->ldisc_mutex);
595 } 599 }
596 600
597 lock_kernel();
598
599 set_bit(TTY_LDISC_CHANGING, &tty->flags); 601 set_bit(TTY_LDISC_CHANGING, &tty->flags);
600 602
601 /* 603 /*
@@ -607,7 +609,7 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
607 609
608 o_ldisc = tty->ldisc; 610 o_ldisc = tty->ldisc;
609 611
610 unlock_kernel(); 612 tty_unlock();
611 /* 613 /*
612 * Make sure we don't change while someone holds a 614 * Make sure we don't change while someone holds a
613 * reference to the line discipline. The TTY_LDISC bit 615 * reference to the line discipline. The TTY_LDISC bit
@@ -632,15 +634,15 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
632 634
633 flush_scheduled_work(); 635 flush_scheduled_work();
634 636
637 tty_lock();
635 mutex_lock(&tty->ldisc_mutex); 638 mutex_lock(&tty->ldisc_mutex);
636 lock_kernel();
637 if (test_bit(TTY_HUPPED, &tty->flags)) { 639 if (test_bit(TTY_HUPPED, &tty->flags)) {
638 /* We were raced by the hangup method. It will have stomped 640 /* We were raced by the hangup method. It will have stomped
639 the ldisc data and closed the ldisc down */ 641 the ldisc data and closed the ldisc down */
640 clear_bit(TTY_LDISC_CHANGING, &tty->flags); 642 clear_bit(TTY_LDISC_CHANGING, &tty->flags);
641 mutex_unlock(&tty->ldisc_mutex); 643 mutex_unlock(&tty->ldisc_mutex);
642 tty_ldisc_put(new_ldisc); 644 tty_ldisc_put(new_ldisc);
643 unlock_kernel(); 645 tty_unlock();
644 return -EIO; 646 return -EIO;
645 } 647 }
646 648
@@ -682,7 +684,7 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
682 if (o_work) 684 if (o_work)
683 schedule_delayed_work(&o_tty->buf.work, 1); 685 schedule_delayed_work(&o_tty->buf.work, 1);
684 mutex_unlock(&tty->ldisc_mutex); 686 mutex_unlock(&tty->ldisc_mutex);
685 unlock_kernel(); 687 tty_unlock();
686 return retval; 688 return retval;
687} 689}
688 690
@@ -780,7 +782,20 @@ void tty_ldisc_hangup(struct tty_struct *tty)
780 * Avoid racing set_ldisc or tty_ldisc_release 782 * Avoid racing set_ldisc or tty_ldisc_release
781 */ 783 */
782 mutex_lock(&tty->ldisc_mutex); 784 mutex_lock(&tty->ldisc_mutex);
783 tty_ldisc_halt(tty); 785
786 /*
787 * this is like tty_ldisc_halt, but we need to give up
788 * the BTM before calling cancel_delayed_work_sync,
789 * which may need to wait for another function taking the BTM
790 */
791 clear_bit(TTY_LDISC, &tty->flags);
792 tty_unlock();
793 cancel_delayed_work_sync(&tty->buf.work);
794 mutex_unlock(&tty->ldisc_mutex);
795
796 tty_lock();
797 mutex_lock(&tty->ldisc_mutex);
798
784 /* At this point we have a closed ldisc and we want to 799 /* At this point we have a closed ldisc and we want to
785 reopen it. We could defer this to the next open but 800 reopen it. We could defer this to the next open but
786 it means auditing a lot of other paths so this is 801 it means auditing a lot of other paths so this is
@@ -851,8 +866,10 @@ void tty_ldisc_release(struct tty_struct *tty, struct tty_struct *o_tty)
851 * race with the set_ldisc code path. 866 * race with the set_ldisc code path.
852 */ 867 */
853 868
869 tty_unlock();
854 tty_ldisc_halt(tty); 870 tty_ldisc_halt(tty);
855 flush_scheduled_work(); 871 flush_scheduled_work();
872 tty_lock();
856 873
857 mutex_lock(&tty->ldisc_mutex); 874 mutex_lock(&tty->ldisc_mutex);
858 /* 875 /*
diff --git a/drivers/char/tty_mutex.c b/drivers/char/tty_mutex.c
new file mode 100644
index 000000000000..133697540c73
--- /dev/null
+++ b/drivers/char/tty_mutex.c
@@ -0,0 +1,47 @@
1/*
2 * drivers/char/tty_lock.c
3 */
4#include <linux/tty.h>
5#include <linux/module.h>
6#include <linux/kallsyms.h>
7#include <linux/semaphore.h>
8#include <linux/sched.h>
9
10/*
11 * The 'big tty mutex'
12 *
13 * This mutex is taken and released by tty_lock() and tty_unlock(),
14 * replacing the older big kernel lock.
15 * It can no longer be taken recursively, and does not get
16 * released implicitly while sleeping.
17 *
18 * Don't use in new code.
19 */
20static DEFINE_MUTEX(big_tty_mutex);
21struct task_struct *__big_tty_mutex_owner;
22EXPORT_SYMBOL_GPL(__big_tty_mutex_owner);
23
24/*
25 * Getting the big tty mutex.
26 */
27void __lockfunc tty_lock(void)
28{
29 struct task_struct *task = current;
30
31 WARN_ON(__big_tty_mutex_owner == task);
32
33 mutex_lock(&big_tty_mutex);
34 __big_tty_mutex_owner = task;
35}
36EXPORT_SYMBOL(tty_lock);
37
38void __lockfunc tty_unlock(void)
39{
40 struct task_struct *task = current;
41
42 WARN_ON(__big_tty_mutex_owner != task);
43 __big_tty_mutex_owner = NULL;
44
45 mutex_unlock(&big_tty_mutex);
46}
47EXPORT_SYMBOL(tty_unlock);
diff --git a/drivers/char/tty_port.c b/drivers/char/tty_port.c
index a3bd1d0b66cf..33d37d230f8f 100644
--- a/drivers/char/tty_port.c
+++ b/drivers/char/tty_port.c
@@ -231,7 +231,7 @@ int tty_port_block_til_ready(struct tty_port *port,
231 231
232 /* block if port is in the process of being closed */ 232 /* block if port is in the process of being closed */
233 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) { 233 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) {
234 wait_event_interruptible(port->close_wait, 234 wait_event_interruptible_tty(port->close_wait,
235 !(port->flags & ASYNC_CLOSING)); 235 !(port->flags & ASYNC_CLOSING));
236 if (port->flags & ASYNC_HUP_NOTIFY) 236 if (port->flags & ASYNC_HUP_NOTIFY)
237 return -EAGAIN; 237 return -EAGAIN;
@@ -294,7 +294,9 @@ int tty_port_block_til_ready(struct tty_port *port,
294 retval = -ERESTARTSYS; 294 retval = -ERESTARTSYS;
295 break; 295 break;
296 } 296 }
297 tty_unlock();
297 schedule(); 298 schedule();
299 tty_lock();
298 } 300 }
299 finish_wait(&port->open_wait, &wait); 301 finish_wait(&port->open_wait, &wait);
300 302
diff --git a/drivers/char/vc_screen.c b/drivers/char/vc_screen.c
index c1791a63d99d..bcce46c96b88 100644
--- a/drivers/char/vc_screen.c
+++ b/drivers/char/vc_screen.c
@@ -463,10 +463,10 @@ vcs_open(struct inode *inode, struct file *filp)
463 unsigned int currcons = iminor(inode) & 127; 463 unsigned int currcons = iminor(inode) & 127;
464 int ret = 0; 464 int ret = 0;
465 465
466 lock_kernel(); 466 tty_lock();
467 if(currcons && !vc_cons_allocated(currcons-1)) 467 if(currcons && !vc_cons_allocated(currcons-1))
468 ret = -ENXIO; 468 ret = -ENXIO;
469 unlock_kernel(); 469 tty_unlock();
470 return ret; 470 return ret;
471} 471}
472 472
diff --git a/drivers/char/vt.c b/drivers/char/vt.c
index 4a9eb3044e52..c734f9b1263a 100644
--- a/drivers/char/vt.c
+++ b/drivers/char/vt.c
@@ -105,6 +105,7 @@
105#include <asm/system.h> 105#include <asm/system.h>
106#include <linux/uaccess.h> 106#include <linux/uaccess.h>
107#include <linux/kdb.h> 107#include <linux/kdb.h>
108#include <linux/ctype.h>
108 109
109#define MAX_NR_CON_DRIVER 16 110#define MAX_NR_CON_DRIVER 16
110 111
@@ -286,8 +287,12 @@ static inline unsigned short *screenpos(struct vc_data *vc, int offset, int view
286 return p; 287 return p;
287} 288}
288 289
290/* Called from the keyboard irq path.. */
289static inline void scrolldelta(int lines) 291static inline void scrolldelta(int lines)
290{ 292{
293 /* FIXME */
294 /* scrolldelta needs some kind of consistency lock, but the BKL was
295 and still is not protecting versus the scheduled back end */
291 scrollback_delta += lines; 296 scrollback_delta += lines;
292 schedule_console_callback(); 297 schedule_console_callback();
293} 298}
@@ -704,7 +709,10 @@ void redraw_screen(struct vc_data *vc, int is_switch)
704 update_attr(vc); 709 update_attr(vc);
705 clear_buffer_attributes(vc); 710 clear_buffer_attributes(vc);
706 } 711 }
707 if (update && vc->vc_mode != KD_GRAPHICS) 712
713 /* Forcibly update if we're panicing */
714 if ((update && vc->vc_mode != KD_GRAPHICS) ||
715 vt_force_oops_output(vc))
708 do_update_region(vc, vc->vc_origin, vc->vc_screenbuf_size / 2); 716 do_update_region(vc, vc->vc_origin, vc->vc_screenbuf_size / 2);
709 } 717 }
710 set_cursor(vc); 718 set_cursor(vc);
@@ -742,6 +750,7 @@ static void visual_init(struct vc_data *vc, int num, int init)
742 vc->vc_hi_font_mask = 0; 750 vc->vc_hi_font_mask = 0;
743 vc->vc_complement_mask = 0; 751 vc->vc_complement_mask = 0;
744 vc->vc_can_do_color = 0; 752 vc->vc_can_do_color = 0;
753 vc->vc_panic_force_write = false;
745 vc->vc_sw->con_init(vc, init); 754 vc->vc_sw->con_init(vc, init);
746 if (!vc->vc_complement_mask) 755 if (!vc->vc_complement_mask)
747 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800; 756 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
@@ -774,6 +783,7 @@ int vc_allocate(unsigned int currcons) /* return 0 on success */
774 if (!vc) 783 if (!vc)
775 return -ENOMEM; 784 return -ENOMEM;
776 vc_cons[currcons].d = vc; 785 vc_cons[currcons].d = vc;
786 tty_port_init(&vc->port);
777 INIT_WORK(&vc_cons[currcons].SAK_work, vc_SAK); 787 INIT_WORK(&vc_cons[currcons].SAK_work, vc_SAK);
778 visual_init(vc, currcons, 1); 788 visual_init(vc, currcons, 1);
779 if (!*vc->vc_uni_pagedir_loc) 789 if (!*vc->vc_uni_pagedir_loc)
@@ -837,9 +847,10 @@ static int vc_do_resize(struct tty_struct *tty, struct vc_data *vc,
837 unsigned int cols, unsigned int lines) 847 unsigned int cols, unsigned int lines)
838{ 848{
839 unsigned long old_origin, new_origin, new_scr_end, rlth, rrem, err = 0; 849 unsigned long old_origin, new_origin, new_scr_end, rlth, rrem, err = 0;
850 unsigned long end;
840 unsigned int old_cols, old_rows, old_row_size, old_screen_size; 851 unsigned int old_cols, old_rows, old_row_size, old_screen_size;
841 unsigned int new_cols, new_rows, new_row_size, new_screen_size; 852 unsigned int new_cols, new_rows, new_row_size, new_screen_size;
842 unsigned int end, user; 853 unsigned int user;
843 unsigned short *newscreen; 854 unsigned short *newscreen;
844 855
845 WARN_CONSOLE_UNLOCKED(); 856 WARN_CONSOLE_UNLOCKED();
@@ -962,12 +973,12 @@ static int vc_do_resize(struct tty_struct *tty, struct vc_data *vc,
962 * Resize a virtual console as seen from the console end of things. We 973 * Resize a virtual console as seen from the console end of things. We
963 * use the common vc_do_resize methods to update the structures. The 974 * use the common vc_do_resize methods to update the structures. The
964 * caller must hold the console sem to protect console internals and 975 * caller must hold the console sem to protect console internals and
965 * vc->vc_tty 976 * vc->port.tty
966 */ 977 */
967 978
968int vc_resize(struct vc_data *vc, unsigned int cols, unsigned int rows) 979int vc_resize(struct vc_data *vc, unsigned int cols, unsigned int rows)
969{ 980{
970 return vc_do_resize(vc->vc_tty, vc, cols, rows); 981 return vc_do_resize(vc->port.tty, vc, cols, rows);
971} 982}
972 983
973/** 984/**
@@ -1795,8 +1806,8 @@ static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, int c)
1795 vc->vc_state = ESnormal; 1806 vc->vc_state = ESnormal;
1796 return; 1807 return;
1797 case ESpalette: 1808 case ESpalette:
1798 if ( (c>='0'&&c<='9') || (c>='A'&&c<='F') || (c>='a'&&c<='f') ) { 1809 if (isxdigit(c)) {
1799 vc->vc_par[vc->vc_npar++] = (c > '9' ? (c & 0xDF) - 'A' + 10 : c - '0'); 1810 vc->vc_par[vc->vc_npar++] = hex_to_bin(c);
1800 if (vc->vc_npar == 7) { 1811 if (vc->vc_npar == 7) {
1801 int i = vc->vc_par[0] * 3, j = 1; 1812 int i = vc->vc_par[0] * 3, j = 1;
1802 vc->vc_palette[i] = 16 * vc->vc_par[j++]; 1813 vc->vc_palette[i] = 16 * vc->vc_par[j++];
@@ -2504,7 +2515,7 @@ static void vt_console_print(struct console *co, const char *b, unsigned count)
2504 goto quit; 2515 goto quit;
2505 } 2516 }
2506 2517
2507 if (vc->vc_mode != KD_TEXT) 2518 if (vc->vc_mode != KD_TEXT && !vt_force_oops_output(vc))
2508 goto quit; 2519 goto quit;
2509 2520
2510 /* undraw cursor first */ 2521 /* undraw cursor first */
@@ -2610,8 +2621,6 @@ int tioclinux(struct tty_struct *tty, unsigned long arg)
2610 return -EFAULT; 2621 return -EFAULT;
2611 ret = 0; 2622 ret = 0;
2612 2623
2613 lock_kernel();
2614
2615 switch (type) 2624 switch (type)
2616 { 2625 {
2617 case TIOCL_SETSEL: 2626 case TIOCL_SETSEL:
@@ -2686,7 +2695,6 @@ int tioclinux(struct tty_struct *tty, unsigned long arg)
2686 ret = -EINVAL; 2695 ret = -EINVAL;
2687 break; 2696 break;
2688 } 2697 }
2689 unlock_kernel();
2690 return ret; 2698 return ret;
2691} 2699}
2692 2700
@@ -2799,12 +2807,12 @@ static int con_open(struct tty_struct *tty, struct file *filp)
2799 struct vc_data *vc = vc_cons[currcons].d; 2807 struct vc_data *vc = vc_cons[currcons].d;
2800 2808
2801 /* Still being freed */ 2809 /* Still being freed */
2802 if (vc->vc_tty) { 2810 if (vc->port.tty) {
2803 release_console_sem(); 2811 release_console_sem();
2804 return -ERESTARTSYS; 2812 return -ERESTARTSYS;
2805 } 2813 }
2806 tty->driver_data = vc; 2814 tty->driver_data = vc;
2807 vc->vc_tty = tty; 2815 vc->port.tty = tty;
2808 2816
2809 if (!tty->winsize.ws_row && !tty->winsize.ws_col) { 2817 if (!tty->winsize.ws_row && !tty->winsize.ws_col) {
2810 tty->winsize.ws_row = vc_cons[currcons].d->vc_rows; 2818 tty->winsize.ws_row = vc_cons[currcons].d->vc_rows;
@@ -2832,7 +2840,7 @@ static void con_shutdown(struct tty_struct *tty)
2832 struct vc_data *vc = tty->driver_data; 2840 struct vc_data *vc = tty->driver_data;
2833 BUG_ON(vc == NULL); 2841 BUG_ON(vc == NULL);
2834 acquire_console_sem(); 2842 acquire_console_sem();
2835 vc->vc_tty = NULL; 2843 vc->port.tty = NULL;
2836 release_console_sem(); 2844 release_console_sem();
2837 tty_shutdown(tty); 2845 tty_shutdown(tty);
2838} 2846}
@@ -2914,6 +2922,7 @@ static int __init con_init(void)
2914 for (currcons = 0; currcons < MIN_NR_CONSOLES; currcons++) { 2922 for (currcons = 0; currcons < MIN_NR_CONSOLES; currcons++) {
2915 vc_cons[currcons].d = vc = kzalloc(sizeof(struct vc_data), GFP_NOWAIT); 2923 vc_cons[currcons].d = vc = kzalloc(sizeof(struct vc_data), GFP_NOWAIT);
2916 INIT_WORK(&vc_cons[currcons].SAK_work, vc_SAK); 2924 INIT_WORK(&vc_cons[currcons].SAK_work, vc_SAK);
2925 tty_port_init(&vc->port);
2917 visual_init(vc, currcons, 1); 2926 visual_init(vc, currcons, 1);
2918 vc->vc_screenbuf = kzalloc(vc->vc_screenbuf_size, GFP_NOWAIT); 2927 vc->vc_screenbuf = kzalloc(vc->vc_screenbuf_size, GFP_NOWAIT);
2919 vc_init(vc, vc->vc_rows, vc->vc_cols, 2928 vc_init(vc, vc->vc_rows, vc->vc_cols,
@@ -3065,7 +3074,8 @@ static int bind_con_driver(const struct consw *csw, int first, int last,
3065 3074
3066 old_was_color = vc->vc_can_do_color; 3075 old_was_color = vc->vc_can_do_color;
3067 vc->vc_sw->con_deinit(vc); 3076 vc->vc_sw->con_deinit(vc);
3068 vc->vc_origin = (unsigned long)vc->vc_screenbuf; 3077 if (!vc->vc_origin)
3078 vc->vc_origin = (unsigned long)vc->vc_screenbuf;
3069 visual_init(vc, i, 0); 3079 visual_init(vc, i, 0);
3070 set_origin(vc); 3080 set_origin(vc);
3071 update_attr(vc); 3081 update_attr(vc);
@@ -3781,7 +3791,8 @@ void do_unblank_screen(int leaving_gfx)
3781 return; 3791 return;
3782 } 3792 }
3783 vc = vc_cons[fg_console].d; 3793 vc = vc_cons[fg_console].d;
3784 if (vc->vc_mode != KD_TEXT) 3794 /* Try to unblank in oops case too */
3795 if (vc->vc_mode != KD_TEXT && !vt_force_oops_output(vc))
3785 return; /* but leave console_blanked != 0 */ 3796 return; /* but leave console_blanked != 0 */
3786 3797
3787 if (blankinterval) { 3798 if (blankinterval) {
@@ -3790,7 +3801,7 @@ void do_unblank_screen(int leaving_gfx)
3790 } 3801 }
3791 3802
3792 console_blanked = 0; 3803 console_blanked = 0;
3793 if (vc->vc_sw->con_blank(vc, 0, leaving_gfx)) 3804 if (vc->vc_sw->con_blank(vc, 0, leaving_gfx) || vt_force_oops_output(vc))
3794 /* Low-level driver cannot restore -> do it ourselves */ 3805 /* Low-level driver cannot restore -> do it ourselves */
3795 update_screen(vc); 3806 update_screen(vc);
3796 if (console_blank_hook) 3807 if (console_blank_hook)
diff --git a/drivers/char/vt_ioctl.c b/drivers/char/vt_ioctl.c
index cb19dbc52136..2bbeaaea46e9 100644
--- a/drivers/char/vt_ioctl.c
+++ b/drivers/char/vt_ioctl.c
@@ -133,7 +133,7 @@ static void vt_event_wait(struct vt_event_wait *vw)
133 list_add(&vw->list, &vt_events); 133 list_add(&vw->list, &vt_events);
134 spin_unlock_irqrestore(&vt_event_lock, flags); 134 spin_unlock_irqrestore(&vt_event_lock, flags);
135 /* Wait for it to pass */ 135 /* Wait for it to pass */
136 wait_event_interruptible(vt_event_waitqueue, vw->done); 136 wait_event_interruptible_tty(vt_event_waitqueue, vw->done);
137 /* Dequeue it */ 137 /* Dequeue it */
138 spin_lock_irqsave(&vt_event_lock, flags); 138 spin_lock_irqsave(&vt_event_lock, flags);
139 list_del(&vw->list); 139 list_del(&vw->list);
@@ -509,7 +509,7 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
509 509
510 console = vc->vc_num; 510 console = vc->vc_num;
511 511
512 lock_kernel(); 512 tty_lock();
513 513
514 if (!vc_cons_allocated(console)) { /* impossible? */ 514 if (!vc_cons_allocated(console)) { /* impossible? */
515 ret = -ENOIOCTLCMD; 515 ret = -ENOIOCTLCMD;
@@ -1336,7 +1336,7 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
1336 ret = -ENOIOCTLCMD; 1336 ret = -ENOIOCTLCMD;
1337 } 1337 }
1338out: 1338out:
1339 unlock_kernel(); 1339 tty_unlock();
1340 return ret; 1340 return ret;
1341eperm: 1341eperm:
1342 ret = -EPERM; 1342 ret = -EPERM;
@@ -1369,7 +1369,7 @@ void vc_SAK(struct work_struct *work)
1369 acquire_console_sem(); 1369 acquire_console_sem();
1370 vc = vc_con->d; 1370 vc = vc_con->d;
1371 if (vc) { 1371 if (vc) {
1372 tty = vc->vc_tty; 1372 tty = vc->port.tty;
1373 /* 1373 /*
1374 * SAK should also work in all raw modes and reset 1374 * SAK should also work in all raw modes and reset
1375 * them properly. 1375 * them properly.
@@ -1503,7 +1503,7 @@ long vt_compat_ioctl(struct tty_struct *tty, struct file * file,
1503 1503
1504 console = vc->vc_num; 1504 console = vc->vc_num;
1505 1505
1506 lock_kernel(); 1506 tty_lock();
1507 1507
1508 if (!vc_cons_allocated(console)) { /* impossible? */ 1508 if (!vc_cons_allocated(console)) { /* impossible? */
1509 ret = -ENOIOCTLCMD; 1509 ret = -ENOIOCTLCMD;
@@ -1571,11 +1571,11 @@ long vt_compat_ioctl(struct tty_struct *tty, struct file * file,
1571 goto fallback; 1571 goto fallback;
1572 } 1572 }
1573out: 1573out:
1574 unlock_kernel(); 1574 tty_unlock();
1575 return ret; 1575 return ret;
1576 1576
1577fallback: 1577fallback:
1578 unlock_kernel(); 1578 tty_unlock();
1579 return vt_ioctl(tty, file, cmd, arg); 1579 return vt_ioctl(tty, file, cmd, arg);
1580} 1580}
1581 1581
@@ -1761,10 +1761,13 @@ int vt_move_to_console(unsigned int vt, int alloc)
1761 return -EIO; 1761 return -EIO;
1762 } 1762 }
1763 release_console_sem(); 1763 release_console_sem();
1764 tty_lock();
1764 if (vt_waitactive(vt + 1)) { 1765 if (vt_waitactive(vt + 1)) {
1765 pr_debug("Suspend: Can't switch VCs."); 1766 pr_debug("Suspend: Can't switch VCs.");
1767 tty_unlock();
1766 return -EINTR; 1768 return -EINTR;
1767 } 1769 }
1770 tty_unlock();
1768 return prev; 1771 return prev;
1769} 1772}
1770 1773
diff --git a/drivers/char/xilinx_hwicap/xilinx_hwicap.c b/drivers/char/xilinx_hwicap/xilinx_hwicap.c
index ed8a9cec2a05..0ed763cd2e77 100644
--- a/drivers/char/xilinx_hwicap/xilinx_hwicap.c
+++ b/drivers/char/xilinx_hwicap/xilinx_hwicap.c
@@ -761,7 +761,7 @@ static struct platform_driver hwicap_platform_driver = {
761 761
762#if defined(CONFIG_OF) 762#if defined(CONFIG_OF)
763static int __devinit 763static int __devinit
764hwicap_of_probe(struct of_device *op, const struct of_device_id *match) 764hwicap_of_probe(struct platform_device *op, const struct of_device_id *match)
765{ 765{
766 struct resource res; 766 struct resource res;
767 const unsigned int *id; 767 const unsigned int *id;
@@ -798,7 +798,7 @@ hwicap_of_probe(struct of_device *op, const struct of_device_id *match)
798 regs); 798 regs);
799} 799}
800 800
801static int __devexit hwicap_of_remove(struct of_device *op) 801static int __devexit hwicap_of_remove(struct platform_device *op)
802{ 802{
803 return hwicap_remove(&op->dev); 803 return hwicap_remove(&op->dev);
804} 804}
diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
index dbefe15bd582..a50710843378 100644
--- a/drivers/cpuidle/cpuidle.c
+++ b/drivers/cpuidle/cpuidle.c
@@ -74,6 +74,17 @@ static void cpuidle_idle_call(void)
74 */ 74 */
75 hrtimer_peek_ahead_timers(); 75 hrtimer_peek_ahead_timers();
76#endif 76#endif
77
78 /*
79 * Call the device's prepare function before calling the
80 * governor's select function. ->prepare gives the device's
81 * cpuidle driver a chance to update any dynamic information
82 * of its cpuidle states for the current idle period, e.g.
83 * state availability, latencies, residencies, etc.
84 */
85 if (dev->prepare)
86 dev->prepare(dev);
87
77 /* ask the governor for the next state */ 88 /* ask the governor for the next state */
78 next_state = cpuidle_curr_governor->select(dev); 89 next_state = cpuidle_curr_governor->select(dev);
79 if (need_resched()) { 90 if (need_resched()) {
@@ -282,6 +293,26 @@ static int __cpuidle_register_device(struct cpuidle_device *dev)
282 293
283 poll_idle_init(dev); 294 poll_idle_init(dev);
284 295
296 /*
297 * cpuidle driver should set the dev->power_specified bit
298 * before registering the device if the driver provides
299 * power_usage numbers.
300 *
301 * For those devices whose ->power_specified is not set,
302 * we fill in power_usage with decreasing values as the
303 * cpuidle code has an implicit assumption that state Cn
304 * uses less power than C(n-1).
305 *
306 * With CONFIG_ARCH_HAS_CPU_RELAX, C0 is already assigned
307 * an power value of -1. So we use -2, -3, etc, for other
308 * c-states.
309 */
310 if (!dev->power_specified) {
311 int i;
312 for (i = CPUIDLE_DRIVER_STATE_START; i < dev->state_count; i++)
313 dev->states[i].power_usage = -1 - i;
314 }
315
285 per_cpu(cpuidle_devices, dev->cpu) = dev; 316 per_cpu(cpuidle_devices, dev->cpu) = dev;
286 list_add(&dev->device_list, &cpuidle_detected_devices); 317 list_add(&dev->device_list, &cpuidle_detected_devices);
287 if ((ret = cpuidle_add_sysfs(sys_dev))) { 318 if ((ret = cpuidle_add_sysfs(sys_dev))) {
diff --git a/drivers/cpuidle/governors/menu.c b/drivers/cpuidle/governors/menu.c
index 1b128702d300..c2408bbe9c2e 100644
--- a/drivers/cpuidle/governors/menu.c
+++ b/drivers/cpuidle/governors/menu.c
@@ -234,6 +234,7 @@ static int menu_select(struct cpuidle_device *dev)
234{ 234{
235 struct menu_device *data = &__get_cpu_var(menu_devices); 235 struct menu_device *data = &__get_cpu_var(menu_devices);
236 int latency_req = pm_qos_request(PM_QOS_CPU_DMA_LATENCY); 236 int latency_req = pm_qos_request(PM_QOS_CPU_DMA_LATENCY);
237 unsigned int power_usage = -1;
237 int i; 238 int i;
238 int multiplier; 239 int multiplier;
239 240
@@ -278,19 +279,27 @@ static int menu_select(struct cpuidle_device *dev)
278 if (data->expected_us > 5) 279 if (data->expected_us > 5)
279 data->last_state_idx = CPUIDLE_DRIVER_STATE_START; 280 data->last_state_idx = CPUIDLE_DRIVER_STATE_START;
280 281
281 282 /*
282 /* find the deepest idle state that satisfies our constraints */ 283 * Find the idle state with the lowest power while satisfying
284 * our constraints.
285 */
283 for (i = CPUIDLE_DRIVER_STATE_START; i < dev->state_count; i++) { 286 for (i = CPUIDLE_DRIVER_STATE_START; i < dev->state_count; i++) {
284 struct cpuidle_state *s = &dev->states[i]; 287 struct cpuidle_state *s = &dev->states[i];
285 288
289 if (s->flags & CPUIDLE_FLAG_IGNORE)
290 continue;
286 if (s->target_residency > data->predicted_us) 291 if (s->target_residency > data->predicted_us)
287 break; 292 continue;
288 if (s->exit_latency > latency_req) 293 if (s->exit_latency > latency_req)
289 break; 294 continue;
290 if (s->exit_latency * multiplier > data->predicted_us) 295 if (s->exit_latency * multiplier > data->predicted_us)
291 break; 296 continue;
292 data->exit_us = s->exit_latency; 297
293 data->last_state_idx = i; 298 if (s->power_usage < power_usage) {
299 power_usage = s->power_usage;
300 data->last_state_idx = i;
301 data->exit_us = s->exit_latency;
302 }
294 } 303 }
295 304
296 return data->last_state_idx; 305 return data->last_state_idx;
diff --git a/drivers/crypto/Kconfig b/drivers/crypto/Kconfig
index fbf94cf496f0..ea0b3863ad0f 100644
--- a/drivers/crypto/Kconfig
+++ b/drivers/crypto/Kconfig
@@ -77,7 +77,7 @@ config ZCRYPT
77 77
78config ZCRYPT_MONOLITHIC 78config ZCRYPT_MONOLITHIC
79 bool "Monolithic zcrypt module" 79 bool "Monolithic zcrypt module"
80 depends on ZCRYPT="m" 80 depends on ZCRYPT
81 help 81 help
82 Select this option if you want to have a single module z90crypt, 82 Select this option if you want to have a single module z90crypt,
83 that contains all parts of the crypto device driver (ap bus, 83 that contains all parts of the crypto device driver (ap bus,
diff --git a/drivers/crypto/amcc/crypto4xx_core.c b/drivers/crypto/amcc/crypto4xx_core.c
index 983530ba04a7..2b1baee525bc 100644
--- a/drivers/crypto/amcc/crypto4xx_core.c
+++ b/drivers/crypto/amcc/crypto4xx_core.c
@@ -1150,7 +1150,7 @@ struct crypto4xx_alg_common crypto4xx_alg[] = {
1150/** 1150/**
1151 * Module Initialization Routine 1151 * Module Initialization Routine
1152 */ 1152 */
1153static int __init crypto4xx_probe(struct of_device *ofdev, 1153static int __init crypto4xx_probe(struct platform_device *ofdev,
1154 const struct of_device_id *match) 1154 const struct of_device_id *match)
1155{ 1155{
1156 int rc; 1156 int rc;
@@ -1258,7 +1258,7 @@ err_alloc_dev:
1258 return rc; 1258 return rc;
1259} 1259}
1260 1260
1261static int __exit crypto4xx_remove(struct of_device *ofdev) 1261static int __exit crypto4xx_remove(struct platform_device *ofdev)
1262{ 1262{
1263 struct device *dev = &ofdev->dev; 1263 struct device *dev = &ofdev->dev;
1264 struct crypto4xx_core_device *core_dev = dev_get_drvdata(dev); 1264 struct crypto4xx_core_device *core_dev = dev_get_drvdata(dev);
diff --git a/drivers/crypto/amcc/crypto4xx_core.h b/drivers/crypto/amcc/crypto4xx_core.h
index da9cbe3b9fc3..bac0bdeb4b5f 100644
--- a/drivers/crypto/amcc/crypto4xx_core.h
+++ b/drivers/crypto/amcc/crypto4xx_core.h
@@ -104,7 +104,7 @@ struct crypto4xx_device {
104 104
105struct crypto4xx_core_device { 105struct crypto4xx_core_device {
106 struct device *device; 106 struct device *device;
107 struct of_device *ofdev; 107 struct platform_device *ofdev;
108 struct crypto4xx_device *dev; 108 struct crypto4xx_device *dev;
109 u32 int_status; 109 u32 int_status;
110 u32 irq; 110 u32 irq;
diff --git a/drivers/crypto/ixp4xx_crypto.c b/drivers/crypto/ixp4xx_crypto.c
index f17ddf37a1ed..0d662213c066 100644
--- a/drivers/crypto/ixp4xx_crypto.c
+++ b/drivers/crypto/ixp4xx_crypto.c
@@ -97,8 +97,13 @@
97 97
98struct buffer_desc { 98struct buffer_desc {
99 u32 phys_next; 99 u32 phys_next;
100#ifdef __ARMEB__
100 u16 buf_len; 101 u16 buf_len;
101 u16 pkt_len; 102 u16 pkt_len;
103#else
104 u16 pkt_len;
105 u16 buf_len;
106#endif
102 u32 phys_addr; 107 u32 phys_addr;
103 u32 __reserved[4]; 108 u32 __reserved[4];
104 struct buffer_desc *next; 109 struct buffer_desc *next;
@@ -106,17 +111,30 @@ struct buffer_desc {
106}; 111};
107 112
108struct crypt_ctl { 113struct crypt_ctl {
114#ifdef __ARMEB__
109 u8 mode; /* NPE_OP_* operation mode */ 115 u8 mode; /* NPE_OP_* operation mode */
110 u8 init_len; 116 u8 init_len;
111 u16 reserved; 117 u16 reserved;
118#else
119 u16 reserved;
120 u8 init_len;
121 u8 mode; /* NPE_OP_* operation mode */
122#endif
112 u8 iv[MAX_IVLEN]; /* IV for CBC mode or CTR IV for CTR mode */ 123 u8 iv[MAX_IVLEN]; /* IV for CBC mode or CTR IV for CTR mode */
113 u32 icv_rev_aes; /* icv or rev aes */ 124 u32 icv_rev_aes; /* icv or rev aes */
114 u32 src_buf; 125 u32 src_buf;
115 u32 dst_buf; 126 u32 dst_buf;
127#ifdef __ARMEB__
116 u16 auth_offs; /* Authentication start offset */ 128 u16 auth_offs; /* Authentication start offset */
117 u16 auth_len; /* Authentication data length */ 129 u16 auth_len; /* Authentication data length */
118 u16 crypt_offs; /* Cryption start offset */ 130 u16 crypt_offs; /* Cryption start offset */
119 u16 crypt_len; /* Cryption data length */ 131 u16 crypt_len; /* Cryption data length */
132#else
133 u16 auth_len; /* Authentication data length */
134 u16 auth_offs; /* Authentication start offset */
135 u16 crypt_len; /* Cryption data length */
136 u16 crypt_offs; /* Cryption start offset */
137#endif
120 u32 aadAddr; /* Additional Auth Data Addr for CCM mode */ 138 u32 aadAddr; /* Additional Auth Data Addr for CCM mode */
121 u32 crypto_ctx; /* NPE Crypto Param structure address */ 139 u32 crypto_ctx; /* NPE Crypto Param structure address */
122 140
@@ -652,6 +670,9 @@ static int setup_auth(struct crypto_tfm *tfm, int encrypt, unsigned authsize,
652 670
653 /* write cfg word to cryptinfo */ 671 /* write cfg word to cryptinfo */
654 cfgword = algo->cfgword | ( authsize << 6); /* (authsize/4) << 8 */ 672 cfgword = algo->cfgword | ( authsize << 6); /* (authsize/4) << 8 */
673#ifndef __ARMEB__
674 cfgword ^= 0xAA000000; /* change the "byte swap" flags */
675#endif
655 *(u32*)cinfo = cpu_to_be32(cfgword); 676 *(u32*)cinfo = cpu_to_be32(cfgword);
656 cinfo += sizeof(cfgword); 677 cinfo += sizeof(cfgword);
657 678
diff --git a/drivers/crypto/n2_core.c b/drivers/crypto/n2_core.c
index 26af2dd5d831..88ee01510ec0 100644
--- a/drivers/crypto/n2_core.c
+++ b/drivers/crypto/n2_core.c
@@ -1552,7 +1552,7 @@ static void __exit n2_unregister_algs(void)
1552 1552
1553/* To map CWQ queues to interrupt sources, the hypervisor API provides 1553/* To map CWQ queues to interrupt sources, the hypervisor API provides
1554 * a devino. This isn't very useful to us because all of the 1554 * a devino. This isn't very useful to us because all of the
1555 * interrupts listed in the of_device node have been translated to 1555 * interrupts listed in the device_node have been translated to
1556 * Linux virtual IRQ cookie numbers. 1556 * Linux virtual IRQ cookie numbers.
1557 * 1557 *
1558 * So we have to back-translate, going through the 'intr' and 'ino' 1558 * So we have to back-translate, going through the 'intr' and 'ino'
@@ -1560,7 +1560,7 @@ static void __exit n2_unregister_algs(void)
1560 * 'interrupts' property entries, in order to to figure out which 1560 * 'interrupts' property entries, in order to to figure out which
1561 * devino goes to which already-translated IRQ. 1561 * devino goes to which already-translated IRQ.
1562 */ 1562 */
1563static int find_devino_index(struct of_device *dev, struct spu_mdesc_info *ip, 1563static int find_devino_index(struct platform_device *dev, struct spu_mdesc_info *ip,
1564 unsigned long dev_ino) 1564 unsigned long dev_ino)
1565{ 1565{
1566 const unsigned int *dev_intrs; 1566 const unsigned int *dev_intrs;
@@ -1580,7 +1580,7 @@ static int find_devino_index(struct of_device *dev, struct spu_mdesc_info *ip,
1580 if (!dev_intrs) 1580 if (!dev_intrs)
1581 return -ENODEV; 1581 return -ENODEV;
1582 1582
1583 for (i = 0; i < dev->num_irqs; i++) { 1583 for (i = 0; i < dev->archdata.num_irqs; i++) {
1584 if (dev_intrs[i] == intr) 1584 if (dev_intrs[i] == intr)
1585 return i; 1585 return i;
1586 } 1586 }
@@ -1588,7 +1588,7 @@ static int find_devino_index(struct of_device *dev, struct spu_mdesc_info *ip,
1588 return -ENODEV; 1588 return -ENODEV;
1589} 1589}
1590 1590
1591static int spu_map_ino(struct of_device *dev, struct spu_mdesc_info *ip, 1591static int spu_map_ino(struct platform_device *dev, struct spu_mdesc_info *ip,
1592 const char *irq_name, struct spu_queue *p, 1592 const char *irq_name, struct spu_queue *p,
1593 irq_handler_t handler) 1593 irq_handler_t handler)
1594{ 1594{
@@ -1603,7 +1603,7 @@ static int spu_map_ino(struct of_device *dev, struct spu_mdesc_info *ip,
1603 if (index < 0) 1603 if (index < 0)
1604 return index; 1604 return index;
1605 1605
1606 p->irq = dev->irqs[index]; 1606 p->irq = dev->archdata.irqs[index];
1607 1607
1608 sprintf(p->irq_name, "%s-%d", irq_name, index); 1608 sprintf(p->irq_name, "%s-%d", irq_name, index);
1609 1609
@@ -1736,7 +1736,7 @@ static void spu_list_destroy(struct list_head *list)
1736 * gathering cpu membership information. 1736 * gathering cpu membership information.
1737 */ 1737 */
1738static int spu_mdesc_walk_arcs(struct mdesc_handle *mdesc, 1738static int spu_mdesc_walk_arcs(struct mdesc_handle *mdesc,
1739 struct of_device *dev, 1739 struct platform_device *dev,
1740 u64 node, struct spu_queue *p, 1740 u64 node, struct spu_queue *p,
1741 struct spu_queue **table) 1741 struct spu_queue **table)
1742{ 1742{
@@ -1763,7 +1763,7 @@ static int spu_mdesc_walk_arcs(struct mdesc_handle *mdesc,
1763 1763
1764/* Process an 'exec-unit' MDESC node of type 'cwq'. */ 1764/* Process an 'exec-unit' MDESC node of type 'cwq'. */
1765static int handle_exec_unit(struct spu_mdesc_info *ip, struct list_head *list, 1765static int handle_exec_unit(struct spu_mdesc_info *ip, struct list_head *list,
1766 struct of_device *dev, struct mdesc_handle *mdesc, 1766 struct platform_device *dev, struct mdesc_handle *mdesc,
1767 u64 node, const char *iname, unsigned long q_type, 1767 u64 node, const char *iname, unsigned long q_type,
1768 irq_handler_t handler, struct spu_queue **table) 1768 irq_handler_t handler, struct spu_queue **table)
1769{ 1769{
@@ -1794,7 +1794,7 @@ static int handle_exec_unit(struct spu_mdesc_info *ip, struct list_head *list,
1794 return spu_map_ino(dev, ip, iname, p, handler); 1794 return spu_map_ino(dev, ip, iname, p, handler);
1795} 1795}
1796 1796
1797static int spu_mdesc_scan(struct mdesc_handle *mdesc, struct of_device *dev, 1797static int spu_mdesc_scan(struct mdesc_handle *mdesc, struct platform_device *dev,
1798 struct spu_mdesc_info *ip, struct list_head *list, 1798 struct spu_mdesc_info *ip, struct list_head *list,
1799 const char *exec_name, unsigned long q_type, 1799 const char *exec_name, unsigned long q_type,
1800 irq_handler_t handler, struct spu_queue **table) 1800 irq_handler_t handler, struct spu_queue **table)
@@ -1855,7 +1855,7 @@ static int __devinit get_irq_props(struct mdesc_handle *mdesc, u64 node,
1855} 1855}
1856 1856
1857static int __devinit grab_mdesc_irq_props(struct mdesc_handle *mdesc, 1857static int __devinit grab_mdesc_irq_props(struct mdesc_handle *mdesc,
1858 struct of_device *dev, 1858 struct platform_device *dev,
1859 struct spu_mdesc_info *ip, 1859 struct spu_mdesc_info *ip,
1860 const char *node_name) 1860 const char *node_name)
1861{ 1861{
@@ -2004,7 +2004,7 @@ static void __devinit n2_spu_driver_version(void)
2004 pr_info("%s", version); 2004 pr_info("%s", version);
2005} 2005}
2006 2006
2007static int __devinit n2_crypto_probe(struct of_device *dev, 2007static int __devinit n2_crypto_probe(struct platform_device *dev,
2008 const struct of_device_id *match) 2008 const struct of_device_id *match)
2009{ 2009{
2010 struct mdesc_handle *mdesc; 2010 struct mdesc_handle *mdesc;
@@ -2081,7 +2081,7 @@ out_free_n2cp:
2081 return err; 2081 return err;
2082} 2082}
2083 2083
2084static int __devexit n2_crypto_remove(struct of_device *dev) 2084static int __devexit n2_crypto_remove(struct platform_device *dev)
2085{ 2085{
2086 struct n2_crypto *np = dev_get_drvdata(&dev->dev); 2086 struct n2_crypto *np = dev_get_drvdata(&dev->dev);
2087 2087
@@ -2116,7 +2116,7 @@ static void free_ncp(struct n2_mau *mp)
2116 kfree(mp); 2116 kfree(mp);
2117} 2117}
2118 2118
2119static int __devinit n2_mau_probe(struct of_device *dev, 2119static int __devinit n2_mau_probe(struct platform_device *dev,
2120 const struct of_device_id *match) 2120 const struct of_device_id *match)
2121{ 2121{
2122 struct mdesc_handle *mdesc; 2122 struct mdesc_handle *mdesc;
@@ -2184,7 +2184,7 @@ out_free_ncp:
2184 return err; 2184 return err;
2185} 2185}
2186 2186
2187static int __devexit n2_mau_remove(struct of_device *dev) 2187static int __devexit n2_mau_remove(struct platform_device *dev)
2188{ 2188{
2189 struct n2_mau *mp = dev_get_drvdata(&dev->dev); 2189 struct n2_mau *mp = dev_get_drvdata(&dev->dev);
2190 2190
diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c
index 97f4af1d8a64..4bcd825b5739 100644
--- a/drivers/crypto/talitos.c
+++ b/drivers/crypto/talitos.c
@@ -118,7 +118,7 @@ struct talitos_channel {
118 118
119struct talitos_private { 119struct talitos_private {
120 struct device *dev; 120 struct device *dev;
121 struct of_device *ofdev; 121 struct platform_device *ofdev;
122 void __iomem *reg; 122 void __iomem *reg;
123 int irq; 123 int irq;
124 124
@@ -2308,7 +2308,7 @@ static int hw_supports(struct device *dev, __be32 desc_hdr_template)
2308 return ret; 2308 return ret;
2309} 2309}
2310 2310
2311static int talitos_remove(struct of_device *ofdev) 2311static int talitos_remove(struct platform_device *ofdev)
2312{ 2312{
2313 struct device *dev = &ofdev->dev; 2313 struct device *dev = &ofdev->dev;
2314 struct talitos_private *priv = dev_get_drvdata(dev); 2314 struct talitos_private *priv = dev_get_drvdata(dev);
@@ -2401,7 +2401,7 @@ static struct talitos_crypto_alg *talitos_alg_alloc(struct device *dev,
2401 return t_alg; 2401 return t_alg;
2402} 2402}
2403 2403
2404static int talitos_probe(struct of_device *ofdev, 2404static int talitos_probe(struct platform_device *ofdev,
2405 const struct of_device_id *match) 2405 const struct of_device_id *match)
2406{ 2406{
2407 struct device *dev = &ofdev->dev; 2407 struct device *dev = &ofdev->dev;
diff --git a/drivers/dma/Kconfig b/drivers/dma/Kconfig
index 9e01e96fee94..9520cf02edc8 100644
--- a/drivers/dma/Kconfig
+++ b/drivers/dma/Kconfig
@@ -33,6 +33,19 @@ if DMADEVICES
33 33
34comment "DMA Devices" 34comment "DMA Devices"
35 35
36config INTEL_MID_DMAC
37 tristate "Intel MID DMA support for Peripheral DMA controllers"
38 depends on PCI && X86
39 select DMA_ENGINE
40 default n
41 help
42 Enable support for the Intel(R) MID DMA engine present
43 in Intel MID chipsets.
44
45 Say Y here if you have such a chipset.
46
47 If unsure, say N.
48
36config ASYNC_TX_DISABLE_CHANNEL_SWITCH 49config ASYNC_TX_DISABLE_CHANNEL_SWITCH
37 bool 50 bool
38 51
@@ -128,7 +141,7 @@ config TXX9_DMAC
128 141
129config SH_DMAE 142config SH_DMAE
130 tristate "Renesas SuperH DMAC support" 143 tristate "Renesas SuperH DMAC support"
131 depends on SUPERH && SH_DMA 144 depends on (SUPERH && SH_DMA) || (ARM && ARCH_SHMOBILE)
132 depends on !SH_DMA_API 145 depends on !SH_DMA_API
133 select DMA_ENGINE 146 select DMA_ENGINE
134 help 147 help
@@ -175,6 +188,13 @@ config PL330_DMA
175 You need to provide platform specific settings via 188 You need to provide platform specific settings via
176 platform_data for a dma-pl330 device. 189 platform_data for a dma-pl330 device.
177 190
191config PCH_DMA
192 tristate "Topcliff PCH DMA support"
193 depends on PCI && X86
194 select DMA_ENGINE
195 help
196 Enable support for the Topcliff PCH DMA engine.
197
178config DMA_ENGINE 198config DMA_ENGINE
179 bool 199 bool
180 200
diff --git a/drivers/dma/Makefile b/drivers/dma/Makefile
index 0fe5ebbfda5d..72bd70384d8a 100644
--- a/drivers/dma/Makefile
+++ b/drivers/dma/Makefile
@@ -7,6 +7,7 @@ endif
7 7
8obj-$(CONFIG_DMA_ENGINE) += dmaengine.o 8obj-$(CONFIG_DMA_ENGINE) += dmaengine.o
9obj-$(CONFIG_NET_DMA) += iovlock.o 9obj-$(CONFIG_NET_DMA) += iovlock.o
10obj-$(CONFIG_INTEL_MID_DMAC) += intel_mid_dma.o
10obj-$(CONFIG_DMATEST) += dmatest.o 11obj-$(CONFIG_DMATEST) += dmatest.o
11obj-$(CONFIG_INTEL_IOATDMA) += ioat/ 12obj-$(CONFIG_INTEL_IOATDMA) += ioat/
12obj-$(CONFIG_INTEL_IOP_ADMA) += iop-adma.o 13obj-$(CONFIG_INTEL_IOP_ADMA) += iop-adma.o
@@ -23,3 +24,4 @@ obj-$(CONFIG_AMCC_PPC440SPE_ADMA) += ppc4xx/
23obj-$(CONFIG_TIMB_DMA) += timb_dma.o 24obj-$(CONFIG_TIMB_DMA) += timb_dma.o
24obj-$(CONFIG_STE_DMA40) += ste_dma40.o ste_dma40_ll.o 25obj-$(CONFIG_STE_DMA40) += ste_dma40.o ste_dma40_ll.o
25obj-$(CONFIG_PL330_DMA) += pl330.o 26obj-$(CONFIG_PL330_DMA) += pl330.o
27obj-$(CONFIG_PCH_DMA) += pch_dma.o
diff --git a/drivers/dma/at_hdmac.c b/drivers/dma/at_hdmac.c
index e88076022a7a..a0f3e6a06e06 100644
--- a/drivers/dma/at_hdmac.c
+++ b/drivers/dma/at_hdmac.c
@@ -790,12 +790,12 @@ static int atc_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
790 list_splice_init(&atchan->queue, &list); 790 list_splice_init(&atchan->queue, &list);
791 list_splice_init(&atchan->active_list, &list); 791 list_splice_init(&atchan->active_list, &list);
792 792
793 spin_unlock_bh(&atchan->lock);
794
795 /* Flush all pending and queued descriptors */ 793 /* Flush all pending and queued descriptors */
796 list_for_each_entry_safe(desc, _desc, &list, desc_node) 794 list_for_each_entry_safe(desc, _desc, &list, desc_node)
797 atc_chain_complete(atchan, desc); 795 atc_chain_complete(atchan, desc);
798 796
797 spin_unlock_bh(&atchan->lock);
798
799 return 0; 799 return 0;
800} 800}
801 801
diff --git a/drivers/dma/coh901318.c b/drivers/dma/coh901318.c
index a724e6be1b4d..557e2272e5b3 100644
--- a/drivers/dma/coh901318.c
+++ b/drivers/dma/coh901318.c
@@ -72,6 +72,9 @@ struct coh901318_chan {
72 unsigned long nbr_active_done; 72 unsigned long nbr_active_done;
73 unsigned long busy; 73 unsigned long busy;
74 74
75 u32 runtime_addr;
76 u32 runtime_ctrl;
77
75 struct coh901318_base *base; 78 struct coh901318_base *base;
76}; 79};
77 80
@@ -190,6 +193,9 @@ static inline struct coh901318_chan *to_coh901318_chan(struct dma_chan *chan)
190static inline dma_addr_t 193static inline dma_addr_t
191cohc_dev_addr(struct coh901318_chan *cohc) 194cohc_dev_addr(struct coh901318_chan *cohc)
192{ 195{
196 /* Runtime supplied address will take precedence */
197 if (cohc->runtime_addr)
198 return cohc->runtime_addr;
193 return cohc->base->platform->chan_conf[cohc->id].dev_addr; 199 return cohc->base->platform->chan_conf[cohc->id].dev_addr;
194} 200}
195 201
@@ -1055,6 +1061,14 @@ coh901318_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl,
1055 1061
1056 params = cohc_chan_param(cohc); 1062 params = cohc_chan_param(cohc);
1057 config = params->config; 1063 config = params->config;
1064 /*
1065 * Add runtime-specific control on top, make
1066 * sure the bits you set per peripheral channel are
1067 * cleared in the default config from the platform.
1068 */
1069 ctrl_chained |= cohc->runtime_ctrl;
1070 ctrl_last |= cohc->runtime_ctrl;
1071 ctrl |= cohc->runtime_ctrl;
1058 1072
1059 if (direction == DMA_TO_DEVICE) { 1073 if (direction == DMA_TO_DEVICE) {
1060 u32 tx_flags = COH901318_CX_CTRL_PRDD_SOURCE | 1074 u32 tx_flags = COH901318_CX_CTRL_PRDD_SOURCE |
@@ -1113,6 +1127,12 @@ coh901318_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl,
1113 if (ret) 1127 if (ret)
1114 goto err_lli_fill; 1128 goto err_lli_fill;
1115 1129
1130 /*
1131 * Set the default ctrl for the channel to the one from the lli,
1132 * things may have changed due to odd buffer alignment etc.
1133 */
1134 coh901318_set_ctrl(cohc, lli->control);
1135
1116 COH_DBG(coh901318_list_print(cohc, lli)); 1136 COH_DBG(coh901318_list_print(cohc, lli));
1117 1137
1118 /* Pick a descriptor to handle this transfer */ 1138 /* Pick a descriptor to handle this transfer */
@@ -1175,6 +1195,146 @@ coh901318_issue_pending(struct dma_chan *chan)
1175 spin_unlock_irqrestore(&cohc->lock, flags); 1195 spin_unlock_irqrestore(&cohc->lock, flags);
1176} 1196}
1177 1197
1198/*
1199 * Here we wrap in the runtime dma control interface
1200 */
1201struct burst_table {
1202 int burst_8bit;
1203 int burst_16bit;
1204 int burst_32bit;
1205 u32 reg;
1206};
1207
1208static const struct burst_table burst_sizes[] = {
1209 {
1210 .burst_8bit = 64,
1211 .burst_16bit = 32,
1212 .burst_32bit = 16,
1213 .reg = COH901318_CX_CTRL_BURST_COUNT_64_BYTES,
1214 },
1215 {
1216 .burst_8bit = 48,
1217 .burst_16bit = 24,
1218 .burst_32bit = 12,
1219 .reg = COH901318_CX_CTRL_BURST_COUNT_48_BYTES,
1220 },
1221 {
1222 .burst_8bit = 32,
1223 .burst_16bit = 16,
1224 .burst_32bit = 8,
1225 .reg = COH901318_CX_CTRL_BURST_COUNT_32_BYTES,
1226 },
1227 {
1228 .burst_8bit = 16,
1229 .burst_16bit = 8,
1230 .burst_32bit = 4,
1231 .reg = COH901318_CX_CTRL_BURST_COUNT_16_BYTES,
1232 },
1233 {
1234 .burst_8bit = 8,
1235 .burst_16bit = 4,
1236 .burst_32bit = 2,
1237 .reg = COH901318_CX_CTRL_BURST_COUNT_8_BYTES,
1238 },
1239 {
1240 .burst_8bit = 4,
1241 .burst_16bit = 2,
1242 .burst_32bit = 1,
1243 .reg = COH901318_CX_CTRL_BURST_COUNT_4_BYTES,
1244 },
1245 {
1246 .burst_8bit = 2,
1247 .burst_16bit = 1,
1248 .burst_32bit = 0,
1249 .reg = COH901318_CX_CTRL_BURST_COUNT_2_BYTES,
1250 },
1251 {
1252 .burst_8bit = 1,
1253 .burst_16bit = 0,
1254 .burst_32bit = 0,
1255 .reg = COH901318_CX_CTRL_BURST_COUNT_1_BYTE,
1256 },
1257};
1258
1259static void coh901318_dma_set_runtimeconfig(struct dma_chan *chan,
1260 struct dma_slave_config *config)
1261{
1262 struct coh901318_chan *cohc = to_coh901318_chan(chan);
1263 dma_addr_t addr;
1264 enum dma_slave_buswidth addr_width;
1265 u32 maxburst;
1266 u32 runtime_ctrl = 0;
1267 int i = 0;
1268
1269 /* We only support mem to per or per to mem transfers */
1270 if (config->direction == DMA_FROM_DEVICE) {
1271 addr = config->src_addr;
1272 addr_width = config->src_addr_width;
1273 maxburst = config->src_maxburst;
1274 } else if (config->direction == DMA_TO_DEVICE) {
1275 addr = config->dst_addr;
1276 addr_width = config->dst_addr_width;
1277 maxburst = config->dst_maxburst;
1278 } else {
1279 dev_err(COHC_2_DEV(cohc), "illegal channel mode\n");
1280 return;
1281 }
1282
1283 dev_dbg(COHC_2_DEV(cohc), "configure channel for %d byte transfers\n",
1284 addr_width);
1285 switch (addr_width) {
1286 case DMA_SLAVE_BUSWIDTH_1_BYTE:
1287 runtime_ctrl |=
1288 COH901318_CX_CTRL_SRC_BUS_SIZE_8_BITS |
1289 COH901318_CX_CTRL_DST_BUS_SIZE_8_BITS;
1290
1291 while (i < ARRAY_SIZE(burst_sizes)) {
1292 if (burst_sizes[i].burst_8bit <= maxburst)
1293 break;
1294 i++;
1295 }
1296
1297 break;
1298 case DMA_SLAVE_BUSWIDTH_2_BYTES:
1299 runtime_ctrl |=
1300 COH901318_CX_CTRL_SRC_BUS_SIZE_16_BITS |
1301 COH901318_CX_CTRL_DST_BUS_SIZE_16_BITS;
1302
1303 while (i < ARRAY_SIZE(burst_sizes)) {
1304 if (burst_sizes[i].burst_16bit <= maxburst)
1305 break;
1306 i++;
1307 }
1308
1309 break;
1310 case DMA_SLAVE_BUSWIDTH_4_BYTES:
1311 /* Direction doesn't matter here, it's 32/32 bits */
1312 runtime_ctrl |=
1313 COH901318_CX_CTRL_SRC_BUS_SIZE_32_BITS |
1314 COH901318_CX_CTRL_DST_BUS_SIZE_32_BITS;
1315
1316 while (i < ARRAY_SIZE(burst_sizes)) {
1317 if (burst_sizes[i].burst_32bit <= maxburst)
1318 break;
1319 i++;
1320 }
1321
1322 break;
1323 default:
1324 dev_err(COHC_2_DEV(cohc),
1325 "bad runtimeconfig: alien address width\n");
1326 return;
1327 }
1328
1329 runtime_ctrl |= burst_sizes[i].reg;
1330 dev_dbg(COHC_2_DEV(cohc),
1331 "selected burst size %d bytes for address width %d bytes, maxburst %d\n",
1332 burst_sizes[i].burst_8bit, addr_width, maxburst);
1333
1334 cohc->runtime_addr = addr;
1335 cohc->runtime_ctrl = runtime_ctrl;
1336}
1337
1178static int 1338static int
1179coh901318_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd, 1339coh901318_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
1180 unsigned long arg) 1340 unsigned long arg)
@@ -1184,6 +1344,14 @@ coh901318_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
1184 struct coh901318_desc *cohd; 1344 struct coh901318_desc *cohd;
1185 void __iomem *virtbase = cohc->base->virtbase; 1345 void __iomem *virtbase = cohc->base->virtbase;
1186 1346
1347 if (cmd == DMA_SLAVE_CONFIG) {
1348 struct dma_slave_config *config =
1349 (struct dma_slave_config *) arg;
1350
1351 coh901318_dma_set_runtimeconfig(chan, config);
1352 return 0;
1353 }
1354
1187 if (cmd == DMA_PAUSE) { 1355 if (cmd == DMA_PAUSE) {
1188 coh901318_pause(chan); 1356 coh901318_pause(chan);
1189 return 0; 1357 return 0;
@@ -1240,6 +1408,7 @@ coh901318_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
1240 1408
1241 return 0; 1409 return 0;
1242} 1410}
1411
1243void coh901318_base_init(struct dma_device *dma, const int *pick_chans, 1412void coh901318_base_init(struct dma_device *dma, const int *pick_chans,
1244 struct coh901318_base *base) 1413 struct coh901318_base *base)
1245{ 1414{
diff --git a/drivers/dma/dmatest.c b/drivers/dma/dmatest.c
index 68d58c414cf0..5589358b684d 100644
--- a/drivers/dma/dmatest.c
+++ b/drivers/dma/dmatest.c
@@ -540,7 +540,7 @@ static int dmatest_add_channel(struct dma_chan *chan)
540 struct dmatest_chan *dtc; 540 struct dmatest_chan *dtc;
541 struct dma_device *dma_dev = chan->device; 541 struct dma_device *dma_dev = chan->device;
542 unsigned int thread_count = 0; 542 unsigned int thread_count = 0;
543 unsigned int cnt; 543 int cnt;
544 544
545 dtc = kmalloc(sizeof(struct dmatest_chan), GFP_KERNEL); 545 dtc = kmalloc(sizeof(struct dmatest_chan), GFP_KERNEL);
546 if (!dtc) { 546 if (!dtc) {
diff --git a/drivers/dma/fsldma.c b/drivers/dma/fsldma.c
index f0fd6db6063c..cea08bed9cf9 100644
--- a/drivers/dma/fsldma.c
+++ b/drivers/dma/fsldma.c
@@ -1297,7 +1297,7 @@ static void fsl_dma_chan_remove(struct fsldma_chan *chan)
1297 kfree(chan); 1297 kfree(chan);
1298} 1298}
1299 1299
1300static int __devinit fsldma_of_probe(struct of_device *op, 1300static int __devinit fsldma_of_probe(struct platform_device *op,
1301 const struct of_device_id *match) 1301 const struct of_device_id *match)
1302{ 1302{
1303 struct fsldma_device *fdev; 1303 struct fsldma_device *fdev;
@@ -1382,7 +1382,7 @@ out_return:
1382 return err; 1382 return err;
1383} 1383}
1384 1384
1385static int fsldma_of_remove(struct of_device *op) 1385static int fsldma_of_remove(struct platform_device *op)
1386{ 1386{
1387 struct fsldma_device *fdev; 1387 struct fsldma_device *fdev;
1388 unsigned int i; 1388 unsigned int i;
diff --git a/drivers/dma/intel_mid_dma.c b/drivers/dma/intel_mid_dma.c
new file mode 100644
index 000000000000..c2591e8d9b6e
--- /dev/null
+++ b/drivers/dma/intel_mid_dma.c
@@ -0,0 +1,1143 @@
1/*
2 * intel_mid_dma.c - Intel Langwell DMA Drivers
3 *
4 * Copyright (C) 2008-10 Intel Corp
5 * Author: Vinod Koul <vinod.koul@intel.com>
6 * The driver design is based on dw_dmac driver
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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; version 2 of the License.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 *
22 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23 *
24 *
25 */
26#include <linux/pci.h>
27#include <linux/interrupt.h>
28#include <linux/intel_mid_dma.h>
29
30#define MAX_CHAN 4 /*max ch across controllers*/
31#include "intel_mid_dma_regs.h"
32
33#define INTEL_MID_DMAC1_ID 0x0814
34#define INTEL_MID_DMAC2_ID 0x0813
35#define INTEL_MID_GP_DMAC2_ID 0x0827
36#define INTEL_MFLD_DMAC1_ID 0x0830
37#define LNW_PERIPHRAL_MASK_BASE 0xFFAE8008
38#define LNW_PERIPHRAL_MASK_SIZE 0x10
39#define LNW_PERIPHRAL_STATUS 0x0
40#define LNW_PERIPHRAL_MASK 0x8
41
42struct intel_mid_dma_probe_info {
43 u8 max_chan;
44 u8 ch_base;
45 u16 block_size;
46 u32 pimr_mask;
47};
48
49#define INFO(_max_chan, _ch_base, _block_size, _pimr_mask) \
50 ((kernel_ulong_t)&(struct intel_mid_dma_probe_info) { \
51 .max_chan = (_max_chan), \
52 .ch_base = (_ch_base), \
53 .block_size = (_block_size), \
54 .pimr_mask = (_pimr_mask), \
55 })
56
57/*****************************************************************************
58Utility Functions*/
59/**
60 * get_ch_index - convert status to channel
61 * @status: status mask
62 * @base: dma ch base value
63 *
64 * Modify the status mask and return the channel index needing
65 * attention (or -1 if neither)
66 */
67static int get_ch_index(int *status, unsigned int base)
68{
69 int i;
70 for (i = 0; i < MAX_CHAN; i++) {
71 if (*status & (1 << (i + base))) {
72 *status = *status & ~(1 << (i + base));
73 pr_debug("MDMA: index %d New status %x\n", i, *status);
74 return i;
75 }
76 }
77 return -1;
78}
79
80/**
81 * get_block_ts - calculates dma transaction length
82 * @len: dma transfer length
83 * @tx_width: dma transfer src width
84 * @block_size: dma controller max block size
85 *
86 * Based on src width calculate the DMA trsaction length in data items
87 * return data items or FFFF if exceeds max length for block
88 */
89static int get_block_ts(int len, int tx_width, int block_size)
90{
91 int byte_width = 0, block_ts = 0;
92
93 switch (tx_width) {
94 case LNW_DMA_WIDTH_8BIT:
95 byte_width = 1;
96 break;
97 case LNW_DMA_WIDTH_16BIT:
98 byte_width = 2;
99 break;
100 case LNW_DMA_WIDTH_32BIT:
101 default:
102 byte_width = 4;
103 break;
104 }
105
106 block_ts = len/byte_width;
107 if (block_ts > block_size)
108 block_ts = 0xFFFF;
109 return block_ts;
110}
111
112/*****************************************************************************
113DMAC1 interrupt Functions*/
114
115/**
116 * dmac1_mask_periphral_intr - mask the periphral interrupt
117 * @midc: dma channel for which masking is required
118 *
119 * Masks the DMA periphral interrupt
120 * this is valid for DMAC1 family controllers only
121 * This controller should have periphral mask registers already mapped
122 */
123static void dmac1_mask_periphral_intr(struct intel_mid_dma_chan *midc)
124{
125 u32 pimr;
126 struct middma_device *mid = to_middma_device(midc->chan.device);
127
128 if (mid->pimr_mask) {
129 pimr = readl(mid->mask_reg + LNW_PERIPHRAL_MASK);
130 pimr |= mid->pimr_mask;
131 writel(pimr, mid->mask_reg + LNW_PERIPHRAL_MASK);
132 }
133 return;
134}
135
136/**
137 * dmac1_unmask_periphral_intr - unmask the periphral interrupt
138 * @midc: dma channel for which masking is required
139 *
140 * UnMasks the DMA periphral interrupt,
141 * this is valid for DMAC1 family controllers only
142 * This controller should have periphral mask registers already mapped
143 */
144static void dmac1_unmask_periphral_intr(struct intel_mid_dma_chan *midc)
145{
146 u32 pimr;
147 struct middma_device *mid = to_middma_device(midc->chan.device);
148
149 if (mid->pimr_mask) {
150 pimr = readl(mid->mask_reg + LNW_PERIPHRAL_MASK);
151 pimr &= ~mid->pimr_mask;
152 writel(pimr, mid->mask_reg + LNW_PERIPHRAL_MASK);
153 }
154 return;
155}
156
157/**
158 * enable_dma_interrupt - enable the periphral interrupt
159 * @midc: dma channel for which enable interrupt is required
160 *
161 * Enable the DMA periphral interrupt,
162 * this is valid for DMAC1 family controllers only
163 * This controller should have periphral mask registers already mapped
164 */
165static void enable_dma_interrupt(struct intel_mid_dma_chan *midc)
166{
167 dmac1_unmask_periphral_intr(midc);
168
169 /*en ch interrupts*/
170 iowrite32(UNMASK_INTR_REG(midc->ch_id), midc->dma_base + MASK_TFR);
171 iowrite32(UNMASK_INTR_REG(midc->ch_id), midc->dma_base + MASK_ERR);
172 return;
173}
174
175/**
176 * disable_dma_interrupt - disable the periphral interrupt
177 * @midc: dma channel for which disable interrupt is required
178 *
179 * Disable the DMA periphral interrupt,
180 * this is valid for DMAC1 family controllers only
181 * This controller should have periphral mask registers already mapped
182 */
183static void disable_dma_interrupt(struct intel_mid_dma_chan *midc)
184{
185 /*Check LPE PISR, make sure fwd is disabled*/
186 dmac1_mask_periphral_intr(midc);
187 iowrite32(MASK_INTR_REG(midc->ch_id), midc->dma_base + MASK_BLOCK);
188 iowrite32(MASK_INTR_REG(midc->ch_id), midc->dma_base + MASK_TFR);
189 iowrite32(MASK_INTR_REG(midc->ch_id), midc->dma_base + MASK_ERR);
190 return;
191}
192
193/*****************************************************************************
194DMA channel helper Functions*/
195/**
196 * mid_desc_get - get a descriptor
197 * @midc: dma channel for which descriptor is required
198 *
199 * Obtain a descriptor for the channel. Returns NULL if none are free.
200 * Once the descriptor is returned it is private until put on another
201 * list or freed
202 */
203static struct intel_mid_dma_desc *midc_desc_get(struct intel_mid_dma_chan *midc)
204{
205 struct intel_mid_dma_desc *desc, *_desc;
206 struct intel_mid_dma_desc *ret = NULL;
207
208 spin_lock_bh(&midc->lock);
209 list_for_each_entry_safe(desc, _desc, &midc->free_list, desc_node) {
210 if (async_tx_test_ack(&desc->txd)) {
211 list_del(&desc->desc_node);
212 ret = desc;
213 break;
214 }
215 }
216 spin_unlock_bh(&midc->lock);
217 return ret;
218}
219
220/**
221 * mid_desc_put - put a descriptor
222 * @midc: dma channel for which descriptor is required
223 * @desc: descriptor to put
224 *
225 * Return a descriptor from lwn_desc_get back to the free pool
226 */
227static void midc_desc_put(struct intel_mid_dma_chan *midc,
228 struct intel_mid_dma_desc *desc)
229{
230 if (desc) {
231 spin_lock_bh(&midc->lock);
232 list_add_tail(&desc->desc_node, &midc->free_list);
233 spin_unlock_bh(&midc->lock);
234 }
235}
236/**
237 * midc_dostart - begin a DMA transaction
238 * @midc: channel for which txn is to be started
239 * @first: first descriptor of series
240 *
241 * Load a transaction into the engine. This must be called with midc->lock
242 * held and bh disabled.
243 */
244static void midc_dostart(struct intel_mid_dma_chan *midc,
245 struct intel_mid_dma_desc *first)
246{
247 struct middma_device *mid = to_middma_device(midc->chan.device);
248
249 /* channel is idle */
250 if (midc->in_use && test_ch_en(midc->dma_base, midc->ch_id)) {
251 /*error*/
252 pr_err("ERR_MDMA: channel is busy in start\n");
253 /* The tasklet will hopefully advance the queue... */
254 return;
255 }
256
257 /*write registers and en*/
258 iowrite32(first->sar, midc->ch_regs + SAR);
259 iowrite32(first->dar, midc->ch_regs + DAR);
260 iowrite32(first->cfg_hi, midc->ch_regs + CFG_HIGH);
261 iowrite32(first->cfg_lo, midc->ch_regs + CFG_LOW);
262 iowrite32(first->ctl_lo, midc->ch_regs + CTL_LOW);
263 iowrite32(first->ctl_hi, midc->ch_regs + CTL_HIGH);
264 pr_debug("MDMA:TX SAR %x,DAR %x,CFGL %x,CFGH %x,CTLH %x, CTLL %x\n",
265 (int)first->sar, (int)first->dar, first->cfg_hi,
266 first->cfg_lo, first->ctl_hi, first->ctl_lo);
267
268 iowrite32(ENABLE_CHANNEL(midc->ch_id), mid->dma_base + DMA_CHAN_EN);
269 first->status = DMA_IN_PROGRESS;
270}
271
272/**
273 * midc_descriptor_complete - process completed descriptor
274 * @midc: channel owning the descriptor
275 * @desc: the descriptor itself
276 *
277 * Process a completed descriptor and perform any callbacks upon
278 * the completion. The completion handling drops the lock during the
279 * callbacks but must be called with the lock held.
280 */
281static void midc_descriptor_complete(struct intel_mid_dma_chan *midc,
282 struct intel_mid_dma_desc *desc)
283{
284 struct dma_async_tx_descriptor *txd = &desc->txd;
285 dma_async_tx_callback callback_txd = NULL;
286 void *param_txd = NULL;
287
288 midc->completed = txd->cookie;
289 callback_txd = txd->callback;
290 param_txd = txd->callback_param;
291
292 list_move(&desc->desc_node, &midc->free_list);
293
294 spin_unlock_bh(&midc->lock);
295 if (callback_txd) {
296 pr_debug("MDMA: TXD callback set ... calling\n");
297 callback_txd(param_txd);
298 spin_lock_bh(&midc->lock);
299 return;
300 }
301 spin_lock_bh(&midc->lock);
302
303}
304/**
305 * midc_scan_descriptors - check the descriptors in channel
306 * mark completed when tx is completete
307 * @mid: device
308 * @midc: channel to scan
309 *
310 * Walk the descriptor chain for the device and process any entries
311 * that are complete.
312 */
313static void midc_scan_descriptors(struct middma_device *mid,
314 struct intel_mid_dma_chan *midc)
315{
316 struct intel_mid_dma_desc *desc = NULL, *_desc = NULL;
317
318 /*tx is complete*/
319 list_for_each_entry_safe(desc, _desc, &midc->active_list, desc_node) {
320 if (desc->status == DMA_IN_PROGRESS) {
321 desc->status = DMA_SUCCESS;
322 midc_descriptor_complete(midc, desc);
323 }
324 }
325 return;
326}
327
328/*****************************************************************************
329DMA engine callback Functions*/
330/**
331 * intel_mid_dma_tx_submit - callback to submit DMA transaction
332 * @tx: dma engine descriptor
333 *
334 * Submit the DMA trasaction for this descriptor, start if ch idle
335 */
336static dma_cookie_t intel_mid_dma_tx_submit(struct dma_async_tx_descriptor *tx)
337{
338 struct intel_mid_dma_desc *desc = to_intel_mid_dma_desc(tx);
339 struct intel_mid_dma_chan *midc = to_intel_mid_dma_chan(tx->chan);
340 dma_cookie_t cookie;
341
342 spin_lock_bh(&midc->lock);
343 cookie = midc->chan.cookie;
344
345 if (++cookie < 0)
346 cookie = 1;
347
348 midc->chan.cookie = cookie;
349 desc->txd.cookie = cookie;
350
351
352 if (list_empty(&midc->active_list)) {
353 midc_dostart(midc, desc);
354 list_add_tail(&desc->desc_node, &midc->active_list);
355 } else {
356 list_add_tail(&desc->desc_node, &midc->queue);
357 }
358 spin_unlock_bh(&midc->lock);
359
360 return cookie;
361}
362
363/**
364 * intel_mid_dma_issue_pending - callback to issue pending txn
365 * @chan: chan where pending trascation needs to be checked and submitted
366 *
367 * Call for scan to issue pending descriptors
368 */
369static void intel_mid_dma_issue_pending(struct dma_chan *chan)
370{
371 struct intel_mid_dma_chan *midc = to_intel_mid_dma_chan(chan);
372
373 spin_lock_bh(&midc->lock);
374 if (!list_empty(&midc->queue))
375 midc_scan_descriptors(to_middma_device(chan->device), midc);
376 spin_unlock_bh(&midc->lock);
377}
378
379/**
380 * intel_mid_dma_tx_status - Return status of txn
381 * @chan: chan for where status needs to be checked
382 * @cookie: cookie for txn
383 * @txstate: DMA txn state
384 *
385 * Return status of DMA txn
386 */
387static enum dma_status intel_mid_dma_tx_status(struct dma_chan *chan,
388 dma_cookie_t cookie,
389 struct dma_tx_state *txstate)
390{
391 struct intel_mid_dma_chan *midc = to_intel_mid_dma_chan(chan);
392 dma_cookie_t last_used;
393 dma_cookie_t last_complete;
394 int ret;
395
396 last_complete = midc->completed;
397 last_used = chan->cookie;
398
399 ret = dma_async_is_complete(cookie, last_complete, last_used);
400 if (ret != DMA_SUCCESS) {
401 midc_scan_descriptors(to_middma_device(chan->device), midc);
402
403 last_complete = midc->completed;
404 last_used = chan->cookie;
405
406 ret = dma_async_is_complete(cookie, last_complete, last_used);
407 }
408
409 if (txstate) {
410 txstate->last = last_complete;
411 txstate->used = last_used;
412 txstate->residue = 0;
413 }
414 return ret;
415}
416
417/**
418 * intel_mid_dma_device_control - DMA device control
419 * @chan: chan for DMA control
420 * @cmd: control cmd
421 * @arg: cmd arg value
422 *
423 * Perform DMA control command
424 */
425static int intel_mid_dma_device_control(struct dma_chan *chan,
426 enum dma_ctrl_cmd cmd, unsigned long arg)
427{
428 struct intel_mid_dma_chan *midc = to_intel_mid_dma_chan(chan);
429 struct middma_device *mid = to_middma_device(chan->device);
430 struct intel_mid_dma_desc *desc, *_desc;
431 LIST_HEAD(list);
432
433 if (cmd != DMA_TERMINATE_ALL)
434 return -ENXIO;
435
436 spin_lock_bh(&midc->lock);
437 if (midc->in_use == false) {
438 spin_unlock_bh(&midc->lock);
439 return 0;
440 }
441 list_splice_init(&midc->free_list, &list);
442 midc->descs_allocated = 0;
443 midc->slave = NULL;
444
445 /* Disable interrupts */
446 disable_dma_interrupt(midc);
447
448 spin_unlock_bh(&midc->lock);
449 list_for_each_entry_safe(desc, _desc, &list, desc_node) {
450 pr_debug("MDMA: freeing descriptor %p\n", desc);
451 pci_pool_free(mid->dma_pool, desc, desc->txd.phys);
452 }
453 return 0;
454}
455
456/**
457 * intel_mid_dma_prep_slave_sg - Prep slave sg txn
458 * @chan: chan for DMA transfer
459 * @sgl: scatter gather list
460 * @sg_len: length of sg txn
461 * @direction: DMA transfer dirtn
462 * @flags: DMA flags
463 *
464 * Do DMA sg txn: NOT supported now
465 */
466static struct dma_async_tx_descriptor *intel_mid_dma_prep_slave_sg(
467 struct dma_chan *chan, struct scatterlist *sgl,
468 unsigned int sg_len, enum dma_data_direction direction,
469 unsigned long flags)
470{
471 /*not supported now*/
472 return NULL;
473}
474
475/**
476 * intel_mid_dma_prep_memcpy - Prep memcpy txn
477 * @chan: chan for DMA transfer
478 * @dest: destn address
479 * @src: src address
480 * @len: DMA transfer len
481 * @flags: DMA flags
482 *
483 * Perform a DMA memcpy. Note we support slave periphral DMA transfers only
484 * The periphral txn details should be filled in slave structure properly
485 * Returns the descriptor for this txn
486 */
487static struct dma_async_tx_descriptor *intel_mid_dma_prep_memcpy(
488 struct dma_chan *chan, dma_addr_t dest,
489 dma_addr_t src, size_t len, unsigned long flags)
490{
491 struct intel_mid_dma_chan *midc;
492 struct intel_mid_dma_desc *desc = NULL;
493 struct intel_mid_dma_slave *mids;
494 union intel_mid_dma_ctl_lo ctl_lo;
495 union intel_mid_dma_ctl_hi ctl_hi;
496 union intel_mid_dma_cfg_lo cfg_lo;
497 union intel_mid_dma_cfg_hi cfg_hi;
498 enum intel_mid_dma_width width = 0;
499
500 pr_debug("MDMA: Prep for memcpy\n");
501 WARN_ON(!chan);
502 if (!len)
503 return NULL;
504
505 mids = chan->private;
506 WARN_ON(!mids);
507
508 midc = to_intel_mid_dma_chan(chan);
509 WARN_ON(!midc);
510
511 pr_debug("MDMA:called for DMA %x CH %d Length %zu\n",
512 midc->dma->pci_id, midc->ch_id, len);
513 pr_debug("MDMA:Cfg passed Mode %x, Dirn %x, HS %x, Width %x\n",
514 mids->cfg_mode, mids->dirn, mids->hs_mode, mids->src_width);
515
516 /*calculate CFG_LO*/
517 if (mids->hs_mode == LNW_DMA_SW_HS) {
518 cfg_lo.cfg_lo = 0;
519 cfg_lo.cfgx.hs_sel_dst = 1;
520 cfg_lo.cfgx.hs_sel_src = 1;
521 } else if (mids->hs_mode == LNW_DMA_HW_HS)
522 cfg_lo.cfg_lo = 0x00000;
523
524 /*calculate CFG_HI*/
525 if (mids->cfg_mode == LNW_DMA_MEM_TO_MEM) {
526 /*SW HS only*/
527 cfg_hi.cfg_hi = 0;
528 } else {
529 cfg_hi.cfg_hi = 0;
530 if (midc->dma->pimr_mask) {
531 cfg_hi.cfgx.protctl = 0x0; /*default value*/
532 cfg_hi.cfgx.fifo_mode = 1;
533 if (mids->dirn == DMA_TO_DEVICE) {
534 cfg_hi.cfgx.src_per = 0;
535 if (mids->device_instance == 0)
536 cfg_hi.cfgx.dst_per = 3;
537 if (mids->device_instance == 1)
538 cfg_hi.cfgx.dst_per = 1;
539 } else if (mids->dirn == DMA_FROM_DEVICE) {
540 if (mids->device_instance == 0)
541 cfg_hi.cfgx.src_per = 2;
542 if (mids->device_instance == 1)
543 cfg_hi.cfgx.src_per = 0;
544 cfg_hi.cfgx.dst_per = 0;
545 }
546 } else {
547 cfg_hi.cfgx.protctl = 0x1; /*default value*/
548 cfg_hi.cfgx.src_per = cfg_hi.cfgx.dst_per =
549 midc->ch_id - midc->dma->chan_base;
550 }
551 }
552
553 /*calculate CTL_HI*/
554 ctl_hi.ctlx.reser = 0;
555 width = mids->src_width;
556
557 ctl_hi.ctlx.block_ts = get_block_ts(len, width, midc->dma->block_size);
558 pr_debug("MDMA:calc len %d for block size %d\n",
559 ctl_hi.ctlx.block_ts, midc->dma->block_size);
560 /*calculate CTL_LO*/
561 ctl_lo.ctl_lo = 0;
562 ctl_lo.ctlx.int_en = 1;
563 ctl_lo.ctlx.dst_tr_width = mids->dst_width;
564 ctl_lo.ctlx.src_tr_width = mids->src_width;
565 ctl_lo.ctlx.dst_msize = mids->src_msize;
566 ctl_lo.ctlx.src_msize = mids->dst_msize;
567
568 if (mids->cfg_mode == LNW_DMA_MEM_TO_MEM) {
569 ctl_lo.ctlx.tt_fc = 0;
570 ctl_lo.ctlx.sinc = 0;
571 ctl_lo.ctlx.dinc = 0;
572 } else {
573 if (mids->dirn == DMA_TO_DEVICE) {
574 ctl_lo.ctlx.sinc = 0;
575 ctl_lo.ctlx.dinc = 2;
576 ctl_lo.ctlx.tt_fc = 1;
577 } else if (mids->dirn == DMA_FROM_DEVICE) {
578 ctl_lo.ctlx.sinc = 2;
579 ctl_lo.ctlx.dinc = 0;
580 ctl_lo.ctlx.tt_fc = 2;
581 }
582 }
583
584 pr_debug("MDMA:Calc CTL LO %x, CTL HI %x, CFG LO %x, CFG HI %x\n",
585 ctl_lo.ctl_lo, ctl_hi.ctl_hi, cfg_lo.cfg_lo, cfg_hi.cfg_hi);
586
587 enable_dma_interrupt(midc);
588
589 desc = midc_desc_get(midc);
590 if (desc == NULL)
591 goto err_desc_get;
592 desc->sar = src;
593 desc->dar = dest ;
594 desc->len = len;
595 desc->cfg_hi = cfg_hi.cfg_hi;
596 desc->cfg_lo = cfg_lo.cfg_lo;
597 desc->ctl_lo = ctl_lo.ctl_lo;
598 desc->ctl_hi = ctl_hi.ctl_hi;
599 desc->width = width;
600 desc->dirn = mids->dirn;
601 return &desc->txd;
602
603err_desc_get:
604 pr_err("ERR_MDMA: Failed to get desc\n");
605 midc_desc_put(midc, desc);
606 return NULL;
607}
608
609/**
610 * intel_mid_dma_free_chan_resources - Frees dma resources
611 * @chan: chan requiring attention
612 *
613 * Frees the allocated resources on this DMA chan
614 */
615static void intel_mid_dma_free_chan_resources(struct dma_chan *chan)
616{
617 struct intel_mid_dma_chan *midc = to_intel_mid_dma_chan(chan);
618 struct middma_device *mid = to_middma_device(chan->device);
619 struct intel_mid_dma_desc *desc, *_desc;
620
621 if (true == midc->in_use) {
622 /*trying to free ch in use!!!!!*/
623 pr_err("ERR_MDMA: trying to free ch in use\n");
624 }
625
626 spin_lock_bh(&midc->lock);
627 midc->descs_allocated = 0;
628 list_for_each_entry_safe(desc, _desc, &midc->active_list, desc_node) {
629 list_del(&desc->desc_node);
630 pci_pool_free(mid->dma_pool, desc, desc->txd.phys);
631 }
632 list_for_each_entry_safe(desc, _desc, &midc->free_list, desc_node) {
633 list_del(&desc->desc_node);
634 pci_pool_free(mid->dma_pool, desc, desc->txd.phys);
635 }
636 list_for_each_entry_safe(desc, _desc, &midc->queue, desc_node) {
637 list_del(&desc->desc_node);
638 pci_pool_free(mid->dma_pool, desc, desc->txd.phys);
639 }
640 spin_unlock_bh(&midc->lock);
641 midc->in_use = false;
642 /* Disable CH interrupts */
643 iowrite32(MASK_INTR_REG(midc->ch_id), mid->dma_base + MASK_BLOCK);
644 iowrite32(MASK_INTR_REG(midc->ch_id), mid->dma_base + MASK_ERR);
645}
646
647/**
648 * intel_mid_dma_alloc_chan_resources - Allocate dma resources
649 * @chan: chan requiring attention
650 *
651 * Allocates DMA resources on this chan
652 * Return the descriptors allocated
653 */
654static int intel_mid_dma_alloc_chan_resources(struct dma_chan *chan)
655{
656 struct intel_mid_dma_chan *midc = to_intel_mid_dma_chan(chan);
657 struct middma_device *mid = to_middma_device(chan->device);
658 struct intel_mid_dma_desc *desc;
659 dma_addr_t phys;
660 int i = 0;
661
662
663 /* ASSERT: channel is idle */
664 if (test_ch_en(mid->dma_base, midc->ch_id)) {
665 /*ch is not idle*/
666 pr_err("ERR_MDMA: ch not idle\n");
667 return -EIO;
668 }
669 midc->completed = chan->cookie = 1;
670
671 spin_lock_bh(&midc->lock);
672 while (midc->descs_allocated < DESCS_PER_CHANNEL) {
673 spin_unlock_bh(&midc->lock);
674 desc = pci_pool_alloc(mid->dma_pool, GFP_KERNEL, &phys);
675 if (!desc) {
676 pr_err("ERR_MDMA: desc failed\n");
677 return -ENOMEM;
678 /*check*/
679 }
680 dma_async_tx_descriptor_init(&desc->txd, chan);
681 desc->txd.tx_submit = intel_mid_dma_tx_submit;
682 desc->txd.flags = DMA_CTRL_ACK;
683 desc->txd.phys = phys;
684 spin_lock_bh(&midc->lock);
685 i = ++midc->descs_allocated;
686 list_add_tail(&desc->desc_node, &midc->free_list);
687 }
688 spin_unlock_bh(&midc->lock);
689 midc->in_use = false;
690 pr_debug("MID_DMA: Desc alloc done ret: %d desc\n", i);
691 return i;
692}
693
694/**
695 * midc_handle_error - Handle DMA txn error
696 * @mid: controller where error occured
697 * @midc: chan where error occured
698 *
699 * Scan the descriptor for error
700 */
701static void midc_handle_error(struct middma_device *mid,
702 struct intel_mid_dma_chan *midc)
703{
704 midc_scan_descriptors(mid, midc);
705}
706
707/**
708 * dma_tasklet - DMA interrupt tasklet
709 * @data: tasklet arg (the controller structure)
710 *
711 * Scan the controller for interrupts for completion/error
712 * Clear the interrupt and call for handling completion/error
713 */
714static void dma_tasklet(unsigned long data)
715{
716 struct middma_device *mid = NULL;
717 struct intel_mid_dma_chan *midc = NULL;
718 u32 status;
719 int i;
720
721 mid = (struct middma_device *)data;
722 if (mid == NULL) {
723 pr_err("ERR_MDMA: tasklet Null param\n");
724 return;
725 }
726 pr_debug("MDMA: in tasklet for device %x\n", mid->pci_id);
727 status = ioread32(mid->dma_base + RAW_TFR);
728 pr_debug("MDMA:RAW_TFR %x\n", status);
729 status &= mid->intr_mask;
730 while (status) {
731 /*txn interrupt*/
732 i = get_ch_index(&status, mid->chan_base);
733 if (i < 0) {
734 pr_err("ERR_MDMA:Invalid ch index %x\n", i);
735 return;
736 }
737 midc = &mid->ch[i];
738 if (midc == NULL) {
739 pr_err("ERR_MDMA:Null param midc\n");
740 return;
741 }
742 pr_debug("MDMA:Tx complete interrupt %x, Ch No %d Index %d\n",
743 status, midc->ch_id, i);
744 /*clearing this interrupts first*/
745 iowrite32((1 << midc->ch_id), mid->dma_base + CLEAR_TFR);
746 iowrite32((1 << midc->ch_id), mid->dma_base + CLEAR_BLOCK);
747
748 spin_lock_bh(&midc->lock);
749 midc_scan_descriptors(mid, midc);
750 pr_debug("MDMA:Scan of desc... complete, unmasking\n");
751 iowrite32(UNMASK_INTR_REG(midc->ch_id),
752 mid->dma_base + MASK_TFR);
753 spin_unlock_bh(&midc->lock);
754 }
755
756 status = ioread32(mid->dma_base + RAW_ERR);
757 status &= mid->intr_mask;
758 while (status) {
759 /*err interrupt*/
760 i = get_ch_index(&status, mid->chan_base);
761 if (i < 0) {
762 pr_err("ERR_MDMA:Invalid ch index %x\n", i);
763 return;
764 }
765 midc = &mid->ch[i];
766 if (midc == NULL) {
767 pr_err("ERR_MDMA:Null param midc\n");
768 return;
769 }
770 pr_debug("MDMA:Tx complete interrupt %x, Ch No %d Index %d\n",
771 status, midc->ch_id, i);
772
773 iowrite32((1 << midc->ch_id), mid->dma_base + CLEAR_ERR);
774 spin_lock_bh(&midc->lock);
775 midc_handle_error(mid, midc);
776 iowrite32(UNMASK_INTR_REG(midc->ch_id),
777 mid->dma_base + MASK_ERR);
778 spin_unlock_bh(&midc->lock);
779 }
780 pr_debug("MDMA:Exiting takslet...\n");
781 return;
782}
783
784static void dma_tasklet1(unsigned long data)
785{
786 pr_debug("MDMA:in takslet1...\n");
787 return dma_tasklet(data);
788}
789
790static void dma_tasklet2(unsigned long data)
791{
792 pr_debug("MDMA:in takslet2...\n");
793 return dma_tasklet(data);
794}
795
796/**
797 * intel_mid_dma_interrupt - DMA ISR
798 * @irq: IRQ where interrupt occurred
799 * @data: ISR cllback data (the controller structure)
800 *
801 * See if this is our interrupt if so then schedule the tasklet
802 * otherwise ignore
803 */
804static irqreturn_t intel_mid_dma_interrupt(int irq, void *data)
805{
806 struct middma_device *mid = data;
807 u32 status;
808 int call_tasklet = 0;
809
810 /*DMA Interrupt*/
811 pr_debug("MDMA:Got an interrupt on irq %d\n", irq);
812 if (!mid) {
813 pr_err("ERR_MDMA:null pointer mid\n");
814 return -EINVAL;
815 }
816
817 status = ioread32(mid->dma_base + RAW_TFR);
818 pr_debug("MDMA: Status %x, Mask %x\n", status, mid->intr_mask);
819 status &= mid->intr_mask;
820 if (status) {
821 /*need to disable intr*/
822 iowrite32((status << 8), mid->dma_base + MASK_TFR);
823 pr_debug("MDMA: Calling tasklet %x\n", status);
824 call_tasklet = 1;
825 }
826 status = ioread32(mid->dma_base + RAW_ERR);
827 status &= mid->intr_mask;
828 if (status) {
829 iowrite32(MASK_INTR_REG(status), mid->dma_base + MASK_ERR);
830 call_tasklet = 1;
831 }
832 if (call_tasklet)
833 tasklet_schedule(&mid->tasklet);
834
835 return IRQ_HANDLED;
836}
837
838static irqreturn_t intel_mid_dma_interrupt1(int irq, void *data)
839{
840 return intel_mid_dma_interrupt(irq, data);
841}
842
843static irqreturn_t intel_mid_dma_interrupt2(int irq, void *data)
844{
845 return intel_mid_dma_interrupt(irq, data);
846}
847
848/**
849 * mid_setup_dma - Setup the DMA controller
850 * @pdev: Controller PCI device structure
851 *
852 * Initilize the DMA controller, channels, registers with DMA engine,
853 * ISR. Initilize DMA controller channels.
854 */
855static int mid_setup_dma(struct pci_dev *pdev)
856{
857 struct middma_device *dma = pci_get_drvdata(pdev);
858 int err, i;
859 unsigned int irq_level;
860
861 /* DMA coherent memory pool for DMA descriptor allocations */
862 dma->dma_pool = pci_pool_create("intel_mid_dma_desc_pool", pdev,
863 sizeof(struct intel_mid_dma_desc),
864 32, 0);
865 if (NULL == dma->dma_pool) {
866 pr_err("ERR_MDMA:pci_pool_create failed\n");
867 err = -ENOMEM;
868 kfree(dma);
869 goto err_dma_pool;
870 }
871
872 INIT_LIST_HEAD(&dma->common.channels);
873 dma->pci_id = pdev->device;
874 if (dma->pimr_mask) {
875 dma->mask_reg = ioremap(LNW_PERIPHRAL_MASK_BASE,
876 LNW_PERIPHRAL_MASK_SIZE);
877 if (dma->mask_reg == NULL) {
878 pr_err("ERR_MDMA:Cant map periphral intr space !!\n");
879 return -ENOMEM;
880 }
881 } else
882 dma->mask_reg = NULL;
883
884 pr_debug("MDMA:Adding %d channel for this controller\n", dma->max_chan);
885 /*init CH structures*/
886 dma->intr_mask = 0;
887 for (i = 0; i < dma->max_chan; i++) {
888 struct intel_mid_dma_chan *midch = &dma->ch[i];
889
890 midch->chan.device = &dma->common;
891 midch->chan.cookie = 1;
892 midch->chan.chan_id = i;
893 midch->ch_id = dma->chan_base + i;
894 pr_debug("MDMA:Init CH %d, ID %d\n", i, midch->ch_id);
895
896 midch->dma_base = dma->dma_base;
897 midch->ch_regs = dma->dma_base + DMA_CH_SIZE * midch->ch_id;
898 midch->dma = dma;
899 dma->intr_mask |= 1 << (dma->chan_base + i);
900 spin_lock_init(&midch->lock);
901
902 INIT_LIST_HEAD(&midch->active_list);
903 INIT_LIST_HEAD(&midch->queue);
904 INIT_LIST_HEAD(&midch->free_list);
905 /*mask interrupts*/
906 iowrite32(MASK_INTR_REG(midch->ch_id),
907 dma->dma_base + MASK_BLOCK);
908 iowrite32(MASK_INTR_REG(midch->ch_id),
909 dma->dma_base + MASK_SRC_TRAN);
910 iowrite32(MASK_INTR_REG(midch->ch_id),
911 dma->dma_base + MASK_DST_TRAN);
912 iowrite32(MASK_INTR_REG(midch->ch_id),
913 dma->dma_base + MASK_ERR);
914 iowrite32(MASK_INTR_REG(midch->ch_id),
915 dma->dma_base + MASK_TFR);
916
917 disable_dma_interrupt(midch);
918 list_add_tail(&midch->chan.device_node, &dma->common.channels);
919 }
920 pr_debug("MDMA: Calc Mask as %x for this controller\n", dma->intr_mask);
921
922 /*init dma structure*/
923 dma_cap_zero(dma->common.cap_mask);
924 dma_cap_set(DMA_MEMCPY, dma->common.cap_mask);
925 dma_cap_set(DMA_SLAVE, dma->common.cap_mask);
926 dma_cap_set(DMA_PRIVATE, dma->common.cap_mask);
927 dma->common.dev = &pdev->dev;
928 dma->common.chancnt = dma->max_chan;
929
930 dma->common.device_alloc_chan_resources =
931 intel_mid_dma_alloc_chan_resources;
932 dma->common.device_free_chan_resources =
933 intel_mid_dma_free_chan_resources;
934
935 dma->common.device_tx_status = intel_mid_dma_tx_status;
936 dma->common.device_prep_dma_memcpy = intel_mid_dma_prep_memcpy;
937 dma->common.device_issue_pending = intel_mid_dma_issue_pending;
938 dma->common.device_prep_slave_sg = intel_mid_dma_prep_slave_sg;
939 dma->common.device_control = intel_mid_dma_device_control;
940
941 /*enable dma cntrl*/
942 iowrite32(REG_BIT0, dma->dma_base + DMA_CFG);
943
944 /*register irq */
945 if (dma->pimr_mask) {
946 irq_level = IRQF_SHARED;
947 pr_debug("MDMA:Requesting irq shared for DMAC1\n");
948 err = request_irq(pdev->irq, intel_mid_dma_interrupt1,
949 IRQF_SHARED, "INTEL_MID_DMAC1", dma);
950 if (0 != err)
951 goto err_irq;
952 } else {
953 dma->intr_mask = 0x03;
954 irq_level = 0;
955 pr_debug("MDMA:Requesting irq for DMAC2\n");
956 err = request_irq(pdev->irq, intel_mid_dma_interrupt2,
957 0, "INTEL_MID_DMAC2", dma);
958 if (0 != err)
959 goto err_irq;
960 }
961 /*register device w/ engine*/
962 err = dma_async_device_register(&dma->common);
963 if (0 != err) {
964 pr_err("ERR_MDMA:device_register failed: %d\n", err);
965 goto err_engine;
966 }
967 if (dma->pimr_mask) {
968 pr_debug("setting up tasklet1 for DMAC1\n");
969 tasklet_init(&dma->tasklet, dma_tasklet1, (unsigned long)dma);
970 } else {
971 pr_debug("setting up tasklet2 for DMAC2\n");
972 tasklet_init(&dma->tasklet, dma_tasklet2, (unsigned long)dma);
973 }
974 return 0;
975
976err_engine:
977 free_irq(pdev->irq, dma);
978err_irq:
979 pci_pool_destroy(dma->dma_pool);
980 kfree(dma);
981err_dma_pool:
982 pr_err("ERR_MDMA:setup_dma failed: %d\n", err);
983 return err;
984
985}
986
987/**
988 * middma_shutdown - Shutdown the DMA controller
989 * @pdev: Controller PCI device structure
990 *
991 * Called by remove
992 * Unregister DMa controller, clear all structures and free interrupt
993 */
994static void middma_shutdown(struct pci_dev *pdev)
995{
996 struct middma_device *device = pci_get_drvdata(pdev);
997
998 dma_async_device_unregister(&device->common);
999 pci_pool_destroy(device->dma_pool);
1000 if (device->mask_reg)
1001 iounmap(device->mask_reg);
1002 if (device->dma_base)
1003 iounmap(device->dma_base);
1004 free_irq(pdev->irq, device);
1005 return;
1006}
1007
1008/**
1009 * intel_mid_dma_probe - PCI Probe
1010 * @pdev: Controller PCI device structure
1011 * @id: pci device id structure
1012 *
1013 * Initilize the PCI device, map BARs, query driver data.
1014 * Call setup_dma to complete contoller and chan initilzation
1015 */
1016static int __devinit intel_mid_dma_probe(struct pci_dev *pdev,
1017 const struct pci_device_id *id)
1018{
1019 struct middma_device *device;
1020 u32 base_addr, bar_size;
1021 struct intel_mid_dma_probe_info *info;
1022 int err;
1023
1024 pr_debug("MDMA: probe for %x\n", pdev->device);
1025 info = (void *)id->driver_data;
1026 pr_debug("MDMA: CH %d, base %d, block len %d, Periphral mask %x\n",
1027 info->max_chan, info->ch_base,
1028 info->block_size, info->pimr_mask);
1029
1030 err = pci_enable_device(pdev);
1031 if (err)
1032 goto err_enable_device;
1033
1034 err = pci_request_regions(pdev, "intel_mid_dmac");
1035 if (err)
1036 goto err_request_regions;
1037
1038 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
1039 if (err)
1040 goto err_set_dma_mask;
1041
1042 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
1043 if (err)
1044 goto err_set_dma_mask;
1045
1046 device = kzalloc(sizeof(*device), GFP_KERNEL);
1047 if (!device) {
1048 pr_err("ERR_MDMA:kzalloc failed probe\n");
1049 err = -ENOMEM;
1050 goto err_kzalloc;
1051 }
1052 device->pdev = pci_dev_get(pdev);
1053
1054 base_addr = pci_resource_start(pdev, 0);
1055 bar_size = pci_resource_len(pdev, 0);
1056 device->dma_base = ioremap_nocache(base_addr, DMA_REG_SIZE);
1057 if (!device->dma_base) {
1058 pr_err("ERR_MDMA:ioremap failed\n");
1059 err = -ENOMEM;
1060 goto err_ioremap;
1061 }
1062 pci_set_drvdata(pdev, device);
1063 pci_set_master(pdev);
1064 device->max_chan = info->max_chan;
1065 device->chan_base = info->ch_base;
1066 device->block_size = info->block_size;
1067 device->pimr_mask = info->pimr_mask;
1068
1069 err = mid_setup_dma(pdev);
1070 if (err)
1071 goto err_dma;
1072
1073 return 0;
1074
1075err_dma:
1076 iounmap(device->dma_base);
1077err_ioremap:
1078 pci_dev_put(pdev);
1079 kfree(device);
1080err_kzalloc:
1081err_set_dma_mask:
1082 pci_release_regions(pdev);
1083 pci_disable_device(pdev);
1084err_request_regions:
1085err_enable_device:
1086 pr_err("ERR_MDMA:Probe failed %d\n", err);
1087 return err;
1088}
1089
1090/**
1091 * intel_mid_dma_remove - PCI remove
1092 * @pdev: Controller PCI device structure
1093 *
1094 * Free up all resources and data
1095 * Call shutdown_dma to complete contoller and chan cleanup
1096 */
1097static void __devexit intel_mid_dma_remove(struct pci_dev *pdev)
1098{
1099 struct middma_device *device = pci_get_drvdata(pdev);
1100 middma_shutdown(pdev);
1101 pci_dev_put(pdev);
1102 kfree(device);
1103 pci_release_regions(pdev);
1104 pci_disable_device(pdev);
1105}
1106
1107/******************************************************************************
1108* PCI stuff
1109*/
1110static struct pci_device_id intel_mid_dma_ids[] = {
1111 { PCI_VDEVICE(INTEL, INTEL_MID_DMAC1_ID), INFO(2, 6, 4095, 0x200020)},
1112 { PCI_VDEVICE(INTEL, INTEL_MID_DMAC2_ID), INFO(2, 0, 2047, 0)},
1113 { PCI_VDEVICE(INTEL, INTEL_MID_GP_DMAC2_ID), INFO(2, 0, 2047, 0)},
1114 { PCI_VDEVICE(INTEL, INTEL_MFLD_DMAC1_ID), INFO(4, 0, 4095, 0x400040)},
1115 { 0, }
1116};
1117MODULE_DEVICE_TABLE(pci, intel_mid_dma_ids);
1118
1119static struct pci_driver intel_mid_dma_pci = {
1120 .name = "Intel MID DMA",
1121 .id_table = intel_mid_dma_ids,
1122 .probe = intel_mid_dma_probe,
1123 .remove = __devexit_p(intel_mid_dma_remove),
1124};
1125
1126static int __init intel_mid_dma_init(void)
1127{
1128 pr_debug("INFO_MDMA: LNW DMA Driver Version %s\n",
1129 INTEL_MID_DMA_DRIVER_VERSION);
1130 return pci_register_driver(&intel_mid_dma_pci);
1131}
1132fs_initcall(intel_mid_dma_init);
1133
1134static void __exit intel_mid_dma_exit(void)
1135{
1136 pci_unregister_driver(&intel_mid_dma_pci);
1137}
1138module_exit(intel_mid_dma_exit);
1139
1140MODULE_AUTHOR("Vinod Koul <vinod.koul@intel.com>");
1141MODULE_DESCRIPTION("Intel (R) MID DMAC Driver");
1142MODULE_LICENSE("GPL v2");
1143MODULE_VERSION(INTEL_MID_DMA_DRIVER_VERSION);
diff --git a/drivers/dma/intel_mid_dma_regs.h b/drivers/dma/intel_mid_dma_regs.h
new file mode 100644
index 000000000000..d81aa658ab09
--- /dev/null
+++ b/drivers/dma/intel_mid_dma_regs.h
@@ -0,0 +1,260 @@
1/*
2 * intel_mid_dma_regs.h - Intel MID DMA Drivers
3 *
4 * Copyright (C) 2008-10 Intel Corp
5 * Author: Vinod Koul <vinod.koul@intel.com>
6 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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; version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20 *
21 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
22 *
23 *
24 */
25#ifndef __INTEL_MID_DMAC_REGS_H__
26#define __INTEL_MID_DMAC_REGS_H__
27
28#include <linux/dmaengine.h>
29#include <linux/dmapool.h>
30#include <linux/pci_ids.h>
31
32#define INTEL_MID_DMA_DRIVER_VERSION "1.0.5"
33
34#define REG_BIT0 0x00000001
35#define REG_BIT8 0x00000100
36
37#define UNMASK_INTR_REG(chan_num) \
38 ((REG_BIT0 << chan_num) | (REG_BIT8 << chan_num))
39#define MASK_INTR_REG(chan_num) (REG_BIT8 << chan_num)
40
41#define ENABLE_CHANNEL(chan_num) \
42 ((REG_BIT0 << chan_num) | (REG_BIT8 << chan_num))
43
44#define DESCS_PER_CHANNEL 16
45/*DMA Registers*/
46/*registers associated with channel programming*/
47#define DMA_REG_SIZE 0x400
48#define DMA_CH_SIZE 0x58
49
50/*CH X REG = (DMA_CH_SIZE)*CH_NO + REG*/
51#define SAR 0x00 /* Source Address Register*/
52#define DAR 0x08 /* Destination Address Register*/
53#define CTL_LOW 0x18 /* Control Register*/
54#define CTL_HIGH 0x1C /* Control Register*/
55#define CFG_LOW 0x40 /* Configuration Register Low*/
56#define CFG_HIGH 0x44 /* Configuration Register high*/
57
58#define STATUS_TFR 0x2E8
59#define STATUS_BLOCK 0x2F0
60#define STATUS_ERR 0x308
61
62#define RAW_TFR 0x2C0
63#define RAW_BLOCK 0x2C8
64#define RAW_ERR 0x2E0
65
66#define MASK_TFR 0x310
67#define MASK_BLOCK 0x318
68#define MASK_SRC_TRAN 0x320
69#define MASK_DST_TRAN 0x328
70#define MASK_ERR 0x330
71
72#define CLEAR_TFR 0x338
73#define CLEAR_BLOCK 0x340
74#define CLEAR_SRC_TRAN 0x348
75#define CLEAR_DST_TRAN 0x350
76#define CLEAR_ERR 0x358
77
78#define INTR_STATUS 0x360
79#define DMA_CFG 0x398
80#define DMA_CHAN_EN 0x3A0
81
82/*DMA channel control registers*/
83union intel_mid_dma_ctl_lo {
84 struct {
85 u32 int_en:1; /*enable or disable interrupts*/
86 /*should be 0*/
87 u32 dst_tr_width:3; /*destination transfer width*/
88 /*usually 32 bits = 010*/
89 u32 src_tr_width:3; /*source transfer width*/
90 /*usually 32 bits = 010*/
91 u32 dinc:2; /*destination address inc/dec*/
92 /*For mem:INC=00, Periphral NoINC=11*/
93 u32 sinc:2; /*source address inc or dec, as above*/
94 u32 dst_msize:3; /*destination burst transaction length*/
95 /*always = 16 ie 011*/
96 u32 src_msize:3; /*source burst transaction length*/
97 /*always = 16 ie 011*/
98 u32 reser1:3;
99 u32 tt_fc:3; /*transfer type and flow controller*/
100 /*M-M = 000
101 P-M = 010
102 M-P = 001*/
103 u32 dms:2; /*destination master select = 0*/
104 u32 sms:2; /*source master select = 0*/
105 u32 llp_dst_en:1; /*enable/disable destination LLP = 0*/
106 u32 llp_src_en:1; /*enable/disable source LLP = 0*/
107 u32 reser2:3;
108 } ctlx;
109 u32 ctl_lo;
110};
111
112union intel_mid_dma_ctl_hi {
113 struct {
114 u32 block_ts:12; /*block transfer size*/
115 /*configured by DMAC*/
116 u32 reser:20;
117 } ctlx;
118 u32 ctl_hi;
119
120};
121
122/*DMA channel configuration registers*/
123union intel_mid_dma_cfg_lo {
124 struct {
125 u32 reser1:5;
126 u32 ch_prior:3; /*channel priority = 0*/
127 u32 ch_susp:1; /*channel suspend = 0*/
128 u32 fifo_empty:1; /*FIFO empty or not R bit = 0*/
129 u32 hs_sel_dst:1; /*select HW/SW destn handshaking*/
130 /*HW = 0, SW = 1*/
131 u32 hs_sel_src:1; /*select HW/SW src handshaking*/
132 u32 reser2:6;
133 u32 dst_hs_pol:1; /*dest HS interface polarity*/
134 u32 src_hs_pol:1; /*src HS interface polarity*/
135 u32 max_abrst:10; /*max AMBA burst len = 0 (no sw limit*/
136 u32 reload_src:1; /*auto reload src addr =1 if src is P*/
137 u32 reload_dst:1; /*AR destn addr =1 if dstn is P*/
138 } cfgx;
139 u32 cfg_lo;
140};
141
142union intel_mid_dma_cfg_hi {
143 struct {
144 u32 fcmode:1; /*flow control mode = 1*/
145 u32 fifo_mode:1; /*FIFO mode select = 1*/
146 u32 protctl:3; /*protection control = 0*/
147 u32 rsvd:2;
148 u32 src_per:4; /*src hw HS interface*/
149 u32 dst_per:4; /*dstn hw HS interface*/
150 u32 reser2:17;
151 } cfgx;
152 u32 cfg_hi;
153};
154
155/**
156 * struct intel_mid_dma_chan - internal mid representation of a DMA channel
157 * @chan: dma_chan strcture represetation for mid chan
158 * @ch_regs: MMIO register space pointer to channel register
159 * @dma_base: MMIO register space DMA engine base pointer
160 * @ch_id: DMA channel id
161 * @lock: channel spinlock
162 * @completed: DMA cookie
163 * @active_list: current active descriptors
164 * @queue: current queued up descriptors
165 * @free_list: current free descriptors
166 * @slave: dma slave struture
167 * @descs_allocated: total number of decsiptors allocated
168 * @dma: dma device struture pointer
169 * @in_use: bool representing if ch is in use or not
170 */
171struct intel_mid_dma_chan {
172 struct dma_chan chan;
173 void __iomem *ch_regs;
174 void __iomem *dma_base;
175 int ch_id;
176 spinlock_t lock;
177 dma_cookie_t completed;
178 struct list_head active_list;
179 struct list_head queue;
180 struct list_head free_list;
181 struct intel_mid_dma_slave *slave;
182 unsigned int descs_allocated;
183 struct middma_device *dma;
184 bool in_use;
185};
186
187static inline struct intel_mid_dma_chan *to_intel_mid_dma_chan(
188 struct dma_chan *chan)
189{
190 return container_of(chan, struct intel_mid_dma_chan, chan);
191}
192
193/**
194 * struct middma_device - internal representation of a DMA device
195 * @pdev: PCI device
196 * @dma_base: MMIO register space pointer of DMA
197 * @dma_pool: for allocating DMA descriptors
198 * @common: embedded struct dma_device
199 * @tasklet: dma tasklet for processing interrupts
200 * @ch: per channel data
201 * @pci_id: DMA device PCI ID
202 * @intr_mask: Interrupt mask to be used
203 * @mask_reg: MMIO register for periphral mask
204 * @chan_base: Base ch index (read from driver data)
205 * @max_chan: max number of chs supported (from drv_data)
206 * @block_size: Block size of DMA transfer supported (from drv_data)
207 * @pimr_mask: MMIO register addr for periphral interrupt (from drv_data)
208 */
209struct middma_device {
210 struct pci_dev *pdev;
211 void __iomem *dma_base;
212 struct pci_pool *dma_pool;
213 struct dma_device common;
214 struct tasklet_struct tasklet;
215 struct intel_mid_dma_chan ch[MAX_CHAN];
216 unsigned int pci_id;
217 unsigned int intr_mask;
218 void __iomem *mask_reg;
219 int chan_base;
220 int max_chan;
221 int block_size;
222 unsigned int pimr_mask;
223};
224
225static inline struct middma_device *to_middma_device(struct dma_device *common)
226{
227 return container_of(common, struct middma_device, common);
228}
229
230struct intel_mid_dma_desc {
231 void __iomem *block; /*ch ptr*/
232 struct list_head desc_node;
233 struct dma_async_tx_descriptor txd;
234 size_t len;
235 dma_addr_t sar;
236 dma_addr_t dar;
237 u32 cfg_hi;
238 u32 cfg_lo;
239 u32 ctl_lo;
240 u32 ctl_hi;
241 dma_addr_t next;
242 enum dma_data_direction dirn;
243 enum dma_status status;
244 enum intel_mid_dma_width width; /*width of DMA txn*/
245 enum intel_mid_dma_mode cfg_mode; /*mode configuration*/
246
247};
248
249static inline int test_ch_en(void __iomem *dma, u32 ch_no)
250{
251 u32 en_reg = ioread32(dma + DMA_CHAN_EN);
252 return (en_reg >> ch_no) & 0x1;
253}
254
255static inline struct intel_mid_dma_desc *to_intel_mid_dma_desc
256 (struct dma_async_tx_descriptor *txd)
257{
258 return container_of(txd, struct intel_mid_dma_desc, txd);
259}
260#endif /*__INTEL_MID_DMAC_REGS_H__*/
diff --git a/drivers/dma/ioat/dma.h b/drivers/dma/ioat/dma.h
index 6d3a73b57e54..5216c8a92a21 100644
--- a/drivers/dma/ioat/dma.h
+++ b/drivers/dma/ioat/dma.h
@@ -97,6 +97,7 @@ struct ioat_chan_common {
97 #define IOAT_RESET_PENDING 2 97 #define IOAT_RESET_PENDING 2
98 #define IOAT_KOBJ_INIT_FAIL 3 98 #define IOAT_KOBJ_INIT_FAIL 3
99 #define IOAT_RESHAPE_PENDING 4 99 #define IOAT_RESHAPE_PENDING 4
100 #define IOAT_RUN 5
100 struct timer_list timer; 101 struct timer_list timer;
101 #define COMPLETION_TIMEOUT msecs_to_jiffies(100) 102 #define COMPLETION_TIMEOUT msecs_to_jiffies(100)
102 #define IDLE_TIMEOUT msecs_to_jiffies(2000) 103 #define IDLE_TIMEOUT msecs_to_jiffies(2000)
diff --git a/drivers/dma/ioat/dma_v2.c b/drivers/dma/ioat/dma_v2.c
index 3c8b32a83794..216f9d383b5b 100644
--- a/drivers/dma/ioat/dma_v2.c
+++ b/drivers/dma/ioat/dma_v2.c
@@ -287,7 +287,10 @@ void ioat2_timer_event(unsigned long data)
287 chanerr = readl(chan->reg_base + IOAT_CHANERR_OFFSET); 287 chanerr = readl(chan->reg_base + IOAT_CHANERR_OFFSET);
288 dev_err(to_dev(chan), "%s: Channel halted (%x)\n", 288 dev_err(to_dev(chan), "%s: Channel halted (%x)\n",
289 __func__, chanerr); 289 __func__, chanerr);
290 BUG_ON(is_ioat_bug(chanerr)); 290 if (test_bit(IOAT_RUN, &chan->state))
291 BUG_ON(is_ioat_bug(chanerr));
292 else /* we never got off the ground */
293 return;
291 } 294 }
292 295
293 /* if we haven't made progress and we have already 296 /* if we haven't made progress and we have already
@@ -492,6 +495,8 @@ static struct ioat_ring_ent **ioat2_alloc_ring(struct dma_chan *c, int order, gf
492 return ring; 495 return ring;
493} 496}
494 497
498void ioat2_free_chan_resources(struct dma_chan *c);
499
495/* ioat2_alloc_chan_resources - allocate/initialize ioat2 descriptor ring 500/* ioat2_alloc_chan_resources - allocate/initialize ioat2 descriptor ring
496 * @chan: channel to be initialized 501 * @chan: channel to be initialized
497 */ 502 */
@@ -500,6 +505,7 @@ int ioat2_alloc_chan_resources(struct dma_chan *c)
500 struct ioat2_dma_chan *ioat = to_ioat2_chan(c); 505 struct ioat2_dma_chan *ioat = to_ioat2_chan(c);
501 struct ioat_chan_common *chan = &ioat->base; 506 struct ioat_chan_common *chan = &ioat->base;
502 struct ioat_ring_ent **ring; 507 struct ioat_ring_ent **ring;
508 u64 status;
503 int order; 509 int order;
504 510
505 /* have we already been set up? */ 511 /* have we already been set up? */
@@ -540,7 +546,20 @@ int ioat2_alloc_chan_resources(struct dma_chan *c)
540 tasklet_enable(&chan->cleanup_task); 546 tasklet_enable(&chan->cleanup_task);
541 ioat2_start_null_desc(ioat); 547 ioat2_start_null_desc(ioat);
542 548
543 return 1 << ioat->alloc_order; 549 /* check that we got off the ground */
550 udelay(5);
551 status = ioat_chansts(chan);
552 if (is_ioat_active(status) || is_ioat_idle(status)) {
553 set_bit(IOAT_RUN, &chan->state);
554 return 1 << ioat->alloc_order;
555 } else {
556 u32 chanerr = readl(chan->reg_base + IOAT_CHANERR_OFFSET);
557
558 dev_WARN(to_dev(chan),
559 "failed to start channel chanerr: %#x\n", chanerr);
560 ioat2_free_chan_resources(c);
561 return -EFAULT;
562 }
544} 563}
545 564
546bool reshape_ring(struct ioat2_dma_chan *ioat, int order) 565bool reshape_ring(struct ioat2_dma_chan *ioat, int order)
@@ -778,6 +797,7 @@ void ioat2_free_chan_resources(struct dma_chan *c)
778 del_timer_sync(&chan->timer); 797 del_timer_sync(&chan->timer);
779 device->cleanup_fn((unsigned long) c); 798 device->cleanup_fn((unsigned long) c);
780 device->reset_hw(chan); 799 device->reset_hw(chan);
800 clear_bit(IOAT_RUN, &chan->state);
781 801
782 spin_lock_bh(&chan->cleanup_lock); 802 spin_lock_bh(&chan->cleanup_lock);
783 spin_lock_bh(&ioat->prep_lock); 803 spin_lock_bh(&ioat->prep_lock);
diff --git a/drivers/dma/ioat/dma_v3.c b/drivers/dma/ioat/dma_v3.c
index 1cdd22e1051b..d0f499098479 100644
--- a/drivers/dma/ioat/dma_v3.c
+++ b/drivers/dma/ioat/dma_v3.c
@@ -361,7 +361,10 @@ static void ioat3_timer_event(unsigned long data)
361 chanerr = readl(chan->reg_base + IOAT_CHANERR_OFFSET); 361 chanerr = readl(chan->reg_base + IOAT_CHANERR_OFFSET);
362 dev_err(to_dev(chan), "%s: Channel halted (%x)\n", 362 dev_err(to_dev(chan), "%s: Channel halted (%x)\n",
363 __func__, chanerr); 363 __func__, chanerr);
364 BUG_ON(is_ioat_bug(chanerr)); 364 if (test_bit(IOAT_RUN, &chan->state))
365 BUG_ON(is_ioat_bug(chanerr));
366 else /* we never got off the ground */
367 return;
365 } 368 }
366 369
367 /* if we haven't made progress and we have already 370 /* if we haven't made progress and we have already
diff --git a/drivers/dma/mpc512x_dma.c b/drivers/dma/mpc512x_dma.c
index 14a8c0f1698e..4e9cbf300594 100644
--- a/drivers/dma/mpc512x_dma.c
+++ b/drivers/dma/mpc512x_dma.c
@@ -627,7 +627,7 @@ mpc_dma_prep_memcpy(struct dma_chan *chan, dma_addr_t dst, dma_addr_t src,
627 return &mdesc->desc; 627 return &mdesc->desc;
628} 628}
629 629
630static int __devinit mpc_dma_probe(struct of_device *op, 630static int __devinit mpc_dma_probe(struct platform_device *op,
631 const struct of_device_id *match) 631 const struct of_device_id *match)
632{ 632{
633 struct device_node *dn = op->dev.of_node; 633 struct device_node *dn = op->dev.of_node;
@@ -753,7 +753,7 @@ static int __devinit mpc_dma_probe(struct of_device *op,
753 return retval; 753 return retval;
754} 754}
755 755
756static int __devexit mpc_dma_remove(struct of_device *op) 756static int __devexit mpc_dma_remove(struct platform_device *op)
757{ 757{
758 struct device *dev = &op->dev; 758 struct device *dev = &op->dev;
759 struct mpc_dma *mdma = dev_get_drvdata(dev); 759 struct mpc_dma *mdma = dev_get_drvdata(dev);
diff --git a/drivers/dma/pch_dma.c b/drivers/dma/pch_dma.c
new file mode 100644
index 000000000000..3533948b88ba
--- /dev/null
+++ b/drivers/dma/pch_dma.c
@@ -0,0 +1,957 @@
1/*
2 * Topcliff PCH DMA controller driver
3 * Copyright (c) 2010 Intel Corporation
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19#include <linux/dmaengine.h>
20#include <linux/dma-mapping.h>
21#include <linux/init.h>
22#include <linux/pci.h>
23#include <linux/interrupt.h>
24#include <linux/module.h>
25#include <linux/pch_dma.h>
26
27#define DRV_NAME "pch-dma"
28
29#define DMA_CTL0_DISABLE 0x0
30#define DMA_CTL0_SG 0x1
31#define DMA_CTL0_ONESHOT 0x2
32#define DMA_CTL0_MODE_MASK_BITS 0x3
33#define DMA_CTL0_DIR_SHIFT_BITS 2
34#define DMA_CTL0_BITS_PER_CH 4
35
36#define DMA_CTL2_START_SHIFT_BITS 8
37#define DMA_CTL2_IRQ_ENABLE_MASK ((1UL << DMA_CTL2_START_SHIFT_BITS) - 1)
38
39#define DMA_STATUS_IDLE 0x0
40#define DMA_STATUS_DESC_READ 0x1
41#define DMA_STATUS_WAIT 0x2
42#define DMA_STATUS_ACCESS 0x3
43#define DMA_STATUS_BITS_PER_CH 2
44#define DMA_STATUS_MASK_BITS 0x3
45#define DMA_STATUS_SHIFT_BITS 16
46#define DMA_STATUS_IRQ(x) (0x1 << (x))
47#define DMA_STATUS_ERR(x) (0x1 << ((x) + 8))
48
49#define DMA_DESC_WIDTH_SHIFT_BITS 12
50#define DMA_DESC_WIDTH_1_BYTE (0x3 << DMA_DESC_WIDTH_SHIFT_BITS)
51#define DMA_DESC_WIDTH_2_BYTES (0x2 << DMA_DESC_WIDTH_SHIFT_BITS)
52#define DMA_DESC_WIDTH_4_BYTES (0x0 << DMA_DESC_WIDTH_SHIFT_BITS)
53#define DMA_DESC_MAX_COUNT_1_BYTE 0x3FF
54#define DMA_DESC_MAX_COUNT_2_BYTES 0x3FF
55#define DMA_DESC_MAX_COUNT_4_BYTES 0x7FF
56#define DMA_DESC_END_WITHOUT_IRQ 0x0
57#define DMA_DESC_END_WITH_IRQ 0x1
58#define DMA_DESC_FOLLOW_WITHOUT_IRQ 0x2
59#define DMA_DESC_FOLLOW_WITH_IRQ 0x3
60
61#define MAX_CHAN_NR 8
62
63static unsigned int init_nr_desc_per_channel = 64;
64module_param(init_nr_desc_per_channel, uint, 0644);
65MODULE_PARM_DESC(init_nr_desc_per_channel,
66 "initial descriptors per channel (default: 64)");
67
68struct pch_dma_desc_regs {
69 u32 dev_addr;
70 u32 mem_addr;
71 u32 size;
72 u32 next;
73};
74
75struct pch_dma_regs {
76 u32 dma_ctl0;
77 u32 dma_ctl1;
78 u32 dma_ctl2;
79 u32 reserved1;
80 u32 dma_sts0;
81 u32 dma_sts1;
82 u32 reserved2;
83 u32 reserved3;
84 struct pch_dma_desc_regs desc[0];
85};
86
87struct pch_dma_desc {
88 struct pch_dma_desc_regs regs;
89 struct dma_async_tx_descriptor txd;
90 struct list_head desc_node;
91 struct list_head tx_list;
92};
93
94struct pch_dma_chan {
95 struct dma_chan chan;
96 void __iomem *membase;
97 enum dma_data_direction dir;
98 struct tasklet_struct tasklet;
99 unsigned long err_status;
100
101 spinlock_t lock;
102
103 dma_cookie_t completed_cookie;
104 struct list_head active_list;
105 struct list_head queue;
106 struct list_head free_list;
107 unsigned int descs_allocated;
108};
109
110#define PDC_DEV_ADDR 0x00
111#define PDC_MEM_ADDR 0x04
112#define PDC_SIZE 0x08
113#define PDC_NEXT 0x0C
114
115#define channel_readl(pdc, name) \
116 readl((pdc)->membase + PDC_##name)
117#define channel_writel(pdc, name, val) \
118 writel((val), (pdc)->membase + PDC_##name)
119
120struct pch_dma {
121 struct dma_device dma;
122 void __iomem *membase;
123 struct pci_pool *pool;
124 struct pch_dma_regs regs;
125 struct pch_dma_desc_regs ch_regs[MAX_CHAN_NR];
126 struct pch_dma_chan channels[0];
127};
128
129#define PCH_DMA_CTL0 0x00
130#define PCH_DMA_CTL1 0x04
131#define PCH_DMA_CTL2 0x08
132#define PCH_DMA_STS0 0x10
133#define PCH_DMA_STS1 0x14
134
135#define dma_readl(pd, name) \
136 readl((pd)->membase + PCH_DMA_##name)
137#define dma_writel(pd, name, val) \
138 writel((val), (pd)->membase + PCH_DMA_##name)
139
140static inline struct pch_dma_desc *to_pd_desc(struct dma_async_tx_descriptor *txd)
141{
142 return container_of(txd, struct pch_dma_desc, txd);
143}
144
145static inline struct pch_dma_chan *to_pd_chan(struct dma_chan *chan)
146{
147 return container_of(chan, struct pch_dma_chan, chan);
148}
149
150static inline struct pch_dma *to_pd(struct dma_device *ddev)
151{
152 return container_of(ddev, struct pch_dma, dma);
153}
154
155static inline struct device *chan2dev(struct dma_chan *chan)
156{
157 return &chan->dev->device;
158}
159
160static inline struct device *chan2parent(struct dma_chan *chan)
161{
162 return chan->dev->device.parent;
163}
164
165static inline struct pch_dma_desc *pdc_first_active(struct pch_dma_chan *pd_chan)
166{
167 return list_first_entry(&pd_chan->active_list,
168 struct pch_dma_desc, desc_node);
169}
170
171static inline struct pch_dma_desc *pdc_first_queued(struct pch_dma_chan *pd_chan)
172{
173 return list_first_entry(&pd_chan->queue,
174 struct pch_dma_desc, desc_node);
175}
176
177static void pdc_enable_irq(struct dma_chan *chan, int enable)
178{
179 struct pch_dma *pd = to_pd(chan->device);
180 u32 val;
181
182 val = dma_readl(pd, CTL2);
183
184 if (enable)
185 val |= 0x1 << chan->chan_id;
186 else
187 val &= ~(0x1 << chan->chan_id);
188
189 dma_writel(pd, CTL2, val);
190
191 dev_dbg(chan2dev(chan), "pdc_enable_irq: chan %d -> %x\n",
192 chan->chan_id, val);
193}
194
195static void pdc_set_dir(struct dma_chan *chan)
196{
197 struct pch_dma_chan *pd_chan = to_pd_chan(chan);
198 struct pch_dma *pd = to_pd(chan->device);
199 u32 val;
200
201 val = dma_readl(pd, CTL0);
202
203 if (pd_chan->dir == DMA_TO_DEVICE)
204 val |= 0x1 << (DMA_CTL0_BITS_PER_CH * chan->chan_id +
205 DMA_CTL0_DIR_SHIFT_BITS);
206 else
207 val &= ~(0x1 << (DMA_CTL0_BITS_PER_CH * chan->chan_id +
208 DMA_CTL0_DIR_SHIFT_BITS));
209
210 dma_writel(pd, CTL0, val);
211
212 dev_dbg(chan2dev(chan), "pdc_set_dir: chan %d -> %x\n",
213 chan->chan_id, val);
214}
215
216static void pdc_set_mode(struct dma_chan *chan, u32 mode)
217{
218 struct pch_dma *pd = to_pd(chan->device);
219 u32 val;
220
221 val = dma_readl(pd, CTL0);
222
223 val &= ~(DMA_CTL0_MODE_MASK_BITS <<
224 (DMA_CTL0_BITS_PER_CH * chan->chan_id));
225 val |= mode << (DMA_CTL0_BITS_PER_CH * chan->chan_id);
226
227 dma_writel(pd, CTL0, val);
228
229 dev_dbg(chan2dev(chan), "pdc_set_mode: chan %d -> %x\n",
230 chan->chan_id, val);
231}
232
233static u32 pdc_get_status(struct pch_dma_chan *pd_chan)
234{
235 struct pch_dma *pd = to_pd(pd_chan->chan.device);
236 u32 val;
237
238 val = dma_readl(pd, STS0);
239 return DMA_STATUS_MASK_BITS & (val >> (DMA_STATUS_SHIFT_BITS +
240 DMA_STATUS_BITS_PER_CH * pd_chan->chan.chan_id));
241}
242
243static bool pdc_is_idle(struct pch_dma_chan *pd_chan)
244{
245 if (pdc_get_status(pd_chan) == DMA_STATUS_IDLE)
246 return true;
247 else
248 return false;
249}
250
251static void pdc_dostart(struct pch_dma_chan *pd_chan, struct pch_dma_desc* desc)
252{
253 struct pch_dma *pd = to_pd(pd_chan->chan.device);
254 u32 val;
255
256 if (!pdc_is_idle(pd_chan)) {
257 dev_err(chan2dev(&pd_chan->chan),
258 "BUG: Attempt to start non-idle channel\n");
259 return;
260 }
261
262 channel_writel(pd_chan, DEV_ADDR, desc->regs.dev_addr);
263 channel_writel(pd_chan, MEM_ADDR, desc->regs.mem_addr);
264 channel_writel(pd_chan, SIZE, desc->regs.size);
265 channel_writel(pd_chan, NEXT, desc->regs.next);
266
267 dev_dbg(chan2dev(&pd_chan->chan), "chan %d -> dev_addr: %x\n",
268 pd_chan->chan.chan_id, desc->regs.dev_addr);
269 dev_dbg(chan2dev(&pd_chan->chan), "chan %d -> mem_addr: %x\n",
270 pd_chan->chan.chan_id, desc->regs.mem_addr);
271 dev_dbg(chan2dev(&pd_chan->chan), "chan %d -> size: %x\n",
272 pd_chan->chan.chan_id, desc->regs.size);
273 dev_dbg(chan2dev(&pd_chan->chan), "chan %d -> next: %x\n",
274 pd_chan->chan.chan_id, desc->regs.next);
275
276 if (list_empty(&desc->tx_list))
277 pdc_set_mode(&pd_chan->chan, DMA_CTL0_ONESHOT);
278 else
279 pdc_set_mode(&pd_chan->chan, DMA_CTL0_SG);
280
281 val = dma_readl(pd, CTL2);
282 val |= 1 << (DMA_CTL2_START_SHIFT_BITS + pd_chan->chan.chan_id);
283 dma_writel(pd, CTL2, val);
284}
285
286static void pdc_chain_complete(struct pch_dma_chan *pd_chan,
287 struct pch_dma_desc *desc)
288{
289 struct dma_async_tx_descriptor *txd = &desc->txd;
290 dma_async_tx_callback callback = txd->callback;
291 void *param = txd->callback_param;
292
293 list_splice_init(&desc->tx_list, &pd_chan->free_list);
294 list_move(&desc->desc_node, &pd_chan->free_list);
295
296 if (callback)
297 callback(param);
298}
299
300static void pdc_complete_all(struct pch_dma_chan *pd_chan)
301{
302 struct pch_dma_desc *desc, *_d;
303 LIST_HEAD(list);
304
305 BUG_ON(!pdc_is_idle(pd_chan));
306
307 if (!list_empty(&pd_chan->queue))
308 pdc_dostart(pd_chan, pdc_first_queued(pd_chan));
309
310 list_splice_init(&pd_chan->active_list, &list);
311 list_splice_init(&pd_chan->queue, &pd_chan->active_list);
312
313 list_for_each_entry_safe(desc, _d, &list, desc_node)
314 pdc_chain_complete(pd_chan, desc);
315}
316
317static void pdc_handle_error(struct pch_dma_chan *pd_chan)
318{
319 struct pch_dma_desc *bad_desc;
320
321 bad_desc = pdc_first_active(pd_chan);
322 list_del(&bad_desc->desc_node);
323
324 list_splice_init(&pd_chan->queue, pd_chan->active_list.prev);
325
326 if (!list_empty(&pd_chan->active_list))
327 pdc_dostart(pd_chan, pdc_first_active(pd_chan));
328
329 dev_crit(chan2dev(&pd_chan->chan), "Bad descriptor submitted\n");
330 dev_crit(chan2dev(&pd_chan->chan), "descriptor cookie: %d\n",
331 bad_desc->txd.cookie);
332
333 pdc_chain_complete(pd_chan, bad_desc);
334}
335
336static void pdc_advance_work(struct pch_dma_chan *pd_chan)
337{
338 if (list_empty(&pd_chan->active_list) ||
339 list_is_singular(&pd_chan->active_list)) {
340 pdc_complete_all(pd_chan);
341 } else {
342 pdc_chain_complete(pd_chan, pdc_first_active(pd_chan));
343 pdc_dostart(pd_chan, pdc_first_active(pd_chan));
344 }
345}
346
347static dma_cookie_t pdc_assign_cookie(struct pch_dma_chan *pd_chan,
348 struct pch_dma_desc *desc)
349{
350 dma_cookie_t cookie = pd_chan->chan.cookie;
351
352 if (++cookie < 0)
353 cookie = 1;
354
355 pd_chan->chan.cookie = cookie;
356 desc->txd.cookie = cookie;
357
358 return cookie;
359}
360
361static dma_cookie_t pd_tx_submit(struct dma_async_tx_descriptor *txd)
362{
363 struct pch_dma_desc *desc = to_pd_desc(txd);
364 struct pch_dma_chan *pd_chan = to_pd_chan(txd->chan);
365 dma_cookie_t cookie;
366
367 spin_lock_bh(&pd_chan->lock);
368 cookie = pdc_assign_cookie(pd_chan, desc);
369
370 if (list_empty(&pd_chan->active_list)) {
371 list_add_tail(&desc->desc_node, &pd_chan->active_list);
372 pdc_dostart(pd_chan, desc);
373 } else {
374 list_add_tail(&desc->desc_node, &pd_chan->queue);
375 }
376
377 spin_unlock_bh(&pd_chan->lock);
378 return 0;
379}
380
381static struct pch_dma_desc *pdc_alloc_desc(struct dma_chan *chan, gfp_t flags)
382{
383 struct pch_dma_desc *desc = NULL;
384 struct pch_dma *pd = to_pd(chan->device);
385 dma_addr_t addr;
386
387 desc = pci_pool_alloc(pd->pool, GFP_KERNEL, &addr);
388 if (desc) {
389 memset(desc, 0, sizeof(struct pch_dma_desc));
390 INIT_LIST_HEAD(&desc->tx_list);
391 dma_async_tx_descriptor_init(&desc->txd, chan);
392 desc->txd.tx_submit = pd_tx_submit;
393 desc->txd.flags = DMA_CTRL_ACK;
394 desc->txd.phys = addr;
395 }
396
397 return desc;
398}
399
400static struct pch_dma_desc *pdc_desc_get(struct pch_dma_chan *pd_chan)
401{
402 struct pch_dma_desc *desc, *_d;
403 struct pch_dma_desc *ret = NULL;
404 int i;
405
406 spin_lock_bh(&pd_chan->lock);
407 list_for_each_entry_safe(desc, _d, &pd_chan->free_list, desc_node) {
408 i++;
409 if (async_tx_test_ack(&desc->txd)) {
410 list_del(&desc->desc_node);
411 ret = desc;
412 break;
413 }
414 dev_dbg(chan2dev(&pd_chan->chan), "desc %p not ACKed\n", desc);
415 }
416 spin_unlock_bh(&pd_chan->lock);
417 dev_dbg(chan2dev(&pd_chan->chan), "scanned %d descriptors\n", i);
418
419 if (!ret) {
420 ret = pdc_alloc_desc(&pd_chan->chan, GFP_NOIO);
421 if (ret) {
422 spin_lock_bh(&pd_chan->lock);
423 pd_chan->descs_allocated++;
424 spin_unlock_bh(&pd_chan->lock);
425 } else {
426 dev_err(chan2dev(&pd_chan->chan),
427 "failed to alloc desc\n");
428 }
429 }
430
431 return ret;
432}
433
434static void pdc_desc_put(struct pch_dma_chan *pd_chan,
435 struct pch_dma_desc *desc)
436{
437 if (desc) {
438 spin_lock_bh(&pd_chan->lock);
439 list_splice_init(&desc->tx_list, &pd_chan->free_list);
440 list_add(&desc->desc_node, &pd_chan->free_list);
441 spin_unlock_bh(&pd_chan->lock);
442 }
443}
444
445static int pd_alloc_chan_resources(struct dma_chan *chan)
446{
447 struct pch_dma_chan *pd_chan = to_pd_chan(chan);
448 struct pch_dma_desc *desc;
449 LIST_HEAD(tmp_list);
450 int i;
451
452 if (!pdc_is_idle(pd_chan)) {
453 dev_dbg(chan2dev(chan), "DMA channel not idle ?\n");
454 return -EIO;
455 }
456
457 if (!list_empty(&pd_chan->free_list))
458 return pd_chan->descs_allocated;
459
460 for (i = 0; i < init_nr_desc_per_channel; i++) {
461 desc = pdc_alloc_desc(chan, GFP_KERNEL);
462
463 if (!desc) {
464 dev_warn(chan2dev(chan),
465 "Only allocated %d initial descriptors\n", i);
466 break;
467 }
468
469 list_add_tail(&desc->desc_node, &tmp_list);
470 }
471
472 spin_lock_bh(&pd_chan->lock);
473 list_splice(&tmp_list, &pd_chan->free_list);
474 pd_chan->descs_allocated = i;
475 pd_chan->completed_cookie = chan->cookie = 1;
476 spin_unlock_bh(&pd_chan->lock);
477
478 pdc_enable_irq(chan, 1);
479 pdc_set_dir(chan);
480
481 return pd_chan->descs_allocated;
482}
483
484static void pd_free_chan_resources(struct dma_chan *chan)
485{
486 struct pch_dma_chan *pd_chan = to_pd_chan(chan);
487 struct pch_dma *pd = to_pd(chan->device);
488 struct pch_dma_desc *desc, *_d;
489 LIST_HEAD(tmp_list);
490
491 BUG_ON(!pdc_is_idle(pd_chan));
492 BUG_ON(!list_empty(&pd_chan->active_list));
493 BUG_ON(!list_empty(&pd_chan->queue));
494
495 spin_lock_bh(&pd_chan->lock);
496 list_splice_init(&pd_chan->free_list, &tmp_list);
497 pd_chan->descs_allocated = 0;
498 spin_unlock_bh(&pd_chan->lock);
499
500 list_for_each_entry_safe(desc, _d, &tmp_list, desc_node)
501 pci_pool_free(pd->pool, desc, desc->txd.phys);
502
503 pdc_enable_irq(chan, 0);
504}
505
506static enum dma_status pd_tx_status(struct dma_chan *chan, dma_cookie_t cookie,
507 struct dma_tx_state *txstate)
508{
509 struct pch_dma_chan *pd_chan = to_pd_chan(chan);
510 dma_cookie_t last_used;
511 dma_cookie_t last_completed;
512 int ret;
513
514 spin_lock_bh(&pd_chan->lock);
515 last_completed = pd_chan->completed_cookie;
516 last_used = chan->cookie;
517 spin_unlock_bh(&pd_chan->lock);
518
519 ret = dma_async_is_complete(cookie, last_completed, last_used);
520
521 dma_set_tx_state(txstate, last_completed, last_used, 0);
522
523 return ret;
524}
525
526static void pd_issue_pending(struct dma_chan *chan)
527{
528 struct pch_dma_chan *pd_chan = to_pd_chan(chan);
529
530 if (pdc_is_idle(pd_chan)) {
531 spin_lock_bh(&pd_chan->lock);
532 pdc_advance_work(pd_chan);
533 spin_unlock_bh(&pd_chan->lock);
534 }
535}
536
537static struct dma_async_tx_descriptor *pd_prep_slave_sg(struct dma_chan *chan,
538 struct scatterlist *sgl, unsigned int sg_len,
539 enum dma_data_direction direction, unsigned long flags)
540{
541 struct pch_dma_chan *pd_chan = to_pd_chan(chan);
542 struct pch_dma_slave *pd_slave = chan->private;
543 struct pch_dma_desc *first = NULL;
544 struct pch_dma_desc *prev = NULL;
545 struct pch_dma_desc *desc = NULL;
546 struct scatterlist *sg;
547 dma_addr_t reg;
548 int i;
549
550 if (unlikely(!sg_len)) {
551 dev_info(chan2dev(chan), "prep_slave_sg: length is zero!\n");
552 return NULL;
553 }
554
555 if (direction == DMA_FROM_DEVICE)
556 reg = pd_slave->rx_reg;
557 else if (direction == DMA_TO_DEVICE)
558 reg = pd_slave->tx_reg;
559 else
560 return NULL;
561
562 for_each_sg(sgl, sg, sg_len, i) {
563 desc = pdc_desc_get(pd_chan);
564
565 if (!desc)
566 goto err_desc_get;
567
568 desc->regs.dev_addr = reg;
569 desc->regs.mem_addr = sg_phys(sg);
570 desc->regs.size = sg_dma_len(sg);
571 desc->regs.next = DMA_DESC_FOLLOW_WITHOUT_IRQ;
572
573 switch (pd_slave->width) {
574 case PCH_DMA_WIDTH_1_BYTE:
575 if (desc->regs.size > DMA_DESC_MAX_COUNT_1_BYTE)
576 goto err_desc_get;
577 desc->regs.size |= DMA_DESC_WIDTH_1_BYTE;
578 break;
579 case PCH_DMA_WIDTH_2_BYTES:
580 if (desc->regs.size > DMA_DESC_MAX_COUNT_2_BYTES)
581 goto err_desc_get;
582 desc->regs.size |= DMA_DESC_WIDTH_2_BYTES;
583 break;
584 case PCH_DMA_WIDTH_4_BYTES:
585 if (desc->regs.size > DMA_DESC_MAX_COUNT_4_BYTES)
586 goto err_desc_get;
587 desc->regs.size |= DMA_DESC_WIDTH_4_BYTES;
588 break;
589 default:
590 goto err_desc_get;
591 }
592
593
594 if (!first) {
595 first = desc;
596 } else {
597 prev->regs.next |= desc->txd.phys;
598 list_add_tail(&desc->desc_node, &first->tx_list);
599 }
600
601 prev = desc;
602 }
603
604 if (flags & DMA_PREP_INTERRUPT)
605 desc->regs.next = DMA_DESC_END_WITH_IRQ;
606 else
607 desc->regs.next = DMA_DESC_END_WITHOUT_IRQ;
608
609 first->txd.cookie = -EBUSY;
610 desc->txd.flags = flags;
611
612 return &first->txd;
613
614err_desc_get:
615 dev_err(chan2dev(chan), "failed to get desc or wrong parameters\n");
616 pdc_desc_put(pd_chan, first);
617 return NULL;
618}
619
620static int pd_device_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
621 unsigned long arg)
622{
623 struct pch_dma_chan *pd_chan = to_pd_chan(chan);
624 struct pch_dma_desc *desc, *_d;
625 LIST_HEAD(list);
626
627 if (cmd != DMA_TERMINATE_ALL)
628 return -ENXIO;
629
630 spin_lock_bh(&pd_chan->lock);
631
632 pdc_set_mode(&pd_chan->chan, DMA_CTL0_DISABLE);
633
634 list_splice_init(&pd_chan->active_list, &list);
635 list_splice_init(&pd_chan->queue, &list);
636
637 list_for_each_entry_safe(desc, _d, &list, desc_node)
638 pdc_chain_complete(pd_chan, desc);
639
640 spin_unlock_bh(&pd_chan->lock);
641
642
643 return 0;
644}
645
646static void pdc_tasklet(unsigned long data)
647{
648 struct pch_dma_chan *pd_chan = (struct pch_dma_chan *)data;
649
650 if (!pdc_is_idle(pd_chan)) {
651 dev_err(chan2dev(&pd_chan->chan),
652 "BUG: handle non-idle channel in tasklet\n");
653 return;
654 }
655
656 spin_lock_bh(&pd_chan->lock);
657 if (test_and_clear_bit(0, &pd_chan->err_status))
658 pdc_handle_error(pd_chan);
659 else
660 pdc_advance_work(pd_chan);
661 spin_unlock_bh(&pd_chan->lock);
662}
663
664static irqreturn_t pd_irq(int irq, void *devid)
665{
666 struct pch_dma *pd = (struct pch_dma *)devid;
667 struct pch_dma_chan *pd_chan;
668 u32 sts0;
669 int i;
670 int ret = IRQ_NONE;
671
672 sts0 = dma_readl(pd, STS0);
673
674 dev_dbg(pd->dma.dev, "pd_irq sts0: %x\n", sts0);
675
676 for (i = 0; i < pd->dma.chancnt; i++) {
677 pd_chan = &pd->channels[i];
678
679 if (sts0 & DMA_STATUS_IRQ(i)) {
680 if (sts0 & DMA_STATUS_ERR(i))
681 set_bit(0, &pd_chan->err_status);
682
683 tasklet_schedule(&pd_chan->tasklet);
684 ret = IRQ_HANDLED;
685 }
686
687 }
688
689 /* clear interrupt bits in status register */
690 dma_writel(pd, STS0, sts0);
691
692 return ret;
693}
694
695static void pch_dma_save_regs(struct pch_dma *pd)
696{
697 struct pch_dma_chan *pd_chan;
698 struct dma_chan *chan, *_c;
699 int i = 0;
700
701 pd->regs.dma_ctl0 = dma_readl(pd, CTL0);
702 pd->regs.dma_ctl1 = dma_readl(pd, CTL1);
703 pd->regs.dma_ctl2 = dma_readl(pd, CTL2);
704
705 list_for_each_entry_safe(chan, _c, &pd->dma.channels, device_node) {
706 pd_chan = to_pd_chan(chan);
707
708 pd->ch_regs[i].dev_addr = channel_readl(pd_chan, DEV_ADDR);
709 pd->ch_regs[i].mem_addr = channel_readl(pd_chan, MEM_ADDR);
710 pd->ch_regs[i].size = channel_readl(pd_chan, SIZE);
711 pd->ch_regs[i].next = channel_readl(pd_chan, NEXT);
712
713 i++;
714 }
715}
716
717static void pch_dma_restore_regs(struct pch_dma *pd)
718{
719 struct pch_dma_chan *pd_chan;
720 struct dma_chan *chan, *_c;
721 int i = 0;
722
723 dma_writel(pd, CTL0, pd->regs.dma_ctl0);
724 dma_writel(pd, CTL1, pd->regs.dma_ctl1);
725 dma_writel(pd, CTL2, pd->regs.dma_ctl2);
726
727 list_for_each_entry_safe(chan, _c, &pd->dma.channels, device_node) {
728 pd_chan = to_pd_chan(chan);
729
730 channel_writel(pd_chan, DEV_ADDR, pd->ch_regs[i].dev_addr);
731 channel_writel(pd_chan, MEM_ADDR, pd->ch_regs[i].mem_addr);
732 channel_writel(pd_chan, SIZE, pd->ch_regs[i].size);
733 channel_writel(pd_chan, NEXT, pd->ch_regs[i].next);
734
735 i++;
736 }
737}
738
739static int pch_dma_suspend(struct pci_dev *pdev, pm_message_t state)
740{
741 struct pch_dma *pd = pci_get_drvdata(pdev);
742
743 if (pd)
744 pch_dma_save_regs(pd);
745
746 pci_save_state(pdev);
747 pci_disable_device(pdev);
748 pci_set_power_state(pdev, pci_choose_state(pdev, state));
749
750 return 0;
751}
752
753static int pch_dma_resume(struct pci_dev *pdev)
754{
755 struct pch_dma *pd = pci_get_drvdata(pdev);
756 int err;
757
758 pci_set_power_state(pdev, PCI_D0);
759 pci_restore_state(pdev);
760
761 err = pci_enable_device(pdev);
762 if (err) {
763 dev_dbg(&pdev->dev, "failed to enable device\n");
764 return err;
765 }
766
767 if (pd)
768 pch_dma_restore_regs(pd);
769
770 return 0;
771}
772
773static int __devinit pch_dma_probe(struct pci_dev *pdev,
774 const struct pci_device_id *id)
775{
776 struct pch_dma *pd;
777 struct pch_dma_regs *regs;
778 unsigned int nr_channels;
779 int err;
780 int i;
781
782 nr_channels = id->driver_data;
783 pd = kzalloc(sizeof(struct pch_dma)+
784 sizeof(struct pch_dma_chan) * nr_channels, GFP_KERNEL);
785 if (!pd)
786 return -ENOMEM;
787
788 pci_set_drvdata(pdev, pd);
789
790 err = pci_enable_device(pdev);
791 if (err) {
792 dev_err(&pdev->dev, "Cannot enable PCI device\n");
793 goto err_free_mem;
794 }
795
796 if (!(pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
797 dev_err(&pdev->dev, "Cannot find proper base address\n");
798 goto err_disable_pdev;
799 }
800
801 err = pci_request_regions(pdev, DRV_NAME);
802 if (err) {
803 dev_err(&pdev->dev, "Cannot obtain PCI resources\n");
804 goto err_disable_pdev;
805 }
806
807 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
808 if (err) {
809 dev_err(&pdev->dev, "Cannot set proper DMA config\n");
810 goto err_free_res;
811 }
812
813 regs = pd->membase = pci_iomap(pdev, 1, 0);
814 if (!pd->membase) {
815 dev_err(&pdev->dev, "Cannot map MMIO registers\n");
816 err = -ENOMEM;
817 goto err_free_res;
818 }
819
820 pci_set_master(pdev);
821
822 err = request_irq(pdev->irq, pd_irq, IRQF_SHARED, DRV_NAME, pd);
823 if (err) {
824 dev_err(&pdev->dev, "Failed to request IRQ\n");
825 goto err_iounmap;
826 }
827
828 pd->pool = pci_pool_create("pch_dma_desc_pool", pdev,
829 sizeof(struct pch_dma_desc), 4, 0);
830 if (!pd->pool) {
831 dev_err(&pdev->dev, "Failed to alloc DMA descriptors\n");
832 err = -ENOMEM;
833 goto err_free_irq;
834 }
835
836 pd->dma.dev = &pdev->dev;
837 pd->dma.chancnt = nr_channels;
838
839 INIT_LIST_HEAD(&pd->dma.channels);
840
841 for (i = 0; i < nr_channels; i++) {
842 struct pch_dma_chan *pd_chan = &pd->channels[i];
843
844 pd_chan->chan.device = &pd->dma;
845 pd_chan->chan.cookie = 1;
846 pd_chan->chan.chan_id = i;
847
848 pd_chan->membase = &regs->desc[i];
849
850 pd_chan->dir = (i % 2) ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
851
852 spin_lock_init(&pd_chan->lock);
853
854 INIT_LIST_HEAD(&pd_chan->active_list);
855 INIT_LIST_HEAD(&pd_chan->queue);
856 INIT_LIST_HEAD(&pd_chan->free_list);
857
858 tasklet_init(&pd_chan->tasklet, pdc_tasklet,
859 (unsigned long)pd_chan);
860 list_add_tail(&pd_chan->chan.device_node, &pd->dma.channels);
861 }
862
863 dma_cap_zero(pd->dma.cap_mask);
864 dma_cap_set(DMA_PRIVATE, pd->dma.cap_mask);
865 dma_cap_set(DMA_SLAVE, pd->dma.cap_mask);
866
867 pd->dma.device_alloc_chan_resources = pd_alloc_chan_resources;
868 pd->dma.device_free_chan_resources = pd_free_chan_resources;
869 pd->dma.device_tx_status = pd_tx_status;
870 pd->dma.device_issue_pending = pd_issue_pending;
871 pd->dma.device_prep_slave_sg = pd_prep_slave_sg;
872 pd->dma.device_control = pd_device_control;
873
874 err = dma_async_device_register(&pd->dma);
875 if (err) {
876 dev_err(&pdev->dev, "Failed to register DMA device\n");
877 goto err_free_pool;
878 }
879
880 return 0;
881
882err_free_pool:
883 pci_pool_destroy(pd->pool);
884err_free_irq:
885 free_irq(pdev->irq, pd);
886err_iounmap:
887 pci_iounmap(pdev, pd->membase);
888err_free_res:
889 pci_release_regions(pdev);
890err_disable_pdev:
891 pci_disable_device(pdev);
892err_free_mem:
893 return err;
894}
895
896static void __devexit pch_dma_remove(struct pci_dev *pdev)
897{
898 struct pch_dma *pd = pci_get_drvdata(pdev);
899 struct pch_dma_chan *pd_chan;
900 struct dma_chan *chan, *_c;
901
902 if (pd) {
903 dma_async_device_unregister(&pd->dma);
904
905 list_for_each_entry_safe(chan, _c, &pd->dma.channels,
906 device_node) {
907 pd_chan = to_pd_chan(chan);
908
909 tasklet_disable(&pd_chan->tasklet);
910 tasklet_kill(&pd_chan->tasklet);
911 }
912
913 pci_pool_destroy(pd->pool);
914 free_irq(pdev->irq, pd);
915 pci_iounmap(pdev, pd->membase);
916 pci_release_regions(pdev);
917 pci_disable_device(pdev);
918 kfree(pd);
919 }
920}
921
922/* PCI Device ID of DMA device */
923#define PCI_DEVICE_ID_PCH_DMA_8CH 0x8810
924#define PCI_DEVICE_ID_PCH_DMA_4CH 0x8815
925
926static const struct pci_device_id pch_dma_id_table[] = {
927 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_PCH_DMA_8CH), 8 },
928 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_PCH_DMA_4CH), 4 },
929};
930
931static struct pci_driver pch_dma_driver = {
932 .name = DRV_NAME,
933 .id_table = pch_dma_id_table,
934 .probe = pch_dma_probe,
935 .remove = __devexit_p(pch_dma_remove),
936#ifdef CONFIG_PM
937 .suspend = pch_dma_suspend,
938 .resume = pch_dma_resume,
939#endif
940};
941
942static int __init pch_dma_init(void)
943{
944 return pci_register_driver(&pch_dma_driver);
945}
946
947static void __exit pch_dma_exit(void)
948{
949 pci_unregister_driver(&pch_dma_driver);
950}
951
952module_init(pch_dma_init);
953module_exit(pch_dma_exit);
954
955MODULE_DESCRIPTION("Topcliff PCH DMA controller driver");
956MODULE_AUTHOR("Yong Wang <yong.y.wang@intel.com>");
957MODULE_LICENSE("GPL v2");
diff --git a/drivers/dma/ppc4xx/adma.c b/drivers/dma/ppc4xx/adma.c
index 7c3747902a37..0d58a4a4487f 100644
--- a/drivers/dma/ppc4xx/adma.c
+++ b/drivers/dma/ppc4xx/adma.c
@@ -4257,11 +4257,11 @@ static int ppc440spe_adma_setup_irqs(struct ppc440spe_adma_device *adev,
4257 struct ppc440spe_adma_chan *chan, 4257 struct ppc440spe_adma_chan *chan,
4258 int *initcode) 4258 int *initcode)
4259{ 4259{
4260 struct of_device *ofdev; 4260 struct platform_device *ofdev;
4261 struct device_node *np; 4261 struct device_node *np;
4262 int ret; 4262 int ret;
4263 4263
4264 ofdev = container_of(adev->dev, struct of_device, dev); 4264 ofdev = container_of(adev->dev, struct platform_device, dev);
4265 np = ofdev->dev.of_node; 4265 np = ofdev->dev.of_node;
4266 if (adev->id != PPC440SPE_XOR_ID) { 4266 if (adev->id != PPC440SPE_XOR_ID) {
4267 adev->err_irq = irq_of_parse_and_map(np, 1); 4267 adev->err_irq = irq_of_parse_and_map(np, 1);
@@ -4393,7 +4393,7 @@ static void ppc440spe_adma_release_irqs(struct ppc440spe_adma_device *adev,
4393/** 4393/**
4394 * ppc440spe_adma_probe - probe the asynch device 4394 * ppc440spe_adma_probe - probe the asynch device
4395 */ 4395 */
4396static int __devinit ppc440spe_adma_probe(struct of_device *ofdev, 4396static int __devinit ppc440spe_adma_probe(struct platform_device *ofdev,
4397 const struct of_device_id *match) 4397 const struct of_device_id *match)
4398{ 4398{
4399 struct device_node *np = ofdev->dev.of_node; 4399 struct device_node *np = ofdev->dev.of_node;
@@ -4625,7 +4625,7 @@ out:
4625/** 4625/**
4626 * ppc440spe_adma_remove - remove the asynch device 4626 * ppc440spe_adma_remove - remove the asynch device
4627 */ 4627 */
4628static int __devexit ppc440spe_adma_remove(struct of_device *ofdev) 4628static int __devexit ppc440spe_adma_remove(struct platform_device *ofdev)
4629{ 4629{
4630 struct ppc440spe_adma_device *adev = dev_get_drvdata(&ofdev->dev); 4630 struct ppc440spe_adma_device *adev = dev_get_drvdata(&ofdev->dev);
4631 struct device_node *np = ofdev->dev.of_node; 4631 struct device_node *np = ofdev->dev.of_node;
diff --git a/drivers/dma/shdma.c b/drivers/dma/shdma.c
index a2a519fd2a24..fb64cf36ba61 100644
--- a/drivers/dma/shdma.c
+++ b/drivers/dma/shdma.c
@@ -816,7 +816,7 @@ static irqreturn_t sh_dmae_interrupt(int irq, void *data)
816 return ret; 816 return ret;
817} 817}
818 818
819#if defined(CONFIG_CPU_SH4) 819#if defined(CONFIG_CPU_SH4) || defined(CONFIG_ARCH_SHMOBILE)
820static irqreturn_t sh_dmae_err(int irq, void *data) 820static irqreturn_t sh_dmae_err(int irq, void *data)
821{ 821{
822 struct sh_dmae_device *shdev = (struct sh_dmae_device *)data; 822 struct sh_dmae_device *shdev = (struct sh_dmae_device *)data;
@@ -1057,7 +1057,7 @@ static int __init sh_dmae_probe(struct platform_device *pdev)
1057 /* Default transfer size of 32 bytes requires 32-byte alignment */ 1057 /* Default transfer size of 32 bytes requires 32-byte alignment */
1058 shdev->common.copy_align = LOG2_DEFAULT_XFER_SIZE; 1058 shdev->common.copy_align = LOG2_DEFAULT_XFER_SIZE;
1059 1059
1060#if defined(CONFIG_CPU_SH4) 1060#if defined(CONFIG_CPU_SH4) || defined(CONFIG_ARCH_SHMOBILE)
1061 chanirq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 1); 1061 chanirq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 1);
1062 1062
1063 if (!chanirq_res) 1063 if (!chanirq_res)
@@ -1082,7 +1082,7 @@ static int __init sh_dmae_probe(struct platform_device *pdev)
1082 1082
1083#else 1083#else
1084 chanirq_res = errirq_res; 1084 chanirq_res = errirq_res;
1085#endif /* CONFIG_CPU_SH4 */ 1085#endif /* CONFIG_CPU_SH4 || CONFIG_ARCH_SHMOBILE */
1086 1086
1087 if (chanirq_res->start == chanirq_res->end && 1087 if (chanirq_res->start == chanirq_res->end &&
1088 !platform_get_resource(pdev, IORESOURCE_IRQ, 1)) { 1088 !platform_get_resource(pdev, IORESOURCE_IRQ, 1)) {
@@ -1129,7 +1129,7 @@ static int __init sh_dmae_probe(struct platform_device *pdev)
1129chan_probe_err: 1129chan_probe_err:
1130 sh_dmae_chan_remove(shdev); 1130 sh_dmae_chan_remove(shdev);
1131eirqres: 1131eirqres:
1132#if defined(CONFIG_CPU_SH4) 1132#if defined(CONFIG_CPU_SH4) || defined(CONFIG_ARCH_SHMOBILE)
1133 free_irq(errirq, shdev); 1133 free_irq(errirq, shdev);
1134eirq_err: 1134eirq_err:
1135#endif 1135#endif
diff --git a/drivers/dma/ste_dma40.c b/drivers/dma/ste_dma40.c
index c426829f6ab8..17e2600a00cf 100644
--- a/drivers/dma/ste_dma40.c
+++ b/drivers/dma/ste_dma40.c
@@ -30,14 +30,16 @@
30/* Maximum iterations taken before giving up suspending a channel */ 30/* Maximum iterations taken before giving up suspending a channel */
31#define D40_SUSPEND_MAX_IT 500 31#define D40_SUSPEND_MAX_IT 500
32 32
33/* Hardware requirement on LCLA alignment */
34#define LCLA_ALIGNMENT 0x40000
35/* Attempts before giving up to trying to get pages that are aligned */
36#define MAX_LCLA_ALLOC_ATTEMPTS 256
37
38/* Bit markings for allocation map */
33#define D40_ALLOC_FREE (1 << 31) 39#define D40_ALLOC_FREE (1 << 31)
34#define D40_ALLOC_PHY (1 << 30) 40#define D40_ALLOC_PHY (1 << 30)
35#define D40_ALLOC_LOG_FREE 0 41#define D40_ALLOC_LOG_FREE 0
36 42
37/* The number of free d40_desc to keep in memory before starting
38 * to kfree() them */
39#define D40_DESC_CACHE_SIZE 50
40
41/* Hardware designer of the block */ 43/* Hardware designer of the block */
42#define D40_PERIPHID2_DESIGNER 0x8 44#define D40_PERIPHID2_DESIGNER 0x8
43 45
@@ -68,9 +70,9 @@ enum d40_command {
68 */ 70 */
69struct d40_lli_pool { 71struct d40_lli_pool {
70 void *base; 72 void *base;
71 int size; 73 int size;
72 /* Space for dst and src, plus an extra for padding */ 74 /* Space for dst and src, plus an extra for padding */
73 u8 pre_alloc_lli[3 * sizeof(struct d40_phy_lli)]; 75 u8 pre_alloc_lli[3 * sizeof(struct d40_phy_lli)];
74}; 76};
75 77
76/** 78/**
@@ -81,9 +83,10 @@ struct d40_lli_pool {
81 * lli_len equals one. 83 * lli_len equals one.
82 * @lli_log: Same as above but for logical channels. 84 * @lli_log: Same as above but for logical channels.
83 * @lli_pool: The pool with two entries pre-allocated. 85 * @lli_pool: The pool with two entries pre-allocated.
84 * @lli_len: Number of LLI's in lli_pool 86 * @lli_len: Number of llis of current descriptor.
85 * @lli_tcount: Number of LLIs processed in the transfer. When equals lli_len 87 * @lli_count: Number of transfered llis.
86 * then this transfer job is done. 88 * @lli_tx_len: Max number of LLIs per transfer, there can be
89 * many transfer for one descriptor.
87 * @txd: DMA engine struct. Used for among other things for communication 90 * @txd: DMA engine struct. Used for among other things for communication
88 * during a transfer. 91 * during a transfer.
89 * @node: List entry. 92 * @node: List entry.
@@ -100,8 +103,9 @@ struct d40_desc {
100 struct d40_log_lli_bidir lli_log; 103 struct d40_log_lli_bidir lli_log;
101 104
102 struct d40_lli_pool lli_pool; 105 struct d40_lli_pool lli_pool;
103 u32 lli_len; 106 int lli_len;
104 u32 lli_tcount; 107 int lli_count;
108 u32 lli_tx_len;
105 109
106 struct dma_async_tx_descriptor txd; 110 struct dma_async_tx_descriptor txd;
107 struct list_head node; 111 struct list_head node;
@@ -113,18 +117,20 @@ struct d40_desc {
113/** 117/**
114 * struct d40_lcla_pool - LCLA pool settings and data. 118 * struct d40_lcla_pool - LCLA pool settings and data.
115 * 119 *
116 * @base: The virtual address of LCLA. 120 * @base: The virtual address of LCLA. 18 bit aligned.
117 * @phy: Physical base address of LCLA. 121 * @base_unaligned: The orignal kmalloc pointer, if kmalloc is used.
118 * @base_size: size of lcla. 122 * This pointer is only there for clean-up on error.
123 * @pages: The number of pages needed for all physical channels.
124 * Only used later for clean-up on error
119 * @lock: Lock to protect the content in this struct. 125 * @lock: Lock to protect the content in this struct.
120 * @alloc_map: Mapping between physical channel and LCLA entries. 126 * @alloc_map: Bitmap mapping between physical channel and LCLA entries.
121 * @num_blocks: The number of entries of alloc_map. Equals to the 127 * @num_blocks: The number of entries of alloc_map. Equals to the
122 * number of physical channels. 128 * number of physical channels.
123 */ 129 */
124struct d40_lcla_pool { 130struct d40_lcla_pool {
125 void *base; 131 void *base;
126 dma_addr_t phy; 132 void *base_unaligned;
127 resource_size_t base_size; 133 int pages;
128 spinlock_t lock; 134 spinlock_t lock;
129 u32 *alloc_map; 135 u32 *alloc_map;
130 int num_blocks; 136 int num_blocks;
@@ -163,15 +169,14 @@ struct d40_base;
163 * @pending_tx: The number of pending transfers. Used between interrupt handler 169 * @pending_tx: The number of pending transfers. Used between interrupt handler
164 * and tasklet. 170 * and tasklet.
165 * @busy: Set to true when transfer is ongoing on this channel. 171 * @busy: Set to true when transfer is ongoing on this channel.
166 * @phy_chan: Pointer to physical channel which this instance runs on. 172 * @phy_chan: Pointer to physical channel which this instance runs on. If this
173 * point is NULL, then the channel is not allocated.
167 * @chan: DMA engine handle. 174 * @chan: DMA engine handle.
168 * @tasklet: Tasklet that gets scheduled from interrupt context to complete a 175 * @tasklet: Tasklet that gets scheduled from interrupt context to complete a
169 * transfer and call client callback. 176 * transfer and call client callback.
170 * @client: Cliented owned descriptor list. 177 * @client: Cliented owned descriptor list.
171 * @active: Active descriptor. 178 * @active: Active descriptor.
172 * @queue: Queued jobs. 179 * @queue: Queued jobs.
173 * @free: List of free descripts, ready to be reused.
174 * @free_len: Number of descriptors in the free list.
175 * @dma_cfg: The client configuration of this dma channel. 180 * @dma_cfg: The client configuration of this dma channel.
176 * @base: Pointer to the device instance struct. 181 * @base: Pointer to the device instance struct.
177 * @src_def_cfg: Default cfg register setting for src. 182 * @src_def_cfg: Default cfg register setting for src.
@@ -195,8 +200,6 @@ struct d40_chan {
195 struct list_head client; 200 struct list_head client;
196 struct list_head active; 201 struct list_head active;
197 struct list_head queue; 202 struct list_head queue;
198 struct list_head free;
199 int free_len;
200 struct stedma40_chan_cfg dma_cfg; 203 struct stedma40_chan_cfg dma_cfg;
201 struct d40_base *base; 204 struct d40_base *base;
202 /* Default register configurations */ 205 /* Default register configurations */
@@ -205,6 +208,9 @@ struct d40_chan {
205 struct d40_def_lcsp log_def; 208 struct d40_def_lcsp log_def;
206 struct d40_lcla_elem lcla; 209 struct d40_lcla_elem lcla;
207 struct d40_log_lli_full *lcpa; 210 struct d40_log_lli_full *lcpa;
211 /* Runtime reconfiguration */
212 dma_addr_t runtime_addr;
213 enum dma_data_direction runtime_direction;
208}; 214};
209 215
210/** 216/**
@@ -215,6 +221,7 @@ struct d40_chan {
215 * the same physical register. 221 * the same physical register.
216 * @dev: The device structure. 222 * @dev: The device structure.
217 * @virtbase: The virtual base address of the DMA's register. 223 * @virtbase: The virtual base address of the DMA's register.
224 * @rev: silicon revision detected.
218 * @clk: Pointer to the DMA clock structure. 225 * @clk: Pointer to the DMA clock structure.
219 * @phy_start: Physical memory start of the DMA registers. 226 * @phy_start: Physical memory start of the DMA registers.
220 * @phy_size: Size of the DMA register map. 227 * @phy_size: Size of the DMA register map.
@@ -240,12 +247,14 @@ struct d40_chan {
240 * @lcpa_base: The virtual mapped address of LCPA. 247 * @lcpa_base: The virtual mapped address of LCPA.
241 * @phy_lcpa: The physical address of the LCPA. 248 * @phy_lcpa: The physical address of the LCPA.
242 * @lcpa_size: The size of the LCPA area. 249 * @lcpa_size: The size of the LCPA area.
250 * @desc_slab: cache for descriptors.
243 */ 251 */
244struct d40_base { 252struct d40_base {
245 spinlock_t interrupt_lock; 253 spinlock_t interrupt_lock;
246 spinlock_t execmd_lock; 254 spinlock_t execmd_lock;
247 struct device *dev; 255 struct device *dev;
248 void __iomem *virtbase; 256 void __iomem *virtbase;
257 u8 rev:4;
249 struct clk *clk; 258 struct clk *clk;
250 phys_addr_t phy_start; 259 phys_addr_t phy_start;
251 resource_size_t phy_size; 260 resource_size_t phy_size;
@@ -266,6 +275,7 @@ struct d40_base {
266 void *lcpa_base; 275 void *lcpa_base;
267 dma_addr_t phy_lcpa; 276 dma_addr_t phy_lcpa;
268 resource_size_t lcpa_size; 277 resource_size_t lcpa_size;
278 struct kmem_cache *desc_slab;
269}; 279};
270 280
271/** 281/**
@@ -365,11 +375,6 @@ static dma_cookie_t d40_assign_cookie(struct d40_chan *d40c,
365 return cookie; 375 return cookie;
366} 376}
367 377
368static void d40_desc_reset(struct d40_desc *d40d)
369{
370 d40d->lli_tcount = 0;
371}
372
373static void d40_desc_remove(struct d40_desc *d40d) 378static void d40_desc_remove(struct d40_desc *d40d)
374{ 379{
375 list_del(&d40d->node); 380 list_del(&d40d->node);
@@ -377,7 +382,6 @@ static void d40_desc_remove(struct d40_desc *d40d)
377 382
378static struct d40_desc *d40_desc_get(struct d40_chan *d40c) 383static struct d40_desc *d40_desc_get(struct d40_chan *d40c)
379{ 384{
380 struct d40_desc *desc;
381 struct d40_desc *d; 385 struct d40_desc *d;
382 struct d40_desc *_d; 386 struct d40_desc *_d;
383 387
@@ -386,36 +390,21 @@ static struct d40_desc *d40_desc_get(struct d40_chan *d40c)
386 if (async_tx_test_ack(&d->txd)) { 390 if (async_tx_test_ack(&d->txd)) {
387 d40_pool_lli_free(d); 391 d40_pool_lli_free(d);
388 d40_desc_remove(d); 392 d40_desc_remove(d);
389 desc = d; 393 break;
390 goto out;
391 } 394 }
392 }
393
394 if (list_empty(&d40c->free)) {
395 /* Alloc new desc because we're out of used ones */
396 desc = kzalloc(sizeof(struct d40_desc), GFP_NOWAIT);
397 if (desc == NULL)
398 goto out;
399 INIT_LIST_HEAD(&desc->node);
400 } else { 395 } else {
401 /* Reuse an old desc. */ 396 d = kmem_cache_alloc(d40c->base->desc_slab, GFP_NOWAIT);
402 desc = list_first_entry(&d40c->free, 397 if (d != NULL) {
403 struct d40_desc, 398 memset(d, 0, sizeof(struct d40_desc));
404 node); 399 INIT_LIST_HEAD(&d->node);
405 list_del(&desc->node); 400 }
406 d40c->free_len--;
407 } 401 }
408out: 402 return d;
409 return desc;
410} 403}
411 404
412static void d40_desc_free(struct d40_chan *d40c, struct d40_desc *d40d) 405static void d40_desc_free(struct d40_chan *d40c, struct d40_desc *d40d)
413{ 406{
414 if (d40c->free_len < D40_DESC_CACHE_SIZE) { 407 kmem_cache_free(d40c->base->desc_slab, d40d);
415 list_add_tail(&d40d->node, &d40c->free);
416 d40c->free_len++;
417 } else
418 kfree(d40d);
419} 408}
420 409
421static void d40_desc_submit(struct d40_chan *d40c, struct d40_desc *desc) 410static void d40_desc_submit(struct d40_chan *d40c, struct d40_desc *desc)
@@ -456,37 +445,41 @@ static struct d40_desc *d40_first_queued(struct d40_chan *d40c)
456 445
457/* Support functions for logical channels */ 446/* Support functions for logical channels */
458 447
459static int d40_lcla_id_get(struct d40_chan *d40c, 448static int d40_lcla_id_get(struct d40_chan *d40c)
460 struct d40_lcla_pool *pool)
461{ 449{
462 int src_id = 0; 450 int src_id = 0;
463 int dst_id = 0; 451 int dst_id = 0;
464 struct d40_log_lli *lcla_lidx_base = 452 struct d40_log_lli *lcla_lidx_base =
465 pool->base + d40c->phy_chan->num * 1024; 453 d40c->base->lcla_pool.base + d40c->phy_chan->num * 1024;
466 int i; 454 int i;
467 int lli_per_log = d40c->base->plat_data->llis_per_log; 455 int lli_per_log = d40c->base->plat_data->llis_per_log;
456 unsigned long flags;
468 457
469 if (d40c->lcla.src_id >= 0 && d40c->lcla.dst_id >= 0) 458 if (d40c->lcla.src_id >= 0 && d40c->lcla.dst_id >= 0)
470 return 0; 459 return 0;
471 460
472 if (pool->num_blocks > 32) 461 if (d40c->base->lcla_pool.num_blocks > 32)
473 return -EINVAL; 462 return -EINVAL;
474 463
475 spin_lock(&pool->lock); 464 spin_lock_irqsave(&d40c->base->lcla_pool.lock, flags);
476 465
477 for (i = 0; i < pool->num_blocks; i++) { 466 for (i = 0; i < d40c->base->lcla_pool.num_blocks; i++) {
478 if (!(pool->alloc_map[d40c->phy_chan->num] & (0x1 << i))) { 467 if (!(d40c->base->lcla_pool.alloc_map[d40c->phy_chan->num] &
479 pool->alloc_map[d40c->phy_chan->num] |= (0x1 << i); 468 (0x1 << i))) {
469 d40c->base->lcla_pool.alloc_map[d40c->phy_chan->num] |=
470 (0x1 << i);
480 break; 471 break;
481 } 472 }
482 } 473 }
483 src_id = i; 474 src_id = i;
484 if (src_id >= pool->num_blocks) 475 if (src_id >= d40c->base->lcla_pool.num_blocks)
485 goto err; 476 goto err;
486 477
487 for (; i < pool->num_blocks; i++) { 478 for (; i < d40c->base->lcla_pool.num_blocks; i++) {
488 if (!(pool->alloc_map[d40c->phy_chan->num] & (0x1 << i))) { 479 if (!(d40c->base->lcla_pool.alloc_map[d40c->phy_chan->num] &
489 pool->alloc_map[d40c->phy_chan->num] |= (0x1 << i); 480 (0x1 << i))) {
481 d40c->base->lcla_pool.alloc_map[d40c->phy_chan->num] |=
482 (0x1 << i);
490 break; 483 break;
491 } 484 }
492 } 485 }
@@ -500,28 +493,13 @@ static int d40_lcla_id_get(struct d40_chan *d40c,
500 d40c->lcla.dst = lcla_lidx_base + dst_id * lli_per_log + 1; 493 d40c->lcla.dst = lcla_lidx_base + dst_id * lli_per_log + 1;
501 d40c->lcla.src = lcla_lidx_base + src_id * lli_per_log + 1; 494 d40c->lcla.src = lcla_lidx_base + src_id * lli_per_log + 1;
502 495
503 496 spin_unlock_irqrestore(&d40c->base->lcla_pool.lock, flags);
504 spin_unlock(&pool->lock);
505 return 0; 497 return 0;
506err: 498err:
507 spin_unlock(&pool->lock); 499 spin_unlock_irqrestore(&d40c->base->lcla_pool.lock, flags);
508 return -EINVAL; 500 return -EINVAL;
509} 501}
510 502
511static void d40_lcla_id_put(struct d40_chan *d40c,
512 struct d40_lcla_pool *pool,
513 int id)
514{
515 if (id < 0)
516 return;
517
518 d40c->lcla.src_id = -1;
519 d40c->lcla.dst_id = -1;
520
521 spin_lock(&pool->lock);
522 pool->alloc_map[d40c->phy_chan->num] &= (~(0x1 << id));
523 spin_unlock(&pool->lock);
524}
525 503
526static int d40_channel_execute_command(struct d40_chan *d40c, 504static int d40_channel_execute_command(struct d40_chan *d40c,
527 enum d40_command command) 505 enum d40_command command)
@@ -530,6 +508,7 @@ static int d40_channel_execute_command(struct d40_chan *d40c,
530 void __iomem *active_reg; 508 void __iomem *active_reg;
531 int ret = 0; 509 int ret = 0;
532 unsigned long flags; 510 unsigned long flags;
511 u32 wmask;
533 512
534 spin_lock_irqsave(&d40c->base->execmd_lock, flags); 513 spin_lock_irqsave(&d40c->base->execmd_lock, flags);
535 514
@@ -547,7 +526,9 @@ static int d40_channel_execute_command(struct d40_chan *d40c,
547 goto done; 526 goto done;
548 } 527 }
549 528
550 writel(command << D40_CHAN_POS(d40c->phy_chan->num), active_reg); 529 wmask = 0xffffffff & ~(D40_CHAN_POS_MASK(d40c->phy_chan->num));
530 writel(wmask | (command << D40_CHAN_POS(d40c->phy_chan->num)),
531 active_reg);
551 532
552 if (command == D40_DMA_SUSPEND_REQ) { 533 if (command == D40_DMA_SUSPEND_REQ) {
553 534
@@ -586,8 +567,7 @@ done:
586static void d40_term_all(struct d40_chan *d40c) 567static void d40_term_all(struct d40_chan *d40c)
587{ 568{
588 struct d40_desc *d40d; 569 struct d40_desc *d40d;
589 struct d40_desc *d; 570 unsigned long flags;
590 struct d40_desc *_d;
591 571
592 /* Release active descriptors */ 572 /* Release active descriptors */
593 while ((d40d = d40_first_active_get(d40c))) { 573 while ((d40d = d40_first_active_get(d40c))) {
@@ -605,19 +585,17 @@ static void d40_term_all(struct d40_chan *d40c)
605 d40_desc_free(d40c, d40d); 585 d40_desc_free(d40c, d40d);
606 } 586 }
607 587
608 /* Release client owned descriptors */ 588 spin_lock_irqsave(&d40c->base->lcla_pool.lock, flags);
609 if (!list_empty(&d40c->client)) 589
610 list_for_each_entry_safe(d, _d, &d40c->client, node) { 590 d40c->base->lcla_pool.alloc_map[d40c->phy_chan->num] &=
611 d40_pool_lli_free(d); 591 (~(0x1 << d40c->lcla.dst_id));
612 d40_desc_remove(d); 592 d40c->base->lcla_pool.alloc_map[d40c->phy_chan->num] &=
613 /* Return desc to free-list */ 593 (~(0x1 << d40c->lcla.src_id));
614 d40_desc_free(d40c, d40d); 594
615 } 595 d40c->lcla.src_id = -1;
596 d40c->lcla.dst_id = -1;
616 597
617 d40_lcla_id_put(d40c, &d40c->base->lcla_pool, 598 spin_unlock_irqrestore(&d40c->base->lcla_pool.lock, flags);
618 d40c->lcla.src_id);
619 d40_lcla_id_put(d40c, &d40c->base->lcla_pool,
620 d40c->lcla.dst_id);
621 599
622 d40c->pending_tx = 0; 600 d40c->pending_tx = 0;
623 d40c->busy = false; 601 d40c->busy = false;
@@ -628,6 +606,7 @@ static void d40_config_set_event(struct d40_chan *d40c, bool do_enable)
628 u32 val; 606 u32 val;
629 unsigned long flags; 607 unsigned long flags;
630 608
609 /* Notice, that disable requires the physical channel to be stopped */
631 if (do_enable) 610 if (do_enable)
632 val = D40_ACTIVATE_EVENTLINE; 611 val = D40_ACTIVATE_EVENTLINE;
633 else 612 else
@@ -732,31 +711,34 @@ static int d40_config_write(struct d40_chan *d40c)
732 711
733static void d40_desc_load(struct d40_chan *d40c, struct d40_desc *d40d) 712static void d40_desc_load(struct d40_chan *d40c, struct d40_desc *d40d)
734{ 713{
735
736 if (d40d->lli_phy.dst && d40d->lli_phy.src) { 714 if (d40d->lli_phy.dst && d40d->lli_phy.src) {
737 d40_phy_lli_write(d40c->base->virtbase, 715 d40_phy_lli_write(d40c->base->virtbase,
738 d40c->phy_chan->num, 716 d40c->phy_chan->num,
739 d40d->lli_phy.dst, 717 d40d->lli_phy.dst,
740 d40d->lli_phy.src); 718 d40d->lli_phy.src);
741 d40d->lli_tcount = d40d->lli_len;
742 } else if (d40d->lli_log.dst && d40d->lli_log.src) { 719 } else if (d40d->lli_log.dst && d40d->lli_log.src) {
743 u32 lli_len;
744 struct d40_log_lli *src = d40d->lli_log.src; 720 struct d40_log_lli *src = d40d->lli_log.src;
745 struct d40_log_lli *dst = d40d->lli_log.dst; 721 struct d40_log_lli *dst = d40d->lli_log.dst;
746 722 int s;
747 src += d40d->lli_tcount; 723
748 dst += d40d->lli_tcount; 724 src += d40d->lli_count;
749 725 dst += d40d->lli_count;
750 if (d40d->lli_len <= d40c->base->plat_data->llis_per_log) 726 s = d40_log_lli_write(d40c->lcpa,
751 lli_len = d40d->lli_len; 727 d40c->lcla.src, d40c->lcla.dst,
752 else 728 dst, src,
753 lli_len = d40c->base->plat_data->llis_per_log; 729 d40c->base->plat_data->llis_per_log);
754 d40d->lli_tcount += lli_len; 730
755 d40_log_lli_write(d40c->lcpa, d40c->lcla.src, 731 /* If s equals to zero, the job is not linked */
756 d40c->lcla.dst, 732 if (s > 0) {
757 dst, src, 733 (void) dma_map_single(d40c->base->dev, d40c->lcla.src,
758 d40c->base->plat_data->llis_per_log); 734 s * sizeof(struct d40_log_lli),
735 DMA_TO_DEVICE);
736 (void) dma_map_single(d40c->base->dev, d40c->lcla.dst,
737 s * sizeof(struct d40_log_lli),
738 DMA_TO_DEVICE);
739 }
759 } 740 }
741 d40d->lli_count += d40d->lli_tx_len;
760} 742}
761 743
762static dma_cookie_t d40_tx_submit(struct dma_async_tx_descriptor *tx) 744static dma_cookie_t d40_tx_submit(struct dma_async_tx_descriptor *tx)
@@ -780,18 +762,21 @@ static dma_cookie_t d40_tx_submit(struct dma_async_tx_descriptor *tx)
780 762
781static int d40_start(struct d40_chan *d40c) 763static int d40_start(struct d40_chan *d40c)
782{ 764{
783 int err; 765 if (d40c->base->rev == 0) {
766 int err;
784 767
785 if (d40c->log_num != D40_PHY_CHAN) { 768 if (d40c->log_num != D40_PHY_CHAN) {
786 err = d40_channel_execute_command(d40c, D40_DMA_SUSPEND_REQ); 769 err = d40_channel_execute_command(d40c,
787 if (err) 770 D40_DMA_SUSPEND_REQ);
788 return err; 771 if (err)
789 d40_config_set_event(d40c, true); 772 return err;
773 }
790 } 774 }
791 775
792 err = d40_channel_execute_command(d40c, D40_DMA_RUN); 776 if (d40c->log_num != D40_PHY_CHAN)
777 d40_config_set_event(d40c, true);
793 778
794 return err; 779 return d40_channel_execute_command(d40c, D40_DMA_RUN);
795} 780}
796 781
797static struct d40_desc *d40_queue_start(struct d40_chan *d40c) 782static struct d40_desc *d40_queue_start(struct d40_chan *d40c)
@@ -838,7 +823,7 @@ static void dma_tc_handle(struct d40_chan *d40c)
838 if (d40d == NULL) 823 if (d40d == NULL)
839 return; 824 return;
840 825
841 if (d40d->lli_tcount < d40d->lli_len) { 826 if (d40d->lli_count < d40d->lli_len) {
842 827
843 d40_desc_load(d40c, d40d); 828 d40_desc_load(d40c, d40d);
844 /* Start dma job */ 829 /* Start dma job */
@@ -891,7 +876,6 @@ static void dma_tasklet(unsigned long data)
891 /* Return desc to free-list */ 876 /* Return desc to free-list */
892 d40_desc_free(d40c, d40d_fin); 877 d40_desc_free(d40c, d40d_fin);
893 } else { 878 } else {
894 d40_desc_reset(d40d_fin);
895 if (!d40d_fin->is_in_client_list) { 879 if (!d40d_fin->is_in_client_list) {
896 d40_desc_remove(d40d_fin); 880 d40_desc_remove(d40d_fin);
897 list_add_tail(&d40d_fin->node, &d40c->client); 881 list_add_tail(&d40d_fin->node, &d40c->client);
@@ -975,7 +959,8 @@ static irqreturn_t d40_handle_interrupt(int irq, void *data)
975 if (!il[row].is_error) 959 if (!il[row].is_error)
976 dma_tc_handle(d40c); 960 dma_tc_handle(d40c);
977 else 961 else
978 dev_err(base->dev, "[%s] IRQ chan: %ld offset %d idx %d\n", 962 dev_err(base->dev,
963 "[%s] IRQ chan: %ld offset %d idx %d\n",
979 __func__, chan, il[row].offset, idx); 964 __func__, chan, il[row].offset, idx);
980 965
981 spin_unlock(&d40c->lock); 966 spin_unlock(&d40c->lock);
@@ -1134,7 +1119,8 @@ static int d40_allocate_channel(struct d40_chan *d40c)
1134 int j; 1119 int j;
1135 int log_num; 1120 int log_num;
1136 bool is_src; 1121 bool is_src;
1137 bool is_log = (d40c->dma_cfg.channel_type & STEDMA40_CHANNEL_IN_OPER_MODE) 1122 bool is_log = (d40c->dma_cfg.channel_type &
1123 STEDMA40_CHANNEL_IN_OPER_MODE)
1138 == STEDMA40_CHANNEL_IN_LOG_MODE; 1124 == STEDMA40_CHANNEL_IN_LOG_MODE;
1139 1125
1140 1126
@@ -1169,8 +1155,10 @@ static int d40_allocate_channel(struct d40_chan *d40c)
1169 for (j = 0; j < d40c->base->num_phy_chans; j += 8) { 1155 for (j = 0; j < d40c->base->num_phy_chans; j += 8) {
1170 int phy_num = j + event_group * 2; 1156 int phy_num = j + event_group * 2;
1171 for (i = phy_num; i < phy_num + 2; i++) { 1157 for (i = phy_num; i < phy_num + 2; i++) {
1172 if (d40_alloc_mask_set(&phys[i], is_src, 1158 if (d40_alloc_mask_set(&phys[i],
1173 0, is_log)) 1159 is_src,
1160 0,
1161 is_log))
1174 goto found_phy; 1162 goto found_phy;
1175 } 1163 }
1176 } 1164 }
@@ -1221,30 +1209,6 @@ out:
1221 1209
1222} 1210}
1223 1211
1224static int d40_config_chan(struct d40_chan *d40c,
1225 struct stedma40_chan_cfg *info)
1226{
1227
1228 /* Fill in basic CFG register values */
1229 d40_phy_cfg(&d40c->dma_cfg, &d40c->src_def_cfg,
1230 &d40c->dst_def_cfg, d40c->log_num != D40_PHY_CHAN);
1231
1232 if (d40c->log_num != D40_PHY_CHAN) {
1233 d40_log_cfg(&d40c->dma_cfg,
1234 &d40c->log_def.lcsp1, &d40c->log_def.lcsp3);
1235
1236 if (d40c->dma_cfg.dir == STEDMA40_PERIPH_TO_MEM)
1237 d40c->lcpa = d40c->base->lcpa_base +
1238 d40c->dma_cfg.src_dev_type * 32;
1239 else
1240 d40c->lcpa = d40c->base->lcpa_base +
1241 d40c->dma_cfg.dst_dev_type * 32 + 16;
1242 }
1243
1244 /* Write channel configuration to the DMA */
1245 return d40_config_write(d40c);
1246}
1247
1248static int d40_config_memcpy(struct d40_chan *d40c) 1212static int d40_config_memcpy(struct d40_chan *d40c)
1249{ 1213{
1250 dma_cap_mask_t cap = d40c->chan.device->cap_mask; 1214 dma_cap_mask_t cap = d40c->chan.device->cap_mask;
@@ -1272,13 +1236,25 @@ static int d40_free_dma(struct d40_chan *d40c)
1272{ 1236{
1273 1237
1274 int res = 0; 1238 int res = 0;
1275 u32 event, dir; 1239 u32 event;
1276 struct d40_phy_res *phy = d40c->phy_chan; 1240 struct d40_phy_res *phy = d40c->phy_chan;
1277 bool is_src; 1241 bool is_src;
1242 struct d40_desc *d;
1243 struct d40_desc *_d;
1244
1278 1245
1279 /* Terminate all queued and active transfers */ 1246 /* Terminate all queued and active transfers */
1280 d40_term_all(d40c); 1247 d40_term_all(d40c);
1281 1248
1249 /* Release client owned descriptors */
1250 if (!list_empty(&d40c->client))
1251 list_for_each_entry_safe(d, _d, &d40c->client, node) {
1252 d40_pool_lli_free(d);
1253 d40_desc_remove(d);
1254 /* Return desc to free-list */
1255 d40_desc_free(d40c, d);
1256 }
1257
1282 if (phy == NULL) { 1258 if (phy == NULL) {
1283 dev_err(&d40c->chan.dev->device, "[%s] phy == null\n", 1259 dev_err(&d40c->chan.dev->device, "[%s] phy == null\n",
1284 __func__); 1260 __func__);
@@ -1292,22 +1268,12 @@ static int d40_free_dma(struct d40_chan *d40c)
1292 return -EINVAL; 1268 return -EINVAL;
1293 } 1269 }
1294 1270
1295
1296 res = d40_channel_execute_command(d40c, D40_DMA_SUSPEND_REQ);
1297 if (res) {
1298 dev_err(&d40c->chan.dev->device, "[%s] suspend\n",
1299 __func__);
1300 return res;
1301 }
1302
1303 if (d40c->dma_cfg.dir == STEDMA40_MEM_TO_PERIPH || 1271 if (d40c->dma_cfg.dir == STEDMA40_MEM_TO_PERIPH ||
1304 d40c->dma_cfg.dir == STEDMA40_MEM_TO_MEM) { 1272 d40c->dma_cfg.dir == STEDMA40_MEM_TO_MEM) {
1305 event = D40_TYPE_TO_EVENT(d40c->dma_cfg.dst_dev_type); 1273 event = D40_TYPE_TO_EVENT(d40c->dma_cfg.dst_dev_type);
1306 dir = D40_CHAN_REG_SDLNK;
1307 is_src = false; 1274 is_src = false;
1308 } else if (d40c->dma_cfg.dir == STEDMA40_PERIPH_TO_MEM) { 1275 } else if (d40c->dma_cfg.dir == STEDMA40_PERIPH_TO_MEM) {
1309 event = D40_TYPE_TO_EVENT(d40c->dma_cfg.src_dev_type); 1276 event = D40_TYPE_TO_EVENT(d40c->dma_cfg.src_dev_type);
1310 dir = D40_CHAN_REG_SSLNK;
1311 is_src = true; 1277 is_src = true;
1312 } else { 1278 } else {
1313 dev_err(&d40c->chan.dev->device, 1279 dev_err(&d40c->chan.dev->device,
@@ -1315,16 +1281,17 @@ static int d40_free_dma(struct d40_chan *d40c)
1315 return -EINVAL; 1281 return -EINVAL;
1316 } 1282 }
1317 1283
1284 res = d40_channel_execute_command(d40c, D40_DMA_SUSPEND_REQ);
1285 if (res) {
1286 dev_err(&d40c->chan.dev->device, "[%s] suspend failed\n",
1287 __func__);
1288 return res;
1289 }
1290
1318 if (d40c->log_num != D40_PHY_CHAN) { 1291 if (d40c->log_num != D40_PHY_CHAN) {
1319 /* 1292 /* Release logical channel, deactivate the event line */
1320 * Release logical channel, deactivate the event line during
1321 * the time physical res is suspended.
1322 */
1323 writel((D40_DEACTIVATE_EVENTLINE << D40_EVENTLINE_POS(event)) &
1324 D40_EVENTLINE_MASK(event),
1325 d40c->base->virtbase + D40_DREG_PCBASE +
1326 phy->num * D40_DREG_PCDELTA + dir);
1327 1293
1294 d40_config_set_event(d40c, false);
1328 d40c->base->lookup_log_chans[d40c->log_num] = NULL; 1295 d40c->base->lookup_log_chans[d40c->log_num] = NULL;
1329 1296
1330 /* 1297 /*
@@ -1345,8 +1312,9 @@ static int d40_free_dma(struct d40_chan *d40c)
1345 } 1312 }
1346 return 0; 1313 return 0;
1347 } 1314 }
1348 } else 1315 } else {
1349 d40_alloc_mask_free(phy, is_src, 0); 1316 (void) d40_alloc_mask_free(phy, is_src, 0);
1317 }
1350 1318
1351 /* Release physical channel */ 1319 /* Release physical channel */
1352 res = d40_channel_execute_command(d40c, D40_DMA_STOP); 1320 res = d40_channel_execute_command(d40c, D40_DMA_STOP);
@@ -1361,8 +1329,6 @@ static int d40_free_dma(struct d40_chan *d40c)
1361 d40c->base->lookup_phy_chans[phy->num] = NULL; 1329 d40c->base->lookup_phy_chans[phy->num] = NULL;
1362 1330
1363 return 0; 1331 return 0;
1364
1365
1366} 1332}
1367 1333
1368static int d40_pause(struct dma_chan *chan) 1334static int d40_pause(struct dma_chan *chan)
@@ -1370,7 +1336,6 @@ static int d40_pause(struct dma_chan *chan)
1370 struct d40_chan *d40c = 1336 struct d40_chan *d40c =
1371 container_of(chan, struct d40_chan, chan); 1337 container_of(chan, struct d40_chan, chan);
1372 int res; 1338 int res;
1373
1374 unsigned long flags; 1339 unsigned long flags;
1375 1340
1376 spin_lock_irqsave(&d40c->lock, flags); 1341 spin_lock_irqsave(&d40c->lock, flags);
@@ -1397,7 +1362,6 @@ static bool d40_is_paused(struct d40_chan *d40c)
1397 void __iomem *active_reg; 1362 void __iomem *active_reg;
1398 u32 status; 1363 u32 status;
1399 u32 event; 1364 u32 event;
1400 int res;
1401 1365
1402 spin_lock_irqsave(&d40c->lock, flags); 1366 spin_lock_irqsave(&d40c->lock, flags);
1403 1367
@@ -1416,10 +1380,6 @@ static bool d40_is_paused(struct d40_chan *d40c)
1416 goto _exit; 1380 goto _exit;
1417 } 1381 }
1418 1382
1419 res = d40_channel_execute_command(d40c, D40_DMA_SUSPEND_REQ);
1420 if (res != 0)
1421 goto _exit;
1422
1423 if (d40c->dma_cfg.dir == STEDMA40_MEM_TO_PERIPH || 1383 if (d40c->dma_cfg.dir == STEDMA40_MEM_TO_PERIPH ||
1424 d40c->dma_cfg.dir == STEDMA40_MEM_TO_MEM) 1384 d40c->dma_cfg.dir == STEDMA40_MEM_TO_MEM)
1425 event = D40_TYPE_TO_EVENT(d40c->dma_cfg.dst_dev_type); 1385 event = D40_TYPE_TO_EVENT(d40c->dma_cfg.dst_dev_type);
@@ -1436,12 +1396,6 @@ static bool d40_is_paused(struct d40_chan *d40c)
1436 1396
1437 if (status != D40_DMA_RUN) 1397 if (status != D40_DMA_RUN)
1438 is_paused = true; 1398 is_paused = true;
1439
1440 /* Resume the other logical channels if any */
1441 if (d40_chan_has_events(d40c))
1442 res = d40_channel_execute_command(d40c,
1443 D40_DMA_RUN);
1444
1445_exit: 1399_exit:
1446 spin_unlock_irqrestore(&d40c->lock, flags); 1400 spin_unlock_irqrestore(&d40c->lock, flags);
1447 return is_paused; 1401 return is_paused;
@@ -1468,13 +1422,14 @@ static u32 d40_residue(struct d40_chan *d40c)
1468 u32 num_elt; 1422 u32 num_elt;
1469 1423
1470 if (d40c->log_num != D40_PHY_CHAN) 1424 if (d40c->log_num != D40_PHY_CHAN)
1471 num_elt = (readl(&d40c->lcpa->lcsp2) & D40_MEM_LCSP2_ECNT_MASK) 1425 num_elt = (readl(&d40c->lcpa->lcsp2) & D40_MEM_LCSP2_ECNT_MASK)
1472 >> D40_MEM_LCSP2_ECNT_POS; 1426 >> D40_MEM_LCSP2_ECNT_POS;
1473 else 1427 else
1474 num_elt = (readl(d40c->base->virtbase + D40_DREG_PCBASE + 1428 num_elt = (readl(d40c->base->virtbase + D40_DREG_PCBASE +
1475 d40c->phy_chan->num * D40_DREG_PCDELTA + 1429 d40c->phy_chan->num * D40_DREG_PCDELTA +
1476 D40_CHAN_REG_SDELT) & 1430 D40_CHAN_REG_SDELT) &
1477 D40_SREG_ELEM_PHY_ECNT_MASK) >> D40_SREG_ELEM_PHY_ECNT_POS; 1431 D40_SREG_ELEM_PHY_ECNT_MASK) >>
1432 D40_SREG_ELEM_PHY_ECNT_POS;
1478 return num_elt * (1 << d40c->dma_cfg.dst_info.data_width); 1433 return num_elt * (1 << d40c->dma_cfg.dst_info.data_width);
1479} 1434}
1480 1435
@@ -1487,20 +1442,21 @@ static int d40_resume(struct dma_chan *chan)
1487 1442
1488 spin_lock_irqsave(&d40c->lock, flags); 1443 spin_lock_irqsave(&d40c->lock, flags);
1489 1444
1490 if (d40c->log_num != D40_PHY_CHAN) { 1445 if (d40c->base->rev == 0)
1491 res = d40_channel_execute_command(d40c, D40_DMA_SUSPEND_REQ); 1446 if (d40c->log_num != D40_PHY_CHAN) {
1492 if (res) 1447 res = d40_channel_execute_command(d40c,
1493 goto out; 1448 D40_DMA_SUSPEND_REQ);
1449 goto no_suspend;
1450 }
1494 1451
1495 /* If bytes left to transfer or linked tx resume job */ 1452 /* If bytes left to transfer or linked tx resume job */
1496 if (d40_residue(d40c) || d40_tx_is_linked(d40c)) { 1453 if (d40_residue(d40c) || d40_tx_is_linked(d40c)) {
1454 if (d40c->log_num != D40_PHY_CHAN)
1497 d40_config_set_event(d40c, true); 1455 d40_config_set_event(d40c, true);
1498 res = d40_channel_execute_command(d40c, D40_DMA_RUN);
1499 }
1500 } else if (d40_residue(d40c) || d40_tx_is_linked(d40c))
1501 res = d40_channel_execute_command(d40c, D40_DMA_RUN); 1456 res = d40_channel_execute_command(d40c, D40_DMA_RUN);
1457 }
1502 1458
1503out: 1459no_suspend:
1504 spin_unlock_irqrestore(&d40c->lock, flags); 1460 spin_unlock_irqrestore(&d40c->lock, flags);
1505 return res; 1461 return res;
1506} 1462}
@@ -1534,8 +1490,10 @@ int stedma40_set_psize(struct dma_chan *chan,
1534 if (d40c->log_num != D40_PHY_CHAN) { 1490 if (d40c->log_num != D40_PHY_CHAN) {
1535 d40c->log_def.lcsp1 &= ~D40_MEM_LCSP1_SCFG_PSIZE_MASK; 1491 d40c->log_def.lcsp1 &= ~D40_MEM_LCSP1_SCFG_PSIZE_MASK;
1536 d40c->log_def.lcsp3 &= ~D40_MEM_LCSP1_SCFG_PSIZE_MASK; 1492 d40c->log_def.lcsp3 &= ~D40_MEM_LCSP1_SCFG_PSIZE_MASK;
1537 d40c->log_def.lcsp1 |= src_psize << D40_MEM_LCSP1_SCFG_PSIZE_POS; 1493 d40c->log_def.lcsp1 |= src_psize <<
1538 d40c->log_def.lcsp3 |= dst_psize << D40_MEM_LCSP1_SCFG_PSIZE_POS; 1494 D40_MEM_LCSP1_SCFG_PSIZE_POS;
1495 d40c->log_def.lcsp3 |= dst_psize <<
1496 D40_MEM_LCSP1_SCFG_PSIZE_POS;
1539 goto out; 1497 goto out;
1540 } 1498 }
1541 1499
@@ -1566,37 +1524,42 @@ struct dma_async_tx_descriptor *stedma40_memcpy_sg(struct dma_chan *chan,
1566 struct scatterlist *sgl_dst, 1524 struct scatterlist *sgl_dst,
1567 struct scatterlist *sgl_src, 1525 struct scatterlist *sgl_src,
1568 unsigned int sgl_len, 1526 unsigned int sgl_len,
1569 unsigned long flags) 1527 unsigned long dma_flags)
1570{ 1528{
1571 int res; 1529 int res;
1572 struct d40_desc *d40d; 1530 struct d40_desc *d40d;
1573 struct d40_chan *d40c = container_of(chan, struct d40_chan, 1531 struct d40_chan *d40c = container_of(chan, struct d40_chan,
1574 chan); 1532 chan);
1575 unsigned long flg; 1533 unsigned long flags;
1576 int lli_max = d40c->base->plat_data->llis_per_log;
1577 1534
1535 if (d40c->phy_chan == NULL) {
1536 dev_err(&d40c->chan.dev->device,
1537 "[%s] Unallocated channel.\n", __func__);
1538 return ERR_PTR(-EINVAL);
1539 }
1578 1540
1579 spin_lock_irqsave(&d40c->lock, flg); 1541 spin_lock_irqsave(&d40c->lock, flags);
1580 d40d = d40_desc_get(d40c); 1542 d40d = d40_desc_get(d40c);
1581 1543
1582 if (d40d == NULL) 1544 if (d40d == NULL)
1583 goto err; 1545 goto err;
1584 1546
1585 memset(d40d, 0, sizeof(struct d40_desc));
1586 d40d->lli_len = sgl_len; 1547 d40d->lli_len = sgl_len;
1587 1548 d40d->lli_tx_len = d40d->lli_len;
1588 d40d->txd.flags = flags; 1549 d40d->txd.flags = dma_flags;
1589 1550
1590 if (d40c->log_num != D40_PHY_CHAN) { 1551 if (d40c->log_num != D40_PHY_CHAN) {
1552 if (d40d->lli_len > d40c->base->plat_data->llis_per_log)
1553 d40d->lli_tx_len = d40c->base->plat_data->llis_per_log;
1554
1591 if (sgl_len > 1) 1555 if (sgl_len > 1)
1592 /* 1556 /*
1593 * Check if there is space available in lcla. If not, 1557 * Check if there is space available in lcla. If not,
1594 * split list into 1-length and run only in lcpa 1558 * split list into 1-length and run only in lcpa
1595 * space. 1559 * space.
1596 */ 1560 */
1597 if (d40_lcla_id_get(d40c, 1561 if (d40_lcla_id_get(d40c) != 0)
1598 &d40c->base->lcla_pool) != 0) 1562 d40d->lli_tx_len = 1;
1599 lli_max = 1;
1600 1563
1601 if (d40_pool_lli_alloc(d40d, sgl_len, true) < 0) { 1564 if (d40_pool_lli_alloc(d40d, sgl_len, true) < 0) {
1602 dev_err(&d40c->chan.dev->device, 1565 dev_err(&d40c->chan.dev->device,
@@ -1610,7 +1573,8 @@ struct dma_async_tx_descriptor *stedma40_memcpy_sg(struct dma_chan *chan,
1610 d40d->lli_log.src, 1573 d40d->lli_log.src,
1611 d40c->log_def.lcsp1, 1574 d40c->log_def.lcsp1,
1612 d40c->dma_cfg.src_info.data_width, 1575 d40c->dma_cfg.src_info.data_width,
1613 flags & DMA_PREP_INTERRUPT, lli_max, 1576 dma_flags & DMA_PREP_INTERRUPT,
1577 d40d->lli_tx_len,
1614 d40c->base->plat_data->llis_per_log); 1578 d40c->base->plat_data->llis_per_log);
1615 1579
1616 (void) d40_log_sg_to_lli(d40c->lcla.dst_id, 1580 (void) d40_log_sg_to_lli(d40c->lcla.dst_id,
@@ -1619,7 +1583,8 @@ struct dma_async_tx_descriptor *stedma40_memcpy_sg(struct dma_chan *chan,
1619 d40d->lli_log.dst, 1583 d40d->lli_log.dst,
1620 d40c->log_def.lcsp3, 1584 d40c->log_def.lcsp3,
1621 d40c->dma_cfg.dst_info.data_width, 1585 d40c->dma_cfg.dst_info.data_width,
1622 flags & DMA_PREP_INTERRUPT, lli_max, 1586 dma_flags & DMA_PREP_INTERRUPT,
1587 d40d->lli_tx_len,
1623 d40c->base->plat_data->llis_per_log); 1588 d40c->base->plat_data->llis_per_log);
1624 1589
1625 1590
@@ -1664,11 +1629,11 @@ struct dma_async_tx_descriptor *stedma40_memcpy_sg(struct dma_chan *chan,
1664 1629
1665 d40d->txd.tx_submit = d40_tx_submit; 1630 d40d->txd.tx_submit = d40_tx_submit;
1666 1631
1667 spin_unlock_irqrestore(&d40c->lock, flg); 1632 spin_unlock_irqrestore(&d40c->lock, flags);
1668 1633
1669 return &d40d->txd; 1634 return &d40d->txd;
1670err: 1635err:
1671 spin_unlock_irqrestore(&d40c->lock, flg); 1636 spin_unlock_irqrestore(&d40c->lock, flags);
1672 return NULL; 1637 return NULL;
1673} 1638}
1674EXPORT_SYMBOL(stedma40_memcpy_sg); 1639EXPORT_SYMBOL(stedma40_memcpy_sg);
@@ -1698,46 +1663,66 @@ static int d40_alloc_chan_resources(struct dma_chan *chan)
1698 unsigned long flags; 1663 unsigned long flags;
1699 struct d40_chan *d40c = 1664 struct d40_chan *d40c =
1700 container_of(chan, struct d40_chan, chan); 1665 container_of(chan, struct d40_chan, chan);
1701 1666 bool is_free_phy;
1702 spin_lock_irqsave(&d40c->lock, flags); 1667 spin_lock_irqsave(&d40c->lock, flags);
1703 1668
1704 d40c->completed = chan->cookie = 1; 1669 d40c->completed = chan->cookie = 1;
1705 1670
1706 /* 1671 /*
1707 * If no dma configuration is set (channel_type == 0) 1672 * If no dma configuration is set (channel_type == 0)
1708 * use default configuration 1673 * use default configuration (memcpy)
1709 */ 1674 */
1710 if (d40c->dma_cfg.channel_type == 0) { 1675 if (d40c->dma_cfg.channel_type == 0) {
1711 err = d40_config_memcpy(d40c); 1676 err = d40_config_memcpy(d40c);
1712 if (err) 1677 if (err) {
1713 goto err_alloc; 1678 dev_err(&d40c->chan.dev->device,
1679 "[%s] Failed to configure memcpy channel\n",
1680 __func__);
1681 goto fail;
1682 }
1714 } 1683 }
1684 is_free_phy = (d40c->phy_chan == NULL);
1715 1685
1716 err = d40_allocate_channel(d40c); 1686 err = d40_allocate_channel(d40c);
1717 if (err) { 1687 if (err) {
1718 dev_err(&d40c->chan.dev->device, 1688 dev_err(&d40c->chan.dev->device,
1719 "[%s] Failed to allocate channel\n", __func__); 1689 "[%s] Failed to allocate channel\n", __func__);
1720 goto err_alloc; 1690 goto fail;
1721 } 1691 }
1722 1692
1723 err = d40_config_chan(d40c, &d40c->dma_cfg); 1693 /* Fill in basic CFG register values */
1724 if (err) { 1694 d40_phy_cfg(&d40c->dma_cfg, &d40c->src_def_cfg,
1725 dev_err(&d40c->chan.dev->device, 1695 &d40c->dst_def_cfg, d40c->log_num != D40_PHY_CHAN);
1726 "[%s] Failed to configure channel\n",
1727 __func__);
1728 goto err_config;
1729 }
1730 1696
1731 spin_unlock_irqrestore(&d40c->lock, flags); 1697 if (d40c->log_num != D40_PHY_CHAN) {
1732 return 0; 1698 d40_log_cfg(&d40c->dma_cfg,
1699 &d40c->log_def.lcsp1, &d40c->log_def.lcsp3);
1733 1700
1734 err_config: 1701 if (d40c->dma_cfg.dir == STEDMA40_PERIPH_TO_MEM)
1735 (void) d40_free_dma(d40c); 1702 d40c->lcpa = d40c->base->lcpa_base +
1736 err_alloc: 1703 d40c->dma_cfg.src_dev_type * D40_LCPA_CHAN_SIZE;
1704 else
1705 d40c->lcpa = d40c->base->lcpa_base +
1706 d40c->dma_cfg.dst_dev_type *
1707 D40_LCPA_CHAN_SIZE + D40_LCPA_CHAN_DST_DELTA;
1708 }
1709
1710 /*
1711 * Only write channel configuration to the DMA if the physical
1712 * resource is free. In case of multiple logical channels
1713 * on the same physical resource, only the first write is necessary.
1714 */
1715 if (is_free_phy) {
1716 err = d40_config_write(d40c);
1717 if (err) {
1718 dev_err(&d40c->chan.dev->device,
1719 "[%s] Failed to configure channel\n",
1720 __func__);
1721 }
1722 }
1723fail:
1737 spin_unlock_irqrestore(&d40c->lock, flags); 1724 spin_unlock_irqrestore(&d40c->lock, flags);
1738 dev_err(&d40c->chan.dev->device, 1725 return err;
1739 "[%s] Channel allocation failed\n", __func__);
1740 return -EINVAL;
1741} 1726}
1742 1727
1743static void d40_free_chan_resources(struct dma_chan *chan) 1728static void d40_free_chan_resources(struct dma_chan *chan)
@@ -1747,6 +1732,13 @@ static void d40_free_chan_resources(struct dma_chan *chan)
1747 int err; 1732 int err;
1748 unsigned long flags; 1733 unsigned long flags;
1749 1734
1735 if (d40c->phy_chan == NULL) {
1736 dev_err(&d40c->chan.dev->device,
1737 "[%s] Cannot free unallocated channel\n", __func__);
1738 return;
1739 }
1740
1741
1750 spin_lock_irqsave(&d40c->lock, flags); 1742 spin_lock_irqsave(&d40c->lock, flags);
1751 1743
1752 err = d40_free_dma(d40c); 1744 err = d40_free_dma(d40c);
@@ -1761,15 +1753,21 @@ static struct dma_async_tx_descriptor *d40_prep_memcpy(struct dma_chan *chan,
1761 dma_addr_t dst, 1753 dma_addr_t dst,
1762 dma_addr_t src, 1754 dma_addr_t src,
1763 size_t size, 1755 size_t size,
1764 unsigned long flags) 1756 unsigned long dma_flags)
1765{ 1757{
1766 struct d40_desc *d40d; 1758 struct d40_desc *d40d;
1767 struct d40_chan *d40c = container_of(chan, struct d40_chan, 1759 struct d40_chan *d40c = container_of(chan, struct d40_chan,
1768 chan); 1760 chan);
1769 unsigned long flg; 1761 unsigned long flags;
1770 int err = 0; 1762 int err = 0;
1771 1763
1772 spin_lock_irqsave(&d40c->lock, flg); 1764 if (d40c->phy_chan == NULL) {
1765 dev_err(&d40c->chan.dev->device,
1766 "[%s] Channel is not allocated.\n", __func__);
1767 return ERR_PTR(-EINVAL);
1768 }
1769
1770 spin_lock_irqsave(&d40c->lock, flags);
1773 d40d = d40_desc_get(d40c); 1771 d40d = d40_desc_get(d40c);
1774 1772
1775 if (d40d == NULL) { 1773 if (d40d == NULL) {
@@ -1778,9 +1776,7 @@ static struct dma_async_tx_descriptor *d40_prep_memcpy(struct dma_chan *chan,
1778 goto err; 1776 goto err;
1779 } 1777 }
1780 1778
1781 memset(d40d, 0, sizeof(struct d40_desc)); 1779 d40d->txd.flags = dma_flags;
1782
1783 d40d->txd.flags = flags;
1784 1780
1785 dma_async_tx_descriptor_init(&d40d->txd, chan); 1781 dma_async_tx_descriptor_init(&d40d->txd, chan);
1786 1782
@@ -1794,6 +1790,7 @@ static struct dma_async_tx_descriptor *d40_prep_memcpy(struct dma_chan *chan,
1794 goto err; 1790 goto err;
1795 } 1791 }
1796 d40d->lli_len = 1; 1792 d40d->lli_len = 1;
1793 d40d->lli_tx_len = 1;
1797 1794
1798 d40_log_fill_lli(d40d->lli_log.src, 1795 d40_log_fill_lli(d40d->lli_log.src,
1799 src, 1796 src,
@@ -1801,7 +1798,7 @@ static struct dma_async_tx_descriptor *d40_prep_memcpy(struct dma_chan *chan,
1801 0, 1798 0,
1802 d40c->log_def.lcsp1, 1799 d40c->log_def.lcsp1,
1803 d40c->dma_cfg.src_info.data_width, 1800 d40c->dma_cfg.src_info.data_width,
1804 true, true); 1801 false, true);
1805 1802
1806 d40_log_fill_lli(d40d->lli_log.dst, 1803 d40_log_fill_lli(d40d->lli_log.dst,
1807 dst, 1804 dst,
@@ -1848,7 +1845,7 @@ static struct dma_async_tx_descriptor *d40_prep_memcpy(struct dma_chan *chan,
1848 d40d->lli_pool.size, DMA_TO_DEVICE); 1845 d40d->lli_pool.size, DMA_TO_DEVICE);
1849 } 1846 }
1850 1847
1851 spin_unlock_irqrestore(&d40c->lock, flg); 1848 spin_unlock_irqrestore(&d40c->lock, flags);
1852 return &d40d->txd; 1849 return &d40d->txd;
1853 1850
1854err_fill_lli: 1851err_fill_lli:
@@ -1856,7 +1853,7 @@ err_fill_lli:
1856 "[%s] Failed filling in PHY LLI\n", __func__); 1853 "[%s] Failed filling in PHY LLI\n", __func__);
1857 d40_pool_lli_free(d40d); 1854 d40_pool_lli_free(d40d);
1858err: 1855err:
1859 spin_unlock_irqrestore(&d40c->lock, flg); 1856 spin_unlock_irqrestore(&d40c->lock, flags);
1860 return NULL; 1857 return NULL;
1861} 1858}
1862 1859
@@ -1865,11 +1862,10 @@ static int d40_prep_slave_sg_log(struct d40_desc *d40d,
1865 struct scatterlist *sgl, 1862 struct scatterlist *sgl,
1866 unsigned int sg_len, 1863 unsigned int sg_len,
1867 enum dma_data_direction direction, 1864 enum dma_data_direction direction,
1868 unsigned long flags) 1865 unsigned long dma_flags)
1869{ 1866{
1870 dma_addr_t dev_addr = 0; 1867 dma_addr_t dev_addr = 0;
1871 int total_size; 1868 int total_size;
1872 int lli_max = d40c->base->plat_data->llis_per_log;
1873 1869
1874 if (d40_pool_lli_alloc(d40d, sg_len, true) < 0) { 1870 if (d40_pool_lli_alloc(d40d, sg_len, true) < 0) {
1875 dev_err(&d40c->chan.dev->device, 1871 dev_err(&d40c->chan.dev->device,
@@ -1878,7 +1874,10 @@ static int d40_prep_slave_sg_log(struct d40_desc *d40d,
1878 } 1874 }
1879 1875
1880 d40d->lli_len = sg_len; 1876 d40d->lli_len = sg_len;
1881 d40d->lli_tcount = 0; 1877 if (d40d->lli_len <= d40c->base->plat_data->llis_per_log)
1878 d40d->lli_tx_len = d40d->lli_len;
1879 else
1880 d40d->lli_tx_len = d40c->base->plat_data->llis_per_log;
1882 1881
1883 if (sg_len > 1) 1882 if (sg_len > 1)
1884 /* 1883 /*
@@ -1886,35 +1885,34 @@ static int d40_prep_slave_sg_log(struct d40_desc *d40d,
1886 * If not, split list into 1-length and run only 1885 * If not, split list into 1-length and run only
1887 * in lcpa space. 1886 * in lcpa space.
1888 */ 1887 */
1889 if (d40_lcla_id_get(d40c, &d40c->base->lcla_pool) != 0) 1888 if (d40_lcla_id_get(d40c) != 0)
1890 lli_max = 1; 1889 d40d->lli_tx_len = 1;
1891 1890
1892 if (direction == DMA_FROM_DEVICE) { 1891 if (direction == DMA_FROM_DEVICE)
1893 dev_addr = d40c->base->plat_data->dev_rx[d40c->dma_cfg.src_dev_type]; 1892 if (d40c->runtime_addr)
1894 total_size = d40_log_sg_to_dev(&d40c->lcla, 1893 dev_addr = d40c->runtime_addr;
1895 sgl, sg_len, 1894 else
1896 &d40d->lli_log, 1895 dev_addr = d40c->base->plat_data->dev_rx[d40c->dma_cfg.src_dev_type];
1897 &d40c->log_def, 1896 else if (direction == DMA_TO_DEVICE)
1898 d40c->dma_cfg.src_info.data_width, 1897 if (d40c->runtime_addr)
1899 d40c->dma_cfg.dst_info.data_width, 1898 dev_addr = d40c->runtime_addr;
1900 direction, 1899 else
1901 flags & DMA_PREP_INTERRUPT, 1900 dev_addr = d40c->base->plat_data->dev_tx[d40c->dma_cfg.dst_dev_type];
1902 dev_addr, lli_max, 1901
1903 d40c->base->plat_data->llis_per_log); 1902 else
1904 } else if (direction == DMA_TO_DEVICE) {
1905 dev_addr = d40c->base->plat_data->dev_tx[d40c->dma_cfg.dst_dev_type];
1906 total_size = d40_log_sg_to_dev(&d40c->lcla,
1907 sgl, sg_len,
1908 &d40d->lli_log,
1909 &d40c->log_def,
1910 d40c->dma_cfg.src_info.data_width,
1911 d40c->dma_cfg.dst_info.data_width,
1912 direction,
1913 flags & DMA_PREP_INTERRUPT,
1914 dev_addr, lli_max,
1915 d40c->base->plat_data->llis_per_log);
1916 } else
1917 return -EINVAL; 1903 return -EINVAL;
1904
1905 total_size = d40_log_sg_to_dev(&d40c->lcla,
1906 sgl, sg_len,
1907 &d40d->lli_log,
1908 &d40c->log_def,
1909 d40c->dma_cfg.src_info.data_width,
1910 d40c->dma_cfg.dst_info.data_width,
1911 direction,
1912 dma_flags & DMA_PREP_INTERRUPT,
1913 dev_addr, d40d->lli_tx_len,
1914 d40c->base->plat_data->llis_per_log);
1915
1918 if (total_size < 0) 1916 if (total_size < 0)
1919 return -EINVAL; 1917 return -EINVAL;
1920 1918
@@ -1926,7 +1924,7 @@ static int d40_prep_slave_sg_phy(struct d40_desc *d40d,
1926 struct scatterlist *sgl, 1924 struct scatterlist *sgl,
1927 unsigned int sgl_len, 1925 unsigned int sgl_len,
1928 enum dma_data_direction direction, 1926 enum dma_data_direction direction,
1929 unsigned long flags) 1927 unsigned long dma_flags)
1930{ 1928{
1931 dma_addr_t src_dev_addr; 1929 dma_addr_t src_dev_addr;
1932 dma_addr_t dst_dev_addr; 1930 dma_addr_t dst_dev_addr;
@@ -1939,13 +1937,19 @@ static int d40_prep_slave_sg_phy(struct d40_desc *d40d,
1939 } 1937 }
1940 1938
1941 d40d->lli_len = sgl_len; 1939 d40d->lli_len = sgl_len;
1942 d40d->lli_tcount = 0; 1940 d40d->lli_tx_len = sgl_len;
1943 1941
1944 if (direction == DMA_FROM_DEVICE) { 1942 if (direction == DMA_FROM_DEVICE) {
1945 dst_dev_addr = 0; 1943 dst_dev_addr = 0;
1946 src_dev_addr = d40c->base->plat_data->dev_rx[d40c->dma_cfg.src_dev_type]; 1944 if (d40c->runtime_addr)
1945 src_dev_addr = d40c->runtime_addr;
1946 else
1947 src_dev_addr = d40c->base->plat_data->dev_rx[d40c->dma_cfg.src_dev_type];
1947 } else if (direction == DMA_TO_DEVICE) { 1948 } else if (direction == DMA_TO_DEVICE) {
1948 dst_dev_addr = d40c->base->plat_data->dev_tx[d40c->dma_cfg.dst_dev_type]; 1949 if (d40c->runtime_addr)
1950 dst_dev_addr = d40c->runtime_addr;
1951 else
1952 dst_dev_addr = d40c->base->plat_data->dev_tx[d40c->dma_cfg.dst_dev_type];
1949 src_dev_addr = 0; 1953 src_dev_addr = 0;
1950 } else 1954 } else
1951 return -EINVAL; 1955 return -EINVAL;
@@ -1983,34 +1987,38 @@ static struct dma_async_tx_descriptor *d40_prep_slave_sg(struct dma_chan *chan,
1983 struct scatterlist *sgl, 1987 struct scatterlist *sgl,
1984 unsigned int sg_len, 1988 unsigned int sg_len,
1985 enum dma_data_direction direction, 1989 enum dma_data_direction direction,
1986 unsigned long flags) 1990 unsigned long dma_flags)
1987{ 1991{
1988 struct d40_desc *d40d; 1992 struct d40_desc *d40d;
1989 struct d40_chan *d40c = container_of(chan, struct d40_chan, 1993 struct d40_chan *d40c = container_of(chan, struct d40_chan,
1990 chan); 1994 chan);
1991 unsigned long flg; 1995 unsigned long flags;
1992 int err; 1996 int err;
1993 1997
1998 if (d40c->phy_chan == NULL) {
1999 dev_err(&d40c->chan.dev->device,
2000 "[%s] Cannot prepare unallocated channel\n", __func__);
2001 return ERR_PTR(-EINVAL);
2002 }
2003
1994 if (d40c->dma_cfg.pre_transfer) 2004 if (d40c->dma_cfg.pre_transfer)
1995 d40c->dma_cfg.pre_transfer(chan, 2005 d40c->dma_cfg.pre_transfer(chan,
1996 d40c->dma_cfg.pre_transfer_data, 2006 d40c->dma_cfg.pre_transfer_data,
1997 sg_dma_len(sgl)); 2007 sg_dma_len(sgl));
1998 2008
1999 spin_lock_irqsave(&d40c->lock, flg); 2009 spin_lock_irqsave(&d40c->lock, flags);
2000 d40d = d40_desc_get(d40c); 2010 d40d = d40_desc_get(d40c);
2001 spin_unlock_irqrestore(&d40c->lock, flg); 2011 spin_unlock_irqrestore(&d40c->lock, flags);
2002 2012
2003 if (d40d == NULL) 2013 if (d40d == NULL)
2004 return NULL; 2014 return NULL;
2005 2015
2006 memset(d40d, 0, sizeof(struct d40_desc));
2007
2008 if (d40c->log_num != D40_PHY_CHAN) 2016 if (d40c->log_num != D40_PHY_CHAN)
2009 err = d40_prep_slave_sg_log(d40d, d40c, sgl, sg_len, 2017 err = d40_prep_slave_sg_log(d40d, d40c, sgl, sg_len,
2010 direction, flags); 2018 direction, dma_flags);
2011 else 2019 else
2012 err = d40_prep_slave_sg_phy(d40d, d40c, sgl, sg_len, 2020 err = d40_prep_slave_sg_phy(d40d, d40c, sgl, sg_len,
2013 direction, flags); 2021 direction, dma_flags);
2014 if (err) { 2022 if (err) {
2015 dev_err(&d40c->chan.dev->device, 2023 dev_err(&d40c->chan.dev->device,
2016 "[%s] Failed to prepare %s slave sg job: %d\n", 2024 "[%s] Failed to prepare %s slave sg job: %d\n",
@@ -2019,7 +2027,7 @@ static struct dma_async_tx_descriptor *d40_prep_slave_sg(struct dma_chan *chan,
2019 return NULL; 2027 return NULL;
2020 } 2028 }
2021 2029
2022 d40d->txd.flags = flags; 2030 d40d->txd.flags = dma_flags;
2023 2031
2024 dma_async_tx_descriptor_init(&d40d->txd, chan); 2032 dma_async_tx_descriptor_init(&d40d->txd, chan);
2025 2033
@@ -2037,6 +2045,13 @@ static enum dma_status d40_tx_status(struct dma_chan *chan,
2037 dma_cookie_t last_complete; 2045 dma_cookie_t last_complete;
2038 int ret; 2046 int ret;
2039 2047
2048 if (d40c->phy_chan == NULL) {
2049 dev_err(&d40c->chan.dev->device,
2050 "[%s] Cannot read status of unallocated channel\n",
2051 __func__);
2052 return -EINVAL;
2053 }
2054
2040 last_complete = d40c->completed; 2055 last_complete = d40c->completed;
2041 last_used = chan->cookie; 2056 last_used = chan->cookie;
2042 2057
@@ -2056,6 +2071,12 @@ static void d40_issue_pending(struct dma_chan *chan)
2056 struct d40_chan *d40c = container_of(chan, struct d40_chan, chan); 2071 struct d40_chan *d40c = container_of(chan, struct d40_chan, chan);
2057 unsigned long flags; 2072 unsigned long flags;
2058 2073
2074 if (d40c->phy_chan == NULL) {
2075 dev_err(&d40c->chan.dev->device,
2076 "[%s] Channel is not allocated!\n", __func__);
2077 return;
2078 }
2079
2059 spin_lock_irqsave(&d40c->lock, flags); 2080 spin_lock_irqsave(&d40c->lock, flags);
2060 2081
2061 /* Busy means that pending jobs are already being processed */ 2082 /* Busy means that pending jobs are already being processed */
@@ -2065,12 +2086,129 @@ static void d40_issue_pending(struct dma_chan *chan)
2065 spin_unlock_irqrestore(&d40c->lock, flags); 2086 spin_unlock_irqrestore(&d40c->lock, flags);
2066} 2087}
2067 2088
2089/* Runtime reconfiguration extension */
2090static void d40_set_runtime_config(struct dma_chan *chan,
2091 struct dma_slave_config *config)
2092{
2093 struct d40_chan *d40c = container_of(chan, struct d40_chan, chan);
2094 struct stedma40_chan_cfg *cfg = &d40c->dma_cfg;
2095 enum dma_slave_buswidth config_addr_width;
2096 dma_addr_t config_addr;
2097 u32 config_maxburst;
2098 enum stedma40_periph_data_width addr_width;
2099 int psize;
2100
2101 if (config->direction == DMA_FROM_DEVICE) {
2102 dma_addr_t dev_addr_rx =
2103 d40c->base->plat_data->dev_rx[cfg->src_dev_type];
2104
2105 config_addr = config->src_addr;
2106 if (dev_addr_rx)
2107 dev_dbg(d40c->base->dev,
2108 "channel has a pre-wired RX address %08x "
2109 "overriding with %08x\n",
2110 dev_addr_rx, config_addr);
2111 if (cfg->dir != STEDMA40_PERIPH_TO_MEM)
2112 dev_dbg(d40c->base->dev,
2113 "channel was not configured for peripheral "
2114 "to memory transfer (%d) overriding\n",
2115 cfg->dir);
2116 cfg->dir = STEDMA40_PERIPH_TO_MEM;
2117
2118 config_addr_width = config->src_addr_width;
2119 config_maxburst = config->src_maxburst;
2120
2121 } else if (config->direction == DMA_TO_DEVICE) {
2122 dma_addr_t dev_addr_tx =
2123 d40c->base->plat_data->dev_tx[cfg->dst_dev_type];
2124
2125 config_addr = config->dst_addr;
2126 if (dev_addr_tx)
2127 dev_dbg(d40c->base->dev,
2128 "channel has a pre-wired TX address %08x "
2129 "overriding with %08x\n",
2130 dev_addr_tx, config_addr);
2131 if (cfg->dir != STEDMA40_MEM_TO_PERIPH)
2132 dev_dbg(d40c->base->dev,
2133 "channel was not configured for memory "
2134 "to peripheral transfer (%d) overriding\n",
2135 cfg->dir);
2136 cfg->dir = STEDMA40_MEM_TO_PERIPH;
2137
2138 config_addr_width = config->dst_addr_width;
2139 config_maxburst = config->dst_maxburst;
2140
2141 } else {
2142 dev_err(d40c->base->dev,
2143 "unrecognized channel direction %d\n",
2144 config->direction);
2145 return;
2146 }
2147
2148 switch (config_addr_width) {
2149 case DMA_SLAVE_BUSWIDTH_1_BYTE:
2150 addr_width = STEDMA40_BYTE_WIDTH;
2151 break;
2152 case DMA_SLAVE_BUSWIDTH_2_BYTES:
2153 addr_width = STEDMA40_HALFWORD_WIDTH;
2154 break;
2155 case DMA_SLAVE_BUSWIDTH_4_BYTES:
2156 addr_width = STEDMA40_WORD_WIDTH;
2157 break;
2158 case DMA_SLAVE_BUSWIDTH_8_BYTES:
2159 addr_width = STEDMA40_DOUBLEWORD_WIDTH;
2160 break;
2161 default:
2162 dev_err(d40c->base->dev,
2163 "illegal peripheral address width "
2164 "requested (%d)\n",
2165 config->src_addr_width);
2166 return;
2167 }
2168
2169 if (config_maxburst >= 16)
2170 psize = STEDMA40_PSIZE_LOG_16;
2171 else if (config_maxburst >= 8)
2172 psize = STEDMA40_PSIZE_LOG_8;
2173 else if (config_maxburst >= 4)
2174 psize = STEDMA40_PSIZE_LOG_4;
2175 else
2176 psize = STEDMA40_PSIZE_LOG_1;
2177
2178 /* Set up all the endpoint configs */
2179 cfg->src_info.data_width = addr_width;
2180 cfg->src_info.psize = psize;
2181 cfg->src_info.endianess = STEDMA40_LITTLE_ENDIAN;
2182 cfg->src_info.flow_ctrl = STEDMA40_NO_FLOW_CTRL;
2183 cfg->dst_info.data_width = addr_width;
2184 cfg->dst_info.psize = psize;
2185 cfg->dst_info.endianess = STEDMA40_LITTLE_ENDIAN;
2186 cfg->dst_info.flow_ctrl = STEDMA40_NO_FLOW_CTRL;
2187
2188 /* These settings will take precedence later */
2189 d40c->runtime_addr = config_addr;
2190 d40c->runtime_direction = config->direction;
2191 dev_dbg(d40c->base->dev,
2192 "configured channel %s for %s, data width %d, "
2193 "maxburst %d bytes, LE, no flow control\n",
2194 dma_chan_name(chan),
2195 (config->direction == DMA_FROM_DEVICE) ? "RX" : "TX",
2196 config_addr_width,
2197 config_maxburst);
2198}
2199
2068static int d40_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd, 2200static int d40_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
2069 unsigned long arg) 2201 unsigned long arg)
2070{ 2202{
2071 unsigned long flags; 2203 unsigned long flags;
2072 struct d40_chan *d40c = container_of(chan, struct d40_chan, chan); 2204 struct d40_chan *d40c = container_of(chan, struct d40_chan, chan);
2073 2205
2206 if (d40c->phy_chan == NULL) {
2207 dev_err(&d40c->chan.dev->device,
2208 "[%s] Channel is not allocated!\n", __func__);
2209 return -EINVAL;
2210 }
2211
2074 switch (cmd) { 2212 switch (cmd) {
2075 case DMA_TERMINATE_ALL: 2213 case DMA_TERMINATE_ALL:
2076 spin_lock_irqsave(&d40c->lock, flags); 2214 spin_lock_irqsave(&d40c->lock, flags);
@@ -2081,6 +2219,12 @@ static int d40_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
2081 return d40_pause(chan); 2219 return d40_pause(chan);
2082 case DMA_RESUME: 2220 case DMA_RESUME:
2083 return d40_resume(chan); 2221 return d40_resume(chan);
2222 case DMA_SLAVE_CONFIG:
2223 d40_set_runtime_config(chan,
2224 (struct dma_slave_config *) arg);
2225 return 0;
2226 default:
2227 break;
2084 } 2228 }
2085 2229
2086 /* Other commands are unimplemented */ 2230 /* Other commands are unimplemented */
@@ -2111,13 +2255,10 @@ static void __init d40_chan_init(struct d40_base *base, struct dma_device *dma,
2111 2255
2112 d40c->log_num = D40_PHY_CHAN; 2256 d40c->log_num = D40_PHY_CHAN;
2113 2257
2114 INIT_LIST_HEAD(&d40c->free);
2115 INIT_LIST_HEAD(&d40c->active); 2258 INIT_LIST_HEAD(&d40c->active);
2116 INIT_LIST_HEAD(&d40c->queue); 2259 INIT_LIST_HEAD(&d40c->queue);
2117 INIT_LIST_HEAD(&d40c->client); 2260 INIT_LIST_HEAD(&d40c->client);
2118 2261
2119 d40c->free_len = 0;
2120
2121 tasklet_init(&d40c->tasklet, dma_tasklet, 2262 tasklet_init(&d40c->tasklet, dma_tasklet,
2122 (unsigned long) d40c); 2263 (unsigned long) d40c);
2123 2264
@@ -2243,6 +2384,14 @@ static int __init d40_phy_res_init(struct d40_base *base)
2243 } 2384 }
2244 spin_lock_init(&base->phy_res[i].lock); 2385 spin_lock_init(&base->phy_res[i].lock);
2245 } 2386 }
2387
2388 /* Mark disabled channels as occupied */
2389 for (i = 0; base->plat_data->disabled_channels[i] != -1; i++) {
2390 base->phy_res[i].allocated_src = D40_ALLOC_PHY;
2391 base->phy_res[i].allocated_dst = D40_ALLOC_PHY;
2392 num_phy_chans_avail--;
2393 }
2394
2246 dev_info(base->dev, "%d of %d physical DMA channels available\n", 2395 dev_info(base->dev, "%d of %d physical DMA channels available\n",
2247 num_phy_chans_avail, base->num_phy_chans); 2396 num_phy_chans_avail, base->num_phy_chans);
2248 2397
@@ -2291,6 +2440,7 @@ static struct d40_base * __init d40_hw_detect_init(struct platform_device *pdev)
2291 int num_log_chans = 0; 2440 int num_log_chans = 0;
2292 int num_phy_chans; 2441 int num_phy_chans;
2293 int i; 2442 int i;
2443 u32 val;
2294 2444
2295 clk = clk_get(&pdev->dev, NULL); 2445 clk = clk_get(&pdev->dev, NULL);
2296 2446
@@ -2329,12 +2479,13 @@ static struct d40_base * __init d40_hw_detect_init(struct platform_device *pdev)
2329 } 2479 }
2330 } 2480 }
2331 2481
2332 i = readl(virtbase + D40_DREG_PERIPHID2); 2482 /* Get silicon revision */
2483 val = readl(virtbase + D40_DREG_PERIPHID2);
2333 2484
2334 if ((i & 0xf) != D40_PERIPHID2_DESIGNER) { 2485 if ((val & 0xf) != D40_PERIPHID2_DESIGNER) {
2335 dev_err(&pdev->dev, 2486 dev_err(&pdev->dev,
2336 "[%s] Unknown designer! Got %x wanted %x\n", 2487 "[%s] Unknown designer! Got %x wanted %x\n",
2337 __func__, i & 0xf, D40_PERIPHID2_DESIGNER); 2488 __func__, val & 0xf, D40_PERIPHID2_DESIGNER);
2338 goto failure; 2489 goto failure;
2339 } 2490 }
2340 2491
@@ -2342,7 +2493,7 @@ static struct d40_base * __init d40_hw_detect_init(struct platform_device *pdev)
2342 num_phy_chans = 4 * (readl(virtbase + D40_DREG_ICFG) & 0x7) + 4; 2493 num_phy_chans = 4 * (readl(virtbase + D40_DREG_ICFG) & 0x7) + 4;
2343 2494
2344 dev_info(&pdev->dev, "hardware revision: %d @ 0x%x\n", 2495 dev_info(&pdev->dev, "hardware revision: %d @ 0x%x\n",
2345 (i >> 4) & 0xf, res->start); 2496 (val >> 4) & 0xf, res->start);
2346 2497
2347 plat_data = pdev->dev.platform_data; 2498 plat_data = pdev->dev.platform_data;
2348 2499
@@ -2364,6 +2515,7 @@ static struct d40_base * __init d40_hw_detect_init(struct platform_device *pdev)
2364 goto failure; 2515 goto failure;
2365 } 2516 }
2366 2517
2518 base->rev = (val >> 4) & 0xf;
2367 base->clk = clk; 2519 base->clk = clk;
2368 base->num_phy_chans = num_phy_chans; 2520 base->num_phy_chans = num_phy_chans;
2369 base->num_log_chans = num_log_chans; 2521 base->num_log_chans = num_log_chans;
@@ -2402,6 +2554,12 @@ static struct d40_base * __init d40_hw_detect_init(struct platform_device *pdev)
2402 if (!base->lcla_pool.alloc_map) 2554 if (!base->lcla_pool.alloc_map)
2403 goto failure; 2555 goto failure;
2404 2556
2557 base->desc_slab = kmem_cache_create(D40_NAME, sizeof(struct d40_desc),
2558 0, SLAB_HWCACHE_ALIGN,
2559 NULL);
2560 if (base->desc_slab == NULL)
2561 goto failure;
2562
2405 return base; 2563 return base;
2406 2564
2407failure: 2565failure:
@@ -2495,6 +2653,78 @@ static void __init d40_hw_init(struct d40_base *base)
2495 2653
2496} 2654}
2497 2655
2656static int __init d40_lcla_allocate(struct d40_base *base)
2657{
2658 unsigned long *page_list;
2659 int i, j;
2660 int ret = 0;
2661
2662 /*
2663 * This is somewhat ugly. We need 8192 bytes that are 18 bit aligned,
2664 * To full fill this hardware requirement without wasting 256 kb
2665 * we allocate pages until we get an aligned one.
2666 */
2667 page_list = kmalloc(sizeof(unsigned long) * MAX_LCLA_ALLOC_ATTEMPTS,
2668 GFP_KERNEL);
2669
2670 if (!page_list) {
2671 ret = -ENOMEM;
2672 goto failure;
2673 }
2674
2675 /* Calculating how many pages that are required */
2676 base->lcla_pool.pages = SZ_1K * base->num_phy_chans / PAGE_SIZE;
2677
2678 for (i = 0; i < MAX_LCLA_ALLOC_ATTEMPTS; i++) {
2679 page_list[i] = __get_free_pages(GFP_KERNEL,
2680 base->lcla_pool.pages);
2681 if (!page_list[i]) {
2682
2683 dev_err(base->dev,
2684 "[%s] Failed to allocate %d pages.\n",
2685 __func__, base->lcla_pool.pages);
2686
2687 for (j = 0; j < i; j++)
2688 free_pages(page_list[j], base->lcla_pool.pages);
2689 goto failure;
2690 }
2691
2692 if ((virt_to_phys((void *)page_list[i]) &
2693 (LCLA_ALIGNMENT - 1)) == 0)
2694 break;
2695 }
2696
2697 for (j = 0; j < i; j++)
2698 free_pages(page_list[j], base->lcla_pool.pages);
2699
2700 if (i < MAX_LCLA_ALLOC_ATTEMPTS) {
2701 base->lcla_pool.base = (void *)page_list[i];
2702 } else {
2703 /* After many attempts, no succees with finding the correct
2704 * alignment try with allocating a big buffer */
2705 dev_warn(base->dev,
2706 "[%s] Failed to get %d pages @ 18 bit align.\n",
2707 __func__, base->lcla_pool.pages);
2708 base->lcla_pool.base_unaligned = kmalloc(SZ_1K *
2709 base->num_phy_chans +
2710 LCLA_ALIGNMENT,
2711 GFP_KERNEL);
2712 if (!base->lcla_pool.base_unaligned) {
2713 ret = -ENOMEM;
2714 goto failure;
2715 }
2716
2717 base->lcla_pool.base = PTR_ALIGN(base->lcla_pool.base_unaligned,
2718 LCLA_ALIGNMENT);
2719 }
2720
2721 writel(virt_to_phys(base->lcla_pool.base),
2722 base->virtbase + D40_DREG_LCLA);
2723failure:
2724 kfree(page_list);
2725 return ret;
2726}
2727
2498static int __init d40_probe(struct platform_device *pdev) 2728static int __init d40_probe(struct platform_device *pdev)
2499{ 2729{
2500 int err; 2730 int err;
@@ -2554,41 +2784,11 @@ static int __init d40_probe(struct platform_device *pdev)
2554 __func__); 2784 __func__);
2555 goto failure; 2785 goto failure;
2556 } 2786 }
2557 /* Get IO for logical channel link address */
2558 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "lcla");
2559 if (!res) {
2560 ret = -ENOENT;
2561 dev_err(&pdev->dev,
2562 "[%s] No \"lcla\" resource defined\n",
2563 __func__);
2564 goto failure;
2565 }
2566 2787
2567 base->lcla_pool.base_size = resource_size(res); 2788 ret = d40_lcla_allocate(base);
2568 base->lcla_pool.phy = res->start; 2789 if (ret) {
2569 2790 dev_err(&pdev->dev, "[%s] Failed to allocate LCLA area\n",
2570 if (request_mem_region(res->start, resource_size(res), 2791 __func__);
2571 D40_NAME " I/O lcla") == NULL) {
2572 ret = -EBUSY;
2573 dev_err(&pdev->dev,
2574 "[%s] Failed to request LCLA region 0x%x-0x%x\n",
2575 __func__, res->start, res->end);
2576 goto failure;
2577 }
2578 val = readl(base->virtbase + D40_DREG_LCLA);
2579 if (res->start != val && val != 0) {
2580 dev_warn(&pdev->dev,
2581 "[%s] Mismatch LCLA dma 0x%x, def 0x%x\n",
2582 __func__, val, res->start);
2583 } else
2584 writel(res->start, base->virtbase + D40_DREG_LCLA);
2585
2586 base->lcla_pool.base = ioremap(res->start, resource_size(res));
2587 if (!base->lcla_pool.base) {
2588 ret = -ENOMEM;
2589 dev_err(&pdev->dev,
2590 "[%s] Failed to ioremap LCLA 0x%x-0x%x\n",
2591 __func__, res->start, res->end);
2592 goto failure; 2792 goto failure;
2593 } 2793 }
2594 2794
@@ -2616,11 +2816,15 @@ static int __init d40_probe(struct platform_device *pdev)
2616 2816
2617failure: 2817failure:
2618 if (base) { 2818 if (base) {
2819 if (base->desc_slab)
2820 kmem_cache_destroy(base->desc_slab);
2619 if (base->virtbase) 2821 if (base->virtbase)
2620 iounmap(base->virtbase); 2822 iounmap(base->virtbase);
2621 if (base->lcla_pool.phy) 2823 if (!base->lcla_pool.base_unaligned && base->lcla_pool.base)
2622 release_mem_region(base->lcla_pool.phy, 2824 free_pages((unsigned long)base->lcla_pool.base,
2623 base->lcla_pool.base_size); 2825 base->lcla_pool.pages);
2826 if (base->lcla_pool.base_unaligned)
2827 kfree(base->lcla_pool.base_unaligned);
2624 if (base->phy_lcpa) 2828 if (base->phy_lcpa)
2625 release_mem_region(base->phy_lcpa, 2829 release_mem_region(base->phy_lcpa,
2626 base->lcpa_size); 2830 base->lcpa_size);
diff --git a/drivers/dma/ste_dma40_ll.c b/drivers/dma/ste_dma40_ll.c
index 561fdd8a80c1..d937f76d6e2e 100644
--- a/drivers/dma/ste_dma40_ll.c
+++ b/drivers/dma/ste_dma40_ll.c
@@ -315,11 +315,8 @@ int d40_log_sg_to_dev(struct d40_lcla_elem *lcla,
315 int total_size = 0; 315 int total_size = 0;
316 struct scatterlist *current_sg = sg; 316 struct scatterlist *current_sg = sg;
317 int i; 317 int i;
318 u32 next_lli_off_dst; 318 u32 next_lli_off_dst = 0;
319 u32 next_lli_off_src; 319 u32 next_lli_off_src = 0;
320
321 next_lli_off_src = 0;
322 next_lli_off_dst = 0;
323 320
324 for_each_sg(sg, current_sg, sg_len, i) { 321 for_each_sg(sg, current_sg, sg_len, i) {
325 total_size += sg_dma_len(current_sg); 322 total_size += sg_dma_len(current_sg);
@@ -351,7 +348,7 @@ int d40_log_sg_to_dev(struct d40_lcla_elem *lcla,
351 sg_dma_len(current_sg), 348 sg_dma_len(current_sg),
352 next_lli_off_src, 349 next_lli_off_src,
353 lcsp->lcsp1, src_data_width, 350 lcsp->lcsp1, src_data_width,
354 term_int && !next_lli_off_src, 351 false,
355 true); 352 true);
356 d40_log_fill_lli(&lli->dst[i], 353 d40_log_fill_lli(&lli->dst[i],
357 dev_addr, 354 dev_addr,
@@ -375,7 +372,7 @@ int d40_log_sg_to_dev(struct d40_lcla_elem *lcla,
375 sg_dma_len(current_sg), 372 sg_dma_len(current_sg),
376 next_lli_off_src, 373 next_lli_off_src,
377 lcsp->lcsp1, src_data_width, 374 lcsp->lcsp1, src_data_width,
378 term_int && !next_lli_off_src, 375 false,
379 false); 376 false);
380 } 377 }
381 } 378 }
@@ -423,32 +420,35 @@ int d40_log_sg_to_lli(int lcla_id,
423 return total_size; 420 return total_size;
424} 421}
425 422
426void d40_log_lli_write(struct d40_log_lli_full *lcpa, 423int d40_log_lli_write(struct d40_log_lli_full *lcpa,
427 struct d40_log_lli *lcla_src, 424 struct d40_log_lli *lcla_src,
428 struct d40_log_lli *lcla_dst, 425 struct d40_log_lli *lcla_dst,
429 struct d40_log_lli *lli_dst, 426 struct d40_log_lli *lli_dst,
430 struct d40_log_lli *lli_src, 427 struct d40_log_lli *lli_src,
431 int llis_per_log) 428 int llis_per_log)
432{ 429{
433 u32 slos = 0; 430 u32 slos;
434 u32 dlos = 0; 431 u32 dlos;
435 int i; 432 int i;
436 433
437 lcpa->lcsp0 = lli_src->lcsp02; 434 writel(lli_src->lcsp02, &lcpa->lcsp0);
438 lcpa->lcsp1 = lli_src->lcsp13; 435 writel(lli_src->lcsp13, &lcpa->lcsp1);
439 lcpa->lcsp2 = lli_dst->lcsp02; 436 writel(lli_dst->lcsp02, &lcpa->lcsp2);
440 lcpa->lcsp3 = lli_dst->lcsp13; 437 writel(lli_dst->lcsp13, &lcpa->lcsp3);
441 438
442 slos = lli_src->lcsp13 & D40_MEM_LCSP1_SLOS_MASK; 439 slos = lli_src->lcsp13 & D40_MEM_LCSP1_SLOS_MASK;
443 dlos = lli_dst->lcsp13 & D40_MEM_LCSP3_DLOS_MASK; 440 dlos = lli_dst->lcsp13 & D40_MEM_LCSP3_DLOS_MASK;
444 441
445 for (i = 0; (i < llis_per_log) && slos && dlos; i++) { 442 for (i = 0; (i < llis_per_log) && slos && dlos; i++) {
446 writel(lli_src[i+1].lcsp02, &lcla_src[i].lcsp02); 443 writel(lli_src[i + 1].lcsp02, &lcla_src[i].lcsp02);
447 writel(lli_src[i+1].lcsp13, &lcla_src[i].lcsp13); 444 writel(lli_src[i + 1].lcsp13, &lcla_src[i].lcsp13);
448 writel(lli_dst[i+1].lcsp02, &lcla_dst[i].lcsp02); 445 writel(lli_dst[i + 1].lcsp02, &lcla_dst[i].lcsp02);
449 writel(lli_dst[i+1].lcsp13, &lcla_dst[i].lcsp13); 446 writel(lli_dst[i + 1].lcsp13, &lcla_dst[i].lcsp13);
450 447
451 slos = lli_src[i+1].lcsp13 & D40_MEM_LCSP1_SLOS_MASK; 448 slos = lli_src[i + 1].lcsp13 & D40_MEM_LCSP1_SLOS_MASK;
452 dlos = lli_dst[i+1].lcsp13 & D40_MEM_LCSP3_DLOS_MASK; 449 dlos = lli_dst[i + 1].lcsp13 & D40_MEM_LCSP3_DLOS_MASK;
453 } 450 }
451
452 return i;
453
454} 454}
diff --git a/drivers/dma/ste_dma40_ll.h b/drivers/dma/ste_dma40_ll.h
index 2029280cb332..9c0fa2f5fe57 100644
--- a/drivers/dma/ste_dma40_ll.h
+++ b/drivers/dma/ste_dma40_ll.h
@@ -13,6 +13,9 @@
13#define D40_DREG_PCDELTA (8 * 4) 13#define D40_DREG_PCDELTA (8 * 4)
14#define D40_LLI_ALIGN 16 /* LLI alignment must be 16 bytes. */ 14#define D40_LLI_ALIGN 16 /* LLI alignment must be 16 bytes. */
15 15
16#define D40_LCPA_CHAN_SIZE 32
17#define D40_LCPA_CHAN_DST_DELTA 16
18
16#define D40_TYPE_TO_GROUP(type) (type / 16) 19#define D40_TYPE_TO_GROUP(type) (type / 16)
17#define D40_TYPE_TO_EVENT(type) (type % 16) 20#define D40_TYPE_TO_EVENT(type) (type % 16)
18 21
@@ -336,12 +339,12 @@ int d40_log_sg_to_dev(struct d40_lcla_elem *lcla,
336 bool term_int, dma_addr_t dev_addr, int max_len, 339 bool term_int, dma_addr_t dev_addr, int max_len,
337 int llis_per_log); 340 int llis_per_log);
338 341
339void d40_log_lli_write(struct d40_log_lli_full *lcpa, 342int d40_log_lli_write(struct d40_log_lli_full *lcpa,
340 struct d40_log_lli *lcla_src, 343 struct d40_log_lli *lcla_src,
341 struct d40_log_lli *lcla_dst, 344 struct d40_log_lli *lcla_dst,
342 struct d40_log_lli *lli_dst, 345 struct d40_log_lli *lli_dst,
343 struct d40_log_lli *lli_src, 346 struct d40_log_lli *lli_src,
344 int llis_per_log); 347 int llis_per_log);
345 348
346int d40_log_sg_to_lli(int lcla_id, 349int d40_log_sg_to_lli(int lcla_id,
347 struct scatterlist *sg, 350 struct scatterlist *sg,
diff --git a/drivers/dma/timb_dma.c b/drivers/dma/timb_dma.c
index a1bf77c1993f..2ec1ed56f204 100644
--- a/drivers/dma/timb_dma.c
+++ b/drivers/dma/timb_dma.c
@@ -200,8 +200,8 @@ static int td_fill_desc(struct timb_dma_chan *td_chan, u8 *dma_desc,
200 return -EINVAL; 200 return -EINVAL;
201 } 201 }
202 202
203 dev_dbg(chan2dev(&td_chan->chan), "desc: %p, addr: %p\n", 203 dev_dbg(chan2dev(&td_chan->chan), "desc: %p, addr: 0x%llx\n",
204 dma_desc, (void *)sg_dma_address(sg)); 204 dma_desc, (unsigned long long)sg_dma_address(sg));
205 205
206 dma_desc[7] = (sg_dma_address(sg) >> 24) & 0xff; 206 dma_desc[7] = (sg_dma_address(sg) >> 24) & 0xff;
207 dma_desc[6] = (sg_dma_address(sg) >> 16) & 0xff; 207 dma_desc[6] = (sg_dma_address(sg) >> 16) & 0xff;
@@ -382,7 +382,7 @@ static struct timb_dma_desc *td_alloc_init_desc(struct timb_dma_chan *td_chan)
382 td_desc = kzalloc(sizeof(struct timb_dma_desc), GFP_KERNEL); 382 td_desc = kzalloc(sizeof(struct timb_dma_desc), GFP_KERNEL);
383 if (!td_desc) { 383 if (!td_desc) {
384 dev_err(chan2dev(chan), "Failed to alloc descriptor\n"); 384 dev_err(chan2dev(chan), "Failed to alloc descriptor\n");
385 goto err; 385 goto out;
386 } 386 }
387 387
388 td_desc->desc_list_len = td_chan->desc_elems * TIMB_DMA_DESC_SIZE; 388 td_desc->desc_list_len = td_chan->desc_elems * TIMB_DMA_DESC_SIZE;
@@ -410,7 +410,7 @@ static struct timb_dma_desc *td_alloc_init_desc(struct timb_dma_chan *td_chan)
410err: 410err:
411 kfree(td_desc->desc_list); 411 kfree(td_desc->desc_list);
412 kfree(td_desc); 412 kfree(td_desc);
413 413out:
414 return NULL; 414 return NULL;
415 415
416} 416}
diff --git a/drivers/edac/i5000_edac.c b/drivers/edac/i5000_edac.c
index 996c1bdb5a34..a5cefab8d65d 100644
--- a/drivers/edac/i5000_edac.c
+++ b/drivers/edac/i5000_edac.c
@@ -1482,7 +1482,7 @@ static int __devinit i5000_init_one(struct pci_dev *pdev,
1482 1482
1483 /* wake up device */ 1483 /* wake up device */
1484 rc = pci_enable_device(pdev); 1484 rc = pci_enable_device(pdev);
1485 if (rc == -EIO) 1485 if (rc)
1486 return rc; 1486 return rc;
1487 1487
1488 /* now probe and enable the device */ 1488 /* now probe and enable the device */
diff --git a/drivers/edac/i5400_edac.c b/drivers/edac/i5400_edac.c
index 010c1d6526f5..38a9be9e1c7c 100644
--- a/drivers/edac/i5400_edac.c
+++ b/drivers/edac/i5400_edac.c
@@ -1348,7 +1348,7 @@ static int __devinit i5400_init_one(struct pci_dev *pdev,
1348 1348
1349 /* wake up device */ 1349 /* wake up device */
1350 rc = pci_enable_device(pdev); 1350 rc = pci_enable_device(pdev);
1351 if (rc == -EIO) 1351 if (rc)
1352 return rc; 1352 return rc;
1353 1353
1354 /* now probe and enable the device */ 1354 /* now probe and enable the device */
diff --git a/drivers/edac/mpc85xx_edac.c b/drivers/edac/mpc85xx_edac.c
index 1052340e6802..b123bb308a4a 100644
--- a/drivers/edac/mpc85xx_edac.c
+++ b/drivers/edac/mpc85xx_edac.c
@@ -43,7 +43,7 @@ static u32 orig_pci_err_en;
43#endif 43#endif
44 44
45static u32 orig_l2_err_disable; 45static u32 orig_l2_err_disable;
46#ifdef CONFIG_MPC85xx 46#ifdef CONFIG_FSL_SOC_BOOKE
47static u32 orig_hid1[2]; 47static u32 orig_hid1[2];
48#endif 48#endif
49 49
@@ -200,7 +200,7 @@ static irqreturn_t mpc85xx_pci_isr(int irq, void *dev_id)
200 return IRQ_HANDLED; 200 return IRQ_HANDLED;
201} 201}
202 202
203static int __devinit mpc85xx_pci_err_probe(struct of_device *op, 203static int __devinit mpc85xx_pci_err_probe(struct platform_device *op,
204 const struct of_device_id *match) 204 const struct of_device_id *match)
205{ 205{
206 struct edac_pci_ctl_info *pci; 206 struct edac_pci_ctl_info *pci;
@@ -305,7 +305,7 @@ err:
305 return res; 305 return res;
306} 306}
307 307
308static int mpc85xx_pci_err_remove(struct of_device *op) 308static int mpc85xx_pci_err_remove(struct platform_device *op)
309{ 309{
310 struct edac_pci_ctl_info *pci = dev_get_drvdata(&op->dev); 310 struct edac_pci_ctl_info *pci = dev_get_drvdata(&op->dev);
311 struct mpc85xx_pci_pdata *pdata = pci->pvt_info; 311 struct mpc85xx_pci_pdata *pdata = pci->pvt_info;
@@ -503,7 +503,7 @@ static irqreturn_t mpc85xx_l2_isr(int irq, void *dev_id)
503 return IRQ_HANDLED; 503 return IRQ_HANDLED;
504} 504}
505 505
506static int __devinit mpc85xx_l2_err_probe(struct of_device *op, 506static int __devinit mpc85xx_l2_err_probe(struct platform_device *op,
507 const struct of_device_id *match) 507 const struct of_device_id *match)
508{ 508{
509 struct edac_device_ctl_info *edac_dev; 509 struct edac_device_ctl_info *edac_dev;
@@ -613,7 +613,7 @@ err:
613 return res; 613 return res;
614} 614}
615 615
616static int mpc85xx_l2_err_remove(struct of_device *op) 616static int mpc85xx_l2_err_remove(struct platform_device *op)
617{ 617{
618 struct edac_device_ctl_info *edac_dev = dev_get_drvdata(&op->dev); 618 struct edac_device_ctl_info *edac_dev = dev_get_drvdata(&op->dev);
619 struct mpc85xx_l2_pdata *pdata = edac_dev->pvt_info; 619 struct mpc85xx_l2_pdata *pdata = edac_dev->pvt_info;
@@ -647,7 +647,10 @@ static struct of_device_id mpc85xx_l2_err_of_match[] = {
647 { .compatible = "fsl,mpc8555-l2-cache-controller", }, 647 { .compatible = "fsl,mpc8555-l2-cache-controller", },
648 { .compatible = "fsl,mpc8560-l2-cache-controller", }, 648 { .compatible = "fsl,mpc8560-l2-cache-controller", },
649 { .compatible = "fsl,mpc8568-l2-cache-controller", }, 649 { .compatible = "fsl,mpc8568-l2-cache-controller", },
650 { .compatible = "fsl,mpc8569-l2-cache-controller", },
650 { .compatible = "fsl,mpc8572-l2-cache-controller", }, 651 { .compatible = "fsl,mpc8572-l2-cache-controller", },
652 { .compatible = "fsl,p1020-l2-cache-controller", },
653 { .compatible = "fsl,p1021-l2-cache-controller", },
651 { .compatible = "fsl,p2020-l2-cache-controller", }, 654 { .compatible = "fsl,p2020-l2-cache-controller", },
652 {}, 655 {},
653}; 656};
@@ -953,7 +956,7 @@ static void __devinit mpc85xx_init_csrows(struct mem_ctl_info *mci)
953 } 956 }
954} 957}
955 958
956static int __devinit mpc85xx_mc_err_probe(struct of_device *op, 959static int __devinit mpc85xx_mc_err_probe(struct platform_device *op,
957 const struct of_device_id *match) 960 const struct of_device_id *match)
958{ 961{
959 struct mem_ctl_info *mci; 962 struct mem_ctl_info *mci;
@@ -1085,7 +1088,7 @@ err:
1085 return res; 1088 return res;
1086} 1089}
1087 1090
1088static int mpc85xx_mc_err_remove(struct of_device *op) 1091static int mpc85xx_mc_err_remove(struct platform_device *op)
1089{ 1092{
1090 struct mem_ctl_info *mci = dev_get_drvdata(&op->dev); 1093 struct mem_ctl_info *mci = dev_get_drvdata(&op->dev);
1091 struct mpc85xx_mc_pdata *pdata = mci->pvt_info; 1094 struct mpc85xx_mc_pdata *pdata = mci->pvt_info;
@@ -1125,7 +1128,10 @@ static struct of_device_id mpc85xx_mc_err_of_match[] = {
1125 { .compatible = "fsl,mpc8569-memory-controller", }, 1128 { .compatible = "fsl,mpc8569-memory-controller", },
1126 { .compatible = "fsl,mpc8572-memory-controller", }, 1129 { .compatible = "fsl,mpc8572-memory-controller", },
1127 { .compatible = "fsl,mpc8349-memory-controller", }, 1130 { .compatible = "fsl,mpc8349-memory-controller", },
1131 { .compatible = "fsl,p1020-memory-controller", },
1132 { .compatible = "fsl,p1021-memory-controller", },
1128 { .compatible = "fsl,p2020-memory-controller", }, 1133 { .compatible = "fsl,p2020-memory-controller", },
1134 { .compatible = "fsl,p4080-memory-controller", },
1129 {}, 1135 {},
1130}; 1136};
1131MODULE_DEVICE_TABLE(of, mpc85xx_mc_err_of_match); 1137MODULE_DEVICE_TABLE(of, mpc85xx_mc_err_of_match);
@@ -1140,7 +1146,7 @@ static struct of_platform_driver mpc85xx_mc_err_driver = {
1140 }, 1146 },
1141}; 1147};
1142 1148
1143#ifdef CONFIG_MPC85xx 1149#ifdef CONFIG_FSL_SOC_BOOKE
1144static void __init mpc85xx_mc_clear_rfxe(void *data) 1150static void __init mpc85xx_mc_clear_rfxe(void *data)
1145{ 1151{
1146 orig_hid1[smp_processor_id()] = mfspr(SPRN_HID1); 1152 orig_hid1[smp_processor_id()] = mfspr(SPRN_HID1);
@@ -1179,7 +1185,7 @@ static int __init mpc85xx_mc_init(void)
1179 printk(KERN_WARNING EDAC_MOD_STR "PCI fails to register\n"); 1185 printk(KERN_WARNING EDAC_MOD_STR "PCI fails to register\n");
1180#endif 1186#endif
1181 1187
1182#ifdef CONFIG_MPC85xx 1188#ifdef CONFIG_FSL_SOC_BOOKE
1183 /* 1189 /*
1184 * need to clear HID1[RFXE] to disable machine check int 1190 * need to clear HID1[RFXE] to disable machine check int
1185 * so we can catch it 1191 * so we can catch it
@@ -1193,7 +1199,7 @@ static int __init mpc85xx_mc_init(void)
1193 1199
1194module_init(mpc85xx_mc_init); 1200module_init(mpc85xx_mc_init);
1195 1201
1196#ifdef CONFIG_MPC85xx 1202#ifdef CONFIG_FSL_SOC_BOOKE
1197static void __exit mpc85xx_mc_restore_hid1(void *data) 1203static void __exit mpc85xx_mc_restore_hid1(void *data)
1198{ 1204{
1199 mtspr(SPRN_HID1, orig_hid1[smp_processor_id()]); 1205 mtspr(SPRN_HID1, orig_hid1[smp_processor_id()]);
@@ -1202,7 +1208,7 @@ static void __exit mpc85xx_mc_restore_hid1(void *data)
1202 1208
1203static void __exit mpc85xx_mc_exit(void) 1209static void __exit mpc85xx_mc_exit(void)
1204{ 1210{
1205#ifdef CONFIG_MPC85xx 1211#ifdef CONFIG_FSL_SOC_BOOKE
1206 on_each_cpu(mpc85xx_mc_restore_hid1, NULL, 0); 1212 on_each_cpu(mpc85xx_mc_restore_hid1, NULL, 0);
1207#endif 1213#endif
1208#ifdef CONFIG_PCI 1214#ifdef CONFIG_PCI
diff --git a/drivers/edac/ppc4xx_edac.c b/drivers/edac/ppc4xx_edac.c
index e78839e89a06..070cea41b661 100644
--- a/drivers/edac/ppc4xx_edac.c
+++ b/drivers/edac/ppc4xx_edac.c
@@ -184,9 +184,9 @@ struct ppc4xx_ecc_status {
184 184
185/* Function Prototypes */ 185/* Function Prototypes */
186 186
187static int ppc4xx_edac_probe(struct of_device *device, 187static int ppc4xx_edac_probe(struct platform_device *device,
188 const struct of_device_id *device_id); 188 const struct of_device_id *device_id);
189static int ppc4xx_edac_remove(struct of_device *device); 189static int ppc4xx_edac_remove(struct platform_device *device);
190 190
191/* Global Variables */ 191/* Global Variables */
192 192
@@ -1014,7 +1014,7 @@ ppc4xx_edac_init_csrows(struct mem_ctl_info *mci, u32 mcopt1)
1014 */ 1014 */
1015static int __devinit 1015static int __devinit
1016ppc4xx_edac_mc_init(struct mem_ctl_info *mci, 1016ppc4xx_edac_mc_init(struct mem_ctl_info *mci,
1017 struct of_device *op, 1017 struct platform_device *op,
1018 const struct of_device_id *match, 1018 const struct of_device_id *match,
1019 const dcr_host_t *dcr_host, 1019 const dcr_host_t *dcr_host,
1020 u32 mcopt1) 1020 u32 mcopt1)
@@ -1108,7 +1108,7 @@ ppc4xx_edac_mc_init(struct mem_ctl_info *mci,
1108 * mapped and assigned. 1108 * mapped and assigned.
1109 */ 1109 */
1110static int __devinit 1110static int __devinit
1111ppc4xx_edac_register_irq(struct of_device *op, struct mem_ctl_info *mci) 1111ppc4xx_edac_register_irq(struct platform_device *op, struct mem_ctl_info *mci)
1112{ 1112{
1113 int status = 0; 1113 int status = 0;
1114 int ded_irq, sec_irq; 1114 int ded_irq, sec_irq;
@@ -1238,7 +1238,7 @@ ppc4xx_edac_map_dcrs(const struct device_node *np, dcr_host_t *dcr_host)
1238 * driver; otherwise, < 0 on error. 1238 * driver; otherwise, < 0 on error.
1239 */ 1239 */
1240static int __devinit 1240static int __devinit
1241ppc4xx_edac_probe(struct of_device *op, const struct of_device_id *match) 1241ppc4xx_edac_probe(struct platform_device *op, const struct of_device_id *match)
1242{ 1242{
1243 int status = 0; 1243 int status = 0;
1244 u32 mcopt1, memcheck; 1244 u32 mcopt1, memcheck;
@@ -1359,7 +1359,7 @@ ppc4xx_edac_probe(struct of_device *op, const struct of_device_id *match)
1359 * Unconditionally returns 0. 1359 * Unconditionally returns 0.
1360 */ 1360 */
1361static int 1361static int
1362ppc4xx_edac_remove(struct of_device *op) 1362ppc4xx_edac_remove(struct platform_device *op)
1363{ 1363{
1364 struct mem_ctl_info *mci = dev_get_drvdata(&op->dev); 1364 struct mem_ctl_info *mci = dev_get_drvdata(&op->dev);
1365 struct ppc4xx_edac_pdata *pdata = mci->pvt_info; 1365 struct ppc4xx_edac_pdata *pdata = mci->pvt_info;
diff --git a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig
index a6c670b8ce52..280c9b5ad9e3 100644
--- a/drivers/firmware/Kconfig
+++ b/drivers/firmware/Kconfig
@@ -122,18 +122,10 @@ config ISCSI_IBFT_FIND
122 is necessary for iSCSI Boot Firmware Table Attributes module to work 122 is necessary for iSCSI Boot Firmware Table Attributes module to work
123 properly. 123 properly.
124 124
125config ISCSI_BOOT_SYSFS
126 tristate "iSCSI Boot Sysfs Interface"
127 default n
128 help
129 This option enables support for exposing iSCSI boot information
130 via sysfs to userspace. If you wish to export this information,
131 say Y. Otherwise, say N.
132
133config ISCSI_IBFT 125config ISCSI_IBFT
134 tristate "iSCSI Boot Firmware Table Attributes module" 126 tristate "iSCSI Boot Firmware Table Attributes module"
135 select ISCSI_BOOT_SYSFS 127 select ISCSI_BOOT_SYSFS
136 depends on ISCSI_IBFT_FIND 128 depends on ISCSI_IBFT_FIND && SCSI
137 default n 129 default n
138 help 130 help
139 This option enables support for detection and exposing of iSCSI 131 This option enables support for detection and exposing of iSCSI
diff --git a/drivers/firmware/Makefile b/drivers/firmware/Makefile
index 5fe7e1662922..1c3c17343dbe 100644
--- a/drivers/firmware/Makefile
+++ b/drivers/firmware/Makefile
@@ -10,5 +10,4 @@ obj-$(CONFIG_DCDBAS) += dcdbas.o
10obj-$(CONFIG_DMIID) += dmi-id.o 10obj-$(CONFIG_DMIID) += dmi-id.o
11obj-$(CONFIG_ISCSI_IBFT_FIND) += iscsi_ibft_find.o 11obj-$(CONFIG_ISCSI_IBFT_FIND) += iscsi_ibft_find.o
12obj-$(CONFIG_ISCSI_IBFT) += iscsi_ibft.o 12obj-$(CONFIG_ISCSI_IBFT) += iscsi_ibft.o
13obj-$(CONFIG_ISCSI_BOOT_SYSFS) += iscsi_boot_sysfs.o
14obj-$(CONFIG_FIRMWARE_MEMMAP) += memmap.o 13obj-$(CONFIG_FIRMWARE_MEMMAP) += memmap.o
diff --git a/drivers/firmware/edd.c b/drivers/firmware/edd.c
index 110e24e50883..f287fe79edc4 100644
--- a/drivers/firmware/edd.c
+++ b/drivers/firmware/edd.c
@@ -744,7 +744,7 @@ static inline int edd_num_devices(void)
744static int __init 744static int __init
745edd_init(void) 745edd_init(void)
746{ 746{
747 unsigned int i; 747 int i;
748 int rc=0; 748 int rc=0;
749 struct edd_device *edev; 749 struct edd_device *edev;
750 750
@@ -760,21 +760,27 @@ edd_init(void)
760 if (!edd_kset) 760 if (!edd_kset)
761 return -ENOMEM; 761 return -ENOMEM;
762 762
763 for (i = 0; i < edd_num_devices() && !rc; i++) { 763 for (i = 0; i < edd_num_devices(); i++) {
764 edev = kzalloc(sizeof (*edev), GFP_KERNEL); 764 edev = kzalloc(sizeof (*edev), GFP_KERNEL);
765 if (!edev) 765 if (!edev) {
766 return -ENOMEM; 766 rc = -ENOMEM;
767 goto out;
768 }
767 769
768 rc = edd_device_register(edev, i); 770 rc = edd_device_register(edev, i);
769 if (rc) { 771 if (rc) {
770 kfree(edev); 772 kfree(edev);
771 break; 773 goto out;
772 } 774 }
773 edd_devices[i] = edev; 775 edd_devices[i] = edev;
774 } 776 }
775 777
776 if (rc) 778 return 0;
777 kset_unregister(edd_kset); 779
780out:
781 while (--i >= 0)
782 edd_device_unregister(edd_devices[i]);
783 kset_unregister(edd_kset);
778 return rc; 784 return rc;
779} 785}
780 786
diff --git a/drivers/firmware/iscsi_ibft.c b/drivers/firmware/iscsi_ibft.c
index 4f04ec0410a0..6148a1c67895 100644
--- a/drivers/firmware/iscsi_ibft.c
+++ b/drivers/firmware/iscsi_ibft.c
@@ -727,8 +727,10 @@ static void ibft_unregister(void)
727 727
728static void ibft_cleanup(void) 728static void ibft_cleanup(void)
729{ 729{
730 ibft_unregister(); 730 if (boot_kset) {
731 iscsi_boot_destroy_kset(boot_kset); 731 ibft_unregister();
732 iscsi_boot_destroy_kset(boot_kset);
733 }
732} 734}
733 735
734static void __exit ibft_exit(void) 736static void __exit ibft_exit(void)
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 7face915b963..510aa2054544 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -195,6 +195,24 @@ config GPIO_PCF857X
195 This driver provides an in-kernel interface to those GPIOs using 195 This driver provides an in-kernel interface to those GPIOs using
196 platform-neutral GPIO calls. 196 platform-neutral GPIO calls.
197 197
198config GPIO_SX150X
199 bool "Semtech SX150x I2C GPIO expander"
200 depends on I2C=y
201 default n
202 help
203 Say yes here to provide support for Semtech SX150-series I2C
204 GPIO expanders. Compatible models include:
205
206 8 bits: sx1508q
207 16 bits: sx1509q
208
209config GPIO_STMPE
210 bool "STMPE GPIOs"
211 depends on MFD_STMPE
212 help
213 This enables support for the GPIOs found on the STMPE I/O
214 Expanders.
215
198config GPIO_TC35892 216config GPIO_TC35892
199 bool "TC35892 GPIOs" 217 bool "TC35892 GPIOs"
200 depends on MFD_TC35892 218 depends on MFD_TC35892
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index e53dcff49b4f..fc6019d93720 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -20,6 +20,7 @@ obj-$(CONFIG_GPIO_MCP23S08) += mcp23s08.o
20obj-$(CONFIG_GPIO_PCA953X) += pca953x.o 20obj-$(CONFIG_GPIO_PCA953X) += pca953x.o
21obj-$(CONFIG_GPIO_PCF857X) += pcf857x.o 21obj-$(CONFIG_GPIO_PCF857X) += pcf857x.o
22obj-$(CONFIG_GPIO_PL061) += pl061.o 22obj-$(CONFIG_GPIO_PL061) += pl061.o
23obj-$(CONFIG_GPIO_STMPE) += stmpe-gpio.o
23obj-$(CONFIG_GPIO_TC35892) += tc35892-gpio.o 24obj-$(CONFIG_GPIO_TC35892) += tc35892-gpio.o
24obj-$(CONFIG_GPIO_TIMBERDALE) += timbgpio.o 25obj-$(CONFIG_GPIO_TIMBERDALE) += timbgpio.o
25obj-$(CONFIG_GPIO_TWL4030) += twl4030-gpio.o 26obj-$(CONFIG_GPIO_TWL4030) += twl4030-gpio.o
@@ -35,3 +36,4 @@ obj-$(CONFIG_GPIO_WM8994) += wm8994-gpio.o
35obj-$(CONFIG_GPIO_SCH) += sch_gpio.o 36obj-$(CONFIG_GPIO_SCH) += sch_gpio.o
36obj-$(CONFIG_GPIO_RDC321X) += rdc321x-gpio.o 37obj-$(CONFIG_GPIO_RDC321X) += rdc321x-gpio.o
37obj-$(CONFIG_GPIO_JANZ_TTL) += janz-ttl.o 38obj-$(CONFIG_GPIO_JANZ_TTL) += janz-ttl.o
39obj-$(CONFIG_GPIO_SX150X) += sx150x.o
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 6a6bd569e1f8..21da9c19a0cb 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -57,9 +57,9 @@ struct gpio_desc {
57#define FLAG_TRIG_RISE 6 /* trigger on rising edge */ 57#define FLAG_TRIG_RISE 6 /* trigger on rising edge */
58#define FLAG_ACTIVE_LOW 7 /* sysfs value has active low */ 58#define FLAG_ACTIVE_LOW 7 /* sysfs value has active low */
59 59
60#define PDESC_ID_SHIFT 16 /* add new flags before this one */ 60#define ID_SHIFT 16 /* add new flags before this one */
61 61
62#define GPIO_FLAGS_MASK ((1 << PDESC_ID_SHIFT) - 1) 62#define GPIO_FLAGS_MASK ((1 << ID_SHIFT) - 1)
63#define GPIO_TRIGGER_MASK (BIT(FLAG_TRIG_FALL) | BIT(FLAG_TRIG_RISE)) 63#define GPIO_TRIGGER_MASK (BIT(FLAG_TRIG_FALL) | BIT(FLAG_TRIG_RISE))
64 64
65#ifdef CONFIG_DEBUG_FS 65#ifdef CONFIG_DEBUG_FS
@@ -69,12 +69,7 @@ struct gpio_desc {
69static struct gpio_desc gpio_desc[ARCH_NR_GPIOS]; 69static struct gpio_desc gpio_desc[ARCH_NR_GPIOS];
70 70
71#ifdef CONFIG_GPIO_SYSFS 71#ifdef CONFIG_GPIO_SYSFS
72struct poll_desc { 72static DEFINE_IDR(dirent_idr);
73 struct work_struct work;
74 struct sysfs_dirent *value_sd;
75};
76
77static struct idr pdesc_idr;
78#endif 73#endif
79 74
80static inline void desc_set_label(struct gpio_desc *d, const char *label) 75static inline void desc_set_label(struct gpio_desc *d, const char *label)
@@ -325,24 +320,16 @@ static const DEVICE_ATTR(value, 0644,
325 320
326static irqreturn_t gpio_sysfs_irq(int irq, void *priv) 321static irqreturn_t gpio_sysfs_irq(int irq, void *priv)
327{ 322{
328 struct work_struct *work = priv; 323 struct sysfs_dirent *value_sd = priv;
329 324
330 schedule_work(work); 325 sysfs_notify_dirent(value_sd);
331 return IRQ_HANDLED; 326 return IRQ_HANDLED;
332} 327}
333 328
334static void gpio_notify_sysfs(struct work_struct *work)
335{
336 struct poll_desc *pdesc;
337
338 pdesc = container_of(work, struct poll_desc, work);
339 sysfs_notify_dirent(pdesc->value_sd);
340}
341
342static int gpio_setup_irq(struct gpio_desc *desc, struct device *dev, 329static int gpio_setup_irq(struct gpio_desc *desc, struct device *dev,
343 unsigned long gpio_flags) 330 unsigned long gpio_flags)
344{ 331{
345 struct poll_desc *pdesc; 332 struct sysfs_dirent *value_sd;
346 unsigned long irq_flags; 333 unsigned long irq_flags;
347 int ret, irq, id; 334 int ret, irq, id;
348 335
@@ -353,18 +340,16 @@ static int gpio_setup_irq(struct gpio_desc *desc, struct device *dev,
353 if (irq < 0) 340 if (irq < 0)
354 return -EIO; 341 return -EIO;
355 342
356 id = desc->flags >> PDESC_ID_SHIFT; 343 id = desc->flags >> ID_SHIFT;
357 pdesc = idr_find(&pdesc_idr, id); 344 value_sd = idr_find(&dirent_idr, id);
358 if (pdesc) { 345 if (value_sd)
359 free_irq(irq, &pdesc->work); 346 free_irq(irq, value_sd);
360 cancel_work_sync(&pdesc->work);
361 }
362 347
363 desc->flags &= ~GPIO_TRIGGER_MASK; 348 desc->flags &= ~GPIO_TRIGGER_MASK;
364 349
365 if (!gpio_flags) { 350 if (!gpio_flags) {
366 ret = 0; 351 ret = 0;
367 goto free_sd; 352 goto free_id;
368 } 353 }
369 354
370 irq_flags = IRQF_SHARED; 355 irq_flags = IRQF_SHARED;
@@ -375,55 +360,46 @@ static int gpio_setup_irq(struct gpio_desc *desc, struct device *dev,
375 irq_flags |= test_bit(FLAG_ACTIVE_LOW, &desc->flags) ? 360 irq_flags |= test_bit(FLAG_ACTIVE_LOW, &desc->flags) ?
376 IRQF_TRIGGER_FALLING : IRQF_TRIGGER_RISING; 361 IRQF_TRIGGER_FALLING : IRQF_TRIGGER_RISING;
377 362
378 if (!pdesc) { 363 if (!value_sd) {
379 pdesc = kmalloc(sizeof(*pdesc), GFP_KERNEL); 364 value_sd = sysfs_get_dirent(dev->kobj.sd, NULL, "value");
380 if (!pdesc) { 365 if (!value_sd) {
381 ret = -ENOMEM; 366 ret = -ENODEV;
382 goto err_out; 367 goto err_out;
383 } 368 }
384 369
385 do { 370 do {
386 ret = -ENOMEM; 371 ret = -ENOMEM;
387 if (idr_pre_get(&pdesc_idr, GFP_KERNEL)) 372 if (idr_pre_get(&dirent_idr, GFP_KERNEL))
388 ret = idr_get_new_above(&pdesc_idr, 373 ret = idr_get_new_above(&dirent_idr, value_sd,
389 pdesc, 1, &id); 374 1, &id);
390 } while (ret == -EAGAIN); 375 } while (ret == -EAGAIN);
391 376
392 if (ret) 377 if (ret)
393 goto free_mem; 378 goto free_sd;
394 379
395 desc->flags &= GPIO_FLAGS_MASK; 380 desc->flags &= GPIO_FLAGS_MASK;
396 desc->flags |= (unsigned long)id << PDESC_ID_SHIFT; 381 desc->flags |= (unsigned long)id << ID_SHIFT;
397 382
398 if (desc->flags >> PDESC_ID_SHIFT != id) { 383 if (desc->flags >> ID_SHIFT != id) {
399 ret = -ERANGE; 384 ret = -ERANGE;
400 goto free_id; 385 goto free_id;
401 } 386 }
402
403 pdesc->value_sd = sysfs_get_dirent(dev->kobj.sd, NULL, "value");
404 if (!pdesc->value_sd) {
405 ret = -ENODEV;
406 goto free_id;
407 }
408 INIT_WORK(&pdesc->work, gpio_notify_sysfs);
409 } 387 }
410 388
411 ret = request_irq(irq, gpio_sysfs_irq, irq_flags, 389 ret = request_any_context_irq(irq, gpio_sysfs_irq, irq_flags,
412 "gpiolib", &pdesc->work); 390 "gpiolib", value_sd);
413 if (ret) 391 if (ret < 0)
414 goto free_sd; 392 goto free_id;
415 393
416 desc->flags |= gpio_flags; 394 desc->flags |= gpio_flags;
417 return 0; 395 return 0;
418 396
419free_sd:
420 if (pdesc)
421 sysfs_put(pdesc->value_sd);
422free_id: 397free_id:
423 idr_remove(&pdesc_idr, id); 398 idr_remove(&dirent_idr, id);
424 desc->flags &= GPIO_FLAGS_MASK; 399 desc->flags &= GPIO_FLAGS_MASK;
425free_mem: 400free_sd:
426 kfree(pdesc); 401 if (value_sd)
402 sysfs_put(value_sd);
427err_out: 403err_out:
428 return ret; 404 return ret;
429} 405}
@@ -994,8 +970,6 @@ static int __init gpiolib_sysfs_init(void)
994 unsigned long flags; 970 unsigned long flags;
995 unsigned gpio; 971 unsigned gpio;
996 972
997 idr_init(&pdesc_idr);
998
999 status = class_register(&gpio_class); 973 status = class_register(&gpio_class);
1000 if (status < 0) 974 if (status < 0)
1001 return status; 975 return status;
@@ -1272,7 +1246,7 @@ void gpio_free(unsigned gpio)
1272 if (chip && test_bit(FLAG_REQUESTED, &desc->flags)) { 1246 if (chip && test_bit(FLAG_REQUESTED, &desc->flags)) {
1273 if (chip->free) { 1247 if (chip->free) {
1274 spin_unlock_irqrestore(&gpio_lock, flags); 1248 spin_unlock_irqrestore(&gpio_lock, flags);
1275 might_sleep_if(extra_checks && chip->can_sleep); 1249 might_sleep_if(chip->can_sleep);
1276 chip->free(chip, gpio - chip->base); 1250 chip->free(chip, gpio - chip->base);
1277 spin_lock_irqsave(&gpio_lock, flags); 1251 spin_lock_irqsave(&gpio_lock, flags);
1278 } 1252 }
@@ -1410,7 +1384,7 @@ int gpio_direction_input(unsigned gpio)
1410 1384
1411 spin_unlock_irqrestore(&gpio_lock, flags); 1385 spin_unlock_irqrestore(&gpio_lock, flags);
1412 1386
1413 might_sleep_if(extra_checks && chip->can_sleep); 1387 might_sleep_if(chip->can_sleep);
1414 1388
1415 if (status) { 1389 if (status) {
1416 status = chip->request(chip, gpio); 1390 status = chip->request(chip, gpio);
@@ -1463,7 +1437,7 @@ int gpio_direction_output(unsigned gpio, int value)
1463 1437
1464 spin_unlock_irqrestore(&gpio_lock, flags); 1438 spin_unlock_irqrestore(&gpio_lock, flags);
1465 1439
1466 might_sleep_if(extra_checks && chip->can_sleep); 1440 might_sleep_if(chip->can_sleep);
1467 1441
1468 if (status) { 1442 if (status) {
1469 status = chip->request(chip, gpio); 1443 status = chip->request(chip, gpio);
@@ -1521,7 +1495,7 @@ int gpio_set_debounce(unsigned gpio, unsigned debounce)
1521 1495
1522 spin_unlock_irqrestore(&gpio_lock, flags); 1496 spin_unlock_irqrestore(&gpio_lock, flags);
1523 1497
1524 might_sleep_if(extra_checks && chip->can_sleep); 1498 might_sleep_if(chip->can_sleep);
1525 1499
1526 return chip->set_debounce(chip, gpio, debounce); 1500 return chip->set_debounce(chip, gpio, debounce);
1527 1501
@@ -1571,7 +1545,7 @@ int __gpio_get_value(unsigned gpio)
1571 struct gpio_chip *chip; 1545 struct gpio_chip *chip;
1572 1546
1573 chip = gpio_to_chip(gpio); 1547 chip = gpio_to_chip(gpio);
1574 WARN_ON(extra_checks && chip->can_sleep); 1548 WARN_ON(chip->can_sleep);
1575 return chip->get ? chip->get(chip, gpio - chip->base) : 0; 1549 return chip->get ? chip->get(chip, gpio - chip->base) : 0;
1576} 1550}
1577EXPORT_SYMBOL_GPL(__gpio_get_value); 1551EXPORT_SYMBOL_GPL(__gpio_get_value);
@@ -1590,7 +1564,7 @@ void __gpio_set_value(unsigned gpio, int value)
1590 struct gpio_chip *chip; 1564 struct gpio_chip *chip;
1591 1565
1592 chip = gpio_to_chip(gpio); 1566 chip = gpio_to_chip(gpio);
1593 WARN_ON(extra_checks && chip->can_sleep); 1567 WARN_ON(chip->can_sleep);
1594 chip->set(chip, gpio - chip->base, value); 1568 chip->set(chip, gpio - chip->base, value);
1595} 1569}
1596EXPORT_SYMBOL_GPL(__gpio_set_value); 1570EXPORT_SYMBOL_GPL(__gpio_set_value);
diff --git a/drivers/gpio/max730x.c b/drivers/gpio/max730x.c
index 7696a5625d58..94ce773f95f8 100644
--- a/drivers/gpio/max730x.c
+++ b/drivers/gpio/max730x.c
@@ -54,7 +54,7 @@ static int max7301_direction_input(struct gpio_chip *chip, unsigned offset)
54{ 54{
55 struct max7301 *ts = container_of(chip, struct max7301, chip); 55 struct max7301 *ts = container_of(chip, struct max7301, chip);
56 u8 *config; 56 u8 *config;
57 u8 offset_bits; 57 u8 offset_bits, pin_config;
58 int ret; 58 int ret;
59 59
60 /* First 4 pins are unused in the controller */ 60 /* First 4 pins are unused in the controller */
@@ -63,12 +63,15 @@ static int max7301_direction_input(struct gpio_chip *chip, unsigned offset)
63 63
64 config = &ts->port_config[offset >> 2]; 64 config = &ts->port_config[offset >> 2];
65 65
66 if (ts->input_pullup_active & BIT(offset))
67 pin_config = PIN_CONFIG_IN_PULLUP;
68 else
69 pin_config = PIN_CONFIG_IN_WO_PULLUP;
70
66 mutex_lock(&ts->lock); 71 mutex_lock(&ts->lock);
67 72
68 /* Standard GPIO API doesn't support pull-ups, has to be extended.
69 * Hard-coding no pollup for now. */
70 *config = (*config & ~(PIN_CONFIG_MASK << offset_bits)) 73 *config = (*config & ~(PIN_CONFIG_MASK << offset_bits))
71 | (PIN_CONFIG_IN_WO_PULLUP << offset_bits); 74 | (pin_config << offset_bits);
72 75
73 ret = ts->write(ts->dev, 0x08 + (offset >> 2), *config); 76 ret = ts->write(ts->dev, 0x08 + (offset >> 2), *config);
74 77
@@ -177,6 +180,7 @@ int __devinit __max730x_probe(struct max7301 *ts)
177 /* Power up the chip and disable IRQ output */ 180 /* Power up the chip and disable IRQ output */
178 ts->write(dev, 0x04, 0x01); 181 ts->write(dev, 0x04, 0x01);
179 182
183 ts->input_pullup_active = pdata->input_pullup_active;
180 ts->chip.label = dev->driver->name; 184 ts->chip.label = dev->driver->name;
181 185
182 ts->chip.direction_input = max7301_direction_input; 186 ts->chip.direction_input = max7301_direction_input;
@@ -191,13 +195,17 @@ int __devinit __max730x_probe(struct max7301 *ts)
191 ts->chip.owner = THIS_MODULE; 195 ts->chip.owner = THIS_MODULE;
192 196
193 /* 197 /*
194 * tristate all pins in hardware and cache the 198 * initialize pullups according to platform data and cache the
195 * register values for later use. 199 * register values for later use.
196 */ 200 */
197 for (i = 1; i < 8; i++) { 201 for (i = 1; i < 8; i++) {
198 int j; 202 int j;
199 /* 0xAA means input with internal pullup disabled */ 203 /*
200 ts->write(dev, 0x08 + i, 0xAA); 204 * initialize port_config with "0xAA", which means
205 * input with internal pullup disabled. This is needed
206 * to avoid writing zeros (in the inner for loop),
207 * which is not allowed according to the datasheet.
208 */
201 ts->port_config[i] = 0xAA; 209 ts->port_config[i] = 0xAA;
202 for (j = 0; j < 4; j++) { 210 for (j = 0; j < 4; j++) {
203 int offset = (i - 1) * 4 + j; 211 int offset = (i - 1) * 4 + j;
diff --git a/drivers/gpio/pcf857x.c b/drivers/gpio/pcf857x.c
index 29f19ce3e80f..879b473aab5a 100644
--- a/drivers/gpio/pcf857x.c
+++ b/drivers/gpio/pcf857x.c
@@ -190,7 +190,6 @@ static int pcf857x_probe(struct i2c_client *client,
190 pdata = client->dev.platform_data; 190 pdata = client->dev.platform_data;
191 if (!pdata) { 191 if (!pdata) {
192 dev_dbg(&client->dev, "no platform data\n"); 192 dev_dbg(&client->dev, "no platform data\n");
193 return -EINVAL;
194 } 193 }
195 194
196 /* Allocate, initialize, and register this gpio_chip. */ 195 /* Allocate, initialize, and register this gpio_chip. */
@@ -200,7 +199,7 @@ static int pcf857x_probe(struct i2c_client *client,
200 199
201 mutex_init(&gpio->lock); 200 mutex_init(&gpio->lock);
202 201
203 gpio->chip.base = pdata->gpio_base; 202 gpio->chip.base = pdata ? pdata->gpio_base : -1;
204 gpio->chip.can_sleep = 1; 203 gpio->chip.can_sleep = 1;
205 gpio->chip.dev = &client->dev; 204 gpio->chip.dev = &client->dev;
206 gpio->chip.owner = THIS_MODULE; 205 gpio->chip.owner = THIS_MODULE;
@@ -278,7 +277,7 @@ static int pcf857x_probe(struct i2c_client *client,
278 * to zero, our software copy of the "latch" then matches the chip's 277 * to zero, our software copy of the "latch" then matches the chip's
279 * all-ones reset state. Otherwise it flags pins to be driven low. 278 * all-ones reset state. Otherwise it flags pins to be driven low.
280 */ 279 */
281 gpio->out = ~pdata->n_latch; 280 gpio->out = pdata ? ~pdata->n_latch : ~0;
282 281
283 status = gpiochip_add(&gpio->chip); 282 status = gpiochip_add(&gpio->chip);
284 if (status < 0) 283 if (status < 0)
@@ -299,7 +298,7 @@ static int pcf857x_probe(struct i2c_client *client,
299 /* Let platform code set up the GPIOs and their users. 298 /* Let platform code set up the GPIOs and their users.
300 * Now is the first time anyone could use them. 299 * Now is the first time anyone could use them.
301 */ 300 */
302 if (pdata->setup) { 301 if (pdata && pdata->setup) {
303 status = pdata->setup(client, 302 status = pdata->setup(client,
304 gpio->chip.base, gpio->chip.ngpio, 303 gpio->chip.base, gpio->chip.ngpio,
305 pdata->context); 304 pdata->context);
@@ -322,7 +321,7 @@ static int pcf857x_remove(struct i2c_client *client)
322 struct pcf857x *gpio = i2c_get_clientdata(client); 321 struct pcf857x *gpio = i2c_get_clientdata(client);
323 int status = 0; 322 int status = 0;
324 323
325 if (pdata->teardown) { 324 if (pdata && pdata->teardown) {
326 status = pdata->teardown(client, 325 status = pdata->teardown(client,
327 gpio->chip.base, gpio->chip.ngpio, 326 gpio->chip.base, gpio->chip.ngpio,
328 pdata->context); 327 pdata->context);
diff --git a/drivers/gpio/stmpe-gpio.c b/drivers/gpio/stmpe-gpio.c
new file mode 100644
index 000000000000..4e1f1b9d5e67
--- /dev/null
+++ b/drivers/gpio/stmpe-gpio.c
@@ -0,0 +1,399 @@
1/*
2 * Copyright (C) ST-Ericsson SA 2010
3 *
4 * License Terms: GNU General Public License, version 2
5 * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
6 */
7
8#include <linux/module.h>
9#include <linux/init.h>
10#include <linux/platform_device.h>
11#include <linux/slab.h>
12#include <linux/gpio.h>
13#include <linux/irq.h>
14#include <linux/interrupt.h>
15#include <linux/mfd/stmpe.h>
16
17/*
18 * These registers are modified under the irq bus lock and cached to avoid
19 * unnecessary writes in bus_sync_unlock.
20 */
21enum { REG_RE, REG_FE, REG_IE };
22
23#define CACHE_NR_REGS 3
24#define CACHE_NR_BANKS (STMPE_NR_GPIOS / 8)
25
26struct stmpe_gpio {
27 struct gpio_chip chip;
28 struct stmpe *stmpe;
29 struct device *dev;
30 struct mutex irq_lock;
31
32 int irq_base;
33
34 /* Caches of interrupt control registers for bus_lock */
35 u8 regs[CACHE_NR_REGS][CACHE_NR_BANKS];
36 u8 oldregs[CACHE_NR_REGS][CACHE_NR_BANKS];
37};
38
39static inline struct stmpe_gpio *to_stmpe_gpio(struct gpio_chip *chip)
40{
41 return container_of(chip, struct stmpe_gpio, chip);
42}
43
44static int stmpe_gpio_get(struct gpio_chip *chip, unsigned offset)
45{
46 struct stmpe_gpio *stmpe_gpio = to_stmpe_gpio(chip);
47 struct stmpe *stmpe = stmpe_gpio->stmpe;
48 u8 reg = stmpe->regs[STMPE_IDX_GPMR_LSB] - (offset / 8);
49 u8 mask = 1 << (offset % 8);
50 int ret;
51
52 ret = stmpe_reg_read(stmpe, reg);
53 if (ret < 0)
54 return ret;
55
56 return ret & mask;
57}
58
59static void stmpe_gpio_set(struct gpio_chip *chip, unsigned offset, int val)
60{
61 struct stmpe_gpio *stmpe_gpio = to_stmpe_gpio(chip);
62 struct stmpe *stmpe = stmpe_gpio->stmpe;
63 int which = val ? STMPE_IDX_GPSR_LSB : STMPE_IDX_GPCR_LSB;
64 u8 reg = stmpe->regs[which] - (offset / 8);
65 u8 mask = 1 << (offset % 8);
66
67 stmpe_reg_write(stmpe, reg, mask);
68}
69
70static int stmpe_gpio_direction_output(struct gpio_chip *chip,
71 unsigned offset, int val)
72{
73 struct stmpe_gpio *stmpe_gpio = to_stmpe_gpio(chip);
74 struct stmpe *stmpe = stmpe_gpio->stmpe;
75 u8 reg = stmpe->regs[STMPE_IDX_GPDR_LSB] - (offset / 8);
76 u8 mask = 1 << (offset % 8);
77
78 stmpe_gpio_set(chip, offset, val);
79
80 return stmpe_set_bits(stmpe, reg, mask, mask);
81}
82
83static int stmpe_gpio_direction_input(struct gpio_chip *chip,
84 unsigned offset)
85{
86 struct stmpe_gpio *stmpe_gpio = to_stmpe_gpio(chip);
87 struct stmpe *stmpe = stmpe_gpio->stmpe;
88 u8 reg = stmpe->regs[STMPE_IDX_GPDR_LSB] - (offset / 8);
89 u8 mask = 1 << (offset % 8);
90
91 return stmpe_set_bits(stmpe, reg, mask, 0);
92}
93
94static int stmpe_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
95{
96 struct stmpe_gpio *stmpe_gpio = to_stmpe_gpio(chip);
97
98 return stmpe_gpio->irq_base + offset;
99}
100
101static int stmpe_gpio_request(struct gpio_chip *chip, unsigned offset)
102{
103 struct stmpe_gpio *stmpe_gpio = to_stmpe_gpio(chip);
104 struct stmpe *stmpe = stmpe_gpio->stmpe;
105
106 return stmpe_set_altfunc(stmpe, 1 << offset, STMPE_BLOCK_GPIO);
107}
108
109static struct gpio_chip template_chip = {
110 .label = "stmpe",
111 .owner = THIS_MODULE,
112 .direction_input = stmpe_gpio_direction_input,
113 .get = stmpe_gpio_get,
114 .direction_output = stmpe_gpio_direction_output,
115 .set = stmpe_gpio_set,
116 .to_irq = stmpe_gpio_to_irq,
117 .request = stmpe_gpio_request,
118 .can_sleep = 1,
119};
120
121static int stmpe_gpio_irq_set_type(unsigned int irq, unsigned int type)
122{
123 struct stmpe_gpio *stmpe_gpio = get_irq_chip_data(irq);
124 int offset = irq - stmpe_gpio->irq_base;
125 int regoffset = offset / 8;
126 int mask = 1 << (offset % 8);
127
128 if (type == IRQ_TYPE_LEVEL_LOW || type == IRQ_TYPE_LEVEL_HIGH)
129 return -EINVAL;
130
131 if (type == IRQ_TYPE_EDGE_RISING)
132 stmpe_gpio->regs[REG_RE][regoffset] |= mask;
133 else
134 stmpe_gpio->regs[REG_RE][regoffset] &= ~mask;
135
136 if (type == IRQ_TYPE_EDGE_FALLING)
137 stmpe_gpio->regs[REG_FE][regoffset] |= mask;
138 else
139 stmpe_gpio->regs[REG_FE][regoffset] &= ~mask;
140
141 return 0;
142}
143
144static void stmpe_gpio_irq_lock(unsigned int irq)
145{
146 struct stmpe_gpio *stmpe_gpio = get_irq_chip_data(irq);
147
148 mutex_lock(&stmpe_gpio->irq_lock);
149}
150
151static void stmpe_gpio_irq_sync_unlock(unsigned int irq)
152{
153 struct stmpe_gpio *stmpe_gpio = get_irq_chip_data(irq);
154 struct stmpe *stmpe = stmpe_gpio->stmpe;
155 int num_banks = DIV_ROUND_UP(stmpe->num_gpios, 8);
156 static const u8 regmap[] = {
157 [REG_RE] = STMPE_IDX_GPRER_LSB,
158 [REG_FE] = STMPE_IDX_GPFER_LSB,
159 [REG_IE] = STMPE_IDX_IEGPIOR_LSB,
160 };
161 int i, j;
162
163 for (i = 0; i < CACHE_NR_REGS; i++) {
164 for (j = 0; j < num_banks; j++) {
165 u8 old = stmpe_gpio->oldregs[i][j];
166 u8 new = stmpe_gpio->regs[i][j];
167
168 if (new == old)
169 continue;
170
171 stmpe_gpio->oldregs[i][j] = new;
172 stmpe_reg_write(stmpe, stmpe->regs[regmap[i]] - j, new);
173 }
174 }
175
176 mutex_unlock(&stmpe_gpio->irq_lock);
177}
178
179static void stmpe_gpio_irq_mask(unsigned int irq)
180{
181 struct stmpe_gpio *stmpe_gpio = get_irq_chip_data(irq);
182 int offset = irq - stmpe_gpio->irq_base;
183 int regoffset = offset / 8;
184 int mask = 1 << (offset % 8);
185
186 stmpe_gpio->regs[REG_IE][regoffset] &= ~mask;
187}
188
189static void stmpe_gpio_irq_unmask(unsigned int irq)
190{
191 struct stmpe_gpio *stmpe_gpio = get_irq_chip_data(irq);
192 int offset = irq - stmpe_gpio->irq_base;
193 int regoffset = offset / 8;
194 int mask = 1 << (offset % 8);
195
196 stmpe_gpio->regs[REG_IE][regoffset] |= mask;
197}
198
199static struct irq_chip stmpe_gpio_irq_chip = {
200 .name = "stmpe-gpio",
201 .bus_lock = stmpe_gpio_irq_lock,
202 .bus_sync_unlock = stmpe_gpio_irq_sync_unlock,
203 .mask = stmpe_gpio_irq_mask,
204 .unmask = stmpe_gpio_irq_unmask,
205 .set_type = stmpe_gpio_irq_set_type,
206};
207
208static irqreturn_t stmpe_gpio_irq(int irq, void *dev)
209{
210 struct stmpe_gpio *stmpe_gpio = dev;
211 struct stmpe *stmpe = stmpe_gpio->stmpe;
212 u8 statmsbreg = stmpe->regs[STMPE_IDX_ISGPIOR_MSB];
213 int num_banks = DIV_ROUND_UP(stmpe->num_gpios, 8);
214 u8 status[num_banks];
215 int ret;
216 int i;
217
218 ret = stmpe_block_read(stmpe, statmsbreg, num_banks, status);
219 if (ret < 0)
220 return IRQ_NONE;
221
222 for (i = 0; i < num_banks; i++) {
223 int bank = num_banks - i - 1;
224 unsigned int enabled = stmpe_gpio->regs[REG_IE][bank];
225 unsigned int stat = status[i];
226
227 stat &= enabled;
228 if (!stat)
229 continue;
230
231 while (stat) {
232 int bit = __ffs(stat);
233 int line = bank * 8 + bit;
234
235 handle_nested_irq(stmpe_gpio->irq_base + line);
236 stat &= ~(1 << bit);
237 }
238
239 stmpe_reg_write(stmpe, statmsbreg + i, status[i]);
240 stmpe_reg_write(stmpe, stmpe->regs[STMPE_IDX_GPEDR_MSB] + i,
241 status[i]);
242 }
243
244 return IRQ_HANDLED;
245}
246
247static int __devinit stmpe_gpio_irq_init(struct stmpe_gpio *stmpe_gpio)
248{
249 int base = stmpe_gpio->irq_base;
250 int irq;
251
252 for (irq = base; irq < base + stmpe_gpio->chip.ngpio; irq++) {
253 set_irq_chip_data(irq, stmpe_gpio);
254 set_irq_chip_and_handler(irq, &stmpe_gpio_irq_chip,
255 handle_simple_irq);
256 set_irq_nested_thread(irq, 1);
257#ifdef CONFIG_ARM
258 set_irq_flags(irq, IRQF_VALID);
259#else
260 set_irq_noprobe(irq);
261#endif
262 }
263
264 return 0;
265}
266
267static void stmpe_gpio_irq_remove(struct stmpe_gpio *stmpe_gpio)
268{
269 int base = stmpe_gpio->irq_base;
270 int irq;
271
272 for (irq = base; irq < base + stmpe_gpio->chip.ngpio; irq++) {
273#ifdef CONFIG_ARM
274 set_irq_flags(irq, 0);
275#endif
276 set_irq_chip_and_handler(irq, NULL, NULL);
277 set_irq_chip_data(irq, NULL);
278 }
279}
280
281static int __devinit stmpe_gpio_probe(struct platform_device *pdev)
282{
283 struct stmpe *stmpe = dev_get_drvdata(pdev->dev.parent);
284 struct stmpe_gpio_platform_data *pdata;
285 struct stmpe_gpio *stmpe_gpio;
286 int ret;
287 int irq;
288
289 pdata = stmpe->pdata->gpio;
290 if (!pdata)
291 return -ENODEV;
292
293 irq = platform_get_irq(pdev, 0);
294 if (irq < 0)
295 return irq;
296
297 stmpe_gpio = kzalloc(sizeof(struct stmpe_gpio), GFP_KERNEL);
298 if (!stmpe_gpio)
299 return -ENOMEM;
300
301 mutex_init(&stmpe_gpio->irq_lock);
302
303 stmpe_gpio->dev = &pdev->dev;
304 stmpe_gpio->stmpe = stmpe;
305
306 stmpe_gpio->chip = template_chip;
307 stmpe_gpio->chip.ngpio = stmpe->num_gpios;
308 stmpe_gpio->chip.dev = &pdev->dev;
309 stmpe_gpio->chip.base = pdata ? pdata->gpio_base : -1;
310
311 stmpe_gpio->irq_base = stmpe->irq_base + STMPE_INT_GPIO(0);
312
313 ret = stmpe_enable(stmpe, STMPE_BLOCK_GPIO);
314 if (ret)
315 return ret;
316
317 ret = stmpe_gpio_irq_init(stmpe_gpio);
318 if (ret)
319 goto out_free;
320
321 ret = request_threaded_irq(irq, NULL, stmpe_gpio_irq, IRQF_ONESHOT,
322 "stmpe-gpio", stmpe_gpio);
323 if (ret) {
324 dev_err(&pdev->dev, "unable to get irq: %d\n", ret);
325 goto out_removeirq;
326 }
327
328 ret = gpiochip_add(&stmpe_gpio->chip);
329 if (ret) {
330 dev_err(&pdev->dev, "unable to add gpiochip: %d\n", ret);
331 goto out_freeirq;
332 }
333
334 if (pdata && pdata->setup)
335 pdata->setup(stmpe, stmpe_gpio->chip.base);
336
337 platform_set_drvdata(pdev, stmpe_gpio);
338
339 return 0;
340
341out_freeirq:
342 free_irq(irq, stmpe_gpio);
343out_removeirq:
344 stmpe_gpio_irq_remove(stmpe_gpio);
345out_free:
346 kfree(stmpe_gpio);
347 return ret;
348}
349
350static int __devexit stmpe_gpio_remove(struct platform_device *pdev)
351{
352 struct stmpe_gpio *stmpe_gpio = platform_get_drvdata(pdev);
353 struct stmpe *stmpe = stmpe_gpio->stmpe;
354 struct stmpe_gpio_platform_data *pdata = stmpe->pdata->gpio;
355 int irq = platform_get_irq(pdev, 0);
356 int ret;
357
358 if (pdata && pdata->remove)
359 pdata->remove(stmpe, stmpe_gpio->chip.base);
360
361 ret = gpiochip_remove(&stmpe_gpio->chip);
362 if (ret < 0) {
363 dev_err(stmpe_gpio->dev,
364 "unable to remove gpiochip: %d\n", ret);
365 return ret;
366 }
367
368 stmpe_disable(stmpe, STMPE_BLOCK_GPIO);
369
370 free_irq(irq, stmpe_gpio);
371 stmpe_gpio_irq_remove(stmpe_gpio);
372 platform_set_drvdata(pdev, NULL);
373 kfree(stmpe_gpio);
374
375 return 0;
376}
377
378static struct platform_driver stmpe_gpio_driver = {
379 .driver.name = "stmpe-gpio",
380 .driver.owner = THIS_MODULE,
381 .probe = stmpe_gpio_probe,
382 .remove = __devexit_p(stmpe_gpio_remove),
383};
384
385static int __init stmpe_gpio_init(void)
386{
387 return platform_driver_register(&stmpe_gpio_driver);
388}
389subsys_initcall(stmpe_gpio_init);
390
391static void __exit stmpe_gpio_exit(void)
392{
393 platform_driver_unregister(&stmpe_gpio_driver);
394}
395module_exit(stmpe_gpio_exit);
396
397MODULE_LICENSE("GPL v2");
398MODULE_DESCRIPTION("STMPExxxx GPIO driver");
399MODULE_AUTHOR("Rabin Vincent <rabin.vincent@stericsson.com>");
diff --git a/drivers/gpio/sx150x.c b/drivers/gpio/sx150x.c
new file mode 100644
index 000000000000..b42f42ca70c3
--- /dev/null
+++ b/drivers/gpio/sx150x.c
@@ -0,0 +1,645 @@
1/* Copyright (c) 2010, Code Aurora Forum. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15 * 02110-1301, USA.
16 */
17#include <linux/gpio.h>
18#include <linux/i2c.h>
19#include <linux/init.h>
20#include <linux/interrupt.h>
21#include <linux/irq.h>
22#include <linux/module.h>
23#include <linux/mutex.h>
24#include <linux/slab.h>
25#include <linux/workqueue.h>
26#include <linux/i2c/sx150x.h>
27
28struct sx150x_device_data {
29 u8 reg_pullup;
30 u8 reg_pulldn;
31 u8 reg_drain;
32 u8 reg_polarity;
33 u8 reg_dir;
34 u8 reg_data;
35 u8 reg_irq_mask;
36 u8 reg_irq_src;
37 u8 reg_sense;
38 u8 reg_clock;
39 u8 reg_misc;
40 u8 reg_reset;
41 u8 ngpios;
42};
43
44struct sx150x_chip {
45 struct gpio_chip gpio_chip;
46 struct i2c_client *client;
47 const struct sx150x_device_data *dev_cfg;
48 int irq_summary;
49 int irq_base;
50 u32 irq_sense;
51 unsigned long irq_set_type_pending;
52 struct irq_chip irq_chip;
53 struct mutex lock;
54};
55
56static const struct sx150x_device_data sx150x_devices[] = {
57 [0] = { /* sx1508q */
58 .reg_pullup = 0x03,
59 .reg_pulldn = 0x04,
60 .reg_drain = 0x05,
61 .reg_polarity = 0x06,
62 .reg_dir = 0x07,
63 .reg_data = 0x08,
64 .reg_irq_mask = 0x09,
65 .reg_irq_src = 0x0c,
66 .reg_sense = 0x0b,
67 .reg_clock = 0x0f,
68 .reg_misc = 0x10,
69 .reg_reset = 0x7d,
70 .ngpios = 8
71 },
72 [1] = { /* sx1509q */
73 .reg_pullup = 0x07,
74 .reg_pulldn = 0x09,
75 .reg_drain = 0x0b,
76 .reg_polarity = 0x0d,
77 .reg_dir = 0x0f,
78 .reg_data = 0x11,
79 .reg_irq_mask = 0x13,
80 .reg_irq_src = 0x19,
81 .reg_sense = 0x17,
82 .reg_clock = 0x1e,
83 .reg_misc = 0x1f,
84 .reg_reset = 0x7d,
85 .ngpios = 16
86 },
87};
88
89static const struct i2c_device_id sx150x_id[] = {
90 {"sx1508q", 0},
91 {"sx1509q", 1},
92 {}
93};
94MODULE_DEVICE_TABLE(i2c, sx150x_id);
95
96static s32 sx150x_i2c_write(struct i2c_client *client, u8 reg, u8 val)
97{
98 s32 err = i2c_smbus_write_byte_data(client, reg, val);
99
100 if (err < 0)
101 dev_warn(&client->dev,
102 "i2c write fail: can't write %02x to %02x: %d\n",
103 val, reg, err);
104 return err;
105}
106
107static s32 sx150x_i2c_read(struct i2c_client *client, u8 reg, u8 *val)
108{
109 s32 err = i2c_smbus_read_byte_data(client, reg);
110
111 if (err >= 0)
112 *val = err;
113 else
114 dev_warn(&client->dev,
115 "i2c read fail: can't read from %02x: %d\n",
116 reg, err);
117 return err;
118}
119
120static inline bool offset_is_oscio(struct sx150x_chip *chip, unsigned offset)
121{
122 return (chip->dev_cfg->ngpios == offset);
123}
124
125/*
126 * These utility functions solve the common problem of locating and setting
127 * configuration bits. Configuration bits are grouped into registers
128 * whose indexes increase downwards. For example, with eight-bit registers,
129 * sixteen gpios would have their config bits grouped in the following order:
130 * REGISTER N-1 [ f e d c b a 9 8 ]
131 * N [ 7 6 5 4 3 2 1 0 ]
132 *
133 * For multi-bit configurations, the pattern gets wider:
134 * REGISTER N-3 [ f f e e d d c c ]
135 * N-2 [ b b a a 9 9 8 8 ]
136 * N-1 [ 7 7 6 6 5 5 4 4 ]
137 * N [ 3 3 2 2 1 1 0 0 ]
138 *
139 * Given the address of the starting register 'N', the index of the gpio
140 * whose configuration we seek to change, and the width in bits of that
141 * configuration, these functions allow us to locate the correct
142 * register and mask the correct bits.
143 */
144static inline void sx150x_find_cfg(u8 offset, u8 width,
145 u8 *reg, u8 *mask, u8 *shift)
146{
147 *reg -= offset * width / 8;
148 *mask = (1 << width) - 1;
149 *shift = (offset * width) % 8;
150 *mask <<= *shift;
151}
152
153static s32 sx150x_write_cfg(struct sx150x_chip *chip,
154 u8 offset, u8 width, u8 reg, u8 val)
155{
156 u8 mask;
157 u8 data;
158 u8 shift;
159 s32 err;
160
161 sx150x_find_cfg(offset, width, &reg, &mask, &shift);
162 err = sx150x_i2c_read(chip->client, reg, &data);
163 if (err < 0)
164 return err;
165
166 data &= ~mask;
167 data |= (val << shift) & mask;
168 return sx150x_i2c_write(chip->client, reg, data);
169}
170
171static int sx150x_get_io(struct sx150x_chip *chip, unsigned offset)
172{
173 u8 reg = chip->dev_cfg->reg_data;
174 u8 mask;
175 u8 data;
176 u8 shift;
177 s32 err;
178
179 sx150x_find_cfg(offset, 1, &reg, &mask, &shift);
180 err = sx150x_i2c_read(chip->client, reg, &data);
181 if (err >= 0)
182 err = (data & mask) != 0 ? 1 : 0;
183
184 return err;
185}
186
187static void sx150x_set_oscio(struct sx150x_chip *chip, int val)
188{
189 sx150x_i2c_write(chip->client,
190 chip->dev_cfg->reg_clock,
191 (val ? 0x1f : 0x10));
192}
193
194static void sx150x_set_io(struct sx150x_chip *chip, unsigned offset, int val)
195{
196 sx150x_write_cfg(chip,
197 offset,
198 1,
199 chip->dev_cfg->reg_data,
200 (val ? 1 : 0));
201}
202
203static int sx150x_io_input(struct sx150x_chip *chip, unsigned offset)
204{
205 return sx150x_write_cfg(chip,
206 offset,
207 1,
208 chip->dev_cfg->reg_dir,
209 1);
210}
211
212static int sx150x_io_output(struct sx150x_chip *chip, unsigned offset, int val)
213{
214 int err;
215
216 err = sx150x_write_cfg(chip,
217 offset,
218 1,
219 chip->dev_cfg->reg_data,
220 (val ? 1 : 0));
221 if (err >= 0)
222 err = sx150x_write_cfg(chip,
223 offset,
224 1,
225 chip->dev_cfg->reg_dir,
226 0);
227 return err;
228}
229
230static int sx150x_gpio_get(struct gpio_chip *gc, unsigned offset)
231{
232 struct sx150x_chip *chip;
233 int status = -EINVAL;
234
235 chip = container_of(gc, struct sx150x_chip, gpio_chip);
236
237 if (!offset_is_oscio(chip, offset)) {
238 mutex_lock(&chip->lock);
239 status = sx150x_get_io(chip, offset);
240 mutex_unlock(&chip->lock);
241 }
242
243 return status;
244}
245
246static void sx150x_gpio_set(struct gpio_chip *gc, unsigned offset, int val)
247{
248 struct sx150x_chip *chip;
249
250 chip = container_of(gc, struct sx150x_chip, gpio_chip);
251
252 mutex_lock(&chip->lock);
253 if (offset_is_oscio(chip, offset))
254 sx150x_set_oscio(chip, val);
255 else
256 sx150x_set_io(chip, offset, val);
257 mutex_unlock(&chip->lock);
258}
259
260static int sx150x_gpio_direction_input(struct gpio_chip *gc, unsigned offset)
261{
262 struct sx150x_chip *chip;
263 int status = -EINVAL;
264
265 chip = container_of(gc, struct sx150x_chip, gpio_chip);
266
267 if (!offset_is_oscio(chip, offset)) {
268 mutex_lock(&chip->lock);
269 status = sx150x_io_input(chip, offset);
270 mutex_unlock(&chip->lock);
271 }
272 return status;
273}
274
275static int sx150x_gpio_direction_output(struct gpio_chip *gc,
276 unsigned offset,
277 int val)
278{
279 struct sx150x_chip *chip;
280 int status = 0;
281
282 chip = container_of(gc, struct sx150x_chip, gpio_chip);
283
284 if (!offset_is_oscio(chip, offset)) {
285 mutex_lock(&chip->lock);
286 status = sx150x_io_output(chip, offset, val);
287 mutex_unlock(&chip->lock);
288 }
289 return status;
290}
291
292static int sx150x_gpio_to_irq(struct gpio_chip *gc, unsigned offset)
293{
294 struct sx150x_chip *chip;
295
296 chip = container_of(gc, struct sx150x_chip, gpio_chip);
297
298 if (offset >= chip->dev_cfg->ngpios)
299 return -EINVAL;
300
301 if (chip->irq_base < 0)
302 return -EINVAL;
303
304 return chip->irq_base + offset;
305}
306
307static void sx150x_irq_mask(unsigned int irq)
308{
309 struct irq_chip *ic = get_irq_chip(irq);
310 struct sx150x_chip *chip;
311 unsigned n;
312
313 chip = container_of(ic, struct sx150x_chip, irq_chip);
314 n = irq - chip->irq_base;
315
316 sx150x_write_cfg(chip, n, 1, chip->dev_cfg->reg_irq_mask, 1);
317 sx150x_write_cfg(chip, n, 2, chip->dev_cfg->reg_sense, 0);
318}
319
320static void sx150x_irq_unmask(unsigned int irq)
321{
322 struct irq_chip *ic = get_irq_chip(irq);
323 struct sx150x_chip *chip;
324 unsigned n;
325
326 chip = container_of(ic, struct sx150x_chip, irq_chip);
327 n = irq - chip->irq_base;
328
329 sx150x_write_cfg(chip, n, 1, chip->dev_cfg->reg_irq_mask, 0);
330 sx150x_write_cfg(chip, n, 2, chip->dev_cfg->reg_sense,
331 chip->irq_sense >> (n * 2));
332}
333
334static int sx150x_irq_set_type(unsigned int irq, unsigned int flow_type)
335{
336 struct irq_chip *ic = get_irq_chip(irq);
337 struct sx150x_chip *chip;
338 unsigned n, val = 0;
339
340 if (flow_type & (IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW))
341 return -EINVAL;
342
343 chip = container_of(ic, struct sx150x_chip, irq_chip);
344 n = irq - chip->irq_base;
345
346 if (flow_type & IRQ_TYPE_EDGE_RISING)
347 val |= 0x1;
348 if (flow_type & IRQ_TYPE_EDGE_FALLING)
349 val |= 0x2;
350
351 chip->irq_sense &= ~(3UL << (n * 2));
352 chip->irq_sense |= val << (n * 2);
353 chip->irq_set_type_pending |= BIT(n);
354 return 0;
355}
356
357static irqreturn_t sx150x_irq_thread_fn(int irq, void *dev_id)
358{
359 struct sx150x_chip *chip = (struct sx150x_chip *)dev_id;
360 unsigned nhandled = 0;
361 unsigned sub_irq;
362 unsigned n;
363 s32 err;
364 u8 val;
365 int i;
366
367 for (i = (chip->dev_cfg->ngpios / 8) - 1; i >= 0; --i) {
368 err = sx150x_i2c_read(chip->client,
369 chip->dev_cfg->reg_irq_src - i,
370 &val);
371 if (err < 0)
372 continue;
373
374 sx150x_i2c_write(chip->client,
375 chip->dev_cfg->reg_irq_src - i,
376 val);
377 for (n = 0; n < 8; ++n) {
378 if (val & (1 << n)) {
379 sub_irq = chip->irq_base + (i * 8) + n;
380 handle_nested_irq(sub_irq);
381 ++nhandled;
382 }
383 }
384 }
385
386 return (nhandled > 0 ? IRQ_HANDLED : IRQ_NONE);
387}
388
389static void sx150x_irq_bus_lock(unsigned int irq)
390{
391 struct irq_chip *ic = get_irq_chip(irq);
392 struct sx150x_chip *chip;
393
394 chip = container_of(ic, struct sx150x_chip, irq_chip);
395
396 mutex_lock(&chip->lock);
397}
398
399static void sx150x_irq_bus_sync_unlock(unsigned int irq)
400{
401 struct irq_chip *ic = get_irq_chip(irq);
402 struct sx150x_chip *chip;
403 unsigned n;
404
405 chip = container_of(ic, struct sx150x_chip, irq_chip);
406
407 while (chip->irq_set_type_pending) {
408 n = __ffs(chip->irq_set_type_pending);
409 chip->irq_set_type_pending &= ~BIT(n);
410 if (!(irq_to_desc(n + chip->irq_base)->status & IRQ_MASKED))
411 sx150x_write_cfg(chip, n, 2,
412 chip->dev_cfg->reg_sense,
413 chip->irq_sense >> (n * 2));
414 }
415
416 mutex_unlock(&chip->lock);
417}
418
419static void sx150x_init_chip(struct sx150x_chip *chip,
420 struct i2c_client *client,
421 kernel_ulong_t driver_data,
422 struct sx150x_platform_data *pdata)
423{
424 mutex_init(&chip->lock);
425
426 chip->client = client;
427 chip->dev_cfg = &sx150x_devices[driver_data];
428 chip->gpio_chip.label = client->name;
429 chip->gpio_chip.direction_input = sx150x_gpio_direction_input;
430 chip->gpio_chip.direction_output = sx150x_gpio_direction_output;
431 chip->gpio_chip.get = sx150x_gpio_get;
432 chip->gpio_chip.set = sx150x_gpio_set;
433 chip->gpio_chip.to_irq = sx150x_gpio_to_irq;
434 chip->gpio_chip.base = pdata->gpio_base;
435 chip->gpio_chip.can_sleep = 1;
436 chip->gpio_chip.ngpio = chip->dev_cfg->ngpios;
437 if (pdata->oscio_is_gpo)
438 ++chip->gpio_chip.ngpio;
439
440 chip->irq_chip.name = client->name;
441 chip->irq_chip.mask = sx150x_irq_mask;
442 chip->irq_chip.unmask = sx150x_irq_unmask;
443 chip->irq_chip.set_type = sx150x_irq_set_type;
444 chip->irq_chip.bus_lock = sx150x_irq_bus_lock;
445 chip->irq_chip.bus_sync_unlock = sx150x_irq_bus_sync_unlock;
446 chip->irq_summary = -1;
447 chip->irq_base = -1;
448 chip->irq_sense = 0;
449 chip->irq_set_type_pending = 0;
450}
451
452static int sx150x_init_io(struct sx150x_chip *chip, u8 base, u16 cfg)
453{
454 int err = 0;
455 unsigned n;
456
457 for (n = 0; err >= 0 && n < (chip->dev_cfg->ngpios / 8); ++n)
458 err = sx150x_i2c_write(chip->client, base - n, cfg >> (n * 8));
459 return err;
460}
461
462static int sx150x_init_hw(struct sx150x_chip *chip,
463 struct sx150x_platform_data *pdata)
464{
465 int err = 0;
466
467 err = i2c_smbus_write_word_data(chip->client,
468 chip->dev_cfg->reg_reset,
469 0x3412);
470 if (err < 0)
471 return err;
472
473 err = sx150x_i2c_write(chip->client,
474 chip->dev_cfg->reg_misc,
475 0x01);
476 if (err < 0)
477 return err;
478
479 err = sx150x_init_io(chip, chip->dev_cfg->reg_pullup,
480 pdata->io_pullup_ena);
481 if (err < 0)
482 return err;
483
484 err = sx150x_init_io(chip, chip->dev_cfg->reg_pulldn,
485 pdata->io_pulldn_ena);
486 if (err < 0)
487 return err;
488
489 err = sx150x_init_io(chip, chip->dev_cfg->reg_drain,
490 pdata->io_open_drain_ena);
491 if (err < 0)
492 return err;
493
494 err = sx150x_init_io(chip, chip->dev_cfg->reg_polarity,
495 pdata->io_polarity);
496 if (err < 0)
497 return err;
498
499 if (pdata->oscio_is_gpo)
500 sx150x_set_oscio(chip, 0);
501
502 return err;
503}
504
505static int sx150x_install_irq_chip(struct sx150x_chip *chip,
506 int irq_summary,
507 int irq_base)
508{
509 int err;
510 unsigned n;
511 unsigned irq;
512
513 chip->irq_summary = irq_summary;
514 chip->irq_base = irq_base;
515
516 for (n = 0; n < chip->dev_cfg->ngpios; ++n) {
517 irq = irq_base + n;
518 set_irq_chip_and_handler(irq, &chip->irq_chip, handle_edge_irq);
519 set_irq_nested_thread(irq, 1);
520#ifdef CONFIG_ARM
521 set_irq_flags(irq, IRQF_VALID);
522#else
523 set_irq_noprobe(irq);
524#endif
525 }
526
527 err = request_threaded_irq(irq_summary,
528 NULL,
529 sx150x_irq_thread_fn,
530 IRQF_SHARED | IRQF_TRIGGER_FALLING,
531 chip->irq_chip.name,
532 chip);
533 if (err < 0) {
534 chip->irq_summary = -1;
535 chip->irq_base = -1;
536 }
537
538 return err;
539}
540
541static void sx150x_remove_irq_chip(struct sx150x_chip *chip)
542{
543 unsigned n;
544 unsigned irq;
545
546 free_irq(chip->irq_summary, chip);
547
548 for (n = 0; n < chip->dev_cfg->ngpios; ++n) {
549 irq = chip->irq_base + n;
550 set_irq_handler(irq, NULL);
551 set_irq_chip(irq, NULL);
552 }
553}
554
555static int __devinit sx150x_probe(struct i2c_client *client,
556 const struct i2c_device_id *id)
557{
558 static const u32 i2c_funcs = I2C_FUNC_SMBUS_BYTE_DATA |
559 I2C_FUNC_SMBUS_WRITE_WORD_DATA;
560 struct sx150x_platform_data *pdata;
561 struct sx150x_chip *chip;
562 int rc;
563
564 pdata = client->dev.platform_data;
565 if (!pdata)
566 return -EINVAL;
567
568 if (!i2c_check_functionality(client->adapter, i2c_funcs))
569 return -ENOSYS;
570
571 chip = kzalloc(sizeof(struct sx150x_chip), GFP_KERNEL);
572 if (!chip)
573 return -ENOMEM;
574
575 sx150x_init_chip(chip, client, id->driver_data, pdata);
576 rc = sx150x_init_hw(chip, pdata);
577 if (rc < 0)
578 goto probe_fail_pre_gpiochip_add;
579
580 rc = gpiochip_add(&chip->gpio_chip);
581 if (rc < 0)
582 goto probe_fail_pre_gpiochip_add;
583
584 if (pdata->irq_summary >= 0) {
585 rc = sx150x_install_irq_chip(chip,
586 pdata->irq_summary,
587 pdata->irq_base);
588 if (rc < 0)
589 goto probe_fail_post_gpiochip_add;
590 }
591
592 i2c_set_clientdata(client, chip);
593
594 return 0;
595probe_fail_post_gpiochip_add:
596 WARN_ON(gpiochip_remove(&chip->gpio_chip) < 0);
597probe_fail_pre_gpiochip_add:
598 kfree(chip);
599 return rc;
600}
601
602static int __devexit sx150x_remove(struct i2c_client *client)
603{
604 struct sx150x_chip *chip;
605 int rc;
606
607 chip = i2c_get_clientdata(client);
608 rc = gpiochip_remove(&chip->gpio_chip);
609 if (rc < 0)
610 return rc;
611
612 if (chip->irq_summary >= 0)
613 sx150x_remove_irq_chip(chip);
614
615 kfree(chip);
616
617 return 0;
618}
619
620static struct i2c_driver sx150x_driver = {
621 .driver = {
622 .name = "sx150x",
623 .owner = THIS_MODULE
624 },
625 .probe = sx150x_probe,
626 .remove = __devexit_p(sx150x_remove),
627 .id_table = sx150x_id,
628};
629
630static int __init sx150x_init(void)
631{
632 return i2c_add_driver(&sx150x_driver);
633}
634subsys_initcall(sx150x_init);
635
636static void __exit sx150x_exit(void)
637{
638 return i2c_del_driver(&sx150x_driver);
639}
640module_exit(sx150x_exit);
641
642MODULE_AUTHOR("Gregory Bean <gbean@codeaurora.org>");
643MODULE_DESCRIPTION("Driver for Semtech SX150X I2C GPIO Expanders");
644MODULE_LICENSE("GPL v2");
645MODULE_ALIAS("i2c:sx150x");
diff --git a/drivers/gpio/wm831x-gpio.c b/drivers/gpio/wm831x-gpio.c
index 1fa449a1a4cb..309644cf4d9b 100644
--- a/drivers/gpio/wm831x-gpio.c
+++ b/drivers/gpio/wm831x-gpio.c
@@ -108,6 +108,37 @@ static int wm831x_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
108 return wm831x->irq_base + WM831X_IRQ_GPIO_1 + offset; 108 return wm831x->irq_base + WM831X_IRQ_GPIO_1 + offset;
109} 109}
110 110
111static int wm831x_gpio_set_debounce(struct gpio_chip *chip, unsigned offset,
112 unsigned debounce)
113{
114 struct wm831x_gpio *wm831x_gpio = to_wm831x_gpio(chip);
115 struct wm831x *wm831x = wm831x_gpio->wm831x;
116 int reg = WM831X_GPIO1_CONTROL + offset;
117 int ret, fn;
118
119 ret = wm831x_reg_read(wm831x, reg);
120 if (ret < 0)
121 return ret;
122
123 switch (ret & WM831X_GPN_FN_MASK) {
124 case 0:
125 case 1:
126 break;
127 default:
128 /* Not in GPIO mode */
129 return -EBUSY;
130 }
131
132 if (debounce >= 32 && debounce <= 64)
133 fn = 0;
134 else if (debounce >= 4000 && debounce <= 8000)
135 fn = 1;
136 else
137 return -EINVAL;
138
139 return wm831x_set_bits(wm831x, reg, WM831X_GPN_FN_MASK, fn);
140}
141
111#ifdef CONFIG_DEBUG_FS 142#ifdef CONFIG_DEBUG_FS
112static void wm831x_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip) 143static void wm831x_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
113{ 144{
@@ -208,6 +239,7 @@ static struct gpio_chip template_chip = {
208 .direction_output = wm831x_gpio_direction_out, 239 .direction_output = wm831x_gpio_direction_out,
209 .set = wm831x_gpio_set, 240 .set = wm831x_gpio_set,
210 .to_irq = wm831x_gpio_to_irq, 241 .to_irq = wm831x_gpio_to_irq,
242 .set_debounce = wm831x_gpio_set_debounce,
211 .dbg_show = wm831x_gpio_dbg_show, 243 .dbg_show = wm831x_gpio_dbg_show,
212 .can_sleep = 1, 244 .can_sleep = 1,
213}; 245};
diff --git a/drivers/gpu/drm/ati_pcigart.c b/drivers/gpu/drm/ati_pcigart.c
index 17be051b7aa3..1c3649242208 100644
--- a/drivers/gpu/drm/ati_pcigart.c
+++ b/drivers/gpu/drm/ati_pcigart.c
@@ -152,7 +152,7 @@ int drm_ati_pcigart_init(struct drm_device *dev, struct drm_ati_pcigart_info *ga
152 /* we need to support large memory configurations */ 152 /* we need to support large memory configurations */
153 entry->busaddr[i] = pci_map_page(dev->pdev, entry->pagelist[i], 153 entry->busaddr[i] = pci_map_page(dev->pdev, entry->pagelist[i],
154 0, PAGE_SIZE, PCI_DMA_BIDIRECTIONAL); 154 0, PAGE_SIZE, PCI_DMA_BIDIRECTIONAL);
155 if (entry->busaddr[i] == 0) { 155 if (pci_dma_mapping_error(dev->pdev, entry->busaddr[i])) {
156 DRM_ERROR("unable to map PCIGART pages!\n"); 156 DRM_ERROR("unable to map PCIGART pages!\n");
157 drm_ati_pcigart_cleanup(dev, gart_info); 157 drm_ati_pcigart_cleanup(dev, gart_info);
158 address = NULL; 158 address = NULL;
diff --git a/drivers/gpu/drm/drm_bufs.c b/drivers/gpu/drm/drm_bufs.c
index a5c9ce93bbcb..3e257a50bf56 100644
--- a/drivers/gpu/drm/drm_bufs.c
+++ b/drivers/gpu/drm/drm_bufs.c
@@ -328,14 +328,13 @@ static int drm_addmap_core(struct drm_device * dev, resource_size_t offset,
328 return -EINVAL; 328 return -EINVAL;
329 } 329 }
330 330
331 list = kmalloc(sizeof(*list), GFP_KERNEL); 331 list = kzalloc(sizeof(*list), GFP_KERNEL);
332 if (!list) { 332 if (!list) {
333 if (map->type == _DRM_REGISTERS) 333 if (map->type == _DRM_REGISTERS)
334 iounmap(map->handle); 334 iounmap(map->handle);
335 kfree(map); 335 kfree(map);
336 return -EINVAL; 336 return -EINVAL;
337 } 337 }
338 memset(list, 0, sizeof(*list));
339 list->map = map; 338 list->map = map;
340 339
341 mutex_lock(&dev->struct_mutex); 340 mutex_lock(&dev->struct_mutex);
@@ -678,13 +677,12 @@ int drm_addbufs_agp(struct drm_device * dev, struct drm_buf_desc * request)
678 return -EINVAL; 677 return -EINVAL;
679 } 678 }
680 679
681 entry->buflist = kmalloc(count * sizeof(*entry->buflist), GFP_KERNEL); 680 entry->buflist = kzalloc(count * sizeof(*entry->buflist), GFP_KERNEL);
682 if (!entry->buflist) { 681 if (!entry->buflist) {
683 mutex_unlock(&dev->struct_mutex); 682 mutex_unlock(&dev->struct_mutex);
684 atomic_dec(&dev->buf_alloc); 683 atomic_dec(&dev->buf_alloc);
685 return -ENOMEM; 684 return -ENOMEM;
686 } 685 }
687 memset(entry->buflist, 0, count * sizeof(*entry->buflist));
688 686
689 entry->buf_size = size; 687 entry->buf_size = size;
690 entry->page_order = page_order; 688 entry->page_order = page_order;
@@ -708,7 +706,7 @@ int drm_addbufs_agp(struct drm_device * dev, struct drm_buf_desc * request)
708 buf->file_priv = NULL; 706 buf->file_priv = NULL;
709 707
710 buf->dev_priv_size = dev->driver->dev_priv_size; 708 buf->dev_priv_size = dev->driver->dev_priv_size;
711 buf->dev_private = kmalloc(buf->dev_priv_size, GFP_KERNEL); 709 buf->dev_private = kzalloc(buf->dev_priv_size, GFP_KERNEL);
712 if (!buf->dev_private) { 710 if (!buf->dev_private) {
713 /* Set count correctly so we free the proper amount. */ 711 /* Set count correctly so we free the proper amount. */
714 entry->buf_count = count; 712 entry->buf_count = count;
@@ -717,7 +715,6 @@ int drm_addbufs_agp(struct drm_device * dev, struct drm_buf_desc * request)
717 atomic_dec(&dev->buf_alloc); 715 atomic_dec(&dev->buf_alloc);
718 return -ENOMEM; 716 return -ENOMEM;
719 } 717 }
720 memset(buf->dev_private, 0, buf->dev_priv_size);
721 718
722 DRM_DEBUG("buffer %d @ %p\n", entry->buf_count, buf->address); 719 DRM_DEBUG("buffer %d @ %p\n", entry->buf_count, buf->address);
723 720
@@ -832,22 +829,20 @@ int drm_addbufs_pci(struct drm_device * dev, struct drm_buf_desc * request)
832 return -EINVAL; 829 return -EINVAL;
833 } 830 }
834 831
835 entry->buflist = kmalloc(count * sizeof(*entry->buflist), GFP_KERNEL); 832 entry->buflist = kzalloc(count * sizeof(*entry->buflist), GFP_KERNEL);
836 if (!entry->buflist) { 833 if (!entry->buflist) {
837 mutex_unlock(&dev->struct_mutex); 834 mutex_unlock(&dev->struct_mutex);
838 atomic_dec(&dev->buf_alloc); 835 atomic_dec(&dev->buf_alloc);
839 return -ENOMEM; 836 return -ENOMEM;
840 } 837 }
841 memset(entry->buflist, 0, count * sizeof(*entry->buflist));
842 838
843 entry->seglist = kmalloc(count * sizeof(*entry->seglist), GFP_KERNEL); 839 entry->seglist = kzalloc(count * sizeof(*entry->seglist), GFP_KERNEL);
844 if (!entry->seglist) { 840 if (!entry->seglist) {
845 kfree(entry->buflist); 841 kfree(entry->buflist);
846 mutex_unlock(&dev->struct_mutex); 842 mutex_unlock(&dev->struct_mutex);
847 atomic_dec(&dev->buf_alloc); 843 atomic_dec(&dev->buf_alloc);
848 return -ENOMEM; 844 return -ENOMEM;
849 } 845 }
850 memset(entry->seglist, 0, count * sizeof(*entry->seglist));
851 846
852 /* Keep the original pagelist until we know all the allocations 847 /* Keep the original pagelist until we know all the allocations
853 * have succeeded 848 * have succeeded
@@ -911,8 +906,8 @@ int drm_addbufs_pci(struct drm_device * dev, struct drm_buf_desc * request)
911 buf->file_priv = NULL; 906 buf->file_priv = NULL;
912 907
913 buf->dev_priv_size = dev->driver->dev_priv_size; 908 buf->dev_priv_size = dev->driver->dev_priv_size;
914 buf->dev_private = kmalloc(buf->dev_priv_size, 909 buf->dev_private = kzalloc(buf->dev_priv_size,
915 GFP_KERNEL); 910 GFP_KERNEL);
916 if (!buf->dev_private) { 911 if (!buf->dev_private) {
917 /* Set count correctly so we free the proper amount. */ 912 /* Set count correctly so we free the proper amount. */
918 entry->buf_count = count; 913 entry->buf_count = count;
@@ -923,7 +918,6 @@ int drm_addbufs_pci(struct drm_device * dev, struct drm_buf_desc * request)
923 atomic_dec(&dev->buf_alloc); 918 atomic_dec(&dev->buf_alloc);
924 return -ENOMEM; 919 return -ENOMEM;
925 } 920 }
926 memset(buf->dev_private, 0, buf->dev_priv_size);
927 921
928 DRM_DEBUG("buffer %d @ %p\n", 922 DRM_DEBUG("buffer %d @ %p\n",
929 entry->buf_count, buf->address); 923 entry->buf_count, buf->address);
@@ -1048,14 +1042,13 @@ static int drm_addbufs_sg(struct drm_device * dev, struct drm_buf_desc * request
1048 return -EINVAL; 1042 return -EINVAL;
1049 } 1043 }
1050 1044
1051 entry->buflist = kmalloc(count * sizeof(*entry->buflist), 1045 entry->buflist = kzalloc(count * sizeof(*entry->buflist),
1052 GFP_KERNEL); 1046 GFP_KERNEL);
1053 if (!entry->buflist) { 1047 if (!entry->buflist) {
1054 mutex_unlock(&dev->struct_mutex); 1048 mutex_unlock(&dev->struct_mutex);
1055 atomic_dec(&dev->buf_alloc); 1049 atomic_dec(&dev->buf_alloc);
1056 return -ENOMEM; 1050 return -ENOMEM;
1057 } 1051 }
1058 memset(entry->buflist, 0, count * sizeof(*entry->buflist));
1059 1052
1060 entry->buf_size = size; 1053 entry->buf_size = size;
1061 entry->page_order = page_order; 1054 entry->page_order = page_order;
@@ -1080,7 +1073,7 @@ static int drm_addbufs_sg(struct drm_device * dev, struct drm_buf_desc * request
1080 buf->file_priv = NULL; 1073 buf->file_priv = NULL;
1081 1074
1082 buf->dev_priv_size = dev->driver->dev_priv_size; 1075 buf->dev_priv_size = dev->driver->dev_priv_size;
1083 buf->dev_private = kmalloc(buf->dev_priv_size, GFP_KERNEL); 1076 buf->dev_private = kzalloc(buf->dev_priv_size, GFP_KERNEL);
1084 if (!buf->dev_private) { 1077 if (!buf->dev_private) {
1085 /* Set count correctly so we free the proper amount. */ 1078 /* Set count correctly so we free the proper amount. */
1086 entry->buf_count = count; 1079 entry->buf_count = count;
@@ -1090,8 +1083,6 @@ static int drm_addbufs_sg(struct drm_device * dev, struct drm_buf_desc * request
1090 return -ENOMEM; 1083 return -ENOMEM;
1091 } 1084 }
1092 1085
1093 memset(buf->dev_private, 0, buf->dev_priv_size);
1094
1095 DRM_DEBUG("buffer %d @ %p\n", entry->buf_count, buf->address); 1086 DRM_DEBUG("buffer %d @ %p\n", entry->buf_count, buf->address);
1096 1087
1097 offset += alignment; 1088 offset += alignment;
@@ -1209,14 +1200,13 @@ static int drm_addbufs_fb(struct drm_device * dev, struct drm_buf_desc * request
1209 return -EINVAL; 1200 return -EINVAL;
1210 } 1201 }
1211 1202
1212 entry->buflist = kmalloc(count * sizeof(*entry->buflist), 1203 entry->buflist = kzalloc(count * sizeof(*entry->buflist),
1213 GFP_KERNEL); 1204 GFP_KERNEL);
1214 if (!entry->buflist) { 1205 if (!entry->buflist) {
1215 mutex_unlock(&dev->struct_mutex); 1206 mutex_unlock(&dev->struct_mutex);
1216 atomic_dec(&dev->buf_alloc); 1207 atomic_dec(&dev->buf_alloc);
1217 return -ENOMEM; 1208 return -ENOMEM;
1218 } 1209 }
1219 memset(entry->buflist, 0, count * sizeof(*entry->buflist));
1220 1210
1221 entry->buf_size = size; 1211 entry->buf_size = size;
1222 entry->page_order = page_order; 1212 entry->page_order = page_order;
@@ -1240,7 +1230,7 @@ static int drm_addbufs_fb(struct drm_device * dev, struct drm_buf_desc * request
1240 buf->file_priv = NULL; 1230 buf->file_priv = NULL;
1241 1231
1242 buf->dev_priv_size = dev->driver->dev_priv_size; 1232 buf->dev_priv_size = dev->driver->dev_priv_size;
1243 buf->dev_private = kmalloc(buf->dev_priv_size, GFP_KERNEL); 1233 buf->dev_private = kzalloc(buf->dev_priv_size, GFP_KERNEL);
1244 if (!buf->dev_private) { 1234 if (!buf->dev_private) {
1245 /* Set count correctly so we free the proper amount. */ 1235 /* Set count correctly so we free the proper amount. */
1246 entry->buf_count = count; 1236 entry->buf_count = count;
@@ -1249,7 +1239,6 @@ static int drm_addbufs_fb(struct drm_device * dev, struct drm_buf_desc * request
1249 atomic_dec(&dev->buf_alloc); 1239 atomic_dec(&dev->buf_alloc);
1250 return -ENOMEM; 1240 return -ENOMEM;
1251 } 1241 }
1252 memset(buf->dev_private, 0, buf->dev_priv_size);
1253 1242
1254 DRM_DEBUG("buffer %d @ %p\n", entry->buf_count, buf->address); 1243 DRM_DEBUG("buffer %d @ %p\n", entry->buf_count, buf->address);
1255 1244
diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
index 4c68f76993d8..37e0b4fa482a 100644
--- a/drivers/gpu/drm/drm_crtc.c
+++ b/drivers/gpu/drm/drm_crtc.c
@@ -1682,9 +1682,9 @@ int drm_mode_addfb(struct drm_device *dev,
1682 /* TODO setup destructor callback */ 1682 /* TODO setup destructor callback */
1683 1683
1684 fb = dev->mode_config.funcs->fb_create(dev, file_priv, r); 1684 fb = dev->mode_config.funcs->fb_create(dev, file_priv, r);
1685 if (!fb) { 1685 if (IS_ERR(fb)) {
1686 DRM_ERROR("could not create framebuffer\n"); 1686 DRM_ERROR("could not create framebuffer\n");
1687 ret = -EINVAL; 1687 ret = PTR_ERR(fb);
1688 goto out; 1688 goto out;
1689 } 1689 }
1690 1690
@@ -2541,7 +2541,7 @@ int drm_mode_gamma_set_ioctl(struct drm_device *dev,
2541 goto out; 2541 goto out;
2542 } 2542 }
2543 2543
2544 crtc->funcs->gamma_set(crtc, r_base, g_base, b_base, crtc->gamma_size); 2544 crtc->funcs->gamma_set(crtc, r_base, g_base, b_base, 0, crtc->gamma_size);
2545 2545
2546out: 2546out:
2547 mutex_unlock(&dev->mode_config.mutex); 2547 mutex_unlock(&dev->mode_config.mutex);
diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
index 45981304feb8..7e31d4348340 100644
--- a/drivers/gpu/drm/drm_crtc_helper.c
+++ b/drivers/gpu/drm/drm_crtc_helper.c
@@ -817,12 +817,12 @@ int drm_helper_resume_force_mode(struct drm_device *dev)
817 if (encoder_funcs->dpms) 817 if (encoder_funcs->dpms)
818 (*encoder_funcs->dpms) (encoder, 818 (*encoder_funcs->dpms) (encoder,
819 drm_helper_choose_encoder_dpms(encoder)); 819 drm_helper_choose_encoder_dpms(encoder));
820
821 crtc_funcs = crtc->helper_private;
822 if (crtc_funcs->dpms)
823 (*crtc_funcs->dpms) (crtc,
824 drm_helper_choose_crtc_dpms(crtc));
825 } 820 }
821
822 crtc_funcs = crtc->helper_private;
823 if (crtc_funcs->dpms)
824 (*crtc_funcs->dpms) (crtc,
825 drm_helper_choose_crtc_dpms(crtc));
826 } 826 }
827 } 827 }
828 /* disable the unused connectors while restoring the modesetting */ 828 /* disable the unused connectors while restoring the modesetting */
@@ -839,7 +839,6 @@ static void output_poll_execute(struct work_struct *work)
839 struct drm_connector *connector; 839 struct drm_connector *connector;
840 enum drm_connector_status old_status, status; 840 enum drm_connector_status old_status, status;
841 bool repoll = false, changed = false; 841 bool repoll = false, changed = false;
842 int ret;
843 842
844 mutex_lock(&dev->mode_config.mutex); 843 mutex_lock(&dev->mode_config.mutex);
845 list_for_each_entry(connector, &dev->mode_config.connector_list, head) { 844 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
@@ -874,11 +873,8 @@ static void output_poll_execute(struct work_struct *work)
874 dev->mode_config.funcs->output_poll_changed(dev); 873 dev->mode_config.funcs->output_poll_changed(dev);
875 } 874 }
876 875
877 if (repoll) { 876 if (repoll)
878 ret = queue_delayed_work(system_nrt_wq, delayed_work, DRM_OUTPUT_POLL_PERIOD); 877 queue_delayed_work(system_nrt_wq, delayed_work, DRM_OUTPUT_POLL_PERIOD);
879 if (ret)
880 DRM_ERROR("delayed enqueue failed %d\n", ret);
881 }
882} 878}
883 879
884void drm_kms_helper_poll_disable(struct drm_device *dev) 880void drm_kms_helper_poll_disable(struct drm_device *dev)
@@ -893,18 +889,14 @@ void drm_kms_helper_poll_enable(struct drm_device *dev)
893{ 889{
894 bool poll = false; 890 bool poll = false;
895 struct drm_connector *connector; 891 struct drm_connector *connector;
896 int ret;
897 892
898 list_for_each_entry(connector, &dev->mode_config.connector_list, head) { 893 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
899 if (connector->polled) 894 if (connector->polled)
900 poll = true; 895 poll = true;
901 } 896 }
902 897
903 if (poll) { 898 if (poll)
904 ret = queue_delayed_work(system_nrt_wq, &dev->mode_config.output_poll_work, DRM_OUTPUT_POLL_PERIOD); 899 queue_delayed_work(system_nrt_wq, &dev->mode_config.output_poll_work, DRM_OUTPUT_POLL_PERIOD);
905 if (ret)
906 DRM_ERROR("delayed enqueue failed %d\n", ret);
907 }
908} 900}
909EXPORT_SYMBOL(drm_kms_helper_poll_enable); 901EXPORT_SYMBOL(drm_kms_helper_poll_enable);
910 902
diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
index dce5c4a97f8d..96e963108225 100644
--- a/drivers/gpu/drm/drm_edid.c
+++ b/drivers/gpu/drm/drm_edid.c
@@ -33,6 +33,11 @@
33#include <linux/i2c-algo-bit.h> 33#include <linux/i2c-algo-bit.h>
34#include "drmP.h" 34#include "drmP.h"
35#include "drm_edid.h" 35#include "drm_edid.h"
36#include "drm_edid_modes.h"
37
38#define version_greater(edid, maj, min) \
39 (((edid)->version > (maj)) || \
40 ((edid)->version == (maj) && (edid)->revision > (min)))
36 41
37#define EDID_EST_TIMINGS 16 42#define EDID_EST_TIMINGS 16
38#define EDID_STD_TIMINGS 8 43#define EDID_STD_TIMINGS 8
@@ -62,6 +67,13 @@
62/* use +hsync +vsync for detailed mode */ 67/* use +hsync +vsync for detailed mode */
63#define EDID_QUIRK_DETAILED_SYNC_PP (1 << 6) 68#define EDID_QUIRK_DETAILED_SYNC_PP (1 << 6)
64 69
70struct detailed_mode_closure {
71 struct drm_connector *connector;
72 struct edid *edid;
73 bool preferred;
74 u32 quirks;
75 int modes;
76};
65 77
66#define LEVEL_DMT 0 78#define LEVEL_DMT 0
67#define LEVEL_GTF 1 79#define LEVEL_GTF 1
@@ -375,7 +387,6 @@ static u32 edid_get_quirks(struct edid *edid)
375#define MODE_SIZE(m) ((m)->hdisplay * (m)->vdisplay) 387#define MODE_SIZE(m) ((m)->hdisplay * (m)->vdisplay)
376#define MODE_REFRESH_DIFF(m,r) (abs((m)->vrefresh - target_refresh)) 388#define MODE_REFRESH_DIFF(m,r) (abs((m)->vrefresh - target_refresh))
377 389
378
379/** 390/**
380 * edid_fixup_preferred - set preferred modes based on quirk list 391 * edid_fixup_preferred - set preferred modes based on quirk list
381 * @connector: has mode list to fix up 392 * @connector: has mode list to fix up
@@ -422,245 +433,6 @@ static void edid_fixup_preferred(struct drm_connector *connector,
422 preferred_mode->type |= DRM_MODE_TYPE_PREFERRED; 433 preferred_mode->type |= DRM_MODE_TYPE_PREFERRED;
423} 434}
424 435
425/*
426 * Add the Autogenerated from the DMT spec.
427 * This table is copied from xfree86/modes/xf86EdidModes.c.
428 * But the mode with Reduced blank feature is deleted.
429 */
430static struct drm_display_mode drm_dmt_modes[] = {
431 /* 640x350@85Hz */
432 { DRM_MODE("640x350", DRM_MODE_TYPE_DRIVER, 31500, 640, 672,
433 736, 832, 0, 350, 382, 385, 445, 0,
434 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
435 /* 640x400@85Hz */
436 { DRM_MODE("640x400", DRM_MODE_TYPE_DRIVER, 31500, 640, 672,
437 736, 832, 0, 400, 401, 404, 445, 0,
438 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
439 /* 720x400@85Hz */
440 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 35500, 720, 756,
441 828, 936, 0, 400, 401, 404, 446, 0,
442 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
443 /* 640x480@60Hz */
444 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656,
445 752, 800, 0, 480, 489, 492, 525, 0,
446 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
447 /* 640x480@72Hz */
448 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 664,
449 704, 832, 0, 480, 489, 492, 520, 0,
450 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
451 /* 640x480@75Hz */
452 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 656,
453 720, 840, 0, 480, 481, 484, 500, 0,
454 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
455 /* 640x480@85Hz */
456 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 36000, 640, 696,
457 752, 832, 0, 480, 481, 484, 509, 0,
458 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
459 /* 800x600@56Hz */
460 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 36000, 800, 824,
461 896, 1024, 0, 600, 601, 603, 625, 0,
462 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
463 /* 800x600@60Hz */
464 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 40000, 800, 840,
465 968, 1056, 0, 600, 601, 605, 628, 0,
466 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
467 /* 800x600@72Hz */
468 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 50000, 800, 856,
469 976, 1040, 0, 600, 637, 643, 666, 0,
470 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
471 /* 800x600@75Hz */
472 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 49500, 800, 816,
473 896, 1056, 0, 600, 601, 604, 625, 0,
474 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
475 /* 800x600@85Hz */
476 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 56250, 800, 832,
477 896, 1048, 0, 600, 601, 604, 631, 0,
478 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
479 /* 848x480@60Hz */
480 { DRM_MODE("848x480", DRM_MODE_TYPE_DRIVER, 33750, 848, 864,
481 976, 1088, 0, 480, 486, 494, 517, 0,
482 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
483 /* 1024x768@43Hz, interlace */
484 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 44900, 1024, 1032,
485 1208, 1264, 0, 768, 768, 772, 817, 0,
486 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
487 DRM_MODE_FLAG_INTERLACE) },
488 /* 1024x768@60Hz */
489 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024, 1048,
490 1184, 1344, 0, 768, 771, 777, 806, 0,
491 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
492 /* 1024x768@70Hz */
493 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 75000, 1024, 1048,
494 1184, 1328, 0, 768, 771, 777, 806, 0,
495 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
496 /* 1024x768@75Hz */
497 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 78750, 1024, 1040,
498 1136, 1312, 0, 768, 769, 772, 800, 0,
499 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
500 /* 1024x768@85Hz */
501 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 94500, 1024, 1072,
502 1168, 1376, 0, 768, 769, 772, 808, 0,
503 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
504 /* 1152x864@75Hz */
505 { DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER, 108000, 1152, 1216,
506 1344, 1600, 0, 864, 865, 868, 900, 0,
507 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
508 /* 1280x768@60Hz */
509 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 79500, 1280, 1344,
510 1472, 1664, 0, 768, 771, 778, 798, 0,
511 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
512 /* 1280x768@75Hz */
513 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 102250, 1280, 1360,
514 1488, 1696, 0, 768, 771, 778, 805, 0,
515 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
516 /* 1280x768@85Hz */
517 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 117500, 1280, 1360,
518 1496, 1712, 0, 768, 771, 778, 809, 0,
519 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
520 /* 1280x800@60Hz */
521 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 83500, 1280, 1352,
522 1480, 1680, 0, 800, 803, 809, 831, 0,
523 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
524 /* 1280x800@75Hz */
525 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 106500, 1280, 1360,
526 1488, 1696, 0, 800, 803, 809, 838, 0,
527 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
528 /* 1280x800@85Hz */
529 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 122500, 1280, 1360,
530 1496, 1712, 0, 800, 803, 809, 843, 0,
531 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
532 /* 1280x960@60Hz */
533 { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1376,
534 1488, 1800, 0, 960, 961, 964, 1000, 0,
535 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
536 /* 1280x960@85Hz */
537 { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1344,
538 1504, 1728, 0, 960, 961, 964, 1011, 0,
539 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
540 /* 1280x1024@60Hz */
541 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1328,
542 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
543 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
544 /* 1280x1024@75Hz */
545 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 135000, 1280, 1296,
546 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
547 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
548 /* 1280x1024@85Hz */
549 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 157500, 1280, 1344,
550 1504, 1728, 0, 1024, 1025, 1028, 1072, 0,
551 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
552 /* 1360x768@60Hz */
553 { DRM_MODE("1360x768", DRM_MODE_TYPE_DRIVER, 85500, 1360, 1424,
554 1536, 1792, 0, 768, 771, 777, 795, 0,
555 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
556 /* 1440x1050@60Hz */
557 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 121750, 1400, 1488,
558 1632, 1864, 0, 1050, 1053, 1057, 1089, 0,
559 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
560 /* 1440x1050@75Hz */
561 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 156000, 1400, 1504,
562 1648, 1896, 0, 1050, 1053, 1057, 1099, 0,
563 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
564 /* 1440x1050@85Hz */
565 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 179500, 1400, 1504,
566 1656, 1912, 0, 1050, 1053, 1057, 1105, 0,
567 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
568 /* 1440x900@60Hz */
569 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 106500, 1440, 1520,
570 1672, 1904, 0, 900, 903, 909, 934, 0,
571 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
572 /* 1440x900@75Hz */
573 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 136750, 1440, 1536,
574 1688, 1936, 0, 900, 903, 909, 942, 0,
575 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
576 /* 1440x900@85Hz */
577 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 157000, 1440, 1544,
578 1696, 1952, 0, 900, 903, 909, 948, 0,
579 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
580 /* 1600x1200@60Hz */
581 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 162000, 1600, 1664,
582 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
583 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
584 /* 1600x1200@65Hz */
585 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 175500, 1600, 1664,
586 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
587 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
588 /* 1600x1200@70Hz */
589 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 189000, 1600, 1664,
590 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
591 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
592 /* 1600x1200@75Hz */
593 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 202500, 1600, 1664,
594 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
595 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
596 /* 1600x1200@85Hz */
597 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 229500, 1600, 1664,
598 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
599 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
600 /* 1680x1050@60Hz */
601 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 146250, 1680, 1784,
602 1960, 2240, 0, 1050, 1053, 1059, 1089, 0,
603 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
604 /* 1680x1050@75Hz */
605 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 187000, 1680, 1800,
606 1976, 2272, 0, 1050, 1053, 1059, 1099, 0,
607 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
608 /* 1680x1050@85Hz */
609 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 214750, 1680, 1808,
610 1984, 2288, 0, 1050, 1053, 1059, 1105, 0,
611 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
612 /* 1792x1344@60Hz */
613 { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 204750, 1792, 1920,
614 2120, 2448, 0, 1344, 1345, 1348, 1394, 0,
615 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
616 /* 1729x1344@75Hz */
617 { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 261000, 1792, 1888,
618 2104, 2456, 0, 1344, 1345, 1348, 1417, 0,
619 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
620 /* 1853x1392@60Hz */
621 { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 218250, 1856, 1952,
622 2176, 2528, 0, 1392, 1393, 1396, 1439, 0,
623 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
624 /* 1856x1392@75Hz */
625 { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 288000, 1856, 1984,
626 2208, 2560, 0, 1392, 1395, 1399, 1500, 0,
627 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
628 /* 1920x1200@60Hz */
629 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 193250, 1920, 2056,
630 2256, 2592, 0, 1200, 1203, 1209, 1245, 0,
631 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
632 /* 1920x1200@75Hz */
633 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 245250, 1920, 2056,
634 2264, 2608, 0, 1200, 1203, 1209, 1255, 0,
635 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
636 /* 1920x1200@85Hz */
637 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 281250, 1920, 2064,
638 2272, 2624, 0, 1200, 1203, 1209, 1262, 0,
639 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
640 /* 1920x1440@60Hz */
641 { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 234000, 1920, 2048,
642 2256, 2600, 0, 1440, 1441, 1444, 1500, 0,
643 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
644 /* 1920x1440@75Hz */
645 { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2064,
646 2288, 2640, 0, 1440, 1441, 1444, 1500, 0,
647 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
648 /* 2560x1600@60Hz */
649 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 348500, 2560, 2752,
650 3032, 3504, 0, 1600, 1603, 1609, 1658, 0,
651 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
652 /* 2560x1600@75HZ */
653 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 443250, 2560, 2768,
654 3048, 3536, 0, 1600, 1603, 1609, 1672, 0,
655 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
656 /* 2560x1600@85HZ */
657 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 505250, 2560, 2768,
658 3048, 3536, 0, 1600, 1603, 1609, 1682, 0,
659 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
660};
661static const int drm_num_dmt_modes =
662 sizeof(drm_dmt_modes) / sizeof(struct drm_display_mode);
663
664struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev, 436struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
665 int hsize, int vsize, int fresh) 437 int hsize, int vsize, int fresh)
666{ 438{
@@ -685,6 +457,46 @@ EXPORT_SYMBOL(drm_mode_find_dmt);
685typedef void detailed_cb(struct detailed_timing *timing, void *closure); 457typedef void detailed_cb(struct detailed_timing *timing, void *closure);
686 458
687static void 459static void
460cea_for_each_detailed_block(u8 *ext, detailed_cb *cb, void *closure)
461{
462 int i, n = 0;
463 u8 rev = ext[0x01], d = ext[0x02];
464 u8 *det_base = ext + d;
465
466 switch (rev) {
467 case 0:
468 /* can't happen */
469 return;
470 case 1:
471 /* have to infer how many blocks we have, check pixel clock */
472 for (i = 0; i < 6; i++)
473 if (det_base[18*i] || det_base[18*i+1])
474 n++;
475 break;
476 default:
477 /* explicit count */
478 n = min(ext[0x03] & 0x0f, 6);
479 break;
480 }
481
482 for (i = 0; i < n; i++)
483 cb((struct detailed_timing *)(det_base + 18 * i), closure);
484}
485
486static void
487vtb_for_each_detailed_block(u8 *ext, detailed_cb *cb, void *closure)
488{
489 unsigned int i, n = min((int)ext[0x02], 6);
490 u8 *det_base = ext + 5;
491
492 if (ext[0x01] != 1)
493 return; /* unknown version */
494
495 for (i = 0; i < n; i++)
496 cb((struct detailed_timing *)(det_base + 18 * i), closure);
497}
498
499static void
688drm_for_each_detailed_block(u8 *raw_edid, detailed_cb *cb, void *closure) 500drm_for_each_detailed_block(u8 *raw_edid, detailed_cb *cb, void *closure)
689{ 501{
690 int i; 502 int i;
@@ -696,7 +508,19 @@ drm_for_each_detailed_block(u8 *raw_edid, detailed_cb *cb, void *closure)
696 for (i = 0; i < EDID_DETAILED_TIMINGS; i++) 508 for (i = 0; i < EDID_DETAILED_TIMINGS; i++)
697 cb(&(edid->detailed_timings[i]), closure); 509 cb(&(edid->detailed_timings[i]), closure);
698 510
699 /* XXX extension block walk */ 511 for (i = 1; i <= raw_edid[0x7e]; i++) {
512 u8 *ext = raw_edid + (i * EDID_LENGTH);
513 switch (*ext) {
514 case CEA_EXT:
515 cea_for_each_detailed_block(ext, cb, closure);
516 break;
517 case VTB_EXT:
518 vtb_for_each_detailed_block(ext, cb, closure);
519 break;
520 default:
521 break;
522 }
523 }
700} 524}
701 525
702static void 526static void
@@ -1047,117 +871,6 @@ static struct drm_display_mode *drm_mode_detailed(struct drm_device *dev,
1047 return mode; 871 return mode;
1048} 872}
1049 873
1050/*
1051 * Detailed mode info for the EDID "established modes" data to use.
1052 */
1053static struct drm_display_mode edid_est_modes[] = {
1054 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 40000, 800, 840,
1055 968, 1056, 0, 600, 601, 605, 628, 0,
1056 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@60Hz */
1057 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 36000, 800, 824,
1058 896, 1024, 0, 600, 601, 603, 625, 0,
1059 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@56Hz */
1060 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 656,
1061 720, 840, 0, 480, 481, 484, 500, 0,
1062 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@75Hz */
1063 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 664,
1064 704, 832, 0, 480, 489, 491, 520, 0,
1065 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@72Hz */
1066 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 30240, 640, 704,
1067 768, 864, 0, 480, 483, 486, 525, 0,
1068 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@67Hz */
1069 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25200, 640, 656,
1070 752, 800, 0, 480, 490, 492, 525, 0,
1071 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@60Hz */
1072 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 35500, 720, 738,
1073 846, 900, 0, 400, 421, 423, 449, 0,
1074 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 720x400@88Hz */
1075 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 28320, 720, 738,
1076 846, 900, 0, 400, 412, 414, 449, 0,
1077 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 720x400@70Hz */
1078 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 135000, 1280, 1296,
1079 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
1080 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1280x1024@75Hz */
1081 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 78800, 1024, 1040,
1082 1136, 1312, 0, 768, 769, 772, 800, 0,
1083 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1024x768@75Hz */
1084 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 75000, 1024, 1048,
1085 1184, 1328, 0, 768, 771, 777, 806, 0,
1086 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 1024x768@70Hz */
1087 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024, 1048,
1088 1184, 1344, 0, 768, 771, 777, 806, 0,
1089 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 1024x768@60Hz */
1090 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER,44900, 1024, 1032,
1091 1208, 1264, 0, 768, 768, 776, 817, 0,
1092 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_INTERLACE) }, /* 1024x768@43Hz */
1093 { DRM_MODE("832x624", DRM_MODE_TYPE_DRIVER, 57284, 832, 864,
1094 928, 1152, 0, 624, 625, 628, 667, 0,
1095 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 832x624@75Hz */
1096 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 49500, 800, 816,
1097 896, 1056, 0, 600, 601, 604, 625, 0,
1098 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@75Hz */
1099 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 50000, 800, 856,
1100 976, 1040, 0, 600, 637, 643, 666, 0,
1101 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@72Hz */
1102 { DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER, 108000, 1152, 1216,
1103 1344, 1600, 0, 864, 865, 868, 900, 0,
1104 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1152x864@75Hz */
1105};
1106
1107/**
1108 * add_established_modes - get est. modes from EDID and add them
1109 * @edid: EDID block to scan
1110 *
1111 * Each EDID block contains a bitmap of the supported "established modes" list
1112 * (defined above). Tease them out and add them to the global modes list.
1113 */
1114static int add_established_modes(struct drm_connector *connector, struct edid *edid)
1115{
1116 struct drm_device *dev = connector->dev;
1117 unsigned long est_bits = edid->established_timings.t1 |
1118 (edid->established_timings.t2 << 8) |
1119 ((edid->established_timings.mfg_rsvd & 0x80) << 9);
1120 int i, modes = 0;
1121
1122 for (i = 0; i <= EDID_EST_TIMINGS; i++)
1123 if (est_bits & (1<<i)) {
1124 struct drm_display_mode *newmode;
1125 newmode = drm_mode_duplicate(dev, &edid_est_modes[i]);
1126 if (newmode) {
1127 drm_mode_probed_add(connector, newmode);
1128 modes++;
1129 }
1130 }
1131
1132 return modes;
1133}
1134
1135/**
1136 * add_standard_modes - get std. modes from EDID and add them
1137 * @edid: EDID block to scan
1138 *
1139 * Standard modes can be calculated using the CVT standard. Grab them from
1140 * @edid, calculate them, and add them to the list.
1141 */
1142static int add_standard_modes(struct drm_connector *connector, struct edid *edid)
1143{
1144 int i, modes = 0;
1145
1146 for (i = 0; i < EDID_STD_TIMINGS; i++) {
1147 struct drm_display_mode *newmode;
1148
1149 newmode = drm_mode_std(connector, edid,
1150 &edid->standard_timings[i],
1151 edid->revision);
1152 if (newmode) {
1153 drm_mode_probed_add(connector, newmode);
1154 modes++;
1155 }
1156 }
1157
1158 return modes;
1159}
1160
1161static bool 874static bool
1162mode_is_rb(struct drm_display_mode *mode) 875mode_is_rb(struct drm_display_mode *mode)
1163{ 876{
@@ -1267,113 +980,33 @@ drm_gtf_modes_for_range(struct drm_connector *connector, struct edid *edid,
1267 return modes; 980 return modes;
1268} 981}
1269 982
1270static int drm_cvt_modes(struct drm_connector *connector, 983static void
1271 struct detailed_timing *timing) 984do_inferred_modes(struct detailed_timing *timing, void *c)
1272{ 985{
1273 int i, j, modes = 0; 986 struct detailed_mode_closure *closure = c;
1274 struct drm_display_mode *newmode; 987 struct detailed_non_pixel *data = &timing->data.other_data;
1275 struct drm_device *dev = connector->dev; 988 int gtf = (closure->edid->features & DRM_EDID_FEATURE_DEFAULT_GTF);
1276 struct cvt_timing *cvt;
1277 const int rates[] = { 60, 85, 75, 60, 50 };
1278 const u8 empty[3] = { 0, 0, 0 };
1279
1280 for (i = 0; i < 4; i++) {
1281 int uninitialized_var(width), height;
1282 cvt = &(timing->data.other_data.data.cvt[i]);
1283 989
1284 if (!memcmp(cvt->code, empty, 3)) 990 if (gtf && data->type == EDID_DETAIL_MONITOR_RANGE)
1285 continue; 991 closure->modes += drm_gtf_modes_for_range(closure->connector,
992 closure->edid,
993 timing);
994}
1286 995
1287 height = (cvt->code[0] + ((cvt->code[1] & 0xf0) << 4) + 1) * 2; 996static int
1288 switch (cvt->code[1] & 0x0c) { 997add_inferred_modes(struct drm_connector *connector, struct edid *edid)
1289 case 0x00: 998{
1290 width = height * 4 / 3; 999 struct detailed_mode_closure closure = {
1291 break; 1000 connector, edid, 0, 0, 0
1292 case 0x04: 1001 };
1293 width = height * 16 / 9;
1294 break;
1295 case 0x08:
1296 width = height * 16 / 10;
1297 break;
1298 case 0x0c:
1299 width = height * 15 / 9;
1300 break;
1301 }
1302 1002
1303 for (j = 1; j < 5; j++) { 1003 if (version_greater(edid, 1, 0))
1304 if (cvt->code[2] & (1 << j)) { 1004 drm_for_each_detailed_block((u8 *)edid, do_inferred_modes,
1305 newmode = drm_cvt_mode(dev, width, height, 1005 &closure);
1306 rates[j], j == 0,
1307 false, false);
1308 if (newmode) {
1309 drm_mode_probed_add(connector, newmode);
1310 modes++;
1311 }
1312 }
1313 }
1314 }
1315 1006
1316 return modes; 1007 return closure.modes;
1317} 1008}
1318 1009
1319static const struct {
1320 short w;
1321 short h;
1322 short r;
1323 short rb;
1324} est3_modes[] = {
1325 /* byte 6 */
1326 { 640, 350, 85, 0 },
1327 { 640, 400, 85, 0 },
1328 { 720, 400, 85, 0 },
1329 { 640, 480, 85, 0 },
1330 { 848, 480, 60, 0 },
1331 { 800, 600, 85, 0 },
1332 { 1024, 768, 85, 0 },
1333 { 1152, 864, 75, 0 },
1334 /* byte 7 */
1335 { 1280, 768, 60, 1 },
1336 { 1280, 768, 60, 0 },
1337 { 1280, 768, 75, 0 },
1338 { 1280, 768, 85, 0 },
1339 { 1280, 960, 60, 0 },
1340 { 1280, 960, 85, 0 },
1341 { 1280, 1024, 60, 0 },
1342 { 1280, 1024, 85, 0 },
1343 /* byte 8 */
1344 { 1360, 768, 60, 0 },
1345 { 1440, 900, 60, 1 },
1346 { 1440, 900, 60, 0 },
1347 { 1440, 900, 75, 0 },
1348 { 1440, 900, 85, 0 },
1349 { 1400, 1050, 60, 1 },
1350 { 1400, 1050, 60, 0 },
1351 { 1400, 1050, 75, 0 },
1352 /* byte 9 */
1353 { 1400, 1050, 85, 0 },
1354 { 1680, 1050, 60, 1 },
1355 { 1680, 1050, 60, 0 },
1356 { 1680, 1050, 75, 0 },
1357 { 1680, 1050, 85, 0 },
1358 { 1600, 1200, 60, 0 },
1359 { 1600, 1200, 65, 0 },
1360 { 1600, 1200, 70, 0 },
1361 /* byte 10 */
1362 { 1600, 1200, 75, 0 },
1363 { 1600, 1200, 85, 0 },
1364 { 1792, 1344, 60, 0 },
1365 { 1792, 1344, 85, 0 },
1366 { 1856, 1392, 60, 0 },
1367 { 1856, 1392, 75, 0 },
1368 { 1920, 1200, 60, 1 },
1369 { 1920, 1200, 60, 0 },
1370 /* byte 11 */
1371 { 1920, 1200, 75, 0 },
1372 { 1920, 1200, 85, 0 },
1373 { 1920, 1440, 60, 0 },
1374 { 1920, 1440, 75, 0 },
1375};
1376
1377static int 1010static int
1378drm_est3_modes(struct drm_connector *connector, struct detailed_timing *timing) 1011drm_est3_modes(struct drm_connector *connector, struct detailed_timing *timing)
1379{ 1012{
@@ -1403,37 +1036,63 @@ drm_est3_modes(struct drm_connector *connector, struct detailed_timing *timing)
1403 return modes; 1036 return modes;
1404} 1037}
1405 1038
1406static int add_detailed_modes(struct drm_connector *connector, 1039static void
1407 struct detailed_timing *timing, 1040do_established_modes(struct detailed_timing *timing, void *c)
1408 struct edid *edid, u32 quirks, int preferred)
1409{ 1041{
1410 int i, modes = 0; 1042 struct detailed_mode_closure *closure = c;
1411 struct detailed_non_pixel *data = &timing->data.other_data; 1043 struct detailed_non_pixel *data = &timing->data.other_data;
1412 int gtf = (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF);
1413 struct drm_display_mode *newmode;
1414 struct drm_device *dev = connector->dev;
1415 1044
1416 if (timing->pixel_clock) { 1045 if (data->type == EDID_DETAIL_EST_TIMINGS)
1417 newmode = drm_mode_detailed(dev, edid, timing, quirks); 1046 closure->modes += drm_est3_modes(closure->connector, timing);
1418 if (!newmode) 1047}
1419 return 0;
1420 1048
1421 if (preferred) 1049/**
1422 newmode->type |= DRM_MODE_TYPE_PREFERRED; 1050 * add_established_modes - get est. modes from EDID and add them
1051 * @edid: EDID block to scan
1052 *
1053 * Each EDID block contains a bitmap of the supported "established modes" list
1054 * (defined above). Tease them out and add them to the global modes list.
1055 */
1056static int
1057add_established_modes(struct drm_connector *connector, struct edid *edid)
1058{
1059 struct drm_device *dev = connector->dev;
1060 unsigned long est_bits = edid->established_timings.t1 |
1061 (edid->established_timings.t2 << 8) |
1062 ((edid->established_timings.mfg_rsvd & 0x80) << 9);
1063 int i, modes = 0;
1064 struct detailed_mode_closure closure = {
1065 connector, edid, 0, 0, 0
1066 };
1423 1067
1424 drm_mode_probed_add(connector, newmode); 1068 for (i = 0; i <= EDID_EST_TIMINGS; i++) {
1425 return 1; 1069 if (est_bits & (1<<i)) {
1070 struct drm_display_mode *newmode;
1071 newmode = drm_mode_duplicate(dev, &edid_est_modes[i]);
1072 if (newmode) {
1073 drm_mode_probed_add(connector, newmode);
1074 modes++;
1075 }
1076 }
1426 } 1077 }
1427 1078
1428 /* other timing types */ 1079 if (version_greater(edid, 1, 0))
1429 switch (data->type) { 1080 drm_for_each_detailed_block((u8 *)edid,
1430 case EDID_DETAIL_MONITOR_RANGE: 1081 do_established_modes, &closure);
1431 if (gtf) 1082
1432 modes += drm_gtf_modes_for_range(connector, edid, 1083 return modes + closure.modes;
1433 timing); 1084}
1434 break; 1085
1435 case EDID_DETAIL_STD_MODES: 1086static void
1436 /* Six modes per detailed section */ 1087do_standard_modes(struct detailed_timing *timing, void *c)
1088{
1089 struct detailed_mode_closure *closure = c;
1090 struct detailed_non_pixel *data = &timing->data.other_data;
1091 struct drm_connector *connector = closure->connector;
1092 struct edid *edid = closure->edid;
1093
1094 if (data->type == EDID_DETAIL_STD_MODES) {
1095 int i;
1437 for (i = 0; i < 6; i++) { 1096 for (i = 0; i < 6; i++) {
1438 struct std_timing *std; 1097 struct std_timing *std;
1439 struct drm_display_mode *newmode; 1098 struct drm_display_mode *newmode;
@@ -1443,108 +1102,169 @@ static int add_detailed_modes(struct drm_connector *connector,
1443 edid->revision); 1102 edid->revision);
1444 if (newmode) { 1103 if (newmode) {
1445 drm_mode_probed_add(connector, newmode); 1104 drm_mode_probed_add(connector, newmode);
1446 modes++; 1105 closure->modes++;
1447 } 1106 }
1448 } 1107 }
1449 break;
1450 case EDID_DETAIL_CVT_3BYTE:
1451 modes += drm_cvt_modes(connector, timing);
1452 break;
1453 case EDID_DETAIL_EST_TIMINGS:
1454 modes += drm_est3_modes(connector, timing);
1455 break;
1456 default:
1457 break;
1458 } 1108 }
1459
1460 return modes;
1461} 1109}
1462 1110
1463/** 1111/**
1464 * add_detailed_info - get detailed mode info from EDID data 1112 * add_standard_modes - get std. modes from EDID and add them
1465 * @connector: attached connector
1466 * @edid: EDID block to scan 1113 * @edid: EDID block to scan
1467 * @quirks: quirks to apply
1468 * 1114 *
1469 * Some of the detailed timing sections may contain mode information. Grab 1115 * Standard modes can be calculated using the appropriate standard (DMT,
1470 * it and add it to the list. 1116 * GTF or CVT. Grab them from @edid and add them to the list.
1471 */ 1117 */
1472static int add_detailed_info(struct drm_connector *connector, 1118static int
1473 struct edid *edid, u32 quirks) 1119add_standard_modes(struct drm_connector *connector, struct edid *edid)
1474{ 1120{
1475 int i, modes = 0; 1121 int i, modes = 0;
1122 struct detailed_mode_closure closure = {
1123 connector, edid, 0, 0, 0
1124 };
1125
1126 for (i = 0; i < EDID_STD_TIMINGS; i++) {
1127 struct drm_display_mode *newmode;
1128
1129 newmode = drm_mode_std(connector, edid,
1130 &edid->standard_timings[i],
1131 edid->revision);
1132 if (newmode) {
1133 drm_mode_probed_add(connector, newmode);
1134 modes++;
1135 }
1136 }
1137
1138 if (version_greater(edid, 1, 0))
1139 drm_for_each_detailed_block((u8 *)edid, do_standard_modes,
1140 &closure);
1141
1142 /* XXX should also look for standard codes in VTB blocks */
1143
1144 return modes + closure.modes;
1145}
1476 1146
1477 for (i = 0; i < EDID_DETAILED_TIMINGS; i++) { 1147static int drm_cvt_modes(struct drm_connector *connector,
1478 struct detailed_timing *timing = &edid->detailed_timings[i]; 1148 struct detailed_timing *timing)
1479 int preferred = (i == 0); 1149{
1150 int i, j, modes = 0;
1151 struct drm_display_mode *newmode;
1152 struct drm_device *dev = connector->dev;
1153 struct cvt_timing *cvt;
1154 const int rates[] = { 60, 85, 75, 60, 50 };
1155 const u8 empty[3] = { 0, 0, 0 };
1480 1156
1481 if (preferred && edid->version == 1 && edid->revision < 4) 1157 for (i = 0; i < 4; i++) {
1482 preferred = (edid->features & DRM_EDID_FEATURE_PREFERRED_TIMING); 1158 int uninitialized_var(width), height;
1159 cvt = &(timing->data.other_data.data.cvt[i]);
1483 1160
1484 /* In 1.0, only timings are allowed */ 1161 if (!memcmp(cvt->code, empty, 3))
1485 if (!timing->pixel_clock && edid->version == 1 &&
1486 edid->revision == 0)
1487 continue; 1162 continue;
1488 1163
1489 modes += add_detailed_modes(connector, timing, edid, quirks, 1164 height = (cvt->code[0] + ((cvt->code[1] & 0xf0) << 4) + 1) * 2;
1490 preferred); 1165 switch (cvt->code[1] & 0x0c) {
1166 case 0x00:
1167 width = height * 4 / 3;
1168 break;
1169 case 0x04:
1170 width = height * 16 / 9;
1171 break;
1172 case 0x08:
1173 width = height * 16 / 10;
1174 break;
1175 case 0x0c:
1176 width = height * 15 / 9;
1177 break;
1178 }
1179
1180 for (j = 1; j < 5; j++) {
1181 if (cvt->code[2] & (1 << j)) {
1182 newmode = drm_cvt_mode(dev, width, height,
1183 rates[j], j == 0,
1184 false, false);
1185 if (newmode) {
1186 drm_mode_probed_add(connector, newmode);
1187 modes++;
1188 }
1189 }
1190 }
1491 } 1191 }
1492 1192
1493 return modes; 1193 return modes;
1494} 1194}
1495 1195
1496/** 1196static void
1497 * add_detailed_mode_eedid - get detailed mode info from addtional timing 1197do_cvt_mode(struct detailed_timing *timing, void *c)
1498 * EDID block
1499 * @connector: attached connector
1500 * @edid: EDID block to scan(It is only to get addtional timing EDID block)
1501 * @quirks: quirks to apply
1502 *
1503 * Some of the detailed timing sections may contain mode information. Grab
1504 * it and add it to the list.
1505 */
1506static int add_detailed_info_eedid(struct drm_connector *connector,
1507 struct edid *edid, u32 quirks)
1508{ 1198{
1509 int i, modes = 0; 1199 struct detailed_mode_closure *closure = c;
1510 char *edid_ext = NULL; 1200 struct detailed_non_pixel *data = &timing->data.other_data;
1511 struct detailed_timing *timing;
1512 int start_offset, end_offset;
1513 1201
1514 if (edid->version == 1 && edid->revision < 3) 1202 if (data->type == EDID_DETAIL_CVT_3BYTE)
1515 return 0; 1203 closure->modes += drm_cvt_modes(closure->connector, timing);
1516 if (!edid->extensions) 1204}
1517 return 0;
1518 1205
1519 /* Find CEA extension */ 1206static int
1520 for (i = 0; i < edid->extensions; i++) { 1207add_cvt_modes(struct drm_connector *connector, struct edid *edid)
1521 edid_ext = (char *)edid + EDID_LENGTH * (i + 1); 1208{
1522 if (edid_ext[0] == 0x02) 1209 struct detailed_mode_closure closure = {
1523 break; 1210 connector, edid, 0, 0, 0
1524 } 1211 };
1525 1212
1526 if (i == edid->extensions) 1213 if (version_greater(edid, 1, 2))
1527 return 0; 1214 drm_for_each_detailed_block((u8 *)edid, do_cvt_mode, &closure);
1528 1215
1529 /* Get the start offset of detailed timing block */ 1216 /* XXX should also look for CVT codes in VTB blocks */
1530 start_offset = edid_ext[2];
1531 if (start_offset == 0) {
1532 /* If the start_offset is zero, it means that neither detailed
1533 * info nor data block exist. In such case it is also
1534 * unnecessary to parse the detailed timing info.
1535 */
1536 return 0;
1537 }
1538 1217
1539 end_offset = EDID_LENGTH; 1218 return closure.modes;
1540 end_offset -= sizeof(struct detailed_timing); 1219}
1541 for (i = start_offset; i < end_offset; 1220
1542 i += sizeof(struct detailed_timing)) { 1221static void
1543 timing = (struct detailed_timing *)(edid_ext + i); 1222do_detailed_mode(struct detailed_timing *timing, void *c)
1544 modes += add_detailed_modes(connector, timing, edid, quirks, 0); 1223{
1224 struct detailed_mode_closure *closure = c;
1225 struct drm_display_mode *newmode;
1226
1227 if (timing->pixel_clock) {
1228 newmode = drm_mode_detailed(closure->connector->dev,
1229 closure->edid, timing,
1230 closure->quirks);
1231 if (!newmode)
1232 return;
1233
1234 if (closure->preferred)
1235 newmode->type |= DRM_MODE_TYPE_PREFERRED;
1236
1237 drm_mode_probed_add(closure->connector, newmode);
1238 closure->modes++;
1239 closure->preferred = 0;
1545 } 1240 }
1241}
1546 1242
1547 return modes; 1243/*
1244 * add_detailed_modes - Add modes from detailed timings
1245 * @connector: attached connector
1246 * @edid: EDID block to scan
1247 * @quirks: quirks to apply
1248 */
1249static int
1250add_detailed_modes(struct drm_connector *connector, struct edid *edid,
1251 u32 quirks)
1252{
1253 struct detailed_mode_closure closure = {
1254 connector,
1255 edid,
1256 1,
1257 quirks,
1258 0
1259 };
1260
1261 if (closure.preferred && !version_greater(edid, 1, 3))
1262 closure.preferred =
1263 (edid->features & DRM_EDID_FEATURE_PREFERRED_TIMING);
1264
1265 drm_for_each_detailed_block((u8 *)edid, do_detailed_mode, &closure);
1266
1267 return closure.modes;
1548} 1268}
1549 1269
1550#define HDMI_IDENTIFIER 0x000C03 1270#define HDMI_IDENTIFIER 0x000C03
@@ -1640,35 +1360,21 @@ int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid)
1640 * - established timing codes 1360 * - established timing codes
1641 * - modes inferred from GTF or CVT range information 1361 * - modes inferred from GTF or CVT range information
1642 * 1362 *
1643 * We don't quite implement this yet, but we're close. 1363 * We get this pretty much right.
1644 * 1364 *
1645 * XXX order for additional mode types in extension blocks? 1365 * XXX order for additional mode types in extension blocks?
1646 */ 1366 */
1647 num_modes += add_detailed_info(connector, edid, quirks); 1367 num_modes += add_detailed_modes(connector, edid, quirks);
1648 num_modes += add_detailed_info_eedid(connector, edid, quirks); 1368 num_modes += add_cvt_modes(connector, edid);
1649 num_modes += add_standard_modes(connector, edid); 1369 num_modes += add_standard_modes(connector, edid);
1650 num_modes += add_established_modes(connector, edid); 1370 num_modes += add_established_modes(connector, edid);
1371 num_modes += add_inferred_modes(connector, edid);
1651 1372
1652 if (quirks & (EDID_QUIRK_PREFER_LARGE_60 | EDID_QUIRK_PREFER_LARGE_75)) 1373 if (quirks & (EDID_QUIRK_PREFER_LARGE_60 | EDID_QUIRK_PREFER_LARGE_75))
1653 edid_fixup_preferred(connector, quirks); 1374 edid_fixup_preferred(connector, quirks);
1654 1375
1655 connector->display_info.serration_vsync = (edid->input & DRM_EDID_INPUT_SERRATION_VSYNC) ? 1 : 0;
1656 connector->display_info.sync_on_green = (edid->input & DRM_EDID_INPUT_SYNC_ON_GREEN) ? 1 : 0;
1657 connector->display_info.composite_sync = (edid->input & DRM_EDID_INPUT_COMPOSITE_SYNC) ? 1 : 0;
1658 connector->display_info.separate_syncs = (edid->input & DRM_EDID_INPUT_SEPARATE_SYNCS) ? 1 : 0;
1659 connector->display_info.blank_to_black = (edid->input & DRM_EDID_INPUT_BLANK_TO_BLACK) ? 1 : 0;
1660 connector->display_info.video_level = (edid->input & DRM_EDID_INPUT_VIDEO_LEVEL) >> 5;
1661 connector->display_info.digital = (edid->input & DRM_EDID_INPUT_DIGITAL) ? 1 : 0;
1662 connector->display_info.width_mm = edid->width_cm * 10; 1376 connector->display_info.width_mm = edid->width_cm * 10;
1663 connector->display_info.height_mm = edid->height_cm * 10; 1377 connector->display_info.height_mm = edid->height_cm * 10;
1664 connector->display_info.gamma = edid->gamma;
1665 connector->display_info.gtf_supported = (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF) ? 1 : 0;
1666 connector->display_info.standard_color = (edid->features & DRM_EDID_FEATURE_STANDARD_COLOR) ? 1 : 0;
1667 connector->display_info.display_type = (edid->features & DRM_EDID_FEATURE_DISPLAY_TYPE) >> 3;
1668 connector->display_info.active_off_supported = (edid->features & DRM_EDID_FEATURE_PM_ACTIVE_OFF) ? 1 : 0;
1669 connector->display_info.suspend_supported = (edid->features & DRM_EDID_FEATURE_PM_SUSPEND) ? 1 : 0;
1670 connector->display_info.standby_supported = (edid->features & DRM_EDID_FEATURE_PM_STANDBY) ? 1 : 0;
1671 connector->display_info.gamma = edid->gamma;
1672 1378
1673 return num_modes; 1379 return num_modes;
1674} 1380}
diff --git a/drivers/gpu/drm/drm_edid_modes.h b/drivers/gpu/drm/drm_edid_modes.h
new file mode 100644
index 000000000000..6eb7592e152f
--- /dev/null
+++ b/drivers/gpu/drm/drm_edid_modes.h
@@ -0,0 +1,380 @@
1/*
2 * Copyright (c) 2007-2008 Intel Corporation
3 * Jesse Barnes <jesse.barnes@intel.com>
4 * Copyright 2010 Red Hat, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sub license,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
15 * of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
24 */
25
26#include <linux/kernel.h>
27#include "drmP.h"
28#include "drm_edid.h"
29
30/*
31 * Autogenerated from the DMT spec.
32 * This table is copied from xfree86/modes/xf86EdidModes.c.
33 * But the mode with Reduced blank feature is deleted.
34 */
35static struct drm_display_mode drm_dmt_modes[] = {
36 /* 640x350@85Hz */
37 { DRM_MODE("640x350", DRM_MODE_TYPE_DRIVER, 31500, 640, 672,
38 736, 832, 0, 350, 382, 385, 445, 0,
39 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
40 /* 640x400@85Hz */
41 { DRM_MODE("640x400", DRM_MODE_TYPE_DRIVER, 31500, 640, 672,
42 736, 832, 0, 400, 401, 404, 445, 0,
43 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
44 /* 720x400@85Hz */
45 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 35500, 720, 756,
46 828, 936, 0, 400, 401, 404, 446, 0,
47 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
48 /* 640x480@60Hz */
49 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656,
50 752, 800, 0, 480, 489, 492, 525, 0,
51 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
52 /* 640x480@72Hz */
53 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 664,
54 704, 832, 0, 480, 489, 492, 520, 0,
55 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
56 /* 640x480@75Hz */
57 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 656,
58 720, 840, 0, 480, 481, 484, 500, 0,
59 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
60 /* 640x480@85Hz */
61 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 36000, 640, 696,
62 752, 832, 0, 480, 481, 484, 509, 0,
63 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
64 /* 800x600@56Hz */
65 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 36000, 800, 824,
66 896, 1024, 0, 600, 601, 603, 625, 0,
67 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
68 /* 800x600@60Hz */
69 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 40000, 800, 840,
70 968, 1056, 0, 600, 601, 605, 628, 0,
71 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
72 /* 800x600@72Hz */
73 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 50000, 800, 856,
74 976, 1040, 0, 600, 637, 643, 666, 0,
75 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
76 /* 800x600@75Hz */
77 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 49500, 800, 816,
78 896, 1056, 0, 600, 601, 604, 625, 0,
79 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
80 /* 800x600@85Hz */
81 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 56250, 800, 832,
82 896, 1048, 0, 600, 601, 604, 631, 0,
83 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
84 /* 848x480@60Hz */
85 { DRM_MODE("848x480", DRM_MODE_TYPE_DRIVER, 33750, 848, 864,
86 976, 1088, 0, 480, 486, 494, 517, 0,
87 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
88 /* 1024x768@43Hz, interlace */
89 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 44900, 1024, 1032,
90 1208, 1264, 0, 768, 768, 772, 817, 0,
91 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
92 DRM_MODE_FLAG_INTERLACE) },
93 /* 1024x768@60Hz */
94 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024, 1048,
95 1184, 1344, 0, 768, 771, 777, 806, 0,
96 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
97 /* 1024x768@70Hz */
98 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 75000, 1024, 1048,
99 1184, 1328, 0, 768, 771, 777, 806, 0,
100 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
101 /* 1024x768@75Hz */
102 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 78750, 1024, 1040,
103 1136, 1312, 0, 768, 769, 772, 800, 0,
104 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
105 /* 1024x768@85Hz */
106 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 94500, 1024, 1072,
107 1168, 1376, 0, 768, 769, 772, 808, 0,
108 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
109 /* 1152x864@75Hz */
110 { DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER, 108000, 1152, 1216,
111 1344, 1600, 0, 864, 865, 868, 900, 0,
112 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
113 /* 1280x768@60Hz */
114 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 79500, 1280, 1344,
115 1472, 1664, 0, 768, 771, 778, 798, 0,
116 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
117 /* 1280x768@75Hz */
118 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 102250, 1280, 1360,
119 1488, 1696, 0, 768, 771, 778, 805, 0,
120 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
121 /* 1280x768@85Hz */
122 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 117500, 1280, 1360,
123 1496, 1712, 0, 768, 771, 778, 809, 0,
124 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
125 /* 1280x800@60Hz */
126 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 83500, 1280, 1352,
127 1480, 1680, 0, 800, 803, 809, 831, 0,
128 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
129 /* 1280x800@75Hz */
130 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 106500, 1280, 1360,
131 1488, 1696, 0, 800, 803, 809, 838, 0,
132 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
133 /* 1280x800@85Hz */
134 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 122500, 1280, 1360,
135 1496, 1712, 0, 800, 803, 809, 843, 0,
136 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
137 /* 1280x960@60Hz */
138 { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1376,
139 1488, 1800, 0, 960, 961, 964, 1000, 0,
140 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
141 /* 1280x960@85Hz */
142 { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1344,
143 1504, 1728, 0, 960, 961, 964, 1011, 0,
144 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
145 /* 1280x1024@60Hz */
146 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1328,
147 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
148 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
149 /* 1280x1024@75Hz */
150 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 135000, 1280, 1296,
151 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
152 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
153 /* 1280x1024@85Hz */
154 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 157500, 1280, 1344,
155 1504, 1728, 0, 1024, 1025, 1028, 1072, 0,
156 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
157 /* 1360x768@60Hz */
158 { DRM_MODE("1360x768", DRM_MODE_TYPE_DRIVER, 85500, 1360, 1424,
159 1536, 1792, 0, 768, 771, 777, 795, 0,
160 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
161 /* 1440x1050@60Hz */
162 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 121750, 1400, 1488,
163 1632, 1864, 0, 1050, 1053, 1057, 1089, 0,
164 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
165 /* 1440x1050@75Hz */
166 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 156000, 1400, 1504,
167 1648, 1896, 0, 1050, 1053, 1057, 1099, 0,
168 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
169 /* 1440x1050@85Hz */
170 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 179500, 1400, 1504,
171 1656, 1912, 0, 1050, 1053, 1057, 1105, 0,
172 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
173 /* 1440x900@60Hz */
174 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 106500, 1440, 1520,
175 1672, 1904, 0, 900, 903, 909, 934, 0,
176 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
177 /* 1440x900@75Hz */
178 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 136750, 1440, 1536,
179 1688, 1936, 0, 900, 903, 909, 942, 0,
180 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
181 /* 1440x900@85Hz */
182 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 157000, 1440, 1544,
183 1696, 1952, 0, 900, 903, 909, 948, 0,
184 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
185 /* 1600x1200@60Hz */
186 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 162000, 1600, 1664,
187 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
188 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
189 /* 1600x1200@65Hz */
190 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 175500, 1600, 1664,
191 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
192 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
193 /* 1600x1200@70Hz */
194 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 189000, 1600, 1664,
195 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
196 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
197 /* 1600x1200@75Hz */
198 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 202500, 1600, 1664,
199 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
200 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
201 /* 1600x1200@85Hz */
202 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 229500, 1600, 1664,
203 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
204 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
205 /* 1680x1050@60Hz */
206 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 146250, 1680, 1784,
207 1960, 2240, 0, 1050, 1053, 1059, 1089, 0,
208 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
209 /* 1680x1050@75Hz */
210 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 187000, 1680, 1800,
211 1976, 2272, 0, 1050, 1053, 1059, 1099, 0,
212 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
213 /* 1680x1050@85Hz */
214 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 214750, 1680, 1808,
215 1984, 2288, 0, 1050, 1053, 1059, 1105, 0,
216 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
217 /* 1792x1344@60Hz */
218 { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 204750, 1792, 1920,
219 2120, 2448, 0, 1344, 1345, 1348, 1394, 0,
220 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
221 /* 1729x1344@75Hz */
222 { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 261000, 1792, 1888,
223 2104, 2456, 0, 1344, 1345, 1348, 1417, 0,
224 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
225 /* 1853x1392@60Hz */
226 { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 218250, 1856, 1952,
227 2176, 2528, 0, 1392, 1393, 1396, 1439, 0,
228 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
229 /* 1856x1392@75Hz */
230 { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 288000, 1856, 1984,
231 2208, 2560, 0, 1392, 1395, 1399, 1500, 0,
232 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
233 /* 1920x1200@60Hz */
234 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 193250, 1920, 2056,
235 2256, 2592, 0, 1200, 1203, 1209, 1245, 0,
236 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
237 /* 1920x1200@75Hz */
238 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 245250, 1920, 2056,
239 2264, 2608, 0, 1200, 1203, 1209, 1255, 0,
240 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
241 /* 1920x1200@85Hz */
242 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 281250, 1920, 2064,
243 2272, 2624, 0, 1200, 1203, 1209, 1262, 0,
244 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
245 /* 1920x1440@60Hz */
246 { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 234000, 1920, 2048,
247 2256, 2600, 0, 1440, 1441, 1444, 1500, 0,
248 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
249 /* 1920x1440@75Hz */
250 { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2064,
251 2288, 2640, 0, 1440, 1441, 1444, 1500, 0,
252 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
253 /* 2560x1600@60Hz */
254 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 348500, 2560, 2752,
255 3032, 3504, 0, 1600, 1603, 1609, 1658, 0,
256 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
257 /* 2560x1600@75HZ */
258 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 443250, 2560, 2768,
259 3048, 3536, 0, 1600, 1603, 1609, 1672, 0,
260 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
261 /* 2560x1600@85HZ */
262 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 505250, 2560, 2768,
263 3048, 3536, 0, 1600, 1603, 1609, 1682, 0,
264 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
265};
266static const int drm_num_dmt_modes =
267 sizeof(drm_dmt_modes) / sizeof(struct drm_display_mode);
268
269static struct drm_display_mode edid_est_modes[] = {
270 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 40000, 800, 840,
271 968, 1056, 0, 600, 601, 605, 628, 0,
272 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@60Hz */
273 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 36000, 800, 824,
274 896, 1024, 0, 600, 601, 603, 625, 0,
275 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@56Hz */
276 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 656,
277 720, 840, 0, 480, 481, 484, 500, 0,
278 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@75Hz */
279 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 664,
280 704, 832, 0, 480, 489, 491, 520, 0,
281 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@72Hz */
282 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 30240, 640, 704,
283 768, 864, 0, 480, 483, 486, 525, 0,
284 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@67Hz */
285 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25200, 640, 656,
286 752, 800, 0, 480, 490, 492, 525, 0,
287 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@60Hz */
288 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 35500, 720, 738,
289 846, 900, 0, 400, 421, 423, 449, 0,
290 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 720x400@88Hz */
291 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 28320, 720, 738,
292 846, 900, 0, 400, 412, 414, 449, 0,
293 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 720x400@70Hz */
294 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 135000, 1280, 1296,
295 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
296 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1280x1024@75Hz */
297 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 78800, 1024, 1040,
298 1136, 1312, 0, 768, 769, 772, 800, 0,
299 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1024x768@75Hz */
300 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 75000, 1024, 1048,
301 1184, 1328, 0, 768, 771, 777, 806, 0,
302 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 1024x768@70Hz */
303 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024, 1048,
304 1184, 1344, 0, 768, 771, 777, 806, 0,
305 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 1024x768@60Hz */
306 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER,44900, 1024, 1032,
307 1208, 1264, 0, 768, 768, 776, 817, 0,
308 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_INTERLACE) }, /* 1024x768@43Hz */
309 { DRM_MODE("832x624", DRM_MODE_TYPE_DRIVER, 57284, 832, 864,
310 928, 1152, 0, 624, 625, 628, 667, 0,
311 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 832x624@75Hz */
312 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 49500, 800, 816,
313 896, 1056, 0, 600, 601, 604, 625, 0,
314 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@75Hz */
315 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 50000, 800, 856,
316 976, 1040, 0, 600, 637, 643, 666, 0,
317 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@72Hz */
318 { DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER, 108000, 1152, 1216,
319 1344, 1600, 0, 864, 865, 868, 900, 0,
320 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1152x864@75Hz */
321};
322
323static const struct {
324 short w;
325 short h;
326 short r;
327 short rb;
328} est3_modes[] = {
329 /* byte 6 */
330 { 640, 350, 85, 0 },
331 { 640, 400, 85, 0 },
332 { 720, 400, 85, 0 },
333 { 640, 480, 85, 0 },
334 { 848, 480, 60, 0 },
335 { 800, 600, 85, 0 },
336 { 1024, 768, 85, 0 },
337 { 1152, 864, 75, 0 },
338 /* byte 7 */
339 { 1280, 768, 60, 1 },
340 { 1280, 768, 60, 0 },
341 { 1280, 768, 75, 0 },
342 { 1280, 768, 85, 0 },
343 { 1280, 960, 60, 0 },
344 { 1280, 960, 85, 0 },
345 { 1280, 1024, 60, 0 },
346 { 1280, 1024, 85, 0 },
347 /* byte 8 */
348 { 1360, 768, 60, 0 },
349 { 1440, 900, 60, 1 },
350 { 1440, 900, 60, 0 },
351 { 1440, 900, 75, 0 },
352 { 1440, 900, 85, 0 },
353 { 1400, 1050, 60, 1 },
354 { 1400, 1050, 60, 0 },
355 { 1400, 1050, 75, 0 },
356 /* byte 9 */
357 { 1400, 1050, 85, 0 },
358 { 1680, 1050, 60, 1 },
359 { 1680, 1050, 60, 0 },
360 { 1680, 1050, 75, 0 },
361 { 1680, 1050, 85, 0 },
362 { 1600, 1200, 60, 0 },
363 { 1600, 1200, 65, 0 },
364 { 1600, 1200, 70, 0 },
365 /* byte 10 */
366 { 1600, 1200, 75, 0 },
367 { 1600, 1200, 85, 0 },
368 { 1792, 1344, 60, 0 },
369 { 1792, 1344, 85, 0 },
370 { 1856, 1392, 60, 0 },
371 { 1856, 1392, 75, 0 },
372 { 1920, 1200, 60, 1 },
373 { 1920, 1200, 60, 0 },
374 /* byte 11 */
375 { 1920, 1200, 75, 0 },
376 { 1920, 1200, 85, 0 },
377 { 1920, 1440, 60, 0 },
378 { 1920, 1440, 75, 0 },
379};
380static const int num_est3_modes = sizeof(est3_modes) / sizeof(est3_modes[0]);
diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
index 2ca8df8b6102..3a652a65546f 100644
--- a/drivers/gpu/drm/drm_fops.c
+++ b/drivers/gpu/drm/drm_fops.c
@@ -135,15 +135,9 @@ int drm_open(struct inode *inode, struct file *filp)
135 retcode = drm_open_helper(inode, filp, dev); 135 retcode = drm_open_helper(inode, filp, dev);
136 if (!retcode) { 136 if (!retcode) {
137 atomic_inc(&dev->counts[_DRM_STAT_OPENS]); 137 atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
138 spin_lock(&dev->count_lock); 138 if (!dev->open_count++)
139 if (!dev->open_count++) {
140 spin_unlock(&dev->count_lock);
141 retcode = drm_setup(dev); 139 retcode = drm_setup(dev);
142 goto out;
143 }
144 spin_unlock(&dev->count_lock);
145 } 140 }
146out:
147 if (!retcode) { 141 if (!retcode) {
148 mutex_lock(&dev->struct_mutex); 142 mutex_lock(&dev->struct_mutex);
149 if (minor->type == DRM_MINOR_LEGACY) { 143 if (minor->type == DRM_MINOR_LEGACY) {
@@ -570,18 +564,14 @@ int drm_release(struct inode *inode, struct file *filp)
570 */ 564 */
571 565
572 atomic_inc(&dev->counts[_DRM_STAT_CLOSES]); 566 atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
573 spin_lock(&dev->count_lock);
574 if (!--dev->open_count) { 567 if (!--dev->open_count) {
575 if (atomic_read(&dev->ioctl_count)) { 568 if (atomic_read(&dev->ioctl_count)) {
576 DRM_ERROR("Device busy: %d\n", 569 DRM_ERROR("Device busy: %d\n",
577 atomic_read(&dev->ioctl_count)); 570 atomic_read(&dev->ioctl_count));
578 retcode = -EBUSY; 571 retcode = -EBUSY;
579 goto out; 572 } else
580 } 573 retcode = drm_lastclose(dev);
581 retcode = drm_lastclose(dev);
582 } 574 }
583out:
584 spin_unlock(&dev->count_lock);
585 mutex_unlock(&drm_global_mutex); 575 mutex_unlock(&drm_global_mutex);
586 576
587 return retcode; 577 return retcode;
diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c
index 4f1b86714489..bf92d07510df 100644
--- a/drivers/gpu/drm/drm_gem.c
+++ b/drivers/gpu/drm/drm_gem.c
@@ -322,7 +322,7 @@ drm_gem_flink_ioctl(struct drm_device *dev, void *data,
322 322
323 obj = drm_gem_object_lookup(dev, file_priv, args->handle); 323 obj = drm_gem_object_lookup(dev, file_priv, args->handle);
324 if (obj == NULL) 324 if (obj == NULL)
325 return -EBADF; 325 return -ENOENT;
326 326
327again: 327again:
328 if (idr_pre_get(&dev->object_name_idr, GFP_KERNEL) == 0) { 328 if (idr_pre_get(&dev->object_name_idr, GFP_KERNEL) == 0) {
diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
index 7b03b197fc00..47db4df37a69 100644
--- a/drivers/gpu/drm/drm_ioctl.c
+++ b/drivers/gpu/drm/drm_ioctl.c
@@ -392,6 +392,7 @@ int drm_setversion(struct drm_device *dev, void *data, struct drm_file *file_pri
392 if (sv->drm_di_minor >= 1) { 392 if (sv->drm_di_minor >= 1) {
393 /* 393 /*
394 * Version 1.1 includes tying of DRM to specific device 394 * Version 1.1 includes tying of DRM to specific device
395 * Version 1.4 has proper PCI domain support
395 */ 396 */
396 retcode = drm_set_busid(dev, file_priv); 397 retcode = drm_set_busid(dev, file_priv);
397 if (retcode) 398 if (retcode)
diff --git a/drivers/gpu/drm/i2c/ch7006_drv.c b/drivers/gpu/drm/i2c/ch7006_drv.c
index 833b35f44a77..08792a740f18 100644
--- a/drivers/gpu/drm/i2c/ch7006_drv.c
+++ b/drivers/gpu/drm/i2c/ch7006_drv.c
@@ -470,6 +470,7 @@ static int ch7006_encoder_init(struct i2c_client *client,
470 priv->hmargin = 50; 470 priv->hmargin = 50;
471 priv->vmargin = 50; 471 priv->vmargin = 50;
472 priv->last_dpms = -1; 472 priv->last_dpms = -1;
473 priv->chip_version = ch7006_read(client, CH7006_VERSION_ID);
473 474
474 if (ch7006_tv_norm) { 475 if (ch7006_tv_norm) {
475 for (i = 0; i < NUM_TV_NORMS; i++) { 476 for (i = 0; i < NUM_TV_NORMS; i++) {
diff --git a/drivers/gpu/drm/i2c/ch7006_mode.c b/drivers/gpu/drm/i2c/ch7006_mode.c
index e447dfb63890..c860f24a5afc 100644
--- a/drivers/gpu/drm/i2c/ch7006_mode.c
+++ b/drivers/gpu/drm/i2c/ch7006_mode.c
@@ -316,7 +316,10 @@ void ch7006_setup_power_state(struct drm_encoder *encoder)
316 } 316 }
317 317
318 } else { 318 } else {
319 *power |= bitfs(CH7006_POWER_LEVEL, FULL_POWER_OFF); 319 if (priv->chip_version >= 0x20)
320 *power |= bitfs(CH7006_POWER_LEVEL, FULL_POWER_OFF);
321 else
322 *power |= bitfs(CH7006_POWER_LEVEL, POWER_OFF);
320 } 323 }
321} 324}
322 325
diff --git a/drivers/gpu/drm/i2c/ch7006_priv.h b/drivers/gpu/drm/i2c/ch7006_priv.h
index 1c6d2e3bd96f..17667b7d57e7 100644
--- a/drivers/gpu/drm/i2c/ch7006_priv.h
+++ b/drivers/gpu/drm/i2c/ch7006_priv.h
@@ -95,6 +95,7 @@ struct ch7006_priv {
95 int flicker; 95 int flicker;
96 int scale; 96 int scale;
97 97
98 int chip_version;
98 int last_dpms; 99 int last_dpms;
99}; 100};
100 101
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index 2a4ed7ca8b4e..0758c7802e6b 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -456,7 +456,7 @@ i915_gem_pread_ioctl(struct drm_device *dev, void *data,
456 456
457 obj = drm_gem_object_lookup(dev, file_priv, args->handle); 457 obj = drm_gem_object_lookup(dev, file_priv, args->handle);
458 if (obj == NULL) 458 if (obj == NULL)
459 return -EBADF; 459 return -ENOENT;
460 obj_priv = to_intel_bo(obj); 460 obj_priv = to_intel_bo(obj);
461 461
462 /* Bounds check source. 462 /* Bounds check source.
@@ -919,7 +919,7 @@ i915_gem_pwrite_ioctl(struct drm_device *dev, void *data,
919 919
920 obj = drm_gem_object_lookup(dev, file_priv, args->handle); 920 obj = drm_gem_object_lookup(dev, file_priv, args->handle);
921 if (obj == NULL) 921 if (obj == NULL)
922 return -EBADF; 922 return -ENOENT;
923 obj_priv = to_intel_bo(obj); 923 obj_priv = to_intel_bo(obj);
924 924
925 /* Bounds check destination. 925 /* Bounds check destination.
@@ -1002,7 +1002,7 @@ i915_gem_set_domain_ioctl(struct drm_device *dev, void *data,
1002 1002
1003 obj = drm_gem_object_lookup(dev, file_priv, args->handle); 1003 obj = drm_gem_object_lookup(dev, file_priv, args->handle);
1004 if (obj == NULL) 1004 if (obj == NULL)
1005 return -EBADF; 1005 return -ENOENT;
1006 obj_priv = to_intel_bo(obj); 1006 obj_priv = to_intel_bo(obj);
1007 1007
1008 mutex_lock(&dev->struct_mutex); 1008 mutex_lock(&dev->struct_mutex);
@@ -1060,7 +1060,7 @@ i915_gem_sw_finish_ioctl(struct drm_device *dev, void *data,
1060 obj = drm_gem_object_lookup(dev, file_priv, args->handle); 1060 obj = drm_gem_object_lookup(dev, file_priv, args->handle);
1061 if (obj == NULL) { 1061 if (obj == NULL) {
1062 mutex_unlock(&dev->struct_mutex); 1062 mutex_unlock(&dev->struct_mutex);
1063 return -EBADF; 1063 return -ENOENT;
1064 } 1064 }
1065 1065
1066#if WATCH_BUF 1066#if WATCH_BUF
@@ -1099,7 +1099,7 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data,
1099 1099
1100 obj = drm_gem_object_lookup(dev, file_priv, args->handle); 1100 obj = drm_gem_object_lookup(dev, file_priv, args->handle);
1101 if (obj == NULL) 1101 if (obj == NULL)
1102 return -EBADF; 1102 return -ENOENT;
1103 1103
1104 offset = args->offset; 1104 offset = args->offset;
1105 1105
@@ -1373,7 +1373,7 @@ i915_gem_mmap_gtt_ioctl(struct drm_device *dev, void *data,
1373 1373
1374 obj = drm_gem_object_lookup(dev, file_priv, args->handle); 1374 obj = drm_gem_object_lookup(dev, file_priv, args->handle);
1375 if (obj == NULL) 1375 if (obj == NULL)
1376 return -EBADF; 1376 return -ENOENT;
1377 1377
1378 mutex_lock(&dev->struct_mutex); 1378 mutex_lock(&dev->struct_mutex);
1379 1379
@@ -3364,7 +3364,7 @@ i915_gem_object_pin_and_relocate(struct drm_gem_object *obj,
3364 reloc->target_handle); 3364 reloc->target_handle);
3365 if (target_obj == NULL) { 3365 if (target_obj == NULL) {
3366 i915_gem_object_unpin(obj); 3366 i915_gem_object_unpin(obj);
3367 return -EBADF; 3367 return -ENOENT;
3368 } 3368 }
3369 target_obj_priv = to_intel_bo(target_obj); 3369 target_obj_priv = to_intel_bo(target_obj);
3370 3370
@@ -3781,7 +3781,7 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,
3781 exec_list[i].handle, i); 3781 exec_list[i].handle, i);
3782 /* prevent error path from reading uninitialized data */ 3782 /* prevent error path from reading uninitialized data */
3783 args->buffer_count = i + 1; 3783 args->buffer_count = i + 1;
3784 ret = -EBADF; 3784 ret = -ENOENT;
3785 goto err; 3785 goto err;
3786 } 3786 }
3787 3787
@@ -3791,7 +3791,7 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,
3791 object_list[i]); 3791 object_list[i]);
3792 /* prevent error path from reading uninitialized data */ 3792 /* prevent error path from reading uninitialized data */
3793 args->buffer_count = i + 1; 3793 args->buffer_count = i + 1;
3794 ret = -EBADF; 3794 ret = -EINVAL;
3795 goto err; 3795 goto err;
3796 } 3796 }
3797 obj_priv->in_execbuffer = true; 3797 obj_priv->in_execbuffer = true;
@@ -4265,7 +4265,7 @@ i915_gem_pin_ioctl(struct drm_device *dev, void *data,
4265 DRM_ERROR("Bad handle in i915_gem_pin_ioctl(): %d\n", 4265 DRM_ERROR("Bad handle in i915_gem_pin_ioctl(): %d\n",
4266 args->handle); 4266 args->handle);
4267 mutex_unlock(&dev->struct_mutex); 4267 mutex_unlock(&dev->struct_mutex);
4268 return -EBADF; 4268 return -ENOENT;
4269 } 4269 }
4270 obj_priv = to_intel_bo(obj); 4270 obj_priv = to_intel_bo(obj);
4271 4271
@@ -4321,7 +4321,7 @@ i915_gem_unpin_ioctl(struct drm_device *dev, void *data,
4321 DRM_ERROR("Bad handle in i915_gem_unpin_ioctl(): %d\n", 4321 DRM_ERROR("Bad handle in i915_gem_unpin_ioctl(): %d\n",
4322 args->handle); 4322 args->handle);
4323 mutex_unlock(&dev->struct_mutex); 4323 mutex_unlock(&dev->struct_mutex);
4324 return -EBADF; 4324 return -ENOENT;
4325 } 4325 }
4326 4326
4327 obj_priv = to_intel_bo(obj); 4327 obj_priv = to_intel_bo(obj);
@@ -4355,7 +4355,7 @@ i915_gem_busy_ioctl(struct drm_device *dev, void *data,
4355 if (obj == NULL) { 4355 if (obj == NULL) {
4356 DRM_ERROR("Bad handle in i915_gem_busy_ioctl(): %d\n", 4356 DRM_ERROR("Bad handle in i915_gem_busy_ioctl(): %d\n",
4357 args->handle); 4357 args->handle);
4358 return -EBADF; 4358 return -ENOENT;
4359 } 4359 }
4360 4360
4361 mutex_lock(&dev->struct_mutex); 4361 mutex_lock(&dev->struct_mutex);
@@ -4408,7 +4408,7 @@ i915_gem_madvise_ioctl(struct drm_device *dev, void *data,
4408 if (obj == NULL) { 4408 if (obj == NULL) {
4409 DRM_ERROR("Bad handle in i915_gem_madvise_ioctl(): %d\n", 4409 DRM_ERROR("Bad handle in i915_gem_madvise_ioctl(): %d\n",
4410 args->handle); 4410 args->handle);
4411 return -EBADF; 4411 return -ENOENT;
4412 } 4412 }
4413 4413
4414 mutex_lock(&dev->struct_mutex); 4414 mutex_lock(&dev->struct_mutex);
diff --git a/drivers/gpu/drm/i915/i915_gem_tiling.c b/drivers/gpu/drm/i915/i915_gem_tiling.c
index 155719e4d16f..710eca70b323 100644
--- a/drivers/gpu/drm/i915/i915_gem_tiling.c
+++ b/drivers/gpu/drm/i915/i915_gem_tiling.c
@@ -275,7 +275,7 @@ i915_gem_set_tiling(struct drm_device *dev, void *data,
275 275
276 obj = drm_gem_object_lookup(dev, file_priv, args->handle); 276 obj = drm_gem_object_lookup(dev, file_priv, args->handle);
277 if (obj == NULL) 277 if (obj == NULL)
278 return -EINVAL; 278 return -ENOENT;
279 obj_priv = to_intel_bo(obj); 279 obj_priv = to_intel_bo(obj);
280 280
281 if (!i915_tiling_ok(dev, args->stride, obj->size, args->tiling_mode)) { 281 if (!i915_tiling_ok(dev, args->stride, obj->size, args->tiling_mode)) {
@@ -362,7 +362,7 @@ i915_gem_get_tiling(struct drm_device *dev, void *data,
362 362
363 obj = drm_gem_object_lookup(dev, file_priv, args->handle); 363 obj = drm_gem_object_lookup(dev, file_priv, args->handle);
364 if (obj == NULL) 364 if (obj == NULL)
365 return -EINVAL; 365 return -ENOENT;
366 obj_priv = to_intel_bo(obj); 366 obj_priv = to_intel_bo(obj);
367 367
368 mutex_lock(&dev->struct_mutex); 368 mutex_lock(&dev->struct_mutex);
diff --git a/drivers/gpu/drm/i915/i915_opregion.c b/drivers/gpu/drm/i915/i915_opregion.c
index 8fcc75c1aa28..d1bf92b99788 100644
--- a/drivers/gpu/drm/i915/i915_opregion.c
+++ b/drivers/gpu/drm/i915/i915_opregion.c
@@ -535,6 +535,7 @@ int intel_opregion_init(struct drm_device *dev, int resume)
535err_out: 535err_out:
536 iounmap(opregion->header); 536 iounmap(opregion->header);
537 opregion->header = NULL; 537 opregion->header = NULL;
538 acpi_video_register();
538 return err; 539 return err;
539} 540}
540 541
diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
index 1e5e0d379fa9..5ec10e02341b 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -4429,15 +4429,12 @@ void intel_crtc_fb_gamma_get(struct drm_crtc *crtc, u16 *red, u16 *green,
4429} 4429}
4430 4430
4431static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green, 4431static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
4432 u16 *blue, uint32_t size) 4432 u16 *blue, uint32_t start, uint32_t size)
4433{ 4433{
4434 int end = (start + size > 256) ? 256 : start + size, i;
4434 struct intel_crtc *intel_crtc = to_intel_crtc(crtc); 4435 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4435 int i;
4436
4437 if (size != 256)
4438 return;
4439 4436
4440 for (i = 0; i < 256; i++) { 4437 for (i = start; i < end; i++) {
4441 intel_crtc->lut_r[i] = red[i] >> 8; 4438 intel_crtc->lut_r[i] = red[i] >> 8;
4442 intel_crtc->lut_g[i] = green[i] >> 8; 4439 intel_crtc->lut_g[i] = green[i] >> 8;
4443 intel_crtc->lut_b[i] = blue[i] >> 8; 4440 intel_crtc->lut_b[i] = blue[i] >> 8;
@@ -5412,18 +5409,18 @@ intel_user_framebuffer_create(struct drm_device *dev,
5412 5409
5413 obj = drm_gem_object_lookup(dev, filp, mode_cmd->handle); 5410 obj = drm_gem_object_lookup(dev, filp, mode_cmd->handle);
5414 if (!obj) 5411 if (!obj)
5415 return NULL; 5412 return ERR_PTR(-ENOENT);
5416 5413
5417 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); 5414 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
5418 if (!intel_fb) 5415 if (!intel_fb)
5419 return NULL; 5416 return ERR_PTR(-ENOMEM);
5420 5417
5421 ret = intel_framebuffer_init(dev, intel_fb, 5418 ret = intel_framebuffer_init(dev, intel_fb,
5422 mode_cmd, obj); 5419 mode_cmd, obj);
5423 if (ret) { 5420 if (ret) {
5424 drm_gem_object_unreference_unlocked(obj); 5421 drm_gem_object_unreference_unlocked(obj);
5425 kfree(intel_fb); 5422 kfree(intel_fb);
5426 return NULL; 5423 return ERR_PTR(ret);
5427 } 5424 }
5428 5425
5429 return &intel_fb->base; 5426 return &intel_fb->base;
diff --git a/drivers/gpu/drm/i915/intel_fb.c b/drivers/gpu/drm/i915/intel_fb.c
index 54acd8b534df..7bdc96256bf5 100644
--- a/drivers/gpu/drm/i915/intel_fb.c
+++ b/drivers/gpu/drm/i915/intel_fb.c
@@ -121,7 +121,9 @@ static int intelfb_create(struct intel_fbdev *ifbdev,
121 121
122 info->par = ifbdev; 122 info->par = ifbdev;
123 123
124 intel_framebuffer_init(dev, &ifbdev->ifb, &mode_cmd, fbo); 124 ret = intel_framebuffer_init(dev, &ifbdev->ifb, &mode_cmd, fbo);
125 if (ret)
126 goto out_unpin;
125 127
126 fb = &ifbdev->ifb.base; 128 fb = &ifbdev->ifb.base;
127 129
@@ -130,7 +132,7 @@ static int intelfb_create(struct intel_fbdev *ifbdev,
130 132
131 strcpy(info->fix.id, "inteldrmfb"); 133 strcpy(info->fix.id, "inteldrmfb");
132 134
133 info->flags = FBINFO_DEFAULT; 135 info->flags = FBINFO_DEFAULT | FBINFO_CAN_FORCE_OUTPUT;
134 info->fbops = &intelfb_ops; 136 info->fbops = &intelfb_ops;
135 137
136 /* setup aperture base/size for vesafb takeover */ 138 /* setup aperture base/size for vesafb takeover */
@@ -148,8 +150,6 @@ static int intelfb_create(struct intel_fbdev *ifbdev,
148 info->fix.smem_start = dev->mode_config.fb_base + obj_priv->gtt_offset; 150 info->fix.smem_start = dev->mode_config.fb_base + obj_priv->gtt_offset;
149 info->fix.smem_len = size; 151 info->fix.smem_len = size;
150 152
151 info->flags = FBINFO_DEFAULT;
152
153 info->screen_base = ioremap_wc(dev->agp->base + obj_priv->gtt_offset, 153 info->screen_base = ioremap_wc(dev->agp->base + obj_priv->gtt_offset,
154 size); 154 size);
155 if (!info->screen_base) { 155 if (!info->screen_base) {
diff --git a/drivers/gpu/drm/nouveau/Makefile b/drivers/gpu/drm/nouveau/Makefile
index 2405d5ef0ca7..e9b06e4ef2a2 100644
--- a/drivers/gpu/drm/nouveau/Makefile
+++ b/drivers/gpu/drm/nouveau/Makefile
@@ -12,12 +12,12 @@ nouveau-y := nouveau_drv.o nouveau_state.o nouveau_channel.o nouveau_mem.o \
12 nouveau_dp.o \ 12 nouveau_dp.o \
13 nv04_timer.o \ 13 nv04_timer.o \
14 nv04_mc.o nv40_mc.o nv50_mc.o \ 14 nv04_mc.o nv40_mc.o nv50_mc.o \
15 nv04_fb.o nv10_fb.o nv30_fb.o nv40_fb.o nv50_fb.o \ 15 nv04_fb.o nv10_fb.o nv30_fb.o nv40_fb.o nv50_fb.o nvc0_fb.o \
16 nv04_fifo.o nv10_fifo.o nv40_fifo.o nv50_fifo.o \ 16 nv04_fifo.o nv10_fifo.o nv40_fifo.o nv50_fifo.o nvc0_fifo.o \
17 nv04_graph.o nv10_graph.o nv20_graph.o \ 17 nv04_graph.o nv10_graph.o nv20_graph.o \
18 nv40_graph.o nv50_graph.o \ 18 nv40_graph.o nv50_graph.o nvc0_graph.o \
19 nv40_grctx.o nv50_grctx.o \ 19 nv40_grctx.o nv50_grctx.o \
20 nv04_instmem.o nv50_instmem.o \ 20 nv04_instmem.o nv50_instmem.o nvc0_instmem.o \
21 nv50_crtc.o nv50_dac.o nv50_sor.o \ 21 nv50_crtc.o nv50_dac.o nv50_sor.o \
22 nv50_cursor.o nv50_display.o nv50_fbcon.o \ 22 nv50_cursor.o nv50_display.o nv50_fbcon.o \
23 nv04_dac.o nv04_dfp.o nv04_tv.o nv17_tv.o nv17_tv_modes.o \ 23 nv04_dac.o nv04_dfp.o nv04_tv.o nv17_tv.o nv17_tv_modes.o \
diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
index 7369b5e73649..0b69a9628c95 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
@@ -1928,6 +1928,31 @@ init_condition_time(struct nvbios *bios, uint16_t offset,
1928} 1928}
1929 1929
1930static int 1930static int
1931init_ltime(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1932{
1933 /*
1934 * INIT_LTIME opcode: 0x57 ('V')
1935 *
1936 * offset (8 bit): opcode
1937 * offset + 1 (16 bit): time
1938 *
1939 * Sleep for "time" miliseconds.
1940 */
1941
1942 unsigned time = ROM16(bios->data[offset + 1]);
1943
1944 if (!iexec->execute)
1945 return 3;
1946
1947 BIOSLOG(bios, "0x%04X: Sleeping for 0x%04X miliseconds\n",
1948 offset, time);
1949
1950 msleep(time);
1951
1952 return 3;
1953}
1954
1955static int
1931init_zm_reg_sequence(struct nvbios *bios, uint16_t offset, 1956init_zm_reg_sequence(struct nvbios *bios, uint16_t offset,
1932 struct init_exec *iexec) 1957 struct init_exec *iexec)
1933{ 1958{
@@ -1995,6 +2020,64 @@ init_sub_direct(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1995} 2020}
1996 2021
1997static int 2022static int
2023init_i2c_if(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
2024{
2025 /*
2026 * INIT_I2C_IF opcode: 0x5E ('^')
2027 *
2028 * offset (8 bit): opcode
2029 * offset + 1 (8 bit): DCB I2C table entry index
2030 * offset + 2 (8 bit): I2C slave address
2031 * offset + 3 (8 bit): I2C register
2032 * offset + 4 (8 bit): mask
2033 * offset + 5 (8 bit): data
2034 *
2035 * Read the register given by "I2C register" on the device addressed
2036 * by "I2C slave address" on the I2C bus given by "DCB I2C table
2037 * entry index". Compare the result AND "mask" to "data".
2038 * If they're not equal, skip subsequent opcodes until condition is
2039 * inverted (INIT_NOT), or we hit INIT_RESUME
2040 */
2041
2042 uint8_t i2c_index = bios->data[offset + 1];
2043 uint8_t i2c_address = bios->data[offset + 2] >> 1;
2044 uint8_t reg = bios->data[offset + 3];
2045 uint8_t mask = bios->data[offset + 4];
2046 uint8_t data = bios->data[offset + 5];
2047 struct nouveau_i2c_chan *chan;
2048 union i2c_smbus_data val;
2049 int ret;
2050
2051 /* no execute check by design */
2052
2053 BIOSLOG(bios, "0x%04X: DCBI2CIndex: 0x%02X, I2CAddress: 0x%02X\n",
2054 offset, i2c_index, i2c_address);
2055
2056 chan = init_i2c_device_find(bios->dev, i2c_index);
2057 if (!chan)
2058 return -ENODEV;
2059
2060 ret = i2c_smbus_xfer(&chan->adapter, i2c_address, 0,
2061 I2C_SMBUS_READ, reg,
2062 I2C_SMBUS_BYTE_DATA, &val);
2063 if (ret < 0) {
2064 BIOSLOG(bios, "0x%04X: I2CReg: 0x%02X, Value: [no device], "
2065 "Mask: 0x%02X, Data: 0x%02X\n",
2066 offset, reg, mask, data);
2067 iexec->execute = 0;
2068 return 6;
2069 }
2070
2071 BIOSLOG(bios, "0x%04X: I2CReg: 0x%02X, Value: 0x%02X, "
2072 "Mask: 0x%02X, Data: 0x%02X\n",
2073 offset, reg, val.byte, mask, data);
2074
2075 iexec->execute = ((val.byte & mask) == data);
2076
2077 return 6;
2078}
2079
2080static int
1998init_copy_nv_reg(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) 2081init_copy_nv_reg(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
1999{ 2082{
2000 /* 2083 /*
@@ -2083,9 +2166,10 @@ peek_fb(struct drm_device *dev, struct io_mapping *fb,
2083 uint32_t val = 0; 2166 uint32_t val = 0;
2084 2167
2085 if (off < pci_resource_len(dev->pdev, 1)) { 2168 if (off < pci_resource_len(dev->pdev, 1)) {
2086 uint32_t __iomem *p = io_mapping_map_atomic_wc(fb, off, KM_USER0); 2169 uint32_t __iomem *p =
2170 io_mapping_map_atomic_wc(fb, off & PAGE_MASK, KM_USER0);
2087 2171
2088 val = ioread32(p); 2172 val = ioread32(p + (off & ~PAGE_MASK));
2089 2173
2090 io_mapping_unmap_atomic(p, KM_USER0); 2174 io_mapping_unmap_atomic(p, KM_USER0);
2091 } 2175 }
@@ -2098,9 +2182,10 @@ poke_fb(struct drm_device *dev, struct io_mapping *fb,
2098 uint32_t off, uint32_t val) 2182 uint32_t off, uint32_t val)
2099{ 2183{
2100 if (off < pci_resource_len(dev->pdev, 1)) { 2184 if (off < pci_resource_len(dev->pdev, 1)) {
2101 uint32_t __iomem *p = io_mapping_map_atomic_wc(fb, off, KM_USER0); 2185 uint32_t __iomem *p =
2186 io_mapping_map_atomic_wc(fb, off & PAGE_MASK, KM_USER0);
2102 2187
2103 iowrite32(val, p); 2188 iowrite32(val, p + (off & ~PAGE_MASK));
2104 wmb(); 2189 wmb();
2105 2190
2106 io_mapping_unmap_atomic(p, KM_USER0); 2191 io_mapping_unmap_atomic(p, KM_USER0);
@@ -2165,7 +2250,7 @@ nv04_init_compute_mem(struct nvbios *bios)
2165 NV04_PFB_BOOT_0_RAM_AMOUNT, 2250 NV04_PFB_BOOT_0_RAM_AMOUNT,
2166 NV04_PFB_BOOT_0_RAM_AMOUNT_4MB); 2251 NV04_PFB_BOOT_0_RAM_AMOUNT_4MB);
2167 2252
2168 } else if (peek_fb(dev, fb, 0) == patt) { 2253 } else if (peek_fb(dev, fb, 0) != patt) {
2169 if (read_back_fb(dev, fb, 0x800000, patt)) 2254 if (read_back_fb(dev, fb, 0x800000, patt))
2170 bios_md32(bios, NV04_PFB_BOOT_0, 2255 bios_md32(bios, NV04_PFB_BOOT_0,
2171 NV04_PFB_BOOT_0_RAM_AMOUNT, 2256 NV04_PFB_BOOT_0_RAM_AMOUNT,
@@ -2593,7 +2678,7 @@ init_configure_preinit(struct nvbios *bios, uint16_t offset,
2593 /* no iexec->execute check by design */ 2678 /* no iexec->execute check by design */
2594 2679
2595 uint32_t straps = bios_rd32(bios, NV_PEXTDEV_BOOT_0); 2680 uint32_t straps = bios_rd32(bios, NV_PEXTDEV_BOOT_0);
2596 uint8_t cr3c = ((straps << 2) & 0xf0) | (straps & (1 << 6)); 2681 uint8_t cr3c = ((straps << 2) & 0xf0) | (straps & 0x40) >> 6;
2597 2682
2598 if (bios->major_version > 2) 2683 if (bios->major_version > 2)
2599 return 0; 2684 return 0;
@@ -3140,7 +3225,7 @@ init_gpio(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
3140 const uint32_t nv50_gpio_ctl[2] = { 0xe100, 0xe28c }; 3225 const uint32_t nv50_gpio_ctl[2] = { 0xe100, 0xe28c };
3141 int i; 3226 int i;
3142 3227
3143 if (dev_priv->card_type != NV_50) { 3228 if (dev_priv->card_type < NV_50) {
3144 NV_ERROR(bios->dev, "INIT_GPIO on unsupported chipset\n"); 3229 NV_ERROR(bios->dev, "INIT_GPIO on unsupported chipset\n");
3145 return 1; 3230 return 1;
3146 } 3231 }
@@ -3490,6 +3575,69 @@ init_zm_auxch(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
3490 return len; 3575 return len;
3491} 3576}
3492 3577
3578static int
3579init_i2c_long_if(struct nvbios *bios, uint16_t offset, struct init_exec *iexec)
3580{
3581 /*
3582 * INIT_I2C_LONG_IF opcode: 0x9A ('')
3583 *
3584 * offset (8 bit): opcode
3585 * offset + 1 (8 bit): DCB I2C table entry index
3586 * offset + 2 (8 bit): I2C slave address
3587 * offset + 3 (16 bit): I2C register
3588 * offset + 5 (8 bit): mask
3589 * offset + 6 (8 bit): data
3590 *
3591 * Read the register given by "I2C register" on the device addressed
3592 * by "I2C slave address" on the I2C bus given by "DCB I2C table
3593 * entry index". Compare the result AND "mask" to "data".
3594 * If they're not equal, skip subsequent opcodes until condition is
3595 * inverted (INIT_NOT), or we hit INIT_RESUME
3596 */
3597
3598 uint8_t i2c_index = bios->data[offset + 1];
3599 uint8_t i2c_address = bios->data[offset + 2] >> 1;
3600 uint8_t reglo = bios->data[offset + 3];
3601 uint8_t reghi = bios->data[offset + 4];
3602 uint8_t mask = bios->data[offset + 5];
3603 uint8_t data = bios->data[offset + 6];
3604 struct nouveau_i2c_chan *chan;
3605 uint8_t buf0[2] = { reghi, reglo };
3606 uint8_t buf1[1];
3607 struct i2c_msg msg[2] = {
3608 { i2c_address, 0, 1, buf0 },
3609 { i2c_address, I2C_M_RD, 1, buf1 },
3610 };
3611 int ret;
3612
3613 /* no execute check by design */
3614
3615 BIOSLOG(bios, "0x%04X: DCBI2CIndex: 0x%02X, I2CAddress: 0x%02X\n",
3616 offset, i2c_index, i2c_address);
3617
3618 chan = init_i2c_device_find(bios->dev, i2c_index);
3619 if (!chan)
3620 return -ENODEV;
3621
3622
3623 ret = i2c_transfer(&chan->adapter, msg, 2);
3624 if (ret < 0) {
3625 BIOSLOG(bios, "0x%04X: I2CReg: 0x%02X:0x%02X, Value: [no device], "
3626 "Mask: 0x%02X, Data: 0x%02X\n",
3627 offset, reghi, reglo, mask, data);
3628 iexec->execute = 0;
3629 return 7;
3630 }
3631
3632 BIOSLOG(bios, "0x%04X: I2CReg: 0x%02X:0x%02X, Value: 0x%02X, "
3633 "Mask: 0x%02X, Data: 0x%02X\n",
3634 offset, reghi, reglo, buf1[0], mask, data);
3635
3636 iexec->execute = ((buf1[0] & mask) == data);
3637
3638 return 7;
3639}
3640
3493static struct init_tbl_entry itbl_entry[] = { 3641static struct init_tbl_entry itbl_entry[] = {
3494 /* command name , id , length , offset , mult , command handler */ 3642 /* command name , id , length , offset , mult , command handler */
3495 /* INIT_PROG (0x31, 15, 10, 4) removed due to no example of use */ 3643 /* INIT_PROG (0x31, 15, 10, 4) removed due to no example of use */
@@ -3516,9 +3664,11 @@ static struct init_tbl_entry itbl_entry[] = {
3516 { "INIT_ZM_CR" , 0x53, init_zm_cr }, 3664 { "INIT_ZM_CR" , 0x53, init_zm_cr },
3517 { "INIT_ZM_CR_GROUP" , 0x54, init_zm_cr_group }, 3665 { "INIT_ZM_CR_GROUP" , 0x54, init_zm_cr_group },
3518 { "INIT_CONDITION_TIME" , 0x56, init_condition_time }, 3666 { "INIT_CONDITION_TIME" , 0x56, init_condition_time },
3667 { "INIT_LTIME" , 0x57, init_ltime },
3519 { "INIT_ZM_REG_SEQUENCE" , 0x58, init_zm_reg_sequence }, 3668 { "INIT_ZM_REG_SEQUENCE" , 0x58, init_zm_reg_sequence },
3520 /* INIT_INDIRECT_REG (0x5A, 7, 0, 0) removed due to no example of use */ 3669 /* INIT_INDIRECT_REG (0x5A, 7, 0, 0) removed due to no example of use */
3521 { "INIT_SUB_DIRECT" , 0x5B, init_sub_direct }, 3670 { "INIT_SUB_DIRECT" , 0x5B, init_sub_direct },
3671 { "INIT_I2C_IF" , 0x5E, init_i2c_if },
3522 { "INIT_COPY_NV_REG" , 0x5F, init_copy_nv_reg }, 3672 { "INIT_COPY_NV_REG" , 0x5F, init_copy_nv_reg },
3523 { "INIT_ZM_INDEX_IO" , 0x62, init_zm_index_io }, 3673 { "INIT_ZM_INDEX_IO" , 0x62, init_zm_index_io },
3524 { "INIT_COMPUTE_MEM" , 0x63, init_compute_mem }, 3674 { "INIT_COMPUTE_MEM" , 0x63, init_compute_mem },
@@ -3552,6 +3702,7 @@ static struct init_tbl_entry itbl_entry[] = {
3552 { "INIT_97" , 0x97, init_97 }, 3702 { "INIT_97" , 0x97, init_97 },
3553 { "INIT_AUXCH" , 0x98, init_auxch }, 3703 { "INIT_AUXCH" , 0x98, init_auxch },
3554 { "INIT_ZM_AUXCH" , 0x99, init_zm_auxch }, 3704 { "INIT_ZM_AUXCH" , 0x99, init_zm_auxch },
3705 { "INIT_I2C_LONG_IF" , 0x9A, init_i2c_long_if },
3555 { NULL , 0 , NULL } 3706 { NULL , 0 , NULL }
3556}; 3707};
3557 3708
@@ -4410,7 +4561,7 @@ nouveau_bios_run_display_table(struct drm_device *dev, struct dcb_entry *dcbent,
4410 bios->display.script_table_ptr, 4561 bios->display.script_table_ptr,
4411 table[2], table[3], table[0] >= 0x21); 4562 table[2], table[3], table[0] >= 0x21);
4412 if (!otable) { 4563 if (!otable) {
4413 NV_ERROR(dev, "Couldn't find matching output script table\n"); 4564 NV_DEBUG_KMS(dev, "failed to match any output table\n");
4414 return 1; 4565 return 1;
4415 } 4566 }
4416 4567
@@ -4467,7 +4618,7 @@ nouveau_bios_run_display_table(struct drm_device *dev, struct dcb_entry *dcbent,
4467 if (script) 4618 if (script)
4468 script = clkcmptable(bios, script, pxclk); 4619 script = clkcmptable(bios, script, pxclk);
4469 if (!script) { 4620 if (!script) {
4470 NV_ERROR(dev, "clock script 0 not found\n"); 4621 NV_DEBUG_KMS(dev, "clock script 0 not found\n");
4471 return 1; 4622 return 1;
4472 } 4623 }
4473 4624
@@ -4826,7 +4977,7 @@ int get_pll_limits(struct drm_device *dev, uint32_t limit_match, struct pll_lims
4826 pll_lim->min_p = record[12]; 4977 pll_lim->min_p = record[12];
4827 pll_lim->max_p = record[13]; 4978 pll_lim->max_p = record[13];
4828 /* where did this go to?? */ 4979 /* where did this go to?? */
4829 if (limit_match == 0x00614100 || limit_match == 0x00614900) 4980 if ((entry[0] & 0xf0) == 0x80)
4830 pll_lim->refclk = 27000; 4981 pll_lim->refclk = 27000;
4831 else 4982 else
4832 pll_lim->refclk = 100000; 4983 pll_lim->refclk = 100000;
@@ -5852,7 +6003,7 @@ static void fabricate_vga_output(struct dcb_table *dcb, int i2c, int heads)
5852 entry->i2c_index = i2c; 6003 entry->i2c_index = i2c;
5853 entry->heads = heads; 6004 entry->heads = heads;
5854 entry->location = DCB_LOC_ON_CHIP; 6005 entry->location = DCB_LOC_ON_CHIP;
5855 /* "or" mostly unused in early gen crt modesetting, 0 is fine */ 6006 entry->or = 1;
5856} 6007}
5857 6008
5858static void fabricate_dvi_i_output(struct dcb_table *dcb, bool twoHeads) 6009static void fabricate_dvi_i_output(struct dcb_table *dcb, bool twoHeads)
@@ -5980,7 +6131,13 @@ parse_dcb20_entry(struct drm_device *dev, struct dcb_table *dcb,
5980 } 6131 }
5981 break; 6132 break;
5982 case OUTPUT_TMDS: 6133 case OUTPUT_TMDS:
5983 entry->tmdsconf.sor.link = (conf & 0x00000030) >> 4; 6134 if (dcb->version >= 0x40)
6135 entry->tmdsconf.sor.link = (conf & 0x00000030) >> 4;
6136 else if (dcb->version >= 0x30)
6137 entry->tmdsconf.slave_addr = (conf & 0x00000700) >> 8;
6138 else if (dcb->version >= 0x22)
6139 entry->tmdsconf.slave_addr = (conf & 0x00000070) >> 4;
6140
5984 break; 6141 break;
5985 case 0xe: 6142 case 0xe:
5986 /* weird g80 mobile type that "nv" treats as a terminator */ 6143 /* weird g80 mobile type that "nv" treats as a terminator */
@@ -6270,6 +6427,19 @@ parse_dcb_table(struct drm_device *dev, struct nvbios *bios, bool twoHeads)
6270 dcb->i2c_table = &bios->data[i2ctabptr]; 6427 dcb->i2c_table = &bios->data[i2ctabptr];
6271 if (dcb->version >= 0x30) 6428 if (dcb->version >= 0x30)
6272 dcb->i2c_default_indices = dcb->i2c_table[4]; 6429 dcb->i2c_default_indices = dcb->i2c_table[4];
6430
6431 /*
6432 * Parse the "management" I2C bus, used for hardware
6433 * monitoring and some external TMDS transmitters.
6434 */
6435 if (dcb->version >= 0x22) {
6436 int idx = (dcb->version >= 0x40 ?
6437 dcb->i2c_default_indices & 0xf :
6438 2);
6439
6440 read_dcb_i2c_entry(dev, dcb->version, dcb->i2c_table,
6441 idx, &dcb->i2c[idx]);
6442 }
6273 } 6443 }
6274 6444
6275 if (entries > DCB_MAX_NUM_ENTRIES) 6445 if (entries > DCB_MAX_NUM_ENTRIES)
diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.h b/drivers/gpu/drm/nouveau/nouveau_bios.h
index 024458a8d060..fd14dfd3d780 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bios.h
+++ b/drivers/gpu/drm/nouveau/nouveau_bios.h
@@ -131,6 +131,7 @@ struct dcb_entry {
131 } dpconf; 131 } dpconf;
132 struct { 132 struct {
133 struct sor_conf sor; 133 struct sor_conf sor;
134 int slave_addr;
134 } tmdsconf; 135 } tmdsconf;
135 }; 136 };
136 bool i2c_upper_default; 137 bool i2c_upper_default;
diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c
index 3ca8343c15df..84f85183d041 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bo.c
+++ b/drivers/gpu/drm/nouveau/nouveau_bo.c
@@ -51,9 +51,6 @@ nouveau_bo_del_ttm(struct ttm_buffer_object *bo)
51 if (nvbo->tile) 51 if (nvbo->tile)
52 nv10_mem_expire_tiling(dev, nvbo->tile, NULL); 52 nv10_mem_expire_tiling(dev, nvbo->tile, NULL);
53 53
54 spin_lock(&dev_priv->ttm.bo_list_lock);
55 list_del(&nvbo->head);
56 spin_unlock(&dev_priv->ttm.bo_list_lock);
57 kfree(nvbo); 54 kfree(nvbo);
58} 55}
59 56
@@ -166,9 +163,6 @@ nouveau_bo_new(struct drm_device *dev, struct nouveau_channel *chan,
166 } 163 }
167 nvbo->channel = NULL; 164 nvbo->channel = NULL;
168 165
169 spin_lock(&dev_priv->ttm.bo_list_lock);
170 list_add_tail(&nvbo->head, &dev_priv->ttm.bo_list);
171 spin_unlock(&dev_priv->ttm.bo_list_lock);
172 *pnvbo = nvbo; 166 *pnvbo = nvbo;
173 return 0; 167 return 0;
174} 168}
diff --git a/drivers/gpu/drm/nouveau/nouveau_connector.c b/drivers/gpu/drm/nouveau/nouveau_connector.c
index 734e92635e83..b1b22baf1428 100644
--- a/drivers/gpu/drm/nouveau/nouveau_connector.c
+++ b/drivers/gpu/drm/nouveau/nouveau_connector.c
@@ -37,12 +37,6 @@
37#include "nouveau_connector.h" 37#include "nouveau_connector.h"
38#include "nouveau_hw.h" 38#include "nouveau_hw.h"
39 39
40static inline struct drm_encoder_slave_funcs *
41get_slave_funcs(struct nouveau_encoder *enc)
42{
43 return to_encoder_slave(to_drm_encoder(enc))->slave_funcs;
44}
45
46static struct nouveau_encoder * 40static struct nouveau_encoder *
47find_encoder_by_type(struct drm_connector *connector, int type) 41find_encoder_by_type(struct drm_connector *connector, int type)
48{ 42{
@@ -360,6 +354,7 @@ nouveau_connector_set_property(struct drm_connector *connector,
360{ 354{
361 struct nouveau_connector *nv_connector = nouveau_connector(connector); 355 struct nouveau_connector *nv_connector = nouveau_connector(connector);
362 struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder; 356 struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder;
357 struct drm_encoder *encoder = to_drm_encoder(nv_encoder);
363 struct drm_device *dev = connector->dev; 358 struct drm_device *dev = connector->dev;
364 int ret; 359 int ret;
365 360
@@ -432,8 +427,8 @@ nouveau_connector_set_property(struct drm_connector *connector,
432 } 427 }
433 428
434 if (nv_encoder && nv_encoder->dcb->type == OUTPUT_TV) 429 if (nv_encoder && nv_encoder->dcb->type == OUTPUT_TV)
435 return get_slave_funcs(nv_encoder)-> 430 return get_slave_funcs(encoder)->set_property(
436 set_property(to_drm_encoder(nv_encoder), connector, property, value); 431 encoder, connector, property, value);
437 432
438 return -EINVAL; 433 return -EINVAL;
439} 434}
@@ -545,6 +540,7 @@ nouveau_connector_get_modes(struct drm_connector *connector)
545 struct drm_nouveau_private *dev_priv = dev->dev_private; 540 struct drm_nouveau_private *dev_priv = dev->dev_private;
546 struct nouveau_connector *nv_connector = nouveau_connector(connector); 541 struct nouveau_connector *nv_connector = nouveau_connector(connector);
547 struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder; 542 struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder;
543 struct drm_encoder *encoder = to_drm_encoder(nv_encoder);
548 int ret = 0; 544 int ret = 0;
549 545
550 /* destroy the native mode, the attached monitor could have changed. 546 /* destroy the native mode, the attached monitor could have changed.
@@ -580,8 +576,7 @@ nouveau_connector_get_modes(struct drm_connector *connector)
580 } 576 }
581 577
582 if (nv_encoder->dcb->type == OUTPUT_TV) 578 if (nv_encoder->dcb->type == OUTPUT_TV)
583 ret = get_slave_funcs(nv_encoder)-> 579 ret = get_slave_funcs(encoder)->get_modes(encoder, connector);
584 get_modes(to_drm_encoder(nv_encoder), connector);
585 580
586 if (nv_connector->dcb->type == DCB_CONNECTOR_LVDS || 581 if (nv_connector->dcb->type == DCB_CONNECTOR_LVDS ||
587 nv_connector->dcb->type == DCB_CONNECTOR_eDP) 582 nv_connector->dcb->type == DCB_CONNECTOR_eDP)
@@ -597,6 +592,7 @@ nouveau_connector_mode_valid(struct drm_connector *connector,
597 struct drm_nouveau_private *dev_priv = connector->dev->dev_private; 592 struct drm_nouveau_private *dev_priv = connector->dev->dev_private;
598 struct nouveau_connector *nv_connector = nouveau_connector(connector); 593 struct nouveau_connector *nv_connector = nouveau_connector(connector);
599 struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder; 594 struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder;
595 struct drm_encoder *encoder = to_drm_encoder(nv_encoder);
600 unsigned min_clock = 25000, max_clock = min_clock; 596 unsigned min_clock = 25000, max_clock = min_clock;
601 unsigned clock = mode->clock; 597 unsigned clock = mode->clock;
602 598
@@ -623,8 +619,7 @@ nouveau_connector_mode_valid(struct drm_connector *connector,
623 max_clock = 350000; 619 max_clock = 350000;
624 break; 620 break;
625 case OUTPUT_TV: 621 case OUTPUT_TV:
626 return get_slave_funcs(nv_encoder)-> 622 return get_slave_funcs(encoder)->mode_valid(encoder, mode);
627 mode_valid(to_drm_encoder(nv_encoder), mode);
628 case OUTPUT_DP: 623 case OUTPUT_DP:
629 if (nv_encoder->dp.link_bw == DP_LINK_BW_2_7) 624 if (nv_encoder->dp.link_bw == DP_LINK_BW_2_7)
630 max_clock = nv_encoder->dp.link_nr * 270000; 625 max_clock = nv_encoder->dp.link_nr * 270000;
diff --git a/drivers/gpu/drm/nouveau/nouveau_display.c b/drivers/gpu/drm/nouveau/nouveau_display.c
index 74e6b4ed12c0..2e11fd65b4dd 100644
--- a/drivers/gpu/drm/nouveau/nouveau_display.c
+++ b/drivers/gpu/drm/nouveau/nouveau_display.c
@@ -84,16 +84,16 @@ nouveau_user_framebuffer_create(struct drm_device *dev,
84 84
85 gem = drm_gem_object_lookup(dev, file_priv, mode_cmd->handle); 85 gem = drm_gem_object_lookup(dev, file_priv, mode_cmd->handle);
86 if (!gem) 86 if (!gem)
87 return NULL; 87 return ERR_PTR(-ENOENT);
88 88
89 nouveau_fb = kzalloc(sizeof(struct nouveau_framebuffer), GFP_KERNEL); 89 nouveau_fb = kzalloc(sizeof(struct nouveau_framebuffer), GFP_KERNEL);
90 if (!nouveau_fb) 90 if (!nouveau_fb)
91 return NULL; 91 return ERR_PTR(-ENOMEM);
92 92
93 ret = nouveau_framebuffer_init(dev, nouveau_fb, mode_cmd, nouveau_gem_object(gem)); 93 ret = nouveau_framebuffer_init(dev, nouveau_fb, mode_cmd, nouveau_gem_object(gem));
94 if (ret) { 94 if (ret) {
95 drm_gem_object_unreference(gem); 95 drm_gem_object_unreference(gem);
96 return NULL; 96 return ERR_PTR(ret);
97 } 97 }
98 98
99 return &nouveau_fb->base; 99 return &nouveau_fb->base;
diff --git a/drivers/gpu/drm/nouveau/nouveau_dp.c b/drivers/gpu/drm/nouveau/nouveau_dp.c
index 33742b11188b..8a1b188b4cd1 100644
--- a/drivers/gpu/drm/nouveau/nouveau_dp.c
+++ b/drivers/gpu/drm/nouveau/nouveau_dp.c
@@ -572,47 +572,64 @@ out:
572 return ret ? ret : (stat & NV50_AUXCH_STAT_REPLY); 572 return ret ? ret : (stat & NV50_AUXCH_STAT_REPLY);
573} 573}
574 574
575int 575static int
576nouveau_dp_i2c_aux_ch(struct i2c_adapter *adapter, int mode, 576nouveau_dp_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
577 uint8_t write_byte, uint8_t *read_byte)
578{ 577{
579 struct i2c_algo_dp_aux_data *algo_data = adapter->algo_data; 578 struct nouveau_i2c_chan *auxch = (struct nouveau_i2c_chan *)adap;
580 struct nouveau_i2c_chan *auxch = (struct nouveau_i2c_chan *)adapter;
581 struct drm_device *dev = auxch->dev; 579 struct drm_device *dev = auxch->dev;
582 int ret = 0, cmd, addr = algo_data->address; 580 struct i2c_msg *msg = msgs;
583 uint8_t *buf; 581 int ret, mcnt = num;
584
585 if (mode == MODE_I2C_READ) {
586 cmd = AUX_I2C_READ;
587 buf = read_byte;
588 } else {
589 cmd = (mode & MODE_I2C_READ) ? AUX_I2C_READ : AUX_I2C_WRITE;
590 buf = &write_byte;
591 }
592 582
593 if (!(mode & MODE_I2C_STOP)) 583 while (mcnt--) {
594 cmd |= AUX_I2C_MOT; 584 u8 remaining = msg->len;
585 u8 *ptr = msg->buf;
595 586
596 if (mode & MODE_I2C_START) 587 while (remaining) {
597 return 1; 588 u8 cnt = (remaining > 16) ? 16 : remaining;
589 u8 cmd;
598 590
599 for (;;) { 591 if (msg->flags & I2C_M_RD)
600 ret = nouveau_dp_auxch(auxch, cmd, addr, buf, 1); 592 cmd = AUX_I2C_READ;
601 if (ret < 0) 593 else
602 return ret; 594 cmd = AUX_I2C_WRITE;
603 595
604 switch (ret & NV50_AUXCH_STAT_REPLY_I2C) { 596 if (mcnt || remaining > 16)
605 case NV50_AUXCH_STAT_REPLY_I2C_ACK: 597 cmd |= AUX_I2C_MOT;
606 return 1; 598
607 case NV50_AUXCH_STAT_REPLY_I2C_NACK: 599 ret = nouveau_dp_auxch(auxch, cmd, msg->addr, ptr, cnt);
608 return -EREMOTEIO; 600 if (ret < 0)
609 case NV50_AUXCH_STAT_REPLY_I2C_DEFER: 601 return ret;
610 udelay(100); 602
611 break; 603 switch (ret & NV50_AUXCH_STAT_REPLY_I2C) {
612 default: 604 case NV50_AUXCH_STAT_REPLY_I2C_ACK:
613 NV_ERROR(dev, "invalid auxch status: 0x%08x\n", ret); 605 break;
614 return -EREMOTEIO; 606 case NV50_AUXCH_STAT_REPLY_I2C_NACK:
607 return -EREMOTEIO;
608 case NV50_AUXCH_STAT_REPLY_I2C_DEFER:
609 udelay(100);
610 continue;
611 default:
612 NV_ERROR(dev, "bad auxch reply: 0x%08x\n", ret);
613 return -EREMOTEIO;
614 }
615
616 ptr += cnt;
617 remaining -= cnt;
615 } 618 }
619
620 msg++;
616 } 621 }
622
623 return num;
624}
625
626static u32
627nouveau_dp_i2c_func(struct i2c_adapter *adap)
628{
629 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
617} 630}
618 631
632const struct i2c_algorithm nouveau_dp_i2c_algo = {
633 .master_xfer = nouveau_dp_i2c_xfer,
634 .functionality = nouveau_dp_i2c_func
635};
diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
index e15db15dca77..e424bf74d706 100644
--- a/drivers/gpu/drm/nouveau/nouveau_drv.h
+++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
@@ -410,7 +410,7 @@ enum nv04_fp_display_regs {
410 410
411struct nv04_crtc_reg { 411struct nv04_crtc_reg {
412 unsigned char MiscOutReg; /* */ 412 unsigned char MiscOutReg; /* */
413 uint8_t CRTC[0x9f]; 413 uint8_t CRTC[0xa0];
414 uint8_t CR58[0x10]; 414 uint8_t CR58[0x10];
415 uint8_t Sequencer[5]; 415 uint8_t Sequencer[5];
416 uint8_t Graphics[9]; 416 uint8_t Graphics[9];
@@ -509,6 +509,7 @@ enum nouveau_card_type {
509 NV_30 = 0x30, 509 NV_30 = 0x30,
510 NV_40 = 0x40, 510 NV_40 = 0x40,
511 NV_50 = 0x50, 511 NV_50 = 0x50,
512 NV_C0 = 0xc0,
512}; 513};
513 514
514struct drm_nouveau_private { 515struct drm_nouveau_private {
@@ -536,8 +537,6 @@ struct drm_nouveau_private {
536 struct drm_global_reference mem_global_ref; 537 struct drm_global_reference mem_global_ref;
537 struct ttm_bo_global_ref bo_global_ref; 538 struct ttm_bo_global_ref bo_global_ref;
538 struct ttm_bo_device bdev; 539 struct ttm_bo_device bdev;
539 spinlock_t bo_list_lock;
540 struct list_head bo_list;
541 atomic_t validate_sequence; 540 atomic_t validate_sequence;
542 } ttm; 541 } ttm;
543 542
@@ -931,6 +930,10 @@ extern void nv40_fb_set_region_tiling(struct drm_device *, int, uint32_t,
931extern int nv50_fb_init(struct drm_device *); 930extern int nv50_fb_init(struct drm_device *);
932extern void nv50_fb_takedown(struct drm_device *); 931extern void nv50_fb_takedown(struct drm_device *);
933 932
933/* nvc0_fb.c */
934extern int nvc0_fb_init(struct drm_device *);
935extern void nvc0_fb_takedown(struct drm_device *);
936
934/* nv04_fifo.c */ 937/* nv04_fifo.c */
935extern int nv04_fifo_init(struct drm_device *); 938extern int nv04_fifo_init(struct drm_device *);
936extern void nv04_fifo_disable(struct drm_device *); 939extern void nv04_fifo_disable(struct drm_device *);
@@ -968,6 +971,20 @@ extern void nv50_fifo_destroy_context(struct nouveau_channel *);
968extern int nv50_fifo_load_context(struct nouveau_channel *); 971extern int nv50_fifo_load_context(struct nouveau_channel *);
969extern int nv50_fifo_unload_context(struct drm_device *); 972extern int nv50_fifo_unload_context(struct drm_device *);
970 973
974/* nvc0_fifo.c */
975extern int nvc0_fifo_init(struct drm_device *);
976extern void nvc0_fifo_takedown(struct drm_device *);
977extern void nvc0_fifo_disable(struct drm_device *);
978extern void nvc0_fifo_enable(struct drm_device *);
979extern bool nvc0_fifo_reassign(struct drm_device *, bool);
980extern bool nvc0_fifo_cache_flush(struct drm_device *);
981extern bool nvc0_fifo_cache_pull(struct drm_device *, bool);
982extern int nvc0_fifo_channel_id(struct drm_device *);
983extern int nvc0_fifo_create_context(struct nouveau_channel *);
984extern void nvc0_fifo_destroy_context(struct nouveau_channel *);
985extern int nvc0_fifo_load_context(struct nouveau_channel *);
986extern int nvc0_fifo_unload_context(struct drm_device *);
987
971/* nv04_graph.c */ 988/* nv04_graph.c */
972extern struct nouveau_pgraph_object_class nv04_graph_grclass[]; 989extern struct nouveau_pgraph_object_class nv04_graph_grclass[];
973extern int nv04_graph_init(struct drm_device *); 990extern int nv04_graph_init(struct drm_device *);
@@ -1032,6 +1049,16 @@ extern int nv50_graph_unload_context(struct drm_device *);
1032extern void nv50_graph_context_switch(struct drm_device *); 1049extern void nv50_graph_context_switch(struct drm_device *);
1033extern int nv50_grctx_init(struct nouveau_grctx *); 1050extern int nv50_grctx_init(struct nouveau_grctx *);
1034 1051
1052/* nvc0_graph.c */
1053extern int nvc0_graph_init(struct drm_device *);
1054extern void nvc0_graph_takedown(struct drm_device *);
1055extern void nvc0_graph_fifo_access(struct drm_device *, bool);
1056extern struct nouveau_channel *nvc0_graph_channel(struct drm_device *);
1057extern int nvc0_graph_create_context(struct nouveau_channel *);
1058extern void nvc0_graph_destroy_context(struct nouveau_channel *);
1059extern int nvc0_graph_load_context(struct nouveau_channel *);
1060extern int nvc0_graph_unload_context(struct drm_device *);
1061
1035/* nv04_instmem.c */ 1062/* nv04_instmem.c */
1036extern int nv04_instmem_init(struct drm_device *); 1063extern int nv04_instmem_init(struct drm_device *);
1037extern void nv04_instmem_takedown(struct drm_device *); 1064extern void nv04_instmem_takedown(struct drm_device *);
@@ -1058,6 +1085,18 @@ extern void nv50_instmem_flush(struct drm_device *);
1058extern void nv84_instmem_flush(struct drm_device *); 1085extern void nv84_instmem_flush(struct drm_device *);
1059extern void nv50_vm_flush(struct drm_device *, int engine); 1086extern void nv50_vm_flush(struct drm_device *, int engine);
1060 1087
1088/* nvc0_instmem.c */
1089extern int nvc0_instmem_init(struct drm_device *);
1090extern void nvc0_instmem_takedown(struct drm_device *);
1091extern int nvc0_instmem_suspend(struct drm_device *);
1092extern void nvc0_instmem_resume(struct drm_device *);
1093extern int nvc0_instmem_populate(struct drm_device *, struct nouveau_gpuobj *,
1094 uint32_t *size);
1095extern void nvc0_instmem_clear(struct drm_device *, struct nouveau_gpuobj *);
1096extern int nvc0_instmem_bind(struct drm_device *, struct nouveau_gpuobj *);
1097extern int nvc0_instmem_unbind(struct drm_device *, struct nouveau_gpuobj *);
1098extern void nvc0_instmem_flush(struct drm_device *);
1099
1061/* nv04_mc.c */ 1100/* nv04_mc.c */
1062extern int nv04_mc_init(struct drm_device *); 1101extern int nv04_mc_init(struct drm_device *);
1063extern void nv04_mc_takedown(struct drm_device *); 1102extern void nv04_mc_takedown(struct drm_device *);
diff --git a/drivers/gpu/drm/nouveau/nouveau_encoder.h b/drivers/gpu/drm/nouveau/nouveau_encoder.h
index a1a0d48ae70c..7c82d68bc155 100644
--- a/drivers/gpu/drm/nouveau/nouveau_encoder.h
+++ b/drivers/gpu/drm/nouveau/nouveau_encoder.h
@@ -71,6 +71,12 @@ static inline struct drm_encoder *to_drm_encoder(struct nouveau_encoder *enc)
71 return &enc->base.base; 71 return &enc->base.base;
72} 72}
73 73
74static inline struct drm_encoder_slave_funcs *
75get_slave_funcs(struct drm_encoder *enc)
76{
77 return to_encoder_slave(enc)->slave_funcs;
78}
79
74struct nouveau_connector * 80struct nouveau_connector *
75nouveau_encoder_connector_get(struct nouveau_encoder *encoder); 81nouveau_encoder_connector_get(struct nouveau_encoder *encoder);
76int nv50_sor_create(struct drm_connector *, struct dcb_entry *); 82int nv50_sor_create(struct drm_connector *, struct dcb_entry *);
diff --git a/drivers/gpu/drm/nouveau/nouveau_fbcon.c b/drivers/gpu/drm/nouveau/nouveau_fbcon.c
index 2fb2444d2322..dbd30b2e43fd 100644
--- a/drivers/gpu/drm/nouveau/nouveau_fbcon.c
+++ b/drivers/gpu/drm/nouveau/nouveau_fbcon.c
@@ -250,6 +250,7 @@ nouveau_fbcon_create(struct nouveau_fbdev *nfbdev,
250 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_COPYAREA | 250 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_COPYAREA |
251 FBINFO_HWACCEL_FILLRECT | 251 FBINFO_HWACCEL_FILLRECT |
252 FBINFO_HWACCEL_IMAGEBLIT; 252 FBINFO_HWACCEL_IMAGEBLIT;
253 info->flags |= FBINFO_CAN_FORCE_OUTPUT;
253 info->fbops = &nouveau_fbcon_ops; 254 info->fbops = &nouveau_fbcon_ops;
254 info->fix.smem_start = dev->mode_config.fb_base + nvbo->bo.offset - 255 info->fix.smem_start = dev->mode_config.fb_base + nvbo->bo.offset -
255 dev_priv->vm_vram_base; 256 dev_priv->vm_vram_base;
@@ -280,6 +281,8 @@ nouveau_fbcon_create(struct nouveau_fbdev *nfbdev,
280 281
281 if (dev_priv->channel && !nouveau_nofbaccel) { 282 if (dev_priv->channel && !nouveau_nofbaccel) {
282 switch (dev_priv->card_type) { 283 switch (dev_priv->card_type) {
284 case NV_C0:
285 break;
283 case NV_50: 286 case NV_50:
284 nv50_fbcon_accel_init(info); 287 nv50_fbcon_accel_init(info);
285 info->fbops = &nv50_fbcon_ops; 288 info->fbops = &nv50_fbcon_ops;
diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
index 547f2c24c1e7..0f417ac1b696 100644
--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
@@ -284,7 +284,7 @@ retry:
284 if (!gem) { 284 if (!gem) {
285 NV_ERROR(dev, "Unknown handle 0x%08x\n", b->handle); 285 NV_ERROR(dev, "Unknown handle 0x%08x\n", b->handle);
286 validate_fini(op, NULL); 286 validate_fini(op, NULL);
287 return -EINVAL; 287 return -ENOENT;
288 } 288 }
289 nvbo = gem->driver_private; 289 nvbo = gem->driver_private;
290 290
@@ -759,7 +759,7 @@ nouveau_gem_ioctl_cpu_prep(struct drm_device *dev, void *data,
759 759
760 gem = drm_gem_object_lookup(dev, file_priv, req->handle); 760 gem = drm_gem_object_lookup(dev, file_priv, req->handle);
761 if (!gem) 761 if (!gem)
762 return ret; 762 return -ENOENT;
763 nvbo = nouveau_gem_object(gem); 763 nvbo = nouveau_gem_object(gem);
764 764
765 if (nvbo->cpu_filp) { 765 if (nvbo->cpu_filp) {
@@ -797,7 +797,7 @@ nouveau_gem_ioctl_cpu_fini(struct drm_device *dev, void *data,
797 797
798 gem = drm_gem_object_lookup(dev, file_priv, req->handle); 798 gem = drm_gem_object_lookup(dev, file_priv, req->handle);
799 if (!gem) 799 if (!gem)
800 return ret; 800 return -ENOENT;
801 nvbo = nouveau_gem_object(gem); 801 nvbo = nouveau_gem_object(gem);
802 802
803 if (nvbo->cpu_filp != file_priv) 803 if (nvbo->cpu_filp != file_priv)
@@ -822,7 +822,7 @@ nouveau_gem_ioctl_info(struct drm_device *dev, void *data,
822 822
823 gem = drm_gem_object_lookup(dev, file_priv, req->handle); 823 gem = drm_gem_object_lookup(dev, file_priv, req->handle);
824 if (!gem) 824 if (!gem)
825 return -EINVAL; 825 return -ENOENT;
826 826
827 ret = nouveau_gem_info(gem, req); 827 ret = nouveau_gem_info(gem, req);
828 drm_gem_object_unreference_unlocked(gem); 828 drm_gem_object_unreference_unlocked(gem);
diff --git a/drivers/gpu/drm/nouveau/nouveau_hw.c b/drivers/gpu/drm/nouveau/nouveau_hw.c
index 7855b35effc3..7b613682e400 100644
--- a/drivers/gpu/drm/nouveau/nouveau_hw.c
+++ b/drivers/gpu/drm/nouveau/nouveau_hw.c
@@ -865,8 +865,12 @@ nv_save_state_ext(struct drm_device *dev, int head,
865 rd_cio_state(dev, head, regp, NV_CIO_CRE_FF_INDEX); 865 rd_cio_state(dev, head, regp, NV_CIO_CRE_FF_INDEX);
866 rd_cio_state(dev, head, regp, NV_CIO_CRE_FFLWM__INDEX); 866 rd_cio_state(dev, head, regp, NV_CIO_CRE_FFLWM__INDEX);
867 rd_cio_state(dev, head, regp, NV_CIO_CRE_21); 867 rd_cio_state(dev, head, regp, NV_CIO_CRE_21);
868 if (dev_priv->card_type >= NV_30) 868
869 if (dev_priv->card_type >= NV_30) {
869 rd_cio_state(dev, head, regp, NV_CIO_CRE_47); 870 rd_cio_state(dev, head, regp, NV_CIO_CRE_47);
871 rd_cio_state(dev, head, regp, 0x9f);
872 }
873
870 rd_cio_state(dev, head, regp, NV_CIO_CRE_49); 874 rd_cio_state(dev, head, regp, NV_CIO_CRE_49);
871 rd_cio_state(dev, head, regp, NV_CIO_CRE_HCUR_ADDR0_INDEX); 875 rd_cio_state(dev, head, regp, NV_CIO_CRE_HCUR_ADDR0_INDEX);
872 rd_cio_state(dev, head, regp, NV_CIO_CRE_HCUR_ADDR1_INDEX); 876 rd_cio_state(dev, head, regp, NV_CIO_CRE_HCUR_ADDR1_INDEX);
@@ -971,8 +975,11 @@ nv_load_state_ext(struct drm_device *dev, int head,
971 wr_cio_state(dev, head, regp, NV_CIO_CRE_ENH_INDEX); 975 wr_cio_state(dev, head, regp, NV_CIO_CRE_ENH_INDEX);
972 wr_cio_state(dev, head, regp, NV_CIO_CRE_FF_INDEX); 976 wr_cio_state(dev, head, regp, NV_CIO_CRE_FF_INDEX);
973 wr_cio_state(dev, head, regp, NV_CIO_CRE_FFLWM__INDEX); 977 wr_cio_state(dev, head, regp, NV_CIO_CRE_FFLWM__INDEX);
974 if (dev_priv->card_type >= NV_30) 978
979 if (dev_priv->card_type >= NV_30) {
975 wr_cio_state(dev, head, regp, NV_CIO_CRE_47); 980 wr_cio_state(dev, head, regp, NV_CIO_CRE_47);
981 wr_cio_state(dev, head, regp, 0x9f);
982 }
976 983
977 wr_cio_state(dev, head, regp, NV_CIO_CRE_49); 984 wr_cio_state(dev, head, regp, NV_CIO_CRE_49);
978 wr_cio_state(dev, head, regp, NV_CIO_CRE_HCUR_ADDR0_INDEX); 985 wr_cio_state(dev, head, regp, NV_CIO_CRE_HCUR_ADDR0_INDEX);
diff --git a/drivers/gpu/drm/nouveau/nouveau_i2c.c b/drivers/gpu/drm/nouveau/nouveau_i2c.c
index cb0cb34440c6..0bd407ca3d42 100644
--- a/drivers/gpu/drm/nouveau/nouveau_i2c.c
+++ b/drivers/gpu/drm/nouveau/nouveau_i2c.c
@@ -163,7 +163,7 @@ nouveau_i2c_init(struct drm_device *dev, struct dcb_i2c_entry *entry, int index)
163 if (entry->chan) 163 if (entry->chan)
164 return -EEXIST; 164 return -EEXIST;
165 165
166 if (dev_priv->card_type == NV_50 && entry->read >= NV50_I2C_PORTS) { 166 if (dev_priv->card_type == NV_C0 && entry->read >= NV50_I2C_PORTS) {
167 NV_ERROR(dev, "unknown i2c port %d\n", entry->read); 167 NV_ERROR(dev, "unknown i2c port %d\n", entry->read);
168 return -EINVAL; 168 return -EINVAL;
169 } 169 }
@@ -174,26 +174,26 @@ nouveau_i2c_init(struct drm_device *dev, struct dcb_i2c_entry *entry, int index)
174 174
175 switch (entry->port_type) { 175 switch (entry->port_type) {
176 case 0: 176 case 0:
177 i2c->algo.bit.setsda = nv04_i2c_setsda; 177 i2c->bit.setsda = nv04_i2c_setsda;
178 i2c->algo.bit.setscl = nv04_i2c_setscl; 178 i2c->bit.setscl = nv04_i2c_setscl;
179 i2c->algo.bit.getsda = nv04_i2c_getsda; 179 i2c->bit.getsda = nv04_i2c_getsda;
180 i2c->algo.bit.getscl = nv04_i2c_getscl; 180 i2c->bit.getscl = nv04_i2c_getscl;
181 i2c->rd = entry->read; 181 i2c->rd = entry->read;
182 i2c->wr = entry->write; 182 i2c->wr = entry->write;
183 break; 183 break;
184 case 4: 184 case 4:
185 i2c->algo.bit.setsda = nv4e_i2c_setsda; 185 i2c->bit.setsda = nv4e_i2c_setsda;
186 i2c->algo.bit.setscl = nv4e_i2c_setscl; 186 i2c->bit.setscl = nv4e_i2c_setscl;
187 i2c->algo.bit.getsda = nv4e_i2c_getsda; 187 i2c->bit.getsda = nv4e_i2c_getsda;
188 i2c->algo.bit.getscl = nv4e_i2c_getscl; 188 i2c->bit.getscl = nv4e_i2c_getscl;
189 i2c->rd = 0x600800 + entry->read; 189 i2c->rd = 0x600800 + entry->read;
190 i2c->wr = 0x600800 + entry->write; 190 i2c->wr = 0x600800 + entry->write;
191 break; 191 break;
192 case 5: 192 case 5:
193 i2c->algo.bit.setsda = nv50_i2c_setsda; 193 i2c->bit.setsda = nv50_i2c_setsda;
194 i2c->algo.bit.setscl = nv50_i2c_setscl; 194 i2c->bit.setscl = nv50_i2c_setscl;
195 i2c->algo.bit.getsda = nv50_i2c_getsda; 195 i2c->bit.getsda = nv50_i2c_getsda;
196 i2c->algo.bit.getscl = nv50_i2c_getscl; 196 i2c->bit.getscl = nv50_i2c_getscl;
197 i2c->rd = nv50_i2c_port[entry->read]; 197 i2c->rd = nv50_i2c_port[entry->read];
198 i2c->wr = i2c->rd; 198 i2c->wr = i2c->rd;
199 break; 199 break;
@@ -216,17 +216,14 @@ nouveau_i2c_init(struct drm_device *dev, struct dcb_i2c_entry *entry, int index)
216 i2c_set_adapdata(&i2c->adapter, i2c); 216 i2c_set_adapdata(&i2c->adapter, i2c);
217 217
218 if (entry->port_type < 6) { 218 if (entry->port_type < 6) {
219 i2c->adapter.algo_data = &i2c->algo.bit; 219 i2c->adapter.algo_data = &i2c->bit;
220 i2c->algo.bit.udelay = 40; 220 i2c->bit.udelay = 40;
221 i2c->algo.bit.timeout = usecs_to_jiffies(5000); 221 i2c->bit.timeout = usecs_to_jiffies(5000);
222 i2c->algo.bit.data = i2c; 222 i2c->bit.data = i2c;
223 ret = i2c_bit_add_bus(&i2c->adapter); 223 ret = i2c_bit_add_bus(&i2c->adapter);
224 } else { 224 } else {
225 i2c->adapter.algo_data = &i2c->algo.dp; 225 i2c->adapter.algo = &nouveau_dp_i2c_algo;
226 i2c->algo.dp.running = false; 226 ret = i2c_add_adapter(&i2c->adapter);
227 i2c->algo.dp.address = 0;
228 i2c->algo.dp.aux_ch = nouveau_dp_i2c_aux_ch;
229 ret = i2c_dp_aux_add_bus(&i2c->adapter);
230 } 227 }
231 228
232 if (ret) { 229 if (ret) {
diff --git a/drivers/gpu/drm/nouveau/nouveau_i2c.h b/drivers/gpu/drm/nouveau/nouveau_i2c.h
index 6dd2f8713cd1..f71cb32f7571 100644
--- a/drivers/gpu/drm/nouveau/nouveau_i2c.h
+++ b/drivers/gpu/drm/nouveau/nouveau_i2c.h
@@ -33,10 +33,7 @@ struct dcb_i2c_entry;
33struct nouveau_i2c_chan { 33struct nouveau_i2c_chan {
34 struct i2c_adapter adapter; 34 struct i2c_adapter adapter;
35 struct drm_device *dev; 35 struct drm_device *dev;
36 union { 36 struct i2c_algo_bit_data bit;
37 struct i2c_algo_bit_data bit;
38 struct i2c_algo_dp_aux_data dp;
39 } algo;
40 unsigned rd; 37 unsigned rd;
41 unsigned wr; 38 unsigned wr;
42 unsigned data; 39 unsigned data;
@@ -49,7 +46,6 @@ bool nouveau_probe_i2c_addr(struct nouveau_i2c_chan *i2c, int addr);
49int nouveau_i2c_identify(struct drm_device *dev, const char *what, 46int nouveau_i2c_identify(struct drm_device *dev, const char *what,
50 struct i2c_board_info *info, int index); 47 struct i2c_board_info *info, int index);
51 48
52int nouveau_dp_i2c_aux_ch(struct i2c_adapter *, int mode, uint8_t write_byte, 49extern const struct i2c_algorithm nouveau_dp_i2c_algo;
53 uint8_t *read_byte);
54 50
55#endif /* __NOUVEAU_I2C_H__ */ 51#endif /* __NOUVEAU_I2C_H__ */
diff --git a/drivers/gpu/drm/nouveau/nouveau_irq.c b/drivers/gpu/drm/nouveau/nouveau_irq.c
index 53360f156063..794b0ee30cf6 100644
--- a/drivers/gpu/drm/nouveau/nouveau_irq.c
+++ b/drivers/gpu/drm/nouveau/nouveau_irq.c
@@ -49,7 +49,7 @@ nouveau_irq_preinstall(struct drm_device *dev)
49 /* Master disable */ 49 /* Master disable */
50 nv_wr32(dev, NV03_PMC_INTR_EN_0, 0); 50 nv_wr32(dev, NV03_PMC_INTR_EN_0, 0);
51 51
52 if (dev_priv->card_type == NV_50) { 52 if (dev_priv->card_type >= NV_50) {
53 INIT_WORK(&dev_priv->irq_work, nv50_display_irq_handler_bh); 53 INIT_WORK(&dev_priv->irq_work, nv50_display_irq_handler_bh);
54 INIT_WORK(&dev_priv->hpd_work, nv50_display_irq_hotplug_bh); 54 INIT_WORK(&dev_priv->hpd_work, nv50_display_irq_hotplug_bh);
55 INIT_LIST_HEAD(&dev_priv->vbl_waiting); 55 INIT_LIST_HEAD(&dev_priv->vbl_waiting);
@@ -586,11 +586,11 @@ nouveau_pgraph_irq_handler(struct drm_device *dev)
586 } 586 }
587 587
588 if (status & NV_PGRAPH_INTR_CONTEXT_SWITCH) { 588 if (status & NV_PGRAPH_INTR_CONTEXT_SWITCH) {
589 nouveau_pgraph_intr_context_switch(dev);
590
591 status &= ~NV_PGRAPH_INTR_CONTEXT_SWITCH; 589 status &= ~NV_PGRAPH_INTR_CONTEXT_SWITCH;
592 nv_wr32(dev, NV03_PGRAPH_INTR, 590 nv_wr32(dev, NV03_PGRAPH_INTR,
593 NV_PGRAPH_INTR_CONTEXT_SWITCH); 591 NV_PGRAPH_INTR_CONTEXT_SWITCH);
592
593 nouveau_pgraph_intr_context_switch(dev);
594 } 594 }
595 595
596 if (status) { 596 if (status) {
diff --git a/drivers/gpu/drm/nouveau/nouveau_mem.c b/drivers/gpu/drm/nouveau/nouveau_mem.c
index a9f36ab256b7..9689d4147686 100644
--- a/drivers/gpu/drm/nouveau/nouveau_mem.c
+++ b/drivers/gpu/drm/nouveau/nouveau_mem.c
@@ -320,7 +320,8 @@ nouveau_mem_detect(struct drm_device *dev)
320 if (dev_priv->card_type < NV_50) { 320 if (dev_priv->card_type < NV_50) {
321 dev_priv->vram_size = nv_rd32(dev, NV04_PFB_FIFO_DATA); 321 dev_priv->vram_size = nv_rd32(dev, NV04_PFB_FIFO_DATA);
322 dev_priv->vram_size &= NV10_PFB_FIFO_DATA_RAM_AMOUNT_MB_MASK; 322 dev_priv->vram_size &= NV10_PFB_FIFO_DATA_RAM_AMOUNT_MB_MASK;
323 } else { 323 } else
324 if (dev_priv->card_type < NV_C0) {
324 dev_priv->vram_size = nv_rd32(dev, NV04_PFB_FIFO_DATA); 325 dev_priv->vram_size = nv_rd32(dev, NV04_PFB_FIFO_DATA);
325 dev_priv->vram_size |= (dev_priv->vram_size & 0xff) << 32; 326 dev_priv->vram_size |= (dev_priv->vram_size & 0xff) << 32;
326 dev_priv->vram_size &= 0xffffffff00ll; 327 dev_priv->vram_size &= 0xffffffff00ll;
@@ -328,6 +329,9 @@ nouveau_mem_detect(struct drm_device *dev)
328 dev_priv->vram_sys_base = nv_rd32(dev, 0x100e10); 329 dev_priv->vram_sys_base = nv_rd32(dev, 0x100e10);
329 dev_priv->vram_sys_base <<= 12; 330 dev_priv->vram_sys_base <<= 12;
330 } 331 }
332 } else {
333 dev_priv->vram_size = nv_rd32(dev, 0x10f20c) << 20;
334 dev_priv->vram_size *= nv_rd32(dev, 0x121c74);
331 } 335 }
332 336
333 NV_INFO(dev, "Detected %dMiB VRAM\n", (int)(dev_priv->vram_size >> 20)); 337 NV_INFO(dev, "Detected %dMiB VRAM\n", (int)(dev_priv->vram_size >> 20));
@@ -351,7 +355,7 @@ nouveau_mem_reset_agp(struct drm_device *dev)
351 /* First of all, disable fast writes, otherwise if it's 355 /* First of all, disable fast writes, otherwise if it's
352 * already enabled in the AGP bridge and we disable the card's 356 * already enabled in the AGP bridge and we disable the card's
353 * AGP controller we might be locking ourselves out of it. */ 357 * AGP controller we might be locking ourselves out of it. */
354 if (dev->agp->acquired) { 358 if (nv_rd32(dev, NV04_PBUS_PCI_NV_19) & PCI_AGP_COMMAND_FW) {
355 struct drm_agp_info info; 359 struct drm_agp_info info;
356 struct drm_agp_mode mode; 360 struct drm_agp_mode mode;
357 361
@@ -359,7 +363,7 @@ nouveau_mem_reset_agp(struct drm_device *dev)
359 if (ret) 363 if (ret)
360 return ret; 364 return ret;
361 365
362 mode.mode = info.mode & ~0x10; 366 mode.mode = info.mode & ~PCI_AGP_COMMAND_FW;
363 ret = drm_agp_enable(dev, mode); 367 ret = drm_agp_enable(dev, mode);
364 if (ret) 368 if (ret)
365 return ret; 369 return ret;
@@ -405,6 +409,8 @@ nouveau_mem_init_agp(struct drm_device *dev)
405 } 409 }
406 } 410 }
407 411
412 nouveau_mem_reset_agp(dev);
413
408 ret = drm_agp_info(dev, &info); 414 ret = drm_agp_info(dev, &info);
409 if (ret) { 415 if (ret) {
410 NV_ERROR(dev, "Unable to get AGP info: %d\n", ret); 416 NV_ERROR(dev, "Unable to get AGP info: %d\n", ret);
@@ -459,8 +465,6 @@ nouveau_mem_init(struct drm_device *dev)
459 return ret; 465 return ret;
460 } 466 }
461 467
462 INIT_LIST_HEAD(&dev_priv->ttm.bo_list);
463 spin_lock_init(&dev_priv->ttm.bo_list_lock);
464 spin_lock_init(&dev_priv->tile.lock); 468 spin_lock_init(&dev_priv->tile.lock);
465 469
466 dev_priv->fb_available_size = dev_priv->vram_size; 470 dev_priv->fb_available_size = dev_priv->vram_size;
@@ -494,7 +498,6 @@ nouveau_mem_init(struct drm_device *dev)
494 /* GART */ 498 /* GART */
495#if !defined(__powerpc__) && !defined(__ia64__) 499#if !defined(__powerpc__) && !defined(__ia64__)
496 if (drm_device_is_agp(dev) && dev->agp && !nouveau_noagp) { 500 if (drm_device_is_agp(dev) && dev->agp && !nouveau_noagp) {
497 nouveau_mem_reset_agp(dev);
498 ret = nouveau_mem_init_agp(dev); 501 ret = nouveau_mem_init_agp(dev);
499 if (ret) 502 if (ret)
500 NV_ERROR(dev, "Error initialising AGP: %d\n", ret); 503 NV_ERROR(dev, "Error initialising AGP: %d\n", ret);
diff --git a/drivers/gpu/drm/nouveau/nouveau_reg.h b/drivers/gpu/drm/nouveau/nouveau_reg.h
index 9c1056cb8a90..21a6e453b975 100644
--- a/drivers/gpu/drm/nouveau/nouveau_reg.h
+++ b/drivers/gpu/drm/nouveau/nouveau_reg.h
@@ -220,28 +220,21 @@
220# define NV_PGRAPH_INTR_ERROR (1<<20) 220# define NV_PGRAPH_INTR_ERROR (1<<20)
221#define NV10_PGRAPH_CTX_CONTROL 0x00400144 221#define NV10_PGRAPH_CTX_CONTROL 0x00400144
222#define NV10_PGRAPH_CTX_USER 0x00400148 222#define NV10_PGRAPH_CTX_USER 0x00400148
223#define NV10_PGRAPH_CTX_SWITCH1 0x0040014C 223#define NV10_PGRAPH_CTX_SWITCH(i) (0x0040014C + 0x4*(i))
224#define NV10_PGRAPH_CTX_SWITCH2 0x00400150
225#define NV10_PGRAPH_CTX_SWITCH3 0x00400154
226#define NV10_PGRAPH_CTX_SWITCH4 0x00400158
227#define NV10_PGRAPH_CTX_SWITCH5 0x0040015C
228#define NV04_PGRAPH_CTX_SWITCH1 0x00400160 224#define NV04_PGRAPH_CTX_SWITCH1 0x00400160
229#define NV10_PGRAPH_CTX_CACHE1 0x00400160 225#define NV10_PGRAPH_CTX_CACHE(i, j) (0x00400160 \
226 + 0x4*(i) + 0x20*(j))
230#define NV04_PGRAPH_CTX_SWITCH2 0x00400164 227#define NV04_PGRAPH_CTX_SWITCH2 0x00400164
231#define NV04_PGRAPH_CTX_SWITCH3 0x00400168 228#define NV04_PGRAPH_CTX_SWITCH3 0x00400168
232#define NV04_PGRAPH_CTX_SWITCH4 0x0040016C 229#define NV04_PGRAPH_CTX_SWITCH4 0x0040016C
233#define NV04_PGRAPH_CTX_CONTROL 0x00400170 230#define NV04_PGRAPH_CTX_CONTROL 0x00400170
234#define NV04_PGRAPH_CTX_USER 0x00400174 231#define NV04_PGRAPH_CTX_USER 0x00400174
235#define NV04_PGRAPH_CTX_CACHE1 0x00400180 232#define NV04_PGRAPH_CTX_CACHE1 0x00400180
236#define NV10_PGRAPH_CTX_CACHE2 0x00400180
237#define NV03_PGRAPH_CTX_CONTROL 0x00400190 233#define NV03_PGRAPH_CTX_CONTROL 0x00400190
238#define NV03_PGRAPH_CTX_USER 0x00400194 234#define NV03_PGRAPH_CTX_USER 0x00400194
239#define NV04_PGRAPH_CTX_CACHE2 0x004001A0 235#define NV04_PGRAPH_CTX_CACHE2 0x004001A0
240#define NV10_PGRAPH_CTX_CACHE3 0x004001A0
241#define NV04_PGRAPH_CTX_CACHE3 0x004001C0 236#define NV04_PGRAPH_CTX_CACHE3 0x004001C0
242#define NV10_PGRAPH_CTX_CACHE4 0x004001C0
243#define NV04_PGRAPH_CTX_CACHE4 0x004001E0 237#define NV04_PGRAPH_CTX_CACHE4 0x004001E0
244#define NV10_PGRAPH_CTX_CACHE5 0x004001E0
245#define NV40_PGRAPH_CTXCTL_0304 0x00400304 238#define NV40_PGRAPH_CTXCTL_0304 0x00400304
246#define NV40_PGRAPH_CTXCTL_0304_XFER_CTX 0x00000001 239#define NV40_PGRAPH_CTXCTL_0304_XFER_CTX 0x00000001
247#define NV40_PGRAPH_CTXCTL_UCODE_STAT 0x00400308 240#define NV40_PGRAPH_CTXCTL_UCODE_STAT 0x00400308
@@ -356,9 +349,12 @@
356#define NV04_PGRAPH_FFINTFC_ST2 0x00400754 349#define NV04_PGRAPH_FFINTFC_ST2 0x00400754
357#define NV10_PGRAPH_RDI_DATA 0x00400754 350#define NV10_PGRAPH_RDI_DATA 0x00400754
358#define NV04_PGRAPH_DMA_PITCH 0x00400760 351#define NV04_PGRAPH_DMA_PITCH 0x00400760
359#define NV10_PGRAPH_FFINTFC_ST2 0x00400764 352#define NV10_PGRAPH_FFINTFC_FIFO_PTR 0x00400760
360#define NV04_PGRAPH_DVD_COLORFMT 0x00400764 353#define NV04_PGRAPH_DVD_COLORFMT 0x00400764
354#define NV10_PGRAPH_FFINTFC_ST2 0x00400764
361#define NV04_PGRAPH_SCALED_FORMAT 0x00400768 355#define NV04_PGRAPH_SCALED_FORMAT 0x00400768
356#define NV10_PGRAPH_FFINTFC_ST2_DL 0x00400768
357#define NV10_PGRAPH_FFINTFC_ST2_DH 0x0040076c
362#define NV10_PGRAPH_DMA_PITCH 0x00400770 358#define NV10_PGRAPH_DMA_PITCH 0x00400770
363#define NV10_PGRAPH_DVD_COLORFMT 0x00400774 359#define NV10_PGRAPH_DVD_COLORFMT 0x00400774
364#define NV10_PGRAPH_SCALED_FORMAT 0x00400778 360#define NV10_PGRAPH_SCALED_FORMAT 0x00400778
diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
index ee3729e7823b..989322be3728 100644
--- a/drivers/gpu/drm/nouveau/nouveau_state.c
+++ b/drivers/gpu/drm/nouveau/nouveau_state.c
@@ -359,6 +359,54 @@ static int nouveau_init_engine_ptrs(struct drm_device *dev)
359 engine->gpio.set = nv50_gpio_set; 359 engine->gpio.set = nv50_gpio_set;
360 engine->gpio.irq_enable = nv50_gpio_irq_enable; 360 engine->gpio.irq_enable = nv50_gpio_irq_enable;
361 break; 361 break;
362 case 0xC0:
363 engine->instmem.init = nvc0_instmem_init;
364 engine->instmem.takedown = nvc0_instmem_takedown;
365 engine->instmem.suspend = nvc0_instmem_suspend;
366 engine->instmem.resume = nvc0_instmem_resume;
367 engine->instmem.populate = nvc0_instmem_populate;
368 engine->instmem.clear = nvc0_instmem_clear;
369 engine->instmem.bind = nvc0_instmem_bind;
370 engine->instmem.unbind = nvc0_instmem_unbind;
371 engine->instmem.flush = nvc0_instmem_flush;
372 engine->mc.init = nv50_mc_init;
373 engine->mc.takedown = nv50_mc_takedown;
374 engine->timer.init = nv04_timer_init;
375 engine->timer.read = nv04_timer_read;
376 engine->timer.takedown = nv04_timer_takedown;
377 engine->fb.init = nvc0_fb_init;
378 engine->fb.takedown = nvc0_fb_takedown;
379 engine->graph.grclass = NULL; //nvc0_graph_grclass;
380 engine->graph.init = nvc0_graph_init;
381 engine->graph.takedown = nvc0_graph_takedown;
382 engine->graph.fifo_access = nvc0_graph_fifo_access;
383 engine->graph.channel = nvc0_graph_channel;
384 engine->graph.create_context = nvc0_graph_create_context;
385 engine->graph.destroy_context = nvc0_graph_destroy_context;
386 engine->graph.load_context = nvc0_graph_load_context;
387 engine->graph.unload_context = nvc0_graph_unload_context;
388 engine->fifo.channels = 128;
389 engine->fifo.init = nvc0_fifo_init;
390 engine->fifo.takedown = nvc0_fifo_takedown;
391 engine->fifo.disable = nvc0_fifo_disable;
392 engine->fifo.enable = nvc0_fifo_enable;
393 engine->fifo.reassign = nvc0_fifo_reassign;
394 engine->fifo.channel_id = nvc0_fifo_channel_id;
395 engine->fifo.create_context = nvc0_fifo_create_context;
396 engine->fifo.destroy_context = nvc0_fifo_destroy_context;
397 engine->fifo.load_context = nvc0_fifo_load_context;
398 engine->fifo.unload_context = nvc0_fifo_unload_context;
399 engine->display.early_init = nv50_display_early_init;
400 engine->display.late_takedown = nv50_display_late_takedown;
401 engine->display.create = nv50_display_create;
402 engine->display.init = nv50_display_init;
403 engine->display.destroy = nv50_display_destroy;
404 engine->gpio.init = nv50_gpio_init;
405 engine->gpio.takedown = nouveau_stub_takedown;
406 engine->gpio.get = nv50_gpio_get;
407 engine->gpio.set = nv50_gpio_set;
408 engine->gpio.irq_enable = nv50_gpio_irq_enable;
409 break;
362 default: 410 default:
363 NV_ERROR(dev, "NV%02x unsupported\n", dev_priv->chipset); 411 NV_ERROR(dev, "NV%02x unsupported\n", dev_priv->chipset);
364 return 1; 412 return 1;
@@ -739,8 +787,10 @@ int nouveau_load(struct drm_device *dev, unsigned long flags)
739 int ret; 787 int ret;
740 788
741 dev_priv = kzalloc(sizeof(*dev_priv), GFP_KERNEL); 789 dev_priv = kzalloc(sizeof(*dev_priv), GFP_KERNEL);
742 if (!dev_priv) 790 if (!dev_priv) {
743 return -ENOMEM; 791 ret = -ENOMEM;
792 goto err_out;
793 }
744 dev->dev_private = dev_priv; 794 dev->dev_private = dev_priv;
745 dev_priv->dev = dev; 795 dev_priv->dev = dev;
746 796
@@ -750,8 +800,10 @@ int nouveau_load(struct drm_device *dev, unsigned long flags)
750 dev->pci_vendor, dev->pci_device, dev->pdev->class); 800 dev->pci_vendor, dev->pci_device, dev->pdev->class);
751 801
752 dev_priv->wq = create_workqueue("nouveau"); 802 dev_priv->wq = create_workqueue("nouveau");
753 if (!dev_priv->wq) 803 if (!dev_priv->wq) {
754 return -EINVAL; 804 ret = -EINVAL;
805 goto err_priv;
806 }
755 807
756 /* resource 0 is mmio regs */ 808 /* resource 0 is mmio regs */
757 /* resource 1 is linear FB */ 809 /* resource 1 is linear FB */
@@ -764,7 +816,8 @@ int nouveau_load(struct drm_device *dev, unsigned long flags)
764 if (!dev_priv->mmio) { 816 if (!dev_priv->mmio) {
765 NV_ERROR(dev, "Unable to initialize the mmio mapping. " 817 NV_ERROR(dev, "Unable to initialize the mmio mapping. "
766 "Please report your setup to " DRIVER_EMAIL "\n"); 818 "Please report your setup to " DRIVER_EMAIL "\n");
767 return -EINVAL; 819 ret = -EINVAL;
820 goto err_wq;
768 } 821 }
769 NV_DEBUG(dev, "regs mapped ok at 0x%llx\n", 822 NV_DEBUG(dev, "regs mapped ok at 0x%llx\n",
770 (unsigned long long)mmio_start_offs); 823 (unsigned long long)mmio_start_offs);
@@ -810,9 +863,13 @@ int nouveau_load(struct drm_device *dev, unsigned long flags)
810 case 0xa0: 863 case 0xa0:
811 dev_priv->card_type = NV_50; 864 dev_priv->card_type = NV_50;
812 break; 865 break;
866 case 0xc0:
867 dev_priv->card_type = NV_C0;
868 break;
813 default: 869 default:
814 NV_INFO(dev, "Unsupported chipset 0x%08x\n", reg0); 870 NV_INFO(dev, "Unsupported chipset 0x%08x\n", reg0);
815 return -EINVAL; 871 ret = -EINVAL;
872 goto err_mmio;
816 } 873 }
817 874
818 NV_INFO(dev, "Detected an NV%2x generation card (0x%08x)\n", 875 NV_INFO(dev, "Detected an NV%2x generation card (0x%08x)\n",
@@ -820,7 +877,7 @@ int nouveau_load(struct drm_device *dev, unsigned long flags)
820 877
821 ret = nouveau_remove_conflicting_drivers(dev); 878 ret = nouveau_remove_conflicting_drivers(dev);
822 if (ret) 879 if (ret)
823 return ret; 880 goto err_mmio;
824 881
825 /* Map PRAMIN BAR, or on older cards, the aperture withing BAR0 */ 882 /* Map PRAMIN BAR, or on older cards, the aperture withing BAR0 */
826 if (dev_priv->card_type >= NV_40) { 883 if (dev_priv->card_type >= NV_40) {
@@ -834,7 +891,8 @@ int nouveau_load(struct drm_device *dev, unsigned long flags)
834 dev_priv->ramin_size); 891 dev_priv->ramin_size);
835 if (!dev_priv->ramin) { 892 if (!dev_priv->ramin) {
836 NV_ERROR(dev, "Failed to PRAMIN BAR"); 893 NV_ERROR(dev, "Failed to PRAMIN BAR");
837 return -ENOMEM; 894 ret = -ENOMEM;
895 goto err_mmio;
838 } 896 }
839 } else { 897 } else {
840 dev_priv->ramin_size = 1 * 1024 * 1024; 898 dev_priv->ramin_size = 1 * 1024 * 1024;
@@ -842,7 +900,8 @@ int nouveau_load(struct drm_device *dev, unsigned long flags)
842 dev_priv->ramin_size); 900 dev_priv->ramin_size);
843 if (!dev_priv->ramin) { 901 if (!dev_priv->ramin) {
844 NV_ERROR(dev, "Failed to map BAR0 PRAMIN.\n"); 902 NV_ERROR(dev, "Failed to map BAR0 PRAMIN.\n");
845 return -ENOMEM; 903 ret = -ENOMEM;
904 goto err_mmio;
846 } 905 }
847 } 906 }
848 907
@@ -857,9 +916,21 @@ int nouveau_load(struct drm_device *dev, unsigned long flags)
857 /* For kernel modesetting, init card now and bring up fbcon */ 916 /* For kernel modesetting, init card now and bring up fbcon */
858 ret = nouveau_card_init(dev); 917 ret = nouveau_card_init(dev);
859 if (ret) 918 if (ret)
860 return ret; 919 goto err_ramin;
861 920
862 return 0; 921 return 0;
922
923err_ramin:
924 iounmap(dev_priv->ramin);
925err_mmio:
926 iounmap(dev_priv->mmio);
927err_wq:
928 destroy_workqueue(dev_priv->wq);
929err_priv:
930 kfree(dev_priv);
931 dev->dev_private = NULL;
932err_out:
933 return ret;
863} 934}
864 935
865void nouveau_lastclose(struct drm_device *dev) 936void nouveau_lastclose(struct drm_device *dev)
diff --git a/drivers/gpu/drm/nouveau/nv04_crtc.c b/drivers/gpu/drm/nouveau/nv04_crtc.c
index 1c20c08ce67c..497df8765f28 100644
--- a/drivers/gpu/drm/nouveau/nv04_crtc.c
+++ b/drivers/gpu/drm/nouveau/nv04_crtc.c
@@ -542,6 +542,9 @@ nv_crtc_mode_set_regs(struct drm_crtc *crtc, struct drm_display_mode * mode)
542 * 1 << 30 on 0x60.830), for no apparent reason */ 542 * 1 << 30 on 0x60.830), for no apparent reason */
543 regp->CRTC[NV_CIO_CRE_59] = off_chip_digital; 543 regp->CRTC[NV_CIO_CRE_59] = off_chip_digital;
544 544
545 if (dev_priv->card_type >= NV_30)
546 regp->CRTC[0x9f] = off_chip_digital ? 0x11 : 0x1;
547
545 regp->crtc_830 = mode->crtc_vdisplay - 3; 548 regp->crtc_830 = mode->crtc_vdisplay - 3;
546 regp->crtc_834 = mode->crtc_vdisplay - 1; 549 regp->crtc_834 = mode->crtc_vdisplay - 1;
547 550
@@ -739,15 +742,13 @@ nv_crtc_gamma_load(struct drm_crtc *crtc)
739} 742}
740 743
741static void 744static void
742nv_crtc_gamma_set(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b, uint32_t size) 745nv_crtc_gamma_set(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b, uint32_t start,
746 uint32_t size)
743{ 747{
748 int end = (start + size > 256) ? 256 : start + size, i;
744 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); 749 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
745 int i;
746 750
747 if (size != 256) 751 for (i = start; i < end; i++) {
748 return;
749
750 for (i = 0; i < 256; i++) {
751 nv_crtc->lut.r[i] = r[i]; 752 nv_crtc->lut.r[i] = r[i];
752 nv_crtc->lut.g[i] = g[i]; 753 nv_crtc->lut.g[i] = g[i];
753 nv_crtc->lut.b[i] = b[i]; 754 nv_crtc->lut.b[i] = b[i];
@@ -914,7 +915,7 @@ nv04_crtc_cursor_set(struct drm_crtc *crtc, struct drm_file *file_priv,
914 915
915 gem = drm_gem_object_lookup(dev, file_priv, buffer_handle); 916 gem = drm_gem_object_lookup(dev, file_priv, buffer_handle);
916 if (!gem) 917 if (!gem)
917 return -EINVAL; 918 return -ENOENT;
918 cursor = nouveau_gem_object(gem); 919 cursor = nouveau_gem_object(gem);
919 920
920 ret = nouveau_bo_map(cursor); 921 ret = nouveau_bo_map(cursor);
diff --git a/drivers/gpu/drm/nouveau/nv04_dfp.c b/drivers/gpu/drm/nouveau/nv04_dfp.c
index 3311f3a8c818..a5dcf7685800 100644
--- a/drivers/gpu/drm/nouveau/nv04_dfp.c
+++ b/drivers/gpu/drm/nouveau/nv04_dfp.c
@@ -34,6 +34,8 @@
34#include "nouveau_hw.h" 34#include "nouveau_hw.h"
35#include "nvreg.h" 35#include "nvreg.h"
36 36
37#include "i2c/sil164.h"
38
37#define FP_TG_CONTROL_ON (NV_PRAMDAC_FP_TG_CONTROL_DISPEN_POS | \ 39#define FP_TG_CONTROL_ON (NV_PRAMDAC_FP_TG_CONTROL_DISPEN_POS | \
38 NV_PRAMDAC_FP_TG_CONTROL_HSYNC_POS | \ 40 NV_PRAMDAC_FP_TG_CONTROL_HSYNC_POS | \
39 NV_PRAMDAC_FP_TG_CONTROL_VSYNC_POS) 41 NV_PRAMDAC_FP_TG_CONTROL_VSYNC_POS)
@@ -144,6 +146,36 @@ void nv04_dfp_update_fp_control(struct drm_encoder *encoder, int mode)
144 } 146 }
145} 147}
146 148
149static struct drm_encoder *get_tmds_slave(struct drm_encoder *encoder)
150{
151 struct drm_device *dev = encoder->dev;
152 struct dcb_entry *dcb = nouveau_encoder(encoder)->dcb;
153 struct drm_encoder *slave;
154
155 if (dcb->type != OUTPUT_TMDS || dcb->location == DCB_LOC_ON_CHIP)
156 return NULL;
157
158 /* Some BIOSes (e.g. the one in a Quadro FX1000) report several
159 * TMDS transmitters at the same I2C address, in the same I2C
160 * bus. This can still work because in that case one of them is
161 * always hard-wired to a reasonable configuration using straps,
162 * and the other one needs to be programmed.
163 *
164 * I don't think there's a way to know which is which, even the
165 * blob programs the one exposed via I2C for *both* heads, so
166 * let's do the same.
167 */
168 list_for_each_entry(slave, &dev->mode_config.encoder_list, head) {
169 struct dcb_entry *slave_dcb = nouveau_encoder(slave)->dcb;
170
171 if (slave_dcb->type == OUTPUT_TMDS && get_slave_funcs(slave) &&
172 slave_dcb->tmdsconf.slave_addr == dcb->tmdsconf.slave_addr)
173 return slave;
174 }
175
176 return NULL;
177}
178
147static bool nv04_dfp_mode_fixup(struct drm_encoder *encoder, 179static bool nv04_dfp_mode_fixup(struct drm_encoder *encoder,
148 struct drm_display_mode *mode, 180 struct drm_display_mode *mode,
149 struct drm_display_mode *adjusted_mode) 181 struct drm_display_mode *adjusted_mode)
@@ -429,6 +461,11 @@ static void nv04_dfp_commit(struct drm_encoder *encoder)
429 else 461 else
430 NVWriteRAMDAC(dev, 0, NV_PRAMDAC_TEST_CONTROL + nv04_dac_output_offset(encoder), 0x00100000); 462 NVWriteRAMDAC(dev, 0, NV_PRAMDAC_TEST_CONTROL + nv04_dac_output_offset(encoder), 0x00100000);
431 463
464 /* Init external transmitters */
465 if (get_tmds_slave(encoder))
466 get_slave_funcs(get_tmds_slave(encoder))->mode_set(
467 encoder, &nv_encoder->mode, &nv_encoder->mode);
468
432 helper->dpms(encoder, DRM_MODE_DPMS_ON); 469 helper->dpms(encoder, DRM_MODE_DPMS_ON);
433 470
434 NV_INFO(dev, "Output %s is running on CRTC %d using output %c\n", 471 NV_INFO(dev, "Output %s is running on CRTC %d using output %c\n",
@@ -550,10 +587,42 @@ static void nv04_dfp_destroy(struct drm_encoder *encoder)
550 587
551 NV_DEBUG_KMS(encoder->dev, "\n"); 588 NV_DEBUG_KMS(encoder->dev, "\n");
552 589
590 if (get_slave_funcs(encoder))
591 get_slave_funcs(encoder)->destroy(encoder);
592
553 drm_encoder_cleanup(encoder); 593 drm_encoder_cleanup(encoder);
554 kfree(nv_encoder); 594 kfree(nv_encoder);
555} 595}
556 596
597static void nv04_tmds_slave_init(struct drm_encoder *encoder)
598{
599 struct drm_device *dev = encoder->dev;
600 struct dcb_entry *dcb = nouveau_encoder(encoder)->dcb;
601 struct nouveau_i2c_chan *i2c = nouveau_i2c_find(dev, 2);
602 struct i2c_board_info info[] = {
603 {
604 .type = "sil164",
605 .addr = (dcb->tmdsconf.slave_addr == 0x7 ? 0x3a : 0x38),
606 .platform_data = &(struct sil164_encoder_params) {
607 SIL164_INPUT_EDGE_RISING
608 }
609 },
610 { }
611 };
612 int type;
613
614 if (!nv_gf4_disp_arch(dev) || !i2c ||
615 get_tmds_slave(encoder))
616 return;
617
618 type = nouveau_i2c_identify(dev, "TMDS transmitter", info, 2);
619 if (type < 0)
620 return;
621
622 drm_i2c_encoder_init(dev, to_encoder_slave(encoder),
623 &i2c->adapter, &info[type]);
624}
625
557static const struct drm_encoder_helper_funcs nv04_lvds_helper_funcs = { 626static const struct drm_encoder_helper_funcs nv04_lvds_helper_funcs = {
558 .dpms = nv04_lvds_dpms, 627 .dpms = nv04_lvds_dpms,
559 .save = nv04_dfp_save, 628 .save = nv04_dfp_save,
@@ -616,6 +685,10 @@ nv04_dfp_create(struct drm_connector *connector, struct dcb_entry *entry)
616 encoder->possible_crtcs = entry->heads; 685 encoder->possible_crtcs = entry->heads;
617 encoder->possible_clones = 0; 686 encoder->possible_clones = 0;
618 687
688 if (entry->type == OUTPUT_TMDS &&
689 entry->location != DCB_LOC_ON_CHIP)
690 nv04_tmds_slave_init(encoder);
691
619 drm_mode_connector_attach_encoder(connector, encoder); 692 drm_mode_connector_attach_encoder(connector, encoder);
620 return 0; 693 return 0;
621} 694}
diff --git a/drivers/gpu/drm/nouveau/nv04_tv.c b/drivers/gpu/drm/nouveau/nv04_tv.c
index 94e299cef0b2..0b5d012d7c28 100644
--- a/drivers/gpu/drm/nouveau/nv04_tv.c
+++ b/drivers/gpu/drm/nouveau/nv04_tv.c
@@ -89,7 +89,7 @@ static void nv04_tv_dpms(struct drm_encoder *encoder, int mode)
89 89
90 NVWriteRAMDAC(dev, 0, NV_PRAMDAC_PLL_COEFF_SELECT, state->pllsel); 90 NVWriteRAMDAC(dev, 0, NV_PRAMDAC_PLL_COEFF_SELECT, state->pllsel);
91 91
92 to_encoder_slave(encoder)->slave_funcs->dpms(encoder, mode); 92 get_slave_funcs(encoder)->dpms(encoder, mode);
93} 93}
94 94
95static void nv04_tv_bind(struct drm_device *dev, int head, bool bind) 95static void nv04_tv_bind(struct drm_device *dev, int head, bool bind)
@@ -152,7 +152,7 @@ static void nv04_tv_mode_set(struct drm_encoder *encoder,
152 regp->tv_vskew = 1; 152 regp->tv_vskew = 1;
153 regp->tv_vsync_delay = 1; 153 regp->tv_vsync_delay = 1;
154 154
155 to_encoder_slave(encoder)->slave_funcs->mode_set(encoder, mode, adjusted_mode); 155 get_slave_funcs(encoder)->mode_set(encoder, mode, adjusted_mode);
156} 156}
157 157
158static void nv04_tv_commit(struct drm_encoder *encoder) 158static void nv04_tv_commit(struct drm_encoder *encoder)
@@ -171,8 +171,7 @@ static void nv04_tv_commit(struct drm_encoder *encoder)
171 171
172static void nv04_tv_destroy(struct drm_encoder *encoder) 172static void nv04_tv_destroy(struct drm_encoder *encoder)
173{ 173{
174 to_encoder_slave(encoder)->slave_funcs->destroy(encoder); 174 get_slave_funcs(encoder)->destroy(encoder);
175
176 drm_encoder_cleanup(encoder); 175 drm_encoder_cleanup(encoder);
177 176
178 kfree(encoder->helper_private); 177 kfree(encoder->helper_private);
@@ -229,7 +228,7 @@ nv04_tv_create(struct drm_connector *connector, struct dcb_entry *entry)
229 goto fail_cleanup; 228 goto fail_cleanup;
230 229
231 /* Fill the function pointers */ 230 /* Fill the function pointers */
232 sfuncs = to_encoder_slave(encoder)->slave_funcs; 231 sfuncs = get_slave_funcs(encoder);
233 232
234 *hfuncs = (struct drm_encoder_helper_funcs) { 233 *hfuncs = (struct drm_encoder_helper_funcs) {
235 .dpms = nv04_tv_dpms, 234 .dpms = nv04_tv_dpms,
@@ -243,7 +242,6 @@ nv04_tv_create(struct drm_connector *connector, struct dcb_entry *entry)
243 }; 242 };
244 243
245 /* Attach it to the specified connector. */ 244 /* Attach it to the specified connector. */
246 sfuncs->set_config(encoder, nv04_tv_encoder_info[type].platform_data);
247 sfuncs->create_resources(encoder, connector); 245 sfuncs->create_resources(encoder, connector);
248 drm_mode_connector_attach_encoder(connector, encoder); 246 drm_mode_connector_attach_encoder(connector, encoder);
249 247
diff --git a/drivers/gpu/drm/nouveau/nv10_graph.c b/drivers/gpu/drm/nouveau/nv10_graph.c
index fcf2cdd19493..b2f6a57c0cc5 100644
--- a/drivers/gpu/drm/nouveau/nv10_graph.c
+++ b/drivers/gpu/drm/nouveau/nv10_graph.c
@@ -43,51 +43,51 @@ struct pipe_state {
43}; 43};
44 44
45static int nv10_graph_ctx_regs[] = { 45static int nv10_graph_ctx_regs[] = {
46 NV10_PGRAPH_CTX_SWITCH1, 46 NV10_PGRAPH_CTX_SWITCH(0),
47 NV10_PGRAPH_CTX_SWITCH2, 47 NV10_PGRAPH_CTX_SWITCH(1),
48 NV10_PGRAPH_CTX_SWITCH3, 48 NV10_PGRAPH_CTX_SWITCH(2),
49 NV10_PGRAPH_CTX_SWITCH4, 49 NV10_PGRAPH_CTX_SWITCH(3),
50 NV10_PGRAPH_CTX_SWITCH5, 50 NV10_PGRAPH_CTX_SWITCH(4),
51 NV10_PGRAPH_CTX_CACHE1, /* 8 values from 0x400160 to 0x40017c */ 51 NV10_PGRAPH_CTX_CACHE(0, 0),
52 NV10_PGRAPH_CTX_CACHE2, /* 8 values from 0x400180 to 0x40019c */ 52 NV10_PGRAPH_CTX_CACHE(0, 1),
53 NV10_PGRAPH_CTX_CACHE3, /* 8 values from 0x4001a0 to 0x4001bc */ 53 NV10_PGRAPH_CTX_CACHE(0, 2),
54 NV10_PGRAPH_CTX_CACHE4, /* 8 values from 0x4001c0 to 0x4001dc */ 54 NV10_PGRAPH_CTX_CACHE(0, 3),
55 NV10_PGRAPH_CTX_CACHE5, /* 8 values from 0x4001e0 to 0x4001fc */ 55 NV10_PGRAPH_CTX_CACHE(0, 4),
56 0x00400164, 56 NV10_PGRAPH_CTX_CACHE(1, 0),
57 0x00400184, 57 NV10_PGRAPH_CTX_CACHE(1, 1),
58 0x004001a4, 58 NV10_PGRAPH_CTX_CACHE(1, 2),
59 0x004001c4, 59 NV10_PGRAPH_CTX_CACHE(1, 3),
60 0x004001e4, 60 NV10_PGRAPH_CTX_CACHE(1, 4),
61 0x00400168, 61 NV10_PGRAPH_CTX_CACHE(2, 0),
62 0x00400188, 62 NV10_PGRAPH_CTX_CACHE(2, 1),
63 0x004001a8, 63 NV10_PGRAPH_CTX_CACHE(2, 2),
64 0x004001c8, 64 NV10_PGRAPH_CTX_CACHE(2, 3),
65 0x004001e8, 65 NV10_PGRAPH_CTX_CACHE(2, 4),
66 0x0040016c, 66 NV10_PGRAPH_CTX_CACHE(3, 0),
67 0x0040018c, 67 NV10_PGRAPH_CTX_CACHE(3, 1),
68 0x004001ac, 68 NV10_PGRAPH_CTX_CACHE(3, 2),
69 0x004001cc, 69 NV10_PGRAPH_CTX_CACHE(3, 3),
70 0x004001ec, 70 NV10_PGRAPH_CTX_CACHE(3, 4),
71 0x00400170, 71 NV10_PGRAPH_CTX_CACHE(4, 0),
72 0x00400190, 72 NV10_PGRAPH_CTX_CACHE(4, 1),
73 0x004001b0, 73 NV10_PGRAPH_CTX_CACHE(4, 2),
74 0x004001d0, 74 NV10_PGRAPH_CTX_CACHE(4, 3),
75 0x004001f0, 75 NV10_PGRAPH_CTX_CACHE(4, 4),
76 0x00400174, 76 NV10_PGRAPH_CTX_CACHE(5, 0),
77 0x00400194, 77 NV10_PGRAPH_CTX_CACHE(5, 1),
78 0x004001b4, 78 NV10_PGRAPH_CTX_CACHE(5, 2),
79 0x004001d4, 79 NV10_PGRAPH_CTX_CACHE(5, 3),
80 0x004001f4, 80 NV10_PGRAPH_CTX_CACHE(5, 4),
81 0x00400178, 81 NV10_PGRAPH_CTX_CACHE(6, 0),
82 0x00400198, 82 NV10_PGRAPH_CTX_CACHE(6, 1),
83 0x004001b8, 83 NV10_PGRAPH_CTX_CACHE(6, 2),
84 0x004001d8, 84 NV10_PGRAPH_CTX_CACHE(6, 3),
85 0x004001f8, 85 NV10_PGRAPH_CTX_CACHE(6, 4),
86 0x0040017c, 86 NV10_PGRAPH_CTX_CACHE(7, 0),
87 0x0040019c, 87 NV10_PGRAPH_CTX_CACHE(7, 1),
88 0x004001bc, 88 NV10_PGRAPH_CTX_CACHE(7, 2),
89 0x004001dc, 89 NV10_PGRAPH_CTX_CACHE(7, 3),
90 0x004001fc, 90 NV10_PGRAPH_CTX_CACHE(7, 4),
91 NV10_PGRAPH_CTX_USER, 91 NV10_PGRAPH_CTX_USER,
92 NV04_PGRAPH_DMA_START_0, 92 NV04_PGRAPH_DMA_START_0,
93 NV04_PGRAPH_DMA_START_1, 93 NV04_PGRAPH_DMA_START_1,
@@ -653,6 +653,78 @@ static int nv17_graph_ctx_regs_find_offset(struct drm_device *dev, int reg)
653 return -1; 653 return -1;
654} 654}
655 655
656static void nv10_graph_load_dma_vtxbuf(struct nouveau_channel *chan,
657 uint32_t inst)
658{
659 struct drm_device *dev = chan->dev;
660 struct drm_nouveau_private *dev_priv = dev->dev_private;
661 struct nouveau_pgraph_engine *pgraph = &dev_priv->engine.graph;
662 uint32_t st2, st2_dl, st2_dh, fifo_ptr, fifo[0x60/4];
663 uint32_t ctx_user, ctx_switch[5];
664 int i, subchan = -1;
665
666 /* NV10TCL_DMA_VTXBUF (method 0x18c) modifies hidden state
667 * that cannot be restored via MMIO. Do it through the FIFO
668 * instead.
669 */
670
671 /* Look for a celsius object */
672 for (i = 0; i < 8; i++) {
673 int class = nv_rd32(dev, NV10_PGRAPH_CTX_CACHE(i, 0)) & 0xfff;
674
675 if (class == 0x56 || class == 0x96 || class == 0x99) {
676 subchan = i;
677 break;
678 }
679 }
680
681 if (subchan < 0 || !inst)
682 return;
683
684 /* Save the current ctx object */
685 ctx_user = nv_rd32(dev, NV10_PGRAPH_CTX_USER);
686 for (i = 0; i < 5; i++)
687 ctx_switch[i] = nv_rd32(dev, NV10_PGRAPH_CTX_SWITCH(i));
688
689 /* Save the FIFO state */
690 st2 = nv_rd32(dev, NV10_PGRAPH_FFINTFC_ST2);
691 st2_dl = nv_rd32(dev, NV10_PGRAPH_FFINTFC_ST2_DL);
692 st2_dh = nv_rd32(dev, NV10_PGRAPH_FFINTFC_ST2_DH);
693 fifo_ptr = nv_rd32(dev, NV10_PGRAPH_FFINTFC_FIFO_PTR);
694
695 for (i = 0; i < ARRAY_SIZE(fifo); i++)
696 fifo[i] = nv_rd32(dev, 0x4007a0 + 4 * i);
697
698 /* Switch to the celsius subchannel */
699 for (i = 0; i < 5; i++)
700 nv_wr32(dev, NV10_PGRAPH_CTX_SWITCH(i),
701 nv_rd32(dev, NV10_PGRAPH_CTX_CACHE(subchan, i)));
702 nv_mask(dev, NV10_PGRAPH_CTX_USER, 0xe000, subchan << 13);
703
704 /* Inject NV10TCL_DMA_VTXBUF */
705 nv_wr32(dev, NV10_PGRAPH_FFINTFC_FIFO_PTR, 0);
706 nv_wr32(dev, NV10_PGRAPH_FFINTFC_ST2,
707 0x2c000000 | chan->id << 20 | subchan << 16 | 0x18c);
708 nv_wr32(dev, NV10_PGRAPH_FFINTFC_ST2_DL, inst);
709 nv_mask(dev, NV10_PGRAPH_CTX_CONTROL, 0, 0x10000);
710 pgraph->fifo_access(dev, true);
711 pgraph->fifo_access(dev, false);
712
713 /* Restore the FIFO state */
714 for (i = 0; i < ARRAY_SIZE(fifo); i++)
715 nv_wr32(dev, 0x4007a0 + 4 * i, fifo[i]);
716
717 nv_wr32(dev, NV10_PGRAPH_FFINTFC_FIFO_PTR, fifo_ptr);
718 nv_wr32(dev, NV10_PGRAPH_FFINTFC_ST2, st2);
719 nv_wr32(dev, NV10_PGRAPH_FFINTFC_ST2_DL, st2_dl);
720 nv_wr32(dev, NV10_PGRAPH_FFINTFC_ST2_DH, st2_dh);
721
722 /* Restore the current ctx object */
723 for (i = 0; i < 5; i++)
724 nv_wr32(dev, NV10_PGRAPH_CTX_SWITCH(i), ctx_switch[i]);
725 nv_wr32(dev, NV10_PGRAPH_CTX_USER, ctx_user);
726}
727
656int nv10_graph_load_context(struct nouveau_channel *chan) 728int nv10_graph_load_context(struct nouveau_channel *chan)
657{ 729{
658 struct drm_device *dev = chan->dev; 730 struct drm_device *dev = chan->dev;
@@ -670,6 +742,8 @@ int nv10_graph_load_context(struct nouveau_channel *chan)
670 } 742 }
671 743
672 nv10_graph_load_pipe(chan); 744 nv10_graph_load_pipe(chan);
745 nv10_graph_load_dma_vtxbuf(chan, (nv_rd32(dev, NV10_PGRAPH_GLOBALSTATE1)
746 & 0xffff));
673 747
674 nv_wr32(dev, NV10_PGRAPH_CTX_CONTROL, 0x10010100); 748 nv_wr32(dev, NV10_PGRAPH_CTX_CONTROL, 0x10010100);
675 tmp = nv_rd32(dev, NV10_PGRAPH_CTX_USER); 749 tmp = nv_rd32(dev, NV10_PGRAPH_CTX_USER);
@@ -856,11 +930,12 @@ int nv10_graph_init(struct drm_device *dev)
856 for (i = 0; i < NV10_PFB_TILE__SIZE; i++) 930 for (i = 0; i < NV10_PFB_TILE__SIZE; i++)
857 nv10_graph_set_region_tiling(dev, i, 0, 0, 0); 931 nv10_graph_set_region_tiling(dev, i, 0, 0, 0);
858 932
859 nv_wr32(dev, NV10_PGRAPH_CTX_SWITCH1, 0x00000000); 933 nv_wr32(dev, NV10_PGRAPH_CTX_SWITCH(0), 0x00000000);
860 nv_wr32(dev, NV10_PGRAPH_CTX_SWITCH2, 0x00000000); 934 nv_wr32(dev, NV10_PGRAPH_CTX_SWITCH(1), 0x00000000);
861 nv_wr32(dev, NV10_PGRAPH_CTX_SWITCH3, 0x00000000); 935 nv_wr32(dev, NV10_PGRAPH_CTX_SWITCH(2), 0x00000000);
862 nv_wr32(dev, NV10_PGRAPH_CTX_SWITCH4, 0x00000000); 936 nv_wr32(dev, NV10_PGRAPH_CTX_SWITCH(3), 0x00000000);
863 nv_wr32(dev, NV10_PGRAPH_STATE , 0xFFFFFFFF); 937 nv_wr32(dev, NV10_PGRAPH_CTX_SWITCH(4), 0x00000000);
938 nv_wr32(dev, NV10_PGRAPH_STATE, 0xFFFFFFFF);
864 939
865 tmp = nv_rd32(dev, NV10_PGRAPH_CTX_USER) & 0x00ffffff; 940 tmp = nv_rd32(dev, NV10_PGRAPH_CTX_USER) & 0x00ffffff;
866 tmp |= (dev_priv->engine.fifo.channels - 1) << 24; 941 tmp |= (dev_priv->engine.fifo.channels - 1) << 24;
diff --git a/drivers/gpu/drm/nouveau/nv30_fb.c b/drivers/gpu/drm/nouveau/nv30_fb.c
index 9d35c8b3b839..4a3f2f095128 100644
--- a/drivers/gpu/drm/nouveau/nv30_fb.c
+++ b/drivers/gpu/drm/nouveau/nv30_fb.c
@@ -30,15 +30,25 @@
30#include "nouveau_drm.h" 30#include "nouveau_drm.h"
31 31
32static int 32static int
33calc_ref(int b, int l, int i) 33calc_bias(struct drm_device *dev, int k, int i, int j)
34{
35 struct drm_nouveau_private *dev_priv = dev->dev_private;
36 int b = (dev_priv->chipset > 0x30 ?
37 nv_rd32(dev, 0x122c + 0x10 * k + 0x4 * j) >> (4 * (i ^ 1)) :
38 0) & 0xf;
39
40 return 2 * (b & 0x8 ? b - 0x10 : b);
41}
42
43static int
44calc_ref(struct drm_device *dev, int l, int k, int i)
34{ 45{
35 int j, x = 0; 46 int j, x = 0;
36 47
37 for (j = 0; j < 4; j++) { 48 for (j = 0; j < 4; j++) {
38 int n = (b >> (8 * j) & 0xf); 49 int m = (l >> (8 * i) & 0xff) + calc_bias(dev, k, i, j);
39 int m = (l >> (8 * i) & 0xff) + 2 * (n & 0x8 ? n - 0x10 : n);
40 50
41 x |= (0x80 | (m & 0x1f)) << (8 * j); 51 x |= (0x80 | clamp(m, 0, 0x1f)) << (8 * j);
42 } 52 }
43 53
44 return x; 54 return x;
@@ -63,18 +73,16 @@ nv30_fb_init(struct drm_device *dev)
63 dev_priv->chipset == 0x35) { 73 dev_priv->chipset == 0x35) {
64 /* Related to ROP count */ 74 /* Related to ROP count */
65 int n = (dev_priv->chipset == 0x31 ? 2 : 4); 75 int n = (dev_priv->chipset == 0x31 ? 2 : 4);
66 int b = (dev_priv->chipset > 0x30 ?
67 nv_rd32(dev, 0x122c) & 0xf : 0);
68 int l = nv_rd32(dev, 0x1003d0); 76 int l = nv_rd32(dev, 0x1003d0);
69 77
70 for (i = 0; i < n; i++) { 78 for (i = 0; i < n; i++) {
71 for (j = 0; j < 3; j++) 79 for (j = 0; j < 3; j++)
72 nv_wr32(dev, 0x10037c + 0xc * i + 0x4 * j, 80 nv_wr32(dev, 0x10037c + 0xc * i + 0x4 * j,
73 calc_ref(b, l, j)); 81 calc_ref(dev, l, 0, j));
74 82
75 for (j = 0; j < 2; j++) 83 for (j = 0; j < 2; j++)
76 nv_wr32(dev, 0x1003ac + 0x8 * i + 0x4 * j, 84 nv_wr32(dev, 0x1003ac + 0x8 * i + 0x4 * j,
77 calc_ref(b, l, j)); 85 calc_ref(dev, l, 1, j));
78 } 86 }
79 } 87 }
80 88
diff --git a/drivers/gpu/drm/nouveau/nv50_crtc.c b/drivers/gpu/drm/nouveau/nv50_crtc.c
index 5d11ea101666..bfd4ca2fe7ef 100644
--- a/drivers/gpu/drm/nouveau/nv50_crtc.c
+++ b/drivers/gpu/drm/nouveau/nv50_crtc.c
@@ -264,11 +264,16 @@ nv50_crtc_set_scale(struct nouveau_crtc *nv_crtc, int scaling_mode, bool update)
264int 264int
265nv50_crtc_set_clock(struct drm_device *dev, int head, int pclk) 265nv50_crtc_set_clock(struct drm_device *dev, int head, int pclk)
266{ 266{
267 uint32_t reg = NV50_PDISPLAY_CRTC_CLK_CTRL1(head); 267 struct drm_nouveau_private *dev_priv = dev->dev_private;
268 struct pll_lims pll; 268 struct pll_lims pll;
269 uint32_t reg1, reg2; 269 uint32_t reg, reg1, reg2;
270 int ret, N1, M1, N2, M2, P; 270 int ret, N1, M1, N2, M2, P;
271 271
272 if (dev_priv->chipset < NV_C0)
273 reg = NV50_PDISPLAY_CRTC_CLK_CTRL1(head);
274 else
275 reg = 0x614140 + (head * 0x800);
276
272 ret = get_pll_limits(dev, reg, &pll); 277 ret = get_pll_limits(dev, reg, &pll);
273 if (ret) 278 if (ret)
274 return ret; 279 return ret;
@@ -286,7 +291,8 @@ nv50_crtc_set_clock(struct drm_device *dev, int head, int pclk)
286 nv_wr32(dev, reg, 0x10000611); 291 nv_wr32(dev, reg, 0x10000611);
287 nv_wr32(dev, reg + 4, reg1 | (M1 << 16) | N1); 292 nv_wr32(dev, reg + 4, reg1 | (M1 << 16) | N1);
288 nv_wr32(dev, reg + 8, reg2 | (P << 28) | (M2 << 16) | N2); 293 nv_wr32(dev, reg + 8, reg2 | (P << 28) | (M2 << 16) | N2);
289 } else { 294 } else
295 if (dev_priv->chipset < NV_C0) {
290 ret = nv50_calc_pll2(dev, &pll, pclk, &N1, &N2, &M1, &P); 296 ret = nv50_calc_pll2(dev, &pll, pclk, &N1, &N2, &M1, &P);
291 if (ret <= 0) 297 if (ret <= 0)
292 return 0; 298 return 0;
@@ -298,6 +304,17 @@ nv50_crtc_set_clock(struct drm_device *dev, int head, int pclk)
298 nv_wr32(dev, reg, 0x50000610); 304 nv_wr32(dev, reg, 0x50000610);
299 nv_wr32(dev, reg + 4, reg1 | (P << 16) | (M1 << 8) | N1); 305 nv_wr32(dev, reg + 4, reg1 | (P << 16) | (M1 << 8) | N1);
300 nv_wr32(dev, reg + 8, N2); 306 nv_wr32(dev, reg + 8, N2);
307 } else {
308 ret = nv50_calc_pll2(dev, &pll, pclk, &N1, &N2, &M1, &P);
309 if (ret <= 0)
310 return 0;
311
312 NV_DEBUG(dev, "pclk %d out %d N %d fN 0x%04x M %d P %d\n",
313 pclk, ret, N1, N2, M1, P);
314
315 nv_mask(dev, reg + 0x0c, 0x00000000, 0x00000100);
316 nv_wr32(dev, reg + 0x04, (P << 16) | (N1 << 8) | M1);
317 nv_wr32(dev, reg + 0x10, N2 << 16);
301 } 318 }
302 319
303 return 0; 320 return 0;
@@ -348,7 +365,7 @@ nv50_crtc_cursor_set(struct drm_crtc *crtc, struct drm_file *file_priv,
348 365
349 gem = drm_gem_object_lookup(dev, file_priv, buffer_handle); 366 gem = drm_gem_object_lookup(dev, file_priv, buffer_handle);
350 if (!gem) 367 if (!gem)
351 return -EINVAL; 368 return -ENOENT;
352 cursor = nouveau_gem_object(gem); 369 cursor = nouveau_gem_object(gem);
353 370
354 ret = nouveau_bo_map(cursor); 371 ret = nouveau_bo_map(cursor);
@@ -381,15 +398,12 @@ nv50_crtc_cursor_move(struct drm_crtc *crtc, int x, int y)
381 398
382static void 399static void
383nv50_crtc_gamma_set(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b, 400nv50_crtc_gamma_set(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
384 uint32_t size) 401 uint32_t start, uint32_t size)
385{ 402{
403 int end = (start + size > 256) ? 256 : start + size, i;
386 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); 404 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
387 int i;
388
389 if (size != 256)
390 return;
391 405
392 for (i = 0; i < 256; i++) { 406 for (i = start; i < end; i++) {
393 nv_crtc->lut.r[i] = r[i]; 407 nv_crtc->lut.r[i] = r[i];
394 nv_crtc->lut.g[i] = g[i]; 408 nv_crtc->lut.g[i] = g[i];
395 nv_crtc->lut.b[i] = b[i]; 409 nv_crtc->lut.b[i] = b[i];
diff --git a/drivers/gpu/drm/nouveau/nv50_display.c b/drivers/gpu/drm/nouveau/nv50_display.c
index f13ad0de9c8f..612fa6d6a0cb 100644
--- a/drivers/gpu/drm/nouveau/nv50_display.c
+++ b/drivers/gpu/drm/nouveau/nv50_display.c
@@ -76,7 +76,10 @@ nv50_evo_dmaobj_new(struct nouveau_channel *evo, uint32_t class, uint32_t name,
76 nv_wo32(dev, obj, 2, offset); 76 nv_wo32(dev, obj, 2, offset);
77 nv_wo32(dev, obj, 3, 0x00000000); 77 nv_wo32(dev, obj, 3, 0x00000000);
78 nv_wo32(dev, obj, 4, 0x00000000); 78 nv_wo32(dev, obj, 4, 0x00000000);
79 nv_wo32(dev, obj, 5, 0x00010000); 79 if (dev_priv->card_type < NV_C0)
80 nv_wo32(dev, obj, 5, 0x00010000);
81 else
82 nv_wo32(dev, obj, 5, 0x00020000);
80 dev_priv->engine.instmem.flush(dev); 83 dev_priv->engine.instmem.flush(dev);
81 84
82 return 0; 85 return 0;
diff --git a/drivers/gpu/drm/nouveau/nvc0_fb.c b/drivers/gpu/drm/nouveau/nvc0_fb.c
new file mode 100644
index 000000000000..26a996025dd2
--- /dev/null
+++ b/drivers/gpu/drm/nouveau/nvc0_fb.c
@@ -0,0 +1,38 @@
1/*
2 * Copyright 2010 Red Hat Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * Authors: Ben Skeggs
23 */
24
25#include "drmP.h"
26
27#include "nouveau_drv.h"
28
29int
30nvc0_fb_init(struct drm_device *dev)
31{
32 return 0;
33}
34
35void
36nvc0_fb_takedown(struct drm_device *dev)
37{
38}
diff --git a/drivers/gpu/drm/nouveau/nvc0_fifo.c b/drivers/gpu/drm/nouveau/nvc0_fifo.c
new file mode 100644
index 000000000000..d64375871979
--- /dev/null
+++ b/drivers/gpu/drm/nouveau/nvc0_fifo.c
@@ -0,0 +1,96 @@
1/*
2 * Copyright 2010 Red Hat Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * Authors: Ben Skeggs
23 */
24
25#include "drmP.h"
26
27#include "nouveau_drv.h"
28
29void
30nvc0_fifo_disable(struct drm_device *dev)
31{
32}
33
34void
35nvc0_fifo_enable(struct drm_device *dev)
36{
37}
38
39bool
40nvc0_fifo_reassign(struct drm_device *dev, bool enable)
41{
42 return false;
43}
44
45bool
46nvc0_fifo_cache_flush(struct drm_device *dev)
47{
48 return true;
49}
50
51bool
52nvc0_fifo_cache_pull(struct drm_device *dev, bool enable)
53{
54 return false;
55}
56
57int
58nvc0_fifo_channel_id(struct drm_device *dev)
59{
60 return 127;
61}
62
63int
64nvc0_fifo_create_context(struct nouveau_channel *chan)
65{
66 return 0;
67}
68
69void
70nvc0_fifo_destroy_context(struct nouveau_channel *chan)
71{
72}
73
74int
75nvc0_fifo_load_context(struct nouveau_channel *chan)
76{
77 return 0;
78}
79
80int
81nvc0_fifo_unload_context(struct drm_device *dev)
82{
83 return 0;
84}
85
86void
87nvc0_fifo_takedown(struct drm_device *dev)
88{
89}
90
91int
92nvc0_fifo_init(struct drm_device *dev)
93{
94 return 0;
95}
96
diff --git a/drivers/gpu/drm/nouveau/nvc0_graph.c b/drivers/gpu/drm/nouveau/nvc0_graph.c
new file mode 100644
index 000000000000..717a5177a8d8
--- /dev/null
+++ b/drivers/gpu/drm/nouveau/nvc0_graph.c
@@ -0,0 +1,75 @@
1/*
2 * Copyright 2010 Red Hat Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * Authors: Ben Skeggs
23 */
24
25#include "drmP.h"
26
27#include "nouveau_drv.h"
28
29void
30nvc0_graph_fifo_access(struct drm_device *dev, bool enabled)
31{
32}
33
34struct nouveau_channel *
35nvc0_graph_channel(struct drm_device *dev)
36{
37 return NULL;
38}
39
40int
41nvc0_graph_create_context(struct nouveau_channel *chan)
42{
43 return 0;
44}
45
46void
47nvc0_graph_destroy_context(struct nouveau_channel *chan)
48{
49}
50
51int
52nvc0_graph_load_context(struct nouveau_channel *chan)
53{
54 return 0;
55}
56
57int
58nvc0_graph_unload_context(struct drm_device *dev)
59{
60 return 0;
61}
62
63void
64nvc0_graph_takedown(struct drm_device *dev)
65{
66}
67
68int
69nvc0_graph_init(struct drm_device *dev)
70{
71 struct drm_nouveau_private *dev_priv = dev->dev_private;
72 dev_priv->engine.graph.accel_blocked = true;
73 return 0;
74}
75
diff --git a/drivers/gpu/drm/nouveau/nvc0_instmem.c b/drivers/gpu/drm/nouveau/nvc0_instmem.c
new file mode 100644
index 000000000000..3ab3cdc42173
--- /dev/null
+++ b/drivers/gpu/drm/nouveau/nvc0_instmem.c
@@ -0,0 +1,232 @@
1/*
2 * Copyright 2010 Red Hat Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * Authors: Ben Skeggs
23 */
24
25#include "drmP.h"
26
27#include "nouveau_drv.h"
28
29int
30nvc0_instmem_populate(struct drm_device *dev, struct nouveau_gpuobj *gpuobj,
31 uint32_t *size)
32{
33 int ret;
34
35 *size = ALIGN(*size, 4096);
36 if (*size == 0)
37 return -EINVAL;
38
39 ret = nouveau_bo_new(dev, NULL, *size, 0, TTM_PL_FLAG_VRAM, 0, 0x0000,
40 true, false, &gpuobj->im_backing);
41 if (ret) {
42 NV_ERROR(dev, "error getting PRAMIN backing pages: %d\n", ret);
43 return ret;
44 }
45
46 ret = nouveau_bo_pin(gpuobj->im_backing, TTM_PL_FLAG_VRAM);
47 if (ret) {
48 NV_ERROR(dev, "error pinning PRAMIN backing VRAM: %d\n", ret);
49 nouveau_bo_ref(NULL, &gpuobj->im_backing);
50 return ret;
51 }
52
53 gpuobj->im_backing_start = gpuobj->im_backing->bo.mem.mm_node->start;
54 gpuobj->im_backing_start <<= PAGE_SHIFT;
55 return 0;
56}
57
58void
59nvc0_instmem_clear(struct drm_device *dev, struct nouveau_gpuobj *gpuobj)
60{
61 struct drm_nouveau_private *dev_priv = dev->dev_private;
62
63 if (gpuobj && gpuobj->im_backing) {
64 if (gpuobj->im_bound)
65 dev_priv->engine.instmem.unbind(dev, gpuobj);
66 nouveau_bo_unpin(gpuobj->im_backing);
67 nouveau_bo_ref(NULL, &gpuobj->im_backing);
68 gpuobj->im_backing = NULL;
69 }
70}
71
72int
73nvc0_instmem_bind(struct drm_device *dev, struct nouveau_gpuobj *gpuobj)
74{
75 struct drm_nouveau_private *dev_priv = dev->dev_private;
76 uint32_t pte, pte_end;
77 uint64_t vram;
78
79 if (!gpuobj->im_backing || !gpuobj->im_pramin || gpuobj->im_bound)
80 return -EINVAL;
81
82 NV_DEBUG(dev, "st=0x%lx sz=0x%lx\n",
83 gpuobj->im_pramin->start, gpuobj->im_pramin->size);
84
85 pte = gpuobj->im_pramin->start >> 12;
86 pte_end = (gpuobj->im_pramin->size >> 12) + pte;
87 vram = gpuobj->im_backing_start;
88
89 NV_DEBUG(dev, "pramin=0x%lx, pte=%d, pte_end=%d\n",
90 gpuobj->im_pramin->start, pte, pte_end);
91 NV_DEBUG(dev, "first vram page: 0x%08x\n", gpuobj->im_backing_start);
92
93 while (pte < pte_end) {
94 nv_wr32(dev, 0x702000 + (pte * 8), (vram >> 8) | 1);
95 nv_wr32(dev, 0x702004 + (pte * 8), 0);
96 vram += 4096;
97 pte++;
98 }
99 dev_priv->engine.instmem.flush(dev);
100
101 if (1) {
102 u32 chan = nv_rd32(dev, 0x1700) << 16;
103 nv_wr32(dev, 0x100cb8, (chan + 0x1000) >> 8);
104 nv_wr32(dev, 0x100cbc, 0x80000005);
105 }
106
107 gpuobj->im_bound = 1;
108 return 0;
109}
110
111int
112nvc0_instmem_unbind(struct drm_device *dev, struct nouveau_gpuobj *gpuobj)
113{
114 struct drm_nouveau_private *dev_priv = dev->dev_private;
115 uint32_t pte, pte_end;
116
117 if (gpuobj->im_bound == 0)
118 return -EINVAL;
119
120 pte = gpuobj->im_pramin->start >> 12;
121 pte_end = (gpuobj->im_pramin->size >> 12) + pte;
122 while (pte < pte_end) {
123 nv_wr32(dev, 0x702000 + (pte * 8), 0);
124 nv_wr32(dev, 0x702004 + (pte * 8), 0);
125 pte++;
126 }
127 dev_priv->engine.instmem.flush(dev);
128
129 gpuobj->im_bound = 0;
130 return 0;
131}
132
133void
134nvc0_instmem_flush(struct drm_device *dev)
135{
136 nv_wr32(dev, 0x070000, 1);
137 if (!nv_wait(0x070000, 0x00000002, 0x00000000))
138 NV_ERROR(dev, "PRAMIN flush timeout\n");
139}
140
141int
142nvc0_instmem_suspend(struct drm_device *dev)
143{
144 struct drm_nouveau_private *dev_priv = dev->dev_private;
145 int i;
146
147 dev_priv->susres.ramin_copy = vmalloc(65536);
148 if (!dev_priv->susres.ramin_copy)
149 return -ENOMEM;
150
151 for (i = 0x700000; i < 0x710000; i += 4)
152 dev_priv->susres.ramin_copy[i/4] = nv_rd32(dev, i);
153 return 0;
154}
155
156void
157nvc0_instmem_resume(struct drm_device *dev)
158{
159 struct drm_nouveau_private *dev_priv = dev->dev_private;
160 u64 chan;
161 int i;
162
163 chan = dev_priv->vram_size - dev_priv->ramin_rsvd_vram;
164 nv_wr32(dev, 0x001700, chan >> 16);
165
166 for (i = 0x700000; i < 0x710000; i += 4)
167 nv_wr32(dev, i, dev_priv->susres.ramin_copy[i/4]);
168 vfree(dev_priv->susres.ramin_copy);
169 dev_priv->susres.ramin_copy = NULL;
170
171 nv_wr32(dev, 0x001714, 0xc0000000 | (chan >> 12));
172}
173
174int
175nvc0_instmem_init(struct drm_device *dev)
176{
177 struct drm_nouveau_private *dev_priv = dev->dev_private;
178 u64 chan, pgt3, imem, lim3 = dev_priv->ramin_size - 1;
179 int ret, i;
180
181 dev_priv->ramin_rsvd_vram = 1 * 1024 * 1024;
182 chan = dev_priv->vram_size - dev_priv->ramin_rsvd_vram;
183 imem = 4096 + 4096 + 32768;
184
185 nv_wr32(dev, 0x001700, chan >> 16);
186
187 /* channel setup */
188 nv_wr32(dev, 0x700200, lower_32_bits(chan + 0x1000));
189 nv_wr32(dev, 0x700204, upper_32_bits(chan + 0x1000));
190 nv_wr32(dev, 0x700208, lower_32_bits(lim3));
191 nv_wr32(dev, 0x70020c, upper_32_bits(lim3));
192
193 /* point pgd -> pgt */
194 nv_wr32(dev, 0x701000, 0);
195 nv_wr32(dev, 0x701004, ((chan + 0x2000) >> 8) | 1);
196
197 /* point pgt -> physical vram for channel */
198 pgt3 = 0x2000;
199 for (i = 0; i < dev_priv->ramin_rsvd_vram; i += 4096, pgt3 += 8) {
200 nv_wr32(dev, 0x700000 + pgt3, ((chan + i) >> 8) | 1);
201 nv_wr32(dev, 0x700004 + pgt3, 0);
202 }
203
204 /* clear rest of pgt */
205 for (; i < dev_priv->ramin_size; i += 4096, pgt3 += 8) {
206 nv_wr32(dev, 0x700000 + pgt3, 0);
207 nv_wr32(dev, 0x700004 + pgt3, 0);
208 }
209
210 /* point bar3 at the channel */
211 nv_wr32(dev, 0x001714, 0xc0000000 | (chan >> 12));
212
213 /* Global PRAMIN heap */
214 ret = drm_mm_init(&dev_priv->ramin_heap, imem,
215 dev_priv->ramin_size - imem);
216 if (ret) {
217 NV_ERROR(dev, "Failed to init RAMIN heap\n");
218 return -ENOMEM;
219 }
220
221 /*XXX: incorrect, but needed to make hash func "work" */
222 dev_priv->ramht_offset = 0x10000;
223 dev_priv->ramht_bits = 9;
224 dev_priv->ramht_size = (1 << dev_priv->ramht_bits);
225 return 0;
226}
227
228void
229nvc0_instmem_takedown(struct drm_device *dev)
230{
231}
232
diff --git a/drivers/gpu/drm/radeon/r600_cp.c b/drivers/gpu/drm/radeon/r600_cp.c
index 68e6f4349309..4f4cd8b286d5 100644
--- a/drivers/gpu/drm/radeon/r600_cp.c
+++ b/drivers/gpu/drm/radeon/r600_cp.c
@@ -200,7 +200,7 @@ int r600_page_table_init(struct drm_device *dev)
200 entry->pagelist[i], 0, 200 entry->pagelist[i], 0,
201 PAGE_SIZE, 201 PAGE_SIZE,
202 PCI_DMA_BIDIRECTIONAL); 202 PCI_DMA_BIDIRECTIONAL);
203 if (entry->busaddr[i] == 0) { 203 if (pci_dma_mapping_error(dev->pdev, entry->busaddr[i])) {
204 DRM_ERROR("unable to map PCIGART pages!\n"); 204 DRM_ERROR("unable to map PCIGART pages!\n");
205 r600_page_table_cleanup(dev, gart_info); 205 r600_page_table_cleanup(dev, gart_info);
206 goto done; 206 goto done;
diff --git a/drivers/gpu/drm/radeon/r600_cs.c b/drivers/gpu/drm/radeon/r600_cs.c
index c3ea212e0c3c..d8864949e387 100644
--- a/drivers/gpu/drm/radeon/r600_cs.c
+++ b/drivers/gpu/drm/radeon/r600_cs.c
@@ -133,6 +133,7 @@ static inline int r600_bpe_from_format(u32 *bpe, u32 format)
133 case V_038004_FMT_GB_GR: 133 case V_038004_FMT_GB_GR:
134 case V_038004_FMT_BG_RG: 134 case V_038004_FMT_BG_RG:
135 case V_038004_COLOR_INVALID: 135 case V_038004_COLOR_INVALID:
136 default:
136 *bpe = 16; 137 *bpe = 16;
137 return -EINVAL; 138 return -EINVAL;
138 } 139 }
@@ -174,7 +175,7 @@ static inline int r600_cs_track_validate_cb(struct radeon_cs_parser *p, int i)
174 dev_warn(p->dev, "FMASK or CMASK buffer are not supported by this kernel\n"); 175 dev_warn(p->dev, "FMASK or CMASK buffer are not supported by this kernel\n");
175 return -EINVAL; 176 return -EINVAL;
176 } 177 }
177 size = radeon_bo_size(track->cb_color_bo[i]); 178 size = radeon_bo_size(track->cb_color_bo[i]) - track->cb_color_bo_offset[i];
178 if (r600_bpe_from_format(&bpe, G_0280A0_FORMAT(track->cb_color_info[i]))) { 179 if (r600_bpe_from_format(&bpe, G_0280A0_FORMAT(track->cb_color_info[i]))) {
179 dev_warn(p->dev, "%s:%d cb invalid format %d for %d (0x%08X)\n", 180 dev_warn(p->dev, "%s:%d cb invalid format %d for %d (0x%08X)\n",
180 __func__, __LINE__, G_0280A0_FORMAT(track->cb_color_info[i]), 181 __func__, __LINE__, G_0280A0_FORMAT(track->cb_color_info[i]),
@@ -327,7 +328,6 @@ static int r600_cs_track_check(struct radeon_cs_parser *p)
327 dev_warn(p->dev, "z/stencil buffer size not set\n"); 328 dev_warn(p->dev, "z/stencil buffer size not set\n");
328 return -EINVAL; 329 return -EINVAL;
329 } 330 }
330 printk_once(KERN_WARNING "You have old & broken userspace please consider updating mesa\n");
331 tmp = radeon_bo_size(track->db_bo) - track->db_offset; 331 tmp = radeon_bo_size(track->db_bo) - track->db_offset;
332 tmp = (tmp / bpe) >> 6; 332 tmp = (tmp / bpe) >> 6;
333 if (!tmp) { 333 if (!tmp) {
@@ -882,8 +882,6 @@ static inline int r600_cs_check_reg(struct radeon_cs_parser *p, u32 reg, u32 idx
882 return -EINVAL; 882 return -EINVAL;
883 } 883 }
884 ib[idx] = track->cb_color_base_last[tmp]; 884 ib[idx] = track->cb_color_base_last[tmp];
885 printk_once(KERN_WARNING "You have old & broken userspace "
886 "please consider updating mesa & xf86-video-ati\n");
887 track->cb_color_frag_bo[tmp] = track->cb_color_bo[tmp]; 885 track->cb_color_frag_bo[tmp] = track->cb_color_bo[tmp];
888 } else { 886 } else {
889 r = r600_cs_packet_next_reloc(p, &reloc); 887 r = r600_cs_packet_next_reloc(p, &reloc);
@@ -910,8 +908,6 @@ static inline int r600_cs_check_reg(struct radeon_cs_parser *p, u32 reg, u32 idx
910 return -EINVAL; 908 return -EINVAL;
911 } 909 }
912 ib[idx] = track->cb_color_base_last[tmp]; 910 ib[idx] = track->cb_color_base_last[tmp];
913 printk_once(KERN_WARNING "You have old & broken userspace "
914 "please consider updating mesa & xf86-video-ati\n");
915 track->cb_color_tile_bo[tmp] = track->cb_color_bo[tmp]; 911 track->cb_color_tile_bo[tmp] = track->cb_color_bo[tmp];
916 } else { 912 } else {
917 r = r600_cs_packet_next_reloc(p, &reloc); 913 r = r600_cs_packet_next_reloc(p, &reloc);
@@ -938,7 +934,7 @@ static inline int r600_cs_check_reg(struct radeon_cs_parser *p, u32 reg, u32 idx
938 return -EINVAL; 934 return -EINVAL;
939 } 935 }
940 tmp = (reg - CB_COLOR0_BASE) / 4; 936 tmp = (reg - CB_COLOR0_BASE) / 4;
941 track->cb_color_bo_offset[tmp] = radeon_get_ib_value(p, idx); 937 track->cb_color_bo_offset[tmp] = radeon_get_ib_value(p, idx) << 8;
942 ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff); 938 ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
943 track->cb_color_base_last[tmp] = ib[idx]; 939 track->cb_color_base_last[tmp] = ib[idx];
944 track->cb_color_bo[tmp] = reloc->robj; 940 track->cb_color_bo[tmp] = reloc->robj;
@@ -950,7 +946,7 @@ static inline int r600_cs_check_reg(struct radeon_cs_parser *p, u32 reg, u32 idx
950 "0x%04X\n", reg); 946 "0x%04X\n", reg);
951 return -EINVAL; 947 return -EINVAL;
952 } 948 }
953 track->db_offset = radeon_get_ib_value(p, idx); 949 track->db_offset = radeon_get_ib_value(p, idx) << 8;
954 ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff); 950 ib[idx] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
955 track->db_bo = reloc->robj; 951 track->db_bo = reloc->robj;
956 break; 952 break;
@@ -1055,10 +1051,10 @@ static void r600_texture_size(unsigned nfaces, unsigned blevel, unsigned nlevels
1055 } 1051 }
1056 *l0_size = ALIGN((w0 * bpe), pitch_align) * h0 * d0; 1052 *l0_size = ALIGN((w0 * bpe), pitch_align) * h0 * d0;
1057 *mipmap_size = offset; 1053 *mipmap_size = offset;
1058 if (!blevel)
1059 *mipmap_size -= *l0_size;
1060 if (!nlevels) 1054 if (!nlevels)
1061 *mipmap_size = *l0_size; 1055 *mipmap_size = *l0_size;
1056 if (!blevel)
1057 *mipmap_size -= *l0_size;
1062} 1058}
1063 1059
1064/** 1060/**
@@ -1165,14 +1161,14 @@ static inline int r600_check_texture_resource(struct radeon_cs_parser *p, u32 i
1165 (pitch_align * bpe), 1161 (pitch_align * bpe),
1166 &l0_size, &mipmap_size); 1162 &l0_size, &mipmap_size);
1167 /* using get ib will give us the offset into the texture bo */ 1163 /* using get ib will give us the offset into the texture bo */
1168 word0 = radeon_get_ib_value(p, idx + 2); 1164 word0 = radeon_get_ib_value(p, idx + 2) << 8;
1169 if ((l0_size + word0) > radeon_bo_size(texture)) { 1165 if ((l0_size + word0) > radeon_bo_size(texture)) {
1170 dev_warn(p->dev, "texture bo too small (%d %d %d %d -> %d have %ld)\n", 1166 dev_warn(p->dev, "texture bo too small (%d %d %d %d -> %d have %ld)\n",
1171 w0, h0, bpe, word0, l0_size, radeon_bo_size(texture)); 1167 w0, h0, bpe, word0, l0_size, radeon_bo_size(texture));
1172 return -EINVAL; 1168 return -EINVAL;
1173 } 1169 }
1174 /* using get ib will give us the offset into the mipmap bo */ 1170 /* using get ib will give us the offset into the mipmap bo */
1175 word0 = radeon_get_ib_value(p, idx + 3); 1171 word0 = radeon_get_ib_value(p, idx + 3) << 8;
1176 if ((mipmap_size + word0) > radeon_bo_size(mipmap)) { 1172 if ((mipmap_size + word0) > radeon_bo_size(mipmap)) {
1177 dev_warn(p->dev, "mipmap bo too small (%d %d %d %d %d %d -> %d have %ld)\n", 1173 dev_warn(p->dev, "mipmap bo too small (%d %d %d %d %d %d -> %d have %ld)\n",
1178 w0, h0, bpe, blevel, nlevels, word0, mipmap_size, radeon_bo_size(texture)); 1174 w0, h0, bpe, blevel, nlevels, word0, mipmap_size, radeon_bo_size(texture));
@@ -1366,7 +1362,7 @@ static int r600_packet3_check(struct radeon_cs_parser *p,
1366 } 1362 }
1367 for (i = 0; i < (pkt->count / 7); i++) { 1363 for (i = 0; i < (pkt->count / 7); i++) {
1368 struct radeon_bo *texture, *mipmap; 1364 struct radeon_bo *texture, *mipmap;
1369 u32 size, offset; 1365 u32 size, offset, base_offset, mip_offset;
1370 1366
1371 switch (G__SQ_VTX_CONSTANT_TYPE(radeon_get_ib_value(p, idx+(i*7)+6+1))) { 1367 switch (G__SQ_VTX_CONSTANT_TYPE(radeon_get_ib_value(p, idx+(i*7)+6+1))) {
1372 case SQ_TEX_VTX_VALID_TEXTURE: 1368 case SQ_TEX_VTX_VALID_TEXTURE:
@@ -1376,7 +1372,7 @@ static int r600_packet3_check(struct radeon_cs_parser *p,
1376 DRM_ERROR("bad SET_RESOURCE\n"); 1372 DRM_ERROR("bad SET_RESOURCE\n");
1377 return -EINVAL; 1373 return -EINVAL;
1378 } 1374 }
1379 ib[idx+1+(i*7)+2] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff); 1375 base_offset = (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
1380 if (reloc->lobj.tiling_flags & RADEON_TILING_MACRO) 1376 if (reloc->lobj.tiling_flags & RADEON_TILING_MACRO)
1381 ib[idx+1+(i*7)+0] |= S_038000_TILE_MODE(V_038000_ARRAY_2D_TILED_THIN1); 1377 ib[idx+1+(i*7)+0] |= S_038000_TILE_MODE(V_038000_ARRAY_2D_TILED_THIN1);
1382 else if (reloc->lobj.tiling_flags & RADEON_TILING_MICRO) 1378 else if (reloc->lobj.tiling_flags & RADEON_TILING_MICRO)
@@ -1388,12 +1384,14 @@ static int r600_packet3_check(struct radeon_cs_parser *p,
1388 DRM_ERROR("bad SET_RESOURCE\n"); 1384 DRM_ERROR("bad SET_RESOURCE\n");
1389 return -EINVAL; 1385 return -EINVAL;
1390 } 1386 }
1391 ib[idx+1+(i*7)+3] += (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff); 1387 mip_offset = (u32)((reloc->lobj.gpu_offset >> 8) & 0xffffffff);
1392 mipmap = reloc->robj; 1388 mipmap = reloc->robj;
1393 r = r600_check_texture_resource(p, idx+(i*7)+1, 1389 r = r600_check_texture_resource(p, idx+(i*7)+1,
1394 texture, mipmap, reloc->lobj.tiling_flags); 1390 texture, mipmap, reloc->lobj.tiling_flags);
1395 if (r) 1391 if (r)
1396 return r; 1392 return r;
1393 ib[idx+1+(i*7)+2] += base_offset;
1394 ib[idx+1+(i*7)+3] += mip_offset;
1397 break; 1395 break;
1398 case SQ_TEX_VTX_VALID_BUFFER: 1396 case SQ_TEX_VTX_VALID_BUFFER:
1399 /* vtx base */ 1397 /* vtx base */
@@ -1403,10 +1401,11 @@ static int r600_packet3_check(struct radeon_cs_parser *p,
1403 return -EINVAL; 1401 return -EINVAL;
1404 } 1402 }
1405 offset = radeon_get_ib_value(p, idx+1+(i*7)+0); 1403 offset = radeon_get_ib_value(p, idx+1+(i*7)+0);
1406 size = radeon_get_ib_value(p, idx+1+(i*7)+1); 1404 size = radeon_get_ib_value(p, idx+1+(i*7)+1) + 1;
1407 if (p->rdev && (size + offset) > radeon_bo_size(reloc->robj)) { 1405 if (p->rdev && (size + offset) > radeon_bo_size(reloc->robj)) {
1408 /* force size to size of the buffer */ 1406 /* force size to size of the buffer */
1409 dev_warn(p->dev, "vbo resource seems too big for the bo\n"); 1407 dev_warn(p->dev, "vbo resource seems too big (%d) for the bo (%ld)\n",
1408 size + offset, radeon_bo_size(reloc->robj));
1410 ib[idx+1+(i*7)+1] = radeon_bo_size(reloc->robj); 1409 ib[idx+1+(i*7)+1] = radeon_bo_size(reloc->robj);
1411 } 1410 }
1412 ib[idx+1+(i*7)+0] += (u32)((reloc->lobj.gpu_offset) & 0xffffffff); 1411 ib[idx+1+(i*7)+0] += (u32)((reloc->lobj.gpu_offset) & 0xffffffff);
diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
index 3cd1c470b777..3dfcfa3ca425 100644
--- a/drivers/gpu/drm/radeon/radeon.h
+++ b/drivers/gpu/drm/radeon/radeon.h
@@ -1100,6 +1100,8 @@ struct radeon_device {
1100 struct notifier_block acpi_nb; 1100 struct notifier_block acpi_nb;
1101 /* only one userspace can use Hyperz features at a time */ 1101 /* only one userspace can use Hyperz features at a time */
1102 struct drm_file *hyperz_filp; 1102 struct drm_file *hyperz_filp;
1103 /* i2c buses */
1104 struct radeon_i2c_chan *i2c_bus[RADEON_MAX_I2C_BUS];
1103}; 1105};
1104 1106
1105int radeon_device_init(struct radeon_device *rdev, 1107int radeon_device_init(struct radeon_device *rdev,
diff --git a/drivers/gpu/drm/radeon/radeon_atombios.c b/drivers/gpu/drm/radeon/radeon_atombios.c
index 3bc2bcdf5308..6d30868744ee 100644
--- a/drivers/gpu/drm/radeon/radeon_atombios.c
+++ b/drivers/gpu/drm/radeon/radeon_atombios.c
@@ -48,7 +48,8 @@ radeon_add_atom_connector(struct drm_device *dev,
48 struct radeon_i2c_bus_rec *i2c_bus, 48 struct radeon_i2c_bus_rec *i2c_bus,
49 bool linkb, uint32_t igp_lane_info, 49 bool linkb, uint32_t igp_lane_info,
50 uint16_t connector_object_id, 50 uint16_t connector_object_id,
51 struct radeon_hpd *hpd); 51 struct radeon_hpd *hpd,
52 struct radeon_router *router);
52 53
53/* from radeon_legacy_encoder.c */ 54/* from radeon_legacy_encoder.c */
54extern void 55extern void
@@ -114,7 +115,8 @@ static inline struct radeon_i2c_bus_rec radeon_lookup_i2c_gpio(struct radeon_dev
114 115
115 i2c.i2c_id = gpio->sucI2cId.ucAccess; 116 i2c.i2c_id = gpio->sucI2cId.ucAccess;
116 117
117 i2c.valid = true; 118 if (i2c.mask_clk_reg)
119 i2c.valid = true;
118 break; 120 break;
119 } 121 }
120 } 122 }
@@ -123,6 +125,66 @@ static inline struct radeon_i2c_bus_rec radeon_lookup_i2c_gpio(struct radeon_dev
123 return i2c; 125 return i2c;
124} 126}
125 127
128void radeon_atombios_i2c_init(struct radeon_device *rdev)
129{
130 struct atom_context *ctx = rdev->mode_info.atom_context;
131 ATOM_GPIO_I2C_ASSIGMENT *gpio;
132 struct radeon_i2c_bus_rec i2c;
133 int index = GetIndexIntoMasterTable(DATA, GPIO_I2C_Info);
134 struct _ATOM_GPIO_I2C_INFO *i2c_info;
135 uint16_t data_offset, size;
136 int i, num_indices;
137 char stmp[32];
138
139 memset(&i2c, 0, sizeof(struct radeon_i2c_bus_rec));
140
141 if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
142 i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset);
143
144 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
145 sizeof(ATOM_GPIO_I2C_ASSIGMENT);
146
147 for (i = 0; i < num_indices; i++) {
148 gpio = &i2c_info->asGPIO_Info[i];
149 i2c.valid = false;
150 i2c.mask_clk_reg = le16_to_cpu(gpio->usClkMaskRegisterIndex) * 4;
151 i2c.mask_data_reg = le16_to_cpu(gpio->usDataMaskRegisterIndex) * 4;
152 i2c.en_clk_reg = le16_to_cpu(gpio->usClkEnRegisterIndex) * 4;
153 i2c.en_data_reg = le16_to_cpu(gpio->usDataEnRegisterIndex) * 4;
154 i2c.y_clk_reg = le16_to_cpu(gpio->usClkY_RegisterIndex) * 4;
155 i2c.y_data_reg = le16_to_cpu(gpio->usDataY_RegisterIndex) * 4;
156 i2c.a_clk_reg = le16_to_cpu(gpio->usClkA_RegisterIndex) * 4;
157 i2c.a_data_reg = le16_to_cpu(gpio->usDataA_RegisterIndex) * 4;
158 i2c.mask_clk_mask = (1 << gpio->ucClkMaskShift);
159 i2c.mask_data_mask = (1 << gpio->ucDataMaskShift);
160 i2c.en_clk_mask = (1 << gpio->ucClkEnShift);
161 i2c.en_data_mask = (1 << gpio->ucDataEnShift);
162 i2c.y_clk_mask = (1 << gpio->ucClkY_Shift);
163 i2c.y_data_mask = (1 << gpio->ucDataY_Shift);
164 i2c.a_clk_mask = (1 << gpio->ucClkA_Shift);
165 i2c.a_data_mask = (1 << gpio->ucDataA_Shift);
166
167 if (gpio->sucI2cId.sbfAccess.bfHW_Capable)
168 i2c.hw_capable = true;
169 else
170 i2c.hw_capable = false;
171
172 if (gpio->sucI2cId.ucAccess == 0xa0)
173 i2c.mm_i2c = true;
174 else
175 i2c.mm_i2c = false;
176
177 i2c.i2c_id = gpio->sucI2cId.ucAccess;
178
179 if (i2c.mask_clk_reg) {
180 i2c.valid = true;
181 sprintf(stmp, "0x%x", i2c.i2c_id);
182 rdev->i2c_bus[i] = radeon_i2c_create(rdev->ddev, &i2c, stmp);
183 }
184 }
185 }
186}
187
126static inline struct radeon_gpio_rec radeon_lookup_gpio(struct radeon_device *rdev, 188static inline struct radeon_gpio_rec radeon_lookup_gpio(struct radeon_device *rdev,
127 u8 id) 189 u8 id)
128{ 190{
@@ -206,6 +268,7 @@ static bool radeon_atom_apply_quirks(struct drm_device *dev,
206 uint16_t *line_mux, 268 uint16_t *line_mux,
207 struct radeon_hpd *hpd) 269 struct radeon_hpd *hpd)
208{ 270{
271 struct radeon_device *rdev = dev->dev_private;
209 272
210 /* Asus M2A-VM HDMI board lists the DVI port as HDMI */ 273 /* Asus M2A-VM HDMI board lists the DVI port as HDMI */
211 if ((dev->pdev->device == 0x791e) && 274 if ((dev->pdev->device == 0x791e) &&
@@ -308,13 +371,22 @@ static bool radeon_atom_apply_quirks(struct drm_device *dev,
308 } 371 }
309 } 372 }
310 373
311 /* Acer laptop reports DVI-D as DVI-I */ 374 /* Acer laptop reports DVI-D as DVI-I and hpd pins reversed */
312 if ((dev->pdev->device == 0x95c4) && 375 if ((dev->pdev->device == 0x95c4) &&
313 (dev->pdev->subsystem_vendor == 0x1025) && 376 (dev->pdev->subsystem_vendor == 0x1025) &&
314 (dev->pdev->subsystem_device == 0x013c)) { 377 (dev->pdev->subsystem_device == 0x013c)) {
378 struct radeon_gpio_rec gpio;
379
315 if ((*connector_type == DRM_MODE_CONNECTOR_DVII) && 380 if ((*connector_type == DRM_MODE_CONNECTOR_DVII) &&
316 (supported_device == ATOM_DEVICE_DFP1_SUPPORT)) 381 (supported_device == ATOM_DEVICE_DFP1_SUPPORT)) {
382 gpio = radeon_lookup_gpio(rdev, 6);
383 *hpd = radeon_atom_get_hpd_info_from_gpio(rdev, &gpio);
317 *connector_type = DRM_MODE_CONNECTOR_DVID; 384 *connector_type = DRM_MODE_CONNECTOR_DVID;
385 } else if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
386 (supported_device == ATOM_DEVICE_DFP1_SUPPORT)) {
387 gpio = radeon_lookup_gpio(rdev, 7);
388 *hpd = radeon_atom_get_hpd_info_from_gpio(rdev, &gpio);
389 }
318 } 390 }
319 391
320 /* XFX Pine Group device rv730 reports no VGA DDC lines 392 /* XFX Pine Group device rv730 reports no VGA DDC lines
@@ -399,13 +471,15 @@ bool radeon_get_atom_connector_info_from_object_table(struct drm_device *dev)
399 u16 size, data_offset; 471 u16 size, data_offset;
400 u8 frev, crev; 472 u8 frev, crev;
401 ATOM_CONNECTOR_OBJECT_TABLE *con_obj; 473 ATOM_CONNECTOR_OBJECT_TABLE *con_obj;
474 ATOM_OBJECT_TABLE *router_obj;
402 ATOM_DISPLAY_OBJECT_PATH_TABLE *path_obj; 475 ATOM_DISPLAY_OBJECT_PATH_TABLE *path_obj;
403 ATOM_OBJECT_HEADER *obj_header; 476 ATOM_OBJECT_HEADER *obj_header;
404 int i, j, path_size, device_support; 477 int i, j, k, path_size, device_support;
405 int connector_type; 478 int connector_type;
406 u16 igp_lane_info, conn_id, connector_object_id; 479 u16 igp_lane_info, conn_id, connector_object_id;
407 bool linkb; 480 bool linkb;
408 struct radeon_i2c_bus_rec ddc_bus; 481 struct radeon_i2c_bus_rec ddc_bus;
482 struct radeon_router router;
409 struct radeon_gpio_rec gpio; 483 struct radeon_gpio_rec gpio;
410 struct radeon_hpd hpd; 484 struct radeon_hpd hpd;
411 485
@@ -415,6 +489,8 @@ bool radeon_get_atom_connector_info_from_object_table(struct drm_device *dev)
415 if (crev < 2) 489 if (crev < 2)
416 return false; 490 return false;
417 491
492 router.valid = false;
493
418 obj_header = (ATOM_OBJECT_HEADER *) (ctx->bios + data_offset); 494 obj_header = (ATOM_OBJECT_HEADER *) (ctx->bios + data_offset);
419 path_obj = (ATOM_DISPLAY_OBJECT_PATH_TABLE *) 495 path_obj = (ATOM_DISPLAY_OBJECT_PATH_TABLE *)
420 (ctx->bios + data_offset + 496 (ctx->bios + data_offset +
@@ -422,6 +498,9 @@ bool radeon_get_atom_connector_info_from_object_table(struct drm_device *dev)
422 con_obj = (ATOM_CONNECTOR_OBJECT_TABLE *) 498 con_obj = (ATOM_CONNECTOR_OBJECT_TABLE *)
423 (ctx->bios + data_offset + 499 (ctx->bios + data_offset +
424 le16_to_cpu(obj_header->usConnectorObjectTableOffset)); 500 le16_to_cpu(obj_header->usConnectorObjectTableOffset));
501 router_obj = (ATOM_OBJECT_TABLE *)
502 (ctx->bios + data_offset +
503 le16_to_cpu(obj_header->usRouterObjectTableOffset));
425 device_support = le16_to_cpu(obj_header->usDeviceSupport); 504 device_support = le16_to_cpu(obj_header->usDeviceSupport);
426 505
427 path_size = 0; 506 path_size = 0;
@@ -508,33 +587,86 @@ bool radeon_get_atom_connector_info_from_object_table(struct drm_device *dev)
508 if (connector_type == DRM_MODE_CONNECTOR_Unknown) 587 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
509 continue; 588 continue;
510 589
511 for (j = 0; j < ((le16_to_cpu(path->usSize) - 8) / 2); 590 for (j = 0; j < ((le16_to_cpu(path->usSize) - 8) / 2); j++) {
512 j++) { 591 uint8_t grph_obj_id, grph_obj_num, grph_obj_type;
513 uint8_t enc_obj_id, enc_obj_num, enc_obj_type;
514 592
515 enc_obj_id = 593 grph_obj_id =
516 (le16_to_cpu(path->usGraphicObjIds[j]) & 594 (le16_to_cpu(path->usGraphicObjIds[j]) &
517 OBJECT_ID_MASK) >> OBJECT_ID_SHIFT; 595 OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
518 enc_obj_num = 596 grph_obj_num =
519 (le16_to_cpu(path->usGraphicObjIds[j]) & 597 (le16_to_cpu(path->usGraphicObjIds[j]) &
520 ENUM_ID_MASK) >> ENUM_ID_SHIFT; 598 ENUM_ID_MASK) >> ENUM_ID_SHIFT;
521 enc_obj_type = 599 grph_obj_type =
522 (le16_to_cpu(path->usGraphicObjIds[j]) & 600 (le16_to_cpu(path->usGraphicObjIds[j]) &
523 OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT; 601 OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
524 602
525 /* FIXME: add support for router objects */ 603 if (grph_obj_type == GRAPH_OBJECT_TYPE_ENCODER) {
526 if (enc_obj_type == GRAPH_OBJECT_TYPE_ENCODER) { 604 if (grph_obj_num == 2)
527 if (enc_obj_num == 2)
528 linkb = true; 605 linkb = true;
529 else 606 else
530 linkb = false; 607 linkb = false;
531 608
532 radeon_add_atom_encoder(dev, 609 radeon_add_atom_encoder(dev,
533 enc_obj_id, 610 grph_obj_id,
534 le16_to_cpu 611 le16_to_cpu
535 (path-> 612 (path->
536 usDeviceTag)); 613 usDeviceTag));
537 614
615 } else if (grph_obj_type == GRAPH_OBJECT_TYPE_ROUTER) {
616 router.valid = false;
617 for (k = 0; k < router_obj->ucNumberOfObjects; k++) {
618 u16 router_obj_id = le16_to_cpu(router_obj->asObjects[j].usObjectID);
619 if (le16_to_cpu(path->usGraphicObjIds[j]) == router_obj_id) {
620 ATOM_COMMON_RECORD_HEADER *record = (ATOM_COMMON_RECORD_HEADER *)
621 (ctx->bios + data_offset +
622 le16_to_cpu(router_obj->asObjects[k].usRecordOffset));
623 ATOM_I2C_RECORD *i2c_record;
624 ATOM_I2C_ID_CONFIG_ACCESS *i2c_config;
625 ATOM_ROUTER_DDC_PATH_SELECT_RECORD *ddc_path;
626 ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT *router_src_dst_table =
627 (ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT *)
628 (ctx->bios + data_offset +
629 le16_to_cpu(router_obj->asObjects[k].usSrcDstTableOffset));
630 int enum_id;
631
632 router.router_id = router_obj_id;
633 for (enum_id = 0; enum_id < router_src_dst_table->ucNumberOfDst;
634 enum_id++) {
635 if (le16_to_cpu(path->usConnObjectId) ==
636 le16_to_cpu(router_src_dst_table->usDstObjectID[enum_id]))
637 break;
638 }
639
640 while (record->ucRecordType > 0 &&
641 record->ucRecordType <= ATOM_MAX_OBJECT_RECORD_NUMBER) {
642 switch (record->ucRecordType) {
643 case ATOM_I2C_RECORD_TYPE:
644 i2c_record =
645 (ATOM_I2C_RECORD *)
646 record;
647 i2c_config =
648 (ATOM_I2C_ID_CONFIG_ACCESS *)
649 &i2c_record->sucI2cId;
650 router.i2c_info =
651 radeon_lookup_i2c_gpio(rdev,
652 i2c_config->
653 ucAccess);
654 router.i2c_addr = i2c_record->ucI2CAddr >> 1;
655 break;
656 case ATOM_ROUTER_DDC_PATH_SELECT_RECORD_TYPE:
657 ddc_path = (ATOM_ROUTER_DDC_PATH_SELECT_RECORD *)
658 record;
659 router.valid = true;
660 router.mux_type = ddc_path->ucMuxType;
661 router.mux_control_pin = ddc_path->ucMuxControlPin;
662 router.mux_state = ddc_path->ucMuxState[enum_id];
663 break;
664 }
665 record = (ATOM_COMMON_RECORD_HEADER *)
666 ((char *)record + record->ucRecordSize);
667 }
668 }
669 }
538 } 670 }
539 } 671 }
540 672
@@ -614,7 +746,8 @@ bool radeon_get_atom_connector_info_from_object_table(struct drm_device *dev)
614 connector_type, &ddc_bus, 746 connector_type, &ddc_bus,
615 linkb, igp_lane_info, 747 linkb, igp_lane_info,
616 connector_object_id, 748 connector_object_id,
617 &hpd); 749 &hpd,
750 &router);
618 751
619 } 752 }
620 } 753 }
@@ -691,6 +824,9 @@ bool radeon_get_atom_connector_info_from_supported_devices_table(struct
691 int i, j, max_device; 824 int i, j, max_device;
692 struct bios_connector *bios_connectors; 825 struct bios_connector *bios_connectors;
693 size_t bc_size = sizeof(*bios_connectors) * ATOM_MAX_SUPPORTED_DEVICE; 826 size_t bc_size = sizeof(*bios_connectors) * ATOM_MAX_SUPPORTED_DEVICE;
827 struct radeon_router router;
828
829 router.valid = false;
694 830
695 bios_connectors = kzalloc(bc_size, GFP_KERNEL); 831 bios_connectors = kzalloc(bc_size, GFP_KERNEL);
696 if (!bios_connectors) 832 if (!bios_connectors)
@@ -862,7 +998,8 @@ bool radeon_get_atom_connector_info_from_supported_devices_table(struct
862 &bios_connectors[i].ddc_bus, 998 &bios_connectors[i].ddc_bus,
863 false, 0, 999 false, 0,
864 connector_object_id, 1000 connector_object_id,
865 &bios_connectors[i].hpd); 1001 &bios_connectors[i].hpd,
1002 &router);
866 } 1003 }
867 } 1004 }
868 1005
@@ -1521,7 +1658,7 @@ void radeon_atombios_get_power_modes(struct radeon_device *rdev)
1521 thermal_controller_names[power_info->info.ucOverdriveThermalController], 1658 thermal_controller_names[power_info->info.ucOverdriveThermalController],
1522 power_info->info.ucOverdriveControllerAddress >> 1); 1659 power_info->info.ucOverdriveControllerAddress >> 1);
1523 i2c_bus = radeon_lookup_i2c_gpio(rdev, power_info->info.ucOverdriveI2cLine); 1660 i2c_bus = radeon_lookup_i2c_gpio(rdev, power_info->info.ucOverdriveI2cLine);
1524 rdev->pm.i2c_bus = radeon_i2c_create(rdev->ddev, &i2c_bus, "Thermal"); 1661 rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
1525 if (rdev->pm.i2c_bus) { 1662 if (rdev->pm.i2c_bus) {
1526 struct i2c_board_info info = { }; 1663 struct i2c_board_info info = { };
1527 const char *name = thermal_controller_names[power_info->info. 1664 const char *name = thermal_controller_names[power_info->info.
@@ -1814,7 +1951,7 @@ void radeon_atombios_get_power_modes(struct radeon_device *rdev)
1814 (controller->ucFanParameters & 1951 (controller->ucFanParameters &
1815 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with"); 1952 ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
1816 i2c_bus = radeon_lookup_i2c_gpio(rdev, controller->ucI2cLine); 1953 i2c_bus = radeon_lookup_i2c_gpio(rdev, controller->ucI2cLine);
1817 rdev->pm.i2c_bus = radeon_i2c_create(rdev->ddev, &i2c_bus, "Thermal"); 1954 rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
1818 if (rdev->pm.i2c_bus) { 1955 if (rdev->pm.i2c_bus) {
1819 struct i2c_board_info info = { }; 1956 struct i2c_board_info info = { };
1820 const char *name = pp_lib_thermal_controller_names[controller->ucType]; 1957 const char *name = pp_lib_thermal_controller_names[controller->ucType];
@@ -1927,6 +2064,11 @@ void radeon_atombios_get_power_modes(struct radeon_device *rdev)
1927 rdev->pm.power_state[state_index].type = 2064 rdev->pm.power_state[state_index].type =
1928 POWER_STATE_TYPE_PERFORMANCE; 2065 POWER_STATE_TYPE_PERFORMANCE;
1929 break; 2066 break;
2067 case ATOM_PPLIB_CLASSIFICATION_UI_NONE:
2068 if (misc2 & ATOM_PPLIB_CLASSIFICATION_3DPERFORMANCE)
2069 rdev->pm.power_state[state_index].type =
2070 POWER_STATE_TYPE_PERFORMANCE;
2071 break;
1930 } 2072 }
1931 rdev->pm.power_state[state_index].flags = 0; 2073 rdev->pm.power_state[state_index].flags = 0;
1932 if (misc & ATOM_PPLIB_SINGLE_DISPLAY_ONLY) 2074 if (misc & ATOM_PPLIB_SINGLE_DISPLAY_ONLY)
diff --git a/drivers/gpu/drm/radeon/radeon_clocks.c b/drivers/gpu/drm/radeon/radeon_clocks.c
index f64936cc4dd9..14448a740ba6 100644
--- a/drivers/gpu/drm/radeon/radeon_clocks.c
+++ b/drivers/gpu/drm/radeon/radeon_clocks.c
@@ -91,6 +91,85 @@ uint32_t radeon_legacy_get_memory_clock(struct radeon_device *rdev)
91 return mclk; 91 return mclk;
92} 92}
93 93
94#ifdef CONFIG_OF
95/*
96 * Read XTAL (ref clock), SCLK and MCLK from Open Firmware device
97 * tree. Hopefully, ATI OF driver is kind enough to fill these
98 */
99static bool __devinit radeon_read_clocks_OF(struct drm_device *dev)
100{
101 struct radeon_device *rdev = dev->dev_private;
102 struct device_node *dp = rdev->pdev->dev.of_node;
103 const u32 *val;
104 struct radeon_pll *p1pll = &rdev->clock.p1pll;
105 struct radeon_pll *p2pll = &rdev->clock.p2pll;
106 struct radeon_pll *spll = &rdev->clock.spll;
107 struct radeon_pll *mpll = &rdev->clock.mpll;
108
109 if (dp == NULL)
110 return false;
111 val = of_get_property(dp, "ATY,RefCLK", NULL);
112 if (!val || !*val) {
113 printk(KERN_WARNING "radeonfb: No ATY,RefCLK property !\n");
114 return false;
115 }
116 p1pll->reference_freq = p2pll->reference_freq = (*val) / 10;
117 p1pll->reference_div = RREG32_PLL(RADEON_PPLL_REF_DIV) & 0x3ff;
118 if (p1pll->reference_div < 2)
119 p1pll->reference_div = 12;
120 p2pll->reference_div = p1pll->reference_div;
121
122 /* These aren't in the device-tree */
123 if (rdev->family >= CHIP_R420) {
124 p1pll->pll_in_min = 100;
125 p1pll->pll_in_max = 1350;
126 p1pll->pll_out_min = 20000;
127 p1pll->pll_out_max = 50000;
128 p2pll->pll_in_min = 100;
129 p2pll->pll_in_max = 1350;
130 p2pll->pll_out_min = 20000;
131 p2pll->pll_out_max = 50000;
132 } else {
133 p1pll->pll_in_min = 40;
134 p1pll->pll_in_max = 500;
135 p1pll->pll_out_min = 12500;
136 p1pll->pll_out_max = 35000;
137 p2pll->pll_in_min = 40;
138 p2pll->pll_in_max = 500;
139 p2pll->pll_out_min = 12500;
140 p2pll->pll_out_max = 35000;
141 }
142
143 spll->reference_freq = mpll->reference_freq = p1pll->reference_freq;
144 spll->reference_div = mpll->reference_div =
145 RREG32_PLL(RADEON_M_SPLL_REF_FB_DIV) &
146 RADEON_M_SPLL_REF_DIV_MASK;
147
148 val = of_get_property(dp, "ATY,SCLK", NULL);
149 if (val && *val)
150 rdev->clock.default_sclk = (*val) / 10;
151 else
152 rdev->clock.default_sclk =
153 radeon_legacy_get_engine_clock(rdev);
154
155 val = of_get_property(dp, "ATY,MCLK", NULL);
156 if (val && *val)
157 rdev->clock.default_mclk = (*val) / 10;
158 else
159 rdev->clock.default_mclk =
160 radeon_legacy_get_memory_clock(rdev);
161
162 DRM_INFO("Using device-tree clock info\n");
163
164 return true;
165}
166#else
167static bool __devinit radeon_read_clocks_OF(struct drm_device *dev)
168{
169 return false;
170}
171#endif /* CONFIG_OF */
172
94void radeon_get_clock_info(struct drm_device *dev) 173void radeon_get_clock_info(struct drm_device *dev)
95{ 174{
96 struct radeon_device *rdev = dev->dev_private; 175 struct radeon_device *rdev = dev->dev_private;
@@ -105,6 +184,8 @@ void radeon_get_clock_info(struct drm_device *dev)
105 ret = radeon_atom_get_clock_info(dev); 184 ret = radeon_atom_get_clock_info(dev);
106 else 185 else
107 ret = radeon_combios_get_clock_info(dev); 186 ret = radeon_combios_get_clock_info(dev);
187 if (!ret)
188 ret = radeon_read_clocks_OF(dev);
108 189
109 if (ret) { 190 if (ret) {
110 if (p1pll->reference_div < 2) { 191 if (p1pll->reference_div < 2) {
diff --git a/drivers/gpu/drm/radeon/radeon_combios.c b/drivers/gpu/drm/radeon/radeon_combios.c
index 5e1474cde4b4..885dcfac1838 100644
--- a/drivers/gpu/drm/radeon/radeon_combios.c
+++ b/drivers/gpu/drm/radeon/radeon_combios.c
@@ -480,9 +480,66 @@ radeon_combios_get_hardcoded_edid(struct radeon_device *rdev)
480} 480}
481 481
482static struct radeon_i2c_bus_rec combios_setup_i2c_bus(struct radeon_device *rdev, 482static struct radeon_i2c_bus_rec combios_setup_i2c_bus(struct radeon_device *rdev,
483 int ddc_line) 483 enum radeon_combios_ddc ddc,
484 u32 clk_mask,
485 u32 data_mask)
484{ 486{
485 struct radeon_i2c_bus_rec i2c; 487 struct radeon_i2c_bus_rec i2c;
488 int ddc_line = 0;
489
490 /* ddc id = mask reg
491 * DDC_NONE_DETECTED = none
492 * DDC_DVI = RADEON_GPIO_DVI_DDC
493 * DDC_VGA = RADEON_GPIO_VGA_DDC
494 * DDC_LCD = RADEON_GPIOPAD_MASK
495 * DDC_GPIO = RADEON_MDGPIO_MASK
496 * r1xx/r2xx
497 * DDC_MONID = RADEON_GPIO_MONID
498 * DDC_CRT2 = RADEON_GPIO_CRT2_DDC
499 * r3xx
500 * DDC_MONID = RADEON_GPIO_MONID
501 * DDC_CRT2 = RADEON_GPIO_DVI_DDC
502 * rs3xx/rs4xx
503 * DDC_MONID = RADEON_GPIOPAD_MASK
504 * DDC_CRT2 = RADEON_GPIO_MONID
505 */
506 switch (ddc) {
507 case DDC_NONE_DETECTED:
508 default:
509 ddc_line = 0;
510 break;
511 case DDC_DVI:
512 ddc_line = RADEON_GPIO_DVI_DDC;
513 break;
514 case DDC_VGA:
515 ddc_line = RADEON_GPIO_VGA_DDC;
516 break;
517 case DDC_LCD:
518 ddc_line = RADEON_GPIOPAD_MASK;
519 break;
520 case DDC_GPIO:
521 ddc_line = RADEON_MDGPIO_MASK;
522 break;
523 case DDC_MONID:
524 if (rdev->family == CHIP_RS300 ||
525 rdev->family == CHIP_RS400 ||
526 rdev->family == CHIP_RS480)
527 ddc_line = RADEON_GPIOPAD_MASK;
528 else
529 ddc_line = RADEON_GPIO_MONID;
530 break;
531 case DDC_CRT2:
532 if (rdev->family == CHIP_RS300 ||
533 rdev->family == CHIP_RS400 ||
534 rdev->family == CHIP_RS480)
535 ddc_line = RADEON_GPIO_MONID;
536 else if (rdev->family >= CHIP_R300) {
537 ddc_line = RADEON_GPIO_DVI_DDC;
538 ddc = DDC_DVI;
539 } else
540 ddc_line = RADEON_GPIO_CRT2_DDC;
541 break;
542 }
486 543
487 if (ddc_line == RADEON_GPIOPAD_MASK) { 544 if (ddc_line == RADEON_GPIOPAD_MASK) {
488 i2c.mask_clk_reg = RADEON_GPIOPAD_MASK; 545 i2c.mask_clk_reg = RADEON_GPIOPAD_MASK;
@@ -503,15 +560,6 @@ static struct radeon_i2c_bus_rec combios_setup_i2c_bus(struct radeon_device *rde
503 i2c.y_clk_reg = RADEON_MDGPIO_Y; 560 i2c.y_clk_reg = RADEON_MDGPIO_Y;
504 i2c.y_data_reg = RADEON_MDGPIO_Y; 561 i2c.y_data_reg = RADEON_MDGPIO_Y;
505 } else { 562 } else {
506 i2c.mask_clk_mask = RADEON_GPIO_EN_1;
507 i2c.mask_data_mask = RADEON_GPIO_EN_0;
508 i2c.a_clk_mask = RADEON_GPIO_A_1;
509 i2c.a_data_mask = RADEON_GPIO_A_0;
510 i2c.en_clk_mask = RADEON_GPIO_EN_1;
511 i2c.en_data_mask = RADEON_GPIO_EN_0;
512 i2c.y_clk_mask = RADEON_GPIO_Y_1;
513 i2c.y_data_mask = RADEON_GPIO_Y_0;
514
515 i2c.mask_clk_reg = ddc_line; 563 i2c.mask_clk_reg = ddc_line;
516 i2c.mask_data_reg = ddc_line; 564 i2c.mask_data_reg = ddc_line;
517 i2c.a_clk_reg = ddc_line; 565 i2c.a_clk_reg = ddc_line;
@@ -522,6 +570,26 @@ static struct radeon_i2c_bus_rec combios_setup_i2c_bus(struct radeon_device *rde
522 i2c.y_data_reg = ddc_line; 570 i2c.y_data_reg = ddc_line;
523 } 571 }
524 572
573 if (clk_mask && data_mask) {
574 i2c.mask_clk_mask = clk_mask;
575 i2c.mask_data_mask = data_mask;
576 i2c.a_clk_mask = clk_mask;
577 i2c.a_data_mask = data_mask;
578 i2c.en_clk_mask = clk_mask;
579 i2c.en_data_mask = data_mask;
580 i2c.y_clk_mask = clk_mask;
581 i2c.y_data_mask = data_mask;
582 } else {
583 i2c.mask_clk_mask = RADEON_GPIO_EN_1;
584 i2c.mask_data_mask = RADEON_GPIO_EN_0;
585 i2c.a_clk_mask = RADEON_GPIO_A_1;
586 i2c.a_data_mask = RADEON_GPIO_A_0;
587 i2c.en_clk_mask = RADEON_GPIO_EN_1;
588 i2c.en_data_mask = RADEON_GPIO_EN_0;
589 i2c.y_clk_mask = RADEON_GPIO_Y_1;
590 i2c.y_data_mask = RADEON_GPIO_Y_0;
591 }
592
525 switch (rdev->family) { 593 switch (rdev->family) {
526 case CHIP_R100: 594 case CHIP_R100:
527 case CHIP_RV100: 595 case CHIP_RV100:
@@ -599,7 +667,8 @@ static struct radeon_i2c_bus_rec combios_setup_i2c_bus(struct radeon_device *rde
599 break; 667 break;
600 } 668 }
601 i2c.mm_i2c = false; 669 i2c.mm_i2c = false;
602 i2c.i2c_id = 0; 670
671 i2c.i2c_id = ddc;
603 i2c.hpd = RADEON_HPD_NONE; 672 i2c.hpd = RADEON_HPD_NONE;
604 673
605 if (ddc_line) 674 if (ddc_line)
@@ -610,6 +679,62 @@ static struct radeon_i2c_bus_rec combios_setup_i2c_bus(struct radeon_device *rde
610 return i2c; 679 return i2c;
611} 680}
612 681
682void radeon_combios_i2c_init(struct radeon_device *rdev)
683{
684 struct drm_device *dev = rdev->ddev;
685 struct radeon_i2c_bus_rec i2c;
686
687
688 i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
689 rdev->i2c_bus[0] = radeon_i2c_create(dev, &i2c, "DVI_DDC");
690
691 i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
692 rdev->i2c_bus[1] = radeon_i2c_create(dev, &i2c, "VGA_DDC");
693
694 i2c.valid = true;
695 i2c.hw_capable = true;
696 i2c.mm_i2c = true;
697 i2c.i2c_id = 0xa0;
698 rdev->i2c_bus[2] = radeon_i2c_create(dev, &i2c, "MM_I2C");
699
700 if (rdev->family == CHIP_RS300 ||
701 rdev->family == CHIP_RS400 ||
702 rdev->family == CHIP_RS480) {
703 u16 offset;
704 u8 id, blocks, clk, data;
705 int i;
706
707 i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
708 rdev->i2c_bus[3] = radeon_i2c_create(dev, &i2c, "MONID");
709
710 offset = combios_get_table_offset(dev, COMBIOS_I2C_INFO_TABLE);
711 if (offset) {
712 blocks = RBIOS8(offset + 2);
713 for (i = 0; i < blocks; i++) {
714 id = RBIOS8(offset + 3 + (i * 5) + 0);
715 if (id == 136) {
716 clk = RBIOS8(offset + 3 + (i * 5) + 3);
717 data = RBIOS8(offset + 3 + (i * 5) + 4);
718 i2c = combios_setup_i2c_bus(rdev, DDC_MONID,
719 clk, data);
720 rdev->i2c_bus[4] = radeon_i2c_create(dev, &i2c, "GPIOPAD_MASK");
721 break;
722 }
723 }
724 }
725
726 } else if (rdev->family >= CHIP_R300) {
727 i2c = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
728 rdev->i2c_bus[3] = radeon_i2c_create(dev, &i2c, "MONID");
729 } else {
730 i2c = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
731 rdev->i2c_bus[3] = radeon_i2c_create(dev, &i2c, "MONID");
732
733 i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
734 rdev->i2c_bus[4] = radeon_i2c_create(dev, &i2c, "CRT2_DDC");
735 }
736}
737
613bool radeon_combios_get_clock_info(struct drm_device *dev) 738bool radeon_combios_get_clock_info(struct drm_device *dev)
614{ 739{
615 struct radeon_device *rdev = dev->dev_private; 740 struct radeon_device *rdev = dev->dev_private;
@@ -1247,8 +1372,8 @@ bool radeon_legacy_get_ext_tmds_info_from_table(struct radeon_encoder *encoder,
1247 struct radeon_i2c_bus_rec i2c_bus; 1372 struct radeon_i2c_bus_rec i2c_bus;
1248 1373
1249 /* default for macs */ 1374 /* default for macs */
1250 i2c_bus = combios_setup_i2c_bus(rdev, RADEON_GPIO_MONID); 1375 i2c_bus = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
1251 tmds->i2c_bus = radeon_i2c_create(dev, &i2c_bus, "DVO"); 1376 tmds->i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
1252 1377
1253 /* XXX some macs have duallink chips */ 1378 /* XXX some macs have duallink chips */
1254 switch (rdev->mode_info.connector_table) { 1379 switch (rdev->mode_info.connector_table) {
@@ -1269,47 +1394,16 @@ bool radeon_legacy_get_ext_tmds_info_from_combios(struct radeon_encoder *encoder
1269 struct drm_device *dev = encoder->base.dev; 1394 struct drm_device *dev = encoder->base.dev;
1270 struct radeon_device *rdev = dev->dev_private; 1395 struct radeon_device *rdev = dev->dev_private;
1271 uint16_t offset; 1396 uint16_t offset;
1272 uint8_t ver, id, blocks, clk, data; 1397 uint8_t ver;
1273 int i;
1274 enum radeon_combios_ddc gpio; 1398 enum radeon_combios_ddc gpio;
1275 struct radeon_i2c_bus_rec i2c_bus; 1399 struct radeon_i2c_bus_rec i2c_bus;
1276 1400
1277 tmds->i2c_bus = NULL; 1401 tmds->i2c_bus = NULL;
1278 if (rdev->flags & RADEON_IS_IGP) { 1402 if (rdev->flags & RADEON_IS_IGP) {
1279 offset = combios_get_table_offset(dev, COMBIOS_I2C_INFO_TABLE); 1403 i2c_bus = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
1280 if (offset) { 1404 tmds->i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
1281 ver = RBIOS8(offset); 1405 tmds->dvo_chip = DVO_SIL164;
1282 DRM_INFO("GPIO Table revision: %d\n", ver); 1406 tmds->slave_addr = 0x70 >> 1; /* 7 bit addressing */
1283 blocks = RBIOS8(offset + 2);
1284 for (i = 0; i < blocks; i++) {
1285 id = RBIOS8(offset + 3 + (i * 5) + 0);
1286 if (id == 136) {
1287 clk = RBIOS8(offset + 3 + (i * 5) + 3);
1288 data = RBIOS8(offset + 3 + (i * 5) + 4);
1289 i2c_bus.valid = true;
1290 i2c_bus.mask_clk_mask = (1 << clk);
1291 i2c_bus.mask_data_mask = (1 << data);
1292 i2c_bus.a_clk_mask = (1 << clk);
1293 i2c_bus.a_data_mask = (1 << data);
1294 i2c_bus.en_clk_mask = (1 << clk);
1295 i2c_bus.en_data_mask = (1 << data);
1296 i2c_bus.y_clk_mask = (1 << clk);
1297 i2c_bus.y_data_mask = (1 << data);
1298 i2c_bus.mask_clk_reg = RADEON_GPIOPAD_MASK;
1299 i2c_bus.mask_data_reg = RADEON_GPIOPAD_MASK;
1300 i2c_bus.a_clk_reg = RADEON_GPIOPAD_A;
1301 i2c_bus.a_data_reg = RADEON_GPIOPAD_A;
1302 i2c_bus.en_clk_reg = RADEON_GPIOPAD_EN;
1303 i2c_bus.en_data_reg = RADEON_GPIOPAD_EN;
1304 i2c_bus.y_clk_reg = RADEON_GPIOPAD_Y;
1305 i2c_bus.y_data_reg = RADEON_GPIOPAD_Y;
1306 tmds->i2c_bus = radeon_i2c_create(dev, &i2c_bus, "DVO");
1307 tmds->dvo_chip = DVO_SIL164;
1308 tmds->slave_addr = 0x70 >> 1; /* 7 bit addressing */
1309 break;
1310 }
1311 }
1312 }
1313 } else { 1407 } else {
1314 offset = combios_get_table_offset(dev, COMBIOS_EXT_TMDS_INFO_TABLE); 1408 offset = combios_get_table_offset(dev, COMBIOS_EXT_TMDS_INFO_TABLE);
1315 if (offset) { 1409 if (offset) {
@@ -1318,37 +1412,15 @@ bool radeon_legacy_get_ext_tmds_info_from_combios(struct radeon_encoder *encoder
1318 tmds->slave_addr = RBIOS8(offset + 4 + 2); 1412 tmds->slave_addr = RBIOS8(offset + 4 + 2);
1319 tmds->slave_addr >>= 1; /* 7 bit addressing */ 1413 tmds->slave_addr >>= 1; /* 7 bit addressing */
1320 gpio = RBIOS8(offset + 4 + 3); 1414 gpio = RBIOS8(offset + 4 + 3);
1321 switch (gpio) { 1415 if (gpio == DDC_LCD) {
1322 case DDC_MONID: 1416 /* MM i2c */
1323 i2c_bus = combios_setup_i2c_bus(rdev, RADEON_GPIO_MONID);
1324 tmds->i2c_bus = radeon_i2c_create(dev, &i2c_bus, "DVO");
1325 break;
1326 case DDC_DVI:
1327 i2c_bus = combios_setup_i2c_bus(rdev, RADEON_GPIO_DVI_DDC);
1328 tmds->i2c_bus = radeon_i2c_create(dev, &i2c_bus, "DVO");
1329 break;
1330 case DDC_VGA:
1331 i2c_bus = combios_setup_i2c_bus(rdev, RADEON_GPIO_VGA_DDC);
1332 tmds->i2c_bus = radeon_i2c_create(dev, &i2c_bus, "DVO");
1333 break;
1334 case DDC_CRT2:
1335 /* R3xx+ chips don't have GPIO_CRT2_DDC gpio pad */
1336 if (rdev->family >= CHIP_R300)
1337 i2c_bus = combios_setup_i2c_bus(rdev, RADEON_GPIO_MONID);
1338 else
1339 i2c_bus = combios_setup_i2c_bus(rdev, RADEON_GPIO_CRT2_DDC);
1340 tmds->i2c_bus = radeon_i2c_create(dev, &i2c_bus, "DVO");
1341 break;
1342 case DDC_LCD: /* MM i2c */
1343 i2c_bus.valid = true; 1417 i2c_bus.valid = true;
1344 i2c_bus.hw_capable = true; 1418 i2c_bus.hw_capable = true;
1345 i2c_bus.mm_i2c = true; 1419 i2c_bus.mm_i2c = true;
1346 tmds->i2c_bus = radeon_i2c_create(dev, &i2c_bus, "DVO"); 1420 i2c_bus.i2c_id = 0xa0;
1347 break; 1421 } else
1348 default: 1422 i2c_bus = combios_setup_i2c_bus(rdev, gpio, 0, 0);
1349 DRM_ERROR("Unsupported gpio %d\n", gpio); 1423 tmds->i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
1350 break;
1351 }
1352 } 1424 }
1353 } 1425 }
1354 1426
@@ -1430,7 +1502,7 @@ bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
1430 /* these are the most common settings */ 1502 /* these are the most common settings */
1431 if (rdev->flags & RADEON_SINGLE_CRTC) { 1503 if (rdev->flags & RADEON_SINGLE_CRTC) {
1432 /* VGA - primary dac */ 1504 /* VGA - primary dac */
1433 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_VGA_DDC); 1505 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
1434 hpd.hpd = RADEON_HPD_NONE; 1506 hpd.hpd = RADEON_HPD_NONE;
1435 radeon_add_legacy_encoder(dev, 1507 radeon_add_legacy_encoder(dev,
1436 radeon_get_encoder_id(dev, 1508 radeon_get_encoder_id(dev,
@@ -1445,7 +1517,7 @@ bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
1445 &hpd); 1517 &hpd);
1446 } else if (rdev->flags & RADEON_IS_MOBILITY) { 1518 } else if (rdev->flags & RADEON_IS_MOBILITY) {
1447 /* LVDS */ 1519 /* LVDS */
1448 ddc_i2c = combios_setup_i2c_bus(rdev, 0); 1520 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_NONE_DETECTED, 0, 0);
1449 hpd.hpd = RADEON_HPD_NONE; 1521 hpd.hpd = RADEON_HPD_NONE;
1450 radeon_add_legacy_encoder(dev, 1522 radeon_add_legacy_encoder(dev,
1451 radeon_get_encoder_id(dev, 1523 radeon_get_encoder_id(dev,
@@ -1460,7 +1532,7 @@ bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
1460 &hpd); 1532 &hpd);
1461 1533
1462 /* VGA - primary dac */ 1534 /* VGA - primary dac */
1463 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_VGA_DDC); 1535 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
1464 hpd.hpd = RADEON_HPD_NONE; 1536 hpd.hpd = RADEON_HPD_NONE;
1465 radeon_add_legacy_encoder(dev, 1537 radeon_add_legacy_encoder(dev,
1466 radeon_get_encoder_id(dev, 1538 radeon_get_encoder_id(dev,
@@ -1475,7 +1547,7 @@ bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
1475 &hpd); 1547 &hpd);
1476 } else { 1548 } else {
1477 /* DVI-I - tv dac, int tmds */ 1549 /* DVI-I - tv dac, int tmds */
1478 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_DVI_DDC); 1550 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
1479 hpd.hpd = RADEON_HPD_1; 1551 hpd.hpd = RADEON_HPD_1;
1480 radeon_add_legacy_encoder(dev, 1552 radeon_add_legacy_encoder(dev,
1481 radeon_get_encoder_id(dev, 1553 radeon_get_encoder_id(dev,
@@ -1496,7 +1568,7 @@ bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
1496 &hpd); 1568 &hpd);
1497 1569
1498 /* VGA - primary dac */ 1570 /* VGA - primary dac */
1499 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_VGA_DDC); 1571 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
1500 hpd.hpd = RADEON_HPD_NONE; 1572 hpd.hpd = RADEON_HPD_NONE;
1501 radeon_add_legacy_encoder(dev, 1573 radeon_add_legacy_encoder(dev,
1502 radeon_get_encoder_id(dev, 1574 radeon_get_encoder_id(dev,
@@ -1532,7 +1604,7 @@ bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
1532 DRM_INFO("Connector Table: %d (ibook)\n", 1604 DRM_INFO("Connector Table: %d (ibook)\n",
1533 rdev->mode_info.connector_table); 1605 rdev->mode_info.connector_table);
1534 /* LVDS */ 1606 /* LVDS */
1535 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_DVI_DDC); 1607 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
1536 hpd.hpd = RADEON_HPD_NONE; 1608 hpd.hpd = RADEON_HPD_NONE;
1537 radeon_add_legacy_encoder(dev, 1609 radeon_add_legacy_encoder(dev,
1538 radeon_get_encoder_id(dev, 1610 radeon_get_encoder_id(dev,
@@ -1544,7 +1616,7 @@ bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
1544 CONNECTOR_OBJECT_ID_LVDS, 1616 CONNECTOR_OBJECT_ID_LVDS,
1545 &hpd); 1617 &hpd);
1546 /* VGA - TV DAC */ 1618 /* VGA - TV DAC */
1547 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_VGA_DDC); 1619 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
1548 hpd.hpd = RADEON_HPD_NONE; 1620 hpd.hpd = RADEON_HPD_NONE;
1549 radeon_add_legacy_encoder(dev, 1621 radeon_add_legacy_encoder(dev,
1550 radeon_get_encoder_id(dev, 1622 radeon_get_encoder_id(dev,
@@ -1573,7 +1645,7 @@ bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
1573 DRM_INFO("Connector Table: %d (powerbook external tmds)\n", 1645 DRM_INFO("Connector Table: %d (powerbook external tmds)\n",
1574 rdev->mode_info.connector_table); 1646 rdev->mode_info.connector_table);
1575 /* LVDS */ 1647 /* LVDS */
1576 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_DVI_DDC); 1648 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
1577 hpd.hpd = RADEON_HPD_NONE; 1649 hpd.hpd = RADEON_HPD_NONE;
1578 radeon_add_legacy_encoder(dev, 1650 radeon_add_legacy_encoder(dev,
1579 radeon_get_encoder_id(dev, 1651 radeon_get_encoder_id(dev,
@@ -1585,7 +1657,7 @@ bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
1585 CONNECTOR_OBJECT_ID_LVDS, 1657 CONNECTOR_OBJECT_ID_LVDS,
1586 &hpd); 1658 &hpd);
1587 /* DVI-I - primary dac, ext tmds */ 1659 /* DVI-I - primary dac, ext tmds */
1588 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_VGA_DDC); 1660 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
1589 hpd.hpd = RADEON_HPD_2; /* ??? */ 1661 hpd.hpd = RADEON_HPD_2; /* ??? */
1590 radeon_add_legacy_encoder(dev, 1662 radeon_add_legacy_encoder(dev,
1591 radeon_get_encoder_id(dev, 1663 radeon_get_encoder_id(dev,
@@ -1622,7 +1694,7 @@ bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
1622 DRM_INFO("Connector Table: %d (powerbook internal tmds)\n", 1694 DRM_INFO("Connector Table: %d (powerbook internal tmds)\n",
1623 rdev->mode_info.connector_table); 1695 rdev->mode_info.connector_table);
1624 /* LVDS */ 1696 /* LVDS */
1625 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_DVI_DDC); 1697 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
1626 hpd.hpd = RADEON_HPD_NONE; 1698 hpd.hpd = RADEON_HPD_NONE;
1627 radeon_add_legacy_encoder(dev, 1699 radeon_add_legacy_encoder(dev,
1628 radeon_get_encoder_id(dev, 1700 radeon_get_encoder_id(dev,
@@ -1634,7 +1706,7 @@ bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
1634 CONNECTOR_OBJECT_ID_LVDS, 1706 CONNECTOR_OBJECT_ID_LVDS,
1635 &hpd); 1707 &hpd);
1636 /* DVI-I - primary dac, int tmds */ 1708 /* DVI-I - primary dac, int tmds */
1637 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_VGA_DDC); 1709 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
1638 hpd.hpd = RADEON_HPD_1; /* ??? */ 1710 hpd.hpd = RADEON_HPD_1; /* ??? */
1639 radeon_add_legacy_encoder(dev, 1711 radeon_add_legacy_encoder(dev,
1640 radeon_get_encoder_id(dev, 1712 radeon_get_encoder_id(dev,
@@ -1670,7 +1742,7 @@ bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
1670 DRM_INFO("Connector Table: %d (powerbook vga)\n", 1742 DRM_INFO("Connector Table: %d (powerbook vga)\n",
1671 rdev->mode_info.connector_table); 1743 rdev->mode_info.connector_table);
1672 /* LVDS */ 1744 /* LVDS */
1673 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_DVI_DDC); 1745 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
1674 hpd.hpd = RADEON_HPD_NONE; 1746 hpd.hpd = RADEON_HPD_NONE;
1675 radeon_add_legacy_encoder(dev, 1747 radeon_add_legacy_encoder(dev,
1676 radeon_get_encoder_id(dev, 1748 radeon_get_encoder_id(dev,
@@ -1682,7 +1754,7 @@ bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
1682 CONNECTOR_OBJECT_ID_LVDS, 1754 CONNECTOR_OBJECT_ID_LVDS,
1683 &hpd); 1755 &hpd);
1684 /* VGA - primary dac */ 1756 /* VGA - primary dac */
1685 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_VGA_DDC); 1757 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
1686 hpd.hpd = RADEON_HPD_NONE; 1758 hpd.hpd = RADEON_HPD_NONE;
1687 radeon_add_legacy_encoder(dev, 1759 radeon_add_legacy_encoder(dev,
1688 radeon_get_encoder_id(dev, 1760 radeon_get_encoder_id(dev,
@@ -1711,7 +1783,7 @@ bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
1711 DRM_INFO("Connector Table: %d (mini external tmds)\n", 1783 DRM_INFO("Connector Table: %d (mini external tmds)\n",
1712 rdev->mode_info.connector_table); 1784 rdev->mode_info.connector_table);
1713 /* DVI-I - tv dac, ext tmds */ 1785 /* DVI-I - tv dac, ext tmds */
1714 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_CRT2_DDC); 1786 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
1715 hpd.hpd = RADEON_HPD_2; /* ??? */ 1787 hpd.hpd = RADEON_HPD_2; /* ??? */
1716 radeon_add_legacy_encoder(dev, 1788 radeon_add_legacy_encoder(dev,
1717 radeon_get_encoder_id(dev, 1789 radeon_get_encoder_id(dev,
@@ -1748,7 +1820,7 @@ bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
1748 DRM_INFO("Connector Table: %d (mini internal tmds)\n", 1820 DRM_INFO("Connector Table: %d (mini internal tmds)\n",
1749 rdev->mode_info.connector_table); 1821 rdev->mode_info.connector_table);
1750 /* DVI-I - tv dac, int tmds */ 1822 /* DVI-I - tv dac, int tmds */
1751 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_CRT2_DDC); 1823 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
1752 hpd.hpd = RADEON_HPD_1; /* ??? */ 1824 hpd.hpd = RADEON_HPD_1; /* ??? */
1753 radeon_add_legacy_encoder(dev, 1825 radeon_add_legacy_encoder(dev,
1754 radeon_get_encoder_id(dev, 1826 radeon_get_encoder_id(dev,
@@ -1784,7 +1856,7 @@ bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
1784 DRM_INFO("Connector Table: %d (imac g5 isight)\n", 1856 DRM_INFO("Connector Table: %d (imac g5 isight)\n",
1785 rdev->mode_info.connector_table); 1857 rdev->mode_info.connector_table);
1786 /* DVI-D - int tmds */ 1858 /* DVI-D - int tmds */
1787 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_MONID); 1859 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
1788 hpd.hpd = RADEON_HPD_1; /* ??? */ 1860 hpd.hpd = RADEON_HPD_1; /* ??? */
1789 radeon_add_legacy_encoder(dev, 1861 radeon_add_legacy_encoder(dev,
1790 radeon_get_encoder_id(dev, 1862 radeon_get_encoder_id(dev,
@@ -1796,7 +1868,7 @@ bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
1796 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D, 1868 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D,
1797 &hpd); 1869 &hpd);
1798 /* VGA - tv dac */ 1870 /* VGA - tv dac */
1799 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_DVI_DDC); 1871 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
1800 hpd.hpd = RADEON_HPD_NONE; 1872 hpd.hpd = RADEON_HPD_NONE;
1801 radeon_add_legacy_encoder(dev, 1873 radeon_add_legacy_encoder(dev,
1802 radeon_get_encoder_id(dev, 1874 radeon_get_encoder_id(dev,
@@ -1825,7 +1897,7 @@ bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
1825 DRM_INFO("Connector Table: %d (emac)\n", 1897 DRM_INFO("Connector Table: %d (emac)\n",
1826 rdev->mode_info.connector_table); 1898 rdev->mode_info.connector_table);
1827 /* VGA - primary dac */ 1899 /* VGA - primary dac */
1828 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_VGA_DDC); 1900 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
1829 hpd.hpd = RADEON_HPD_NONE; 1901 hpd.hpd = RADEON_HPD_NONE;
1830 radeon_add_legacy_encoder(dev, 1902 radeon_add_legacy_encoder(dev,
1831 radeon_get_encoder_id(dev, 1903 radeon_get_encoder_id(dev,
@@ -1837,7 +1909,7 @@ bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
1837 CONNECTOR_OBJECT_ID_VGA, 1909 CONNECTOR_OBJECT_ID_VGA,
1838 &hpd); 1910 &hpd);
1839 /* VGA - tv dac */ 1911 /* VGA - tv dac */
1840 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_CRT2_DDC); 1912 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
1841 hpd.hpd = RADEON_HPD_NONE; 1913 hpd.hpd = RADEON_HPD_NONE;
1842 radeon_add_legacy_encoder(dev, 1914 radeon_add_legacy_encoder(dev,
1843 radeon_get_encoder_id(dev, 1915 radeon_get_encoder_id(dev,
@@ -1866,7 +1938,7 @@ bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
1866 DRM_INFO("Connector Table: %d (rn50-power)\n", 1938 DRM_INFO("Connector Table: %d (rn50-power)\n",
1867 rdev->mode_info.connector_table); 1939 rdev->mode_info.connector_table);
1868 /* VGA - primary dac */ 1940 /* VGA - primary dac */
1869 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_VGA_DDC); 1941 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
1870 hpd.hpd = RADEON_HPD_NONE; 1942 hpd.hpd = RADEON_HPD_NONE;
1871 radeon_add_legacy_encoder(dev, 1943 radeon_add_legacy_encoder(dev,
1872 radeon_get_encoder_id(dev, 1944 radeon_get_encoder_id(dev,
@@ -1877,7 +1949,7 @@ bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
1877 DRM_MODE_CONNECTOR_VGA, &ddc_i2c, 1949 DRM_MODE_CONNECTOR_VGA, &ddc_i2c,
1878 CONNECTOR_OBJECT_ID_VGA, 1950 CONNECTOR_OBJECT_ID_VGA,
1879 &hpd); 1951 &hpd);
1880 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_CRT2_DDC); 1952 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_CRT2, 0, 0);
1881 hpd.hpd = RADEON_HPD_NONE; 1953 hpd.hpd = RADEON_HPD_NONE;
1882 radeon_add_legacy_encoder(dev, 1954 radeon_add_legacy_encoder(dev,
1883 radeon_get_encoder_id(dev, 1955 radeon_get_encoder_id(dev,
@@ -1907,31 +1979,6 @@ static bool radeon_apply_legacy_quirks(struct drm_device *dev,
1907 struct radeon_i2c_bus_rec *ddc_i2c, 1979 struct radeon_i2c_bus_rec *ddc_i2c,
1908 struct radeon_hpd *hpd) 1980 struct radeon_hpd *hpd)
1909{ 1981{
1910 struct radeon_device *rdev = dev->dev_private;
1911
1912 /* XPRESS DDC quirks */
1913 if ((rdev->family == CHIP_RS400 ||
1914 rdev->family == CHIP_RS480) &&
1915 ddc_i2c->mask_clk_reg == RADEON_GPIO_CRT2_DDC)
1916 *ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_MONID);
1917 else if ((rdev->family == CHIP_RS400 ||
1918 rdev->family == CHIP_RS480) &&
1919 ddc_i2c->mask_clk_reg == RADEON_GPIO_MONID) {
1920 *ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIOPAD_MASK);
1921 ddc_i2c->mask_clk_mask = (0x20 << 8);
1922 ddc_i2c->mask_data_mask = 0x80;
1923 ddc_i2c->a_clk_mask = (0x20 << 8);
1924 ddc_i2c->a_data_mask = 0x80;
1925 ddc_i2c->en_clk_mask = (0x20 << 8);
1926 ddc_i2c->en_data_mask = 0x80;
1927 ddc_i2c->y_clk_mask = (0x20 << 8);
1928 ddc_i2c->y_data_mask = 0x80;
1929 }
1930
1931 /* R3xx+ chips don't have GPIO_CRT2_DDC gpio pad */
1932 if ((rdev->family >= CHIP_R300) &&
1933 ddc_i2c->mask_clk_reg == RADEON_GPIO_CRT2_DDC)
1934 *ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_DVI_DDC);
1935 1982
1936 /* Certain IBM chipset RN50s have a BIOS reporting two VGAs, 1983 /* Certain IBM chipset RN50s have a BIOS reporting two VGAs,
1937 one with VGA DDC and one with CRT2 DDC. - kill the CRT2 DDC one */ 1984 one with VGA DDC and one with CRT2 DDC. - kill the CRT2 DDC one */
@@ -2035,27 +2082,7 @@ bool radeon_get_legacy_connector_info_from_bios(struct drm_device *dev)
2035 connector = (tmp >> 12) & 0xf; 2082 connector = (tmp >> 12) & 0xf;
2036 2083
2037 ddc_type = (tmp >> 8) & 0xf; 2084 ddc_type = (tmp >> 8) & 0xf;
2038 switch (ddc_type) { 2085 ddc_i2c = combios_setup_i2c_bus(rdev, ddc_type, 0, 0);
2039 case DDC_MONID:
2040 ddc_i2c =
2041 combios_setup_i2c_bus(rdev, RADEON_GPIO_MONID);
2042 break;
2043 case DDC_DVI:
2044 ddc_i2c =
2045 combios_setup_i2c_bus(rdev, RADEON_GPIO_DVI_DDC);
2046 break;
2047 case DDC_VGA:
2048 ddc_i2c =
2049 combios_setup_i2c_bus(rdev, RADEON_GPIO_VGA_DDC);
2050 break;
2051 case DDC_CRT2:
2052 ddc_i2c =
2053 combios_setup_i2c_bus(rdev, RADEON_GPIO_CRT2_DDC);
2054 break;
2055 default:
2056 ddc_i2c.valid = false;
2057 break;
2058 }
2059 2086
2060 switch (connector) { 2087 switch (connector) {
2061 case CONNECTOR_PROPRIETARY_LEGACY: 2088 case CONNECTOR_PROPRIETARY_LEGACY:
@@ -2225,7 +2252,7 @@ bool radeon_get_legacy_connector_info_from_bios(struct drm_device *dev)
2225 0), 2252 0),
2226 ATOM_DEVICE_DFP1_SUPPORT); 2253 ATOM_DEVICE_DFP1_SUPPORT);
2227 2254
2228 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_DVI_DDC); 2255 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
2229 hpd.hpd = RADEON_HPD_1; 2256 hpd.hpd = RADEON_HPD_1;
2230 radeon_add_legacy_connector(dev, 2257 radeon_add_legacy_connector(dev,
2231 0, 2258 0,
@@ -2245,7 +2272,7 @@ bool radeon_get_legacy_connector_info_from_bios(struct drm_device *dev)
2245 ATOM_DEVICE_CRT1_SUPPORT, 2272 ATOM_DEVICE_CRT1_SUPPORT,
2246 1), 2273 1),
2247 ATOM_DEVICE_CRT1_SUPPORT); 2274 ATOM_DEVICE_CRT1_SUPPORT);
2248 ddc_i2c = combios_setup_i2c_bus(rdev, RADEON_GPIO_VGA_DDC); 2275 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_VGA, 0, 0);
2249 hpd.hpd = RADEON_HPD_NONE; 2276 hpd.hpd = RADEON_HPD_NONE;
2250 radeon_add_legacy_connector(dev, 2277 radeon_add_legacy_connector(dev,
2251 0, 2278 0,
@@ -2278,70 +2305,25 @@ bool radeon_get_legacy_connector_info_from_bios(struct drm_device *dev)
2278 if (lcd_ddc_info) { 2305 if (lcd_ddc_info) {
2279 ddc_type = RBIOS8(lcd_ddc_info + 2); 2306 ddc_type = RBIOS8(lcd_ddc_info + 2);
2280 switch (ddc_type) { 2307 switch (ddc_type) {
2281 case DDC_MONID:
2282 ddc_i2c =
2283 combios_setup_i2c_bus
2284 (rdev, RADEON_GPIO_MONID);
2285 break;
2286 case DDC_DVI:
2287 ddc_i2c =
2288 combios_setup_i2c_bus
2289 (rdev, RADEON_GPIO_DVI_DDC);
2290 break;
2291 case DDC_VGA:
2292 ddc_i2c =
2293 combios_setup_i2c_bus
2294 (rdev, RADEON_GPIO_VGA_DDC);
2295 break;
2296 case DDC_CRT2:
2297 ddc_i2c =
2298 combios_setup_i2c_bus
2299 (rdev, RADEON_GPIO_CRT2_DDC);
2300 break;
2301 case DDC_LCD: 2308 case DDC_LCD:
2302 ddc_i2c = 2309 ddc_i2c =
2303 combios_setup_i2c_bus 2310 combios_setup_i2c_bus(rdev,
2304 (rdev, RADEON_GPIOPAD_MASK); 2311 DDC_LCD,
2305 ddc_i2c.mask_clk_mask = 2312 RBIOS32(lcd_ddc_info + 3),
2306 RBIOS32(lcd_ddc_info + 3); 2313 RBIOS32(lcd_ddc_info + 7));
2307 ddc_i2c.mask_data_mask = 2314 radeon_i2c_add(rdev, &ddc_i2c, "LCD");
2308 RBIOS32(lcd_ddc_info + 7);
2309 ddc_i2c.a_clk_mask =
2310 RBIOS32(lcd_ddc_info + 3);
2311 ddc_i2c.a_data_mask =
2312 RBIOS32(lcd_ddc_info + 7);
2313 ddc_i2c.en_clk_mask =
2314 RBIOS32(lcd_ddc_info + 3);
2315 ddc_i2c.en_data_mask =
2316 RBIOS32(lcd_ddc_info + 7);
2317 ddc_i2c.y_clk_mask =
2318 RBIOS32(lcd_ddc_info + 3);
2319 ddc_i2c.y_data_mask =
2320 RBIOS32(lcd_ddc_info + 7);
2321 break; 2315 break;
2322 case DDC_GPIO: 2316 case DDC_GPIO:
2323 ddc_i2c = 2317 ddc_i2c =
2324 combios_setup_i2c_bus 2318 combios_setup_i2c_bus(rdev,
2325 (rdev, RADEON_MDGPIO_MASK); 2319 DDC_GPIO,
2326 ddc_i2c.mask_clk_mask = 2320 RBIOS32(lcd_ddc_info + 3),
2327 RBIOS32(lcd_ddc_info + 3); 2321 RBIOS32(lcd_ddc_info + 7));
2328 ddc_i2c.mask_data_mask = 2322 radeon_i2c_add(rdev, &ddc_i2c, "LCD");
2329 RBIOS32(lcd_ddc_info + 7);
2330 ddc_i2c.a_clk_mask =
2331 RBIOS32(lcd_ddc_info + 3);
2332 ddc_i2c.a_data_mask =
2333 RBIOS32(lcd_ddc_info + 7);
2334 ddc_i2c.en_clk_mask =
2335 RBIOS32(lcd_ddc_info + 3);
2336 ddc_i2c.en_data_mask =
2337 RBIOS32(lcd_ddc_info + 7);
2338 ddc_i2c.y_clk_mask =
2339 RBIOS32(lcd_ddc_info + 3);
2340 ddc_i2c.y_data_mask =
2341 RBIOS32(lcd_ddc_info + 7);
2342 break; 2323 break;
2343 default: 2324 default:
2344 ddc_i2c.valid = false; 2325 ddc_i2c =
2326 combios_setup_i2c_bus(rdev, ddc_type, 0, 0);
2345 break; 2327 break;
2346 } 2328 }
2347 DRM_DEBUG_KMS("LCD DDC Info Table found!\n"); 2329 DRM_DEBUG_KMS("LCD DDC Info Table found!\n");
diff --git a/drivers/gpu/drm/radeon/radeon_connectors.c b/drivers/gpu/drm/radeon/radeon_connectors.c
index 2395c8600cf4..47c4b276d30c 100644
--- a/drivers/gpu/drm/radeon/radeon_connectors.c
+++ b/drivers/gpu/drm/radeon/radeon_connectors.c
@@ -518,8 +518,6 @@ static void radeon_connector_destroy(struct drm_connector *connector)
518{ 518{
519 struct radeon_connector *radeon_connector = to_radeon_connector(connector); 519 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
520 520
521 if (radeon_connector->ddc_bus)
522 radeon_i2c_destroy(radeon_connector->ddc_bus);
523 if (radeon_connector->edid) 521 if (radeon_connector->edid)
524 kfree(radeon_connector->edid); 522 kfree(radeon_connector->edid);
525 kfree(radeon_connector->con_priv); 523 kfree(radeon_connector->con_priv);
@@ -955,8 +953,6 @@ static void radeon_dp_connector_destroy(struct drm_connector *connector)
955 struct radeon_connector *radeon_connector = to_radeon_connector(connector); 953 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
956 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv; 954 struct radeon_connector_atom_dig *radeon_dig_connector = radeon_connector->con_priv;
957 955
958 if (radeon_connector->ddc_bus)
959 radeon_i2c_destroy(radeon_connector->ddc_bus);
960 if (radeon_connector->edid) 956 if (radeon_connector->edid)
961 kfree(radeon_connector->edid); 957 kfree(radeon_connector->edid);
962 if (radeon_dig_connector->dp_i2c_bus) 958 if (radeon_dig_connector->dp_i2c_bus)
@@ -1044,7 +1040,8 @@ radeon_add_atom_connector(struct drm_device *dev,
1044 bool linkb, 1040 bool linkb,
1045 uint32_t igp_lane_info, 1041 uint32_t igp_lane_info,
1046 uint16_t connector_object_id, 1042 uint16_t connector_object_id,
1047 struct radeon_hpd *hpd) 1043 struct radeon_hpd *hpd,
1044 struct radeon_router *router)
1048{ 1045{
1049 struct radeon_device *rdev = dev->dev_private; 1046 struct radeon_device *rdev = dev->dev_private;
1050 struct drm_connector *connector; 1047 struct drm_connector *connector;
@@ -1069,6 +1066,11 @@ radeon_add_atom_connector(struct drm_device *dev,
1069 radeon_connector->shared_ddc = true; 1066 radeon_connector->shared_ddc = true;
1070 shared_ddc = true; 1067 shared_ddc = true;
1071 } 1068 }
1069 if (radeon_connector->router_bus && router->valid &&
1070 (radeon_connector->router.router_id == router->router_id)) {
1071 radeon_connector->shared_ddc = false;
1072 shared_ddc = false;
1073 }
1072 } 1074 }
1073 } 1075 }
1074 1076
@@ -1083,12 +1085,18 @@ radeon_add_atom_connector(struct drm_device *dev,
1083 radeon_connector->shared_ddc = shared_ddc; 1085 radeon_connector->shared_ddc = shared_ddc;
1084 radeon_connector->connector_object_id = connector_object_id; 1086 radeon_connector->connector_object_id = connector_object_id;
1085 radeon_connector->hpd = *hpd; 1087 radeon_connector->hpd = *hpd;
1088 radeon_connector->router = *router;
1089 if (router->valid) {
1090 radeon_connector->router_bus = radeon_i2c_lookup(rdev, &router->i2c_info);
1091 if (!radeon_connector->router_bus)
1092 goto failed;
1093 }
1086 switch (connector_type) { 1094 switch (connector_type) {
1087 case DRM_MODE_CONNECTOR_VGA: 1095 case DRM_MODE_CONNECTOR_VGA:
1088 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type); 1096 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
1089 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs); 1097 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
1090 if (i2c_bus->valid) { 1098 if (i2c_bus->valid) {
1091 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "VGA"); 1099 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1092 if (!radeon_connector->ddc_bus) 1100 if (!radeon_connector->ddc_bus)
1093 goto failed; 1101 goto failed;
1094 } 1102 }
@@ -1104,7 +1112,7 @@ radeon_add_atom_connector(struct drm_device *dev,
1104 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type); 1112 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
1105 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs); 1113 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
1106 if (i2c_bus->valid) { 1114 if (i2c_bus->valid) {
1107 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI"); 1115 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1108 if (!radeon_connector->ddc_bus) 1116 if (!radeon_connector->ddc_bus)
1109 goto failed; 1117 goto failed;
1110 } 1118 }
@@ -1126,7 +1134,7 @@ radeon_add_atom_connector(struct drm_device *dev,
1126 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type); 1134 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
1127 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs); 1135 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
1128 if (i2c_bus->valid) { 1136 if (i2c_bus->valid) {
1129 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI"); 1137 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1130 if (!radeon_connector->ddc_bus) 1138 if (!radeon_connector->ddc_bus)
1131 goto failed; 1139 goto failed;
1132 } 1140 }
@@ -1156,7 +1164,7 @@ radeon_add_atom_connector(struct drm_device *dev,
1156 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type); 1164 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
1157 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs); 1165 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
1158 if (i2c_bus->valid) { 1166 if (i2c_bus->valid) {
1159 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "HDMI"); 1167 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1160 if (!radeon_connector->ddc_bus) 1168 if (!radeon_connector->ddc_bus)
1161 goto failed; 1169 goto failed;
1162 } 1170 }
@@ -1187,10 +1195,7 @@ radeon_add_atom_connector(struct drm_device *dev,
1187 radeon_dig_connector->dp_i2c_bus = radeon_i2c_create_dp(dev, i2c_bus, "DP-auxch"); 1195 radeon_dig_connector->dp_i2c_bus = radeon_i2c_create_dp(dev, i2c_bus, "DP-auxch");
1188 if (!radeon_dig_connector->dp_i2c_bus) 1196 if (!radeon_dig_connector->dp_i2c_bus)
1189 goto failed; 1197 goto failed;
1190 if (connector_type == DRM_MODE_CONNECTOR_eDP) 1198 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1191 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "eDP");
1192 else
1193 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DP");
1194 if (!radeon_connector->ddc_bus) 1199 if (!radeon_connector->ddc_bus)
1195 goto failed; 1200 goto failed;
1196 } 1201 }
@@ -1230,7 +1235,7 @@ radeon_add_atom_connector(struct drm_device *dev,
1230 drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type); 1235 drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type);
1231 drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs); 1236 drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
1232 if (i2c_bus->valid) { 1237 if (i2c_bus->valid) {
1233 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "LVDS"); 1238 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1234 if (!radeon_connector->ddc_bus) 1239 if (!radeon_connector->ddc_bus)
1235 goto failed; 1240 goto failed;
1236 } 1241 }
@@ -1252,8 +1257,6 @@ radeon_add_atom_connector(struct drm_device *dev,
1252 return; 1257 return;
1253 1258
1254failed: 1259failed:
1255 if (radeon_connector->ddc_bus)
1256 radeon_i2c_destroy(radeon_connector->ddc_bus);
1257 drm_connector_cleanup(connector); 1260 drm_connector_cleanup(connector);
1258 kfree(connector); 1261 kfree(connector);
1259} 1262}
@@ -1300,7 +1303,7 @@ radeon_add_legacy_connector(struct drm_device *dev,
1300 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type); 1303 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
1301 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs); 1304 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
1302 if (i2c_bus->valid) { 1305 if (i2c_bus->valid) {
1303 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "VGA"); 1306 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1304 if (!radeon_connector->ddc_bus) 1307 if (!radeon_connector->ddc_bus)
1305 goto failed; 1308 goto failed;
1306 } 1309 }
@@ -1316,7 +1319,7 @@ radeon_add_legacy_connector(struct drm_device *dev,
1316 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type); 1319 drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
1317 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs); 1320 drm_connector_helper_add(&radeon_connector->base, &radeon_vga_connector_helper_funcs);
1318 if (i2c_bus->valid) { 1321 if (i2c_bus->valid) {
1319 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI"); 1322 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1320 if (!radeon_connector->ddc_bus) 1323 if (!radeon_connector->ddc_bus)
1321 goto failed; 1324 goto failed;
1322 } 1325 }
@@ -1332,7 +1335,7 @@ radeon_add_legacy_connector(struct drm_device *dev,
1332 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type); 1335 drm_connector_init(dev, &radeon_connector->base, &radeon_dvi_connector_funcs, connector_type);
1333 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs); 1336 drm_connector_helper_add(&radeon_connector->base, &radeon_dvi_connector_helper_funcs);
1334 if (i2c_bus->valid) { 1337 if (i2c_bus->valid) {
1335 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "DVI"); 1338 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1336 if (!radeon_connector->ddc_bus) 1339 if (!radeon_connector->ddc_bus)
1337 goto failed; 1340 goto failed;
1338 } 1341 }
@@ -1372,7 +1375,7 @@ radeon_add_legacy_connector(struct drm_device *dev,
1372 drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type); 1375 drm_connector_init(dev, &radeon_connector->base, &radeon_lvds_connector_funcs, connector_type);
1373 drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs); 1376 drm_connector_helper_add(&radeon_connector->base, &radeon_lvds_connector_helper_funcs);
1374 if (i2c_bus->valid) { 1377 if (i2c_bus->valid) {
1375 radeon_connector->ddc_bus = radeon_i2c_create(dev, i2c_bus, "LVDS"); 1378 radeon_connector->ddc_bus = radeon_i2c_lookup(rdev, i2c_bus);
1376 if (!radeon_connector->ddc_bus) 1379 if (!radeon_connector->ddc_bus)
1377 goto failed; 1380 goto failed;
1378 } 1381 }
@@ -1393,8 +1396,6 @@ radeon_add_legacy_connector(struct drm_device *dev,
1393 return; 1396 return;
1394 1397
1395failed: 1398failed:
1396 if (radeon_connector->ddc_bus)
1397 radeon_i2c_destroy(radeon_connector->ddc_bus);
1398 drm_connector_cleanup(connector); 1399 drm_connector_cleanup(connector);
1399 kfree(connector); 1400 kfree(connector);
1400} 1401}
diff --git a/drivers/gpu/drm/radeon/radeon_cs.c b/drivers/gpu/drm/radeon/radeon_cs.c
index ae0fb7356e62..fcc79b5d22d1 100644
--- a/drivers/gpu/drm/radeon/radeon_cs.c
+++ b/drivers/gpu/drm/radeon/radeon_cs.c
@@ -72,7 +72,7 @@ int radeon_cs_parser_relocs(struct radeon_cs_parser *p)
72 if (p->relocs[i].gobj == NULL) { 72 if (p->relocs[i].gobj == NULL) {
73 DRM_ERROR("gem object lookup failed 0x%x\n", 73 DRM_ERROR("gem object lookup failed 0x%x\n",
74 r->handle); 74 r->handle);
75 return -EINVAL; 75 return -ENOENT;
76 } 76 }
77 p->relocs_ptr[i] = &p->relocs[i]; 77 p->relocs_ptr[i] = &p->relocs[i];
78 p->relocs[i].robj = p->relocs[i].gobj->driver_private; 78 p->relocs[i].robj = p->relocs[i].gobj->driver_private;
diff --git a/drivers/gpu/drm/radeon/radeon_cursor.c b/drivers/gpu/drm/radeon/radeon_cursor.c
index 4eb67c0e0996..5731fc9b1ae3 100644
--- a/drivers/gpu/drm/radeon/radeon_cursor.c
+++ b/drivers/gpu/drm/radeon/radeon_cursor.c
@@ -170,7 +170,7 @@ int radeon_crtc_cursor_set(struct drm_crtc *crtc,
170 obj = drm_gem_object_lookup(crtc->dev, file_priv, handle); 170 obj = drm_gem_object_lookup(crtc->dev, file_priv, handle);
171 if (!obj) { 171 if (!obj) {
172 DRM_ERROR("Cannot find cursor object %x for crtc %d\n", handle, radeon_crtc->crtc_id); 172 DRM_ERROR("Cannot find cursor object %x for crtc %d\n", handle, radeon_crtc->crtc_id);
173 return -EINVAL; 173 return -ENOENT;
174 } 174 }
175 175
176 ret = radeon_gem_object_pin(obj, RADEON_GEM_DOMAIN_VRAM, &gpu_addr); 176 ret = radeon_gem_object_pin(obj, RADEON_GEM_DOMAIN_VRAM, &gpu_addr);
diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
index a64811a94519..4f7a170d1566 100644
--- a/drivers/gpu/drm/radeon/radeon_device.c
+++ b/drivers/gpu/drm/radeon/radeon_device.c
@@ -347,7 +347,8 @@ int radeon_dummy_page_init(struct radeon_device *rdev)
347 return -ENOMEM; 347 return -ENOMEM;
348 rdev->dummy_page.addr = pci_map_page(rdev->pdev, rdev->dummy_page.page, 348 rdev->dummy_page.addr = pci_map_page(rdev->pdev, rdev->dummy_page.page,
349 0, PAGE_SIZE, PCI_DMA_BIDIRECTIONAL); 349 0, PAGE_SIZE, PCI_DMA_BIDIRECTIONAL);
350 if (!rdev->dummy_page.addr) { 350 if (pci_dma_mapping_error(rdev->pdev, rdev->dummy_page.addr)) {
351 dev_err(&rdev->pdev->dev, "Failed to DMA MAP the dummy page\n");
351 __free_page(rdev->dummy_page.page); 352 __free_page(rdev->dummy_page.page);
352 rdev->dummy_page.page = NULL; 353 rdev->dummy_page.page = NULL;
353 return -ENOMEM; 354 return -ENOMEM;
diff --git a/drivers/gpu/drm/radeon/radeon_display.c b/drivers/gpu/drm/radeon/radeon_display.c
index 74dac9635d70..5764f4d3b4f1 100644
--- a/drivers/gpu/drm/radeon/radeon_display.c
+++ b/drivers/gpu/drm/radeon/radeon_display.c
@@ -161,17 +161,13 @@ void radeon_crtc_fb_gamma_get(struct drm_crtc *crtc, u16 *red, u16 *green,
161} 161}
162 162
163static void radeon_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green, 163static void radeon_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
164 u16 *blue, uint32_t size) 164 u16 *blue, uint32_t start, uint32_t size)
165{ 165{
166 struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); 166 struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
167 int i; 167 int end = (start + size > 256) ? 256 : start + size, i;
168
169 if (size != 256) {
170 return;
171 }
172 168
173 /* userspace palettes are always correct as is */ 169 /* userspace palettes are always correct as is */
174 for (i = 0; i < 256; i++) { 170 for (i = start; i < end; i++) {
175 radeon_crtc->lut_r[i] = red[i] >> 6; 171 radeon_crtc->lut_r[i] = red[i] >> 6;
176 radeon_crtc->lut_g[i] = green[i] >> 6; 172 radeon_crtc->lut_g[i] = green[i] >> 6;
177 radeon_crtc->lut_b[i] = blue[i] >> 6; 173 radeon_crtc->lut_b[i] = blue[i] >> 6;
@@ -319,6 +315,10 @@ static void radeon_print_display_setup(struct drm_device *dev)
319 radeon_connector->ddc_bus->rec.en_data_reg, 315 radeon_connector->ddc_bus->rec.en_data_reg,
320 radeon_connector->ddc_bus->rec.y_clk_reg, 316 radeon_connector->ddc_bus->rec.y_clk_reg,
321 radeon_connector->ddc_bus->rec.y_data_reg); 317 radeon_connector->ddc_bus->rec.y_data_reg);
318 if (radeon_connector->router_bus)
319 DRM_INFO(" DDC Router 0x%x/0x%x\n",
320 radeon_connector->router.mux_control_pin,
321 radeon_connector->router.mux_state);
322 } else { 322 } else {
323 if (connector->connector_type == DRM_MODE_CONNECTOR_VGA || 323 if (connector->connector_type == DRM_MODE_CONNECTOR_VGA ||
324 connector->connector_type == DRM_MODE_CONNECTOR_DVII || 324 connector->connector_type == DRM_MODE_CONNECTOR_DVII ||
@@ -395,6 +395,10 @@ int radeon_ddc_get_modes(struct radeon_connector *radeon_connector)
395 struct radeon_device *rdev = dev->dev_private; 395 struct radeon_device *rdev = dev->dev_private;
396 int ret = 0; 396 int ret = 0;
397 397
398 /* on hw with routers, select right port */
399 if (radeon_connector->router.valid)
400 radeon_router_select_port(radeon_connector);
401
398 if ((radeon_connector->base.connector_type == DRM_MODE_CONNECTOR_DisplayPort) || 402 if ((radeon_connector->base.connector_type == DRM_MODE_CONNECTOR_DisplayPort) ||
399 (radeon_connector->base.connector_type == DRM_MODE_CONNECTOR_eDP)) { 403 (radeon_connector->base.connector_type == DRM_MODE_CONNECTOR_eDP)) {
400 struct radeon_connector_atom_dig *dig = radeon_connector->con_priv; 404 struct radeon_connector_atom_dig *dig = radeon_connector->con_priv;
@@ -425,6 +429,10 @@ static int radeon_ddc_dump(struct drm_connector *connector)
425 struct radeon_connector *radeon_connector = to_radeon_connector(connector); 429 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
426 int ret = 0; 430 int ret = 0;
427 431
432 /* on hw with routers, select right port */
433 if (radeon_connector->router.valid)
434 radeon_router_select_port(radeon_connector);
435
428 if (!radeon_connector->ddc_bus) 436 if (!radeon_connector->ddc_bus)
429 return -1; 437 return -1;
430 edid = drm_get_edid(connector, &radeon_connector->ddc_bus->adapter); 438 edid = drm_get_edid(connector, &radeon_connector->ddc_bus->adapter);
@@ -876,13 +884,12 @@ radeon_user_framebuffer_create(struct drm_device *dev,
876 if (obj == NULL) { 884 if (obj == NULL) {
877 dev_err(&dev->pdev->dev, "No GEM object associated to handle 0x%08X, " 885 dev_err(&dev->pdev->dev, "No GEM object associated to handle 0x%08X, "
878 "can't create framebuffer\n", mode_cmd->handle); 886 "can't create framebuffer\n", mode_cmd->handle);
879 return NULL; 887 return ERR_PTR(-ENOENT);
880 } 888 }
881 889
882 radeon_fb = kzalloc(sizeof(*radeon_fb), GFP_KERNEL); 890 radeon_fb = kzalloc(sizeof(*radeon_fb), GFP_KERNEL);
883 if (radeon_fb == NULL) { 891 if (radeon_fb == NULL)
884 return NULL; 892 return ERR_PTR(-ENOMEM);
885 }
886 893
887 radeon_framebuffer_init(dev, radeon_fb, mode_cmd, obj); 894 radeon_framebuffer_init(dev, radeon_fb, mode_cmd, obj);
888 895
@@ -1040,6 +1047,9 @@ int radeon_modeset_init(struct radeon_device *rdev)
1040 return ret; 1047 return ret;
1041 } 1048 }
1042 1049
1050 /* init i2c buses */
1051 radeon_i2c_init(rdev);
1052
1043 /* check combios for a valid hardcoded EDID - Sun servers */ 1053 /* check combios for a valid hardcoded EDID - Sun servers */
1044 if (!rdev->is_atom_bios) { 1054 if (!rdev->is_atom_bios) {
1045 /* check for hardcoded EDID in BIOS */ 1055 /* check for hardcoded EDID in BIOS */
@@ -1080,6 +1090,8 @@ void radeon_modeset_fini(struct radeon_device *rdev)
1080 drm_mode_config_cleanup(rdev->ddev); 1090 drm_mode_config_cleanup(rdev->ddev);
1081 rdev->mode_info.mode_config_initialized = false; 1091 rdev->mode_info.mode_config_initialized = false;
1082 } 1092 }
1093 /* free i2c buses */
1094 radeon_i2c_fini(rdev);
1083} 1095}
1084 1096
1085bool radeon_crtc_scaling_mode_fixup(struct drm_crtc *crtc, 1097bool radeon_crtc_scaling_mode_fixup(struct drm_crtc *crtc,
diff --git a/drivers/gpu/drm/radeon/radeon_fb.c b/drivers/gpu/drm/radeon/radeon_fb.c
index dc1634bb0c11..dbf86962bdd1 100644
--- a/drivers/gpu/drm/radeon/radeon_fb.c
+++ b/drivers/gpu/drm/radeon/radeon_fb.c
@@ -224,7 +224,7 @@ static int radeonfb_create(struct radeon_fbdev *rfbdev,
224 224
225 drm_fb_helper_fill_fix(info, fb->pitch, fb->depth); 225 drm_fb_helper_fill_fix(info, fb->pitch, fb->depth);
226 226
227 info->flags = FBINFO_DEFAULT; 227 info->flags = FBINFO_DEFAULT | FBINFO_CAN_FORCE_OUTPUT;
228 info->fbops = &radeonfb_ops; 228 info->fbops = &radeonfb_ops;
229 229
230 tmp = radeon_bo_gpu_offset(rbo) - rdev->mc.vram_start; 230 tmp = radeon_bo_gpu_offset(rbo) - rdev->mc.vram_start;
diff --git a/drivers/gpu/drm/radeon/radeon_gem.c b/drivers/gpu/drm/radeon/radeon_gem.c
index a72a3ee5d69b..c578f265b24c 100644
--- a/drivers/gpu/drm/radeon/radeon_gem.c
+++ b/drivers/gpu/drm/radeon/radeon_gem.c
@@ -226,7 +226,7 @@ int radeon_gem_set_domain_ioctl(struct drm_device *dev, void *data,
226 /* just do a BO wait for now */ 226 /* just do a BO wait for now */
227 gobj = drm_gem_object_lookup(dev, filp, args->handle); 227 gobj = drm_gem_object_lookup(dev, filp, args->handle);
228 if (gobj == NULL) { 228 if (gobj == NULL) {
229 return -EINVAL; 229 return -ENOENT;
230 } 230 }
231 robj = gobj->driver_private; 231 robj = gobj->driver_private;
232 232
@@ -245,7 +245,7 @@ int radeon_gem_mmap_ioctl(struct drm_device *dev, void *data,
245 245
246 gobj = drm_gem_object_lookup(dev, filp, args->handle); 246 gobj = drm_gem_object_lookup(dev, filp, args->handle);
247 if (gobj == NULL) { 247 if (gobj == NULL) {
248 return -EINVAL; 248 return -ENOENT;
249 } 249 }
250 robj = gobj->driver_private; 250 robj = gobj->driver_private;
251 args->addr_ptr = radeon_bo_mmap_offset(robj); 251 args->addr_ptr = radeon_bo_mmap_offset(robj);
@@ -264,7 +264,7 @@ int radeon_gem_busy_ioctl(struct drm_device *dev, void *data,
264 264
265 gobj = drm_gem_object_lookup(dev, filp, args->handle); 265 gobj = drm_gem_object_lookup(dev, filp, args->handle);
266 if (gobj == NULL) { 266 if (gobj == NULL) {
267 return -EINVAL; 267 return -ENOENT;
268 } 268 }
269 robj = gobj->driver_private; 269 robj = gobj->driver_private;
270 r = radeon_bo_wait(robj, &cur_placement, true); 270 r = radeon_bo_wait(robj, &cur_placement, true);
@@ -294,7 +294,7 @@ int radeon_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
294 294
295 gobj = drm_gem_object_lookup(dev, filp, args->handle); 295 gobj = drm_gem_object_lookup(dev, filp, args->handle);
296 if (gobj == NULL) { 296 if (gobj == NULL) {
297 return -EINVAL; 297 return -ENOENT;
298 } 298 }
299 robj = gobj->driver_private; 299 robj = gobj->driver_private;
300 r = radeon_bo_wait(robj, NULL, false); 300 r = radeon_bo_wait(robj, NULL, false);
@@ -316,7 +316,7 @@ int radeon_gem_set_tiling_ioctl(struct drm_device *dev, void *data,
316 DRM_DEBUG("%d \n", args->handle); 316 DRM_DEBUG("%d \n", args->handle);
317 gobj = drm_gem_object_lookup(dev, filp, args->handle); 317 gobj = drm_gem_object_lookup(dev, filp, args->handle);
318 if (gobj == NULL) 318 if (gobj == NULL)
319 return -EINVAL; 319 return -ENOENT;
320 robj = gobj->driver_private; 320 robj = gobj->driver_private;
321 r = radeon_bo_set_tiling_flags(robj, args->tiling_flags, args->pitch); 321 r = radeon_bo_set_tiling_flags(robj, args->tiling_flags, args->pitch);
322 drm_gem_object_unreference_unlocked(gobj); 322 drm_gem_object_unreference_unlocked(gobj);
@@ -334,7 +334,7 @@ int radeon_gem_get_tiling_ioctl(struct drm_device *dev, void *data,
334 DRM_DEBUG("\n"); 334 DRM_DEBUG("\n");
335 gobj = drm_gem_object_lookup(dev, filp, args->handle); 335 gobj = drm_gem_object_lookup(dev, filp, args->handle);
336 if (gobj == NULL) 336 if (gobj == NULL)
337 return -EINVAL; 337 return -ENOENT;
338 rbo = gobj->driver_private; 338 rbo = gobj->driver_private;
339 r = radeon_bo_reserve(rbo, false); 339 r = radeon_bo_reserve(rbo, false);
340 if (unlikely(r != 0)) 340 if (unlikely(r != 0))
diff --git a/drivers/gpu/drm/radeon/radeon_i2c.c b/drivers/gpu/drm/radeon/radeon_i2c.c
index 5def6f5dff38..bfd2ce5f5372 100644
--- a/drivers/gpu/drm/radeon/radeon_i2c.c
+++ b/drivers/gpu/drm/radeon/radeon_i2c.c
@@ -52,6 +52,10 @@ bool radeon_ddc_probe(struct radeon_connector *radeon_connector)
52 } 52 }
53 }; 53 };
54 54
55 /* on hw with routers, select right port */
56 if (radeon_connector->router.valid)
57 radeon_router_select_port(radeon_connector);
58
55 ret = i2c_transfer(&radeon_connector->ddc_bus->adapter, msgs, 2); 59 ret = i2c_transfer(&radeon_connector->ddc_bus->adapter, msgs, 2);
56 if (ret == 2) 60 if (ret == 2)
57 return true; 61 return true;
@@ -960,6 +964,59 @@ void radeon_i2c_destroy(struct radeon_i2c_chan *i2c)
960 kfree(i2c); 964 kfree(i2c);
961} 965}
962 966
967/* Add the default buses */
968void radeon_i2c_init(struct radeon_device *rdev)
969{
970 if (rdev->is_atom_bios)
971 radeon_atombios_i2c_init(rdev);
972 else
973 radeon_combios_i2c_init(rdev);
974}
975
976/* remove all the buses */
977void radeon_i2c_fini(struct radeon_device *rdev)
978{
979 int i;
980
981 for (i = 0; i < RADEON_MAX_I2C_BUS; i++) {
982 if (rdev->i2c_bus[i]) {
983 radeon_i2c_destroy(rdev->i2c_bus[i]);
984 rdev->i2c_bus[i] = NULL;
985 }
986 }
987}
988
989/* Add additional buses */
990void radeon_i2c_add(struct radeon_device *rdev,
991 struct radeon_i2c_bus_rec *rec,
992 const char *name)
993{
994 struct drm_device *dev = rdev->ddev;
995 int i;
996
997 for (i = 0; i < RADEON_MAX_I2C_BUS; i++) {
998 if (!rdev->i2c_bus[i]) {
999 rdev->i2c_bus[i] = radeon_i2c_create(dev, rec, name);
1000 return;
1001 }
1002 }
1003}
1004
1005/* looks up bus based on id */
1006struct radeon_i2c_chan *radeon_i2c_lookup(struct radeon_device *rdev,
1007 struct radeon_i2c_bus_rec *i2c_bus)
1008{
1009 int i;
1010
1011 for (i = 0; i < RADEON_MAX_I2C_BUS; i++) {
1012 if (rdev->i2c_bus[i] &&
1013 (rdev->i2c_bus[i]->rec.i2c_id == i2c_bus->i2c_id)) {
1014 return rdev->i2c_bus[i];
1015 }
1016 }
1017 return NULL;
1018}
1019
963struct drm_encoder *radeon_best_encoder(struct drm_connector *connector) 1020struct drm_encoder *radeon_best_encoder(struct drm_connector *connector)
964{ 1021{
965 return NULL; 1022 return NULL;
@@ -1020,3 +1077,28 @@ void radeon_i2c_put_byte(struct radeon_i2c_chan *i2c_bus,
1020 addr, val); 1077 addr, val);
1021} 1078}
1022 1079
1080/* router switching */
1081void radeon_router_select_port(struct radeon_connector *radeon_connector)
1082{
1083 u8 val;
1084
1085 if (!radeon_connector->router.valid)
1086 return;
1087
1088 radeon_i2c_get_byte(radeon_connector->router_bus,
1089 radeon_connector->router.i2c_addr,
1090 0x3, &val);
1091 val &= radeon_connector->router.mux_control_pin;
1092 radeon_i2c_put_byte(radeon_connector->router_bus,
1093 radeon_connector->router.i2c_addr,
1094 0x3, val);
1095 radeon_i2c_get_byte(radeon_connector->router_bus,
1096 radeon_connector->router.i2c_addr,
1097 0x1, &val);
1098 val &= radeon_connector->router.mux_control_pin;
1099 val |= radeon_connector->router.mux_state;
1100 radeon_i2c_put_byte(radeon_connector->router_bus,
1101 radeon_connector->router.i2c_addr,
1102 0x1, val);
1103}
1104
diff --git a/drivers/gpu/drm/radeon/radeon_kms.c b/drivers/gpu/drm/radeon/radeon_kms.c
index ddcd3b13f151..b1c8ace5f080 100644
--- a/drivers/gpu/drm/radeon/radeon_kms.c
+++ b/drivers/gpu/drm/radeon/radeon_kms.c
@@ -112,7 +112,9 @@ int radeon_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
112 112
113 info = data; 113 info = data;
114 value_ptr = (uint32_t *)((unsigned long)info->value); 114 value_ptr = (uint32_t *)((unsigned long)info->value);
115 value = *value_ptr; 115 if (DRM_COPY_FROM_USER(&value, value_ptr, sizeof(value)))
116 return -EFAULT;
117
116 switch (info->request) { 118 switch (info->request) {
117 case RADEON_INFO_DEVICE_ID: 119 case RADEON_INFO_DEVICE_ID:
118 value = dev->pci_device; 120 value = dev->pci_device;
@@ -160,13 +162,27 @@ int radeon_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
160 return -EINVAL; 162 return -EINVAL;
161 } 163 }
162 case RADEON_INFO_WANT_HYPERZ: 164 case RADEON_INFO_WANT_HYPERZ:
165 /* The "value" here is both an input and output parameter.
166 * If the input value is 1, filp requests hyper-z access.
167 * If the input value is 0, filp revokes its hyper-z access.
168 *
169 * When returning, the value is 1 if filp owns hyper-z access,
170 * 0 otherwise. */
171 if (value >= 2) {
172 DRM_DEBUG_KMS("WANT_HYPERZ: invalid value %d\n", value);
173 return -EINVAL;
174 }
163 mutex_lock(&dev->struct_mutex); 175 mutex_lock(&dev->struct_mutex);
164 if (rdev->hyperz_filp) 176 if (value == 1) {
165 value = 0; 177 /* wants hyper-z */
166 else { 178 if (!rdev->hyperz_filp)
167 rdev->hyperz_filp = filp; 179 rdev->hyperz_filp = filp;
168 value = 1; 180 } else if (value == 0) {
181 /* revokes hyper-z */
182 if (rdev->hyperz_filp == filp)
183 rdev->hyperz_filp = NULL;
169 } 184 }
185 value = rdev->hyperz_filp == filp ? 1 : 0;
170 mutex_unlock(&dev->struct_mutex); 186 mutex_unlock(&dev->struct_mutex);
171 break; 187 break;
172 default: 188 default:
diff --git a/drivers/gpu/drm/radeon/radeon_mode.h b/drivers/gpu/drm/radeon/radeon_mode.h
index 71aea4037e90..5bbc086b9267 100644
--- a/drivers/gpu/drm/radeon/radeon_mode.h
+++ b/drivers/gpu/drm/radeon/radeon_mode.h
@@ -82,6 +82,8 @@ enum radeon_hpd_id {
82 RADEON_HPD_NONE = 0xff, 82 RADEON_HPD_NONE = 0xff,
83}; 83};
84 84
85#define RADEON_MAX_I2C_BUS 16
86
85/* radeon gpio-based i2c 87/* radeon gpio-based i2c
86 * 1. "mask" reg and bits 88 * 1. "mask" reg and bits
87 * grabs the gpio pins for software use 89 * grabs the gpio pins for software use
@@ -398,6 +400,16 @@ struct radeon_hpd {
398 struct radeon_gpio_rec gpio; 400 struct radeon_gpio_rec gpio;
399}; 401};
400 402
403struct radeon_router {
404 bool valid;
405 u32 router_id;
406 struct radeon_i2c_bus_rec i2c_info;
407 u8 i2c_addr;
408 u8 mux_type;
409 u8 mux_control_pin;
410 u8 mux_state;
411};
412
401struct radeon_connector { 413struct radeon_connector {
402 struct drm_connector base; 414 struct drm_connector base;
403 uint32_t connector_id; 415 uint32_t connector_id;
@@ -413,6 +425,8 @@ struct radeon_connector {
413 bool dac_load_detect; 425 bool dac_load_detect;
414 uint16_t connector_object_id; 426 uint16_t connector_object_id;
415 struct radeon_hpd hpd; 427 struct radeon_hpd hpd;
428 struct radeon_router router;
429 struct radeon_i2c_chan *router_bus;
416}; 430};
417 431
418struct radeon_framebuffer { 432struct radeon_framebuffer {
@@ -445,6 +459,15 @@ extern void atombios_dig_transmitter_setup(struct drm_encoder *encoder,
445extern int radeon_dp_i2c_aux_ch(struct i2c_adapter *adapter, int mode, 459extern int radeon_dp_i2c_aux_ch(struct i2c_adapter *adapter, int mode,
446 uint8_t write_byte, uint8_t *read_byte); 460 uint8_t write_byte, uint8_t *read_byte);
447 461
462extern void radeon_i2c_init(struct radeon_device *rdev);
463extern void radeon_i2c_fini(struct radeon_device *rdev);
464extern void radeon_combios_i2c_init(struct radeon_device *rdev);
465extern void radeon_atombios_i2c_init(struct radeon_device *rdev);
466extern void radeon_i2c_add(struct radeon_device *rdev,
467 struct radeon_i2c_bus_rec *rec,
468 const char *name);
469extern struct radeon_i2c_chan *radeon_i2c_lookup(struct radeon_device *rdev,
470 struct radeon_i2c_bus_rec *i2c_bus);
448extern struct radeon_i2c_chan *radeon_i2c_create_dp(struct drm_device *dev, 471extern struct radeon_i2c_chan *radeon_i2c_create_dp(struct drm_device *dev,
449 struct radeon_i2c_bus_rec *rec, 472 struct radeon_i2c_bus_rec *rec,
450 const char *name); 473 const char *name);
@@ -460,6 +483,7 @@ extern void radeon_i2c_put_byte(struct radeon_i2c_chan *i2c,
460 u8 slave_addr, 483 u8 slave_addr,
461 u8 addr, 484 u8 addr,
462 u8 val); 485 u8 val);
486extern void radeon_router_select_port(struct radeon_connector *radeon_connector);
463extern bool radeon_ddc_probe(struct radeon_connector *radeon_connector); 487extern bool radeon_ddc_probe(struct radeon_connector *radeon_connector);
464extern int radeon_ddc_get_modes(struct radeon_connector *radeon_connector); 488extern int radeon_ddc_get_modes(struct radeon_connector *radeon_connector);
465 489
diff --git a/drivers/gpu/drm/radeon/radeon_pm.c b/drivers/gpu/drm/radeon/radeon_pm.c
index 95f8b3a3c43d..58038f5cab38 100644
--- a/drivers/gpu/drm/radeon/radeon_pm.c
+++ b/drivers/gpu/drm/radeon/radeon_pm.c
@@ -472,9 +472,9 @@ static const struct attribute_group hwmon_attrgroup = {
472 .attrs = hwmon_attributes, 472 .attrs = hwmon_attributes,
473}; 473};
474 474
475static void radeon_hwmon_init(struct radeon_device *rdev) 475static int radeon_hwmon_init(struct radeon_device *rdev)
476{ 476{
477 int err; 477 int err = 0;
478 478
479 rdev->pm.int_hwmon_dev = NULL; 479 rdev->pm.int_hwmon_dev = NULL;
480 480
@@ -483,15 +483,26 @@ static void radeon_hwmon_init(struct radeon_device *rdev)
483 case THERMAL_TYPE_RV770: 483 case THERMAL_TYPE_RV770:
484 case THERMAL_TYPE_EVERGREEN: 484 case THERMAL_TYPE_EVERGREEN:
485 rdev->pm.int_hwmon_dev = hwmon_device_register(rdev->dev); 485 rdev->pm.int_hwmon_dev = hwmon_device_register(rdev->dev);
486 if (IS_ERR(rdev->pm.int_hwmon_dev)) {
487 err = PTR_ERR(rdev->pm.int_hwmon_dev);
488 dev_err(rdev->dev,
489 "Unable to register hwmon device: %d\n", err);
490 break;
491 }
486 dev_set_drvdata(rdev->pm.int_hwmon_dev, rdev->ddev); 492 dev_set_drvdata(rdev->pm.int_hwmon_dev, rdev->ddev);
487 err = sysfs_create_group(&rdev->pm.int_hwmon_dev->kobj, 493 err = sysfs_create_group(&rdev->pm.int_hwmon_dev->kobj,
488 &hwmon_attrgroup); 494 &hwmon_attrgroup);
489 if (err) 495 if (err) {
490 DRM_ERROR("Unable to create hwmon sysfs file: %d\n", err); 496 dev_err(rdev->dev,
497 "Unable to create hwmon sysfs file: %d\n", err);
498 hwmon_device_unregister(rdev->dev);
499 }
491 break; 500 break;
492 default: 501 default:
493 break; 502 break;
494 } 503 }
504
505 return err;
495} 506}
496 507
497static void radeon_hwmon_fini(struct radeon_device *rdev) 508static void radeon_hwmon_fini(struct radeon_device *rdev)
@@ -540,6 +551,7 @@ void radeon_pm_resume(struct radeon_device *rdev)
540int radeon_pm_init(struct radeon_device *rdev) 551int radeon_pm_init(struct radeon_device *rdev)
541{ 552{
542 int ret; 553 int ret;
554
543 /* default to profile method */ 555 /* default to profile method */
544 rdev->pm.pm_method = PM_METHOD_PROFILE; 556 rdev->pm.pm_method = PM_METHOD_PROFILE;
545 rdev->pm.profile = PM_PROFILE_DEFAULT; 557 rdev->pm.profile = PM_PROFILE_DEFAULT;
@@ -561,7 +573,9 @@ int radeon_pm_init(struct radeon_device *rdev)
561 } 573 }
562 574
563 /* set up the internal thermal sensor if applicable */ 575 /* set up the internal thermal sensor if applicable */
564 radeon_hwmon_init(rdev); 576 ret = radeon_hwmon_init(rdev);
577 if (ret)
578 return ret;
565 if (rdev->pm.num_power_states > 1) { 579 if (rdev->pm.num_power_states > 1) {
566 /* where's the best place to put these? */ 580 /* where's the best place to put these? */
567 ret = device_create_file(rdev->dev, &dev_attr_power_profile); 581 ret = device_create_file(rdev->dev, &dev_attr_power_profile);
diff --git a/drivers/gpu/drm/radeon/reg_srcs/rv515 b/drivers/gpu/drm/radeon/reg_srcs/rv515
index 8293855f5f0d..b3f9f1d92005 100644
--- a/drivers/gpu/drm/radeon/reg_srcs/rv515
+++ b/drivers/gpu/drm/radeon/reg_srcs/rv515
@@ -316,6 +316,7 @@ rv515 0x6d40
3160x4BD0 FG_FOG_COLOR_B 3160x4BD0 FG_FOG_COLOR_B
3170x4BD4 FG_ALPHA_FUNC 3170x4BD4 FG_ALPHA_FUNC
3180x4BD8 FG_DEPTH_SRC 3180x4BD8 FG_DEPTH_SRC
3190x4BE0 FG_ALPHA_VALUE
3190x4C00 US_ALU_CONST_R_0 3200x4C00 US_ALU_CONST_R_0
3200x4C04 US_ALU_CONST_G_0 3210x4C04 US_ALU_CONST_G_0
3210x4C08 US_ALU_CONST_B_0 3220x4C08 US_ALU_CONST_B_0
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
index 437ac786277a..64d7f47df868 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
@@ -737,7 +737,7 @@ static struct drm_framebuffer *vmw_kms_fb_create(struct drm_device *dev,
737 737
738 if (ret) { 738 if (ret) {
739 DRM_ERROR("failed to create vmw_framebuffer: %i\n", ret); 739 DRM_ERROR("failed to create vmw_framebuffer: %i\n", ret);
740 return NULL; 740 return ERR_PTR(ret);
741 } 741 }
742 return &vfb->base; 742 return &vfb->base;
743 743
@@ -747,7 +747,7 @@ try_dmabuf:
747 ret = vmw_user_dmabuf_lookup(tfile, mode_cmd->handle, &bo); 747 ret = vmw_user_dmabuf_lookup(tfile, mode_cmd->handle, &bo);
748 if (ret) { 748 if (ret) {
749 DRM_ERROR("failed to find buffer: %i\n", ret); 749 DRM_ERROR("failed to find buffer: %i\n", ret);
750 return NULL; 750 return ERR_PTR(-ENOENT);
751 } 751 }
752 752
753 ret = vmw_kms_new_framebuffer_dmabuf(dev_priv, bo, &vfb, 753 ret = vmw_kms_new_framebuffer_dmabuf(dev_priv, bo, &vfb,
@@ -758,7 +758,7 @@ try_dmabuf:
758 758
759 if (ret) { 759 if (ret) {
760 DRM_ERROR("failed to create vmw_framebuffer: %i\n", ret); 760 DRM_ERROR("failed to create vmw_framebuffer: %i\n", ret);
761 return NULL; 761 return ERR_PTR(ret);
762 } 762 }
763 763
764 return &vfb->base; 764 return &vfb->base;
@@ -768,7 +768,7 @@ err_not_scanout:
768 /* vmw_user_surface_lookup takes one ref */ 768 /* vmw_user_surface_lookup takes one ref */
769 vmw_surface_unreference(&surface); 769 vmw_surface_unreference(&surface);
770 770
771 return NULL; 771 return ERR_PTR(-EINVAL);
772} 772}
773 773
774static struct drm_mode_config_funcs vmw_kms_funcs = { 774static struct drm_mode_config_funcs vmw_kms_funcs = {
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c
index cfaf690a5b2f..2ff5cf78235f 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c
@@ -79,7 +79,7 @@ static void vmw_ldu_crtc_restore(struct drm_crtc *crtc)
79 79
80static void vmw_ldu_crtc_gamma_set(struct drm_crtc *crtc, 80static void vmw_ldu_crtc_gamma_set(struct drm_crtc *crtc,
81 u16 *r, u16 *g, u16 *b, 81 u16 *r, u16 *g, u16 *b,
82 uint32_t size) 82 uint32_t start, uint32_t size)
83{ 83{
84} 84}
85 85
diff --git a/drivers/hid/hid-wacom.c b/drivers/hid/hid-wacom.c
index 807dcd1555a6..724f46ed612f 100644
--- a/drivers/hid/hid-wacom.c
+++ b/drivers/hid/hid-wacom.c
@@ -230,7 +230,7 @@ static int wacom_raw_event(struct hid_device *hdev, struct hid_report *report,
230 input_report_key(input, BTN_RIGHT, 0); 230 input_report_key(input, BTN_RIGHT, 0);
231 input_report_key(input, BTN_MIDDLE, 0); 231 input_report_key(input, BTN_MIDDLE, 0);
232 input_report_abs(input, ABS_DISTANCE, 232 input_report_abs(input, ABS_DISTANCE,
233 input->absmax[ABS_DISTANCE]); 233 input_abs_get_max(input, ABS_DISTANCE));
234 } else { 234 } else {
235 input_report_key(input, BTN_TOUCH, 0); 235 input_report_key(input, BTN_TOUCH, 0);
236 input_report_key(input, BTN_STYLUS, 0); 236 input_report_key(input, BTN_STYLUS, 0);
@@ -383,38 +383,37 @@ move_on:
383 383
384 /* Basics */ 384 /* Basics */
385 input->evbit[0] |= BIT(EV_KEY) | BIT(EV_ABS) | BIT(EV_REL); 385 input->evbit[0] |= BIT(EV_KEY) | BIT(EV_ABS) | BIT(EV_REL);
386 input->absbit[0] |= BIT(ABS_X) | BIT(ABS_Y) | 386
387 BIT(ABS_PRESSURE) | BIT(ABS_DISTANCE); 387 __set_bit(REL_WHEEL, input->relbit);
388 input->relbit[0] |= BIT(REL_WHEEL); 388
389 set_bit(BTN_TOOL_PEN, input->keybit); 389 __set_bit(BTN_TOOL_PEN, input->keybit);
390 set_bit(BTN_TOUCH, input->keybit); 390 __set_bit(BTN_TOUCH, input->keybit);
391 set_bit(BTN_STYLUS, input->keybit); 391 __set_bit(BTN_STYLUS, input->keybit);
392 set_bit(BTN_STYLUS2, input->keybit); 392 __set_bit(BTN_STYLUS2, input->keybit);
393 set_bit(BTN_LEFT, input->keybit); 393 __set_bit(BTN_LEFT, input->keybit);
394 set_bit(BTN_RIGHT, input->keybit); 394 __set_bit(BTN_RIGHT, input->keybit);
395 set_bit(BTN_MIDDLE, input->keybit); 395 __set_bit(BTN_MIDDLE, input->keybit);
396 396
397 /* Pad */ 397 /* Pad */
398 input->evbit[0] |= BIT(EV_MSC); 398 input->evbit[0] |= BIT(EV_MSC);
399 input->mscbit[0] |= BIT(MSC_SERIAL);
400 set_bit(BTN_0, input->keybit);
401 set_bit(BTN_1, input->keybit);
402 set_bit(BTN_TOOL_FINGER, input->keybit);
403 399
404 /* Distance, rubber and mouse */ 400 __set_bit(MSC_SERIAL, input->mscbit);
405 input->absbit[0] |= BIT(ABS_DISTANCE);
406 set_bit(BTN_TOOL_RUBBER, input->keybit);
407 set_bit(BTN_TOOL_MOUSE, input->keybit);
408 401
409 input->absmax[ABS_PRESSURE] = 511; 402 __set_bit(BTN_0, input->keybit);
410 input->absmax[ABS_DISTANCE] = 32; 403 __set_bit(BTN_1, input->keybit);
404 __set_bit(BTN_TOOL_FINGER, input->keybit);
411 405
412 input->absmax[ABS_X] = 16704; 406 /* Distance, rubber and mouse */
413 input->absmax[ABS_Y] = 12064; 407 __set_bit(BTN_TOOL_RUBBER, input->keybit);
414 input->absfuzz[ABS_X] = 4; 408 __set_bit(BTN_TOOL_MOUSE, input->keybit);
415 input->absfuzz[ABS_Y] = 4; 409
410 input_set_abs_params(input, ABS_X, 0, 16704, 4, 0);
411 input_set_abs_params(input, ABS_Y, 0, 12064, 4, 0);
412 input_set_abs_params(input, ABS_PRESSURE, 0, 511, 0, 0);
413 input_set_abs_params(input, ABS_DISTANCE, 0, 32, 0, 0);
416 414
417 return 0; 415 return 0;
416
418err_free: 417err_free:
419 kfree(wdata); 418 kfree(wdata);
420 return ret; 419 return ret;
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 4d382ae53092..0fba82943125 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -332,11 +332,11 @@ config SENSORS_F71805F
332 will be called f71805f. 332 will be called f71805f.
333 333
334config SENSORS_F71882FG 334config SENSORS_F71882FG
335 tristate "Fintek F71858FG, F71862FG, F71882FG, F71889FG and F8000" 335 tristate "Fintek F71808E, F71858FG, F71862FG, F71882FG, F71889FG and F8000"
336 depends on EXPERIMENTAL 336 depends on EXPERIMENTAL
337 help 337 help
338 If you say yes here you get support for hardware monitoring 338 If you say yes here you get support for hardware monitoring features
339 features of the Fintek F71858FG, F71862FG/71863FG, F71882FG/F71883FG, 339 of the Fintek F71808E, F71858FG, F71862FG/71863FG, F71882FG/F71883FG,
340 F71889FG and F8000 Super-I/O chips. 340 F71889FG and F8000 Super-I/O chips.
341 341
342 This driver can also be built as a module. If so, the module 342 This driver can also be built as a module. If so, the module
@@ -405,7 +405,7 @@ config SENSORS_CORETEMP
405 help 405 help
406 If you say yes here you get support for the temperature 406 If you say yes here you get support for the temperature
407 sensor inside your CPU. Most of the family 6 CPUs 407 sensor inside your CPU. Most of the family 6 CPUs
408 are supported. Check documentation/driver for details. 408 are supported. Check Documentation/hwmon/coretemp for details.
409 409
410config SENSORS_PKGTEMP 410config SENSORS_PKGTEMP
411 tristate "Intel processor package temperature sensor" 411 tristate "Intel processor package temperature sensor"
@@ -463,6 +463,18 @@ config SENSORS_JZ4740
463 This driver can also be build as a module. If so, the module will be 463 This driver can also be build as a module. If so, the module will be
464 called jz4740-hwmon. 464 called jz4740-hwmon.
465 465
466config SENSORS_JC42
467 tristate "JEDEC JC42.4 compliant temperature sensors"
468 depends on I2C
469 help
470 If you say yes here you get support for Jedec JC42.4 compliant
471 temperature sensors. Support will include, but not be limited to,
472 ADT7408, CAT34TS02,, CAT6095, MAX6604, MCP9805, MCP98242, MCP98243,
473 MCP9843, SE97, SE98, STTS424, TSE2002B3, and TS3000B3.
474
475 This driver can also be built as a module. If so, the module
476 will be called jc42.
477
466config SENSORS_LM63 478config SENSORS_LM63
467 tristate "National Semiconductor LM63 and LM64" 479 tristate "National Semiconductor LM63 and LM64"
468 depends on I2C 480 depends on I2C
@@ -700,7 +712,8 @@ config SENSORS_PC87427
700 functions of the National Semiconductor PC87427 Super-I/O chip. 712 functions of the National Semiconductor PC87427 Super-I/O chip.
701 The chip has two distinct logical devices, one for fan speed 713 The chip has two distinct logical devices, one for fan speed
702 monitoring and control, and one for voltage and temperature 714 monitoring and control, and one for voltage and temperature
703 monitoring. Only fan speed monitoring is supported right now. 715 monitoring. Fan speed monitoring and control are supported, as
716 well as temperature monitoring. Voltages aren't supported yet.
704 717
705 This driver can also be built as a module. If so, the module 718 This driver can also be built as a module. If so, the module
706 will be called pc87427. 719 will be called pc87427.
@@ -756,6 +769,21 @@ config SENSORS_SIS5595
756 This driver can also be built as a module. If so, the module 769 This driver can also be built as a module. If so, the module
757 will be called sis5595. 770 will be called sis5595.
758 771
772config SENSORS_SMM665
773 tristate "Summit Microelectronics SMM665"
774 depends on I2C && EXPERIMENTAL
775 default n
776 help
777 If you say yes here you get support for the hardware monitoring
778 features of the Summit Microelectronics SMM665/SMM665B Six-Channel
779 Active DC Output Controller / Monitor.
780
781 Other supported chips are SMM465, SMM665C, SMM764, and SMM766.
782 Support for those chips is untested.
783
784 This driver can also be built as a module. If so, the module will
785 be called smm665.
786
759config SENSORS_DME1737 787config SENSORS_DME1737
760 tristate "SMSC DME1737, SCH311x and compatibles" 788 tristate "SMSC DME1737, SCH311x and compatibles"
761 depends on I2C && EXPERIMENTAL 789 depends on I2C && EXPERIMENTAL
@@ -778,6 +806,16 @@ config SENSORS_EMC1403
778 Threshold values can be configured using sysfs. 806 Threshold values can be configured using sysfs.
779 Data from the different diodes are accessible via sysfs. 807 Data from the different diodes are accessible via sysfs.
780 808
809config SENSORS_EMC2103
810 tristate "SMSC EMC2103"
811 depends on I2C
812 help
813 If you say yes here you get support for the temperature
814 and fan sensors of the SMSC EMC2103 chips.
815
816 This driver can also be built as a module. If so, the module
817 will be called emc2103.
818
781config SENSORS_SMSC47M1 819config SENSORS_SMSC47M1
782 tristate "SMSC LPC47M10x and compatibles" 820 tristate "SMSC LPC47M10x and compatibles"
783 help 821 help
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 9103bd6ea73a..e3c2484f6c5f 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -43,6 +43,7 @@ obj-$(CONFIG_SENSORS_PKGTEMP) += pkgtemp.o
43obj-$(CONFIG_SENSORS_DME1737) += dme1737.o 43obj-$(CONFIG_SENSORS_DME1737) += dme1737.o
44obj-$(CONFIG_SENSORS_DS1621) += ds1621.o 44obj-$(CONFIG_SENSORS_DS1621) += ds1621.o
45obj-$(CONFIG_SENSORS_EMC1403) += emc1403.o 45obj-$(CONFIG_SENSORS_EMC1403) += emc1403.o
46obj-$(CONFIG_SENSORS_EMC2103) += emc2103.o
46obj-$(CONFIG_SENSORS_F71805F) += f71805f.o 47obj-$(CONFIG_SENSORS_F71805F) += f71805f.o
47obj-$(CONFIG_SENSORS_F71882FG) += f71882fg.o 48obj-$(CONFIG_SENSORS_F71882FG) += f71882fg.o
48obj-$(CONFIG_SENSORS_F75375S) += f75375s.o 49obj-$(CONFIG_SENSORS_F75375S) += f75375s.o
@@ -56,6 +57,7 @@ obj-$(CONFIG_SENSORS_I5K_AMB) += i5k_amb.o
56obj-$(CONFIG_SENSORS_IBMAEM) += ibmaem.o 57obj-$(CONFIG_SENSORS_IBMAEM) += ibmaem.o
57obj-$(CONFIG_SENSORS_IBMPEX) += ibmpex.o 58obj-$(CONFIG_SENSORS_IBMPEX) += ibmpex.o
58obj-$(CONFIG_SENSORS_IT87) += it87.o 59obj-$(CONFIG_SENSORS_IT87) += it87.o
60obj-$(CONFIG_SENSORS_JC42) += jc42.o
59obj-$(CONFIG_SENSORS_JZ4740) += jz4740-hwmon.o 61obj-$(CONFIG_SENSORS_JZ4740) += jz4740-hwmon.o
60obj-$(CONFIG_SENSORS_K8TEMP) += k8temp.o 62obj-$(CONFIG_SENSORS_K8TEMP) += k8temp.o
61obj-$(CONFIG_SENSORS_K10TEMP) += k10temp.o 63obj-$(CONFIG_SENSORS_K10TEMP) += k10temp.o
@@ -88,6 +90,7 @@ obj-$(CONFIG_SENSORS_PCF8591) += pcf8591.o
88obj-$(CONFIG_SENSORS_S3C) += s3c-hwmon.o 90obj-$(CONFIG_SENSORS_S3C) += s3c-hwmon.o
89obj-$(CONFIG_SENSORS_SHT15) += sht15.o 91obj-$(CONFIG_SENSORS_SHT15) += sht15.o
90obj-$(CONFIG_SENSORS_SIS5595) += sis5595.o 92obj-$(CONFIG_SENSORS_SIS5595) += sis5595.o
93obj-$(CONFIG_SENSORS_SMM665) += smm665.o
91obj-$(CONFIG_SENSORS_SMSC47B397)+= smsc47b397.o 94obj-$(CONFIG_SENSORS_SMSC47B397)+= smsc47b397.o
92obj-$(CONFIG_SENSORS_SMSC47M1) += smsc47m1.o 95obj-$(CONFIG_SENSORS_SMSC47M1) += smsc47m1.o
93obj-$(CONFIG_SENSORS_SMSC47M192)+= smsc47m192.o 96obj-$(CONFIG_SENSORS_SMSC47M192)+= smsc47m192.o
diff --git a/drivers/hwmon/ams/ams.h b/drivers/hwmon/ams/ams.h
index b28d7e27a031..90f094d45450 100644
--- a/drivers/hwmon/ams/ams.h
+++ b/drivers/hwmon/ams/ams.h
@@ -23,7 +23,7 @@ struct ams {
23 23
24 /* General properties */ 24 /* General properties */
25 struct device_node *of_node; 25 struct device_node *of_node;
26 struct of_device *of_dev; 26 struct platform_device *of_dev;
27 char has_device; 27 char has_device;
28 char vflag; 28 char vflag;
29 u32 orient1; 29 u32 orient1;
diff --git a/drivers/hwmon/asc7621.c b/drivers/hwmon/asc7621.c
index 3b973f30b1f6..89b4f3babe87 100644
--- a/drivers/hwmon/asc7621.c
+++ b/drivers/hwmon/asc7621.c
@@ -1150,9 +1150,6 @@ static int asc7621_detect(struct i2c_client *client,
1150{ 1150{
1151 struct i2c_adapter *adapter = client->adapter; 1151 struct i2c_adapter *adapter = client->adapter;
1152 int company, verstep, chip_index; 1152 int company, verstep, chip_index;
1153 struct device *dev;
1154
1155 dev = &client->dev;
1156 1153
1157 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 1154 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
1158 return -ENODEV; 1155 return -ENODEV;
@@ -1169,13 +1166,11 @@ static int asc7621_detect(struct i2c_client *client,
1169 1166
1170 if (company == asc7621_chips[chip_index].company_id && 1167 if (company == asc7621_chips[chip_index].company_id &&
1171 verstep == asc7621_chips[chip_index].verstep_id) { 1168 verstep == asc7621_chips[chip_index].verstep_id) {
1172 strlcpy(client->name, asc7621_chips[chip_index].name,
1173 I2C_NAME_SIZE);
1174 strlcpy(info->type, asc7621_chips[chip_index].name, 1169 strlcpy(info->type, asc7621_chips[chip_index].name,
1175 I2C_NAME_SIZE); 1170 I2C_NAME_SIZE);
1176 1171
1177 dev_info(&adapter->dev, "Matched %s\n", 1172 dev_info(&adapter->dev, "Matched %s at 0x%02x\n",
1178 asc7621_chips[chip_index].name); 1173 asc7621_chips[chip_index].name, client->addr);
1179 return 0; 1174 return 0;
1180 } 1175 }
1181 } 1176 }
diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
index 05344af50734..c070c9714cbe 100644
--- a/drivers/hwmon/coretemp.c
+++ b/drivers/hwmon/coretemp.c
@@ -480,7 +480,6 @@ exit:
480 return err; 480 return err;
481} 481}
482 482
483#ifdef CONFIG_HOTPLUG_CPU
484static void coretemp_device_remove(unsigned int cpu) 483static void coretemp_device_remove(unsigned int cpu)
485{ 484{
486 struct pdev_entry *p, *n; 485 struct pdev_entry *p, *n;
@@ -515,7 +514,6 @@ static int __cpuinit coretemp_cpu_callback(struct notifier_block *nfb,
515static struct notifier_block coretemp_cpu_notifier __refdata = { 514static struct notifier_block coretemp_cpu_notifier __refdata = {
516 .notifier_call = coretemp_cpu_callback, 515 .notifier_call = coretemp_cpu_callback,
517}; 516};
518#endif /* !CONFIG_HOTPLUG_CPU */
519 517
520static int __init coretemp_init(void) 518static int __init coretemp_init(void)
521{ 519{
@@ -537,12 +535,9 @@ static int __init coretemp_init(void)
537 * sensors. We check this bit only, all the early CPUs 535 * sensors. We check this bit only, all the early CPUs
538 * without thermal sensors will be filtered out. 536 * without thermal sensors will be filtered out.
539 */ 537 */
540 if (c->cpuid_level >= 6 && (cpuid_eax(0x06) & 0x01)) { 538 if (c->cpuid_level >= 6 && (cpuid_eax(0x06) & 0x01))
541 err = coretemp_device_add(i); 539 coretemp_device_add(i);
542 if (err) 540 else {
543 goto exit_devices_unreg;
544
545 } else {
546 printk(KERN_INFO DRVNAME ": CPU (model=0x%x)" 541 printk(KERN_INFO DRVNAME ": CPU (model=0x%x)"
547 " has no thermal sensor.\n", c->x86_model); 542 " has no thermal sensor.\n", c->x86_model);
548 } 543 }
@@ -552,21 +547,13 @@ static int __init coretemp_init(void)
552 goto exit_driver_unreg; 547 goto exit_driver_unreg;
553 } 548 }
554 549
555#ifdef CONFIG_HOTPLUG_CPU
556 register_hotcpu_notifier(&coretemp_cpu_notifier); 550 register_hotcpu_notifier(&coretemp_cpu_notifier);
557#endif
558 return 0; 551 return 0;
559 552
560exit_devices_unreg:
561 mutex_lock(&pdev_list_mutex);
562 list_for_each_entry_safe(p, n, &pdev_list, list) {
563 platform_device_unregister(p->pdev);
564 list_del(&p->list);
565 kfree(p);
566 }
567 mutex_unlock(&pdev_list_mutex);
568exit_driver_unreg: 553exit_driver_unreg:
554#ifndef CONFIG_HOTPLUG_CPU
569 platform_driver_unregister(&coretemp_driver); 555 platform_driver_unregister(&coretemp_driver);
556#endif
570exit: 557exit:
571 return err; 558 return err;
572} 559}
diff --git a/drivers/hwmon/emc1403.c b/drivers/hwmon/emc1403.c
index 0e4b5642638d..5b58b20dead1 100644
--- a/drivers/hwmon/emc1403.c
+++ b/drivers/hwmon/emc1403.c
@@ -89,6 +89,35 @@ static ssize_t store_temp(struct device *dev,
89 return count; 89 return count;
90} 90}
91 91
92static ssize_t store_bit(struct device *dev,
93 struct device_attribute *attr, const char *buf, size_t count)
94{
95 struct i2c_client *client = to_i2c_client(dev);
96 struct thermal_data *data = i2c_get_clientdata(client);
97 struct sensor_device_attribute_2 *sda = to_sensor_dev_attr_2(attr);
98 unsigned long val;
99 int retval;
100
101 if (strict_strtoul(buf, 10, &val))
102 return -EINVAL;
103
104 mutex_lock(&data->mutex);
105 retval = i2c_smbus_read_byte_data(client, sda->nr);
106 if (retval < 0)
107 goto fail;
108
109 retval &= ~sda->index;
110 if (val)
111 retval |= sda->index;
112
113 retval = i2c_smbus_write_byte_data(client, sda->index, retval);
114 if (retval == 0)
115 retval = count;
116fail:
117 mutex_unlock(&data->mutex);
118 return retval;
119}
120
92static ssize_t show_hyst(struct device *dev, 121static ssize_t show_hyst(struct device *dev,
93 struct device_attribute *attr, char *buf) 122 struct device_attribute *attr, char *buf)
94{ 123{
@@ -200,6 +229,9 @@ static SENSOR_DEVICE_ATTR_2(temp3_crit_alarm, S_IRUGO,
200static SENSOR_DEVICE_ATTR(temp3_crit_hyst, S_IRUGO | S_IWUSR, 229static SENSOR_DEVICE_ATTR(temp3_crit_hyst, S_IRUGO | S_IWUSR,
201 show_hyst, store_hyst, 0x1A); 230 show_hyst, store_hyst, 0x1A);
202 231
232static SENSOR_DEVICE_ATTR_2(power_state, S_IRUGO | S_IWUSR,
233 show_bit, store_bit, 0x03, 0x40);
234
203static struct attribute *mid_att_thermal[] = { 235static struct attribute *mid_att_thermal[] = {
204 &sensor_dev_attr_temp1_min.dev_attr.attr, 236 &sensor_dev_attr_temp1_min.dev_attr.attr,
205 &sensor_dev_attr_temp1_max.dev_attr.attr, 237 &sensor_dev_attr_temp1_max.dev_attr.attr,
@@ -225,6 +257,7 @@ static struct attribute *mid_att_thermal[] = {
225 &sensor_dev_attr_temp3_max_alarm.dev_attr.attr, 257 &sensor_dev_attr_temp3_max_alarm.dev_attr.attr,
226 &sensor_dev_attr_temp3_crit_alarm.dev_attr.attr, 258 &sensor_dev_attr_temp3_crit_alarm.dev_attr.attr,
227 &sensor_dev_attr_temp3_crit_hyst.dev_attr.attr, 259 &sensor_dev_attr_temp3_crit_hyst.dev_attr.attr,
260 &sensor_dev_attr_power_state.dev_attr.attr,
228 NULL 261 NULL
229}; 262};
230 263
diff --git a/drivers/hwmon/emc2103.c b/drivers/hwmon/emc2103.c
new file mode 100644
index 000000000000..af914ad93ece
--- /dev/null
+++ b/drivers/hwmon/emc2103.c
@@ -0,0 +1,740 @@
1/*
2 emc2103.c - Support for SMSC EMC2103
3 Copyright (c) 2010 SMSC
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 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18*/
19
20#include <linux/module.h>
21#include <linux/init.h>
22#include <linux/slab.h>
23#include <linux/jiffies.h>
24#include <linux/i2c.h>
25#include <linux/hwmon.h>
26#include <linux/hwmon-sysfs.h>
27#include <linux/err.h>
28#include <linux/mutex.h>
29
30/* Addresses scanned */
31static const unsigned short normal_i2c[] = { 0x2E, I2C_CLIENT_END };
32
33static const u8 REG_TEMP[4] = { 0x00, 0x02, 0x04, 0x06 };
34static const u8 REG_TEMP_MIN[4] = { 0x3c, 0x38, 0x39, 0x3a };
35static const u8 REG_TEMP_MAX[4] = { 0x34, 0x30, 0x31, 0x32 };
36
37#define REG_CONF1 0x20
38#define REG_TEMP_MAX_ALARM 0x24
39#define REG_TEMP_MIN_ALARM 0x25
40#define REG_FAN_CONF1 0x42
41#define REG_FAN_TARGET_LO 0x4c
42#define REG_FAN_TARGET_HI 0x4d
43#define REG_FAN_TACH_HI 0x4e
44#define REG_FAN_TACH_LO 0x4f
45#define REG_PRODUCT_ID 0xfd
46#define REG_MFG_ID 0xfe
47
48/* equation 4 from datasheet: rpm = (3932160 * multipler) / count */
49#define FAN_RPM_FACTOR 3932160
50
51/* 2103-2 and 2103-4's 3rd temperature sensor can be connected to two diodes
52 * in anti-parallel mode, and in this configuration both can be read
53 * independently (so we have 4 temperature inputs). The device can't
54 * detect if it's connected in this mode, so we have to manually enable
55 * it. Default is to leave the device in the state it's already in (-1).
56 * This parameter allows APD mode to be optionally forced on or off */
57static int apd = -1;
58module_param(apd, bool, 0);
59MODULE_PARM_DESC(init, "Set to zero to disable anti-parallel diode mode");
60
61struct temperature {
62 s8 degrees;
63 u8 fraction; /* 0-7 multiples of 0.125 */
64};
65
66struct emc2103_data {
67 struct device *hwmon_dev;
68 struct mutex update_lock;
69 bool valid; /* registers are valid */
70 bool fan_rpm_control;
71 int temp_count; /* num of temp sensors */
72 unsigned long last_updated; /* in jiffies */
73 struct temperature temp[4]; /* internal + 3 external */
74 s8 temp_min[4]; /* no fractional part */
75 s8 temp_max[4]; /* no fractional part */
76 u8 temp_min_alarm;
77 u8 temp_max_alarm;
78 u8 fan_multiplier;
79 u16 fan_tach;
80 u16 fan_target;
81};
82
83static int read_u8_from_i2c(struct i2c_client *client, u8 i2c_reg, u8 *output)
84{
85 int status = i2c_smbus_read_byte_data(client, i2c_reg);
86 if (status < 0) {
87 dev_warn(&client->dev, "reg 0x%02x, err %d\n",
88 i2c_reg, status);
89 } else {
90 *output = status;
91 }
92 return status;
93}
94
95static void read_temp_from_i2c(struct i2c_client *client, u8 i2c_reg,
96 struct temperature *temp)
97{
98 u8 degrees, fractional;
99
100 if (read_u8_from_i2c(client, i2c_reg, &degrees) < 0)
101 return;
102
103 if (read_u8_from_i2c(client, i2c_reg + 1, &fractional) < 0)
104 return;
105
106 temp->degrees = degrees;
107 temp->fraction = (fractional & 0xe0) >> 5;
108}
109
110static void read_fan_from_i2c(struct i2c_client *client, u16 *output,
111 u8 hi_addr, u8 lo_addr)
112{
113 u8 high_byte, lo_byte;
114
115 if (read_u8_from_i2c(client, hi_addr, &high_byte) < 0)
116 return;
117
118 if (read_u8_from_i2c(client, lo_addr, &lo_byte) < 0)
119 return;
120
121 *output = ((u16)high_byte << 5) | (lo_byte >> 3);
122}
123
124static void write_fan_target_to_i2c(struct i2c_client *client, u16 new_target)
125{
126 u8 high_byte = (new_target & 0x1fe0) >> 5;
127 u8 low_byte = (new_target & 0x001f) << 3;
128 i2c_smbus_write_byte_data(client, REG_FAN_TARGET_LO, low_byte);
129 i2c_smbus_write_byte_data(client, REG_FAN_TARGET_HI, high_byte);
130}
131
132static void read_fan_config_from_i2c(struct i2c_client *client)
133
134{
135 struct emc2103_data *data = i2c_get_clientdata(client);
136 u8 conf1;
137
138 if (read_u8_from_i2c(client, REG_FAN_CONF1, &conf1) < 0)
139 return;
140
141 data->fan_multiplier = 1 << ((conf1 & 0x60) >> 5);
142 data->fan_rpm_control = (conf1 & 0x80) != 0;
143}
144
145static struct emc2103_data *emc2103_update_device(struct device *dev)
146{
147 struct i2c_client *client = to_i2c_client(dev);
148 struct emc2103_data *data = i2c_get_clientdata(client);
149
150 mutex_lock(&data->update_lock);
151
152 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
153 || !data->valid) {
154 int i;
155
156 for (i = 0; i < data->temp_count; i++) {
157 read_temp_from_i2c(client, REG_TEMP[i], &data->temp[i]);
158 read_u8_from_i2c(client, REG_TEMP_MIN[i],
159 &data->temp_min[i]);
160 read_u8_from_i2c(client, REG_TEMP_MAX[i],
161 &data->temp_max[i]);
162 }
163
164 read_u8_from_i2c(client, REG_TEMP_MIN_ALARM,
165 &data->temp_min_alarm);
166 read_u8_from_i2c(client, REG_TEMP_MAX_ALARM,
167 &data->temp_max_alarm);
168
169 read_fan_from_i2c(client, &data->fan_tach,
170 REG_FAN_TACH_HI, REG_FAN_TACH_LO);
171 read_fan_from_i2c(client, &data->fan_target,
172 REG_FAN_TARGET_HI, REG_FAN_TARGET_LO);
173 read_fan_config_from_i2c(client);
174
175 data->last_updated = jiffies;
176 data->valid = true;
177 }
178
179 mutex_unlock(&data->update_lock);
180
181 return data;
182}
183
184static ssize_t
185show_temp(struct device *dev, struct device_attribute *da, char *buf)
186{
187 int nr = to_sensor_dev_attr(da)->index;
188 struct emc2103_data *data = emc2103_update_device(dev);
189 int millidegrees = data->temp[nr].degrees * 1000
190 + data->temp[nr].fraction * 125;
191 return sprintf(buf, "%d\n", millidegrees);
192}
193
194static ssize_t
195show_temp_min(struct device *dev, struct device_attribute *da, char *buf)
196{
197 int nr = to_sensor_dev_attr(da)->index;
198 struct emc2103_data *data = emc2103_update_device(dev);
199 int millidegrees = data->temp_min[nr] * 1000;
200 return sprintf(buf, "%d\n", millidegrees);
201}
202
203static ssize_t
204show_temp_max(struct device *dev, struct device_attribute *da, char *buf)
205{
206 int nr = to_sensor_dev_attr(da)->index;
207 struct emc2103_data *data = emc2103_update_device(dev);
208 int millidegrees = data->temp_max[nr] * 1000;
209 return sprintf(buf, "%d\n", millidegrees);
210}
211
212static ssize_t
213show_temp_fault(struct device *dev, struct device_attribute *da, char *buf)
214{
215 int nr = to_sensor_dev_attr(da)->index;
216 struct emc2103_data *data = emc2103_update_device(dev);
217 bool fault = (data->temp[nr].degrees == -128);
218 return sprintf(buf, "%d\n", fault ? 1 : 0);
219}
220
221static ssize_t
222show_temp_min_alarm(struct device *dev, struct device_attribute *da, char *buf)
223{
224 int nr = to_sensor_dev_attr(da)->index;
225 struct emc2103_data *data = emc2103_update_device(dev);
226 bool alarm = data->temp_min_alarm & (1 << nr);
227 return sprintf(buf, "%d\n", alarm ? 1 : 0);
228}
229
230static ssize_t
231show_temp_max_alarm(struct device *dev, struct device_attribute *da, char *buf)
232{
233 int nr = to_sensor_dev_attr(da)->index;
234 struct emc2103_data *data = emc2103_update_device(dev);
235 bool alarm = data->temp_max_alarm & (1 << nr);
236 return sprintf(buf, "%d\n", alarm ? 1 : 0);
237}
238
239static ssize_t set_temp_min(struct device *dev, struct device_attribute *da,
240 const char *buf, size_t count)
241{
242 int nr = to_sensor_dev_attr(da)->index;
243 struct i2c_client *client = to_i2c_client(dev);
244 struct emc2103_data *data = i2c_get_clientdata(client);
245 long val;
246
247 int result = strict_strtol(buf, 10, &val);
248 if (result < 0)
249 return -EINVAL;
250
251 val = DIV_ROUND_CLOSEST(val, 1000);
252 if ((val < -63) || (val > 127))
253 return -EINVAL;
254
255 mutex_lock(&data->update_lock);
256 data->temp_min[nr] = val;
257 i2c_smbus_write_byte_data(client, REG_TEMP_MIN[nr], val);
258 mutex_unlock(&data->update_lock);
259
260 return count;
261}
262
263static ssize_t set_temp_max(struct device *dev, struct device_attribute *da,
264 const char *buf, size_t count)
265{
266 int nr = to_sensor_dev_attr(da)->index;
267 struct i2c_client *client = to_i2c_client(dev);
268 struct emc2103_data *data = i2c_get_clientdata(client);
269 long val;
270
271 int result = strict_strtol(buf, 10, &val);
272 if (result < 0)
273 return -EINVAL;
274
275 val = DIV_ROUND_CLOSEST(val, 1000);
276 if ((val < -63) || (val > 127))
277 return -EINVAL;
278
279 mutex_lock(&data->update_lock);
280 data->temp_max[nr] = val;
281 i2c_smbus_write_byte_data(client, REG_TEMP_MAX[nr], val);
282 mutex_unlock(&data->update_lock);
283
284 return count;
285}
286
287static ssize_t
288show_fan(struct device *dev, struct device_attribute *da, char *buf)
289{
290 struct emc2103_data *data = emc2103_update_device(dev);
291 int rpm = 0;
292 if (data->fan_tach != 0)
293 rpm = (FAN_RPM_FACTOR * data->fan_multiplier) / data->fan_tach;
294 return sprintf(buf, "%d\n", rpm);
295}
296
297static ssize_t
298show_fan_div(struct device *dev, struct device_attribute *da, char *buf)
299{
300 struct emc2103_data *data = emc2103_update_device(dev);
301 int fan_div = 8 / data->fan_multiplier;
302 return sprintf(buf, "%d\n", fan_div);
303}
304
305/* Note: we also update the fan target here, because its value is
306 determined in part by the fan clock divider. This follows the principle
307 of least surprise; the user doesn't expect the fan target to change just
308 because the divider changed. */
309static ssize_t set_fan_div(struct device *dev, struct device_attribute *da,
310 const char *buf, size_t count)
311{
312 struct emc2103_data *data = emc2103_update_device(dev);
313 struct i2c_client *client = to_i2c_client(dev);
314 int new_range_bits, old_div = 8 / data->fan_multiplier;
315 long new_div;
316
317 int status = strict_strtol(buf, 10, &new_div);
318 if (status < 0)
319 return -EINVAL;
320
321 if (new_div == old_div) /* No change */
322 return count;
323
324 switch (new_div) {
325 case 1:
326 new_range_bits = 3;
327 break;
328 case 2:
329 new_range_bits = 2;
330 break;
331 case 4:
332 new_range_bits = 1;
333 break;
334 case 8:
335 new_range_bits = 0;
336 break;
337 default:
338 return -EINVAL;
339 }
340
341 mutex_lock(&data->update_lock);
342
343 status = i2c_smbus_read_byte_data(client, REG_FAN_CONF1);
344 if (status < 0) {
345 dev_dbg(&client->dev, "reg 0x%02x, err %d\n",
346 REG_FAN_CONF1, status);
347 mutex_unlock(&data->update_lock);
348 return -EIO;
349 }
350 status &= 0x9F;
351 status |= (new_range_bits << 5);
352 i2c_smbus_write_byte_data(client, REG_FAN_CONF1, status);
353
354 data->fan_multiplier = 8 / new_div;
355
356 /* update fan target if high byte is not disabled */
357 if ((data->fan_target & 0x1fe0) != 0x1fe0) {
358 u16 new_target = (data->fan_target * old_div) / new_div;
359 data->fan_target = min(new_target, (u16)0x1fff);
360 write_fan_target_to_i2c(client, data->fan_target);
361 }
362
363 /* invalidate data to force re-read from hardware */
364 data->valid = false;
365
366 mutex_unlock(&data->update_lock);
367 return count;
368}
369
370static ssize_t
371show_fan_target(struct device *dev, struct device_attribute *da, char *buf)
372{
373 struct emc2103_data *data = emc2103_update_device(dev);
374 int rpm = 0;
375
376 /* high byte of 0xff indicates disabled so return 0 */
377 if ((data->fan_target != 0) && ((data->fan_target & 0x1fe0) != 0x1fe0))
378 rpm = (FAN_RPM_FACTOR * data->fan_multiplier)
379 / data->fan_target;
380
381 return sprintf(buf, "%d\n", rpm);
382}
383
384static ssize_t set_fan_target(struct device *dev, struct device_attribute *da,
385 const char *buf, size_t count)
386{
387 struct emc2103_data *data = emc2103_update_device(dev);
388 struct i2c_client *client = to_i2c_client(dev);
389 long rpm_target;
390
391 int result = strict_strtol(buf, 10, &rpm_target);
392 if (result < 0)
393 return -EINVAL;
394
395 /* Datasheet states 16384 as maximum RPM target (table 3.2) */
396 if ((rpm_target < 0) || (rpm_target > 16384))
397 return -EINVAL;
398
399 mutex_lock(&data->update_lock);
400
401 if (rpm_target == 0)
402 data->fan_target = 0x1fff;
403 else
404 data->fan_target = SENSORS_LIMIT(
405 (FAN_RPM_FACTOR * data->fan_multiplier) / rpm_target,
406 0, 0x1fff);
407
408 write_fan_target_to_i2c(client, data->fan_target);
409
410 mutex_unlock(&data->update_lock);
411 return count;
412}
413
414static ssize_t
415show_fan_fault(struct device *dev, struct device_attribute *da, char *buf)
416{
417 struct emc2103_data *data = emc2103_update_device(dev);
418 bool fault = ((data->fan_tach & 0x1fe0) == 0x1fe0);
419 return sprintf(buf, "%d\n", fault ? 1 : 0);
420}
421
422static ssize_t
423show_pwm_enable(struct device *dev, struct device_attribute *da, char *buf)
424{
425 struct emc2103_data *data = emc2103_update_device(dev);
426 return sprintf(buf, "%d\n", data->fan_rpm_control ? 3 : 0);
427}
428
429static ssize_t set_pwm_enable(struct device *dev, struct device_attribute *da,
430 const char *buf, size_t count)
431{
432 struct i2c_client *client = to_i2c_client(dev);
433 struct emc2103_data *data = i2c_get_clientdata(client);
434 long new_value;
435 u8 conf_reg;
436
437 int result = strict_strtol(buf, 10, &new_value);
438 if (result < 0)
439 return -EINVAL;
440
441 mutex_lock(&data->update_lock);
442 switch (new_value) {
443 case 0:
444 data->fan_rpm_control = false;
445 break;
446 case 3:
447 data->fan_rpm_control = true;
448 break;
449 default:
450 mutex_unlock(&data->update_lock);
451 return -EINVAL;
452 }
453
454 read_u8_from_i2c(client, REG_FAN_CONF1, &conf_reg);
455
456 if (data->fan_rpm_control)
457 conf_reg |= 0x80;
458 else
459 conf_reg &= ~0x80;
460
461 i2c_smbus_write_byte_data(client, REG_FAN_CONF1, conf_reg);
462
463 mutex_unlock(&data->update_lock);
464 return count;
465}
466
467static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
468static SENSOR_DEVICE_ATTR(temp1_min, S_IRUGO | S_IWUSR, show_temp_min,
469 set_temp_min, 0);
470static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO | S_IWUSR, show_temp_max,
471 set_temp_max, 0);
472static SENSOR_DEVICE_ATTR(temp1_fault, S_IRUGO, show_temp_fault, NULL, 0);
473static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_temp_min_alarm,
474 NULL, 0);
475static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_temp_max_alarm,
476 NULL, 0);
477
478static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1);
479static SENSOR_DEVICE_ATTR(temp2_min, S_IRUGO | S_IWUSR, show_temp_min,
480 set_temp_min, 1);
481static SENSOR_DEVICE_ATTR(temp2_max, S_IRUGO | S_IWUSR, show_temp_max,
482 set_temp_max, 1);
483static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_temp_fault, NULL, 1);
484static SENSOR_DEVICE_ATTR(temp2_min_alarm, S_IRUGO, show_temp_min_alarm,
485 NULL, 1);
486static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_temp_max_alarm,
487 NULL, 1);
488
489static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2);
490static SENSOR_DEVICE_ATTR(temp3_min, S_IRUGO | S_IWUSR, show_temp_min,
491 set_temp_min, 2);
492static SENSOR_DEVICE_ATTR(temp3_max, S_IRUGO | S_IWUSR, show_temp_max,
493 set_temp_max, 2);
494static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_temp_fault, NULL, 2);
495static SENSOR_DEVICE_ATTR(temp3_min_alarm, S_IRUGO, show_temp_min_alarm,
496 NULL, 2);
497static SENSOR_DEVICE_ATTR(temp3_max_alarm, S_IRUGO, show_temp_max_alarm,
498 NULL, 2);
499
500static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, show_temp, NULL, 3);
501static SENSOR_DEVICE_ATTR(temp4_min, S_IRUGO | S_IWUSR, show_temp_min,
502 set_temp_min, 3);
503static SENSOR_DEVICE_ATTR(temp4_max, S_IRUGO | S_IWUSR, show_temp_max,
504 set_temp_max, 3);
505static SENSOR_DEVICE_ATTR(temp4_fault, S_IRUGO, show_temp_fault, NULL, 3);
506static SENSOR_DEVICE_ATTR(temp4_min_alarm, S_IRUGO, show_temp_min_alarm,
507 NULL, 3);
508static SENSOR_DEVICE_ATTR(temp4_max_alarm, S_IRUGO, show_temp_max_alarm,
509 NULL, 3);
510
511static DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL);
512static DEVICE_ATTR(fan1_div, S_IRUGO | S_IWUSR, show_fan_div, set_fan_div);
513static DEVICE_ATTR(fan1_target, S_IRUGO | S_IWUSR, show_fan_target,
514 set_fan_target);
515static DEVICE_ATTR(fan1_fault, S_IRUGO, show_fan_fault, NULL);
516
517static DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, show_pwm_enable,
518 set_pwm_enable);
519
520/* sensors present on all models */
521static struct attribute *emc2103_attributes[] = {
522 &sensor_dev_attr_temp1_input.dev_attr.attr,
523 &sensor_dev_attr_temp1_min.dev_attr.attr,
524 &sensor_dev_attr_temp1_max.dev_attr.attr,
525 &sensor_dev_attr_temp1_fault.dev_attr.attr,
526 &sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
527 &sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
528 &sensor_dev_attr_temp2_input.dev_attr.attr,
529 &sensor_dev_attr_temp2_min.dev_attr.attr,
530 &sensor_dev_attr_temp2_max.dev_attr.attr,
531 &sensor_dev_attr_temp2_fault.dev_attr.attr,
532 &sensor_dev_attr_temp2_min_alarm.dev_attr.attr,
533 &sensor_dev_attr_temp2_max_alarm.dev_attr.attr,
534 &dev_attr_fan1_input.attr,
535 &dev_attr_fan1_div.attr,
536 &dev_attr_fan1_target.attr,
537 &dev_attr_fan1_fault.attr,
538 &dev_attr_pwm1_enable.attr,
539 NULL
540};
541
542/* extra temperature sensors only present on 2103-2 and 2103-4 */
543static struct attribute *emc2103_attributes_temp3[] = {
544 &sensor_dev_attr_temp3_input.dev_attr.attr,
545 &sensor_dev_attr_temp3_min.dev_attr.attr,
546 &sensor_dev_attr_temp3_max.dev_attr.attr,
547 &sensor_dev_attr_temp3_fault.dev_attr.attr,
548 &sensor_dev_attr_temp3_min_alarm.dev_attr.attr,
549 &sensor_dev_attr_temp3_max_alarm.dev_attr.attr,
550 NULL
551};
552
553/* extra temperature sensors only present on 2103-2 and 2103-4 in APD mode */
554static struct attribute *emc2103_attributes_temp4[] = {
555 &sensor_dev_attr_temp4_input.dev_attr.attr,
556 &sensor_dev_attr_temp4_min.dev_attr.attr,
557 &sensor_dev_attr_temp4_max.dev_attr.attr,
558 &sensor_dev_attr_temp4_fault.dev_attr.attr,
559 &sensor_dev_attr_temp4_min_alarm.dev_attr.attr,
560 &sensor_dev_attr_temp4_max_alarm.dev_attr.attr,
561 NULL
562};
563
564static const struct attribute_group emc2103_group = {
565 .attrs = emc2103_attributes,
566};
567
568static const struct attribute_group emc2103_temp3_group = {
569 .attrs = emc2103_attributes_temp3,
570};
571
572static const struct attribute_group emc2103_temp4_group = {
573 .attrs = emc2103_attributes_temp4,
574};
575
576static int
577emc2103_probe(struct i2c_client *client, const struct i2c_device_id *id)
578{
579 struct emc2103_data *data;
580 int status;
581
582 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
583 return -EIO;
584
585 data = kzalloc(sizeof(struct emc2103_data), GFP_KERNEL);
586 if (!data)
587 return -ENOMEM;
588
589 i2c_set_clientdata(client, data);
590 mutex_init(&data->update_lock);
591
592 /* 2103-2 and 2103-4 have 3 external diodes, 2103-1 has 1 */
593 status = i2c_smbus_read_byte_data(client, REG_PRODUCT_ID);
594 if (status == 0x24) {
595 /* 2103-1 only has 1 external diode */
596 data->temp_count = 2;
597 } else {
598 /* 2103-2 and 2103-4 have 3 or 4 external diodes */
599 status = i2c_smbus_read_byte_data(client, REG_CONF1);
600 if (status < 0) {
601 dev_dbg(&client->dev, "reg 0x%02x, err %d\n", REG_CONF1,
602 status);
603 goto exit_free;
604 }
605
606 /* detect current state of hardware */
607 data->temp_count = (status & 0x01) ? 4 : 3;
608
609 /* force APD state if module parameter is set */
610 if (apd == 0) {
611 /* force APD mode off */
612 data->temp_count = 3;
613 status &= ~(0x01);
614 i2c_smbus_write_byte_data(client, REG_CONF1, status);
615 } else if (apd == 1) {
616 /* force APD mode on */
617 data->temp_count = 4;
618 status |= 0x01;
619 i2c_smbus_write_byte_data(client, REG_CONF1, status);
620 }
621 }
622
623 /* Register sysfs hooks */
624 status = sysfs_create_group(&client->dev.kobj, &emc2103_group);
625 if (status)
626 goto exit_free;
627
628 if (data->temp_count >= 3) {
629 status = sysfs_create_group(&client->dev.kobj,
630 &emc2103_temp3_group);
631 if (status)
632 goto exit_remove;
633 }
634
635 if (data->temp_count == 4) {
636 status = sysfs_create_group(&client->dev.kobj,
637 &emc2103_temp4_group);
638 if (status)
639 goto exit_remove_temp3;
640 }
641
642 data->hwmon_dev = hwmon_device_register(&client->dev);
643 if (IS_ERR(data->hwmon_dev)) {
644 status = PTR_ERR(data->hwmon_dev);
645 goto exit_remove_temp4;
646 }
647
648 dev_info(&client->dev, "%s: sensor '%s'\n",
649 dev_name(data->hwmon_dev), client->name);
650
651 return 0;
652
653exit_remove_temp4:
654 if (data->temp_count == 4)
655 sysfs_remove_group(&client->dev.kobj, &emc2103_temp4_group);
656exit_remove_temp3:
657 if (data->temp_count >= 3)
658 sysfs_remove_group(&client->dev.kobj, &emc2103_temp3_group);
659exit_remove:
660 sysfs_remove_group(&client->dev.kobj, &emc2103_group);
661exit_free:
662 kfree(data);
663 return status;
664}
665
666static int emc2103_remove(struct i2c_client *client)
667{
668 struct emc2103_data *data = i2c_get_clientdata(client);
669
670 hwmon_device_unregister(data->hwmon_dev);
671
672 if (data->temp_count == 4)
673 sysfs_remove_group(&client->dev.kobj, &emc2103_temp4_group);
674
675 if (data->temp_count >= 3)
676 sysfs_remove_group(&client->dev.kobj, &emc2103_temp3_group);
677
678 sysfs_remove_group(&client->dev.kobj, &emc2103_group);
679
680 kfree(data);
681 return 0;
682}
683
684static const struct i2c_device_id emc2103_ids[] = {
685 { "emc2103", 0, },
686 { /* LIST END */ }
687};
688MODULE_DEVICE_TABLE(i2c, emc2103_ids);
689
690/* Return 0 if detection is successful, -ENODEV otherwise */
691static int
692emc2103_detect(struct i2c_client *new_client, struct i2c_board_info *info)
693{
694 struct i2c_adapter *adapter = new_client->adapter;
695 int manufacturer, product;
696
697 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
698 return -ENODEV;
699
700 manufacturer = i2c_smbus_read_byte_data(new_client, REG_MFG_ID);
701 if (manufacturer != 0x5D)
702 return -ENODEV;
703
704 product = i2c_smbus_read_byte_data(new_client, REG_PRODUCT_ID);
705 if ((product != 0x24) && (product != 0x26))
706 return -ENODEV;
707
708 strlcpy(info->type, "emc2103", I2C_NAME_SIZE);
709
710 return 0;
711}
712
713static struct i2c_driver emc2103_driver = {
714 .class = I2C_CLASS_HWMON,
715 .driver = {
716 .name = "emc2103",
717 },
718 .probe = emc2103_probe,
719 .remove = emc2103_remove,
720 .id_table = emc2103_ids,
721 .detect = emc2103_detect,
722 .address_list = normal_i2c,
723};
724
725static int __init sensors_emc2103_init(void)
726{
727 return i2c_add_driver(&emc2103_driver);
728}
729
730static void __exit sensors_emc2103_exit(void)
731{
732 i2c_del_driver(&emc2103_driver);
733}
734
735MODULE_AUTHOR("Steve Glendinning <steve.glendinning@smsc.com>");
736MODULE_DESCRIPTION("SMSC EMC2103 hwmon driver");
737MODULE_LICENSE("GPL");
738
739module_init(sensors_emc2103_init);
740module_exit(sensors_emc2103_exit);
diff --git a/drivers/hwmon/f71882fg.c b/drivers/hwmon/f71882fg.c
index 537841ef44b9..6207120dcd4d 100644
--- a/drivers/hwmon/f71882fg.c
+++ b/drivers/hwmon/f71882fg.c
@@ -45,6 +45,7 @@
45#define SIO_REG_ADDR 0x60 /* Logical device address (2 bytes) */ 45#define SIO_REG_ADDR 0x60 /* Logical device address (2 bytes) */
46 46
47#define SIO_FINTEK_ID 0x1934 /* Manufacturers ID */ 47#define SIO_FINTEK_ID 0x1934 /* Manufacturers ID */
48#define SIO_F71808_ID 0x0901 /* Chipset ID */
48#define SIO_F71858_ID 0x0507 /* Chipset ID */ 49#define SIO_F71858_ID 0x0507 /* Chipset ID */
49#define SIO_F71862_ID 0x0601 /* Chipset ID */ 50#define SIO_F71862_ID 0x0601 /* Chipset ID */
50#define SIO_F71882_ID 0x0541 /* Chipset ID */ 51#define SIO_F71882_ID 0x0541 /* Chipset ID */
@@ -96,9 +97,10 @@ static unsigned short force_id;
96module_param(force_id, ushort, 0); 97module_param(force_id, ushort, 0);
97MODULE_PARM_DESC(force_id, "Override the detected device ID"); 98MODULE_PARM_DESC(force_id, "Override the detected device ID");
98 99
99enum chips { f71858fg, f71862fg, f71882fg, f71889fg, f8000 }; 100enum chips { f71808fg, f71858fg, f71862fg, f71882fg, f71889fg, f8000 };
100 101
101static const char *f71882fg_names[] = { 102static const char *f71882fg_names[] = {
103 "f71808fg",
102 "f71858fg", 104 "f71858fg",
103 "f71862fg", 105 "f71862fg",
104 "f71882fg", 106 "f71882fg",
@@ -306,8 +308,8 @@ static struct sensor_device_attribute_2 f71858fg_in_temp_attr[] = {
306 SENSOR_ATTR_2(temp3_fault, S_IRUGO, show_temp_fault, NULL, 0, 2), 308 SENSOR_ATTR_2(temp3_fault, S_IRUGO, show_temp_fault, NULL, 0, 2),
307}; 309};
308 310
309/* Temp and in attr common to the f71862fg, f71882fg and f71889fg */ 311/* In attr common to the f71862fg, f71882fg and f71889fg */
310static struct sensor_device_attribute_2 fxxxx_in_temp_attr[] = { 312static struct sensor_device_attribute_2 fxxxx_in_attr[] = {
311 SENSOR_ATTR_2(in0_input, S_IRUGO, show_in, NULL, 0, 0), 313 SENSOR_ATTR_2(in0_input, S_IRUGO, show_in, NULL, 0, 0),
312 SENSOR_ATTR_2(in1_input, S_IRUGO, show_in, NULL, 0, 1), 314 SENSOR_ATTR_2(in1_input, S_IRUGO, show_in, NULL, 0, 1),
313 SENSOR_ATTR_2(in2_input, S_IRUGO, show_in, NULL, 0, 2), 315 SENSOR_ATTR_2(in2_input, S_IRUGO, show_in, NULL, 0, 2),
@@ -317,6 +319,22 @@ static struct sensor_device_attribute_2 fxxxx_in_temp_attr[] = {
317 SENSOR_ATTR_2(in6_input, S_IRUGO, show_in, NULL, 0, 6), 319 SENSOR_ATTR_2(in6_input, S_IRUGO, show_in, NULL, 0, 6),
318 SENSOR_ATTR_2(in7_input, S_IRUGO, show_in, NULL, 0, 7), 320 SENSOR_ATTR_2(in7_input, S_IRUGO, show_in, NULL, 0, 7),
319 SENSOR_ATTR_2(in8_input, S_IRUGO, show_in, NULL, 0, 8), 321 SENSOR_ATTR_2(in8_input, S_IRUGO, show_in, NULL, 0, 8),
322};
323
324/* In attr for the f71808fg */
325static struct sensor_device_attribute_2 f71808_in_attr[] = {
326 SENSOR_ATTR_2(in0_input, S_IRUGO, show_in, NULL, 0, 0),
327 SENSOR_ATTR_2(in1_input, S_IRUGO, show_in, NULL, 0, 1),
328 SENSOR_ATTR_2(in2_input, S_IRUGO, show_in, NULL, 0, 2),
329 SENSOR_ATTR_2(in3_input, S_IRUGO, show_in, NULL, 0, 3),
330 SENSOR_ATTR_2(in4_input, S_IRUGO, show_in, NULL, 0, 4),
331 SENSOR_ATTR_2(in5_input, S_IRUGO, show_in, NULL, 0, 5),
332 SENSOR_ATTR_2(in6_input, S_IRUGO, show_in, NULL, 0, 7),
333 SENSOR_ATTR_2(in7_input, S_IRUGO, show_in, NULL, 0, 8),
334};
335
336/* Temp attr common to the f71808fg, f71862fg, f71882fg and f71889fg */
337static struct sensor_device_attribute_2 fxxxx_temp_attr[] = {
320 SENSOR_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 1), 338 SENSOR_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 1),
321 SENSOR_ATTR_2(temp1_max, S_IRUGO|S_IWUSR, show_temp_max, 339 SENSOR_ATTR_2(temp1_max, S_IRUGO|S_IWUSR, show_temp_max,
322 store_temp_max, 0, 1), 340 store_temp_max, 0, 1),
@@ -355,6 +373,10 @@ static struct sensor_device_attribute_2 fxxxx_in_temp_attr[] = {
355 store_temp_beep, 0, 6), 373 store_temp_beep, 0, 6),
356 SENSOR_ATTR_2(temp2_type, S_IRUGO, show_temp_type, NULL, 0, 2), 374 SENSOR_ATTR_2(temp2_type, S_IRUGO, show_temp_type, NULL, 0, 2),
357 SENSOR_ATTR_2(temp2_fault, S_IRUGO, show_temp_fault, NULL, 0, 2), 375 SENSOR_ATTR_2(temp2_fault, S_IRUGO, show_temp_fault, NULL, 0, 2),
376};
377
378/* Temp and in attr common to the f71862fg, f71882fg and f71889fg */
379static struct sensor_device_attribute_2 f71862_temp_attr[] = {
358 SENSOR_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 0, 3), 380 SENSOR_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 0, 3),
359 SENSOR_ATTR_2(temp3_max, S_IRUGO|S_IWUSR, show_temp_max, 381 SENSOR_ATTR_2(temp3_max, S_IRUGO|S_IWUSR, show_temp_max,
360 store_temp_max, 0, 3), 382 store_temp_max, 0, 3),
@@ -989,6 +1011,11 @@ static struct f71882fg_data *f71882fg_update_device(struct device *dev)
989 data->temp_type[1] = 6; 1011 data->temp_type[1] = 6;
990 break; 1012 break;
991 } 1013 }
1014 } else if (data->type == f71808fg) {
1015 reg = f71882fg_read8(data, F71882FG_REG_TEMP_TYPE);
1016 data->temp_type[1] = (reg & 0x02) ? 2 : 4;
1017 data->temp_type[2] = (reg & 0x04) ? 2 : 4;
1018
992 } else { 1019 } else {
993 reg2 = f71882fg_read8(data, F71882FG_REG_PECI); 1020 reg2 = f71882fg_read8(data, F71882FG_REG_PECI);
994 if ((reg2 & 0x03) == 0x01) 1021 if ((reg2 & 0x03) == 0x01)
@@ -1871,7 +1898,8 @@ static ssize_t store_pwm_auto_point_temp(struct device *dev,
1871 1898
1872 val /= 1000; 1899 val /= 1000;
1873 1900
1874 if (data->type == f71889fg) 1901 if (data->type == f71889fg
1902 || data->type == f71808fg)
1875 val = SENSORS_LIMIT(val, -128, 127); 1903 val = SENSORS_LIMIT(val, -128, 127);
1876 else 1904 else
1877 val = SENSORS_LIMIT(val, 0, 127); 1905 val = SENSORS_LIMIT(val, 0, 127);
@@ -1974,8 +2002,28 @@ static int __devinit f71882fg_probe(struct platform_device *pdev)
1974 /* fall through! */ 2002 /* fall through! */
1975 case f71862fg: 2003 case f71862fg:
1976 err = f71882fg_create_sysfs_files(pdev, 2004 err = f71882fg_create_sysfs_files(pdev,
1977 fxxxx_in_temp_attr, 2005 f71862_temp_attr,
1978 ARRAY_SIZE(fxxxx_in_temp_attr)); 2006 ARRAY_SIZE(f71862_temp_attr));
2007 if (err)
2008 goto exit_unregister_sysfs;
2009 err = f71882fg_create_sysfs_files(pdev,
2010 fxxxx_in_attr,
2011 ARRAY_SIZE(fxxxx_in_attr));
2012 if (err)
2013 goto exit_unregister_sysfs;
2014 err = f71882fg_create_sysfs_files(pdev,
2015 fxxxx_temp_attr,
2016 ARRAY_SIZE(fxxxx_temp_attr));
2017 break;
2018 case f71808fg:
2019 err = f71882fg_create_sysfs_files(pdev,
2020 f71808_in_attr,
2021 ARRAY_SIZE(f71808_in_attr));
2022 if (err)
2023 goto exit_unregister_sysfs;
2024 err = f71882fg_create_sysfs_files(pdev,
2025 fxxxx_temp_attr,
2026 ARRAY_SIZE(fxxxx_temp_attr));
1979 break; 2027 break;
1980 case f8000: 2028 case f8000:
1981 err = f71882fg_create_sysfs_files(pdev, 2029 err = f71882fg_create_sysfs_files(pdev,
@@ -2002,6 +2050,7 @@ static int __devinit f71882fg_probe(struct platform_device *pdev)
2002 case f71862fg: 2050 case f71862fg:
2003 err = (data->pwm_enable & 0x15) != 0x15; 2051 err = (data->pwm_enable & 0x15) != 0x15;
2004 break; 2052 break;
2053 case f71808fg:
2005 case f71882fg: 2054 case f71882fg:
2006 case f71889fg: 2055 case f71889fg:
2007 err = 0; 2056 err = 0;
@@ -2047,6 +2096,7 @@ static int __devinit f71882fg_probe(struct platform_device *pdev)
2047 f8000_auto_pwm_attr, 2096 f8000_auto_pwm_attr,
2048 ARRAY_SIZE(f8000_auto_pwm_attr)); 2097 ARRAY_SIZE(f8000_auto_pwm_attr));
2049 break; 2098 break;
2099 case f71808fg:
2050 case f71889fg: 2100 case f71889fg:
2051 for (i = 0; i < nr_fans; i++) { 2101 for (i = 0; i < nr_fans; i++) {
2052 data->pwm_auto_point_mapping[i] = 2102 data->pwm_auto_point_mapping[i] =
@@ -2126,8 +2176,22 @@ static int f71882fg_remove(struct platform_device *pdev)
2126 /* fall through! */ 2176 /* fall through! */
2127 case f71862fg: 2177 case f71862fg:
2128 f71882fg_remove_sysfs_files(pdev, 2178 f71882fg_remove_sysfs_files(pdev,
2129 fxxxx_in_temp_attr, 2179 f71862_temp_attr,
2130 ARRAY_SIZE(fxxxx_in_temp_attr)); 2180 ARRAY_SIZE(f71862_temp_attr));
2181 f71882fg_remove_sysfs_files(pdev,
2182 fxxxx_in_attr,
2183 ARRAY_SIZE(fxxxx_in_attr));
2184 f71882fg_remove_sysfs_files(pdev,
2185 fxxxx_temp_attr,
2186 ARRAY_SIZE(fxxxx_temp_attr));
2187 break;
2188 case f71808fg:
2189 f71882fg_remove_sysfs_files(pdev,
2190 f71808_in_attr,
2191 ARRAY_SIZE(f71808_in_attr));
2192 f71882fg_remove_sysfs_files(pdev,
2193 fxxxx_temp_attr,
2194 ARRAY_SIZE(fxxxx_temp_attr));
2131 break; 2195 break;
2132 case f8000: 2196 case f8000:
2133 f71882fg_remove_sysfs_files(pdev, 2197 f71882fg_remove_sysfs_files(pdev,
@@ -2195,6 +2259,9 @@ static int __init f71882fg_find(int sioaddr, unsigned short *address,
2195 2259
2196 devid = force_id ? force_id : superio_inw(sioaddr, SIO_REG_DEVID); 2260 devid = force_id ? force_id : superio_inw(sioaddr, SIO_REG_DEVID);
2197 switch (devid) { 2261 switch (devid) {
2262 case SIO_F71808_ID:
2263 sio_data->type = f71808fg;
2264 break;
2198 case SIO_F71858_ID: 2265 case SIO_F71858_ID:
2199 sio_data->type = f71858fg; 2266 sio_data->type = f71858fg;
2200 break; 2267 break;
diff --git a/drivers/hwmon/hdaps.c b/drivers/hwmon/hdaps.c
index be2d131e405c..bfd42f18924b 100644
--- a/drivers/hwmon/hdaps.c
+++ b/drivers/hwmon/hdaps.c
@@ -522,6 +522,7 @@ static struct dmi_system_id __initdata hdaps_whitelist[] = {
522 HDAPS_DMI_MATCH_INVERT("IBM", "ThinkPad T42p", HDAPS_BOTH_AXES), 522 HDAPS_DMI_MATCH_INVERT("IBM", "ThinkPad T42p", HDAPS_BOTH_AXES),
523 HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad T42"), 523 HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad T42"),
524 HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad T43"), 524 HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad T43"),
525 HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad T400", HDAPS_BOTH_AXES),
525 HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad T60", HDAPS_BOTH_AXES), 526 HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad T60", HDAPS_BOTH_AXES),
526 HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad T61p", HDAPS_BOTH_AXES), 527 HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad T61p", HDAPS_BOTH_AXES),
527 HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad T61", HDAPS_BOTH_AXES), 528 HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad T61", HDAPS_BOTH_AXES),
diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c
index 25763d2223b6..f7701295937d 100644
--- a/drivers/hwmon/it87.c
+++ b/drivers/hwmon/it87.c
@@ -259,6 +259,7 @@ struct it87_sio_data {
259 u8 revision; 259 u8 revision;
260 u8 vid_value; 260 u8 vid_value;
261 u8 beep_pin; 261 u8 beep_pin;
262 u8 internal; /* Internal sensors can be labeled */
262 /* Features skipped based on config or DMI */ 263 /* Features skipped based on config or DMI */
263 u8 skip_vid; 264 u8 skip_vid;
264 u8 skip_fan; 265 u8 skip_fan;
@@ -1194,6 +1195,22 @@ static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr,
1194} 1195}
1195static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL); 1196static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
1196 1197
1198static ssize_t show_label(struct device *dev, struct device_attribute *attr,
1199 char *buf)
1200{
1201 static const char *labels[] = {
1202 "+5V",
1203 "5VSB",
1204 "Vbat",
1205 };
1206 int nr = to_sensor_dev_attr(attr)->index;
1207
1208 return sprintf(buf, "%s\n", labels[nr]);
1209}
1210static SENSOR_DEVICE_ATTR(in3_label, S_IRUGO, show_label, NULL, 0);
1211static SENSOR_DEVICE_ATTR(in7_label, S_IRUGO, show_label, NULL, 1);
1212static SENSOR_DEVICE_ATTR(in8_label, S_IRUGO, show_label, NULL, 2);
1213
1197static ssize_t show_name(struct device *dev, struct device_attribute 1214static ssize_t show_name(struct device *dev, struct device_attribute
1198 *devattr, char *buf) 1215 *devattr, char *buf)
1199{ 1216{
@@ -1434,6 +1451,17 @@ static const struct attribute_group it87_group_vid = {
1434 .attrs = it87_attributes_vid, 1451 .attrs = it87_attributes_vid,
1435}; 1452};
1436 1453
1454static struct attribute *it87_attributes_label[] = {
1455 &sensor_dev_attr_in3_label.dev_attr.attr,
1456 &sensor_dev_attr_in7_label.dev_attr.attr,
1457 &sensor_dev_attr_in8_label.dev_attr.attr,
1458 NULL
1459};
1460
1461static const struct attribute_group it87_group_label = {
1462 .attrs = it87_attributes_vid,
1463};
1464
1437/* SuperIO detection - will change isa_address if a chip is found */ 1465/* SuperIO detection - will change isa_address if a chip is found */
1438static int __init it87_find(unsigned short *address, 1466static int __init it87_find(unsigned short *address,
1439 struct it87_sio_data *sio_data) 1467 struct it87_sio_data *sio_data)
@@ -1487,6 +1515,9 @@ static int __init it87_find(unsigned short *address,
1487 pr_info("it87: Found IT%04xF chip at 0x%x, revision %d\n", 1515 pr_info("it87: Found IT%04xF chip at 0x%x, revision %d\n",
1488 chip_type, *address, sio_data->revision); 1516 chip_type, *address, sio_data->revision);
1489 1517
1518 /* in8 (Vbat) is always internal */
1519 sio_data->internal = (1 << 2);
1520
1490 /* Read GPIO config and VID value from LDN 7 (GPIO) */ 1521 /* Read GPIO config and VID value from LDN 7 (GPIO) */
1491 if (sio_data->type == it87) { 1522 if (sio_data->type == it87) {
1492 /* The IT8705F doesn't have VID pins at all */ 1523 /* The IT8705F doesn't have VID pins at all */
@@ -1540,9 +1571,9 @@ static int __init it87_find(unsigned short *address,
1540 pr_notice("it87: Routing internal VCCH to in7\n"); 1571 pr_notice("it87: Routing internal VCCH to in7\n");
1541 } 1572 }
1542 if (reg & (1 << 0)) 1573 if (reg & (1 << 0))
1543 pr_info("it87: in3 is VCC (+5V)\n"); 1574 sio_data->internal |= (1 << 0);
1544 if (reg & (1 << 1)) 1575 if (reg & (1 << 1))
1545 pr_info("it87: in7 is VCCH (+5V Stand-By)\n"); 1576 sio_data->internal |= (1 << 1);
1546 1577
1547 sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f; 1578 sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f;
1548 } 1579 }
@@ -1600,6 +1631,7 @@ static void it87_remove_files(struct device *dev)
1600 } 1631 }
1601 if (!sio_data->skip_vid) 1632 if (!sio_data->skip_vid)
1602 sysfs_remove_group(&dev->kobj, &it87_group_vid); 1633 sysfs_remove_group(&dev->kobj, &it87_group_vid);
1634 sysfs_remove_group(&dev->kobj, &it87_group_label);
1603} 1635}
1604 1636
1605static int __devinit it87_probe(struct platform_device *pdev) 1637static int __devinit it87_probe(struct platform_device *pdev)
@@ -1725,6 +1757,16 @@ static int __devinit it87_probe(struct platform_device *pdev)
1725 goto ERROR4; 1757 goto ERROR4;
1726 } 1758 }
1727 1759
1760 /* Export labels for internal sensors */
1761 for (i = 0; i < 3; i++) {
1762 if (!(sio_data->internal & (1 << i)))
1763 continue;
1764 err = sysfs_create_file(&dev->kobj,
1765 it87_attributes_label[i]);
1766 if (err)
1767 goto ERROR4;
1768 }
1769
1728 data->hwmon_dev = hwmon_device_register(dev); 1770 data->hwmon_dev = hwmon_device_register(dev);
1729 if (IS_ERR(data->hwmon_dev)) { 1771 if (IS_ERR(data->hwmon_dev)) {
1730 err = PTR_ERR(data->hwmon_dev); 1772 err = PTR_ERR(data->hwmon_dev);
diff --git a/drivers/hwmon/jc42.c b/drivers/hwmon/jc42.c
new file mode 100644
index 000000000000..340fc78c8dde
--- /dev/null
+++ b/drivers/hwmon/jc42.c
@@ -0,0 +1,593 @@
1/*
2 * jc42.c - driver for Jedec JC42.4 compliant temperature sensors
3 *
4 * Copyright (c) 2010 Ericsson AB.
5 *
6 * Derived from lm77.c by Andras BALI <drewie@freemail.hu>.
7 *
8 * JC42.4 compliant temperature sensors are typically used on memory modules.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */
24
25#include <linux/module.h>
26#include <linux/init.h>
27#include <linux/slab.h>
28#include <linux/jiffies.h>
29#include <linux/i2c.h>
30#include <linux/hwmon.h>
31#include <linux/hwmon-sysfs.h>
32#include <linux/err.h>
33#include <linux/mutex.h>
34
35/* Addresses to scan */
36static const unsigned short normal_i2c[] = {
37 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, I2C_CLIENT_END };
38
39/* JC42 registers. All registers are 16 bit. */
40#define JC42_REG_CAP 0x00
41#define JC42_REG_CONFIG 0x01
42#define JC42_REG_TEMP_UPPER 0x02
43#define JC42_REG_TEMP_LOWER 0x03
44#define JC42_REG_TEMP_CRITICAL 0x04
45#define JC42_REG_TEMP 0x05
46#define JC42_REG_MANID 0x06
47#define JC42_REG_DEVICEID 0x07
48
49/* Status bits in temperature register */
50#define JC42_ALARM_CRIT_BIT 15
51#define JC42_ALARM_MAX_BIT 14
52#define JC42_ALARM_MIN_BIT 13
53
54/* Configuration register defines */
55#define JC42_CFG_CRIT_ONLY (1 << 2)
56#define JC42_CFG_SHUTDOWN (1 << 8)
57#define JC42_CFG_HYST_SHIFT 9
58#define JC42_CFG_HYST_MASK 0x03
59
60/* Capabilities */
61#define JC42_CAP_RANGE (1 << 2)
62
63/* Manufacturer IDs */
64#define ADT_MANID 0x11d4 /* Analog Devices */
65#define MAX_MANID 0x004d /* Maxim */
66#define IDT_MANID 0x00b3 /* IDT */
67#define MCP_MANID 0x0054 /* Microchip */
68#define NXP_MANID 0x1131 /* NXP Semiconductors */
69#define ONS_MANID 0x1b09 /* ON Semiconductor */
70#define STM_MANID 0x104a /* ST Microelectronics */
71
72/* Supported chips */
73
74/* Analog Devices */
75#define ADT7408_DEVID 0x0801
76#define ADT7408_DEVID_MASK 0xffff
77
78/* IDT */
79#define TS3000B3_DEVID 0x2903 /* Also matches TSE2002B3 */
80#define TS3000B3_DEVID_MASK 0xffff
81
82/* Maxim */
83#define MAX6604_DEVID 0x3e00
84#define MAX6604_DEVID_MASK 0xffff
85
86/* Microchip */
87#define MCP98242_DEVID 0x2000
88#define MCP98242_DEVID_MASK 0xfffc
89
90#define MCP98243_DEVID 0x2100
91#define MCP98243_DEVID_MASK 0xfffc
92
93#define MCP9843_DEVID 0x0000 /* Also matches mcp9805 */
94#define MCP9843_DEVID_MASK 0xfffe
95
96/* NXP */
97#define SE97_DEVID 0xa200
98#define SE97_DEVID_MASK 0xfffc
99
100#define SE98_DEVID 0xa100
101#define SE98_DEVID_MASK 0xfffc
102
103/* ON Semiconductor */
104#define CAT6095_DEVID 0x0800 /* Also matches CAT34TS02 */
105#define CAT6095_DEVID_MASK 0xffe0
106
107/* ST Microelectronics */
108#define STTS424_DEVID 0x0101
109#define STTS424_DEVID_MASK 0xffff
110
111#define STTS424E_DEVID 0x0000
112#define STTS424E_DEVID_MASK 0xfffe
113
114static u16 jc42_hysteresis[] = { 0, 1500, 3000, 6000 };
115
116struct jc42_chips {
117 u16 manid;
118 u16 devid;
119 u16 devid_mask;
120};
121
122static struct jc42_chips jc42_chips[] = {
123 { ADT_MANID, ADT7408_DEVID, ADT7408_DEVID_MASK },
124 { IDT_MANID, TS3000B3_DEVID, TS3000B3_DEVID_MASK },
125 { MAX_MANID, MAX6604_DEVID, MAX6604_DEVID_MASK },
126 { MCP_MANID, MCP98242_DEVID, MCP98242_DEVID_MASK },
127 { MCP_MANID, MCP98243_DEVID, MCP98243_DEVID_MASK },
128 { MCP_MANID, MCP9843_DEVID, MCP9843_DEVID_MASK },
129 { NXP_MANID, SE97_DEVID, SE97_DEVID_MASK },
130 { ONS_MANID, CAT6095_DEVID, CAT6095_DEVID_MASK },
131 { NXP_MANID, SE98_DEVID, SE98_DEVID_MASK },
132 { STM_MANID, STTS424_DEVID, STTS424_DEVID_MASK },
133 { STM_MANID, STTS424E_DEVID, STTS424E_DEVID_MASK },
134};
135
136/* Each client has this additional data */
137struct jc42_data {
138 struct device *hwmon_dev;
139 struct mutex update_lock; /* protect register access */
140 bool extended; /* true if extended range supported */
141 bool valid;
142 unsigned long last_updated; /* In jiffies */
143 u16 orig_config; /* original configuration */
144 u16 config; /* current configuration */
145 u16 temp_input; /* Temperatures */
146 u16 temp_crit;
147 u16 temp_min;
148 u16 temp_max;
149};
150
151static int jc42_probe(struct i2c_client *client,
152 const struct i2c_device_id *id);
153static int jc42_detect(struct i2c_client *client, struct i2c_board_info *info);
154static int jc42_remove(struct i2c_client *client);
155static int jc42_read_value(struct i2c_client *client, u8 reg);
156static int jc42_write_value(struct i2c_client *client, u8 reg, u16 value);
157
158static struct jc42_data *jc42_update_device(struct device *dev);
159
160static const struct i2c_device_id jc42_id[] = {
161 { "adt7408", 0 },
162 { "cat94ts02", 0 },
163 { "cat6095", 0 },
164 { "jc42", 0 },
165 { "max6604", 0 },
166 { "mcp9805", 0 },
167 { "mcp98242", 0 },
168 { "mcp98243", 0 },
169 { "mcp9843", 0 },
170 { "se97", 0 },
171 { "se97b", 0 },
172 { "se98", 0 },
173 { "stts424", 0 },
174 { "tse2002b3", 0 },
175 { "ts3000b3", 0 },
176 { }
177};
178MODULE_DEVICE_TABLE(i2c, jc42_id);
179
180#ifdef CONFIG_PM
181
182static int jc42_suspend(struct device *dev)
183{
184 struct i2c_client *client = to_i2c_client(dev);
185 struct jc42_data *data = i2c_get_clientdata(client);
186
187 data->config |= JC42_CFG_SHUTDOWN;
188 jc42_write_value(client, JC42_REG_CONFIG, data->config);
189 return 0;
190}
191
192static int jc42_resume(struct device *dev)
193{
194 struct i2c_client *client = to_i2c_client(dev);
195 struct jc42_data *data = i2c_get_clientdata(client);
196
197 data->config &= ~JC42_CFG_SHUTDOWN;
198 jc42_write_value(client, JC42_REG_CONFIG, data->config);
199 return 0;
200}
201
202static const struct dev_pm_ops jc42_dev_pm_ops = {
203 .suspend = jc42_suspend,
204 .resume = jc42_resume,
205};
206
207#define JC42_DEV_PM_OPS (&jc42_dev_pm_ops)
208#else
209#define JC42_DEV_PM_OPS NULL
210#endif /* CONFIG_PM */
211
212/* This is the driver that will be inserted */
213static struct i2c_driver jc42_driver = {
214 .class = I2C_CLASS_HWMON,
215 .driver = {
216 .name = "jc42",
217 .pm = JC42_DEV_PM_OPS,
218 },
219 .probe = jc42_probe,
220 .remove = jc42_remove,
221 .id_table = jc42_id,
222 .detect = jc42_detect,
223 .address_list = normal_i2c,
224};
225
226#define JC42_TEMP_MIN_EXTENDED (-40000)
227#define JC42_TEMP_MIN 0
228#define JC42_TEMP_MAX 125000
229
230static u16 jc42_temp_to_reg(int temp, bool extended)
231{
232 int ntemp = SENSORS_LIMIT(temp,
233 extended ? JC42_TEMP_MIN_EXTENDED :
234 JC42_TEMP_MIN, JC42_TEMP_MAX);
235
236 /* convert from 0.001 to 0.0625 resolution */
237 return (ntemp * 2 / 125) & 0x1fff;
238}
239
240static int jc42_temp_from_reg(s16 reg)
241{
242 reg &= 0x1fff;
243
244 /* sign extend register */
245 if (reg & 0x1000)
246 reg |= 0xf000;
247
248 /* convert from 0.0625 to 0.001 resolution */
249 return reg * 125 / 2;
250}
251
252/* sysfs stuff */
253
254/* read routines for temperature limits */
255#define show(value) \
256static ssize_t show_##value(struct device *dev, \
257 struct device_attribute *attr, \
258 char *buf) \
259{ \
260 struct jc42_data *data = jc42_update_device(dev); \
261 if (IS_ERR(data)) \
262 return PTR_ERR(data); \
263 return sprintf(buf, "%d\n", jc42_temp_from_reg(data->value)); \
264}
265
266show(temp_input);
267show(temp_crit);
268show(temp_min);
269show(temp_max);
270
271/* read routines for hysteresis values */
272static ssize_t show_temp_crit_hyst(struct device *dev,
273 struct device_attribute *attr, char *buf)
274{
275 struct jc42_data *data = jc42_update_device(dev);
276 int temp, hyst;
277
278 if (IS_ERR(data))
279 return PTR_ERR(data);
280
281 temp = jc42_temp_from_reg(data->temp_crit);
282 hyst = jc42_hysteresis[(data->config >> JC42_CFG_HYST_SHIFT)
283 & JC42_CFG_HYST_MASK];
284 return sprintf(buf, "%d\n", temp - hyst);
285}
286
287static ssize_t show_temp_max_hyst(struct device *dev,
288 struct device_attribute *attr, char *buf)
289{
290 struct jc42_data *data = jc42_update_device(dev);
291 int temp, hyst;
292
293 if (IS_ERR(data))
294 return PTR_ERR(data);
295
296 temp = jc42_temp_from_reg(data->temp_max);
297 hyst = jc42_hysteresis[(data->config >> JC42_CFG_HYST_SHIFT)
298 & JC42_CFG_HYST_MASK];
299 return sprintf(buf, "%d\n", temp - hyst);
300}
301
302/* write routines */
303#define set(value, reg) \
304static ssize_t set_##value(struct device *dev, \
305 struct device_attribute *attr, \
306 const char *buf, size_t count) \
307{ \
308 struct i2c_client *client = to_i2c_client(dev); \
309 struct jc42_data *data = i2c_get_clientdata(client); \
310 int err, ret = count; \
311 long val; \
312 if (strict_strtol(buf, 10, &val) < 0) \
313 return -EINVAL; \
314 mutex_lock(&data->update_lock); \
315 data->value = jc42_temp_to_reg(val, data->extended); \
316 err = jc42_write_value(client, reg, data->value); \
317 if (err < 0) \
318 ret = err; \
319 mutex_unlock(&data->update_lock); \
320 return ret; \
321}
322
323set(temp_min, JC42_REG_TEMP_LOWER);
324set(temp_max, JC42_REG_TEMP_UPPER);
325set(temp_crit, JC42_REG_TEMP_CRITICAL);
326
327/* JC42.4 compliant chips only support four hysteresis values.
328 * Pick best choice and go from there. */
329static ssize_t set_temp_crit_hyst(struct device *dev,
330 struct device_attribute *attr,
331 const char *buf, size_t count)
332{
333 struct i2c_client *client = to_i2c_client(dev);
334 struct jc42_data *data = i2c_get_clientdata(client);
335 long val;
336 int diff, hyst;
337 int err;
338 int ret = count;
339
340 if (strict_strtoul(buf, 10, &val) < 0)
341 return -EINVAL;
342
343 diff = jc42_temp_from_reg(data->temp_crit) - val;
344 hyst = 0;
345 if (diff > 0) {
346 if (diff < 2250)
347 hyst = 1; /* 1.5 degrees C */
348 else if (diff < 4500)
349 hyst = 2; /* 3.0 degrees C */
350 else
351 hyst = 3; /* 6.0 degrees C */
352 }
353
354 mutex_lock(&data->update_lock);
355 data->config = (data->config
356 & ~(JC42_CFG_HYST_MASK << JC42_CFG_HYST_SHIFT))
357 | (hyst << JC42_CFG_HYST_SHIFT);
358 err = jc42_write_value(client, JC42_REG_CONFIG, data->config);
359 if (err < 0)
360 ret = err;
361 mutex_unlock(&data->update_lock);
362 return ret;
363}
364
365static ssize_t show_alarm(struct device *dev,
366 struct device_attribute *attr, char *buf)
367{
368 u16 bit = to_sensor_dev_attr(attr)->index;
369 struct jc42_data *data = jc42_update_device(dev);
370 u16 val;
371
372 if (IS_ERR(data))
373 return PTR_ERR(data);
374
375 val = data->temp_input;
376 if (bit != JC42_ALARM_CRIT_BIT && (data->config & JC42_CFG_CRIT_ONLY))
377 val = 0;
378 return sprintf(buf, "%u\n", (val >> bit) & 1);
379}
380
381static DEVICE_ATTR(temp1_input, S_IRUGO,
382 show_temp_input, NULL);
383static DEVICE_ATTR(temp1_crit, S_IWUSR | S_IRUGO,
384 show_temp_crit, set_temp_crit);
385static DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO,
386 show_temp_min, set_temp_min);
387static DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO,
388 show_temp_max, set_temp_max);
389
390static DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO,
391 show_temp_crit_hyst, set_temp_crit_hyst);
392static DEVICE_ATTR(temp1_max_hyst, S_IRUGO,
393 show_temp_max_hyst, NULL);
394
395static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL,
396 JC42_ALARM_CRIT_BIT);
397static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL,
398 JC42_ALARM_MIN_BIT);
399static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL,
400 JC42_ALARM_MAX_BIT);
401
402static struct attribute *jc42_attributes[] = {
403 &dev_attr_temp1_input.attr,
404 &dev_attr_temp1_crit.attr,
405 &dev_attr_temp1_min.attr,
406 &dev_attr_temp1_max.attr,
407 &dev_attr_temp1_crit_hyst.attr,
408 &dev_attr_temp1_max_hyst.attr,
409 &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr,
410 &sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
411 &sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
412 NULL
413};
414
415static const struct attribute_group jc42_group = {
416 .attrs = jc42_attributes,
417};
418
419/* Return 0 if detection is successful, -ENODEV otherwise */
420static int jc42_detect(struct i2c_client *new_client,
421 struct i2c_board_info *info)
422{
423 struct i2c_adapter *adapter = new_client->adapter;
424 int i, config, cap, manid, devid;
425
426 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA |
427 I2C_FUNC_SMBUS_WORD_DATA))
428 return -ENODEV;
429
430 cap = jc42_read_value(new_client, JC42_REG_CAP);
431 config = jc42_read_value(new_client, JC42_REG_CONFIG);
432 manid = jc42_read_value(new_client, JC42_REG_MANID);
433 devid = jc42_read_value(new_client, JC42_REG_DEVICEID);
434
435 if (cap < 0 || config < 0 || manid < 0 || devid < 0)
436 return -ENODEV;
437
438 if ((cap & 0xff00) || (config & 0xf800))
439 return -ENODEV;
440
441 for (i = 0; i < ARRAY_SIZE(jc42_chips); i++) {
442 struct jc42_chips *chip = &jc42_chips[i];
443 if (manid == chip->manid &&
444 (devid & chip->devid_mask) == chip->devid) {
445 strlcpy(info->type, "jc42", I2C_NAME_SIZE);
446 return 0;
447 }
448 }
449 return -ENODEV;
450}
451
452static int jc42_probe(struct i2c_client *new_client,
453 const struct i2c_device_id *id)
454{
455 struct jc42_data *data;
456 int config, cap, err;
457
458 data = kzalloc(sizeof(struct jc42_data), GFP_KERNEL);
459 if (!data) {
460 err = -ENOMEM;
461 goto exit;
462 }
463
464 i2c_set_clientdata(new_client, data);
465 mutex_init(&data->update_lock);
466
467 cap = jc42_read_value(new_client, JC42_REG_CAP);
468 if (cap < 0) {
469 err = -EINVAL;
470 goto exit_free;
471 }
472 data->extended = !!(cap & JC42_CAP_RANGE);
473
474 config = jc42_read_value(new_client, JC42_REG_CONFIG);
475 if (config < 0) {
476 err = -EINVAL;
477 goto exit_free;
478 }
479 data->orig_config = config;
480 if (config & JC42_CFG_SHUTDOWN) {
481 config &= ~JC42_CFG_SHUTDOWN;
482 jc42_write_value(new_client, JC42_REG_CONFIG, config);
483 }
484 data->config = config;
485
486 /* Register sysfs hooks */
487 err = sysfs_create_group(&new_client->dev.kobj, &jc42_group);
488 if (err)
489 goto exit_free;
490
491 data->hwmon_dev = hwmon_device_register(&new_client->dev);
492 if (IS_ERR(data->hwmon_dev)) {
493 err = PTR_ERR(data->hwmon_dev);
494 goto exit_remove;
495 }
496
497 return 0;
498
499exit_remove:
500 sysfs_remove_group(&new_client->dev.kobj, &jc42_group);
501exit_free:
502 kfree(data);
503exit:
504 return err;
505}
506
507static int jc42_remove(struct i2c_client *client)
508{
509 struct jc42_data *data = i2c_get_clientdata(client);
510 hwmon_device_unregister(data->hwmon_dev);
511 sysfs_remove_group(&client->dev.kobj, &jc42_group);
512 if (data->config != data->orig_config)
513 jc42_write_value(client, JC42_REG_CONFIG, data->orig_config);
514 kfree(data);
515 return 0;
516}
517
518/* All registers are word-sized. */
519static int jc42_read_value(struct i2c_client *client, u8 reg)
520{
521 int ret = i2c_smbus_read_word_data(client, reg);
522 if (ret < 0)
523 return ret;
524 return swab16(ret);
525}
526
527static int jc42_write_value(struct i2c_client *client, u8 reg, u16 value)
528{
529 return i2c_smbus_write_word_data(client, reg, swab16(value));
530}
531
532static struct jc42_data *jc42_update_device(struct device *dev)
533{
534 struct i2c_client *client = to_i2c_client(dev);
535 struct jc42_data *data = i2c_get_clientdata(client);
536 struct jc42_data *ret = data;
537 int val;
538
539 mutex_lock(&data->update_lock);
540
541 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
542 val = jc42_read_value(client, JC42_REG_TEMP);
543 if (val < 0) {
544 ret = ERR_PTR(val);
545 goto abort;
546 }
547 data->temp_input = val;
548
549 val = jc42_read_value(client, JC42_REG_TEMP_CRITICAL);
550 if (val < 0) {
551 ret = ERR_PTR(val);
552 goto abort;
553 }
554 data->temp_crit = val;
555
556 val = jc42_read_value(client, JC42_REG_TEMP_LOWER);
557 if (val < 0) {
558 ret = ERR_PTR(val);
559 goto abort;
560 }
561 data->temp_min = val;
562
563 val = jc42_read_value(client, JC42_REG_TEMP_UPPER);
564 if (val < 0) {
565 ret = ERR_PTR(val);
566 goto abort;
567 }
568 data->temp_max = val;
569
570 data->last_updated = jiffies;
571 data->valid = true;
572 }
573abort:
574 mutex_unlock(&data->update_lock);
575 return ret;
576}
577
578static int __init sensors_jc42_init(void)
579{
580 return i2c_add_driver(&jc42_driver);
581}
582
583static void __exit sensors_jc42_exit(void)
584{
585 i2c_del_driver(&jc42_driver);
586}
587
588MODULE_AUTHOR("Guenter Roeck <guenter.roeck@ericsson.com>");
589MODULE_DESCRIPTION("JC42 driver");
590MODULE_LICENSE("GPL");
591
592module_init(sensors_jc42_init);
593module_exit(sensors_jc42_exit);
diff --git a/drivers/hwmon/k8temp.c b/drivers/hwmon/k8temp.c
index 8bdf80d91598..b9bb3e0ca530 100644
--- a/drivers/hwmon/k8temp.c
+++ b/drivers/hwmon/k8temp.c
@@ -252,12 +252,13 @@ static int __devinit k8temp_probe(struct pci_dev *pdev,
252 &sensor_dev_attr_temp3_input.dev_attr); 252 &sensor_dev_attr_temp3_input.dev_attr);
253 if (err) 253 if (err)
254 goto exit_remove; 254 goto exit_remove;
255 if (data->sensorsp & SEL_PLACE) 255 if (data->sensorsp & SEL_PLACE) {
256 err = device_create_file(&pdev->dev, 256 err = device_create_file(&pdev->dev,
257 &sensor_dev_attr_temp4_input. 257 &sensor_dev_attr_temp4_input.
258 dev_attr); 258 dev_attr);
259 if (err) 259 if (err)
260 goto exit_remove; 260 goto exit_remove;
261 }
261 } 262 }
262 263
263 err = device_create_file(&pdev->dev, &dev_attr_name); 264 err = device_create_file(&pdev->dev, &dev_attr_name);
diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c
index 393f354f92a4..ab5b87a81677 100644
--- a/drivers/hwmon/lm75.c
+++ b/drivers/hwmon/lm75.c
@@ -280,10 +280,49 @@ static int lm75_detect(struct i2c_client *new_client,
280 return 0; 280 return 0;
281} 281}
282 282
283#ifdef CONFIG_PM
284static int lm75_suspend(struct device *dev)
285{
286 int status;
287 struct i2c_client *client = to_i2c_client(dev);
288 status = lm75_read_value(client, LM75_REG_CONF);
289 if (status < 0) {
290 dev_dbg(&client->dev, "Can't read config? %d\n", status);
291 return status;
292 }
293 status = status | LM75_SHUTDOWN;
294 lm75_write_value(client, LM75_REG_CONF, status);
295 return 0;
296}
297
298static int lm75_resume(struct device *dev)
299{
300 int status;
301 struct i2c_client *client = to_i2c_client(dev);
302 status = lm75_read_value(client, LM75_REG_CONF);
303 if (status < 0) {
304 dev_dbg(&client->dev, "Can't read config? %d\n", status);
305 return status;
306 }
307 status = status & ~LM75_SHUTDOWN;
308 lm75_write_value(client, LM75_REG_CONF, status);
309 return 0;
310}
311
312static const struct dev_pm_ops lm75_dev_pm_ops = {
313 .suspend = lm75_suspend,
314 .resume = lm75_resume,
315};
316#define LM75_DEV_PM_OPS (&lm75_dev_pm_ops)
317#else
318#define LM75_DEV_PM_OPS NULL
319#endif /* CONFIG_PM */
320
283static struct i2c_driver lm75_driver = { 321static struct i2c_driver lm75_driver = {
284 .class = I2C_CLASS_HWMON, 322 .class = I2C_CLASS_HWMON,
285 .driver = { 323 .driver = {
286 .name = "lm75", 324 .name = "lm75",
325 .pm = LM75_DEV_PM_OPS,
287 }, 326 },
288 .probe = lm75_probe, 327 .probe = lm75_probe,
289 .remove = lm75_remove, 328 .remove = lm75_remove,
diff --git a/drivers/hwmon/lm75.h b/drivers/hwmon/lm75.h
index 7c93454bb4e3..e547a3eb4de3 100644
--- a/drivers/hwmon/lm75.h
+++ b/drivers/hwmon/lm75.h
@@ -30,6 +30,7 @@
30/* straight from the datasheet */ 30/* straight from the datasheet */
31#define LM75_TEMP_MIN (-55000) 31#define LM75_TEMP_MIN (-55000)
32#define LM75_TEMP_MAX 125000 32#define LM75_TEMP_MAX 125000
33#define LM75_SHUTDOWN 0x01
33 34
34/* TEMP: 0.001C/bit (-55C to +125C) 35/* TEMP: 0.001C/bit (-55C to +125C)
35 REG: (0.5C/bit, two's complement) << 7 */ 36 REG: (0.5C/bit, two's complement) << 7 */
diff --git a/drivers/hwmon/ltc4245.c b/drivers/hwmon/ltc4245.c
index 21d201befc2c..659308329308 100644
--- a/drivers/hwmon/ltc4245.c
+++ b/drivers/hwmon/ltc4245.c
@@ -21,6 +21,7 @@
21#include <linux/i2c.h> 21#include <linux/i2c.h>
22#include <linux/hwmon.h> 22#include <linux/hwmon.h>
23#include <linux/hwmon-sysfs.h> 23#include <linux/hwmon-sysfs.h>
24#include <linux/i2c/ltc4245.h>
24 25
25/* Here are names of the chip's registers (a.k.a. commands) */ 26/* Here are names of the chip's registers (a.k.a. commands) */
26enum ltc4245_cmd { 27enum ltc4245_cmd {
@@ -60,8 +61,72 @@ struct ltc4245_data {
60 61
61 /* Voltage registers */ 62 /* Voltage registers */
62 u8 vregs[0x0d]; 63 u8 vregs[0x0d];
64
65 /* GPIO ADC registers */
66 bool use_extra_gpios;
67 int gpios[3];
63}; 68};
64 69
70/*
71 * Update the readings from the GPIO pins. If the driver has been configured to
72 * sample all GPIO's as analog voltages, a round-robin sampling method is used.
73 * Otherwise, only the configured GPIO pin is sampled.
74 *
75 * LOCKING: must hold data->update_lock
76 */
77static void ltc4245_update_gpios(struct device *dev)
78{
79 struct i2c_client *client = to_i2c_client(dev);
80 struct ltc4245_data *data = i2c_get_clientdata(client);
81 u8 gpio_curr, gpio_next, gpio_reg;
82 int i;
83
84 /* no extra gpio support, we're basically done */
85 if (!data->use_extra_gpios) {
86 data->gpios[0] = data->vregs[LTC4245_GPIOADC - 0x10];
87 return;
88 }
89
90 /*
91 * If the last reading was too long ago, then we mark all old GPIO
92 * readings as stale by setting them to -EAGAIN
93 */
94 if (time_after(jiffies, data->last_updated + 5 * HZ)) {
95 dev_dbg(&client->dev, "Marking GPIOs invalid\n");
96 for (i = 0; i < ARRAY_SIZE(data->gpios); i++)
97 data->gpios[i] = -EAGAIN;
98 }
99
100 /*
101 * Get the current GPIO pin
102 *
103 * The datasheet calls these GPIO[1-3], but we'll calculate the zero
104 * based array index instead, and call them GPIO[0-2]. This is much
105 * easier to think about.
106 */
107 gpio_curr = (data->cregs[LTC4245_GPIO] & 0xc0) >> 6;
108 if (gpio_curr > 0)
109 gpio_curr -= 1;
110
111 /* Read the GPIO voltage from the GPIOADC register */
112 data->gpios[gpio_curr] = data->vregs[LTC4245_GPIOADC - 0x10];
113
114 /* Find the next GPIO pin to read */
115 gpio_next = (gpio_curr + 1) % ARRAY_SIZE(data->gpios);
116
117 /*
118 * Calculate the correct setting for the GPIO register so it will
119 * sample the next GPIO pin
120 */
121 gpio_reg = (data->cregs[LTC4245_GPIO] & 0x3f) | ((gpio_next + 1) << 6);
122
123 /* Update the GPIO register */
124 i2c_smbus_write_byte_data(client, LTC4245_GPIO, gpio_reg);
125
126 /* Update saved data */
127 data->cregs[LTC4245_GPIO] = gpio_reg;
128}
129
65static struct ltc4245_data *ltc4245_update_device(struct device *dev) 130static struct ltc4245_data *ltc4245_update_device(struct device *dev)
66{ 131{
67 struct i2c_client *client = to_i2c_client(dev); 132 struct i2c_client *client = to_i2c_client(dev);
@@ -93,6 +158,9 @@ static struct ltc4245_data *ltc4245_update_device(struct device *dev)
93 data->vregs[i] = val; 158 data->vregs[i] = val;
94 } 159 }
95 160
161 /* Update GPIO readings */
162 ltc4245_update_gpios(dev);
163
96 data->last_updated = jiffies; 164 data->last_updated = jiffies;
97 data->valid = 1; 165 data->valid = 1;
98 } 166 }
@@ -233,6 +301,22 @@ static ssize_t ltc4245_show_alarm(struct device *dev,
233 return snprintf(buf, PAGE_SIZE, "%u\n", (reg & mask) ? 1 : 0); 301 return snprintf(buf, PAGE_SIZE, "%u\n", (reg & mask) ? 1 : 0);
234} 302}
235 303
304static ssize_t ltc4245_show_gpio(struct device *dev,
305 struct device_attribute *da,
306 char *buf)
307{
308 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
309 struct ltc4245_data *data = ltc4245_update_device(dev);
310 int val = data->gpios[attr->index];
311
312 /* handle stale GPIO's */
313 if (val < 0)
314 return val;
315
316 /* Convert to millivolts and print */
317 return snprintf(buf, PAGE_SIZE, "%u\n", val * 10);
318}
319
236/* These macros are used below in constructing device attribute objects 320/* These macros are used below in constructing device attribute objects
237 * for use with sysfs_create_group() to make a sysfs device file 321 * for use with sysfs_create_group() to make a sysfs device file
238 * for each register. 322 * for each register.
@@ -254,6 +338,10 @@ static ssize_t ltc4245_show_alarm(struct device *dev,
254 static SENSOR_DEVICE_ATTR_2(name, S_IRUGO, \ 338 static SENSOR_DEVICE_ATTR_2(name, S_IRUGO, \
255 ltc4245_show_alarm, NULL, (mask), reg) 339 ltc4245_show_alarm, NULL, (mask), reg)
256 340
341#define LTC4245_GPIO_VOLTAGE(name, gpio_num) \
342 static SENSOR_DEVICE_ATTR(name, S_IRUGO, \
343 ltc4245_show_gpio, NULL, gpio_num)
344
257/* Construct a sensor_device_attribute structure for each register */ 345/* Construct a sensor_device_attribute structure for each register */
258 346
259/* Input voltages */ 347/* Input voltages */
@@ -293,7 +381,9 @@ LTC4245_ALARM(in7_min_alarm, (1 << 2), LTC4245_FAULT2);
293LTC4245_ALARM(in8_min_alarm, (1 << 3), LTC4245_FAULT2); 381LTC4245_ALARM(in8_min_alarm, (1 << 3), LTC4245_FAULT2);
294 382
295/* GPIO voltages */ 383/* GPIO voltages */
296LTC4245_VOLTAGE(in9_input, LTC4245_GPIOADC); 384LTC4245_GPIO_VOLTAGE(in9_input, 0);
385LTC4245_GPIO_VOLTAGE(in10_input, 1);
386LTC4245_GPIO_VOLTAGE(in11_input, 2);
297 387
298/* Power Consumption (virtual) */ 388/* Power Consumption (virtual) */
299LTC4245_POWER(power1_input, LTC4245_12VSENSE); 389LTC4245_POWER(power1_input, LTC4245_12VSENSE);
@@ -304,7 +394,7 @@ LTC4245_POWER(power4_input, LTC4245_VEESENSE);
304/* Finally, construct an array of pointers to members of the above objects, 394/* Finally, construct an array of pointers to members of the above objects,
305 * as required for sysfs_create_group() 395 * as required for sysfs_create_group()
306 */ 396 */
307static struct attribute *ltc4245_attributes[] = { 397static struct attribute *ltc4245_std_attributes[] = {
308 &sensor_dev_attr_in1_input.dev_attr.attr, 398 &sensor_dev_attr_in1_input.dev_attr.attr,
309 &sensor_dev_attr_in2_input.dev_attr.attr, 399 &sensor_dev_attr_in2_input.dev_attr.attr,
310 &sensor_dev_attr_in3_input.dev_attr.attr, 400 &sensor_dev_attr_in3_input.dev_attr.attr,
@@ -345,10 +435,77 @@ static struct attribute *ltc4245_attributes[] = {
345 NULL, 435 NULL,
346}; 436};
347 437
348static const struct attribute_group ltc4245_group = { 438static struct attribute *ltc4245_gpio_attributes[] = {
349 .attrs = ltc4245_attributes, 439 &sensor_dev_attr_in10_input.dev_attr.attr,
440 &sensor_dev_attr_in11_input.dev_attr.attr,
441 NULL,
442};
443
444static const struct attribute_group ltc4245_std_group = {
445 .attrs = ltc4245_std_attributes,
446};
447
448static const struct attribute_group ltc4245_gpio_group = {
449 .attrs = ltc4245_gpio_attributes,
350}; 450};
351 451
452static int ltc4245_sysfs_create_groups(struct i2c_client *client)
453{
454 struct ltc4245_data *data = i2c_get_clientdata(client);
455 struct device *dev = &client->dev;
456 int ret;
457
458 /* register the standard sysfs attributes */
459 ret = sysfs_create_group(&dev->kobj, &ltc4245_std_group);
460 if (ret) {
461 dev_err(dev, "unable to register standard attributes\n");
462 return ret;
463 }
464
465 /* if we're using the extra gpio support, register it's attributes */
466 if (data->use_extra_gpios) {
467 ret = sysfs_create_group(&dev->kobj, &ltc4245_gpio_group);
468 if (ret) {
469 dev_err(dev, "unable to register gpio attributes\n");
470 sysfs_remove_group(&dev->kobj, &ltc4245_std_group);
471 return ret;
472 }
473 }
474
475 return 0;
476}
477
478static void ltc4245_sysfs_remove_groups(struct i2c_client *client)
479{
480 struct ltc4245_data *data = i2c_get_clientdata(client);
481 struct device *dev = &client->dev;
482
483 if (data->use_extra_gpios)
484 sysfs_remove_group(&dev->kobj, &ltc4245_gpio_group);
485
486 sysfs_remove_group(&dev->kobj, &ltc4245_std_group);
487}
488
489static bool ltc4245_use_extra_gpios(struct i2c_client *client)
490{
491 struct ltc4245_platform_data *pdata = dev_get_platdata(&client->dev);
492#ifdef CONFIG_OF
493 struct device_node *np = client->dev.of_node;
494#endif
495
496 /* prefer platform data */
497 if (pdata)
498 return pdata->use_extra_gpios;
499
500#ifdef CONFIG_OF
501 /* fallback on OF */
502 if (of_find_property(np, "ltc4245,use-extra-gpios", NULL))
503 return true;
504#endif
505
506 return false;
507}
508
352static int ltc4245_probe(struct i2c_client *client, 509static int ltc4245_probe(struct i2c_client *client,
353 const struct i2c_device_id *id) 510 const struct i2c_device_id *id)
354{ 511{
@@ -367,15 +524,16 @@ static int ltc4245_probe(struct i2c_client *client,
367 524
368 i2c_set_clientdata(client, data); 525 i2c_set_clientdata(client, data);
369 mutex_init(&data->update_lock); 526 mutex_init(&data->update_lock);
527 data->use_extra_gpios = ltc4245_use_extra_gpios(client);
370 528
371 /* Initialize the LTC4245 chip */ 529 /* Initialize the LTC4245 chip */
372 i2c_smbus_write_byte_data(client, LTC4245_FAULT1, 0x00); 530 i2c_smbus_write_byte_data(client, LTC4245_FAULT1, 0x00);
373 i2c_smbus_write_byte_data(client, LTC4245_FAULT2, 0x00); 531 i2c_smbus_write_byte_data(client, LTC4245_FAULT2, 0x00);
374 532
375 /* Register sysfs hooks */ 533 /* Register sysfs hooks */
376 ret = sysfs_create_group(&client->dev.kobj, &ltc4245_group); 534 ret = ltc4245_sysfs_create_groups(client);
377 if (ret) 535 if (ret)
378 goto out_sysfs_create_group; 536 goto out_sysfs_create_groups;
379 537
380 data->hwmon_dev = hwmon_device_register(&client->dev); 538 data->hwmon_dev = hwmon_device_register(&client->dev);
381 if (IS_ERR(data->hwmon_dev)) { 539 if (IS_ERR(data->hwmon_dev)) {
@@ -386,8 +544,8 @@ static int ltc4245_probe(struct i2c_client *client,
386 return 0; 544 return 0;
387 545
388out_hwmon_device_register: 546out_hwmon_device_register:
389 sysfs_remove_group(&client->dev.kobj, &ltc4245_group); 547 ltc4245_sysfs_remove_groups(client);
390out_sysfs_create_group: 548out_sysfs_create_groups:
391 kfree(data); 549 kfree(data);
392out_kzalloc: 550out_kzalloc:
393 return ret; 551 return ret;
@@ -398,8 +556,7 @@ static int ltc4245_remove(struct i2c_client *client)
398 struct ltc4245_data *data = i2c_get_clientdata(client); 556 struct ltc4245_data *data = i2c_get_clientdata(client);
399 557
400 hwmon_device_unregister(data->hwmon_dev); 558 hwmon_device_unregister(data->hwmon_dev);
401 sysfs_remove_group(&client->dev.kobj, &ltc4245_group); 559 ltc4245_sysfs_remove_groups(client);
402
403 kfree(data); 560 kfree(data);
404 561
405 return 0; 562 return 0;
diff --git a/drivers/hwmon/mc13783-adc.c b/drivers/hwmon/mc13783-adc.c
index ce3c7bc81814..d5226c9e1201 100644
--- a/drivers/hwmon/mc13783-adc.c
+++ b/drivers/hwmon/mc13783-adc.c
@@ -18,7 +18,7 @@
18 * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */ 19 */
20 20
21#include <linux/mfd/mc13783-private.h> 21#include <linux/mfd/mc13783.h>
22#include <linux/platform_device.h> 22#include <linux/platform_device.h>
23#include <linux/hwmon-sysfs.h> 23#include <linux/hwmon-sysfs.h>
24#include <linux/kernel.h> 24#include <linux/kernel.h>
@@ -144,6 +144,14 @@ static const struct attribute_group mc13783_group_ts = {
144 .attrs = mc13783_attr_ts, 144 .attrs = mc13783_attr_ts,
145}; 145};
146 146
147static int mc13783_adc_use_touchscreen(struct platform_device *pdev)
148{
149 struct mc13783_adc_priv *priv = platform_get_drvdata(pdev);
150 unsigned flags = mc13783_get_flags(priv->mc13783);
151
152 return flags & MC13783_USE_TOUCHSCREEN;
153}
154
147static int __init mc13783_adc_probe(struct platform_device *pdev) 155static int __init mc13783_adc_probe(struct platform_device *pdev)
148{ 156{
149 struct mc13783_adc_priv *priv; 157 struct mc13783_adc_priv *priv;
@@ -162,10 +170,11 @@ static int __init mc13783_adc_probe(struct platform_device *pdev)
162 if (ret) 170 if (ret)
163 goto out_err_create1; 171 goto out_err_create1;
164 172
165 if (!(priv->mc13783->flags & MC13783_USE_TOUCHSCREEN)) 173 if (!mc13783_adc_use_touchscreen(pdev)) {
166 ret = sysfs_create_group(&pdev->dev.kobj, &mc13783_group_ts); 174 ret = sysfs_create_group(&pdev->dev.kobj, &mc13783_group_ts);
167 if (ret) 175 if (ret)
168 goto out_err_create2; 176 goto out_err_create2;
177 }
169 178
170 priv->hwmon_dev = hwmon_device_register(&pdev->dev); 179 priv->hwmon_dev = hwmon_device_register(&pdev->dev);
171 if (IS_ERR(priv->hwmon_dev)) { 180 if (IS_ERR(priv->hwmon_dev)) {
@@ -180,7 +189,7 @@ static int __init mc13783_adc_probe(struct platform_device *pdev)
180 189
181out_err_register: 190out_err_register:
182 191
183 if (!(priv->mc13783->flags & MC13783_USE_TOUCHSCREEN)) 192 if (!mc13783_adc_use_touchscreen(pdev))
184 sysfs_remove_group(&pdev->dev.kobj, &mc13783_group_ts); 193 sysfs_remove_group(&pdev->dev.kobj, &mc13783_group_ts);
185out_err_create2: 194out_err_create2:
186 195
@@ -199,7 +208,7 @@ static int __devexit mc13783_adc_remove(struct platform_device *pdev)
199 208
200 hwmon_device_unregister(priv->hwmon_dev); 209 hwmon_device_unregister(priv->hwmon_dev);
201 210
202 if (!(priv->mc13783->flags & MC13783_USE_TOUCHSCREEN)) 211 if (!mc13783_adc_use_touchscreen(pdev))
203 sysfs_remove_group(&pdev->dev.kobj, &mc13783_group_ts); 212 sysfs_remove_group(&pdev->dev.kobj, &mc13783_group_ts);
204 213
205 sysfs_remove_group(&pdev->dev.kobj, &mc13783_group); 214 sysfs_remove_group(&pdev->dev.kobj, &mc13783_group);
diff --git a/drivers/hwmon/pc87360.c b/drivers/hwmon/pc87360.c
index 4a64b85d4ec9..68e69a49633c 100644
--- a/drivers/hwmon/pc87360.c
+++ b/drivers/hwmon/pc87360.c
@@ -1610,11 +1610,8 @@ static struct pc87360_data *pc87360_update_device(struct device *dev)
1610 1610
1611static int __init pc87360_device_add(unsigned short address) 1611static int __init pc87360_device_add(unsigned short address)
1612{ 1612{
1613 struct resource res = { 1613 struct resource res[3];
1614 .name = "pc87360", 1614 int err, i, res_count;
1615 .flags = IORESOURCE_IO,
1616 };
1617 int err, i;
1618 1615
1619 pdev = platform_device_alloc("pc87360", address); 1616 pdev = platform_device_alloc("pc87360", address);
1620 if (!pdev) { 1617 if (!pdev) {
@@ -1623,22 +1620,28 @@ static int __init pc87360_device_add(unsigned short address)
1623 goto exit; 1620 goto exit;
1624 } 1621 }
1625 1622
1623 memset(res, 0, 3 * sizeof(struct resource));
1624 res_count = 0;
1626 for (i = 0; i < 3; i++) { 1625 for (i = 0; i < 3; i++) {
1627 if (!extra_isa[i]) 1626 if (!extra_isa[i])
1628 continue; 1627 continue;
1629 res.start = extra_isa[i]; 1628 res[res_count].start = extra_isa[i];
1630 res.end = extra_isa[i] + PC87360_EXTENT - 1; 1629 res[res_count].end = extra_isa[i] + PC87360_EXTENT - 1;
1630 res[res_count].name = "pc87360",
1631 res[res_count].flags = IORESOURCE_IO,
1631 1632
1632 err = acpi_check_resource_conflict(&res); 1633 err = acpi_check_resource_conflict(&res[res_count]);
1633 if (err) 1634 if (err)
1634 goto exit_device_put; 1635 goto exit_device_put;
1635 1636
1636 err = platform_device_add_resources(pdev, &res, 1); 1637 res_count++;
1637 if (err) { 1638 }
1638 printk(KERN_ERR "pc87360: Device resource[%d] " 1639
1639 "addition failed (%d)\n", i, err); 1640 err = platform_device_add_resources(pdev, res, res_count);
1640 goto exit_device_put; 1641 if (err) {
1641 } 1642 printk(KERN_ERR "pc87360: Device resources addition failed "
1643 "(%d)\n", err);
1644 goto exit_device_put;
1642 } 1645 }
1643 1646
1644 err = platform_device_add(pdev); 1647 err = platform_device_add(pdev);
diff --git a/drivers/hwmon/pc87427.c b/drivers/hwmon/pc87427.c
index 3170b26d2443..9ec4daaf6ca6 100644
--- a/drivers/hwmon/pc87427.c
+++ b/drivers/hwmon/pc87427.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * pc87427.c - hardware monitoring driver for the 2 * pc87427.c - hardware monitoring driver for the
3 * National Semiconductor PC87427 Super-I/O chip 3 * National Semiconductor PC87427 Super-I/O chip
4 * Copyright (C) 2006 Jean Delvare <khali@linux-fr.org> 4 * Copyright (C) 2006, 2008, 2010 Jean Delvare <khali@linux-fr.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as 7 * it under the terms of the GNU General Public License version 2 as
@@ -15,10 +15,11 @@
15 * Supports the following chips: 15 * Supports the following chips:
16 * 16 *
17 * Chip #vin #fan #pwm #temp devid 17 * Chip #vin #fan #pwm #temp devid
18 * PC87427 - 8 - - 0xF2 18 * PC87427 - 8 4 6 0xF2
19 * 19 *
20 * This driver assumes that no more than one chip is present. 20 * This driver assumes that no more than one chip is present.
21 * Only fan inputs are supported so far, although the chip can do much more. 21 * Only fans are fully supported so far. Temperatures are in read-only
22 * mode, and voltages aren't supported at all.
22 */ 23 */
23 24
24#include <linux/module.h> 25#include <linux/module.h>
@@ -57,6 +58,25 @@ struct pc87427_data {
57 u16 fan[8]; /* register values */ 58 u16 fan[8]; /* register values */
58 u16 fan_min[8]; /* register values */ 59 u16 fan_min[8]; /* register values */
59 u8 fan_status[8]; /* register values */ 60 u8 fan_status[8]; /* register values */
61
62 u8 pwm_enabled; /* bit vector */
63 u8 pwm_auto_ok; /* bit vector */
64 u8 pwm_enable[4]; /* register values */
65 u8 pwm[4]; /* register values */
66
67 u8 temp_enabled; /* bit vector */
68 s16 temp[6]; /* register values */
69 s8 temp_min[6]; /* register values */
70 s8 temp_max[6]; /* register values */
71 s8 temp_crit[6]; /* register values */
72 u8 temp_status[6]; /* register values */
73 u8 temp_type[6]; /* register values */
74};
75
76struct pc87427_sio_data {
77 unsigned short address[2];
78 u8 has_fanin;
79 u8 has_fanout;
60}; 80};
61 81
62/* 82/*
@@ -65,6 +85,13 @@ struct pc87427_data {
65 85
66#define SIOREG_LDSEL 0x07 /* Logical device select */ 86#define SIOREG_LDSEL 0x07 /* Logical device select */
67#define SIOREG_DEVID 0x20 /* Device ID */ 87#define SIOREG_DEVID 0x20 /* Device ID */
88#define SIOREG_CF2 0x22 /* Configuration 2 */
89#define SIOREG_CF3 0x23 /* Configuration 3 */
90#define SIOREG_CF4 0x24 /* Configuration 4 */
91#define SIOREG_CF5 0x25 /* Configuration 5 */
92#define SIOREG_CFB 0x2B /* Configuration B */
93#define SIOREG_CFC 0x2C /* Configuration C */
94#define SIOREG_CFD 0x2D /* Configuration D */
68#define SIOREG_ACT 0x30 /* Device activation */ 95#define SIOREG_ACT 0x30 /* Device activation */
69#define SIOREG_MAP 0x50 /* I/O or memory mapping */ 96#define SIOREG_MAP 0x50 /* I/O or memory mapping */
70#define SIOREG_IOBASE 0x60 /* I/O base address */ 97#define SIOREG_IOBASE 0x60 /* I/O base address */
@@ -102,6 +129,8 @@ static inline void superio_exit(int sioaddr)
102#define BANK_FM(nr) (nr) 129#define BANK_FM(nr) (nr)
103#define BANK_FT(nr) (0x08 + (nr)) 130#define BANK_FT(nr) (0x08 + (nr))
104#define BANK_FC(nr) (0x10 + (nr) * 2) 131#define BANK_FC(nr) (0x10 + (nr) * 2)
132#define BANK_TM(nr) (nr)
133#define BANK_VM(nr) (0x08 + (nr))
105 134
106/* 135/*
107 * I/O access functions 136 * I/O access functions
@@ -179,6 +208,127 @@ static inline u16 fan_to_reg(unsigned long val)
179} 208}
180 209
181/* 210/*
211 * PWM registers and conversions
212 */
213
214#define PC87427_REG_PWM_ENABLE 0x10
215#define PC87427_REG_PWM_DUTY 0x12
216
217#define PWM_ENABLE_MODE_MASK (7 << 4)
218#define PWM_ENABLE_CTLEN (1 << 0)
219
220#define PWM_MODE_MANUAL (0 << 4)
221#define PWM_MODE_AUTO (1 << 4)
222#define PWM_MODE_OFF (2 << 4)
223#define PWM_MODE_ON (7 << 4)
224
225/* Dedicated function to read all registers related to a given PWM output.
226 This saves us quite a few locks and bank selections.
227 Must be called with data->lock held.
228 nr is from 0 to 3 */
229static void pc87427_readall_pwm(struct pc87427_data *data, u8 nr)
230{
231 int iobase = data->address[LD_FAN];
232
233 outb(BANK_FC(nr), iobase + PC87427_REG_BANK);
234 data->pwm_enable[nr] = inb(iobase + PC87427_REG_PWM_ENABLE);
235 data->pwm[nr] = inb(iobase + PC87427_REG_PWM_DUTY);
236}
237
238static inline int pwm_enable_from_reg(u8 reg)
239{
240 switch (reg & PWM_ENABLE_MODE_MASK) {
241 case PWM_MODE_ON:
242 return 0;
243 case PWM_MODE_MANUAL:
244 case PWM_MODE_OFF:
245 return 1;
246 case PWM_MODE_AUTO:
247 return 2;
248 default:
249 return -EPROTO;
250 }
251}
252
253static inline u8 pwm_enable_to_reg(unsigned long val, u8 pwmval)
254{
255 switch (val) {
256 default:
257 return PWM_MODE_ON;
258 case 1:
259 return pwmval ? PWM_MODE_MANUAL : PWM_MODE_OFF;
260 case 2:
261 return PWM_MODE_AUTO;
262 }
263}
264
265/*
266 * Temperature registers and conversions
267 */
268
269#define PC87427_REG_TEMP_STATUS 0x10
270#define PC87427_REG_TEMP 0x14
271#define PC87427_REG_TEMP_MAX 0x18
272#define PC87427_REG_TEMP_MIN 0x19
273#define PC87427_REG_TEMP_CRIT 0x1a
274#define PC87427_REG_TEMP_TYPE 0x1d
275
276#define TEMP_STATUS_CHANEN (1 << 0)
277#define TEMP_STATUS_LOWFLG (1 << 1)
278#define TEMP_STATUS_HIGHFLG (1 << 2)
279#define TEMP_STATUS_CRITFLG (1 << 3)
280#define TEMP_STATUS_SENSERR (1 << 5)
281#define TEMP_TYPE_MASK (3 << 5)
282
283#define TEMP_TYPE_THERMISTOR (1 << 5)
284#define TEMP_TYPE_REMOTE_DIODE (2 << 5)
285#define TEMP_TYPE_LOCAL_DIODE (3 << 5)
286
287/* Dedicated function to read all registers related to a given temperature
288 input. This saves us quite a few locks and bank selections.
289 Must be called with data->lock held.
290 nr is from 0 to 5 */
291static void pc87427_readall_temp(struct pc87427_data *data, u8 nr)
292{
293 int iobase = data->address[LD_TEMP];
294
295 outb(BANK_TM(nr), iobase + PC87427_REG_BANK);
296 data->temp[nr] = le16_to_cpu(inw(iobase + PC87427_REG_TEMP));
297 data->temp_max[nr] = inb(iobase + PC87427_REG_TEMP_MAX);
298 data->temp_min[nr] = inb(iobase + PC87427_REG_TEMP_MIN);
299 data->temp_crit[nr] = inb(iobase + PC87427_REG_TEMP_CRIT);
300 data->temp_type[nr] = inb(iobase + PC87427_REG_TEMP_TYPE);
301 data->temp_status[nr] = inb(iobase + PC87427_REG_TEMP_STATUS);
302 /* Clear fan alarm bits */
303 outb(data->temp_status[nr], iobase + PC87427_REG_TEMP_STATUS);
304}
305
306static inline unsigned int temp_type_from_reg(u8 reg)
307{
308 switch (reg & TEMP_TYPE_MASK) {
309 case TEMP_TYPE_THERMISTOR:
310 return 4;
311 case TEMP_TYPE_REMOTE_DIODE:
312 case TEMP_TYPE_LOCAL_DIODE:
313 return 3;
314 default:
315 return 0;
316 }
317}
318
319/* We assume 8-bit thermal sensors; 9-bit thermal sensors are possible
320 too, but I have no idea how to figure out when they are used. */
321static inline long temp_from_reg(s16 reg)
322{
323 return reg * 1000 / 256;
324}
325
326static inline long temp_from_reg8(s8 reg)
327{
328 return reg * 1000;
329}
330
331/*
182 * Data interface 332 * Data interface
183 */ 333 */
184 334
@@ -198,6 +348,21 @@ static struct pc87427_data *pc87427_update_device(struct device *dev)
198 continue; 348 continue;
199 pc87427_readall_fan(data, i); 349 pc87427_readall_fan(data, i);
200 } 350 }
351
352 /* PWM outputs */
353 for (i = 0; i < 4; i++) {
354 if (!(data->pwm_enabled & (1 << i)))
355 continue;
356 pc87427_readall_pwm(data, i);
357 }
358
359 /* Temperature channels */
360 for (i = 0; i < 6; i++) {
361 if (!(data->temp_enabled & (1 << i)))
362 continue;
363 pc87427_readall_temp(data, i);
364 }
365
201 data->last_updated = jiffies; 366 data->last_updated = jiffies;
202 367
203done: 368done:
@@ -208,9 +373,8 @@ done:
208static ssize_t show_fan_input(struct device *dev, struct device_attribute 373static ssize_t show_fan_input(struct device *dev, struct device_attribute
209 *devattr, char *buf) 374 *devattr, char *buf)
210{ 375{
211 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
212 struct pc87427_data *data = pc87427_update_device(dev); 376 struct pc87427_data *data = pc87427_update_device(dev);
213 int nr = attr->index; 377 int nr = to_sensor_dev_attr(devattr)->index;
214 378
215 return sprintf(buf, "%lu\n", fan_from_reg(data->fan[nr])); 379 return sprintf(buf, "%lu\n", fan_from_reg(data->fan[nr]));
216} 380}
@@ -218,9 +382,8 @@ static ssize_t show_fan_input(struct device *dev, struct device_attribute
218static ssize_t show_fan_min(struct device *dev, struct device_attribute 382static ssize_t show_fan_min(struct device *dev, struct device_attribute
219 *devattr, char *buf) 383 *devattr, char *buf)
220{ 384{
221 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
222 struct pc87427_data *data = pc87427_update_device(dev); 385 struct pc87427_data *data = pc87427_update_device(dev);
223 int nr = attr->index; 386 int nr = to_sensor_dev_attr(devattr)->index;
224 387
225 return sprintf(buf, "%lu\n", fan_from_reg(data->fan_min[nr])); 388 return sprintf(buf, "%lu\n", fan_from_reg(data->fan_min[nr]));
226} 389}
@@ -228,9 +391,8 @@ static ssize_t show_fan_min(struct device *dev, struct device_attribute
228static ssize_t show_fan_alarm(struct device *dev, struct device_attribute 391static ssize_t show_fan_alarm(struct device *dev, struct device_attribute
229 *devattr, char *buf) 392 *devattr, char *buf)
230{ 393{
231 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
232 struct pc87427_data *data = pc87427_update_device(dev); 394 struct pc87427_data *data = pc87427_update_device(dev);
233 int nr = attr->index; 395 int nr = to_sensor_dev_attr(devattr)->index;
234 396
235 return sprintf(buf, "%d\n", !!(data->fan_status[nr] 397 return sprintf(buf, "%d\n", !!(data->fan_status[nr]
236 & FAN_STATUS_LOSPD)); 398 & FAN_STATUS_LOSPD));
@@ -239,9 +401,8 @@ static ssize_t show_fan_alarm(struct device *dev, struct device_attribute
239static ssize_t show_fan_fault(struct device *dev, struct device_attribute 401static ssize_t show_fan_fault(struct device *dev, struct device_attribute
240 *devattr, char *buf) 402 *devattr, char *buf)
241{ 403{
242 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
243 struct pc87427_data *data = pc87427_update_device(dev); 404 struct pc87427_data *data = pc87427_update_device(dev);
244 int nr = attr->index; 405 int nr = to_sensor_dev_attr(devattr)->index;
245 406
246 return sprintf(buf, "%d\n", !!(data->fan_status[nr] 407 return sprintf(buf, "%d\n", !!(data->fan_status[nr]
247 & FAN_STATUS_STALL)); 408 & FAN_STATUS_STALL));
@@ -251,11 +412,13 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute
251 *devattr, const char *buf, size_t count) 412 *devattr, const char *buf, size_t count)
252{ 413{
253 struct pc87427_data *data = dev_get_drvdata(dev); 414 struct pc87427_data *data = dev_get_drvdata(dev);
254 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 415 int nr = to_sensor_dev_attr(devattr)->index;
255 int nr = attr->index; 416 unsigned long val;
256 unsigned long val = simple_strtoul(buf, NULL, 10);
257 int iobase = data->address[LD_FAN]; 417 int iobase = data->address[LD_FAN];
258 418
419 if (strict_strtoul(buf, 10, &val) < 0)
420 return -EINVAL;
421
259 mutex_lock(&data->lock); 422 mutex_lock(&data->lock);
260 outb(BANK_FM(nr), iobase + PC87427_REG_BANK); 423 outb(BANK_FM(nr), iobase + PC87427_REG_BANK);
261 /* The low speed limit registers are read-only while monitoring 424 /* The low speed limit registers are read-only while monitoring
@@ -377,6 +540,390 @@ static const struct attribute_group pc87427_group_fan[8] = {
377 { .attrs = pc87427_attributes_fan[7] }, 540 { .attrs = pc87427_attributes_fan[7] },
378}; 541};
379 542
543/* Must be called with data->lock held and pc87427_readall_pwm() freshly
544 called */
545static void update_pwm_enable(struct pc87427_data *data, int nr, u8 mode)
546{
547 int iobase = data->address[LD_FAN];
548 data->pwm_enable[nr] &= ~PWM_ENABLE_MODE_MASK;
549 data->pwm_enable[nr] |= mode;
550 outb(data->pwm_enable[nr], iobase + PC87427_REG_PWM_ENABLE);
551}
552
553static ssize_t show_pwm_enable(struct device *dev, struct device_attribute
554 *devattr, char *buf)
555{
556 struct pc87427_data *data = pc87427_update_device(dev);
557 int nr = to_sensor_dev_attr(devattr)->index;
558 int pwm_enable;
559
560 pwm_enable = pwm_enable_from_reg(data->pwm_enable[nr]);
561 if (pwm_enable < 0)
562 return pwm_enable;
563 return sprintf(buf, "%d\n", pwm_enable);
564}
565
566static ssize_t set_pwm_enable(struct device *dev, struct device_attribute
567 *devattr, const char *buf, size_t count)
568{
569 struct pc87427_data *data = dev_get_drvdata(dev);
570 int nr = to_sensor_dev_attr(devattr)->index;
571 unsigned long val;
572
573 if (strict_strtoul(buf, 10, &val) < 0 || val > 2)
574 return -EINVAL;
575 /* Can't go to automatic mode if it isn't configured */
576 if (val == 2 && !(data->pwm_auto_ok & (1 << nr)))
577 return -EINVAL;
578
579 mutex_lock(&data->lock);
580 pc87427_readall_pwm(data, nr);
581 update_pwm_enable(data, nr, pwm_enable_to_reg(val, data->pwm[nr]));
582 mutex_unlock(&data->lock);
583
584 return count;
585}
586
587static ssize_t show_pwm(struct device *dev, struct device_attribute
588 *devattr, char *buf)
589{
590 struct pc87427_data *data = pc87427_update_device(dev);
591 int nr = to_sensor_dev_attr(devattr)->index;
592
593 return sprintf(buf, "%d\n", (int)data->pwm[nr]);
594}
595
596static ssize_t set_pwm(struct device *dev, struct device_attribute
597 *devattr, const char *buf, size_t count)
598{
599 struct pc87427_data *data = dev_get_drvdata(dev);
600 int nr = to_sensor_dev_attr(devattr)->index;
601 unsigned long val;
602 int iobase = data->address[LD_FAN];
603 u8 mode;
604
605 if (strict_strtoul(buf, 10, &val) < 0 || val > 0xff)
606 return -EINVAL;
607
608 mutex_lock(&data->lock);
609 pc87427_readall_pwm(data, nr);
610 mode = data->pwm_enable[nr] & PWM_ENABLE_MODE_MASK;
611 if (mode != PWM_MODE_MANUAL && mode != PWM_MODE_OFF) {
612 dev_notice(dev, "Can't set PWM%d duty cycle while not in "
613 "manual mode\n", nr + 1);
614 mutex_unlock(&data->lock);
615 return -EPERM;
616 }
617
618 /* We may have to change the mode */
619 if (mode == PWM_MODE_MANUAL && val == 0) {
620 /* Transition from Manual to Off */
621 update_pwm_enable(data, nr, PWM_MODE_OFF);
622 mode = PWM_MODE_OFF;
623 dev_dbg(dev, "Switching PWM%d from %s to %s\n", nr + 1,
624 "manual", "off");
625 } else if (mode == PWM_MODE_OFF && val != 0) {
626 /* Transition from Off to Manual */
627 update_pwm_enable(data, nr, PWM_MODE_MANUAL);
628 mode = PWM_MODE_MANUAL;
629 dev_dbg(dev, "Switching PWM%d from %s to %s\n", nr + 1,
630 "off", "manual");
631 }
632
633 data->pwm[nr] = val;
634 if (mode == PWM_MODE_MANUAL)
635 outb(val, iobase + PC87427_REG_PWM_DUTY);
636 mutex_unlock(&data->lock);
637
638 return count;
639}
640
641static SENSOR_DEVICE_ATTR(pwm1_enable, S_IWUSR | S_IRUGO,
642 show_pwm_enable, set_pwm_enable, 0);
643static SENSOR_DEVICE_ATTR(pwm2_enable, S_IWUSR | S_IRUGO,
644 show_pwm_enable, set_pwm_enable, 1);
645static SENSOR_DEVICE_ATTR(pwm3_enable, S_IWUSR | S_IRUGO,
646 show_pwm_enable, set_pwm_enable, 2);
647static SENSOR_DEVICE_ATTR(pwm4_enable, S_IWUSR | S_IRUGO,
648 show_pwm_enable, set_pwm_enable, 3);
649
650static SENSOR_DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 0);
651static SENSOR_DEVICE_ATTR(pwm2, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 1);
652static SENSOR_DEVICE_ATTR(pwm3, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 2);
653static SENSOR_DEVICE_ATTR(pwm4, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 3);
654
655static struct attribute *pc87427_attributes_pwm[4][3] = {
656 {
657 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
658 &sensor_dev_attr_pwm1.dev_attr.attr,
659 NULL
660 }, {
661 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
662 &sensor_dev_attr_pwm2.dev_attr.attr,
663 NULL
664 }, {
665 &sensor_dev_attr_pwm3_enable.dev_attr.attr,
666 &sensor_dev_attr_pwm3.dev_attr.attr,
667 NULL
668 }, {
669 &sensor_dev_attr_pwm4_enable.dev_attr.attr,
670 &sensor_dev_attr_pwm4.dev_attr.attr,
671 NULL
672 }
673};
674
675static const struct attribute_group pc87427_group_pwm[4] = {
676 { .attrs = pc87427_attributes_pwm[0] },
677 { .attrs = pc87427_attributes_pwm[1] },
678 { .attrs = pc87427_attributes_pwm[2] },
679 { .attrs = pc87427_attributes_pwm[3] },
680};
681
682static ssize_t show_temp_input(struct device *dev, struct device_attribute
683 *devattr, char *buf)
684{
685 struct pc87427_data *data = pc87427_update_device(dev);
686 int nr = to_sensor_dev_attr(devattr)->index;
687
688 return sprintf(buf, "%ld\n", temp_from_reg(data->temp[nr]));
689}
690
691static ssize_t show_temp_min(struct device *dev, struct device_attribute
692 *devattr, char *buf)
693{
694 struct pc87427_data *data = pc87427_update_device(dev);
695 int nr = to_sensor_dev_attr(devattr)->index;
696
697 return sprintf(buf, "%ld\n", temp_from_reg8(data->temp_min[nr]));
698}
699
700static ssize_t show_temp_max(struct device *dev, struct device_attribute
701 *devattr, char *buf)
702{
703 struct pc87427_data *data = pc87427_update_device(dev);
704 int nr = to_sensor_dev_attr(devattr)->index;
705
706 return sprintf(buf, "%ld\n", temp_from_reg8(data->temp_max[nr]));
707}
708
709static ssize_t show_temp_crit(struct device *dev, struct device_attribute
710 *devattr, char *buf)
711{
712 struct pc87427_data *data = pc87427_update_device(dev);
713 int nr = to_sensor_dev_attr(devattr)->index;
714
715 return sprintf(buf, "%ld\n", temp_from_reg8(data->temp_crit[nr]));
716}
717
718static ssize_t show_temp_type(struct device *dev, struct device_attribute
719 *devattr, char *buf)
720{
721 struct pc87427_data *data = pc87427_update_device(dev);
722 int nr = to_sensor_dev_attr(devattr)->index;
723
724 return sprintf(buf, "%u\n", temp_type_from_reg(data->temp_type[nr]));
725}
726
727static ssize_t show_temp_min_alarm(struct device *dev, struct device_attribute
728 *devattr, char *buf)
729{
730 struct pc87427_data *data = pc87427_update_device(dev);
731 int nr = to_sensor_dev_attr(devattr)->index;
732
733 return sprintf(buf, "%d\n", !!(data->temp_status[nr]
734 & TEMP_STATUS_LOWFLG));
735}
736
737static ssize_t show_temp_max_alarm(struct device *dev, struct device_attribute
738 *devattr, char *buf)
739{
740 struct pc87427_data *data = pc87427_update_device(dev);
741 int nr = to_sensor_dev_attr(devattr)->index;
742
743 return sprintf(buf, "%d\n", !!(data->temp_status[nr]
744 & TEMP_STATUS_HIGHFLG));
745}
746
747static ssize_t show_temp_crit_alarm(struct device *dev, struct device_attribute
748 *devattr, char *buf)
749{
750 struct pc87427_data *data = pc87427_update_device(dev);
751 int nr = to_sensor_dev_attr(devattr)->index;
752
753 return sprintf(buf, "%d\n", !!(data->temp_status[nr]
754 & TEMP_STATUS_CRITFLG));
755}
756
757static ssize_t show_temp_fault(struct device *dev, struct device_attribute
758 *devattr, char *buf)
759{
760 struct pc87427_data *data = pc87427_update_device(dev);
761 int nr = to_sensor_dev_attr(devattr)->index;
762
763 return sprintf(buf, "%d\n", !!(data->temp_status[nr]
764 & TEMP_STATUS_SENSERR));
765}
766
767static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp_input, NULL, 0);
768static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp_input, NULL, 1);
769static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp_input, NULL, 2);
770static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, show_temp_input, NULL, 3);
771static SENSOR_DEVICE_ATTR(temp5_input, S_IRUGO, show_temp_input, NULL, 4);
772static SENSOR_DEVICE_ATTR(temp6_input, S_IRUGO, show_temp_input, NULL, 5);
773
774static SENSOR_DEVICE_ATTR(temp1_min, S_IRUGO, show_temp_min, NULL, 0);
775static SENSOR_DEVICE_ATTR(temp2_min, S_IRUGO, show_temp_min, NULL, 1);
776static SENSOR_DEVICE_ATTR(temp3_min, S_IRUGO, show_temp_min, NULL, 2);
777static SENSOR_DEVICE_ATTR(temp4_min, S_IRUGO, show_temp_min, NULL, 3);
778static SENSOR_DEVICE_ATTR(temp5_min, S_IRUGO, show_temp_min, NULL, 4);
779static SENSOR_DEVICE_ATTR(temp6_min, S_IRUGO, show_temp_min, NULL, 5);
780
781static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO, show_temp_max, NULL, 0);
782static SENSOR_DEVICE_ATTR(temp2_max, S_IRUGO, show_temp_max, NULL, 1);
783static SENSOR_DEVICE_ATTR(temp3_max, S_IRUGO, show_temp_max, NULL, 2);
784static SENSOR_DEVICE_ATTR(temp4_max, S_IRUGO, show_temp_max, NULL, 3);
785static SENSOR_DEVICE_ATTR(temp5_max, S_IRUGO, show_temp_max, NULL, 4);
786static SENSOR_DEVICE_ATTR(temp6_max, S_IRUGO, show_temp_max, NULL, 5);
787
788static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO, show_temp_crit, NULL, 0);
789static SENSOR_DEVICE_ATTR(temp2_crit, S_IRUGO, show_temp_crit, NULL, 1);
790static SENSOR_DEVICE_ATTR(temp3_crit, S_IRUGO, show_temp_crit, NULL, 2);
791static SENSOR_DEVICE_ATTR(temp4_crit, S_IRUGO, show_temp_crit, NULL, 3);
792static SENSOR_DEVICE_ATTR(temp5_crit, S_IRUGO, show_temp_crit, NULL, 4);
793static SENSOR_DEVICE_ATTR(temp6_crit, S_IRUGO, show_temp_crit, NULL, 5);
794
795static SENSOR_DEVICE_ATTR(temp1_type, S_IRUGO, show_temp_type, NULL, 0);
796static SENSOR_DEVICE_ATTR(temp2_type, S_IRUGO, show_temp_type, NULL, 1);
797static SENSOR_DEVICE_ATTR(temp3_type, S_IRUGO, show_temp_type, NULL, 2);
798static SENSOR_DEVICE_ATTR(temp4_type, S_IRUGO, show_temp_type, NULL, 3);
799static SENSOR_DEVICE_ATTR(temp5_type, S_IRUGO, show_temp_type, NULL, 4);
800static SENSOR_DEVICE_ATTR(temp6_type, S_IRUGO, show_temp_type, NULL, 5);
801
802static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO,
803 show_temp_min_alarm, NULL, 0);
804static SENSOR_DEVICE_ATTR(temp2_min_alarm, S_IRUGO,
805 show_temp_min_alarm, NULL, 1);
806static SENSOR_DEVICE_ATTR(temp3_min_alarm, S_IRUGO,
807 show_temp_min_alarm, NULL, 2);
808static SENSOR_DEVICE_ATTR(temp4_min_alarm, S_IRUGO,
809 show_temp_min_alarm, NULL, 3);
810static SENSOR_DEVICE_ATTR(temp5_min_alarm, S_IRUGO,
811 show_temp_min_alarm, NULL, 4);
812static SENSOR_DEVICE_ATTR(temp6_min_alarm, S_IRUGO,
813 show_temp_min_alarm, NULL, 5);
814
815static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO,
816 show_temp_max_alarm, NULL, 0);
817static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO,
818 show_temp_max_alarm, NULL, 1);
819static SENSOR_DEVICE_ATTR(temp3_max_alarm, S_IRUGO,
820 show_temp_max_alarm, NULL, 2);
821static SENSOR_DEVICE_ATTR(temp4_max_alarm, S_IRUGO,
822 show_temp_max_alarm, NULL, 3);
823static SENSOR_DEVICE_ATTR(temp5_max_alarm, S_IRUGO,
824 show_temp_max_alarm, NULL, 4);
825static SENSOR_DEVICE_ATTR(temp6_max_alarm, S_IRUGO,
826 show_temp_max_alarm, NULL, 5);
827
828static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO,
829 show_temp_crit_alarm, NULL, 0);
830static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO,
831 show_temp_crit_alarm, NULL, 1);
832static SENSOR_DEVICE_ATTR(temp3_crit_alarm, S_IRUGO,
833 show_temp_crit_alarm, NULL, 2);
834static SENSOR_DEVICE_ATTR(temp4_crit_alarm, S_IRUGO,
835 show_temp_crit_alarm, NULL, 3);
836static SENSOR_DEVICE_ATTR(temp5_crit_alarm, S_IRUGO,
837 show_temp_crit_alarm, NULL, 4);
838static SENSOR_DEVICE_ATTR(temp6_crit_alarm, S_IRUGO,
839 show_temp_crit_alarm, NULL, 5);
840
841static SENSOR_DEVICE_ATTR(temp1_fault, S_IRUGO, show_temp_fault, NULL, 0);
842static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_temp_fault, NULL, 1);
843static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_temp_fault, NULL, 2);
844static SENSOR_DEVICE_ATTR(temp4_fault, S_IRUGO, show_temp_fault, NULL, 3);
845static SENSOR_DEVICE_ATTR(temp5_fault, S_IRUGO, show_temp_fault, NULL, 4);
846static SENSOR_DEVICE_ATTR(temp6_fault, S_IRUGO, show_temp_fault, NULL, 5);
847
848static struct attribute *pc87427_attributes_temp[6][10] = {
849 {
850 &sensor_dev_attr_temp1_input.dev_attr.attr,
851 &sensor_dev_attr_temp1_min.dev_attr.attr,
852 &sensor_dev_attr_temp1_max.dev_attr.attr,
853 &sensor_dev_attr_temp1_crit.dev_attr.attr,
854 &sensor_dev_attr_temp1_type.dev_attr.attr,
855 &sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
856 &sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
857 &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr,
858 &sensor_dev_attr_temp1_fault.dev_attr.attr,
859 NULL
860 }, {
861 &sensor_dev_attr_temp2_input.dev_attr.attr,
862 &sensor_dev_attr_temp2_min.dev_attr.attr,
863 &sensor_dev_attr_temp2_max.dev_attr.attr,
864 &sensor_dev_attr_temp2_crit.dev_attr.attr,
865 &sensor_dev_attr_temp2_type.dev_attr.attr,
866 &sensor_dev_attr_temp2_min_alarm.dev_attr.attr,
867 &sensor_dev_attr_temp2_max_alarm.dev_attr.attr,
868 &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr,
869 &sensor_dev_attr_temp2_fault.dev_attr.attr,
870 NULL
871 }, {
872 &sensor_dev_attr_temp3_input.dev_attr.attr,
873 &sensor_dev_attr_temp3_min.dev_attr.attr,
874 &sensor_dev_attr_temp3_max.dev_attr.attr,
875 &sensor_dev_attr_temp3_crit.dev_attr.attr,
876 &sensor_dev_attr_temp3_type.dev_attr.attr,
877 &sensor_dev_attr_temp3_min_alarm.dev_attr.attr,
878 &sensor_dev_attr_temp3_max_alarm.dev_attr.attr,
879 &sensor_dev_attr_temp3_crit_alarm.dev_attr.attr,
880 &sensor_dev_attr_temp3_fault.dev_attr.attr,
881 NULL
882 }, {
883 &sensor_dev_attr_temp4_input.dev_attr.attr,
884 &sensor_dev_attr_temp4_min.dev_attr.attr,
885 &sensor_dev_attr_temp4_max.dev_attr.attr,
886 &sensor_dev_attr_temp4_crit.dev_attr.attr,
887 &sensor_dev_attr_temp4_type.dev_attr.attr,
888 &sensor_dev_attr_temp4_min_alarm.dev_attr.attr,
889 &sensor_dev_attr_temp4_max_alarm.dev_attr.attr,
890 &sensor_dev_attr_temp4_crit_alarm.dev_attr.attr,
891 &sensor_dev_attr_temp4_fault.dev_attr.attr,
892 NULL
893 }, {
894 &sensor_dev_attr_temp5_input.dev_attr.attr,
895 &sensor_dev_attr_temp5_min.dev_attr.attr,
896 &sensor_dev_attr_temp5_max.dev_attr.attr,
897 &sensor_dev_attr_temp5_crit.dev_attr.attr,
898 &sensor_dev_attr_temp5_type.dev_attr.attr,
899 &sensor_dev_attr_temp5_min_alarm.dev_attr.attr,
900 &sensor_dev_attr_temp5_max_alarm.dev_attr.attr,
901 &sensor_dev_attr_temp5_crit_alarm.dev_attr.attr,
902 &sensor_dev_attr_temp5_fault.dev_attr.attr,
903 NULL
904 }, {
905 &sensor_dev_attr_temp6_input.dev_attr.attr,
906 &sensor_dev_attr_temp6_min.dev_attr.attr,
907 &sensor_dev_attr_temp6_max.dev_attr.attr,
908 &sensor_dev_attr_temp6_crit.dev_attr.attr,
909 &sensor_dev_attr_temp6_type.dev_attr.attr,
910 &sensor_dev_attr_temp6_min_alarm.dev_attr.attr,
911 &sensor_dev_attr_temp6_max_alarm.dev_attr.attr,
912 &sensor_dev_attr_temp6_crit_alarm.dev_attr.attr,
913 &sensor_dev_attr_temp6_fault.dev_attr.attr,
914 NULL
915 }
916};
917
918static const struct attribute_group pc87427_group_temp[6] = {
919 { .attrs = pc87427_attributes_temp[0] },
920 { .attrs = pc87427_attributes_temp[1] },
921 { .attrs = pc87427_attributes_temp[2] },
922 { .attrs = pc87427_attributes_temp[3] },
923 { .attrs = pc87427_attributes_temp[4] },
924 { .attrs = pc87427_attributes_temp[5] },
925};
926
380static ssize_t show_name(struct device *dev, struct device_attribute 927static ssize_t show_name(struct device *dev, struct device_attribute
381 *devattr, char *buf) 928 *devattr, char *buf)
382{ 929{
@@ -391,8 +938,49 @@ static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
391 * Device detection, attach and detach 938 * Device detection, attach and detach
392 */ 939 */
393 940
941static void pc87427_release_regions(struct platform_device *pdev, int count)
942{
943 struct resource *res;
944 int i;
945
946 for (i = 0; i < count; i++) {
947 res = platform_get_resource(pdev, IORESOURCE_IO, i);
948 release_region(res->start, resource_size(res));
949 }
950}
951
952static int __devinit pc87427_request_regions(struct platform_device *pdev,
953 int count)
954{
955 struct resource *res;
956 int i, err = 0;
957
958 for (i = 0; i < count; i++) {
959 res = platform_get_resource(pdev, IORESOURCE_IO, i);
960 if (!res) {
961 err = -ENOENT;
962 dev_err(&pdev->dev, "Missing resource #%d\n", i);
963 break;
964 }
965 if (!request_region(res->start, resource_size(res), DRVNAME)) {
966 err = -EBUSY;
967 dev_err(&pdev->dev,
968 "Failed to request region 0x%lx-0x%lx\n",
969 (unsigned long)res->start,
970 (unsigned long)res->end);
971 break;
972 }
973 }
974
975 if (err && i)
976 pc87427_release_regions(pdev, i);
977
978 return err;
979}
980
394static void __devinit pc87427_init_device(struct device *dev) 981static void __devinit pc87427_init_device(struct device *dev)
395{ 982{
983 struct pc87427_sio_data *sio_data = dev->platform_data;
396 struct pc87427_data *data = dev_get_drvdata(dev); 984 struct pc87427_data *data = dev_get_drvdata(dev);
397 int i; 985 int i;
398 u8 reg; 986 u8 reg;
@@ -400,10 +988,12 @@ static void __devinit pc87427_init_device(struct device *dev)
400 /* The FMC module should be ready */ 988 /* The FMC module should be ready */
401 reg = pc87427_read8(data, LD_FAN, PC87427_REG_BANK); 989 reg = pc87427_read8(data, LD_FAN, PC87427_REG_BANK);
402 if (!(reg & 0x80)) 990 if (!(reg & 0x80))
403 dev_warn(dev, "FMC module not ready!\n"); 991 dev_warn(dev, "%s module not ready!\n", "FMC");
404 992
405 /* Check which fans are enabled */ 993 /* Check which fans are enabled */
406 for (i = 0; i < 8; i++) { 994 for (i = 0; i < 8; i++) {
995 if (!(sio_data->has_fanin & (1 << i))) /* Not wired */
996 continue;
407 reg = pc87427_read8_bank(data, LD_FAN, BANK_FM(i), 997 reg = pc87427_read8_bank(data, LD_FAN, BANK_FM(i),
408 PC87427_REG_FAN_STATUS); 998 PC87427_REG_FAN_STATUS);
409 if (reg & FAN_STATUS_MONEN) 999 if (reg & FAN_STATUS_MONEN)
@@ -411,37 +1001,93 @@ static void __devinit pc87427_init_device(struct device *dev)
411 } 1001 }
412 1002
413 if (!data->fan_enabled) { 1003 if (!data->fan_enabled) {
414 dev_dbg(dev, "Enabling all fan inputs\n"); 1004 dev_dbg(dev, "Enabling monitoring of all fans\n");
415 for (i = 0; i < 8; i++) 1005 for (i = 0; i < 8; i++) {
1006 if (!(sio_data->has_fanin & (1 << i))) /* Not wired */
1007 continue;
416 pc87427_write8_bank(data, LD_FAN, BANK_FM(i), 1008 pc87427_write8_bank(data, LD_FAN, BANK_FM(i),
417 PC87427_REG_FAN_STATUS, 1009 PC87427_REG_FAN_STATUS,
418 FAN_STATUS_MONEN); 1010 FAN_STATUS_MONEN);
419 data->fan_enabled = 0xff; 1011 }
1012 data->fan_enabled = sio_data->has_fanin;
1013 }
1014
1015 /* Check which PWM outputs are enabled */
1016 for (i = 0; i < 4; i++) {
1017 if (!(sio_data->has_fanout & (1 << i))) /* Not wired */
1018 continue;
1019 reg = pc87427_read8_bank(data, LD_FAN, BANK_FC(i),
1020 PC87427_REG_PWM_ENABLE);
1021 if (reg & PWM_ENABLE_CTLEN)
1022 data->pwm_enabled |= (1 << i);
1023
1024 /* We don't expose an interface to reconfigure the automatic
1025 fan control mode, so only allow to return to this mode if
1026 it was originally set. */
1027 if ((reg & PWM_ENABLE_MODE_MASK) == PWM_MODE_AUTO) {
1028 dev_dbg(dev, "PWM%d is in automatic control mode\n",
1029 i + 1);
1030 data->pwm_auto_ok |= (1 << i);
1031 }
1032 }
1033
1034 /* The HMC module should be ready */
1035 reg = pc87427_read8(data, LD_TEMP, PC87427_REG_BANK);
1036 if (!(reg & 0x80))
1037 dev_warn(dev, "%s module not ready!\n", "HMC");
1038
1039 /* Check which temperature channels are enabled */
1040 for (i = 0; i < 6; i++) {
1041 reg = pc87427_read8_bank(data, LD_TEMP, BANK_TM(i),
1042 PC87427_REG_TEMP_STATUS);
1043 if (reg & TEMP_STATUS_CHANEN)
1044 data->temp_enabled |= (1 << i);
1045 }
1046}
1047
1048static void pc87427_remove_files(struct device *dev)
1049{
1050 struct pc87427_data *data = dev_get_drvdata(dev);
1051 int i;
1052
1053 device_remove_file(dev, &dev_attr_name);
1054 for (i = 0; i < 8; i++) {
1055 if (!(data->fan_enabled & (1 << i)))
1056 continue;
1057 sysfs_remove_group(&dev->kobj, &pc87427_group_fan[i]);
1058 }
1059 for (i = 0; i < 4; i++) {
1060 if (!(data->pwm_enabled & (1 << i)))
1061 continue;
1062 sysfs_remove_group(&dev->kobj, &pc87427_group_pwm[i]);
1063 }
1064 for (i = 0; i < 6; i++) {
1065 if (!(data->temp_enabled & (1 << i)))
1066 continue;
1067 sysfs_remove_group(&dev->kobj, &pc87427_group_temp[i]);
420 } 1068 }
421} 1069}
422 1070
423static int __devinit pc87427_probe(struct platform_device *pdev) 1071static int __devinit pc87427_probe(struct platform_device *pdev)
424{ 1072{
1073 struct pc87427_sio_data *sio_data = pdev->dev.platform_data;
425 struct pc87427_data *data; 1074 struct pc87427_data *data;
426 struct resource *res; 1075 int i, err, res_count;
427 int i, err;
428 1076
429 if (!(data = kzalloc(sizeof(struct pc87427_data), GFP_KERNEL))) { 1077 data = kzalloc(sizeof(struct pc87427_data), GFP_KERNEL);
1078 if (!data) {
430 err = -ENOMEM; 1079 err = -ENOMEM;
431 printk(KERN_ERR DRVNAME ": Out of memory\n"); 1080 printk(KERN_ERR DRVNAME ": Out of memory\n");
432 goto exit; 1081 goto exit;
433 } 1082 }
434 1083
435 /* This will need to be revisited when we add support for 1084 data->address[0] = sio_data->address[0];
436 temperature and voltage monitoring. */ 1085 data->address[1] = sio_data->address[1];
437 res = platform_get_resource(pdev, IORESOURCE_IO, 0); 1086 res_count = (data->address[0] != 0) + (data->address[1] != 0);
438 if (!request_region(res->start, resource_size(res), DRVNAME)) { 1087
439 err = -EBUSY; 1088 err = pc87427_request_regions(pdev, res_count);
440 dev_err(&pdev->dev, "Failed to request region 0x%lx-0x%lx\n", 1089 if (err)
441 (unsigned long)res->start, (unsigned long)res->end);
442 goto exit_kfree; 1090 goto exit_kfree;
443 }
444 data->address[0] = res->start;
445 1091
446 mutex_init(&data->lock); 1092 mutex_init(&data->lock);
447 data->name = "pc87427"; 1093 data->name = "pc87427";
@@ -449,13 +1095,31 @@ static int __devinit pc87427_probe(struct platform_device *pdev)
449 pc87427_init_device(&pdev->dev); 1095 pc87427_init_device(&pdev->dev);
450 1096
451 /* Register sysfs hooks */ 1097 /* Register sysfs hooks */
452 if ((err = device_create_file(&pdev->dev, &dev_attr_name))) 1098 err = device_create_file(&pdev->dev, &dev_attr_name);
1099 if (err)
453 goto exit_release_region; 1100 goto exit_release_region;
454 for (i = 0; i < 8; i++) { 1101 for (i = 0; i < 8; i++) {
455 if (!(data->fan_enabled & (1 << i))) 1102 if (!(data->fan_enabled & (1 << i)))
456 continue; 1103 continue;
457 if ((err = sysfs_create_group(&pdev->dev.kobj, 1104 err = sysfs_create_group(&pdev->dev.kobj,
458 &pc87427_group_fan[i]))) 1105 &pc87427_group_fan[i]);
1106 if (err)
1107 goto exit_remove_files;
1108 }
1109 for (i = 0; i < 4; i++) {
1110 if (!(data->pwm_enabled & (1 << i)))
1111 continue;
1112 err = sysfs_create_group(&pdev->dev.kobj,
1113 &pc87427_group_pwm[i]);
1114 if (err)
1115 goto exit_remove_files;
1116 }
1117 for (i = 0; i < 6; i++) {
1118 if (!(data->temp_enabled & (1 << i)))
1119 continue;
1120 err = sysfs_create_group(&pdev->dev.kobj,
1121 &pc87427_group_temp[i]);
1122 if (err)
459 goto exit_remove_files; 1123 goto exit_remove_files;
460 } 1124 }
461 1125
@@ -469,13 +1133,9 @@ static int __devinit pc87427_probe(struct platform_device *pdev)
469 return 0; 1133 return 0;
470 1134
471exit_remove_files: 1135exit_remove_files:
472 for (i = 0; i < 8; i++) { 1136 pc87427_remove_files(&pdev->dev);
473 if (!(data->fan_enabled & (1 << i)))
474 continue;
475 sysfs_remove_group(&pdev->dev.kobj, &pc87427_group_fan[i]);
476 }
477exit_release_region: 1137exit_release_region:
478 release_region(res->start, resource_size(res)); 1138 pc87427_release_regions(pdev, res_count);
479exit_kfree: 1139exit_kfree:
480 platform_set_drvdata(pdev, NULL); 1140 platform_set_drvdata(pdev, NULL);
481 kfree(data); 1141 kfree(data);
@@ -486,21 +1146,16 @@ exit:
486static int __devexit pc87427_remove(struct platform_device *pdev) 1146static int __devexit pc87427_remove(struct platform_device *pdev)
487{ 1147{
488 struct pc87427_data *data = platform_get_drvdata(pdev); 1148 struct pc87427_data *data = platform_get_drvdata(pdev);
489 struct resource *res; 1149 int res_count;
490 int i; 1150
1151 res_count = (data->address[0] != 0) + (data->address[1] != 0);
491 1152
492 hwmon_device_unregister(data->hwmon_dev); 1153 hwmon_device_unregister(data->hwmon_dev);
493 device_remove_file(&pdev->dev, &dev_attr_name); 1154 pc87427_remove_files(&pdev->dev);
494 for (i = 0; i < 8; i++) {
495 if (!(data->fan_enabled & (1 << i)))
496 continue;
497 sysfs_remove_group(&pdev->dev.kobj, &pc87427_group_fan[i]);
498 }
499 platform_set_drvdata(pdev, NULL); 1155 platform_set_drvdata(pdev, NULL);
500 kfree(data); 1156 kfree(data);
501 1157
502 res = platform_get_resource(pdev, IORESOURCE_IO, 0); 1158 pc87427_release_regions(pdev, res_count);
503 release_region(res->start, resource_size(res));
504 1159
505 return 0; 1160 return 0;
506} 1161}
@@ -515,34 +1170,50 @@ static struct platform_driver pc87427_driver = {
515 .remove = __devexit_p(pc87427_remove), 1170 .remove = __devexit_p(pc87427_remove),
516}; 1171};
517 1172
518static int __init pc87427_device_add(unsigned short address) 1173static int __init pc87427_device_add(const struct pc87427_sio_data *sio_data)
519{ 1174{
520 struct resource res = { 1175 struct resource res[2] = {
521 .start = address, 1176 { .flags = IORESOURCE_IO },
522 .end = address + REGION_LENGTH - 1, 1177 { .flags = IORESOURCE_IO },
523 .name = logdev_str[0],
524 .flags = IORESOURCE_IO,
525 }; 1178 };
526 int err; 1179 int err, i, res_count;
527 1180
528 err = acpi_check_resource_conflict(&res); 1181 res_count = 0;
529 if (err) 1182 for (i = 0; i < 2; i++) {
530 goto exit; 1183 if (!sio_data->address[i])
1184 continue;
1185 res[res_count].start = sio_data->address[i];
1186 res[res_count].end = sio_data->address[i] + REGION_LENGTH - 1;
1187 res[res_count].name = logdev_str[i];
531 1188
532 pdev = platform_device_alloc(DRVNAME, address); 1189 err = acpi_check_resource_conflict(&res[res_count]);
1190 if (err)
1191 goto exit;
1192
1193 res_count++;
1194 }
1195
1196 pdev = platform_device_alloc(DRVNAME, res[0].start);
533 if (!pdev) { 1197 if (!pdev) {
534 err = -ENOMEM; 1198 err = -ENOMEM;
535 printk(KERN_ERR DRVNAME ": Device allocation failed\n"); 1199 printk(KERN_ERR DRVNAME ": Device allocation failed\n");
536 goto exit; 1200 goto exit;
537 } 1201 }
538 1202
539 err = platform_device_add_resources(pdev, &res, 1); 1203 err = platform_device_add_resources(pdev, res, res_count);
540 if (err) { 1204 if (err) {
541 printk(KERN_ERR DRVNAME ": Device resource addition failed " 1205 printk(KERN_ERR DRVNAME ": Device resource addition failed "
542 "(%d)\n", err); 1206 "(%d)\n", err);
543 goto exit_device_put; 1207 goto exit_device_put;
544 } 1208 }
545 1209
1210 err = platform_device_add_data(pdev, sio_data,
1211 sizeof(struct pc87427_sio_data));
1212 if (err) {
1213 printk(KERN_ERR DRVNAME ": Platform data allocation failed\n");
1214 goto exit_device_put;
1215 }
1216
546 err = platform_device_add(pdev); 1217 err = platform_device_add(pdev);
547 if (err) { 1218 if (err) {
548 printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n", 1219 printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n",
@@ -558,9 +1229,10 @@ exit:
558 return err; 1229 return err;
559} 1230}
560 1231
561static int __init pc87427_find(int sioaddr, unsigned short *address) 1232static int __init pc87427_find(int sioaddr, struct pc87427_sio_data *sio_data)
562{ 1233{
563 u16 val; 1234 u16 val;
1235 u8 cfg, cfg_b;
564 int i, err = 0; 1236 int i, err = 0;
565 1237
566 /* Identify device */ 1238 /* Identify device */
@@ -571,7 +1243,7 @@ static int __init pc87427_find(int sioaddr, unsigned short *address)
571 } 1243 }
572 1244
573 for (i = 0; i < 2; i++) { 1245 for (i = 0; i < 2; i++) {
574 address[i] = 0; 1246 sio_data->address[i] = 0;
575 /* Select logical device */ 1247 /* Select logical device */
576 superio_outb(sioaddr, SIOREG_LDSEL, logdev[i]); 1248 superio_outb(sioaddr, SIOREG_LDSEL, logdev[i]);
577 1249
@@ -596,9 +1268,58 @@ static int __init pc87427_find(int sioaddr, unsigned short *address)
596 "for logical device 0x%02x\n", logdev[i]); 1268 "for logical device 0x%02x\n", logdev[i]);
597 continue; 1269 continue;
598 } 1270 }
599 address[i] = val; 1271 sio_data->address[i] = val;
600 } 1272 }
601 1273
1274 /* No point in loading the driver if everything is disabled */
1275 if (!sio_data->address[0] && !sio_data->address[1]) {
1276 err = -ENODEV;
1277 goto exit;
1278 }
1279
1280 /* Check which fan inputs are wired */
1281 sio_data->has_fanin = (1 << 2) | (1 << 3); /* FANIN2, FANIN3 */
1282
1283 cfg = superio_inb(sioaddr, SIOREG_CF2);
1284 if (!(cfg & (1 << 3)))
1285 sio_data->has_fanin |= (1 << 0); /* FANIN0 */
1286 if (!(cfg & (1 << 2)))
1287 sio_data->has_fanin |= (1 << 4); /* FANIN4 */
1288
1289 cfg = superio_inb(sioaddr, SIOREG_CFD);
1290 if (!(cfg & (1 << 0)))
1291 sio_data->has_fanin |= (1 << 1); /* FANIN1 */
1292
1293 cfg = superio_inb(sioaddr, SIOREG_CF4);
1294 if (!(cfg & (1 << 0)))
1295 sio_data->has_fanin |= (1 << 7); /* FANIN7 */
1296 cfg_b = superio_inb(sioaddr, SIOREG_CFB);
1297 if (!(cfg & (1 << 1)) && (cfg_b & (1 << 3)))
1298 sio_data->has_fanin |= (1 << 5); /* FANIN5 */
1299 cfg = superio_inb(sioaddr, SIOREG_CF3);
1300 if ((cfg & (1 << 3)) && !(cfg_b & (1 << 5)))
1301 sio_data->has_fanin |= (1 << 6); /* FANIN6 */
1302
1303 /* Check which fan outputs are wired */
1304 sio_data->has_fanout = (1 << 0); /* FANOUT0 */
1305 if (cfg_b & (1 << 0))
1306 sio_data->has_fanout |= (1 << 3); /* FANOUT3 */
1307
1308 cfg = superio_inb(sioaddr, SIOREG_CFC);
1309 if (!(cfg & (1 << 4))) {
1310 if (cfg_b & (1 << 1))
1311 sio_data->has_fanout |= (1 << 1); /* FANOUT1 */
1312 if (cfg_b & (1 << 2))
1313 sio_data->has_fanout |= (1 << 2); /* FANOUT2 */
1314 }
1315
1316 /* FANOUT1 and FANOUT2 can each be routed to 2 different pins */
1317 cfg = superio_inb(sioaddr, SIOREG_CF5);
1318 if (cfg & (1 << 6))
1319 sio_data->has_fanout |= (1 << 1); /* FANOUT1 */
1320 if (cfg & (1 << 5))
1321 sio_data->has_fanout |= (1 << 2); /* FANOUT2 */
1322
602exit: 1323exit:
603 superio_exit(sioaddr); 1324 superio_exit(sioaddr);
604 return err; 1325 return err;
@@ -607,15 +1328,10 @@ exit:
607static int __init pc87427_init(void) 1328static int __init pc87427_init(void)
608{ 1329{
609 int err; 1330 int err;
610 unsigned short address[2]; 1331 struct pc87427_sio_data sio_data;
611
612 if (pc87427_find(0x2e, address)
613 && pc87427_find(0x4e, address))
614 return -ENODEV;
615 1332
616 /* For now the driver only handles fans so we only care about the 1333 if (pc87427_find(0x2e, &sio_data)
617 first address. */ 1334 && pc87427_find(0x4e, &sio_data))
618 if (!address[0])
619 return -ENODEV; 1335 return -ENODEV;
620 1336
621 err = platform_driver_register(&pc87427_driver); 1337 err = platform_driver_register(&pc87427_driver);
@@ -623,7 +1339,7 @@ static int __init pc87427_init(void)
623 goto exit; 1339 goto exit;
624 1340
625 /* Sets global pdev as a side effect */ 1341 /* Sets global pdev as a side effect */
626 err = pc87427_device_add(address[0]); 1342 err = pc87427_device_add(&sio_data);
627 if (err) 1343 if (err)
628 goto exit_driver; 1344 goto exit_driver;
629 1345
diff --git a/drivers/hwmon/smm665.c b/drivers/hwmon/smm665.c
new file mode 100644
index 000000000000..425df5bccd45
--- /dev/null
+++ b/drivers/hwmon/smm665.c
@@ -0,0 +1,743 @@
1/*
2 * Driver for SMM665 Power Controller / Monitor
3 *
4 * Copyright (C) 2010 Ericsson AB.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This driver should also work for SMM465, SMM764, and SMM766, but is untested
11 * for those chips. Only monitoring functionality is implemented.
12 *
13 * Datasheets:
14 * http://www.summitmicro.com/prod_select/summary/SMM665/SMM665B_2089_20.pdf
15 * http://www.summitmicro.com/prod_select/summary/SMM766B/SMM766B_2122.pdf
16 */
17
18#include <linux/kernel.h>
19#include <linux/module.h>
20#include <linux/init.h>
21#include <linux/err.h>
22#include <linux/slab.h>
23#include <linux/i2c.h>
24#include <linux/hwmon.h>
25#include <linux/hwmon-sysfs.h>
26#include <linux/delay.h>
27
28/* Internal reference voltage (VREF, x 1000 */
29#define SMM665_VREF_ADC_X1000 1250
30
31/* module parameters */
32static int vref = SMM665_VREF_ADC_X1000;
33module_param(vref, int, 0);
34MODULE_PARM_DESC(vref, "Reference voltage in mV");
35
36enum chips { smm465, smm665, smm665c, smm764, smm766 };
37
38/*
39 * ADC channel addresses
40 */
41#define SMM665_MISC16_ADC_DATA_A 0x00
42#define SMM665_MISC16_ADC_DATA_B 0x01
43#define SMM665_MISC16_ADC_DATA_C 0x02
44#define SMM665_MISC16_ADC_DATA_D 0x03
45#define SMM665_MISC16_ADC_DATA_E 0x04
46#define SMM665_MISC16_ADC_DATA_F 0x05
47#define SMM665_MISC16_ADC_DATA_VDD 0x06
48#define SMM665_MISC16_ADC_DATA_12V 0x07
49#define SMM665_MISC16_ADC_DATA_INT_TEMP 0x08
50#define SMM665_MISC16_ADC_DATA_AIN1 0x09
51#define SMM665_MISC16_ADC_DATA_AIN2 0x0a
52
53/*
54 * Command registers
55 */
56#define SMM665_MISC8_CMD_STS 0x80
57#define SMM665_MISC8_STATUS1 0x81
58#define SMM665_MISC8_STATUSS2 0x82
59#define SMM665_MISC8_IO_POLARITY 0x83
60#define SMM665_MISC8_PUP_POLARITY 0x84
61#define SMM665_MISC8_ADOC_STATUS1 0x85
62#define SMM665_MISC8_ADOC_STATUS2 0x86
63#define SMM665_MISC8_WRITE_PROT 0x87
64#define SMM665_MISC8_STS_TRACK 0x88
65
66/*
67 * Configuration registers and register groups
68 */
69#define SMM665_ADOC_ENABLE 0x0d
70#define SMM665_LIMIT_BASE 0x80 /* First limit register */
71
72/*
73 * Limit register bit masks
74 */
75#define SMM665_TRIGGER_RST 0x8000
76#define SMM665_TRIGGER_HEALTHY 0x4000
77#define SMM665_TRIGGER_POWEROFF 0x2000
78#define SMM665_TRIGGER_SHUTDOWN 0x1000
79#define SMM665_ADC_MASK 0x03ff
80
81#define smm665_is_critical(lim) ((lim) & (SMM665_TRIGGER_RST \
82 | SMM665_TRIGGER_POWEROFF \
83 | SMM665_TRIGGER_SHUTDOWN))
84/*
85 * Fault register bit definitions
86 * Values are merged from status registers 1/2,
87 * with status register 1 providing the upper 8 bits.
88 */
89#define SMM665_FAULT_A 0x0001
90#define SMM665_FAULT_B 0x0002
91#define SMM665_FAULT_C 0x0004
92#define SMM665_FAULT_D 0x0008
93#define SMM665_FAULT_E 0x0010
94#define SMM665_FAULT_F 0x0020
95#define SMM665_FAULT_VDD 0x0040
96#define SMM665_FAULT_12V 0x0080
97#define SMM665_FAULT_TEMP 0x0100
98#define SMM665_FAULT_AIN1 0x0200
99#define SMM665_FAULT_AIN2 0x0400
100
101/*
102 * I2C Register addresses
103 *
104 * The configuration register needs to be the configured base register.
105 * The command/status register address is derived from it.
106 */
107#define SMM665_REGMASK 0x78
108#define SMM665_CMDREG_BASE 0x48
109#define SMM665_CONFREG_BASE 0x50
110
111/*
112 * Equations given by chip manufacturer to calculate voltage/temperature values
113 * vref = Reference voltage on VREF_ADC pin (module parameter)
114 * adc = 10bit ADC value read back from registers
115 */
116
117/* Voltage A-F and VDD */
118#define SMM665_VMON_ADC_TO_VOLTS(adc) ((adc) * vref / 256)
119
120/* Voltage 12VIN */
121#define SMM665_12VIN_ADC_TO_VOLTS(adc) ((adc) * vref * 3 / 256)
122
123/* Voltage AIN1, AIN2 */
124#define SMM665_AIN_ADC_TO_VOLTS(adc) ((adc) * vref / 512)
125
126/* Temp Sensor */
127#define SMM665_TEMP_ADC_TO_CELSIUS(adc) ((adc) <= 511) ? \
128 ((int)(adc) * 1000 / 4) : \
129 (((int)(adc) - 0x400) * 1000 / 4)
130
131#define SMM665_NUM_ADC 11
132
133/*
134 * Chip dependent ADC conversion time, in uS
135 */
136#define SMM665_ADC_WAIT_SMM665 70
137#define SMM665_ADC_WAIT_SMM766 185
138
139struct smm665_data {
140 enum chips type;
141 int conversion_time; /* ADC conversion time */
142 struct device *hwmon_dev;
143 struct mutex update_lock;
144 bool valid;
145 unsigned long last_updated; /* in jiffies */
146 u16 adc[SMM665_NUM_ADC]; /* adc values (raw) */
147 u16 faults; /* fault status */
148 /* The following values are in mV */
149 int critical_min_limit[SMM665_NUM_ADC];
150 int alarm_min_limit[SMM665_NUM_ADC];
151 int critical_max_limit[SMM665_NUM_ADC];
152 int alarm_max_limit[SMM665_NUM_ADC];
153 struct i2c_client *cmdreg;
154};
155
156/*
157 * smm665_read16()
158 *
159 * Read 16 bit value from <reg>, <reg+1>. Upper 8 bits are in <reg>.
160 */
161static int smm665_read16(struct i2c_client *client, int reg)
162{
163 int rv, val;
164
165 rv = i2c_smbus_read_byte_data(client, reg);
166 if (rv < 0)
167 return rv;
168 val = rv << 8;
169 rv = i2c_smbus_read_byte_data(client, reg + 1);
170 if (rv < 0)
171 return rv;
172 val |= rv;
173 return val;
174}
175
176/*
177 * Read adc value.
178 */
179static int smm665_read_adc(struct smm665_data *data, int adc)
180{
181 struct i2c_client *client = data->cmdreg;
182 int rv;
183 int radc;
184
185 /*
186 * Algorithm for reading ADC, per SMM665 datasheet
187 *
188 * {[S][addr][W][Ack]} {[offset][Ack]} {[S][addr][R][Nack]}
189 * [wait conversion time]
190 * {[S][addr][R][Ack]} {[datahi][Ack]} {[datalo][Ack][P]}
191 *
192 * To implement the first part of this exchange,
193 * do a full read transaction and expect a failure/Nack.
194 * This sets up the address pointer on the SMM665
195 * and starts the ADC conversion.
196 * Then do a two-byte read transaction.
197 */
198 rv = i2c_smbus_read_byte_data(client, adc << 3);
199 if (rv != -ENXIO) {
200 /*
201 * We expect ENXIO to reflect NACK
202 * (per Documentation/i2c/fault-codes).
203 * Everything else is an error.
204 */
205 dev_dbg(&client->dev,
206 "Unexpected return code %d when setting ADC index", rv);
207 return (rv < 0) ? rv : -EIO;
208 }
209
210 udelay(data->conversion_time);
211
212 /*
213 * Now read two bytes.
214 *
215 * Neither i2c_smbus_read_byte() nor
216 * i2c_smbus_read_block_data() worked here,
217 * so use i2c_smbus_read_word_data() instead.
218 * We could also try to use i2c_master_recv(),
219 * but that is not always supported.
220 */
221 rv = i2c_smbus_read_word_data(client, 0);
222 if (rv < 0) {
223 dev_dbg(&client->dev, "Failed to read ADC value: error %d", rv);
224 return -1;
225 }
226 /*
227 * Validate/verify readback adc channel (in bit 11..14).
228 * High byte is in lower 8 bit of rv, so only shift by 3.
229 */
230 radc = (rv >> 3) & 0x0f;
231 if (radc != adc) {
232 dev_dbg(&client->dev, "Unexpected RADC: Expected %d got %d",
233 adc, radc);
234 return -EIO;
235 }
236 /*
237 * Chip replies with H/L, while SMBus expects L/H.
238 * Thus, byte order is reversed, and we have to swap
239 * the result.
240 */
241 rv = swab16(rv) & SMM665_ADC_MASK;
242
243 return rv;
244}
245
246static struct smm665_data *smm665_update_device(struct device *dev)
247{
248 struct i2c_client *client = to_i2c_client(dev);
249 struct smm665_data *data = i2c_get_clientdata(client);
250 struct smm665_data *ret = data;
251
252 mutex_lock(&data->update_lock);
253
254 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
255 int i, val;
256
257 /*
258 * read status registers
259 */
260 val = smm665_read16(client, SMM665_MISC8_STATUS1);
261 if (unlikely(val < 0)) {
262 ret = ERR_PTR(val);
263 goto abort;
264 }
265 data->faults = val;
266
267 /* Read adc registers */
268 for (i = 0; i < SMM665_NUM_ADC; i++) {
269 val = smm665_read_adc(data, i);
270 if (unlikely(val < 0)) {
271 ret = ERR_PTR(val);
272 goto abort;
273 }
274 data->adc[i] = val;
275 }
276 data->last_updated = jiffies;
277 data->valid = 1;
278 }
279abort:
280 mutex_unlock(&data->update_lock);
281 return ret;
282}
283
284/* Return converted value from given adc */
285static int smm665_convert(u16 adcval, int index)
286{
287 int val = 0;
288
289 switch (index) {
290 case SMM665_MISC16_ADC_DATA_12V:
291 val = SMM665_12VIN_ADC_TO_VOLTS(adcval & SMM665_ADC_MASK);
292 break;
293
294 case SMM665_MISC16_ADC_DATA_VDD:
295 case SMM665_MISC16_ADC_DATA_A:
296 case SMM665_MISC16_ADC_DATA_B:
297 case SMM665_MISC16_ADC_DATA_C:
298 case SMM665_MISC16_ADC_DATA_D:
299 case SMM665_MISC16_ADC_DATA_E:
300 case SMM665_MISC16_ADC_DATA_F:
301 val = SMM665_VMON_ADC_TO_VOLTS(adcval & SMM665_ADC_MASK);
302 break;
303
304 case SMM665_MISC16_ADC_DATA_AIN1:
305 case SMM665_MISC16_ADC_DATA_AIN2:
306 val = SMM665_AIN_ADC_TO_VOLTS(adcval & SMM665_ADC_MASK);
307 break;
308
309 case SMM665_MISC16_ADC_DATA_INT_TEMP:
310 val = SMM665_TEMP_ADC_TO_CELSIUS(adcval & SMM665_ADC_MASK);
311 break;
312
313 default:
314 /* If we get here, the developer messed up */
315 WARN_ON_ONCE(1);
316 break;
317 }
318
319 return val;
320}
321
322static int smm665_get_min(struct device *dev, int index)
323{
324 struct i2c_client *client = to_i2c_client(dev);
325 struct smm665_data *data = i2c_get_clientdata(client);
326
327 return data->alarm_min_limit[index];
328}
329
330static int smm665_get_max(struct device *dev, int index)
331{
332 struct i2c_client *client = to_i2c_client(dev);
333 struct smm665_data *data = i2c_get_clientdata(client);
334
335 return data->alarm_max_limit[index];
336}
337
338static int smm665_get_lcrit(struct device *dev, int index)
339{
340 struct i2c_client *client = to_i2c_client(dev);
341 struct smm665_data *data = i2c_get_clientdata(client);
342
343 return data->critical_min_limit[index];
344}
345
346static int smm665_get_crit(struct device *dev, int index)
347{
348 struct i2c_client *client = to_i2c_client(dev);
349 struct smm665_data *data = i2c_get_clientdata(client);
350
351 return data->critical_max_limit[index];
352}
353
354static ssize_t smm665_show_crit_alarm(struct device *dev,
355 struct device_attribute *da, char *buf)
356{
357 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
358 struct smm665_data *data = smm665_update_device(dev);
359 int val = 0;
360
361 if (IS_ERR(data))
362 return PTR_ERR(data);
363
364 if (data->faults & (1 << attr->index))
365 val = 1;
366
367 return snprintf(buf, PAGE_SIZE, "%d\n", val);
368}
369
370static ssize_t smm665_show_input(struct device *dev,
371 struct device_attribute *da, char *buf)
372{
373 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
374 struct smm665_data *data = smm665_update_device(dev);
375 int adc = attr->index;
376 int val;
377
378 if (IS_ERR(data))
379 return PTR_ERR(data);
380
381 val = smm665_convert(data->adc[adc], adc);
382 return snprintf(buf, PAGE_SIZE, "%d\n", val);
383}
384
385#define SMM665_SHOW(what) \
386 static ssize_t smm665_show_##what(struct device *dev, \
387 struct device_attribute *da, char *buf) \
388{ \
389 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); \
390 const int val = smm665_get_##what(dev, attr->index); \
391 return snprintf(buf, PAGE_SIZE, "%d\n", val); \
392}
393
394SMM665_SHOW(min);
395SMM665_SHOW(max);
396SMM665_SHOW(lcrit);
397SMM665_SHOW(crit);
398
399/* These macros are used below in constructing device attribute objects
400 * for use with sysfs_create_group() to make a sysfs device file
401 * for each register.
402 */
403
404#define SMM665_ATTR(name, type, cmd_idx) \
405 static SENSOR_DEVICE_ATTR(name##_##type, S_IRUGO, \
406 smm665_show_##type, NULL, cmd_idx)
407
408/* Construct a sensor_device_attribute structure for each register */
409
410/* Input voltages */
411SMM665_ATTR(in1, input, SMM665_MISC16_ADC_DATA_12V);
412SMM665_ATTR(in2, input, SMM665_MISC16_ADC_DATA_VDD);
413SMM665_ATTR(in3, input, SMM665_MISC16_ADC_DATA_A);
414SMM665_ATTR(in4, input, SMM665_MISC16_ADC_DATA_B);
415SMM665_ATTR(in5, input, SMM665_MISC16_ADC_DATA_C);
416SMM665_ATTR(in6, input, SMM665_MISC16_ADC_DATA_D);
417SMM665_ATTR(in7, input, SMM665_MISC16_ADC_DATA_E);
418SMM665_ATTR(in8, input, SMM665_MISC16_ADC_DATA_F);
419SMM665_ATTR(in9, input, SMM665_MISC16_ADC_DATA_AIN1);
420SMM665_ATTR(in10, input, SMM665_MISC16_ADC_DATA_AIN2);
421
422/* Input voltages min */
423SMM665_ATTR(in1, min, SMM665_MISC16_ADC_DATA_12V);
424SMM665_ATTR(in2, min, SMM665_MISC16_ADC_DATA_VDD);
425SMM665_ATTR(in3, min, SMM665_MISC16_ADC_DATA_A);
426SMM665_ATTR(in4, min, SMM665_MISC16_ADC_DATA_B);
427SMM665_ATTR(in5, min, SMM665_MISC16_ADC_DATA_C);
428SMM665_ATTR(in6, min, SMM665_MISC16_ADC_DATA_D);
429SMM665_ATTR(in7, min, SMM665_MISC16_ADC_DATA_E);
430SMM665_ATTR(in8, min, SMM665_MISC16_ADC_DATA_F);
431SMM665_ATTR(in9, min, SMM665_MISC16_ADC_DATA_AIN1);
432SMM665_ATTR(in10, min, SMM665_MISC16_ADC_DATA_AIN2);
433
434/* Input voltages max */
435SMM665_ATTR(in1, max, SMM665_MISC16_ADC_DATA_12V);
436SMM665_ATTR(in2, max, SMM665_MISC16_ADC_DATA_VDD);
437SMM665_ATTR(in3, max, SMM665_MISC16_ADC_DATA_A);
438SMM665_ATTR(in4, max, SMM665_MISC16_ADC_DATA_B);
439SMM665_ATTR(in5, max, SMM665_MISC16_ADC_DATA_C);
440SMM665_ATTR(in6, max, SMM665_MISC16_ADC_DATA_D);
441SMM665_ATTR(in7, max, SMM665_MISC16_ADC_DATA_E);
442SMM665_ATTR(in8, max, SMM665_MISC16_ADC_DATA_F);
443SMM665_ATTR(in9, max, SMM665_MISC16_ADC_DATA_AIN1);
444SMM665_ATTR(in10, max, SMM665_MISC16_ADC_DATA_AIN2);
445
446/* Input voltages lcrit */
447SMM665_ATTR(in1, lcrit, SMM665_MISC16_ADC_DATA_12V);
448SMM665_ATTR(in2, lcrit, SMM665_MISC16_ADC_DATA_VDD);
449SMM665_ATTR(in3, lcrit, SMM665_MISC16_ADC_DATA_A);
450SMM665_ATTR(in4, lcrit, SMM665_MISC16_ADC_DATA_B);
451SMM665_ATTR(in5, lcrit, SMM665_MISC16_ADC_DATA_C);
452SMM665_ATTR(in6, lcrit, SMM665_MISC16_ADC_DATA_D);
453SMM665_ATTR(in7, lcrit, SMM665_MISC16_ADC_DATA_E);
454SMM665_ATTR(in8, lcrit, SMM665_MISC16_ADC_DATA_F);
455SMM665_ATTR(in9, lcrit, SMM665_MISC16_ADC_DATA_AIN1);
456SMM665_ATTR(in10, lcrit, SMM665_MISC16_ADC_DATA_AIN2);
457
458/* Input voltages crit */
459SMM665_ATTR(in1, crit, SMM665_MISC16_ADC_DATA_12V);
460SMM665_ATTR(in2, crit, SMM665_MISC16_ADC_DATA_VDD);
461SMM665_ATTR(in3, crit, SMM665_MISC16_ADC_DATA_A);
462SMM665_ATTR(in4, crit, SMM665_MISC16_ADC_DATA_B);
463SMM665_ATTR(in5, crit, SMM665_MISC16_ADC_DATA_C);
464SMM665_ATTR(in6, crit, SMM665_MISC16_ADC_DATA_D);
465SMM665_ATTR(in7, crit, SMM665_MISC16_ADC_DATA_E);
466SMM665_ATTR(in8, crit, SMM665_MISC16_ADC_DATA_F);
467SMM665_ATTR(in9, crit, SMM665_MISC16_ADC_DATA_AIN1);
468SMM665_ATTR(in10, crit, SMM665_MISC16_ADC_DATA_AIN2);
469
470/* critical alarms */
471SMM665_ATTR(in1, crit_alarm, SMM665_FAULT_12V);
472SMM665_ATTR(in2, crit_alarm, SMM665_FAULT_VDD);
473SMM665_ATTR(in3, crit_alarm, SMM665_FAULT_A);
474SMM665_ATTR(in4, crit_alarm, SMM665_FAULT_B);
475SMM665_ATTR(in5, crit_alarm, SMM665_FAULT_C);
476SMM665_ATTR(in6, crit_alarm, SMM665_FAULT_D);
477SMM665_ATTR(in7, crit_alarm, SMM665_FAULT_E);
478SMM665_ATTR(in8, crit_alarm, SMM665_FAULT_F);
479SMM665_ATTR(in9, crit_alarm, SMM665_FAULT_AIN1);
480SMM665_ATTR(in10, crit_alarm, SMM665_FAULT_AIN2);
481
482/* Temperature */
483SMM665_ATTR(temp1, input, SMM665_MISC16_ADC_DATA_INT_TEMP);
484SMM665_ATTR(temp1, min, SMM665_MISC16_ADC_DATA_INT_TEMP);
485SMM665_ATTR(temp1, max, SMM665_MISC16_ADC_DATA_INT_TEMP);
486SMM665_ATTR(temp1, lcrit, SMM665_MISC16_ADC_DATA_INT_TEMP);
487SMM665_ATTR(temp1, crit, SMM665_MISC16_ADC_DATA_INT_TEMP);
488SMM665_ATTR(temp1, crit_alarm, SMM665_FAULT_TEMP);
489
490/*
491 * Finally, construct an array of pointers to members of the above objects,
492 * as required for sysfs_create_group()
493 */
494static struct attribute *smm665_attributes[] = {
495 &sensor_dev_attr_in1_input.dev_attr.attr,
496 &sensor_dev_attr_in1_min.dev_attr.attr,
497 &sensor_dev_attr_in1_max.dev_attr.attr,
498 &sensor_dev_attr_in1_lcrit.dev_attr.attr,
499 &sensor_dev_attr_in1_crit.dev_attr.attr,
500 &sensor_dev_attr_in1_crit_alarm.dev_attr.attr,
501
502 &sensor_dev_attr_in2_input.dev_attr.attr,
503 &sensor_dev_attr_in2_min.dev_attr.attr,
504 &sensor_dev_attr_in2_max.dev_attr.attr,
505 &sensor_dev_attr_in2_lcrit.dev_attr.attr,
506 &sensor_dev_attr_in2_crit.dev_attr.attr,
507 &sensor_dev_attr_in2_crit_alarm.dev_attr.attr,
508
509 &sensor_dev_attr_in3_input.dev_attr.attr,
510 &sensor_dev_attr_in3_min.dev_attr.attr,
511 &sensor_dev_attr_in3_max.dev_attr.attr,
512 &sensor_dev_attr_in3_lcrit.dev_attr.attr,
513 &sensor_dev_attr_in3_crit.dev_attr.attr,
514 &sensor_dev_attr_in3_crit_alarm.dev_attr.attr,
515
516 &sensor_dev_attr_in4_input.dev_attr.attr,
517 &sensor_dev_attr_in4_min.dev_attr.attr,
518 &sensor_dev_attr_in4_max.dev_attr.attr,
519 &sensor_dev_attr_in4_lcrit.dev_attr.attr,
520 &sensor_dev_attr_in4_crit.dev_attr.attr,
521 &sensor_dev_attr_in4_crit_alarm.dev_attr.attr,
522
523 &sensor_dev_attr_in5_input.dev_attr.attr,
524 &sensor_dev_attr_in5_min.dev_attr.attr,
525 &sensor_dev_attr_in5_max.dev_attr.attr,
526 &sensor_dev_attr_in5_lcrit.dev_attr.attr,
527 &sensor_dev_attr_in5_crit.dev_attr.attr,
528 &sensor_dev_attr_in5_crit_alarm.dev_attr.attr,
529
530 &sensor_dev_attr_in6_input.dev_attr.attr,
531 &sensor_dev_attr_in6_min.dev_attr.attr,
532 &sensor_dev_attr_in6_max.dev_attr.attr,
533 &sensor_dev_attr_in6_lcrit.dev_attr.attr,
534 &sensor_dev_attr_in6_crit.dev_attr.attr,
535 &sensor_dev_attr_in6_crit_alarm.dev_attr.attr,
536
537 &sensor_dev_attr_in7_input.dev_attr.attr,
538 &sensor_dev_attr_in7_min.dev_attr.attr,
539 &sensor_dev_attr_in7_max.dev_attr.attr,
540 &sensor_dev_attr_in7_lcrit.dev_attr.attr,
541 &sensor_dev_attr_in7_crit.dev_attr.attr,
542 &sensor_dev_attr_in7_crit_alarm.dev_attr.attr,
543
544 &sensor_dev_attr_in8_input.dev_attr.attr,
545 &sensor_dev_attr_in8_min.dev_attr.attr,
546 &sensor_dev_attr_in8_max.dev_attr.attr,
547 &sensor_dev_attr_in8_lcrit.dev_attr.attr,
548 &sensor_dev_attr_in8_crit.dev_attr.attr,
549 &sensor_dev_attr_in8_crit_alarm.dev_attr.attr,
550
551 &sensor_dev_attr_in9_input.dev_attr.attr,
552 &sensor_dev_attr_in9_min.dev_attr.attr,
553 &sensor_dev_attr_in9_max.dev_attr.attr,
554 &sensor_dev_attr_in9_lcrit.dev_attr.attr,
555 &sensor_dev_attr_in9_crit.dev_attr.attr,
556 &sensor_dev_attr_in9_crit_alarm.dev_attr.attr,
557
558 &sensor_dev_attr_in10_input.dev_attr.attr,
559 &sensor_dev_attr_in10_min.dev_attr.attr,
560 &sensor_dev_attr_in10_max.dev_attr.attr,
561 &sensor_dev_attr_in10_lcrit.dev_attr.attr,
562 &sensor_dev_attr_in10_crit.dev_attr.attr,
563 &sensor_dev_attr_in10_crit_alarm.dev_attr.attr,
564
565 &sensor_dev_attr_temp1_input.dev_attr.attr,
566 &sensor_dev_attr_temp1_min.dev_attr.attr,
567 &sensor_dev_attr_temp1_max.dev_attr.attr,
568 &sensor_dev_attr_temp1_lcrit.dev_attr.attr,
569 &sensor_dev_attr_temp1_crit.dev_attr.attr,
570 &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr,
571
572 NULL,
573};
574
575static const struct attribute_group smm665_group = {
576 .attrs = smm665_attributes,
577};
578
579static int smm665_probe(struct i2c_client *client,
580 const struct i2c_device_id *id)
581{
582 struct i2c_adapter *adapter = client->adapter;
583 struct smm665_data *data;
584 int i, ret;
585
586 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA
587 | I2C_FUNC_SMBUS_WORD_DATA))
588 return -ENODEV;
589
590 if (i2c_smbus_read_byte_data(client, SMM665_ADOC_ENABLE) < 0)
591 return -ENODEV;
592
593 ret = -ENOMEM;
594 data = kzalloc(sizeof(*data), GFP_KERNEL);
595 if (!data)
596 goto out_return;
597
598 i2c_set_clientdata(client, data);
599 mutex_init(&data->update_lock);
600
601 data->type = id->driver_data;
602 data->cmdreg = i2c_new_dummy(adapter, (client->addr & ~SMM665_REGMASK)
603 | SMM665_CMDREG_BASE);
604 if (!data->cmdreg)
605 goto out_kfree;
606
607 switch (data->type) {
608 case smm465:
609 case smm665:
610 data->conversion_time = SMM665_ADC_WAIT_SMM665;
611 break;
612 case smm665c:
613 case smm764:
614 case smm766:
615 data->conversion_time = SMM665_ADC_WAIT_SMM766;
616 break;
617 }
618
619 ret = -ENODEV;
620 if (i2c_smbus_read_byte_data(data->cmdreg, SMM665_MISC8_CMD_STS) < 0)
621 goto out_unregister;
622
623 /*
624 * Read limits.
625 *
626 * Limit registers start with register SMM665_LIMIT_BASE.
627 * Each channel uses 8 registers, providing four limit values
628 * per channel. Each limit value requires two registers, with the
629 * high byte in the first register and the low byte in the second
630 * register. The first two limits are under limit values, followed
631 * by two over limit values.
632 *
633 * Limit register order matches the ADC register order, so we use
634 * ADC register defines throughout the code to index limit registers.
635 *
636 * We save the first retrieved value both as "critical" and "alarm"
637 * value. The second value overwrites either the critical or the
638 * alarm value, depending on its configuration. This ensures that both
639 * critical and alarm values are initialized, even if both registers are
640 * configured as critical or non-critical.
641 */
642 for (i = 0; i < SMM665_NUM_ADC; i++) {
643 int val;
644
645 val = smm665_read16(client, SMM665_LIMIT_BASE + i * 8);
646 if (unlikely(val < 0))
647 goto out_unregister;
648 data->critical_min_limit[i] = data->alarm_min_limit[i]
649 = smm665_convert(val, i);
650 val = smm665_read16(client, SMM665_LIMIT_BASE + i * 8 + 2);
651 if (unlikely(val < 0))
652 goto out_unregister;
653 if (smm665_is_critical(val))
654 data->critical_min_limit[i] = smm665_convert(val, i);
655 else
656 data->alarm_min_limit[i] = smm665_convert(val, i);
657 val = smm665_read16(client, SMM665_LIMIT_BASE + i * 8 + 4);
658 if (unlikely(val < 0))
659 goto out_unregister;
660 data->critical_max_limit[i] = data->alarm_max_limit[i]
661 = smm665_convert(val, i);
662 val = smm665_read16(client, SMM665_LIMIT_BASE + i * 8 + 6);
663 if (unlikely(val < 0))
664 goto out_unregister;
665 if (smm665_is_critical(val))
666 data->critical_max_limit[i] = smm665_convert(val, i);
667 else
668 data->alarm_max_limit[i] = smm665_convert(val, i);
669 }
670
671 /* Register sysfs hooks */
672 ret = sysfs_create_group(&client->dev.kobj, &smm665_group);
673 if (ret)
674 goto out_unregister;
675
676 data->hwmon_dev = hwmon_device_register(&client->dev);
677 if (IS_ERR(data->hwmon_dev)) {
678 ret = PTR_ERR(data->hwmon_dev);
679 goto out_remove_group;
680 }
681
682 return 0;
683
684out_remove_group:
685 sysfs_remove_group(&client->dev.kobj, &smm665_group);
686out_unregister:
687 i2c_unregister_device(data->cmdreg);
688out_kfree:
689 kfree(data);
690out_return:
691 return ret;
692}
693
694static int smm665_remove(struct i2c_client *client)
695{
696 struct smm665_data *data = i2c_get_clientdata(client);
697
698 i2c_unregister_device(data->cmdreg);
699 hwmon_device_unregister(data->hwmon_dev);
700 sysfs_remove_group(&client->dev.kobj, &smm665_group);
701
702 kfree(data);
703
704 return 0;
705}
706
707static const struct i2c_device_id smm665_id[] = {
708 {"smm465", smm465},
709 {"smm665", smm665},
710 {"smm665c", smm665c},
711 {"smm764", smm764},
712 {"smm766", smm766},
713 {}
714};
715
716MODULE_DEVICE_TABLE(i2c, smm665_id);
717
718/* This is the driver that will be inserted */
719static struct i2c_driver smm665_driver = {
720 .driver = {
721 .name = "smm665",
722 },
723 .probe = smm665_probe,
724 .remove = smm665_remove,
725 .id_table = smm665_id,
726};
727
728static int __init smm665_init(void)
729{
730 return i2c_add_driver(&smm665_driver);
731}
732
733static void __exit smm665_exit(void)
734{
735 i2c_del_driver(&smm665_driver);
736}
737
738MODULE_AUTHOR("Guenter Roeck");
739MODULE_DESCRIPTION("SMM665 driver");
740MODULE_LICENSE("GPL");
741
742module_init(smm665_init);
743module_exit(smm665_exit);
diff --git a/drivers/hwmon/ultra45_env.c b/drivers/hwmon/ultra45_env.c
index 89643261ccdb..d863e13a50b8 100644
--- a/drivers/hwmon/ultra45_env.c
+++ b/drivers/hwmon/ultra45_env.c
@@ -234,7 +234,7 @@ static const struct attribute_group env_group = {
234 .attrs = env_attributes, 234 .attrs = env_attributes,
235}; 235};
236 236
237static int __devinit env_probe(struct of_device *op, 237static int __devinit env_probe(struct platform_device *op,
238 const struct of_device_id *match) 238 const struct of_device_id *match)
239{ 239{
240 struct env *p = kzalloc(sizeof(*p), GFP_KERNEL); 240 struct env *p = kzalloc(sizeof(*p), GFP_KERNEL);
@@ -276,7 +276,7 @@ out_free:
276 goto out; 276 goto out;
277} 277}
278 278
279static int __devexit env_remove(struct of_device *op) 279static int __devexit env_remove(struct platform_device *op)
280{ 280{
281 struct env *p = dev_get_drvdata(&op->dev); 281 struct env *p = dev_get_drvdata(&op->dev);
282 282
diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
index 7442cf754856..ffb793af680b 100644
--- a/drivers/hwmon/via-cputemp.c
+++ b/drivers/hwmon/via-cputemp.c
@@ -39,7 +39,7 @@
39 39
40#define DRVNAME "via_cputemp" 40#define DRVNAME "via_cputemp"
41 41
42enum { SHOW_TEMP, SHOW_LABEL, SHOW_NAME } SHOW; 42enum { SHOW_TEMP, SHOW_LABEL, SHOW_NAME };
43 43
44/* 44/*
45 * Functions declaration 45 * Functions declaration
diff --git a/drivers/hwmon/w83627ehf.c b/drivers/hwmon/w83627ehf.c
index 0dcaba9b7189..e96e69dd36fb 100644
--- a/drivers/hwmon/w83627ehf.c
+++ b/drivers/hwmon/w83627ehf.c
@@ -39,6 +39,7 @@
39 w83627dhg 9 5 4 3 0xa020 0xc1 0x5ca3 39 w83627dhg 9 5 4 3 0xa020 0xc1 0x5ca3
40 w83627dhg-p 9 5 4 3 0xb070 0xc1 0x5ca3 40 w83627dhg-p 9 5 4 3 0xb070 0xc1 0x5ca3
41 w83667hg 9 5 3 3 0xa510 0xc1 0x5ca3 41 w83667hg 9 5 3 3 0xa510 0xc1 0x5ca3
42 w83667hg-b 9 5 3 3 0xb350 0xc1 0x5ca3
42*/ 43*/
43 44
44#include <linux/module.h> 45#include <linux/module.h>
@@ -55,7 +56,7 @@
55#include <linux/io.h> 56#include <linux/io.h>
56#include "lm75.h" 57#include "lm75.h"
57 58
58enum kinds { w83627ehf, w83627dhg, w83627dhg_p, w83667hg }; 59enum kinds { w83627ehf, w83627dhg, w83627dhg_p, w83667hg, w83667hg_b };
59 60
60/* used to set data->name = w83627ehf_device_names[data->sio_kind] */ 61/* used to set data->name = w83627ehf_device_names[data->sio_kind] */
61static const char * w83627ehf_device_names[] = { 62static const char * w83627ehf_device_names[] = {
@@ -63,6 +64,7 @@ static const char * w83627ehf_device_names[] = {
63 "w83627dhg", 64 "w83627dhg",
64 "w83627dhg", 65 "w83627dhg",
65 "w83667hg", 66 "w83667hg",
67 "w83667hg",
66}; 68};
67 69
68static unsigned short force_id; 70static unsigned short force_id;
@@ -91,6 +93,7 @@ MODULE_PARM_DESC(force_id, "Override the detected device ID");
91#define SIO_W83627DHG_ID 0xa020 93#define SIO_W83627DHG_ID 0xa020
92#define SIO_W83627DHG_P_ID 0xb070 94#define SIO_W83627DHG_P_ID 0xb070
93#define SIO_W83667HG_ID 0xa510 95#define SIO_W83667HG_ID 0xa510
96#define SIO_W83667HG_B_ID 0xb350
94#define SIO_ID_MASK 0xFFF0 97#define SIO_ID_MASK 0xFFF0
95 98
96static inline void 99static inline void
@@ -201,8 +204,14 @@ static const u8 W83627EHF_REG_TOLERANCE[] = { 0x07, 0x07, 0x14, 0x62 };
201static const u8 W83627EHF_REG_FAN_START_OUTPUT[] = { 0x0a, 0x0b, 0x16, 0x65 }; 204static const u8 W83627EHF_REG_FAN_START_OUTPUT[] = { 0x0a, 0x0b, 0x16, 0x65 };
202static const u8 W83627EHF_REG_FAN_STOP_OUTPUT[] = { 0x08, 0x09, 0x15, 0x64 }; 205static const u8 W83627EHF_REG_FAN_STOP_OUTPUT[] = { 0x08, 0x09, 0x15, 0x64 };
203static const u8 W83627EHF_REG_FAN_STOP_TIME[] = { 0x0c, 0x0d, 0x17, 0x66 }; 206static const u8 W83627EHF_REG_FAN_STOP_TIME[] = { 0x0c, 0x0d, 0x17, 0x66 };
204static const u8 W83627EHF_REG_FAN_MAX_OUTPUT[] = { 0xff, 0x67, 0xff, 0x69 }; 207
205static const u8 W83627EHF_REG_FAN_STEP_OUTPUT[] = { 0xff, 0x68, 0xff, 0x6a }; 208static const u8 W83627EHF_REG_FAN_MAX_OUTPUT_COMMON[]
209 = { 0xff, 0x67, 0xff, 0x69 };
210static const u8 W83627EHF_REG_FAN_STEP_OUTPUT_COMMON[]
211 = { 0xff, 0x68, 0xff, 0x6a };
212
213static const u8 W83627EHF_REG_FAN_MAX_OUTPUT_W83667_B[] = { 0x67, 0x69, 0x6b };
214static const u8 W83627EHF_REG_FAN_STEP_OUTPUT_W83667_B[] = { 0x68, 0x6a, 0x6c };
206 215
207/* 216/*
208 * Conversions 217 * Conversions
@@ -277,6 +286,11 @@ struct w83627ehf_data {
277 struct device *hwmon_dev; 286 struct device *hwmon_dev;
278 struct mutex lock; 287 struct mutex lock;
279 288
289 const u8 *REG_FAN_START_OUTPUT;
290 const u8 *REG_FAN_STOP_OUTPUT;
291 const u8 *REG_FAN_MAX_OUTPUT;
292 const u8 *REG_FAN_STEP_OUTPUT;
293
280 struct mutex update_lock; 294 struct mutex update_lock;
281 char valid; /* !=0 if following fields are valid */ 295 char valid; /* !=0 if following fields are valid */
282 unsigned long last_updated; /* In jiffies */ 296 unsigned long last_updated; /* In jiffies */
@@ -524,7 +538,10 @@ static struct w83627ehf_data *w83627ehf_update_device(struct device *dev)
524 } 538 }
525 } 539 }
526 540
527 for (i = 0; i < 4; i++) { 541 for (i = 0; i < data->pwm_num; i++) {
542 if (!(data->has_fan & (1 << i)))
543 continue;
544
528 /* pwmcfg, tolerance mapped for i=0, i=1 to same reg */ 545 /* pwmcfg, tolerance mapped for i=0, i=1 to same reg */
529 if (i != 1) { 546 if (i != 1) {
530 pwmcfg = w83627ehf_read_value(data, 547 pwmcfg = w83627ehf_read_value(data,
@@ -546,6 +563,17 @@ static struct w83627ehf_data *w83627ehf_update_device(struct device *dev)
546 W83627EHF_REG_FAN_STOP_OUTPUT[i]); 563 W83627EHF_REG_FAN_STOP_OUTPUT[i]);
547 data->fan_stop_time[i] = w83627ehf_read_value(data, 564 data->fan_stop_time[i] = w83627ehf_read_value(data,
548 W83627EHF_REG_FAN_STOP_TIME[i]); 565 W83627EHF_REG_FAN_STOP_TIME[i]);
566
567 if (data->REG_FAN_MAX_OUTPUT[i] != 0xff)
568 data->fan_max_output[i] =
569 w83627ehf_read_value(data,
570 data->REG_FAN_MAX_OUTPUT[i]);
571
572 if (data->REG_FAN_STEP_OUTPUT[i] != 0xff)
573 data->fan_step_output[i] =
574 w83627ehf_read_value(data,
575 data->REG_FAN_STEP_OUTPUT[i]);
576
549 data->target_temp[i] = 577 data->target_temp[i] =
550 w83627ehf_read_value(data, 578 w83627ehf_read_value(data,
551 W83627EHF_REG_TARGET[i]) & 579 W83627EHF_REG_TARGET[i]) &
@@ -1126,7 +1154,7 @@ store_##reg(struct device *dev, struct device_attribute *attr, \
1126 u32 val = SENSORS_LIMIT(simple_strtoul(buf, NULL, 10), 1, 255); \ 1154 u32 val = SENSORS_LIMIT(simple_strtoul(buf, NULL, 10), 1, 255); \
1127 mutex_lock(&data->update_lock); \ 1155 mutex_lock(&data->update_lock); \
1128 data->reg[nr] = val; \ 1156 data->reg[nr] = val; \
1129 w83627ehf_write_value(data, W83627EHF_REG_##REG[nr], val); \ 1157 w83627ehf_write_value(data, data->REG_##REG[nr], val); \
1130 mutex_unlock(&data->update_lock); \ 1158 mutex_unlock(&data->update_lock); \
1131 return count; \ 1159 return count; \
1132} 1160}
@@ -1206,12 +1234,26 @@ static struct sensor_device_attribute sda_sf3_arrays[] = {
1206 store_fan_stop_output, 1), 1234 store_fan_stop_output, 1),
1207 SENSOR_ATTR(pwm3_stop_output, S_IWUSR | S_IRUGO, show_fan_stop_output, 1235 SENSOR_ATTR(pwm3_stop_output, S_IWUSR | S_IRUGO, show_fan_stop_output,
1208 store_fan_stop_output, 2), 1236 store_fan_stop_output, 2),
1237};
1209 1238
1210 /* pwm1 and pwm3 don't support max and step settings */ 1239
1240/*
1241 * pwm1 and pwm3 don't support max and step settings on all chips.
1242 * Need to check support while generating/removing attribute files.
1243 */
1244static struct sensor_device_attribute sda_sf3_max_step_arrays[] = {
1245 SENSOR_ATTR(pwm1_max_output, S_IWUSR | S_IRUGO, show_fan_max_output,
1246 store_fan_max_output, 0),
1247 SENSOR_ATTR(pwm1_step_output, S_IWUSR | S_IRUGO, show_fan_step_output,
1248 store_fan_step_output, 0),
1211 SENSOR_ATTR(pwm2_max_output, S_IWUSR | S_IRUGO, show_fan_max_output, 1249 SENSOR_ATTR(pwm2_max_output, S_IWUSR | S_IRUGO, show_fan_max_output,
1212 store_fan_max_output, 1), 1250 store_fan_max_output, 1),
1213 SENSOR_ATTR(pwm2_step_output, S_IWUSR | S_IRUGO, show_fan_step_output, 1251 SENSOR_ATTR(pwm2_step_output, S_IWUSR | S_IRUGO, show_fan_step_output,
1214 store_fan_step_output, 1), 1252 store_fan_step_output, 1),
1253 SENSOR_ATTR(pwm3_max_output, S_IWUSR | S_IRUGO, show_fan_max_output,
1254 store_fan_max_output, 2),
1255 SENSOR_ATTR(pwm3_step_output, S_IWUSR | S_IRUGO, show_fan_step_output,
1256 store_fan_step_output, 2),
1215}; 1257};
1216 1258
1217static ssize_t 1259static ssize_t
@@ -1235,6 +1277,12 @@ static void w83627ehf_device_remove_files(struct device *dev)
1235 1277
1236 for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays); i++) 1278 for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays); i++)
1237 device_remove_file(dev, &sda_sf3_arrays[i].dev_attr); 1279 device_remove_file(dev, &sda_sf3_arrays[i].dev_attr);
1280 for (i = 0; i < ARRAY_SIZE(sda_sf3_max_step_arrays); i++) {
1281 struct sensor_device_attribute *attr =
1282 &sda_sf3_max_step_arrays[i];
1283 if (data->REG_FAN_STEP_OUTPUT[attr->index] != 0xff)
1284 device_remove_file(dev, &attr->dev_attr);
1285 }
1238 for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays_fan4); i++) 1286 for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays_fan4); i++)
1239 device_remove_file(dev, &sda_sf3_arrays_fan4[i].dev_attr); 1287 device_remove_file(dev, &sda_sf3_arrays_fan4[i].dev_attr);
1240 for (i = 0; i < data->in_num; i++) { 1288 for (i = 0; i < data->in_num; i++) {
@@ -1343,22 +1391,37 @@ static int __devinit w83627ehf_probe(struct platform_device *pdev)
1343 /* 627EHG and 627EHF have 10 voltage inputs; 627DHG and 667HG have 9 */ 1391 /* 627EHG and 627EHF have 10 voltage inputs; 627DHG and 667HG have 9 */
1344 data->in_num = (sio_data->kind == w83627ehf) ? 10 : 9; 1392 data->in_num = (sio_data->kind == w83627ehf) ? 10 : 9;
1345 /* 667HG has 3 pwms */ 1393 /* 667HG has 3 pwms */
1346 data->pwm_num = (sio_data->kind == w83667hg) ? 3 : 4; 1394 data->pwm_num = (sio_data->kind == w83667hg
1395 || sio_data->kind == w83667hg_b) ? 3 : 4;
1347 1396
1348 /* Check temp3 configuration bit for 667HG */ 1397 /* Check temp3 configuration bit for 667HG */
1349 if (sio_data->kind == w83667hg) { 1398 if (sio_data->kind == w83667hg || sio_data->kind == w83667hg_b) {
1350 data->temp3_disable = w83627ehf_read_value(data, 1399 data->temp3_disable = w83627ehf_read_value(data,
1351 W83627EHF_REG_TEMP_CONFIG[1]) & 0x01; 1400 W83627EHF_REG_TEMP_CONFIG[1]) & 0x01;
1352 data->in6_skip = !data->temp3_disable; 1401 data->in6_skip = !data->temp3_disable;
1353 } 1402 }
1354 1403
1404 data->REG_FAN_START_OUTPUT = W83627EHF_REG_FAN_START_OUTPUT;
1405 data->REG_FAN_STOP_OUTPUT = W83627EHF_REG_FAN_STOP_OUTPUT;
1406 if (sio_data->kind == w83667hg_b) {
1407 data->REG_FAN_MAX_OUTPUT =
1408 W83627EHF_REG_FAN_MAX_OUTPUT_W83667_B;
1409 data->REG_FAN_STEP_OUTPUT =
1410 W83627EHF_REG_FAN_STEP_OUTPUT_W83667_B;
1411 } else {
1412 data->REG_FAN_MAX_OUTPUT =
1413 W83627EHF_REG_FAN_MAX_OUTPUT_COMMON;
1414 data->REG_FAN_STEP_OUTPUT =
1415 W83627EHF_REG_FAN_STEP_OUTPUT_COMMON;
1416 }
1417
1355 /* Initialize the chip */ 1418 /* Initialize the chip */
1356 w83627ehf_init_device(data); 1419 w83627ehf_init_device(data);
1357 1420
1358 data->vrm = vid_which_vrm(); 1421 data->vrm = vid_which_vrm();
1359 superio_enter(sio_data->sioreg); 1422 superio_enter(sio_data->sioreg);
1360 /* Read VID value */ 1423 /* Read VID value */
1361 if (sio_data->kind == w83667hg) { 1424 if (sio_data->kind == w83667hg || sio_data->kind == w83667hg_b) {
1362 /* W83667HG has different pins for VID input and output, so 1425 /* W83667HG has different pins for VID input and output, so
1363 we can get the VID input values directly at logical device D 1426 we can get the VID input values directly at logical device D
1364 0xe3. */ 1427 0xe3. */
@@ -1409,7 +1472,7 @@ static int __devinit w83627ehf_probe(struct platform_device *pdev)
1409 } 1472 }
1410 1473
1411 /* fan4 and fan5 share some pins with the GPIO and serial flash */ 1474 /* fan4 and fan5 share some pins with the GPIO and serial flash */
1412 if (sio_data->kind == w83667hg) { 1475 if (sio_data->kind == w83667hg || sio_data->kind == w83667hg_b) {
1413 fan5pin = superio_inb(sio_data->sioreg, 0x27) & 0x20; 1476 fan5pin = superio_inb(sio_data->sioreg, 0x27) & 0x20;
1414 fan4pin = superio_inb(sio_data->sioreg, 0x27) & 0x40; 1477 fan4pin = superio_inb(sio_data->sioreg, 0x27) & 0x40;
1415 } else { 1478 } else {
@@ -1440,6 +1503,15 @@ static int __devinit w83627ehf_probe(struct platform_device *pdev)
1440 &sda_sf3_arrays[i].dev_attr))) 1503 &sda_sf3_arrays[i].dev_attr)))
1441 goto exit_remove; 1504 goto exit_remove;
1442 1505
1506 for (i = 0; i < ARRAY_SIZE(sda_sf3_max_step_arrays); i++) {
1507 struct sensor_device_attribute *attr =
1508 &sda_sf3_max_step_arrays[i];
1509 if (data->REG_FAN_STEP_OUTPUT[attr->index] != 0xff) {
1510 err = device_create_file(dev, &attr->dev_attr);
1511 if (err)
1512 goto exit_remove;
1513 }
1514 }
1443 /* if fan4 is enabled create the sf3 files for it */ 1515 /* if fan4 is enabled create the sf3 files for it */
1444 if ((data->has_fan & (1 << 3)) && data->pwm_num >= 4) 1516 if ((data->has_fan & (1 << 3)) && data->pwm_num >= 4)
1445 for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays_fan4); i++) { 1517 for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays_fan4); i++) {
@@ -1556,6 +1628,7 @@ static int __init w83627ehf_find(int sioaddr, unsigned short *addr,
1556 static const char __initdata sio_name_W83627DHG[] = "W83627DHG"; 1628 static const char __initdata sio_name_W83627DHG[] = "W83627DHG";
1557 static const char __initdata sio_name_W83627DHG_P[] = "W83627DHG-P"; 1629 static const char __initdata sio_name_W83627DHG_P[] = "W83627DHG-P";
1558 static const char __initdata sio_name_W83667HG[] = "W83667HG"; 1630 static const char __initdata sio_name_W83667HG[] = "W83667HG";
1631 static const char __initdata sio_name_W83667HG_B[] = "W83667HG-B";
1559 1632
1560 u16 val; 1633 u16 val;
1561 const char *sio_name; 1634 const char *sio_name;
@@ -1588,6 +1661,10 @@ static int __init w83627ehf_find(int sioaddr, unsigned short *addr,
1588 sio_data->kind = w83667hg; 1661 sio_data->kind = w83667hg;
1589 sio_name = sio_name_W83667HG; 1662 sio_name = sio_name_W83667HG;
1590 break; 1663 break;
1664 case SIO_W83667HG_B_ID:
1665 sio_data->kind = w83667hg_b;
1666 sio_name = sio_name_W83667HG_B;
1667 break;
1591 default: 1668 default:
1592 if (val != 0xffff) 1669 if (val != 0xffff)
1593 pr_debug(DRVNAME ": unsupported chip ID: 0x%04x\n", 1670 pr_debug(DRVNAME ": unsupported chip ID: 0x%04x\n",
diff --git a/drivers/i2c/Kconfig b/drivers/i2c/Kconfig
index d06083fdffbb..30f06e956bfb 100644
--- a/drivers/i2c/Kconfig
+++ b/drivers/i2c/Kconfig
@@ -47,6 +47,19 @@ config I2C_CHARDEV
47 This support is also available as a module. If so, the module 47 This support is also available as a module. If so, the module
48 will be called i2c-dev. 48 will be called i2c-dev.
49 49
50config I2C_MUX
51 tristate "I2C bus multiplexing support"
52 depends on EXPERIMENTAL
53 help
54 Say Y here if you want the I2C core to support the ability to
55 handle multiplexed I2C bus topologies, by presenting each
56 multiplexed segment as a I2C adapter.
57
58 This support is also available as a module. If so, the module
59 will be called i2c-mux.
60
61source drivers/i2c/muxes/Kconfig
62
50config I2C_HELPER_AUTO 63config I2C_HELPER_AUTO
51 bool "Autoselect pertinent helper modules" 64 bool "Autoselect pertinent helper modules"
52 default y 65 default y
diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile
index a7d9b4be9bb3..c00fd66388f5 100644
--- a/drivers/i2c/Makefile
+++ b/drivers/i2c/Makefile
@@ -6,7 +6,8 @@ obj-$(CONFIG_I2C_BOARDINFO) += i2c-boardinfo.o
6obj-$(CONFIG_I2C) += i2c-core.o 6obj-$(CONFIG_I2C) += i2c-core.o
7obj-$(CONFIG_I2C_SMBUS) += i2c-smbus.o 7obj-$(CONFIG_I2C_SMBUS) += i2c-smbus.o
8obj-$(CONFIG_I2C_CHARDEV) += i2c-dev.o 8obj-$(CONFIG_I2C_CHARDEV) += i2c-dev.o
9obj-y += algos/ busses/ 9obj-$(CONFIG_I2C_MUX) += i2c-mux.o
10obj-y += algos/ busses/ muxes/
10 11
11ifeq ($(CONFIG_I2C_DEBUG_CORE),y) 12ifeq ($(CONFIG_I2C_DEBUG_CORE),y)
12EXTRA_CFLAGS += -DDEBUG 13EXTRA_CFLAGS += -DDEBUG
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index bceafbfa7268..6539ac2907e9 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -448,6 +448,13 @@ config I2C_NOMADIK
448 If you say yes to this option, support will be included for the 448 If you say yes to this option, support will be included for the
449 I2C interface from ST-Ericsson's Nomadik and Ux500 architectures. 449 I2C interface from ST-Ericsson's Nomadik and Ux500 architectures.
450 450
451config I2C_NUC900
452 tristate "NUC900 I2C Driver"
453 depends on ARCH_W90X900
454 help
455 Say Y here to include support for I2C controller in the
456 Winbond/Nuvoton NUC900 based System-on-Chip devices.
457
451config I2C_OCORES 458config I2C_OCORES
452 tristate "OpenCores I2C Controller" 459 tristate "OpenCores I2C Controller"
453 depends on EXPERIMENTAL 460 depends on EXPERIMENTAL
@@ -496,8 +503,8 @@ config I2C_PMCMSP
496 will be called i2c-pmcmsp. 503 will be called i2c-pmcmsp.
497 504
498config I2C_PNX 505config I2C_PNX
499 tristate "I2C bus support for Philips PNX targets" 506 tristate "I2C bus support for Philips PNX and NXP LPC targets"
500 depends on ARCH_PNX4008 507 depends on ARCH_PNX4008 || ARCH_LPC32XX
501 help 508 help
502 This driver supports the Philips IP3204 I2C IP block master and/or 509 This driver supports the Philips IP3204 I2C IP block master and/or
503 slave controller 510 slave controller
@@ -521,12 +528,19 @@ config I2C_PXA_SLAVE
521 is necessary for systems where the PXA may be a target on the 528 is necessary for systems where the PXA may be a target on the
522 I2C bus. 529 I2C bus.
523 530
531config HAVE_S3C2410_I2C
532 bool
533 help
534 This will include I2C support for Samsung SoCs. If you want to
535 include I2C support for any machine, kindly select this in the
536 respective Kconfig file.
537
524config I2C_S3C2410 538config I2C_S3C2410
525 tristate "S3C2410 I2C Driver" 539 tristate "S3C2410 I2C Driver"
526 depends on ARCH_S3C2410 || ARCH_S3C64XX 540 depends on HAVE_S3C2410_I2C
527 help 541 help
528 Say Y here to include support for I2C controller in the 542 Say Y here to include support for I2C controller in the
529 Samsung S3C2410 based System-on-Chip devices. 543 Samsung SoCs.
530 544
531config I2C_S6000 545config I2C_S6000
532 tristate "S6000 I2C support" 546 tristate "S6000 I2C support"
@@ -549,7 +563,7 @@ config I2C_SH7760
549 563
550config I2C_SH_MOBILE 564config I2C_SH_MOBILE
551 tristate "SuperH Mobile I2C Controller" 565 tristate "SuperH Mobile I2C Controller"
552 depends on SUPERH 566 depends on SUPERH || ARCH_SHMOBILE
553 help 567 help
554 If you say yes to this option, support will be included for the 568 If you say yes to this option, support will be included for the
555 built-in I2C interface on the Renesas SH-Mobile processor. 569 built-in I2C interface on the Renesas SH-Mobile processor.
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
index 936880bd1dc5..c3ef49230cba 100644
--- a/drivers/i2c/busses/Makefile
+++ b/drivers/i2c/busses/Makefile
@@ -43,6 +43,7 @@ obj-$(CONFIG_I2C_IXP2000) += i2c-ixp2000.o
43obj-$(CONFIG_I2C_MPC) += i2c-mpc.o 43obj-$(CONFIG_I2C_MPC) += i2c-mpc.o
44obj-$(CONFIG_I2C_MV64XXX) += i2c-mv64xxx.o 44obj-$(CONFIG_I2C_MV64XXX) += i2c-mv64xxx.o
45obj-$(CONFIG_I2C_NOMADIK) += i2c-nomadik.o 45obj-$(CONFIG_I2C_NOMADIK) += i2c-nomadik.o
46obj-$(CONFIG_I2C_NUC900) += i2c-nuc900.o
46obj-$(CONFIG_I2C_OCORES) += i2c-ocores.o 47obj-$(CONFIG_I2C_OCORES) += i2c-ocores.o
47obj-$(CONFIG_I2C_OMAP) += i2c-omap.o 48obj-$(CONFIG_I2C_OMAP) += i2c-omap.o
48obj-$(CONFIG_I2C_PASEMI) += i2c-pasemi.o 49obj-$(CONFIG_I2C_PASEMI) += i2c-pasemi.o
diff --git a/drivers/i2c/busses/i2c-cpm.c b/drivers/i2c/busses/i2c-cpm.c
index e591de1bc704..f7bd2613cecc 100644
--- a/drivers/i2c/busses/i2c-cpm.c
+++ b/drivers/i2c/busses/i2c-cpm.c
@@ -105,7 +105,7 @@ struct i2c_reg {
105 105
106struct cpm_i2c { 106struct cpm_i2c {
107 char *base; 107 char *base;
108 struct of_device *ofdev; 108 struct platform_device *ofdev;
109 struct i2c_adapter adap; 109 struct i2c_adapter adap;
110 uint dp_addr; 110 uint dp_addr;
111 int version; /* CPM1=1, CPM2=2 */ 111 int version; /* CPM1=1, CPM2=2 */
@@ -428,7 +428,7 @@ static const struct i2c_adapter cpm_ops = {
428 428
429static int __devinit cpm_i2c_setup(struct cpm_i2c *cpm) 429static int __devinit cpm_i2c_setup(struct cpm_i2c *cpm)
430{ 430{
431 struct of_device *ofdev = cpm->ofdev; 431 struct platform_device *ofdev = cpm->ofdev;
432 const u32 *data; 432 const u32 *data;
433 int len, ret, i; 433 int len, ret, i;
434 void __iomem *i2c_base; 434 void __iomem *i2c_base;
@@ -634,7 +634,7 @@ static void cpm_i2c_shutdown(struct cpm_i2c *cpm)
634 cpm_muram_free(cpm->i2c_addr); 634 cpm_muram_free(cpm->i2c_addr);
635} 635}
636 636
637static int __devinit cpm_i2c_probe(struct of_device *ofdev, 637static int __devinit cpm_i2c_probe(struct platform_device *ofdev,
638 const struct of_device_id *match) 638 const struct of_device_id *match)
639{ 639{
640 int result, len; 640 int result, len;
@@ -687,7 +687,7 @@ out_free:
687 return result; 687 return result;
688} 688}
689 689
690static int __devexit cpm_i2c_remove(struct of_device *ofdev) 690static int __devexit cpm_i2c_remove(struct platform_device *ofdev)
691{ 691{
692 struct cpm_i2c *cpm = dev_get_drvdata(&ofdev->dev); 692 struct cpm_i2c *cpm = dev_get_drvdata(&ofdev->dev);
693 693
diff --git a/drivers/i2c/busses/i2c-davinci.c b/drivers/i2c/busses/i2c-davinci.c
index 4523364e6722..2222c87876b9 100644
--- a/drivers/i2c/busses/i2c-davinci.c
+++ b/drivers/i2c/busses/i2c-davinci.c
@@ -36,14 +36,16 @@
36#include <linux/platform_device.h> 36#include <linux/platform_device.h>
37#include <linux/io.h> 37#include <linux/io.h>
38#include <linux/slab.h> 38#include <linux/slab.h>
39#include <linux/cpufreq.h>
40#include <linux/gpio.h>
39 41
40#include <mach/hardware.h> 42#include <mach/hardware.h>
41
42#include <mach/i2c.h> 43#include <mach/i2c.h>
43 44
44/* ----- global defines ----------------------------------------------- */ 45/* ----- global defines ----------------------------------------------- */
45 46
46#define DAVINCI_I2C_TIMEOUT (1*HZ) 47#define DAVINCI_I2C_TIMEOUT (1*HZ)
48#define DAVINCI_I2C_MAX_TRIES 2
47#define I2C_DAVINCI_INTR_ALL (DAVINCI_I2C_IMR_AAS | \ 49#define I2C_DAVINCI_INTR_ALL (DAVINCI_I2C_IMR_AAS | \
48 DAVINCI_I2C_IMR_SCD | \ 50 DAVINCI_I2C_IMR_SCD | \
49 DAVINCI_I2C_IMR_ARDY | \ 51 DAVINCI_I2C_IMR_ARDY | \
@@ -72,37 +74,29 @@
72#define DAVINCI_I2C_IVR_NACK 0x02 74#define DAVINCI_I2C_IVR_NACK 0x02
73#define DAVINCI_I2C_IVR_AL 0x01 75#define DAVINCI_I2C_IVR_AL 0x01
74 76
75#define DAVINCI_I2C_STR_BB (1 << 12) 77#define DAVINCI_I2C_STR_BB BIT(12)
76#define DAVINCI_I2C_STR_RSFULL (1 << 11) 78#define DAVINCI_I2C_STR_RSFULL BIT(11)
77#define DAVINCI_I2C_STR_SCD (1 << 5) 79#define DAVINCI_I2C_STR_SCD BIT(5)
78#define DAVINCI_I2C_STR_ARDY (1 << 2) 80#define DAVINCI_I2C_STR_ARDY BIT(2)
79#define DAVINCI_I2C_STR_NACK (1 << 1) 81#define DAVINCI_I2C_STR_NACK BIT(1)
80#define DAVINCI_I2C_STR_AL (1 << 0) 82#define DAVINCI_I2C_STR_AL BIT(0)
81 83
82#define DAVINCI_I2C_MDR_NACK (1 << 15) 84#define DAVINCI_I2C_MDR_NACK BIT(15)
83#define DAVINCI_I2C_MDR_STT (1 << 13) 85#define DAVINCI_I2C_MDR_STT BIT(13)
84#define DAVINCI_I2C_MDR_STP (1 << 11) 86#define DAVINCI_I2C_MDR_STP BIT(11)
85#define DAVINCI_I2C_MDR_MST (1 << 10) 87#define DAVINCI_I2C_MDR_MST BIT(10)
86#define DAVINCI_I2C_MDR_TRX (1 << 9) 88#define DAVINCI_I2C_MDR_TRX BIT(9)
87#define DAVINCI_I2C_MDR_XA (1 << 8) 89#define DAVINCI_I2C_MDR_XA BIT(8)
88#define DAVINCI_I2C_MDR_RM (1 << 7) 90#define DAVINCI_I2C_MDR_RM BIT(7)
89#define DAVINCI_I2C_MDR_IRS (1 << 5) 91#define DAVINCI_I2C_MDR_IRS BIT(5)
90 92
91#define DAVINCI_I2C_IMR_AAS (1 << 6) 93#define DAVINCI_I2C_IMR_AAS BIT(6)
92#define DAVINCI_I2C_IMR_SCD (1 << 5) 94#define DAVINCI_I2C_IMR_SCD BIT(5)
93#define DAVINCI_I2C_IMR_XRDY (1 << 4) 95#define DAVINCI_I2C_IMR_XRDY BIT(4)
94#define DAVINCI_I2C_IMR_RRDY (1 << 3) 96#define DAVINCI_I2C_IMR_RRDY BIT(3)
95#define DAVINCI_I2C_IMR_ARDY (1 << 2) 97#define DAVINCI_I2C_IMR_ARDY BIT(2)
96#define DAVINCI_I2C_IMR_NACK (1 << 1) 98#define DAVINCI_I2C_IMR_NACK BIT(1)
97#define DAVINCI_I2C_IMR_AL (1 << 0) 99#define DAVINCI_I2C_IMR_AL BIT(0)
98
99#define MOD_REG_BIT(val, mask, set) do { \
100 if (set) { \
101 val |= mask; \
102 } else { \
103 val &= ~mask; \
104 } \
105} while (0)
106 100
107struct davinci_i2c_dev { 101struct davinci_i2c_dev {
108 struct device *dev; 102 struct device *dev;
@@ -113,8 +107,13 @@ struct davinci_i2c_dev {
113 u8 *buf; 107 u8 *buf;
114 size_t buf_len; 108 size_t buf_len;
115 int irq; 109 int irq;
110 int stop;
116 u8 terminate; 111 u8 terminate;
117 struct i2c_adapter adapter; 112 struct i2c_adapter adapter;
113#ifdef CONFIG_CPU_FREQ
114 struct completion xfr_complete;
115 struct notifier_block freq_transition;
116#endif
118}; 117};
119 118
120/* default platform data to use if not supplied in the platform_device */ 119/* default platform data to use if not supplied in the platform_device */
@@ -134,12 +133,59 @@ static inline u16 davinci_i2c_read_reg(struct davinci_i2c_dev *i2c_dev, int reg)
134 return __raw_readw(i2c_dev->base + reg); 133 return __raw_readw(i2c_dev->base + reg);
135} 134}
136 135
137/* 136/* Generate a pulse on the i2c clock pin. */
138 * This functions configures I2C and brings I2C out of reset. 137static void generic_i2c_clock_pulse(unsigned int scl_pin)
139 * This function is called during I2C init function. This function 138{
140 * also gets called if I2C encounters any errors. 139 u16 i;
140
141 if (scl_pin) {
142 /* Send high and low on the SCL line */
143 for (i = 0; i < 9; i++) {
144 gpio_set_value(scl_pin, 0);
145 udelay(20);
146 gpio_set_value(scl_pin, 1);
147 udelay(20);
148 }
149 }
150}
151
152/* This routine does i2c bus recovery as specified in the
153 * i2c protocol Rev. 03 section 3.16 titled "Bus clear"
141 */ 154 */
142static int i2c_davinci_init(struct davinci_i2c_dev *dev) 155static void i2c_recover_bus(struct davinci_i2c_dev *dev)
156{
157 u32 flag = 0;
158 struct davinci_i2c_platform_data *pdata = dev->dev->platform_data;
159
160 dev_err(dev->dev, "initiating i2c bus recovery\n");
161 /* Send NACK to the slave */
162 flag = davinci_i2c_read_reg(dev, DAVINCI_I2C_MDR_REG);
163 flag |= DAVINCI_I2C_MDR_NACK;
164 /* write the data into mode register */
165 davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, flag);
166 if (pdata)
167 generic_i2c_clock_pulse(pdata->scl_pin);
168 /* Send STOP */
169 flag = davinci_i2c_read_reg(dev, DAVINCI_I2C_MDR_REG);
170 flag |= DAVINCI_I2C_MDR_STP;
171 davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, flag);
172}
173
174static inline void davinci_i2c_reset_ctrl(struct davinci_i2c_dev *i2c_dev,
175 int val)
176{
177 u16 w;
178
179 w = davinci_i2c_read_reg(i2c_dev, DAVINCI_I2C_MDR_REG);
180 if (!val) /* put I2C into reset */
181 w &= ~DAVINCI_I2C_MDR_IRS;
182 else /* take I2C out of reset */
183 w |= DAVINCI_I2C_MDR_IRS;
184
185 davinci_i2c_write_reg(i2c_dev, DAVINCI_I2C_MDR_REG, w);
186}
187
188static void i2c_davinci_calc_clk_dividers(struct davinci_i2c_dev *dev)
143{ 189{
144 struct davinci_i2c_platform_data *pdata = dev->dev->platform_data; 190 struct davinci_i2c_platform_data *pdata = dev->dev->platform_data;
145 u16 psc; 191 u16 psc;
@@ -148,15 +194,6 @@ static int i2c_davinci_init(struct davinci_i2c_dev *dev)
148 u32 clkh; 194 u32 clkh;
149 u32 clkl; 195 u32 clkl;
150 u32 input_clock = clk_get_rate(dev->clk); 196 u32 input_clock = clk_get_rate(dev->clk);
151 u16 w;
152
153 if (!pdata)
154 pdata = &davinci_i2c_platform_data_default;
155
156 /* put I2C into reset */
157 w = davinci_i2c_read_reg(dev, DAVINCI_I2C_MDR_REG);
158 MOD_REG_BIT(w, DAVINCI_I2C_MDR_IRS, 0);
159 davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, w);
160 197
161 /* NOTE: I2C Clock divider programming info 198 /* NOTE: I2C Clock divider programming info
162 * As per I2C specs the following formulas provide prescaler 199 * As per I2C specs the following formulas provide prescaler
@@ -188,12 +225,32 @@ static int i2c_davinci_init(struct davinci_i2c_dev *dev)
188 davinci_i2c_write_reg(dev, DAVINCI_I2C_CLKH_REG, clkh); 225 davinci_i2c_write_reg(dev, DAVINCI_I2C_CLKH_REG, clkh);
189 davinci_i2c_write_reg(dev, DAVINCI_I2C_CLKL_REG, clkl); 226 davinci_i2c_write_reg(dev, DAVINCI_I2C_CLKL_REG, clkl);
190 227
228 dev_dbg(dev->dev, "input_clock = %d, CLK = %d\n", input_clock, clk);
229}
230
231/*
232 * This function configures I2C and brings I2C out of reset.
233 * This function is called during I2C init function. This function
234 * also gets called if I2C encounters any errors.
235 */
236static int i2c_davinci_init(struct davinci_i2c_dev *dev)
237{
238 struct davinci_i2c_platform_data *pdata = dev->dev->platform_data;
239
240 if (!pdata)
241 pdata = &davinci_i2c_platform_data_default;
242
243 /* put I2C into reset */
244 davinci_i2c_reset_ctrl(dev, 0);
245
246 /* compute clock dividers */
247 i2c_davinci_calc_clk_dividers(dev);
248
191 /* Respond at reserved "SMBus Host" slave address" (and zero); 249 /* Respond at reserved "SMBus Host" slave address" (and zero);
192 * we seem to have no option to not respond... 250 * we seem to have no option to not respond...
193 */ 251 */
194 davinci_i2c_write_reg(dev, DAVINCI_I2C_OAR_REG, 0x08); 252 davinci_i2c_write_reg(dev, DAVINCI_I2C_OAR_REG, 0x08);
195 253
196 dev_dbg(dev->dev, "input_clock = %d, CLK = %d\n", input_clock, clk);
197 dev_dbg(dev->dev, "PSC = %d\n", 254 dev_dbg(dev->dev, "PSC = %d\n",
198 davinci_i2c_read_reg(dev, DAVINCI_I2C_PSC_REG)); 255 davinci_i2c_read_reg(dev, DAVINCI_I2C_PSC_REG));
199 dev_dbg(dev->dev, "CLKL = %d\n", 256 dev_dbg(dev->dev, "CLKL = %d\n",
@@ -204,9 +261,7 @@ static int i2c_davinci_init(struct davinci_i2c_dev *dev)
204 pdata->bus_freq, pdata->bus_delay); 261 pdata->bus_freq, pdata->bus_delay);
205 262
206 /* Take the I2C module out of reset: */ 263 /* Take the I2C module out of reset: */
207 w = davinci_i2c_read_reg(dev, DAVINCI_I2C_MDR_REG); 264 davinci_i2c_reset_ctrl(dev, 1);
208 MOD_REG_BIT(w, DAVINCI_I2C_MDR_IRS, 1);
209 davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, w);
210 265
211 /* Enable interrupts */ 266 /* Enable interrupts */
212 davinci_i2c_write_reg(dev, DAVINCI_I2C_IMR_REG, I2C_DAVINCI_INTR_ALL); 267 davinci_i2c_write_reg(dev, DAVINCI_I2C_IMR_REG, I2C_DAVINCI_INTR_ALL);
@@ -221,14 +276,22 @@ static int i2c_davinci_wait_bus_not_busy(struct davinci_i2c_dev *dev,
221 char allow_sleep) 276 char allow_sleep)
222{ 277{
223 unsigned long timeout; 278 unsigned long timeout;
279 static u16 to_cnt;
224 280
225 timeout = jiffies + dev->adapter.timeout; 281 timeout = jiffies + dev->adapter.timeout;
226 while (davinci_i2c_read_reg(dev, DAVINCI_I2C_STR_REG) 282 while (davinci_i2c_read_reg(dev, DAVINCI_I2C_STR_REG)
227 & DAVINCI_I2C_STR_BB) { 283 & DAVINCI_I2C_STR_BB) {
228 if (time_after(jiffies, timeout)) { 284 if (to_cnt <= DAVINCI_I2C_MAX_TRIES) {
229 dev_warn(dev->dev, 285 if (time_after(jiffies, timeout)) {
230 "timeout waiting for bus ready\n"); 286 dev_warn(dev->dev,
231 return -ETIMEDOUT; 287 "timeout waiting for bus ready\n");
288 to_cnt++;
289 return -ETIMEDOUT;
290 } else {
291 to_cnt = 0;
292 i2c_recover_bus(dev);
293 i2c_davinci_init(dev);
294 }
232 } 295 }
233 if (allow_sleep) 296 if (allow_sleep)
234 schedule_timeout(1); 297 schedule_timeout(1);
@@ -250,9 +313,6 @@ i2c_davinci_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, int stop)
250 u16 w; 313 u16 w;
251 int r; 314 int r;
252 315
253 if (msg->len == 0)
254 return -EINVAL;
255
256 if (!pdata) 316 if (!pdata)
257 pdata = &davinci_i2c_platform_data_default; 317 pdata = &davinci_i2c_platform_data_default;
258 /* Introduce a delay, required for some boards (e.g Davinci EVM) */ 318 /* Introduce a delay, required for some boards (e.g Davinci EVM) */
@@ -264,6 +324,7 @@ i2c_davinci_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, int stop)
264 324
265 dev->buf = msg->buf; 325 dev->buf = msg->buf;
266 dev->buf_len = msg->len; 326 dev->buf_len = msg->len;
327 dev->stop = stop;
267 328
268 davinci_i2c_write_reg(dev, DAVINCI_I2C_CNT_REG, dev->buf_len); 329 davinci_i2c_write_reg(dev, DAVINCI_I2C_CNT_REG, dev->buf_len);
269 330
@@ -281,23 +342,40 @@ i2c_davinci_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, int stop)
281 flag |= DAVINCI_I2C_MDR_TRX; 342 flag |= DAVINCI_I2C_MDR_TRX;
282 if (stop) 343 if (stop)
283 flag |= DAVINCI_I2C_MDR_STP; 344 flag |= DAVINCI_I2C_MDR_STP;
345 if (msg->len == 0) {
346 flag |= DAVINCI_I2C_MDR_RM;
347 flag &= ~DAVINCI_I2C_MDR_STP;
348 }
284 349
285 /* Enable receive or transmit interrupts */ 350 /* Enable receive or transmit interrupts */
286 w = davinci_i2c_read_reg(dev, DAVINCI_I2C_IMR_REG); 351 w = davinci_i2c_read_reg(dev, DAVINCI_I2C_IMR_REG);
287 if (msg->flags & I2C_M_RD) 352 if (msg->flags & I2C_M_RD)
288 MOD_REG_BIT(w, DAVINCI_I2C_IMR_RRDY, 1); 353 w |= DAVINCI_I2C_IMR_RRDY;
289 else 354 else
290 MOD_REG_BIT(w, DAVINCI_I2C_IMR_XRDY, 1); 355 w |= DAVINCI_I2C_IMR_XRDY;
291 davinci_i2c_write_reg(dev, DAVINCI_I2C_IMR_REG, w); 356 davinci_i2c_write_reg(dev, DAVINCI_I2C_IMR_REG, w);
292 357
293 dev->terminate = 0; 358 dev->terminate = 0;
359
294 /* write the data into mode register */ 360 /* write the data into mode register */
295 davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, flag); 361 davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, flag);
296 362
363 /*
364 * First byte should be set here, not after interrupt,
365 * because transmit-data-ready interrupt can come before
366 * NACK-interrupt during sending of previous message and
367 * ICDXR may have wrong data
368 */
369 if ((!(msg->flags & I2C_M_RD)) && dev->buf_len) {
370 davinci_i2c_write_reg(dev, DAVINCI_I2C_DXR_REG, *dev->buf++);
371 dev->buf_len--;
372 }
373
297 r = wait_for_completion_interruptible_timeout(&dev->cmd_complete, 374 r = wait_for_completion_interruptible_timeout(&dev->cmd_complete,
298 dev->adapter.timeout); 375 dev->adapter.timeout);
299 if (r == 0) { 376 if (r == 0) {
300 dev_err(dev->dev, "controller timed out\n"); 377 dev_err(dev->dev, "controller timed out\n");
378 i2c_recover_bus(dev);
301 i2c_davinci_init(dev); 379 i2c_davinci_init(dev);
302 dev->buf_len = 0; 380 dev->buf_len = 0;
303 return -ETIMEDOUT; 381 return -ETIMEDOUT;
@@ -334,7 +412,7 @@ i2c_davinci_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, int stop)
334 return msg->len; 412 return msg->len;
335 if (stop) { 413 if (stop) {
336 w = davinci_i2c_read_reg(dev, DAVINCI_I2C_MDR_REG); 414 w = davinci_i2c_read_reg(dev, DAVINCI_I2C_MDR_REG);
337 MOD_REG_BIT(w, DAVINCI_I2C_MDR_STP, 1); 415 w |= DAVINCI_I2C_MDR_STP;
338 davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, w); 416 davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, w);
339 } 417 }
340 return -EREMOTEIO; 418 return -EREMOTEIO;
@@ -367,12 +445,17 @@ i2c_davinci_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
367 if (ret < 0) 445 if (ret < 0)
368 return ret; 446 return ret;
369 } 447 }
448
449#ifdef CONFIG_CPU_FREQ
450 complete(&dev->xfr_complete);
451#endif
452
370 return num; 453 return num;
371} 454}
372 455
373static u32 i2c_davinci_func(struct i2c_adapter *adap) 456static u32 i2c_davinci_func(struct i2c_adapter *adap)
374{ 457{
375 return I2C_FUNC_I2C | (I2C_FUNC_SMBUS_EMUL & ~I2C_FUNC_SMBUS_QUICK); 458 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
376} 459}
377 460
378static void terminate_read(struct davinci_i2c_dev *dev) 461static void terminate_read(struct davinci_i2c_dev *dev)
@@ -431,6 +514,14 @@ static irqreturn_t i2c_davinci_isr(int this_irq, void *dev_id)
431 case DAVINCI_I2C_IVR_ARDY: 514 case DAVINCI_I2C_IVR_ARDY:
432 davinci_i2c_write_reg(dev, 515 davinci_i2c_write_reg(dev,
433 DAVINCI_I2C_STR_REG, DAVINCI_I2C_STR_ARDY); 516 DAVINCI_I2C_STR_REG, DAVINCI_I2C_STR_ARDY);
517 if (((dev->buf_len == 0) && (dev->stop != 0)) ||
518 (dev->cmd_err & DAVINCI_I2C_STR_NACK)) {
519 w = davinci_i2c_read_reg(dev,
520 DAVINCI_I2C_MDR_REG);
521 w |= DAVINCI_I2C_MDR_STP;
522 davinci_i2c_write_reg(dev,
523 DAVINCI_I2C_MDR_REG, w);
524 }
434 complete(&dev->cmd_complete); 525 complete(&dev->cmd_complete);
435 break; 526 break;
436 527
@@ -462,7 +553,7 @@ static irqreturn_t i2c_davinci_isr(int this_irq, void *dev_id)
462 553
463 w = davinci_i2c_read_reg(dev, 554 w = davinci_i2c_read_reg(dev,
464 DAVINCI_I2C_IMR_REG); 555 DAVINCI_I2C_IMR_REG);
465 MOD_REG_BIT(w, DAVINCI_I2C_IMR_XRDY, 0); 556 w &= ~DAVINCI_I2C_IMR_XRDY;
466 davinci_i2c_write_reg(dev, 557 davinci_i2c_write_reg(dev,
467 DAVINCI_I2C_IMR_REG, 558 DAVINCI_I2C_IMR_REG,
468 w); 559 w);
@@ -491,6 +582,48 @@ static irqreturn_t i2c_davinci_isr(int this_irq, void *dev_id)
491 return count ? IRQ_HANDLED : IRQ_NONE; 582 return count ? IRQ_HANDLED : IRQ_NONE;
492} 583}
493 584
585#ifdef CONFIG_CPU_FREQ
586static int i2c_davinci_cpufreq_transition(struct notifier_block *nb,
587 unsigned long val, void *data)
588{
589 struct davinci_i2c_dev *dev;
590
591 dev = container_of(nb, struct davinci_i2c_dev, freq_transition);
592 if (val == CPUFREQ_PRECHANGE) {
593 wait_for_completion(&dev->xfr_complete);
594 davinci_i2c_reset_ctrl(dev, 0);
595 } else if (val == CPUFREQ_POSTCHANGE) {
596 i2c_davinci_calc_clk_dividers(dev);
597 davinci_i2c_reset_ctrl(dev, 1);
598 }
599
600 return 0;
601}
602
603static inline int i2c_davinci_cpufreq_register(struct davinci_i2c_dev *dev)
604{
605 dev->freq_transition.notifier_call = i2c_davinci_cpufreq_transition;
606
607 return cpufreq_register_notifier(&dev->freq_transition,
608 CPUFREQ_TRANSITION_NOTIFIER);
609}
610
611static inline void i2c_davinci_cpufreq_deregister(struct davinci_i2c_dev *dev)
612{
613 cpufreq_unregister_notifier(&dev->freq_transition,
614 CPUFREQ_TRANSITION_NOTIFIER);
615}
616#else
617static inline int i2c_davinci_cpufreq_register(struct davinci_i2c_dev *dev)
618{
619 return 0;
620}
621
622static inline void i2c_davinci_cpufreq_deregister(struct davinci_i2c_dev *dev)
623{
624}
625#endif
626
494static struct i2c_algorithm i2c_davinci_algo = { 627static struct i2c_algorithm i2c_davinci_algo = {
495 .master_xfer = i2c_davinci_xfer, 628 .master_xfer = i2c_davinci_xfer,
496 .functionality = i2c_davinci_func, 629 .functionality = i2c_davinci_func,
@@ -530,6 +663,9 @@ static int davinci_i2c_probe(struct platform_device *pdev)
530 } 663 }
531 664
532 init_completion(&dev->cmd_complete); 665 init_completion(&dev->cmd_complete);
666#ifdef CONFIG_CPU_FREQ
667 init_completion(&dev->xfr_complete);
668#endif
533 dev->dev = get_device(&pdev->dev); 669 dev->dev = get_device(&pdev->dev);
534 dev->irq = irq->start; 670 dev->irq = irq->start;
535 platform_set_drvdata(pdev, dev); 671 platform_set_drvdata(pdev, dev);
@@ -541,7 +677,12 @@ static int davinci_i2c_probe(struct platform_device *pdev)
541 } 677 }
542 clk_enable(dev->clk); 678 clk_enable(dev->clk);
543 679
544 dev->base = (void __iomem *)IO_ADDRESS(mem->start); 680 dev->base = ioremap(mem->start, resource_size(mem));
681 if (!dev->base) {
682 r = -EBUSY;
683 goto err_mem_ioremap;
684 }
685
545 i2c_davinci_init(dev); 686 i2c_davinci_init(dev);
546 687
547 r = request_irq(dev->irq, i2c_davinci_isr, 0, pdev->name, dev); 688 r = request_irq(dev->irq, i2c_davinci_isr, 0, pdev->name, dev);
@@ -550,6 +691,12 @@ static int davinci_i2c_probe(struct platform_device *pdev)
550 goto err_unuse_clocks; 691 goto err_unuse_clocks;
551 } 692 }
552 693
694 r = i2c_davinci_cpufreq_register(dev);
695 if (r) {
696 dev_err(&pdev->dev, "failed to register cpufreq\n");
697 goto err_free_irq;
698 }
699
553 adap = &dev->adapter; 700 adap = &dev->adapter;
554 i2c_set_adapdata(adap, dev); 701 i2c_set_adapdata(adap, dev);
555 adap->owner = THIS_MODULE; 702 adap->owner = THIS_MODULE;
@@ -571,6 +718,8 @@ static int davinci_i2c_probe(struct platform_device *pdev)
571err_free_irq: 718err_free_irq:
572 free_irq(dev->irq, dev); 719 free_irq(dev->irq, dev);
573err_unuse_clocks: 720err_unuse_clocks:
721 iounmap(dev->base);
722err_mem_ioremap:
574 clk_disable(dev->clk); 723 clk_disable(dev->clk);
575 clk_put(dev->clk); 724 clk_put(dev->clk);
576 dev->clk = NULL; 725 dev->clk = NULL;
@@ -589,6 +738,8 @@ static int davinci_i2c_remove(struct platform_device *pdev)
589 struct davinci_i2c_dev *dev = platform_get_drvdata(pdev); 738 struct davinci_i2c_dev *dev = platform_get_drvdata(pdev);
590 struct resource *mem; 739 struct resource *mem;
591 740
741 i2c_davinci_cpufreq_deregister(dev);
742
592 platform_set_drvdata(pdev, NULL); 743 platform_set_drvdata(pdev, NULL);
593 i2c_del_adapter(&dev->adapter); 744 i2c_del_adapter(&dev->adapter);
594 put_device(&pdev->dev); 745 put_device(&pdev->dev);
@@ -599,6 +750,7 @@ static int davinci_i2c_remove(struct platform_device *pdev)
599 750
600 davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, 0); 751 davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, 0);
601 free_irq(IRQ_I2C, dev); 752 free_irq(IRQ_I2C, dev);
753 iounmap(dev->base);
602 kfree(dev); 754 kfree(dev);
603 755
604 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 756 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -606,6 +758,41 @@ static int davinci_i2c_remove(struct platform_device *pdev)
606 return 0; 758 return 0;
607} 759}
608 760
761#ifdef CONFIG_PM
762static int davinci_i2c_suspend(struct device *dev)
763{
764 struct platform_device *pdev = to_platform_device(dev);
765 struct davinci_i2c_dev *i2c_dev = platform_get_drvdata(pdev);
766
767 /* put I2C into reset */
768 davinci_i2c_reset_ctrl(i2c_dev, 0);
769 clk_disable(i2c_dev->clk);
770
771 return 0;
772}
773
774static int davinci_i2c_resume(struct device *dev)
775{
776 struct platform_device *pdev = to_platform_device(dev);
777 struct davinci_i2c_dev *i2c_dev = platform_get_drvdata(pdev);
778
779 clk_enable(i2c_dev->clk);
780 /* take I2C out of reset */
781 davinci_i2c_reset_ctrl(i2c_dev, 1);
782
783 return 0;
784}
785
786static const struct dev_pm_ops davinci_i2c_pm = {
787 .suspend = davinci_i2c_suspend,
788 .resume = davinci_i2c_resume,
789};
790
791#define davinci_i2c_pm_ops (&davinci_i2c_pm)
792#else
793#define davinci_i2c_pm_ops NULL
794#endif
795
609/* work with hotplug and coldplug */ 796/* work with hotplug and coldplug */
610MODULE_ALIAS("platform:i2c_davinci"); 797MODULE_ALIAS("platform:i2c_davinci");
611 798
@@ -615,6 +802,7 @@ static struct platform_driver davinci_i2c_driver = {
615 .driver = { 802 .driver = {
616 .name = "i2c_davinci", 803 .name = "i2c_davinci",
617 .owner = THIS_MODULE, 804 .owner = THIS_MODULE,
805 .pm = davinci_i2c_pm_ops,
618 }, 806 },
619}; 807};
620 808
diff --git a/drivers/i2c/busses/i2c-ibm_iic.c b/drivers/i2c/busses/i2c-ibm_iic.c
index 1168d61418c9..43ca32fddde2 100644
--- a/drivers/i2c/busses/i2c-ibm_iic.c
+++ b/drivers/i2c/busses/i2c-ibm_iic.c
@@ -661,7 +661,7 @@ static inline u8 iic_clckdiv(unsigned int opb)
661 return (u8)((opb + 9) / 10 - 1); 661 return (u8)((opb + 9) / 10 - 1);
662} 662}
663 663
664static int __devinit iic_request_irq(struct of_device *ofdev, 664static int __devinit iic_request_irq(struct platform_device *ofdev,
665 struct ibm_iic_private *dev) 665 struct ibm_iic_private *dev)
666{ 666{
667 struct device_node *np = ofdev->dev.of_node; 667 struct device_node *np = ofdev->dev.of_node;
@@ -692,7 +692,7 @@ static int __devinit iic_request_irq(struct of_device *ofdev,
692/* 692/*
693 * Register single IIC interface 693 * Register single IIC interface
694 */ 694 */
695static int __devinit iic_probe(struct of_device *ofdev, 695static int __devinit iic_probe(struct platform_device *ofdev,
696 const struct of_device_id *match) 696 const struct of_device_id *match)
697{ 697{
698 struct device_node *np = ofdev->dev.of_node; 698 struct device_node *np = ofdev->dev.of_node;
@@ -780,7 +780,7 @@ error_cleanup:
780/* 780/*
781 * Cleanup initialized IIC interface 781 * Cleanup initialized IIC interface
782 */ 782 */
783static int __devexit iic_remove(struct of_device *ofdev) 783static int __devexit iic_remove(struct platform_device *ofdev)
784{ 784{
785 struct ibm_iic_private *dev = dev_get_drvdata(&ofdev->dev); 785 struct ibm_iic_private *dev = dev_get_drvdata(&ofdev->dev);
786 786
diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c
index 6545d1c99b61..a1c419a716af 100644
--- a/drivers/i2c/busses/i2c-mpc.c
+++ b/drivers/i2c/busses/i2c-mpc.c
@@ -560,7 +560,7 @@ static struct i2c_adapter mpc_ops = {
560 .timeout = HZ, 560 .timeout = HZ,
561}; 561};
562 562
563static int __devinit fsl_i2c_probe(struct of_device *op, 563static int __devinit fsl_i2c_probe(struct platform_device *op,
564 const struct of_device_id *match) 564 const struct of_device_id *match)
565{ 565{
566 struct mpc_i2c *i2c; 566 struct mpc_i2c *i2c;
@@ -646,7 +646,7 @@ static int __devinit fsl_i2c_probe(struct of_device *op,
646 return result; 646 return result;
647}; 647};
648 648
649static int __devexit fsl_i2c_remove(struct of_device *op) 649static int __devexit fsl_i2c_remove(struct platform_device *op)
650{ 650{
651 struct mpc_i2c *i2c = dev_get_drvdata(&op->dev); 651 struct mpc_i2c *i2c = dev_get_drvdata(&op->dev);
652 652
diff --git a/drivers/i2c/busses/i2c-nuc900.c b/drivers/i2c/busses/i2c-nuc900.c
new file mode 100644
index 000000000000..92d770d7bbc2
--- /dev/null
+++ b/drivers/i2c/busses/i2c-nuc900.c
@@ -0,0 +1,709 @@
1/*
2 * linux/drivers/i2c/busses/i2c-nuc900.c
3 *
4 * Copyright (c) 2010 Nuvoton technology corporation.
5 *
6 * This driver based on S3C2410 I2C driver of Ben Dooks <ben-Y5A6D6n0/KfQXOPxS62xeg@public.gmane.org>.
7 * Written by Wan ZongShun <mcuos.com-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
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;version 2 of the License.
12 *
13 */
14
15#include <linux/kernel.h>
16#include <linux/module.h>
17
18#include <linux/i2c.h>
19#include <linux/i2c-id.h>
20#include <linux/init.h>
21#include <linux/time.h>
22#include <linux/interrupt.h>
23#include <linux/delay.h>
24#include <linux/errno.h>
25#include <linux/err.h>
26#include <linux/platform_device.h>
27#include <linux/clk.h>
28#include <linux/cpufreq.h>
29#include <linux/slab.h>
30#include <linux/io.h>
31
32#include <mach/mfp.h>
33#include <mach/i2c.h>
34
35/* nuc900 i2c registers offset */
36
37#define CSR 0x00
38#define DIVIDER 0x04
39#define CMDR 0x08
40#define SWR 0x0C
41#define RXR 0x10
42#define TXR 0x14
43
44/* nuc900 i2c CSR register bits */
45
46#define IRQEN 0x003
47#define I2CBUSY 0x400
48#define I2CSTART 0x018
49#define IRQFLAG 0x004
50#define ARBIT_LOST 0x200
51#define SLAVE_ACK 0x800
52
53/* nuc900 i2c CMDR register bits */
54
55#define I2C_CMD_START 0x10
56#define I2C_CMD_STOP 0x08
57#define I2C_CMD_READ 0x04
58#define I2C_CMD_WRITE 0x02
59#define I2C_CMD_NACK 0x01
60
61/* i2c controller state */
62
63enum nuc900_i2c_state {
64 STATE_IDLE,
65 STATE_START,
66 STATE_READ,
67 STATE_WRITE,
68 STATE_STOP
69};
70
71/* i2c controller private data */
72
73struct nuc900_i2c {
74 spinlock_t lock;
75 wait_queue_head_t wait;
76
77 struct i2c_msg *msg;
78 unsigned int msg_num;
79 unsigned int msg_idx;
80 unsigned int msg_ptr;
81 unsigned int irq;
82
83 enum nuc900_i2c_state state;
84
85 void __iomem *regs;
86 struct clk *clk;
87 struct device *dev;
88 struct resource *ioarea;
89 struct i2c_adapter adap;
90};
91
92/* nuc900_i2c_master_complete
93 *
94 * complete the message and wake up the caller, using the given return code,
95 * or zero to mean ok.
96*/
97
98static inline void nuc900_i2c_master_complete(struct nuc900_i2c *i2c, int ret)
99{
100 dev_dbg(i2c->dev, "master_complete %d\n", ret);
101
102 i2c->msg_ptr = 0;
103 i2c->msg = NULL;
104 i2c->msg_idx++;
105 i2c->msg_num = 0;
106 if (ret)
107 i2c->msg_idx = ret;
108
109 wake_up(&i2c->wait);
110}
111
112/* irq enable/disable functions */
113
114static inline void nuc900_i2c_disable_irq(struct nuc900_i2c *i2c)
115{
116 unsigned long tmp;
117
118 tmp = readl(i2c->regs + CSR);
119 writel(tmp & ~IRQEN, i2c->regs + CSR);
120}
121
122static inline void nuc900_i2c_enable_irq(struct nuc900_i2c *i2c)
123{
124 unsigned long tmp;
125
126 tmp = readl(i2c->regs + CSR);
127 writel(tmp | IRQEN, i2c->regs + CSR);
128}
129
130
131/* nuc900_i2c_message_start
132 *
133 * put the start of a message onto the bus
134*/
135
136static void nuc900_i2c_message_start(struct nuc900_i2c *i2c,
137 struct i2c_msg *msg)
138{
139 unsigned int addr = (msg->addr & 0x7f) << 1;
140
141 if (msg->flags & I2C_M_RD)
142 addr |= 0x1;
143 writel(addr & 0xff, i2c->regs + TXR);
144 writel(I2C_CMD_START | I2C_CMD_WRITE, i2c->regs + CMDR);
145}
146
147static inline void nuc900_i2c_stop(struct nuc900_i2c *i2c, int ret)
148{
149
150 dev_dbg(i2c->dev, "STOP\n");
151
152 /* stop the transfer */
153 i2c->state = STATE_STOP;
154 writel(I2C_CMD_STOP, i2c->regs + CMDR);
155
156 nuc900_i2c_master_complete(i2c, ret);
157 nuc900_i2c_disable_irq(i2c);
158}
159
160/* helper functions to determine the current state in the set of
161 * messages we are sending
162*/
163
164/* is_lastmsg()
165 *
166 * returns TRUE if the current message is the last in the set
167*/
168
169static inline int is_lastmsg(struct nuc900_i2c *i2c)
170{
171 return i2c->msg_idx >= (i2c->msg_num - 1);
172}
173
174/* is_msglast
175 *
176 * returns TRUE if we this is the last byte in the current message
177*/
178
179static inline int is_msglast(struct nuc900_i2c *i2c)
180{
181 return i2c->msg_ptr == i2c->msg->len-1;
182}
183
184/* is_msgend
185 *
186 * returns TRUE if we reached the end of the current message
187*/
188
189static inline int is_msgend(struct nuc900_i2c *i2c)
190{
191 return i2c->msg_ptr >= i2c->msg->len;
192}
193
194/* i2c_nuc900_irq_nextbyte
195 *
196 * process an interrupt and work out what to do
197 */
198
199static void i2c_nuc900_irq_nextbyte(struct nuc900_i2c *i2c,
200 unsigned long iicstat)
201{
202 unsigned char byte;
203
204 switch (i2c->state) {
205
206 case STATE_IDLE:
207 dev_err(i2c->dev, "%s: called in STATE_IDLE\n", __func__);
208 break;
209
210 case STATE_STOP:
211 dev_err(i2c->dev, "%s: called in STATE_STOP\n", __func__);
212 nuc900_i2c_disable_irq(i2c);
213 break;
214
215 case STATE_START:
216 /* last thing we did was send a start condition on the
217 * bus, or started a new i2c message
218 */
219
220 if (iicstat & SLAVE_ACK &&
221 !(i2c->msg->flags & I2C_M_IGNORE_NAK)) {
222 /* ack was not received... */
223
224 dev_dbg(i2c->dev, "ack was not received\n");
225 nuc900_i2c_stop(i2c, -ENXIO);
226 break;
227 }
228
229 if (i2c->msg->flags & I2C_M_RD)
230 i2c->state = STATE_READ;
231 else
232 i2c->state = STATE_WRITE;
233
234 /* terminate the transfer if there is nothing to do
235 * as this is used by the i2c probe to find devices.
236 */
237
238 if (is_lastmsg(i2c) && i2c->msg->len == 0) {
239 nuc900_i2c_stop(i2c, 0);
240 break;
241 }
242
243 if (i2c->state == STATE_READ)
244 goto prepare_read;
245
246 /* fall through to the write state, as we will need to
247 * send a byte as well
248 */
249
250 case STATE_WRITE:
251 /* we are writing data to the device... check for the
252 * end of the message, and if so, work out what to do
253 */
254
255 if (!(i2c->msg->flags & I2C_M_IGNORE_NAK)) {
256 if (iicstat & SLAVE_ACK) {
257 dev_dbg(i2c->dev, "WRITE: No Ack\n");
258
259 nuc900_i2c_stop(i2c, -ECONNREFUSED);
260 break;
261 }
262 }
263
264retry_write:
265
266 if (!is_msgend(i2c)) {
267 byte = i2c->msg->buf[i2c->msg_ptr++];
268 writeb(byte, i2c->regs + TXR);
269 writel(I2C_CMD_WRITE, i2c->regs + CMDR);
270
271 } else if (!is_lastmsg(i2c)) {
272 /* we need to go to the next i2c message */
273
274 dev_dbg(i2c->dev, "WRITE: Next Message\n");
275
276 i2c->msg_ptr = 0;
277 i2c->msg_idx++;
278 i2c->msg++;
279
280 /* check to see if we need to do another message */
281 if (i2c->msg->flags & I2C_M_NOSTART) {
282
283 if (i2c->msg->flags & I2C_M_RD) {
284 /* cannot do this, the controller
285 * forces us to send a new START
286 * when we change direction
287 */
288
289 nuc900_i2c_stop(i2c, -EINVAL);
290 }
291
292 goto retry_write;
293 } else {
294 /* send the new start */
295 nuc900_i2c_message_start(i2c, i2c->msg);
296 i2c->state = STATE_START;
297 }
298
299 } else {
300 /* send stop */
301
302 nuc900_i2c_stop(i2c, 0);
303 }
304 break;
305
306 case STATE_READ:
307 /* we have a byte of data in the data register, do
308 * something with it, and then work out wether we are
309 * going to do any more read/write
310 */
311
312 byte = readb(i2c->regs + RXR);
313 i2c->msg->buf[i2c->msg_ptr++] = byte;
314
315prepare_read:
316 if (is_msglast(i2c)) {
317 /* last byte of buffer */
318
319 if (is_lastmsg(i2c))
320 writel(I2C_CMD_READ | I2C_CMD_NACK,
321 i2c->regs + CMDR);
322
323 } else if (is_msgend(i2c)) {
324 /* ok, we've read the entire buffer, see if there
325 * is anything else we need to do
326 */
327
328 if (is_lastmsg(i2c)) {
329 /* last message, send stop and complete */
330 dev_dbg(i2c->dev, "READ: Send Stop\n");
331
332 nuc900_i2c_stop(i2c, 0);
333 } else {
334 /* go to the next transfer */
335 dev_dbg(i2c->dev, "READ: Next Transfer\n");
336
337 i2c->msg_ptr = 0;
338 i2c->msg_idx++;
339 i2c->msg++;
340
341 writel(I2C_CMD_READ, i2c->regs + CMDR);
342 }
343
344 } else {
345 writel(I2C_CMD_READ, i2c->regs + CMDR);
346 }
347
348 break;
349 }
350}
351
352/* nuc900_i2c_irq
353 *
354 * top level IRQ servicing routine
355*/
356
357static irqreturn_t nuc900_i2c_irq(int irqno, void *dev_id)
358{
359 struct nuc900_i2c *i2c = dev_id;
360 unsigned long status;
361
362 status = readl(i2c->regs + CSR);
363 writel(status | IRQFLAG, i2c->regs + CSR);
364
365 if (status & ARBIT_LOST) {
366 /* deal with arbitration loss */
367 dev_err(i2c->dev, "deal with arbitration loss\n");
368 goto out;
369 }
370
371 if (i2c->state == STATE_IDLE) {
372 dev_dbg(i2c->dev, "IRQ: error i2c->state == IDLE\n");
373 goto out;
374 }
375
376 /* pretty much this leaves us with the fact that we've
377 * transmitted or received whatever byte we last sent
378 */
379
380 i2c_nuc900_irq_nextbyte(i2c, status);
381
382 out:
383 return IRQ_HANDLED;
384}
385
386
387/* nuc900_i2c_set_master
388 *
389 * get the i2c bus for a master transaction
390*/
391
392static int nuc900_i2c_set_master(struct nuc900_i2c *i2c)
393{
394 int timeout = 400;
395
396 while (timeout-- > 0) {
397 if (((readl(i2c->regs + SWR) & I2CSTART) == I2CSTART) &&
398 ((readl(i2c->regs + CSR) & I2CBUSY) == 0)) {
399 return 0;
400 }
401
402 msleep(1);
403 }
404
405 return -ETIMEDOUT;
406}
407
408/* nuc900_i2c_doxfer
409 *
410 * this starts an i2c transfer
411*/
412
413static int nuc900_i2c_doxfer(struct nuc900_i2c *i2c,
414 struct i2c_msg *msgs, int num)
415{
416 unsigned long iicstat, timeout;
417 int spins = 20;
418 int ret;
419
420 ret = nuc900_i2c_set_master(i2c);
421 if (ret != 0) {
422 dev_err(i2c->dev, "cannot get bus (error %d)\n", ret);
423 ret = -EAGAIN;
424 goto out;
425 }
426
427 spin_lock_irq(&i2c->lock);
428
429 i2c->msg = msgs;
430 i2c->msg_num = num;
431 i2c->msg_ptr = 0;
432 i2c->msg_idx = 0;
433 i2c->state = STATE_START;
434
435 nuc900_i2c_message_start(i2c, msgs);
436 spin_unlock_irq(&i2c->lock);
437
438 timeout = wait_event_timeout(i2c->wait, i2c->msg_num == 0, HZ * 5);
439
440 ret = i2c->msg_idx;
441
442 /* having these next two as dev_err() makes life very
443 * noisy when doing an i2cdetect
444 */
445
446 if (timeout == 0)
447 dev_dbg(i2c->dev, "timeout\n");
448 else if (ret != num)
449 dev_dbg(i2c->dev, "incomplete xfer (%d)\n", ret);
450
451 /* ensure the stop has been through the bus */
452
453 dev_dbg(i2c->dev, "waiting for bus idle\n");
454
455 /* first, try busy waiting briefly */
456 do {
457 iicstat = readl(i2c->regs + CSR);
458 } while ((iicstat & I2CBUSY) && --spins);
459
460 /* if that timed out sleep */
461 if (!spins) {
462 msleep(1);
463 iicstat = readl(i2c->regs + CSR);
464 }
465
466 if (iicstat & I2CBUSY)
467 dev_warn(i2c->dev, "timeout waiting for bus idle\n");
468
469 out:
470 return ret;
471}
472
473/* nuc900_i2c_xfer
474 *
475 * first port of call from the i2c bus code when an message needs
476 * transferring across the i2c bus.
477*/
478
479static int nuc900_i2c_xfer(struct i2c_adapter *adap,
480 struct i2c_msg *msgs, int num)
481{
482 struct nuc900_i2c *i2c = (struct nuc900_i2c *)adap->algo_data;
483 int retry;
484 int ret;
485
486 nuc900_i2c_enable_irq(i2c);
487
488 for (retry = 0; retry < adap->retries; retry++) {
489
490 ret = nuc900_i2c_doxfer(i2c, msgs, num);
491
492 if (ret != -EAGAIN)
493 return ret;
494
495 dev_dbg(i2c->dev, "Retrying transmission (%d)\n", retry);
496
497 udelay(100);
498 }
499
500 return -EREMOTEIO;
501}
502
503/* declare our i2c functionality */
504static u32 nuc900_i2c_func(struct i2c_adapter *adap)
505{
506 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_PROTOCOL_MANGLING;
507}
508
509/* i2c bus registration info */
510
511static const struct i2c_algorithm nuc900_i2c_algorithm = {
512 .master_xfer = nuc900_i2c_xfer,
513 .functionality = nuc900_i2c_func,
514};
515
516/* nuc900_i2c_probe
517 *
518 * called by the bus driver when a suitable device is found
519*/
520
521static int __devinit nuc900_i2c_probe(struct platform_device *pdev)
522{
523 struct nuc900_i2c *i2c;
524 struct nuc900_platform_i2c *pdata;
525 struct resource *res;
526 int ret;
527
528 pdata = pdev->dev.platform_data;
529 if (!pdata) {
530 dev_err(&pdev->dev, "no platform data\n");
531 return -EINVAL;
532 }
533
534 i2c = kzalloc(sizeof(struct nuc900_i2c), GFP_KERNEL);
535 if (!i2c) {
536 dev_err(&pdev->dev, "no memory for state\n");
537 return -ENOMEM;
538 }
539
540 strlcpy(i2c->adap.name, "nuc900-i2c0", sizeof(i2c->adap.name));
541 i2c->adap.owner = THIS_MODULE;
542 i2c->adap.algo = &nuc900_i2c_algorithm;
543 i2c->adap.retries = 2;
544 i2c->adap.class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
545
546 spin_lock_init(&i2c->lock);
547 init_waitqueue_head(&i2c->wait);
548
549 /* find the clock and enable it */
550
551 i2c->dev = &pdev->dev;
552 i2c->clk = clk_get(&pdev->dev, NULL);
553 if (IS_ERR(i2c->clk)) {
554 dev_err(&pdev->dev, "cannot get clock\n");
555 ret = -ENOENT;
556 goto err_noclk;
557 }
558
559 dev_dbg(&pdev->dev, "clock source %p\n", i2c->clk);
560
561 clk_enable(i2c->clk);
562
563 /* map the registers */
564
565 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
566 if (res == NULL) {
567 dev_err(&pdev->dev, "cannot find IO resource\n");
568 ret = -ENOENT;
569 goto err_clk;
570 }
571
572 i2c->ioarea = request_mem_region(res->start, resource_size(res),
573 pdev->name);
574
575 if (i2c->ioarea == NULL) {
576 dev_err(&pdev->dev, "cannot request IO\n");
577 ret = -ENXIO;
578 goto err_clk;
579 }
580
581 i2c->regs = ioremap(res->start, resource_size(res));
582
583 if (i2c->regs == NULL) {
584 dev_err(&pdev->dev, "cannot map IO\n");
585 ret = -ENXIO;
586 goto err_ioarea;
587 }
588
589 dev_dbg(&pdev->dev, "registers %p (%p, %p)\n",
590 i2c->regs, i2c->ioarea, res);
591
592 /* setup info block for the i2c core */
593
594 i2c->adap.algo_data = i2c;
595 i2c->adap.dev.parent = &pdev->dev;
596
597 mfp_set_groupg(&pdev->dev);
598
599 clk_get_rate(i2c->clk);
600
601 ret = (i2c->clk.apbfreq)/(pdata->bus_freq * 5) - 1;
602 writel(ret & 0xffff, i2c->regs + DIVIDER);
603
604 /* find the IRQ for this unit (note, this relies on the init call to
605 * ensure no current IRQs pending
606 */
607
608 i2c->irq = ret = platform_get_irq(pdev, 0);
609 if (ret <= 0) {
610 dev_err(&pdev->dev, "cannot find IRQ\n");
611 goto err_iomap;
612 }
613
614 ret = request_irq(i2c->irq, nuc900_i2c_irq, IRQF_DISABLED | IRQF_SHARED,
615 dev_name(&pdev->dev), i2c);
616
617 if (ret != 0) {
618 dev_err(&pdev->dev, "cannot claim IRQ %d\n", i2c->irq);
619 goto err_iomap;
620 }
621
622 /* Note, previous versions of the driver used i2c_add_adapter()
623 * to add the bus at any number. We now pass the bus number via
624 * the platform data, so if unset it will now default to always
625 * being bus 0.
626 */
627
628 i2c->adap.nr = pdata->bus_num;
629
630 ret = i2c_add_numbered_adapter(&i2c->adap);
631 if (ret < 0) {
632 dev_err(&pdev->dev, "failed to add bus to i2c core\n");
633 goto err_irq;
634 }
635
636 platform_set_drvdata(pdev, i2c);
637
638 dev_info(&pdev->dev, "%s: NUC900 I2C adapter\n",
639 dev_name(&i2c->adap.dev));
640 return 0;
641
642 err_irq:
643 free_irq(i2c->irq, i2c);
644
645 err_iomap:
646 iounmap(i2c->regs);
647
648 err_ioarea:
649 release_resource(i2c->ioarea);
650 kfree(i2c->ioarea);
651
652 err_clk:
653 clk_disable(i2c->clk);
654 clk_put(i2c->clk);
655
656 err_noclk:
657 kfree(i2c);
658 return ret;
659}
660
661/* nuc900_i2c_remove
662 *
663 * called when device is removed from the bus
664*/
665
666static int __devexit nuc900_i2c_remove(struct platform_device *pdev)
667{
668 struct nuc900_i2c *i2c = platform_get_drvdata(pdev);
669
670 i2c_del_adapter(&i2c->adap);
671 free_irq(i2c->irq, i2c);
672
673 clk_disable(i2c->clk);
674 clk_put(i2c->clk);
675
676 iounmap(i2c->regs);
677
678 release_resource(i2c->ioarea);
679 kfree(i2c->ioarea);
680 kfree(i2c);
681
682 return 0;
683}
684
685static struct platform_driver nuc900_i2c_driver = {
686 .probe = nuc900_i2c_probe,
687 .remove = __devexit_p(nuc900_i2c_remove),
688 .driver = {
689 .owner = THIS_MODULE,
690 .name = "nuc900-i2c0",
691 },
692};
693
694static int __init i2c_adap_nuc900_init(void)
695{
696 return platform_driver_register(&nuc900_i2c_driver);
697}
698
699static void __exit i2c_adap_nuc900_exit(void)
700{
701 platform_driver_unregister(&nuc900_i2c_driver);
702}
703subsys_initcall(i2c_adap_nuc900_init);
704module_exit(i2c_adap_nuc900_exit);
705
706MODULE_DESCRIPTION("NUC900 I2C Bus driver");
707MODULE_AUTHOR("Wan ZongShun, <mcuos.com-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>");
708MODULE_LICENSE("GPL");
709MODULE_ALIAS("platform:nuc900-i2c0");
diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c
index 020ff23d762f..c94e51b2651e 100644
--- a/drivers/i2c/busses/i2c-pxa.c
+++ b/drivers/i2c/busses/i2c-pxa.c
@@ -1001,7 +1001,7 @@ static int i2c_pxa_probe(struct platform_device *dev)
1001 struct pxa_i2c *i2c; 1001 struct pxa_i2c *i2c;
1002 struct resource *res; 1002 struct resource *res;
1003 struct i2c_pxa_platform_data *plat = dev->dev.platform_data; 1003 struct i2c_pxa_platform_data *plat = dev->dev.platform_data;
1004 struct platform_device_id *id = platform_get_device_id(dev); 1004 const struct platform_device_id *id = platform_get_device_id(dev);
1005 int ret; 1005 int ret;
1006 int irq; 1006 int irq;
1007 1007
diff --git a/drivers/i2c/busses/i2c-sh_mobile.c b/drivers/i2c/busses/i2c-sh_mobile.c
index ffb405d7c6f2..598c49acaeb5 100644
--- a/drivers/i2c/busses/i2c-sh_mobile.c
+++ b/drivers/i2c/busses/i2c-sh_mobile.c
@@ -119,8 +119,10 @@ struct sh_mobile_i2c_data {
119 struct i2c_adapter adap; 119 struct i2c_adapter adap;
120 120
121 struct clk *clk; 121 struct clk *clk;
122 u_int8_t icic;
122 u_int8_t iccl; 123 u_int8_t iccl;
123 u_int8_t icch; 124 u_int8_t icch;
125 u_int8_t flags;
124 126
125 spinlock_t lock; 127 spinlock_t lock;
126 wait_queue_head_t wait; 128 wait_queue_head_t wait;
@@ -129,15 +131,17 @@ struct sh_mobile_i2c_data {
129 int sr; 131 int sr;
130}; 132};
131 133
134#define IIC_FLAG_HAS_ICIC67 (1 << 0)
135
132#define NORMAL_SPEED 100000 /* FAST_SPEED 400000 */ 136#define NORMAL_SPEED 100000 /* FAST_SPEED 400000 */
133 137
134/* Register offsets */ 138/* Register offsets */
135#define ICDR(pd) (pd->reg + 0x00) 139#define ICDR 0x00
136#define ICCR(pd) (pd->reg + 0x04) 140#define ICCR 0x04
137#define ICSR(pd) (pd->reg + 0x08) 141#define ICSR 0x08
138#define ICIC(pd) (pd->reg + 0x0c) 142#define ICIC 0x0c
139#define ICCL(pd) (pd->reg + 0x10) 143#define ICCL 0x10
140#define ICCH(pd) (pd->reg + 0x14) 144#define ICCH 0x14
141 145
142/* Register bits */ 146/* Register bits */
143#define ICCR_ICE 0x80 147#define ICCR_ICE 0x80
@@ -155,11 +159,32 @@ struct sh_mobile_i2c_data {
155#define ICSR_WAIT 0x02 159#define ICSR_WAIT 0x02
156#define ICSR_DTE 0x01 160#define ICSR_DTE 0x01
157 161
162#define ICIC_ICCLB8 0x80
163#define ICIC_ICCHB8 0x40
158#define ICIC_ALE 0x08 164#define ICIC_ALE 0x08
159#define ICIC_TACKE 0x04 165#define ICIC_TACKE 0x04
160#define ICIC_WAITE 0x02 166#define ICIC_WAITE 0x02
161#define ICIC_DTEE 0x01 167#define ICIC_DTEE 0x01
162 168
169static void iic_wr(struct sh_mobile_i2c_data *pd, int offs, unsigned char data)
170{
171 if (offs == ICIC)
172 data |= pd->icic;
173
174 iowrite8(data, pd->reg + offs);
175}
176
177static unsigned char iic_rd(struct sh_mobile_i2c_data *pd, int offs)
178{
179 return ioread8(pd->reg + offs);
180}
181
182static void iic_set_clr(struct sh_mobile_i2c_data *pd, int offs,
183 unsigned char set, unsigned char clr)
184{
185 iic_wr(pd, offs, (iic_rd(pd, offs) | set) & ~clr);
186}
187
163static void activate_ch(struct sh_mobile_i2c_data *pd) 188static void activate_ch(struct sh_mobile_i2c_data *pd)
164{ 189{
165 unsigned long i2c_clk; 190 unsigned long i2c_clk;
@@ -187,6 +212,14 @@ static void activate_ch(struct sh_mobile_i2c_data *pd)
187 else 212 else
188 pd->iccl = (u_int8_t)(num/denom); 213 pd->iccl = (u_int8_t)(num/denom);
189 214
215 /* one more bit of ICCL in ICIC */
216 if (pd->flags & IIC_FLAG_HAS_ICIC67) {
217 if ((num/denom) > 0xff)
218 pd->icic |= ICIC_ICCLB8;
219 else
220 pd->icic &= ~ICIC_ICCLB8;
221 }
222
190 /* Calculate the value for icch. From the data sheet: 223 /* Calculate the value for icch. From the data sheet:
191 icch = (p clock / transfer rate) * (H / (L + H)) */ 224 icch = (p clock / transfer rate) * (H / (L + H)) */
192 num = i2c_clk * 4; 225 num = i2c_clk * 4;
@@ -196,25 +229,33 @@ static void activate_ch(struct sh_mobile_i2c_data *pd)
196 else 229 else
197 pd->icch = (u_int8_t)(num/denom); 230 pd->icch = (u_int8_t)(num/denom);
198 231
232 /* one more bit of ICCH in ICIC */
233 if (pd->flags & IIC_FLAG_HAS_ICIC67) {
234 if ((num/denom) > 0xff)
235 pd->icic |= ICIC_ICCHB8;
236 else
237 pd->icic &= ~ICIC_ICCHB8;
238 }
239
199 /* Enable channel and configure rx ack */ 240 /* Enable channel and configure rx ack */
200 iowrite8(ioread8(ICCR(pd)) | ICCR_ICE, ICCR(pd)); 241 iic_set_clr(pd, ICCR, ICCR_ICE, 0);
201 242
202 /* Mask all interrupts */ 243 /* Mask all interrupts */
203 iowrite8(0, ICIC(pd)); 244 iic_wr(pd, ICIC, 0);
204 245
205 /* Set the clock */ 246 /* Set the clock */
206 iowrite8(pd->iccl, ICCL(pd)); 247 iic_wr(pd, ICCL, pd->iccl);
207 iowrite8(pd->icch, ICCH(pd)); 248 iic_wr(pd, ICCH, pd->icch);
208} 249}
209 250
210static void deactivate_ch(struct sh_mobile_i2c_data *pd) 251static void deactivate_ch(struct sh_mobile_i2c_data *pd)
211{ 252{
212 /* Clear/disable interrupts */ 253 /* Clear/disable interrupts */
213 iowrite8(0, ICSR(pd)); 254 iic_wr(pd, ICSR, 0);
214 iowrite8(0, ICIC(pd)); 255 iic_wr(pd, ICIC, 0);
215 256
216 /* Disable channel */ 257 /* Disable channel */
217 iowrite8(ioread8(ICCR(pd)) & ~ICCR_ICE, ICCR(pd)); 258 iic_set_clr(pd, ICCR, 0, ICCR_ICE);
218 259
219 /* Disable clock and mark device as idle */ 260 /* Disable clock and mark device as idle */
220 clk_disable(pd->clk); 261 clk_disable(pd->clk);
@@ -233,35 +274,35 @@ static unsigned char i2c_op(struct sh_mobile_i2c_data *pd,
233 274
234 switch (op) { 275 switch (op) {
235 case OP_START: /* issue start and trigger DTE interrupt */ 276 case OP_START: /* issue start and trigger DTE interrupt */
236 iowrite8(0x94, ICCR(pd)); 277 iic_wr(pd, ICCR, 0x94);
237 break; 278 break;
238 case OP_TX_FIRST: /* disable DTE interrupt and write data */ 279 case OP_TX_FIRST: /* disable DTE interrupt and write data */
239 iowrite8(ICIC_WAITE | ICIC_ALE | ICIC_TACKE, ICIC(pd)); 280 iic_wr(pd, ICIC, ICIC_WAITE | ICIC_ALE | ICIC_TACKE);
240 iowrite8(data, ICDR(pd)); 281 iic_wr(pd, ICDR, data);
241 break; 282 break;
242 case OP_TX: /* write data */ 283 case OP_TX: /* write data */
243 iowrite8(data, ICDR(pd)); 284 iic_wr(pd, ICDR, data);
244 break; 285 break;
245 case OP_TX_STOP: /* write data and issue a stop afterwards */ 286 case OP_TX_STOP: /* write data and issue a stop afterwards */
246 iowrite8(data, ICDR(pd)); 287 iic_wr(pd, ICDR, data);
247 iowrite8(0x90, ICCR(pd)); 288 iic_wr(pd, ICCR, 0x90);
248 break; 289 break;
249 case OP_TX_TO_RX: /* select read mode */ 290 case OP_TX_TO_RX: /* select read mode */
250 iowrite8(0x81, ICCR(pd)); 291 iic_wr(pd, ICCR, 0x81);
251 break; 292 break;
252 case OP_RX: /* just read data */ 293 case OP_RX: /* just read data */
253 ret = ioread8(ICDR(pd)); 294 ret = iic_rd(pd, ICDR);
254 break; 295 break;
255 case OP_RX_STOP: /* enable DTE interrupt, issue stop */ 296 case OP_RX_STOP: /* enable DTE interrupt, issue stop */
256 iowrite8(ICIC_DTEE | ICIC_WAITE | ICIC_ALE | ICIC_TACKE, 297 iic_wr(pd, ICIC,
257 ICIC(pd)); 298 ICIC_DTEE | ICIC_WAITE | ICIC_ALE | ICIC_TACKE);
258 iowrite8(0xc0, ICCR(pd)); 299 iic_wr(pd, ICCR, 0xc0);
259 break; 300 break;
260 case OP_RX_STOP_DATA: /* enable DTE interrupt, read data, issue stop */ 301 case OP_RX_STOP_DATA: /* enable DTE interrupt, read data, issue stop */
261 iowrite8(ICIC_DTEE | ICIC_WAITE | ICIC_ALE | ICIC_TACKE, 302 iic_wr(pd, ICIC,
262 ICIC(pd)); 303 ICIC_DTEE | ICIC_WAITE | ICIC_ALE | ICIC_TACKE);
263 ret = ioread8(ICDR(pd)); 304 ret = iic_rd(pd, ICDR);
264 iowrite8(0xc0, ICCR(pd)); 305 iic_wr(pd, ICCR, 0xc0);
265 break; 306 break;
266 } 307 }
267 308
@@ -367,7 +408,7 @@ static irqreturn_t sh_mobile_i2c_isr(int irq, void *dev_id)
367 unsigned char sr; 408 unsigned char sr;
368 int wakeup; 409 int wakeup;
369 410
370 sr = ioread8(ICSR(pd)); 411 sr = iic_rd(pd, ICSR);
371 pd->sr |= sr; /* remember state */ 412 pd->sr |= sr; /* remember state */
372 413
373 dev_dbg(pd->dev, "i2c_isr 0x%02x 0x%02x %s %d %d!\n", sr, pd->sr, 414 dev_dbg(pd->dev, "i2c_isr 0x%02x 0x%02x %s %d %d!\n", sr, pd->sr,
@@ -376,7 +417,7 @@ static irqreturn_t sh_mobile_i2c_isr(int irq, void *dev_id)
376 417
377 if (sr & (ICSR_AL | ICSR_TACK)) { 418 if (sr & (ICSR_AL | ICSR_TACK)) {
378 /* don't interrupt transaction - continue to issue stop */ 419 /* don't interrupt transaction - continue to issue stop */
379 iowrite8(sr & ~(ICSR_AL | ICSR_TACK), ICSR(pd)); 420 iic_wr(pd, ICSR, sr & ~(ICSR_AL | ICSR_TACK));
380 wakeup = 0; 421 wakeup = 0;
381 } else if (pd->msg->flags & I2C_M_RD) 422 } else if (pd->msg->flags & I2C_M_RD)
382 wakeup = sh_mobile_i2c_isr_rx(pd); 423 wakeup = sh_mobile_i2c_isr_rx(pd);
@@ -384,7 +425,7 @@ static irqreturn_t sh_mobile_i2c_isr(int irq, void *dev_id)
384 wakeup = sh_mobile_i2c_isr_tx(pd); 425 wakeup = sh_mobile_i2c_isr_tx(pd);
385 426
386 if (sr & ICSR_WAIT) /* TODO: add delay here to support slow acks */ 427 if (sr & ICSR_WAIT) /* TODO: add delay here to support slow acks */
387 iowrite8(sr & ~ICSR_WAIT, ICSR(pd)); 428 iic_wr(pd, ICSR, sr & ~ICSR_WAIT);
388 429
389 if (wakeup) { 430 if (wakeup) {
390 pd->sr |= SW_DONE; 431 pd->sr |= SW_DONE;
@@ -402,21 +443,21 @@ static int start_ch(struct sh_mobile_i2c_data *pd, struct i2c_msg *usr_msg)
402 } 443 }
403 444
404 /* Initialize channel registers */ 445 /* Initialize channel registers */
405 iowrite8(ioread8(ICCR(pd)) & ~ICCR_ICE, ICCR(pd)); 446 iic_set_clr(pd, ICCR, 0, ICCR_ICE);
406 447
407 /* Enable channel and configure rx ack */ 448 /* Enable channel and configure rx ack */
408 iowrite8(ioread8(ICCR(pd)) | ICCR_ICE, ICCR(pd)); 449 iic_set_clr(pd, ICCR, ICCR_ICE, 0);
409 450
410 /* Set the clock */ 451 /* Set the clock */
411 iowrite8(pd->iccl, ICCL(pd)); 452 iic_wr(pd, ICCL, pd->iccl);
412 iowrite8(pd->icch, ICCH(pd)); 453 iic_wr(pd, ICCH, pd->icch);
413 454
414 pd->msg = usr_msg; 455 pd->msg = usr_msg;
415 pd->pos = -1; 456 pd->pos = -1;
416 pd->sr = 0; 457 pd->sr = 0;
417 458
418 /* Enable all interrupts to begin with */ 459 /* Enable all interrupts to begin with */
419 iowrite8(ICIC_WAITE | ICIC_ALE | ICIC_TACKE | ICIC_DTEE, ICIC(pd)); 460 iic_wr(pd, ICIC, ICIC_DTEE | ICIC_WAITE | ICIC_ALE | ICIC_TACKE);
420 return 0; 461 return 0;
421} 462}
422 463
@@ -451,7 +492,7 @@ static int sh_mobile_i2c_xfer(struct i2c_adapter *adapter,
451 492
452 retry_count = 1000; 493 retry_count = 1000;
453again: 494again:
454 val = ioread8(ICSR(pd)); 495 val = iic_rd(pd, ICSR);
455 496
456 dev_dbg(pd->dev, "val 0x%02x pd->sr 0x%02x\n", val, pd->sr); 497 dev_dbg(pd->dev, "val 0x%02x pd->sr 0x%02x\n", val, pd->sr);
457 498
@@ -576,6 +617,12 @@ static int sh_mobile_i2c_probe(struct platform_device *dev)
576 goto err_irq; 617 goto err_irq;
577 } 618 }
578 619
620 /* The IIC blocks on SH-Mobile ARM processors
621 * come with two new bits in ICIC.
622 */
623 if (size > 0x17)
624 pd->flags |= IIC_FLAG_HAS_ICIC67;
625
579 /* Enable Runtime PM for this device. 626 /* Enable Runtime PM for this device.
580 * 627 *
581 * Also tell the Runtime PM core to ignore children 628 * Also tell the Runtime PM core to ignore children
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index df937df845eb..6649176de940 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -20,7 +20,9 @@
20/* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi>. 20/* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi>.
21 All SMBus-related things are written by Frodo Looijaard <frodol@dds.nl> 21 All SMBus-related things are written by Frodo Looijaard <frodol@dds.nl>
22 SMBus 2.0 support by Mark Studebaker <mdsxyz123@yahoo.com> and 22 SMBus 2.0 support by Mark Studebaker <mdsxyz123@yahoo.com> and
23 Jean Delvare <khali@linux-fr.org> */ 23 Jean Delvare <khali@linux-fr.org>
24 Mux support by Rodolfo Giometti <giometti@enneenne.com> and
25 Michael Lawnick <michael.lawnick.ext@nsn.com> */
24 26
25#include <linux/module.h> 27#include <linux/module.h>
26#include <linux/kernel.h> 28#include <linux/kernel.h>
@@ -423,11 +425,87 @@ static int __i2c_check_addr_busy(struct device *dev, void *addrp)
423 return 0; 425 return 0;
424} 426}
425 427
428/* walk up mux tree */
429static int i2c_check_mux_parents(struct i2c_adapter *adapter, int addr)
430{
431 int result;
432
433 result = device_for_each_child(&adapter->dev, &addr,
434 __i2c_check_addr_busy);
435
436 if (!result && i2c_parent_is_i2c_adapter(adapter))
437 result = i2c_check_mux_parents(
438 to_i2c_adapter(adapter->dev.parent), addr);
439
440 return result;
441}
442
443/* recurse down mux tree */
444static int i2c_check_mux_children(struct device *dev, void *addrp)
445{
446 int result;
447
448 if (dev->type == &i2c_adapter_type)
449 result = device_for_each_child(dev, addrp,
450 i2c_check_mux_children);
451 else
452 result = __i2c_check_addr_busy(dev, addrp);
453
454 return result;
455}
456
426static int i2c_check_addr_busy(struct i2c_adapter *adapter, int addr) 457static int i2c_check_addr_busy(struct i2c_adapter *adapter, int addr)
427{ 458{
428 return device_for_each_child(&adapter->dev, &addr, 459 int result = 0;
429 __i2c_check_addr_busy); 460
461 if (i2c_parent_is_i2c_adapter(adapter))
462 result = i2c_check_mux_parents(
463 to_i2c_adapter(adapter->dev.parent), addr);
464
465 if (!result)
466 result = device_for_each_child(&adapter->dev, &addr,
467 i2c_check_mux_children);
468
469 return result;
470}
471
472/**
473 * i2c_lock_adapter - Get exclusive access to an I2C bus segment
474 * @adapter: Target I2C bus segment
475 */
476void i2c_lock_adapter(struct i2c_adapter *adapter)
477{
478 if (i2c_parent_is_i2c_adapter(adapter))
479 i2c_lock_adapter(to_i2c_adapter(adapter->dev.parent));
480 else
481 rt_mutex_lock(&adapter->bus_lock);
482}
483EXPORT_SYMBOL_GPL(i2c_lock_adapter);
484
485/**
486 * i2c_trylock_adapter - Try to get exclusive access to an I2C bus segment
487 * @adapter: Target I2C bus segment
488 */
489static int i2c_trylock_adapter(struct i2c_adapter *adapter)
490{
491 if (i2c_parent_is_i2c_adapter(adapter))
492 return i2c_trylock_adapter(to_i2c_adapter(adapter->dev.parent));
493 else
494 return rt_mutex_trylock(&adapter->bus_lock);
495}
496
497/**
498 * i2c_unlock_adapter - Release exclusive access to an I2C bus segment
499 * @adapter: Target I2C bus segment
500 */
501void i2c_unlock_adapter(struct i2c_adapter *adapter)
502{
503 if (i2c_parent_is_i2c_adapter(adapter))
504 i2c_unlock_adapter(to_i2c_adapter(adapter->dev.parent));
505 else
506 rt_mutex_unlock(&adapter->bus_lock);
430} 507}
508EXPORT_SYMBOL_GPL(i2c_unlock_adapter);
431 509
432/** 510/**
433 * i2c_new_device - instantiate an i2c device 511 * i2c_new_device - instantiate an i2c device
@@ -633,9 +711,9 @@ i2c_sysfs_new_device(struct device *dev, struct device_attribute *attr,
633 return -EINVAL; 711 return -EINVAL;
634 712
635 /* Keep track of the added device */ 713 /* Keep track of the added device */
636 i2c_lock_adapter(adap); 714 mutex_lock(&adap->userspace_clients_lock);
637 list_add_tail(&client->detected, &adap->userspace_clients); 715 list_add_tail(&client->detected, &adap->userspace_clients);
638 i2c_unlock_adapter(adap); 716 mutex_unlock(&adap->userspace_clients_lock);
639 dev_info(dev, "%s: Instantiated device %s at 0x%02hx\n", "new_device", 717 dev_info(dev, "%s: Instantiated device %s at 0x%02hx\n", "new_device",
640 info.type, info.addr); 718 info.type, info.addr);
641 719
@@ -674,7 +752,7 @@ i2c_sysfs_delete_device(struct device *dev, struct device_attribute *attr,
674 752
675 /* Make sure the device was added through sysfs */ 753 /* Make sure the device was added through sysfs */
676 res = -ENOENT; 754 res = -ENOENT;
677 i2c_lock_adapter(adap); 755 mutex_lock(&adap->userspace_clients_lock);
678 list_for_each_entry_safe(client, next, &adap->userspace_clients, 756 list_for_each_entry_safe(client, next, &adap->userspace_clients,
679 detected) { 757 detected) {
680 if (client->addr == addr) { 758 if (client->addr == addr) {
@@ -687,7 +765,7 @@ i2c_sysfs_delete_device(struct device *dev, struct device_attribute *attr,
687 break; 765 break;
688 } 766 }
689 } 767 }
690 i2c_unlock_adapter(adap); 768 mutex_unlock(&adap->userspace_clients_lock);
691 769
692 if (res < 0) 770 if (res < 0)
693 dev_err(dev, "%s: Can't find device in list\n", 771 dev_err(dev, "%s: Can't find device in list\n",
@@ -714,10 +792,11 @@ static const struct attribute_group *i2c_adapter_attr_groups[] = {
714 NULL 792 NULL
715}; 793};
716 794
717static struct device_type i2c_adapter_type = { 795struct device_type i2c_adapter_type = {
718 .groups = i2c_adapter_attr_groups, 796 .groups = i2c_adapter_attr_groups,
719 .release = i2c_adapter_dev_release, 797 .release = i2c_adapter_dev_release,
720}; 798};
799EXPORT_SYMBOL_GPL(i2c_adapter_type);
721 800
722#ifdef CONFIG_I2C_COMPAT 801#ifdef CONFIG_I2C_COMPAT
723static struct class_compat *i2c_adapter_compat_class; 802static struct class_compat *i2c_adapter_compat_class;
@@ -760,7 +839,7 @@ static int __process_new_adapter(struct device_driver *d, void *data)
760 839
761static int i2c_register_adapter(struct i2c_adapter *adap) 840static int i2c_register_adapter(struct i2c_adapter *adap)
762{ 841{
763 int res = 0, dummy; 842 int res = 0;
764 843
765 /* Can't register until after driver model init */ 844 /* Can't register until after driver model init */
766 if (unlikely(WARN_ON(!i2c_bus_type.p))) { 845 if (unlikely(WARN_ON(!i2c_bus_type.p))) {
@@ -769,6 +848,7 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
769 } 848 }
770 849
771 rt_mutex_init(&adap->bus_lock); 850 rt_mutex_init(&adap->bus_lock);
851 mutex_init(&adap->userspace_clients_lock);
772 INIT_LIST_HEAD(&adap->userspace_clients); 852 INIT_LIST_HEAD(&adap->userspace_clients);
773 853
774 /* Set default timeout to 1 second if not already set */ 854 /* Set default timeout to 1 second if not already set */
@@ -801,8 +881,7 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
801 881
802 /* Notify drivers */ 882 /* Notify drivers */
803 mutex_lock(&core_lock); 883 mutex_lock(&core_lock);
804 dummy = bus_for_each_drv(&i2c_bus_type, NULL, adap, 884 bus_for_each_drv(&i2c_bus_type, NULL, adap, __process_new_adapter);
805 __process_new_adapter);
806 mutex_unlock(&core_lock); 885 mutex_unlock(&core_lock);
807 886
808 return 0; 887 return 0;
@@ -975,7 +1054,7 @@ int i2c_del_adapter(struct i2c_adapter *adap)
975 return res; 1054 return res;
976 1055
977 /* Remove devices instantiated from sysfs */ 1056 /* Remove devices instantiated from sysfs */
978 i2c_lock_adapter(adap); 1057 mutex_lock(&adap->userspace_clients_lock);
979 list_for_each_entry_safe(client, next, &adap->userspace_clients, 1058 list_for_each_entry_safe(client, next, &adap->userspace_clients,
980 detected) { 1059 detected) {
981 dev_dbg(&adap->dev, "Removing %s at 0x%x\n", client->name, 1060 dev_dbg(&adap->dev, "Removing %s at 0x%x\n", client->name,
@@ -983,7 +1062,7 @@ int i2c_del_adapter(struct i2c_adapter *adap)
983 list_del(&client->detected); 1062 list_del(&client->detected);
984 i2c_unregister_device(client); 1063 i2c_unregister_device(client);
985 } 1064 }
986 i2c_unlock_adapter(adap); 1065 mutex_unlock(&adap->userspace_clients_lock);
987 1066
988 /* Detach any active clients. This can't fail, thus we do not 1067 /* Detach any active clients. This can't fail, thus we do not
989 checking the returned value. */ 1068 checking the returned value. */
@@ -1238,12 +1317,12 @@ int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
1238#endif 1317#endif
1239 1318
1240 if (in_atomic() || irqs_disabled()) { 1319 if (in_atomic() || irqs_disabled()) {
1241 ret = rt_mutex_trylock(&adap->bus_lock); 1320 ret = i2c_trylock_adapter(adap);
1242 if (!ret) 1321 if (!ret)
1243 /* I2C activity is ongoing. */ 1322 /* I2C activity is ongoing. */
1244 return -EAGAIN; 1323 return -EAGAIN;
1245 } else { 1324 } else {
1246 rt_mutex_lock(&adap->bus_lock); 1325 i2c_lock_adapter(adap);
1247 } 1326 }
1248 1327
1249 /* Retry automatically on arbitration loss */ 1328 /* Retry automatically on arbitration loss */
@@ -1255,7 +1334,7 @@ int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
1255 if (time_after(jiffies, orig_jiffies + adap->timeout)) 1334 if (time_after(jiffies, orig_jiffies + adap->timeout))
1256 break; 1335 break;
1257 } 1336 }
1258 rt_mutex_unlock(&adap->bus_lock); 1337 i2c_unlock_adapter(adap);
1259 1338
1260 return ret; 1339 return ret;
1261 } else { 1340 } else {
@@ -1350,13 +1429,17 @@ static int i2c_default_probe(struct i2c_adapter *adap, unsigned short addr)
1350 I2C_SMBUS_BYTE_DATA, &dummy); 1429 I2C_SMBUS_BYTE_DATA, &dummy);
1351 else 1430 else
1352#endif 1431#endif
1353 if ((addr & ~0x07) == 0x30 || (addr & ~0x0f) == 0x50 1432 if (!((addr & ~0x07) == 0x30 || (addr & ~0x0f) == 0x50)
1354 || !i2c_check_functionality(adap, I2C_FUNC_SMBUS_QUICK)) 1433 && i2c_check_functionality(adap, I2C_FUNC_SMBUS_QUICK))
1355 err = i2c_smbus_xfer(adap, addr, 0, I2C_SMBUS_READ, 0,
1356 I2C_SMBUS_BYTE, &dummy);
1357 else
1358 err = i2c_smbus_xfer(adap, addr, 0, I2C_SMBUS_WRITE, 0, 1434 err = i2c_smbus_xfer(adap, addr, 0, I2C_SMBUS_WRITE, 0,
1359 I2C_SMBUS_QUICK, NULL); 1435 I2C_SMBUS_QUICK, NULL);
1436 else if (i2c_check_functionality(adap, I2C_FUNC_SMBUS_READ_BYTE))
1437 err = i2c_smbus_xfer(adap, addr, 0, I2C_SMBUS_READ, 0,
1438 I2C_SMBUS_BYTE, &dummy);
1439 else {
1440 dev_warn(&adap->dev, "No suitable probing method supported\n");
1441 err = -EOPNOTSUPP;
1442 }
1360 1443
1361 return err >= 0; 1444 return err >= 0;
1362} 1445}
@@ -1437,16 +1520,6 @@ static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver)
1437 if (!(adapter->class & driver->class)) 1520 if (!(adapter->class & driver->class))
1438 goto exit_free; 1521 goto exit_free;
1439 1522
1440 /* Stop here if the bus doesn't support probing */
1441 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_BYTE)) {
1442 if (address_list[0] == I2C_CLIENT_END)
1443 goto exit_free;
1444
1445 dev_warn(&adapter->dev, "Probing not supported\n");
1446 err = -EOPNOTSUPP;
1447 goto exit_free;
1448 }
1449
1450 for (i = 0; address_list[i] != I2C_CLIENT_END; i += 1) { 1523 for (i = 0; address_list[i] != I2C_CLIENT_END; i += 1) {
1451 dev_dbg(&adapter->dev, "found normal entry for adapter %d, " 1524 dev_dbg(&adapter->dev, "found normal entry for adapter %d, "
1452 "addr 0x%02x\n", adap_id, address_list[i]); 1525 "addr 0x%02x\n", adap_id, address_list[i]);
@@ -1461,18 +1534,23 @@ static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver)
1461 return err; 1534 return err;
1462} 1535}
1463 1536
1537int i2c_probe_func_quick_read(struct i2c_adapter *adap, unsigned short addr)
1538{
1539 return i2c_smbus_xfer(adap, addr, 0, I2C_SMBUS_READ, 0,
1540 I2C_SMBUS_QUICK, NULL) >= 0;
1541}
1542EXPORT_SYMBOL_GPL(i2c_probe_func_quick_read);
1543
1464struct i2c_client * 1544struct i2c_client *
1465i2c_new_probed_device(struct i2c_adapter *adap, 1545i2c_new_probed_device(struct i2c_adapter *adap,
1466 struct i2c_board_info *info, 1546 struct i2c_board_info *info,
1467 unsigned short const *addr_list) 1547 unsigned short const *addr_list,
1548 int (*probe)(struct i2c_adapter *, unsigned short addr))
1468{ 1549{
1469 int i; 1550 int i;
1470 1551
1471 /* Stop here if the bus doesn't support probing */ 1552 if (!probe)
1472 if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_READ_BYTE)) { 1553 probe = i2c_default_probe;
1473 dev_err(&adap->dev, "Probing not supported\n");
1474 return NULL;
1475 }
1476 1554
1477 for (i = 0; addr_list[i] != I2C_CLIENT_END; i++) { 1555 for (i = 0; addr_list[i] != I2C_CLIENT_END; i++) {
1478 /* Check address validity */ 1556 /* Check address validity */
@@ -1490,7 +1568,7 @@ i2c_new_probed_device(struct i2c_adapter *adap,
1490 } 1568 }
1491 1569
1492 /* Test address responsiveness */ 1570 /* Test address responsiveness */
1493 if (i2c_default_probe(adap, addr_list[i])) 1571 if (probe(adap, addr_list[i]))
1494 break; 1572 break;
1495 } 1573 }
1496 1574
@@ -2002,7 +2080,7 @@ s32 i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr, unsigned short flags,
2002 flags &= I2C_M_TEN | I2C_CLIENT_PEC; 2080 flags &= I2C_M_TEN | I2C_CLIENT_PEC;
2003 2081
2004 if (adapter->algo->smbus_xfer) { 2082 if (adapter->algo->smbus_xfer) {
2005 rt_mutex_lock(&adapter->bus_lock); 2083 i2c_lock_adapter(adapter);
2006 2084
2007 /* Retry automatically on arbitration loss */ 2085 /* Retry automatically on arbitration loss */
2008 orig_jiffies = jiffies; 2086 orig_jiffies = jiffies;
@@ -2016,7 +2094,7 @@ s32 i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr, unsigned short flags,
2016 orig_jiffies + adapter->timeout)) 2094 orig_jiffies + adapter->timeout))
2017 break; 2095 break;
2018 } 2096 }
2019 rt_mutex_unlock(&adapter->bus_lock); 2097 i2c_unlock_adapter(adapter);
2020 } else 2098 } else
2021 res = i2c_smbus_xfer_emulated(adapter, addr, flags, read_write, 2099 res = i2c_smbus_xfer_emulated(adapter, addr, flags, read_write,
2022 command, protocol, data); 2100 command, protocol, data);
diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
index e0694e4d86c7..5f3a52d517c3 100644
--- a/drivers/i2c/i2c-dev.c
+++ b/drivers/i2c/i2c-dev.c
@@ -167,13 +167,9 @@ static ssize_t i2cdev_write(struct file *file, const char __user *buf,
167 if (count > 8192) 167 if (count > 8192)
168 count = 8192; 168 count = 8192;
169 169
170 tmp = kmalloc(count, GFP_KERNEL); 170 tmp = memdup_user(buf, count);
171 if (tmp == NULL) 171 if (IS_ERR(tmp))
172 return -ENOMEM; 172 return PTR_ERR(tmp);
173 if (copy_from_user(tmp, buf, count)) {
174 kfree(tmp);
175 return -EFAULT;
176 }
177 173
178 pr_debug("i2c-dev: i2c-%d writing %zu bytes.\n", 174 pr_debug("i2c-dev: i2c-%d writing %zu bytes.\n",
179 iminor(file->f_path.dentry->d_inode), count); 175 iminor(file->f_path.dentry->d_inode), count);
@@ -193,12 +189,50 @@ static int i2cdev_check(struct device *dev, void *addrp)
193 return dev->driver ? -EBUSY : 0; 189 return dev->driver ? -EBUSY : 0;
194} 190}
195 191
192/* walk up mux tree */
193static int i2cdev_check_mux_parents(struct i2c_adapter *adapter, int addr)
194{
195 int result;
196
197 result = device_for_each_child(&adapter->dev, &addr, i2cdev_check);
198
199 if (!result && i2c_parent_is_i2c_adapter(adapter))
200 result = i2cdev_check_mux_parents(
201 to_i2c_adapter(adapter->dev.parent), addr);
202
203 return result;
204}
205
206/* recurse down mux tree */
207static int i2cdev_check_mux_children(struct device *dev, void *addrp)
208{
209 int result;
210
211 if (dev->type == &i2c_adapter_type)
212 result = device_for_each_child(dev, addrp,
213 i2cdev_check_mux_children);
214 else
215 result = i2cdev_check(dev, addrp);
216
217 return result;
218}
219
196/* This address checking function differs from the one in i2c-core 220/* This address checking function differs from the one in i2c-core
197 in that it considers an address with a registered device, but no 221 in that it considers an address with a registered device, but no
198 driver bound to it, as NOT busy. */ 222 driver bound to it, as NOT busy. */
199static int i2cdev_check_addr(struct i2c_adapter *adapter, unsigned int addr) 223static int i2cdev_check_addr(struct i2c_adapter *adapter, unsigned int addr)
200{ 224{
201 return device_for_each_child(&adapter->dev, &addr, i2cdev_check); 225 int result = 0;
226
227 if (i2c_parent_is_i2c_adapter(adapter))
228 result = i2cdev_check_mux_parents(
229 to_i2c_adapter(adapter->dev.parent), addr);
230
231 if (!result)
232 result = device_for_each_child(&adapter->dev, &addr,
233 i2cdev_check_mux_children);
234
235 return result;
202} 236}
203 237
204static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client, 238static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
@@ -219,9 +253,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
219 if (rdwr_arg.nmsgs > I2C_RDRW_IOCTL_MAX_MSGS) 253 if (rdwr_arg.nmsgs > I2C_RDRW_IOCTL_MAX_MSGS)
220 return -EINVAL; 254 return -EINVAL;
221 255
222 rdwr_pa = (struct i2c_msg *) 256 rdwr_pa = kmalloc(rdwr_arg.nmsgs * sizeof(struct i2c_msg), GFP_KERNEL);
223 kmalloc(rdwr_arg.nmsgs * sizeof(struct i2c_msg),
224 GFP_KERNEL);
225 if (!rdwr_pa) 257 if (!rdwr_pa)
226 return -ENOMEM; 258 return -ENOMEM;
227 259
@@ -247,15 +279,9 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
247 break; 279 break;
248 } 280 }
249 data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf; 281 data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
250 rdwr_pa[i].buf = kmalloc(rdwr_pa[i].len, GFP_KERNEL); 282 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
251 if (rdwr_pa[i].buf == NULL) { 283 if (IS_ERR(rdwr_pa[i].buf)) {
252 res = -ENOMEM; 284 res = PTR_ERR(rdwr_pa[i].buf);
253 break;
254 }
255 if (copy_from_user(rdwr_pa[i].buf, data_ptrs[i],
256 rdwr_pa[i].len)) {
257 ++i; /* Needs to be kfreed too */
258 res = -EFAULT;
259 break; 285 break;
260 } 286 }
261 } 287 }
diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
new file mode 100644
index 000000000000..d32a4843fc3a
--- /dev/null
+++ b/drivers/i2c/i2c-mux.c
@@ -0,0 +1,165 @@
1/*
2 * Multiplexed I2C bus driver.
3 *
4 * Copyright (c) 2008-2009 Rodolfo Giometti <giometti@linux.it>
5 * Copyright (c) 2008-2009 Eurotech S.p.A. <info@eurotech.it>
6 * Copyright (c) 2009-2010 NSN GmbH & Co KG <michael.lawnick.ext@nsn.com>
7 *
8 * Simplifies access to complex multiplexed I2C bus topologies, by presenting
9 * each multiplexed bus segment as an additional I2C adapter.
10 * Supports multi-level mux'ing (mux behind a mux).
11 *
12 * Based on:
13 * i2c-virt.c from Kumar Gala <galak@kernel.crashing.org>
14 * i2c-virtual.c from Ken Harrenstien, Copyright (c) 2004 Google, Inc.
15 * i2c-virtual.c from Brian Kuschak <bkuschak@yahoo.com>
16 *
17 * This file is licensed under the terms of the GNU General Public
18 * License version 2. This program is licensed "as is" without any
19 * warranty of any kind, whether express or implied.
20 */
21
22#include <linux/kernel.h>
23#include <linux/module.h>
24#include <linux/slab.h>
25#include <linux/i2c.h>
26#include <linux/i2c-mux.h>
27
28/* multiplexer per channel data */
29struct i2c_mux_priv {
30 struct i2c_adapter adap;
31 struct i2c_algorithm algo;
32
33 struct i2c_adapter *parent;
34 void *mux_dev; /* the mux chip/device */
35 u32 chan_id; /* the channel id */
36
37 int (*select)(struct i2c_adapter *, void *mux_dev, u32 chan_id);
38 int (*deselect)(struct i2c_adapter *, void *mux_dev, u32 chan_id);
39};
40
41static int i2c_mux_master_xfer(struct i2c_adapter *adap,
42 struct i2c_msg msgs[], int num)
43{
44 struct i2c_mux_priv *priv = adap->algo_data;
45 struct i2c_adapter *parent = priv->parent;
46 int ret;
47
48 /* Switch to the right mux port and perform the transfer. */
49
50 ret = priv->select(parent, priv->mux_dev, priv->chan_id);
51 if (ret >= 0)
52 ret = parent->algo->master_xfer(parent, msgs, num);
53 if (priv->deselect)
54 priv->deselect(parent, priv->mux_dev, priv->chan_id);
55
56 return ret;
57}
58
59static int i2c_mux_smbus_xfer(struct i2c_adapter *adap,
60 u16 addr, unsigned short flags,
61 char read_write, u8 command,
62 int size, union i2c_smbus_data *data)
63{
64 struct i2c_mux_priv *priv = adap->algo_data;
65 struct i2c_adapter *parent = priv->parent;
66 int ret;
67
68 /* Select the right mux port and perform the transfer. */
69
70 ret = priv->select(parent, priv->mux_dev, priv->chan_id);
71 if (ret >= 0)
72 ret = parent->algo->smbus_xfer(parent, addr, flags,
73 read_write, command, size, data);
74 if (priv->deselect)
75 priv->deselect(parent, priv->mux_dev, priv->chan_id);
76
77 return ret;
78}
79
80/* Return the parent's functionality */
81static u32 i2c_mux_functionality(struct i2c_adapter *adap)
82{
83 struct i2c_mux_priv *priv = adap->algo_data;
84 struct i2c_adapter *parent = priv->parent;
85
86 return parent->algo->functionality(parent);
87}
88
89struct i2c_adapter *i2c_add_mux_adapter(struct i2c_adapter *parent,
90 void *mux_dev, u32 force_nr, u32 chan_id,
91 int (*select) (struct i2c_adapter *,
92 void *, u32),
93 int (*deselect) (struct i2c_adapter *,
94 void *, u32))
95{
96 struct i2c_mux_priv *priv;
97 int ret;
98
99 priv = kzalloc(sizeof(struct i2c_mux_priv), GFP_KERNEL);
100 if (!priv)
101 return NULL;
102
103 /* Set up private adapter data */
104 priv->parent = parent;
105 priv->mux_dev = mux_dev;
106 priv->chan_id = chan_id;
107 priv->select = select;
108 priv->deselect = deselect;
109
110 /* Need to do algo dynamically because we don't know ahead
111 * of time what sort of physical adapter we'll be dealing with.
112 */
113 if (parent->algo->master_xfer)
114 priv->algo.master_xfer = i2c_mux_master_xfer;
115 if (parent->algo->smbus_xfer)
116 priv->algo.smbus_xfer = i2c_mux_smbus_xfer;
117 priv->algo.functionality = i2c_mux_functionality;
118
119 /* Now fill out new adapter structure */
120 snprintf(priv->adap.name, sizeof(priv->adap.name),
121 "i2c-%d-mux (chan_id %d)", i2c_adapter_id(parent), chan_id);
122 priv->adap.owner = THIS_MODULE;
123 priv->adap.id = parent->id;
124 priv->adap.algo = &priv->algo;
125 priv->adap.algo_data = priv;
126 priv->adap.dev.parent = &parent->dev;
127
128 if (force_nr) {
129 priv->adap.nr = force_nr;
130 ret = i2c_add_numbered_adapter(&priv->adap);
131 } else {
132 ret = i2c_add_adapter(&priv->adap);
133 }
134 if (ret < 0) {
135 dev_err(&parent->dev,
136 "failed to add mux-adapter (error=%d)\n",
137 ret);
138 kfree(priv);
139 return NULL;
140 }
141
142 dev_info(&parent->dev, "Added multiplexed i2c bus %d\n",
143 i2c_adapter_id(&priv->adap));
144
145 return &priv->adap;
146}
147EXPORT_SYMBOL_GPL(i2c_add_mux_adapter);
148
149int i2c_del_mux_adapter(struct i2c_adapter *adap)
150{
151 struct i2c_mux_priv *priv = adap->algo_data;
152 int ret;
153
154 ret = i2c_del_adapter(adap);
155 if (ret < 0)
156 return ret;
157 kfree(priv);
158
159 return 0;
160}
161EXPORT_SYMBOL_GPL(i2c_del_mux_adapter);
162
163MODULE_AUTHOR("Rodolfo Giometti <giometti@linux.it>");
164MODULE_DESCRIPTION("I2C driver for multiplexed I2C busses");
165MODULE_LICENSE("GPL v2");
diff --git a/drivers/i2c/muxes/Kconfig b/drivers/i2c/muxes/Kconfig
new file mode 100644
index 000000000000..4c9a99c4fcb0
--- /dev/null
+++ b/drivers/i2c/muxes/Kconfig
@@ -0,0 +1,18 @@
1#
2# Multiplexer I2C chip drivers configuration
3#
4
5menu "Multiplexer I2C Chip support"
6 depends on I2C_MUX
7
8config I2C_MUX_PCA954x
9 tristate "Philips PCA954x I2C Mux/switches"
10 depends on EXPERIMENTAL
11 help
12 If you say yes here you get support for the Philips PCA954x
13 I2C mux/switch devices.
14
15 This driver can also be built as a module. If so, the module
16 will be called pca954x.
17
18endmenu
diff --git a/drivers/i2c/muxes/Makefile b/drivers/i2c/muxes/Makefile
new file mode 100644
index 000000000000..bd83b5274815
--- /dev/null
+++ b/drivers/i2c/muxes/Makefile
@@ -0,0 +1,8 @@
1#
2# Makefile for multiplexer I2C chip drivers.
3
4obj-$(CONFIG_I2C_MUX_PCA954x) += pca954x.o
5
6ifeq ($(CONFIG_I2C_DEBUG_BUS),y)
7EXTRA_CFLAGS += -DDEBUG
8endif
diff --git a/drivers/i2c/muxes/pca954x.c b/drivers/i2c/muxes/pca954x.c
new file mode 100644
index 000000000000..6f9accf3189d
--- /dev/null
+++ b/drivers/i2c/muxes/pca954x.c
@@ -0,0 +1,301 @@
1/*
2 * I2C multiplexer
3 *
4 * Copyright (c) 2008-2009 Rodolfo Giometti <giometti@linux.it>
5 * Copyright (c) 2008-2009 Eurotech S.p.A. <info@eurotech.it>
6 *
7 * This module supports the PCA954x series of I2C multiplexer/switch chips
8 * made by Philips Semiconductors.
9 * This includes the:
10 * PCA9540, PCA9542, PCA9543, PCA9544, PCA9545, PCA9546, PCA9547
11 * and PCA9548.
12 *
13 * These chips are all controlled via the I2C bus itself, and all have a
14 * single 8-bit register. The upstream "parent" bus fans out to two,
15 * four, or eight downstream busses or channels; which of these
16 * are selected is determined by the chip type and register contents. A
17 * mux can select only one sub-bus at a time; a switch can select any
18 * combination simultaneously.
19 *
20 * Based on:
21 * pca954x.c from Kumar Gala <galak@kernel.crashing.org>
22 * Copyright (C) 2006
23 *
24 * Based on:
25 * pca954x.c from Ken Harrenstien
26 * Copyright (C) 2004 Google, Inc. (Ken Harrenstien)
27 *
28 * Based on:
29 * i2c-virtual_cb.c from Brian Kuschak <bkuschak@yahoo.com>
30 * and
31 * pca9540.c from Jean Delvare <khali@linux-fr.org>.
32 *
33 * This file is licensed under the terms of the GNU General Public
34 * License version 2. This program is licensed "as is" without any
35 * warranty of any kind, whether express or implied.
36 */
37
38#include <linux/module.h>
39#include <linux/init.h>
40#include <linux/slab.h>
41#include <linux/device.h>
42#include <linux/i2c.h>
43#include <linux/i2c-mux.h>
44
45#include <linux/i2c/pca954x.h>
46
47#define PCA954X_MAX_NCHANS 8
48
49enum pca_type {
50 pca_9540,
51 pca_9542,
52 pca_9543,
53 pca_9544,
54 pca_9545,
55 pca_9546,
56 pca_9547,
57 pca_9548,
58};
59
60struct pca954x {
61 enum pca_type type;
62 struct i2c_adapter *virt_adaps[PCA954X_MAX_NCHANS];
63
64 u8 last_chan; /* last register value */
65};
66
67struct chip_desc {
68 u8 nchans;
69 u8 enable; /* used for muxes only */
70 enum muxtype {
71 pca954x_ismux = 0,
72 pca954x_isswi
73 } muxtype;
74};
75
76/* Provide specs for the PCA954x types we know about */
77static const struct chip_desc chips[] = {
78 [pca_9540] = {
79 .nchans = 2,
80 .enable = 0x4,
81 .muxtype = pca954x_ismux,
82 },
83 [pca_9543] = {
84 .nchans = 2,
85 .muxtype = pca954x_isswi,
86 },
87 [pca_9544] = {
88 .nchans = 4,
89 .enable = 0x4,
90 .muxtype = pca954x_ismux,
91 },
92 [pca_9545] = {
93 .nchans = 4,
94 .muxtype = pca954x_isswi,
95 },
96 [pca_9547] = {
97 .nchans = 8,
98 .enable = 0x8,
99 .muxtype = pca954x_ismux,
100 },
101 [pca_9548] = {
102 .nchans = 8,
103 .muxtype = pca954x_isswi,
104 },
105};
106
107static const struct i2c_device_id pca954x_id[] = {
108 { "pca9540", pca_9540 },
109 { "pca9542", pca_9540 },
110 { "pca9543", pca_9543 },
111 { "pca9544", pca_9544 },
112 { "pca9545", pca_9545 },
113 { "pca9546", pca_9545 },
114 { "pca9547", pca_9547 },
115 { "pca9548", pca_9548 },
116 { }
117};
118MODULE_DEVICE_TABLE(i2c, pca954x_id);
119
120/* Write to mux register. Don't use i2c_transfer()/i2c_smbus_xfer()
121 for this as they will try to lock adapter a second time */
122static int pca954x_reg_write(struct i2c_adapter *adap,
123 struct i2c_client *client, u8 val)
124{
125 int ret = -ENODEV;
126
127 if (adap->algo->master_xfer) {
128 struct i2c_msg msg;
129 char buf[1];
130
131 msg.addr = client->addr;
132 msg.flags = 0;
133 msg.len = 1;
134 buf[0] = val;
135 msg.buf = buf;
136 ret = adap->algo->master_xfer(adap, &msg, 1);
137 } else {
138 union i2c_smbus_data data;
139 ret = adap->algo->smbus_xfer(adap, client->addr,
140 client->flags,
141 I2C_SMBUS_WRITE,
142 val, I2C_SMBUS_BYTE, &data);
143 }
144
145 return ret;
146}
147
148static int pca954x_select_chan(struct i2c_adapter *adap,
149 void *client, u32 chan)
150{
151 struct pca954x *data = i2c_get_clientdata(client);
152 const struct chip_desc *chip = &chips[data->type];
153 u8 regval;
154 int ret = 0;
155
156 /* we make switches look like muxes, not sure how to be smarter */
157 if (chip->muxtype == pca954x_ismux)
158 regval = chan | chip->enable;
159 else
160 regval = 1 << chan;
161
162 /* Only select the channel if its different from the last channel */
163 if (data->last_chan != regval) {
164 ret = pca954x_reg_write(adap, client, regval);
165 data->last_chan = regval;
166 }
167
168 return ret;
169}
170
171static int pca954x_deselect_mux(struct i2c_adapter *adap,
172 void *client, u32 chan)
173{
174 struct pca954x *data = i2c_get_clientdata(client);
175
176 /* Deselect active channel */
177 data->last_chan = 0;
178 return pca954x_reg_write(adap, client, data->last_chan);
179}
180
181/*
182 * I2C init/probing/exit functions
183 */
184static int __devinit pca954x_probe(struct i2c_client *client,
185 const struct i2c_device_id *id)
186{
187 struct i2c_adapter *adap = to_i2c_adapter(client->dev.parent);
188 struct pca954x_platform_data *pdata = client->dev.platform_data;
189 int num, force;
190 struct pca954x *data;
191 int ret = -ENODEV;
192
193 if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_BYTE))
194 goto err;
195
196 data = kzalloc(sizeof(struct pca954x), GFP_KERNEL);
197 if (!data) {
198 ret = -ENOMEM;
199 goto err;
200 }
201
202 i2c_set_clientdata(client, data);
203
204 /* Read the mux register at addr to verify
205 * that the mux is in fact present.
206 */
207 if (i2c_smbus_read_byte(client) < 0) {
208 dev_warn(&client->dev, "probe failed\n");
209 goto exit_free;
210 }
211
212 data->type = id->driver_data;
213 data->last_chan = 0; /* force the first selection */
214
215 /* Now create an adapter for each channel */
216 for (num = 0; num < chips[data->type].nchans; num++) {
217 force = 0; /* dynamic adap number */
218 if (pdata) {
219 if (num < pdata->num_modes)
220 /* force static number */
221 force = pdata->modes[num].adap_id;
222 else
223 /* discard unconfigured channels */
224 break;
225 }
226
227 data->virt_adaps[num] =
228 i2c_add_mux_adapter(adap, client,
229 force, num, pca954x_select_chan,
230 (pdata && pdata->modes[num].deselect_on_exit)
231 ? pca954x_deselect_mux : NULL);
232
233 if (data->virt_adaps[num] == NULL) {
234 ret = -ENODEV;
235 dev_err(&client->dev,
236 "failed to register multiplexed adapter"
237 " %d as bus %d\n", num, force);
238 goto virt_reg_failed;
239 }
240 }
241
242 dev_info(&client->dev,
243 "registered %d multiplexed busses for I2C %s %s\n",
244 num, chips[data->type].muxtype == pca954x_ismux
245 ? "mux" : "switch", client->name);
246
247 return 0;
248
249virt_reg_failed:
250 for (num--; num >= 0; num--)
251 i2c_del_mux_adapter(data->virt_adaps[num]);
252exit_free:
253 kfree(data);
254err:
255 return ret;
256}
257
258static int __devexit pca954x_remove(struct i2c_client *client)
259{
260 struct pca954x *data = i2c_get_clientdata(client);
261 const struct chip_desc *chip = &chips[data->type];
262 int i, err;
263
264 for (i = 0; i < chip->nchans; ++i)
265 if (data->virt_adaps[i]) {
266 err = i2c_del_mux_adapter(data->virt_adaps[i]);
267 if (err)
268 return err;
269 data->virt_adaps[i] = NULL;
270 }
271
272 kfree(data);
273 return 0;
274}
275
276static struct i2c_driver pca954x_driver = {
277 .driver = {
278 .name = "pca954x",
279 .owner = THIS_MODULE,
280 },
281 .probe = pca954x_probe,
282 .remove = __devexit_p(pca954x_remove),
283 .id_table = pca954x_id,
284};
285
286static int __init pca954x_init(void)
287{
288 return i2c_add_driver(&pca954x_driver);
289}
290
291static void __exit pca954x_exit(void)
292{
293 i2c_del_driver(&pca954x_driver);
294}
295
296module_init(pca954x_init);
297module_exit(pca954x_exit);
298
299MODULE_AUTHOR("Rodolfo Giometti <giometti@linux.it>");
300MODULE_DESCRIPTION("PCA954x I2C mux/switch driver");
301MODULE_LICENSE("GPL v2");
diff --git a/drivers/ide/ide-atapi.c b/drivers/ide/ide-atapi.c
index f9daffd7d0e3..e88a2cf17711 100644
--- a/drivers/ide/ide-atapi.c
+++ b/drivers/ide/ide-atapi.c
@@ -190,7 +190,7 @@ void ide_prep_sense(ide_drive_t *drive, struct request *rq)
190 190
191 BUG_ON(sense_len > sizeof(*sense)); 191 BUG_ON(sense_len > sizeof(*sense));
192 192
193 if (blk_sense_request(rq) || drive->sense_rq_armed) 193 if (rq->cmd_type == REQ_TYPE_SENSE || drive->sense_rq_armed)
194 return; 194 return;
195 195
196 memset(sense, 0, sizeof(*sense)); 196 memset(sense, 0, sizeof(*sense));
@@ -307,13 +307,16 @@ EXPORT_SYMBOL_GPL(ide_cd_expiry);
307 307
308int ide_cd_get_xferlen(struct request *rq) 308int ide_cd_get_xferlen(struct request *rq)
309{ 309{
310 if (blk_fs_request(rq)) 310 switch (rq->cmd_type) {
311 case REQ_TYPE_FS:
311 return 32768; 312 return 32768;
312 else if (blk_sense_request(rq) || blk_pc_request(rq) || 313 case REQ_TYPE_SENSE:
313 rq->cmd_type == REQ_TYPE_ATA_PC) 314 case REQ_TYPE_BLOCK_PC:
315 case REQ_TYPE_ATA_PC:
314 return blk_rq_bytes(rq); 316 return blk_rq_bytes(rq);
315 else 317 default:
316 return 0; 318 return 0;
319 }
317} 320}
318EXPORT_SYMBOL_GPL(ide_cd_get_xferlen); 321EXPORT_SYMBOL_GPL(ide_cd_get_xferlen);
319 322
@@ -474,12 +477,12 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
474 if (uptodate == 0) 477 if (uptodate == 0)
475 drive->failed_pc = NULL; 478 drive->failed_pc = NULL;
476 479
477 if (blk_special_request(rq)) { 480 if (rq->cmd_type == REQ_TYPE_SPECIAL) {
478 rq->errors = 0; 481 rq->errors = 0;
479 error = 0; 482 error = 0;
480 } else { 483 } else {
481 484
482 if (blk_fs_request(rq) == 0 && uptodate <= 0) { 485 if (rq->cmd_type != REQ_TYPE_FS && uptodate <= 0) {
483 if (rq->errors == 0) 486 if (rq->errors == 0)
484 rq->errors = -EIO; 487 rq->errors = -EIO;
485 } 488 }
diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
index 64207df8da82..31fc76960a8f 100644
--- a/drivers/ide/ide-cd.c
+++ b/drivers/ide/ide-cd.c
@@ -31,6 +31,7 @@
31#include <linux/delay.h> 31#include <linux/delay.h>
32#include <linux/timer.h> 32#include <linux/timer.h>
33#include <linux/seq_file.h> 33#include <linux/seq_file.h>
34#include <linux/smp_lock.h>
34#include <linux/slab.h> 35#include <linux/slab.h>
35#include <linux/interrupt.h> 36#include <linux/interrupt.h>
36#include <linux/errno.h> 37#include <linux/errno.h>
@@ -176,7 +177,7 @@ static void cdrom_analyze_sense_data(ide_drive_t *drive,
176 if (!sense->valid) 177 if (!sense->valid)
177 break; 178 break;
178 if (failed_command == NULL || 179 if (failed_command == NULL ||
179 !blk_fs_request(failed_command)) 180 failed_command->cmd_type != REQ_TYPE_FS)
180 break; 181 break;
181 sector = (sense->information[0] << 24) | 182 sector = (sense->information[0] << 24) |
182 (sense->information[1] << 16) | 183 (sense->information[1] << 16) |
@@ -292,7 +293,7 @@ static int cdrom_decode_status(ide_drive_t *drive, u8 stat)
292 "stat 0x%x", 293 "stat 0x%x",
293 rq->cmd[0], rq->cmd_type, err, stat); 294 rq->cmd[0], rq->cmd_type, err, stat);
294 295
295 if (blk_sense_request(rq)) { 296 if (rq->cmd_type == REQ_TYPE_SENSE) {
296 /* 297 /*
297 * We got an error trying to get sense info from the drive 298 * We got an error trying to get sense info from the drive
298 * (probably while trying to recover from a former error). 299 * (probably while trying to recover from a former error).
@@ -303,7 +304,7 @@ static int cdrom_decode_status(ide_drive_t *drive, u8 stat)
303 } 304 }
304 305
305 /* if we have an error, pass CHECK_CONDITION as the SCSI status byte */ 306 /* if we have an error, pass CHECK_CONDITION as the SCSI status byte */
306 if (blk_pc_request(rq) && !rq->errors) 307 if (rq->cmd_type == REQ_TYPE_BLOCK_PC && !rq->errors)
307 rq->errors = SAM_STAT_CHECK_CONDITION; 308 rq->errors = SAM_STAT_CHECK_CONDITION;
308 309
309 if (blk_noretry_request(rq)) 310 if (blk_noretry_request(rq))
@@ -311,13 +312,14 @@ static int cdrom_decode_status(ide_drive_t *drive, u8 stat)
311 312
312 switch (sense_key) { 313 switch (sense_key) {
313 case NOT_READY: 314 case NOT_READY:
314 if (blk_fs_request(rq) && rq_data_dir(rq) == WRITE) { 315 if (rq->cmd_type == REQ_TYPE_FS && rq_data_dir(rq) == WRITE) {
315 if (ide_cd_breathe(drive, rq)) 316 if (ide_cd_breathe(drive, rq))
316 return 1; 317 return 1;
317 } else { 318 } else {
318 cdrom_saw_media_change(drive); 319 cdrom_saw_media_change(drive);
319 320
320 if (blk_fs_request(rq) && !blk_rq_quiet(rq)) 321 if (rq->cmd_type == REQ_TYPE_FS &&
322 !(rq->cmd_flags & REQ_QUIET))
321 printk(KERN_ERR PFX "%s: tray open\n", 323 printk(KERN_ERR PFX "%s: tray open\n",
322 drive->name); 324 drive->name);
323 } 325 }
@@ -326,7 +328,7 @@ static int cdrom_decode_status(ide_drive_t *drive, u8 stat)
326 case UNIT_ATTENTION: 328 case UNIT_ATTENTION:
327 cdrom_saw_media_change(drive); 329 cdrom_saw_media_change(drive);
328 330
329 if (blk_fs_request(rq) == 0) 331 if (rq->cmd_type != REQ_TYPE_FS)
330 return 0; 332 return 0;
331 333
332 /* 334 /*
@@ -352,7 +354,7 @@ static int cdrom_decode_status(ide_drive_t *drive, u8 stat)
352 * No point in retrying after an illegal request or data 354 * No point in retrying after an illegal request or data
353 * protect error. 355 * protect error.
354 */ 356 */
355 if (!blk_rq_quiet(rq)) 357 if (!(rq->cmd_flags & REQ_QUIET))
356 ide_dump_status(drive, "command error", stat); 358 ide_dump_status(drive, "command error", stat);
357 do_end_request = 1; 359 do_end_request = 1;
358 break; 360 break;
@@ -361,20 +363,20 @@ static int cdrom_decode_status(ide_drive_t *drive, u8 stat)
361 * No point in re-trying a zillion times on a bad sector. 363 * No point in re-trying a zillion times on a bad sector.
362 * If we got here the error is not correctable. 364 * If we got here the error is not correctable.
363 */ 365 */
364 if (!blk_rq_quiet(rq)) 366 if (!(rq->cmd_flags & REQ_QUIET))
365 ide_dump_status(drive, "media error " 367 ide_dump_status(drive, "media error "
366 "(bad sector)", stat); 368 "(bad sector)", stat);
367 do_end_request = 1; 369 do_end_request = 1;
368 break; 370 break;
369 case BLANK_CHECK: 371 case BLANK_CHECK:
370 /* disk appears blank? */ 372 /* disk appears blank? */
371 if (!blk_rq_quiet(rq)) 373 if (!(rq->cmd_flags & REQ_QUIET))
372 ide_dump_status(drive, "media error (blank)", 374 ide_dump_status(drive, "media error (blank)",
373 stat); 375 stat);
374 do_end_request = 1; 376 do_end_request = 1;
375 break; 377 break;
376 default: 378 default:
377 if (blk_fs_request(rq) == 0) 379 if (rq->cmd_type != REQ_TYPE_FS)
378 break; 380 break;
379 if (err & ~ATA_ABORTED) { 381 if (err & ~ATA_ABORTED) {
380 /* go to the default handler for other errors */ 382 /* go to the default handler for other errors */
@@ -385,7 +387,7 @@ static int cdrom_decode_status(ide_drive_t *drive, u8 stat)
385 do_end_request = 1; 387 do_end_request = 1;
386 } 388 }
387 389
388 if (blk_fs_request(rq) == 0) { 390 if (rq->cmd_type != REQ_TYPE_FS) {
389 rq->cmd_flags |= REQ_FAILED; 391 rq->cmd_flags |= REQ_FAILED;
390 do_end_request = 1; 392 do_end_request = 1;
391 } 393 }
@@ -506,15 +508,22 @@ int ide_cd_queue_pc(ide_drive_t *drive, const unsigned char *cmd,
506 return (flags & REQ_FAILED) ? -EIO : 0; 508 return (flags & REQ_FAILED) ? -EIO : 0;
507} 509}
508 510
509static void ide_cd_error_cmd(ide_drive_t *drive, struct ide_cmd *cmd) 511/*
512 * returns true if rq has been completed
513 */
514static bool ide_cd_error_cmd(ide_drive_t *drive, struct ide_cmd *cmd)
510{ 515{
511 unsigned int nr_bytes = cmd->nbytes - cmd->nleft; 516 unsigned int nr_bytes = cmd->nbytes - cmd->nleft;
512 517
513 if (cmd->tf_flags & IDE_TFLAG_WRITE) 518 if (cmd->tf_flags & IDE_TFLAG_WRITE)
514 nr_bytes -= cmd->last_xfer_len; 519 nr_bytes -= cmd->last_xfer_len;
515 520
516 if (nr_bytes > 0) 521 if (nr_bytes > 0) {
517 ide_complete_rq(drive, 0, nr_bytes); 522 ide_complete_rq(drive, 0, nr_bytes);
523 return true;
524 }
525
526 return false;
518} 527}
519 528
520static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive) 529static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
@@ -525,7 +534,7 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
525 ide_expiry_t *expiry = NULL; 534 ide_expiry_t *expiry = NULL;
526 int dma_error = 0, dma, thislen, uptodate = 0; 535 int dma_error = 0, dma, thislen, uptodate = 0;
527 int write = (rq_data_dir(rq) == WRITE) ? 1 : 0, rc = 0; 536 int write = (rq_data_dir(rq) == WRITE) ? 1 : 0, rc = 0;
528 int sense = blk_sense_request(rq); 537 int sense = (rq->cmd_type == REQ_TYPE_SENSE);
529 unsigned int timeout; 538 unsigned int timeout;
530 u16 len; 539 u16 len;
531 u8 ireason, stat; 540 u8 ireason, stat;
@@ -568,7 +577,7 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
568 577
569 ide_read_bcount_and_ireason(drive, &len, &ireason); 578 ide_read_bcount_and_ireason(drive, &len, &ireason);
570 579
571 thislen = blk_fs_request(rq) ? len : cmd->nleft; 580 thislen = (rq->cmd_type == REQ_TYPE_FS) ? len : cmd->nleft;
572 if (thislen > len) 581 if (thislen > len)
573 thislen = len; 582 thislen = len;
574 583
@@ -577,7 +586,7 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
577 586
578 /* If DRQ is clear, the command has completed. */ 587 /* If DRQ is clear, the command has completed. */
579 if ((stat & ATA_DRQ) == 0) { 588 if ((stat & ATA_DRQ) == 0) {
580 if (blk_fs_request(rq)) { 589 if (rq->cmd_type == REQ_TYPE_FS) {
581 /* 590 /*
582 * If we're not done reading/writing, complain. 591 * If we're not done reading/writing, complain.
583 * Otherwise, complete the command normally. 592 * Otherwise, complete the command normally.
@@ -591,7 +600,7 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
591 rq->cmd_flags |= REQ_FAILED; 600 rq->cmd_flags |= REQ_FAILED;
592 uptodate = 0; 601 uptodate = 0;
593 } 602 }
594 } else if (!blk_pc_request(rq)) { 603 } else if (rq->cmd_type != REQ_TYPE_BLOCK_PC) {
595 ide_cd_request_sense_fixup(drive, cmd); 604 ide_cd_request_sense_fixup(drive, cmd);
596 605
597 uptodate = cmd->nleft ? 0 : 1; 606 uptodate = cmd->nleft ? 0 : 1;
@@ -640,7 +649,7 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
640 649
641 /* pad, if necessary */ 650 /* pad, if necessary */
642 if (len > 0) { 651 if (len > 0) {
643 if (blk_fs_request(rq) == 0 || write == 0) 652 if (rq->cmd_type != REQ_TYPE_FS || write == 0)
644 ide_pad_transfer(drive, write, len); 653 ide_pad_transfer(drive, write, len);
645 else { 654 else {
646 printk(KERN_ERR PFX "%s: confused, missing data\n", 655 printk(KERN_ERR PFX "%s: confused, missing data\n",
@@ -649,11 +658,11 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
649 } 658 }
650 } 659 }
651 660
652 if (blk_pc_request(rq)) { 661 if (rq->cmd_type == REQ_TYPE_BLOCK_PC) {
653 timeout = rq->timeout; 662 timeout = rq->timeout;
654 } else { 663 } else {
655 timeout = ATAPI_WAIT_PC; 664 timeout = ATAPI_WAIT_PC;
656 if (!blk_fs_request(rq)) 665 if (rq->cmd_type != REQ_TYPE_FS)
657 expiry = ide_cd_expiry; 666 expiry = ide_cd_expiry;
658 } 667 }
659 668
@@ -662,7 +671,7 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
662 return ide_started; 671 return ide_started;
663 672
664out_end: 673out_end:
665 if (blk_pc_request(rq) && rc == 0) { 674 if (rq->cmd_type == REQ_TYPE_BLOCK_PC && rc == 0) {
666 rq->resid_len = 0; 675 rq->resid_len = 0;
667 blk_end_request_all(rq, 0); 676 blk_end_request_all(rq, 0);
668 hwif->rq = NULL; 677 hwif->rq = NULL;
@@ -670,7 +679,7 @@ out_end:
670 if (sense && uptodate) 679 if (sense && uptodate)
671 ide_cd_complete_failed_rq(drive, rq); 680 ide_cd_complete_failed_rq(drive, rq);
672 681
673 if (blk_fs_request(rq)) { 682 if (rq->cmd_type == REQ_TYPE_FS) {
674 if (cmd->nleft == 0) 683 if (cmd->nleft == 0)
675 uptodate = 1; 684 uptodate = 1;
676 } else { 685 } else {
@@ -679,10 +688,11 @@ out_end:
679 } 688 }
680 689
681 if (uptodate == 0 && rq->bio) 690 if (uptodate == 0 && rq->bio)
682 ide_cd_error_cmd(drive, cmd); 691 if (ide_cd_error_cmd(drive, cmd))
692 return ide_stopped;
683 693
684 /* make sure it's fully ended */ 694 /* make sure it's fully ended */
685 if (blk_fs_request(rq) == 0) { 695 if (rq->cmd_type != REQ_TYPE_FS) {
686 rq->resid_len -= cmd->nbytes - cmd->nleft; 696 rq->resid_len -= cmd->nbytes - cmd->nleft;
687 if (uptodate == 0 && (cmd->tf_flags & IDE_TFLAG_WRITE)) 697 if (uptodate == 0 && (cmd->tf_flags & IDE_TFLAG_WRITE))
688 rq->resid_len += cmd->last_xfer_len; 698 rq->resid_len += cmd->last_xfer_len;
@@ -742,7 +752,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
742 ide_debug_log(IDE_DBG_PC, "rq->cmd[0]: 0x%x, rq->cmd_type: 0x%x", 752 ide_debug_log(IDE_DBG_PC, "rq->cmd[0]: 0x%x, rq->cmd_type: 0x%x",
743 rq->cmd[0], rq->cmd_type); 753 rq->cmd[0], rq->cmd_type);
744 754
745 if (blk_pc_request(rq)) 755 if (rq->cmd_type == REQ_TYPE_BLOCK_PC)
746 rq->cmd_flags |= REQ_QUIET; 756 rq->cmd_flags |= REQ_QUIET;
747 else 757 else
748 rq->cmd_flags &= ~REQ_FAILED; 758 rq->cmd_flags &= ~REQ_FAILED;
@@ -783,21 +793,26 @@ static ide_startstop_t ide_cd_do_request(ide_drive_t *drive, struct request *rq,
783 if (drive->debug_mask & IDE_DBG_RQ) 793 if (drive->debug_mask & IDE_DBG_RQ)
784 blk_dump_rq_flags(rq, "ide_cd_do_request"); 794 blk_dump_rq_flags(rq, "ide_cd_do_request");
785 795
786 if (blk_fs_request(rq)) { 796 switch (rq->cmd_type) {
797 case REQ_TYPE_FS:
787 if (cdrom_start_rw(drive, rq) == ide_stopped) 798 if (cdrom_start_rw(drive, rq) == ide_stopped)
788 goto out_end; 799 goto out_end;
789 } else if (blk_sense_request(rq) || blk_pc_request(rq) || 800 break;
790 rq->cmd_type == REQ_TYPE_ATA_PC) { 801 case REQ_TYPE_SENSE:
802 case REQ_TYPE_BLOCK_PC:
803 case REQ_TYPE_ATA_PC:
791 if (!rq->timeout) 804 if (!rq->timeout)
792 rq->timeout = ATAPI_WAIT_PC; 805 rq->timeout = ATAPI_WAIT_PC;
793 806
794 cdrom_do_block_pc(drive, rq); 807 cdrom_do_block_pc(drive, rq);
795 } else if (blk_special_request(rq)) { 808 break;
809 case REQ_TYPE_SPECIAL:
796 /* right now this can only be a reset... */ 810 /* right now this can only be a reset... */
797 uptodate = 1; 811 uptodate = 1;
798 goto out_end; 812 goto out_end;
799 } else 813 default:
800 BUG(); 814 BUG();
815 }
801 816
802 /* prepare sense request for this command */ 817 /* prepare sense request for this command */
803 ide_prep_sense(drive, rq); 818 ide_prep_sense(drive, rq);
@@ -809,7 +824,7 @@ static ide_startstop_t ide_cd_do_request(ide_drive_t *drive, struct request *rq,
809 824
810 cmd.rq = rq; 825 cmd.rq = rq;
811 826
812 if (blk_fs_request(rq) || blk_rq_bytes(rq)) { 827 if (rq->cmd_type == REQ_TYPE_FS || blk_rq_bytes(rq)) {
813 ide_init_sg_cmd(&cmd, blk_rq_bytes(rq)); 828 ide_init_sg_cmd(&cmd, blk_rq_bytes(rq));
814 ide_map_sg(drive, &cmd); 829 ide_map_sg(drive, &cmd);
815 } 830 }
@@ -1365,9 +1380,9 @@ static int ide_cdrom_prep_pc(struct request *rq)
1365 1380
1366static int ide_cdrom_prep_fn(struct request_queue *q, struct request *rq) 1381static int ide_cdrom_prep_fn(struct request_queue *q, struct request *rq)
1367{ 1382{
1368 if (blk_fs_request(rq)) 1383 if (rq->cmd_type == REQ_TYPE_FS)
1369 return ide_cdrom_prep_fs(q, rq); 1384 return ide_cdrom_prep_fs(q, rq);
1370 else if (blk_pc_request(rq)) 1385 else if (rq->cmd_type == REQ_TYPE_BLOCK_PC)
1371 return ide_cdrom_prep_pc(rq); 1386 return ide_cdrom_prep_pc(rq);
1372 1387
1373 return 0; 1388 return 0;
@@ -1584,17 +1599,19 @@ static struct ide_driver ide_cdrom_driver = {
1584 1599
1585static int idecd_open(struct block_device *bdev, fmode_t mode) 1600static int idecd_open(struct block_device *bdev, fmode_t mode)
1586{ 1601{
1587 struct cdrom_info *info = ide_cd_get(bdev->bd_disk); 1602 struct cdrom_info *info;
1588 int rc = -ENOMEM; 1603 int rc = -ENXIO;
1589 1604
1605 lock_kernel();
1606 info = ide_cd_get(bdev->bd_disk);
1590 if (!info) 1607 if (!info)
1591 return -ENXIO; 1608 goto out;
1592 1609
1593 rc = cdrom_open(&info->devinfo, bdev, mode); 1610 rc = cdrom_open(&info->devinfo, bdev, mode);
1594
1595 if (rc < 0) 1611 if (rc < 0)
1596 ide_cd_put(info); 1612 ide_cd_put(info);
1597 1613out:
1614 unlock_kernel();
1598 return rc; 1615 return rc;
1599} 1616}
1600 1617
@@ -1602,9 +1619,11 @@ static int idecd_release(struct gendisk *disk, fmode_t mode)
1602{ 1619{
1603 struct cdrom_info *info = ide_drv_g(disk, cdrom_info); 1620 struct cdrom_info *info = ide_drv_g(disk, cdrom_info);
1604 1621
1622 lock_kernel();
1605 cdrom_release(&info->devinfo, mode); 1623 cdrom_release(&info->devinfo, mode);
1606 1624
1607 ide_cd_put(info); 1625 ide_cd_put(info);
1626 unlock_kernel();
1608 1627
1609 return 0; 1628 return 0;
1610} 1629}
@@ -1648,7 +1667,7 @@ static int idecd_get_spindown(struct cdrom_device_info *cdi, unsigned long arg)
1648 return 0; 1667 return 0;
1649} 1668}
1650 1669
1651static int idecd_ioctl(struct block_device *bdev, fmode_t mode, 1670static int idecd_locked_ioctl(struct block_device *bdev, fmode_t mode,
1652 unsigned int cmd, unsigned long arg) 1671 unsigned int cmd, unsigned long arg)
1653{ 1672{
1654 struct cdrom_info *info = ide_drv_g(bdev->bd_disk, cdrom_info); 1673 struct cdrom_info *info = ide_drv_g(bdev->bd_disk, cdrom_info);
@@ -1670,6 +1689,19 @@ static int idecd_ioctl(struct block_device *bdev, fmode_t mode,
1670 return err; 1689 return err;
1671} 1690}
1672 1691
1692static int idecd_ioctl(struct block_device *bdev, fmode_t mode,
1693 unsigned int cmd, unsigned long arg)
1694{
1695 int ret;
1696
1697 lock_kernel();
1698 ret = idecd_locked_ioctl(bdev, mode, cmd, arg);
1699 unlock_kernel();
1700
1701 return ret;
1702}
1703
1704
1673static int idecd_media_changed(struct gendisk *disk) 1705static int idecd_media_changed(struct gendisk *disk)
1674{ 1706{
1675 struct cdrom_info *info = ide_drv_g(disk, cdrom_info); 1707 struct cdrom_info *info = ide_drv_g(disk, cdrom_info);
@@ -1690,7 +1722,7 @@ static const struct block_device_operations idecd_ops = {
1690 .owner = THIS_MODULE, 1722 .owner = THIS_MODULE,
1691 .open = idecd_open, 1723 .open = idecd_open,
1692 .release = idecd_release, 1724 .release = idecd_release,
1693 .locked_ioctl = idecd_ioctl, 1725 .ioctl = idecd_ioctl,
1694 .media_changed = idecd_media_changed, 1726 .media_changed = idecd_media_changed,
1695 .revalidate_disk = idecd_revalidate_disk 1727 .revalidate_disk = idecd_revalidate_disk
1696}; 1728};
diff --git a/drivers/ide/ide-cd_ioctl.c b/drivers/ide/ide-cd_ioctl.c
index 02712bf045c1..766b3deeb23c 100644
--- a/drivers/ide/ide-cd_ioctl.c
+++ b/drivers/ide/ide-cd_ioctl.c
@@ -454,7 +454,7 @@ int ide_cdrom_packet(struct cdrom_device_info *cdi,
454 touch it at all. */ 454 touch it at all. */
455 455
456 if (cgc->data_direction == CGC_DATA_WRITE) 456 if (cgc->data_direction == CGC_DATA_WRITE)
457 flags |= REQ_RW; 457 flags |= REQ_WRITE;
458 458
459 if (cgc->sense) 459 if (cgc->sense)
460 memset(cgc->sense, 0, sizeof(struct request_sense)); 460 memset(cgc->sense, 0, sizeof(struct request_sense));
diff --git a/drivers/ide/ide-disk.c b/drivers/ide/ide-disk.c
index 33d65039cce9..7433e07de30e 100644
--- a/drivers/ide/ide-disk.c
+++ b/drivers/ide/ide-disk.c
@@ -184,7 +184,7 @@ static ide_startstop_t ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
184 ide_hwif_t *hwif = drive->hwif; 184 ide_hwif_t *hwif = drive->hwif;
185 185
186 BUG_ON(drive->dev_flags & IDE_DFLAG_BLOCKED); 186 BUG_ON(drive->dev_flags & IDE_DFLAG_BLOCKED);
187 BUG_ON(!blk_fs_request(rq)); 187 BUG_ON(rq->cmd_type != REQ_TYPE_FS);
188 188
189 ledtrig_ide_activity(); 189 ledtrig_ide_activity();
190 190
@@ -427,10 +427,15 @@ static void ide_disk_unlock_native_capacity(ide_drive_t *drive)
427 drive->dev_flags |= IDE_DFLAG_NOHPA; /* disable HPA on resume */ 427 drive->dev_flags |= IDE_DFLAG_NOHPA; /* disable HPA on resume */
428} 428}
429 429
430static void idedisk_prepare_flush(struct request_queue *q, struct request *rq) 430static int idedisk_prep_fn(struct request_queue *q, struct request *rq)
431{ 431{
432 ide_drive_t *drive = q->queuedata; 432 ide_drive_t *drive = q->queuedata;
433 struct ide_cmd *cmd = kmalloc(sizeof(*cmd), GFP_ATOMIC); 433 struct ide_cmd *cmd;
434
435 if (!(rq->cmd_flags & REQ_FLUSH))
436 return BLKPREP_OK;
437
438 cmd = kmalloc(sizeof(*cmd), GFP_ATOMIC);
434 439
435 /* FIXME: map struct ide_taskfile on rq->cmd[] */ 440 /* FIXME: map struct ide_taskfile on rq->cmd[] */
436 BUG_ON(cmd == NULL); 441 BUG_ON(cmd == NULL);
@@ -448,6 +453,8 @@ static void idedisk_prepare_flush(struct request_queue *q, struct request *rq)
448 rq->cmd_type = REQ_TYPE_ATA_TASKFILE; 453 rq->cmd_type = REQ_TYPE_ATA_TASKFILE;
449 rq->special = cmd; 454 rq->special = cmd;
450 cmd->rq = rq; 455 cmd->rq = rq;
456
457 return BLKPREP_OK;
451} 458}
452 459
453ide_devset_get(multcount, mult_count); 460ide_devset_get(multcount, mult_count);
@@ -513,7 +520,6 @@ static void update_ordered(ide_drive_t *drive)
513{ 520{
514 u16 *id = drive->id; 521 u16 *id = drive->id;
515 unsigned ordered = QUEUE_ORDERED_NONE; 522 unsigned ordered = QUEUE_ORDERED_NONE;
516 prepare_flush_fn *prep_fn = NULL;
517 523
518 if (drive->dev_flags & IDE_DFLAG_WCACHE) { 524 if (drive->dev_flags & IDE_DFLAG_WCACHE) {
519 unsigned long long capacity; 525 unsigned long long capacity;
@@ -538,12 +544,12 @@ static void update_ordered(ide_drive_t *drive)
538 544
539 if (barrier) { 545 if (barrier) {
540 ordered = QUEUE_ORDERED_DRAIN_FLUSH; 546 ordered = QUEUE_ORDERED_DRAIN_FLUSH;
541 prep_fn = idedisk_prepare_flush; 547 blk_queue_prep_rq(drive->queue, idedisk_prep_fn);
542 } 548 }
543 } else 549 } else
544 ordered = QUEUE_ORDERED_DRAIN; 550 ordered = QUEUE_ORDERED_DRAIN;
545 551
546 blk_queue_ordered(drive->queue, ordered, prep_fn); 552 blk_queue_ordered(drive->queue, ordered);
547} 553}
548 554
549ide_devset_get_flag(wcache, IDE_DFLAG_WCACHE); 555ide_devset_get_flag(wcache, IDE_DFLAG_WCACHE);
diff --git a/drivers/ide/ide-disk_ioctl.c b/drivers/ide/ide-disk_ioctl.c
index 7b783dd7c0be..ec94c66918f6 100644
--- a/drivers/ide/ide-disk_ioctl.c
+++ b/drivers/ide/ide-disk_ioctl.c
@@ -1,6 +1,7 @@
1#include <linux/kernel.h> 1#include <linux/kernel.h>
2#include <linux/ide.h> 2#include <linux/ide.h>
3#include <linux/hdreg.h> 3#include <linux/hdreg.h>
4#include <linux/smp_lock.h>
4 5
5#include "ide-disk.h" 6#include "ide-disk.h"
6 7
@@ -18,9 +19,13 @@ int ide_disk_ioctl(ide_drive_t *drive, struct block_device *bdev, fmode_t mode,
18{ 19{
19 int err; 20 int err;
20 21
22 lock_kernel();
21 err = ide_setting_ioctl(drive, bdev, cmd, arg, ide_disk_ioctl_settings); 23 err = ide_setting_ioctl(drive, bdev, cmd, arg, ide_disk_ioctl_settings);
22 if (err != -EOPNOTSUPP) 24 if (err != -EOPNOTSUPP)
23 return err; 25 goto out;
24 26
25 return generic_ide_ioctl(drive, bdev, cmd, arg); 27 err = generic_ide_ioctl(drive, bdev, cmd, arg);
28out:
29 unlock_kernel();
30 return err;
26} 31}
diff --git a/drivers/ide/ide-eh.c b/drivers/ide/ide-eh.c
index e9abf2c3c335..c0aa93fb7a60 100644
--- a/drivers/ide/ide-eh.c
+++ b/drivers/ide/ide-eh.c
@@ -122,7 +122,7 @@ ide_startstop_t ide_error(ide_drive_t *drive, const char *msg, u8 stat)
122 return ide_stopped; 122 return ide_stopped;
123 123
124 /* retry only "normal" I/O: */ 124 /* retry only "normal" I/O: */
125 if (!blk_fs_request(rq)) { 125 if (rq->cmd_type != REQ_TYPE_FS) {
126 if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE) { 126 if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE) {
127 struct ide_cmd *cmd = rq->special; 127 struct ide_cmd *cmd = rq->special;
128 128
@@ -146,7 +146,8 @@ static inline void ide_complete_drive_reset(ide_drive_t *drive, int err)
146{ 146{
147 struct request *rq = drive->hwif->rq; 147 struct request *rq = drive->hwif->rq;
148 148
149 if (rq && blk_special_request(rq) && rq->cmd[0] == REQ_DRIVE_RESET) { 149 if (rq && rq->cmd_type == REQ_TYPE_SPECIAL &&
150 rq->cmd[0] == REQ_DRIVE_RESET) {
150 if (err <= 0 && rq->errors == 0) 151 if (err <= 0 && rq->errors == 0)
151 rq->errors = -EIO; 152 rq->errors = -EIO;
152 ide_complete_rq(drive, err ? err : 0, blk_rq_bytes(rq)); 153 ide_complete_rq(drive, err ? err : 0, blk_rq_bytes(rq));
diff --git a/drivers/ide/ide-floppy.c b/drivers/ide/ide-floppy.c
index 4713bdca20b6..5406b6ea3ad1 100644
--- a/drivers/ide/ide-floppy.c
+++ b/drivers/ide/ide-floppy.c
@@ -73,7 +73,7 @@ static int ide_floppy_callback(ide_drive_t *drive, int dsc)
73 drive->failed_pc = NULL; 73 drive->failed_pc = NULL;
74 74
75 if (pc->c[0] == GPCMD_READ_10 || pc->c[0] == GPCMD_WRITE_10 || 75 if (pc->c[0] == GPCMD_READ_10 || pc->c[0] == GPCMD_WRITE_10 ||
76 (rq && blk_pc_request(rq))) 76 (rq && rq->cmd_type == REQ_TYPE_BLOCK_PC))
77 uptodate = 1; /* FIXME */ 77 uptodate = 1; /* FIXME */
78 else if (pc->c[0] == GPCMD_REQUEST_SENSE) { 78 else if (pc->c[0] == GPCMD_REQUEST_SENSE) {
79 79
@@ -98,7 +98,7 @@ static int ide_floppy_callback(ide_drive_t *drive, int dsc)
98 "Aborting request!\n"); 98 "Aborting request!\n");
99 } 99 }
100 100
101 if (blk_special_request(rq)) 101 if (rq->cmd_type == REQ_TYPE_SPECIAL)
102 rq->errors = uptodate ? 0 : IDE_DRV_ERROR_GENERAL; 102 rq->errors = uptodate ? 0 : IDE_DRV_ERROR_GENERAL;
103 103
104 return uptodate; 104 return uptodate;
@@ -207,7 +207,7 @@ static void idefloppy_create_rw_cmd(ide_drive_t *drive,
207 memcpy(rq->cmd, pc->c, 12); 207 memcpy(rq->cmd, pc->c, 12);
208 208
209 pc->rq = rq; 209 pc->rq = rq;
210 if (rq->cmd_flags & REQ_RW) 210 if (rq->cmd_flags & REQ_WRITE)
211 pc->flags |= PC_FLAG_WRITING; 211 pc->flags |= PC_FLAG_WRITING;
212 212
213 pc->flags |= PC_FLAG_DMA_OK; 213 pc->flags |= PC_FLAG_DMA_OK;
@@ -247,14 +247,16 @@ static ide_startstop_t ide_floppy_do_request(ide_drive_t *drive,
247 } else 247 } else
248 printk(KERN_ERR PFX "%s: I/O error\n", drive->name); 248 printk(KERN_ERR PFX "%s: I/O error\n", drive->name);
249 249
250 if (blk_special_request(rq)) { 250 if (rq->cmd_type == REQ_TYPE_SPECIAL) {
251 rq->errors = 0; 251 rq->errors = 0;
252 ide_complete_rq(drive, 0, blk_rq_bytes(rq)); 252 ide_complete_rq(drive, 0, blk_rq_bytes(rq));
253 return ide_stopped; 253 return ide_stopped;
254 } else 254 } else
255 goto out_end; 255 goto out_end;
256 } 256 }
257 if (blk_fs_request(rq)) { 257
258 switch (rq->cmd_type) {
259 case REQ_TYPE_FS:
258 if (((long)blk_rq_pos(rq) % floppy->bs_factor) || 260 if (((long)blk_rq_pos(rq) % floppy->bs_factor) ||
259 (blk_rq_sectors(rq) % floppy->bs_factor)) { 261 (blk_rq_sectors(rq) % floppy->bs_factor)) {
260 printk(KERN_ERR PFX "%s: unsupported r/w rq size\n", 262 printk(KERN_ERR PFX "%s: unsupported r/w rq size\n",
@@ -263,13 +265,18 @@ static ide_startstop_t ide_floppy_do_request(ide_drive_t *drive,
263 } 265 }
264 pc = &floppy->queued_pc; 266 pc = &floppy->queued_pc;
265 idefloppy_create_rw_cmd(drive, pc, rq, (unsigned long)block); 267 idefloppy_create_rw_cmd(drive, pc, rq, (unsigned long)block);
266 } else if (blk_special_request(rq) || blk_sense_request(rq)) { 268 break;
269 case REQ_TYPE_SPECIAL:
270 case REQ_TYPE_SENSE:
267 pc = (struct ide_atapi_pc *)rq->special; 271 pc = (struct ide_atapi_pc *)rq->special;
268 } else if (blk_pc_request(rq)) { 272 break;
273 case REQ_TYPE_BLOCK_PC:
269 pc = &floppy->queued_pc; 274 pc = &floppy->queued_pc;
270 idefloppy_blockpc_cmd(floppy, pc, rq); 275 idefloppy_blockpc_cmd(floppy, pc, rq);
271 } else 276 break;
277 default:
272 BUG(); 278 BUG();
279 }
273 280
274 ide_prep_sense(drive, rq); 281 ide_prep_sense(drive, rq);
275 282
@@ -280,7 +287,7 @@ static ide_startstop_t ide_floppy_do_request(ide_drive_t *drive,
280 287
281 cmd.rq = rq; 288 cmd.rq = rq;
282 289
283 if (blk_fs_request(rq) || blk_rq_bytes(rq)) { 290 if (rq->cmd_type == REQ_TYPE_FS || blk_rq_bytes(rq)) {
284 ide_init_sg_cmd(&cmd, blk_rq_bytes(rq)); 291 ide_init_sg_cmd(&cmd, blk_rq_bytes(rq));
285 ide_map_sg(drive, &cmd); 292 ide_map_sg(drive, &cmd);
286 } 293 }
@@ -290,7 +297,7 @@ static ide_startstop_t ide_floppy_do_request(ide_drive_t *drive,
290 return ide_floppy_issue_pc(drive, &cmd, pc); 297 return ide_floppy_issue_pc(drive, &cmd, pc);
291out_end: 298out_end:
292 drive->failed_pc = NULL; 299 drive->failed_pc = NULL;
293 if (blk_fs_request(rq) == 0 && rq->errors == 0) 300 if (rq->cmd_type != REQ_TYPE_FS && rq->errors == 0)
294 rq->errors = -EIO; 301 rq->errors = -EIO;
295 ide_complete_rq(drive, -EIO, blk_rq_bytes(rq)); 302 ide_complete_rq(drive, -EIO, blk_rq_bytes(rq));
296 return ide_stopped; 303 return ide_stopped;
diff --git a/drivers/ide/ide-floppy_ioctl.c b/drivers/ide/ide-floppy_ioctl.c
index 9c2288234dea..fd3d05ab3417 100644
--- a/drivers/ide/ide-floppy_ioctl.c
+++ b/drivers/ide/ide-floppy_ioctl.c
@@ -5,6 +5,7 @@
5#include <linux/kernel.h> 5#include <linux/kernel.h>
6#include <linux/ide.h> 6#include <linux/ide.h>
7#include <linux/cdrom.h> 7#include <linux/cdrom.h>
8#include <linux/smp_lock.h>
8 9
9#include <asm/unaligned.h> 10#include <asm/unaligned.h>
10 11
@@ -275,12 +276,15 @@ int ide_floppy_ioctl(ide_drive_t *drive, struct block_device *bdev,
275 void __user *argp = (void __user *)arg; 276 void __user *argp = (void __user *)arg;
276 int err; 277 int err;
277 278
278 if (cmd == CDROMEJECT || cmd == CDROM_LOCKDOOR) 279 lock_kernel();
279 return ide_floppy_lockdoor(drive, &pc, arg, cmd); 280 if (cmd == CDROMEJECT || cmd == CDROM_LOCKDOOR) {
281 err = ide_floppy_lockdoor(drive, &pc, arg, cmd);
282 goto out;
283 }
280 284
281 err = ide_floppy_format_ioctl(drive, &pc, mode, cmd, argp); 285 err = ide_floppy_format_ioctl(drive, &pc, mode, cmd, argp);
282 if (err != -ENOTTY) 286 if (err != -ENOTTY)
283 return err; 287 goto out;
284 288
285 /* 289 /*
286 * skip SCSI_IOCTL_SEND_COMMAND (deprecated) 290 * skip SCSI_IOCTL_SEND_COMMAND (deprecated)
@@ -293,5 +297,7 @@ int ide_floppy_ioctl(ide_drive_t *drive, struct block_device *bdev,
293 if (err == -ENOTTY) 297 if (err == -ENOTTY)
294 err = generic_ide_ioctl(drive, bdev, cmd, arg); 298 err = generic_ide_ioctl(drive, bdev, cmd, arg);
295 299
300out:
301 unlock_kernel();
296 return err; 302 return err;
297} 303}
diff --git a/drivers/ide/ide-gd.c b/drivers/ide/ide-gd.c
index 79399534782c..70aeeb18833e 100644
--- a/drivers/ide/ide-gd.c
+++ b/drivers/ide/ide-gd.c
@@ -1,3 +1,4 @@
1#include <linux/smp_lock.h>
1#include <linux/module.h> 2#include <linux/module.h>
2#include <linux/types.h> 3#include <linux/types.h>
3#include <linux/string.h> 4#include <linux/string.h>
@@ -237,6 +238,18 @@ out_put_idkp:
237 return ret; 238 return ret;
238} 239}
239 240
241static int ide_gd_unlocked_open(struct block_device *bdev, fmode_t mode)
242{
243 int ret;
244
245 lock_kernel();
246 ret = ide_gd_open(bdev, mode);
247 unlock_kernel();
248
249 return ret;
250}
251
252
240static int ide_gd_release(struct gendisk *disk, fmode_t mode) 253static int ide_gd_release(struct gendisk *disk, fmode_t mode)
241{ 254{
242 struct ide_disk_obj *idkp = ide_drv_g(disk, ide_disk_obj); 255 struct ide_disk_obj *idkp = ide_drv_g(disk, ide_disk_obj);
@@ -244,6 +257,7 @@ static int ide_gd_release(struct gendisk *disk, fmode_t mode)
244 257
245 ide_debug_log(IDE_DBG_FUNC, "enter"); 258 ide_debug_log(IDE_DBG_FUNC, "enter");
246 259
260 lock_kernel();
247 if (idkp->openers == 1) 261 if (idkp->openers == 1)
248 drive->disk_ops->flush(drive); 262 drive->disk_ops->flush(drive);
249 263
@@ -255,6 +269,7 @@ static int ide_gd_release(struct gendisk *disk, fmode_t mode)
255 idkp->openers--; 269 idkp->openers--;
256 270
257 ide_disk_put(idkp); 271 ide_disk_put(idkp);
272 unlock_kernel();
258 273
259 return 0; 274 return 0;
260} 275}
@@ -321,9 +336,9 @@ static int ide_gd_ioctl(struct block_device *bdev, fmode_t mode,
321 336
322static const struct block_device_operations ide_gd_ops = { 337static const struct block_device_operations ide_gd_ops = {
323 .owner = THIS_MODULE, 338 .owner = THIS_MODULE,
324 .open = ide_gd_open, 339 .open = ide_gd_unlocked_open,
325 .release = ide_gd_release, 340 .release = ide_gd_release,
326 .locked_ioctl = ide_gd_ioctl, 341 .ioctl = ide_gd_ioctl,
327 .getgeo = ide_gd_getgeo, 342 .getgeo = ide_gd_getgeo,
328 .media_changed = ide_gd_media_changed, 343 .media_changed = ide_gd_media_changed,
329 .unlock_native_capacity = ide_gd_unlock_native_capacity, 344 .unlock_native_capacity = ide_gd_unlock_native_capacity,
diff --git a/drivers/ide/ide-io.c b/drivers/ide/ide-io.c
index 172ac9218154..a381be814070 100644
--- a/drivers/ide/ide-io.c
+++ b/drivers/ide/ide-io.c
@@ -135,7 +135,7 @@ EXPORT_SYMBOL(ide_complete_rq);
135 135
136void ide_kill_rq(ide_drive_t *drive, struct request *rq) 136void ide_kill_rq(ide_drive_t *drive, struct request *rq)
137{ 137{
138 u8 drv_req = blk_special_request(rq) && rq->rq_disk; 138 u8 drv_req = (rq->cmd_type == REQ_TYPE_SPECIAL) && rq->rq_disk;
139 u8 media = drive->media; 139 u8 media = drive->media;
140 140
141 drive->failed_pc = NULL; 141 drive->failed_pc = NULL;
@@ -145,7 +145,7 @@ void ide_kill_rq(ide_drive_t *drive, struct request *rq)
145 } else { 145 } else {
146 if (media == ide_tape) 146 if (media == ide_tape)
147 rq->errors = IDE_DRV_ERROR_GENERAL; 147 rq->errors = IDE_DRV_ERROR_GENERAL;
148 else if (blk_fs_request(rq) == 0 && rq->errors == 0) 148 else if (rq->cmd_type != REQ_TYPE_FS && rq->errors == 0)
149 rq->errors = -EIO; 149 rq->errors = -EIO;
150 } 150 }
151 151
@@ -307,7 +307,7 @@ static ide_startstop_t start_request (ide_drive_t *drive, struct request *rq)
307{ 307{
308 ide_startstop_t startstop; 308 ide_startstop_t startstop;
309 309
310 BUG_ON(!blk_rq_started(rq)); 310 BUG_ON(!(rq->cmd_flags & REQ_STARTED));
311 311
312#ifdef DEBUG 312#ifdef DEBUG
313 printk("%s: start_request: current=0x%08lx\n", 313 printk("%s: start_request: current=0x%08lx\n",
@@ -353,7 +353,7 @@ static ide_startstop_t start_request (ide_drive_t *drive, struct request *rq)
353 pm->pm_step == IDE_PM_COMPLETED) 353 pm->pm_step == IDE_PM_COMPLETED)
354 ide_complete_pm_rq(drive, rq); 354 ide_complete_pm_rq(drive, rq);
355 return startstop; 355 return startstop;
356 } else if (!rq->rq_disk && blk_special_request(rq)) 356 } else if (!rq->rq_disk && rq->cmd_type == REQ_TYPE_SPECIAL)
357 /* 357 /*
358 * TODO: Once all ULDs have been modified to 358 * TODO: Once all ULDs have been modified to
359 * check for specific op codes rather than 359 * check for specific op codes rather than
diff --git a/drivers/ide/ide-pm.c b/drivers/ide/ide-pm.c
index 1c08311b0a0e..92406097efeb 100644
--- a/drivers/ide/ide-pm.c
+++ b/drivers/ide/ide-pm.c
@@ -191,10 +191,10 @@ void ide_complete_pm_rq(ide_drive_t *drive, struct request *rq)
191 191
192#ifdef DEBUG_PM 192#ifdef DEBUG_PM
193 printk("%s: completing PM request, %s\n", drive->name, 193 printk("%s: completing PM request, %s\n", drive->name,
194 blk_pm_suspend_request(rq) ? "suspend" : "resume"); 194 (rq->cmd_type == REQ_TYPE_PM_SUSPEND) ? "suspend" : "resume");
195#endif 195#endif
196 spin_lock_irqsave(q->queue_lock, flags); 196 spin_lock_irqsave(q->queue_lock, flags);
197 if (blk_pm_suspend_request(rq)) 197 if (rq->cmd_type == REQ_TYPE_PM_SUSPEND)
198 blk_stop_queue(q); 198 blk_stop_queue(q);
199 else 199 else
200 drive->dev_flags &= ~IDE_DFLAG_BLOCKED; 200 drive->dev_flags &= ~IDE_DFLAG_BLOCKED;
@@ -210,11 +210,11 @@ void ide_check_pm_state(ide_drive_t *drive, struct request *rq)
210{ 210{
211 struct request_pm_state *pm = rq->special; 211 struct request_pm_state *pm = rq->special;
212 212
213 if (blk_pm_suspend_request(rq) && 213 if (rq->cmd_type == REQ_TYPE_PM_SUSPEND &&
214 pm->pm_step == IDE_PM_START_SUSPEND) 214 pm->pm_step == IDE_PM_START_SUSPEND)
215 /* Mark drive blocked when starting the suspend sequence. */ 215 /* Mark drive blocked when starting the suspend sequence. */
216 drive->dev_flags |= IDE_DFLAG_BLOCKED; 216 drive->dev_flags |= IDE_DFLAG_BLOCKED;
217 else if (blk_pm_resume_request(rq) && 217 else if (rq->cmd_type == REQ_TYPE_PM_RESUME &&
218 pm->pm_step == IDE_PM_START_RESUME) { 218 pm->pm_step == IDE_PM_START_RESUME) {
219 /* 219 /*
220 * The first thing we do on wakeup is to wait for BSY bit to 220 * The first thing we do on wakeup is to wait for BSY bit to
diff --git a/drivers/ide/ide-tape.c b/drivers/ide/ide-tape.c
index b07232880ec9..6d622cb5ac81 100644
--- a/drivers/ide/ide-tape.c
+++ b/drivers/ide/ide-tape.c
@@ -32,6 +32,7 @@
32#include <linux/errno.h> 32#include <linux/errno.h>
33#include <linux/genhd.h> 33#include <linux/genhd.h>
34#include <linux/seq_file.h> 34#include <linux/seq_file.h>
35#include <linux/smp_lock.h>
35#include <linux/slab.h> 36#include <linux/slab.h>
36#include <linux/pci.h> 37#include <linux/pci.h>
37#include <linux/ide.h> 38#include <linux/ide.h>
@@ -577,7 +578,8 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
577 rq->cmd[0], (unsigned long long)blk_rq_pos(rq), 578 rq->cmd[0], (unsigned long long)blk_rq_pos(rq),
578 blk_rq_sectors(rq)); 579 blk_rq_sectors(rq));
579 580
580 BUG_ON(!(blk_special_request(rq) || blk_sense_request(rq))); 581 BUG_ON(!(rq->cmd_type == REQ_TYPE_SPECIAL ||
582 rq->cmd_type == REQ_TYPE_SENSE));
581 583
582 /* Retry a failed packet command */ 584 /* Retry a failed packet command */
583 if (drive->failed_pc && drive->pc->c[0] == REQUEST_SENSE) { 585 if (drive->failed_pc && drive->pc->c[0] == REQUEST_SENSE) {
@@ -1905,7 +1907,11 @@ static const struct file_operations idetape_fops = {
1905 1907
1906static int idetape_open(struct block_device *bdev, fmode_t mode) 1908static int idetape_open(struct block_device *bdev, fmode_t mode)
1907{ 1909{
1908 struct ide_tape_obj *tape = ide_tape_get(bdev->bd_disk, false, 0); 1910 struct ide_tape_obj *tape;
1911
1912 lock_kernel();
1913 tape = ide_tape_get(bdev->bd_disk, false, 0);
1914 unlock_kernel();
1909 1915
1910 if (!tape) 1916 if (!tape)
1911 return -ENXIO; 1917 return -ENXIO;
@@ -1917,7 +1923,10 @@ static int idetape_release(struct gendisk *disk, fmode_t mode)
1917{ 1923{
1918 struct ide_tape_obj *tape = ide_drv_g(disk, ide_tape_obj); 1924 struct ide_tape_obj *tape = ide_drv_g(disk, ide_tape_obj);
1919 1925
1926 lock_kernel();
1920 ide_tape_put(tape); 1927 ide_tape_put(tape);
1928 unlock_kernel();
1929
1921 return 0; 1930 return 0;
1922} 1931}
1923 1932
@@ -1926,9 +1935,14 @@ static int idetape_ioctl(struct block_device *bdev, fmode_t mode,
1926{ 1935{
1927 struct ide_tape_obj *tape = ide_drv_g(bdev->bd_disk, ide_tape_obj); 1936 struct ide_tape_obj *tape = ide_drv_g(bdev->bd_disk, ide_tape_obj);
1928 ide_drive_t *drive = tape->drive; 1937 ide_drive_t *drive = tape->drive;
1929 int err = generic_ide_ioctl(drive, bdev, cmd, arg); 1938 int err;
1939
1940 lock_kernel();
1941 err = generic_ide_ioctl(drive, bdev, cmd, arg);
1930 if (err == -EINVAL) 1942 if (err == -EINVAL)
1931 err = idetape_blkdev_ioctl(drive, cmd, arg); 1943 err = idetape_blkdev_ioctl(drive, cmd, arg);
1944 unlock_kernel();
1945
1932 return err; 1946 return err;
1933} 1947}
1934 1948
@@ -1936,7 +1950,7 @@ static const struct block_device_operations idetape_block_ops = {
1936 .owner = THIS_MODULE, 1950 .owner = THIS_MODULE,
1937 .open = idetape_open, 1951 .open = idetape_open,
1938 .release = idetape_release, 1952 .release = idetape_release,
1939 .locked_ioctl = idetape_ioctl, 1953 .ioctl = idetape_ioctl,
1940}; 1954};
1941 1955
1942static int ide_tape_probe(ide_drive_t *drive) 1956static int ide_tape_probe(ide_drive_t *drive)
diff --git a/drivers/ide/ide-taskfile.c b/drivers/ide/ide-taskfile.c
index 67fb73559fd5..34b9872f35d1 100644
--- a/drivers/ide/ide-taskfile.c
+++ b/drivers/ide/ide-taskfile.c
@@ -480,13 +480,9 @@ int ide_taskfile_ioctl(ide_drive_t *drive, unsigned long arg)
480 u16 nsect = 0; 480 u16 nsect = 0;
481 char __user *buf = (char __user *)arg; 481 char __user *buf = (char __user *)arg;
482 482
483 req_task = kzalloc(tasksize, GFP_KERNEL); 483 req_task = memdup_user(buf, tasksize);
484 if (req_task == NULL) 484 if (IS_ERR(req_task))
485 return -ENOMEM; 485 return PTR_ERR(req_task);
486 if (copy_from_user(req_task, buf, tasksize)) {
487 kfree(req_task);
488 return -EFAULT;
489 }
490 486
491 taskout = req_task->out_size; 487 taskout = req_task->out_size;
492 taskin = req_task->in_size; 488 taskin = req_task->in_size;
diff --git a/drivers/ide/ide.c b/drivers/ide/ide.c
index 3cb9c4e056ff..fa896210ed7b 100644
--- a/drivers/ide/ide.c
+++ b/drivers/ide/ide.c
@@ -177,7 +177,7 @@ EXPORT_SYMBOL_GPL(ide_pci_clk);
177module_param_named(pci_clock, ide_pci_clk, int, 0); 177module_param_named(pci_clock, ide_pci_clk, int, 0);
178MODULE_PARM_DESC(pci_clock, "PCI bus clock frequency (in MHz)"); 178MODULE_PARM_DESC(pci_clock, "PCI bus clock frequency (in MHz)");
179 179
180static int ide_set_dev_param_mask(const char *s, struct kernel_param *kp) 180static int ide_set_dev_param_mask(const char *s, const struct kernel_param *kp)
181{ 181{
182 int a, b, i, j = 1; 182 int a, b, i, j = 1;
183 unsigned int *dev_param_mask = (unsigned int *)kp->arg; 183 unsigned int *dev_param_mask = (unsigned int *)kp->arg;
@@ -200,34 +200,40 @@ static int ide_set_dev_param_mask(const char *s, struct kernel_param *kp)
200 return 0; 200 return 0;
201} 201}
202 202
203static struct kernel_param_ops param_ops_ide_dev_mask = {
204 .set = ide_set_dev_param_mask
205};
206
207#define param_check_ide_dev_mask(name, p) param_check_uint(name, p)
208
203static unsigned int ide_nodma; 209static unsigned int ide_nodma;
204 210
205module_param_call(nodma, ide_set_dev_param_mask, NULL, &ide_nodma, 0); 211module_param_named(nodma, ide_nodma, ide_dev_mask, 0);
206MODULE_PARM_DESC(nodma, "disallow DMA for a device"); 212MODULE_PARM_DESC(nodma, "disallow DMA for a device");
207 213
208static unsigned int ide_noflush; 214static unsigned int ide_noflush;
209 215
210module_param_call(noflush, ide_set_dev_param_mask, NULL, &ide_noflush, 0); 216module_param_named(noflush, ide_noflush, ide_dev_mask, 0);
211MODULE_PARM_DESC(noflush, "disable flush requests for a device"); 217MODULE_PARM_DESC(noflush, "disable flush requests for a device");
212 218
213static unsigned int ide_nohpa; 219static unsigned int ide_nohpa;
214 220
215module_param_call(nohpa, ide_set_dev_param_mask, NULL, &ide_nohpa, 0); 221module_param_named(nohpa, ide_nohpa, ide_dev_mask, 0);
216MODULE_PARM_DESC(nohpa, "disable Host Protected Area for a device"); 222MODULE_PARM_DESC(nohpa, "disable Host Protected Area for a device");
217 223
218static unsigned int ide_noprobe; 224static unsigned int ide_noprobe;
219 225
220module_param_call(noprobe, ide_set_dev_param_mask, NULL, &ide_noprobe, 0); 226module_param_named(noprobe, ide_noprobe, ide_dev_mask, 0);
221MODULE_PARM_DESC(noprobe, "skip probing for a device"); 227MODULE_PARM_DESC(noprobe, "skip probing for a device");
222 228
223static unsigned int ide_nowerr; 229static unsigned int ide_nowerr;
224 230
225module_param_call(nowerr, ide_set_dev_param_mask, NULL, &ide_nowerr, 0); 231module_param_named(nowerr, ide_nowerr, ide_dev_mask, 0);
226MODULE_PARM_DESC(nowerr, "ignore the ATA_DF bit for a device"); 232MODULE_PARM_DESC(nowerr, "ignore the ATA_DF bit for a device");
227 233
228static unsigned int ide_cdroms; 234static unsigned int ide_cdroms;
229 235
230module_param_call(cdrom, ide_set_dev_param_mask, NULL, &ide_cdroms, 0); 236module_param_named(cdrom, ide_cdroms, ide_dev_mask, 0);
231MODULE_PARM_DESC(cdrom, "force device as a CD-ROM"); 237MODULE_PARM_DESC(cdrom, "force device as a CD-ROM");
232 238
233struct chs_geom { 239struct chs_geom {
diff --git a/drivers/ide/tx4938ide.c b/drivers/ide/tx4938ide.c
index 1d80f1fdbc97..7002765b593c 100644
--- a/drivers/ide/tx4938ide.c
+++ b/drivers/ide/tx4938ide.c
@@ -64,7 +64,7 @@ static void tx4938ide_set_pio_mode(ide_hwif_t *hwif, ide_drive_t *drive)
64 64
65 pair = ide_get_pair_dev(drive); 65 pair = ide_get_pair_dev(drive);
66 if (pair) 66 if (pair)
67 safe = min(safe, pair->pio_mode - XFER_PIO_0); 67 safe = min_t(u8, safe, pair->pio_mode - XFER_PIO_0);
68 tx4938ide_tune_ebusc(pdata->ebus_ch, pdata->gbus_clock, safe); 68 tx4938ide_tune_ebusc(pdata->ebus_ch, pdata->gbus_clock, safe);
69} 69}
70 70
diff --git a/drivers/ide/tx4939ide.c b/drivers/ide/tx4939ide.c
index 3c7367751873..bed3e39aac96 100644
--- a/drivers/ide/tx4939ide.c
+++ b/drivers/ide/tx4939ide.c
@@ -114,7 +114,7 @@ static void tx4939ide_set_pio_mode(ide_hwif_t *hwif, ide_drive_t *drive)
114 114
115 pair = ide_get_pair_dev(drive); 115 pair = ide_get_pair_dev(drive);
116 if (pair) 116 if (pair)
117 safe = min(safe, pair->pio_mode - XFER_PIO_0); 117 safe = min_t(u8, safe, pair->pio_mode - XFER_PIO_0);
118 /* 118 /*
119 * Update Command Transfer Mode for master/slave and Data 119 * Update Command Transfer Mode for master/slave and Data
120 * Transfer Mode for this drive. 120 * Transfer Mode for this drive.
diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
index 101f40022386..d2a0997b78f8 100644
--- a/drivers/ide/via82cxxx.c
+++ b/drivers/ide/via82cxxx.c
@@ -79,7 +79,7 @@ static struct via_isa_bridge {
79 { "vt8261", PCI_DEVICE_ID_VIA_8261, 0x00, 0x2f, ATA_UDMA6, VIA_BAD_AST }, 79 { "vt8261", PCI_DEVICE_ID_VIA_8261, 0x00, 0x2f, ATA_UDMA6, VIA_BAD_AST },
80 { "vt8237s", PCI_DEVICE_ID_VIA_8237S, 0x00, 0x2f, ATA_UDMA6, VIA_BAD_AST }, 80 { "vt8237s", PCI_DEVICE_ID_VIA_8237S, 0x00, 0x2f, ATA_UDMA6, VIA_BAD_AST },
81 { "vt6410", PCI_DEVICE_ID_VIA_6410, 0x00, 0x2f, ATA_UDMA6, VIA_BAD_AST }, 81 { "vt6410", PCI_DEVICE_ID_VIA_6410, 0x00, 0x2f, ATA_UDMA6, VIA_BAD_AST },
82 { "vt6415", PCI_DEVICE_ID_VIA_6410, 0x00, 0xff, ATA_UDMA6, VIA_BAD_AST }, 82 { "vt6415", PCI_DEVICE_ID_VIA_6415, 0x00, 0xff, ATA_UDMA6, VIA_BAD_AST },
83 { "vt8251", PCI_DEVICE_ID_VIA_8251, 0x00, 0x2f, ATA_UDMA6, VIA_BAD_AST }, 83 { "vt8251", PCI_DEVICE_ID_VIA_8251, 0x00, 0x2f, ATA_UDMA6, VIA_BAD_AST },
84 { "vt8237", PCI_DEVICE_ID_VIA_8237, 0x00, 0x2f, ATA_UDMA6, VIA_BAD_AST }, 84 { "vt8237", PCI_DEVICE_ID_VIA_8237, 0x00, 0x2f, ATA_UDMA6, VIA_BAD_AST },
85 { "vt8237a", PCI_DEVICE_ID_VIA_8237A, 0x00, 0x2f, ATA_UDMA6, VIA_BAD_AST }, 85 { "vt8237a", PCI_DEVICE_ID_VIA_8237A, 0x00, 0x2f, ATA_UDMA6, VIA_BAD_AST },
diff --git a/drivers/idle/Kconfig b/drivers/idle/Kconfig
index fb5c5186d4aa..8489eb58a52c 100644
--- a/drivers/idle/Kconfig
+++ b/drivers/idle/Kconfig
@@ -1,9 +1,8 @@
1config INTEL_IDLE 1config INTEL_IDLE
2 tristate "Cpuidle Driver for Intel Processors" 2 bool "Cpuidle Driver for Intel Processors"
3 depends on CPU_IDLE 3 depends on CPU_IDLE
4 depends on X86 4 depends on X86
5 depends on CPU_SUP_INTEL 5 depends on CPU_SUP_INTEL
6 depends on EXPERIMENTAL
7 help 6 help
8 Enable intel_idle, a cpuidle driver that includes knowledge of 7 Enable intel_idle, a cpuidle driver that includes knowledge of
9 native Intel hardware idle features. The acpi_idle driver 8 native Intel hardware idle features. The acpi_idle driver
diff --git a/drivers/idle/intel_idle.c b/drivers/idle/intel_idle.c
index 03d202b1ff27..a10152bb1427 100755
--- a/drivers/idle/intel_idle.c
+++ b/drivers/idle/intel_idle.c
@@ -77,10 +77,8 @@ static struct cpuidle_driver intel_idle_driver = {
77}; 77};
78/* intel_idle.max_cstate=0 disables driver */ 78/* intel_idle.max_cstate=0 disables driver */
79static int max_cstate = MWAIT_MAX_NUM_CSTATES - 1; 79static int max_cstate = MWAIT_MAX_NUM_CSTATES - 1;
80static int power_policy = 7; /* 0 = max perf; 15 = max powersave */
81 80
82static unsigned int substates; 81static unsigned int mwait_substates;
83static int (*choose_substate)(int);
84 82
85/* Reliable LAPIC Timer States, bit 1 for C1 etc. */ 83/* Reliable LAPIC Timer States, bit 1 for C1 etc. */
86static unsigned int lapic_timer_reliable_states; 84static unsigned int lapic_timer_reliable_states;
@@ -168,41 +166,6 @@ static struct cpuidle_state atom_cstates[MWAIT_MAX_NUM_CSTATES] = {
168 .enter = NULL }, /* disabled */ 166 .enter = NULL }, /* disabled */
169}; 167};
170 168
171/*
172 * choose_tunable_substate()
173 *
174 * Run-time decision on which C-state substate to invoke
175 * If power_policy = 0, choose shallowest substate (0)
176 * If power_policy = 15, choose deepest substate
177 * If power_policy = middle, choose middle substate etc.
178 */
179static int choose_tunable_substate(int cstate)
180{
181 unsigned int num_substates;
182 unsigned int substate_choice;
183
184 power_policy &= 0xF; /* valid range: 0-15 */
185 cstate &= 7; /* valid range: 0-7 */
186
187 num_substates = (substates >> ((cstate) * 4)) & MWAIT_SUBSTATE_MASK;
188
189 if (num_substates <= 1)
190 return 0;
191
192 substate_choice = ((power_policy + (power_policy + 1) *
193 (num_substates - 1)) / 16);
194
195 return substate_choice;
196}
197
198/*
199 * choose_zero_substate()
200 */
201static int choose_zero_substate(int cstate)
202{
203 return 0;
204}
205
206/** 169/**
207 * intel_idle 170 * intel_idle
208 * @dev: cpuidle_device 171 * @dev: cpuidle_device
@@ -220,8 +183,6 @@ static int intel_idle(struct cpuidle_device *dev, struct cpuidle_state *state)
220 183
221 cstate = (((eax) >> MWAIT_SUBSTATE_SIZE) & MWAIT_CSTATE_MASK) + 1; 184 cstate = (((eax) >> MWAIT_SUBSTATE_SIZE) & MWAIT_CSTATE_MASK) + 1;
222 185
223 eax = eax + (choose_substate)(cstate);
224
225 local_irq_disable(); 186 local_irq_disable();
226 187
227 if (!(lapic_timer_reliable_states & (1 << (cstate)))) 188 if (!(lapic_timer_reliable_states & (1 << (cstate))))
@@ -259,7 +220,7 @@ static int intel_idle(struct cpuidle_device *dev, struct cpuidle_state *state)
259 */ 220 */
260static int intel_idle_probe(void) 221static int intel_idle_probe(void)
261{ 222{
262 unsigned int eax, ebx, ecx, edx; 223 unsigned int eax, ebx, ecx;
263 224
264 if (max_cstate == 0) { 225 if (max_cstate == 0) {
265 pr_debug(PREFIX "disabled\n"); 226 pr_debug(PREFIX "disabled\n");
@@ -275,17 +236,13 @@ static int intel_idle_probe(void)
275 if (boot_cpu_data.cpuid_level < CPUID_MWAIT_LEAF) 236 if (boot_cpu_data.cpuid_level < CPUID_MWAIT_LEAF)
276 return -ENODEV; 237 return -ENODEV;
277 238
278 cpuid(CPUID_MWAIT_LEAF, &eax, &ebx, &ecx, &edx); 239 cpuid(CPUID_MWAIT_LEAF, &eax, &ebx, &ecx, &mwait_substates);
279 240
280 if (!(ecx & CPUID5_ECX_EXTENSIONS_SUPPORTED) || 241 if (!(ecx & CPUID5_ECX_EXTENSIONS_SUPPORTED) ||
281 !(ecx & CPUID5_ECX_INTERRUPT_BREAK)) 242 !(ecx & CPUID5_ECX_INTERRUPT_BREAK))
282 return -ENODEV; 243 return -ENODEV;
283#ifdef DEBUG
284 if (substates == 0) /* can over-ride via modparam */
285#endif
286 substates = edx;
287 244
288 pr_debug(PREFIX "MWAIT substates: 0x%x\n", substates); 245 pr_debug(PREFIX "MWAIT substates: 0x%x\n", mwait_substates);
289 246
290 if (boot_cpu_has(X86_FEATURE_ARAT)) /* Always Reliable APIC Timer */ 247 if (boot_cpu_has(X86_FEATURE_ARAT)) /* Always Reliable APIC Timer */
291 lapic_timer_reliable_states = 0xFFFFFFFF; 248 lapic_timer_reliable_states = 0xFFFFFFFF;
@@ -299,18 +256,18 @@ static int intel_idle_probe(void)
299 case 0x1E: /* Core i7 and i5 Processor - Lynnfield Jasper Forest */ 256 case 0x1E: /* Core i7 and i5 Processor - Lynnfield Jasper Forest */
300 case 0x1F: /* Core i7 and i5 Processor - Nehalem */ 257 case 0x1F: /* Core i7 and i5 Processor - Nehalem */
301 case 0x2E: /* Nehalem-EX Xeon */ 258 case 0x2E: /* Nehalem-EX Xeon */
259 case 0x2F: /* Westmere-EX Xeon */
302 lapic_timer_reliable_states = (1 << 1); /* C1 */ 260 lapic_timer_reliable_states = (1 << 1); /* C1 */
303 261
304 case 0x25: /* Westmere */ 262 case 0x25: /* Westmere */
305 case 0x2C: /* Westmere */ 263 case 0x2C: /* Westmere */
306 cpuidle_state_table = nehalem_cstates; 264 cpuidle_state_table = nehalem_cstates;
307 choose_substate = choose_tunable_substate;
308 break; 265 break;
309 266
310 case 0x1C: /* 28 - Atom Processor */ 267 case 0x1C: /* 28 - Atom Processor */
268 case 0x26: /* 38 - Lincroft Atom Processor */
311 lapic_timer_reliable_states = (1 << 2) | (1 << 1); /* C2, C1 */ 269 lapic_timer_reliable_states = (1 << 2) | (1 << 1); /* C2, C1 */
312 cpuidle_state_table = atom_cstates; 270 cpuidle_state_table = atom_cstates;
313 choose_substate = choose_zero_substate;
314 break; 271 break;
315#ifdef FUTURE_USE 272#ifdef FUTURE_USE
316 case 0x17: /* 23 - Core 2 Duo */ 273 case 0x17: /* 23 - Core 2 Duo */
@@ -376,7 +333,7 @@ static int intel_idle_cpuidle_devices_init(void)
376 } 333 }
377 334
378 /* does the state exist in CPUID.MWAIT? */ 335 /* does the state exist in CPUID.MWAIT? */
379 num_substates = (substates >> ((cstate) * 4)) 336 num_substates = (mwait_substates >> ((cstate) * 4))
380 & MWAIT_SUBSTATE_MASK; 337 & MWAIT_SUBSTATE_MASK;
381 if (num_substates == 0) 338 if (num_substates == 0)
382 continue; 339 continue;
@@ -450,11 +407,7 @@ static void __exit intel_idle_exit(void)
450module_init(intel_idle_init); 407module_init(intel_idle_init);
451module_exit(intel_idle_exit); 408module_exit(intel_idle_exit);
452 409
453module_param(power_policy, int, 0644);
454module_param(max_cstate, int, 0444); 410module_param(max_cstate, int, 0444);
455#ifdef DEBUG
456module_param(substates, int, 0444);
457#endif
458 411
459MODULE_AUTHOR("Len Brown <len.brown@intel.com>"); 412MODULE_AUTHOR("Len Brown <len.brown@intel.com>");
460MODULE_DESCRIPTION("Cpuidle driver for Intel Hardware v" INTEL_IDLE_VERSION); 413MODULE_DESCRIPTION("Cpuidle driver for Intel Hardware v" INTEL_IDLE_VERSION);
diff --git a/drivers/infiniband/hw/cxgb4/device.c b/drivers/infiniband/hw/cxgb4/device.c
index d870f9c17c1e..9bbf491d5d9e 100644
--- a/drivers/infiniband/hw/cxgb4/device.c
+++ b/drivers/infiniband/hw/cxgb4/device.c
@@ -250,12 +250,17 @@ static int c4iw_rdev_open(struct c4iw_rdev *rdev)
250 rdev->cqshift = PAGE_SHIFT - ilog2(rdev->lldi.ucq_density); 250 rdev->cqshift = PAGE_SHIFT - ilog2(rdev->lldi.ucq_density);
251 rdev->cqmask = rdev->lldi.ucq_density - 1; 251 rdev->cqmask = rdev->lldi.ucq_density - 1;
252 PDBG("%s dev %s stag start 0x%0x size 0x%0x num stags %d " 252 PDBG("%s dev %s stag start 0x%0x size 0x%0x num stags %d "
253 "pbl start 0x%0x size 0x%0x rq start 0x%0x size 0x%0x\n", 253 "pbl start 0x%0x size 0x%0x rq start 0x%0x size 0x%0x "
254 "qp qid start %u size %u cq qid start %u size %u\n",
254 __func__, pci_name(rdev->lldi.pdev), rdev->lldi.vr->stag.start, 255 __func__, pci_name(rdev->lldi.pdev), rdev->lldi.vr->stag.start,
255 rdev->lldi.vr->stag.size, c4iw_num_stags(rdev), 256 rdev->lldi.vr->stag.size, c4iw_num_stags(rdev),
256 rdev->lldi.vr->pbl.start, 257 rdev->lldi.vr->pbl.start,
257 rdev->lldi.vr->pbl.size, rdev->lldi.vr->rq.start, 258 rdev->lldi.vr->pbl.size, rdev->lldi.vr->rq.start,
258 rdev->lldi.vr->rq.size); 259 rdev->lldi.vr->rq.size,
260 rdev->lldi.vr->qp.start,
261 rdev->lldi.vr->qp.size,
262 rdev->lldi.vr->cq.start,
263 rdev->lldi.vr->cq.size);
259 PDBG("udb len 0x%x udb base %p db_reg %p gts_reg %p qpshift %lu " 264 PDBG("udb len 0x%x udb base %p db_reg %p gts_reg %p qpshift %lu "
260 "qpmask 0x%x cqshift %lu cqmask 0x%x\n", 265 "qpmask 0x%x cqshift %lu cqmask 0x%x\n",
261 (unsigned)pci_resource_len(rdev->lldi.pdev, 2), 266 (unsigned)pci_resource_len(rdev->lldi.pdev, 2),
diff --git a/drivers/infiniband/hw/cxgb4/resource.c b/drivers/infiniband/hw/cxgb4/resource.c
index fb195d1d9015..83b23dfa250d 100644
--- a/drivers/infiniband/hw/cxgb4/resource.c
+++ b/drivers/infiniband/hw/cxgb4/resource.c
@@ -110,11 +110,12 @@ static int c4iw_init_qid_fifo(struct c4iw_rdev *rdev)
110 110
111 spin_lock_init(&rdev->resource.qid_fifo_lock); 111 spin_lock_init(&rdev->resource.qid_fifo_lock);
112 112
113 if (kfifo_alloc(&rdev->resource.qid_fifo, T4_MAX_QIDS * sizeof(u32), 113 if (kfifo_alloc(&rdev->resource.qid_fifo, rdev->lldi.vr->qp.size *
114 GFP_KERNEL)) 114 sizeof(u32), GFP_KERNEL))
115 return -ENOMEM; 115 return -ENOMEM;
116 116
117 for (i = T4_QID_BASE; i < T4_QID_BASE + T4_MAX_QIDS; i++) 117 for (i = rdev->lldi.vr->qp.start;
118 i < rdev->lldi.vr->qp.start + rdev->lldi.vr->qp.size; i++)
118 if (!(i & rdev->qpmask)) 119 if (!(i & rdev->qpmask))
119 kfifo_in(&rdev->resource.qid_fifo, 120 kfifo_in(&rdev->resource.qid_fifo,
120 (unsigned char *) &i, sizeof(u32)); 121 (unsigned char *) &i, sizeof(u32));
diff --git a/drivers/infiniband/hw/cxgb4/t4.h b/drivers/infiniband/hw/cxgb4/t4.h
index aef55f42bea4..24f369046ef3 100644
--- a/drivers/infiniband/hw/cxgb4/t4.h
+++ b/drivers/infiniband/hw/cxgb4/t4.h
@@ -36,8 +36,6 @@
36#include "t4_msg.h" 36#include "t4_msg.h"
37#include "t4fw_ri_api.h" 37#include "t4fw_ri_api.h"
38 38
39#define T4_QID_BASE 1024
40#define T4_MAX_QIDS 256
41#define T4_MAX_NUM_QP (1<<16) 39#define T4_MAX_NUM_QP (1<<16)
42#define T4_MAX_NUM_CQ (1<<15) 40#define T4_MAX_NUM_CQ (1<<15)
43#define T4_MAX_NUM_PD (1<<15) 41#define T4_MAX_NUM_PD (1<<15)
diff --git a/drivers/infiniband/hw/ehca/ehca_classes.h b/drivers/infiniband/hw/ehca/ehca_classes.h
index 0136abd50dd4..aaf6023a4835 100644
--- a/drivers/infiniband/hw/ehca/ehca_classes.h
+++ b/drivers/infiniband/hw/ehca/ehca_classes.h
@@ -112,7 +112,7 @@ struct ehca_sport {
112 112
113struct ehca_shca { 113struct ehca_shca {
114 struct ib_device ib_device; 114 struct ib_device ib_device;
115 struct of_device *ofdev; 115 struct platform_device *ofdev;
116 u8 num_ports; 116 u8 num_ports;
117 int hw_level; 117 int hw_level;
118 struct list_head shca_list; 118 struct list_head shca_list;
diff --git a/drivers/infiniband/hw/ehca/ehca_main.c b/drivers/infiniband/hw/ehca/ehca_main.c
index cfc4de7a5da4..c240e9972cb0 100644
--- a/drivers/infiniband/hw/ehca/ehca_main.c
+++ b/drivers/infiniband/hw/ehca/ehca_main.c
@@ -713,7 +713,7 @@ static struct attribute_group ehca_dev_attr_grp = {
713 .attrs = ehca_dev_attrs 713 .attrs = ehca_dev_attrs
714}; 714};
715 715
716static int __devinit ehca_probe(struct of_device *dev, 716static int __devinit ehca_probe(struct platform_device *dev,
717 const struct of_device_id *id) 717 const struct of_device_id *id)
718{ 718{
719 struct ehca_shca *shca; 719 struct ehca_shca *shca;
@@ -879,7 +879,7 @@ probe1:
879 return -EINVAL; 879 return -EINVAL;
880} 880}
881 881
882static int __devexit ehca_remove(struct of_device *dev) 882static int __devexit ehca_remove(struct platform_device *dev)
883{ 883{
884 struct ehca_shca *shca = dev_get_drvdata(&dev->dev); 884 struct ehca_shca *shca = dev_get_drvdata(&dev->dev);
885 unsigned long flags; 885 unsigned long flags;
diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
index 054edf346e0b..c908c5f83645 100644
--- a/drivers/input/evdev.c
+++ b/drivers/input/evdev.c
@@ -492,13 +492,15 @@ static int str_to_user(const char *str, unsigned int maxlen, void __user *p)
492} 492}
493 493
494#define OLD_KEY_MAX 0x1ff 494#define OLD_KEY_MAX 0x1ff
495static int handle_eviocgbit(struct input_dev *dev, unsigned int cmd, void __user *p, int compat_mode) 495static int handle_eviocgbit(struct input_dev *dev,
496 unsigned int type, unsigned int size,
497 void __user *p, int compat_mode)
496{ 498{
497 static unsigned long keymax_warn_time; 499 static unsigned long keymax_warn_time;
498 unsigned long *bits; 500 unsigned long *bits;
499 int len; 501 int len;
500 502
501 switch (_IOC_NR(cmd) & EV_MAX) { 503 switch (type) {
502 504
503 case 0: bits = dev->evbit; len = EV_MAX; break; 505 case 0: bits = dev->evbit; len = EV_MAX; break;
504 case EV_KEY: bits = dev->keybit; len = KEY_MAX; break; 506 case EV_KEY: bits = dev->keybit; len = KEY_MAX; break;
@@ -517,7 +519,7 @@ static int handle_eviocgbit(struct input_dev *dev, unsigned int cmd, void __user
517 * EVIOCGBIT(EV_KEY, KEY_MAX) and not realize that 'len' 519 * EVIOCGBIT(EV_KEY, KEY_MAX) and not realize that 'len'
518 * should be in bytes, not in bits. 520 * should be in bytes, not in bits.
519 */ 521 */
520 if ((_IOC_NR(cmd) & EV_MAX) == EV_KEY && _IOC_SIZE(cmd) == OLD_KEY_MAX) { 522 if (type == EV_KEY && size == OLD_KEY_MAX) {
521 len = OLD_KEY_MAX; 523 len = OLD_KEY_MAX;
522 if (printk_timed_ratelimit(&keymax_warn_time, 10 * 1000)) 524 if (printk_timed_ratelimit(&keymax_warn_time, 10 * 1000))
523 printk(KERN_WARNING 525 printk(KERN_WARNING
@@ -528,7 +530,7 @@ static int handle_eviocgbit(struct input_dev *dev, unsigned int cmd, void __user
528 BITS_TO_LONGS(OLD_KEY_MAX) * sizeof(long)); 530 BITS_TO_LONGS(OLD_KEY_MAX) * sizeof(long));
529 } 531 }
530 532
531 return bits_to_user(bits, len, _IOC_SIZE(cmd), p, compat_mode); 533 return bits_to_user(bits, len, size, p, compat_mode);
532} 534}
533#undef OLD_KEY_MAX 535#undef OLD_KEY_MAX
534 536
@@ -542,8 +544,10 @@ static long evdev_do_ioctl(struct file *file, unsigned int cmd,
542 struct ff_effect effect; 544 struct ff_effect effect;
543 int __user *ip = (int __user *)p; 545 int __user *ip = (int __user *)p;
544 unsigned int i, t, u, v; 546 unsigned int i, t, u, v;
547 unsigned int size;
545 int error; 548 int error;
546 549
550 /* First we check for fixed-length commands */
547 switch (cmd) { 551 switch (cmd) {
548 552
549 case EVIOCGVERSION: 553 case EVIOCGVERSION:
@@ -610,112 +614,102 @@ static long evdev_do_ioctl(struct file *file, unsigned int cmd,
610 return evdev_grab(evdev, client); 614 return evdev_grab(evdev, client);
611 else 615 else
612 return evdev_ungrab(evdev, client); 616 return evdev_ungrab(evdev, client);
617 }
613 618
614 default: 619 size = _IOC_SIZE(cmd);
615
616 if (_IOC_TYPE(cmd) != 'E')
617 return -EINVAL;
618
619 if (_IOC_DIR(cmd) == _IOC_READ) {
620 620
621 if ((_IOC_NR(cmd) & ~EV_MAX) == _IOC_NR(EVIOCGBIT(0, 0))) 621 /* Now check variable-length commands */
622 return handle_eviocgbit(dev, cmd, p, compat_mode); 622#define EVIOC_MASK_SIZE(nr) ((nr) & ~(_IOC_SIZEMASK << _IOC_SIZESHIFT))
623 623
624 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGKEY(0))) 624 switch (EVIOC_MASK_SIZE(cmd)) {
625 return bits_to_user(dev->key, KEY_MAX, _IOC_SIZE(cmd),
626 p, compat_mode);
627 625
628 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGLED(0))) 626 case EVIOCGKEY(0):
629 return bits_to_user(dev->led, LED_MAX, _IOC_SIZE(cmd), 627 return bits_to_user(dev->key, KEY_MAX, size, p, compat_mode);
630 p, compat_mode);
631 628
632 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGSND(0))) 629 case EVIOCGLED(0):
633 return bits_to_user(dev->snd, SND_MAX, _IOC_SIZE(cmd), 630 return bits_to_user(dev->led, LED_MAX, size, p, compat_mode);
634 p, compat_mode);
635 631
636 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGSW(0))) 632 case EVIOCGSND(0):
637 return bits_to_user(dev->sw, SW_MAX, _IOC_SIZE(cmd), 633 return bits_to_user(dev->snd, SND_MAX, size, p, compat_mode);
638 p, compat_mode);
639 634
640 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGNAME(0))) 635 case EVIOCGSW(0):
641 return str_to_user(dev->name, _IOC_SIZE(cmd), p); 636 return bits_to_user(dev->sw, SW_MAX, size, p, compat_mode);
642 637
643 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGPHYS(0))) 638 case EVIOCGNAME(0):
644 return str_to_user(dev->phys, _IOC_SIZE(cmd), p); 639 return str_to_user(dev->name, size, p);
645 640
646 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGUNIQ(0))) 641 case EVIOCGPHYS(0):
647 return str_to_user(dev->uniq, _IOC_SIZE(cmd), p); 642 return str_to_user(dev->phys, size, p);
648 643
649 if ((_IOC_NR(cmd) & ~ABS_MAX) == _IOC_NR(EVIOCGABS(0))) { 644 case EVIOCGUNIQ(0):
645 return str_to_user(dev->uniq, size, p);
650 646
651 t = _IOC_NR(cmd) & ABS_MAX; 647 case EVIOC_MASK_SIZE(EVIOCSFF):
648 if (input_ff_effect_from_user(p, size, &effect))
649 return -EFAULT;
652 650
653 abs.value = dev->abs[t]; 651 error = input_ff_upload(dev, &effect, file);
654 abs.minimum = dev->absmin[t];
655 abs.maximum = dev->absmax[t];
656 abs.fuzz = dev->absfuzz[t];
657 abs.flat = dev->absflat[t];
658 abs.resolution = dev->absres[t];
659 652
660 if (copy_to_user(p, &abs, min_t(size_t, 653 if (put_user(effect.id, &(((struct ff_effect __user *)p)->id)))
661 _IOC_SIZE(cmd), 654 return -EFAULT;
662 sizeof(struct input_absinfo))))
663 return -EFAULT;
664 655
665 return 0; 656 return error;
666 } 657 }
667 658
668 } 659 /* Multi-number variable-length handlers */
660 if (_IOC_TYPE(cmd) != 'E')
661 return -EINVAL;
669 662
670 if (_IOC_DIR(cmd) == _IOC_WRITE) { 663 if (_IOC_DIR(cmd) == _IOC_READ) {
671 664
672 if (_IOC_NR(cmd) == _IOC_NR(EVIOCSFF)) { 665 if ((_IOC_NR(cmd) & ~EV_MAX) == _IOC_NR(EVIOCGBIT(0, 0)))
666 return handle_eviocgbit(dev,
667 _IOC_NR(cmd) & EV_MAX, size,
668 p, compat_mode);
673 669
674 if (input_ff_effect_from_user(p, _IOC_SIZE(cmd), &effect)) 670 if ((_IOC_NR(cmd) & ~ABS_MAX) == _IOC_NR(EVIOCGABS(0))) {
675 return -EFAULT;
676 671
677 error = input_ff_upload(dev, &effect, file); 672 t = _IOC_NR(cmd) & ABS_MAX;
673 abs = dev->absinfo[t];
678 674
679 if (put_user(effect.id, &(((struct ff_effect __user *)p)->id))) 675 if (copy_to_user(p, &abs, min_t(size_t,
680 return -EFAULT; 676 size, sizeof(struct input_absinfo))))
677 return -EFAULT;
681 678
682 return error; 679 return 0;
683 } 680 }
681 }
684 682
685 if ((_IOC_NR(cmd) & ~ABS_MAX) == _IOC_NR(EVIOCSABS(0))) { 683 if (_IOC_DIR(cmd) == _IOC_READ) {
686 684
687 t = _IOC_NR(cmd) & ABS_MAX; 685 if ((_IOC_NR(cmd) & ~ABS_MAX) == _IOC_NR(EVIOCSABS(0))) {
688 686
689 if (copy_from_user(&abs, p, min_t(size_t, 687 t = _IOC_NR(cmd) & ABS_MAX;
690 _IOC_SIZE(cmd),
691 sizeof(struct input_absinfo))))
692 return -EFAULT;
693 688
694 /* We can't change number of reserved MT slots */ 689 if (copy_from_user(&abs, p, min_t(size_t,
695 if (t == ABS_MT_SLOT) 690 size, sizeof(struct input_absinfo))))
696 return -EINVAL; 691 return -EFAULT;
697 692
698 /* 693 if (size < sizeof(struct input_absinfo))
699 * Take event lock to ensure that we are not 694 abs.resolution = 0;
700 * changing device parameters in the middle
701 * of event.
702 */
703 spin_lock_irq(&dev->event_lock);
704 695
705 dev->abs[t] = abs.value; 696 /* We can't change number of reserved MT slots */
706 dev->absmin[t] = abs.minimum; 697 if (t == ABS_MT_SLOT)
707 dev->absmax[t] = abs.maximum; 698 return -EINVAL;
708 dev->absfuzz[t] = abs.fuzz;
709 dev->absflat[t] = abs.flat;
710 dev->absres[t] = _IOC_SIZE(cmd) < sizeof(struct input_absinfo) ?
711 0 : abs.resolution;
712 699
713 spin_unlock_irq(&dev->event_lock); 700 /*
701 * Take event lock to ensure that we are not
702 * changing device parameters in the middle
703 * of event.
704 */
705 spin_lock_irq(&dev->event_lock);
706 dev->absinfo[t] = abs;
707 spin_unlock_irq(&dev->event_lock);
714 708
715 return 0; 709 return 0;
716 }
717 } 710 }
718 } 711 }
712
719 return -EINVAL; 713 return -EINVAL;
720} 714}
721 715
diff --git a/drivers/input/input.c b/drivers/input/input.c
index e1243b4b32a5..a9b025f4147a 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -182,7 +182,7 @@ static int input_handle_abs_event(struct input_dev *dev,
182 is_mt_event = code >= ABS_MT_FIRST && code <= ABS_MT_LAST; 182 is_mt_event = code >= ABS_MT_FIRST && code <= ABS_MT_LAST;
183 183
184 if (!is_mt_event) { 184 if (!is_mt_event) {
185 pold = &dev->abs[code]; 185 pold = &dev->absinfo[code].value;
186 } else if (dev->mt) { 186 } else if (dev->mt) {
187 struct input_mt_slot *mtslot = &dev->mt[dev->slot]; 187 struct input_mt_slot *mtslot = &dev->mt[dev->slot];
188 pold = &mtslot->abs[code - ABS_MT_FIRST]; 188 pold = &mtslot->abs[code - ABS_MT_FIRST];
@@ -196,7 +196,7 @@ static int input_handle_abs_event(struct input_dev *dev,
196 196
197 if (pold) { 197 if (pold) {
198 *pval = input_defuzz_abs_event(*pval, *pold, 198 *pval = input_defuzz_abs_event(*pval, *pold,
199 dev->absfuzz[code]); 199 dev->absinfo[code].fuzz);
200 if (*pold == *pval) 200 if (*pold == *pval)
201 return INPUT_IGNORE_EVENT; 201 return INPUT_IGNORE_EVENT;
202 202
@@ -204,8 +204,8 @@ static int input_handle_abs_event(struct input_dev *dev,
204 } 204 }
205 205
206 /* Flush pending "slot" event */ 206 /* Flush pending "slot" event */
207 if (is_mt_event && dev->slot != dev->abs[ABS_MT_SLOT]) { 207 if (is_mt_event && dev->slot != input_abs_get_val(dev, ABS_MT_SLOT)) {
208 dev->abs[ABS_MT_SLOT] = dev->slot; 208 input_abs_set_val(dev, ABS_MT_SLOT, dev->slot);
209 input_pass_event(dev, EV_ABS, ABS_MT_SLOT, dev->slot); 209 input_pass_event(dev, EV_ABS, ABS_MT_SLOT, dev->slot);
210 } 210 }
211 211
@@ -391,6 +391,43 @@ void input_inject_event(struct input_handle *handle,
391EXPORT_SYMBOL(input_inject_event); 391EXPORT_SYMBOL(input_inject_event);
392 392
393/** 393/**
394 * input_alloc_absinfo - allocates array of input_absinfo structs
395 * @dev: the input device emitting absolute events
396 *
397 * If the absinfo struct the caller asked for is already allocated, this
398 * functions will not do anything.
399 */
400void input_alloc_absinfo(struct input_dev *dev)
401{
402 if (!dev->absinfo)
403 dev->absinfo = kcalloc(ABS_CNT, sizeof(struct input_absinfo),
404 GFP_KERNEL);
405
406 WARN(!dev->absinfo, "%s(): kcalloc() failed?\n", __func__);
407}
408EXPORT_SYMBOL(input_alloc_absinfo);
409
410void input_set_abs_params(struct input_dev *dev, unsigned int axis,
411 int min, int max, int fuzz, int flat)
412{
413 struct input_absinfo *absinfo;
414
415 input_alloc_absinfo(dev);
416 if (!dev->absinfo)
417 return;
418
419 absinfo = &dev->absinfo[axis];
420 absinfo->minimum = min;
421 absinfo->maximum = max;
422 absinfo->fuzz = fuzz;
423 absinfo->flat = flat;
424
425 dev->absbit[BIT_WORD(axis)] |= BIT_MASK(axis);
426}
427EXPORT_SYMBOL(input_set_abs_params);
428
429
430/**
394 * input_grab_device - grabs device for exclusive use 431 * input_grab_device - grabs device for exclusive use
395 * @handle: input handle that wants to own the device 432 * @handle: input handle that wants to own the device
396 * 433 *
@@ -1308,6 +1345,7 @@ static void input_dev_release(struct device *device)
1308 1345
1309 input_ff_destroy(dev); 1346 input_ff_destroy(dev);
1310 input_mt_destroy_slots(dev); 1347 input_mt_destroy_slots(dev);
1348 kfree(dev->absinfo);
1311 kfree(dev); 1349 kfree(dev);
1312 1350
1313 module_put(THIS_MODULE); 1351 module_put(THIS_MODULE);
diff --git a/drivers/input/joydev.c b/drivers/input/joydev.c
index 63834585c283..d85bd8a7967d 100644
--- a/drivers/input/joydev.c
+++ b/drivers/input/joydev.c
@@ -530,7 +530,7 @@ static int joydev_ioctl_common(struct joydev *joydev,
530{ 530{
531 struct input_dev *dev = joydev->handle.dev; 531 struct input_dev *dev = joydev->handle.dev;
532 size_t len; 532 size_t len;
533 int i, j; 533 int i;
534 const char *name; 534 const char *name;
535 535
536 /* Process fixed-sized commands. */ 536 /* Process fixed-sized commands. */
@@ -562,12 +562,11 @@ static int joydev_ioctl_common(struct joydev *joydev,
562 case JSIOCSCORR: 562 case JSIOCSCORR:
563 if (copy_from_user(joydev->corr, argp, 563 if (copy_from_user(joydev->corr, argp,
564 sizeof(joydev->corr[0]) * joydev->nabs)) 564 sizeof(joydev->corr[0]) * joydev->nabs))
565 return -EFAULT; 565 return -EFAULT;
566 566
567 for (i = 0; i < joydev->nabs; i++) { 567 for (i = 0; i < joydev->nabs; i++) {
568 j = joydev->abspam[i]; 568 int val = input_abs_get_val(dev, joydev->abspam[i]);
569 joydev->abs[i] = joydev_correct(dev->abs[j], 569 joydev->abs[i] = joydev_correct(val, &joydev->corr[i]);
570 &joydev->corr[i]);
571 } 570 }
572 return 0; 571 return 0;
573 572
@@ -848,25 +847,27 @@ static int joydev_connect(struct input_handler *handler, struct input_dev *dev,
848 847
849 for (i = 0; i < joydev->nabs; i++) { 848 for (i = 0; i < joydev->nabs; i++) {
850 j = joydev->abspam[i]; 849 j = joydev->abspam[i];
851 if (dev->absmax[j] == dev->absmin[j]) { 850 if (input_abs_get_max(dev, j) == input_abs_get_min(dev, j)) {
852 joydev->corr[i].type = JS_CORR_NONE; 851 joydev->corr[i].type = JS_CORR_NONE;
853 joydev->abs[i] = dev->abs[j]; 852 joydev->abs[i] = input_abs_get_val(dev, j);
854 continue; 853 continue;
855 } 854 }
856 joydev->corr[i].type = JS_CORR_BROKEN; 855 joydev->corr[i].type = JS_CORR_BROKEN;
857 joydev->corr[i].prec = dev->absfuzz[j]; 856 joydev->corr[i].prec = input_abs_get_fuzz(dev, j);
858 joydev->corr[i].coef[0] = 857
859 (dev->absmax[j] + dev->absmin[j]) / 2 - dev->absflat[j]; 858 t = (input_abs_get_max(dev, j) + input_abs_get_min(dev, j)) / 2;
860 joydev->corr[i].coef[1] = 859 joydev->corr[i].coef[0] = t - input_abs_get_flat(dev, j);
861 (dev->absmax[j] + dev->absmin[j]) / 2 + dev->absflat[j]; 860 joydev->corr[i].coef[1] = t + input_abs_get_flat(dev, j);
862 861
863 t = (dev->absmax[j] - dev->absmin[j]) / 2 - 2 * dev->absflat[j]; 862 t = (input_abs_get_max(dev, j) - input_abs_get_min(dev, j)) / 2
863 - 2 * input_abs_get_flat(dev, j);
864 if (t) { 864 if (t) {
865 joydev->corr[i].coef[2] = (1 << 29) / t; 865 joydev->corr[i].coef[2] = (1 << 29) / t;
866 joydev->corr[i].coef[3] = (1 << 29) / t; 866 joydev->corr[i].coef[3] = (1 << 29) / t;
867 867
868 joydev->abs[i] = joydev_correct(dev->abs[j], 868 joydev->abs[i] =
869 joydev->corr + i); 869 joydev_correct(input_abs_get_val(dev, j),
870 joydev->corr + i);
870 } 871 }
871 } 872 }
872 873
diff --git a/drivers/input/joystick/a3d.c b/drivers/input/joystick/a3d.c
index 6489f4010c4f..d259b41354b8 100644
--- a/drivers/input/joystick/a3d.c
+++ b/drivers/input/joystick/a3d.c
@@ -342,7 +342,8 @@ static int a3d_connect(struct gameport *gameport, struct gameport_driver *drv)
342 342
343 for (i = 0; i < 4; i++) { 343 for (i = 0; i < 4; i++) {
344 if (i < 2) 344 if (i < 2)
345 input_set_abs_params(input_dev, axes[i], 48, input_dev->abs[axes[i]] * 2 - 48, 0, 8); 345 input_set_abs_params(input_dev, axes[i],
346 48, input_abs_get_val(input_dev, axes[i]) * 2 - 48, 0, 8);
346 else 347 else
347 input_set_abs_params(input_dev, axes[i], 2, 253, 0, 0); 348 input_set_abs_params(input_dev, axes[i], 2, 253, 0, 0);
348 input_set_abs_params(input_dev, ABS_HAT0X + i, -1, 1, 0, 0); 349 input_set_abs_params(input_dev, ABS_HAT0X + i, -1, 1, 0, 0);
diff --git a/drivers/input/joystick/adi.c b/drivers/input/joystick/adi.c
index 89c4c084d4ad..b992fbf91f2f 100644
--- a/drivers/input/joystick/adi.c
+++ b/drivers/input/joystick/adi.c
@@ -452,7 +452,7 @@ static void adi_init_center(struct adi *adi)
452 for (i = 0; i < adi->axes10 + adi->axes8 + (adi->hats + (adi->pad != -1)) * 2; i++) { 452 for (i = 0; i < adi->axes10 + adi->axes8 + (adi->hats + (adi->pad != -1)) * 2; i++) {
453 453
454 t = adi->abs[i]; 454 t = adi->abs[i];
455 x = adi->dev->abs[t]; 455 x = input_abs_get_val(adi->dev, t);
456 456
457 if (t == ABS_THROTTLE || t == ABS_RUDDER || adi->id == ADI_ID_WGPE) 457 if (t == ABS_THROTTLE || t == ABS_RUDDER || adi->id == ADI_ID_WGPE)
458 x = i < adi->axes10 ? 512 : 128; 458 x = i < adi->axes10 ? 512 : 128;
diff --git a/drivers/input/joystick/amijoy.c b/drivers/input/joystick/amijoy.c
index 05022f07ec77..0bc86204213e 100644
--- a/drivers/input/joystick/amijoy.c
+++ b/drivers/input/joystick/amijoy.c
@@ -139,8 +139,8 @@ static int __init amijoy_init(void)
139 amijoy_dev[i]->keybit[BIT_WORD(BTN_LEFT)] = BIT_MASK(BTN_LEFT) | 139 amijoy_dev[i]->keybit[BIT_WORD(BTN_LEFT)] = BIT_MASK(BTN_LEFT) |
140 BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT); 140 BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT);
141 for (j = 0; j < 2; j++) { 141 for (j = 0; j < 2; j++) {
142 amijoy_dev[i]->absmin[ABS_X + j] = -1; 142 input_set_abs_params(amijoy_dev[i], ABS_X + j,
143 amijoy_dev[i]->absmax[ABS_X + j] = 1; 143 -1, 1, 0, 0);
144 } 144 }
145 145
146 err = input_register_device(amijoy_dev[i]); 146 err = input_register_device(amijoy_dev[i]);
diff --git a/drivers/input/joystick/gf2k.c b/drivers/input/joystick/gf2k.c
index 45ac70eae0aa..0536b1b2f018 100644
--- a/drivers/input/joystick/gf2k.c
+++ b/drivers/input/joystick/gf2k.c
@@ -318,11 +318,8 @@ static int gf2k_connect(struct gameport *gameport, struct gameport_driver *drv)
318 for (i = 0; i < gf2k_axes[gf2k->id]; i++) 318 for (i = 0; i < gf2k_axes[gf2k->id]; i++)
319 set_bit(gf2k_abs[i], input_dev->absbit); 319 set_bit(gf2k_abs[i], input_dev->absbit);
320 320
321 for (i = 0; i < gf2k_hats[gf2k->id]; i++) { 321 for (i = 0; i < gf2k_hats[gf2k->id]; i++)
322 set_bit(ABS_HAT0X + i, input_dev->absbit); 322 input_set_abs_params(input_dev, ABS_HAT0X + i, -1, 1, 0, 0);
323 input_dev->absmin[ABS_HAT0X + i] = -1;
324 input_dev->absmax[ABS_HAT0X + i] = 1;
325 }
326 323
327 for (i = 0; i < gf2k_joys[gf2k->id]; i++) 324 for (i = 0; i < gf2k_joys[gf2k->id]; i++)
328 set_bit(gf2k_btn_joy[i], input_dev->keybit); 325 set_bit(gf2k_btn_joy[i], input_dev->keybit);
@@ -334,11 +331,14 @@ static int gf2k_connect(struct gameport *gameport, struct gameport_driver *drv)
334 gf2k_read(gf2k, data); 331 gf2k_read(gf2k, data);
335 332
336 for (i = 0; i < gf2k_axes[gf2k->id]; i++) { 333 for (i = 0; i < gf2k_axes[gf2k->id]; i++) {
337 input_dev->absmax[gf2k_abs[i]] = (i < 2) ? input_dev->abs[gf2k_abs[i]] * 2 - 32 : 334 int max = i < 2 ?
338 input_dev->abs[gf2k_abs[0]] + input_dev->abs[gf2k_abs[1]] - 32; 335 input_abs_get_val(input_dev, gf2k_abs[i]) * 2 :
339 input_dev->absmin[gf2k_abs[i]] = 32; 336 input_abs_get_val(input_dev, gf2k_abs[0]) +
340 input_dev->absfuzz[gf2k_abs[i]] = 8; 337 input_abs_get_val(input_dev, gf2k_abs[1]);
341 input_dev->absflat[gf2k_abs[i]] = (i < 2) ? 24 : 0; 338 int flat = i < 2 ? 24 : 0;
339
340 input_set_abs_params(input_dev, gf2k_abs[i],
341 32, max - 32, 8, flat);
342 } 342 }
343 343
344 err = input_register_device(gf2k->dev); 344 err = input_register_device(gf2k->dev);
diff --git a/drivers/input/joystick/interact.c b/drivers/input/joystick/interact.c
index 2478289aeeea..16fb19d1ca25 100644
--- a/drivers/input/joystick/interact.c
+++ b/drivers/input/joystick/interact.c
@@ -270,18 +270,14 @@ static int interact_connect(struct gameport *gameport, struct gameport_driver *d
270 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); 270 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
271 271
272 for (i = 0; (t = interact_type[interact->type].abs[i]) >= 0; i++) { 272 for (i = 0; (t = interact_type[interact->type].abs[i]) >= 0; i++) {
273 set_bit(t, input_dev->absbit); 273 if (i < interact_type[interact->type].b8)
274 if (i < interact_type[interact->type].b8) { 274 input_set_abs_params(input_dev, t, 0, 255, 0, 0);
275 input_dev->absmin[t] = 0; 275 else
276 input_dev->absmax[t] = 255; 276 input_set_abs_params(input_dev, t, -1, 1, 0, 0);
277 } else {
278 input_dev->absmin[t] = -1;
279 input_dev->absmax[t] = 1;
280 }
281 } 277 }
282 278
283 for (i = 0; (t = interact_type[interact->type].btn[i]) >= 0; i++) 279 for (i = 0; (t = interact_type[interact->type].btn[i]) >= 0; i++)
284 set_bit(t, input_dev->keybit); 280 __set_bit(t, input_dev->keybit);
285 281
286 err = input_register_device(interact->dev); 282 err = input_register_device(interact->dev);
287 if (err) 283 if (err)
diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
index ca13a6bec33e..b8d86115644b 100644
--- a/drivers/input/joystick/sidewinder.c
+++ b/drivers/input/joystick/sidewinder.c
@@ -761,17 +761,21 @@ static int sw_connect(struct gameport *gameport, struct gameport_driver *drv)
761 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); 761 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
762 762
763 for (j = 0; (bits = sw_bit[sw->type][j]); j++) { 763 for (j = 0; (bits = sw_bit[sw->type][j]); j++) {
764 int min, max, fuzz, flat;
765
764 code = sw_abs[sw->type][j]; 766 code = sw_abs[sw->type][j];
765 set_bit(code, input_dev->absbit); 767 min = bits == 1 ? -1 : 0;
766 input_dev->absmax[code] = (1 << bits) - 1; 768 max = (1 << bits) - 1;
767 input_dev->absmin[code] = (bits == 1) ? -1 : 0; 769 fuzz = (bits >> 1) >= 2 ? 1 << ((bits >> 1) - 2) : 0;
768 input_dev->absfuzz[code] = ((bits >> 1) >= 2) ? (1 << ((bits >> 1) - 2)) : 0; 770 flat = code == ABS_THROTTLE || bits < 5 ?
769 if (code != ABS_THROTTLE) 771 0 : 1 << (bits - 5);
770 input_dev->absflat[code] = (bits >= 5) ? (1 << (bits - 5)) : 0; 772
773 input_set_abs_params(input_dev, code,
774 min, max, fuzz, flat);
771 } 775 }
772 776
773 for (j = 0; (code = sw_btn[sw->type][j]); j++) 777 for (j = 0; (code = sw_btn[sw->type][j]); j++)
774 set_bit(code, input_dev->keybit); 778 __set_bit(code, input_dev->keybit);
775 779
776 dbg("%s%s [%d-bit id %d data %d]\n", sw->name, comment, m, l, k); 780 dbg("%s%s [%d-bit id %d data %d]\n", sw->name, comment, m, l, k);
777 781
diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
index 269a846f3694..f9fb7fa10af3 100644
--- a/drivers/input/joystick/xpad.c
+++ b/drivers/input/joystick/xpad.c
@@ -148,6 +148,7 @@ static const struct xpad_device {
148 { 0x0e6f, 0x0005, "Eclipse wireless Controller", 0, XTYPE_XBOX }, 148 { 0x0e6f, 0x0005, "Eclipse wireless Controller", 0, XTYPE_XBOX },
149 { 0x0e6f, 0x0006, "Edge wireless Controller", 0, XTYPE_XBOX }, 149 { 0x0e6f, 0x0006, "Edge wireless Controller", 0, XTYPE_XBOX },
150 { 0x0e6f, 0x0006, "Pelican 'TSZ' Wired Xbox 360 Controller", 0, XTYPE_XBOX360 }, 150 { 0x0e6f, 0x0006, "Pelican 'TSZ' Wired Xbox 360 Controller", 0, XTYPE_XBOX360 },
151 { 0x0e6f, 0x0201, "Pelican PL-3601 'TSZ' Wired Xbox 360 Controller", 0, XTYPE_XBOX360 },
151 { 0x0e8f, 0x0201, "SmartJoy Frag Xpad/PS2 adaptor", 0, XTYPE_XBOX }, 152 { 0x0e8f, 0x0201, "SmartJoy Frag Xpad/PS2 adaptor", 0, XTYPE_XBOX },
152 { 0x0f30, 0x0202, "Joytech Advanced Controller", 0, XTYPE_XBOX }, 153 { 0x0f30, 0x0202, "Joytech Advanced Controller", 0, XTYPE_XBOX },
153 { 0x0f30, 0x8888, "BigBen XBMiniPad Controller", 0, XTYPE_XBOX }, 154 { 0x0f30, 0x8888, "BigBen XBMiniPad Controller", 0, XTYPE_XBOX },
diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
index b171f63fe4d7..9cc488d21490 100644
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -395,6 +395,16 @@ config KEYBOARD_SH_KEYSC
395 To compile this driver as a module, choose M here: the 395 To compile this driver as a module, choose M here: the
396 module will be called sh_keysc. 396 module will be called sh_keysc.
397 397
398config KEYBOARD_STMPE
399 tristate "STMPE keypad support"
400 depends on MFD_STMPE
401 help
402 Say Y here if you want to use the keypad controller on STMPE I/O
403 expanders.
404
405 To compile this driver as a module, choose M here: the module will be
406 called stmpe-keypad.
407
398config KEYBOARD_DAVINCI 408config KEYBOARD_DAVINCI
399 tristate "TI DaVinci Key Scan" 409 tristate "TI DaVinci Key Scan"
400 depends on ARCH_DAVINCI_DM365 410 depends on ARCH_DAVINCI_DM365
diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile
index 1a66d5f1ca8b..504b591be0cd 100644
--- a/drivers/input/keyboard/Makefile
+++ b/drivers/input/keyboard/Makefile
@@ -35,6 +35,7 @@ obj-$(CONFIG_KEYBOARD_PXA930_ROTARY) += pxa930_rotary.o
35obj-$(CONFIG_KEYBOARD_QT2160) += qt2160.o 35obj-$(CONFIG_KEYBOARD_QT2160) += qt2160.o
36obj-$(CONFIG_KEYBOARD_SAMSUNG) += samsung-keypad.o 36obj-$(CONFIG_KEYBOARD_SAMSUNG) += samsung-keypad.o
37obj-$(CONFIG_KEYBOARD_SH_KEYSC) += sh_keysc.o 37obj-$(CONFIG_KEYBOARD_SH_KEYSC) += sh_keysc.o
38obj-$(CONFIG_KEYBOARD_STMPE) += stmpe-keypad.o
38obj-$(CONFIG_KEYBOARD_STOWAWAY) += stowaway.o 39obj-$(CONFIG_KEYBOARD_STOWAWAY) += stowaway.o
39obj-$(CONFIG_KEYBOARD_SUNKBD) += sunkbd.o 40obj-$(CONFIG_KEYBOARD_SUNKBD) += sunkbd.o
40obj-$(CONFIG_KEYBOARD_TWL4030) += twl4030_keypad.o 41obj-$(CONFIG_KEYBOARD_TWL4030) += twl4030_keypad.o
diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
index a9fd147f2ba7..6069abe31e42 100644
--- a/drivers/input/keyboard/gpio_keys.c
+++ b/drivers/input/keyboard/gpio_keys.c
@@ -39,6 +39,8 @@ struct gpio_keys_drvdata {
39 struct input_dev *input; 39 struct input_dev *input;
40 struct mutex disable_lock; 40 struct mutex disable_lock;
41 unsigned int n_buttons; 41 unsigned int n_buttons;
42 int (*enable)(struct device *dev);
43 void (*disable)(struct device *dev);
42 struct gpio_button_data data[0]; 44 struct gpio_button_data data[0];
43}; 45};
44 46
@@ -423,6 +425,21 @@ fail2:
423 return error; 425 return error;
424} 426}
425 427
428static int gpio_keys_open(struct input_dev *input)
429{
430 struct gpio_keys_drvdata *ddata = input_get_drvdata(input);
431
432 return ddata->enable ? ddata->enable(input->dev.parent) : 0;
433}
434
435static void gpio_keys_close(struct input_dev *input)
436{
437 struct gpio_keys_drvdata *ddata = input_get_drvdata(input);
438
439 if (ddata->disable)
440 ddata->disable(input->dev.parent);
441}
442
426static int __devinit gpio_keys_probe(struct platform_device *pdev) 443static int __devinit gpio_keys_probe(struct platform_device *pdev)
427{ 444{
428 struct gpio_keys_platform_data *pdata = pdev->dev.platform_data; 445 struct gpio_keys_platform_data *pdata = pdev->dev.platform_data;
@@ -444,13 +461,18 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
444 461
445 ddata->input = input; 462 ddata->input = input;
446 ddata->n_buttons = pdata->nbuttons; 463 ddata->n_buttons = pdata->nbuttons;
464 ddata->enable = pdata->enable;
465 ddata->disable = pdata->disable;
447 mutex_init(&ddata->disable_lock); 466 mutex_init(&ddata->disable_lock);
448 467
449 platform_set_drvdata(pdev, ddata); 468 platform_set_drvdata(pdev, ddata);
469 input_set_drvdata(input, ddata);
450 470
451 input->name = pdev->name; 471 input->name = pdev->name;
452 input->phys = "gpio-keys/input0"; 472 input->phys = "gpio-keys/input0";
453 input->dev.parent = &pdev->dev; 473 input->dev.parent = &pdev->dev;
474 input->open = gpio_keys_open;
475 input->close = gpio_keys_close;
454 476
455 input->id.bustype = BUS_HOST; 477 input->id.bustype = BUS_HOST;
456 input->id.vendor = 0x0001; 478 input->id.vendor = 0x0001;
diff --git a/drivers/input/keyboard/hil_kbd.c b/drivers/input/keyboard/hil_kbd.c
index c83f4b2ec7d3..dcc86b97a153 100644
--- a/drivers/input/keyboard/hil_kbd.c
+++ b/drivers/input/keyboard/hil_kbd.c
@@ -232,15 +232,16 @@ static void hil_dev_handle_ptr_events(struct hil_dev *ptr)
232 if (absdev) { 232 if (absdev) {
233 val = lo + (hi << 8); 233 val = lo + (hi << 8);
234#ifdef TABLET_AUTOADJUST 234#ifdef TABLET_AUTOADJUST
235 if (val < dev->absmin[ABS_X + i]) 235 if (val < input_abs_min(dev, ABS_X + i))
236 dev->absmin[ABS_X + i] = val; 236 input_abs_set_min(dev, ABS_X + i, val);
237 if (val > dev->absmax[ABS_X + i]) 237 if (val > input_abs_max(dev, ABS_X + i))
238 dev->absmax[ABS_X + i] = val; 238 input_abs_set_max(dev, ABS_X + i, val);
239#endif 239#endif
240 if (i%3) val = dev->absmax[ABS_X + i] - val; 240 if (i % 3)
241 val = input_abs_max(dev, ABS_X + i) - val;
241 input_report_abs(dev, ABS_X + i, val); 242 input_report_abs(dev, ABS_X + i, val);
242 } else { 243 } else {
243 val = (int) (((int8_t)lo) | ((int8_t)hi << 8)); 244 val = (int) (((int8_t) lo) | ((int8_t) hi << 8));
244 if (i % 3) 245 if (i % 3)
245 val *= -1; 246 val *= -1;
246 input_report_rel(dev, REL_X + i, val); 247 input_report_rel(dev, REL_X + i, val);
@@ -387,9 +388,11 @@ static void hil_dev_pointer_setup(struct hil_dev *ptr)
387 388
388#ifdef TABLET_AUTOADJUST 389#ifdef TABLET_AUTOADJUST
389 for (i = 0; i < ABS_MAX; i++) { 390 for (i = 0; i < ABS_MAX; i++) {
390 int diff = input_dev->absmax[ABS_X + i] / 10; 391 int diff = input_abs_max(input_dev, ABS_X + i) / 10;
391 input_dev->absmin[ABS_X + i] += diff; 392 input_abs_set_min(input_dev, ABS_X + i,
392 input_dev->absmax[ABS_X + i] -= diff; 393 input_abs_min(input_dev, ABS_X + i) + diff)
394 input_abs_set_max(input_dev, ABS_X + i,
395 input_abs_max(input_dev, ABS_X + i) - diff)
393 } 396 }
394#endif 397#endif
395 398
diff --git a/drivers/input/keyboard/stmpe-keypad.c b/drivers/input/keyboard/stmpe-keypad.c
new file mode 100644
index 000000000000..ab7610ca10eb
--- /dev/null
+++ b/drivers/input/keyboard/stmpe-keypad.c
@@ -0,0 +1,386 @@
1/*
2 * Copyright (C) ST-Ericsson SA 2010
3 *
4 * License Terms: GNU General Public License, version 2
5 * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
6 */
7
8#include <linux/module.h>
9#include <linux/init.h>
10#include <linux/slab.h>
11#include <linux/input.h>
12#include <linux/interrupt.h>
13#include <linux/platform_device.h>
14#include <linux/input/matrix_keypad.h>
15#include <linux/mfd/stmpe.h>
16
17/* These are at the same addresses in all STMPE variants */
18#define STMPE_KPC_COL 0x60
19#define STMPE_KPC_ROW_MSB 0x61
20#define STMPE_KPC_ROW_LSB 0x62
21#define STMPE_KPC_CTRL_MSB 0x63
22#define STMPE_KPC_CTRL_LSB 0x64
23#define STMPE_KPC_COMBI_KEY_0 0x65
24#define STMPE_KPC_COMBI_KEY_1 0x66
25#define STMPE_KPC_COMBI_KEY_2 0x67
26#define STMPE_KPC_DATA_BYTE0 0x68
27#define STMPE_KPC_DATA_BYTE1 0x69
28#define STMPE_KPC_DATA_BYTE2 0x6a
29#define STMPE_KPC_DATA_BYTE3 0x6b
30#define STMPE_KPC_DATA_BYTE4 0x6c
31
32#define STMPE_KPC_CTRL_LSB_SCAN (0x1 << 0)
33#define STMPE_KPC_CTRL_LSB_DEBOUNCE (0x7f << 1)
34#define STMPE_KPC_CTRL_MSB_SCAN_COUNT (0xf << 4)
35
36#define STMPE_KPC_ROW_MSB_ROWS 0xff
37
38#define STMPE_KPC_DATA_UP (0x1 << 7)
39#define STMPE_KPC_DATA_ROW (0xf << 3)
40#define STMPE_KPC_DATA_COL (0x7 << 0)
41#define STMPE_KPC_DATA_NOKEY_MASK 0x78
42
43#define STMPE_KEYPAD_MAX_DEBOUNCE 127
44#define STMPE_KEYPAD_MAX_SCAN_COUNT 15
45
46#define STMPE_KEYPAD_MAX_ROWS 8
47#define STMPE_KEYPAD_MAX_COLS 8
48#define STMPE_KEYPAD_ROW_SHIFT 3
49#define STMPE_KEYPAD_KEYMAP_SIZE \
50 (STMPE_KEYPAD_MAX_ROWS * STMPE_KEYPAD_MAX_COLS)
51
52/**
53 * struct stmpe_keypad_variant - model-specific attributes
54 * @auto_increment: whether the KPC_DATA_BYTE register address
55 * auto-increments on multiple read
56 * @num_data: number of data bytes
57 * @num_normal_data: number of normal keys' data bytes
58 * @max_cols: maximum number of columns supported
59 * @max_rows: maximum number of rows supported
60 * @col_gpios: bitmask of gpios which can be used for columns
61 * @row_gpios: bitmask of gpios which can be used for rows
62 */
63struct stmpe_keypad_variant {
64 bool auto_increment;
65 int num_data;
66 int num_normal_data;
67 int max_cols;
68 int max_rows;
69 unsigned int col_gpios;
70 unsigned int row_gpios;
71};
72
73static const struct stmpe_keypad_variant stmpe_keypad_variants[] = {
74 [STMPE1601] = {
75 .auto_increment = true,
76 .num_data = 5,
77 .num_normal_data = 3,
78 .max_cols = 8,
79 .max_rows = 8,
80 .col_gpios = 0x000ff, /* GPIO 0 - 7 */
81 .row_gpios = 0x0ff00, /* GPIO 8 - 15 */
82 },
83 [STMPE2401] = {
84 .auto_increment = false,
85 .num_data = 3,
86 .num_normal_data = 2,
87 .max_cols = 8,
88 .max_rows = 12,
89 .col_gpios = 0x0000ff, /* GPIO 0 - 7*/
90 .row_gpios = 0x1fef00, /* GPIO 8-14, 16-20 */
91 },
92 [STMPE2403] = {
93 .auto_increment = true,
94 .num_data = 5,
95 .num_normal_data = 3,
96 .max_cols = 8,
97 .max_rows = 12,
98 .col_gpios = 0x0000ff, /* GPIO 0 - 7*/
99 .row_gpios = 0x1fef00, /* GPIO 8-14, 16-20 */
100 },
101};
102
103struct stmpe_keypad {
104 struct stmpe *stmpe;
105 struct input_dev *input;
106 const struct stmpe_keypad_variant *variant;
107 const struct stmpe_keypad_platform_data *plat;
108
109 unsigned int rows;
110 unsigned int cols;
111
112 unsigned short keymap[STMPE_KEYPAD_KEYMAP_SIZE];
113};
114
115static int stmpe_keypad_read_data(struct stmpe_keypad *keypad, u8 *data)
116{
117 const struct stmpe_keypad_variant *variant = keypad->variant;
118 struct stmpe *stmpe = keypad->stmpe;
119 int ret;
120 int i;
121
122 if (variant->auto_increment)
123 return stmpe_block_read(stmpe, STMPE_KPC_DATA_BYTE0,
124 variant->num_data, data);
125
126 for (i = 0; i < variant->num_data; i++) {
127 ret = stmpe_reg_read(stmpe, STMPE_KPC_DATA_BYTE0 + i);
128 if (ret < 0)
129 return ret;
130
131 data[i] = ret;
132 }
133
134 return 0;
135}
136
137static irqreturn_t stmpe_keypad_irq(int irq, void *dev)
138{
139 struct stmpe_keypad *keypad = dev;
140 struct input_dev *input = keypad->input;
141 const struct stmpe_keypad_variant *variant = keypad->variant;
142 u8 fifo[variant->num_data];
143 int ret;
144 int i;
145
146 ret = stmpe_keypad_read_data(keypad, fifo);
147 if (ret < 0)
148 return IRQ_NONE;
149
150 for (i = 0; i < variant->num_normal_data; i++) {
151 u8 data = fifo[i];
152 int row = (data & STMPE_KPC_DATA_ROW) >> 3;
153 int col = data & STMPE_KPC_DATA_COL;
154 int code = MATRIX_SCAN_CODE(row, col, STMPE_KEYPAD_ROW_SHIFT);
155 bool up = data & STMPE_KPC_DATA_UP;
156
157 if ((data & STMPE_KPC_DATA_NOKEY_MASK)
158 == STMPE_KPC_DATA_NOKEY_MASK)
159 continue;
160
161 input_event(input, EV_MSC, MSC_SCAN, code);
162 input_report_key(input, keypad->keymap[code], !up);
163 input_sync(input);
164 }
165
166 return IRQ_HANDLED;
167}
168
169static int __devinit stmpe_keypad_altfunc_init(struct stmpe_keypad *keypad)
170{
171 const struct stmpe_keypad_variant *variant = keypad->variant;
172 unsigned int col_gpios = variant->col_gpios;
173 unsigned int row_gpios = variant->row_gpios;
174 struct stmpe *stmpe = keypad->stmpe;
175 unsigned int pins = 0;
176 int i;
177
178 /*
179 * Figure out which pins need to be set to the keypad alternate
180 * function.
181 *
182 * {cols,rows}_gpios are bitmasks of which pins on the chip can be used
183 * for the keypad.
184 *
185 * keypad->{cols,rows} are a bitmask of which pins (of the ones useable
186 * for the keypad) are used on the board.
187 */
188
189 for (i = 0; i < variant->max_cols; i++) {
190 int num = __ffs(col_gpios);
191
192 if (keypad->cols & (1 << i))
193 pins |= 1 << num;
194
195 col_gpios &= ~(1 << num);
196 }
197
198 for (i = 0; i < variant->max_rows; i++) {
199 int num = __ffs(row_gpios);
200
201 if (keypad->rows & (1 << i))
202 pins |= 1 << num;
203
204 row_gpios &= ~(1 << num);
205 }
206
207 return stmpe_set_altfunc(stmpe, pins, STMPE_BLOCK_KEYPAD);
208}
209
210static int __devinit stmpe_keypad_chip_init(struct stmpe_keypad *keypad)
211{
212 const struct stmpe_keypad_platform_data *plat = keypad->plat;
213 const struct stmpe_keypad_variant *variant = keypad->variant;
214 struct stmpe *stmpe = keypad->stmpe;
215 int ret;
216
217 if (plat->debounce_ms > STMPE_KEYPAD_MAX_DEBOUNCE)
218 return -EINVAL;
219
220 if (plat->scan_count > STMPE_KEYPAD_MAX_SCAN_COUNT)
221 return -EINVAL;
222
223 ret = stmpe_enable(stmpe, STMPE_BLOCK_KEYPAD);
224 if (ret < 0)
225 return ret;
226
227 ret = stmpe_keypad_altfunc_init(keypad);
228 if (ret < 0)
229 return ret;
230
231 ret = stmpe_reg_write(stmpe, STMPE_KPC_COL, keypad->cols);
232 if (ret < 0)
233 return ret;
234
235 ret = stmpe_reg_write(stmpe, STMPE_KPC_ROW_LSB, keypad->rows);
236 if (ret < 0)
237 return ret;
238
239 if (variant->max_rows > 8) {
240 ret = stmpe_set_bits(stmpe, STMPE_KPC_ROW_MSB,
241 STMPE_KPC_ROW_MSB_ROWS,
242 keypad->rows >> 8);
243 if (ret < 0)
244 return ret;
245 }
246
247 ret = stmpe_set_bits(stmpe, STMPE_KPC_CTRL_MSB,
248 STMPE_KPC_CTRL_MSB_SCAN_COUNT,
249 plat->scan_count << 4);
250 if (ret < 0)
251 return ret;
252
253 return stmpe_set_bits(stmpe, STMPE_KPC_CTRL_LSB,
254 STMPE_KPC_CTRL_LSB_SCAN |
255 STMPE_KPC_CTRL_LSB_DEBOUNCE,
256 STMPE_KPC_CTRL_LSB_SCAN |
257 (plat->debounce_ms << 1));
258}
259
260static int __devinit stmpe_keypad_probe(struct platform_device *pdev)
261{
262 struct stmpe *stmpe = dev_get_drvdata(pdev->dev.parent);
263 struct stmpe_keypad_platform_data *plat;
264 struct stmpe_keypad *keypad;
265 struct input_dev *input;
266 int ret;
267 int irq;
268 int i;
269
270 plat = stmpe->pdata->keypad;
271 if (!plat)
272 return -ENODEV;
273
274 irq = platform_get_irq(pdev, 0);
275 if (irq < 0)
276 return irq;
277
278 keypad = kzalloc(sizeof(struct stmpe_keypad), GFP_KERNEL);
279 if (!keypad)
280 return -ENOMEM;
281
282 input = input_allocate_device();
283 if (!input) {
284 ret = -ENOMEM;
285 goto out_freekeypad;
286 }
287
288 input->name = "STMPE keypad";
289 input->id.bustype = BUS_I2C;
290 input->dev.parent = &pdev->dev;
291
292 input_set_capability(input, EV_MSC, MSC_SCAN);
293
294 __set_bit(EV_KEY, input->evbit);
295 if (!plat->no_autorepeat)
296 __set_bit(EV_REP, input->evbit);
297
298 input->keycode = keypad->keymap;
299 input->keycodesize = sizeof(keypad->keymap[0]);
300 input->keycodemax = ARRAY_SIZE(keypad->keymap);
301
302 matrix_keypad_build_keymap(plat->keymap_data, STMPE_KEYPAD_ROW_SHIFT,
303 input->keycode, input->keybit);
304
305 for (i = 0; i < plat->keymap_data->keymap_size; i++) {
306 unsigned int key = plat->keymap_data->keymap[i];
307
308 keypad->cols |= 1 << KEY_COL(key);
309 keypad->rows |= 1 << KEY_ROW(key);
310 }
311
312 keypad->stmpe = stmpe;
313 keypad->plat = plat;
314 keypad->input = input;
315 keypad->variant = &stmpe_keypad_variants[stmpe->partnum];
316
317 ret = stmpe_keypad_chip_init(keypad);
318 if (ret < 0)
319 goto out_freeinput;
320
321 ret = input_register_device(input);
322 if (ret) {
323 dev_err(&pdev->dev,
324 "unable to register input device: %d\n", ret);
325 goto out_freeinput;
326 }
327
328 ret = request_threaded_irq(irq, NULL, stmpe_keypad_irq, IRQF_ONESHOT,
329 "stmpe-keypad", keypad);
330 if (ret) {
331 dev_err(&pdev->dev, "unable to get irq: %d\n", ret);
332 goto out_unregisterinput;
333 }
334
335 platform_set_drvdata(pdev, keypad);
336
337 return 0;
338
339out_unregisterinput:
340 input_unregister_device(input);
341 input = NULL;
342out_freeinput:
343 input_free_device(input);
344out_freekeypad:
345 kfree(keypad);
346 return ret;
347}
348
349static int __devexit stmpe_keypad_remove(struct platform_device *pdev)
350{
351 struct stmpe_keypad *keypad = platform_get_drvdata(pdev);
352 struct stmpe *stmpe = keypad->stmpe;
353 int irq = platform_get_irq(pdev, 0);
354
355 stmpe_disable(stmpe, STMPE_BLOCK_KEYPAD);
356
357 free_irq(irq, keypad);
358 input_unregister_device(keypad->input);
359 platform_set_drvdata(pdev, NULL);
360 kfree(keypad);
361
362 return 0;
363}
364
365static struct platform_driver stmpe_keypad_driver = {
366 .driver.name = "stmpe-keypad",
367 .driver.owner = THIS_MODULE,
368 .probe = stmpe_keypad_probe,
369 .remove = __devexit_p(stmpe_keypad_remove),
370};
371
372static int __init stmpe_keypad_init(void)
373{
374 return platform_driver_register(&stmpe_keypad_driver);
375}
376module_init(stmpe_keypad_init);
377
378static void __exit stmpe_keypad_exit(void)
379{
380 platform_driver_unregister(&stmpe_keypad_driver);
381}
382module_exit(stmpe_keypad_exit);
383
384MODULE_LICENSE("GPL v2");
385MODULE_DESCRIPTION("STMPExxxx keypad driver");
386MODULE_AUTHOR("Rabin Vincent <rabin.vincent@stericsson.com>");
diff --git a/drivers/input/misc/adxl34x.c b/drivers/input/misc/adxl34x.c
index e2ca01708080..de5900d50788 100644
--- a/drivers/input/misc/adxl34x.c
+++ b/drivers/input/misc/adxl34x.c
@@ -724,7 +724,6 @@ struct adxl34x *adxl34x_probe(struct device *dev, int irq,
724 pdata = &ac->pdata; 724 pdata = &ac->pdata;
725 725
726 ac->input = input_dev; 726 ac->input = input_dev;
727 ac->disabled = true;
728 ac->dev = dev; 727 ac->dev = dev;
729 ac->irq = irq; 728 ac->irq = irq;
730 ac->bops = bops; 729 ac->bops = bops;
diff --git a/drivers/input/misc/ati_remote2.c b/drivers/input/misc/ati_remote2.c
index e148749b5851..23257652b8e8 100644
--- a/drivers/input/misc/ati_remote2.c
+++ b/drivers/input/misc/ati_remote2.c
@@ -38,7 +38,8 @@ enum {
38}; 38};
39 39
40static int ati_remote2_set_mask(const char *val, 40static int ati_remote2_set_mask(const char *val,
41 struct kernel_param *kp, unsigned int max) 41 const struct kernel_param *kp,
42 unsigned int max)
42{ 43{
43 unsigned long mask; 44 unsigned long mask;
44 int ret; 45 int ret;
@@ -59,28 +60,31 @@ static int ati_remote2_set_mask(const char *val,
59} 60}
60 61
61static int ati_remote2_set_channel_mask(const char *val, 62static int ati_remote2_set_channel_mask(const char *val,
62 struct kernel_param *kp) 63 const struct kernel_param *kp)
63{ 64{
64 pr_debug("%s()\n", __func__); 65 pr_debug("%s()\n", __func__);
65 66
66 return ati_remote2_set_mask(val, kp, ATI_REMOTE2_MAX_CHANNEL_MASK); 67 return ati_remote2_set_mask(val, kp, ATI_REMOTE2_MAX_CHANNEL_MASK);
67} 68}
68 69
69static int ati_remote2_get_channel_mask(char *buffer, struct kernel_param *kp) 70static int ati_remote2_get_channel_mask(char *buffer,
71 const struct kernel_param *kp)
70{ 72{
71 pr_debug("%s()\n", __func__); 73 pr_debug("%s()\n", __func__);
72 74
73 return sprintf(buffer, "0x%04x", *(unsigned int *)kp->arg); 75 return sprintf(buffer, "0x%04x", *(unsigned int *)kp->arg);
74} 76}
75 77
76static int ati_remote2_set_mode_mask(const char *val, struct kernel_param *kp) 78static int ati_remote2_set_mode_mask(const char *val,
79 const struct kernel_param *kp)
77{ 80{
78 pr_debug("%s()\n", __func__); 81 pr_debug("%s()\n", __func__);
79 82
80 return ati_remote2_set_mask(val, kp, ATI_REMOTE2_MAX_MODE_MASK); 83 return ati_remote2_set_mask(val, kp, ATI_REMOTE2_MAX_MODE_MASK);
81} 84}
82 85
83static int ati_remote2_get_mode_mask(char *buffer, struct kernel_param *kp) 86static int ati_remote2_get_mode_mask(char *buffer,
87 const struct kernel_param *kp)
84{ 88{
85 pr_debug("%s()\n", __func__); 89 pr_debug("%s()\n", __func__);
86 90
@@ -89,15 +93,19 @@ static int ati_remote2_get_mode_mask(char *buffer, struct kernel_param *kp)
89 93
90static unsigned int channel_mask = ATI_REMOTE2_MAX_CHANNEL_MASK; 94static unsigned int channel_mask = ATI_REMOTE2_MAX_CHANNEL_MASK;
91#define param_check_channel_mask(name, p) __param_check(name, p, unsigned int) 95#define param_check_channel_mask(name, p) __param_check(name, p, unsigned int)
92#define param_set_channel_mask ati_remote2_set_channel_mask 96static struct kernel_param_ops param_ops_channel_mask = {
93#define param_get_channel_mask ati_remote2_get_channel_mask 97 .set = ati_remote2_set_channel_mask,
98 .get = ati_remote2_get_channel_mask,
99};
94module_param(channel_mask, channel_mask, 0644); 100module_param(channel_mask, channel_mask, 0644);
95MODULE_PARM_DESC(channel_mask, "Bitmask of channels to accept <15:Channel16>...<1:Channel2><0:Channel1>"); 101MODULE_PARM_DESC(channel_mask, "Bitmask of channels to accept <15:Channel16>...<1:Channel2><0:Channel1>");
96 102
97static unsigned int mode_mask = ATI_REMOTE2_MAX_MODE_MASK; 103static unsigned int mode_mask = ATI_REMOTE2_MAX_MODE_MASK;
98#define param_check_mode_mask(name, p) __param_check(name, p, unsigned int) 104#define param_check_mode_mask(name, p) __param_check(name, p, unsigned int)
99#define param_set_mode_mask ati_remote2_set_mode_mask 105static struct kernel_param_ops param_ops_mode_mask = {
100#define param_get_mode_mask ati_remote2_get_mode_mask 106 .set = ati_remote2_set_mode_mask,
107 .get = ati_remote2_get_mode_mask,
108};
101module_param(mode_mask, mode_mask, 0644); 109module_param(mode_mask, mode_mask, 0644);
102MODULE_PARM_DESC(mode_mask, "Bitmask of modes to accept <4:PC><3:AUX4><2:AUX3><1:AUX2><0:AUX1>"); 110MODULE_PARM_DESC(mode_mask, "Bitmask of modes to accept <4:PC><3:AUX4><2:AUX3><1:AUX2><0:AUX1>");
103 111
diff --git a/drivers/input/misc/sparcspkr.c b/drivers/input/misc/sparcspkr.c
index f3bb92e9755f..8e130bf7d32b 100644
--- a/drivers/input/misc/sparcspkr.c
+++ b/drivers/input/misc/sparcspkr.c
@@ -173,7 +173,7 @@ static int __devinit sparcspkr_probe(struct device *dev)
173 return 0; 173 return 0;
174} 174}
175 175
176static int sparcspkr_shutdown(struct of_device *dev) 176static int sparcspkr_shutdown(struct platform_device *dev)
177{ 177{
178 struct sparcspkr_state *state = dev_get_drvdata(&dev->dev); 178 struct sparcspkr_state *state = dev_get_drvdata(&dev->dev);
179 struct input_dev *input_dev = state->input_dev; 179 struct input_dev *input_dev = state->input_dev;
@@ -184,7 +184,7 @@ static int sparcspkr_shutdown(struct of_device *dev)
184 return 0; 184 return 0;
185} 185}
186 186
187static int __devinit bbc_beep_probe(struct of_device *op, const struct of_device_id *match) 187static int __devinit bbc_beep_probe(struct platform_device *op, const struct of_device_id *match)
188{ 188{
189 struct sparcspkr_state *state; 189 struct sparcspkr_state *state;
190 struct bbc_beep_info *info; 190 struct bbc_beep_info *info;
@@ -231,7 +231,7 @@ out_err:
231 return err; 231 return err;
232} 232}
233 233
234static int __devexit bbc_remove(struct of_device *op) 234static int __devexit bbc_remove(struct platform_device *op)
235{ 235{
236 struct sparcspkr_state *state = dev_get_drvdata(&op->dev); 236 struct sparcspkr_state *state = dev_get_drvdata(&op->dev);
237 struct input_dev *input_dev = state->input_dev; 237 struct input_dev *input_dev = state->input_dev;
@@ -269,7 +269,7 @@ static struct of_platform_driver bbc_beep_driver = {
269 .shutdown = sparcspkr_shutdown, 269 .shutdown = sparcspkr_shutdown,
270}; 270};
271 271
272static int __devinit grover_beep_probe(struct of_device *op, const struct of_device_id *match) 272static int __devinit grover_beep_probe(struct platform_device *op, const struct of_device_id *match)
273{ 273{
274 struct sparcspkr_state *state; 274 struct sparcspkr_state *state;
275 struct grover_beep_info *info; 275 struct grover_beep_info *info;
@@ -312,7 +312,7 @@ out_err:
312 return err; 312 return err;
313} 313}
314 314
315static int __devexit grover_remove(struct of_device *op) 315static int __devexit grover_remove(struct platform_device *op)
316{ 316{
317 struct sparcspkr_state *state = dev_get_drvdata(&op->dev); 317 struct sparcspkr_state *state = dev_get_drvdata(&op->dev);
318 struct grover_beep_info *info = &state->u.grover; 318 struct grover_beep_info *info = &state->u.grover;
diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c
index b71eb55f2dbc..bb53fd33cd1c 100644
--- a/drivers/input/misc/uinput.c
+++ b/drivers/input/misc/uinput.c
@@ -304,21 +304,25 @@ static int uinput_validate_absbits(struct input_dev *dev)
304 if (!test_bit(cnt, dev->absbit)) 304 if (!test_bit(cnt, dev->absbit))
305 continue; 305 continue;
306 306
307 if ((dev->absmax[cnt] <= dev->absmin[cnt])) { 307 if (input_abs_get_max(dev, cnt) <= input_abs_get_min(dev, cnt)) {
308 printk(KERN_DEBUG 308 printk(KERN_DEBUG
309 "%s: invalid abs[%02x] min:%d max:%d\n", 309 "%s: invalid abs[%02x] min:%d max:%d\n",
310 UINPUT_NAME, cnt, 310 UINPUT_NAME, cnt,
311 dev->absmin[cnt], dev->absmax[cnt]); 311 input_abs_get_min(dev, cnt),
312 input_abs_get_max(dev, cnt));
312 retval = -EINVAL; 313 retval = -EINVAL;
313 break; 314 break;
314 } 315 }
315 316
316 if (dev->absflat[cnt] > (dev->absmax[cnt] - dev->absmin[cnt])) { 317 if (input_abs_get_flat(dev, cnt) >
318 input_abs_get_max(dev, cnt) - input_abs_get_min(dev, cnt)) {
317 printk(KERN_DEBUG 319 printk(KERN_DEBUG
318 "%s: absflat[%02x] out of range: %d " 320 "%s: abs_flat #%02x out of range: %d "
319 "(min:%d/max:%d)\n", 321 "(min:%d/max:%d)\n",
320 UINPUT_NAME, cnt, dev->absflat[cnt], 322 UINPUT_NAME, cnt,
321 dev->absmin[cnt], dev->absmax[cnt]); 323 input_abs_get_flat(dev, cnt),
324 input_abs_get_min(dev, cnt),
325 input_abs_get_max(dev, cnt));
322 retval = -EINVAL; 326 retval = -EINVAL;
323 break; 327 break;
324 } 328 }
@@ -343,7 +347,7 @@ static int uinput_setup_device(struct uinput_device *udev, const char __user *bu
343 struct uinput_user_dev *user_dev; 347 struct uinput_user_dev *user_dev;
344 struct input_dev *dev; 348 struct input_dev *dev;
345 char *name; 349 char *name;
346 int size; 350 int i, size;
347 int retval; 351 int retval;
348 352
349 if (count != sizeof(struct uinput_user_dev)) 353 if (count != sizeof(struct uinput_user_dev))
@@ -387,11 +391,12 @@ static int uinput_setup_device(struct uinput_device *udev, const char __user *bu
387 dev->id.product = user_dev->id.product; 391 dev->id.product = user_dev->id.product;
388 dev->id.version = user_dev->id.version; 392 dev->id.version = user_dev->id.version;
389 393
390 size = sizeof(int) * ABS_CNT; 394 for (i = 0; i < ABS_CNT; i++) {
391 memcpy(dev->absmax, user_dev->absmax, size); 395 input_abs_set_max(dev, i, user_dev->absmax[i]);
392 memcpy(dev->absmin, user_dev->absmin, size); 396 input_abs_set_min(dev, i, user_dev->absmin[i]);
393 memcpy(dev->absfuzz, user_dev->absfuzz, size); 397 input_abs_set_fuzz(dev, i, user_dev->absfuzz[i]);
394 memcpy(dev->absflat, user_dev->absflat, size); 398 input_abs_set_flat(dev, i, user_dev->absflat[i]);
399 }
395 400
396 /* check if absmin/absmax/absfuzz/absflat are filled as 401 /* check if absmin/absmax/absfuzz/absflat are filled as
397 * told in Documentation/input/input-programming.txt */ 402 * told in Documentation/input/input-programming.txt */
diff --git a/drivers/input/mouse/appletouch.c b/drivers/input/mouse/appletouch.c
index 05edd75abca0..a9cf76831634 100644
--- a/drivers/input/mouse/appletouch.c
+++ b/drivers/input/mouse/appletouch.c
@@ -205,8 +205,8 @@ struct atp {
205 bool overflow_warned; 205 bool overflow_warned;
206 int x_old; /* last reported x/y, */ 206 int x_old; /* last reported x/y, */
207 int y_old; /* used for smoothing */ 207 int y_old; /* used for smoothing */
208 u8 xy_cur[ATP_XSENSORS + ATP_YSENSORS]; 208 signed char xy_cur[ATP_XSENSORS + ATP_YSENSORS];
209 u8 xy_old[ATP_XSENSORS + ATP_YSENSORS]; 209 signed char xy_old[ATP_XSENSORS + ATP_YSENSORS];
210 int xy_acc[ATP_XSENSORS + ATP_YSENSORS]; 210 int xy_acc[ATP_XSENSORS + ATP_YSENSORS];
211 int idlecount; /* number of empty packets */ 211 int idlecount; /* number of empty packets */
212 struct work_struct work; 212 struct work_struct work;
@@ -531,7 +531,7 @@ static void atp_complete_geyser_1_2(struct urb *urb)
531 531
532 for (i = 0; i < ATP_XSENSORS + ATP_YSENSORS; i++) { 532 for (i = 0; i < ATP_XSENSORS + ATP_YSENSORS; i++) {
533 /* accumulate the change */ 533 /* accumulate the change */
534 int change = dev->xy_old[i] - dev->xy_cur[i]; 534 signed char change = dev->xy_old[i] - dev->xy_cur[i];
535 dev->xy_acc[i] -= change; 535 dev->xy_acc[i] -= change;
536 536
537 /* prevent down drifting */ 537 /* prevent down drifting */
diff --git a/drivers/input/mouse/elantech.c b/drivers/input/mouse/elantech.c
index b18862b2a70e..48311204ba51 100644
--- a/drivers/input/mouse/elantech.c
+++ b/drivers/input/mouse/elantech.c
@@ -185,7 +185,6 @@ static void elantech_report_absolute_v1(struct psmouse *psmouse)
185 struct elantech_data *etd = psmouse->private; 185 struct elantech_data *etd = psmouse->private;
186 unsigned char *packet = psmouse->packet; 186 unsigned char *packet = psmouse->packet;
187 int fingers; 187 int fingers;
188 static int old_fingers;
189 188
190 if (etd->fw_version < 0x020000) { 189 if (etd->fw_version < 0x020000) {
191 /* 190 /*
@@ -203,10 +202,13 @@ static void elantech_report_absolute_v1(struct psmouse *psmouse)
203 } 202 }
204 203
205 if (etd->jumpy_cursor) { 204 if (etd->jumpy_cursor) {
206 /* Discard packets that are likely to have bogus coordinates */ 205 if (fingers != 1) {
207 if (fingers > old_fingers) { 206 etd->single_finger_reports = 0;
207 } else if (etd->single_finger_reports < 2) {
208 /* Discard first 2 reports of one finger, bogus */
209 etd->single_finger_reports++;
208 elantech_debug("discarding packet\n"); 210 elantech_debug("discarding packet\n");
209 goto discard_packet_v1; 211 return;
210 } 212 }
211 } 213 }
212 214
@@ -238,9 +240,6 @@ static void elantech_report_absolute_v1(struct psmouse *psmouse)
238 } 240 }
239 241
240 input_sync(dev); 242 input_sync(dev);
241
242 discard_packet_v1:
243 old_fingers = fingers;
244} 243}
245 244
246/* 245/*
@@ -258,6 +257,14 @@ static void elantech_report_absolute_v2(struct psmouse *psmouse)
258 input_report_key(dev, BTN_TOUCH, fingers != 0); 257 input_report_key(dev, BTN_TOUCH, fingers != 0);
259 258
260 switch (fingers) { 259 switch (fingers) {
260 case 3:
261 /*
262 * Same as one finger, except report of more than 3 fingers:
263 * byte 3: n4 . w1 w0 . . . .
264 */
265 if (packet[3] & 0x80)
266 fingers = 4;
267 /* pass through... */
261 case 1: 268 case 1:
262 /* 269 /*
263 * byte 1: . . . . . x10 x9 x8 270 * byte 1: . . . . . x10 x9 x8
@@ -310,6 +317,7 @@ static void elantech_report_absolute_v2(struct psmouse *psmouse)
310 input_report_key(dev, BTN_TOOL_FINGER, fingers == 1); 317 input_report_key(dev, BTN_TOOL_FINGER, fingers == 1);
311 input_report_key(dev, BTN_TOOL_DOUBLETAP, fingers == 2); 318 input_report_key(dev, BTN_TOOL_DOUBLETAP, fingers == 2);
312 input_report_key(dev, BTN_TOOL_TRIPLETAP, fingers == 3); 319 input_report_key(dev, BTN_TOOL_TRIPLETAP, fingers == 3);
320 input_report_key(dev, BTN_TOOL_QUADTAP, fingers == 4);
313 input_report_key(dev, BTN_LEFT, packet[0] & 0x01); 321 input_report_key(dev, BTN_LEFT, packet[0] & 0x01);
314 input_report_key(dev, BTN_RIGHT, packet[0] & 0x02); 322 input_report_key(dev, BTN_RIGHT, packet[0] & 0x02);
315 323
@@ -467,6 +475,7 @@ static void elantech_set_input_params(struct psmouse *psmouse)
467 break; 475 break;
468 476
469 case 2: 477 case 2:
478 __set_bit(BTN_TOOL_QUADTAP, dev->keybit);
470 input_set_abs_params(dev, ABS_X, ETP_XMIN_V2, ETP_XMAX_V2, 0, 0); 479 input_set_abs_params(dev, ABS_X, ETP_XMIN_V2, ETP_XMAX_V2, 0, 0);
471 input_set_abs_params(dev, ABS_Y, ETP_YMIN_V2, ETP_YMAX_V2, 0, 0); 480 input_set_abs_params(dev, ABS_Y, ETP_YMIN_V2, ETP_YMAX_V2, 0, 0);
472 input_set_abs_params(dev, ABS_HAT0X, ETP_2FT_XMIN, ETP_2FT_XMAX, 0, 0); 481 input_set_abs_params(dev, ABS_HAT0X, ETP_2FT_XMIN, ETP_2FT_XMAX, 0, 0);
@@ -733,13 +742,13 @@ int elantech_init(struct psmouse *psmouse)
733 etd->capabilities = param[0]; 742 etd->capabilities = param[0];
734 743
735 /* 744 /*
736 * This firmware seems to suffer from misreporting coordinates when 745 * This firmware suffers from misreporting coordinates when
737 * a touch action starts causing the mouse cursor or scrolled page 746 * a touch action starts causing the mouse cursor or scrolled page
738 * to jump. Enable a workaround. 747 * to jump. Enable a workaround.
739 */ 748 */
740 if (etd->fw_version == 0x020022) { 749 if (etd->fw_version == 0x020022 || etd->fw_version == 0x020600) {
741 pr_info("firmware version 2.0.34 detected, enabling jumpy cursor workaround\n"); 750 pr_info("firmware version 2.0.34/2.6.0 detected, enabling jumpy cursor workaround\n");
742 etd->jumpy_cursor = 1; 751 etd->jumpy_cursor = true;
743 } 752 }
744 753
745 if (elantech_set_absolute_mode(psmouse)) { 754 if (elantech_set_absolute_mode(psmouse)) {
diff --git a/drivers/input/mouse/elantech.h b/drivers/input/mouse/elantech.h
index ac57bde1bb9f..aa4aac5d2198 100644
--- a/drivers/input/mouse/elantech.h
+++ b/drivers/input/mouse/elantech.h
@@ -100,10 +100,11 @@ struct elantech_data {
100 unsigned char reg_26; 100 unsigned char reg_26;
101 unsigned char debug; 101 unsigned char debug;
102 unsigned char capabilities; 102 unsigned char capabilities;
103 unsigned char paritycheck; 103 bool paritycheck;
104 unsigned char jumpy_cursor; 104 bool jumpy_cursor;
105 unsigned char hw_version; 105 unsigned char hw_version;
106 unsigned int fw_version; 106 unsigned int fw_version;
107 unsigned int single_finger_reports;
107 unsigned char parity[256]; 108 unsigned char parity[256];
108}; 109};
109 110
diff --git a/drivers/input/mouse/pc110pad.c b/drivers/input/mouse/pc110pad.c
index 3941f97cfa60..7b02b652e267 100644
--- a/drivers/input/mouse/pc110pad.c
+++ b/drivers/input/mouse/pc110pad.c
@@ -145,8 +145,8 @@ static int __init pc110pad_init(void)
145 pc110pad_dev->absbit[0] = BIT_MASK(ABS_X) | BIT_MASK(ABS_Y); 145 pc110pad_dev->absbit[0] = BIT_MASK(ABS_X) | BIT_MASK(ABS_Y);
146 pc110pad_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); 146 pc110pad_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
147 147
148 pc110pad_dev->absmax[ABS_X] = 0x1ff; 148 input_abs_set_max(pc110pad_dev, ABS_X, 0x1ff);
149 pc110pad_dev->absmax[ABS_Y] = 0x0ff; 149 input_abs_set_max(pc110pad_dev, ABS_Y, 0x0ff);
150 150
151 pc110pad_dev->open = pc110pad_open; 151 pc110pad_dev->open = pc110pad_open;
152 pc110pad_dev->close = pc110pad_close; 152 pc110pad_dev->close = pc110pad_close;
diff --git a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c
index 979c50215282..73a7af2542a8 100644
--- a/drivers/input/mouse/psmouse-base.c
+++ b/drivers/input/mouse/psmouse-base.c
@@ -39,11 +39,13 @@ MODULE_DESCRIPTION(DRIVER_DESC);
39MODULE_LICENSE("GPL"); 39MODULE_LICENSE("GPL");
40 40
41static unsigned int psmouse_max_proto = PSMOUSE_AUTO; 41static unsigned int psmouse_max_proto = PSMOUSE_AUTO;
42static int psmouse_set_maxproto(const char *val, struct kernel_param *kp); 42static int psmouse_set_maxproto(const char *val, const struct kernel_param *);
43static int psmouse_get_maxproto(char *buffer, struct kernel_param *kp); 43static int psmouse_get_maxproto(char *buffer, const struct kernel_param *kp);
44static struct kernel_param_ops param_ops_proto_abbrev = {
45 .set = psmouse_set_maxproto,
46 .get = psmouse_get_maxproto,
47};
44#define param_check_proto_abbrev(name, p) __param_check(name, p, unsigned int) 48#define param_check_proto_abbrev(name, p) __param_check(name, p, unsigned int)
45#define param_set_proto_abbrev psmouse_set_maxproto
46#define param_get_proto_abbrev psmouse_get_maxproto
47module_param_named(proto, psmouse_max_proto, proto_abbrev, 0644); 49module_param_named(proto, psmouse_max_proto, proto_abbrev, 0644);
48MODULE_PARM_DESC(proto, "Highest protocol extension to probe (bare, imps, exps, any). Useful for KVM switches."); 50MODULE_PARM_DESC(proto, "Highest protocol extension to probe (bare, imps, exps, any). Useful for KVM switches.");
49 51
@@ -1679,7 +1681,7 @@ static ssize_t psmouse_attr_set_resolution(struct psmouse *psmouse, void *data,
1679} 1681}
1680 1682
1681 1683
1682static int psmouse_set_maxproto(const char *val, struct kernel_param *kp) 1684static int psmouse_set_maxproto(const char *val, const struct kernel_param *kp)
1683{ 1685{
1684 const struct psmouse_protocol *proto; 1686 const struct psmouse_protocol *proto;
1685 1687
@@ -1696,7 +1698,7 @@ static int psmouse_set_maxproto(const char *val, struct kernel_param *kp)
1696 return 0; 1698 return 0;
1697} 1699}
1698 1700
1699static int psmouse_get_maxproto(char *buffer, struct kernel_param *kp) 1701static int psmouse_get_maxproto(char *buffer, const struct kernel_param *kp)
1700{ 1702{
1701 int type = *((unsigned int *)kp->arg); 1703 int type = *((unsigned int *)kp->arg);
1702 1704
diff --git a/drivers/input/mouse/synaptics.c b/drivers/input/mouse/synaptics.c
index 8c324403b9f2..96b70a43515f 100644
--- a/drivers/input/mouse/synaptics.c
+++ b/drivers/input/mouse/synaptics.c
@@ -635,8 +635,8 @@ static void set_input_params(struct input_dev *dev, struct synaptics_data *priv)
635 __clear_bit(REL_X, dev->relbit); 635 __clear_bit(REL_X, dev->relbit);
636 __clear_bit(REL_Y, dev->relbit); 636 __clear_bit(REL_Y, dev->relbit);
637 637
638 dev->absres[ABS_X] = priv->x_res; 638 input_abs_set_res(dev, ABS_X, priv->x_res);
639 dev->absres[ABS_Y] = priv->y_res; 639 input_abs_set_res(dev, ABS_Y, priv->y_res);
640 640
641 if (SYN_CAP_CLICKPAD(priv->ext_cap_0c)) { 641 if (SYN_CAP_CLICKPAD(priv->ext_cap_0c)) {
642 /* Clickpads report only left button */ 642 /* Clickpads report only left button */
diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
index d8f68f77007b..83c24cca234a 100644
--- a/drivers/input/mousedev.c
+++ b/drivers/input/mousedev.c
@@ -22,6 +22,7 @@
22#include <linux/random.h> 22#include <linux/random.h>
23#include <linux/major.h> 23#include <linux/major.h>
24#include <linux/device.h> 24#include <linux/device.h>
25#include <linux/kernel.h>
25#ifdef CONFIG_INPUT_MOUSEDEV_PSAUX 26#ifdef CONFIG_INPUT_MOUSEDEV_PSAUX
26#include <linux/miscdevice.h> 27#include <linux/miscdevice.h>
27#endif 28#endif
@@ -134,11 +135,14 @@ static void mousedev_touchpad_event(struct input_dev *dev,
134 switch (code) { 135 switch (code) {
135 136
136 case ABS_X: 137 case ABS_X:
138
137 fx(0) = value; 139 fx(0) = value;
138 if (mousedev->touch && mousedev->pkt_count >= 2) { 140 if (mousedev->touch && mousedev->pkt_count >= 2) {
139 size = dev->absmax[ABS_X] - dev->absmin[ABS_X]; 141 size = input_abs_get_min(dev, ABS_X) -
142 input_abs_get_max(dev, ABS_X);
140 if (size == 0) 143 if (size == 0)
141 size = 256 * 2; 144 size = 256 * 2;
145
142 tmp = ((value - fx(2)) * 256 * FRACTION_DENOM) / size; 146 tmp = ((value - fx(2)) * 256 * FRACTION_DENOM) / size;
143 tmp += mousedev->frac_dx; 147 tmp += mousedev->frac_dx;
144 mousedev->packet.dx = tmp / FRACTION_DENOM; 148 mousedev->packet.dx = tmp / FRACTION_DENOM;
@@ -150,10 +154,12 @@ static void mousedev_touchpad_event(struct input_dev *dev,
150 case ABS_Y: 154 case ABS_Y:
151 fy(0) = value; 155 fy(0) = value;
152 if (mousedev->touch && mousedev->pkt_count >= 2) { 156 if (mousedev->touch && mousedev->pkt_count >= 2) {
153 /* use X size to keep the same scale */ 157 /* use X size for ABS_Y to keep the same scale */
154 size = dev->absmax[ABS_X] - dev->absmin[ABS_X]; 158 size = input_abs_get_min(dev, ABS_X) -
159 input_abs_get_max(dev, ABS_X);
155 if (size == 0) 160 if (size == 0)
156 size = 256 * 2; 161 size = 256 * 2;
162
157 tmp = -((value - fy(2)) * 256 * FRACTION_DENOM) / size; 163 tmp = -((value - fy(2)) * 256 * FRACTION_DENOM) / size;
158 tmp += mousedev->frac_dy; 164 tmp += mousedev->frac_dy;
159 mousedev->packet.dy = tmp / FRACTION_DENOM; 165 mousedev->packet.dy = tmp / FRACTION_DENOM;
@@ -167,33 +173,35 @@ static void mousedev_touchpad_event(struct input_dev *dev,
167static void mousedev_abs_event(struct input_dev *dev, struct mousedev *mousedev, 173static void mousedev_abs_event(struct input_dev *dev, struct mousedev *mousedev,
168 unsigned int code, int value) 174 unsigned int code, int value)
169{ 175{
170 int size; 176 int min, max, size;
171 177
172 switch (code) { 178 switch (code) {
173 179
174 case ABS_X: 180 case ABS_X:
175 size = dev->absmax[ABS_X] - dev->absmin[ABS_X]; 181 min = input_abs_get_min(dev, ABS_X);
182 max = input_abs_get_max(dev, ABS_X);
183
184 size = max - min;
176 if (size == 0) 185 if (size == 0)
177 size = xres ? : 1; 186 size = xres ? : 1;
178 if (value > dev->absmax[ABS_X]) 187
179 value = dev->absmax[ABS_X]; 188 clamp(value, min, max);
180 if (value < dev->absmin[ABS_X]) 189
181 value = dev->absmin[ABS_X]; 190 mousedev->packet.x = ((value - min) * xres) / size;
182 mousedev->packet.x =
183 ((value - dev->absmin[ABS_X]) * xres) / size;
184 mousedev->packet.abs_event = 1; 191 mousedev->packet.abs_event = 1;
185 break; 192 break;
186 193
187 case ABS_Y: 194 case ABS_Y:
188 size = dev->absmax[ABS_Y] - dev->absmin[ABS_Y]; 195 min = input_abs_get_min(dev, ABS_Y);
196 max = input_abs_get_max(dev, ABS_Y);
197
198 size = max - min;
189 if (size == 0) 199 if (size == 0)
190 size = yres ? : 1; 200 size = yres ? : 1;
191 if (value > dev->absmax[ABS_Y]) 201
192 value = dev->absmax[ABS_Y]; 202 clamp(value, min, max);
193 if (value < dev->absmin[ABS_Y]) 203
194 value = dev->absmin[ABS_Y]; 204 mousedev->packet.y = yres - ((value - min) * yres) / size;
195 mousedev->packet.y = yres -
196 ((value - dev->absmin[ABS_Y]) * yres) / size;
197 mousedev->packet.abs_event = 1; 205 mousedev->packet.abs_event = 1;
198 break; 206 break;
199 } 207 }
diff --git a/drivers/input/serio/i8042-sparcio.h b/drivers/input/serio/i8042-sparcio.h
index cb2a24b94746..c5cc4508d6df 100644
--- a/drivers/input/serio/i8042-sparcio.h
+++ b/drivers/input/serio/i8042-sparcio.h
@@ -49,7 +49,7 @@ static inline void i8042_write_command(int val)
49#define OBP_PS2MS_NAME1 "kdmouse" 49#define OBP_PS2MS_NAME1 "kdmouse"
50#define OBP_PS2MS_NAME2 "mouse" 50#define OBP_PS2MS_NAME2 "mouse"
51 51
52static int __devinit sparc_i8042_probe(struct of_device *op, const struct of_device_id *match) 52static int __devinit sparc_i8042_probe(struct platform_device *op, const struct of_device_id *match)
53{ 53{
54 struct device_node *dp = op->dev.of_node; 54 struct device_node *dp = op->dev.of_node;
55 55
@@ -57,7 +57,7 @@ static int __devinit sparc_i8042_probe(struct of_device *op, const struct of_dev
57 while (dp) { 57 while (dp) {
58 if (!strcmp(dp->name, OBP_PS2KBD_NAME1) || 58 if (!strcmp(dp->name, OBP_PS2KBD_NAME1) ||
59 !strcmp(dp->name, OBP_PS2KBD_NAME2)) { 59 !strcmp(dp->name, OBP_PS2KBD_NAME2)) {
60 struct of_device *kbd = of_find_device_by_node(dp); 60 struct platform_device *kbd = of_find_device_by_node(dp);
61 unsigned int irq = kbd->archdata.irqs[0]; 61 unsigned int irq = kbd->archdata.irqs[0];
62 if (irq == 0xffffffff) 62 if (irq == 0xffffffff)
63 irq = op->archdata.irqs[0]; 63 irq = op->archdata.irqs[0];
@@ -67,7 +67,7 @@ static int __devinit sparc_i8042_probe(struct of_device *op, const struct of_dev
67 kbd_res = &kbd->resource[0]; 67 kbd_res = &kbd->resource[0];
68 } else if (!strcmp(dp->name, OBP_PS2MS_NAME1) || 68 } else if (!strcmp(dp->name, OBP_PS2MS_NAME1) ||
69 !strcmp(dp->name, OBP_PS2MS_NAME2)) { 69 !strcmp(dp->name, OBP_PS2MS_NAME2)) {
70 struct of_device *ms = of_find_device_by_node(dp); 70 struct platform_device *ms = of_find_device_by_node(dp);
71 unsigned int irq = ms->archdata.irqs[0]; 71 unsigned int irq = ms->archdata.irqs[0];
72 if (irq == 0xffffffff) 72 if (irq == 0xffffffff)
73 irq = op->archdata.irqs[0]; 73 irq = op->archdata.irqs[0];
@@ -80,7 +80,7 @@ static int __devinit sparc_i8042_probe(struct of_device *op, const struct of_dev
80 return 0; 80 return 0;
81} 81}
82 82
83static int __devexit sparc_i8042_remove(struct of_device *op) 83static int __devexit sparc_i8042_remove(struct platform_device *op)
84{ 84{
85 of_iounmap(kbd_res, kbd_iobase, 8); 85 of_iounmap(kbd_res, kbd_iobase, 8);
86 86
diff --git a/drivers/input/serio/i8042.c b/drivers/input/serio/i8042.c
index 258b98b9d7c2..46e4ba0b9246 100644
--- a/drivers/input/serio/i8042.c
+++ b/drivers/input/serio/i8042.c
@@ -61,10 +61,6 @@ static bool i8042_noloop;
61module_param_named(noloop, i8042_noloop, bool, 0); 61module_param_named(noloop, i8042_noloop, bool, 0);
62MODULE_PARM_DESC(noloop, "Disable the AUX Loopback command while probing for the AUX port"); 62MODULE_PARM_DESC(noloop, "Disable the AUX Loopback command while probing for the AUX port");
63 63
64static unsigned int i8042_blink_frequency = 500;
65module_param_named(panicblink, i8042_blink_frequency, uint, 0600);
66MODULE_PARM_DESC(panicblink, "Frequency with which keyboard LEDs should blink when kernel panics");
67
68#ifdef CONFIG_X86 64#ifdef CONFIG_X86
69static bool i8042_dritek; 65static bool i8042_dritek;
70module_param_named(dritek, i8042_dritek, bool, 0); 66module_param_named(dritek, i8042_dritek, bool, 0);
@@ -1030,8 +1026,8 @@ static void i8042_controller_reset(void)
1030 1026
1031 1027
1032/* 1028/*
1033 * i8042_panic_blink() will flash the keyboard LEDs and is called when 1029 * i8042_panic_blink() will turn the keyboard LEDs on or off and is called
1034 * kernel panics. Flashing LEDs is useful for users running X who may 1030 * when kernel panics. Flashing LEDs is useful for users running X who may
1035 * not see the console and will help distingushing panics from "real" 1031 * not see the console and will help distingushing panics from "real"
1036 * lockups. 1032 * lockups.
1037 * 1033 *
@@ -1041,22 +1037,12 @@ static void i8042_controller_reset(void)
1041 1037
1042#define DELAY do { mdelay(1); if (++delay > 10) return delay; } while(0) 1038#define DELAY do { mdelay(1); if (++delay > 10) return delay; } while(0)
1043 1039
1044static long i8042_panic_blink(long count) 1040static long i8042_panic_blink(int state)
1045{ 1041{
1046 long delay = 0; 1042 long delay = 0;
1047 static long last_blink; 1043 char led;
1048 static char led;
1049
1050 /*
1051 * We expect frequency to be about 1/2s. KDB uses about 1s.
1052 * Make sure they are different.
1053 */
1054 if (!i8042_blink_frequency)
1055 return 0;
1056 if (count - last_blink < i8042_blink_frequency)
1057 return 0;
1058 1044
1059 led ^= 0x01 | 0x04; 1045 led = (state) ? 0x01 | 0x04 : 0;
1060 while (i8042_read_status() & I8042_STR_IBF) 1046 while (i8042_read_status() & I8042_STR_IBF)
1061 DELAY; 1047 DELAY;
1062 dbg("%02x -> i8042 (panic blink)", 0xed); 1048 dbg("%02x -> i8042 (panic blink)", 0xed);
@@ -1069,7 +1055,6 @@ static long i8042_panic_blink(long count)
1069 dbg("%02x -> i8042 (panic blink)", led); 1055 dbg("%02x -> i8042 (panic blink)", led);
1070 i8042_write_data(led); 1056 i8042_write_data(led);
1071 DELAY; 1057 DELAY;
1072 last_blink = count;
1073 return delay; 1058 return delay;
1074} 1059}
1075 1060
diff --git a/drivers/input/serio/xilinx_ps2.c b/drivers/input/serio/xilinx_ps2.c
index e2c028d2638f..bb14449fb022 100644
--- a/drivers/input/serio/xilinx_ps2.c
+++ b/drivers/input/serio/xilinx_ps2.c
@@ -232,7 +232,7 @@ static void sxps2_close(struct serio *pserio)
232 * It returns 0, if the driver is bound to the PS/2 device, or a negative 232 * It returns 0, if the driver is bound to the PS/2 device, or a negative
233 * value if there is an error. 233 * value if there is an error.
234 */ 234 */
235static int __devinit xps2_of_probe(struct of_device *ofdev, 235static int __devinit xps2_of_probe(struct platform_device *ofdev,
236 const struct of_device_id *match) 236 const struct of_device_id *match)
237{ 237{
238 struct resource r_irq; /* Interrupt resources */ 238 struct resource r_irq; /* Interrupt resources */
@@ -332,7 +332,7 @@ failed1:
332 * if the driver module is being unloaded. It frees any resources allocated to 332 * if the driver module is being unloaded. It frees any resources allocated to
333 * the device. 333 * the device.
334 */ 334 */
335static int __devexit xps2_of_remove(struct of_device *of_dev) 335static int __devexit xps2_of_remove(struct platform_device *of_dev)
336{ 336{
337 struct device *dev = &of_dev->dev; 337 struct device *dev = &of_dev->dev;
338 struct xps2data *drvdata = dev_get_drvdata(dev); 338 struct xps2data *drvdata = dev_get_drvdata(dev);
diff --git a/drivers/input/tablet/aiptek.c b/drivers/input/tablet/aiptek.c
index 51b80b08d467..57b25b84d1fc 100644
--- a/drivers/input/tablet/aiptek.c
+++ b/drivers/input/tablet/aiptek.c
@@ -987,20 +987,17 @@ static int aiptek_program_tablet(struct aiptek *aiptek)
987 /* Query getXextension */ 987 /* Query getXextension */
988 if ((ret = aiptek_query(aiptek, 0x01, 0x00)) < 0) 988 if ((ret = aiptek_query(aiptek, 0x01, 0x00)) < 0)
989 return ret; 989 return ret;
990 aiptek->inputdev->absmin[ABS_X] = 0; 990 input_set_abs_params(aiptek->inputdev, ABS_X, 0, ret - 1, 0, 0);
991 aiptek->inputdev->absmax[ABS_X] = ret - 1;
992 991
993 /* Query getYextension */ 992 /* Query getYextension */
994 if ((ret = aiptek_query(aiptek, 0x01, 0x01)) < 0) 993 if ((ret = aiptek_query(aiptek, 0x01, 0x01)) < 0)
995 return ret; 994 return ret;
996 aiptek->inputdev->absmin[ABS_Y] = 0; 995 input_set_abs_params(aiptek->inputdev, ABS_Y, 0, ret - 1, 0, 0);
997 aiptek->inputdev->absmax[ABS_Y] = ret - 1;
998 996
999 /* Query getPressureLevels */ 997 /* Query getPressureLevels */
1000 if ((ret = aiptek_query(aiptek, 0x08, 0x00)) < 0) 998 if ((ret = aiptek_query(aiptek, 0x08, 0x00)) < 0)
1001 return ret; 999 return ret;
1002 aiptek->inputdev->absmin[ABS_PRESSURE] = 0; 1000 input_set_abs_params(aiptek->inputdev, ABS_PRESSURE, 0, ret - 1, 0, 0);
1003 aiptek->inputdev->absmax[ABS_PRESSURE] = ret - 1;
1004 1001
1005 /* Depending on whether we are in absolute or relative mode, we will 1002 /* Depending on whether we are in absolute or relative mode, we will
1006 * do a switchToTablet(absolute) or switchToMouse(relative) command. 1003 * do a switchToTablet(absolute) or switchToMouse(relative) command.
@@ -1054,8 +1051,8 @@ static ssize_t show_tabletSize(struct device *dev, struct device_attribute *attr
1054 struct aiptek *aiptek = dev_get_drvdata(dev); 1051 struct aiptek *aiptek = dev_get_drvdata(dev);
1055 1052
1056 return snprintf(buf, PAGE_SIZE, "%dx%d\n", 1053 return snprintf(buf, PAGE_SIZE, "%dx%d\n",
1057 aiptek->inputdev->absmax[ABS_X] + 1, 1054 input_abs_get_max(aiptek->inputdev, ABS_X) + 1,
1058 aiptek->inputdev->absmax[ABS_Y] + 1); 1055 input_abs_get_max(aiptek->inputdev, ABS_Y) + 1);
1059} 1056}
1060 1057
1061/* These structs define the sysfs files, param #1 is the name of the 1058/* These structs define the sysfs files, param #1 is the name of the
@@ -1843,7 +1840,7 @@ aiptek_probe(struct usb_interface *intf, const struct usb_device_id *id)
1843 for (i = 0; i < ARRAY_SIZE(speeds); ++i) { 1840 for (i = 0; i < ARRAY_SIZE(speeds); ++i) {
1844 aiptek->curSetting.programmableDelay = speeds[i]; 1841 aiptek->curSetting.programmableDelay = speeds[i];
1845 (void)aiptek_program_tablet(aiptek); 1842 (void)aiptek_program_tablet(aiptek);
1846 if (aiptek->inputdev->absmax[ABS_X] > 0) { 1843 if (input_abs_get_max(aiptek->inputdev, ABS_X) > 0) {
1847 dev_info(&intf->dev, 1844 dev_info(&intf->dev,
1848 "Aiptek using %d ms programming speed\n", 1845 "Aiptek using %d ms programming speed\n",
1849 aiptek->curSetting.programmableDelay); 1846 aiptek->curSetting.programmableDelay);
diff --git a/drivers/input/tablet/wacom_wac.c b/drivers/input/tablet/wacom_wac.c
index ce0b4608dad9..40d77ba8fdc1 100644
--- a/drivers/input/tablet/wacom_wac.c
+++ b/drivers/input/tablet/wacom_wac.c
@@ -687,10 +687,10 @@ static void wacom_tpc_finger_in(struct wacom_wac *wacom, char *data, int idx)
687 * protocol. 687 * protocol.
688 */ 688 */
689 if (wacom->last_finger != finger) { 689 if (wacom->last_finger != finger) {
690 if (x == input->abs[ABS_X]) 690 if (x == input_abs_get_val(input, ABS_X))
691 x++; 691 x++;
692 692
693 if (y == input->abs[ABS_Y]) 693 if (y == input_abs_get_val(input, ABS_Y))
694 y++; 694 y++;
695 } 695 }
696 696
diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig
index 61f35184f76c..0069d9703fda 100644
--- a/drivers/input/touchscreen/Kconfig
+++ b/drivers/input/touchscreen/Kconfig
@@ -628,4 +628,14 @@ config TOUCHSCREEN_TPS6507X
628 To compile this driver as a module, choose M here: the 628 To compile this driver as a module, choose M here: the
629 module will be called tps6507x_ts. 629 module will be called tps6507x_ts.
630 630
631config TOUCHSCREEN_STMPE
632 tristate "STMicroelectronics STMPE touchscreens"
633 depends on MFD_STMPE
634 help
635 Say Y here if you want support for STMicroelectronics
636 STMPE touchscreen controllers.
637
638 To compile this driver as a module, choose M here: the
639 module will be called stmpe-ts.
640
631endif 641endif
diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile
index bd6f30b4ff70..28217e1dcafd 100644
--- a/drivers/input/touchscreen/Makefile
+++ b/drivers/input/touchscreen/Makefile
@@ -36,6 +36,7 @@ obj-$(CONFIG_TOUCHSCREEN_PCAP) += pcap_ts.o
36obj-$(CONFIG_TOUCHSCREEN_PENMOUNT) += penmount.o 36obj-$(CONFIG_TOUCHSCREEN_PENMOUNT) += penmount.o
37obj-$(CONFIG_TOUCHSCREEN_QT602240) += qt602240_ts.o 37obj-$(CONFIG_TOUCHSCREEN_QT602240) += qt602240_ts.o
38obj-$(CONFIG_TOUCHSCREEN_S3C2410) += s3c2410_ts.o 38obj-$(CONFIG_TOUCHSCREEN_S3C2410) += s3c2410_ts.o
39obj-$(CONFIG_TOUCHSCREEN_STMPE) += stmpe-ts.o
39obj-$(CONFIG_TOUCHSCREEN_TOUCHIT213) += touchit213.o 40obj-$(CONFIG_TOUCHSCREEN_TOUCHIT213) += touchit213.o
40obj-$(CONFIG_TOUCHSCREEN_TOUCHRIGHT) += touchright.o 41obj-$(CONFIG_TOUCHSCREEN_TOUCHRIGHT) += touchright.o
41obj-$(CONFIG_TOUCHSCREEN_TOUCHWIN) += touchwin.o 42obj-$(CONFIG_TOUCHSCREEN_TOUCHWIN) += touchwin.o
diff --git a/drivers/input/touchscreen/cy8ctmg110_ts.c b/drivers/input/touchscreen/cy8ctmg110_ts.c
index 4eb7df0b7f87..5ec0946938fe 100644
--- a/drivers/input/touchscreen/cy8ctmg110_ts.c
+++ b/drivers/input/touchscreen/cy8ctmg110_ts.c
@@ -75,7 +75,7 @@ static int cy8ctmg110_write_regs(struct cy8ctmg110 *tsc, unsigned char reg,
75 unsigned char len, unsigned char *value) 75 unsigned char len, unsigned char *value)
76{ 76{
77 struct i2c_client *client = tsc->client; 77 struct i2c_client *client = tsc->client;
78 unsigned int ret; 78 int ret;
79 unsigned char i2c_data[6]; 79 unsigned char i2c_data[6];
80 80
81 BUG_ON(len > 5); 81 BUG_ON(len > 5);
@@ -86,7 +86,7 @@ static int cy8ctmg110_write_regs(struct cy8ctmg110 *tsc, unsigned char reg,
86 ret = i2c_master_send(client, i2c_data, len + 1); 86 ret = i2c_master_send(client, i2c_data, len + 1);
87 if (ret != 1) { 87 if (ret != 1) {
88 dev_err(&client->dev, "i2c write data cmd failed\n"); 88 dev_err(&client->dev, "i2c write data cmd failed\n");
89 return ret; 89 return ret ? ret : -EIO;
90 } 90 }
91 91
92 return 0; 92 return 0;
@@ -96,7 +96,7 @@ static int cy8ctmg110_read_regs(struct cy8ctmg110 *tsc,
96 unsigned char *data, unsigned char len, unsigned char cmd) 96 unsigned char *data, unsigned char len, unsigned char cmd)
97{ 97{
98 struct i2c_client *client = tsc->client; 98 struct i2c_client *client = tsc->client;
99 unsigned int ret; 99 int ret;
100 struct i2c_msg msg[2] = { 100 struct i2c_msg msg[2] = {
101 /* first write slave position to i2c devices */ 101 /* first write slave position to i2c devices */
102 { client->addr, 0, 1, &cmd }, 102 { client->addr, 0, 1, &cmd },
diff --git a/drivers/input/touchscreen/stmpe-ts.c b/drivers/input/touchscreen/stmpe-ts.c
new file mode 100644
index 000000000000..656148ec0027
--- /dev/null
+++ b/drivers/input/touchscreen/stmpe-ts.c
@@ -0,0 +1,397 @@
1/* STMicroelectronics STMPE811 Touchscreen Driver
2 *
3 * (C) 2010 Luotao Fu <l.fu@pengutronix.de>
4 * All rights reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
10 *
11 */
12
13#include <linux/kernel.h>
14#include <linux/module.h>
15#include <linux/sched.h>
16#include <linux/interrupt.h>
17#include <linux/init.h>
18#include <linux/device.h>
19#include <linux/platform_device.h>
20#include <linux/input.h>
21#include <linux/slab.h>
22#include <linux/delay.h>
23#include <linux/i2c.h>
24#include <linux/workqueue.h>
25
26#include <linux/mfd/stmpe.h>
27
28/* Register layouts and functionalities are identical on all stmpexxx variants
29 * with touchscreen controller
30 */
31#define STMPE_REG_INT_STA 0x0B
32#define STMPE_REG_ADC_CTRL1 0x20
33#define STMPE_REG_ADC_CTRL2 0x21
34#define STMPE_REG_TSC_CTRL 0x40
35#define STMPE_REG_TSC_CFG 0x41
36#define STMPE_REG_FIFO_TH 0x4A
37#define STMPE_REG_FIFO_STA 0x4B
38#define STMPE_REG_FIFO_SIZE 0x4C
39#define STMPE_REG_TSC_DATA_XYZ 0x52
40#define STMPE_REG_TSC_FRACTION_Z 0x56
41#define STMPE_REG_TSC_I_DRIVE 0x58
42
43#define OP_MOD_XYZ 0
44
45#define STMPE_TSC_CTRL_TSC_EN (1<<0)
46
47#define STMPE_FIFO_STA_RESET (1<<0)
48
49#define STMPE_IRQ_TOUCH_DET 0
50
51#define SAMPLE_TIME(x) ((x & 0xf) << 4)
52#define MOD_12B(x) ((x & 0x1) << 3)
53#define REF_SEL(x) ((x & 0x1) << 1)
54#define ADC_FREQ(x) (x & 0x3)
55#define AVE_CTRL(x) ((x & 0x3) << 6)
56#define DET_DELAY(x) ((x & 0x7) << 3)
57#define SETTLING(x) (x & 0x7)
58#define FRACTION_Z(x) (x & 0x7)
59#define I_DRIVE(x) (x & 0x1)
60#define OP_MODE(x) ((x & 0x7) << 1)
61
62#define STMPE_TS_NAME "stmpe-ts"
63#define XY_MASK 0xfff
64
65struct stmpe_touch {
66 struct stmpe *stmpe;
67 struct input_dev *idev;
68 struct delayed_work work;
69 struct device *dev;
70 u8 sample_time;
71 u8 mod_12b;
72 u8 ref_sel;
73 u8 adc_freq;
74 u8 ave_ctrl;
75 u8 touch_det_delay;
76 u8 settling;
77 u8 fraction_z;
78 u8 i_drive;
79};
80
81static int __stmpe_reset_fifo(struct stmpe *stmpe)
82{
83 int ret;
84
85 ret = stmpe_set_bits(stmpe, STMPE_REG_FIFO_STA,
86 STMPE_FIFO_STA_RESET, STMPE_FIFO_STA_RESET);
87 if (ret)
88 return ret;
89
90 return stmpe_set_bits(stmpe, STMPE_REG_FIFO_STA,
91 STMPE_FIFO_STA_RESET, 0);
92}
93
94static void stmpe_work(struct work_struct *work)
95{
96 int int_sta;
97 u32 timeout = 40;
98
99 struct stmpe_touch *ts =
100 container_of(work, struct stmpe_touch, work.work);
101
102 int_sta = stmpe_reg_read(ts->stmpe, STMPE_REG_INT_STA);
103
104 /*
105 * touch_det sometimes get desasserted or just get stuck. This appears
106 * to be a silicon bug, We still have to clearify this with the
107 * manufacture. As a workaround We release the key anyway if the
108 * touch_det keeps coming in after 4ms, while the FIFO contains no value
109 * during the whole time.
110 */
111 while ((int_sta & (1 << STMPE_IRQ_TOUCH_DET)) && (timeout > 0)) {
112 timeout--;
113 int_sta = stmpe_reg_read(ts->stmpe, STMPE_REG_INT_STA);
114 udelay(100);
115 }
116
117 /* reset the FIFO before we report release event */
118 __stmpe_reset_fifo(ts->stmpe);
119
120 input_report_abs(ts->idev, ABS_PRESSURE, 0);
121 input_sync(ts->idev);
122}
123
124static irqreturn_t stmpe_ts_handler(int irq, void *data)
125{
126 u8 data_set[4];
127 int x, y, z;
128 struct stmpe_touch *ts = data;
129
130 /*
131 * Cancel scheduled polling for release if we have new value
132 * available. Wait if the polling is already running.
133 */
134 cancel_delayed_work_sync(&ts->work);
135
136 /*
137 * The FIFO sometimes just crashes and stops generating interrupts. This
138 * appears to be a silicon bug. We still have to clearify this with
139 * the manufacture. As a workaround we disable the TSC while we are
140 * collecting data and flush the FIFO after reading
141 */
142 stmpe_set_bits(ts->stmpe, STMPE_REG_TSC_CTRL,
143 STMPE_TSC_CTRL_TSC_EN, 0);
144
145 stmpe_block_read(ts->stmpe, STMPE_REG_TSC_DATA_XYZ, 4, data_set);
146
147 x = (data_set[0] << 4) | (data_set[1] >> 4);
148 y = ((data_set[1] & 0xf) << 8) | data_set[2];
149 z = data_set[3];
150
151 input_report_abs(ts->idev, ABS_X, x);
152 input_report_abs(ts->idev, ABS_Y, y);
153 input_report_abs(ts->idev, ABS_PRESSURE, z);
154 input_sync(ts->idev);
155
156 /* flush the FIFO after we have read out our values. */
157 __stmpe_reset_fifo(ts->stmpe);
158
159 /* reenable the tsc */
160 stmpe_set_bits(ts->stmpe, STMPE_REG_TSC_CTRL,
161 STMPE_TSC_CTRL_TSC_EN, STMPE_TSC_CTRL_TSC_EN);
162
163 /* start polling for touch_det to detect release */
164 schedule_delayed_work(&ts->work, HZ / 50);
165
166 return IRQ_HANDLED;
167}
168
169static int __devinit stmpe_init_hw(struct stmpe_touch *ts)
170{
171 int ret;
172 u8 adc_ctrl1, adc_ctrl1_mask, tsc_cfg, tsc_cfg_mask;
173 struct stmpe *stmpe = ts->stmpe;
174 struct device *dev = ts->dev;
175
176 ret = stmpe_enable(stmpe, STMPE_BLOCK_TOUCHSCREEN | STMPE_BLOCK_ADC);
177 if (ret) {
178 dev_err(dev, "Could not enable clock for ADC and TS\n");
179 return ret;
180 }
181
182 adc_ctrl1 = SAMPLE_TIME(ts->sample_time) | MOD_12B(ts->mod_12b) |
183 REF_SEL(ts->ref_sel);
184 adc_ctrl1_mask = SAMPLE_TIME(0xff) | MOD_12B(0xff) | REF_SEL(0xff);
185
186 ret = stmpe_set_bits(stmpe, STMPE_REG_ADC_CTRL1,
187 adc_ctrl1_mask, adc_ctrl1);
188 if (ret) {
189 dev_err(dev, "Could not setup ADC\n");
190 return ret;
191 }
192
193 ret = stmpe_set_bits(stmpe, STMPE_REG_ADC_CTRL2,
194 ADC_FREQ(0xff), ADC_FREQ(ts->adc_freq));
195 if (ret) {
196 dev_err(dev, "Could not setup ADC\n");
197 return ret;
198 }
199
200 tsc_cfg = AVE_CTRL(ts->ave_ctrl) | DET_DELAY(ts->touch_det_delay) |
201 SETTLING(ts->settling);
202 tsc_cfg_mask = AVE_CTRL(0xff) | DET_DELAY(0xff) | SETTLING(0xff);
203
204 ret = stmpe_set_bits(stmpe, STMPE_REG_TSC_CFG, tsc_cfg_mask, tsc_cfg);
205 if (ret) {
206 dev_err(dev, "Could not config touch\n");
207 return ret;
208 }
209
210 ret = stmpe_set_bits(stmpe, STMPE_REG_TSC_FRACTION_Z,
211 FRACTION_Z(0xff), FRACTION_Z(ts->fraction_z));
212 if (ret) {
213 dev_err(dev, "Could not config touch\n");
214 return ret;
215 }
216
217 ret = stmpe_set_bits(stmpe, STMPE_REG_TSC_I_DRIVE,
218 I_DRIVE(0xff), I_DRIVE(ts->i_drive));
219 if (ret) {
220 dev_err(dev, "Could not config touch\n");
221 return ret;
222 }
223
224 /* set FIFO to 1 for single point reading */
225 ret = stmpe_reg_write(stmpe, STMPE_REG_FIFO_TH, 1);
226 if (ret) {
227 dev_err(dev, "Could not set FIFO\n");
228 return ret;
229 }
230
231 ret = stmpe_set_bits(stmpe, STMPE_REG_TSC_CTRL,
232 OP_MODE(0xff), OP_MODE(OP_MOD_XYZ));
233 if (ret) {
234 dev_err(dev, "Could not set mode\n");
235 return ret;
236 }
237
238 return 0;
239}
240
241static int stmpe_ts_open(struct input_dev *dev)
242{
243 struct stmpe_touch *ts = input_get_drvdata(dev);
244 int ret = 0;
245
246 ret = __stmpe_reset_fifo(ts->stmpe);
247 if (ret)
248 return ret;
249
250 return stmpe_set_bits(ts->stmpe, STMPE_REG_TSC_CTRL,
251 STMPE_TSC_CTRL_TSC_EN, STMPE_TSC_CTRL_TSC_EN);
252}
253
254static void stmpe_ts_close(struct input_dev *dev)
255{
256 struct stmpe_touch *ts = input_get_drvdata(dev);
257
258 cancel_delayed_work_sync(&ts->work);
259
260 stmpe_set_bits(ts->stmpe, STMPE_REG_TSC_CTRL,
261 STMPE_TSC_CTRL_TSC_EN, 0);
262}
263
264static int __devinit stmpe_input_probe(struct platform_device *pdev)
265{
266 struct stmpe *stmpe = dev_get_drvdata(pdev->dev.parent);
267 struct stmpe_platform_data *pdata = stmpe->pdata;
268 struct stmpe_touch *ts;
269 struct input_dev *idev;
270 struct stmpe_ts_platform_data *ts_pdata = NULL;
271 int ret = 0;
272 int ts_irq;
273
274 ts_irq = platform_get_irq_byname(pdev, "FIFO_TH");
275 if (ts_irq < 0)
276 return ts_irq;
277
278 ts = kzalloc(sizeof(*ts), GFP_KERNEL);
279 if (!ts)
280 goto err_out;
281
282 idev = input_allocate_device();
283 if (!idev)
284 goto err_free_ts;
285
286 platform_set_drvdata(pdev, ts);
287 ts->stmpe = stmpe;
288 ts->idev = idev;
289 ts->dev = &pdev->dev;
290
291 if (pdata)
292 ts_pdata = pdata->ts;
293
294 if (ts_pdata) {
295 ts->sample_time = ts_pdata->sample_time;
296 ts->mod_12b = ts_pdata->mod_12b;
297 ts->ref_sel = ts_pdata->ref_sel;
298 ts->adc_freq = ts_pdata->adc_freq;
299 ts->ave_ctrl = ts_pdata->ave_ctrl;
300 ts->touch_det_delay = ts_pdata->touch_det_delay;
301 ts->settling = ts_pdata->settling;
302 ts->fraction_z = ts_pdata->fraction_z;
303 ts->i_drive = ts_pdata->i_drive;
304 }
305
306 INIT_DELAYED_WORK(&ts->work, stmpe_work);
307
308 ret = request_threaded_irq(ts_irq, NULL, stmpe_ts_handler,
309 IRQF_ONESHOT, STMPE_TS_NAME, ts);
310 if (ret) {
311 dev_err(&pdev->dev, "Failed to request IRQ %d\n", ts_irq);
312 goto err_free_input;
313 }
314
315 ret = stmpe_init_hw(ts);
316 if (ret)
317 goto err_free_irq;
318
319 idev->name = STMPE_TS_NAME;
320 idev->id.bustype = BUS_I2C;
321 idev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
322 idev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
323
324 idev->open = stmpe_ts_open;
325 idev->close = stmpe_ts_close;
326
327 input_set_drvdata(idev, ts);
328
329 input_set_abs_params(idev, ABS_X, 0, XY_MASK, 0, 0);
330 input_set_abs_params(idev, ABS_Y, 0, XY_MASK, 0, 0);
331 input_set_abs_params(idev, ABS_PRESSURE, 0x0, 0xff, 0, 0);
332
333 ret = input_register_device(idev);
334 if (ret) {
335 dev_err(&pdev->dev, "Could not register input device\n");
336 goto err_free_irq;
337 }
338
339 return ret;
340
341err_free_irq:
342 free_irq(ts_irq, ts);
343err_free_input:
344 input_free_device(idev);
345 platform_set_drvdata(pdev, NULL);
346err_free_ts:
347 kfree(ts);
348err_out:
349 return ret;
350}
351
352static int __devexit stmpe_ts_remove(struct platform_device *pdev)
353{
354 struct stmpe_touch *ts = platform_get_drvdata(pdev);
355 unsigned int ts_irq = platform_get_irq_byname(pdev, "FIFO_TH");
356
357 stmpe_disable(ts->stmpe, STMPE_BLOCK_TOUCHSCREEN);
358
359 free_irq(ts_irq, ts);
360
361 platform_set_drvdata(pdev, NULL);
362
363 input_unregister_device(ts->idev);
364 input_free_device(ts->idev);
365
366 kfree(ts);
367
368 return 0;
369}
370
371static struct platform_driver stmpe_ts_driver = {
372 .driver = {
373 .name = STMPE_TS_NAME,
374 .owner = THIS_MODULE,
375 },
376 .probe = stmpe_input_probe,
377 .remove = __devexit_p(stmpe_ts_remove),
378};
379
380static int __init stmpe_ts_init(void)
381{
382 return platform_driver_register(&stmpe_ts_driver);
383}
384
385module_init(stmpe_ts_init);
386
387static void __exit stmpe_ts_exit(void)
388{
389 platform_driver_unregister(&stmpe_ts_driver);
390}
391
392module_exit(stmpe_ts_exit);
393
394MODULE_AUTHOR("Luotao Fu <l.fu@pengutronix.de>");
395MODULE_DESCRIPTION("STMPEXXX touchscreen driver");
396MODULE_LICENSE("GPL");
397MODULE_ALIAS("platform:" STMPE_TS_NAME);
diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
index 0ded3640b926..707d9c94cf9e 100644
--- a/drivers/isdn/gigaset/bas-gigaset.c
+++ b/drivers/isdn/gigaset/bas-gigaset.c
@@ -1914,11 +1914,13 @@ static int gigaset_write_cmd(struct cardstate *cs, struct cmdbuf_t *cb)
1914 * The next command will reopen the AT channel automatically. 1914 * The next command will reopen the AT channel automatically.
1915 */ 1915 */
1916 if (cb->len == 3 && !memcmp(cb->buf, "+++", 3)) { 1916 if (cb->len == 3 && !memcmp(cb->buf, "+++", 3)) {
1917 kfree(cb);
1918 rc = req_submit(cs->bcs, HD_CLOSE_ATCHANNEL, 0, BAS_TIMEOUT); 1917 rc = req_submit(cs->bcs, HD_CLOSE_ATCHANNEL, 0, BAS_TIMEOUT);
1919 if (cb->wake_tasklet) 1918 if (cb->wake_tasklet)
1920 tasklet_schedule(cb->wake_tasklet); 1919 tasklet_schedule(cb->wake_tasklet);
1921 return rc < 0 ? rc : cb->len; 1920 if (!rc)
1921 rc = cb->len;
1922 kfree(cb);
1923 return rc;
1922 } 1924 }
1923 1925
1924 spin_lock_irqsave(&cs->cmdlock, flags); 1926 spin_lock_irqsave(&cs->cmdlock, flags);
diff --git a/drivers/isdn/gigaset/capi.c b/drivers/isdn/gigaset/capi.c
index e5ea344a551a..bcc174e4f3b1 100644
--- a/drivers/isdn/gigaset/capi.c
+++ b/drivers/isdn/gigaset/capi.c
@@ -1052,6 +1052,7 @@ static inline void remove_appl_from_channel(struct bc_state *bcs,
1052 do { 1052 do {
1053 if (bcap->bcnext == ap) { 1053 if (bcap->bcnext == ap) {
1054 bcap->bcnext = bcap->bcnext->bcnext; 1054 bcap->bcnext = bcap->bcnext->bcnext;
1055 spin_unlock_irqrestore(&bcs->aplock, flags);
1055 return; 1056 return;
1056 } 1057 }
1057 bcap = bcap->bcnext; 1058 bcap = bcap->bcnext;
diff --git a/drivers/isdn/hardware/avm/c4.c b/drivers/isdn/hardware/avm/c4.c
index 7715d3242ec8..d3530f6e8115 100644
--- a/drivers/isdn/hardware/avm/c4.c
+++ b/drivers/isdn/hardware/avm/c4.c
@@ -1273,6 +1273,7 @@ static int __devinit c4_probe(struct pci_dev *dev,
1273 if (retval != 0) { 1273 if (retval != 0) {
1274 printk(KERN_ERR "c4: no AVM-C%d at i/o %#x, irq %d detected, mem %#x\n", 1274 printk(KERN_ERR "c4: no AVM-C%d at i/o %#x, irq %d detected, mem %#x\n",
1275 nr, param.port, param.irq, param.membase); 1275 nr, param.port, param.irq, param.membase);
1276 pci_disable_device(dev);
1276 return -ENODEV; 1277 return -ENODEV;
1277 } 1278 }
1278 return 0; 1279 return 0;
diff --git a/drivers/isdn/hardware/avm/t1pci.c b/drivers/isdn/hardware/avm/t1pci.c
index 5a3f83098018..a79eb5afb92d 100644
--- a/drivers/isdn/hardware/avm/t1pci.c
+++ b/drivers/isdn/hardware/avm/t1pci.c
@@ -210,6 +210,7 @@ static int __devinit t1pci_probe(struct pci_dev *dev,
210 if (retval != 0) { 210 if (retval != 0) {
211 printk(KERN_ERR "t1pci: no AVM-T1-PCI at i/o %#x, irq %d detected, mem %#x\n", 211 printk(KERN_ERR "t1pci: no AVM-T1-PCI at i/o %#x, irq %d detected, mem %#x\n",
212 param.port, param.irq, param.membase); 212 param.port, param.irq, param.membase);
213 pci_disable_device(dev);
213 return -ENODEV; 214 return -ENODEV;
214 } 215 }
215 return 0; 216 return 0;
diff --git a/drivers/isdn/hardware/mISDN/mISDNinfineon.c b/drivers/isdn/hardware/mISDN/mISDNinfineon.c
index d2dd61d65d51..af25e1f3efd4 100644
--- a/drivers/isdn/hardware/mISDN/mISDNinfineon.c
+++ b/drivers/isdn/hardware/mISDN/mISDNinfineon.c
@@ -1094,6 +1094,7 @@ inf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1094 pr_info("mISDN: do not have informations about adapter at %s\n", 1094 pr_info("mISDN: do not have informations about adapter at %s\n",
1095 pci_name(pdev)); 1095 pci_name(pdev));
1096 kfree(card); 1096 kfree(card);
1097 pci_disable_device(pdev);
1097 return -EINVAL; 1098 return -EINVAL;
1098 } else 1099 } else
1099 pr_notice("mISDN: found adapter %s at %s\n", 1100 pr_notice("mISDN: found adapter %s at %s\n",
@@ -1103,7 +1104,7 @@ inf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1103 pci_set_drvdata(pdev, card); 1104 pci_set_drvdata(pdev, card);
1104 err = setup_instance(card); 1105 err = setup_instance(card);
1105 if (err) { 1106 if (err) {
1106 pci_disable_device(card->pdev); 1107 pci_disable_device(pdev);
1107 kfree(card); 1108 kfree(card);
1108 pci_set_drvdata(pdev, NULL); 1109 pci_set_drvdata(pdev, NULL);
1109 } else if (ent->driver_data == INF_SCT_1) { 1110 } else if (ent->driver_data == INF_SCT_1) {
@@ -1114,6 +1115,7 @@ inf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1114 sc = kzalloc(sizeof(struct inf_hw), GFP_KERNEL); 1115 sc = kzalloc(sizeof(struct inf_hw), GFP_KERNEL);
1115 if (!sc) { 1116 if (!sc) {
1116 release_card(card); 1117 release_card(card);
1118 pci_disable_device(pdev);
1117 return -ENOMEM; 1119 return -ENOMEM;
1118 } 1120 }
1119 sc->irq = card->irq; 1121 sc->irq = card->irq;
@@ -1121,6 +1123,7 @@ inf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1121 sc->ci = card->ci + i; 1123 sc->ci = card->ci + i;
1122 err = setup_instance(sc); 1124 err = setup_instance(sc);
1123 if (err) { 1125 if (err) {
1126 pci_disable_device(pdev);
1124 kfree(sc); 1127 kfree(sc);
1125 release_card(card); 1128 release_card(card);
1126 break; 1129 break;
diff --git a/drivers/isdn/sc/ioctl.c b/drivers/isdn/sc/ioctl.c
index 43c5dc3516e5..4cfdbe08ffd1 100644
--- a/drivers/isdn/sc/ioctl.c
+++ b/drivers/isdn/sc/ioctl.c
@@ -174,7 +174,7 @@ int sc_ioctl(int card, scs_ioctl *data)
174 pr_debug("%s: SCIOGETSPID: ioctl received\n", 174 pr_debug("%s: SCIOGETSPID: ioctl received\n",
175 sc_adapter[card]->devicename); 175 sc_adapter[card]->devicename);
176 176
177 spid = kmalloc(SCIOC_SPIDSIZE, GFP_KERNEL); 177 spid = kzalloc(SCIOC_SPIDSIZE, GFP_KERNEL);
178 if (!spid) { 178 if (!spid) {
179 kfree(rcvmsg); 179 kfree(rcvmsg);
180 return -ENOMEM; 180 return -ENOMEM;
@@ -194,7 +194,7 @@ int sc_ioctl(int card, scs_ioctl *data)
194 kfree(rcvmsg); 194 kfree(rcvmsg);
195 return status; 195 return status;
196 } 196 }
197 strcpy(spid, rcvmsg->msg_data.byte_array); 197 strlcpy(spid, rcvmsg->msg_data.byte_array, SCIOC_SPIDSIZE);
198 198
199 /* 199 /*
200 * Package the switch type and send to user space 200 * Package the switch type and send to user space
@@ -266,12 +266,12 @@ int sc_ioctl(int card, scs_ioctl *data)
266 return status; 266 return status;
267 } 267 }
268 268
269 dn = kmalloc(SCIOC_DNSIZE, GFP_KERNEL); 269 dn = kzalloc(SCIOC_DNSIZE, GFP_KERNEL);
270 if (!dn) { 270 if (!dn) {
271 kfree(rcvmsg); 271 kfree(rcvmsg);
272 return -ENOMEM; 272 return -ENOMEM;
273 } 273 }
274 strcpy(dn, rcvmsg->msg_data.byte_array); 274 strlcpy(dn, rcvmsg->msg_data.byte_array, SCIOC_DNSIZE);
275 kfree(rcvmsg); 275 kfree(rcvmsg);
276 276
277 /* 277 /*
@@ -337,7 +337,7 @@ int sc_ioctl(int card, scs_ioctl *data)
337 pr_debug("%s: SCIOSTAT: ioctl received\n", 337 pr_debug("%s: SCIOSTAT: ioctl received\n",
338 sc_adapter[card]->devicename); 338 sc_adapter[card]->devicename);
339 339
340 bi = kmalloc (sizeof(boardInfo), GFP_KERNEL); 340 bi = kzalloc(sizeof(boardInfo), GFP_KERNEL);
341 if (!bi) { 341 if (!bi) {
342 kfree(rcvmsg); 342 kfree(rcvmsg);
343 return -ENOMEM; 343 return -ENOMEM;
diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c
index cc22eeefa10b..ea57e05d08f3 100644
--- a/drivers/leds/leds-gpio.c
+++ b/drivers/leds/leds-gpio.c
@@ -224,7 +224,7 @@ struct gpio_led_of_platform_data {
224 struct gpio_led_data led_data[]; 224 struct gpio_led_data led_data[];
225}; 225};
226 226
227static int __devinit of_gpio_leds_probe(struct of_device *ofdev, 227static int __devinit of_gpio_leds_probe(struct platform_device *ofdev,
228 const struct of_device_id *match) 228 const struct of_device_id *match)
229{ 229{
230 struct device_node *np = ofdev->dev.of_node, *child; 230 struct device_node *np = ofdev->dev.of_node, *child;
@@ -283,7 +283,7 @@ err:
283 return ret; 283 return ret;
284} 284}
285 285
286static int __devexit of_gpio_leds_remove(struct of_device *ofdev) 286static int __devexit of_gpio_leds_remove(struct platform_device *ofdev)
287{ 287{
288 struct gpio_led_of_platform_data *pdata = dev_get_drvdata(&ofdev->dev); 288 struct gpio_led_of_platform_data *pdata = dev_get_drvdata(&ofdev->dev);
289 int i; 289 int i;
diff --git a/drivers/macintosh/macio_sysfs.c b/drivers/macintosh/macio_sysfs.c
index 6024038a5b9d..8eb40afbd0f5 100644
--- a/drivers/macintosh/macio_sysfs.c
+++ b/drivers/macintosh/macio_sysfs.c
@@ -15,7 +15,7 @@ field##_show (struct device *dev, struct device_attribute *attr, \
15static ssize_t 15static ssize_t
16compatible_show (struct device *dev, struct device_attribute *attr, char *buf) 16compatible_show (struct device *dev, struct device_attribute *attr, char *buf)
17{ 17{
18 struct of_device *of; 18 struct platform_device *of;
19 const char *compat; 19 const char *compat;
20 int cplen; 20 int cplen;
21 int length = 0; 21 int length = 0;
@@ -52,9 +52,9 @@ static ssize_t modalias_show (struct device *dev, struct device_attribute *attr,
52static ssize_t devspec_show(struct device *dev, 52static ssize_t devspec_show(struct device *dev,
53 struct device_attribute *attr, char *buf) 53 struct device_attribute *attr, char *buf)
54{ 54{
55 struct of_device *ofdev; 55 struct platform_device *ofdev;
56 56
57 ofdev = to_of_device(dev); 57 ofdev = to_platform_device(dev);
58 return sprintf(buf, "%s\n", ofdev->dev.of_node->full_name); 58 return sprintf(buf, "%s\n", ofdev->dev.of_node->full_name);
59} 59}
60 60
diff --git a/drivers/macintosh/smu.c b/drivers/macintosh/smu.c
index 2506c957712e..e58c3d33e035 100644
--- a/drivers/macintosh/smu.c
+++ b/drivers/macintosh/smu.c
@@ -75,7 +75,7 @@ struct smu_cmd_buf {
75struct smu_device { 75struct smu_device {
76 spinlock_t lock; 76 spinlock_t lock;
77 struct device_node *of_node; 77 struct device_node *of_node;
78 struct of_device *of_dev; 78 struct platform_device *of_dev;
79 int doorbell; /* doorbell gpio */ 79 int doorbell; /* doorbell gpio */
80 u32 __iomem *db_buf; /* doorbell buffer */ 80 u32 __iomem *db_buf; /* doorbell buffer */
81 struct device_node *db_node; 81 struct device_node *db_node;
@@ -645,7 +645,7 @@ static void smu_expose_childs(struct work_struct *unused)
645 645
646static DECLARE_WORK(smu_expose_childs_work, smu_expose_childs); 646static DECLARE_WORK(smu_expose_childs_work, smu_expose_childs);
647 647
648static int smu_platform_probe(struct of_device* dev, 648static int smu_platform_probe(struct platform_device* dev,
649 const struct of_device_id *match) 649 const struct of_device_id *match)
650{ 650{
651 if (!smu) 651 if (!smu)
@@ -695,7 +695,7 @@ static int __init smu_init_sysfs(void)
695 695
696device_initcall(smu_init_sysfs); 696device_initcall(smu_init_sysfs);
697 697
698struct of_device *smu_get_ofdev(void) 698struct platform_device *smu_get_ofdev(void)
699{ 699{
700 if (!smu) 700 if (!smu)
701 return NULL; 701 return NULL;
diff --git a/drivers/macintosh/therm_adt746x.c b/drivers/macintosh/therm_adt746x.c
index c42eeb43042d..d0d221332db0 100644
--- a/drivers/macintosh/therm_adt746x.c
+++ b/drivers/macintosh/therm_adt746x.c
@@ -84,7 +84,7 @@ struct thermostat {
84 84
85static enum {ADT7460, ADT7467} therm_type; 85static enum {ADT7460, ADT7467} therm_type;
86static int therm_bus, therm_address; 86static int therm_bus, therm_address;
87static struct of_device * of_dev; 87static struct platform_device * of_dev;
88static struct thermostat* thermostat; 88static struct thermostat* thermostat;
89static struct task_struct *thread_therm = NULL; 89static struct task_struct *thread_therm = NULL;
90 90
diff --git a/drivers/macintosh/therm_pm72.c b/drivers/macintosh/therm_pm72.c
index e60605bd0ea9..44549272333c 100644
--- a/drivers/macintosh/therm_pm72.c
+++ b/drivers/macintosh/therm_pm72.c
@@ -148,7 +148,7 @@
148 * Driver statics 148 * Driver statics
149 */ 149 */
150 150
151static struct of_device * of_dev; 151static struct platform_device * of_dev;
152static struct i2c_adapter * u3_0; 152static struct i2c_adapter * u3_0;
153static struct i2c_adapter * u3_1; 153static struct i2c_adapter * u3_1;
154static struct i2c_adapter * k2; 154static struct i2c_adapter * k2;
@@ -2210,7 +2210,7 @@ static void fcu_lookup_fans(struct device_node *fcu_node)
2210 } 2210 }
2211} 2211}
2212 2212
2213static int fcu_of_probe(struct of_device* dev, const struct of_device_id *match) 2213static int fcu_of_probe(struct platform_device* dev, const struct of_device_id *match)
2214{ 2214{
2215 state = state_detached; 2215 state = state_detached;
2216 2216
@@ -2221,7 +2221,7 @@ static int fcu_of_probe(struct of_device* dev, const struct of_device_id *match)
2221 return i2c_add_driver(&therm_pm72_driver); 2221 return i2c_add_driver(&therm_pm72_driver);
2222} 2222}
2223 2223
2224static int fcu_of_remove(struct of_device* dev) 2224static int fcu_of_remove(struct platform_device* dev)
2225{ 2225{
2226 i2c_del_driver(&therm_pm72_driver); 2226 i2c_del_driver(&therm_pm72_driver);
2227 2227
diff --git a/drivers/macintosh/therm_windtunnel.c b/drivers/macintosh/therm_windtunnel.c
index 5c9367acf0cf..c89f396e4c53 100644
--- a/drivers/macintosh/therm_windtunnel.c
+++ b/drivers/macintosh/therm_windtunnel.c
@@ -52,7 +52,7 @@ static struct {
52 struct task_struct *poll_task; 52 struct task_struct *poll_task;
53 53
54 struct mutex lock; 54 struct mutex lock;
55 struct of_device *of_dev; 55 struct platform_device *of_dev;
56 56
57 struct i2c_client *thermostat; 57 struct i2c_client *thermostat;
58 struct i2c_client *fan; 58 struct i2c_client *fan;
@@ -322,10 +322,10 @@ do_attach( struct i2c_adapter *adapter )
322 322
323 memset(&info, 0, sizeof(struct i2c_board_info)); 323 memset(&info, 0, sizeof(struct i2c_board_info));
324 strlcpy(info.type, "therm_ds1775", I2C_NAME_SIZE); 324 strlcpy(info.type, "therm_ds1775", I2C_NAME_SIZE);
325 i2c_new_probed_device(adapter, &info, scan_ds1775); 325 i2c_new_probed_device(adapter, &info, scan_ds1775, NULL);
326 326
327 strlcpy(info.type, "therm_adm1030", I2C_NAME_SIZE); 327 strlcpy(info.type, "therm_adm1030", I2C_NAME_SIZE);
328 i2c_new_probed_device(adapter, &info, scan_adm1030); 328 i2c_new_probed_device(adapter, &info, scan_adm1030, NULL);
329 329
330 if( x.thermostat && x.fan ) { 330 if( x.thermostat && x.fan ) {
331 x.running = 1; 331 x.running = 1;
@@ -444,13 +444,13 @@ static struct i2c_driver g4fan_driver = {
444/************************************************************************/ 444/************************************************************************/
445 445
446static int 446static int
447therm_of_probe( struct of_device *dev, const struct of_device_id *match ) 447therm_of_probe( struct platform_device *dev, const struct of_device_id *match )
448{ 448{
449 return i2c_add_driver( &g4fan_driver ); 449 return i2c_add_driver( &g4fan_driver );
450} 450}
451 451
452static int 452static int
453therm_of_remove( struct of_device *dev ) 453therm_of_remove( struct platform_device *dev )
454{ 454{
455 i2c_del_driver( &g4fan_driver ); 455 i2c_del_driver( &g4fan_driver );
456 return 0; 456 return 0;
diff --git a/drivers/md/Kconfig b/drivers/md/Kconfig
index 4a6feac8c94a..bf1a95e31559 100644
--- a/drivers/md/Kconfig
+++ b/drivers/md/Kconfig
@@ -121,7 +121,7 @@ config MD_RAID10
121config MD_RAID456 121config MD_RAID456
122 tristate "RAID-4/RAID-5/RAID-6 mode" 122 tristate "RAID-4/RAID-5/RAID-6 mode"
123 depends on BLK_DEV_MD 123 depends on BLK_DEV_MD
124 select MD_RAID6_PQ 124 select RAID6_PQ
125 select ASYNC_MEMCPY 125 select ASYNC_MEMCPY
126 select ASYNC_XOR 126 select ASYNC_XOR
127 select ASYNC_PQ 127 select ASYNC_PQ
@@ -165,22 +165,6 @@ config MULTICORE_RAID456
165 165
166 If unsure, say N. 166 If unsure, say N.
167 167
168config MD_RAID6_PQ
169 tristate
170
171config ASYNC_RAID6_TEST
172 tristate "Self test for hardware accelerated raid6 recovery"
173 depends on MD_RAID6_PQ
174 select ASYNC_RAID6_RECOV
175 ---help---
176 This is a one-shot self test that permutes through the
177 recovery of all the possible two disk failure scenarios for a
178 N-disk array. Recovery is performed with the asynchronous
179 raid6 recovery routines, and will optionally use an offload
180 engine if one is available.
181
182 If unsure, say N.
183
184config MD_MULTIPATH 168config MD_MULTIPATH
185 tristate "Multipath I/O support" 169 tristate "Multipath I/O support"
186 depends on BLK_DEV_MD 170 depends on BLK_DEV_MD
diff --git a/drivers/md/Makefile b/drivers/md/Makefile
index e355e7f6a536..5e3aac41919d 100644
--- a/drivers/md/Makefile
+++ b/drivers/md/Makefile
@@ -12,13 +12,6 @@ dm-log-userspace-y \
12 += dm-log-userspace-base.o dm-log-userspace-transfer.o 12 += dm-log-userspace-base.o dm-log-userspace-transfer.o
13md-mod-y += md.o bitmap.o 13md-mod-y += md.o bitmap.o
14raid456-y += raid5.o 14raid456-y += raid5.o
15raid6_pq-y += raid6algos.o raid6recov.o raid6tables.o \
16 raid6int1.o raid6int2.o raid6int4.o \
17 raid6int8.o raid6int16.o raid6int32.o \
18 raid6altivec1.o raid6altivec2.o raid6altivec4.o \
19 raid6altivec8.o \
20 raid6mmx.o raid6sse1.o raid6sse2.o
21hostprogs-y += mktables
22 15
23# Note: link order is important. All raid personalities 16# Note: link order is important. All raid personalities
24# and must come before md.o, as they each initialise 17# and must come before md.o, as they each initialise
@@ -29,7 +22,6 @@ obj-$(CONFIG_MD_LINEAR) += linear.o
29obj-$(CONFIG_MD_RAID0) += raid0.o 22obj-$(CONFIG_MD_RAID0) += raid0.o
30obj-$(CONFIG_MD_RAID1) += raid1.o 23obj-$(CONFIG_MD_RAID1) += raid1.o
31obj-$(CONFIG_MD_RAID10) += raid10.o 24obj-$(CONFIG_MD_RAID10) += raid10.o
32obj-$(CONFIG_MD_RAID6_PQ) += raid6_pq.o
33obj-$(CONFIG_MD_RAID456) += raid456.o 25obj-$(CONFIG_MD_RAID456) += raid456.o
34obj-$(CONFIG_MD_MULTIPATH) += multipath.o 26obj-$(CONFIG_MD_MULTIPATH) += multipath.o
35obj-$(CONFIG_MD_FAULTY) += faulty.o 27obj-$(CONFIG_MD_FAULTY) += faulty.o
@@ -45,75 +37,6 @@ obj-$(CONFIG_DM_MIRROR) += dm-mirror.o dm-log.o dm-region-hash.o
45obj-$(CONFIG_DM_LOG_USERSPACE) += dm-log-userspace.o 37obj-$(CONFIG_DM_LOG_USERSPACE) += dm-log-userspace.o
46obj-$(CONFIG_DM_ZERO) += dm-zero.o 38obj-$(CONFIG_DM_ZERO) += dm-zero.o
47 39
48quiet_cmd_unroll = UNROLL $@
49 cmd_unroll = $(AWK) -f$(srctree)/$(src)/unroll.awk -vN=$(UNROLL) \
50 < $< > $@ || ( rm -f $@ && exit 1 )
51
52ifeq ($(CONFIG_ALTIVEC),y)
53altivec_flags := -maltivec -mabi=altivec
54endif
55
56ifeq ($(CONFIG_DM_UEVENT),y) 40ifeq ($(CONFIG_DM_UEVENT),y)
57dm-mod-objs += dm-uevent.o 41dm-mod-objs += dm-uevent.o
58endif 42endif
59
60targets += raid6int1.c
61$(obj)/raid6int1.c: UNROLL := 1
62$(obj)/raid6int1.c: $(src)/raid6int.uc $(src)/unroll.awk FORCE
63 $(call if_changed,unroll)
64
65targets += raid6int2.c
66$(obj)/raid6int2.c: UNROLL := 2
67$(obj)/raid6int2.c: $(src)/raid6int.uc $(src)/unroll.awk FORCE
68 $(call if_changed,unroll)
69
70targets += raid6int4.c
71$(obj)/raid6int4.c: UNROLL := 4
72$(obj)/raid6int4.c: $(src)/raid6int.uc $(src)/unroll.awk FORCE
73 $(call if_changed,unroll)
74
75targets += raid6int8.c
76$(obj)/raid6int8.c: UNROLL := 8
77$(obj)/raid6int8.c: $(src)/raid6int.uc $(src)/unroll.awk FORCE
78 $(call if_changed,unroll)
79
80targets += raid6int16.c
81$(obj)/raid6int16.c: UNROLL := 16
82$(obj)/raid6int16.c: $(src)/raid6int.uc $(src)/unroll.awk FORCE
83 $(call if_changed,unroll)
84
85targets += raid6int32.c
86$(obj)/raid6int32.c: UNROLL := 32
87$(obj)/raid6int32.c: $(src)/raid6int.uc $(src)/unroll.awk FORCE
88 $(call if_changed,unroll)
89
90CFLAGS_raid6altivec1.o += $(altivec_flags)
91targets += raid6altivec1.c
92$(obj)/raid6altivec1.c: UNROLL := 1
93$(obj)/raid6altivec1.c: $(src)/raid6altivec.uc $(src)/unroll.awk FORCE
94 $(call if_changed,unroll)
95
96CFLAGS_raid6altivec2.o += $(altivec_flags)
97targets += raid6altivec2.c
98$(obj)/raid6altivec2.c: UNROLL := 2
99$(obj)/raid6altivec2.c: $(src)/raid6altivec.uc $(src)/unroll.awk FORCE
100 $(call if_changed,unroll)
101
102CFLAGS_raid6altivec4.o += $(altivec_flags)
103targets += raid6altivec4.c
104$(obj)/raid6altivec4.c: UNROLL := 4
105$(obj)/raid6altivec4.c: $(src)/raid6altivec.uc $(src)/unroll.awk FORCE
106 $(call if_changed,unroll)
107
108CFLAGS_raid6altivec8.o += $(altivec_flags)
109targets += raid6altivec8.c
110$(obj)/raid6altivec8.c: UNROLL := 8
111$(obj)/raid6altivec8.c: $(src)/raid6altivec.uc $(src)/unroll.awk FORCE
112 $(call if_changed,unroll)
113
114quiet_cmd_mktable = TABLE $@
115 cmd_mktable = $(obj)/mktables > $@ || ( rm -f $@ && exit 1 )
116
117targets += raid6tables.c
118$(obj)/raid6tables.c: $(obj)/mktables FORCE
119 $(call if_changed,mktable)
diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
index 1742435ce3ae..1ba1e122e948 100644
--- a/drivers/md/bitmap.c
+++ b/drivers/md/bitmap.c
@@ -13,7 +13,6 @@
13 * Still to do: 13 * Still to do:
14 * 14 *
15 * flush after percent set rather than just time based. (maybe both). 15 * flush after percent set rather than just time based. (maybe both).
16 * wait if count gets too high, wake when it drops to half.
17 */ 16 */
18 17
19#include <linux/blkdev.h> 18#include <linux/blkdev.h>
@@ -30,6 +29,7 @@
30#include "md.h" 29#include "md.h"
31#include "bitmap.h" 30#include "bitmap.h"
32 31
32#include <linux/dm-dirty-log.h>
33/* debug macros */ 33/* debug macros */
34 34
35#define DEBUG 0 35#define DEBUG 0
@@ -51,9 +51,6 @@
51#define INJECT_FATAL_FAULT_3 0 /* undef */ 51#define INJECT_FATAL_FAULT_3 0 /* undef */
52#endif 52#endif
53 53
54//#define DPRINTK PRINTK /* set this NULL to avoid verbose debug output */
55#define DPRINTK(x...) do { } while(0)
56
57#ifndef PRINTK 54#ifndef PRINTK
58# if DEBUG > 0 55# if DEBUG > 0
59# define PRINTK(x...) printk(KERN_DEBUG x) 56# define PRINTK(x...) printk(KERN_DEBUG x)
@@ -62,12 +59,11 @@
62# endif 59# endif
63#endif 60#endif
64 61
65static inline char * bmname(struct bitmap *bitmap) 62static inline char *bmname(struct bitmap *bitmap)
66{ 63{
67 return bitmap->mddev ? mdname(bitmap->mddev) : "mdX"; 64 return bitmap->mddev ? mdname(bitmap->mddev) : "mdX";
68} 65}
69 66
70
71/* 67/*
72 * just a placeholder - calls kmalloc for bitmap pages 68 * just a placeholder - calls kmalloc for bitmap pages
73 */ 69 */
@@ -78,7 +74,7 @@ static unsigned char *bitmap_alloc_page(struct bitmap *bitmap)
78#ifdef INJECT_FAULTS_1 74#ifdef INJECT_FAULTS_1
79 page = NULL; 75 page = NULL;
80#else 76#else
81 page = kmalloc(PAGE_SIZE, GFP_NOIO); 77 page = kzalloc(PAGE_SIZE, GFP_NOIO);
82#endif 78#endif
83 if (!page) 79 if (!page)
84 printk("%s: bitmap_alloc_page FAILED\n", bmname(bitmap)); 80 printk("%s: bitmap_alloc_page FAILED\n", bmname(bitmap));
@@ -107,7 +103,8 @@ static void bitmap_free_page(struct bitmap *bitmap, unsigned char *page)
107 * if we find our page, we increment the page's refcount so that it stays 103 * if we find our page, we increment the page's refcount so that it stays
108 * allocated while we're using it 104 * allocated while we're using it
109 */ 105 */
110static int bitmap_checkpage(struct bitmap *bitmap, unsigned long page, int create) 106static int bitmap_checkpage(struct bitmap *bitmap,
107 unsigned long page, int create)
111__releases(bitmap->lock) 108__releases(bitmap->lock)
112__acquires(bitmap->lock) 109__acquires(bitmap->lock)
113{ 110{
@@ -121,7 +118,6 @@ __acquires(bitmap->lock)
121 return -EINVAL; 118 return -EINVAL;
122 } 119 }
123 120
124
125 if (bitmap->bp[page].hijacked) /* it's hijacked, don't try to alloc */ 121 if (bitmap->bp[page].hijacked) /* it's hijacked, don't try to alloc */
126 return 0; 122 return 0;
127 123
@@ -131,43 +127,34 @@ __acquires(bitmap->lock)
131 if (!create) 127 if (!create)
132 return -ENOENT; 128 return -ENOENT;
133 129
134 spin_unlock_irq(&bitmap->lock);
135
136 /* this page has not been allocated yet */ 130 /* this page has not been allocated yet */
137 131
138 if ((mappage = bitmap_alloc_page(bitmap)) == NULL) { 132 spin_unlock_irq(&bitmap->lock);
133 mappage = bitmap_alloc_page(bitmap);
134 spin_lock_irq(&bitmap->lock);
135
136 if (mappage == NULL) {
139 PRINTK("%s: bitmap map page allocation failed, hijacking\n", 137 PRINTK("%s: bitmap map page allocation failed, hijacking\n",
140 bmname(bitmap)); 138 bmname(bitmap));
141 /* failed - set the hijacked flag so that we can use the 139 /* failed - set the hijacked flag so that we can use the
142 * pointer as a counter */ 140 * pointer as a counter */
143 spin_lock_irq(&bitmap->lock);
144 if (!bitmap->bp[page].map) 141 if (!bitmap->bp[page].map)
145 bitmap->bp[page].hijacked = 1; 142 bitmap->bp[page].hijacked = 1;
146 goto out; 143 } else if (bitmap->bp[page].map ||
147 } 144 bitmap->bp[page].hijacked) {
148
149 /* got a page */
150
151 spin_lock_irq(&bitmap->lock);
152
153 /* recheck the page */
154
155 if (bitmap->bp[page].map || bitmap->bp[page].hijacked) {
156 /* somebody beat us to getting the page */ 145 /* somebody beat us to getting the page */
157 bitmap_free_page(bitmap, mappage); 146 bitmap_free_page(bitmap, mappage);
158 return 0; 147 return 0;
159 } 148 } else {
160 149
161 /* no page was in place and we have one, so install it */ 150 /* no page was in place and we have one, so install it */
162 151
163 memset(mappage, 0, PAGE_SIZE); 152 bitmap->bp[page].map = mappage;
164 bitmap->bp[page].map = mappage; 153 bitmap->missing_pages--;
165 bitmap->missing_pages--; 154 }
166out:
167 return 0; 155 return 0;
168} 156}
169 157
170
171/* if page is completely empty, put it back on the free list, or dealloc it */ 158/* if page is completely empty, put it back on the free list, or dealloc it */
172/* if page was hijacked, unmark the flag so it might get alloced next time */ 159/* if page was hijacked, unmark the flag so it might get alloced next time */
173/* Note: lock should be held when calling this */ 160/* Note: lock should be held when calling this */
@@ -183,26 +170,15 @@ static void bitmap_checkfree(struct bitmap *bitmap, unsigned long page)
183 if (bitmap->bp[page].hijacked) { /* page was hijacked, undo this now */ 170 if (bitmap->bp[page].hijacked) { /* page was hijacked, undo this now */
184 bitmap->bp[page].hijacked = 0; 171 bitmap->bp[page].hijacked = 0;
185 bitmap->bp[page].map = NULL; 172 bitmap->bp[page].map = NULL;
186 return; 173 } else {
174 /* normal case, free the page */
175 ptr = bitmap->bp[page].map;
176 bitmap->bp[page].map = NULL;
177 bitmap->missing_pages++;
178 bitmap_free_page(bitmap, ptr);
187 } 179 }
188
189 /* normal case, free the page */
190
191#if 0
192/* actually ... let's not. We will probably need the page again exactly when
193 * memory is tight and we are flusing to disk
194 */
195 return;
196#else
197 ptr = bitmap->bp[page].map;
198 bitmap->bp[page].map = NULL;
199 bitmap->missing_pages++;
200 bitmap_free_page(bitmap, ptr);
201 return;
202#endif
203} 180}
204 181
205
206/* 182/*
207 * bitmap file handling - read and write the bitmap file and its superblock 183 * bitmap file handling - read and write the bitmap file and its superblock
208 */ 184 */
@@ -220,11 +196,14 @@ static struct page *read_sb_page(mddev_t *mddev, loff_t offset,
220 196
221 mdk_rdev_t *rdev; 197 mdk_rdev_t *rdev;
222 sector_t target; 198 sector_t target;
199 int did_alloc = 0;
223 200
224 if (!page) 201 if (!page) {
225 page = alloc_page(GFP_KERNEL); 202 page = alloc_page(GFP_KERNEL);
226 if (!page) 203 if (!page)
227 return ERR_PTR(-ENOMEM); 204 return ERR_PTR(-ENOMEM);
205 did_alloc = 1;
206 }
228 207
229 list_for_each_entry(rdev, &mddev->disks, same_set) { 208 list_for_each_entry(rdev, &mddev->disks, same_set) {
230 if (! test_bit(In_sync, &rdev->flags) 209 if (! test_bit(In_sync, &rdev->flags)
@@ -242,6 +221,8 @@ static struct page *read_sb_page(mddev_t *mddev, loff_t offset,
242 return page; 221 return page;
243 } 222 }
244 } 223 }
224 if (did_alloc)
225 put_page(page);
245 return ERR_PTR(-EIO); 226 return ERR_PTR(-EIO);
246 227
247} 228}
@@ -286,49 +267,51 @@ static int write_sb_page(struct bitmap *bitmap, struct page *page, int wait)
286 mddev_t *mddev = bitmap->mddev; 267 mddev_t *mddev = bitmap->mddev;
287 268
288 while ((rdev = next_active_rdev(rdev, mddev)) != NULL) { 269 while ((rdev = next_active_rdev(rdev, mddev)) != NULL) {
289 int size = PAGE_SIZE; 270 int size = PAGE_SIZE;
290 loff_t offset = mddev->bitmap_info.offset; 271 loff_t offset = mddev->bitmap_info.offset;
291 if (page->index == bitmap->file_pages-1) 272 if (page->index == bitmap->file_pages-1)
292 size = roundup(bitmap->last_page_size, 273 size = roundup(bitmap->last_page_size,
293 bdev_logical_block_size(rdev->bdev)); 274 bdev_logical_block_size(rdev->bdev));
294 /* Just make sure we aren't corrupting data or 275 /* Just make sure we aren't corrupting data or
295 * metadata 276 * metadata
296 */ 277 */
297 if (mddev->external) { 278 if (mddev->external) {
298 /* Bitmap could be anywhere. */ 279 /* Bitmap could be anywhere. */
299 if (rdev->sb_start + offset + (page->index *(PAGE_SIZE/512)) > 280 if (rdev->sb_start + offset + (page->index
300 rdev->data_offset && 281 * (PAGE_SIZE/512))
301 rdev->sb_start + offset < 282 > rdev->data_offset
302 rdev->data_offset + mddev->dev_sectors + 283 &&
303 (PAGE_SIZE/512)) 284 rdev->sb_start + offset
304 goto bad_alignment; 285 < (rdev->data_offset + mddev->dev_sectors
305 } else if (offset < 0) { 286 + (PAGE_SIZE/512)))
306 /* DATA BITMAP METADATA */ 287 goto bad_alignment;
307 if (offset 288 } else if (offset < 0) {
308 + (long)(page->index * (PAGE_SIZE/512)) 289 /* DATA BITMAP METADATA */
309 + size/512 > 0) 290 if (offset
310 /* bitmap runs in to metadata */ 291 + (long)(page->index * (PAGE_SIZE/512))
311 goto bad_alignment; 292 + size/512 > 0)
312 if (rdev->data_offset + mddev->dev_sectors 293 /* bitmap runs in to metadata */
313 > rdev->sb_start + offset) 294 goto bad_alignment;
314 /* data runs in to bitmap */ 295 if (rdev->data_offset + mddev->dev_sectors
315 goto bad_alignment; 296 > rdev->sb_start + offset)
316 } else if (rdev->sb_start < rdev->data_offset) { 297 /* data runs in to bitmap */
317 /* METADATA BITMAP DATA */ 298 goto bad_alignment;
318 if (rdev->sb_start 299 } else if (rdev->sb_start < rdev->data_offset) {
319 + offset 300 /* METADATA BITMAP DATA */
320 + page->index*(PAGE_SIZE/512) + size/512 301 if (rdev->sb_start
321 > rdev->data_offset) 302 + offset
322 /* bitmap runs in to data */ 303 + page->index*(PAGE_SIZE/512) + size/512
323 goto bad_alignment; 304 > rdev->data_offset)
324 } else { 305 /* bitmap runs in to data */
325 /* DATA METADATA BITMAP - no problems */ 306 goto bad_alignment;
326 } 307 } else {
327 md_super_write(mddev, rdev, 308 /* DATA METADATA BITMAP - no problems */
328 rdev->sb_start + offset 309 }
329 + page->index * (PAGE_SIZE/512), 310 md_super_write(mddev, rdev,
330 size, 311 rdev->sb_start + offset
331 page); 312 + page->index * (PAGE_SIZE/512),
313 size,
314 page);
332 } 315 }
333 316
334 if (wait) 317 if (wait)
@@ -364,10 +347,9 @@ static void write_page(struct bitmap *bitmap, struct page *page, int wait)
364 bh = bh->b_this_page; 347 bh = bh->b_this_page;
365 } 348 }
366 349
367 if (wait) { 350 if (wait)
368 wait_event(bitmap->write_wait, 351 wait_event(bitmap->write_wait,
369 atomic_read(&bitmap->pending_writes)==0); 352 atomic_read(&bitmap->pending_writes)==0);
370 }
371 } 353 }
372 if (bitmap->flags & BITMAP_WRITE_ERROR) 354 if (bitmap->flags & BITMAP_WRITE_ERROR)
373 bitmap_file_kick(bitmap); 355 bitmap_file_kick(bitmap);
@@ -424,7 +406,7 @@ static struct page *read_page(struct file *file, unsigned long index,
424 struct buffer_head *bh; 406 struct buffer_head *bh;
425 sector_t block; 407 sector_t block;
426 408
427 PRINTK("read bitmap file (%dB @ %Lu)\n", (int)PAGE_SIZE, 409 PRINTK("read bitmap file (%dB @ %llu)\n", (int)PAGE_SIZE,
428 (unsigned long long)index << PAGE_SHIFT); 410 (unsigned long long)index << PAGE_SHIFT);
429 411
430 page = alloc_page(GFP_KERNEL); 412 page = alloc_page(GFP_KERNEL);
@@ -478,7 +460,7 @@ static struct page *read_page(struct file *file, unsigned long index,
478 } 460 }
479out: 461out:
480 if (IS_ERR(page)) 462 if (IS_ERR(page))
481 printk(KERN_ALERT "md: bitmap read error: (%dB @ %Lu): %ld\n", 463 printk(KERN_ALERT "md: bitmap read error: (%dB @ %llu): %ld\n",
482 (int)PAGE_SIZE, 464 (int)PAGE_SIZE,
483 (unsigned long long)index << PAGE_SHIFT, 465 (unsigned long long)index << PAGE_SHIFT,
484 PTR_ERR(page)); 466 PTR_ERR(page));
@@ -664,11 +646,14 @@ static int bitmap_mask_state(struct bitmap *bitmap, enum bitmap_state bits,
664 sb = kmap_atomic(bitmap->sb_page, KM_USER0); 646 sb = kmap_atomic(bitmap->sb_page, KM_USER0);
665 old = le32_to_cpu(sb->state) & bits; 647 old = le32_to_cpu(sb->state) & bits;
666 switch (op) { 648 switch (op) {
667 case MASK_SET: sb->state |= cpu_to_le32(bits); 649 case MASK_SET:
668 break; 650 sb->state |= cpu_to_le32(bits);
669 case MASK_UNSET: sb->state &= cpu_to_le32(~bits); 651 break;
670 break; 652 case MASK_UNSET:
671 default: BUG(); 653 sb->state &= cpu_to_le32(~bits);
654 break;
655 default:
656 BUG();
672 } 657 }
673 kunmap_atomic(sb, KM_USER0); 658 kunmap_atomic(sb, KM_USER0);
674 return old; 659 return old;
@@ -710,12 +695,14 @@ static inline unsigned long file_page_offset(struct bitmap *bitmap, unsigned lon
710static inline struct page *filemap_get_page(struct bitmap *bitmap, 695static inline struct page *filemap_get_page(struct bitmap *bitmap,
711 unsigned long chunk) 696 unsigned long chunk)
712{ 697{
713 if (file_page_index(bitmap, chunk) >= bitmap->file_pages) return NULL; 698 if (bitmap->filemap == NULL)
699 return NULL;
700 if (file_page_index(bitmap, chunk) >= bitmap->file_pages)
701 return NULL;
714 return bitmap->filemap[file_page_index(bitmap, chunk) 702 return bitmap->filemap[file_page_index(bitmap, chunk)
715 - file_page_index(bitmap, 0)]; 703 - file_page_index(bitmap, 0)];
716} 704}
717 705
718
719static void bitmap_file_unmap(struct bitmap *bitmap) 706static void bitmap_file_unmap(struct bitmap *bitmap)
720{ 707{
721 struct page **map, *sb_page; 708 struct page **map, *sb_page;
@@ -766,7 +753,6 @@ static void bitmap_file_put(struct bitmap *bitmap)
766 } 753 }
767} 754}
768 755
769
770/* 756/*
771 * bitmap_file_kick - if an error occurs while manipulating the bitmap file 757 * bitmap_file_kick - if an error occurs while manipulating the bitmap file
772 * then it is no longer reliable, so we stop using it and we mark the file 758 * then it is no longer reliable, so we stop using it and we mark the file
@@ -785,7 +771,6 @@ static void bitmap_file_kick(struct bitmap *bitmap)
785 ptr = d_path(&bitmap->file->f_path, path, 771 ptr = d_path(&bitmap->file->f_path, path,
786 PAGE_SIZE); 772 PAGE_SIZE);
787 773
788
789 printk(KERN_ALERT 774 printk(KERN_ALERT
790 "%s: kicking failed bitmap file %s from array!\n", 775 "%s: kicking failed bitmap file %s from array!\n",
791 bmname(bitmap), IS_ERR(ptr) ? "" : ptr); 776 bmname(bitmap), IS_ERR(ptr) ? "" : ptr);
@@ -803,27 +788,36 @@ static void bitmap_file_kick(struct bitmap *bitmap)
803} 788}
804 789
805enum bitmap_page_attr { 790enum bitmap_page_attr {
806 BITMAP_PAGE_DIRTY = 0, // there are set bits that need to be synced 791 BITMAP_PAGE_DIRTY = 0, /* there are set bits that need to be synced */
807 BITMAP_PAGE_CLEAN = 1, // there are bits that might need to be cleared 792 BITMAP_PAGE_CLEAN = 1, /* there are bits that might need to be cleared */
808 BITMAP_PAGE_NEEDWRITE=2, // there are cleared bits that need to be synced 793 BITMAP_PAGE_NEEDWRITE = 2, /* there are cleared bits that need to be synced */
809}; 794};
810 795
811static inline void set_page_attr(struct bitmap *bitmap, struct page *page, 796static inline void set_page_attr(struct bitmap *bitmap, struct page *page,
812 enum bitmap_page_attr attr) 797 enum bitmap_page_attr attr)
813{ 798{
814 __set_bit((page->index<<2) + attr, bitmap->filemap_attr); 799 if (page)
800 __set_bit((page->index<<2) + attr, bitmap->filemap_attr);
801 else
802 __set_bit(attr, &bitmap->logattrs);
815} 803}
816 804
817static inline void clear_page_attr(struct bitmap *bitmap, struct page *page, 805static inline void clear_page_attr(struct bitmap *bitmap, struct page *page,
818 enum bitmap_page_attr attr) 806 enum bitmap_page_attr attr)
819{ 807{
820 __clear_bit((page->index<<2) + attr, bitmap->filemap_attr); 808 if (page)
809 __clear_bit((page->index<<2) + attr, bitmap->filemap_attr);
810 else
811 __clear_bit(attr, &bitmap->logattrs);
821} 812}
822 813
823static inline unsigned long test_page_attr(struct bitmap *bitmap, struct page *page, 814static inline unsigned long test_page_attr(struct bitmap *bitmap, struct page *page,
824 enum bitmap_page_attr attr) 815 enum bitmap_page_attr attr)
825{ 816{
826 return test_bit((page->index<<2) + attr, bitmap->filemap_attr); 817 if (page)
818 return test_bit((page->index<<2) + attr, bitmap->filemap_attr);
819 else
820 return test_bit(attr, &bitmap->logattrs);
827} 821}
828 822
829/* 823/*
@@ -836,30 +830,32 @@ static inline unsigned long test_page_attr(struct bitmap *bitmap, struct page *p
836static void bitmap_file_set_bit(struct bitmap *bitmap, sector_t block) 830static void bitmap_file_set_bit(struct bitmap *bitmap, sector_t block)
837{ 831{
838 unsigned long bit; 832 unsigned long bit;
839 struct page *page; 833 struct page *page = NULL;
840 void *kaddr; 834 void *kaddr;
841 unsigned long chunk = block >> CHUNK_BLOCK_SHIFT(bitmap); 835 unsigned long chunk = block >> CHUNK_BLOCK_SHIFT(bitmap);
842 836
843 if (!bitmap->filemap) { 837 if (!bitmap->filemap) {
844 return; 838 struct dm_dirty_log *log = bitmap->mddev->bitmap_info.log;
845 } 839 if (log)
846 840 log->type->mark_region(log, chunk);
847 page = filemap_get_page(bitmap, chunk); 841 } else {
848 if (!page) return;
849 bit = file_page_offset(bitmap, chunk);
850 842
851 /* set the bit */ 843 page = filemap_get_page(bitmap, chunk);
852 kaddr = kmap_atomic(page, KM_USER0); 844 if (!page)
853 if (bitmap->flags & BITMAP_HOSTENDIAN) 845 return;
854 set_bit(bit, kaddr); 846 bit = file_page_offset(bitmap, chunk);
855 else
856 ext2_set_bit(bit, kaddr);
857 kunmap_atomic(kaddr, KM_USER0);
858 PRINTK("set file bit %lu page %lu\n", bit, page->index);
859 847
848 /* set the bit */
849 kaddr = kmap_atomic(page, KM_USER0);
850 if (bitmap->flags & BITMAP_HOSTENDIAN)
851 set_bit(bit, kaddr);
852 else
853 ext2_set_bit(bit, kaddr);
854 kunmap_atomic(kaddr, KM_USER0);
855 PRINTK("set file bit %lu page %lu\n", bit, page->index);
856 }
860 /* record page number so it gets flushed to disk when unplug occurs */ 857 /* record page number so it gets flushed to disk when unplug occurs */
861 set_page_attr(bitmap, page, BITMAP_PAGE_DIRTY); 858 set_page_attr(bitmap, page, BITMAP_PAGE_DIRTY);
862
863} 859}
864 860
865/* this gets called when the md device is ready to unplug its underlying 861/* this gets called when the md device is ready to unplug its underlying
@@ -874,6 +870,16 @@ void bitmap_unplug(struct bitmap *bitmap)
874 870
875 if (!bitmap) 871 if (!bitmap)
876 return; 872 return;
873 if (!bitmap->filemap) {
874 /* Must be using a dirty_log */
875 struct dm_dirty_log *log = bitmap->mddev->bitmap_info.log;
876 dirty = test_and_clear_bit(BITMAP_PAGE_DIRTY, &bitmap->logattrs);
877 need_write = test_and_clear_bit(BITMAP_PAGE_NEEDWRITE, &bitmap->logattrs);
878 if (dirty || need_write)
879 if (log->type->flush(log))
880 bitmap->flags |= BITMAP_WRITE_ERROR;
881 goto out;
882 }
877 883
878 /* look at each page to see if there are any set bits that need to be 884 /* look at each page to see if there are any set bits that need to be
879 * flushed out to disk */ 885 * flushed out to disk */
@@ -892,7 +898,7 @@ void bitmap_unplug(struct bitmap *bitmap)
892 wait = 1; 898 wait = 1;
893 spin_unlock_irqrestore(&bitmap->lock, flags); 899 spin_unlock_irqrestore(&bitmap->lock, flags);
894 900
895 if (dirty | need_write) 901 if (dirty || need_write)
896 write_page(bitmap, page, 0); 902 write_page(bitmap, page, 0);
897 } 903 }
898 if (wait) { /* if any writes were performed, we need to wait on them */ 904 if (wait) { /* if any writes were performed, we need to wait on them */
@@ -902,9 +908,11 @@ void bitmap_unplug(struct bitmap *bitmap)
902 else 908 else
903 md_super_wait(bitmap->mddev); 909 md_super_wait(bitmap->mddev);
904 } 910 }
911out:
905 if (bitmap->flags & BITMAP_WRITE_ERROR) 912 if (bitmap->flags & BITMAP_WRITE_ERROR)
906 bitmap_file_kick(bitmap); 913 bitmap_file_kick(bitmap);
907} 914}
915EXPORT_SYMBOL(bitmap_unplug);
908 916
909static void bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset, int needed); 917static void bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset, int needed);
910/* * bitmap_init_from_disk -- called at bitmap_create time to initialize 918/* * bitmap_init_from_disk -- called at bitmap_create time to initialize
@@ -943,12 +951,11 @@ static int bitmap_init_from_disk(struct bitmap *bitmap, sector_t start)
943 printk(KERN_INFO "%s: bitmap file is out of date, doing full " 951 printk(KERN_INFO "%s: bitmap file is out of date, doing full "
944 "recovery\n", bmname(bitmap)); 952 "recovery\n", bmname(bitmap));
945 953
946 bytes = (chunks + 7) / 8; 954 bytes = DIV_ROUND_UP(bitmap->chunks, 8);
947 if (!bitmap->mddev->bitmap_info.external) 955 if (!bitmap->mddev->bitmap_info.external)
948 bytes += sizeof(bitmap_super_t); 956 bytes += sizeof(bitmap_super_t);
949 957
950 958 num_pages = DIV_ROUND_UP(bytes, PAGE_SIZE);
951 num_pages = (bytes + PAGE_SIZE - 1) / PAGE_SIZE;
952 959
953 if (file && i_size_read(file->f_mapping->host) < bytes) { 960 if (file && i_size_read(file->f_mapping->host) < bytes) {
954 printk(KERN_INFO "%s: bitmap file too short %lu < %lu\n", 961 printk(KERN_INFO "%s: bitmap file too short %lu < %lu\n",
@@ -966,7 +973,7 @@ static int bitmap_init_from_disk(struct bitmap *bitmap, sector_t start)
966 973
967 /* We need 4 bits per page, rounded up to a multiple of sizeof(unsigned long) */ 974 /* We need 4 bits per page, rounded up to a multiple of sizeof(unsigned long) */
968 bitmap->filemap_attr = kzalloc( 975 bitmap->filemap_attr = kzalloc(
969 roundup( DIV_ROUND_UP(num_pages*4, 8), sizeof(unsigned long)), 976 roundup(DIV_ROUND_UP(num_pages*4, 8), sizeof(unsigned long)),
970 GFP_KERNEL); 977 GFP_KERNEL);
971 if (!bitmap->filemap_attr) 978 if (!bitmap->filemap_attr)
972 goto err; 979 goto err;
@@ -1021,7 +1028,7 @@ static int bitmap_init_from_disk(struct bitmap *bitmap, sector_t start)
1021 if (outofdate) { 1028 if (outofdate) {
1022 /* 1029 /*
1023 * if bitmap is out of date, dirty the 1030 * if bitmap is out of date, dirty the
1024 * whole page and write it out 1031 * whole page and write it out
1025 */ 1032 */
1026 paddr = kmap_atomic(page, KM_USER0); 1033 paddr = kmap_atomic(page, KM_USER0);
1027 memset(paddr + offset, 0xff, 1034 memset(paddr + offset, 0xff,
@@ -1052,7 +1059,7 @@ static int bitmap_init_from_disk(struct bitmap *bitmap, sector_t start)
1052 } 1059 }
1053 } 1060 }
1054 1061
1055 /* everything went OK */ 1062 /* everything went OK */
1056 ret = 0; 1063 ret = 0;
1057 bitmap_mask_state(bitmap, BITMAP_STALE, MASK_UNSET); 1064 bitmap_mask_state(bitmap, BITMAP_STALE, MASK_UNSET);
1058 1065
@@ -1080,21 +1087,16 @@ void bitmap_write_all(struct bitmap *bitmap)
1080 */ 1087 */
1081 int i; 1088 int i;
1082 1089
1083 for (i=0; i < bitmap->file_pages; i++) 1090 for (i = 0; i < bitmap->file_pages; i++)
1084 set_page_attr(bitmap, bitmap->filemap[i], 1091 set_page_attr(bitmap, bitmap->filemap[i],
1085 BITMAP_PAGE_NEEDWRITE); 1092 BITMAP_PAGE_NEEDWRITE);
1086} 1093}
1087 1094
1088
1089static void bitmap_count_page(struct bitmap *bitmap, sector_t offset, int inc) 1095static void bitmap_count_page(struct bitmap *bitmap, sector_t offset, int inc)
1090{ 1096{
1091 sector_t chunk = offset >> CHUNK_BLOCK_SHIFT(bitmap); 1097 sector_t chunk = offset >> CHUNK_BLOCK_SHIFT(bitmap);
1092 unsigned long page = chunk >> PAGE_COUNTER_SHIFT; 1098 unsigned long page = chunk >> PAGE_COUNTER_SHIFT;
1093 bitmap->bp[page].count += inc; 1099 bitmap->bp[page].count += inc;
1094/*
1095 if (page == 0) printk("count page 0, offset %llu: %d gives %d\n",
1096 (unsigned long long)offset, inc, bitmap->bp[page].count);
1097*/
1098 bitmap_checkfree(bitmap, page); 1100 bitmap_checkfree(bitmap, page);
1099} 1101}
1100static bitmap_counter_t *bitmap_get_counter(struct bitmap *bitmap, 1102static bitmap_counter_t *bitmap_get_counter(struct bitmap *bitmap,
@@ -1114,6 +1116,7 @@ void bitmap_daemon_work(mddev_t *mddev)
1114 struct page *page = NULL, *lastpage = NULL; 1116 struct page *page = NULL, *lastpage = NULL;
1115 int blocks; 1117 int blocks;
1116 void *paddr; 1118 void *paddr;
1119 struct dm_dirty_log *log = mddev->bitmap_info.log;
1117 1120
1118 /* Use a mutex to guard daemon_work against 1121 /* Use a mutex to guard daemon_work against
1119 * bitmap_destroy. 1122 * bitmap_destroy.
@@ -1138,11 +1141,12 @@ void bitmap_daemon_work(mddev_t *mddev)
1138 spin_lock_irqsave(&bitmap->lock, flags); 1141 spin_lock_irqsave(&bitmap->lock, flags);
1139 for (j = 0; j < bitmap->chunks; j++) { 1142 for (j = 0; j < bitmap->chunks; j++) {
1140 bitmap_counter_t *bmc; 1143 bitmap_counter_t *bmc;
1141 if (!bitmap->filemap) 1144 if (!bitmap->filemap) {
1142 /* error or shutdown */ 1145 if (!log)
1143 break; 1146 /* error or shutdown */
1144 1147 break;
1145 page = filemap_get_page(bitmap, j); 1148 } else
1149 page = filemap_get_page(bitmap, j);
1146 1150
1147 if (page != lastpage) { 1151 if (page != lastpage) {
1148 /* skip this page unless it's marked as needing cleaning */ 1152 /* skip this page unless it's marked as needing cleaning */
@@ -1197,14 +1201,11 @@ void bitmap_daemon_work(mddev_t *mddev)
1197 (sector_t)j << CHUNK_BLOCK_SHIFT(bitmap), 1201 (sector_t)j << CHUNK_BLOCK_SHIFT(bitmap),
1198 &blocks, 0); 1202 &blocks, 0);
1199 if (bmc) { 1203 if (bmc) {
1200/*
1201 if (j < 100) printk("bitmap: j=%lu, *bmc = 0x%x\n", j, *bmc);
1202*/
1203 if (*bmc) 1204 if (*bmc)
1204 bitmap->allclean = 0; 1205 bitmap->allclean = 0;
1205 1206
1206 if (*bmc == 2) { 1207 if (*bmc == 2) {
1207 *bmc=1; /* maybe clear the bit next time */ 1208 *bmc = 1; /* maybe clear the bit next time */
1208 set_page_attr(bitmap, page, BITMAP_PAGE_CLEAN); 1209 set_page_attr(bitmap, page, BITMAP_PAGE_CLEAN);
1209 } else if (*bmc == 1 && !bitmap->need_sync) { 1210 } else if (*bmc == 1 && !bitmap->need_sync) {
1210 /* we can clear the bit */ 1211 /* we can clear the bit */
@@ -1214,14 +1215,17 @@ void bitmap_daemon_work(mddev_t *mddev)
1214 -1); 1215 -1);
1215 1216
1216 /* clear the bit */ 1217 /* clear the bit */
1217 paddr = kmap_atomic(page, KM_USER0); 1218 if (page) {
1218 if (bitmap->flags & BITMAP_HOSTENDIAN) 1219 paddr = kmap_atomic(page, KM_USER0);
1219 clear_bit(file_page_offset(bitmap, j), 1220 if (bitmap->flags & BITMAP_HOSTENDIAN)
1220 paddr); 1221 clear_bit(file_page_offset(bitmap, j),
1221 else 1222 paddr);
1222 ext2_clear_bit(file_page_offset(bitmap, j), 1223 else
1223 paddr); 1224 ext2_clear_bit(file_page_offset(bitmap, j),
1224 kunmap_atomic(paddr, KM_USER0); 1225 paddr);
1226 kunmap_atomic(paddr, KM_USER0);
1227 } else
1228 log->type->clear_region(log, j);
1225 } 1229 }
1226 } else 1230 } else
1227 j |= PAGE_COUNTER_MASK; 1231 j |= PAGE_COUNTER_MASK;
@@ -1229,12 +1233,16 @@ void bitmap_daemon_work(mddev_t *mddev)
1229 spin_unlock_irqrestore(&bitmap->lock, flags); 1233 spin_unlock_irqrestore(&bitmap->lock, flags);
1230 1234
1231 /* now sync the final page */ 1235 /* now sync the final page */
1232 if (lastpage != NULL) { 1236 if (lastpage != NULL || log != NULL) {
1233 spin_lock_irqsave(&bitmap->lock, flags); 1237 spin_lock_irqsave(&bitmap->lock, flags);
1234 if (test_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE)) { 1238 if (test_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE)) {
1235 clear_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE); 1239 clear_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE);
1236 spin_unlock_irqrestore(&bitmap->lock, flags); 1240 spin_unlock_irqrestore(&bitmap->lock, flags);
1237 write_page(bitmap, lastpage, 0); 1241 if (lastpage)
1242 write_page(bitmap, lastpage, 0);
1243 else
1244 if (log->type->flush(log))
1245 bitmap->flags |= BITMAP_WRITE_ERROR;
1238 } else { 1246 } else {
1239 set_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE); 1247 set_page_attr(bitmap, lastpage, BITMAP_PAGE_NEEDWRITE);
1240 spin_unlock_irqrestore(&bitmap->lock, flags); 1248 spin_unlock_irqrestore(&bitmap->lock, flags);
@@ -1243,7 +1251,7 @@ void bitmap_daemon_work(mddev_t *mddev)
1243 1251
1244 done: 1252 done:
1245 if (bitmap->allclean == 0) 1253 if (bitmap->allclean == 0)
1246 bitmap->mddev->thread->timeout = 1254 bitmap->mddev->thread->timeout =
1247 bitmap->mddev->bitmap_info.daemon_sleep; 1255 bitmap->mddev->bitmap_info.daemon_sleep;
1248 mutex_unlock(&mddev->bitmap_info.mutex); 1256 mutex_unlock(&mddev->bitmap_info.mutex);
1249} 1257}
@@ -1262,34 +1270,38 @@ __acquires(bitmap->lock)
1262 unsigned long page = chunk >> PAGE_COUNTER_SHIFT; 1270 unsigned long page = chunk >> PAGE_COUNTER_SHIFT;
1263 unsigned long pageoff = (chunk & PAGE_COUNTER_MASK) << COUNTER_BYTE_SHIFT; 1271 unsigned long pageoff = (chunk & PAGE_COUNTER_MASK) << COUNTER_BYTE_SHIFT;
1264 sector_t csize; 1272 sector_t csize;
1273 int err;
1265 1274
1266 if (bitmap_checkpage(bitmap, page, create) < 0) { 1275 err = bitmap_checkpage(bitmap, page, create);
1276
1277 if (bitmap->bp[page].hijacked ||
1278 bitmap->bp[page].map == NULL)
1279 csize = ((sector_t)1) << (CHUNK_BLOCK_SHIFT(bitmap) +
1280 PAGE_COUNTER_SHIFT - 1);
1281 else
1267 csize = ((sector_t)1) << (CHUNK_BLOCK_SHIFT(bitmap)); 1282 csize = ((sector_t)1) << (CHUNK_BLOCK_SHIFT(bitmap));
1268 *blocks = csize - (offset & (csize- 1)); 1283 *blocks = csize - (offset & (csize - 1));
1284
1285 if (err < 0)
1269 return NULL; 1286 return NULL;
1270 } 1287
1271 /* now locked ... */ 1288 /* now locked ... */
1272 1289
1273 if (bitmap->bp[page].hijacked) { /* hijacked pointer */ 1290 if (bitmap->bp[page].hijacked) { /* hijacked pointer */
1274 /* should we use the first or second counter field 1291 /* should we use the first or second counter field
1275 * of the hijacked pointer? */ 1292 * of the hijacked pointer? */
1276 int hi = (pageoff > PAGE_COUNTER_MASK); 1293 int hi = (pageoff > PAGE_COUNTER_MASK);
1277 csize = ((sector_t)1) << (CHUNK_BLOCK_SHIFT(bitmap) +
1278 PAGE_COUNTER_SHIFT - 1);
1279 *blocks = csize - (offset & (csize- 1));
1280 return &((bitmap_counter_t *) 1294 return &((bitmap_counter_t *)
1281 &bitmap->bp[page].map)[hi]; 1295 &bitmap->bp[page].map)[hi];
1282 } else { /* page is allocated */ 1296 } else /* page is allocated */
1283 csize = ((sector_t)1) << (CHUNK_BLOCK_SHIFT(bitmap));
1284 *blocks = csize - (offset & (csize- 1));
1285 return (bitmap_counter_t *) 1297 return (bitmap_counter_t *)
1286 &(bitmap->bp[page].map[pageoff]); 1298 &(bitmap->bp[page].map[pageoff]);
1287 }
1288} 1299}
1289 1300
1290int bitmap_startwrite(struct bitmap *bitmap, sector_t offset, unsigned long sectors, int behind) 1301int bitmap_startwrite(struct bitmap *bitmap, sector_t offset, unsigned long sectors, int behind)
1291{ 1302{
1292 if (!bitmap) return 0; 1303 if (!bitmap)
1304 return 0;
1293 1305
1294 if (behind) { 1306 if (behind) {
1295 int bw; 1307 int bw;
@@ -1322,17 +1334,16 @@ int bitmap_startwrite(struct bitmap *bitmap, sector_t offset, unsigned long sect
1322 prepare_to_wait(&bitmap->overflow_wait, &__wait, 1334 prepare_to_wait(&bitmap->overflow_wait, &__wait,
1323 TASK_UNINTERRUPTIBLE); 1335 TASK_UNINTERRUPTIBLE);
1324 spin_unlock_irq(&bitmap->lock); 1336 spin_unlock_irq(&bitmap->lock);
1325 blk_unplug(bitmap->mddev->queue); 1337 md_unplug(bitmap->mddev);
1326 schedule(); 1338 schedule();
1327 finish_wait(&bitmap->overflow_wait, &__wait); 1339 finish_wait(&bitmap->overflow_wait, &__wait);
1328 continue; 1340 continue;
1329 } 1341 }
1330 1342
1331 switch(*bmc) { 1343 switch (*bmc) {
1332 case 0: 1344 case 0:
1333 bitmap_file_set_bit(bitmap, offset); 1345 bitmap_file_set_bit(bitmap, offset);
1334 bitmap_count_page(bitmap,offset, 1); 1346 bitmap_count_page(bitmap, offset, 1);
1335 blk_plug_device_unlocked(bitmap->mddev->queue);
1336 /* fall through */ 1347 /* fall through */
1337 case 1: 1348 case 1:
1338 *bmc = 2; 1349 *bmc = 2;
@@ -1345,16 +1356,19 @@ int bitmap_startwrite(struct bitmap *bitmap, sector_t offset, unsigned long sect
1345 offset += blocks; 1356 offset += blocks;
1346 if (sectors > blocks) 1357 if (sectors > blocks)
1347 sectors -= blocks; 1358 sectors -= blocks;
1348 else sectors = 0; 1359 else
1360 sectors = 0;
1349 } 1361 }
1350 bitmap->allclean = 0; 1362 bitmap->allclean = 0;
1351 return 0; 1363 return 0;
1352} 1364}
1365EXPORT_SYMBOL(bitmap_startwrite);
1353 1366
1354void bitmap_endwrite(struct bitmap *bitmap, sector_t offset, unsigned long sectors, 1367void bitmap_endwrite(struct bitmap *bitmap, sector_t offset, unsigned long sectors,
1355 int success, int behind) 1368 int success, int behind)
1356{ 1369{
1357 if (!bitmap) return; 1370 if (!bitmap)
1371 return;
1358 if (behind) { 1372 if (behind) {
1359 if (atomic_dec_and_test(&bitmap->behind_writes)) 1373 if (atomic_dec_and_test(&bitmap->behind_writes))
1360 wake_up(&bitmap->behind_wait); 1374 wake_up(&bitmap->behind_wait);
@@ -1381,7 +1395,7 @@ void bitmap_endwrite(struct bitmap *bitmap, sector_t offset, unsigned long secto
1381 bitmap->events_cleared < bitmap->mddev->events) { 1395 bitmap->events_cleared < bitmap->mddev->events) {
1382 bitmap->events_cleared = bitmap->mddev->events; 1396 bitmap->events_cleared = bitmap->mddev->events;
1383 bitmap->need_sync = 1; 1397 bitmap->need_sync = 1;
1384 sysfs_notify_dirent(bitmap->sysfs_can_clear); 1398 sysfs_notify_dirent_safe(bitmap->sysfs_can_clear);
1385 } 1399 }
1386 1400
1387 if (!success && ! (*bmc & NEEDED_MASK)) 1401 if (!success && ! (*bmc & NEEDED_MASK))
@@ -1391,18 +1405,22 @@ void bitmap_endwrite(struct bitmap *bitmap, sector_t offset, unsigned long secto
1391 wake_up(&bitmap->overflow_wait); 1405 wake_up(&bitmap->overflow_wait);
1392 1406
1393 (*bmc)--; 1407 (*bmc)--;
1394 if (*bmc <= 2) { 1408 if (*bmc <= 2)
1395 set_page_attr(bitmap, 1409 set_page_attr(bitmap,
1396 filemap_get_page(bitmap, offset >> CHUNK_BLOCK_SHIFT(bitmap)), 1410 filemap_get_page(
1411 bitmap,
1412 offset >> CHUNK_BLOCK_SHIFT(bitmap)),
1397 BITMAP_PAGE_CLEAN); 1413 BITMAP_PAGE_CLEAN);
1398 } 1414
1399 spin_unlock_irqrestore(&bitmap->lock, flags); 1415 spin_unlock_irqrestore(&bitmap->lock, flags);
1400 offset += blocks; 1416 offset += blocks;
1401 if (sectors > blocks) 1417 if (sectors > blocks)
1402 sectors -= blocks; 1418 sectors -= blocks;
1403 else sectors = 0; 1419 else
1420 sectors = 0;
1404 } 1421 }
1405} 1422}
1423EXPORT_SYMBOL(bitmap_endwrite);
1406 1424
1407static int __bitmap_start_sync(struct bitmap *bitmap, sector_t offset, int *blocks, 1425static int __bitmap_start_sync(struct bitmap *bitmap, sector_t offset, int *blocks,
1408 int degraded) 1426 int degraded)
@@ -1455,14 +1473,14 @@ int bitmap_start_sync(struct bitmap *bitmap, sector_t offset, int *blocks,
1455 } 1473 }
1456 return rv; 1474 return rv;
1457} 1475}
1476EXPORT_SYMBOL(bitmap_start_sync);
1458 1477
1459void bitmap_end_sync(struct bitmap *bitmap, sector_t offset, int *blocks, int aborted) 1478void bitmap_end_sync(struct bitmap *bitmap, sector_t offset, int *blocks, int aborted)
1460{ 1479{
1461 bitmap_counter_t *bmc; 1480 bitmap_counter_t *bmc;
1462 unsigned long flags; 1481 unsigned long flags;
1463/* 1482
1464 if (offset == 0) printk("bitmap_end_sync 0 (%d)\n", aborted); 1483 if (bitmap == NULL) {
1465*/ if (bitmap == NULL) {
1466 *blocks = 1024; 1484 *blocks = 1024;
1467 return; 1485 return;
1468 } 1486 }
@@ -1471,26 +1489,23 @@ void bitmap_end_sync(struct bitmap *bitmap, sector_t offset, int *blocks, int ab
1471 if (bmc == NULL) 1489 if (bmc == NULL)
1472 goto unlock; 1490 goto unlock;
1473 /* locked */ 1491 /* locked */
1474/*
1475 if (offset == 0) printk("bitmap_end sync found 0x%x, blocks %d\n", *bmc, *blocks);
1476*/
1477 if (RESYNC(*bmc)) { 1492 if (RESYNC(*bmc)) {
1478 *bmc &= ~RESYNC_MASK; 1493 *bmc &= ~RESYNC_MASK;
1479 1494
1480 if (!NEEDED(*bmc) && aborted) 1495 if (!NEEDED(*bmc) && aborted)
1481 *bmc |= NEEDED_MASK; 1496 *bmc |= NEEDED_MASK;
1482 else { 1497 else {
1483 if (*bmc <= 2) { 1498 if (*bmc <= 2)
1484 set_page_attr(bitmap, 1499 set_page_attr(bitmap,
1485 filemap_get_page(bitmap, offset >> CHUNK_BLOCK_SHIFT(bitmap)), 1500 filemap_get_page(bitmap, offset >> CHUNK_BLOCK_SHIFT(bitmap)),
1486 BITMAP_PAGE_CLEAN); 1501 BITMAP_PAGE_CLEAN);
1487 }
1488 } 1502 }
1489 } 1503 }
1490 unlock: 1504 unlock:
1491 spin_unlock_irqrestore(&bitmap->lock, flags); 1505 spin_unlock_irqrestore(&bitmap->lock, flags);
1492 bitmap->allclean = 0; 1506 bitmap->allclean = 0;
1493} 1507}
1508EXPORT_SYMBOL(bitmap_end_sync);
1494 1509
1495void bitmap_close_sync(struct bitmap *bitmap) 1510void bitmap_close_sync(struct bitmap *bitmap)
1496{ 1511{
@@ -1507,6 +1522,7 @@ void bitmap_close_sync(struct bitmap *bitmap)
1507 sector += blocks; 1522 sector += blocks;
1508 } 1523 }
1509} 1524}
1525EXPORT_SYMBOL(bitmap_close_sync);
1510 1526
1511void bitmap_cond_end_sync(struct bitmap *bitmap, sector_t sector) 1527void bitmap_cond_end_sync(struct bitmap *bitmap, sector_t sector)
1512{ 1528{
@@ -1526,7 +1542,8 @@ void bitmap_cond_end_sync(struct bitmap *bitmap, sector_t sector)
1526 atomic_read(&bitmap->mddev->recovery_active) == 0); 1542 atomic_read(&bitmap->mddev->recovery_active) == 0);
1527 1543
1528 bitmap->mddev->curr_resync_completed = bitmap->mddev->curr_resync; 1544 bitmap->mddev->curr_resync_completed = bitmap->mddev->curr_resync;
1529 set_bit(MD_CHANGE_CLEAN, &bitmap->mddev->flags); 1545 if (bitmap->mddev->persistent)
1546 set_bit(MD_CHANGE_CLEAN, &bitmap->mddev->flags);
1530 sector &= ~((1ULL << CHUNK_BLOCK_SHIFT(bitmap)) - 1); 1547 sector &= ~((1ULL << CHUNK_BLOCK_SHIFT(bitmap)) - 1);
1531 s = 0; 1548 s = 0;
1532 while (s < sector && s < bitmap->mddev->resync_max_sectors) { 1549 while (s < sector && s < bitmap->mddev->resync_max_sectors) {
@@ -1536,6 +1553,7 @@ void bitmap_cond_end_sync(struct bitmap *bitmap, sector_t sector)
1536 bitmap->last_end_sync = jiffies; 1553 bitmap->last_end_sync = jiffies;
1537 sysfs_notify(&bitmap->mddev->kobj, NULL, "sync_completed"); 1554 sysfs_notify(&bitmap->mddev->kobj, NULL, "sync_completed");
1538} 1555}
1556EXPORT_SYMBOL(bitmap_cond_end_sync);
1539 1557
1540static void bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset, int needed) 1558static void bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset, int needed)
1541{ 1559{
@@ -1552,9 +1570,9 @@ static void bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset, int n
1552 spin_unlock_irq(&bitmap->lock); 1570 spin_unlock_irq(&bitmap->lock);
1553 return; 1571 return;
1554 } 1572 }
1555 if (! *bmc) { 1573 if (!*bmc) {
1556 struct page *page; 1574 struct page *page;
1557 *bmc = 1 | (needed?NEEDED_MASK:0); 1575 *bmc = 1 | (needed ? NEEDED_MASK : 0);
1558 bitmap_count_page(bitmap, offset, 1); 1576 bitmap_count_page(bitmap, offset, 1);
1559 page = filemap_get_page(bitmap, offset >> CHUNK_BLOCK_SHIFT(bitmap)); 1577 page = filemap_get_page(bitmap, offset >> CHUNK_BLOCK_SHIFT(bitmap));
1560 set_page_attr(bitmap, page, BITMAP_PAGE_CLEAN); 1578 set_page_attr(bitmap, page, BITMAP_PAGE_CLEAN);
@@ -1663,15 +1681,17 @@ int bitmap_create(mddev_t *mddev)
1663 unsigned long pages; 1681 unsigned long pages;
1664 struct file *file = mddev->bitmap_info.file; 1682 struct file *file = mddev->bitmap_info.file;
1665 int err; 1683 int err;
1666 sector_t start; 1684 struct sysfs_dirent *bm = NULL;
1667 struct sysfs_dirent *bm;
1668 1685
1669 BUILD_BUG_ON(sizeof(bitmap_super_t) != 256); 1686 BUILD_BUG_ON(sizeof(bitmap_super_t) != 256);
1670 1687
1671 if (!file && !mddev->bitmap_info.offset) /* bitmap disabled, nothing to do */ 1688 if (!file
1689 && !mddev->bitmap_info.offset
1690 && !mddev->bitmap_info.log) /* bitmap disabled, nothing to do */
1672 return 0; 1691 return 0;
1673 1692
1674 BUG_ON(file && mddev->bitmap_info.offset); 1693 BUG_ON(file && mddev->bitmap_info.offset);
1694 BUG_ON(mddev->bitmap_info.offset && mddev->bitmap_info.log);
1675 1695
1676 bitmap = kzalloc(sizeof(*bitmap), GFP_KERNEL); 1696 bitmap = kzalloc(sizeof(*bitmap), GFP_KERNEL);
1677 if (!bitmap) 1697 if (!bitmap)
@@ -1685,7 +1705,8 @@ int bitmap_create(mddev_t *mddev)
1685 1705
1686 bitmap->mddev = mddev; 1706 bitmap->mddev = mddev;
1687 1707
1688 bm = sysfs_get_dirent(mddev->kobj.sd, NULL, "bitmap"); 1708 if (mddev->kobj.sd)
1709 bm = sysfs_get_dirent(mddev->kobj.sd, NULL, "bitmap");
1689 if (bm) { 1710 if (bm) {
1690 bitmap->sysfs_can_clear = sysfs_get_dirent(bm, NULL, "can_clear"); 1711 bitmap->sysfs_can_clear = sysfs_get_dirent(bm, NULL, "can_clear");
1691 sysfs_put(bm); 1712 sysfs_put(bm);
@@ -1719,9 +1740,9 @@ int bitmap_create(mddev_t *mddev)
1719 bitmap->chunkshift = ffz(~mddev->bitmap_info.chunksize); 1740 bitmap->chunkshift = ffz(~mddev->bitmap_info.chunksize);
1720 1741
1721 /* now that chunksize and chunkshift are set, we can use these macros */ 1742 /* now that chunksize and chunkshift are set, we can use these macros */
1722 chunks = (blocks + CHUNK_BLOCK_RATIO(bitmap) - 1) >> 1743 chunks = (blocks + CHUNK_BLOCK_RATIO(bitmap) - 1) >>
1723 CHUNK_BLOCK_SHIFT(bitmap); 1744 CHUNK_BLOCK_SHIFT(bitmap);
1724 pages = (chunks + PAGE_COUNTER_RATIO - 1) / PAGE_COUNTER_RATIO; 1745 pages = (chunks + PAGE_COUNTER_RATIO - 1) / PAGE_COUNTER_RATIO;
1725 1746
1726 BUG_ON(!pages); 1747 BUG_ON(!pages);
1727 1748
@@ -1741,27 +1762,11 @@ int bitmap_create(mddev_t *mddev)
1741 if (!bitmap->bp) 1762 if (!bitmap->bp)
1742 goto error; 1763 goto error;
1743 1764
1744 /* now that we have some pages available, initialize the in-memory
1745 * bitmap from the on-disk bitmap */
1746 start = 0;
1747 if (mddev->degraded == 0
1748 || bitmap->events_cleared == mddev->events)
1749 /* no need to keep dirty bits to optimise a re-add of a missing device */
1750 start = mddev->recovery_cp;
1751 err = bitmap_init_from_disk(bitmap, start);
1752
1753 if (err)
1754 goto error;
1755
1756 printk(KERN_INFO "created bitmap (%lu pages) for device %s\n", 1765 printk(KERN_INFO "created bitmap (%lu pages) for device %s\n",
1757 pages, bmname(bitmap)); 1766 pages, bmname(bitmap));
1758 1767
1759 mddev->bitmap = bitmap; 1768 mddev->bitmap = bitmap;
1760 1769
1761 mddev->thread->timeout = mddev->bitmap_info.daemon_sleep;
1762 md_wakeup_thread(mddev->thread);
1763
1764 bitmap_update_sb(bitmap);
1765 1770
1766 return (bitmap->flags & BITMAP_WRITE_ERROR) ? -EIO : 0; 1771 return (bitmap->flags & BITMAP_WRITE_ERROR) ? -EIO : 0;
1767 1772
@@ -1770,15 +1775,69 @@ int bitmap_create(mddev_t *mddev)
1770 return err; 1775 return err;
1771} 1776}
1772 1777
1778int bitmap_load(mddev_t *mddev)
1779{
1780 int err = 0;
1781 sector_t sector = 0;
1782 struct bitmap *bitmap = mddev->bitmap;
1783
1784 if (!bitmap)
1785 goto out;
1786
1787 /* Clear out old bitmap info first: Either there is none, or we
1788 * are resuming after someone else has possibly changed things,
1789 * so we should forget old cached info.
1790 * All chunks should be clean, but some might need_sync.
1791 */
1792 while (sector < mddev->resync_max_sectors) {
1793 int blocks;
1794 bitmap_start_sync(bitmap, sector, &blocks, 0);
1795 sector += blocks;
1796 }
1797 bitmap_close_sync(bitmap);
1798
1799 if (mddev->bitmap_info.log) {
1800 unsigned long i;
1801 struct dm_dirty_log *log = mddev->bitmap_info.log;
1802 for (i = 0; i < bitmap->chunks; i++)
1803 if (!log->type->in_sync(log, i, 1))
1804 bitmap_set_memory_bits(bitmap,
1805 (sector_t)i << CHUNK_BLOCK_SHIFT(bitmap),
1806 1);
1807 } else {
1808 sector_t start = 0;
1809 if (mddev->degraded == 0
1810 || bitmap->events_cleared == mddev->events)
1811 /* no need to keep dirty bits to optimise a
1812 * re-add of a missing device */
1813 start = mddev->recovery_cp;
1814
1815 err = bitmap_init_from_disk(bitmap, start);
1816 }
1817 if (err)
1818 goto out;
1819
1820 mddev->thread->timeout = mddev->bitmap_info.daemon_sleep;
1821 md_wakeup_thread(mddev->thread);
1822
1823 bitmap_update_sb(bitmap);
1824
1825 if (bitmap->flags & BITMAP_WRITE_ERROR)
1826 err = -EIO;
1827out:
1828 return err;
1829}
1830EXPORT_SYMBOL_GPL(bitmap_load);
1831
1773static ssize_t 1832static ssize_t
1774location_show(mddev_t *mddev, char *page) 1833location_show(mddev_t *mddev, char *page)
1775{ 1834{
1776 ssize_t len; 1835 ssize_t len;
1777 if (mddev->bitmap_info.file) { 1836 if (mddev->bitmap_info.file)
1778 len = sprintf(page, "file"); 1837 len = sprintf(page, "file");
1779 } else if (mddev->bitmap_info.offset) { 1838 else if (mddev->bitmap_info.offset)
1780 len = sprintf(page, "%+lld", (long long)mddev->bitmap_info.offset); 1839 len = sprintf(page, "%+lld", (long long)mddev->bitmap_info.offset);
1781 } else 1840 else
1782 len = sprintf(page, "none"); 1841 len = sprintf(page, "none");
1783 len += sprintf(page+len, "\n"); 1842 len += sprintf(page+len, "\n");
1784 return len; 1843 return len;
@@ -1867,7 +1926,7 @@ timeout_show(mddev_t *mddev, char *page)
1867 ssize_t len; 1926 ssize_t len;
1868 unsigned long secs = mddev->bitmap_info.daemon_sleep / HZ; 1927 unsigned long secs = mddev->bitmap_info.daemon_sleep / HZ;
1869 unsigned long jifs = mddev->bitmap_info.daemon_sleep % HZ; 1928 unsigned long jifs = mddev->bitmap_info.daemon_sleep % HZ;
1870 1929
1871 len = sprintf(page, "%lu", secs); 1930 len = sprintf(page, "%lu", secs);
1872 if (jifs) 1931 if (jifs)
1873 len += sprintf(page+len, ".%03u", jiffies_to_msecs(jifs)); 1932 len += sprintf(page+len, ".%03u", jiffies_to_msecs(jifs));
@@ -2049,12 +2108,3 @@ struct attribute_group md_bitmap_group = {
2049 .attrs = md_bitmap_attrs, 2108 .attrs = md_bitmap_attrs,
2050}; 2109};
2051 2110
2052
2053/* the bitmap API -- for raid personalities */
2054EXPORT_SYMBOL(bitmap_startwrite);
2055EXPORT_SYMBOL(bitmap_endwrite);
2056EXPORT_SYMBOL(bitmap_start_sync);
2057EXPORT_SYMBOL(bitmap_end_sync);
2058EXPORT_SYMBOL(bitmap_unplug);
2059EXPORT_SYMBOL(bitmap_close_sync);
2060EXPORT_SYMBOL(bitmap_cond_end_sync);
diff --git a/drivers/md/bitmap.h b/drivers/md/bitmap.h
index 3797dea4723a..e872a7bad6b8 100644
--- a/drivers/md/bitmap.h
+++ b/drivers/md/bitmap.h
@@ -222,6 +222,10 @@ struct bitmap {
222 unsigned long file_pages; /* number of pages in the file */ 222 unsigned long file_pages; /* number of pages in the file */
223 int last_page_size; /* bytes in the last page */ 223 int last_page_size; /* bytes in the last page */
224 224
225 unsigned long logattrs; /* used when filemap_attr doesn't exist
226 * because we are working with a dirty_log
227 */
228
225 unsigned long flags; 229 unsigned long flags;
226 230
227 int allclean; 231 int allclean;
@@ -243,12 +247,14 @@ struct bitmap {
243 wait_queue_head_t behind_wait; 247 wait_queue_head_t behind_wait;
244 248
245 struct sysfs_dirent *sysfs_can_clear; 249 struct sysfs_dirent *sysfs_can_clear;
250
246}; 251};
247 252
248/* the bitmap API */ 253/* the bitmap API */
249 254
250/* these are used only by md/bitmap */ 255/* these are used only by md/bitmap */
251int bitmap_create(mddev_t *mddev); 256int bitmap_create(mddev_t *mddev);
257int bitmap_load(mddev_t *mddev);
252void bitmap_flush(mddev_t *mddev); 258void bitmap_flush(mddev_t *mddev);
253void bitmap_destroy(mddev_t *mddev); 259void bitmap_destroy(mddev_t *mddev);
254 260
diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
index 3bdbb6115702..368e8e98f705 100644
--- a/drivers/md/dm-crypt.c
+++ b/drivers/md/dm-crypt.c
@@ -107,11 +107,10 @@ struct crypt_config {
107 struct workqueue_struct *io_queue; 107 struct workqueue_struct *io_queue;
108 struct workqueue_struct *crypt_queue; 108 struct workqueue_struct *crypt_queue;
109 109
110 /* 110 char *cipher;
111 * crypto related data 111 char *cipher_mode;
112 */ 112
113 struct crypt_iv_operations *iv_gen_ops; 113 struct crypt_iv_operations *iv_gen_ops;
114 char *iv_mode;
115 union { 114 union {
116 struct iv_essiv_private essiv; 115 struct iv_essiv_private essiv;
117 struct iv_benbi_private benbi; 116 struct iv_benbi_private benbi;
@@ -135,8 +134,6 @@ struct crypt_config {
135 unsigned int dmreq_start; 134 unsigned int dmreq_start;
136 struct ablkcipher_request *req; 135 struct ablkcipher_request *req;
137 136
138 char cipher[CRYPTO_MAX_ALG_NAME];
139 char chainmode[CRYPTO_MAX_ALG_NAME];
140 struct crypto_ablkcipher *tfm; 137 struct crypto_ablkcipher *tfm;
141 unsigned long flags; 138 unsigned long flags;
142 unsigned int key_size; 139 unsigned int key_size;
@@ -999,82 +996,135 @@ static int crypt_wipe_key(struct crypt_config *cc)
999 return crypto_ablkcipher_setkey(cc->tfm, cc->key, cc->key_size); 996 return crypto_ablkcipher_setkey(cc->tfm, cc->key, cc->key_size);
1000} 997}
1001 998
1002/* 999static void crypt_dtr(struct dm_target *ti)
1003 * Construct an encryption mapping:
1004 * <cipher> <key> <iv_offset> <dev_path> <start>
1005 */
1006static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
1007{ 1000{
1008 struct crypt_config *cc; 1001 struct crypt_config *cc = ti->private;
1009 struct crypto_ablkcipher *tfm;
1010 char *tmp;
1011 char *cipher;
1012 char *chainmode;
1013 char *ivmode;
1014 char *ivopts;
1015 unsigned int key_size;
1016 unsigned long long tmpll;
1017 1002
1018 if (argc != 5) { 1003 ti->private = NULL;
1019 ti->error = "Not enough arguments"; 1004
1005 if (!cc)
1006 return;
1007
1008 if (cc->io_queue)
1009 destroy_workqueue(cc->io_queue);
1010 if (cc->crypt_queue)
1011 destroy_workqueue(cc->crypt_queue);
1012
1013 if (cc->bs)
1014 bioset_free(cc->bs);
1015
1016 if (cc->page_pool)
1017 mempool_destroy(cc->page_pool);
1018 if (cc->req_pool)
1019 mempool_destroy(cc->req_pool);
1020 if (cc->io_pool)
1021 mempool_destroy(cc->io_pool);
1022
1023 if (cc->iv_gen_ops && cc->iv_gen_ops->dtr)
1024 cc->iv_gen_ops->dtr(cc);
1025
1026 if (cc->tfm && !IS_ERR(cc->tfm))
1027 crypto_free_ablkcipher(cc->tfm);
1028
1029 if (cc->dev)
1030 dm_put_device(ti, cc->dev);
1031
1032 kzfree(cc->cipher);
1033 kzfree(cc->cipher_mode);
1034
1035 /* Must zero key material before freeing */
1036 kzfree(cc);
1037}
1038
1039static int crypt_ctr_cipher(struct dm_target *ti,
1040 char *cipher_in, char *key)
1041{
1042 struct crypt_config *cc = ti->private;
1043 char *tmp, *cipher, *chainmode, *ivmode, *ivopts;
1044 char *cipher_api = NULL;
1045 int ret = -EINVAL;
1046
1047 /* Convert to crypto api definition? */
1048 if (strchr(cipher_in, '(')) {
1049 ti->error = "Bad cipher specification";
1020 return -EINVAL; 1050 return -EINVAL;
1021 } 1051 }
1022 1052
1023 tmp = argv[0]; 1053 /*
1054 * Legacy dm-crypt cipher specification
1055 * cipher-mode-iv:ivopts
1056 */
1057 tmp = cipher_in;
1024 cipher = strsep(&tmp, "-"); 1058 cipher = strsep(&tmp, "-");
1059
1060 cc->cipher = kstrdup(cipher, GFP_KERNEL);
1061 if (!cc->cipher)
1062 goto bad_mem;
1063
1064 if (tmp) {
1065 cc->cipher_mode = kstrdup(tmp, GFP_KERNEL);
1066 if (!cc->cipher_mode)
1067 goto bad_mem;
1068 }
1069
1025 chainmode = strsep(&tmp, "-"); 1070 chainmode = strsep(&tmp, "-");
1026 ivopts = strsep(&tmp, "-"); 1071 ivopts = strsep(&tmp, "-");
1027 ivmode = strsep(&ivopts, ":"); 1072 ivmode = strsep(&ivopts, ":");
1028 1073
1029 if (tmp) 1074 if (tmp)
1030 DMWARN("Unexpected additional cipher options"); 1075 DMWARN("Ignoring unexpected additional cipher options");
1031
1032 key_size = strlen(argv[1]) >> 1;
1033
1034 cc = kzalloc(sizeof(*cc) + key_size * sizeof(u8), GFP_KERNEL);
1035 if (cc == NULL) {
1036 ti->error =
1037 "Cannot allocate transparent encryption context";
1038 return -ENOMEM;
1039 }
1040 1076
1041 /* Compatibility mode for old dm-crypt cipher strings */ 1077 /* Compatibility mode for old dm-crypt mappings */
1042 if (!chainmode || (strcmp(chainmode, "plain") == 0 && !ivmode)) { 1078 if (!chainmode || (!strcmp(chainmode, "plain") && !ivmode)) {
1079 kfree(cc->cipher_mode);
1080 cc->cipher_mode = kstrdup("cbc-plain", GFP_KERNEL);
1043 chainmode = "cbc"; 1081 chainmode = "cbc";
1044 ivmode = "plain"; 1082 ivmode = "plain";
1045 } 1083 }
1046 1084
1047 if (strcmp(chainmode, "ecb") && !ivmode) { 1085 if (strcmp(chainmode, "ecb") && !ivmode) {
1048 ti->error = "This chaining mode requires an IV mechanism"; 1086 ti->error = "IV mechanism required";
1049 goto bad_cipher; 1087 return -EINVAL;
1050 } 1088 }
1051 1089
1052 if (snprintf(cc->cipher, CRYPTO_MAX_ALG_NAME, "%s(%s)", 1090 cipher_api = kmalloc(CRYPTO_MAX_ALG_NAME, GFP_KERNEL);
1053 chainmode, cipher) >= CRYPTO_MAX_ALG_NAME) { 1091 if (!cipher_api)
1054 ti->error = "Chain mode + cipher name is too long"; 1092 goto bad_mem;
1055 goto bad_cipher; 1093
1094 ret = snprintf(cipher_api, CRYPTO_MAX_ALG_NAME,
1095 "%s(%s)", chainmode, cipher);
1096 if (ret < 0) {
1097 kfree(cipher_api);
1098 goto bad_mem;
1056 } 1099 }
1057 1100
1058 tfm = crypto_alloc_ablkcipher(cc->cipher, 0, 0); 1101 /* Allocate cipher */
1059 if (IS_ERR(tfm)) { 1102 cc->tfm = crypto_alloc_ablkcipher(cipher_api, 0, 0);
1103 if (IS_ERR(cc->tfm)) {
1104 ret = PTR_ERR(cc->tfm);
1060 ti->error = "Error allocating crypto tfm"; 1105 ti->error = "Error allocating crypto tfm";
1061 goto bad_cipher; 1106 goto bad;
1062 } 1107 }
1063 1108
1064 strcpy(cc->cipher, cipher); 1109 /* Initialize and set key */
1065 strcpy(cc->chainmode, chainmode); 1110 ret = crypt_set_key(cc, key);
1066 cc->tfm = tfm; 1111 if (ret < 0) {
1067
1068 if (crypt_set_key(cc, argv[1]) < 0) {
1069 ti->error = "Error decoding and setting key"; 1112 ti->error = "Error decoding and setting key";
1070 goto bad_ivmode; 1113 goto bad;
1071 } 1114 }
1072 1115
1073 /* 1116 /* Initialize IV */
1074 * Choose ivmode. Valid modes: "plain", "essiv:<esshash>", "benbi". 1117 cc->iv_size = crypto_ablkcipher_ivsize(cc->tfm);
1075 * See comments at iv code 1118 if (cc->iv_size)
1076 */ 1119 /* at least a 64 bit sector number should fit in our buffer */
1120 cc->iv_size = max(cc->iv_size,
1121 (unsigned int)(sizeof(u64) / sizeof(u8)));
1122 else if (ivmode) {
1123 DMWARN("Selected cipher does not support IVs");
1124 ivmode = NULL;
1125 }
1077 1126
1127 /* Choose ivmode, see comments at iv code. */
1078 if (ivmode == NULL) 1128 if (ivmode == NULL)
1079 cc->iv_gen_ops = NULL; 1129 cc->iv_gen_ops = NULL;
1080 else if (strcmp(ivmode, "plain") == 0) 1130 else if (strcmp(ivmode, "plain") == 0)
@@ -1088,159 +1138,138 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
1088 else if (strcmp(ivmode, "null") == 0) 1138 else if (strcmp(ivmode, "null") == 0)
1089 cc->iv_gen_ops = &crypt_iv_null_ops; 1139 cc->iv_gen_ops = &crypt_iv_null_ops;
1090 else { 1140 else {
1141 ret = -EINVAL;
1091 ti->error = "Invalid IV mode"; 1142 ti->error = "Invalid IV mode";
1092 goto bad_ivmode; 1143 goto bad;
1093 } 1144 }
1094 1145
1095 if (cc->iv_gen_ops && cc->iv_gen_ops->ctr && 1146 /* Allocate IV */
1096 cc->iv_gen_ops->ctr(cc, ti, ivopts) < 0) 1147 if (cc->iv_gen_ops && cc->iv_gen_ops->ctr) {
1097 goto bad_ivmode; 1148 ret = cc->iv_gen_ops->ctr(cc, ti, ivopts);
1098 1149 if (ret < 0) {
1099 if (cc->iv_gen_ops && cc->iv_gen_ops->init && 1150 ti->error = "Error creating IV";
1100 cc->iv_gen_ops->init(cc) < 0) { 1151 goto bad;
1101 ti->error = "Error initialising IV"; 1152 }
1102 goto bad_slab_pool;
1103 } 1153 }
1104 1154
1105 cc->iv_size = crypto_ablkcipher_ivsize(tfm); 1155 /* Initialize IV (set keys for ESSIV etc) */
1106 if (cc->iv_size) 1156 if (cc->iv_gen_ops && cc->iv_gen_ops->init) {
1107 /* at least a 64 bit sector number should fit in our buffer */ 1157 ret = cc->iv_gen_ops->init(cc);
1108 cc->iv_size = max(cc->iv_size, 1158 if (ret < 0) {
1109 (unsigned int)(sizeof(u64) / sizeof(u8))); 1159 ti->error = "Error initialising IV";
1110 else { 1160 goto bad;
1111 if (cc->iv_gen_ops) {
1112 DMWARN("Selected cipher does not support IVs");
1113 if (cc->iv_gen_ops->dtr)
1114 cc->iv_gen_ops->dtr(cc);
1115 cc->iv_gen_ops = NULL;
1116 } 1161 }
1117 } 1162 }
1118 1163
1164 ret = 0;
1165bad:
1166 kfree(cipher_api);
1167 return ret;
1168
1169bad_mem:
1170 ti->error = "Cannot allocate cipher strings";
1171 return -ENOMEM;
1172}
1173
1174/*
1175 * Construct an encryption mapping:
1176 * <cipher> <key> <iv_offset> <dev_path> <start>
1177 */
1178static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
1179{
1180 struct crypt_config *cc;
1181 unsigned int key_size;
1182 unsigned long long tmpll;
1183 int ret;
1184
1185 if (argc != 5) {
1186 ti->error = "Not enough arguments";
1187 return -EINVAL;
1188 }
1189
1190 key_size = strlen(argv[1]) >> 1;
1191
1192 cc = kzalloc(sizeof(*cc) + key_size * sizeof(u8), GFP_KERNEL);
1193 if (!cc) {
1194 ti->error = "Cannot allocate encryption context";
1195 return -ENOMEM;
1196 }
1197
1198 ti->private = cc;
1199 ret = crypt_ctr_cipher(ti, argv[0], argv[1]);
1200 if (ret < 0)
1201 goto bad;
1202
1203 ret = -ENOMEM;
1119 cc->io_pool = mempool_create_slab_pool(MIN_IOS, _crypt_io_pool); 1204 cc->io_pool = mempool_create_slab_pool(MIN_IOS, _crypt_io_pool);
1120 if (!cc->io_pool) { 1205 if (!cc->io_pool) {
1121 ti->error = "Cannot allocate crypt io mempool"; 1206 ti->error = "Cannot allocate crypt io mempool";
1122 goto bad_slab_pool; 1207 goto bad;
1123 } 1208 }
1124 1209
1125 cc->dmreq_start = sizeof(struct ablkcipher_request); 1210 cc->dmreq_start = sizeof(struct ablkcipher_request);
1126 cc->dmreq_start += crypto_ablkcipher_reqsize(tfm); 1211 cc->dmreq_start += crypto_ablkcipher_reqsize(cc->tfm);
1127 cc->dmreq_start = ALIGN(cc->dmreq_start, crypto_tfm_ctx_alignment()); 1212 cc->dmreq_start = ALIGN(cc->dmreq_start, crypto_tfm_ctx_alignment());
1128 cc->dmreq_start += crypto_ablkcipher_alignmask(tfm) & 1213 cc->dmreq_start += crypto_ablkcipher_alignmask(cc->tfm) &
1129 ~(crypto_tfm_ctx_alignment() - 1); 1214 ~(crypto_tfm_ctx_alignment() - 1);
1130 1215
1131 cc->req_pool = mempool_create_kmalloc_pool(MIN_IOS, cc->dmreq_start + 1216 cc->req_pool = mempool_create_kmalloc_pool(MIN_IOS, cc->dmreq_start +
1132 sizeof(struct dm_crypt_request) + cc->iv_size); 1217 sizeof(struct dm_crypt_request) + cc->iv_size);
1133 if (!cc->req_pool) { 1218 if (!cc->req_pool) {
1134 ti->error = "Cannot allocate crypt request mempool"; 1219 ti->error = "Cannot allocate crypt request mempool";
1135 goto bad_req_pool; 1220 goto bad;
1136 } 1221 }
1137 cc->req = NULL; 1222 cc->req = NULL;
1138 1223
1139 cc->page_pool = mempool_create_page_pool(MIN_POOL_PAGES, 0); 1224 cc->page_pool = mempool_create_page_pool(MIN_POOL_PAGES, 0);
1140 if (!cc->page_pool) { 1225 if (!cc->page_pool) {
1141 ti->error = "Cannot allocate page mempool"; 1226 ti->error = "Cannot allocate page mempool";
1142 goto bad_page_pool; 1227 goto bad;
1143 } 1228 }
1144 1229
1145 cc->bs = bioset_create(MIN_IOS, 0); 1230 cc->bs = bioset_create(MIN_IOS, 0);
1146 if (!cc->bs) { 1231 if (!cc->bs) {
1147 ti->error = "Cannot allocate crypt bioset"; 1232 ti->error = "Cannot allocate crypt bioset";
1148 goto bad_bs; 1233 goto bad;
1149 } 1234 }
1150 1235
1236 ret = -EINVAL;
1151 if (sscanf(argv[2], "%llu", &tmpll) != 1) { 1237 if (sscanf(argv[2], "%llu", &tmpll) != 1) {
1152 ti->error = "Invalid iv_offset sector"; 1238 ti->error = "Invalid iv_offset sector";
1153 goto bad_device; 1239 goto bad;
1154 } 1240 }
1155 cc->iv_offset = tmpll; 1241 cc->iv_offset = tmpll;
1156 1242
1157 if (sscanf(argv[4], "%llu", &tmpll) != 1) {
1158 ti->error = "Invalid device sector";
1159 goto bad_device;
1160 }
1161 cc->start = tmpll;
1162
1163 if (dm_get_device(ti, argv[3], dm_table_get_mode(ti->table), &cc->dev)) { 1243 if (dm_get_device(ti, argv[3], dm_table_get_mode(ti->table), &cc->dev)) {
1164 ti->error = "Device lookup failed"; 1244 ti->error = "Device lookup failed";
1165 goto bad_device; 1245 goto bad;
1166 } 1246 }
1167 1247
1168 if (ivmode && cc->iv_gen_ops) { 1248 if (sscanf(argv[4], "%llu", &tmpll) != 1) {
1169 if (ivopts) 1249 ti->error = "Invalid device sector";
1170 *(ivopts - 1) = ':'; 1250 goto bad;
1171 cc->iv_mode = kmalloc(strlen(ivmode) + 1, GFP_KERNEL); 1251 }
1172 if (!cc->iv_mode) { 1252 cc->start = tmpll;
1173 ti->error = "Error kmallocing iv_mode string";
1174 goto bad_ivmode_string;
1175 }
1176 strcpy(cc->iv_mode, ivmode);
1177 } else
1178 cc->iv_mode = NULL;
1179 1253
1254 ret = -ENOMEM;
1180 cc->io_queue = create_singlethread_workqueue("kcryptd_io"); 1255 cc->io_queue = create_singlethread_workqueue("kcryptd_io");
1181 if (!cc->io_queue) { 1256 if (!cc->io_queue) {
1182 ti->error = "Couldn't create kcryptd io queue"; 1257 ti->error = "Couldn't create kcryptd io queue";
1183 goto bad_io_queue; 1258 goto bad;
1184 } 1259 }
1185 1260
1186 cc->crypt_queue = create_singlethread_workqueue("kcryptd"); 1261 cc->crypt_queue = create_singlethread_workqueue("kcryptd");
1187 if (!cc->crypt_queue) { 1262 if (!cc->crypt_queue) {
1188 ti->error = "Couldn't create kcryptd queue"; 1263 ti->error = "Couldn't create kcryptd queue";
1189 goto bad_crypt_queue; 1264 goto bad;
1190 } 1265 }
1191 1266
1192 ti->num_flush_requests = 1; 1267 ti->num_flush_requests = 1;
1193 ti->private = cc;
1194 return 0; 1268 return 0;
1195 1269
1196bad_crypt_queue: 1270bad:
1197 destroy_workqueue(cc->io_queue); 1271 crypt_dtr(ti);
1198bad_io_queue: 1272 return ret;
1199 kfree(cc->iv_mode);
1200bad_ivmode_string:
1201 dm_put_device(ti, cc->dev);
1202bad_device:
1203 bioset_free(cc->bs);
1204bad_bs:
1205 mempool_destroy(cc->page_pool);
1206bad_page_pool:
1207 mempool_destroy(cc->req_pool);
1208bad_req_pool:
1209 mempool_destroy(cc->io_pool);
1210bad_slab_pool:
1211 if (cc->iv_gen_ops && cc->iv_gen_ops->dtr)
1212 cc->iv_gen_ops->dtr(cc);
1213bad_ivmode:
1214 crypto_free_ablkcipher(tfm);
1215bad_cipher:
1216 /* Must zero key material before freeing */
1217 kzfree(cc);
1218 return -EINVAL;
1219}
1220
1221static void crypt_dtr(struct dm_target *ti)
1222{
1223 struct crypt_config *cc = (struct crypt_config *) ti->private;
1224
1225 destroy_workqueue(cc->io_queue);
1226 destroy_workqueue(cc->crypt_queue);
1227
1228 if (cc->req)
1229 mempool_free(cc->req, cc->req_pool);
1230
1231 bioset_free(cc->bs);
1232 mempool_destroy(cc->page_pool);
1233 mempool_destroy(cc->req_pool);
1234 mempool_destroy(cc->io_pool);
1235
1236 kfree(cc->iv_mode);
1237 if (cc->iv_gen_ops && cc->iv_gen_ops->dtr)
1238 cc->iv_gen_ops->dtr(cc);
1239 crypto_free_ablkcipher(cc->tfm);
1240 dm_put_device(ti, cc->dev);
1241
1242 /* Must zero key material before freeing */
1243 kzfree(cc);
1244} 1273}
1245 1274
1246static int crypt_map(struct dm_target *ti, struct bio *bio, 1275static int crypt_map(struct dm_target *ti, struct bio *bio,
@@ -1255,7 +1284,7 @@ static int crypt_map(struct dm_target *ti, struct bio *bio,
1255 return DM_MAPIO_REMAPPED; 1284 return DM_MAPIO_REMAPPED;
1256 } 1285 }
1257 1286
1258 io = crypt_io_alloc(ti, bio, bio->bi_sector - ti->begin); 1287 io = crypt_io_alloc(ti, bio, dm_target_offset(ti, bio->bi_sector));
1259 1288
1260 if (bio_data_dir(io->base_bio) == READ) 1289 if (bio_data_dir(io->base_bio) == READ)
1261 kcryptd_queue_io(io); 1290 kcryptd_queue_io(io);
@@ -1268,7 +1297,7 @@ static int crypt_map(struct dm_target *ti, struct bio *bio,
1268static int crypt_status(struct dm_target *ti, status_type_t type, 1297static int crypt_status(struct dm_target *ti, status_type_t type,
1269 char *result, unsigned int maxlen) 1298 char *result, unsigned int maxlen)
1270{ 1299{
1271 struct crypt_config *cc = (struct crypt_config *) ti->private; 1300 struct crypt_config *cc = ti->private;
1272 unsigned int sz = 0; 1301 unsigned int sz = 0;
1273 1302
1274 switch (type) { 1303 switch (type) {
@@ -1277,11 +1306,10 @@ static int crypt_status(struct dm_target *ti, status_type_t type,
1277 break; 1306 break;
1278 1307
1279 case STATUSTYPE_TABLE: 1308 case STATUSTYPE_TABLE:
1280 if (cc->iv_mode) 1309 if (cc->cipher_mode)
1281 DMEMIT("%s-%s-%s ", cc->cipher, cc->chainmode, 1310 DMEMIT("%s-%s ", cc->cipher, cc->cipher_mode);
1282 cc->iv_mode);
1283 else 1311 else
1284 DMEMIT("%s-%s ", cc->cipher, cc->chainmode); 1312 DMEMIT("%s ", cc->cipher);
1285 1313
1286 if (cc->key_size > 0) { 1314 if (cc->key_size > 0) {
1287 if ((maxlen - sz) < ((cc->key_size << 1) + 1)) 1315 if ((maxlen - sz) < ((cc->key_size << 1) + 1))
@@ -1378,7 +1406,7 @@ static int crypt_merge(struct dm_target *ti, struct bvec_merge_data *bvm,
1378 return max_size; 1406 return max_size;
1379 1407
1380 bvm->bi_bdev = cc->dev->bdev; 1408 bvm->bi_bdev = cc->dev->bdev;
1381 bvm->bi_sector = cc->start + bvm->bi_sector - ti->begin; 1409 bvm->bi_sector = cc->start + dm_target_offset(ti, bvm->bi_sector);
1382 1410
1383 return min(max_size, q->merge_bvec_fn(q, bvm, biovec)); 1411 return min(max_size, q->merge_bvec_fn(q, bvm, biovec));
1384} 1412}
diff --git a/drivers/md/dm-delay.c b/drivers/md/dm-delay.c
index 852052880d7a..baa11912cc94 100644
--- a/drivers/md/dm-delay.c
+++ b/drivers/md/dm-delay.c
@@ -198,6 +198,7 @@ out:
198 atomic_set(&dc->may_delay, 1); 198 atomic_set(&dc->may_delay, 1);
199 199
200 ti->num_flush_requests = 1; 200 ti->num_flush_requests = 1;
201 ti->num_discard_requests = 1;
201 ti->private = dc; 202 ti->private = dc;
202 return 0; 203 return 0;
203 204
@@ -281,14 +282,13 @@ static int delay_map(struct dm_target *ti, struct bio *bio,
281 bio->bi_bdev = dc->dev_write->bdev; 282 bio->bi_bdev = dc->dev_write->bdev;
282 if (bio_sectors(bio)) 283 if (bio_sectors(bio))
283 bio->bi_sector = dc->start_write + 284 bio->bi_sector = dc->start_write +
284 (bio->bi_sector - ti->begin); 285 dm_target_offset(ti, bio->bi_sector);
285 286
286 return delay_bio(dc, dc->write_delay, bio); 287 return delay_bio(dc, dc->write_delay, bio);
287 } 288 }
288 289
289 bio->bi_bdev = dc->dev_read->bdev; 290 bio->bi_bdev = dc->dev_read->bdev;
290 bio->bi_sector = dc->start_read + 291 bio->bi_sector = dc->start_read + dm_target_offset(ti, bio->bi_sector);
291 (bio->bi_sector - ti->begin);
292 292
293 return delay_bio(dc, dc->read_delay, bio); 293 return delay_bio(dc, dc->read_delay, bio);
294} 294}
diff --git a/drivers/md/dm-exception-store.c b/drivers/md/dm-exception-store.c
index 2b7907b6dd09..0bdb201c2c2a 100644
--- a/drivers/md/dm-exception-store.c
+++ b/drivers/md/dm-exception-store.c
@@ -173,7 +173,9 @@ int dm_exception_store_set_chunk_size(struct dm_exception_store *store,
173 173
174 /* Validate the chunk size against the device block size */ 174 /* Validate the chunk size against the device block size */
175 if (chunk_size % 175 if (chunk_size %
176 (bdev_logical_block_size(dm_snap_cow(store->snap)->bdev) >> 9)) { 176 (bdev_logical_block_size(dm_snap_cow(store->snap)->bdev) >> 9) ||
177 chunk_size %
178 (bdev_logical_block_size(dm_snap_origin(store->snap)->bdev) >> 9)) {
177 *error = "Chunk size is not a multiple of device blocksize"; 179 *error = "Chunk size is not a multiple of device blocksize";
178 return -EINVAL; 180 return -EINVAL;
179 } 181 }
diff --git a/drivers/md/dm-exception-store.h b/drivers/md/dm-exception-store.h
index e8dfa06af3ba..0b2536247cf5 100644
--- a/drivers/md/dm-exception-store.h
+++ b/drivers/md/dm-exception-store.h
@@ -126,8 +126,9 @@ struct dm_exception_store {
126}; 126};
127 127
128/* 128/*
129 * Obtain the cow device used by a given snapshot. 129 * Obtain the origin or cow device used by a given snapshot.
130 */ 130 */
131struct dm_dev *dm_snap_origin(struct dm_snapshot *snap);
131struct dm_dev *dm_snap_cow(struct dm_snapshot *snap); 132struct dm_dev *dm_snap_cow(struct dm_snapshot *snap);
132 133
133/* 134/*
diff --git a/drivers/md/dm-io.c b/drivers/md/dm-io.c
index 10f457ca6af2..0590c75b0ab6 100644
--- a/drivers/md/dm-io.c
+++ b/drivers/md/dm-io.c
@@ -356,7 +356,7 @@ static void dispatch_io(int rw, unsigned int num_regions,
356 BUG_ON(num_regions > DM_IO_MAX_REGIONS); 356 BUG_ON(num_regions > DM_IO_MAX_REGIONS);
357 357
358 if (sync) 358 if (sync)
359 rw |= (1 << BIO_RW_SYNCIO) | (1 << BIO_RW_UNPLUG); 359 rw |= REQ_SYNC | REQ_UNPLUG;
360 360
361 /* 361 /*
362 * For multiple regions we need to be careful to rewind 362 * For multiple regions we need to be careful to rewind
@@ -364,7 +364,7 @@ static void dispatch_io(int rw, unsigned int num_regions,
364 */ 364 */
365 for (i = 0; i < num_regions; i++) { 365 for (i = 0; i < num_regions; i++) {
366 *dp = old_pages; 366 *dp = old_pages;
367 if (where[i].count || (rw & (1 << BIO_RW_BARRIER))) 367 if (where[i].count || (rw & REQ_HARDBARRIER))
368 do_region(rw, i, where + i, dp, io); 368 do_region(rw, i, where + i, dp, io);
369 } 369 }
370 370
@@ -412,8 +412,8 @@ retry:
412 } 412 }
413 set_current_state(TASK_RUNNING); 413 set_current_state(TASK_RUNNING);
414 414
415 if (io->eopnotsupp_bits && (rw & (1 << BIO_RW_BARRIER))) { 415 if (io->eopnotsupp_bits && (rw & REQ_HARDBARRIER)) {
416 rw &= ~(1 << BIO_RW_BARRIER); 416 rw &= ~REQ_HARDBARRIER;
417 goto retry; 417 goto retry;
418 } 418 }
419 419
@@ -479,8 +479,8 @@ static int dp_init(struct dm_io_request *io_req, struct dpages *dp)
479 * New collapsed (a)synchronous interface. 479 * New collapsed (a)synchronous interface.
480 * 480 *
481 * If the IO is asynchronous (i.e. it has notify.fn), you must either unplug 481 * If the IO is asynchronous (i.e. it has notify.fn), you must either unplug
482 * the queue with blk_unplug() some time later or set the BIO_RW_SYNC bit in 482 * the queue with blk_unplug() some time later or set REQ_SYNC in
483 * io_req->bi_rw. If you fail to do one of these, the IO will be submitted to 483io_req->bi_rw. If you fail to do one of these, the IO will be submitted to
484 * the disk after q->unplug_delay, which defaults to 3ms in blk-settings.c. 484 * the disk after q->unplug_delay, which defaults to 3ms in blk-settings.c.
485 */ 485 */
486int dm_io(struct dm_io_request *io_req, unsigned num_regions, 486int dm_io(struct dm_io_request *io_req, unsigned num_regions,
diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
index d7500e1c26f2..3e39193e5036 100644
--- a/drivers/md/dm-ioctl.c
+++ b/drivers/md/dm-ioctl.c
@@ -249,55 +249,66 @@ static void __hash_remove(struct hash_cell *hc)
249 249
250static void dm_hash_remove_all(int keep_open_devices) 250static void dm_hash_remove_all(int keep_open_devices)
251{ 251{
252 int i, dev_skipped, dev_removed; 252 int i, dev_skipped;
253 struct hash_cell *hc; 253 struct hash_cell *hc;
254 struct list_head *tmp, *n; 254 struct mapped_device *md;
255
256retry:
257 dev_skipped = 0;
255 258
256 down_write(&_hash_lock); 259 down_write(&_hash_lock);
257 260
258retry:
259 dev_skipped = dev_removed = 0;
260 for (i = 0; i < NUM_BUCKETS; i++) { 261 for (i = 0; i < NUM_BUCKETS; i++) {
261 list_for_each_safe (tmp, n, _name_buckets + i) { 262 list_for_each_entry(hc, _name_buckets + i, name_list) {
262 hc = list_entry(tmp, struct hash_cell, name_list); 263 md = hc->md;
264 dm_get(md);
263 265
264 if (keep_open_devices && 266 if (keep_open_devices && dm_lock_for_deletion(md)) {
265 dm_lock_for_deletion(hc->md)) { 267 dm_put(md);
266 dev_skipped++; 268 dev_skipped++;
267 continue; 269 continue;
268 } 270 }
271
269 __hash_remove(hc); 272 __hash_remove(hc);
270 dev_removed = 1;
271 }
272 }
273 273
274 /* 274 up_write(&_hash_lock);
275 * Some mapped devices may be using other mapped devices, so if any
276 * still exist, repeat until we make no further progress.
277 */
278 if (dev_skipped) {
279 if (dev_removed)
280 goto retry;
281 275
282 DMWARN("remove_all left %d open device(s)", dev_skipped); 276 dm_put(md);
277 if (likely(keep_open_devices))
278 dm_destroy(md);
279 else
280 dm_destroy_immediate(md);
281
282 /*
283 * Some mapped devices may be using other mapped
284 * devices, so repeat until we make no further
285 * progress. If a new mapped device is created
286 * here it will also get removed.
287 */
288 goto retry;
289 }
283 } 290 }
284 291
285 up_write(&_hash_lock); 292 up_write(&_hash_lock);
293
294 if (dev_skipped)
295 DMWARN("remove_all left %d open device(s)", dev_skipped);
286} 296}
287 297
288static int dm_hash_rename(uint32_t cookie, uint32_t *flags, const char *old, 298static struct mapped_device *dm_hash_rename(struct dm_ioctl *param,
289 const char *new) 299 const char *new)
290{ 300{
291 char *new_name, *old_name; 301 char *new_name, *old_name;
292 struct hash_cell *hc; 302 struct hash_cell *hc;
293 struct dm_table *table; 303 struct dm_table *table;
304 struct mapped_device *md;
294 305
295 /* 306 /*
296 * duplicate new. 307 * duplicate new.
297 */ 308 */
298 new_name = kstrdup(new, GFP_KERNEL); 309 new_name = kstrdup(new, GFP_KERNEL);
299 if (!new_name) 310 if (!new_name)
300 return -ENOMEM; 311 return ERR_PTR(-ENOMEM);
301 312
302 down_write(&_hash_lock); 313 down_write(&_hash_lock);
303 314
@@ -306,24 +317,24 @@ static int dm_hash_rename(uint32_t cookie, uint32_t *flags, const char *old,
306 */ 317 */
307 hc = __get_name_cell(new); 318 hc = __get_name_cell(new);
308 if (hc) { 319 if (hc) {
309 DMWARN("asked to rename to an already existing name %s -> %s", 320 DMWARN("asked to rename to an already-existing name %s -> %s",
310 old, new); 321 param->name, new);
311 dm_put(hc->md); 322 dm_put(hc->md);
312 up_write(&_hash_lock); 323 up_write(&_hash_lock);
313 kfree(new_name); 324 kfree(new_name);
314 return -EBUSY; 325 return ERR_PTR(-EBUSY);
315 } 326 }
316 327
317 /* 328 /*
318 * Is there such a device as 'old' ? 329 * Is there such a device as 'old' ?
319 */ 330 */
320 hc = __get_name_cell(old); 331 hc = __get_name_cell(param->name);
321 if (!hc) { 332 if (!hc) {
322 DMWARN("asked to rename a non existent device %s -> %s", 333 DMWARN("asked to rename a non-existent device %s -> %s",
323 old, new); 334 param->name, new);
324 up_write(&_hash_lock); 335 up_write(&_hash_lock);
325 kfree(new_name); 336 kfree(new_name);
326 return -ENXIO; 337 return ERR_PTR(-ENXIO);
327 } 338 }
328 339
329 /* 340 /*
@@ -345,13 +356,14 @@ static int dm_hash_rename(uint32_t cookie, uint32_t *flags, const char *old,
345 dm_table_put(table); 356 dm_table_put(table);
346 } 357 }
347 358
348 if (!dm_kobject_uevent(hc->md, KOBJ_CHANGE, cookie)) 359 if (!dm_kobject_uevent(hc->md, KOBJ_CHANGE, param->event_nr))
349 *flags |= DM_UEVENT_GENERATED_FLAG; 360 param->flags |= DM_UEVENT_GENERATED_FLAG;
350 361
351 dm_put(hc->md); 362 md = hc->md;
352 up_write(&_hash_lock); 363 up_write(&_hash_lock);
353 kfree(old_name); 364 kfree(old_name);
354 return 0; 365
366 return md;
355} 367}
356 368
357/*----------------------------------------------------------------- 369/*-----------------------------------------------------------------
@@ -573,7 +585,7 @@ static struct dm_table *dm_get_live_or_inactive_table(struct mapped_device *md,
573 * Fills in a dm_ioctl structure, ready for sending back to 585 * Fills in a dm_ioctl structure, ready for sending back to
574 * userland. 586 * userland.
575 */ 587 */
576static int __dev_status(struct mapped_device *md, struct dm_ioctl *param) 588static void __dev_status(struct mapped_device *md, struct dm_ioctl *param)
577{ 589{
578 struct gendisk *disk = dm_disk(md); 590 struct gendisk *disk = dm_disk(md);
579 struct dm_table *table; 591 struct dm_table *table;
@@ -617,8 +629,6 @@ static int __dev_status(struct mapped_device *md, struct dm_ioctl *param)
617 dm_table_put(table); 629 dm_table_put(table);
618 } 630 }
619 } 631 }
620
621 return 0;
622} 632}
623 633
624static int dev_create(struct dm_ioctl *param, size_t param_size) 634static int dev_create(struct dm_ioctl *param, size_t param_size)
@@ -640,15 +650,17 @@ static int dev_create(struct dm_ioctl *param, size_t param_size)
640 r = dm_hash_insert(param->name, *param->uuid ? param->uuid : NULL, md); 650 r = dm_hash_insert(param->name, *param->uuid ? param->uuid : NULL, md);
641 if (r) { 651 if (r) {
642 dm_put(md); 652 dm_put(md);
653 dm_destroy(md);
643 return r; 654 return r;
644 } 655 }
645 656
646 param->flags &= ~DM_INACTIVE_PRESENT_FLAG; 657 param->flags &= ~DM_INACTIVE_PRESENT_FLAG;
647 658
648 r = __dev_status(md, param); 659 __dev_status(md, param);
660
649 dm_put(md); 661 dm_put(md);
650 662
651 return r; 663 return 0;
652} 664}
653 665
654/* 666/*
@@ -742,6 +754,7 @@ static int dev_remove(struct dm_ioctl *param, size_t param_size)
742 param->flags |= DM_UEVENT_GENERATED_FLAG; 754 param->flags |= DM_UEVENT_GENERATED_FLAG;
743 755
744 dm_put(md); 756 dm_put(md);
757 dm_destroy(md);
745 return 0; 758 return 0;
746} 759}
747 760
@@ -762,6 +775,7 @@ static int dev_rename(struct dm_ioctl *param, size_t param_size)
762{ 775{
763 int r; 776 int r;
764 char *new_name = (char *) param + param->data_start; 777 char *new_name = (char *) param + param->data_start;
778 struct mapped_device *md;
765 779
766 if (new_name < param->data || 780 if (new_name < param->data ||
767 invalid_str(new_name, (void *) param + param_size) || 781 invalid_str(new_name, (void *) param + param_size) ||
@@ -774,10 +788,14 @@ static int dev_rename(struct dm_ioctl *param, size_t param_size)
774 if (r) 788 if (r)
775 return r; 789 return r;
776 790
777 param->data_size = 0; 791 md = dm_hash_rename(param, new_name);
792 if (IS_ERR(md))
793 return PTR_ERR(md);
794
795 __dev_status(md, param);
796 dm_put(md);
778 797
779 return dm_hash_rename(param->event_nr, &param->flags, param->name, 798 return 0;
780 new_name);
781} 799}
782 800
783static int dev_set_geometry(struct dm_ioctl *param, size_t param_size) 801static int dev_set_geometry(struct dm_ioctl *param, size_t param_size)
@@ -818,8 +836,6 @@ static int dev_set_geometry(struct dm_ioctl *param, size_t param_size)
818 geometry.start = indata[3]; 836 geometry.start = indata[3];
819 837
820 r = dm_set_geometry(md, &geometry); 838 r = dm_set_geometry(md, &geometry);
821 if (!r)
822 r = __dev_status(md, param);
823 839
824 param->data_size = 0; 840 param->data_size = 0;
825 841
@@ -843,13 +859,17 @@ static int do_suspend(struct dm_ioctl *param)
843 if (param->flags & DM_NOFLUSH_FLAG) 859 if (param->flags & DM_NOFLUSH_FLAG)
844 suspend_flags |= DM_SUSPEND_NOFLUSH_FLAG; 860 suspend_flags |= DM_SUSPEND_NOFLUSH_FLAG;
845 861
846 if (!dm_suspended_md(md)) 862 if (!dm_suspended_md(md)) {
847 r = dm_suspend(md, suspend_flags); 863 r = dm_suspend(md, suspend_flags);
864 if (r)
865 goto out;
866 }
848 867
849 if (!r) 868 __dev_status(md, param);
850 r = __dev_status(md, param);
851 869
870out:
852 dm_put(md); 871 dm_put(md);
872
853 return r; 873 return r;
854} 874}
855 875
@@ -911,7 +931,7 @@ static int do_resume(struct dm_ioctl *param)
911 dm_table_destroy(old_map); 931 dm_table_destroy(old_map);
912 932
913 if (!r) 933 if (!r)
914 r = __dev_status(md, param); 934 __dev_status(md, param);
915 935
916 dm_put(md); 936 dm_put(md);
917 return r; 937 return r;
@@ -935,16 +955,16 @@ static int dev_suspend(struct dm_ioctl *param, size_t param_size)
935 */ 955 */
936static int dev_status(struct dm_ioctl *param, size_t param_size) 956static int dev_status(struct dm_ioctl *param, size_t param_size)
937{ 957{
938 int r;
939 struct mapped_device *md; 958 struct mapped_device *md;
940 959
941 md = find_device(param); 960 md = find_device(param);
942 if (!md) 961 if (!md)
943 return -ENXIO; 962 return -ENXIO;
944 963
945 r = __dev_status(md, param); 964 __dev_status(md, param);
946 dm_put(md); 965 dm_put(md);
947 return r; 966
967 return 0;
948} 968}
949 969
950/* 970/*
@@ -1019,7 +1039,7 @@ static void retrieve_status(struct dm_table *table,
1019 */ 1039 */
1020static int dev_wait(struct dm_ioctl *param, size_t param_size) 1040static int dev_wait(struct dm_ioctl *param, size_t param_size)
1021{ 1041{
1022 int r; 1042 int r = 0;
1023 struct mapped_device *md; 1043 struct mapped_device *md;
1024 struct dm_table *table; 1044 struct dm_table *table;
1025 1045
@@ -1040,9 +1060,7 @@ static int dev_wait(struct dm_ioctl *param, size_t param_size)
1040 * changed to trigger the event, so we may as well tell 1060 * changed to trigger the event, so we may as well tell
1041 * him and save an ioctl. 1061 * him and save an ioctl.
1042 */ 1062 */
1043 r = __dev_status(md, param); 1063 __dev_status(md, param);
1044 if (r)
1045 goto out;
1046 1064
1047 table = dm_get_live_or_inactive_table(md, param); 1065 table = dm_get_live_or_inactive_table(md, param);
1048 if (table) { 1066 if (table) {
@@ -1050,8 +1068,9 @@ static int dev_wait(struct dm_ioctl *param, size_t param_size)
1050 dm_table_put(table); 1068 dm_table_put(table);
1051 } 1069 }
1052 1070
1053 out: 1071out:
1054 dm_put(md); 1072 dm_put(md);
1073
1055 return r; 1074 return r;
1056} 1075}
1057 1076
@@ -1112,28 +1131,9 @@ static int populate_table(struct dm_table *table,
1112 next = spec->next; 1131 next = spec->next;
1113 } 1132 }
1114 1133
1115 r = dm_table_set_type(table);
1116 if (r) {
1117 DMWARN("unable to set table type");
1118 return r;
1119 }
1120
1121 return dm_table_complete(table); 1134 return dm_table_complete(table);
1122} 1135}
1123 1136
1124static int table_prealloc_integrity(struct dm_table *t,
1125 struct mapped_device *md)
1126{
1127 struct list_head *devices = dm_table_get_devices(t);
1128 struct dm_dev_internal *dd;
1129
1130 list_for_each_entry(dd, devices, list)
1131 if (bdev_get_integrity(dd->dm_dev.bdev))
1132 return blk_integrity_register(dm_disk(md), NULL);
1133
1134 return 0;
1135}
1136
1137static int table_load(struct dm_ioctl *param, size_t param_size) 1137static int table_load(struct dm_ioctl *param, size_t param_size)
1138{ 1138{
1139 int r; 1139 int r;
@@ -1155,21 +1155,30 @@ static int table_load(struct dm_ioctl *param, size_t param_size)
1155 goto out; 1155 goto out;
1156 } 1156 }
1157 1157
1158 r = table_prealloc_integrity(t, md); 1158 /* Protect md->type and md->queue against concurrent table loads. */
1159 if (r) { 1159 dm_lock_md_type(md);
1160 DMERR("%s: could not register integrity profile.", 1160 if (dm_get_md_type(md) == DM_TYPE_NONE)
1161 dm_device_name(md)); 1161 /* Initial table load: acquire type of table. */
1162 dm_set_md_type(md, dm_table_get_type(t));
1163 else if (dm_get_md_type(md) != dm_table_get_type(t)) {
1164 DMWARN("can't change device type after initial table load.");
1162 dm_table_destroy(t); 1165 dm_table_destroy(t);
1166 dm_unlock_md_type(md);
1167 r = -EINVAL;
1163 goto out; 1168 goto out;
1164 } 1169 }
1165 1170
1166 r = dm_table_alloc_md_mempools(t); 1171 /* setup md->queue to reflect md's type (may block) */
1172 r = dm_setup_md_queue(md);
1167 if (r) { 1173 if (r) {
1168 DMWARN("unable to allocate mempools for this table"); 1174 DMWARN("unable to set up device queue for new table.");
1169 dm_table_destroy(t); 1175 dm_table_destroy(t);
1176 dm_unlock_md_type(md);
1170 goto out; 1177 goto out;
1171 } 1178 }
1179 dm_unlock_md_type(md);
1172 1180
1181 /* stage inactive table */
1173 down_write(&_hash_lock); 1182 down_write(&_hash_lock);
1174 hc = dm_get_mdptr(md); 1183 hc = dm_get_mdptr(md);
1175 if (!hc || hc->md != md) { 1184 if (!hc || hc->md != md) {
@@ -1186,7 +1195,7 @@ static int table_load(struct dm_ioctl *param, size_t param_size)
1186 up_write(&_hash_lock); 1195 up_write(&_hash_lock);
1187 1196
1188 param->flags |= DM_INACTIVE_PRESENT_FLAG; 1197 param->flags |= DM_INACTIVE_PRESENT_FLAG;
1189 r = __dev_status(md, param); 1198 __dev_status(md, param);
1190 1199
1191out: 1200out:
1192 dm_put(md); 1201 dm_put(md);
@@ -1196,7 +1205,6 @@ out:
1196 1205
1197static int table_clear(struct dm_ioctl *param, size_t param_size) 1206static int table_clear(struct dm_ioctl *param, size_t param_size)
1198{ 1207{
1199 int r;
1200 struct hash_cell *hc; 1208 struct hash_cell *hc;
1201 struct mapped_device *md; 1209 struct mapped_device *md;
1202 1210
@@ -1216,11 +1224,12 @@ static int table_clear(struct dm_ioctl *param, size_t param_size)
1216 1224
1217 param->flags &= ~DM_INACTIVE_PRESENT_FLAG; 1225 param->flags &= ~DM_INACTIVE_PRESENT_FLAG;
1218 1226
1219 r = __dev_status(hc->md, param); 1227 __dev_status(hc->md, param);
1220 md = hc->md; 1228 md = hc->md;
1221 up_write(&_hash_lock); 1229 up_write(&_hash_lock);
1222 dm_put(md); 1230 dm_put(md);
1223 return r; 1231
1232 return 0;
1224} 1233}
1225 1234
1226/* 1235/*
@@ -1265,7 +1274,6 @@ static void retrieve_deps(struct dm_table *table,
1265 1274
1266static int table_deps(struct dm_ioctl *param, size_t param_size) 1275static int table_deps(struct dm_ioctl *param, size_t param_size)
1267{ 1276{
1268 int r = 0;
1269 struct mapped_device *md; 1277 struct mapped_device *md;
1270 struct dm_table *table; 1278 struct dm_table *table;
1271 1279
@@ -1273,9 +1281,7 @@ static int table_deps(struct dm_ioctl *param, size_t param_size)
1273 if (!md) 1281 if (!md)
1274 return -ENXIO; 1282 return -ENXIO;
1275 1283
1276 r = __dev_status(md, param); 1284 __dev_status(md, param);
1277 if (r)
1278 goto out;
1279 1285
1280 table = dm_get_live_or_inactive_table(md, param); 1286 table = dm_get_live_or_inactive_table(md, param);
1281 if (table) { 1287 if (table) {
@@ -1283,9 +1289,9 @@ static int table_deps(struct dm_ioctl *param, size_t param_size)
1283 dm_table_put(table); 1289 dm_table_put(table);
1284 } 1290 }
1285 1291
1286 out:
1287 dm_put(md); 1292 dm_put(md);
1288 return r; 1293
1294 return 0;
1289} 1295}
1290 1296
1291/* 1297/*
@@ -1294,7 +1300,6 @@ static int table_deps(struct dm_ioctl *param, size_t param_size)
1294 */ 1300 */
1295static int table_status(struct dm_ioctl *param, size_t param_size) 1301static int table_status(struct dm_ioctl *param, size_t param_size)
1296{ 1302{
1297 int r;
1298 struct mapped_device *md; 1303 struct mapped_device *md;
1299 struct dm_table *table; 1304 struct dm_table *table;
1300 1305
@@ -1302,9 +1307,7 @@ static int table_status(struct dm_ioctl *param, size_t param_size)
1302 if (!md) 1307 if (!md)
1303 return -ENXIO; 1308 return -ENXIO;
1304 1309
1305 r = __dev_status(md, param); 1310 __dev_status(md, param);
1306 if (r)
1307 goto out;
1308 1311
1309 table = dm_get_live_or_inactive_table(md, param); 1312 table = dm_get_live_or_inactive_table(md, param);
1310 if (table) { 1313 if (table) {
@@ -1312,9 +1315,9 @@ static int table_status(struct dm_ioctl *param, size_t param_size)
1312 dm_table_put(table); 1315 dm_table_put(table);
1313 } 1316 }
1314 1317
1315out:
1316 dm_put(md); 1318 dm_put(md);
1317 return r; 1319
1320 return 0;
1318} 1321}
1319 1322
1320/* 1323/*
@@ -1333,10 +1336,6 @@ static int target_message(struct dm_ioctl *param, size_t param_size)
1333 if (!md) 1336 if (!md)
1334 return -ENXIO; 1337 return -ENXIO;
1335 1338
1336 r = __dev_status(md, param);
1337 if (r)
1338 goto out;
1339
1340 if (tmsg < (struct dm_target_msg *) param->data || 1339 if (tmsg < (struct dm_target_msg *) param->data ||
1341 invalid_str(tmsg->message, (void *) param + param_size)) { 1340 invalid_str(tmsg->message, (void *) param + param_size)) {
1342 DMWARN("Invalid target message parameters."); 1341 DMWARN("Invalid target message parameters.");
@@ -1593,18 +1592,22 @@ static long dm_compat_ctl_ioctl(struct file *file, uint command, ulong u)
1593#endif 1592#endif
1594 1593
1595static const struct file_operations _ctl_fops = { 1594static const struct file_operations _ctl_fops = {
1595 .open = nonseekable_open,
1596 .unlocked_ioctl = dm_ctl_ioctl, 1596 .unlocked_ioctl = dm_ctl_ioctl,
1597 .compat_ioctl = dm_compat_ctl_ioctl, 1597 .compat_ioctl = dm_compat_ctl_ioctl,
1598 .owner = THIS_MODULE, 1598 .owner = THIS_MODULE,
1599}; 1599};
1600 1600
1601static struct miscdevice _dm_misc = { 1601static struct miscdevice _dm_misc = {
1602 .minor = MISC_DYNAMIC_MINOR, 1602 .minor = MAPPER_CTRL_MINOR,
1603 .name = DM_NAME, 1603 .name = DM_NAME,
1604 .nodename = "mapper/control", 1604 .nodename = DM_DIR "/" DM_CONTROL_NODE,
1605 .fops = &_ctl_fops 1605 .fops = &_ctl_fops
1606}; 1606};
1607 1607
1608MODULE_ALIAS_MISCDEV(MAPPER_CTRL_MINOR);
1609MODULE_ALIAS("devname:" DM_DIR "/" DM_CONTROL_NODE);
1610
1608/* 1611/*
1609 * Create misc character device and link to DM_DIR/control. 1612 * Create misc character device and link to DM_DIR/control.
1610 */ 1613 */
diff --git a/drivers/md/dm-kcopyd.c b/drivers/md/dm-kcopyd.c
index addf83475040..d8587bac5682 100644
--- a/drivers/md/dm-kcopyd.c
+++ b/drivers/md/dm-kcopyd.c
@@ -345,7 +345,7 @@ static int run_io_job(struct kcopyd_job *job)
345{ 345{
346 int r; 346 int r;
347 struct dm_io_request io_req = { 347 struct dm_io_request io_req = {
348 .bi_rw = job->rw | (1 << BIO_RW_SYNCIO) | (1 << BIO_RW_UNPLUG), 348 .bi_rw = job->rw | REQ_SYNC | REQ_UNPLUG,
349 .mem.type = DM_IO_PAGE_LIST, 349 .mem.type = DM_IO_PAGE_LIST,
350 .mem.ptr.pl = job->pages, 350 .mem.ptr.pl = job->pages,
351 .mem.offset = job->offset, 351 .mem.offset = job->offset,
diff --git a/drivers/md/dm-linear.c b/drivers/md/dm-linear.c
index 9200dbf2391a..3921e3bb43c1 100644
--- a/drivers/md/dm-linear.c
+++ b/drivers/md/dm-linear.c
@@ -53,6 +53,7 @@ static int linear_ctr(struct dm_target *ti, unsigned int argc, char **argv)
53 } 53 }
54 54
55 ti->num_flush_requests = 1; 55 ti->num_flush_requests = 1;
56 ti->num_discard_requests = 1;
56 ti->private = lc; 57 ti->private = lc;
57 return 0; 58 return 0;
58 59
@@ -73,7 +74,7 @@ static sector_t linear_map_sector(struct dm_target *ti, sector_t bi_sector)
73{ 74{
74 struct linear_c *lc = ti->private; 75 struct linear_c *lc = ti->private;
75 76
76 return lc->start + (bi_sector - ti->begin); 77 return lc->start + dm_target_offset(ti, bi_sector);
77} 78}
78 79
79static void linear_map_bio(struct dm_target *ti, struct bio *bio) 80static void linear_map_bio(struct dm_target *ti, struct bio *bio)
diff --git a/drivers/md/dm-mpath.c b/drivers/md/dm-mpath.c
index 826bce7343b3..487ecda90ad4 100644
--- a/drivers/md/dm-mpath.c
+++ b/drivers/md/dm-mpath.c
@@ -706,6 +706,7 @@ static struct priority_group *parse_priority_group(struct arg_set *as,
706 706
707 if (as->argc < nr_params) { 707 if (as->argc < nr_params) {
708 ti->error = "not enough path parameters"; 708 ti->error = "not enough path parameters";
709 r = -EINVAL;
709 goto bad; 710 goto bad;
710 } 711 }
711 712
@@ -892,6 +893,7 @@ static int multipath_ctr(struct dm_target *ti, unsigned int argc,
892 } 893 }
893 894
894 ti->num_flush_requests = 1; 895 ti->num_flush_requests = 1;
896 ti->num_discard_requests = 1;
895 897
896 return 0; 898 return 0;
897 899
@@ -1271,6 +1273,15 @@ static int do_end_io(struct multipath *m, struct request *clone,
1271 if (error == -EOPNOTSUPP) 1273 if (error == -EOPNOTSUPP)
1272 return error; 1274 return error;
1273 1275
1276 if (clone->cmd_flags & REQ_DISCARD)
1277 /*
1278 * Pass all discard request failures up.
1279 * FIXME: only fail_path if the discard failed due to a
1280 * transport problem. This requires precise understanding
1281 * of the underlying failure (e.g. the SCSI sense).
1282 */
1283 return error;
1284
1274 if (mpio->pgpath) 1285 if (mpio->pgpath)
1275 fail_path(mpio->pgpath); 1286 fail_path(mpio->pgpath);
1276 1287
diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
index ddda531723dc..7c081bcbc3cf 100644
--- a/drivers/md/dm-raid1.c
+++ b/drivers/md/dm-raid1.c
@@ -445,7 +445,7 @@ static sector_t map_sector(struct mirror *m, struct bio *bio)
445{ 445{
446 if (unlikely(!bio->bi_size)) 446 if (unlikely(!bio->bi_size))
447 return 0; 447 return 0;
448 return m->offset + (bio->bi_sector - m->ms->ti->begin); 448 return m->offset + dm_target_offset(m->ms->ti, bio->bi_sector);
449} 449}
450 450
451static void map_bio(struct mirror *m, struct bio *bio) 451static void map_bio(struct mirror *m, struct bio *bio)
@@ -1211,7 +1211,7 @@ static int mirror_end_io(struct dm_target *ti, struct bio *bio,
1211 if (error == -EOPNOTSUPP) 1211 if (error == -EOPNOTSUPP)
1212 goto out; 1212 goto out;
1213 1213
1214 if ((error == -EWOULDBLOCK) && bio_rw_flagged(bio, BIO_RW_AHEAD)) 1214 if ((error == -EWOULDBLOCK) && (bio->bi_rw & REQ_RAHEAD))
1215 goto out; 1215 goto out;
1216 1216
1217 if (unlikely(error)) { 1217 if (unlikely(error)) {
diff --git a/drivers/md/dm-snap-persistent.c b/drivers/md/dm-snap-persistent.c
index c097d8a4823d..cc2bdb83f9ad 100644
--- a/drivers/md/dm-snap-persistent.c
+++ b/drivers/md/dm-snap-persistent.c
@@ -266,7 +266,7 @@ static int chunk_io(struct pstore *ps, void *area, chunk_t chunk, int rw,
266 */ 266 */
267static chunk_t area_location(struct pstore *ps, chunk_t area) 267static chunk_t area_location(struct pstore *ps, chunk_t area)
268{ 268{
269 return 1 + ((ps->exceptions_per_area + 1) * area); 269 return NUM_SNAPSHOT_HDR_CHUNKS + ((ps->exceptions_per_area + 1) * area);
270} 270}
271 271
272/* 272/*
@@ -780,8 +780,8 @@ static int persistent_commit_merge(struct dm_exception_store *store,
780 * ps->current_area does not get reduced by prepare_merge() until 780 * ps->current_area does not get reduced by prepare_merge() until
781 * after commit_merge() has removed the nr_merged previous exceptions. 781 * after commit_merge() has removed the nr_merged previous exceptions.
782 */ 782 */
783 ps->next_free = (area_location(ps, ps->current_area) - 1) + 783 ps->next_free = area_location(ps, ps->current_area) +
784 (ps->current_committed + 1) + NUM_SNAPSHOT_HDR_CHUNKS; 784 ps->current_committed + 1;
785 785
786 return 0; 786 return 0;
787} 787}
diff --git a/drivers/md/dm-snap.c b/drivers/md/dm-snap.c
index 54853773510c..5974d3094d97 100644
--- a/drivers/md/dm-snap.c
+++ b/drivers/md/dm-snap.c
@@ -148,6 +148,12 @@ struct dm_snapshot {
148#define RUNNING_MERGE 0 148#define RUNNING_MERGE 0
149#define SHUTDOWN_MERGE 1 149#define SHUTDOWN_MERGE 1
150 150
151struct dm_dev *dm_snap_origin(struct dm_snapshot *s)
152{
153 return s->origin;
154}
155EXPORT_SYMBOL(dm_snap_origin);
156
151struct dm_dev *dm_snap_cow(struct dm_snapshot *s) 157struct dm_dev *dm_snap_cow(struct dm_snapshot *s)
152{ 158{
153 return s->cow; 159 return s->cow;
@@ -1065,10 +1071,6 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv)
1065 origin_mode = FMODE_WRITE; 1071 origin_mode = FMODE_WRITE;
1066 } 1072 }
1067 1073
1068 origin_path = argv[0];
1069 argv++;
1070 argc--;
1071
1072 s = kmalloc(sizeof(*s), GFP_KERNEL); 1074 s = kmalloc(sizeof(*s), GFP_KERNEL);
1073 if (!s) { 1075 if (!s) {
1074 ti->error = "Cannot allocate snapshot context private " 1076 ti->error = "Cannot allocate snapshot context private "
@@ -1077,6 +1079,16 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv)
1077 goto bad; 1079 goto bad;
1078 } 1080 }
1079 1081
1082 origin_path = argv[0];
1083 argv++;
1084 argc--;
1085
1086 r = dm_get_device(ti, origin_path, origin_mode, &s->origin);
1087 if (r) {
1088 ti->error = "Cannot get origin device";
1089 goto bad_origin;
1090 }
1091
1080 cow_path = argv[0]; 1092 cow_path = argv[0];
1081 argv++; 1093 argv++;
1082 argc--; 1094 argc--;
@@ -1097,12 +1109,6 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv)
1097 argv += args_used; 1109 argv += args_used;
1098 argc -= args_used; 1110 argc -= args_used;
1099 1111
1100 r = dm_get_device(ti, origin_path, origin_mode, &s->origin);
1101 if (r) {
1102 ti->error = "Cannot get origin device";
1103 goto bad_origin;
1104 }
1105
1106 s->ti = ti; 1112 s->ti = ti;
1107 s->valid = 1; 1113 s->valid = 1;
1108 s->active = 0; 1114 s->active = 0;
@@ -1212,15 +1218,15 @@ bad_kcopyd:
1212 dm_exception_table_exit(&s->complete, exception_cache); 1218 dm_exception_table_exit(&s->complete, exception_cache);
1213 1219
1214bad_hash_tables: 1220bad_hash_tables:
1215 dm_put_device(ti, s->origin);
1216
1217bad_origin:
1218 dm_exception_store_destroy(s->store); 1221 dm_exception_store_destroy(s->store);
1219 1222
1220bad_store: 1223bad_store:
1221 dm_put_device(ti, s->cow); 1224 dm_put_device(ti, s->cow);
1222 1225
1223bad_cow: 1226bad_cow:
1227 dm_put_device(ti, s->origin);
1228
1229bad_origin:
1224 kfree(s); 1230 kfree(s);
1225 1231
1226bad: 1232bad:
@@ -1314,12 +1320,12 @@ static void snapshot_dtr(struct dm_target *ti)
1314 1320
1315 mempool_destroy(s->pending_pool); 1321 mempool_destroy(s->pending_pool);
1316 1322
1317 dm_put_device(ti, s->origin);
1318
1319 dm_exception_store_destroy(s->store); 1323 dm_exception_store_destroy(s->store);
1320 1324
1321 dm_put_device(ti, s->cow); 1325 dm_put_device(ti, s->cow);
1322 1326
1327 dm_put_device(ti, s->origin);
1328
1323 kfree(s); 1329 kfree(s);
1324} 1330}
1325 1331
@@ -1686,7 +1692,7 @@ static int snapshot_merge_map(struct dm_target *ti, struct bio *bio,
1686 chunk_t chunk; 1692 chunk_t chunk;
1687 1693
1688 if (unlikely(bio_empty_barrier(bio))) { 1694 if (unlikely(bio_empty_barrier(bio))) {
1689 if (!map_context->flush_request) 1695 if (!map_context->target_request_nr)
1690 bio->bi_bdev = s->origin->bdev; 1696 bio->bi_bdev = s->origin->bdev;
1691 else 1697 else
1692 bio->bi_bdev = s->cow->bdev; 1698 bio->bi_bdev = s->cow->bdev;
@@ -1899,8 +1905,14 @@ static int snapshot_iterate_devices(struct dm_target *ti,
1899 iterate_devices_callout_fn fn, void *data) 1905 iterate_devices_callout_fn fn, void *data)
1900{ 1906{
1901 struct dm_snapshot *snap = ti->private; 1907 struct dm_snapshot *snap = ti->private;
1908 int r;
1909
1910 r = fn(ti, snap->origin, 0, ti->len, data);
1911
1912 if (!r)
1913 r = fn(ti, snap->cow, 0, get_dev_size(snap->cow->bdev), data);
1902 1914
1903 return fn(ti, snap->origin, 0, ti->len, data); 1915 return r;
1904} 1916}
1905 1917
1906 1918
@@ -2159,6 +2171,21 @@ static int origin_status(struct dm_target *ti, status_type_t type, char *result,
2159 return 0; 2171 return 0;
2160} 2172}
2161 2173
2174static int origin_merge(struct dm_target *ti, struct bvec_merge_data *bvm,
2175 struct bio_vec *biovec, int max_size)
2176{
2177 struct dm_dev *dev = ti->private;
2178 struct request_queue *q = bdev_get_queue(dev->bdev);
2179
2180 if (!q->merge_bvec_fn)
2181 return max_size;
2182
2183 bvm->bi_bdev = dev->bdev;
2184 bvm->bi_sector = bvm->bi_sector;
2185
2186 return min(max_size, q->merge_bvec_fn(q, bvm, biovec));
2187}
2188
2162static int origin_iterate_devices(struct dm_target *ti, 2189static int origin_iterate_devices(struct dm_target *ti,
2163 iterate_devices_callout_fn fn, void *data) 2190 iterate_devices_callout_fn fn, void *data)
2164{ 2191{
@@ -2176,6 +2203,7 @@ static struct target_type origin_target = {
2176 .map = origin_map, 2203 .map = origin_map,
2177 .resume = origin_resume, 2204 .resume = origin_resume,
2178 .status = origin_status, 2205 .status = origin_status,
2206 .merge = origin_merge,
2179 .iterate_devices = origin_iterate_devices, 2207 .iterate_devices = origin_iterate_devices,
2180}; 2208};
2181 2209
diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
index e610725db766..c297f6da91ea 100644
--- a/drivers/md/dm-stripe.c
+++ b/drivers/md/dm-stripe.c
@@ -25,6 +25,8 @@ struct stripe {
25 25
26struct stripe_c { 26struct stripe_c {
27 uint32_t stripes; 27 uint32_t stripes;
28 int stripes_shift;
29 sector_t stripes_mask;
28 30
29 /* The size of this target / num. stripes */ 31 /* The size of this target / num. stripes */
30 sector_t stripe_width; 32 sector_t stripe_width;
@@ -162,16 +164,22 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
162 164
163 /* Set pointer to dm target; used in trigger_event */ 165 /* Set pointer to dm target; used in trigger_event */
164 sc->ti = ti; 166 sc->ti = ti;
165
166 sc->stripes = stripes; 167 sc->stripes = stripes;
167 sc->stripe_width = width; 168 sc->stripe_width = width;
169
170 if (stripes & (stripes - 1))
171 sc->stripes_shift = -1;
172 else {
173 sc->stripes_shift = ffs(stripes) - 1;
174 sc->stripes_mask = ((sector_t) stripes) - 1;
175 }
176
168 ti->split_io = chunk_size; 177 ti->split_io = chunk_size;
169 ti->num_flush_requests = stripes; 178 ti->num_flush_requests = stripes;
179 ti->num_discard_requests = stripes;
170 180
181 sc->chunk_shift = ffs(chunk_size) - 1;
171 sc->chunk_mask = ((sector_t) chunk_size) - 1; 182 sc->chunk_mask = ((sector_t) chunk_size) - 1;
172 for (sc->chunk_shift = 0; chunk_size; sc->chunk_shift++)
173 chunk_size >>= 1;
174 sc->chunk_shift--;
175 183
176 /* 184 /*
177 * Get the stripe destinations. 185 * Get the stripe destinations.
@@ -207,26 +215,79 @@ static void stripe_dtr(struct dm_target *ti)
207 kfree(sc); 215 kfree(sc);
208} 216}
209 217
218static void stripe_map_sector(struct stripe_c *sc, sector_t sector,
219 uint32_t *stripe, sector_t *result)
220{
221 sector_t offset = dm_target_offset(sc->ti, sector);
222 sector_t chunk = offset >> sc->chunk_shift;
223
224 if (sc->stripes_shift < 0)
225 *stripe = sector_div(chunk, sc->stripes);
226 else {
227 *stripe = chunk & sc->stripes_mask;
228 chunk >>= sc->stripes_shift;
229 }
230
231 *result = (chunk << sc->chunk_shift) | (offset & sc->chunk_mask);
232}
233
234static void stripe_map_range_sector(struct stripe_c *sc, sector_t sector,
235 uint32_t target_stripe, sector_t *result)
236{
237 uint32_t stripe;
238
239 stripe_map_sector(sc, sector, &stripe, result);
240 if (stripe == target_stripe)
241 return;
242 *result &= ~sc->chunk_mask; /* round down */
243 if (target_stripe < stripe)
244 *result += sc->chunk_mask + 1; /* next chunk */
245}
246
247static int stripe_map_discard(struct stripe_c *sc, struct bio *bio,
248 uint32_t target_stripe)
249{
250 sector_t begin, end;
251
252 stripe_map_range_sector(sc, bio->bi_sector, target_stripe, &begin);
253 stripe_map_range_sector(sc, bio->bi_sector + bio_sectors(bio),
254 target_stripe, &end);
255 if (begin < end) {
256 bio->bi_bdev = sc->stripe[target_stripe].dev->bdev;
257 bio->bi_sector = begin + sc->stripe[target_stripe].physical_start;
258 bio->bi_size = to_bytes(end - begin);
259 return DM_MAPIO_REMAPPED;
260 } else {
261 /* The range doesn't map to the target stripe */
262 bio_endio(bio, 0);
263 return DM_MAPIO_SUBMITTED;
264 }
265}
266
210static int stripe_map(struct dm_target *ti, struct bio *bio, 267static int stripe_map(struct dm_target *ti, struct bio *bio,
211 union map_info *map_context) 268 union map_info *map_context)
212{ 269{
213 struct stripe_c *sc = (struct stripe_c *) ti->private; 270 struct stripe_c *sc = ti->private;
214 sector_t offset, chunk;
215 uint32_t stripe; 271 uint32_t stripe;
272 unsigned target_request_nr;
216 273
217 if (unlikely(bio_empty_barrier(bio))) { 274 if (unlikely(bio_empty_barrier(bio))) {
218 BUG_ON(map_context->flush_request >= sc->stripes); 275 target_request_nr = map_context->target_request_nr;
219 bio->bi_bdev = sc->stripe[map_context->flush_request].dev->bdev; 276 BUG_ON(target_request_nr >= sc->stripes);
277 bio->bi_bdev = sc->stripe[target_request_nr].dev->bdev;
220 return DM_MAPIO_REMAPPED; 278 return DM_MAPIO_REMAPPED;
221 } 279 }
280 if (unlikely(bio->bi_rw & REQ_DISCARD)) {
281 target_request_nr = map_context->target_request_nr;
282 BUG_ON(target_request_nr >= sc->stripes);
283 return stripe_map_discard(sc, bio, target_request_nr);
284 }
222 285
223 offset = bio->bi_sector - ti->begin; 286 stripe_map_sector(sc, bio->bi_sector, &stripe, &bio->bi_sector);
224 chunk = offset >> sc->chunk_shift;
225 stripe = sector_div(chunk, sc->stripes);
226 287
288 bio->bi_sector += sc->stripe[stripe].physical_start;
227 bio->bi_bdev = sc->stripe[stripe].dev->bdev; 289 bio->bi_bdev = sc->stripe[stripe].dev->bdev;
228 bio->bi_sector = sc->stripe[stripe].physical_start + 290
229 (chunk << sc->chunk_shift) + (offset & sc->chunk_mask);
230 return DM_MAPIO_REMAPPED; 291 return DM_MAPIO_REMAPPED;
231} 292}
232 293
@@ -284,7 +345,7 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
284 if (!error) 345 if (!error)
285 return 0; /* I/O complete */ 346 return 0; /* I/O complete */
286 347
287 if ((error == -EWOULDBLOCK) && bio_rw_flagged(bio, BIO_RW_AHEAD)) 348 if ((error == -EWOULDBLOCK) && (bio->bi_rw & REQ_RAHEAD))
288 return error; 349 return error;
289 350
290 if (error == -EOPNOTSUPP) 351 if (error == -EOPNOTSUPP)
diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
index 9924ea23032d..f9fc07d7a4b9 100644
--- a/drivers/md/dm-table.c
+++ b/drivers/md/dm-table.c
@@ -54,6 +54,8 @@ struct dm_table {
54 sector_t *highs; 54 sector_t *highs;
55 struct dm_target *targets; 55 struct dm_target *targets;
56 56
57 unsigned discards_supported:1;
58
57 /* 59 /*
58 * Indicates the rw permissions for the new logical 60 * Indicates the rw permissions for the new logical
59 * device. This should be a combination of FMODE_READ 61 * device. This should be a combination of FMODE_READ
@@ -203,6 +205,7 @@ int dm_table_create(struct dm_table **result, fmode_t mode,
203 205
204 INIT_LIST_HEAD(&t->devices); 206 INIT_LIST_HEAD(&t->devices);
205 atomic_set(&t->holders, 0); 207 atomic_set(&t->holders, 0);
208 t->discards_supported = 1;
206 209
207 if (!num_targets) 210 if (!num_targets)
208 num_targets = KEYS_PER_NODE; 211 num_targets = KEYS_PER_NODE;
@@ -245,7 +248,7 @@ void dm_table_destroy(struct dm_table *t)
245 msleep(1); 248 msleep(1);
246 smp_mb(); 249 smp_mb();
247 250
248 /* free the indexes (see dm_table_complete) */ 251 /* free the indexes */
249 if (t->depth >= 2) 252 if (t->depth >= 2)
250 vfree(t->index[t->depth - 2]); 253 vfree(t->index[t->depth - 2]);
251 254
@@ -770,6 +773,9 @@ int dm_table_add_target(struct dm_table *t, const char *type,
770 773
771 t->highs[t->num_targets++] = tgt->begin + tgt->len - 1; 774 t->highs[t->num_targets++] = tgt->begin + tgt->len - 1;
772 775
776 if (!tgt->num_discard_requests)
777 t->discards_supported = 0;
778
773 return 0; 779 return 0;
774 780
775 bad: 781 bad:
@@ -778,7 +784,7 @@ int dm_table_add_target(struct dm_table *t, const char *type,
778 return r; 784 return r;
779} 785}
780 786
781int dm_table_set_type(struct dm_table *t) 787static int dm_table_set_type(struct dm_table *t)
782{ 788{
783 unsigned i; 789 unsigned i;
784 unsigned bio_based = 0, request_based = 0; 790 unsigned bio_based = 0, request_based = 0;
@@ -900,7 +906,7 @@ static int setup_indexes(struct dm_table *t)
900/* 906/*
901 * Builds the btree to index the map. 907 * Builds the btree to index the map.
902 */ 908 */
903int dm_table_complete(struct dm_table *t) 909static int dm_table_build_index(struct dm_table *t)
904{ 910{
905 int r = 0; 911 int r = 0;
906 unsigned int leaf_nodes; 912 unsigned int leaf_nodes;
@@ -919,6 +925,55 @@ int dm_table_complete(struct dm_table *t)
919 return r; 925 return r;
920} 926}
921 927
928/*
929 * Register the mapped device for blk_integrity support if
930 * the underlying devices support it.
931 */
932static int dm_table_prealloc_integrity(struct dm_table *t, struct mapped_device *md)
933{
934 struct list_head *devices = dm_table_get_devices(t);
935 struct dm_dev_internal *dd;
936
937 list_for_each_entry(dd, devices, list)
938 if (bdev_get_integrity(dd->dm_dev.bdev))
939 return blk_integrity_register(dm_disk(md), NULL);
940
941 return 0;
942}
943
944/*
945 * Prepares the table for use by building the indices,
946 * setting the type, and allocating mempools.
947 */
948int dm_table_complete(struct dm_table *t)
949{
950 int r;
951
952 r = dm_table_set_type(t);
953 if (r) {
954 DMERR("unable to set table type");
955 return r;
956 }
957
958 r = dm_table_build_index(t);
959 if (r) {
960 DMERR("unable to build btrees");
961 return r;
962 }
963
964 r = dm_table_prealloc_integrity(t, t->md);
965 if (r) {
966 DMERR("could not register integrity profile.");
967 return r;
968 }
969
970 r = dm_table_alloc_md_mempools(t);
971 if (r)
972 DMERR("unable to allocate mempools");
973
974 return r;
975}
976
922static DEFINE_MUTEX(_event_lock); 977static DEFINE_MUTEX(_event_lock);
923void dm_table_event_callback(struct dm_table *t, 978void dm_table_event_callback(struct dm_table *t,
924 void (*fn)(void *), void *context) 979 void (*fn)(void *), void *context)
@@ -1086,6 +1141,11 @@ void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,
1086 else 1141 else
1087 queue_flag_set_unlocked(QUEUE_FLAG_CLUSTER, q); 1142 queue_flag_set_unlocked(QUEUE_FLAG_CLUSTER, q);
1088 1143
1144 if (!dm_table_supports_discards(t))
1145 queue_flag_clear_unlocked(QUEUE_FLAG_DISCARD, q);
1146 else
1147 queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, q);
1148
1089 dm_table_set_integrity(t); 1149 dm_table_set_integrity(t);
1090 1150
1091 /* 1151 /*
@@ -1232,6 +1292,39 @@ struct mapped_device *dm_table_get_md(struct dm_table *t)
1232 return t->md; 1292 return t->md;
1233} 1293}
1234 1294
1295static int device_discard_capable(struct dm_target *ti, struct dm_dev *dev,
1296 sector_t start, sector_t len, void *data)
1297{
1298 struct request_queue *q = bdev_get_queue(dev->bdev);
1299
1300 return q && blk_queue_discard(q);
1301}
1302
1303bool dm_table_supports_discards(struct dm_table *t)
1304{
1305 struct dm_target *ti;
1306 unsigned i = 0;
1307
1308 if (!t->discards_supported)
1309 return 0;
1310
1311 /*
1312 * Ensure that at least one underlying device supports discards.
1313 * t->devices includes internal dm devices such as mirror logs
1314 * so we need to use iterate_devices here, which targets
1315 * supporting discard must provide.
1316 */
1317 while (i < dm_table_get_num_targets(t)) {
1318 ti = dm_table_get_target(t, i++);
1319
1320 if (ti->type->iterate_devices &&
1321 ti->type->iterate_devices(ti, device_discard_capable, NULL))
1322 return 1;
1323 }
1324
1325 return 0;
1326}
1327
1235EXPORT_SYMBOL(dm_vcalloc); 1328EXPORT_SYMBOL(dm_vcalloc);
1236EXPORT_SYMBOL(dm_get_device); 1329EXPORT_SYMBOL(dm_get_device);
1237EXPORT_SYMBOL(dm_put_device); 1330EXPORT_SYMBOL(dm_put_device);
diff --git a/drivers/md/dm-target.c b/drivers/md/dm-target.c
index 11dea11dc0b6..8da366cf381c 100644
--- a/drivers/md/dm-target.c
+++ b/drivers/md/dm-target.c
@@ -113,6 +113,11 @@ void dm_unregister_target(struct target_type *tt)
113 */ 113 */
114static int io_err_ctr(struct dm_target *tt, unsigned int argc, char **args) 114static int io_err_ctr(struct dm_target *tt, unsigned int argc, char **args)
115{ 115{
116 /*
117 * Return error for discards instead of -EOPNOTSUPP
118 */
119 tt->num_discard_requests = 1;
120
116 return 0; 121 return 0;
117} 122}
118 123
diff --git a/drivers/md/dm-zero.c b/drivers/md/dm-zero.c
index bbc97030c0c2..cc2b3cb81946 100644
--- a/drivers/md/dm-zero.c
+++ b/drivers/md/dm-zero.c
@@ -22,6 +22,11 @@ static int zero_ctr(struct dm_target *ti, unsigned int argc, char **argv)
22 return -EINVAL; 22 return -EINVAL;
23 } 23 }
24 24
25 /*
26 * Silently drop discards, avoiding -EOPNOTSUPP.
27 */
28 ti->num_discard_requests = 1;
29
25 return 0; 30 return 0;
26} 31}
27 32
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index d21e1284604f..ac384b2a6a33 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -15,10 +15,12 @@
15#include <linux/blkpg.h> 15#include <linux/blkpg.h>
16#include <linux/bio.h> 16#include <linux/bio.h>
17#include <linux/buffer_head.h> 17#include <linux/buffer_head.h>
18#include <linux/smp_lock.h>
18#include <linux/mempool.h> 19#include <linux/mempool.h>
19#include <linux/slab.h> 20#include <linux/slab.h>
20#include <linux/idr.h> 21#include <linux/idr.h>
21#include <linux/hdreg.h> 22#include <linux/hdreg.h>
23#include <linux/delay.h>
22 24
23#include <trace/events/block.h> 25#include <trace/events/block.h>
24 26
@@ -123,6 +125,10 @@ struct mapped_device {
123 unsigned long flags; 125 unsigned long flags;
124 126
125 struct request_queue *queue; 127 struct request_queue *queue;
128 unsigned type;
129 /* Protect queue and type against concurrent access. */
130 struct mutex type_lock;
131
126 struct gendisk *disk; 132 struct gendisk *disk;
127 char name[16]; 133 char name[16];
128 134
@@ -338,6 +344,7 @@ static int dm_blk_open(struct block_device *bdev, fmode_t mode)
338{ 344{
339 struct mapped_device *md; 345 struct mapped_device *md;
340 346
347 lock_kernel();
341 spin_lock(&_minor_lock); 348 spin_lock(&_minor_lock);
342 349
343 md = bdev->bd_disk->private_data; 350 md = bdev->bd_disk->private_data;
@@ -355,6 +362,7 @@ static int dm_blk_open(struct block_device *bdev, fmode_t mode)
355 362
356out: 363out:
357 spin_unlock(&_minor_lock); 364 spin_unlock(&_minor_lock);
365 unlock_kernel();
358 366
359 return md ? 0 : -ENXIO; 367 return md ? 0 : -ENXIO;
360} 368}
@@ -362,8 +370,12 @@ out:
362static int dm_blk_close(struct gendisk *disk, fmode_t mode) 370static int dm_blk_close(struct gendisk *disk, fmode_t mode)
363{ 371{
364 struct mapped_device *md = disk->private_data; 372 struct mapped_device *md = disk->private_data;
373
374 lock_kernel();
365 atomic_dec(&md->open_count); 375 atomic_dec(&md->open_count);
366 dm_put(md); 376 dm_put(md);
377 unlock_kernel();
378
367 return 0; 379 return 0;
368} 380}
369 381
@@ -614,7 +626,7 @@ static void dec_pending(struct dm_io *io, int error)
614 */ 626 */
615 spin_lock_irqsave(&md->deferred_lock, flags); 627 spin_lock_irqsave(&md->deferred_lock, flags);
616 if (__noflush_suspending(md)) { 628 if (__noflush_suspending(md)) {
617 if (!bio_rw_flagged(io->bio, BIO_RW_BARRIER)) 629 if (!(io->bio->bi_rw & REQ_HARDBARRIER))
618 bio_list_add_head(&md->deferred, 630 bio_list_add_head(&md->deferred,
619 io->bio); 631 io->bio);
620 } else 632 } else
@@ -626,13 +638,19 @@ static void dec_pending(struct dm_io *io, int error)
626 io_error = io->error; 638 io_error = io->error;
627 bio = io->bio; 639 bio = io->bio;
628 640
629 if (bio_rw_flagged(bio, BIO_RW_BARRIER)) { 641 if (bio->bi_rw & REQ_HARDBARRIER) {
630 /* 642 /*
631 * There can be just one barrier request so we use 643 * There can be just one barrier request so we use
632 * a per-device variable for error reporting. 644 * a per-device variable for error reporting.
633 * Note that you can't touch the bio after end_io_acct 645 * Note that you can't touch the bio after end_io_acct
646 *
647 * We ignore -EOPNOTSUPP for empty flush reported by
648 * underlying devices. We assume that if the device
649 * doesn't support empty barriers, it doesn't need
650 * cache flushing commands.
634 */ 651 */
635 if (!md->barrier_error && io_error != -EOPNOTSUPP) 652 if (!md->barrier_error &&
653 !(bio_empty_barrier(bio) && io_error == -EOPNOTSUPP))
636 md->barrier_error = io_error; 654 md->barrier_error = io_error;
637 end_io_acct(io); 655 end_io_acct(io);
638 free_io(md, io); 656 free_io(md, io);
@@ -792,12 +810,12 @@ static void dm_end_request(struct request *clone, int error)
792{ 810{
793 int rw = rq_data_dir(clone); 811 int rw = rq_data_dir(clone);
794 int run_queue = 1; 812 int run_queue = 1;
795 bool is_barrier = blk_barrier_rq(clone); 813 bool is_barrier = clone->cmd_flags & REQ_HARDBARRIER;
796 struct dm_rq_target_io *tio = clone->end_io_data; 814 struct dm_rq_target_io *tio = clone->end_io_data;
797 struct mapped_device *md = tio->md; 815 struct mapped_device *md = tio->md;
798 struct request *rq = tio->orig; 816 struct request *rq = tio->orig;
799 817
800 if (blk_pc_request(rq) && !is_barrier) { 818 if (rq->cmd_type == REQ_TYPE_BLOCK_PC && !is_barrier) {
801 rq->errors = clone->errors; 819 rq->errors = clone->errors;
802 rq->resid_len = clone->resid_len; 820 rq->resid_len = clone->resid_len;
803 821
@@ -844,7 +862,7 @@ void dm_requeue_unmapped_request(struct request *clone)
844 struct request_queue *q = rq->q; 862 struct request_queue *q = rq->q;
845 unsigned long flags; 863 unsigned long flags;
846 864
847 if (unlikely(blk_barrier_rq(clone))) { 865 if (unlikely(clone->cmd_flags & REQ_HARDBARRIER)) {
848 /* 866 /*
849 * Barrier clones share an original request. 867 * Barrier clones share an original request.
850 * Leave it to dm_end_request(), which handles this special 868 * Leave it to dm_end_request(), which handles this special
@@ -943,7 +961,7 @@ static void dm_complete_request(struct request *clone, int error)
943 struct dm_rq_target_io *tio = clone->end_io_data; 961 struct dm_rq_target_io *tio = clone->end_io_data;
944 struct request *rq = tio->orig; 962 struct request *rq = tio->orig;
945 963
946 if (unlikely(blk_barrier_rq(clone))) { 964 if (unlikely(clone->cmd_flags & REQ_HARDBARRIER)) {
947 /* 965 /*
948 * Barrier clones share an original request. So can't use 966 * Barrier clones share an original request. So can't use
949 * softirq_done with the original. 967 * softirq_done with the original.
@@ -972,7 +990,7 @@ void dm_kill_unmapped_request(struct request *clone, int error)
972 struct dm_rq_target_io *tio = clone->end_io_data; 990 struct dm_rq_target_io *tio = clone->end_io_data;
973 struct request *rq = tio->orig; 991 struct request *rq = tio->orig;
974 992
975 if (unlikely(blk_barrier_rq(clone))) { 993 if (unlikely(clone->cmd_flags & REQ_HARDBARRIER)) {
976 /* 994 /*
977 * Barrier clones share an original request. 995 * Barrier clones share an original request.
978 * Leave it to dm_end_request(), which handles this special 996 * Leave it to dm_end_request(), which handles this special
@@ -1012,17 +1030,27 @@ static void end_clone_request(struct request *clone, int error)
1012 dm_complete_request(clone, error); 1030 dm_complete_request(clone, error);
1013} 1031}
1014 1032
1015static sector_t max_io_len(struct mapped_device *md, 1033/*
1016 sector_t sector, struct dm_target *ti) 1034 * Return maximum size of I/O possible at the supplied sector up to the current
1035 * target boundary.
1036 */
1037static sector_t max_io_len_target_boundary(sector_t sector, struct dm_target *ti)
1017{ 1038{
1018 sector_t offset = sector - ti->begin; 1039 sector_t target_offset = dm_target_offset(ti, sector);
1019 sector_t len = ti->len - offset; 1040
1041 return ti->len - target_offset;
1042}
1043
1044static sector_t max_io_len(sector_t sector, struct dm_target *ti)
1045{
1046 sector_t len = max_io_len_target_boundary(sector, ti);
1020 1047
1021 /* 1048 /*
1022 * Does the target need to split even further ? 1049 * Does the target need to split even further ?
1023 */ 1050 */
1024 if (ti->split_io) { 1051 if (ti->split_io) {
1025 sector_t boundary; 1052 sector_t boundary;
1053 sector_t offset = dm_target_offset(ti, sector);
1026 boundary = ((offset + ti->split_io) & ~(ti->split_io - 1)) 1054 boundary = ((offset + ti->split_io) & ~(ti->split_io - 1))
1027 - offset; 1055 - offset;
1028 if (len > boundary) 1056 if (len > boundary)
@@ -1106,7 +1134,7 @@ static struct bio *split_bvec(struct bio *bio, sector_t sector,
1106 1134
1107 clone->bi_sector = sector; 1135 clone->bi_sector = sector;
1108 clone->bi_bdev = bio->bi_bdev; 1136 clone->bi_bdev = bio->bi_bdev;
1109 clone->bi_rw = bio->bi_rw & ~(1 << BIO_RW_BARRIER); 1137 clone->bi_rw = bio->bi_rw & ~REQ_HARDBARRIER;
1110 clone->bi_vcnt = 1; 1138 clone->bi_vcnt = 1;
1111 clone->bi_size = to_bytes(len); 1139 clone->bi_size = to_bytes(len);
1112 clone->bi_io_vec->bv_offset = offset; 1140 clone->bi_io_vec->bv_offset = offset;
@@ -1133,7 +1161,7 @@ static struct bio *clone_bio(struct bio *bio, sector_t sector,
1133 1161
1134 clone = bio_alloc_bioset(GFP_NOIO, bio->bi_max_vecs, bs); 1162 clone = bio_alloc_bioset(GFP_NOIO, bio->bi_max_vecs, bs);
1135 __bio_clone(clone, bio); 1163 __bio_clone(clone, bio);
1136 clone->bi_rw &= ~(1 << BIO_RW_BARRIER); 1164 clone->bi_rw &= ~REQ_HARDBARRIER;
1137 clone->bi_destructor = dm_bio_destructor; 1165 clone->bi_destructor = dm_bio_destructor;
1138 clone->bi_sector = sector; 1166 clone->bi_sector = sector;
1139 clone->bi_idx = idx; 1167 clone->bi_idx = idx;
@@ -1164,36 +1192,96 @@ static struct dm_target_io *alloc_tio(struct clone_info *ci,
1164 return tio; 1192 return tio;
1165} 1193}
1166 1194
1167static void __flush_target(struct clone_info *ci, struct dm_target *ti, 1195static void __issue_target_request(struct clone_info *ci, struct dm_target *ti,
1168 unsigned flush_nr) 1196 unsigned request_nr, sector_t len)
1169{ 1197{
1170 struct dm_target_io *tio = alloc_tio(ci, ti); 1198 struct dm_target_io *tio = alloc_tio(ci, ti);
1171 struct bio *clone; 1199 struct bio *clone;
1172 1200
1173 tio->info.flush_request = flush_nr; 1201 tio->info.target_request_nr = request_nr;
1174 1202
1175 clone = bio_alloc_bioset(GFP_NOIO, 0, ci->md->bs); 1203 /*
1204 * Discard requests require the bio's inline iovecs be initialized.
1205 * ci->bio->bi_max_vecs is BIO_INLINE_VECS anyway, for both flush
1206 * and discard, so no need for concern about wasted bvec allocations.
1207 */
1208 clone = bio_alloc_bioset(GFP_NOIO, ci->bio->bi_max_vecs, ci->md->bs);
1176 __bio_clone(clone, ci->bio); 1209 __bio_clone(clone, ci->bio);
1177 clone->bi_destructor = dm_bio_destructor; 1210 clone->bi_destructor = dm_bio_destructor;
1211 if (len) {
1212 clone->bi_sector = ci->sector;
1213 clone->bi_size = to_bytes(len);
1214 }
1178 1215
1179 __map_bio(ti, clone, tio); 1216 __map_bio(ti, clone, tio);
1180} 1217}
1181 1218
1219static void __issue_target_requests(struct clone_info *ci, struct dm_target *ti,
1220 unsigned num_requests, sector_t len)
1221{
1222 unsigned request_nr;
1223
1224 for (request_nr = 0; request_nr < num_requests; request_nr++)
1225 __issue_target_request(ci, ti, request_nr, len);
1226}
1227
1182static int __clone_and_map_empty_barrier(struct clone_info *ci) 1228static int __clone_and_map_empty_barrier(struct clone_info *ci)
1183{ 1229{
1184 unsigned target_nr = 0, flush_nr; 1230 unsigned target_nr = 0;
1185 struct dm_target *ti; 1231 struct dm_target *ti;
1186 1232
1187 while ((ti = dm_table_get_target(ci->map, target_nr++))) 1233 while ((ti = dm_table_get_target(ci->map, target_nr++)))
1188 for (flush_nr = 0; flush_nr < ti->num_flush_requests; 1234 __issue_target_requests(ci, ti, ti->num_flush_requests, 0);
1189 flush_nr++)
1190 __flush_target(ci, ti, flush_nr);
1191 1235
1192 ci->sector_count = 0; 1236 ci->sector_count = 0;
1193 1237
1194 return 0; 1238 return 0;
1195} 1239}
1196 1240
1241/*
1242 * Perform all io with a single clone.
1243 */
1244static void __clone_and_map_simple(struct clone_info *ci, struct dm_target *ti)
1245{
1246 struct bio *clone, *bio = ci->bio;
1247 struct dm_target_io *tio;
1248
1249 tio = alloc_tio(ci, ti);
1250 clone = clone_bio(bio, ci->sector, ci->idx,
1251 bio->bi_vcnt - ci->idx, ci->sector_count,
1252 ci->md->bs);
1253 __map_bio(ti, clone, tio);
1254 ci->sector_count = 0;
1255}
1256
1257static int __clone_and_map_discard(struct clone_info *ci)
1258{
1259 struct dm_target *ti;
1260 sector_t len;
1261
1262 do {
1263 ti = dm_table_find_target(ci->map, ci->sector);
1264 if (!dm_target_is_valid(ti))
1265 return -EIO;
1266
1267 /*
1268 * Even though the device advertised discard support,
1269 * reconfiguration might have changed that since the
1270 * check was performed.
1271 */
1272 if (!ti->num_discard_requests)
1273 return -EOPNOTSUPP;
1274
1275 len = min(ci->sector_count, max_io_len_target_boundary(ci->sector, ti));
1276
1277 __issue_target_requests(ci, ti, ti->num_discard_requests, len);
1278
1279 ci->sector += len;
1280 } while (ci->sector_count -= len);
1281
1282 return 0;
1283}
1284
1197static int __clone_and_map(struct clone_info *ci) 1285static int __clone_and_map(struct clone_info *ci)
1198{ 1286{
1199 struct bio *clone, *bio = ci->bio; 1287 struct bio *clone, *bio = ci->bio;
@@ -1204,27 +1292,21 @@ static int __clone_and_map(struct clone_info *ci)
1204 if (unlikely(bio_empty_barrier(bio))) 1292 if (unlikely(bio_empty_barrier(bio)))
1205 return __clone_and_map_empty_barrier(ci); 1293 return __clone_and_map_empty_barrier(ci);
1206 1294
1295 if (unlikely(bio->bi_rw & REQ_DISCARD))
1296 return __clone_and_map_discard(ci);
1297
1207 ti = dm_table_find_target(ci->map, ci->sector); 1298 ti = dm_table_find_target(ci->map, ci->sector);
1208 if (!dm_target_is_valid(ti)) 1299 if (!dm_target_is_valid(ti))
1209 return -EIO; 1300 return -EIO;
1210 1301
1211 max = max_io_len(ci->md, ci->sector, ti); 1302 max = max_io_len(ci->sector, ti);
1212
1213 /*
1214 * Allocate a target io object.
1215 */
1216 tio = alloc_tio(ci, ti);
1217 1303
1218 if (ci->sector_count <= max) { 1304 if (ci->sector_count <= max) {
1219 /* 1305 /*
1220 * Optimise for the simple case where we can do all of 1306 * Optimise for the simple case where we can do all of
1221 * the remaining io with a single clone. 1307 * the remaining io with a single clone.
1222 */ 1308 */
1223 clone = clone_bio(bio, ci->sector, ci->idx, 1309 __clone_and_map_simple(ci, ti);
1224 bio->bi_vcnt - ci->idx, ci->sector_count,
1225 ci->md->bs);
1226 __map_bio(ti, clone, tio);
1227 ci->sector_count = 0;
1228 1310
1229 } else if (to_sector(bio->bi_io_vec[ci->idx].bv_len) <= max) { 1311 } else if (to_sector(bio->bi_io_vec[ci->idx].bv_len) <= max) {
1230 /* 1312 /*
@@ -1245,6 +1327,7 @@ static int __clone_and_map(struct clone_info *ci)
1245 len += bv_len; 1327 len += bv_len;
1246 } 1328 }
1247 1329
1330 tio = alloc_tio(ci, ti);
1248 clone = clone_bio(bio, ci->sector, ci->idx, i - ci->idx, len, 1331 clone = clone_bio(bio, ci->sector, ci->idx, i - ci->idx, len,
1249 ci->md->bs); 1332 ci->md->bs);
1250 __map_bio(ti, clone, tio); 1333 __map_bio(ti, clone, tio);
@@ -1267,13 +1350,12 @@ static int __clone_and_map(struct clone_info *ci)
1267 if (!dm_target_is_valid(ti)) 1350 if (!dm_target_is_valid(ti))
1268 return -EIO; 1351 return -EIO;
1269 1352
1270 max = max_io_len(ci->md, ci->sector, ti); 1353 max = max_io_len(ci->sector, ti);
1271
1272 tio = alloc_tio(ci, ti);
1273 } 1354 }
1274 1355
1275 len = min(remaining, max); 1356 len = min(remaining, max);
1276 1357
1358 tio = alloc_tio(ci, ti);
1277 clone = split_bvec(bio, ci->sector, ci->idx, 1359 clone = split_bvec(bio, ci->sector, ci->idx,
1278 bv->bv_offset + offset, len, 1360 bv->bv_offset + offset, len,
1279 ci->md->bs); 1361 ci->md->bs);
@@ -1301,7 +1383,7 @@ static void __split_and_process_bio(struct mapped_device *md, struct bio *bio)
1301 1383
1302 ci.map = dm_get_live_table(md); 1384 ci.map = dm_get_live_table(md);
1303 if (unlikely(!ci.map)) { 1385 if (unlikely(!ci.map)) {
1304 if (!bio_rw_flagged(bio, BIO_RW_BARRIER)) 1386 if (!(bio->bi_rw & REQ_HARDBARRIER))
1305 bio_io_error(bio); 1387 bio_io_error(bio);
1306 else 1388 else
1307 if (!md->barrier_error) 1389 if (!md->barrier_error)
@@ -1355,7 +1437,7 @@ static int dm_merge_bvec(struct request_queue *q,
1355 /* 1437 /*
1356 * Find maximum amount of I/O that won't need splitting 1438 * Find maximum amount of I/O that won't need splitting
1357 */ 1439 */
1358 max_sectors = min(max_io_len(md, bvm->bi_sector, ti), 1440 max_sectors = min(max_io_len(bvm->bi_sector, ti),
1359 (sector_t) BIO_MAX_SECTORS); 1441 (sector_t) BIO_MAX_SECTORS);
1360 max_size = (max_sectors << SECTOR_SHIFT) - bvm->bi_size; 1442 max_size = (max_sectors << SECTOR_SHIFT) - bvm->bi_size;
1361 if (max_size < 0) 1443 if (max_size < 0)
@@ -1414,7 +1496,7 @@ static int _dm_request(struct request_queue *q, struct bio *bio)
1414 * we have to queue this io for later. 1496 * we have to queue this io for later.
1415 */ 1497 */
1416 if (unlikely(test_bit(DMF_QUEUE_IO_TO_THREAD, &md->flags)) || 1498 if (unlikely(test_bit(DMF_QUEUE_IO_TO_THREAD, &md->flags)) ||
1417 unlikely(bio_rw_flagged(bio, BIO_RW_BARRIER))) { 1499 unlikely(bio->bi_rw & REQ_HARDBARRIER)) {
1418 up_read(&md->io_lock); 1500 up_read(&md->io_lock);
1419 1501
1420 if (unlikely(test_bit(DMF_BLOCK_IO_FOR_SUSPEND, &md->flags)) && 1502 if (unlikely(test_bit(DMF_BLOCK_IO_FOR_SUSPEND, &md->flags)) &&
@@ -1455,20 +1537,9 @@ static int dm_request(struct request_queue *q, struct bio *bio)
1455 return _dm_request(q, bio); 1537 return _dm_request(q, bio);
1456} 1538}
1457 1539
1458/*
1459 * Mark this request as flush request, so that dm_request_fn() can
1460 * recognize.
1461 */
1462static void dm_rq_prepare_flush(struct request_queue *q, struct request *rq)
1463{
1464 rq->cmd_type = REQ_TYPE_LINUX_BLOCK;
1465 rq->cmd[0] = REQ_LB_OP_FLUSH;
1466}
1467
1468static bool dm_rq_is_flush_request(struct request *rq) 1540static bool dm_rq_is_flush_request(struct request *rq)
1469{ 1541{
1470 if (rq->cmd_type == REQ_TYPE_LINUX_BLOCK && 1542 if (rq->cmd_flags & REQ_FLUSH)
1471 rq->cmd[0] == REQ_LB_OP_FLUSH)
1472 return true; 1543 return true;
1473 else 1544 else
1474 return false; 1545 return false;
@@ -1849,6 +1920,28 @@ static const struct block_device_operations dm_blk_dops;
1849static void dm_wq_work(struct work_struct *work); 1920static void dm_wq_work(struct work_struct *work);
1850static void dm_rq_barrier_work(struct work_struct *work); 1921static void dm_rq_barrier_work(struct work_struct *work);
1851 1922
1923static void dm_init_md_queue(struct mapped_device *md)
1924{
1925 /*
1926 * Request-based dm devices cannot be stacked on top of bio-based dm
1927 * devices. The type of this dm device has not been decided yet.
1928 * The type is decided at the first table loading time.
1929 * To prevent problematic device stacking, clear the queue flag
1930 * for request stacking support until then.
1931 *
1932 * This queue is new, so no concurrency on the queue_flags.
1933 */
1934 queue_flag_clear_unlocked(QUEUE_FLAG_STACKABLE, md->queue);
1935
1936 md->queue->queuedata = md;
1937 md->queue->backing_dev_info.congested_fn = dm_any_congested;
1938 md->queue->backing_dev_info.congested_data = md;
1939 blk_queue_make_request(md->queue, dm_request);
1940 blk_queue_bounce_limit(md->queue, BLK_BOUNCE_ANY);
1941 md->queue->unplug_fn = dm_unplug_all;
1942 blk_queue_merge_bvec(md->queue, dm_merge_bvec);
1943}
1944
1852/* 1945/*
1853 * Allocate and initialise a blank device with a given minor. 1946 * Allocate and initialise a blank device with a given minor.
1854 */ 1947 */
@@ -1874,8 +1967,10 @@ static struct mapped_device *alloc_dev(int minor)
1874 if (r < 0) 1967 if (r < 0)
1875 goto bad_minor; 1968 goto bad_minor;
1876 1969
1970 md->type = DM_TYPE_NONE;
1877 init_rwsem(&md->io_lock); 1971 init_rwsem(&md->io_lock);
1878 mutex_init(&md->suspend_lock); 1972 mutex_init(&md->suspend_lock);
1973 mutex_init(&md->type_lock);
1879 spin_lock_init(&md->deferred_lock); 1974 spin_lock_init(&md->deferred_lock);
1880 spin_lock_init(&md->barrier_error_lock); 1975 spin_lock_init(&md->barrier_error_lock);
1881 rwlock_init(&md->map_lock); 1976 rwlock_init(&md->map_lock);
@@ -1886,34 +1981,11 @@ static struct mapped_device *alloc_dev(int minor)
1886 INIT_LIST_HEAD(&md->uevent_list); 1981 INIT_LIST_HEAD(&md->uevent_list);
1887 spin_lock_init(&md->uevent_lock); 1982 spin_lock_init(&md->uevent_lock);
1888 1983
1889 md->queue = blk_init_queue(dm_request_fn, NULL); 1984 md->queue = blk_alloc_queue(GFP_KERNEL);
1890 if (!md->queue) 1985 if (!md->queue)
1891 goto bad_queue; 1986 goto bad_queue;
1892 1987
1893 /* 1988 dm_init_md_queue(md);
1894 * Request-based dm devices cannot be stacked on top of bio-based dm
1895 * devices. The type of this dm device has not been decided yet,
1896 * although we initialized the queue using blk_init_queue().
1897 * The type is decided at the first table loading time.
1898 * To prevent problematic device stacking, clear the queue flag
1899 * for request stacking support until then.
1900 *
1901 * This queue is new, so no concurrency on the queue_flags.
1902 */
1903 queue_flag_clear_unlocked(QUEUE_FLAG_STACKABLE, md->queue);
1904 md->saved_make_request_fn = md->queue->make_request_fn;
1905 md->queue->queuedata = md;
1906 md->queue->backing_dev_info.congested_fn = dm_any_congested;
1907 md->queue->backing_dev_info.congested_data = md;
1908 blk_queue_make_request(md->queue, dm_request);
1909 blk_queue_bounce_limit(md->queue, BLK_BOUNCE_ANY);
1910 md->queue->unplug_fn = dm_unplug_all;
1911 blk_queue_merge_bvec(md->queue, dm_merge_bvec);
1912 blk_queue_softirq_done(md->queue, dm_softirq_done);
1913 blk_queue_prep_rq(md->queue, dm_prep_fn);
1914 blk_queue_lld_busy(md->queue, dm_lld_busy);
1915 blk_queue_ordered(md->queue, QUEUE_ORDERED_DRAIN_FLUSH,
1916 dm_rq_prepare_flush);
1917 1989
1918 md->disk = alloc_disk(1); 1990 md->disk = alloc_disk(1);
1919 if (!md->disk) 1991 if (!md->disk)
@@ -2128,6 +2200,72 @@ int dm_create(int minor, struct mapped_device **result)
2128 return 0; 2200 return 0;
2129} 2201}
2130 2202
2203/*
2204 * Functions to manage md->type.
2205 * All are required to hold md->type_lock.
2206 */
2207void dm_lock_md_type(struct mapped_device *md)
2208{
2209 mutex_lock(&md->type_lock);
2210}
2211
2212void dm_unlock_md_type(struct mapped_device *md)
2213{
2214 mutex_unlock(&md->type_lock);
2215}
2216
2217void dm_set_md_type(struct mapped_device *md, unsigned type)
2218{
2219 md->type = type;
2220}
2221
2222unsigned dm_get_md_type(struct mapped_device *md)
2223{
2224 return md->type;
2225}
2226
2227/*
2228 * Fully initialize a request-based queue (->elevator, ->request_fn, etc).
2229 */
2230static int dm_init_request_based_queue(struct mapped_device *md)
2231{
2232 struct request_queue *q = NULL;
2233
2234 if (md->queue->elevator)
2235 return 1;
2236
2237 /* Fully initialize the queue */
2238 q = blk_init_allocated_queue(md->queue, dm_request_fn, NULL);
2239 if (!q)
2240 return 0;
2241
2242 md->queue = q;
2243 md->saved_make_request_fn = md->queue->make_request_fn;
2244 dm_init_md_queue(md);
2245 blk_queue_softirq_done(md->queue, dm_softirq_done);
2246 blk_queue_prep_rq(md->queue, dm_prep_fn);
2247 blk_queue_lld_busy(md->queue, dm_lld_busy);
2248 blk_queue_ordered(md->queue, QUEUE_ORDERED_DRAIN_FLUSH);
2249
2250 elv_register_queue(md->queue);
2251
2252 return 1;
2253}
2254
2255/*
2256 * Setup the DM device's queue based on md's type
2257 */
2258int dm_setup_md_queue(struct mapped_device *md)
2259{
2260 if ((dm_get_md_type(md) == DM_TYPE_REQUEST_BASED) &&
2261 !dm_init_request_based_queue(md)) {
2262 DMWARN("Cannot initialize queue for request-based mapped device");
2263 return -EINVAL;
2264 }
2265
2266 return 0;
2267}
2268
2131static struct mapped_device *dm_find_md(dev_t dev) 2269static struct mapped_device *dm_find_md(dev_t dev)
2132{ 2270{
2133 struct mapped_device *md; 2271 struct mapped_device *md;
@@ -2141,6 +2279,7 @@ static struct mapped_device *dm_find_md(dev_t dev)
2141 md = idr_find(&_minor_idr, minor); 2279 md = idr_find(&_minor_idr, minor);
2142 if (md && (md == MINOR_ALLOCED || 2280 if (md && (md == MINOR_ALLOCED ||
2143 (MINOR(disk_devt(dm_disk(md))) != minor) || 2281 (MINOR(disk_devt(dm_disk(md))) != minor) ||
2282 dm_deleting_md(md) ||
2144 test_bit(DMF_FREEING, &md->flags))) { 2283 test_bit(DMF_FREEING, &md->flags))) {
2145 md = NULL; 2284 md = NULL;
2146 goto out; 2285 goto out;
@@ -2175,6 +2314,7 @@ void dm_set_mdptr(struct mapped_device *md, void *ptr)
2175void dm_get(struct mapped_device *md) 2314void dm_get(struct mapped_device *md)
2176{ 2315{
2177 atomic_inc(&md->holders); 2316 atomic_inc(&md->holders);
2317 BUG_ON(test_bit(DMF_FREEING, &md->flags));
2178} 2318}
2179 2319
2180const char *dm_device_name(struct mapped_device *md) 2320const char *dm_device_name(struct mapped_device *md)
@@ -2183,27 +2323,55 @@ const char *dm_device_name(struct mapped_device *md)
2183} 2323}
2184EXPORT_SYMBOL_GPL(dm_device_name); 2324EXPORT_SYMBOL_GPL(dm_device_name);
2185 2325
2186void dm_put(struct mapped_device *md) 2326static void __dm_destroy(struct mapped_device *md, bool wait)
2187{ 2327{
2188 struct dm_table *map; 2328 struct dm_table *map;
2189 2329
2190 BUG_ON(test_bit(DMF_FREEING, &md->flags)); 2330 might_sleep();
2191 2331
2192 if (atomic_dec_and_lock(&md->holders, &_minor_lock)) { 2332 spin_lock(&_minor_lock);
2193 map = dm_get_live_table(md); 2333 map = dm_get_live_table(md);
2194 idr_replace(&_minor_idr, MINOR_ALLOCED, 2334 idr_replace(&_minor_idr, MINOR_ALLOCED, MINOR(disk_devt(dm_disk(md))));
2195 MINOR(disk_devt(dm_disk(md)))); 2335 set_bit(DMF_FREEING, &md->flags);
2196 set_bit(DMF_FREEING, &md->flags); 2336 spin_unlock(&_minor_lock);
2197 spin_unlock(&_minor_lock); 2337
2198 if (!dm_suspended_md(md)) { 2338 if (!dm_suspended_md(md)) {
2199 dm_table_presuspend_targets(map); 2339 dm_table_presuspend_targets(map);
2200 dm_table_postsuspend_targets(map); 2340 dm_table_postsuspend_targets(map);
2201 }
2202 dm_sysfs_exit(md);
2203 dm_table_put(map);
2204 dm_table_destroy(__unbind(md));
2205 free_dev(md);
2206 } 2341 }
2342
2343 /*
2344 * Rare, but there may be I/O requests still going to complete,
2345 * for example. Wait for all references to disappear.
2346 * No one should increment the reference count of the mapped_device,
2347 * after the mapped_device state becomes DMF_FREEING.
2348 */
2349 if (wait)
2350 while (atomic_read(&md->holders))
2351 msleep(1);
2352 else if (atomic_read(&md->holders))
2353 DMWARN("%s: Forcibly removing mapped_device still in use! (%d users)",
2354 dm_device_name(md), atomic_read(&md->holders));
2355
2356 dm_sysfs_exit(md);
2357 dm_table_put(map);
2358 dm_table_destroy(__unbind(md));
2359 free_dev(md);
2360}
2361
2362void dm_destroy(struct mapped_device *md)
2363{
2364 __dm_destroy(md, true);
2365}
2366
2367void dm_destroy_immediate(struct mapped_device *md)
2368{
2369 __dm_destroy(md, false);
2370}
2371
2372void dm_put(struct mapped_device *md)
2373{
2374 atomic_dec(&md->holders);
2207} 2375}
2208EXPORT_SYMBOL_GPL(dm_put); 2376EXPORT_SYMBOL_GPL(dm_put);
2209 2377
@@ -2258,7 +2426,12 @@ static void process_barrier(struct mapped_device *md, struct bio *bio)
2258 2426
2259 if (!bio_empty_barrier(bio)) { 2427 if (!bio_empty_barrier(bio)) {
2260 __split_and_process_bio(md, bio); 2428 __split_and_process_bio(md, bio);
2261 dm_flush(md); 2429 /*
2430 * If the request isn't supported, don't waste time with
2431 * the second flush.
2432 */
2433 if (md->barrier_error != -EOPNOTSUPP)
2434 dm_flush(md);
2262 } 2435 }
2263 2436
2264 if (md->barrier_error != DM_ENDIO_REQUEUE) 2437 if (md->barrier_error != DM_ENDIO_REQUEUE)
@@ -2296,7 +2469,7 @@ static void dm_wq_work(struct work_struct *work)
2296 if (dm_request_based(md)) 2469 if (dm_request_based(md))
2297 generic_make_request(c); 2470 generic_make_request(c);
2298 else { 2471 else {
2299 if (bio_rw_flagged(c, BIO_RW_BARRIER)) 2472 if (c->bi_rw & REQ_HARDBARRIER)
2300 process_barrier(md, c); 2473 process_barrier(md, c);
2301 else 2474 else
2302 __split_and_process_bio(md, c); 2475 __split_and_process_bio(md, c);
@@ -2315,11 +2488,11 @@ static void dm_queue_flush(struct mapped_device *md)
2315 queue_work(md->wq, &md->work); 2488 queue_work(md->wq, &md->work);
2316} 2489}
2317 2490
2318static void dm_rq_set_flush_nr(struct request *clone, unsigned flush_nr) 2491static void dm_rq_set_target_request_nr(struct request *clone, unsigned request_nr)
2319{ 2492{
2320 struct dm_rq_target_io *tio = clone->end_io_data; 2493 struct dm_rq_target_io *tio = clone->end_io_data;
2321 2494
2322 tio->info.flush_request = flush_nr; 2495 tio->info.target_request_nr = request_nr;
2323} 2496}
2324 2497
2325/* Issue barrier requests to targets and wait for their completion. */ 2498/* Issue barrier requests to targets and wait for their completion. */
@@ -2337,7 +2510,7 @@ static int dm_rq_barrier(struct mapped_device *md)
2337 ti = dm_table_get_target(map, i); 2510 ti = dm_table_get_target(map, i);
2338 for (j = 0; j < ti->num_flush_requests; j++) { 2511 for (j = 0; j < ti->num_flush_requests; j++) {
2339 clone = clone_rq(md->flush_request, md, GFP_NOIO); 2512 clone = clone_rq(md->flush_request, md, GFP_NOIO);
2340 dm_rq_set_flush_nr(clone, j); 2513 dm_rq_set_target_request_nr(clone, j);
2341 atomic_inc(&md->pending[rq_data_dir(clone)]); 2514 atomic_inc(&md->pending[rq_data_dir(clone)]);
2342 map_request(ti, clone, md); 2515 map_request(ti, clone, md);
2343 } 2516 }
@@ -2403,13 +2576,6 @@ struct dm_table *dm_swap_table(struct mapped_device *md, struct dm_table *table)
2403 goto out; 2576 goto out;
2404 } 2577 }
2405 2578
2406 /* cannot change the device type, once a table is bound */
2407 if (md->map &&
2408 (dm_table_get_type(md->map) != dm_table_get_type(table))) {
2409 DMWARN("can't change the device type after a table is bound");
2410 goto out;
2411 }
2412
2413 map = __bind(md, table, &limits); 2579 map = __bind(md, table, &limits);
2414 2580
2415out: 2581out:
diff --git a/drivers/md/dm.h b/drivers/md/dm.h
index bad1724d4869..0c2dd5f4af76 100644
--- a/drivers/md/dm.h
+++ b/drivers/md/dm.h
@@ -59,13 +59,20 @@ void dm_table_postsuspend_targets(struct dm_table *t);
59int dm_table_resume_targets(struct dm_table *t); 59int dm_table_resume_targets(struct dm_table *t);
60int dm_table_any_congested(struct dm_table *t, int bdi_bits); 60int dm_table_any_congested(struct dm_table *t, int bdi_bits);
61int dm_table_any_busy_target(struct dm_table *t); 61int dm_table_any_busy_target(struct dm_table *t);
62int dm_table_set_type(struct dm_table *t);
63unsigned dm_table_get_type(struct dm_table *t); 62unsigned dm_table_get_type(struct dm_table *t);
64bool dm_table_request_based(struct dm_table *t); 63bool dm_table_request_based(struct dm_table *t);
64bool dm_table_supports_discards(struct dm_table *t);
65int dm_table_alloc_md_mempools(struct dm_table *t); 65int dm_table_alloc_md_mempools(struct dm_table *t);
66void dm_table_free_md_mempools(struct dm_table *t); 66void dm_table_free_md_mempools(struct dm_table *t);
67struct dm_md_mempools *dm_table_get_md_mempools(struct dm_table *t); 67struct dm_md_mempools *dm_table_get_md_mempools(struct dm_table *t);
68 68
69void dm_lock_md_type(struct mapped_device *md);
70void dm_unlock_md_type(struct mapped_device *md);
71void dm_set_md_type(struct mapped_device *md, unsigned type);
72unsigned dm_get_md_type(struct mapped_device *md);
73
74int dm_setup_md_queue(struct mapped_device *md);
75
69/* 76/*
70 * To check the return value from dm_table_find_target(). 77 * To check the return value from dm_table_find_target().
71 */ 78 */
@@ -122,6 +129,11 @@ void dm_linear_exit(void);
122int dm_stripe_init(void); 129int dm_stripe_init(void);
123void dm_stripe_exit(void); 130void dm_stripe_exit(void);
124 131
132/*
133 * mapped_device operations
134 */
135void dm_destroy(struct mapped_device *md);
136void dm_destroy_immediate(struct mapped_device *md);
125int dm_open_count(struct mapped_device *md); 137int dm_open_count(struct mapped_device *md);
126int dm_lock_for_deletion(struct mapped_device *md); 138int dm_lock_for_deletion(struct mapped_device *md);
127 139
diff --git a/drivers/md/linear.c b/drivers/md/linear.c
index 7e0e057db9a7..ba19060bcf3f 100644
--- a/drivers/md/linear.c
+++ b/drivers/md/linear.c
@@ -294,7 +294,7 @@ static int linear_make_request (mddev_t *mddev, struct bio *bio)
294 dev_info_t *tmp_dev; 294 dev_info_t *tmp_dev;
295 sector_t start_sector; 295 sector_t start_sector;
296 296
297 if (unlikely(bio_rw_flagged(bio, BIO_RW_BARRIER))) { 297 if (unlikely(bio->bi_rw & REQ_HARDBARRIER)) {
298 md_barrier_request(mddev, bio); 298 md_barrier_request(mddev, bio);
299 return 0; 299 return 0;
300 } 300 }
diff --git a/drivers/md/md.c b/drivers/md/md.c
index cb20d0b0555a..11567c7999a2 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -36,6 +36,7 @@
36#include <linux/blkdev.h> 36#include <linux/blkdev.h>
37#include <linux/sysctl.h> 37#include <linux/sysctl.h>
38#include <linux/seq_file.h> 38#include <linux/seq_file.h>
39#include <linux/smp_lock.h>
39#include <linux/buffer_head.h> /* for invalidate_bdev */ 40#include <linux/buffer_head.h> /* for invalidate_bdev */
40#include <linux/poll.h> 41#include <linux/poll.h>
41#include <linux/ctype.h> 42#include <linux/ctype.h>
@@ -261,7 +262,7 @@ static int md_make_request(struct request_queue *q, struct bio *bio)
261 * Once ->stop is called and completes, the module will be completely 262 * Once ->stop is called and completes, the module will be completely
262 * unused. 263 * unused.
263 */ 264 */
264static void mddev_suspend(mddev_t *mddev) 265void mddev_suspend(mddev_t *mddev)
265{ 266{
266 BUG_ON(mddev->suspended); 267 BUG_ON(mddev->suspended);
267 mddev->suspended = 1; 268 mddev->suspended = 1;
@@ -269,13 +270,15 @@ static void mddev_suspend(mddev_t *mddev)
269 wait_event(mddev->sb_wait, atomic_read(&mddev->active_io) == 0); 270 wait_event(mddev->sb_wait, atomic_read(&mddev->active_io) == 0);
270 mddev->pers->quiesce(mddev, 1); 271 mddev->pers->quiesce(mddev, 1);
271} 272}
273EXPORT_SYMBOL_GPL(mddev_suspend);
272 274
273static void mddev_resume(mddev_t *mddev) 275void mddev_resume(mddev_t *mddev)
274{ 276{
275 mddev->suspended = 0; 277 mddev->suspended = 0;
276 wake_up(&mddev->sb_wait); 278 wake_up(&mddev->sb_wait);
277 mddev->pers->quiesce(mddev, 0); 279 mddev->pers->quiesce(mddev, 0);
278} 280}
281EXPORT_SYMBOL_GPL(mddev_resume);
279 282
280int mddev_congested(mddev_t *mddev, int bits) 283int mddev_congested(mddev_t *mddev, int bits)
281{ 284{
@@ -353,7 +356,7 @@ static void md_submit_barrier(struct work_struct *ws)
353 /* an empty barrier - all done */ 356 /* an empty barrier - all done */
354 bio_endio(bio, 0); 357 bio_endio(bio, 0);
355 else { 358 else {
356 bio->bi_rw &= ~(1<<BIO_RW_BARRIER); 359 bio->bi_rw &= ~REQ_HARDBARRIER;
357 if (mddev->pers->make_request(mddev, bio)) 360 if (mddev->pers->make_request(mddev, bio))
358 generic_make_request(bio); 361 generic_make_request(bio);
359 mddev->barrier = POST_REQUEST_BARRIER; 362 mddev->barrier = POST_REQUEST_BARRIER;
@@ -384,6 +387,51 @@ void md_barrier_request(mddev_t *mddev, struct bio *bio)
384} 387}
385EXPORT_SYMBOL(md_barrier_request); 388EXPORT_SYMBOL(md_barrier_request);
386 389
390/* Support for plugging.
391 * This mirrors the plugging support in request_queue, but does not
392 * require having a whole queue
393 */
394static void plugger_work(struct work_struct *work)
395{
396 struct plug_handle *plug =
397 container_of(work, struct plug_handle, unplug_work);
398 plug->unplug_fn(plug);
399}
400static void plugger_timeout(unsigned long data)
401{
402 struct plug_handle *plug = (void *)data;
403 kblockd_schedule_work(NULL, &plug->unplug_work);
404}
405void plugger_init(struct plug_handle *plug,
406 void (*unplug_fn)(struct plug_handle *))
407{
408 plug->unplug_flag = 0;
409 plug->unplug_fn = unplug_fn;
410 init_timer(&plug->unplug_timer);
411 plug->unplug_timer.function = plugger_timeout;
412 plug->unplug_timer.data = (unsigned long)plug;
413 INIT_WORK(&plug->unplug_work, plugger_work);
414}
415EXPORT_SYMBOL_GPL(plugger_init);
416
417void plugger_set_plug(struct plug_handle *plug)
418{
419 if (!test_and_set_bit(PLUGGED_FLAG, &plug->unplug_flag))
420 mod_timer(&plug->unplug_timer, jiffies + msecs_to_jiffies(3)+1);
421}
422EXPORT_SYMBOL_GPL(plugger_set_plug);
423
424int plugger_remove_plug(struct plug_handle *plug)
425{
426 if (test_and_clear_bit(PLUGGED_FLAG, &plug->unplug_flag)) {
427 del_timer(&plug->unplug_timer);
428 return 1;
429 } else
430 return 0;
431}
432EXPORT_SYMBOL_GPL(plugger_remove_plug);
433
434
387static inline mddev_t *mddev_get(mddev_t *mddev) 435static inline mddev_t *mddev_get(mddev_t *mddev)
388{ 436{
389 atomic_inc(&mddev->active); 437 atomic_inc(&mddev->active);
@@ -416,7 +464,7 @@ static void mddev_put(mddev_t *mddev)
416 spin_unlock(&all_mddevs_lock); 464 spin_unlock(&all_mddevs_lock);
417} 465}
418 466
419static void mddev_init(mddev_t *mddev) 467void mddev_init(mddev_t *mddev)
420{ 468{
421 mutex_init(&mddev->open_mutex); 469 mutex_init(&mddev->open_mutex);
422 mutex_init(&mddev->reconfig_mutex); 470 mutex_init(&mddev->reconfig_mutex);
@@ -436,6 +484,7 @@ static void mddev_init(mddev_t *mddev)
436 mddev->resync_max = MaxSector; 484 mddev->resync_max = MaxSector;
437 mddev->level = LEVEL_NONE; 485 mddev->level = LEVEL_NONE;
438} 486}
487EXPORT_SYMBOL_GPL(mddev_init);
439 488
440static mddev_t * mddev_find(dev_t unit) 489static mddev_t * mddev_find(dev_t unit)
441{ 490{
@@ -532,25 +581,31 @@ static void mddev_unlock(mddev_t * mddev)
532 * an access to the files will try to take reconfig_mutex 581 * an access to the files will try to take reconfig_mutex
533 * while holding the file unremovable, which leads to 582 * while holding the file unremovable, which leads to
534 * a deadlock. 583 * a deadlock.
535 * So hold open_mutex instead - we are allowed to take 584 * So hold set sysfs_active while the remove in happeing,
536 * it while holding reconfig_mutex, and md_run can 585 * and anything else which might set ->to_remove or my
537 * use it to wait for the remove to complete. 586 * otherwise change the sysfs namespace will fail with
587 * -EBUSY if sysfs_active is still set.
588 * We set sysfs_active under reconfig_mutex and elsewhere
589 * test it under the same mutex to ensure its correct value
590 * is seen.
538 */ 591 */
539 struct attribute_group *to_remove = mddev->to_remove; 592 struct attribute_group *to_remove = mddev->to_remove;
540 mddev->to_remove = NULL; 593 mddev->to_remove = NULL;
541 mutex_lock(&mddev->open_mutex); 594 mddev->sysfs_active = 1;
542 mutex_unlock(&mddev->reconfig_mutex); 595 mutex_unlock(&mddev->reconfig_mutex);
543 596
544 if (to_remove != &md_redundancy_group) 597 if (mddev->kobj.sd) {
545 sysfs_remove_group(&mddev->kobj, to_remove); 598 if (to_remove != &md_redundancy_group)
546 if (mddev->pers == NULL || 599 sysfs_remove_group(&mddev->kobj, to_remove);
547 mddev->pers->sync_request == NULL) { 600 if (mddev->pers == NULL ||
548 sysfs_remove_group(&mddev->kobj, &md_redundancy_group); 601 mddev->pers->sync_request == NULL) {
549 if (mddev->sysfs_action) 602 sysfs_remove_group(&mddev->kobj, &md_redundancy_group);
550 sysfs_put(mddev->sysfs_action); 603 if (mddev->sysfs_action)
551 mddev->sysfs_action = NULL; 604 sysfs_put(mddev->sysfs_action);
605 mddev->sysfs_action = NULL;
606 }
552 } 607 }
553 mutex_unlock(&mddev->open_mutex); 608 mddev->sysfs_active = 0;
554 } else 609 } else
555 mutex_unlock(&mddev->reconfig_mutex); 610 mutex_unlock(&mddev->reconfig_mutex);
556 611
@@ -675,11 +730,11 @@ void md_super_write(mddev_t *mddev, mdk_rdev_t *rdev,
675 * if zero is reached. 730 * if zero is reached.
676 * If an error occurred, call md_error 731 * If an error occurred, call md_error
677 * 732 *
678 * As we might need to resubmit the request if BIO_RW_BARRIER 733 * As we might need to resubmit the request if REQ_HARDBARRIER
679 * causes ENOTSUPP, we allocate a spare bio... 734 * causes ENOTSUPP, we allocate a spare bio...
680 */ 735 */
681 struct bio *bio = bio_alloc(GFP_NOIO, 1); 736 struct bio *bio = bio_alloc(GFP_NOIO, 1);
682 int rw = (1<<BIO_RW) | (1<<BIO_RW_SYNCIO) | (1<<BIO_RW_UNPLUG); 737 int rw = REQ_WRITE | REQ_SYNC | REQ_UNPLUG;
683 738
684 bio->bi_bdev = rdev->bdev; 739 bio->bi_bdev = rdev->bdev;
685 bio->bi_sector = sector; 740 bio->bi_sector = sector;
@@ -691,7 +746,7 @@ void md_super_write(mddev_t *mddev, mdk_rdev_t *rdev,
691 atomic_inc(&mddev->pending_writes); 746 atomic_inc(&mddev->pending_writes);
692 if (!test_bit(BarriersNotsupp, &rdev->flags)) { 747 if (!test_bit(BarriersNotsupp, &rdev->flags)) {
693 struct bio *rbio; 748 struct bio *rbio;
694 rw |= (1<<BIO_RW_BARRIER); 749 rw |= REQ_HARDBARRIER;
695 rbio = bio_clone(bio, GFP_NOIO); 750 rbio = bio_clone(bio, GFP_NOIO);
696 rbio->bi_private = bio; 751 rbio->bi_private = bio;
697 rbio->bi_end_io = super_written_barrier; 752 rbio->bi_end_io = super_written_barrier;
@@ -736,7 +791,7 @@ int sync_page_io(struct block_device *bdev, sector_t sector, int size,
736 struct completion event; 791 struct completion event;
737 int ret; 792 int ret;
738 793
739 rw |= (1 << BIO_RW_SYNCIO) | (1 << BIO_RW_UNPLUG); 794 rw |= REQ_SYNC | REQ_UNPLUG;
740 795
741 bio->bi_bdev = bdev; 796 bio->bi_bdev = bdev;
742 bio->bi_sector = sector; 797 bio->bi_sector = sector;
@@ -1811,11 +1866,9 @@ static int bind_rdev_to_array(mdk_rdev_t * rdev, mddev_t * mddev)
1811 goto fail; 1866 goto fail;
1812 1867
1813 ko = &part_to_dev(rdev->bdev->bd_part)->kobj; 1868 ko = &part_to_dev(rdev->bdev->bd_part)->kobj;
1814 if ((err = sysfs_create_link(&rdev->kobj, ko, "block"))) { 1869 if (sysfs_create_link(&rdev->kobj, ko, "block"))
1815 kobject_del(&rdev->kobj); 1870 /* failure here is OK */;
1816 goto fail; 1871 rdev->sysfs_state = sysfs_get_dirent_safe(rdev->kobj.sd, "state");
1817 }
1818 rdev->sysfs_state = sysfs_get_dirent(rdev->kobj.sd, NULL, "state");
1819 1872
1820 list_add_rcu(&rdev->same_set, &mddev->disks); 1873 list_add_rcu(&rdev->same_set, &mddev->disks);
1821 bd_claim_by_disk(rdev->bdev, rdev->bdev->bd_holder, mddev->gendisk); 1874 bd_claim_by_disk(rdev->bdev, rdev->bdev->bd_holder, mddev->gendisk);
@@ -2334,8 +2387,8 @@ state_store(mdk_rdev_t *rdev, const char *buf, size_t len)
2334 set_bit(In_sync, &rdev->flags); 2387 set_bit(In_sync, &rdev->flags);
2335 err = 0; 2388 err = 0;
2336 } 2389 }
2337 if (!err && rdev->sysfs_state) 2390 if (!err)
2338 sysfs_notify_dirent(rdev->sysfs_state); 2391 sysfs_notify_dirent_safe(rdev->sysfs_state);
2339 return err ? err : len; 2392 return err ? err : len;
2340} 2393}
2341static struct rdev_sysfs_entry rdev_state = 2394static struct rdev_sysfs_entry rdev_state =
@@ -2430,14 +2483,10 @@ slot_store(mdk_rdev_t *rdev, const char *buf, size_t len)
2430 rdev->raid_disk = -1; 2483 rdev->raid_disk = -1;
2431 return err; 2484 return err;
2432 } else 2485 } else
2433 sysfs_notify_dirent(rdev->sysfs_state); 2486 sysfs_notify_dirent_safe(rdev->sysfs_state);
2434 sprintf(nm, "rd%d", rdev->raid_disk); 2487 sprintf(nm, "rd%d", rdev->raid_disk);
2435 if (sysfs_create_link(&rdev->mddev->kobj, &rdev->kobj, nm)) 2488 if (sysfs_create_link(&rdev->mddev->kobj, &rdev->kobj, nm))
2436 printk(KERN_WARNING 2489 /* failure here is OK */;
2437 "md: cannot register "
2438 "%s for %s\n",
2439 nm, mdname(rdev->mddev));
2440
2441 /* don't wakeup anyone, leave that to userspace. */ 2490 /* don't wakeup anyone, leave that to userspace. */
2442 } else { 2491 } else {
2443 if (slot >= rdev->mddev->raid_disks) 2492 if (slot >= rdev->mddev->raid_disks)
@@ -2447,7 +2496,7 @@ slot_store(mdk_rdev_t *rdev, const char *buf, size_t len)
2447 clear_bit(Faulty, &rdev->flags); 2496 clear_bit(Faulty, &rdev->flags);
2448 clear_bit(WriteMostly, &rdev->flags); 2497 clear_bit(WriteMostly, &rdev->flags);
2449 set_bit(In_sync, &rdev->flags); 2498 set_bit(In_sync, &rdev->flags);
2450 sysfs_notify_dirent(rdev->sysfs_state); 2499 sysfs_notify_dirent_safe(rdev->sysfs_state);
2451 } 2500 }
2452 return len; 2501 return len;
2453} 2502}
@@ -2695,6 +2744,24 @@ static struct kobj_type rdev_ktype = {
2695 .default_attrs = rdev_default_attrs, 2744 .default_attrs = rdev_default_attrs,
2696}; 2745};
2697 2746
2747void md_rdev_init(mdk_rdev_t *rdev)
2748{
2749 rdev->desc_nr = -1;
2750 rdev->saved_raid_disk = -1;
2751 rdev->raid_disk = -1;
2752 rdev->flags = 0;
2753 rdev->data_offset = 0;
2754 rdev->sb_events = 0;
2755 rdev->last_read_error.tv_sec = 0;
2756 rdev->last_read_error.tv_nsec = 0;
2757 atomic_set(&rdev->nr_pending, 0);
2758 atomic_set(&rdev->read_errors, 0);
2759 atomic_set(&rdev->corrected_errors, 0);
2760
2761 INIT_LIST_HEAD(&rdev->same_set);
2762 init_waitqueue_head(&rdev->blocked_wait);
2763}
2764EXPORT_SYMBOL_GPL(md_rdev_init);
2698/* 2765/*
2699 * Import a device. If 'super_format' >= 0, then sanity check the superblock 2766 * Import a device. If 'super_format' >= 0, then sanity check the superblock
2700 * 2767 *
@@ -2718,6 +2785,7 @@ static mdk_rdev_t *md_import_device(dev_t newdev, int super_format, int super_mi
2718 return ERR_PTR(-ENOMEM); 2785 return ERR_PTR(-ENOMEM);
2719 } 2786 }
2720 2787
2788 md_rdev_init(rdev);
2721 if ((err = alloc_disk_sb(rdev))) 2789 if ((err = alloc_disk_sb(rdev)))
2722 goto abort_free; 2790 goto abort_free;
2723 2791
@@ -2727,18 +2795,6 @@ static mdk_rdev_t *md_import_device(dev_t newdev, int super_format, int super_mi
2727 2795
2728 kobject_init(&rdev->kobj, &rdev_ktype); 2796 kobject_init(&rdev->kobj, &rdev_ktype);
2729 2797
2730 rdev->desc_nr = -1;
2731 rdev->saved_raid_disk = -1;
2732 rdev->raid_disk = -1;
2733 rdev->flags = 0;
2734 rdev->data_offset = 0;
2735 rdev->sb_events = 0;
2736 rdev->last_read_error.tv_sec = 0;
2737 rdev->last_read_error.tv_nsec = 0;
2738 atomic_set(&rdev->nr_pending, 0);
2739 atomic_set(&rdev->read_errors, 0);
2740 atomic_set(&rdev->corrected_errors, 0);
2741
2742 size = rdev->bdev->bd_inode->i_size >> BLOCK_SIZE_BITS; 2798 size = rdev->bdev->bd_inode->i_size >> BLOCK_SIZE_BITS;
2743 if (!size) { 2799 if (!size) {
2744 printk(KERN_WARNING 2800 printk(KERN_WARNING
@@ -2767,9 +2823,6 @@ static mdk_rdev_t *md_import_device(dev_t newdev, int super_format, int super_mi
2767 } 2823 }
2768 } 2824 }
2769 2825
2770 INIT_LIST_HEAD(&rdev->same_set);
2771 init_waitqueue_head(&rdev->blocked_wait);
2772
2773 return rdev; 2826 return rdev;
2774 2827
2775abort_free: 2828abort_free:
@@ -2960,7 +3013,9 @@ level_store(mddev_t *mddev, const char *buf, size_t len)
2960 * - new personality will access other array. 3013 * - new personality will access other array.
2961 */ 3014 */
2962 3015
2963 if (mddev->sync_thread || mddev->reshape_position != MaxSector) 3016 if (mddev->sync_thread ||
3017 mddev->reshape_position != MaxSector ||
3018 mddev->sysfs_active)
2964 return -EBUSY; 3019 return -EBUSY;
2965 3020
2966 if (!mddev->pers->quiesce) { 3021 if (!mddev->pers->quiesce) {
@@ -3437,7 +3492,7 @@ array_state_store(mddev_t *mddev, const char *buf, size_t len)
3437 if (err) 3492 if (err)
3438 return err; 3493 return err;
3439 else { 3494 else {
3440 sysfs_notify_dirent(mddev->sysfs_state); 3495 sysfs_notify_dirent_safe(mddev->sysfs_state);
3441 return len; 3496 return len;
3442 } 3497 }
3443} 3498}
@@ -3735,7 +3790,7 @@ action_store(mddev_t *mddev, const char *page, size_t len)
3735 } 3790 }
3736 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); 3791 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
3737 md_wakeup_thread(mddev->thread); 3792 md_wakeup_thread(mddev->thread);
3738 sysfs_notify_dirent(mddev->sysfs_action); 3793 sysfs_notify_dirent_safe(mddev->sysfs_action);
3739 return len; 3794 return len;
3740} 3795}
3741 3796
@@ -4281,13 +4336,14 @@ static int md_alloc(dev_t dev, char *name)
4281 disk->disk_name); 4336 disk->disk_name);
4282 error = 0; 4337 error = 0;
4283 } 4338 }
4284 if (sysfs_create_group(&mddev->kobj, &md_bitmap_group)) 4339 if (mddev->kobj.sd &&
4340 sysfs_create_group(&mddev->kobj, &md_bitmap_group))
4285 printk(KERN_DEBUG "pointless warning\n"); 4341 printk(KERN_DEBUG "pointless warning\n");
4286 abort: 4342 abort:
4287 mutex_unlock(&disks_mutex); 4343 mutex_unlock(&disks_mutex);
4288 if (!error) { 4344 if (!error && mddev->kobj.sd) {
4289 kobject_uevent(&mddev->kobj, KOBJ_ADD); 4345 kobject_uevent(&mddev->kobj, KOBJ_ADD);
4290 mddev->sysfs_state = sysfs_get_dirent(mddev->kobj.sd, NULL, "array_state"); 4346 mddev->sysfs_state = sysfs_get_dirent_safe(mddev->kobj.sd, "array_state");
4291 } 4347 }
4292 mddev_put(mddev); 4348 mddev_put(mddev);
4293 return error; 4349 return error;
@@ -4325,14 +4381,14 @@ static void md_safemode_timeout(unsigned long data)
4325 if (!atomic_read(&mddev->writes_pending)) { 4381 if (!atomic_read(&mddev->writes_pending)) {
4326 mddev->safemode = 1; 4382 mddev->safemode = 1;
4327 if (mddev->external) 4383 if (mddev->external)
4328 sysfs_notify_dirent(mddev->sysfs_state); 4384 sysfs_notify_dirent_safe(mddev->sysfs_state);
4329 } 4385 }
4330 md_wakeup_thread(mddev->thread); 4386 md_wakeup_thread(mddev->thread);
4331} 4387}
4332 4388
4333static int start_dirty_degraded; 4389static int start_dirty_degraded;
4334 4390
4335static int md_run(mddev_t *mddev) 4391int md_run(mddev_t *mddev)
4336{ 4392{
4337 int err; 4393 int err;
4338 mdk_rdev_t *rdev; 4394 mdk_rdev_t *rdev;
@@ -4344,13 +4400,9 @@ static int md_run(mddev_t *mddev)
4344 4400
4345 if (mddev->pers) 4401 if (mddev->pers)
4346 return -EBUSY; 4402 return -EBUSY;
4347 4403 /* Cannot run until previous stop completes properly */
4348 /* These two calls synchronise us with the 4404 if (mddev->sysfs_active)
4349 * sysfs_remove_group calls in mddev_unlock, 4405 return -EBUSY;
4350 * so they must have completed.
4351 */
4352 mutex_lock(&mddev->open_mutex);
4353 mutex_unlock(&mddev->open_mutex);
4354 4406
4355 /* 4407 /*
4356 * Analyze all RAID superblock(s) 4408 * Analyze all RAID superblock(s)
@@ -4397,7 +4449,7 @@ static int md_run(mddev_t *mddev)
4397 return -EINVAL; 4449 return -EINVAL;
4398 } 4450 }
4399 } 4451 }
4400 sysfs_notify_dirent(rdev->sysfs_state); 4452 sysfs_notify_dirent_safe(rdev->sysfs_state);
4401 } 4453 }
4402 4454
4403 spin_lock(&pers_lock); 4455 spin_lock(&pers_lock);
@@ -4496,11 +4548,12 @@ static int md_run(mddev_t *mddev)
4496 return err; 4548 return err;
4497 } 4549 }
4498 if (mddev->pers->sync_request) { 4550 if (mddev->pers->sync_request) {
4499 if (sysfs_create_group(&mddev->kobj, &md_redundancy_group)) 4551 if (mddev->kobj.sd &&
4552 sysfs_create_group(&mddev->kobj, &md_redundancy_group))
4500 printk(KERN_WARNING 4553 printk(KERN_WARNING
4501 "md: cannot register extra attributes for %s\n", 4554 "md: cannot register extra attributes for %s\n",
4502 mdname(mddev)); 4555 mdname(mddev));
4503 mddev->sysfs_action = sysfs_get_dirent(mddev->kobj.sd, NULL, "sync_action"); 4556 mddev->sysfs_action = sysfs_get_dirent_safe(mddev->kobj.sd, "sync_action");
4504 } else if (mddev->ro == 2) /* auto-readonly not meaningful */ 4557 } else if (mddev->ro == 2) /* auto-readonly not meaningful */
4505 mddev->ro = 0; 4558 mddev->ro = 0;
4506 4559
@@ -4518,8 +4571,7 @@ static int md_run(mddev_t *mddev)
4518 char nm[20]; 4571 char nm[20];
4519 sprintf(nm, "rd%d", rdev->raid_disk); 4572 sprintf(nm, "rd%d", rdev->raid_disk);
4520 if (sysfs_create_link(&mddev->kobj, &rdev->kobj, nm)) 4573 if (sysfs_create_link(&mddev->kobj, &rdev->kobj, nm))
4521 printk("md: cannot register %s for %s\n", 4574 /* failure here is OK */;
4522 nm, mdname(mddev));
4523 } 4575 }
4524 4576
4525 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); 4577 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
@@ -4531,12 +4583,12 @@ static int md_run(mddev_t *mddev)
4531 md_wakeup_thread(mddev->sync_thread); /* possibly kick off a reshape */ 4583 md_wakeup_thread(mddev->sync_thread); /* possibly kick off a reshape */
4532 4584
4533 md_new_event(mddev); 4585 md_new_event(mddev);
4534 sysfs_notify_dirent(mddev->sysfs_state); 4586 sysfs_notify_dirent_safe(mddev->sysfs_state);
4535 if (mddev->sysfs_action) 4587 sysfs_notify_dirent_safe(mddev->sysfs_action);
4536 sysfs_notify_dirent(mddev->sysfs_action);
4537 sysfs_notify(&mddev->kobj, NULL, "degraded"); 4588 sysfs_notify(&mddev->kobj, NULL, "degraded");
4538 return 0; 4589 return 0;
4539} 4590}
4591EXPORT_SYMBOL_GPL(md_run);
4540 4592
4541static int do_md_run(mddev_t *mddev) 4593static int do_md_run(mddev_t *mddev)
4542{ 4594{
@@ -4545,7 +4597,11 @@ static int do_md_run(mddev_t *mddev)
4545 err = md_run(mddev); 4597 err = md_run(mddev);
4546 if (err) 4598 if (err)
4547 goto out; 4599 goto out;
4548 4600 err = bitmap_load(mddev);
4601 if (err) {
4602 bitmap_destroy(mddev);
4603 goto out;
4604 }
4549 set_capacity(mddev->gendisk, mddev->array_sectors); 4605 set_capacity(mddev->gendisk, mddev->array_sectors);
4550 revalidate_disk(mddev->gendisk); 4606 revalidate_disk(mddev->gendisk);
4551 kobject_uevent(&disk_to_dev(mddev->gendisk)->kobj, KOBJ_CHANGE); 4607 kobject_uevent(&disk_to_dev(mddev->gendisk)->kobj, KOBJ_CHANGE);
@@ -4573,7 +4629,7 @@ static int restart_array(mddev_t *mddev)
4573 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); 4629 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
4574 md_wakeup_thread(mddev->thread); 4630 md_wakeup_thread(mddev->thread);
4575 md_wakeup_thread(mddev->sync_thread); 4631 md_wakeup_thread(mddev->sync_thread);
4576 sysfs_notify_dirent(mddev->sysfs_state); 4632 sysfs_notify_dirent_safe(mddev->sysfs_state);
4577 return 0; 4633 return 0;
4578} 4634}
4579 4635
@@ -4644,9 +4700,10 @@ static void md_clean(mddev_t *mddev)
4644 mddev->bitmap_info.chunksize = 0; 4700 mddev->bitmap_info.chunksize = 0;
4645 mddev->bitmap_info.daemon_sleep = 0; 4701 mddev->bitmap_info.daemon_sleep = 0;
4646 mddev->bitmap_info.max_write_behind = 0; 4702 mddev->bitmap_info.max_write_behind = 0;
4703 mddev->plug = NULL;
4647} 4704}
4648 4705
4649static void md_stop_writes(mddev_t *mddev) 4706void md_stop_writes(mddev_t *mddev)
4650{ 4707{
4651 if (mddev->sync_thread) { 4708 if (mddev->sync_thread) {
4652 set_bit(MD_RECOVERY_FROZEN, &mddev->recovery); 4709 set_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
@@ -4666,11 +4723,10 @@ static void md_stop_writes(mddev_t *mddev)
4666 md_update_sb(mddev, 1); 4723 md_update_sb(mddev, 1);
4667 } 4724 }
4668} 4725}
4726EXPORT_SYMBOL_GPL(md_stop_writes);
4669 4727
4670static void md_stop(mddev_t *mddev) 4728void md_stop(mddev_t *mddev)
4671{ 4729{
4672 md_stop_writes(mddev);
4673
4674 mddev->pers->stop(mddev); 4730 mddev->pers->stop(mddev);
4675 if (mddev->pers->sync_request && mddev->to_remove == NULL) 4731 if (mddev->pers->sync_request && mddev->to_remove == NULL)
4676 mddev->to_remove = &md_redundancy_group; 4732 mddev->to_remove = &md_redundancy_group;
@@ -4678,6 +4734,7 @@ static void md_stop(mddev_t *mddev)
4678 mddev->pers = NULL; 4734 mddev->pers = NULL;
4679 clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); 4735 clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
4680} 4736}
4737EXPORT_SYMBOL_GPL(md_stop);
4681 4738
4682static int md_set_readonly(mddev_t *mddev, int is_open) 4739static int md_set_readonly(mddev_t *mddev, int is_open)
4683{ 4740{
@@ -4697,7 +4754,7 @@ static int md_set_readonly(mddev_t *mddev, int is_open)
4697 mddev->ro = 1; 4754 mddev->ro = 1;
4698 set_disk_ro(mddev->gendisk, 1); 4755 set_disk_ro(mddev->gendisk, 1);
4699 clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); 4756 clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
4700 sysfs_notify_dirent(mddev->sysfs_state); 4757 sysfs_notify_dirent_safe(mddev->sysfs_state);
4701 err = 0; 4758 err = 0;
4702 } 4759 }
4703out: 4760out:
@@ -4711,26 +4768,29 @@ out:
4711 */ 4768 */
4712static int do_md_stop(mddev_t * mddev, int mode, int is_open) 4769static int do_md_stop(mddev_t * mddev, int mode, int is_open)
4713{ 4770{
4714 int err = 0;
4715 struct gendisk *disk = mddev->gendisk; 4771 struct gendisk *disk = mddev->gendisk;
4716 mdk_rdev_t *rdev; 4772 mdk_rdev_t *rdev;
4717 4773
4718 mutex_lock(&mddev->open_mutex); 4774 mutex_lock(&mddev->open_mutex);
4719 if (atomic_read(&mddev->openers) > is_open) { 4775 if (atomic_read(&mddev->openers) > is_open ||
4776 mddev->sysfs_active) {
4720 printk("md: %s still in use.\n",mdname(mddev)); 4777 printk("md: %s still in use.\n",mdname(mddev));
4721 err = -EBUSY; 4778 mutex_unlock(&mddev->open_mutex);
4722 } else if (mddev->pers) { 4779 return -EBUSY;
4780 }
4723 4781
4782 if (mddev->pers) {
4724 if (mddev->ro) 4783 if (mddev->ro)
4725 set_disk_ro(disk, 0); 4784 set_disk_ro(disk, 0);
4726 4785
4786 md_stop_writes(mddev);
4727 md_stop(mddev); 4787 md_stop(mddev);
4728 mddev->queue->merge_bvec_fn = NULL; 4788 mddev->queue->merge_bvec_fn = NULL;
4729 mddev->queue->unplug_fn = NULL; 4789 mddev->queue->unplug_fn = NULL;
4730 mddev->queue->backing_dev_info.congested_fn = NULL; 4790 mddev->queue->backing_dev_info.congested_fn = NULL;
4731 4791
4732 /* tell userspace to handle 'inactive' */ 4792 /* tell userspace to handle 'inactive' */
4733 sysfs_notify_dirent(mddev->sysfs_state); 4793 sysfs_notify_dirent_safe(mddev->sysfs_state);
4734 4794
4735 list_for_each_entry(rdev, &mddev->disks, same_set) 4795 list_for_each_entry(rdev, &mddev->disks, same_set)
4736 if (rdev->raid_disk >= 0) { 4796 if (rdev->raid_disk >= 0) {
@@ -4740,21 +4800,17 @@ static int do_md_stop(mddev_t * mddev, int mode, int is_open)
4740 } 4800 }
4741 4801
4742 set_capacity(disk, 0); 4802 set_capacity(disk, 0);
4803 mutex_unlock(&mddev->open_mutex);
4743 revalidate_disk(disk); 4804 revalidate_disk(disk);
4744 4805
4745 if (mddev->ro) 4806 if (mddev->ro)
4746 mddev->ro = 0; 4807 mddev->ro = 0;
4747 4808 } else
4748 err = 0; 4809 mutex_unlock(&mddev->open_mutex);
4749 }
4750 mutex_unlock(&mddev->open_mutex);
4751 if (err)
4752 return err;
4753 /* 4810 /*
4754 * Free resources if final stop 4811 * Free resources if final stop
4755 */ 4812 */
4756 if (mode == 0) { 4813 if (mode == 0) {
4757
4758 printk(KERN_INFO "md: %s stopped.\n", mdname(mddev)); 4814 printk(KERN_INFO "md: %s stopped.\n", mdname(mddev));
4759 4815
4760 bitmap_destroy(mddev); 4816 bitmap_destroy(mddev);
@@ -4771,13 +4827,11 @@ static int do_md_stop(mddev_t * mddev, int mode, int is_open)
4771 kobject_uevent(&disk_to_dev(mddev->gendisk)->kobj, KOBJ_CHANGE); 4827 kobject_uevent(&disk_to_dev(mddev->gendisk)->kobj, KOBJ_CHANGE);
4772 if (mddev->hold_active == UNTIL_STOP) 4828 if (mddev->hold_active == UNTIL_STOP)
4773 mddev->hold_active = 0; 4829 mddev->hold_active = 0;
4774
4775 } 4830 }
4776 err = 0;
4777 blk_integrity_unregister(disk); 4831 blk_integrity_unregister(disk);
4778 md_new_event(mddev); 4832 md_new_event(mddev);
4779 sysfs_notify_dirent(mddev->sysfs_state); 4833 sysfs_notify_dirent_safe(mddev->sysfs_state);
4780 return err; 4834 return 0;
4781} 4835}
4782 4836
4783#ifndef MODULE 4837#ifndef MODULE
@@ -5138,7 +5192,7 @@ static int add_new_disk(mddev_t * mddev, mdu_disk_info_t *info)
5138 if (err) 5192 if (err)
5139 export_rdev(rdev); 5193 export_rdev(rdev);
5140 else 5194 else
5141 sysfs_notify_dirent(rdev->sysfs_state); 5195 sysfs_notify_dirent_safe(rdev->sysfs_state);
5142 5196
5143 md_update_sb(mddev, 1); 5197 md_update_sb(mddev, 1);
5144 if (mddev->degraded) 5198 if (mddev->degraded)
@@ -5331,8 +5385,11 @@ static int set_bitmap_file(mddev_t *mddev, int fd)
5331 err = 0; 5385 err = 0;
5332 if (mddev->pers) { 5386 if (mddev->pers) {
5333 mddev->pers->quiesce(mddev, 1); 5387 mddev->pers->quiesce(mddev, 1);
5334 if (fd >= 0) 5388 if (fd >= 0) {
5335 err = bitmap_create(mddev); 5389 err = bitmap_create(mddev);
5390 if (!err)
5391 err = bitmap_load(mddev);
5392 }
5336 if (fd < 0 || err) { 5393 if (fd < 0 || err) {
5337 bitmap_destroy(mddev); 5394 bitmap_destroy(mddev);
5338 fd = -1; /* make sure to put the file */ 5395 fd = -1; /* make sure to put the file */
@@ -5581,6 +5638,8 @@ static int update_array_info(mddev_t *mddev, mdu_array_info_t *info)
5581 mddev->bitmap_info.default_offset; 5638 mddev->bitmap_info.default_offset;
5582 mddev->pers->quiesce(mddev, 1); 5639 mddev->pers->quiesce(mddev, 1);
5583 rv = bitmap_create(mddev); 5640 rv = bitmap_create(mddev);
5641 if (!rv)
5642 rv = bitmap_load(mddev);
5584 if (rv) 5643 if (rv)
5585 bitmap_destroy(mddev); 5644 bitmap_destroy(mddev);
5586 mddev->pers->quiesce(mddev, 0); 5645 mddev->pers->quiesce(mddev, 0);
@@ -5813,7 +5872,7 @@ static int md_ioctl(struct block_device *bdev, fmode_t mode,
5813 if (_IOC_TYPE(cmd) == MD_MAJOR && mddev->ro && mddev->pers) { 5872 if (_IOC_TYPE(cmd) == MD_MAJOR && mddev->ro && mddev->pers) {
5814 if (mddev->ro == 2) { 5873 if (mddev->ro == 2) {
5815 mddev->ro = 0; 5874 mddev->ro = 0;
5816 sysfs_notify_dirent(mddev->sysfs_state); 5875 sysfs_notify_dirent_safe(mddev->sysfs_state);
5817 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); 5876 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
5818 md_wakeup_thread(mddev->thread); 5877 md_wakeup_thread(mddev->thread);
5819 } else { 5878 } else {
@@ -5902,6 +5961,7 @@ static int md_open(struct block_device *bdev, fmode_t mode)
5902 mddev_t *mddev = mddev_find(bdev->bd_dev); 5961 mddev_t *mddev = mddev_find(bdev->bd_dev);
5903 int err; 5962 int err;
5904 5963
5964 lock_kernel();
5905 if (mddev->gendisk != bdev->bd_disk) { 5965 if (mddev->gendisk != bdev->bd_disk) {
5906 /* we are racing with mddev_put which is discarding this 5966 /* we are racing with mddev_put which is discarding this
5907 * bd_disk. 5967 * bd_disk.
@@ -5910,6 +5970,7 @@ static int md_open(struct block_device *bdev, fmode_t mode)
5910 /* Wait until bdev->bd_disk is definitely gone */ 5970 /* Wait until bdev->bd_disk is definitely gone */
5911 flush_scheduled_work(); 5971 flush_scheduled_work();
5912 /* Then retry the open from the top */ 5972 /* Then retry the open from the top */
5973 unlock_kernel();
5913 return -ERESTARTSYS; 5974 return -ERESTARTSYS;
5914 } 5975 }
5915 BUG_ON(mddev != bdev->bd_disk->private_data); 5976 BUG_ON(mddev != bdev->bd_disk->private_data);
@@ -5923,6 +5984,7 @@ static int md_open(struct block_device *bdev, fmode_t mode)
5923 5984
5924 check_disk_size_change(mddev->gendisk, bdev); 5985 check_disk_size_change(mddev->gendisk, bdev);
5925 out: 5986 out:
5987 unlock_kernel();
5926 return err; 5988 return err;
5927} 5989}
5928 5990
@@ -5931,8 +5993,10 @@ static int md_release(struct gendisk *disk, fmode_t mode)
5931 mddev_t *mddev = disk->private_data; 5993 mddev_t *mddev = disk->private_data;
5932 5994
5933 BUG_ON(!mddev); 5995 BUG_ON(!mddev);
5996 lock_kernel();
5934 atomic_dec(&mddev->openers); 5997 atomic_dec(&mddev->openers);
5935 mddev_put(mddev); 5998 mddev_put(mddev);
5999 unlock_kernel();
5936 6000
5937 return 0; 6001 return 0;
5938} 6002}
@@ -6059,10 +6123,12 @@ void md_error(mddev_t *mddev, mdk_rdev_t *rdev)
6059 mddev->pers->error_handler(mddev,rdev); 6123 mddev->pers->error_handler(mddev,rdev);
6060 if (mddev->degraded) 6124 if (mddev->degraded)
6061 set_bit(MD_RECOVERY_RECOVER, &mddev->recovery); 6125 set_bit(MD_RECOVERY_RECOVER, &mddev->recovery);
6062 sysfs_notify_dirent(rdev->sysfs_state); 6126 sysfs_notify_dirent_safe(rdev->sysfs_state);
6063 set_bit(MD_RECOVERY_INTR, &mddev->recovery); 6127 set_bit(MD_RECOVERY_INTR, &mddev->recovery);
6064 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); 6128 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
6065 md_wakeup_thread(mddev->thread); 6129 md_wakeup_thread(mddev->thread);
6130 if (mddev->event_work.func)
6131 schedule_work(&mddev->event_work);
6066 md_new_event_inintr(mddev); 6132 md_new_event_inintr(mddev);
6067} 6133}
6068 6134
@@ -6520,7 +6586,7 @@ void md_write_start(mddev_t *mddev, struct bio *bi)
6520 spin_unlock_irq(&mddev->write_lock); 6586 spin_unlock_irq(&mddev->write_lock);
6521 } 6587 }
6522 if (did_change) 6588 if (did_change)
6523 sysfs_notify_dirent(mddev->sysfs_state); 6589 sysfs_notify_dirent_safe(mddev->sysfs_state);
6524 wait_event(mddev->sb_wait, 6590 wait_event(mddev->sb_wait,
6525 !test_bit(MD_CHANGE_CLEAN, &mddev->flags) && 6591 !test_bit(MD_CHANGE_CLEAN, &mddev->flags) &&
6526 !test_bit(MD_CHANGE_PENDING, &mddev->flags)); 6592 !test_bit(MD_CHANGE_PENDING, &mddev->flags));
@@ -6563,7 +6629,7 @@ int md_allow_write(mddev_t *mddev)
6563 mddev->safemode = 1; 6629 mddev->safemode = 1;
6564 spin_unlock_irq(&mddev->write_lock); 6630 spin_unlock_irq(&mddev->write_lock);
6565 md_update_sb(mddev, 0); 6631 md_update_sb(mddev, 0);
6566 sysfs_notify_dirent(mddev->sysfs_state); 6632 sysfs_notify_dirent_safe(mddev->sysfs_state);
6567 } else 6633 } else
6568 spin_unlock_irq(&mddev->write_lock); 6634 spin_unlock_irq(&mddev->write_lock);
6569 6635
@@ -6574,6 +6640,14 @@ int md_allow_write(mddev_t *mddev)
6574} 6640}
6575EXPORT_SYMBOL_GPL(md_allow_write); 6641EXPORT_SYMBOL_GPL(md_allow_write);
6576 6642
6643void md_unplug(mddev_t *mddev)
6644{
6645 if (mddev->queue)
6646 blk_unplug(mddev->queue);
6647 if (mddev->plug)
6648 mddev->plug->unplug_fn(mddev->plug);
6649}
6650
6577#define SYNC_MARKS 10 6651#define SYNC_MARKS 10
6578#define SYNC_MARK_STEP (3*HZ) 6652#define SYNC_MARK_STEP (3*HZ)
6579void md_do_sync(mddev_t *mddev) 6653void md_do_sync(mddev_t *mddev)
@@ -6752,12 +6826,13 @@ void md_do_sync(mddev_t *mddev)
6752 >= mddev->resync_max - mddev->curr_resync_completed 6826 >= mddev->resync_max - mddev->curr_resync_completed
6753 )) { 6827 )) {
6754 /* time to update curr_resync_completed */ 6828 /* time to update curr_resync_completed */
6755 blk_unplug(mddev->queue); 6829 md_unplug(mddev);
6756 wait_event(mddev->recovery_wait, 6830 wait_event(mddev->recovery_wait,
6757 atomic_read(&mddev->recovery_active) == 0); 6831 atomic_read(&mddev->recovery_active) == 0);
6758 mddev->curr_resync_completed = 6832 mddev->curr_resync_completed =
6759 mddev->curr_resync; 6833 mddev->curr_resync;
6760 set_bit(MD_CHANGE_CLEAN, &mddev->flags); 6834 if (mddev->persistent)
6835 set_bit(MD_CHANGE_CLEAN, &mddev->flags);
6761 sysfs_notify(&mddev->kobj, NULL, "sync_completed"); 6836 sysfs_notify(&mddev->kobj, NULL, "sync_completed");
6762 } 6837 }
6763 6838
@@ -6829,7 +6904,7 @@ void md_do_sync(mddev_t *mddev)
6829 * about not overloading the IO subsystem. (things like an 6904 * about not overloading the IO subsystem. (things like an
6830 * e2fsck being done on the RAID array should execute fast) 6905 * e2fsck being done on the RAID array should execute fast)
6831 */ 6906 */
6832 blk_unplug(mddev->queue); 6907 md_unplug(mddev);
6833 cond_resched(); 6908 cond_resched();
6834 6909
6835 currspeed = ((unsigned long)(io_sectors-mddev->resync_mark_cnt))/2 6910 currspeed = ((unsigned long)(io_sectors-mddev->resync_mark_cnt))/2
@@ -6848,7 +6923,7 @@ void md_do_sync(mddev_t *mddev)
6848 * this also signals 'finished resyncing' to md_stop 6923 * this also signals 'finished resyncing' to md_stop
6849 */ 6924 */
6850 out: 6925 out:
6851 blk_unplug(mddev->queue); 6926 md_unplug(mddev);
6852 6927
6853 wait_event(mddev->recovery_wait, !atomic_read(&mddev->recovery_active)); 6928 wait_event(mddev->recovery_wait, !atomic_read(&mddev->recovery_active));
6854 6929
@@ -6950,10 +7025,7 @@ static int remove_and_add_spares(mddev_t *mddev)
6950 sprintf(nm, "rd%d", rdev->raid_disk); 7025 sprintf(nm, "rd%d", rdev->raid_disk);
6951 if (sysfs_create_link(&mddev->kobj, 7026 if (sysfs_create_link(&mddev->kobj,
6952 &rdev->kobj, nm)) 7027 &rdev->kobj, nm))
6953 printk(KERN_WARNING 7028 /* failure here is OK */;
6954 "md: cannot register "
6955 "%s for %s\n",
6956 nm, mdname(mddev));
6957 spares++; 7029 spares++;
6958 md_new_event(mddev); 7030 md_new_event(mddev);
6959 set_bit(MD_CHANGE_DEVS, &mddev->flags); 7031 set_bit(MD_CHANGE_DEVS, &mddev->flags);
@@ -7046,7 +7118,7 @@ void md_check_recovery(mddev_t *mddev)
7046 mddev->safemode = 0; 7118 mddev->safemode = 0;
7047 spin_unlock_irq(&mddev->write_lock); 7119 spin_unlock_irq(&mddev->write_lock);
7048 if (did_change) 7120 if (did_change)
7049 sysfs_notify_dirent(mddev->sysfs_state); 7121 sysfs_notify_dirent_safe(mddev->sysfs_state);
7050 } 7122 }
7051 7123
7052 if (mddev->flags) 7124 if (mddev->flags)
@@ -7085,7 +7157,7 @@ void md_check_recovery(mddev_t *mddev)
7085 mddev->recovery = 0; 7157 mddev->recovery = 0;
7086 /* flag recovery needed just to double check */ 7158 /* flag recovery needed just to double check */
7087 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); 7159 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
7088 sysfs_notify_dirent(mddev->sysfs_action); 7160 sysfs_notify_dirent_safe(mddev->sysfs_action);
7089 md_new_event(mddev); 7161 md_new_event(mddev);
7090 goto unlock; 7162 goto unlock;
7091 } 7163 }
@@ -7147,7 +7219,7 @@ void md_check_recovery(mddev_t *mddev)
7147 mddev->recovery = 0; 7219 mddev->recovery = 0;
7148 } else 7220 } else
7149 md_wakeup_thread(mddev->sync_thread); 7221 md_wakeup_thread(mddev->sync_thread);
7150 sysfs_notify_dirent(mddev->sysfs_action); 7222 sysfs_notify_dirent_safe(mddev->sysfs_action);
7151 md_new_event(mddev); 7223 md_new_event(mddev);
7152 } 7224 }
7153 unlock: 7225 unlock:
@@ -7156,7 +7228,7 @@ void md_check_recovery(mddev_t *mddev)
7156 if (test_and_clear_bit(MD_RECOVERY_RECOVER, 7228 if (test_and_clear_bit(MD_RECOVERY_RECOVER,
7157 &mddev->recovery)) 7229 &mddev->recovery))
7158 if (mddev->sysfs_action) 7230 if (mddev->sysfs_action)
7159 sysfs_notify_dirent(mddev->sysfs_action); 7231 sysfs_notify_dirent_safe(mddev->sysfs_action);
7160 } 7232 }
7161 mddev_unlock(mddev); 7233 mddev_unlock(mddev);
7162 } 7234 }
@@ -7164,7 +7236,7 @@ void md_check_recovery(mddev_t *mddev)
7164 7236
7165void md_wait_for_blocked_rdev(mdk_rdev_t *rdev, mddev_t *mddev) 7237void md_wait_for_blocked_rdev(mdk_rdev_t *rdev, mddev_t *mddev)
7166{ 7238{
7167 sysfs_notify_dirent(rdev->sysfs_state); 7239 sysfs_notify_dirent_safe(rdev->sysfs_state);
7168 wait_event_timeout(rdev->blocked_wait, 7240 wait_event_timeout(rdev->blocked_wait,
7169 !test_bit(Blocked, &rdev->flags), 7241 !test_bit(Blocked, &rdev->flags),
7170 msecs_to_jiffies(5000)); 7242 msecs_to_jiffies(5000));
diff --git a/drivers/md/md.h b/drivers/md/md.h
index 10597bfec000..a953fe2808ae 100644
--- a/drivers/md/md.h
+++ b/drivers/md/md.h
@@ -29,6 +29,26 @@
29typedef struct mddev_s mddev_t; 29typedef struct mddev_s mddev_t;
30typedef struct mdk_rdev_s mdk_rdev_t; 30typedef struct mdk_rdev_s mdk_rdev_t;
31 31
32/* generic plugging support - like that provided with request_queue,
33 * but does not require a request_queue
34 */
35struct plug_handle {
36 void (*unplug_fn)(struct plug_handle *);
37 struct timer_list unplug_timer;
38 struct work_struct unplug_work;
39 unsigned long unplug_flag;
40};
41#define PLUGGED_FLAG 1
42void plugger_init(struct plug_handle *plug,
43 void (*unplug_fn)(struct plug_handle *));
44void plugger_set_plug(struct plug_handle *plug);
45int plugger_remove_plug(struct plug_handle *plug);
46static inline void plugger_flush(struct plug_handle *plug)
47{
48 del_timer_sync(&plug->unplug_timer);
49 cancel_work_sync(&plug->unplug_work);
50}
51
32/* 52/*
33 * MD's 'extended' device 53 * MD's 'extended' device
34 */ 54 */
@@ -67,7 +87,7 @@ struct mdk_rdev_s
67#define Faulty 1 /* device is known to have a fault */ 87#define Faulty 1 /* device is known to have a fault */
68#define In_sync 2 /* device is in_sync with rest of array */ 88#define In_sync 2 /* device is in_sync with rest of array */
69#define WriteMostly 4 /* Avoid reading if at all possible */ 89#define WriteMostly 4 /* Avoid reading if at all possible */
70#define BarriersNotsupp 5 /* BIO_RW_BARRIER is not supported */ 90#define BarriersNotsupp 5 /* REQ_HARDBARRIER is not supported */
71#define AllReserved 6 /* If whole device is reserved for 91#define AllReserved 6 /* If whole device is reserved for
72 * one array */ 92 * one array */
73#define AutoDetected 7 /* added by auto-detect */ 93#define AutoDetected 7 /* added by auto-detect */
@@ -125,6 +145,10 @@ struct mddev_s
125 int suspended; 145 int suspended;
126 atomic_t active_io; 146 atomic_t active_io;
127 int ro; 147 int ro;
148 int sysfs_active; /* set when sysfs deletes
149 * are happening, so run/
150 * takeover/stop are not safe
151 */
128 152
129 struct gendisk *gendisk; 153 struct gendisk *gendisk;
130 154
@@ -254,7 +278,7 @@ struct mddev_s
254 * fails. Only supported 278 * fails. Only supported
255 */ 279 */
256 struct bio *biolist; /* bios that need to be retried 280 struct bio *biolist; /* bios that need to be retried
257 * because BIO_RW_BARRIER is not supported 281 * because REQ_HARDBARRIER is not supported
258 */ 282 */
259 283
260 atomic_t recovery_active; /* blocks scheduled, but not written */ 284 atomic_t recovery_active; /* blocks scheduled, but not written */
@@ -297,9 +321,14 @@ struct mddev_s
297 * hot-adding a bitmap. It should 321 * hot-adding a bitmap. It should
298 * eventually be settable by sysfs. 322 * eventually be settable by sysfs.
299 */ 323 */
324 /* When md is serving under dm, it might use a
325 * dirty_log to store the bits.
326 */
327 struct dm_dirty_log *log;
328
300 struct mutex mutex; 329 struct mutex mutex;
301 unsigned long chunksize; 330 unsigned long chunksize;
302 unsigned long daemon_sleep; /* how many seconds between updates? */ 331 unsigned long daemon_sleep; /* how many jiffies between updates? */
303 unsigned long max_write_behind; /* write-behind mode */ 332 unsigned long max_write_behind; /* write-behind mode */
304 int external; 333 int external;
305 } bitmap_info; 334 } bitmap_info;
@@ -308,6 +337,8 @@ struct mddev_s
308 struct list_head all_mddevs; 337 struct list_head all_mddevs;
309 338
310 struct attribute_group *to_remove; 339 struct attribute_group *to_remove;
340 struct plug_handle *plug; /* if used by personality */
341
311 /* Generic barrier handling. 342 /* Generic barrier handling.
312 * If there is a pending barrier request, all other 343 * If there is a pending barrier request, all other
313 * writes are blocked while the devices are flushed. 344 * writes are blocked while the devices are flushed.
@@ -318,6 +349,7 @@ struct mddev_s
318 struct bio *barrier; 349 struct bio *barrier;
319 atomic_t flush_pending; 350 atomic_t flush_pending;
320 struct work_struct barrier_work; 351 struct work_struct barrier_work;
352 struct work_struct event_work; /* used by dm to report failure event */
321}; 353};
322 354
323 355
@@ -382,6 +414,18 @@ struct md_sysfs_entry {
382}; 414};
383extern struct attribute_group md_bitmap_group; 415extern struct attribute_group md_bitmap_group;
384 416
417static inline struct sysfs_dirent *sysfs_get_dirent_safe(struct sysfs_dirent *sd, char *name)
418{
419 if (sd)
420 return sysfs_get_dirent(sd, NULL, name);
421 return sd;
422}
423static inline void sysfs_notify_dirent_safe(struct sysfs_dirent *sd)
424{
425 if (sd)
426 sysfs_notify_dirent(sd);
427}
428
385static inline char * mdname (mddev_t * mddev) 429static inline char * mdname (mddev_t * mddev)
386{ 430{
387 return mddev->gendisk ? mddev->gendisk->disk_name : "mdX"; 431 return mddev->gendisk ? mddev->gendisk->disk_name : "mdX";
@@ -474,5 +518,14 @@ extern int md_integrity_register(mddev_t *mddev);
474extern void md_integrity_add_rdev(mdk_rdev_t *rdev, mddev_t *mddev); 518extern void md_integrity_add_rdev(mdk_rdev_t *rdev, mddev_t *mddev);
475extern int strict_strtoul_scaled(const char *cp, unsigned long *res, int scale); 519extern int strict_strtoul_scaled(const char *cp, unsigned long *res, int scale);
476extern void restore_bitmap_write_access(struct file *file); 520extern void restore_bitmap_write_access(struct file *file);
521extern void md_unplug(mddev_t *mddev);
522
523extern void mddev_init(mddev_t *mddev);
524extern int md_run(mddev_t *mddev);
525extern void md_stop(mddev_t *mddev);
526extern void md_stop_writes(mddev_t *mddev);
527extern void md_rdev_init(mdk_rdev_t *rdev);
477 528
529extern void mddev_suspend(mddev_t *mddev);
530extern void mddev_resume(mddev_t *mddev);
478#endif /* _MD_MD_H */ 531#endif /* _MD_MD_H */
diff --git a/drivers/md/mktables.c b/drivers/md/mktables.c
deleted file mode 100644
index 3b1500843bba..000000000000
--- a/drivers/md/mktables.c
+++ /dev/null
@@ -1,132 +0,0 @@
1/* -*- linux-c -*- ------------------------------------------------------- *
2 *
3 * Copyright 2002-2007 H. Peter Anvin - All Rights Reserved
4 *
5 * This file is part of the Linux kernel, and is made available under
6 * the terms of the GNU General Public License version 2 or (at your
7 * option) any later version; incorporated herein by reference.
8 *
9 * ----------------------------------------------------------------------- */
10
11/*
12 * mktables.c
13 *
14 * Make RAID-6 tables. This is a host user space program to be run at
15 * compile time.
16 */
17
18#include <stdio.h>
19#include <string.h>
20#include <inttypes.h>
21#include <stdlib.h>
22#include <time.h>
23
24static uint8_t gfmul(uint8_t a, uint8_t b)
25{
26 uint8_t v = 0;
27
28 while (b) {
29 if (b & 1)
30 v ^= a;
31 a = (a << 1) ^ (a & 0x80 ? 0x1d : 0);
32 b >>= 1;
33 }
34
35 return v;
36}
37
38static uint8_t gfpow(uint8_t a, int b)
39{
40 uint8_t v = 1;
41
42 b %= 255;
43 if (b < 0)
44 b += 255;
45
46 while (b) {
47 if (b & 1)
48 v = gfmul(v, a);
49 a = gfmul(a, a);
50 b >>= 1;
51 }
52
53 return v;
54}
55
56int main(int argc, char *argv[])
57{
58 int i, j, k;
59 uint8_t v;
60 uint8_t exptbl[256], invtbl[256];
61
62 printf("#include <linux/raid/pq.h>\n");
63
64 /* Compute multiplication table */
65 printf("\nconst u8 __attribute__((aligned(256)))\n"
66 "raid6_gfmul[256][256] =\n"
67 "{\n");
68 for (i = 0; i < 256; i++) {
69 printf("\t{\n");
70 for (j = 0; j < 256; j += 8) {
71 printf("\t\t");
72 for (k = 0; k < 8; k++)
73 printf("0x%02x,%c", gfmul(i, j + k),
74 (k == 7) ? '\n' : ' ');
75 }
76 printf("\t},\n");
77 }
78 printf("};\n");
79 printf("#ifdef __KERNEL__\n");
80 printf("EXPORT_SYMBOL(raid6_gfmul);\n");
81 printf("#endif\n");
82
83 /* Compute power-of-2 table (exponent) */
84 v = 1;
85 printf("\nconst u8 __attribute__((aligned(256)))\n"
86 "raid6_gfexp[256] =\n" "{\n");
87 for (i = 0; i < 256; i += 8) {
88 printf("\t");
89 for (j = 0; j < 8; j++) {
90 exptbl[i + j] = v;
91 printf("0x%02x,%c", v, (j == 7) ? '\n' : ' ');
92 v = gfmul(v, 2);
93 if (v == 1)
94 v = 0; /* For entry 255, not a real entry */
95 }
96 }
97 printf("};\n");
98 printf("#ifdef __KERNEL__\n");
99 printf("EXPORT_SYMBOL(raid6_gfexp);\n");
100 printf("#endif\n");
101
102 /* Compute inverse table x^-1 == x^254 */
103 printf("\nconst u8 __attribute__((aligned(256)))\n"
104 "raid6_gfinv[256] =\n" "{\n");
105 for (i = 0; i < 256; i += 8) {
106 printf("\t");
107 for (j = 0; j < 8; j++) {
108 invtbl[i + j] = v = gfpow(i + j, 254);
109 printf("0x%02x,%c", v, (j == 7) ? '\n' : ' ');
110 }
111 }
112 printf("};\n");
113 printf("#ifdef __KERNEL__\n");
114 printf("EXPORT_SYMBOL(raid6_gfinv);\n");
115 printf("#endif\n");
116
117 /* Compute inv(2^x + 1) (exponent-xor-inverse) table */
118 printf("\nconst u8 __attribute__((aligned(256)))\n"
119 "raid6_gfexi[256] =\n" "{\n");
120 for (i = 0; i < 256; i += 8) {
121 printf("\t");
122 for (j = 0; j < 8; j++)
123 printf("0x%02x,%c", invtbl[exptbl[i + j] ^ 1],
124 (j == 7) ? '\n' : ' ');
125 }
126 printf("};\n");
127 printf("#ifdef __KERNEL__\n");
128 printf("EXPORT_SYMBOL(raid6_gfexi);\n");
129 printf("#endif\n");
130
131 return 0;
132}
diff --git a/drivers/md/multipath.c b/drivers/md/multipath.c
index 410fb60699ac..0307d217e7a4 100644
--- a/drivers/md/multipath.c
+++ b/drivers/md/multipath.c
@@ -91,7 +91,7 @@ static void multipath_end_request(struct bio *bio, int error)
91 91
92 if (uptodate) 92 if (uptodate)
93 multipath_end_bh_io(mp_bh, 0); 93 multipath_end_bh_io(mp_bh, 0);
94 else if (!bio_rw_flagged(bio, BIO_RW_AHEAD)) { 94 else if (!(bio->bi_rw & REQ_RAHEAD)) {
95 /* 95 /*
96 * oops, IO error: 96 * oops, IO error:
97 */ 97 */
@@ -142,7 +142,7 @@ static int multipath_make_request(mddev_t *mddev, struct bio * bio)
142 struct multipath_bh * mp_bh; 142 struct multipath_bh * mp_bh;
143 struct multipath_info *multipath; 143 struct multipath_info *multipath;
144 144
145 if (unlikely(bio_rw_flagged(bio, BIO_RW_BARRIER))) { 145 if (unlikely(bio->bi_rw & REQ_HARDBARRIER)) {
146 md_barrier_request(mddev, bio); 146 md_barrier_request(mddev, bio);
147 return 0; 147 return 0;
148 } 148 }
@@ -163,7 +163,7 @@ static int multipath_make_request(mddev_t *mddev, struct bio * bio)
163 mp_bh->bio = *bio; 163 mp_bh->bio = *bio;
164 mp_bh->bio.bi_sector += multipath->rdev->data_offset; 164 mp_bh->bio.bi_sector += multipath->rdev->data_offset;
165 mp_bh->bio.bi_bdev = multipath->rdev->bdev; 165 mp_bh->bio.bi_bdev = multipath->rdev->bdev;
166 mp_bh->bio.bi_rw |= (1 << BIO_RW_FAILFAST_TRANSPORT); 166 mp_bh->bio.bi_rw |= REQ_FAILFAST_TRANSPORT;
167 mp_bh->bio.bi_end_io = multipath_end_request; 167 mp_bh->bio.bi_end_io = multipath_end_request;
168 mp_bh->bio.bi_private = mp_bh; 168 mp_bh->bio.bi_private = mp_bh;
169 generic_make_request(&mp_bh->bio); 169 generic_make_request(&mp_bh->bio);
@@ -398,7 +398,7 @@ static void multipathd (mddev_t *mddev)
398 *bio = *(mp_bh->master_bio); 398 *bio = *(mp_bh->master_bio);
399 bio->bi_sector += conf->multipaths[mp_bh->path].rdev->data_offset; 399 bio->bi_sector += conf->multipaths[mp_bh->path].rdev->data_offset;
400 bio->bi_bdev = conf->multipaths[mp_bh->path].rdev->bdev; 400 bio->bi_bdev = conf->multipaths[mp_bh->path].rdev->bdev;
401 bio->bi_rw |= (1 << BIO_RW_FAILFAST_TRANSPORT); 401 bio->bi_rw |= REQ_FAILFAST_TRANSPORT;
402 bio->bi_end_io = multipath_end_request; 402 bio->bi_end_io = multipath_end_request;
403 bio->bi_private = mp_bh; 403 bio->bi_private = mp_bh;
404 generic_make_request(bio); 404 generic_make_request(bio);
diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
index 563abed5a2cb..6f7af46d623c 100644
--- a/drivers/md/raid0.c
+++ b/drivers/md/raid0.c
@@ -483,7 +483,7 @@ static int raid0_make_request(mddev_t *mddev, struct bio *bio)
483 struct strip_zone *zone; 483 struct strip_zone *zone;
484 mdk_rdev_t *tmp_dev; 484 mdk_rdev_t *tmp_dev;
485 485
486 if (unlikely(bio_rw_flagged(bio, BIO_RW_BARRIER))) { 486 if (unlikely(bio->bi_rw & REQ_HARDBARRIER)) {
487 md_barrier_request(mddev, bio); 487 md_barrier_request(mddev, bio);
488 return 0; 488 return 0;
489 } 489 }
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index a948da8012de..73cc74ffc26b 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -787,7 +787,7 @@ static int make_request(mddev_t *mddev, struct bio * bio)
787 struct bio_list bl; 787 struct bio_list bl;
788 struct page **behind_pages = NULL; 788 struct page **behind_pages = NULL;
789 const int rw = bio_data_dir(bio); 789 const int rw = bio_data_dir(bio);
790 const bool do_sync = bio_rw_flagged(bio, BIO_RW_SYNCIO); 790 const bool do_sync = (bio->bi_rw & REQ_SYNC);
791 bool do_barriers; 791 bool do_barriers;
792 mdk_rdev_t *blocked_rdev; 792 mdk_rdev_t *blocked_rdev;
793 793
@@ -822,7 +822,7 @@ static int make_request(mddev_t *mddev, struct bio * bio)
822 finish_wait(&conf->wait_barrier, &w); 822 finish_wait(&conf->wait_barrier, &w);
823 } 823 }
824 if (unlikely(!mddev->barriers_work && 824 if (unlikely(!mddev->barriers_work &&
825 bio_rw_flagged(bio, BIO_RW_BARRIER))) { 825 (bio->bi_rw & REQ_HARDBARRIER))) {
826 if (rw == WRITE) 826 if (rw == WRITE)
827 md_write_end(mddev); 827 md_write_end(mddev);
828 bio_endio(bio, -EOPNOTSUPP); 828 bio_endio(bio, -EOPNOTSUPP);
@@ -877,7 +877,7 @@ static int make_request(mddev_t *mddev, struct bio * bio)
877 read_bio->bi_sector = r1_bio->sector + mirror->rdev->data_offset; 877 read_bio->bi_sector = r1_bio->sector + mirror->rdev->data_offset;
878 read_bio->bi_bdev = mirror->rdev->bdev; 878 read_bio->bi_bdev = mirror->rdev->bdev;
879 read_bio->bi_end_io = raid1_end_read_request; 879 read_bio->bi_end_io = raid1_end_read_request;
880 read_bio->bi_rw = READ | (do_sync << BIO_RW_SYNCIO); 880 read_bio->bi_rw = READ | do_sync;
881 read_bio->bi_private = r1_bio; 881 read_bio->bi_private = r1_bio;
882 882
883 generic_make_request(read_bio); 883 generic_make_request(read_bio);
@@ -959,7 +959,7 @@ static int make_request(mddev_t *mddev, struct bio * bio)
959 atomic_set(&r1_bio->remaining, 0); 959 atomic_set(&r1_bio->remaining, 0);
960 atomic_set(&r1_bio->behind_remaining, 0); 960 atomic_set(&r1_bio->behind_remaining, 0);
961 961
962 do_barriers = bio_rw_flagged(bio, BIO_RW_BARRIER); 962 do_barriers = bio->bi_rw & REQ_HARDBARRIER;
963 if (do_barriers) 963 if (do_barriers)
964 set_bit(R1BIO_Barrier, &r1_bio->state); 964 set_bit(R1BIO_Barrier, &r1_bio->state);
965 965
@@ -975,8 +975,7 @@ static int make_request(mddev_t *mddev, struct bio * bio)
975 mbio->bi_sector = r1_bio->sector + conf->mirrors[i].rdev->data_offset; 975 mbio->bi_sector = r1_bio->sector + conf->mirrors[i].rdev->data_offset;
976 mbio->bi_bdev = conf->mirrors[i].rdev->bdev; 976 mbio->bi_bdev = conf->mirrors[i].rdev->bdev;
977 mbio->bi_end_io = raid1_end_write_request; 977 mbio->bi_end_io = raid1_end_write_request;
978 mbio->bi_rw = WRITE | (do_barriers << BIO_RW_BARRIER) | 978 mbio->bi_rw = WRITE | do_barriers | do_sync;
979 (do_sync << BIO_RW_SYNCIO);
980 mbio->bi_private = r1_bio; 979 mbio->bi_private = r1_bio;
981 980
982 if (behind_pages) { 981 if (behind_pages) {
@@ -1633,7 +1632,7 @@ static void raid1d(mddev_t *mddev)
1633 sync_request_write(mddev, r1_bio); 1632 sync_request_write(mddev, r1_bio);
1634 unplug = 1; 1633 unplug = 1;
1635 } else if (test_bit(R1BIO_BarrierRetry, &r1_bio->state)) { 1634 } else if (test_bit(R1BIO_BarrierRetry, &r1_bio->state)) {
1636 /* some requests in the r1bio were BIO_RW_BARRIER 1635 /* some requests in the r1bio were REQ_HARDBARRIER
1637 * requests which failed with -EOPNOTSUPP. Hohumm.. 1636 * requests which failed with -EOPNOTSUPP. Hohumm..
1638 * Better resubmit without the barrier. 1637 * Better resubmit without the barrier.
1639 * We know which devices to resubmit for, because 1638 * We know which devices to resubmit for, because
@@ -1641,7 +1640,7 @@ static void raid1d(mddev_t *mddev)
1641 * We already have a nr_pending reference on these rdevs. 1640 * We already have a nr_pending reference on these rdevs.
1642 */ 1641 */
1643 int i; 1642 int i;
1644 const bool do_sync = bio_rw_flagged(r1_bio->master_bio, BIO_RW_SYNCIO); 1643 const bool do_sync = (r1_bio->master_bio->bi_rw & REQ_SYNC);
1645 clear_bit(R1BIO_BarrierRetry, &r1_bio->state); 1644 clear_bit(R1BIO_BarrierRetry, &r1_bio->state);
1646 clear_bit(R1BIO_Barrier, &r1_bio->state); 1645 clear_bit(R1BIO_Barrier, &r1_bio->state);
1647 for (i=0; i < conf->raid_disks; i++) 1646 for (i=0; i < conf->raid_disks; i++)
@@ -1662,8 +1661,7 @@ static void raid1d(mddev_t *mddev)
1662 conf->mirrors[i].rdev->data_offset; 1661 conf->mirrors[i].rdev->data_offset;
1663 bio->bi_bdev = conf->mirrors[i].rdev->bdev; 1662 bio->bi_bdev = conf->mirrors[i].rdev->bdev;
1664 bio->bi_end_io = raid1_end_write_request; 1663 bio->bi_end_io = raid1_end_write_request;
1665 bio->bi_rw = WRITE | 1664 bio->bi_rw = WRITE | do_sync;
1666 (do_sync << BIO_RW_SYNCIO);
1667 bio->bi_private = r1_bio; 1665 bio->bi_private = r1_bio;
1668 r1_bio->bios[i] = bio; 1666 r1_bio->bios[i] = bio;
1669 generic_make_request(bio); 1667 generic_make_request(bio);
@@ -1698,7 +1696,7 @@ static void raid1d(mddev_t *mddev)
1698 (unsigned long long)r1_bio->sector); 1696 (unsigned long long)r1_bio->sector);
1699 raid_end_bio_io(r1_bio); 1697 raid_end_bio_io(r1_bio);
1700 } else { 1698 } else {
1701 const bool do_sync = bio_rw_flagged(r1_bio->master_bio, BIO_RW_SYNCIO); 1699 const bool do_sync = r1_bio->master_bio->bi_rw & REQ_SYNC;
1702 r1_bio->bios[r1_bio->read_disk] = 1700 r1_bio->bios[r1_bio->read_disk] =
1703 mddev->ro ? IO_BLOCKED : NULL; 1701 mddev->ro ? IO_BLOCKED : NULL;
1704 r1_bio->read_disk = disk; 1702 r1_bio->read_disk = disk;
@@ -1715,7 +1713,7 @@ static void raid1d(mddev_t *mddev)
1715 bio->bi_sector = r1_bio->sector + rdev->data_offset; 1713 bio->bi_sector = r1_bio->sector + rdev->data_offset;
1716 bio->bi_bdev = rdev->bdev; 1714 bio->bi_bdev = rdev->bdev;
1717 bio->bi_end_io = raid1_end_read_request; 1715 bio->bi_end_io = raid1_end_read_request;
1718 bio->bi_rw = READ | (do_sync << BIO_RW_SYNCIO); 1716 bio->bi_rw = READ | do_sync;
1719 bio->bi_private = r1_bio; 1717 bio->bi_private = r1_bio;
1720 unplug = 1; 1718 unplug = 1;
1721 generic_make_request(bio); 1719 generic_make_request(bio);
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 42e64e4e5e25..a88aeb5198c7 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -799,12 +799,12 @@ static int make_request(mddev_t *mddev, struct bio * bio)
799 int i; 799 int i;
800 int chunk_sects = conf->chunk_mask + 1; 800 int chunk_sects = conf->chunk_mask + 1;
801 const int rw = bio_data_dir(bio); 801 const int rw = bio_data_dir(bio);
802 const bool do_sync = bio_rw_flagged(bio, BIO_RW_SYNCIO); 802 const bool do_sync = (bio->bi_rw & REQ_SYNC);
803 struct bio_list bl; 803 struct bio_list bl;
804 unsigned long flags; 804 unsigned long flags;
805 mdk_rdev_t *blocked_rdev; 805 mdk_rdev_t *blocked_rdev;
806 806
807 if (unlikely(bio_rw_flagged(bio, BIO_RW_BARRIER))) { 807 if (unlikely(bio->bi_rw & REQ_HARDBARRIER)) {
808 md_barrier_request(mddev, bio); 808 md_barrier_request(mddev, bio);
809 return 0; 809 return 0;
810 } 810 }
@@ -825,11 +825,29 @@ static int make_request(mddev_t *mddev, struct bio * bio)
825 */ 825 */
826 bp = bio_split(bio, 826 bp = bio_split(bio,
827 chunk_sects - (bio->bi_sector & (chunk_sects - 1)) ); 827 chunk_sects - (bio->bi_sector & (chunk_sects - 1)) );
828
829 /* Each of these 'make_request' calls will call 'wait_barrier'.
830 * If the first succeeds but the second blocks due to the resync
831 * thread raising the barrier, we will deadlock because the
832 * IO to the underlying device will be queued in generic_make_request
833 * and will never complete, so will never reduce nr_pending.
834 * So increment nr_waiting here so no new raise_barriers will
835 * succeed, and so the second wait_barrier cannot block.
836 */
837 spin_lock_irq(&conf->resync_lock);
838 conf->nr_waiting++;
839 spin_unlock_irq(&conf->resync_lock);
840
828 if (make_request(mddev, &bp->bio1)) 841 if (make_request(mddev, &bp->bio1))
829 generic_make_request(&bp->bio1); 842 generic_make_request(&bp->bio1);
830 if (make_request(mddev, &bp->bio2)) 843 if (make_request(mddev, &bp->bio2))
831 generic_make_request(&bp->bio2); 844 generic_make_request(&bp->bio2);
832 845
846 spin_lock_irq(&conf->resync_lock);
847 conf->nr_waiting--;
848 wake_up(&conf->wait_barrier);
849 spin_unlock_irq(&conf->resync_lock);
850
833 bio_pair_release(bp); 851 bio_pair_release(bp);
834 return 0; 852 return 0;
835 bad_map: 853 bad_map:
@@ -879,7 +897,7 @@ static int make_request(mddev_t *mddev, struct bio * bio)
879 mirror->rdev->data_offset; 897 mirror->rdev->data_offset;
880 read_bio->bi_bdev = mirror->rdev->bdev; 898 read_bio->bi_bdev = mirror->rdev->bdev;
881 read_bio->bi_end_io = raid10_end_read_request; 899 read_bio->bi_end_io = raid10_end_read_request;
882 read_bio->bi_rw = READ | (do_sync << BIO_RW_SYNCIO); 900 read_bio->bi_rw = READ | do_sync;
883 read_bio->bi_private = r10_bio; 901 read_bio->bi_private = r10_bio;
884 902
885 generic_make_request(read_bio); 903 generic_make_request(read_bio);
@@ -947,7 +965,7 @@ static int make_request(mddev_t *mddev, struct bio * bio)
947 conf->mirrors[d].rdev->data_offset; 965 conf->mirrors[d].rdev->data_offset;
948 mbio->bi_bdev = conf->mirrors[d].rdev->bdev; 966 mbio->bi_bdev = conf->mirrors[d].rdev->bdev;
949 mbio->bi_end_io = raid10_end_write_request; 967 mbio->bi_end_io = raid10_end_write_request;
950 mbio->bi_rw = WRITE | (do_sync << BIO_RW_SYNCIO); 968 mbio->bi_rw = WRITE | do_sync;
951 mbio->bi_private = r10_bio; 969 mbio->bi_private = r10_bio;
952 970
953 atomic_inc(&r10_bio->remaining); 971 atomic_inc(&r10_bio->remaining);
@@ -1716,7 +1734,7 @@ static void raid10d(mddev_t *mddev)
1716 raid_end_bio_io(r10_bio); 1734 raid_end_bio_io(r10_bio);
1717 bio_put(bio); 1735 bio_put(bio);
1718 } else { 1736 } else {
1719 const bool do_sync = bio_rw_flagged(r10_bio->master_bio, BIO_RW_SYNCIO); 1737 const bool do_sync = (r10_bio->master_bio->bi_rw & REQ_SYNC);
1720 bio_put(bio); 1738 bio_put(bio);
1721 rdev = conf->mirrors[mirror].rdev; 1739 rdev = conf->mirrors[mirror].rdev;
1722 if (printk_ratelimit()) 1740 if (printk_ratelimit())
@@ -1730,7 +1748,7 @@ static void raid10d(mddev_t *mddev)
1730 bio->bi_sector = r10_bio->devs[r10_bio->read_slot].addr 1748 bio->bi_sector = r10_bio->devs[r10_bio->read_slot].addr
1731 + rdev->data_offset; 1749 + rdev->data_offset;
1732 bio->bi_bdev = rdev->bdev; 1750 bio->bi_bdev = rdev->bdev;
1733 bio->bi_rw = READ | (do_sync << BIO_RW_SYNCIO); 1751 bio->bi_rw = READ | do_sync;
1734 bio->bi_private = r10_bio; 1752 bio->bi_private = r10_bio;
1735 bio->bi_end_io = raid10_end_read_request; 1753 bio->bi_end_io = raid10_end_read_request;
1736 unplug = 1; 1754 unplug = 1;
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 96c690279fc6..866d4b5a144c 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -201,11 +201,11 @@ static void __release_stripe(raid5_conf_t *conf, struct stripe_head *sh)
201 if (test_bit(STRIPE_HANDLE, &sh->state)) { 201 if (test_bit(STRIPE_HANDLE, &sh->state)) {
202 if (test_bit(STRIPE_DELAYED, &sh->state)) { 202 if (test_bit(STRIPE_DELAYED, &sh->state)) {
203 list_add_tail(&sh->lru, &conf->delayed_list); 203 list_add_tail(&sh->lru, &conf->delayed_list);
204 blk_plug_device(conf->mddev->queue); 204 plugger_set_plug(&conf->plug);
205 } else if (test_bit(STRIPE_BIT_DELAY, &sh->state) && 205 } else if (test_bit(STRIPE_BIT_DELAY, &sh->state) &&
206 sh->bm_seq - conf->seq_write > 0) { 206 sh->bm_seq - conf->seq_write > 0) {
207 list_add_tail(&sh->lru, &conf->bitmap_list); 207 list_add_tail(&sh->lru, &conf->bitmap_list);
208 blk_plug_device(conf->mddev->queue); 208 plugger_set_plug(&conf->plug);
209 } else { 209 } else {
210 clear_bit(STRIPE_BIT_DELAY, &sh->state); 210 clear_bit(STRIPE_BIT_DELAY, &sh->state);
211 list_add_tail(&sh->lru, &conf->handle_list); 211 list_add_tail(&sh->lru, &conf->handle_list);
@@ -434,7 +434,6 @@ static int has_failed(raid5_conf_t *conf)
434} 434}
435 435
436static void unplug_slaves(mddev_t *mddev); 436static void unplug_slaves(mddev_t *mddev);
437static void raid5_unplug_device(struct request_queue *q);
438 437
439static struct stripe_head * 438static struct stripe_head *
440get_active_stripe(raid5_conf_t *conf, sector_t sector, 439get_active_stripe(raid5_conf_t *conf, sector_t sector,
@@ -464,7 +463,7 @@ get_active_stripe(raid5_conf_t *conf, sector_t sector,
464 < (conf->max_nr_stripes *3/4) 463 < (conf->max_nr_stripes *3/4)
465 || !conf->inactive_blocked), 464 || !conf->inactive_blocked),
466 conf->device_lock, 465 conf->device_lock,
467 raid5_unplug_device(conf->mddev->queue) 466 md_raid5_unplug_device(conf)
468 ); 467 );
469 conf->inactive_blocked = 0; 468 conf->inactive_blocked = 0;
470 } else 469 } else
@@ -1337,10 +1336,14 @@ static int grow_stripes(raid5_conf_t *conf, int num)
1337 struct kmem_cache *sc; 1336 struct kmem_cache *sc;
1338 int devs = max(conf->raid_disks, conf->previous_raid_disks); 1337 int devs = max(conf->raid_disks, conf->previous_raid_disks);
1339 1338
1340 sprintf(conf->cache_name[0], 1339 if (conf->mddev->gendisk)
1341 "raid%d-%s", conf->level, mdname(conf->mddev)); 1340 sprintf(conf->cache_name[0],
1342 sprintf(conf->cache_name[1], 1341 "raid%d-%s", conf->level, mdname(conf->mddev));
1343 "raid%d-%s-alt", conf->level, mdname(conf->mddev)); 1342 else
1343 sprintf(conf->cache_name[0],
1344 "raid%d-%p", conf->level, conf->mddev);
1345 sprintf(conf->cache_name[1], "%s-alt", conf->cache_name[0]);
1346
1344 conf->active_name = 0; 1347 conf->active_name = 0;
1345 sc = kmem_cache_create(conf->cache_name[conf->active_name], 1348 sc = kmem_cache_create(conf->cache_name[conf->active_name],
1346 sizeof(struct stripe_head)+(devs-1)*sizeof(struct r5dev), 1349 sizeof(struct stripe_head)+(devs-1)*sizeof(struct r5dev),
@@ -3614,7 +3617,7 @@ static void raid5_activate_delayed(raid5_conf_t *conf)
3614 list_add_tail(&sh->lru, &conf->hold_list); 3617 list_add_tail(&sh->lru, &conf->hold_list);
3615 } 3618 }
3616 } else 3619 } else
3617 blk_plug_device(conf->mddev->queue); 3620 plugger_set_plug(&conf->plug);
3618} 3621}
3619 3622
3620static void activate_bit_delay(raid5_conf_t *conf) 3623static void activate_bit_delay(raid5_conf_t *conf)
@@ -3655,36 +3658,44 @@ static void unplug_slaves(mddev_t *mddev)
3655 rcu_read_unlock(); 3658 rcu_read_unlock();
3656} 3659}
3657 3660
3658static void raid5_unplug_device(struct request_queue *q) 3661void md_raid5_unplug_device(raid5_conf_t *conf)
3659{ 3662{
3660 mddev_t *mddev = q->queuedata;
3661 raid5_conf_t *conf = mddev->private;
3662 unsigned long flags; 3663 unsigned long flags;
3663 3664
3664 spin_lock_irqsave(&conf->device_lock, flags); 3665 spin_lock_irqsave(&conf->device_lock, flags);
3665 3666
3666 if (blk_remove_plug(q)) { 3667 if (plugger_remove_plug(&conf->plug)) {
3667 conf->seq_flush++; 3668 conf->seq_flush++;
3668 raid5_activate_delayed(conf); 3669 raid5_activate_delayed(conf);
3669 } 3670 }
3670 md_wakeup_thread(mddev->thread); 3671 md_wakeup_thread(conf->mddev->thread);
3671 3672
3672 spin_unlock_irqrestore(&conf->device_lock, flags); 3673 spin_unlock_irqrestore(&conf->device_lock, flags);
3673 3674
3674 unplug_slaves(mddev); 3675 unplug_slaves(conf->mddev);
3675} 3676}
3677EXPORT_SYMBOL_GPL(md_raid5_unplug_device);
3676 3678
3677static int raid5_congested(void *data, int bits) 3679static void raid5_unplug(struct plug_handle *plug)
3680{
3681 raid5_conf_t *conf = container_of(plug, raid5_conf_t, plug);
3682 md_raid5_unplug_device(conf);
3683}
3684
3685static void raid5_unplug_queue(struct request_queue *q)
3686{
3687 mddev_t *mddev = q->queuedata;
3688 md_raid5_unplug_device(mddev->private);
3689}
3690
3691int md_raid5_congested(mddev_t *mddev, int bits)
3678{ 3692{
3679 mddev_t *mddev = data;
3680 raid5_conf_t *conf = mddev->private; 3693 raid5_conf_t *conf = mddev->private;
3681 3694
3682 /* No difference between reads and writes. Just check 3695 /* No difference between reads and writes. Just check
3683 * how busy the stripe_cache is 3696 * how busy the stripe_cache is
3684 */ 3697 */
3685 3698
3686 if (mddev_congested(mddev, bits))
3687 return 1;
3688 if (conf->inactive_blocked) 3699 if (conf->inactive_blocked)
3689 return 1; 3700 return 1;
3690 if (conf->quiesce) 3701 if (conf->quiesce)
@@ -3694,6 +3705,15 @@ static int raid5_congested(void *data, int bits)
3694 3705
3695 return 0; 3706 return 0;
3696} 3707}
3708EXPORT_SYMBOL_GPL(md_raid5_congested);
3709
3710static int raid5_congested(void *data, int bits)
3711{
3712 mddev_t *mddev = data;
3713
3714 return mddev_congested(mddev, bits) ||
3715 md_raid5_congested(mddev, bits);
3716}
3697 3717
3698/* We want read requests to align with chunks where possible, 3718/* We want read requests to align with chunks where possible,
3699 * but write requests don't need to. 3719 * but write requests don't need to.
@@ -3958,7 +3978,7 @@ static int make_request(mddev_t *mddev, struct bio * bi)
3958 const int rw = bio_data_dir(bi); 3978 const int rw = bio_data_dir(bi);
3959 int remaining; 3979 int remaining;
3960 3980
3961 if (unlikely(bio_rw_flagged(bi, BIO_RW_BARRIER))) { 3981 if (unlikely(bi->bi_rw & REQ_HARDBARRIER)) {
3962 /* Drain all pending writes. We only really need 3982 /* Drain all pending writes. We only really need
3963 * to ensure they have been submitted, but this is 3983 * to ensure they have been submitted, but this is
3964 * easier. 3984 * easier.
@@ -4075,7 +4095,7 @@ static int make_request(mddev_t *mddev, struct bio * bi)
4075 * add failed due to overlap. Flush everything 4095 * add failed due to overlap. Flush everything
4076 * and wait a while 4096 * and wait a while
4077 */ 4097 */
4078 raid5_unplug_device(mddev->queue); 4098 md_raid5_unplug_device(conf);
4079 release_stripe(sh); 4099 release_stripe(sh);
4080 schedule(); 4100 schedule();
4081 goto retry; 4101 goto retry;
@@ -4566,23 +4586,15 @@ raid5_show_stripe_cache_size(mddev_t *mddev, char *page)
4566 return 0; 4586 return 0;
4567} 4587}
4568 4588
4569static ssize_t 4589int
4570raid5_store_stripe_cache_size(mddev_t *mddev, const char *page, size_t len) 4590raid5_set_cache_size(mddev_t *mddev, int size)
4571{ 4591{
4572 raid5_conf_t *conf = mddev->private; 4592 raid5_conf_t *conf = mddev->private;
4573 unsigned long new;
4574 int err; 4593 int err;
4575 4594
4576 if (len >= PAGE_SIZE) 4595 if (size <= 16 || size > 32768)
4577 return -EINVAL; 4596 return -EINVAL;
4578 if (!conf) 4597 while (size < conf->max_nr_stripes) {
4579 return -ENODEV;
4580
4581 if (strict_strtoul(page, 10, &new))
4582 return -EINVAL;
4583 if (new <= 16 || new > 32768)
4584 return -EINVAL;
4585 while (new < conf->max_nr_stripes) {
4586 if (drop_one_stripe(conf)) 4598 if (drop_one_stripe(conf))
4587 conf->max_nr_stripes--; 4599 conf->max_nr_stripes--;
4588 else 4600 else
@@ -4591,11 +4603,32 @@ raid5_store_stripe_cache_size(mddev_t *mddev, const char *page, size_t len)
4591 err = md_allow_write(mddev); 4603 err = md_allow_write(mddev);
4592 if (err) 4604 if (err)
4593 return err; 4605 return err;
4594 while (new > conf->max_nr_stripes) { 4606 while (size > conf->max_nr_stripes) {
4595 if (grow_one_stripe(conf)) 4607 if (grow_one_stripe(conf))
4596 conf->max_nr_stripes++; 4608 conf->max_nr_stripes++;
4597 else break; 4609 else break;
4598 } 4610 }
4611 return 0;
4612}
4613EXPORT_SYMBOL(raid5_set_cache_size);
4614
4615static ssize_t
4616raid5_store_stripe_cache_size(mddev_t *mddev, const char *page, size_t len)
4617{
4618 raid5_conf_t *conf = mddev->private;
4619 unsigned long new;
4620 int err;
4621
4622 if (len >= PAGE_SIZE)
4623 return -EINVAL;
4624 if (!conf)
4625 return -ENODEV;
4626
4627 if (strict_strtoul(page, 10, &new))
4628 return -EINVAL;
4629 err = raid5_set_cache_size(mddev, new);
4630 if (err)
4631 return err;
4599 return len; 4632 return len;
4600} 4633}
4601 4634
@@ -4958,7 +4991,7 @@ static int only_parity(int raid_disk, int algo, int raid_disks, int max_degraded
4958static int run(mddev_t *mddev) 4991static int run(mddev_t *mddev)
4959{ 4992{
4960 raid5_conf_t *conf; 4993 raid5_conf_t *conf;
4961 int working_disks = 0, chunk_size; 4994 int working_disks = 0;
4962 int dirty_parity_disks = 0; 4995 int dirty_parity_disks = 0;
4963 mdk_rdev_t *rdev; 4996 mdk_rdev_t *rdev;
4964 sector_t reshape_offset = 0; 4997 sector_t reshape_offset = 0;
@@ -5144,42 +5177,47 @@ static int run(mddev_t *mddev)
5144 "reshape"); 5177 "reshape");
5145 } 5178 }
5146 5179
5147 /* read-ahead size must cover two whole stripes, which is
5148 * 2 * (datadisks) * chunksize where 'n' is the number of raid devices
5149 */
5150 {
5151 int data_disks = conf->previous_raid_disks - conf->max_degraded;
5152 int stripe = data_disks *
5153 ((mddev->chunk_sectors << 9) / PAGE_SIZE);
5154 if (mddev->queue->backing_dev_info.ra_pages < 2 * stripe)
5155 mddev->queue->backing_dev_info.ra_pages = 2 * stripe;
5156 }
5157 5180
5158 /* Ok, everything is just fine now */ 5181 /* Ok, everything is just fine now */
5159 if (mddev->to_remove == &raid5_attrs_group) 5182 if (mddev->to_remove == &raid5_attrs_group)
5160 mddev->to_remove = NULL; 5183 mddev->to_remove = NULL;
5161 else if (sysfs_create_group(&mddev->kobj, &raid5_attrs_group)) 5184 else if (mddev->kobj.sd &&
5185 sysfs_create_group(&mddev->kobj, &raid5_attrs_group))
5162 printk(KERN_WARNING 5186 printk(KERN_WARNING
5163 "md/raid:%s: failed to create sysfs attributes.\n", 5187 "raid5: failed to create sysfs attributes for %s\n",
5164 mdname(mddev)); 5188 mdname(mddev));
5189 md_set_array_sectors(mddev, raid5_size(mddev, 0, 0));
5165 5190
5166 mddev->queue->queue_lock = &conf->device_lock; 5191 plugger_init(&conf->plug, raid5_unplug);
5192 mddev->plug = &conf->plug;
5193 if (mddev->queue) {
5194 int chunk_size;
5195 /* read-ahead size must cover two whole stripes, which
5196 * is 2 * (datadisks) * chunksize where 'n' is the
5197 * number of raid devices
5198 */
5199 int data_disks = conf->previous_raid_disks - conf->max_degraded;
5200 int stripe = data_disks *
5201 ((mddev->chunk_sectors << 9) / PAGE_SIZE);
5202 if (mddev->queue->backing_dev_info.ra_pages < 2 * stripe)
5203 mddev->queue->backing_dev_info.ra_pages = 2 * stripe;
5167 5204
5168 mddev->queue->unplug_fn = raid5_unplug_device; 5205 blk_queue_merge_bvec(mddev->queue, raid5_mergeable_bvec);
5169 mddev->queue->backing_dev_info.congested_data = mddev;
5170 mddev->queue->backing_dev_info.congested_fn = raid5_congested;
5171 5206
5172 md_set_array_sectors(mddev, raid5_size(mddev, 0, 0)); 5207 mddev->queue->backing_dev_info.congested_data = mddev;
5208 mddev->queue->backing_dev_info.congested_fn = raid5_congested;
5209 mddev->queue->queue_lock = &conf->device_lock;
5210 mddev->queue->unplug_fn = raid5_unplug_queue;
5173 5211
5174 blk_queue_merge_bvec(mddev->queue, raid5_mergeable_bvec); 5212 chunk_size = mddev->chunk_sectors << 9;
5175 chunk_size = mddev->chunk_sectors << 9; 5213 blk_queue_io_min(mddev->queue, chunk_size);
5176 blk_queue_io_min(mddev->queue, chunk_size); 5214 blk_queue_io_opt(mddev->queue, chunk_size *
5177 blk_queue_io_opt(mddev->queue, chunk_size * 5215 (conf->raid_disks - conf->max_degraded));
5178 (conf->raid_disks - conf->max_degraded));
5179 5216
5180 list_for_each_entry(rdev, &mddev->disks, same_set) 5217 list_for_each_entry(rdev, &mddev->disks, same_set)
5181 disk_stack_limits(mddev->gendisk, rdev->bdev, 5218 disk_stack_limits(mddev->gendisk, rdev->bdev,
5182 rdev->data_offset << 9); 5219 rdev->data_offset << 9);
5220 }
5183 5221
5184 return 0; 5222 return 0;
5185abort: 5223abort:
@@ -5200,8 +5238,9 @@ static int stop(mddev_t *mddev)
5200 5238
5201 md_unregister_thread(mddev->thread); 5239 md_unregister_thread(mddev->thread);
5202 mddev->thread = NULL; 5240 mddev->thread = NULL;
5203 mddev->queue->backing_dev_info.congested_fn = NULL; 5241 if (mddev->queue)
5204 blk_sync_queue(mddev->queue); /* the unplug fn references 'conf'*/ 5242 mddev->queue->backing_dev_info.congested_fn = NULL;
5243 plugger_flush(&conf->plug); /* the unplug fn references 'conf'*/
5205 free_conf(conf); 5244 free_conf(conf);
5206 mddev->private = NULL; 5245 mddev->private = NULL;
5207 mddev->to_remove = &raid5_attrs_group; 5246 mddev->to_remove = &raid5_attrs_group;
@@ -5545,10 +5584,7 @@ static int raid5_start_reshape(mddev_t *mddev)
5545 sprintf(nm, "rd%d", rdev->raid_disk); 5584 sprintf(nm, "rd%d", rdev->raid_disk);
5546 if (sysfs_create_link(&mddev->kobj, 5585 if (sysfs_create_link(&mddev->kobj,
5547 &rdev->kobj, nm)) 5586 &rdev->kobj, nm))
5548 printk(KERN_WARNING 5587 /* Failure here is OK */;
5549 "md/raid:%s: failed to create "
5550 " link %s\n",
5551 mdname(mddev), nm);
5552 } else 5588 } else
5553 break; 5589 break;
5554 } 5590 }
@@ -5603,7 +5639,7 @@ static void end_reshape(raid5_conf_t *conf)
5603 /* read-ahead size must cover two whole stripes, which is 5639 /* read-ahead size must cover two whole stripes, which is
5604 * 2 * (datadisks) * chunksize where 'n' is the number of raid devices 5640 * 2 * (datadisks) * chunksize where 'n' is the number of raid devices
5605 */ 5641 */
5606 { 5642 if (conf->mddev->queue) {
5607 int data_disks = conf->raid_disks - conf->max_degraded; 5643 int data_disks = conf->raid_disks - conf->max_degraded;
5608 int stripe = data_disks * ((conf->chunk_sectors << 9) 5644 int stripe = data_disks * ((conf->chunk_sectors << 9)
5609 / PAGE_SIZE); 5645 / PAGE_SIZE);
diff --git a/drivers/md/raid5.h b/drivers/md/raid5.h
index 0f86f5e36724..36eaed5dfd6e 100644
--- a/drivers/md/raid5.h
+++ b/drivers/md/raid5.h
@@ -388,7 +388,7 @@ struct raid5_private_data {
388 * two caches. 388 * two caches.
389 */ 389 */
390 int active_name; 390 int active_name;
391 char cache_name[2][20]; 391 char cache_name[2][32];
392 struct kmem_cache *slab_cache; /* for allocating stripes */ 392 struct kmem_cache *slab_cache; /* for allocating stripes */
393 393
394 int seq_flush, seq_write; 394 int seq_flush, seq_write;
@@ -398,6 +398,9 @@ struct raid5_private_data {
398 * (fresh device added). 398 * (fresh device added).
399 * Cleared when a sync completes. 399 * Cleared when a sync completes.
400 */ 400 */
401
402 struct plug_handle plug;
403
401 /* per cpu variables */ 404 /* per cpu variables */
402 struct raid5_percpu { 405 struct raid5_percpu {
403 struct page *spare_page; /* Used when checking P/Q in raid6 */ 406 struct page *spare_page; /* Used when checking P/Q in raid6 */
@@ -497,4 +500,8 @@ static inline int algorithm_is_DDF(int layout)
497{ 500{
498 return layout >= 8 && layout <= 10; 501 return layout >= 8 && layout <= 10;
499} 502}
503
504extern int md_raid5_congested(mddev_t *mddev, int bits);
505extern void md_raid5_unplug_device(raid5_conf_t *conf);
506extern int raid5_set_cache_size(mddev_t *mddev, int size);
500#endif 507#endif
diff --git a/drivers/md/raid6algos.c b/drivers/md/raid6algos.c
deleted file mode 100644
index 1f8784bfd44d..000000000000
--- a/drivers/md/raid6algos.c
+++ /dev/null
@@ -1,154 +0,0 @@
1/* -*- linux-c -*- ------------------------------------------------------- *
2 *
3 * Copyright 2002 H. Peter Anvin - All Rights Reserved
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, Inc., 53 Temple Place Ste 330,
8 * Boston MA 02111-1307, USA; either version 2 of the License, or
9 * (at your option) any later version; incorporated herein by reference.
10 *
11 * ----------------------------------------------------------------------- */
12
13/*
14 * raid6algos.c
15 *
16 * Algorithm list and algorithm selection for RAID-6
17 */
18
19#include <linux/raid/pq.h>
20#include <linux/gfp.h>
21#ifndef __KERNEL__
22#include <sys/mman.h>
23#include <stdio.h>
24#else
25#if !RAID6_USE_EMPTY_ZERO_PAGE
26/* In .bss so it's zeroed */
27const char raid6_empty_zero_page[PAGE_SIZE] __attribute__((aligned(256)));
28EXPORT_SYMBOL(raid6_empty_zero_page);
29#endif
30#endif
31
32struct raid6_calls raid6_call;
33EXPORT_SYMBOL_GPL(raid6_call);
34
35const struct raid6_calls * const raid6_algos[] = {
36 &raid6_intx1,
37 &raid6_intx2,
38 &raid6_intx4,
39 &raid6_intx8,
40#if defined(__ia64__)
41 &raid6_intx16,
42 &raid6_intx32,
43#endif
44#if defined(__i386__) && !defined(__arch_um__)
45 &raid6_mmxx1,
46 &raid6_mmxx2,
47 &raid6_sse1x1,
48 &raid6_sse1x2,
49 &raid6_sse2x1,
50 &raid6_sse2x2,
51#endif
52#if defined(__x86_64__) && !defined(__arch_um__)
53 &raid6_sse2x1,
54 &raid6_sse2x2,
55 &raid6_sse2x4,
56#endif
57#ifdef CONFIG_ALTIVEC
58 &raid6_altivec1,
59 &raid6_altivec2,
60 &raid6_altivec4,
61 &raid6_altivec8,
62#endif
63 NULL
64};
65
66#ifdef __KERNEL__
67#define RAID6_TIME_JIFFIES_LG2 4
68#else
69/* Need more time to be stable in userspace */
70#define RAID6_TIME_JIFFIES_LG2 9
71#define time_before(x, y) ((x) < (y))
72#endif
73
74/* Try to pick the best algorithm */
75/* This code uses the gfmul table as convenient data set to abuse */
76
77int __init raid6_select_algo(void)
78{
79 const struct raid6_calls * const * algo;
80 const struct raid6_calls * best;
81 char *syndromes;
82 void *dptrs[(65536/PAGE_SIZE)+2];
83 int i, disks;
84 unsigned long perf, bestperf;
85 int bestprefer;
86 unsigned long j0, j1;
87
88 disks = (65536/PAGE_SIZE)+2;
89 for ( i = 0 ; i < disks-2 ; i++ ) {
90 dptrs[i] = ((char *)raid6_gfmul) + PAGE_SIZE*i;
91 }
92
93 /* Normal code - use a 2-page allocation to avoid D$ conflict */
94 syndromes = (void *) __get_free_pages(GFP_KERNEL, 1);
95
96 if ( !syndromes ) {
97 printk("raid6: Yikes! No memory available.\n");
98 return -ENOMEM;
99 }
100
101 dptrs[disks-2] = syndromes;
102 dptrs[disks-1] = syndromes + PAGE_SIZE;
103
104 bestperf = 0; bestprefer = 0; best = NULL;
105
106 for ( algo = raid6_algos ; *algo ; algo++ ) {
107 if ( !(*algo)->valid || (*algo)->valid() ) {
108 perf = 0;
109
110 preempt_disable();
111 j0 = jiffies;
112 while ( (j1 = jiffies) == j0 )
113 cpu_relax();
114 while (time_before(jiffies,
115 j1 + (1<<RAID6_TIME_JIFFIES_LG2))) {
116 (*algo)->gen_syndrome(disks, PAGE_SIZE, dptrs);
117 perf++;
118 }
119 preempt_enable();
120
121 if ( (*algo)->prefer > bestprefer ||
122 ((*algo)->prefer == bestprefer &&
123 perf > bestperf) ) {
124 best = *algo;
125 bestprefer = best->prefer;
126 bestperf = perf;
127 }
128 printk("raid6: %-8s %5ld MB/s\n", (*algo)->name,
129 (perf*HZ) >> (20-16+RAID6_TIME_JIFFIES_LG2));
130 }
131 }
132
133 if (best) {
134 printk("raid6: using algorithm %s (%ld MB/s)\n",
135 best->name,
136 (bestperf*HZ) >> (20-16+RAID6_TIME_JIFFIES_LG2));
137 raid6_call = *best;
138 } else
139 printk("raid6: Yikes! No algorithm found!\n");
140
141 free_pages((unsigned long)syndromes, 1);
142
143 return best ? 0 : -EINVAL;
144}
145
146static void raid6_exit(void)
147{
148 do { } while (0);
149}
150
151subsys_initcall(raid6_select_algo);
152module_exit(raid6_exit);
153MODULE_LICENSE("GPL");
154MODULE_DESCRIPTION("RAID6 Q-syndrome calculations");
diff --git a/drivers/md/raid6altivec.uc b/drivers/md/raid6altivec.uc
deleted file mode 100644
index 2654d5c854be..000000000000
--- a/drivers/md/raid6altivec.uc
+++ /dev/null
@@ -1,130 +0,0 @@
1/* -*- linux-c -*- ------------------------------------------------------- *
2 *
3 * Copyright 2002-2004 H. Peter Anvin - All Rights Reserved
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, Inc., 53 Temple Place Ste 330,
8 * Boston MA 02111-1307, USA; either version 2 of the License, or
9 * (at your option) any later version; incorporated herein by reference.
10 *
11 * ----------------------------------------------------------------------- */
12
13/*
14 * raid6altivec$#.c
15 *
16 * $#-way unrolled portable integer math RAID-6 instruction set
17 *
18 * This file is postprocessed using unroll.awk
19 *
20 * <benh> hpa: in process,
21 * you can just "steal" the vec unit with enable_kernel_altivec() (but
22 * bracked this with preempt_disable/enable or in a lock)
23 */
24
25#include <linux/raid/pq.h>
26
27#ifdef CONFIG_ALTIVEC
28
29#include <altivec.h>
30#ifdef __KERNEL__
31# include <asm/system.h>
32# include <asm/cputable.h>
33#endif
34
35/*
36 * This is the C data type to use. We use a vector of
37 * signed char so vec_cmpgt() will generate the right
38 * instruction.
39 */
40
41typedef vector signed char unative_t;
42
43#define NBYTES(x) ((vector signed char) {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x})
44#define NSIZE sizeof(unative_t)
45
46/*
47 * The SHLBYTE() operation shifts each byte left by 1, *not*
48 * rolling over into the next byte
49 */
50static inline __attribute_const__ unative_t SHLBYTE(unative_t v)
51{
52 return vec_add(v,v);
53}
54
55/*
56 * The MASK() operation returns 0xFF in any byte for which the high
57 * bit is 1, 0x00 for any byte for which the high bit is 0.
58 */
59static inline __attribute_const__ unative_t MASK(unative_t v)
60{
61 unative_t zv = NBYTES(0);
62
63 /* vec_cmpgt returns a vector bool char; thus the need for the cast */
64 return (unative_t)vec_cmpgt(zv, v);
65}
66
67
68/* This is noinline to make damned sure that gcc doesn't move any of the
69 Altivec code around the enable/disable code */
70static void noinline
71raid6_altivec$#_gen_syndrome_real(int disks, size_t bytes, void **ptrs)
72{
73 u8 **dptr = (u8 **)ptrs;
74 u8 *p, *q;
75 int d, z, z0;
76
77 unative_t wd$$, wq$$, wp$$, w1$$, w2$$;
78 unative_t x1d = NBYTES(0x1d);
79
80 z0 = disks - 3; /* Highest data disk */
81 p = dptr[z0+1]; /* XOR parity */
82 q = dptr[z0+2]; /* RS syndrome */
83
84 for ( d = 0 ; d < bytes ; d += NSIZE*$# ) {
85 wq$$ = wp$$ = *(unative_t *)&dptr[z0][d+$$*NSIZE];
86 for ( z = z0-1 ; z >= 0 ; z-- ) {
87 wd$$ = *(unative_t *)&dptr[z][d+$$*NSIZE];
88 wp$$ = vec_xor(wp$$, wd$$);
89 w2$$ = MASK(wq$$);
90 w1$$ = SHLBYTE(wq$$);
91 w2$$ = vec_and(w2$$, x1d);
92 w1$$ = vec_xor(w1$$, w2$$);
93 wq$$ = vec_xor(w1$$, wd$$);
94 }
95 *(unative_t *)&p[d+NSIZE*$$] = wp$$;
96 *(unative_t *)&q[d+NSIZE*$$] = wq$$;
97 }
98}
99
100static void raid6_altivec$#_gen_syndrome(int disks, size_t bytes, void **ptrs)
101{
102 preempt_disable();
103 enable_kernel_altivec();
104
105 raid6_altivec$#_gen_syndrome_real(disks, bytes, ptrs);
106
107 preempt_enable();
108}
109
110int raid6_have_altivec(void);
111#if $# == 1
112int raid6_have_altivec(void)
113{
114 /* This assumes either all CPUs have Altivec or none does */
115# ifdef __KERNEL__
116 return cpu_has_feature(CPU_FTR_ALTIVEC);
117# else
118 return 1;
119# endif
120}
121#endif
122
123const struct raid6_calls raid6_altivec$# = {
124 raid6_altivec$#_gen_syndrome,
125 raid6_have_altivec,
126 "altivecx$#",
127 0
128};
129
130#endif /* CONFIG_ALTIVEC */
diff --git a/drivers/md/raid6int.uc b/drivers/md/raid6int.uc
deleted file mode 100644
index d1e276a14fab..000000000000
--- a/drivers/md/raid6int.uc
+++ /dev/null
@@ -1,117 +0,0 @@
1/* -*- linux-c -*- ------------------------------------------------------- *
2 *
3 * Copyright 2002-2004 H. Peter Anvin - All Rights Reserved
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, Inc., 53 Temple Place Ste 330,
8 * Boston MA 02111-1307, USA; either version 2 of the License, or
9 * (at your option) any later version; incorporated herein by reference.
10 *
11 * ----------------------------------------------------------------------- */
12
13/*
14 * raid6int$#.c
15 *
16 * $#-way unrolled portable integer math RAID-6 instruction set
17 *
18 * This file is postprocessed using unroll.awk
19 */
20
21#include <linux/raid/pq.h>
22
23/*
24 * This is the C data type to use
25 */
26
27/* Change this from BITS_PER_LONG if there is something better... */
28#if BITS_PER_LONG == 64
29# define NBYTES(x) ((x) * 0x0101010101010101UL)
30# define NSIZE 8
31# define NSHIFT 3
32# define NSTRING "64"
33typedef u64 unative_t;
34#else
35# define NBYTES(x) ((x) * 0x01010101U)
36# define NSIZE 4
37# define NSHIFT 2
38# define NSTRING "32"
39typedef u32 unative_t;
40#endif
41
42
43
44/*
45 * IA-64 wants insane amounts of unrolling. On other architectures that
46 * is just a waste of space.
47 */
48#if ($# <= 8) || defined(__ia64__)
49
50
51/*
52 * These sub-operations are separate inlines since they can sometimes be
53 * specially optimized using architecture-specific hacks.
54 */
55
56/*
57 * The SHLBYTE() operation shifts each byte left by 1, *not*
58 * rolling over into the next byte
59 */
60static inline __attribute_const__ unative_t SHLBYTE(unative_t v)
61{
62 unative_t vv;
63
64 vv = (v << 1) & NBYTES(0xfe);
65 return vv;
66}
67
68/*
69 * The MASK() operation returns 0xFF in any byte for which the high
70 * bit is 1, 0x00 for any byte for which the high bit is 0.
71 */
72static inline __attribute_const__ unative_t MASK(unative_t v)
73{
74 unative_t vv;
75
76 vv = v & NBYTES(0x80);
77 vv = (vv << 1) - (vv >> 7); /* Overflow on the top bit is OK */
78 return vv;
79}
80
81
82static void raid6_int$#_gen_syndrome(int disks, size_t bytes, void **ptrs)
83{
84 u8 **dptr = (u8 **)ptrs;
85 u8 *p, *q;
86 int d, z, z0;
87
88 unative_t wd$$, wq$$, wp$$, w1$$, w2$$;
89
90 z0 = disks - 3; /* Highest data disk */
91 p = dptr[z0+1]; /* XOR parity */
92 q = dptr[z0+2]; /* RS syndrome */
93
94 for ( d = 0 ; d < bytes ; d += NSIZE*$# ) {
95 wq$$ = wp$$ = *(unative_t *)&dptr[z0][d+$$*NSIZE];
96 for ( z = z0-1 ; z >= 0 ; z-- ) {
97 wd$$ = *(unative_t *)&dptr[z][d+$$*NSIZE];
98 wp$$ ^= wd$$;
99 w2$$ = MASK(wq$$);
100 w1$$ = SHLBYTE(wq$$);
101 w2$$ &= NBYTES(0x1d);
102 w1$$ ^= w2$$;
103 wq$$ = w1$$ ^ wd$$;
104 }
105 *(unative_t *)&p[d+NSIZE*$$] = wp$$;
106 *(unative_t *)&q[d+NSIZE*$$] = wq$$;
107 }
108}
109
110const struct raid6_calls raid6_intx$# = {
111 raid6_int$#_gen_syndrome,
112 NULL, /* always valid */
113 "int" NSTRING "x$#",
114 0
115};
116
117#endif
diff --git a/drivers/md/raid6mmx.c b/drivers/md/raid6mmx.c
deleted file mode 100644
index e7f6c13132bf..000000000000
--- a/drivers/md/raid6mmx.c
+++ /dev/null
@@ -1,142 +0,0 @@
1/* -*- linux-c -*- ------------------------------------------------------- *
2 *
3 * Copyright 2002 H. Peter Anvin - All Rights Reserved
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, Inc., 53 Temple Place Ste 330,
8 * Boston MA 02111-1307, USA; either version 2 of the License, or
9 * (at your option) any later version; incorporated herein by reference.
10 *
11 * ----------------------------------------------------------------------- */
12
13/*
14 * raid6mmx.c
15 *
16 * MMX implementation of RAID-6 syndrome functions
17 */
18
19#if defined(__i386__) && !defined(__arch_um__)
20
21#include <linux/raid/pq.h>
22#include "raid6x86.h"
23
24/* Shared with raid6sse1.c */
25const struct raid6_mmx_constants {
26 u64 x1d;
27} raid6_mmx_constants = {
28 0x1d1d1d1d1d1d1d1dULL,
29};
30
31static int raid6_have_mmx(void)
32{
33 /* Not really "boot_cpu" but "all_cpus" */
34 return boot_cpu_has(X86_FEATURE_MMX);
35}
36
37/*
38 * Plain MMX implementation
39 */
40static void raid6_mmx1_gen_syndrome(int disks, size_t bytes, void **ptrs)
41{
42 u8 **dptr = (u8 **)ptrs;
43 u8 *p, *q;
44 int d, z, z0;
45
46 z0 = disks - 3; /* Highest data disk */
47 p = dptr[z0+1]; /* XOR parity */
48 q = dptr[z0+2]; /* RS syndrome */
49
50 kernel_fpu_begin();
51
52 asm volatile("movq %0,%%mm0" : : "m" (raid6_mmx_constants.x1d));
53 asm volatile("pxor %mm5,%mm5"); /* Zero temp */
54
55 for ( d = 0 ; d < bytes ; d += 8 ) {
56 asm volatile("movq %0,%%mm2" : : "m" (dptr[z0][d])); /* P[0] */
57 asm volatile("movq %mm2,%mm4"); /* Q[0] */
58 for ( z = z0-1 ; z >= 0 ; z-- ) {
59 asm volatile("movq %0,%%mm6" : : "m" (dptr[z][d]));
60 asm volatile("pcmpgtb %mm4,%mm5");
61 asm volatile("paddb %mm4,%mm4");
62 asm volatile("pand %mm0,%mm5");
63 asm volatile("pxor %mm5,%mm4");
64 asm volatile("pxor %mm5,%mm5");
65 asm volatile("pxor %mm6,%mm2");
66 asm volatile("pxor %mm6,%mm4");
67 }
68 asm volatile("movq %%mm2,%0" : "=m" (p[d]));
69 asm volatile("pxor %mm2,%mm2");
70 asm volatile("movq %%mm4,%0" : "=m" (q[d]));
71 asm volatile("pxor %mm4,%mm4");
72 }
73
74 kernel_fpu_end();
75}
76
77const struct raid6_calls raid6_mmxx1 = {
78 raid6_mmx1_gen_syndrome,
79 raid6_have_mmx,
80 "mmxx1",
81 0
82};
83
84/*
85 * Unrolled-by-2 MMX implementation
86 */
87static void raid6_mmx2_gen_syndrome(int disks, size_t bytes, void **ptrs)
88{
89 u8 **dptr = (u8 **)ptrs;
90 u8 *p, *q;
91 int d, z, z0;
92
93 z0 = disks - 3; /* Highest data disk */
94 p = dptr[z0+1]; /* XOR parity */
95 q = dptr[z0+2]; /* RS syndrome */
96
97 kernel_fpu_begin();
98
99 asm volatile("movq %0,%%mm0" : : "m" (raid6_mmx_constants.x1d));
100 asm volatile("pxor %mm5,%mm5"); /* Zero temp */
101 asm volatile("pxor %mm7,%mm7"); /* Zero temp */
102
103 for ( d = 0 ; d < bytes ; d += 16 ) {
104 asm volatile("movq %0,%%mm2" : : "m" (dptr[z0][d])); /* P[0] */
105 asm volatile("movq %0,%%mm3" : : "m" (dptr[z0][d+8]));
106 asm volatile("movq %mm2,%mm4"); /* Q[0] */
107 asm volatile("movq %mm3,%mm6"); /* Q[1] */
108 for ( z = z0-1 ; z >= 0 ; z-- ) {
109 asm volatile("pcmpgtb %mm4,%mm5");
110 asm volatile("pcmpgtb %mm6,%mm7");
111 asm volatile("paddb %mm4,%mm4");
112 asm volatile("paddb %mm6,%mm6");
113 asm volatile("pand %mm0,%mm5");
114 asm volatile("pand %mm0,%mm7");
115 asm volatile("pxor %mm5,%mm4");
116 asm volatile("pxor %mm7,%mm6");
117 asm volatile("movq %0,%%mm5" : : "m" (dptr[z][d]));
118 asm volatile("movq %0,%%mm7" : : "m" (dptr[z][d+8]));
119 asm volatile("pxor %mm5,%mm2");
120 asm volatile("pxor %mm7,%mm3");
121 asm volatile("pxor %mm5,%mm4");
122 asm volatile("pxor %mm7,%mm6");
123 asm volatile("pxor %mm5,%mm5");
124 asm volatile("pxor %mm7,%mm7");
125 }
126 asm volatile("movq %%mm2,%0" : "=m" (p[d]));
127 asm volatile("movq %%mm3,%0" : "=m" (p[d+8]));
128 asm volatile("movq %%mm4,%0" : "=m" (q[d]));
129 asm volatile("movq %%mm6,%0" : "=m" (q[d+8]));
130 }
131
132 kernel_fpu_end();
133}
134
135const struct raid6_calls raid6_mmxx2 = {
136 raid6_mmx2_gen_syndrome,
137 raid6_have_mmx,
138 "mmxx2",
139 0
140};
141
142#endif
diff --git a/drivers/md/raid6recov.c b/drivers/md/raid6recov.c
deleted file mode 100644
index 2609f00e0d61..000000000000
--- a/drivers/md/raid6recov.c
+++ /dev/null
@@ -1,132 +0,0 @@
1/* -*- linux-c -*- ------------------------------------------------------- *
2 *
3 * Copyright 2002 H. Peter Anvin - All Rights Reserved
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, Inc., 53 Temple Place Ste 330,
8 * Boston MA 02111-1307, USA; either version 2 of the License, or
9 * (at your option) any later version; incorporated herein by reference.
10 *
11 * ----------------------------------------------------------------------- */
12
13/*
14 * raid6recov.c
15 *
16 * RAID-6 data recovery in dual failure mode. In single failure mode,
17 * use the RAID-5 algorithm (or, in the case of Q failure, just reconstruct
18 * the syndrome.)
19 */
20
21#include <linux/raid/pq.h>
22
23/* Recover two failed data blocks. */
24void raid6_2data_recov(int disks, size_t bytes, int faila, int failb,
25 void **ptrs)
26{
27 u8 *p, *q, *dp, *dq;
28 u8 px, qx, db;
29 const u8 *pbmul; /* P multiplier table for B data */
30 const u8 *qmul; /* Q multiplier table (for both) */
31
32 p = (u8 *)ptrs[disks-2];
33 q = (u8 *)ptrs[disks-1];
34
35 /* Compute syndrome with zero for the missing data pages
36 Use the dead data pages as temporary storage for
37 delta p and delta q */
38 dp = (u8 *)ptrs[faila];
39 ptrs[faila] = (void *)raid6_empty_zero_page;
40 ptrs[disks-2] = dp;
41 dq = (u8 *)ptrs[failb];
42 ptrs[failb] = (void *)raid6_empty_zero_page;
43 ptrs[disks-1] = dq;
44
45 raid6_call.gen_syndrome(disks, bytes, ptrs);
46
47 /* Restore pointer table */
48 ptrs[faila] = dp;
49 ptrs[failb] = dq;
50 ptrs[disks-2] = p;
51 ptrs[disks-1] = q;
52
53 /* Now, pick the proper data tables */
54 pbmul = raid6_gfmul[raid6_gfexi[failb-faila]];
55 qmul = raid6_gfmul[raid6_gfinv[raid6_gfexp[faila]^raid6_gfexp[failb]]];
56
57 /* Now do it... */
58 while ( bytes-- ) {
59 px = *p ^ *dp;
60 qx = qmul[*q ^ *dq];
61 *dq++ = db = pbmul[px] ^ qx; /* Reconstructed B */
62 *dp++ = db ^ px; /* Reconstructed A */
63 p++; q++;
64 }
65}
66EXPORT_SYMBOL_GPL(raid6_2data_recov);
67
68/* Recover failure of one data block plus the P block */
69void raid6_datap_recov(int disks, size_t bytes, int faila, void **ptrs)
70{
71 u8 *p, *q, *dq;
72 const u8 *qmul; /* Q multiplier table */
73
74 p = (u8 *)ptrs[disks-2];
75 q = (u8 *)ptrs[disks-1];
76
77 /* Compute syndrome with zero for the missing data page
78 Use the dead data page as temporary storage for delta q */
79 dq = (u8 *)ptrs[faila];
80 ptrs[faila] = (void *)raid6_empty_zero_page;
81 ptrs[disks-1] = dq;
82
83 raid6_call.gen_syndrome(disks, bytes, ptrs);
84
85 /* Restore pointer table */
86 ptrs[faila] = dq;
87 ptrs[disks-1] = q;
88
89 /* Now, pick the proper data tables */
90 qmul = raid6_gfmul[raid6_gfinv[raid6_gfexp[faila]]];
91
92 /* Now do it... */
93 while ( bytes-- ) {
94 *p++ ^= *dq = qmul[*q ^ *dq];
95 q++; dq++;
96 }
97}
98EXPORT_SYMBOL_GPL(raid6_datap_recov);
99
100#ifndef __KERNEL__
101/* Testing only */
102
103/* Recover two failed blocks. */
104void raid6_dual_recov(int disks, size_t bytes, int faila, int failb, void **ptrs)
105{
106 if ( faila > failb ) {
107 int tmp = faila;
108 faila = failb;
109 failb = tmp;
110 }
111
112 if ( failb == disks-1 ) {
113 if ( faila == disks-2 ) {
114 /* P+Q failure. Just rebuild the syndrome. */
115 raid6_call.gen_syndrome(disks, bytes, ptrs);
116 } else {
117 /* data+Q failure. Reconstruct data from P,
118 then rebuild syndrome. */
119 /* NOT IMPLEMENTED - equivalent to RAID-5 */
120 }
121 } else {
122 if ( failb == disks-2 ) {
123 /* data+P failure. */
124 raid6_datap_recov(disks, bytes, faila, ptrs);
125 } else {
126 /* data+data failure. */
127 raid6_2data_recov(disks, bytes, faila, failb, ptrs);
128 }
129 }
130}
131
132#endif
diff --git a/drivers/md/raid6sse1.c b/drivers/md/raid6sse1.c
deleted file mode 100644
index b274dd5eab8f..000000000000
--- a/drivers/md/raid6sse1.c
+++ /dev/null
@@ -1,162 +0,0 @@
1/* -*- linux-c -*- ------------------------------------------------------- *
2 *
3 * Copyright 2002 H. Peter Anvin - All Rights Reserved
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, Inc., 53 Temple Place Ste 330,
8 * Boston MA 02111-1307, USA; either version 2 of the License, or
9 * (at your option) any later version; incorporated herein by reference.
10 *
11 * ----------------------------------------------------------------------- */
12
13/*
14 * raid6sse1.c
15 *
16 * SSE-1/MMXEXT implementation of RAID-6 syndrome functions
17 *
18 * This is really an MMX implementation, but it requires SSE-1 or
19 * AMD MMXEXT for prefetch support and a few other features. The
20 * support for nontemporal memory accesses is enough to make this
21 * worthwhile as a separate implementation.
22 */
23
24#if defined(__i386__) && !defined(__arch_um__)
25
26#include <linux/raid/pq.h>
27#include "raid6x86.h"
28
29/* Defined in raid6mmx.c */
30extern const struct raid6_mmx_constants {
31 u64 x1d;
32} raid6_mmx_constants;
33
34static int raid6_have_sse1_or_mmxext(void)
35{
36 /* Not really boot_cpu but "all_cpus" */
37 return boot_cpu_has(X86_FEATURE_MMX) &&
38 (boot_cpu_has(X86_FEATURE_XMM) ||
39 boot_cpu_has(X86_FEATURE_MMXEXT));
40}
41
42/*
43 * Plain SSE1 implementation
44 */
45static void raid6_sse11_gen_syndrome(int disks, size_t bytes, void **ptrs)
46{
47 u8 **dptr = (u8 **)ptrs;
48 u8 *p, *q;
49 int d, z, z0;
50
51 z0 = disks - 3; /* Highest data disk */
52 p = dptr[z0+1]; /* XOR parity */
53 q = dptr[z0+2]; /* RS syndrome */
54
55 kernel_fpu_begin();
56
57 asm volatile("movq %0,%%mm0" : : "m" (raid6_mmx_constants.x1d));
58 asm volatile("pxor %mm5,%mm5"); /* Zero temp */
59
60 for ( d = 0 ; d < bytes ; d += 8 ) {
61 asm volatile("prefetchnta %0" : : "m" (dptr[z0][d]));
62 asm volatile("movq %0,%%mm2" : : "m" (dptr[z0][d])); /* P[0] */
63 asm volatile("prefetchnta %0" : : "m" (dptr[z0-1][d]));
64 asm volatile("movq %mm2,%mm4"); /* Q[0] */
65 asm volatile("movq %0,%%mm6" : : "m" (dptr[z0-1][d]));
66 for ( z = z0-2 ; z >= 0 ; z-- ) {
67 asm volatile("prefetchnta %0" : : "m" (dptr[z][d]));
68 asm volatile("pcmpgtb %mm4,%mm5");
69 asm volatile("paddb %mm4,%mm4");
70 asm volatile("pand %mm0,%mm5");
71 asm volatile("pxor %mm5,%mm4");
72 asm volatile("pxor %mm5,%mm5");
73 asm volatile("pxor %mm6,%mm2");
74 asm volatile("pxor %mm6,%mm4");
75 asm volatile("movq %0,%%mm6" : : "m" (dptr[z][d]));
76 }
77 asm volatile("pcmpgtb %mm4,%mm5");
78 asm volatile("paddb %mm4,%mm4");
79 asm volatile("pand %mm0,%mm5");
80 asm volatile("pxor %mm5,%mm4");
81 asm volatile("pxor %mm5,%mm5");
82 asm volatile("pxor %mm6,%mm2");
83 asm volatile("pxor %mm6,%mm4");
84
85 asm volatile("movntq %%mm2,%0" : "=m" (p[d]));
86 asm volatile("movntq %%mm4,%0" : "=m" (q[d]));
87 }
88
89 asm volatile("sfence" : : : "memory");
90 kernel_fpu_end();
91}
92
93const struct raid6_calls raid6_sse1x1 = {
94 raid6_sse11_gen_syndrome,
95 raid6_have_sse1_or_mmxext,
96 "sse1x1",
97 1 /* Has cache hints */
98};
99
100/*
101 * Unrolled-by-2 SSE1 implementation
102 */
103static void raid6_sse12_gen_syndrome(int disks, size_t bytes, void **ptrs)
104{
105 u8 **dptr = (u8 **)ptrs;
106 u8 *p, *q;
107 int d, z, z0;
108
109 z0 = disks - 3; /* Highest data disk */
110 p = dptr[z0+1]; /* XOR parity */
111 q = dptr[z0+2]; /* RS syndrome */
112
113 kernel_fpu_begin();
114
115 asm volatile("movq %0,%%mm0" : : "m" (raid6_mmx_constants.x1d));
116 asm volatile("pxor %mm5,%mm5"); /* Zero temp */
117 asm volatile("pxor %mm7,%mm7"); /* Zero temp */
118
119 /* We uniformly assume a single prefetch covers at least 16 bytes */
120 for ( d = 0 ; d < bytes ; d += 16 ) {
121 asm volatile("prefetchnta %0" : : "m" (dptr[z0][d]));
122 asm volatile("movq %0,%%mm2" : : "m" (dptr[z0][d])); /* P[0] */
123 asm volatile("movq %0,%%mm3" : : "m" (dptr[z0][d+8])); /* P[1] */
124 asm volatile("movq %mm2,%mm4"); /* Q[0] */
125 asm volatile("movq %mm3,%mm6"); /* Q[1] */
126 for ( z = z0-1 ; z >= 0 ; z-- ) {
127 asm volatile("prefetchnta %0" : : "m" (dptr[z][d]));
128 asm volatile("pcmpgtb %mm4,%mm5");
129 asm volatile("pcmpgtb %mm6,%mm7");
130 asm volatile("paddb %mm4,%mm4");
131 asm volatile("paddb %mm6,%mm6");
132 asm volatile("pand %mm0,%mm5");
133 asm volatile("pand %mm0,%mm7");
134 asm volatile("pxor %mm5,%mm4");
135 asm volatile("pxor %mm7,%mm6");
136 asm volatile("movq %0,%%mm5" : : "m" (dptr[z][d]));
137 asm volatile("movq %0,%%mm7" : : "m" (dptr[z][d+8]));
138 asm volatile("pxor %mm5,%mm2");
139 asm volatile("pxor %mm7,%mm3");
140 asm volatile("pxor %mm5,%mm4");
141 asm volatile("pxor %mm7,%mm6");
142 asm volatile("pxor %mm5,%mm5");
143 asm volatile("pxor %mm7,%mm7");
144 }
145 asm volatile("movntq %%mm2,%0" : "=m" (p[d]));
146 asm volatile("movntq %%mm3,%0" : "=m" (p[d+8]));
147 asm volatile("movntq %%mm4,%0" : "=m" (q[d]));
148 asm volatile("movntq %%mm6,%0" : "=m" (q[d+8]));
149 }
150
151 asm volatile("sfence" : :: "memory");
152 kernel_fpu_end();
153}
154
155const struct raid6_calls raid6_sse1x2 = {
156 raid6_sse12_gen_syndrome,
157 raid6_have_sse1_or_mmxext,
158 "sse1x2",
159 1 /* Has cache hints */
160};
161
162#endif
diff --git a/drivers/md/raid6sse2.c b/drivers/md/raid6sse2.c
deleted file mode 100644
index 6ed6c6c0389f..000000000000
--- a/drivers/md/raid6sse2.c
+++ /dev/null
@@ -1,262 +0,0 @@
1/* -*- linux-c -*- ------------------------------------------------------- *
2 *
3 * Copyright 2002 H. Peter Anvin - All Rights Reserved
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, Inc., 53 Temple Place Ste 330,
8 * Boston MA 02111-1307, USA; either version 2 of the License, or
9 * (at your option) any later version; incorporated herein by reference.
10 *
11 * ----------------------------------------------------------------------- */
12
13/*
14 * raid6sse2.c
15 *
16 * SSE-2 implementation of RAID-6 syndrome functions
17 *
18 */
19
20#if (defined(__i386__) || defined(__x86_64__)) && !defined(__arch_um__)
21
22#include <linux/raid/pq.h>
23#include "raid6x86.h"
24
25static const struct raid6_sse_constants {
26 u64 x1d[2];
27} raid6_sse_constants __attribute__((aligned(16))) = {
28 { 0x1d1d1d1d1d1d1d1dULL, 0x1d1d1d1d1d1d1d1dULL },
29};
30
31static int raid6_have_sse2(void)
32{
33 /* Not really boot_cpu but "all_cpus" */
34 return boot_cpu_has(X86_FEATURE_MMX) &&
35 boot_cpu_has(X86_FEATURE_FXSR) &&
36 boot_cpu_has(X86_FEATURE_XMM) &&
37 boot_cpu_has(X86_FEATURE_XMM2);
38}
39
40/*
41 * Plain SSE2 implementation
42 */
43static void raid6_sse21_gen_syndrome(int disks, size_t bytes, void **ptrs)
44{
45 u8 **dptr = (u8 **)ptrs;
46 u8 *p, *q;
47 int d, z, z0;
48
49 z0 = disks - 3; /* Highest data disk */
50 p = dptr[z0+1]; /* XOR parity */
51 q = dptr[z0+2]; /* RS syndrome */
52
53 kernel_fpu_begin();
54
55 asm volatile("movdqa %0,%%xmm0" : : "m" (raid6_sse_constants.x1d[0]));
56 asm volatile("pxor %xmm5,%xmm5"); /* Zero temp */
57
58 for ( d = 0 ; d < bytes ; d += 16 ) {
59 asm volatile("prefetchnta %0" : : "m" (dptr[z0][d]));
60 asm volatile("movdqa %0,%%xmm2" : : "m" (dptr[z0][d])); /* P[0] */
61 asm volatile("prefetchnta %0" : : "m" (dptr[z0-1][d]));
62 asm volatile("movdqa %xmm2,%xmm4"); /* Q[0] */
63 asm volatile("movdqa %0,%%xmm6" : : "m" (dptr[z0-1][d]));
64 for ( z = z0-2 ; z >= 0 ; z-- ) {
65 asm volatile("prefetchnta %0" : : "m" (dptr[z][d]));
66 asm volatile("pcmpgtb %xmm4,%xmm5");
67 asm volatile("paddb %xmm4,%xmm4");
68 asm volatile("pand %xmm0,%xmm5");
69 asm volatile("pxor %xmm5,%xmm4");
70 asm volatile("pxor %xmm5,%xmm5");
71 asm volatile("pxor %xmm6,%xmm2");
72 asm volatile("pxor %xmm6,%xmm4");
73 asm volatile("movdqa %0,%%xmm6" : : "m" (dptr[z][d]));
74 }
75 asm volatile("pcmpgtb %xmm4,%xmm5");
76 asm volatile("paddb %xmm4,%xmm4");
77 asm volatile("pand %xmm0,%xmm5");
78 asm volatile("pxor %xmm5,%xmm4");
79 asm volatile("pxor %xmm5,%xmm5");
80 asm volatile("pxor %xmm6,%xmm2");
81 asm volatile("pxor %xmm6,%xmm4");
82
83 asm volatile("movntdq %%xmm2,%0" : "=m" (p[d]));
84 asm volatile("pxor %xmm2,%xmm2");
85 asm volatile("movntdq %%xmm4,%0" : "=m" (q[d]));
86 asm volatile("pxor %xmm4,%xmm4");
87 }
88
89 asm volatile("sfence" : : : "memory");
90 kernel_fpu_end();
91}
92
93const struct raid6_calls raid6_sse2x1 = {
94 raid6_sse21_gen_syndrome,
95 raid6_have_sse2,
96 "sse2x1",
97 1 /* Has cache hints */
98};
99
100/*
101 * Unrolled-by-2 SSE2 implementation
102 */
103static void raid6_sse22_gen_syndrome(int disks, size_t bytes, void **ptrs)
104{
105 u8 **dptr = (u8 **)ptrs;
106 u8 *p, *q;
107 int d, z, z0;
108
109 z0 = disks - 3; /* Highest data disk */
110 p = dptr[z0+1]; /* XOR parity */
111 q = dptr[z0+2]; /* RS syndrome */
112
113 kernel_fpu_begin();
114
115 asm volatile("movdqa %0,%%xmm0" : : "m" (raid6_sse_constants.x1d[0]));
116 asm volatile("pxor %xmm5,%xmm5"); /* Zero temp */
117 asm volatile("pxor %xmm7,%xmm7"); /* Zero temp */
118
119 /* We uniformly assume a single prefetch covers at least 32 bytes */
120 for ( d = 0 ; d < bytes ; d += 32 ) {
121 asm volatile("prefetchnta %0" : : "m" (dptr[z0][d]));
122 asm volatile("movdqa %0,%%xmm2" : : "m" (dptr[z0][d])); /* P[0] */
123 asm volatile("movdqa %0,%%xmm3" : : "m" (dptr[z0][d+16])); /* P[1] */
124 asm volatile("movdqa %xmm2,%xmm4"); /* Q[0] */
125 asm volatile("movdqa %xmm3,%xmm6"); /* Q[1] */
126 for ( z = z0-1 ; z >= 0 ; z-- ) {
127 asm volatile("prefetchnta %0" : : "m" (dptr[z][d]));
128 asm volatile("pcmpgtb %xmm4,%xmm5");
129 asm volatile("pcmpgtb %xmm6,%xmm7");
130 asm volatile("paddb %xmm4,%xmm4");
131 asm volatile("paddb %xmm6,%xmm6");
132 asm volatile("pand %xmm0,%xmm5");
133 asm volatile("pand %xmm0,%xmm7");
134 asm volatile("pxor %xmm5,%xmm4");
135 asm volatile("pxor %xmm7,%xmm6");
136 asm volatile("movdqa %0,%%xmm5" : : "m" (dptr[z][d]));
137 asm volatile("movdqa %0,%%xmm7" : : "m" (dptr[z][d+16]));
138 asm volatile("pxor %xmm5,%xmm2");
139 asm volatile("pxor %xmm7,%xmm3");
140 asm volatile("pxor %xmm5,%xmm4");
141 asm volatile("pxor %xmm7,%xmm6");
142 asm volatile("pxor %xmm5,%xmm5");
143 asm volatile("pxor %xmm7,%xmm7");
144 }
145 asm volatile("movntdq %%xmm2,%0" : "=m" (p[d]));
146 asm volatile("movntdq %%xmm3,%0" : "=m" (p[d+16]));
147 asm volatile("movntdq %%xmm4,%0" : "=m" (q[d]));
148 asm volatile("movntdq %%xmm6,%0" : "=m" (q[d+16]));
149 }
150
151 asm volatile("sfence" : : : "memory");
152 kernel_fpu_end();
153}
154
155const struct raid6_calls raid6_sse2x2 = {
156 raid6_sse22_gen_syndrome,
157 raid6_have_sse2,
158 "sse2x2",
159 1 /* Has cache hints */
160};
161
162#endif
163
164#if defined(__x86_64__) && !defined(__arch_um__)
165
166/*
167 * Unrolled-by-4 SSE2 implementation
168 */
169static void raid6_sse24_gen_syndrome(int disks, size_t bytes, void **ptrs)
170{
171 u8 **dptr = (u8 **)ptrs;
172 u8 *p, *q;
173 int d, z, z0;
174
175 z0 = disks - 3; /* Highest data disk */
176 p = dptr[z0+1]; /* XOR parity */
177 q = dptr[z0+2]; /* RS syndrome */
178
179 kernel_fpu_begin();
180
181 asm volatile("movdqa %0,%%xmm0" :: "m" (raid6_sse_constants.x1d[0]));
182 asm volatile("pxor %xmm2,%xmm2"); /* P[0] */
183 asm volatile("pxor %xmm3,%xmm3"); /* P[1] */
184 asm volatile("pxor %xmm4,%xmm4"); /* Q[0] */
185 asm volatile("pxor %xmm5,%xmm5"); /* Zero temp */
186 asm volatile("pxor %xmm6,%xmm6"); /* Q[1] */
187 asm volatile("pxor %xmm7,%xmm7"); /* Zero temp */
188 asm volatile("pxor %xmm10,%xmm10"); /* P[2] */
189 asm volatile("pxor %xmm11,%xmm11"); /* P[3] */
190 asm volatile("pxor %xmm12,%xmm12"); /* Q[2] */
191 asm volatile("pxor %xmm13,%xmm13"); /* Zero temp */
192 asm volatile("pxor %xmm14,%xmm14"); /* Q[3] */
193 asm volatile("pxor %xmm15,%xmm15"); /* Zero temp */
194
195 for ( d = 0 ; d < bytes ; d += 64 ) {
196 for ( z = z0 ; z >= 0 ; z-- ) {
197 /* The second prefetch seems to improve performance... */
198 asm volatile("prefetchnta %0" :: "m" (dptr[z][d]));
199 asm volatile("prefetchnta %0" :: "m" (dptr[z][d+32]));
200 asm volatile("pcmpgtb %xmm4,%xmm5");
201 asm volatile("pcmpgtb %xmm6,%xmm7");
202 asm volatile("pcmpgtb %xmm12,%xmm13");
203 asm volatile("pcmpgtb %xmm14,%xmm15");
204 asm volatile("paddb %xmm4,%xmm4");
205 asm volatile("paddb %xmm6,%xmm6");
206 asm volatile("paddb %xmm12,%xmm12");
207 asm volatile("paddb %xmm14,%xmm14");
208 asm volatile("pand %xmm0,%xmm5");
209 asm volatile("pand %xmm0,%xmm7");
210 asm volatile("pand %xmm0,%xmm13");
211 asm volatile("pand %xmm0,%xmm15");
212 asm volatile("pxor %xmm5,%xmm4");
213 asm volatile("pxor %xmm7,%xmm6");
214 asm volatile("pxor %xmm13,%xmm12");
215 asm volatile("pxor %xmm15,%xmm14");
216 asm volatile("movdqa %0,%%xmm5" :: "m" (dptr[z][d]));
217 asm volatile("movdqa %0,%%xmm7" :: "m" (dptr[z][d+16]));
218 asm volatile("movdqa %0,%%xmm13" :: "m" (dptr[z][d+32]));
219 asm volatile("movdqa %0,%%xmm15" :: "m" (dptr[z][d+48]));
220 asm volatile("pxor %xmm5,%xmm2");
221 asm volatile("pxor %xmm7,%xmm3");
222 asm volatile("pxor %xmm13,%xmm10");
223 asm volatile("pxor %xmm15,%xmm11");
224 asm volatile("pxor %xmm5,%xmm4");
225 asm volatile("pxor %xmm7,%xmm6");
226 asm volatile("pxor %xmm13,%xmm12");
227 asm volatile("pxor %xmm15,%xmm14");
228 asm volatile("pxor %xmm5,%xmm5");
229 asm volatile("pxor %xmm7,%xmm7");
230 asm volatile("pxor %xmm13,%xmm13");
231 asm volatile("pxor %xmm15,%xmm15");
232 }
233 asm volatile("movntdq %%xmm2,%0" : "=m" (p[d]));
234 asm volatile("pxor %xmm2,%xmm2");
235 asm volatile("movntdq %%xmm3,%0" : "=m" (p[d+16]));
236 asm volatile("pxor %xmm3,%xmm3");
237 asm volatile("movntdq %%xmm10,%0" : "=m" (p[d+32]));
238 asm volatile("pxor %xmm10,%xmm10");
239 asm volatile("movntdq %%xmm11,%0" : "=m" (p[d+48]));
240 asm volatile("pxor %xmm11,%xmm11");
241 asm volatile("movntdq %%xmm4,%0" : "=m" (q[d]));
242 asm volatile("pxor %xmm4,%xmm4");
243 asm volatile("movntdq %%xmm6,%0" : "=m" (q[d+16]));
244 asm volatile("pxor %xmm6,%xmm6");
245 asm volatile("movntdq %%xmm12,%0" : "=m" (q[d+32]));
246 asm volatile("pxor %xmm12,%xmm12");
247 asm volatile("movntdq %%xmm14,%0" : "=m" (q[d+48]));
248 asm volatile("pxor %xmm14,%xmm14");
249 }
250
251 asm volatile("sfence" : : : "memory");
252 kernel_fpu_end();
253}
254
255const struct raid6_calls raid6_sse2x4 = {
256 raid6_sse24_gen_syndrome,
257 raid6_have_sse2,
258 "sse2x4",
259 1 /* Has cache hints */
260};
261
262#endif
diff --git a/drivers/md/raid6test/Makefile b/drivers/md/raid6test/Makefile
deleted file mode 100644
index 2874cbef529d..000000000000
--- a/drivers/md/raid6test/Makefile
+++ /dev/null
@@ -1,75 +0,0 @@
1#
2# This is a simple Makefile to test some of the RAID-6 code
3# from userspace.
4#
5
6CC = gcc
7OPTFLAGS = -O2 # Adjust as desired
8CFLAGS = -I.. -I ../../../include -g $(OPTFLAGS)
9LD = ld
10AWK = awk
11AR = ar
12RANLIB = ranlib
13
14.c.o:
15 $(CC) $(CFLAGS) -c -o $@ $<
16
17%.c: ../%.c
18 cp -f $< $@
19
20%.uc: ../%.uc
21 cp -f $< $@
22
23all: raid6.a raid6test
24
25raid6.a: raid6int1.o raid6int2.o raid6int4.o raid6int8.o raid6int16.o \
26 raid6int32.o \
27 raid6mmx.o raid6sse1.o raid6sse2.o \
28 raid6altivec1.o raid6altivec2.o raid6altivec4.o raid6altivec8.o \
29 raid6recov.o raid6algos.o \
30 raid6tables.o
31 rm -f $@
32 $(AR) cq $@ $^
33 $(RANLIB) $@
34
35raid6test: test.c raid6.a
36 $(CC) $(CFLAGS) -o raid6test $^
37
38raid6altivec1.c: raid6altivec.uc ../unroll.awk
39 $(AWK) ../unroll.awk -vN=1 < raid6altivec.uc > $@
40
41raid6altivec2.c: raid6altivec.uc ../unroll.awk
42 $(AWK) ../unroll.awk -vN=2 < raid6altivec.uc > $@
43
44raid6altivec4.c: raid6altivec.uc ../unroll.awk
45 $(AWK) ../unroll.awk -vN=4 < raid6altivec.uc > $@
46
47raid6altivec8.c: raid6altivec.uc ../unroll.awk
48 $(AWK) ../unroll.awk -vN=8 < raid6altivec.uc > $@
49
50raid6int1.c: raid6int.uc ../unroll.awk
51 $(AWK) ../unroll.awk -vN=1 < raid6int.uc > $@
52
53raid6int2.c: raid6int.uc ../unroll.awk
54 $(AWK) ../unroll.awk -vN=2 < raid6int.uc > $@
55
56raid6int4.c: raid6int.uc ../unroll.awk
57 $(AWK) ../unroll.awk -vN=4 < raid6int.uc > $@
58
59raid6int8.c: raid6int.uc ../unroll.awk
60 $(AWK) ../unroll.awk -vN=8 < raid6int.uc > $@
61
62raid6int16.c: raid6int.uc ../unroll.awk
63 $(AWK) ../unroll.awk -vN=16 < raid6int.uc > $@
64
65raid6int32.c: raid6int.uc ../unroll.awk
66 $(AWK) ../unroll.awk -vN=32 < raid6int.uc > $@
67
68raid6tables.c: mktables
69 ./mktables > raid6tables.c
70
71clean:
72 rm -f *.o *.a mktables mktables.c raid6int.uc raid6*.c raid6test
73
74spotless: clean
75 rm -f *~
diff --git a/drivers/md/raid6test/test.c b/drivers/md/raid6test/test.c
deleted file mode 100644
index 7a930318b17d..000000000000
--- a/drivers/md/raid6test/test.c
+++ /dev/null
@@ -1,124 +0,0 @@
1/* -*- linux-c -*- ------------------------------------------------------- *
2 *
3 * Copyright 2002-2007 H. Peter Anvin - All Rights Reserved
4 *
5 * This file is part of the Linux kernel, and is made available under
6 * the terms of the GNU General Public License version 2 or (at your
7 * option) any later version; incorporated herein by reference.
8 *
9 * ----------------------------------------------------------------------- */
10
11/*
12 * raid6test.c
13 *
14 * Test RAID-6 recovery with various algorithms
15 */
16
17#include <stdlib.h>
18#include <stdio.h>
19#include <string.h>
20#include <linux/raid/pq.h>
21
22#define NDISKS 16 /* Including P and Q */
23
24const char raid6_empty_zero_page[PAGE_SIZE] __attribute__((aligned(256)));
25struct raid6_calls raid6_call;
26
27char *dataptrs[NDISKS];
28char data[NDISKS][PAGE_SIZE];
29char recovi[PAGE_SIZE], recovj[PAGE_SIZE];
30
31static void makedata(void)
32{
33 int i, j;
34
35 for (i = 0; i < NDISKS; i++) {
36 for (j = 0; j < PAGE_SIZE; j++)
37 data[i][j] = rand();
38
39 dataptrs[i] = data[i];
40 }
41}
42
43static char disk_type(int d)
44{
45 switch (d) {
46 case NDISKS-2:
47 return 'P';
48 case NDISKS-1:
49 return 'Q';
50 default:
51 return 'D';
52 }
53}
54
55static int test_disks(int i, int j)
56{
57 int erra, errb;
58
59 memset(recovi, 0xf0, PAGE_SIZE);
60 memset(recovj, 0xba, PAGE_SIZE);
61
62 dataptrs[i] = recovi;
63 dataptrs[j] = recovj;
64
65 raid6_dual_recov(NDISKS, PAGE_SIZE, i, j, (void **)&dataptrs);
66
67 erra = memcmp(data[i], recovi, PAGE_SIZE);
68 errb = memcmp(data[j], recovj, PAGE_SIZE);
69
70 if (i < NDISKS-2 && j == NDISKS-1) {
71 /* We don't implement the DQ failure scenario, since it's
72 equivalent to a RAID-5 failure (XOR, then recompute Q) */
73 erra = errb = 0;
74 } else {
75 printf("algo=%-8s faila=%3d(%c) failb=%3d(%c) %s\n",
76 raid6_call.name,
77 i, disk_type(i),
78 j, disk_type(j),
79 (!erra && !errb) ? "OK" :
80 !erra ? "ERRB" :
81 !errb ? "ERRA" : "ERRAB");
82 }
83
84 dataptrs[i] = data[i];
85 dataptrs[j] = data[j];
86
87 return erra || errb;
88}
89
90int main(int argc, char *argv[])
91{
92 const struct raid6_calls *const *algo;
93 int i, j;
94 int err = 0;
95
96 makedata();
97
98 for (algo = raid6_algos; *algo; algo++) {
99 if (!(*algo)->valid || (*algo)->valid()) {
100 raid6_call = **algo;
101
102 /* Nuke syndromes */
103 memset(data[NDISKS-2], 0xee, 2*PAGE_SIZE);
104
105 /* Generate assumed good syndrome */
106 raid6_call.gen_syndrome(NDISKS, PAGE_SIZE,
107 (void **)&dataptrs);
108
109 for (i = 0; i < NDISKS-1; i++)
110 for (j = i+1; j < NDISKS; j++)
111 err += test_disks(i, j);
112 }
113 printf("\n");
114 }
115
116 printf("\n");
117 /* Pick the best algorithm test */
118 raid6_select_algo();
119
120 if (err)
121 printf("\n*** ERRORS FOUND ***\n");
122
123 return err;
124}
diff --git a/drivers/md/raid6x86.h b/drivers/md/raid6x86.h
deleted file mode 100644
index 4c22c1568558..000000000000
--- a/drivers/md/raid6x86.h
+++ /dev/null
@@ -1,61 +0,0 @@
1/* ----------------------------------------------------------------------- *
2 *
3 * Copyright 2002-2004 H. Peter Anvin - All Rights Reserved
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, Inc., 53 Temple Place Ste 330,
8 * Boston MA 02111-1307, USA; either version 2 of the License, or
9 * (at your option) any later version; incorporated herein by reference.
10 *
11 * ----------------------------------------------------------------------- */
12
13/*
14 * raid6x86.h
15 *
16 * Definitions common to x86 and x86-64 RAID-6 code only
17 */
18
19#ifndef LINUX_RAID_RAID6X86_H
20#define LINUX_RAID_RAID6X86_H
21
22#if (defined(__i386__) || defined(__x86_64__)) && !defined(__arch_um__)
23
24#ifdef __KERNEL__ /* Real code */
25
26#include <asm/i387.h>
27
28#else /* Dummy code for user space testing */
29
30static inline void kernel_fpu_begin(void)
31{
32}
33
34static inline void kernel_fpu_end(void)
35{
36}
37
38#define X86_FEATURE_MMX (0*32+23) /* Multimedia Extensions */
39#define X86_FEATURE_FXSR (0*32+24) /* FXSAVE and FXRSTOR instructions
40 * (fast save and restore) */
41#define X86_FEATURE_XMM (0*32+25) /* Streaming SIMD Extensions */
42#define X86_FEATURE_XMM2 (0*32+26) /* Streaming SIMD Extensions-2 */
43#define X86_FEATURE_MMXEXT (1*32+22) /* AMD MMX extensions */
44
45/* Should work well enough on modern CPUs for testing */
46static inline int boot_cpu_has(int flag)
47{
48 u32 eax = (flag >> 5) ? 0x80000001 : 1;
49 u32 edx;
50
51 asm volatile("cpuid"
52 : "+a" (eax), "=d" (edx)
53 : : "ecx", "ebx");
54
55 return (edx >> (flag & 31)) & 1;
56}
57
58#endif /* ndef __KERNEL__ */
59
60#endif
61#endif
diff --git a/drivers/md/unroll.awk b/drivers/md/unroll.awk
deleted file mode 100644
index c6aa03631df8..000000000000
--- a/drivers/md/unroll.awk
+++ /dev/null
@@ -1,20 +0,0 @@
1
2# This filter requires one command line option of form -vN=n
3# where n must be a decimal number.
4#
5# Repeat each input line containing $$ n times, replacing $$ with 0...n-1.
6# Replace each $# with n, and each $* with a single $.
7
8BEGIN {
9 n = N + 0
10}
11{
12 if (/\$\$/) { rep = n } else { rep = 1 }
13 for (i = 0; i < rep; ++i) {
14 tmp = $0
15 gsub(/\$\$/, i, tmp)
16 gsub(/\$\#/, n, tmp)
17 gsub(/\$\*/, "$", tmp)
18 print tmp
19 }
20}
diff --git a/drivers/media/IR/Kconfig b/drivers/media/IR/Kconfig
index 999a8250b3ce..490c57cc4cfe 100644
--- a/drivers/media/IR/Kconfig
+++ b/drivers/media/IR/Kconfig
@@ -1,13 +1,22 @@
1config IR_CORE 1menuconfig IR_CORE
2 tristate 2 tristate "Infrared remote controller adapters"
3 depends on INPUT 3 depends on INPUT
4 default INPUT 4 default INPUT
5 ---help---
6 Enable support for Remote Controllers on Linux. This is
7 needed in order to support several video capture adapters.
8
9 Enable this option if you have a video capture board even
10 if you don't need IR, as otherwise, you may not be able to
11 compile the driver for your adapter.
5 12
6config VIDEO_IR 13config VIDEO_IR
7 tristate 14 tristate
8 depends on IR_CORE 15 depends on IR_CORE
9 default IR_CORE 16 default IR_CORE
10 17
18if IR_CORE
19
11config LIRC 20config LIRC
12 tristate 21 tristate
13 default y 22 default y
@@ -16,7 +25,7 @@ config LIRC
16 Enable this option to build the Linux Infrared Remote 25 Enable this option to build the Linux Infrared Remote
17 Control (LIRC) core device interface driver. The LIRC 26 Control (LIRC) core device interface driver. The LIRC
18 interface passes raw IR to and from userspace, where the 27 interface passes raw IR to and from userspace, where the
19 LIRC daemon handles protocol decoding for IR reception ann 28 LIRC daemon handles protocol decoding for IR reception and
20 encoding for IR transmitting (aka "blasting"). 29 encoding for IR transmitting (aka "blasting").
21 30
22source "drivers/media/IR/keymaps/Kconfig" 31source "drivers/media/IR/keymaps/Kconfig"
@@ -103,3 +112,31 @@ config IR_MCEUSB
103 112
104 To compile this driver as a module, choose M here: the 113 To compile this driver as a module, choose M here: the
105 module will be called mceusb. 114 module will be called mceusb.
115
116config IR_ENE
117 tristate "ENE eHome Receiver/Transciever (pnp id: ENE0100/ENE02xxx)"
118 depends on PNP
119 depends on IR_CORE
120 ---help---
121 Say Y here to enable support for integrated infrared receiver
122 /transciever made by ENE.
123
124 You can see if you have it by looking at lspnp output.
125 Output should include ENE0100 ENE0200 or something similiar.
126
127 To compile this driver as a module, choose M here: the
128 module will be called ene_ir.
129
130config IR_STREAMZAP
131 tristate "Streamzap PC Remote IR Receiver"
132 depends on USB_ARCH_HAS_HCD
133 depends on IR_CORE
134 select USB
135 ---help---
136 Say Y here if you want to use a Streamzap PC Remote
137 Infrared Receiver.
138
139 To compile this driver as a module, choose M here: the
140 module will be called streamzap.
141
142endif #IR_CORE
diff --git a/drivers/media/IR/Makefile b/drivers/media/IR/Makefile
index 2ae4f3abfdbd..53676838fe97 100644
--- a/drivers/media/IR/Makefile
+++ b/drivers/media/IR/Makefile
@@ -16,3 +16,5 @@ obj-$(CONFIG_IR_LIRC_CODEC) += ir-lirc-codec.o
16# stand-alone IR receivers/transmitters 16# stand-alone IR receivers/transmitters
17obj-$(CONFIG_IR_IMON) += imon.o 17obj-$(CONFIG_IR_IMON) += imon.o
18obj-$(CONFIG_IR_MCEUSB) += mceusb.o 18obj-$(CONFIG_IR_MCEUSB) += mceusb.o
19obj-$(CONFIG_IR_ENE) += ene_ir.o
20obj-$(CONFIG_IR_STREAMZAP) += streamzap.o
diff --git a/drivers/media/IR/ene_ir.c b/drivers/media/IR/ene_ir.c
new file mode 100644
index 000000000000..5447750f5e38
--- /dev/null
+++ b/drivers/media/IR/ene_ir.c
@@ -0,0 +1,1023 @@
1/*
2 * driver for ENE KB3926 B/C/D CIR (pnp id: ENE0XXX)
3 *
4 * Copyright (C) 2010 Maxim Levitsky <maximlevitsky@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 * USA
20 */
21
22#include <linux/kernel.h>
23#include <linux/module.h>
24#include <linux/pnp.h>
25#include <linux/io.h>
26#include <linux/interrupt.h>
27#include <linux/sched.h>
28#include <linux/slab.h>
29#include <linux/input.h>
30#include <media/ir-core.h>
31#include <media/ir-common.h>
32#include "ene_ir.h"
33
34
35static int sample_period = -1;
36static int enable_idle = 1;
37static int input = 1;
38static int debug;
39static int txsim;
40
41static int ene_irq_status(struct ene_device *dev);
42
43/* read a hardware register */
44static u8 ene_hw_read_reg(struct ene_device *dev, u16 reg)
45{
46 u8 retval;
47 outb(reg >> 8, dev->hw_io + ENE_ADDR_HI);
48 outb(reg & 0xFF, dev->hw_io + ENE_ADDR_LO);
49 retval = inb(dev->hw_io + ENE_IO);
50
51 ene_dbg_verbose("reg %04x == %02x", reg, retval);
52 return retval;
53}
54
55/* write a hardware register */
56static void ene_hw_write_reg(struct ene_device *dev, u16 reg, u8 value)
57{
58 outb(reg >> 8, dev->hw_io + ENE_ADDR_HI);
59 outb(reg & 0xFF, dev->hw_io + ENE_ADDR_LO);
60 outb(value, dev->hw_io + ENE_IO);
61
62 ene_dbg_verbose("reg %04x <- %02x", reg, value);
63}
64
65/* change specific bits in hardware register */
66static void ene_hw_write_reg_mask(struct ene_device *dev,
67 u16 reg, u8 value, u8 mask)
68{
69 u8 regvalue;
70
71 outb(reg >> 8, dev->hw_io + ENE_ADDR_HI);
72 outb(reg & 0xFF, dev->hw_io + ENE_ADDR_LO);
73
74 regvalue = inb(dev->hw_io + ENE_IO) & ~mask;
75 regvalue |= (value & mask);
76 outb(regvalue, dev->hw_io + ENE_IO);
77
78 ene_dbg_verbose("reg %04x <- %02x (mask=%02x)", reg, value, mask);
79}
80
81/* detect hardware features */
82static int ene_hw_detect(struct ene_device *dev)
83{
84 u8 chip_major, chip_minor;
85 u8 hw_revision, old_ver;
86 u8 tmp;
87 u8 fw_capabilities;
88 int pll_freq;
89
90 tmp = ene_hw_read_reg(dev, ENE_HW_UNK);
91 ene_hw_write_reg(dev, ENE_HW_UNK, tmp & ~ENE_HW_UNK_CLR);
92
93 chip_major = ene_hw_read_reg(dev, ENE_HW_VER_MAJOR);
94 chip_minor = ene_hw_read_reg(dev, ENE_HW_VER_MINOR);
95
96 ene_hw_write_reg(dev, ENE_HW_UNK, tmp);
97 hw_revision = ene_hw_read_reg(dev, ENE_HW_VERSION);
98 old_ver = ene_hw_read_reg(dev, ENE_HW_VER_OLD);
99
100 pll_freq = (ene_hw_read_reg(dev, ENE_PLLFRH) << 4) +
101 (ene_hw_read_reg(dev, ENE_PLLFRL) >> 4);
102
103 if (pll_freq != 1000)
104 dev->rx_period_adjust = 4;
105 else
106 dev->rx_period_adjust = 2;
107
108
109 ene_printk(KERN_NOTICE, "PLL freq = %d\n", pll_freq);
110
111 if (hw_revision == 0xFF) {
112
113 ene_printk(KERN_WARNING, "device seems to be disabled\n");
114 ene_printk(KERN_WARNING,
115 "send a mail to lirc-list@lists.sourceforge.net\n");
116 ene_printk(KERN_WARNING, "please attach output of acpidump\n");
117 return -ENODEV;
118 }
119
120 if (chip_major == 0x33) {
121 ene_printk(KERN_WARNING, "chips 0x33xx aren't supported\n");
122 return -ENODEV;
123 }
124
125 if (chip_major == 0x39 && chip_minor == 0x26 && hw_revision == 0xC0) {
126 dev->hw_revision = ENE_HW_C;
127 } else if (old_ver == 0x24 && hw_revision == 0xC0) {
128 dev->hw_revision = ENE_HW_B;
129 ene_printk(KERN_NOTICE, "KB3926B detected\n");
130 } else {
131 dev->hw_revision = ENE_HW_D;
132 ene_printk(KERN_WARNING,
133 "unknown ENE chip detected, assuming KB3926D\n");
134 ene_printk(KERN_WARNING,
135 "driver support might be not complete");
136
137 }
138
139 ene_printk(KERN_DEBUG,
140 "chip is 0x%02x%02x - kbver = 0x%02x, rev = 0x%02x\n",
141 chip_major, chip_minor, old_ver, hw_revision);
142
143 /* detect features hardware supports */
144 if (dev->hw_revision < ENE_HW_C)
145 return 0;
146
147 fw_capabilities = ene_hw_read_reg(dev, ENE_FW2);
148 ene_dbg("Firmware capabilities: %02x", fw_capabilities);
149
150 dev->hw_gpio40_learning = fw_capabilities & ENE_FW2_GP40_AS_LEARN;
151 dev->hw_learning_and_tx_capable = fw_capabilities & ENE_FW2_LEARNING;
152
153 dev->hw_fan_as_normal_input = dev->hw_learning_and_tx_capable &&
154 (fw_capabilities & ENE_FW2_FAN_AS_NRML_IN);
155
156 ene_printk(KERN_NOTICE, "hardware features:\n");
157 ene_printk(KERN_NOTICE,
158 "learning and transmit %s, gpio40_learn %s, fan_in %s\n",
159 dev->hw_learning_and_tx_capable ? "on" : "off",
160 dev->hw_gpio40_learning ? "on" : "off",
161 dev->hw_fan_as_normal_input ? "on" : "off");
162
163 if (dev->hw_learning_and_tx_capable) {
164 ene_printk(KERN_WARNING,
165 "Device supports transmitting, but that support is\n");
166 ene_printk(KERN_WARNING,
167 "lightly tested. Please test it and mail\n");
168 ene_printk(KERN_WARNING,
169 "lirc-list@lists.sourceforge.net\n");
170 }
171 return 0;
172}
173
174/* this enables/disables IR input via gpio40*/
175static void ene_enable_gpio40_receive(struct ene_device *dev, int enable)
176{
177 ene_hw_write_reg_mask(dev, ENE_CIR_CONF2, enable ?
178 0 : ENE_CIR_CONF2_GPIO40DIS,
179 ENE_CIR_CONF2_GPIO40DIS);
180}
181
182/* this enables/disables IR via standard input */
183static void ene_enable_normal_receive(struct ene_device *dev, int enable)
184{
185 ene_hw_write_reg(dev, ENE_CIR_CONF1, enable ? ENE_CIR_CONF1_RX_ON : 0);
186}
187
188/* this enables/disables IR input via unused fan tachtometer input */
189static void ene_enable_fan_receive(struct ene_device *dev, int enable)
190{
191 if (!enable)
192 ene_hw_write_reg(dev, ENE_FAN_AS_IN1, 0);
193 else {
194 ene_hw_write_reg(dev, ENE_FAN_AS_IN1, ENE_FAN_AS_IN1_EN);
195 ene_hw_write_reg(dev, ENE_FAN_AS_IN2, ENE_FAN_AS_IN2_EN);
196 }
197 dev->rx_fan_input_inuse = enable;
198}
199
200
201/* Sense current received carrier */
202static int ene_rx_sense_carrier(struct ene_device *dev)
203{
204 int period = ene_hw_read_reg(dev, ENE_RX_CARRIER);
205 int carrier;
206 ene_dbg("RX: hardware carrier period = %02x", period);
207
208 if (!(period & ENE_RX_CARRIER_VALID))
209 return 0;
210
211 period &= ~ENE_RX_CARRIER_VALID;
212
213 if (!period)
214 return 0;
215
216 carrier = 2000000 / period;
217 ene_dbg("RX: sensed carrier = %d Hz", carrier);
218 return carrier;
219}
220
221/* determine which input to use*/
222static void ene_rx_set_inputs(struct ene_device *dev)
223{
224 int learning_mode = dev->learning_enabled;
225
226 ene_dbg("RX: setup receiver, learning mode = %d", learning_mode);
227
228 ene_enable_normal_receive(dev, 1);
229
230 /* old hardware doesn't support learning mode for sure */
231 if (dev->hw_revision <= ENE_HW_B)
232 return;
233
234 /* receiver not learning capable, still set gpio40 correctly */
235 if (!dev->hw_learning_and_tx_capable) {
236 ene_enable_gpio40_receive(dev, !dev->hw_gpio40_learning);
237 return;
238 }
239
240 /* enable learning mode */
241 if (learning_mode) {
242 ene_enable_gpio40_receive(dev, dev->hw_gpio40_learning);
243
244 /* fan input is not used for learning */
245 if (dev->hw_fan_as_normal_input)
246 ene_enable_fan_receive(dev, 0);
247
248 /* disable learning mode */
249 } else {
250 if (dev->hw_fan_as_normal_input) {
251 ene_enable_fan_receive(dev, 1);
252 ene_enable_normal_receive(dev, 0);
253 } else
254 ene_enable_gpio40_receive(dev,
255 !dev->hw_gpio40_learning);
256 }
257
258 /* set few additional settings for this mode */
259 ene_hw_write_reg_mask(dev, ENE_CIR_CONF1, learning_mode ?
260 ENE_CIR_CONF1_LEARN1 : 0, ENE_CIR_CONF1_LEARN1);
261
262 ene_hw_write_reg_mask(dev, ENE_CIR_CONF2, learning_mode ?
263 ENE_CIR_CONF2_LEARN2 : 0, ENE_CIR_CONF2_LEARN2);
264
265 if (dev->rx_fan_input_inuse) {
266 dev->props->rx_resolution = ENE_SAMPLE_PERIOD_FAN * 1000;
267
268 dev->props->timeout =
269 ENE_FAN_VALUE_MASK * ENE_SAMPLE_PERIOD_FAN * 1000;
270 } else {
271 dev->props->rx_resolution = sample_period * 1000;
272 dev->props->timeout = ENE_MAXGAP * 1000;
273 }
274}
275
276/* Enable the device for receive */
277static void ene_rx_enable(struct ene_device *dev)
278{
279 u8 reg_value;
280
281 if (dev->hw_revision < ENE_HW_C) {
282 ene_hw_write_reg(dev, ENEB_IRQ, dev->irq << 1);
283 ene_hw_write_reg(dev, ENEB_IRQ_UNK1, 0x01);
284 } else {
285 reg_value = ene_hw_read_reg(dev, ENEC_IRQ) & 0xF0;
286 reg_value |= ENEC_IRQ_UNK_EN;
287 reg_value &= ~ENEC_IRQ_STATUS;
288 reg_value |= (dev->irq & ENEC_IRQ_MASK);
289 ene_hw_write_reg(dev, ENEC_IRQ, reg_value);
290 ene_hw_write_reg(dev, ENE_TX_UNK1, 0x63);
291 }
292
293 ene_hw_write_reg(dev, ENE_CIR_CONF2, 0x00);
294 ene_rx_set_inputs(dev);
295
296 /* set sampling period */
297 ene_hw_write_reg(dev, ENE_CIR_SAMPLE_PERIOD, sample_period);
298
299 /* ack any pending irqs - just in case */
300 ene_irq_status(dev);
301
302 /* enable firmware bits */
303 ene_hw_write_reg_mask(dev, ENE_FW1,
304 ENE_FW1_ENABLE | ENE_FW1_IRQ,
305 ENE_FW1_ENABLE | ENE_FW1_IRQ);
306
307 /* enter idle mode */
308 ir_raw_event_set_idle(dev->idev, 1);
309 ir_raw_event_reset(dev->idev);
310
311}
312
313/* Disable the device receiver */
314static void ene_rx_disable(struct ene_device *dev)
315{
316 /* disable inputs */
317 ene_enable_normal_receive(dev, 0);
318
319 if (dev->hw_fan_as_normal_input)
320 ene_enable_fan_receive(dev, 0);
321
322 /* disable hardware IRQ and firmware flag */
323 ene_hw_write_reg_mask(dev, ENE_FW1, 0, ENE_FW1_ENABLE | ENE_FW1_IRQ);
324
325 ir_raw_event_set_idle(dev->idev, 1);
326 ir_raw_event_reset(dev->idev);
327}
328
329
330/* prepare transmission */
331static void ene_tx_prepare(struct ene_device *dev)
332{
333 u8 conf1;
334
335 conf1 = ene_hw_read_reg(dev, ENE_CIR_CONF1);
336 dev->saved_conf1 = conf1;
337
338 if (dev->hw_revision == ENE_HW_C)
339 conf1 &= ~ENE_CIR_CONF1_TX_CLEAR;
340
341 /* Enable TX engine */
342 conf1 |= ENE_CIR_CONF1_TX_ON;
343
344 /* Set carrier */
345 if (dev->tx_period) {
346
347 /* NOTE: duty cycle handling is just a guess, it might
348 not be aviable. Default values were tested */
349 int tx_period_in500ns = dev->tx_period * 2;
350
351 int tx_pulse_width_in_500ns =
352 tx_period_in500ns / (100 / dev->tx_duty_cycle);
353
354 if (!tx_pulse_width_in_500ns)
355 tx_pulse_width_in_500ns = 1;
356
357 ene_dbg("TX: pulse distance = %d * 500 ns", tx_period_in500ns);
358 ene_dbg("TX: pulse width = %d * 500 ns",
359 tx_pulse_width_in_500ns);
360
361 ene_hw_write_reg(dev, ENE_TX_PERIOD, ENE_TX_PERIOD_UNKBIT |
362 tx_period_in500ns);
363
364 ene_hw_write_reg(dev, ENE_TX_PERIOD_PULSE,
365 tx_pulse_width_in_500ns);
366
367 conf1 |= ENE_CIR_CONF1_TX_CARR;
368 } else
369 conf1 &= ~ENE_CIR_CONF1_TX_CARR;
370
371 ene_hw_write_reg(dev, ENE_CIR_CONF1, conf1);
372
373}
374
375/* end transmission */
376static void ene_tx_complete(struct ene_device *dev)
377{
378 ene_hw_write_reg(dev, ENE_CIR_CONF1, dev->saved_conf1);
379 dev->tx_buffer = NULL;
380}
381
382/* set transmit mask */
383static void ene_tx_hw_set_transmiter_mask(struct ene_device *dev)
384{
385 u8 txport1 = ene_hw_read_reg(dev, ENE_TX_PORT1) & ~ENE_TX_PORT1_EN;
386 u8 txport2 = ene_hw_read_reg(dev, ENE_TX_PORT2) & ~ENE_TX_PORT2_EN;
387
388 if (dev->transmitter_mask & 0x01)
389 txport1 |= ENE_TX_PORT1_EN;
390
391 if (dev->transmitter_mask & 0x02)
392 txport2 |= ENE_TX_PORT2_EN;
393
394 ene_hw_write_reg(dev, ENE_TX_PORT1, txport1);
395 ene_hw_write_reg(dev, ENE_TX_PORT2, txport2);
396}
397
398/* TX one sample - must be called with dev->hw_lock*/
399static void ene_tx_sample(struct ene_device *dev)
400{
401 u8 raw_tx;
402 u32 sample;
403
404 if (!dev->tx_buffer) {
405 ene_dbg("TX: attempt to transmit NULL buffer");
406 return;
407 }
408
409 /* Grab next TX sample */
410 if (!dev->tx_sample) {
411again:
412 if (dev->tx_pos == dev->tx_len + 1) {
413 if (!dev->tx_done) {
414 ene_dbg("TX: no more data to send");
415 dev->tx_done = 1;
416 goto exit;
417 } else {
418 ene_dbg("TX: last sample sent by hardware");
419 ene_tx_complete(dev);
420 complete(&dev->tx_complete);
421 return;
422 }
423 }
424
425 sample = dev->tx_buffer[dev->tx_pos++];
426 dev->tx_sample_pulse = !dev->tx_sample_pulse;
427
428 ene_dbg("TX: sample %8d (%s)", sample, dev->tx_sample_pulse ?
429 "pulse" : "space");
430
431 dev->tx_sample = DIV_ROUND_CLOSEST(sample, ENE_TX_SMPL_PERIOD);
432
433 /* guard against too short samples */
434 if (!dev->tx_sample)
435 goto again;
436 }
437
438 raw_tx = min(dev->tx_sample , (unsigned int)ENE_TX_SMLP_MASK);
439 dev->tx_sample -= raw_tx;
440
441 if (dev->tx_sample_pulse)
442 raw_tx |= ENE_TX_PULSE_MASK;
443
444 ene_hw_write_reg(dev, ENE_TX_INPUT1 + dev->tx_reg, raw_tx);
445 dev->tx_reg = !dev->tx_reg;
446exit:
447 /* simulate TX done interrupt */
448 if (txsim)
449 mod_timer(&dev->tx_sim_timer, jiffies + HZ / 500);
450}
451
452/* timer to simulate tx done interrupt */
453static void ene_tx_irqsim(unsigned long data)
454{
455 struct ene_device *dev = (struct ene_device *)data;
456 unsigned long flags;
457
458 spin_lock_irqsave(&dev->hw_lock, flags);
459 ene_tx_sample(dev);
460 spin_unlock_irqrestore(&dev->hw_lock, flags);
461}
462
463
464/* read irq status and ack it */
465static int ene_irq_status(struct ene_device *dev)
466{
467 u8 irq_status;
468 u8 fw_flags1, fw_flags2;
469 int cur_rx_pointer;
470 int retval = 0;
471
472 fw_flags2 = ene_hw_read_reg(dev, ENE_FW2);
473 cur_rx_pointer = !!(fw_flags2 & ENE_FW2_BUF_HIGH);
474
475 if (dev->hw_revision < ENE_HW_C) {
476 irq_status = ene_hw_read_reg(dev, ENEB_IRQ_STATUS);
477
478 if (!(irq_status & ENEB_IRQ_STATUS_IR))
479 return 0;
480
481 ene_hw_write_reg(dev, ENEB_IRQ_STATUS,
482 irq_status & ~ENEB_IRQ_STATUS_IR);
483 dev->rx_pointer = cur_rx_pointer;
484 return ENE_IRQ_RX;
485 }
486
487 irq_status = ene_hw_read_reg(dev, ENEC_IRQ);
488
489 if (!(irq_status & ENEC_IRQ_STATUS))
490 return 0;
491
492 /* original driver does that twice - a workaround ? */
493 ene_hw_write_reg(dev, ENEC_IRQ, irq_status & ~ENEC_IRQ_STATUS);
494 ene_hw_write_reg(dev, ENEC_IRQ, irq_status & ~ENEC_IRQ_STATUS);
495
496 /* clear unknown flag in F8F9 */
497 if (fw_flags2 & ENE_FW2_IRQ_CLR)
498 ene_hw_write_reg(dev, ENE_FW2, fw_flags2 & ~ENE_FW2_IRQ_CLR);
499
500 /* check if this is a TX interrupt */
501 fw_flags1 = ene_hw_read_reg(dev, ENE_FW1);
502 if (fw_flags1 & ENE_FW1_TXIRQ) {
503 ene_hw_write_reg(dev, ENE_FW1, fw_flags1 & ~ENE_FW1_TXIRQ);
504 retval |= ENE_IRQ_TX;
505 }
506
507 /* Check if this is RX interrupt */
508 if (dev->rx_pointer != cur_rx_pointer) {
509 retval |= ENE_IRQ_RX;
510 dev->rx_pointer = cur_rx_pointer;
511
512 } else if (!(retval & ENE_IRQ_TX)) {
513 ene_dbg("RX: interrupt without change in RX pointer(%d)",
514 dev->rx_pointer);
515 retval |= ENE_IRQ_RX;
516 }
517
518 if ((retval & ENE_IRQ_RX) && (retval & ENE_IRQ_TX))
519 ene_dbg("both RX and TX interrupt at same time");
520
521 return retval;
522}
523
524/* interrupt handler */
525static irqreturn_t ene_isr(int irq, void *data)
526{
527 u16 hw_value;
528 int i, hw_sample;
529 int pulse;
530 int irq_status;
531 unsigned long flags;
532 int carrier = 0;
533 irqreturn_t retval = IRQ_NONE;
534 struct ene_device *dev = (struct ene_device *)data;
535 struct ir_raw_event ev;
536
537
538 spin_lock_irqsave(&dev->hw_lock, flags);
539 irq_status = ene_irq_status(dev);
540
541 if (!irq_status)
542 goto unlock;
543
544 retval = IRQ_HANDLED;
545
546 if (irq_status & ENE_IRQ_TX) {
547
548 if (!dev->hw_learning_and_tx_capable) {
549 ene_dbg("TX interrupt on unsupported device!");
550 goto unlock;
551 }
552 ene_tx_sample(dev);
553 }
554
555 if (!(irq_status & ENE_IRQ_RX))
556 goto unlock;
557
558
559 if (dev->carrier_detect_enabled || debug)
560 carrier = ene_rx_sense_carrier(dev);
561#if 0
562 /* TODO */
563 if (dev->carrier_detect_enabled && carrier)
564 ir_raw_event_report_frequency(dev->idev, carrier);
565#endif
566
567 for (i = 0; i < ENE_SAMPLES_SIZE; i++) {
568 hw_value = ene_hw_read_reg(dev,
569 ENE_SAMPLE_BUFFER + dev->rx_pointer * 4 + i);
570
571 if (dev->rx_fan_input_inuse) {
572 /* read high part of the sample */
573 hw_value |= ene_hw_read_reg(dev,
574 ENE_SAMPLE_BUFFER_FAN +
575 dev->rx_pointer * 4 + i) << 8;
576 pulse = hw_value & ENE_FAN_SMPL_PULS_MSK;
577
578 /* clear space bit, and other unused bits */
579 hw_value &= ENE_FAN_VALUE_MASK;
580 hw_sample = hw_value * ENE_SAMPLE_PERIOD_FAN;
581
582 } else {
583 pulse = !(hw_value & ENE_SAMPLE_SPC_MASK);
584 hw_value &= ENE_SAMPLE_VALUE_MASK;
585 hw_sample = hw_value * sample_period;
586
587 if (dev->rx_period_adjust) {
588 hw_sample *= (100 - dev->rx_period_adjust);
589 hw_sample /= 100;
590 }
591 }
592 /* no more data */
593 if (!(hw_value))
594 break;
595
596 ene_dbg("RX: %d (%s)", hw_sample, pulse ? "pulse" : "space");
597
598
599 ev.duration = hw_sample * 1000;
600 ev.pulse = pulse;
601 ir_raw_event_store_with_filter(dev->idev, &ev);
602 }
603
604 ir_raw_event_handle(dev->idev);
605unlock:
606 spin_unlock_irqrestore(&dev->hw_lock, flags);
607 return retval;
608}
609
610/* Initialize default settings */
611static void ene_setup_settings(struct ene_device *dev)
612{
613 dev->tx_period = 32;
614 dev->tx_duty_cycle = 25; /*%*/
615 dev->transmitter_mask = 3;
616
617 /* Force learning mode if (input == 2), otherwise
618 let user set it with LIRC_SET_REC_CARRIER */
619 dev->learning_enabled =
620 (input == 2 && dev->hw_learning_and_tx_capable);
621
622 dev->rx_pointer = -1;
623
624}
625
626/* outside interface: called on first open*/
627static int ene_open(void *data)
628{
629 struct ene_device *dev = (struct ene_device *)data;
630 unsigned long flags;
631
632 spin_lock_irqsave(&dev->hw_lock, flags);
633 dev->in_use = 1;
634 ene_setup_settings(dev);
635 ene_rx_enable(dev);
636 spin_unlock_irqrestore(&dev->hw_lock, flags);
637 return 0;
638}
639
640/* outside interface: called on device close*/
641static void ene_close(void *data)
642{
643 struct ene_device *dev = (struct ene_device *)data;
644 unsigned long flags;
645 spin_lock_irqsave(&dev->hw_lock, flags);
646
647 ene_rx_disable(dev);
648 dev->in_use = 0;
649 spin_unlock_irqrestore(&dev->hw_lock, flags);
650}
651
652/* outside interface: set transmitter mask */
653static int ene_set_tx_mask(void *data, u32 tx_mask)
654{
655 struct ene_device *dev = (struct ene_device *)data;
656 unsigned long flags;
657 ene_dbg("TX: attempt to set transmitter mask %02x", tx_mask);
658
659 /* invalid txmask */
660 if (!tx_mask || tx_mask & ~0x3) {
661 ene_dbg("TX: invalid mask");
662 /* return count of transmitters */
663 return 2;
664 }
665
666 spin_lock_irqsave(&dev->hw_lock, flags);
667 dev->transmitter_mask = tx_mask;
668 spin_unlock_irqrestore(&dev->hw_lock, flags);
669 return 0;
670}
671
672/* outside interface : set tx carrier */
673static int ene_set_tx_carrier(void *data, u32 carrier)
674{
675 struct ene_device *dev = (struct ene_device *)data;
676 unsigned long flags;
677 u32 period = 1000000 / carrier; /* (1 / freq) (* # usec in 1 sec) */
678
679 ene_dbg("TX: attempt to set tx carrier to %d kHz", carrier);
680
681 if (period && (period > ENE_TX_PERIOD_MAX ||
682 period < ENE_TX_PERIOD_MIN)) {
683
684 ene_dbg("TX: out of range %d-%d carrier, "
685 "falling back to 32 kHz",
686 1000 / ENE_TX_PERIOD_MIN,
687 1000 / ENE_TX_PERIOD_MAX);
688
689 period = 32; /* this is just a coincidence!!! */
690 }
691 ene_dbg("TX: set carrier to %d kHz", carrier);
692
693 spin_lock_irqsave(&dev->hw_lock, flags);
694 dev->tx_period = period;
695 spin_unlock_irqrestore(&dev->hw_lock, flags);
696 return 0;
697}
698
699
700/* outside interface: enable learning mode */
701static int ene_set_learning_mode(void *data, int enable)
702{
703 struct ene_device *dev = (struct ene_device *)data;
704 unsigned long flags;
705 if (enable == dev->learning_enabled)
706 return 0;
707
708 spin_lock_irqsave(&dev->hw_lock, flags);
709 dev->learning_enabled = enable;
710 ene_rx_set_inputs(dev);
711 spin_unlock_irqrestore(&dev->hw_lock, flags);
712 return 0;
713}
714
715/* outside interface: set rec carrier */
716static int ene_set_rec_carrier(void *data, u32 min, u32 max)
717{
718 struct ene_device *dev = (struct ene_device *)data;
719 ene_set_learning_mode(dev,
720 max > ENE_NORMAL_RX_HI || min < ENE_NORMAL_RX_LOW);
721 return 0;
722}
723
724/* outside interface: enable or disable idle mode */
725static void ene_rx_set_idle(void *data, int idle)
726{
727 struct ene_device *dev = (struct ene_device *)data;
728 ene_dbg("%sabling idle mode", idle ? "en" : "dis");
729
730 ene_hw_write_reg_mask(dev, ENE_CIR_SAMPLE_PERIOD,
731 (enable_idle && idle) ? 0 : ENE_CIR_SAMPLE_OVERFLOW,
732 ENE_CIR_SAMPLE_OVERFLOW);
733}
734
735
736/* outside interface: transmit */
737static int ene_transmit(void *data, int *buf, u32 n)
738{
739 struct ene_device *dev = (struct ene_device *)data;
740 unsigned long flags;
741
742 dev->tx_buffer = buf;
743 dev->tx_len = n / sizeof(int);
744 dev->tx_pos = 0;
745 dev->tx_reg = 0;
746 dev->tx_done = 0;
747 dev->tx_sample = 0;
748 dev->tx_sample_pulse = 0;
749
750 ene_dbg("TX: %d samples", dev->tx_len);
751
752 spin_lock_irqsave(&dev->hw_lock, flags);
753
754 ene_tx_hw_set_transmiter_mask(dev);
755 ene_tx_prepare(dev);
756
757 /* Transmit first two samples */
758 ene_tx_sample(dev);
759 ene_tx_sample(dev);
760
761 spin_unlock_irqrestore(&dev->hw_lock, flags);
762
763 if (wait_for_completion_timeout(&dev->tx_complete, 2 * HZ) == 0) {
764 ene_dbg("TX: timeout");
765 spin_lock_irqsave(&dev->hw_lock, flags);
766 ene_tx_complete(dev);
767 spin_unlock_irqrestore(&dev->hw_lock, flags);
768 } else
769 ene_dbg("TX: done");
770 return n;
771}
772
773
774/* probe entry */
775static int ene_probe(struct pnp_dev *pnp_dev, const struct pnp_device_id *id)
776{
777 int error = -ENOMEM;
778 struct ir_dev_props *ir_props;
779 struct input_dev *input_dev;
780 struct ene_device *dev;
781
782 /* allocate memory */
783 input_dev = input_allocate_device();
784 ir_props = kzalloc(sizeof(struct ir_dev_props), GFP_KERNEL);
785 dev = kzalloc(sizeof(struct ene_device), GFP_KERNEL);
786
787 if (!input_dev || !ir_props || !dev)
788 goto error;
789
790 /* validate resources */
791 error = -ENODEV;
792
793 if (!pnp_port_valid(pnp_dev, 0) ||
794 pnp_port_len(pnp_dev, 0) < ENE_MAX_IO)
795 goto error;
796
797 if (!pnp_irq_valid(pnp_dev, 0))
798 goto error;
799
800 dev->hw_io = pnp_port_start(pnp_dev, 0);
801 dev->irq = pnp_irq(pnp_dev, 0);
802 spin_lock_init(&dev->hw_lock);
803
804 /* claim the resources */
805 error = -EBUSY;
806 if (!request_region(dev->hw_io, ENE_MAX_IO, ENE_DRIVER_NAME))
807 goto error;
808
809 if (request_irq(dev->irq, ene_isr,
810 IRQF_SHARED, ENE_DRIVER_NAME, (void *)dev))
811 goto error;
812
813 pnp_set_drvdata(pnp_dev, dev);
814 dev->pnp_dev = pnp_dev;
815
816 /* detect hardware version and features */
817 error = ene_hw_detect(dev);
818 if (error)
819 goto error;
820
821 ene_setup_settings(dev);
822
823 if (!dev->hw_learning_and_tx_capable && txsim) {
824 dev->hw_learning_and_tx_capable = 1;
825 setup_timer(&dev->tx_sim_timer, ene_tx_irqsim,
826 (long unsigned int)dev);
827 ene_printk(KERN_WARNING,
828 "Simulation of TX activated\n");
829 }
830
831 ir_props->driver_type = RC_DRIVER_IR_RAW;
832 ir_props->allowed_protos = IR_TYPE_ALL;
833 ir_props->priv = dev;
834 ir_props->open = ene_open;
835 ir_props->close = ene_close;
836 ir_props->min_timeout = ENE_MINGAP * 1000;
837 ir_props->max_timeout = ENE_MAXGAP * 1000;
838 ir_props->timeout = ENE_MAXGAP * 1000;
839
840 if (dev->hw_revision == ENE_HW_B)
841 ir_props->s_idle = ene_rx_set_idle;
842
843
844 dev->props = ir_props;
845 dev->idev = input_dev;
846
847 /* don't allow too short/long sample periods */
848 if (sample_period < 5 || sample_period > 0x7F)
849 sample_period = -1;
850
851 /* choose default sample period */
852 if (sample_period == -1) {
853
854 sample_period = 50;
855
856 /* on revB, hardware idle mode eats first sample
857 if we set too low sample period */
858 if (dev->hw_revision == ENE_HW_B && enable_idle)
859 sample_period = 75;
860 }
861
862 ir_props->rx_resolution = sample_period * 1000;
863
864 if (dev->hw_learning_and_tx_capable) {
865
866 ir_props->s_learning_mode = ene_set_learning_mode;
867
868 if (input == 0)
869 ir_props->s_rx_carrier_range = ene_set_rec_carrier;
870
871 init_completion(&dev->tx_complete);
872 ir_props->tx_ir = ene_transmit;
873 ir_props->s_tx_mask = ene_set_tx_mask;
874 ir_props->s_tx_carrier = ene_set_tx_carrier;
875 ir_props->tx_resolution = ENE_TX_SMPL_PERIOD * 1000;
876 /* ir_props->s_carrier_report = ene_set_carrier_report; */
877 }
878
879
880 device_set_wakeup_capable(&pnp_dev->dev, 1);
881 device_set_wakeup_enable(&pnp_dev->dev, 1);
882
883 if (dev->hw_learning_and_tx_capable)
884 input_dev->name = "ENE eHome Infrared Remote Transceiver";
885 else
886 input_dev->name = "ENE eHome Infrared Remote Receiver";
887
888
889 error = -ENODEV;
890 if (ir_input_register(input_dev, RC_MAP_RC6_MCE, ir_props,
891 ENE_DRIVER_NAME))
892 goto error;
893
894
895 ene_printk(KERN_NOTICE, "driver has been succesfully loaded\n");
896 return 0;
897error:
898 if (dev->irq)
899 free_irq(dev->irq, dev);
900 if (dev->hw_io)
901 release_region(dev->hw_io, ENE_MAX_IO);
902
903 input_free_device(input_dev);
904 kfree(ir_props);
905 kfree(dev);
906 return error;
907}
908
909/* main unload function */
910static void ene_remove(struct pnp_dev *pnp_dev)
911{
912 struct ene_device *dev = pnp_get_drvdata(pnp_dev);
913 unsigned long flags;
914
915 spin_lock_irqsave(&dev->hw_lock, flags);
916 ene_rx_disable(dev);
917 spin_unlock_irqrestore(&dev->hw_lock, flags);
918
919 free_irq(dev->irq, dev);
920 release_region(dev->hw_io, ENE_MAX_IO);
921 ir_input_unregister(dev->idev);
922 kfree(dev->props);
923 kfree(dev);
924}
925
926/* enable wake on IR (wakes on specific button on original remote) */
927static void ene_enable_wake(struct ene_device *dev, int enable)
928{
929 enable = enable && device_may_wakeup(&dev->pnp_dev->dev);
930
931 ene_dbg("wake on IR %s", enable ? "enabled" : "disabled");
932
933 ene_hw_write_reg_mask(dev, ENE_FW1, enable ?
934 ENE_FW1_WAKE : 0, ENE_FW1_WAKE);
935}
936
937#ifdef CONFIG_PM
938static int ene_suspend(struct pnp_dev *pnp_dev, pm_message_t state)
939{
940 struct ene_device *dev = pnp_get_drvdata(pnp_dev);
941 ene_enable_wake(dev, 1);
942 return 0;
943}
944
945static int ene_resume(struct pnp_dev *pnp_dev)
946{
947 struct ene_device *dev = pnp_get_drvdata(pnp_dev);
948 if (dev->in_use)
949 ene_rx_enable(dev);
950
951 ene_enable_wake(dev, 0);
952 return 0;
953}
954#endif
955
956static void ene_shutdown(struct pnp_dev *pnp_dev)
957{
958 struct ene_device *dev = pnp_get_drvdata(pnp_dev);
959 ene_enable_wake(dev, 1);
960}
961
962static const struct pnp_device_id ene_ids[] = {
963 {.id = "ENE0100",},
964 {.id = "ENE0200",},
965 {.id = "ENE0201",},
966 {.id = "ENE0202",},
967 {},
968};
969
970static struct pnp_driver ene_driver = {
971 .name = ENE_DRIVER_NAME,
972 .id_table = ene_ids,
973 .flags = PNP_DRIVER_RES_DO_NOT_CHANGE,
974
975 .probe = ene_probe,
976 .remove = __devexit_p(ene_remove),
977#ifdef CONFIG_PM
978 .suspend = ene_suspend,
979 .resume = ene_resume,
980#endif
981 .shutdown = ene_shutdown,
982};
983
984static int __init ene_init(void)
985{
986 return pnp_register_driver(&ene_driver);
987}
988
989static void ene_exit(void)
990{
991 pnp_unregister_driver(&ene_driver);
992}
993
994module_param(sample_period, int, S_IRUGO);
995MODULE_PARM_DESC(sample_period, "Hardware sample period (50 us default)");
996
997module_param(enable_idle, bool, S_IRUGO | S_IWUSR);
998MODULE_PARM_DESC(enable_idle,
999 "Enables turning off signal sampling after long inactivity time; "
1000 "if disabled might help detecting input signal (default: enabled)"
1001 " (KB3926B only)");
1002
1003module_param(input, bool, S_IRUGO);
1004MODULE_PARM_DESC(input, "select which input to use "
1005 "0 - auto, 1 - standard, 2 - wideband(KB3926C+)");
1006
1007module_param(debug, int, S_IRUGO | S_IWUSR);
1008MODULE_PARM_DESC(debug, "Enable debug (debug=2 verbose debug output)");
1009
1010module_param(txsim, bool, S_IRUGO);
1011MODULE_PARM_DESC(txsim,
1012 "Simulate TX features on unsupported hardware (dangerous)");
1013
1014MODULE_DEVICE_TABLE(pnp, ene_ids);
1015MODULE_DESCRIPTION
1016 ("Infrared input driver for KB3926B/KB3926C/KB3926D "
1017 "(aka ENE0100/ENE0200/ENE0201) CIR port");
1018
1019MODULE_AUTHOR("Maxim Levitsky");
1020MODULE_LICENSE("GPL");
1021
1022module_init(ene_init);
1023module_exit(ene_exit);
diff --git a/drivers/media/IR/ene_ir.h b/drivers/media/IR/ene_ir.h
new file mode 100644
index 000000000000..54c76af0d033
--- /dev/null
+++ b/drivers/media/IR/ene_ir.h
@@ -0,0 +1,235 @@
1/*
2 * driver for ENE KB3926 B/C/D CIR (also known as ENE0XXX)
3 *
4 * Copyright (C) 2010 Maxim Levitsky <maximlevitsky@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 * USA
20 */
21#include <linux/spinlock.h>
22
23
24/* hardware address */
25#define ENE_STATUS 0 /* hardware status - unused */
26#define ENE_ADDR_HI 1 /* hi byte of register address */
27#define ENE_ADDR_LO 2 /* low byte of register address */
28#define ENE_IO 3 /* read/write window */
29#define ENE_MAX_IO 4
30
31/* 8 bytes of samples, divided in 2 halfs*/
32#define ENE_SAMPLE_BUFFER 0xF8F0 /* regular sample buffer */
33#define ENE_SAMPLE_SPC_MASK 0x80 /* sample is space */
34#define ENE_SAMPLE_VALUE_MASK 0x7F
35#define ENE_SAMPLE_OVERFLOW 0x7F
36#define ENE_SAMPLES_SIZE 4
37
38/* fan input sample buffer */
39#define ENE_SAMPLE_BUFFER_FAN 0xF8FB /* this buffer holds high byte of */
40 /* each sample of normal buffer */
41#define ENE_FAN_SMPL_PULS_MSK 0x8000 /* this bit of combined sample */
42 /* if set, says that sample is pulse */
43#define ENE_FAN_VALUE_MASK 0x0FFF /* mask for valid bits of the value */
44
45/* first firmware register */
46#define ENE_FW1 0xF8F8
47#define ENE_FW1_ENABLE 0x01 /* enable fw processing */
48#define ENE_FW1_TXIRQ 0x02 /* TX interrupt pending */
49#define ENE_FW1_WAKE 0x40 /* enable wake from S3 */
50#define ENE_FW1_IRQ 0x80 /* enable interrupt */
51
52/* second firmware register */
53#define ENE_FW2 0xF8F9
54#define ENE_FW2_BUF_HIGH 0x01 /* which half of the buffer to read */
55#define ENE_FW2_IRQ_CLR 0x04 /* clear this on IRQ */
56#define ENE_FW2_GP40_AS_LEARN 0x08 /* normal input is used as */
57 /* learning input */
58#define ENE_FW2_FAN_AS_NRML_IN 0x40 /* fan is used as normal input */
59#define ENE_FW2_LEARNING 0x80 /* hardware supports learning and TX */
60
61/* transmitter ports */
62#define ENE_TX_PORT2 0xFC01 /* this enables one or both */
63#define ENE_TX_PORT2_EN 0x20 /* TX ports */
64#define ENE_TX_PORT1 0xFC08
65#define ENE_TX_PORT1_EN 0x02
66
67/* IRQ registers block (for revision B) */
68#define ENEB_IRQ 0xFD09 /* IRQ number */
69#define ENEB_IRQ_UNK1 0xFD17 /* unknown setting = 1 */
70#define ENEB_IRQ_STATUS 0xFD80 /* irq status */
71#define ENEB_IRQ_STATUS_IR 0x20 /* IR irq */
72
73/* fan as input settings - only if learning capable */
74#define ENE_FAN_AS_IN1 0xFE30 /* fan init reg 1 */
75#define ENE_FAN_AS_IN1_EN 0xCD
76#define ENE_FAN_AS_IN2 0xFE31 /* fan init reg 2 */
77#define ENE_FAN_AS_IN2_EN 0x03
78#define ENE_SAMPLE_PERIOD_FAN 61 /* fan input has fixed sample period */
79
80/* IRQ registers block (for revision C,D) */
81#define ENEC_IRQ 0xFE9B /* new irq settings register */
82#define ENEC_IRQ_MASK 0x0F /* irq number mask */
83#define ENEC_IRQ_UNK_EN 0x10 /* always enabled */
84#define ENEC_IRQ_STATUS 0x20 /* irq status and ACK */
85
86/* CIR block settings */
87#define ENE_CIR_CONF1 0xFEC0
88#define ENE_CIR_CONF1_TX_CLEAR 0x01 /* clear that on revC */
89 /* while transmitting */
90#define ENE_CIR_CONF1_RX_ON 0x07 /* normal receiver enabled */
91#define ENE_CIR_CONF1_LEARN1 0x08 /* enabled on learning mode */
92#define ENE_CIR_CONF1_TX_ON 0x30 /* enabled on transmit */
93#define ENE_CIR_CONF1_TX_CARR 0x80 /* send TX carrier or not */
94
95#define ENE_CIR_CONF2 0xFEC1 /* unknown setting = 0 */
96#define ENE_CIR_CONF2_LEARN2 0x10 /* set on enable learning */
97#define ENE_CIR_CONF2_GPIO40DIS 0x20 /* disable input via gpio40 */
98
99#define ENE_CIR_SAMPLE_PERIOD 0xFEC8 /* sample period in us */
100#define ENE_CIR_SAMPLE_OVERFLOW 0x80 /* interrupt on overflows if set */
101
102
103/* Two byte tx buffer */
104#define ENE_TX_INPUT1 0xFEC9
105#define ENE_TX_INPUT2 0xFECA
106#define ENE_TX_PULSE_MASK 0x80 /* Transmitted sample is pulse */
107#define ENE_TX_SMLP_MASK 0x7F
108#define ENE_TX_SMPL_PERIOD 50 /* transmit sample period - fixed */
109
110
111/* Unknown TX setting - TX sample period ??? */
112#define ENE_TX_UNK1 0xFECB /* set to 0x63 */
113
114/* Current received carrier period */
115#define ENE_RX_CARRIER 0xFECC /* RX period (500 ns) */
116#define ENE_RX_CARRIER_VALID 0x80 /* Register content valid */
117
118
119/* TX period (1/carrier) */
120#define ENE_TX_PERIOD 0xFECE /* TX period (500 ns) */
121#define ENE_TX_PERIOD_UNKBIT 0x80 /* This bit set on transmit*/
122#define ENE_TX_PERIOD_PULSE 0xFECF /* TX pulse period (500 ns)*/
123
124/* Hardware versions */
125#define ENE_HW_VERSION 0xFF00 /* hardware revision */
126#define ENE_PLLFRH 0xFF16
127#define ENE_PLLFRL 0xFF17
128
129#define ENE_HW_UNK 0xFF1D
130#define ENE_HW_UNK_CLR 0x04
131#define ENE_HW_VER_MAJOR 0xFF1E /* chip version */
132#define ENE_HW_VER_MINOR 0xFF1F
133#define ENE_HW_VER_OLD 0xFD00
134
135/* Normal/Learning carrier ranges - only valid if we have learning input*/
136/* TODO: test */
137#define ENE_NORMAL_RX_LOW 34
138#define ENE_NORMAL_RX_HI 38
139
140/* Tx carrier range */
141/* Hardware might be able to do more, but this range is enough for
142 all purposes */
143#define ENE_TX_PERIOD_MAX 32 /* corresponds to 29.4 kHz */
144#define ENE_TX_PERIOD_MIN 16 /* corrsponds to 62.5 kHz */
145
146
147
148/* Minimal and maximal gaps */
149
150/* Normal case:
151 Minimal gap is 0x7F * sample period
152 Maximum gap depends on hardware.
153 For KB3926B, it is unlimited, for newer models its around
154 250000, after which HW stops sending samples, and that is
155 not possible to change */
156
157/* Fan case:
158 Both minimal and maximal gaps are same, and equal to 0xFFF * 0x61
159 And there is nothing to change this setting
160*/
161
162#define ENE_MAXGAP 250000
163#define ENE_MINGAP (127 * sample_period)
164
165/******************************************************************************/
166
167#define ENE_DRIVER_NAME "ene_ir"
168
169#define ENE_IRQ_RX 1
170#define ENE_IRQ_TX 2
171
172#define ENE_HW_B 1 /* 3926B */
173#define ENE_HW_C 2 /* 3926C */
174#define ENE_HW_D 3 /* 3926D */
175
176#define ene_printk(level, text, ...) \
177 printk(level ENE_DRIVER_NAME ": " text, ## __VA_ARGS__)
178
179#define ene_dbg(text, ...) \
180 if (debug) \
181 printk(KERN_DEBUG \
182 ENE_DRIVER_NAME ": " text "\n" , ## __VA_ARGS__)
183
184#define ene_dbg_verbose(text, ...) \
185 if (debug > 1) \
186 printk(KERN_DEBUG \
187 ENE_DRIVER_NAME ": " text "\n" , ## __VA_ARGS__)
188
189
190struct ene_device {
191 struct pnp_dev *pnp_dev;
192 struct input_dev *idev;
193 struct ir_dev_props *props;
194 int in_use;
195
196 /* hw IO settings */
197 unsigned long hw_io;
198 int irq;
199 spinlock_t hw_lock;
200
201 /* HW features */
202 int hw_revision; /* hardware revision */
203 bool hw_learning_and_tx_capable; /* learning capable */
204 bool hw_gpio40_learning; /* gpio40 is learning */
205 bool hw_fan_as_normal_input; /* fan input is used as */
206 /* regular input */
207 /* HW state*/
208 int rx_pointer; /* hw pointer to rx buffer */
209 bool rx_fan_input_inuse; /* is fan input in use for rx*/
210 int tx_reg; /* current reg used for TX */
211 u8 saved_conf1; /* saved FEC0 reg */
212
213 /* TX sample handling */
214 unsigned int tx_sample; /* current sample for TX */
215 bool tx_sample_pulse; /* current sample is pulse */
216
217 /* TX buffer */
218 int *tx_buffer; /* input samples buffer*/
219 int tx_pos; /* position in that bufer */
220 int tx_len; /* current len of tx buffer */
221 int tx_done; /* done transmitting */
222 /* one more sample pending*/
223 struct completion tx_complete; /* TX completion */
224 struct timer_list tx_sim_timer;
225
226 /* TX settings */
227 int tx_period;
228 int tx_duty_cycle;
229 int transmitter_mask;
230
231 /* RX settings */
232 bool learning_enabled; /* learning input enabled */
233 bool carrier_detect_enabled; /* carrier detect enabled */
234 int rx_period_adjust;
235};
diff --git a/drivers/media/IR/imon.c b/drivers/media/IR/imon.c
index 65c125e44e96..c185422ef28c 100644
--- a/drivers/media/IR/imon.c
+++ b/drivers/media/IR/imon.c
@@ -87,7 +87,6 @@ static ssize_t lcd_write(struct file *file, const char *buf,
87struct imon_context { 87struct imon_context {
88 struct device *dev; 88 struct device *dev;
89 struct ir_dev_props *props; 89 struct ir_dev_props *props;
90 struct ir_input_dev *ir;
91 /* Newer devices have two interfaces */ 90 /* Newer devices have two interfaces */
92 struct usb_device *usbdev_intf0; 91 struct usb_device *usbdev_intf0;
93 struct usb_device *usbdev_intf1; 92 struct usb_device *usbdev_intf1;
@@ -1656,7 +1655,6 @@ static struct input_dev *imon_init_idev(struct imon_context *ictx)
1656{ 1655{
1657 struct input_dev *idev; 1656 struct input_dev *idev;
1658 struct ir_dev_props *props; 1657 struct ir_dev_props *props;
1659 struct ir_input_dev *ir;
1660 int ret, i; 1658 int ret, i;
1661 1659
1662 idev = input_allocate_device(); 1660 idev = input_allocate_device();
@@ -1671,12 +1669,6 @@ static struct input_dev *imon_init_idev(struct imon_context *ictx)
1671 goto props_alloc_failed; 1669 goto props_alloc_failed;
1672 } 1670 }
1673 1671
1674 ir = kzalloc(sizeof(struct ir_input_dev), GFP_KERNEL);
1675 if (!ir) {
1676 dev_err(ictx->dev, "remote ir input dev allocation failed\n");
1677 goto ir_dev_alloc_failed;
1678 }
1679
1680 snprintf(ictx->name_idev, sizeof(ictx->name_idev), 1672 snprintf(ictx->name_idev, sizeof(ictx->name_idev),
1681 "iMON Remote (%04x:%04x)", ictx->vendor, ictx->product); 1673 "iMON Remote (%04x:%04x)", ictx->vendor, ictx->product);
1682 idev->name = ictx->name_idev; 1674 idev->name = ictx->name_idev;
@@ -1706,14 +1698,9 @@ static struct input_dev *imon_init_idev(struct imon_context *ictx)
1706 props->change_protocol = imon_ir_change_protocol; 1698 props->change_protocol = imon_ir_change_protocol;
1707 ictx->props = props; 1699 ictx->props = props;
1708 1700
1709 ictx->ir = ir;
1710 memcpy(&ir->dev, ictx->dev, sizeof(struct device));
1711
1712 usb_to_input_id(ictx->usbdev_intf0, &idev->id); 1701 usb_to_input_id(ictx->usbdev_intf0, &idev->id);
1713 idev->dev.parent = ictx->dev; 1702 idev->dev.parent = ictx->dev;
1714 1703
1715 input_set_drvdata(idev, ir);
1716
1717 ret = ir_input_register(idev, RC_MAP_IMON_PAD, props, MOD_NAME); 1704 ret = ir_input_register(idev, RC_MAP_IMON_PAD, props, MOD_NAME);
1718 if (ret < 0) { 1705 if (ret < 0) {
1719 dev_err(ictx->dev, "remote input dev register failed\n"); 1706 dev_err(ictx->dev, "remote input dev register failed\n");
@@ -1723,8 +1710,6 @@ static struct input_dev *imon_init_idev(struct imon_context *ictx)
1723 return idev; 1710 return idev;
1724 1711
1725idev_register_failed: 1712idev_register_failed:
1726 kfree(ir);
1727ir_dev_alloc_failed:
1728 kfree(props); 1713 kfree(props);
1729props_alloc_failed: 1714props_alloc_failed:
1730 input_free_device(idev); 1715 input_free_device(idev);
@@ -1944,7 +1929,6 @@ static struct imon_context *imon_init_intf0(struct usb_interface *intf)
1944 1929
1945urb_submit_failed: 1930urb_submit_failed:
1946 ir_input_unregister(ictx->idev); 1931 ir_input_unregister(ictx->idev);
1947 input_free_device(ictx->idev);
1948idev_setup_failed: 1932idev_setup_failed:
1949find_endpoint_failed: 1933find_endpoint_failed:
1950 mutex_unlock(&ictx->lock); 1934 mutex_unlock(&ictx->lock);
@@ -2014,10 +1998,8 @@ static struct imon_context *imon_init_intf1(struct usb_interface *intf,
2014 return ictx; 1998 return ictx;
2015 1999
2016urb_submit_failed: 2000urb_submit_failed:
2017 if (ictx->touch) { 2001 if (ictx->touch)
2018 input_unregister_device(ictx->touch); 2002 input_unregister_device(ictx->touch);
2019 input_free_device(ictx->touch);
2020 }
2021touch_setup_failed: 2003touch_setup_failed:
2022find_endpoint_failed: 2004find_endpoint_failed:
2023 mutex_unlock(&ictx->lock); 2005 mutex_unlock(&ictx->lock);
diff --git a/drivers/media/IR/ir-core-priv.h b/drivers/media/IR/ir-core-priv.h
index babd52061bc3..a85a8c7c905a 100644
--- a/drivers/media/IR/ir-core-priv.h
+++ b/drivers/media/IR/ir-core-priv.h
@@ -32,7 +32,7 @@ struct ir_raw_handler {
32 32
33struct ir_raw_event_ctrl { 33struct ir_raw_event_ctrl {
34 struct list_head list; /* to keep track of raw clients */ 34 struct list_head list; /* to keep track of raw clients */
35 struct work_struct rx_work; /* for the rx decoding workqueue */ 35 struct task_struct *thread;
36 struct kfifo kfifo; /* fifo for the pulse/space durations */ 36 struct kfifo kfifo; /* fifo for the pulse/space durations */
37 ktime_t last_event; /* when last event occurred */ 37 ktime_t last_event; /* when last event occurred */
38 enum raw_event_type last_type; /* last event type */ 38 enum raw_event_type last_type; /* last event type */
@@ -41,10 +41,13 @@ struct ir_raw_event_ctrl {
41 41
42 /* raw decoder state follows */ 42 /* raw decoder state follows */
43 struct ir_raw_event prev_ev; 43 struct ir_raw_event prev_ev;
44 struct ir_raw_event this_ev;
44 struct nec_dec { 45 struct nec_dec {
45 int state; 46 int state;
46 unsigned count; 47 unsigned count;
47 u32 bits; 48 u32 bits;
49 bool is_nec_x;
50 bool necx_repeat;
48 } nec; 51 } nec;
49 struct rc5_dec { 52 struct rc5_dec {
50 int state; 53 int state;
@@ -76,7 +79,7 @@ struct ir_raw_event_ctrl {
76 struct lirc_codec { 79 struct lirc_codec {
77 struct ir_input_dev *ir_dev; 80 struct ir_input_dev *ir_dev;
78 struct lirc_driver *drv; 81 struct lirc_driver *drv;
79 int lircdata; 82 int carrier_low;
80 } lirc; 83 } lirc;
81}; 84};
82 85
@@ -104,10 +107,9 @@ static inline void decrease_duration(struct ir_raw_event *ev, unsigned duration)
104 ev->duration -= duration; 107 ev->duration -= duration;
105} 108}
106 109
107#define TO_US(duration) (((duration) + 500) / 1000) 110#define TO_US(duration) DIV_ROUND_CLOSEST((duration), 1000)
108#define TO_STR(is_pulse) ((is_pulse) ? "pulse" : "space") 111#define TO_STR(is_pulse) ((is_pulse) ? "pulse" : "space")
109#define IS_RESET(ev) (ev.duration == 0) 112#define IS_RESET(ev) (ev.duration == 0)
110
111/* 113/*
112 * Routines from ir-sysfs.c - Meant to be called only internally inside 114 * Routines from ir-sysfs.c - Meant to be called only internally inside
113 * ir-core 115 * ir-core
@@ -126,7 +128,8 @@ int ir_raw_handler_register(struct ir_raw_handler *ir_raw_handler);
126void ir_raw_handler_unregister(struct ir_raw_handler *ir_raw_handler); 128void ir_raw_handler_unregister(struct ir_raw_handler *ir_raw_handler);
127void ir_raw_init(void); 129void ir_raw_init(void);
128 130
129 131int ir_rcmap_init(void);
132void ir_rcmap_cleanup(void);
130/* 133/*
131 * Decoder initialization code 134 * Decoder initialization code
132 * 135 *
diff --git a/drivers/media/IR/ir-jvc-decoder.c b/drivers/media/IR/ir-jvc-decoder.c
index 8894d8b36048..77a89c4de014 100644
--- a/drivers/media/IR/ir-jvc-decoder.c
+++ b/drivers/media/IR/ir-jvc-decoder.c
@@ -32,6 +32,7 @@ enum jvc_state {
32 STATE_BIT_SPACE, 32 STATE_BIT_SPACE,
33 STATE_TRAILER_PULSE, 33 STATE_TRAILER_PULSE,
34 STATE_TRAILER_SPACE, 34 STATE_TRAILER_SPACE,
35 STATE_CHECK_REPEAT,
35}; 36};
36 37
37/** 38/**
@@ -60,6 +61,7 @@ static int ir_jvc_decode(struct input_dev *input_dev, struct ir_raw_event ev)
60 IR_dprintk(2, "JVC decode started at state %d (%uus %s)\n", 61 IR_dprintk(2, "JVC decode started at state %d (%uus %s)\n",
61 data->state, TO_US(ev.duration), TO_STR(ev.pulse)); 62 data->state, TO_US(ev.duration), TO_STR(ev.pulse));
62 63
64again:
63 switch (data->state) { 65 switch (data->state) {
64 66
65 case STATE_INACTIVE: 67 case STATE_INACTIVE:
@@ -149,8 +151,18 @@ static int ir_jvc_decode(struct input_dev *input_dev, struct ir_raw_event ev)
149 } 151 }
150 152
151 data->count = 0; 153 data->count = 0;
152 data->state = STATE_BIT_PULSE; 154 data->state = STATE_CHECK_REPEAT;
153 return 0; 155 return 0;
156
157 case STATE_CHECK_REPEAT:
158 if (!ev.pulse)
159 break;
160
161 if (eq_margin(ev.duration, JVC_HEADER_PULSE, JVC_UNIT / 2))
162 data->state = STATE_INACTIVE;
163 else
164 data->state = STATE_BIT_PULSE;
165 goto again;
154 } 166 }
155 167
156out: 168out:
diff --git a/drivers/media/IR/ir-keytable.c b/drivers/media/IR/ir-keytable.c
index 15a0f192d413..7e82a9df726b 100644
--- a/drivers/media/IR/ir-keytable.c
+++ b/drivers/media/IR/ir-keytable.c
@@ -339,6 +339,8 @@ void ir_repeat(struct input_dev *dev)
339 339
340 spin_lock_irqsave(&ir->keylock, flags); 340 spin_lock_irqsave(&ir->keylock, flags);
341 341
342 input_event(dev, EV_MSC, MSC_SCAN, ir->last_scancode);
343
342 if (!ir->keypressed) 344 if (!ir->keypressed)
343 goto out; 345 goto out;
344 346
@@ -370,6 +372,8 @@ void ir_keydown(struct input_dev *dev, int scancode, u8 toggle)
370 372
371 spin_lock_irqsave(&ir->keylock, flags); 373 spin_lock_irqsave(&ir->keylock, flags);
372 374
375 input_event(dev, EV_MSC, MSC_SCAN, scancode);
376
373 /* Repeat event? */ 377 /* Repeat event? */
374 if (ir->keypressed && 378 if (ir->keypressed &&
375 ir->last_scancode == scancode && 379 ir->last_scancode == scancode &&
@@ -383,9 +387,11 @@ void ir_keydown(struct input_dev *dev, int scancode, u8 toggle)
383 ir->last_toggle = toggle; 387 ir->last_toggle = toggle;
384 ir->last_keycode = keycode; 388 ir->last_keycode = keycode;
385 389
390
386 if (keycode == KEY_RESERVED) 391 if (keycode == KEY_RESERVED)
387 goto out; 392 goto out;
388 393
394
389 /* Register a keypress */ 395 /* Register a keypress */
390 ir->keypressed = true; 396 ir->keypressed = true;
391 IR_dprintk(1, "%s: key down event, key 0x%04x, scancode 0x%04x\n", 397 IR_dprintk(1, "%s: key down event, key 0x%04x, scancode 0x%04x\n",
@@ -428,7 +434,7 @@ static void ir_close(struct input_dev *input_dev)
428 */ 434 */
429int __ir_input_register(struct input_dev *input_dev, 435int __ir_input_register(struct input_dev *input_dev,
430 const struct ir_scancode_table *rc_tab, 436 const struct ir_scancode_table *rc_tab,
431 const struct ir_dev_props *props, 437 struct ir_dev_props *props,
432 const char *driver_name) 438 const char *driver_name)
433{ 439{
434 struct ir_input_dev *ir_dev; 440 struct ir_input_dev *ir_dev;
@@ -480,6 +486,8 @@ int __ir_input_register(struct input_dev *input_dev,
480 486
481 set_bit(EV_KEY, input_dev->evbit); 487 set_bit(EV_KEY, input_dev->evbit);
482 set_bit(EV_REP, input_dev->evbit); 488 set_bit(EV_REP, input_dev->evbit);
489 set_bit(EV_MSC, input_dev->evbit);
490 set_bit(MSC_SCAN, input_dev->mscbit);
483 491
484 if (ir_setkeytable(input_dev, &ir_dev->rc_tab, rc_tab)) { 492 if (ir_setkeytable(input_dev, &ir_dev->rc_tab, rc_tab)) {
485 rc = -ENOMEM; 493 rc = -ENOMEM;
@@ -499,7 +507,8 @@ int __ir_input_register(struct input_dev *input_dev,
499 507
500 IR_dprintk(1, "Registered input device on %s for %s remote%s.\n", 508 IR_dprintk(1, "Registered input device on %s for %s remote%s.\n",
501 driver_name, rc_tab->name, 509 driver_name, rc_tab->name,
502 ir_dev->props->driver_type == RC_DRIVER_IR_RAW ? " in raw mode" : ""); 510 (ir_dev->props && ir_dev->props->driver_type == RC_DRIVER_IR_RAW) ?
511 " in raw mode" : "");
503 512
504 return 0; 513 return 0;
505 514
diff --git a/drivers/media/IR/ir-lirc-codec.c b/drivers/media/IR/ir-lirc-codec.c
index 3ba482d96c4b..77b5946413c0 100644
--- a/drivers/media/IR/ir-lirc-codec.c
+++ b/drivers/media/IR/ir-lirc-codec.c
@@ -32,6 +32,7 @@
32static int ir_lirc_decode(struct input_dev *input_dev, struct ir_raw_event ev) 32static int ir_lirc_decode(struct input_dev *input_dev, struct ir_raw_event ev)
33{ 33{
34 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); 34 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
35 int sample;
35 36
36 if (!(ir_dev->raw->enabled_protocols & IR_TYPE_LIRC)) 37 if (!(ir_dev->raw->enabled_protocols & IR_TYPE_LIRC))
37 return 0; 38 return 0;
@@ -39,18 +40,20 @@ static int ir_lirc_decode(struct input_dev *input_dev, struct ir_raw_event ev)
39 if (!ir_dev->raw->lirc.drv || !ir_dev->raw->lirc.drv->rbuf) 40 if (!ir_dev->raw->lirc.drv || !ir_dev->raw->lirc.drv->rbuf)
40 return -EINVAL; 41 return -EINVAL;
41 42
43 if (IS_RESET(ev))
44 return 0;
45
42 IR_dprintk(2, "LIRC data transfer started (%uus %s)\n", 46 IR_dprintk(2, "LIRC data transfer started (%uus %s)\n",
43 TO_US(ev.duration), TO_STR(ev.pulse)); 47 TO_US(ev.duration), TO_STR(ev.pulse));
44 48
45 ir_dev->raw->lirc.lircdata += ev.duration / 1000; 49 sample = ev.duration / 1000;
46 if (ev.pulse) 50 if (ev.pulse)
47 ir_dev->raw->lirc.lircdata |= PULSE_BIT; 51 sample |= PULSE_BIT;
48 52
49 lirc_buffer_write(ir_dev->raw->lirc.drv->rbuf, 53 lirc_buffer_write(ir_dev->raw->lirc.drv->rbuf,
50 (unsigned char *) &ir_dev->raw->lirc.lircdata); 54 (unsigned char *) &sample);
51 wake_up(&ir_dev->raw->lirc.drv->rbuf->wait_poll); 55 wake_up(&ir_dev->raw->lirc.drv->rbuf->wait_poll);
52 56
53 ir_dev->raw->lirc.lircdata = 0;
54 57
55 return 0; 58 return 0;
56} 59}
@@ -92,13 +95,14 @@ out:
92 return ret; 95 return ret;
93} 96}
94 97
95static long ir_lirc_ioctl(struct file *filep, unsigned int cmd, unsigned long arg) 98static long ir_lirc_ioctl(struct file *filep, unsigned int cmd,
99 unsigned long __user arg)
96{ 100{
97 struct lirc_codec *lirc; 101 struct lirc_codec *lirc;
98 struct ir_input_dev *ir_dev; 102 struct ir_input_dev *ir_dev;
99 int ret = 0; 103 int ret = 0;
100 void *drv_data; 104 void *drv_data;
101 unsigned long val; 105 unsigned long val = 0;
102 106
103 lirc = lirc_get_pdata(filep); 107 lirc = lirc_get_pdata(filep);
104 if (!lirc) 108 if (!lirc)
@@ -110,47 +114,106 @@ static long ir_lirc_ioctl(struct file *filep, unsigned int cmd, unsigned long ar
110 114
111 drv_data = ir_dev->props->priv; 115 drv_data = ir_dev->props->priv;
112 116
113 switch (cmd) { 117 if (_IOC_DIR(cmd) & _IOC_WRITE) {
114 case LIRC_SET_TRANSMITTER_MASK:
115 ret = get_user(val, (unsigned long *)arg); 118 ret = get_user(val, (unsigned long *)arg);
116 if (ret) 119 if (ret)
117 return ret; 120 return ret;
121 }
122
123 switch (cmd) {
118 124
119 if (ir_dev->props && ir_dev->props->s_tx_mask) 125 /* legacy support */
126 case LIRC_GET_SEND_MODE:
127 val = LIRC_CAN_SEND_PULSE & LIRC_CAN_SEND_MASK;
128 break;
129
130 case LIRC_SET_SEND_MODE:
131 if (val != (LIRC_MODE_PULSE & LIRC_CAN_SEND_MASK))
132 return -EINVAL;
133 break;
134
135 /* TX settings */
136 case LIRC_SET_TRANSMITTER_MASK:
137 if (ir_dev->props->s_tx_mask)
120 ret = ir_dev->props->s_tx_mask(drv_data, (u32)val); 138 ret = ir_dev->props->s_tx_mask(drv_data, (u32)val);
121 else 139 else
122 return -EINVAL; 140 return -EINVAL;
123 break; 141 break;
124 142
125 case LIRC_SET_SEND_CARRIER: 143 case LIRC_SET_SEND_CARRIER:
126 ret = get_user(val, (unsigned long *)arg); 144 if (ir_dev->props->s_tx_carrier)
127 if (ret)
128 return ret;
129
130 if (ir_dev->props && ir_dev->props->s_tx_carrier)
131 ir_dev->props->s_tx_carrier(drv_data, (u32)val); 145 ir_dev->props->s_tx_carrier(drv_data, (u32)val);
132 else 146 else
133 return -EINVAL; 147 return -EINVAL;
134 break; 148 break;
135 149
136 case LIRC_GET_SEND_MODE: 150 case LIRC_SET_SEND_DUTY_CYCLE:
137 val = LIRC_CAN_SEND_PULSE & LIRC_CAN_SEND_MASK; 151 if (!ir_dev->props->s_tx_duty_cycle)
138 ret = put_user(val, (unsigned long *)arg); 152 return -ENOSYS;
153
154 if (val <= 0 || val >= 100)
155 return -EINVAL;
156
157 ir_dev->props->s_tx_duty_cycle(ir_dev->props->priv, val);
139 break; 158 break;
140 159
141 case LIRC_SET_SEND_MODE: 160 /* RX settings */
142 ret = get_user(val, (unsigned long *)arg); 161 case LIRC_SET_REC_CARRIER:
143 if (ret) 162 if (ir_dev->props->s_rx_carrier_range)
144 return ret; 163 ret = ir_dev->props->s_rx_carrier_range(
164 ir_dev->props->priv,
165 ir_dev->raw->lirc.carrier_low, val);
166 else
167 return -ENOSYS;
145 168
146 if (val != (LIRC_MODE_PULSE & LIRC_CAN_SEND_MASK)) 169 if (!ret)
170 ir_dev->raw->lirc.carrier_low = 0;
171 break;
172
173 case LIRC_SET_REC_CARRIER_RANGE:
174 if (val >= 0)
175 ir_dev->raw->lirc.carrier_low = val;
176 break;
177
178
179 case LIRC_GET_REC_RESOLUTION:
180 val = ir_dev->props->rx_resolution;
181 break;
182
183 case LIRC_SET_WIDEBAND_RECEIVER:
184 if (ir_dev->props->s_learning_mode)
185 return ir_dev->props->s_learning_mode(
186 ir_dev->props->priv, !!val);
187 else
188 return -ENOSYS;
189
190 /* Generic timeout support */
191 case LIRC_GET_MIN_TIMEOUT:
192 if (!ir_dev->props->max_timeout)
193 return -ENOSYS;
194 val = ir_dev->props->min_timeout / 1000;
195 break;
196
197 case LIRC_GET_MAX_TIMEOUT:
198 if (!ir_dev->props->max_timeout)
199 return -ENOSYS;
200 val = ir_dev->props->max_timeout / 1000;
201 break;
202
203 case LIRC_SET_REC_TIMEOUT:
204 if (val < ir_dev->props->min_timeout ||
205 val > ir_dev->props->max_timeout)
147 return -EINVAL; 206 return -EINVAL;
207 ir_dev->props->timeout = val * 1000;
148 break; 208 break;
149 209
150 default: 210 default:
151 return lirc_dev_fop_ioctl(filep, cmd, arg); 211 return lirc_dev_fop_ioctl(filep, cmd, arg);
152 } 212 }
153 213
214 if (_IOC_DIR(cmd) & _IOC_READ)
215 ret = put_user(val, (unsigned long *)arg);
216
154 return ret; 217 return ret;
155} 218}
156 219
@@ -196,13 +259,28 @@ static int ir_lirc_register(struct input_dev *input_dev)
196 259
197 features = LIRC_CAN_REC_MODE2; 260 features = LIRC_CAN_REC_MODE2;
198 if (ir_dev->props->tx_ir) { 261 if (ir_dev->props->tx_ir) {
262
199 features |= LIRC_CAN_SEND_PULSE; 263 features |= LIRC_CAN_SEND_PULSE;
200 if (ir_dev->props->s_tx_mask) 264 if (ir_dev->props->s_tx_mask)
201 features |= LIRC_CAN_SET_TRANSMITTER_MASK; 265 features |= LIRC_CAN_SET_TRANSMITTER_MASK;
202 if (ir_dev->props->s_tx_carrier) 266 if (ir_dev->props->s_tx_carrier)
203 features |= LIRC_CAN_SET_SEND_CARRIER; 267 features |= LIRC_CAN_SET_SEND_CARRIER;
268
269 if (ir_dev->props->s_tx_duty_cycle)
270 features |= LIRC_CAN_SET_REC_DUTY_CYCLE;
204 } 271 }
205 272
273 if (ir_dev->props->s_rx_carrier_range)
274 features |= LIRC_CAN_SET_REC_CARRIER |
275 LIRC_CAN_SET_REC_CARRIER_RANGE;
276
277 if (ir_dev->props->s_learning_mode)
278 features |= LIRC_CAN_USE_WIDEBAND_RECEIVER;
279
280 if (ir_dev->props->max_timeout)
281 features |= LIRC_CAN_SET_REC_TIMEOUT;
282
283
206 snprintf(drv->name, sizeof(drv->name), "ir-lirc-codec (%s)", 284 snprintf(drv->name, sizeof(drv->name), "ir-lirc-codec (%s)",
207 ir_dev->driver_name); 285 ir_dev->driver_name);
208 drv->minor = -1; 286 drv->minor = -1;
@@ -224,8 +302,6 @@ static int ir_lirc_register(struct input_dev *input_dev)
224 302
225 ir_dev->raw->lirc.drv = drv; 303 ir_dev->raw->lirc.drv = drv;
226 ir_dev->raw->lirc.ir_dev = ir_dev; 304 ir_dev->raw->lirc.ir_dev = ir_dev;
227 ir_dev->raw->lirc.lircdata = PULSE_MASK;
228
229 return 0; 305 return 0;
230 306
231lirc_register_failed: 307lirc_register_failed:
diff --git a/drivers/media/IR/ir-nec-decoder.c b/drivers/media/IR/ir-nec-decoder.c
index 52e0f378ae3d..d597421d6547 100644
--- a/drivers/media/IR/ir-nec-decoder.c
+++ b/drivers/media/IR/ir-nec-decoder.c
@@ -20,12 +20,13 @@
20#define NEC_HEADER_PULSE (16 * NEC_UNIT) 20#define NEC_HEADER_PULSE (16 * NEC_UNIT)
21#define NECX_HEADER_PULSE (8 * NEC_UNIT) /* Less common NEC variant */ 21#define NECX_HEADER_PULSE (8 * NEC_UNIT) /* Less common NEC variant */
22#define NEC_HEADER_SPACE (8 * NEC_UNIT) 22#define NEC_HEADER_SPACE (8 * NEC_UNIT)
23#define NEC_REPEAT_SPACE (8 * NEC_UNIT) 23#define NEC_REPEAT_SPACE (4 * NEC_UNIT)
24#define NEC_BIT_PULSE (1 * NEC_UNIT) 24#define NEC_BIT_PULSE (1 * NEC_UNIT)
25#define NEC_BIT_0_SPACE (1 * NEC_UNIT) 25#define NEC_BIT_0_SPACE (1 * NEC_UNIT)
26#define NEC_BIT_1_SPACE (3 * NEC_UNIT) 26#define NEC_BIT_1_SPACE (3 * NEC_UNIT)
27#define NEC_TRAILER_PULSE (1 * NEC_UNIT) 27#define NEC_TRAILER_PULSE (1 * NEC_UNIT)
28#define NEC_TRAILER_SPACE (10 * NEC_UNIT) /* even longer in reality */ 28#define NEC_TRAILER_SPACE (10 * NEC_UNIT) /* even longer in reality */
29#define NECX_REPEAT_BITS 1
29 30
30enum nec_state { 31enum nec_state {
31 STATE_INACTIVE, 32 STATE_INACTIVE,
@@ -67,8 +68,12 @@ static int ir_nec_decode(struct input_dev *input_dev, struct ir_raw_event ev)
67 if (!ev.pulse) 68 if (!ev.pulse)
68 break; 69 break;
69 70
70 if (!eq_margin(ev.duration, NEC_HEADER_PULSE, NEC_UNIT / 2) && 71 if (eq_margin(ev.duration, NEC_HEADER_PULSE, NEC_UNIT / 2)) {
71 !eq_margin(ev.duration, NECX_HEADER_PULSE, NEC_UNIT / 2)) 72 data->is_nec_x = false;
73 data->necx_repeat = false;
74 } else if (eq_margin(ev.duration, NECX_HEADER_PULSE, NEC_UNIT / 2))
75 data->is_nec_x = true;
76 else
72 break; 77 break;
73 78
74 data->count = 0; 79 data->count = 0;
@@ -105,6 +110,17 @@ static int ir_nec_decode(struct input_dev *input_dev, struct ir_raw_event ev)
105 if (ev.pulse) 110 if (ev.pulse)
106 break; 111 break;
107 112
113 if (data->necx_repeat && data->count == NECX_REPEAT_BITS &&
114 geq_margin(ev.duration,
115 NEC_TRAILER_SPACE, NEC_UNIT / 2)) {
116 IR_dprintk(1, "Repeat last key\n");
117 ir_repeat(input_dev);
118 data->state = STATE_INACTIVE;
119 return 0;
120
121 } else if (data->count > NECX_REPEAT_BITS)
122 data->necx_repeat = false;
123
108 data->bits <<= 1; 124 data->bits <<= 1;
109 if (eq_margin(ev.duration, NEC_BIT_1_SPACE, NEC_UNIT / 2)) 125 if (eq_margin(ev.duration, NEC_BIT_1_SPACE, NEC_UNIT / 2))
110 data->bits |= 1; 126 data->bits |= 1;
@@ -159,6 +175,9 @@ static int ir_nec_decode(struct input_dev *input_dev, struct ir_raw_event ev)
159 IR_dprintk(1, "NEC scancode 0x%04x\n", scancode); 175 IR_dprintk(1, "NEC scancode 0x%04x\n", scancode);
160 } 176 }
161 177
178 if (data->is_nec_x)
179 data->necx_repeat = true;
180
162 ir_keydown(input_dev, scancode, 0); 181 ir_keydown(input_dev, scancode, 0);
163 data->state = STATE_INACTIVE; 182 data->state = STATE_INACTIVE;
164 return 0; 183 return 0;
diff --git a/drivers/media/IR/ir-raw-event.c b/drivers/media/IR/ir-raw-event.c
index 6f192ef31db1..43094e7eccfa 100644
--- a/drivers/media/IR/ir-raw-event.c
+++ b/drivers/media/IR/ir-raw-event.c
@@ -12,9 +12,10 @@
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 */ 13 */
14 14
15#include <linux/workqueue.h> 15#include <linux/kthread.h>
16#include <linux/spinlock.h> 16#include <linux/mutex.h>
17#include <linux/sched.h> 17#include <linux/sched.h>
18#include <linux/freezer.h>
18#include "ir-core-priv.h" 19#include "ir-core-priv.h"
19 20
20/* Define the max number of pulse/space transitions to buffer */ 21/* Define the max number of pulse/space transitions to buffer */
@@ -24,7 +25,7 @@
24static LIST_HEAD(ir_raw_client_list); 25static LIST_HEAD(ir_raw_client_list);
25 26
26/* Used to handle IR raw handler extensions */ 27/* Used to handle IR raw handler extensions */
27static DEFINE_SPINLOCK(ir_raw_handler_lock); 28static DEFINE_MUTEX(ir_raw_handler_lock);
28static LIST_HEAD(ir_raw_handler_list); 29static LIST_HEAD(ir_raw_handler_list);
29static u64 available_protocols; 30static u64 available_protocols;
30 31
@@ -33,20 +34,30 @@ static u64 available_protocols;
33static struct work_struct wq_load; 34static struct work_struct wq_load;
34#endif 35#endif
35 36
36static void ir_raw_event_work(struct work_struct *work) 37static int ir_raw_event_thread(void *data)
37{ 38{
38 struct ir_raw_event ev; 39 struct ir_raw_event ev;
39 struct ir_raw_handler *handler; 40 struct ir_raw_handler *handler;
40 struct ir_raw_event_ctrl *raw = 41 struct ir_raw_event_ctrl *raw = (struct ir_raw_event_ctrl *)data;
41 container_of(work, struct ir_raw_event_ctrl, rx_work); 42
42 43 while (!kthread_should_stop()) {
43 while (kfifo_out(&raw->kfifo, &ev, sizeof(ev)) == sizeof(ev)) { 44 try_to_freeze();
44 spin_lock(&ir_raw_handler_lock); 45
45 list_for_each_entry(handler, &ir_raw_handler_list, list) 46 mutex_lock(&ir_raw_handler_lock);
46 handler->decode(raw->input_dev, ev); 47
47 spin_unlock(&ir_raw_handler_lock); 48 while (kfifo_out(&raw->kfifo, &ev, sizeof(ev)) == sizeof(ev)) {
48 raw->prev_ev = ev; 49 list_for_each_entry(handler, &ir_raw_handler_list, list)
50 handler->decode(raw->input_dev, ev);
51 raw->prev_ev = ev;
52 }
53
54 mutex_unlock(&ir_raw_handler_lock);
55
56 set_current_state(TASK_INTERRUPTIBLE);
57 schedule();
49 } 58 }
59
60 return 0;
50} 61}
51 62
52/** 63/**
@@ -66,6 +77,9 @@ int ir_raw_event_store(struct input_dev *input_dev, struct ir_raw_event *ev)
66 if (!ir->raw) 77 if (!ir->raw)
67 return -EINVAL; 78 return -EINVAL;
68 79
80 IR_dprintk(2, "sample: (05%dus %s)\n",
81 TO_US(ev->duration), TO_STR(ev->pulse));
82
69 if (kfifo_in(&ir->raw->kfifo, ev, sizeof(*ev)) != sizeof(*ev)) 83 if (kfifo_in(&ir->raw->kfifo, ev, sizeof(*ev)) != sizeof(*ev))
70 return -ENOMEM; 84 return -ENOMEM;
71 85
@@ -126,6 +140,90 @@ int ir_raw_event_store_edge(struct input_dev *input_dev, enum raw_event_type typ
126EXPORT_SYMBOL_GPL(ir_raw_event_store_edge); 140EXPORT_SYMBOL_GPL(ir_raw_event_store_edge);
127 141
128/** 142/**
143 * ir_raw_event_store_with_filter() - pass next pulse/space to decoders with some processing
144 * @input_dev: the struct input_dev device descriptor
145 * @type: the type of the event that has occurred
146 *
147 * This routine (which may be called from an interrupt context) works
148 * in similiar manner to ir_raw_event_store_edge.
149 * This routine is intended for devices with limited internal buffer
150 * It automerges samples of same type, and handles timeouts
151 */
152int ir_raw_event_store_with_filter(struct input_dev *input_dev,
153 struct ir_raw_event *ev)
154{
155 struct ir_input_dev *ir = input_get_drvdata(input_dev);
156 struct ir_raw_event_ctrl *raw = ir->raw;
157
158 if (!raw || !ir->props)
159 return -EINVAL;
160
161 /* Ignore spaces in idle mode */
162 if (ir->idle && !ev->pulse)
163 return 0;
164 else if (ir->idle)
165 ir_raw_event_set_idle(input_dev, 0);
166
167 if (!raw->this_ev.duration) {
168 raw->this_ev = *ev;
169 } else if (ev->pulse == raw->this_ev.pulse) {
170 raw->this_ev.duration += ev->duration;
171 } else {
172 ir_raw_event_store(input_dev, &raw->this_ev);
173 raw->this_ev = *ev;
174 }
175
176 /* Enter idle mode if nessesary */
177 if (!ev->pulse && ir->props->timeout &&
178 raw->this_ev.duration >= ir->props->timeout)
179 ir_raw_event_set_idle(input_dev, 1);
180 return 0;
181}
182EXPORT_SYMBOL_GPL(ir_raw_event_store_with_filter);
183
184void ir_raw_event_set_idle(struct input_dev *input_dev, int idle)
185{
186 struct ir_input_dev *ir = input_get_drvdata(input_dev);
187 struct ir_raw_event_ctrl *raw = ir->raw;
188 ktime_t now;
189 u64 delta;
190
191 if (!ir->props)
192 return;
193
194 if (!ir->raw)
195 goto out;
196
197 if (idle) {
198 IR_dprintk(2, "enter idle mode\n");
199 raw->last_event = ktime_get();
200 } else {
201 IR_dprintk(2, "exit idle mode\n");
202
203 now = ktime_get();
204 delta = ktime_to_ns(ktime_sub(now, ir->raw->last_event));
205
206 WARN_ON(raw->this_ev.pulse);
207
208 raw->this_ev.duration =
209 min(raw->this_ev.duration + delta,
210 (u64)IR_MAX_DURATION);
211
212 ir_raw_event_store(input_dev, &raw->this_ev);
213
214 if (raw->this_ev.duration == IR_MAX_DURATION)
215 ir_raw_event_reset(input_dev);
216
217 raw->this_ev.duration = 0;
218 }
219out:
220 if (ir->props->s_idle)
221 ir->props->s_idle(ir->props->priv, idle);
222 ir->idle = idle;
223}
224EXPORT_SYMBOL_GPL(ir_raw_event_set_idle);
225
226/**
129 * ir_raw_event_handle() - schedules the decoding of stored ir data 227 * ir_raw_event_handle() - schedules the decoding of stored ir data
130 * @input_dev: the struct input_dev device descriptor 228 * @input_dev: the struct input_dev device descriptor
131 * 229 *
@@ -138,7 +236,7 @@ void ir_raw_event_handle(struct input_dev *input_dev)
138 if (!ir->raw) 236 if (!ir->raw)
139 return; 237 return;
140 238
141 schedule_work(&ir->raw->rx_work); 239 wake_up_process(ir->raw->thread);
142} 240}
143EXPORT_SYMBOL_GPL(ir_raw_event_handle); 241EXPORT_SYMBOL_GPL(ir_raw_event_handle);
144 242
@@ -147,9 +245,9 @@ u64
147ir_raw_get_allowed_protocols() 245ir_raw_get_allowed_protocols()
148{ 246{
149 u64 protocols; 247 u64 protocols;
150 spin_lock(&ir_raw_handler_lock); 248 mutex_lock(&ir_raw_handler_lock);
151 protocols = available_protocols; 249 protocols = available_protocols;
152 spin_unlock(&ir_raw_handler_lock); 250 mutex_unlock(&ir_raw_handler_lock);
153 return protocols; 251 return protocols;
154} 252}
155 253
@@ -167,7 +265,7 @@ int ir_raw_event_register(struct input_dev *input_dev)
167 return -ENOMEM; 265 return -ENOMEM;
168 266
169 ir->raw->input_dev = input_dev; 267 ir->raw->input_dev = input_dev;
170 INIT_WORK(&ir->raw->rx_work, ir_raw_event_work); 268
171 ir->raw->enabled_protocols = ~0; 269 ir->raw->enabled_protocols = ~0;
172 rc = kfifo_alloc(&ir->raw->kfifo, sizeof(s64) * MAX_IR_EVENT_SIZE, 270 rc = kfifo_alloc(&ir->raw->kfifo, sizeof(s64) * MAX_IR_EVENT_SIZE,
173 GFP_KERNEL); 271 GFP_KERNEL);
@@ -177,12 +275,21 @@ int ir_raw_event_register(struct input_dev *input_dev)
177 return rc; 275 return rc;
178 } 276 }
179 277
180 spin_lock(&ir_raw_handler_lock); 278 ir->raw->thread = kthread_run(ir_raw_event_thread, ir->raw,
279 "rc%u", (unsigned int)ir->devno);
280
281 if (IS_ERR(ir->raw->thread)) {
282 kfree(ir->raw);
283 ir->raw = NULL;
284 return PTR_ERR(ir->raw->thread);
285 }
286
287 mutex_lock(&ir_raw_handler_lock);
181 list_add_tail(&ir->raw->list, &ir_raw_client_list); 288 list_add_tail(&ir->raw->list, &ir_raw_client_list);
182 list_for_each_entry(handler, &ir_raw_handler_list, list) 289 list_for_each_entry(handler, &ir_raw_handler_list, list)
183 if (handler->raw_register) 290 if (handler->raw_register)
184 handler->raw_register(ir->raw->input_dev); 291 handler->raw_register(ir->raw->input_dev);
185 spin_unlock(&ir_raw_handler_lock); 292 mutex_unlock(&ir_raw_handler_lock);
186 293
187 return 0; 294 return 0;
188} 295}
@@ -195,14 +302,14 @@ void ir_raw_event_unregister(struct input_dev *input_dev)
195 if (!ir->raw) 302 if (!ir->raw)
196 return; 303 return;
197 304
198 cancel_work_sync(&ir->raw->rx_work); 305 kthread_stop(ir->raw->thread);
199 306
200 spin_lock(&ir_raw_handler_lock); 307 mutex_lock(&ir_raw_handler_lock);
201 list_del(&ir->raw->list); 308 list_del(&ir->raw->list);
202 list_for_each_entry(handler, &ir_raw_handler_list, list) 309 list_for_each_entry(handler, &ir_raw_handler_list, list)
203 if (handler->raw_unregister) 310 if (handler->raw_unregister)
204 handler->raw_unregister(ir->raw->input_dev); 311 handler->raw_unregister(ir->raw->input_dev);
205 spin_unlock(&ir_raw_handler_lock); 312 mutex_unlock(&ir_raw_handler_lock);
206 313
207 kfifo_free(&ir->raw->kfifo); 314 kfifo_free(&ir->raw->kfifo);
208 kfree(ir->raw); 315 kfree(ir->raw);
@@ -217,13 +324,13 @@ int ir_raw_handler_register(struct ir_raw_handler *ir_raw_handler)
217{ 324{
218 struct ir_raw_event_ctrl *raw; 325 struct ir_raw_event_ctrl *raw;
219 326
220 spin_lock(&ir_raw_handler_lock); 327 mutex_lock(&ir_raw_handler_lock);
221 list_add_tail(&ir_raw_handler->list, &ir_raw_handler_list); 328 list_add_tail(&ir_raw_handler->list, &ir_raw_handler_list);
222 if (ir_raw_handler->raw_register) 329 if (ir_raw_handler->raw_register)
223 list_for_each_entry(raw, &ir_raw_client_list, list) 330 list_for_each_entry(raw, &ir_raw_client_list, list)
224 ir_raw_handler->raw_register(raw->input_dev); 331 ir_raw_handler->raw_register(raw->input_dev);
225 available_protocols |= ir_raw_handler->protocols; 332 available_protocols |= ir_raw_handler->protocols;
226 spin_unlock(&ir_raw_handler_lock); 333 mutex_unlock(&ir_raw_handler_lock);
227 334
228 return 0; 335 return 0;
229} 336}
@@ -233,13 +340,13 @@ void ir_raw_handler_unregister(struct ir_raw_handler *ir_raw_handler)
233{ 340{
234 struct ir_raw_event_ctrl *raw; 341 struct ir_raw_event_ctrl *raw;
235 342
236 spin_lock(&ir_raw_handler_lock); 343 mutex_lock(&ir_raw_handler_lock);
237 list_del(&ir_raw_handler->list); 344 list_del(&ir_raw_handler->list);
238 if (ir_raw_handler->raw_unregister) 345 if (ir_raw_handler->raw_unregister)
239 list_for_each_entry(raw, &ir_raw_client_list, list) 346 list_for_each_entry(raw, &ir_raw_client_list, list)
240 ir_raw_handler->raw_unregister(raw->input_dev); 347 ir_raw_handler->raw_unregister(raw->input_dev);
241 available_protocols &= ~ir_raw_handler->protocols; 348 available_protocols &= ~ir_raw_handler->protocols;
242 spin_unlock(&ir_raw_handler_lock); 349 mutex_unlock(&ir_raw_handler_lock);
243} 350}
244EXPORT_SYMBOL(ir_raw_handler_unregister); 351EXPORT_SYMBOL(ir_raw_handler_unregister);
245 352
diff --git a/drivers/media/IR/ir-sysfs.c b/drivers/media/IR/ir-sysfs.c
index 6273047e915b..96dafc425c8e 100644
--- a/drivers/media/IR/ir-sysfs.c
+++ b/drivers/media/IR/ir-sysfs.c
@@ -325,6 +325,7 @@ static int __init ir_core_init(void)
325 325
326 /* Initialize/load the decoders/keymap code that will be used */ 326 /* Initialize/load the decoders/keymap code that will be used */
327 ir_raw_init(); 327 ir_raw_init();
328 ir_rcmap_init();
328 329
329 return 0; 330 return 0;
330} 331}
@@ -332,6 +333,7 @@ static int __init ir_core_init(void)
332static void __exit ir_core_exit(void) 333static void __exit ir_core_exit(void)
333{ 334{
334 class_unregister(&ir_input_class); 335 class_unregister(&ir_input_class);
336 ir_rcmap_cleanup();
335} 337}
336 338
337module_init(ir_core_init); 339module_init(ir_core_init);
diff --git a/drivers/media/IR/keymaps/Makefile b/drivers/media/IR/keymaps/Makefile
index cbee06243b51..950e5d953c6f 100644
--- a/drivers/media/IR/keymaps/Makefile
+++ b/drivers/media/IR/keymaps/Makefile
@@ -19,7 +19,6 @@ obj-$(CONFIG_RC_MAP) += rc-adstech-dvb-t-pci.o \
19 rc-dm1105-nec.o \ 19 rc-dm1105-nec.o \
20 rc-dntv-live-dvb-t.o \ 20 rc-dntv-live-dvb-t.o \
21 rc-dntv-live-dvbt-pro.o \ 21 rc-dntv-live-dvbt-pro.o \
22 rc-empty.o \
23 rc-em-terratec.o \ 22 rc-em-terratec.o \
24 rc-encore-enltv2.o \ 23 rc-encore-enltv2.o \
25 rc-encore-enltv.o \ 24 rc-encore-enltv.o \
@@ -59,6 +58,7 @@ obj-$(CONFIG_RC_MAP) += rc-adstech-dvb-t-pci.o \
59 rc-purpletv.o \ 58 rc-purpletv.o \
60 rc-pv951.o \ 59 rc-pv951.o \
61 rc-rc5-hauppauge-new.o \ 60 rc-rc5-hauppauge-new.o \
61 rc-rc5-streamzap.o \
62 rc-rc5-tv.o \ 62 rc-rc5-tv.o \
63 rc-rc6-mce.o \ 63 rc-rc6-mce.o \
64 rc-real-audio-220-32-keys.o \ 64 rc-real-audio-220-32-keys.o \
diff --git a/drivers/media/IR/keymaps/rc-empty.c b/drivers/media/IR/keymaps/rc-empty.c
deleted file mode 100644
index 3b338d84b476..000000000000
--- a/drivers/media/IR/keymaps/rc-empty.c
+++ /dev/null
@@ -1,44 +0,0 @@
1/* empty.h - Keytable for empty Remote Controller
2 *
3 * keymap imported from ir-keymaps.c
4 *
5 * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 */
12
13#include <media/rc-map.h>
14
15/* empty keytable, can be used as placeholder for not-yet created keytables */
16
17static struct ir_scancode empty[] = {
18 { 0x2a, KEY_COFFEE },
19};
20
21static struct rc_keymap empty_map = {
22 .map = {
23 .scan = empty,
24 .size = ARRAY_SIZE(empty),
25 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */
26 .name = RC_MAP_EMPTY,
27 }
28};
29
30static int __init init_rc_map_empty(void)
31{
32 return ir_register_map(&empty_map);
33}
34
35static void __exit exit_rc_map_empty(void)
36{
37 ir_unregister_map(&empty_map);
38}
39
40module_init(init_rc_map_empty)
41module_exit(exit_rc_map_empty)
42
43MODULE_LICENSE("GPL");
44MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-rc5-streamzap.c b/drivers/media/IR/keymaps/rc-rc5-streamzap.c
new file mode 100644
index 000000000000..4c19c58b46d8
--- /dev/null
+++ b/drivers/media/IR/keymaps/rc-rc5-streamzap.c
@@ -0,0 +1,81 @@
1/* rc-rc5-streamzap.c - Keytable for Streamzap PC Remote, for use
2 * with the Streamzap PC Remote IR Receiver.
3 *
4 * Copyright (c) 2010 by Jarod Wilson <jarod@redhat.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 */
11
12#include <media/rc-map.h>
13
14static struct ir_scancode rc5_streamzap[] = {
15/*
16 * FIXME: The Streamzap remote isn't actually true RC-5, it has an extra
17 * bit in it, which presently throws the in-kernel RC-5 decoder for a loop.
18 * We either have to enhance the decoder to support it, add a new decoder,
19 * or just rely on lirc userspace decoding.
20 */
21 { 0x00, KEY_NUMERIC_0 },
22 { 0x01, KEY_NUMERIC_1 },
23 { 0x02, KEY_NUMERIC_2 },
24 { 0x03, KEY_NUMERIC_3 },
25 { 0x04, KEY_NUMERIC_4 },
26 { 0x05, KEY_NUMERIC_5 },
27 { 0x06, KEY_NUMERIC_6 },
28 { 0x07, KEY_NUMERIC_7 },
29 { 0x08, KEY_NUMERIC_8 },
30 { 0x0a, KEY_POWER },
31 { 0x0b, KEY_MUTE },
32 { 0x0c, KEY_CHANNELUP },
33 { 0x0d, KEY_VOLUMEUP },
34 { 0x0e, KEY_CHANNELDOWN },
35 { 0x0f, KEY_VOLUMEDOWN },
36 { 0x10, KEY_UP },
37 { 0x11, KEY_LEFT },
38 { 0x12, KEY_OK },
39 { 0x13, KEY_RIGHT },
40 { 0x14, KEY_DOWN },
41 { 0x15, KEY_MENU },
42 { 0x16, KEY_EXIT },
43 { 0x17, KEY_PLAY },
44 { 0x18, KEY_PAUSE },
45 { 0x19, KEY_STOP },
46 { 0x1a, KEY_BACK },
47 { 0x1b, KEY_FORWARD },
48 { 0x1c, KEY_RECORD },
49 { 0x1d, KEY_REWIND },
50 { 0x1e, KEY_FASTFORWARD },
51 { 0x20, KEY_RED },
52 { 0x21, KEY_GREEN },
53 { 0x22, KEY_YELLOW },
54 { 0x23, KEY_BLUE },
55
56};
57
58static struct rc_keymap rc5_streamzap_map = {
59 .map = {
60 .scan = rc5_streamzap,
61 .size = ARRAY_SIZE(rc5_streamzap),
62 .ir_type = IR_TYPE_RC5,
63 .name = RC_MAP_RC5_STREAMZAP,
64 }
65};
66
67static int __init init_rc_map_rc5_streamzap(void)
68{
69 return ir_register_map(&rc5_streamzap_map);
70}
71
72static void __exit exit_rc_map_rc5_streamzap(void)
73{
74 ir_unregister_map(&rc5_streamzap_map);
75}
76
77module_init(init_rc_map_rc5_streamzap)
78module_exit(exit_rc_map_rc5_streamzap)
79
80MODULE_LICENSE("GPL");
81MODULE_AUTHOR("Jarod Wilson <jarod@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-rc6-mce.c b/drivers/media/IR/keymaps/rc-rc6-mce.c
index c6726a8039be..64264f7f838f 100644
--- a/drivers/media/IR/keymaps/rc-rc6-mce.c
+++ b/drivers/media/IR/keymaps/rc-rc6-mce.c
@@ -74,6 +74,8 @@ static struct ir_scancode rc6_mce[] = {
74 { 0x800f045a, KEY_SUBTITLE }, /* Caption/Teletext */ 74 { 0x800f045a, KEY_SUBTITLE }, /* Caption/Teletext */
75 { 0x800f044d, KEY_TITLE }, 75 { 0x800f044d, KEY_TITLE },
76 76
77 { 0x800f044e, KEY_PRINT }, /* Print - HP OEM version of remote */
78
77 { 0x800f040c, KEY_POWER }, 79 { 0x800f040c, KEY_POWER },
78 { 0x800f040d, KEY_PROG1 }, /* Windows MCE button */ 80 { 0x800f040d, KEY_PROG1 }, /* Windows MCE button */
79 81
diff --git a/drivers/media/IR/mceusb.c b/drivers/media/IR/mceusb.c
index 78bf7f77a1a0..ac6bb2c01a48 100644
--- a/drivers/media/IR/mceusb.c
+++ b/drivers/media/IR/mceusb.c
@@ -228,7 +228,6 @@ static struct usb_device_id std_tx_mask_list[] = {
228/* data structure for each usb transceiver */ 228/* data structure for each usb transceiver */
229struct mceusb_dev { 229struct mceusb_dev {
230 /* ir-core bits */ 230 /* ir-core bits */
231 struct ir_input_dev *irdev;
232 struct ir_dev_props *props; 231 struct ir_dev_props *props;
233 struct ir_raw_event rawir; 232 struct ir_raw_event rawir;
234 233
@@ -428,7 +427,7 @@ static void mceusb_dev_printdata(struct mceusb_dev *ir, char *buf,
428 } 427 }
429} 428}
430 429
431static void usb_async_callback(struct urb *urb, struct pt_regs *regs) 430static void mce_async_callback(struct urb *urb, struct pt_regs *regs)
432{ 431{
433 struct mceusb_dev *ir; 432 struct mceusb_dev *ir;
434 int len; 433 int len;
@@ -477,7 +476,7 @@ static void mce_request_packet(struct mceusb_dev *ir,
477 /* outbound data */ 476 /* outbound data */
478 usb_fill_int_urb(async_urb, ir->usbdev, 477 usb_fill_int_urb(async_urb, ir->usbdev,
479 usb_sndintpipe(ir->usbdev, ep->bEndpointAddress), 478 usb_sndintpipe(ir->usbdev, ep->bEndpointAddress),
480 async_buf, size, (usb_complete_t) usb_async_callback, 479 async_buf, size, (usb_complete_t)mce_async_callback,
481 ir, ep->bInterval); 480 ir, ep->bInterval);
482 memcpy(async_buf, data, size); 481 memcpy(async_buf, data, size);
483 482
@@ -739,7 +738,7 @@ static void mceusb_dev_recv(struct urb *urb, struct pt_regs *regs)
739 738
740 if (ir->send_flags == RECV_FLAG_IN_PROGRESS) { 739 if (ir->send_flags == RECV_FLAG_IN_PROGRESS) {
741 ir->send_flags = SEND_FLAG_COMPLETE; 740 ir->send_flags = SEND_FLAG_COMPLETE;
742 dev_dbg(&ir->irdev->dev, "setup answer received %d bytes\n", 741 dev_dbg(ir->dev, "setup answer received %d bytes\n",
743 buf_len); 742 buf_len);
744 } 743 }
745 744
@@ -861,7 +860,6 @@ static struct input_dev *mceusb_init_input_dev(struct mceusb_dev *ir)
861{ 860{
862 struct input_dev *idev; 861 struct input_dev *idev;
863 struct ir_dev_props *props; 862 struct ir_dev_props *props;
864 struct ir_input_dev *irdev;
865 struct device *dev = ir->dev; 863 struct device *dev = ir->dev;
866 int ret = -ENODEV; 864 int ret = -ENODEV;
867 865
@@ -878,12 +876,6 @@ static struct input_dev *mceusb_init_input_dev(struct mceusb_dev *ir)
878 goto props_alloc_failed; 876 goto props_alloc_failed;
879 } 877 }
880 878
881 irdev = kzalloc(sizeof(struct ir_input_dev), GFP_KERNEL);
882 if (!irdev) {
883 dev_err(dev, "remote ir input dev allocation failed\n");
884 goto ir_dev_alloc_failed;
885 }
886
887 snprintf(ir->name, sizeof(ir->name), "Media Center Ed. eHome " 879 snprintf(ir->name, sizeof(ir->name), "Media Center Ed. eHome "
888 "Infrared Remote Transceiver (%04x:%04x)", 880 "Infrared Remote Transceiver (%04x:%04x)",
889 le16_to_cpu(ir->usbdev->descriptor.idVendor), 881 le16_to_cpu(ir->usbdev->descriptor.idVendor),
@@ -902,9 +894,6 @@ static struct input_dev *mceusb_init_input_dev(struct mceusb_dev *ir)
902 props->tx_ir = mceusb_tx_ir; 894 props->tx_ir = mceusb_tx_ir;
903 895
904 ir->props = props; 896 ir->props = props;
905 ir->irdev = irdev;
906
907 input_set_drvdata(idev, irdev);
908 897
909 ret = ir_input_register(idev, RC_MAP_RC6_MCE, props, DRIVER_NAME); 898 ret = ir_input_register(idev, RC_MAP_RC6_MCE, props, DRIVER_NAME);
910 if (ret < 0) { 899 if (ret < 0) {
@@ -915,8 +904,6 @@ static struct input_dev *mceusb_init_input_dev(struct mceusb_dev *ir)
915 return idev; 904 return idev;
916 905
917irdev_failed: 906irdev_failed:
918 kfree(irdev);
919ir_dev_alloc_failed:
920 kfree(props); 907 kfree(props);
921props_alloc_failed: 908props_alloc_failed:
922 input_free_device(idev); 909 input_free_device(idev);
@@ -932,7 +919,6 @@ static int __devinit mceusb_dev_probe(struct usb_interface *intf,
932 struct usb_endpoint_descriptor *ep = NULL; 919 struct usb_endpoint_descriptor *ep = NULL;
933 struct usb_endpoint_descriptor *ep_in = NULL; 920 struct usb_endpoint_descriptor *ep_in = NULL;
934 struct usb_endpoint_descriptor *ep_out = NULL; 921 struct usb_endpoint_descriptor *ep_out = NULL;
935 struct usb_host_config *config;
936 struct mceusb_dev *ir = NULL; 922 struct mceusb_dev *ir = NULL;
937 int pipe, maxp, i; 923 int pipe, maxp, i;
938 char buf[63], name[128] = ""; 924 char buf[63], name[128] = "";
@@ -942,7 +928,6 @@ static int __devinit mceusb_dev_probe(struct usb_interface *intf,
942 928
943 dev_dbg(&intf->dev, ": %s called\n", __func__); 929 dev_dbg(&intf->dev, ": %s called\n", __func__);
944 930
945 config = dev->actconfig;
946 idesc = intf->cur_altsetting; 931 idesc = intf->cur_altsetting;
947 932
948 is_gen3 = usb_match_id(intf, gen3_list) ? 1 : 0; 933 is_gen3 = usb_match_id(intf, gen3_list) ? 1 : 0;
diff --git a/drivers/media/IR/rc-map.c b/drivers/media/IR/rc-map.c
index 46a8f1524b5b..689143f2fff0 100644
--- a/drivers/media/IR/rc-map.c
+++ b/drivers/media/IR/rc-map.c
@@ -82,3 +82,26 @@ void ir_unregister_map(struct rc_keymap *map)
82} 82}
83EXPORT_SYMBOL_GPL(ir_unregister_map); 83EXPORT_SYMBOL_GPL(ir_unregister_map);
84 84
85
86static struct ir_scancode empty[] = {
87 { 0x2a, KEY_COFFEE },
88};
89
90static struct rc_keymap empty_map = {
91 .map = {
92 .scan = empty,
93 .size = ARRAY_SIZE(empty),
94 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */
95 .name = RC_MAP_EMPTY,
96 }
97};
98
99int ir_rcmap_init(void)
100{
101 return ir_register_map(&empty_map);
102}
103
104void ir_rcmap_cleanup(void)
105{
106 ir_unregister_map(&empty_map);
107}
diff --git a/drivers/media/IR/streamzap.c b/drivers/media/IR/streamzap.c
new file mode 100644
index 000000000000..058e29fd478c
--- /dev/null
+++ b/drivers/media/IR/streamzap.c
@@ -0,0 +1,741 @@
1/*
2 * Streamzap Remote Control driver
3 *
4 * Copyright (c) 2005 Christoph Bartelmus <lirc@bartelmus.de>
5 * Copyright (c) 2010 Jarod Wilson <jarod@wilsonet.com>
6 *
7 * This driver was based on the work of Greg Wickham and Adrian
8 * Dewhurst. It was substantially rewritten to support correct signal
9 * gaps and now maintains a delay buffer, which is used to present
10 * consistent timing behaviour to user space applications. Without the
11 * delay buffer an ugly hack would be required in lircd, which can
12 * cause sluggish signal decoding in certain situations.
13 *
14 * Ported to in-kernel ir-core interface by Jarod Wilson
15 *
16 * This driver is based on the USB skeleton driver packaged with the
17 * kernel; copyright (C) 2001-2003 Greg Kroah-Hartman (greg@kroah.com)
18 *
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
23 *
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 */
33
34#include <linux/device.h>
35#include <linux/module.h>
36#include <linux/slab.h>
37#include <linux/usb.h>
38#include <linux/input.h>
39#include <media/ir-core.h>
40
41#define DRIVER_VERSION "1.60"
42#define DRIVER_NAME "streamzap"
43#define DRIVER_DESC "Streamzap Remote Control driver"
44
45#ifdef CONFIG_USB_DEBUG
46static int debug = 1;
47#else
48static int debug;
49#endif
50
51#define USB_STREAMZAP_VENDOR_ID 0x0e9c
52#define USB_STREAMZAP_PRODUCT_ID 0x0000
53
54/* table of devices that work with this driver */
55static struct usb_device_id streamzap_table[] = {
56 /* Streamzap Remote Control */
57 { USB_DEVICE(USB_STREAMZAP_VENDOR_ID, USB_STREAMZAP_PRODUCT_ID) },
58 /* Terminating entry */
59 { }
60};
61
62MODULE_DEVICE_TABLE(usb, streamzap_table);
63
64#define STREAMZAP_PULSE_MASK 0xf0
65#define STREAMZAP_SPACE_MASK 0x0f
66#define STREAMZAP_TIMEOUT 0xff
67#define STREAMZAP_RESOLUTION 256
68
69/* number of samples buffered */
70#define SZ_BUF_LEN 128
71
72enum StreamzapDecoderState {
73 PulseSpace,
74 FullPulse,
75 FullSpace,
76 IgnorePulse
77};
78
79/* structure to hold our device specific stuff */
80struct streamzap_ir {
81
82 /* ir-core */
83 struct ir_dev_props *props;
84 struct ir_raw_event rawir;
85
86 /* core device info */
87 struct device *dev;
88 struct input_dev *idev;
89
90 /* usb */
91 struct usb_device *usbdev;
92 struct usb_interface *interface;
93 struct usb_endpoint_descriptor *endpoint;
94 struct urb *urb_in;
95
96 /* buffer & dma */
97 unsigned char *buf_in;
98 dma_addr_t dma_in;
99 unsigned int buf_in_len;
100
101 /* timer used to support delay buffering */
102 struct timer_list delay_timer;
103 bool timer_running;
104 spinlock_t timer_lock;
105 struct timer_list flush_timer;
106 bool flush;
107
108 /* delay buffer */
109 struct kfifo fifo;
110 bool fifo_initialized;
111
112 /* track what state we're in */
113 enum StreamzapDecoderState decoder_state;
114 /* tracks whether we are currently receiving some signal */
115 bool idle;
116 /* sum of signal lengths received since signal start */
117 unsigned long sum;
118 /* start time of signal; necessary for gap tracking */
119 struct timeval signal_last;
120 struct timeval signal_start;
121 /* bool timeout_enabled; */
122
123 char name[128];
124 char phys[64];
125};
126
127
128/* local function prototypes */
129static int streamzap_probe(struct usb_interface *interface,
130 const struct usb_device_id *id);
131static void streamzap_disconnect(struct usb_interface *interface);
132static void streamzap_callback(struct urb *urb);
133static int streamzap_suspend(struct usb_interface *intf, pm_message_t message);
134static int streamzap_resume(struct usb_interface *intf);
135
136/* usb specific object needed to register this driver with the usb subsystem */
137static struct usb_driver streamzap_driver = {
138 .name = DRIVER_NAME,
139 .probe = streamzap_probe,
140 .disconnect = streamzap_disconnect,
141 .suspend = streamzap_suspend,
142 .resume = streamzap_resume,
143 .id_table = streamzap_table,
144};
145
146static void streamzap_stop_timer(struct streamzap_ir *sz)
147{
148 unsigned long flags;
149
150 spin_lock_irqsave(&sz->timer_lock, flags);
151 if (sz->timer_running) {
152 sz->timer_running = false;
153 spin_unlock_irqrestore(&sz->timer_lock, flags);
154 del_timer_sync(&sz->delay_timer);
155 } else {
156 spin_unlock_irqrestore(&sz->timer_lock, flags);
157 }
158}
159
160static void streamzap_flush_timeout(unsigned long arg)
161{
162 struct streamzap_ir *sz = (struct streamzap_ir *)arg;
163
164 dev_info(sz->dev, "%s: callback firing\n", __func__);
165
166 /* finally start accepting data */
167 sz->flush = false;
168}
169
170static void streamzap_delay_timeout(unsigned long arg)
171{
172 struct streamzap_ir *sz = (struct streamzap_ir *)arg;
173 struct ir_raw_event rawir = { .pulse = false, .duration = 0 };
174 unsigned long flags;
175 int len, ret;
176 static unsigned long delay;
177 bool wake = false;
178
179 /* deliver data every 10 ms */
180 delay = msecs_to_jiffies(10);
181
182 spin_lock_irqsave(&sz->timer_lock, flags);
183
184 if (kfifo_len(&sz->fifo) > 0) {
185 ret = kfifo_out(&sz->fifo, &rawir, sizeof(rawir));
186 if (ret != sizeof(rawir))
187 dev_err(sz->dev, "Problem w/kfifo_out...\n");
188 ir_raw_event_store(sz->idev, &rawir);
189 wake = true;
190 }
191
192 len = kfifo_len(&sz->fifo);
193 if (len > 0) {
194 while ((len < SZ_BUF_LEN / 2) &&
195 (len < SZ_BUF_LEN * sizeof(int))) {
196 ret = kfifo_out(&sz->fifo, &rawir, sizeof(rawir));
197 if (ret != sizeof(rawir))
198 dev_err(sz->dev, "Problem w/kfifo_out...\n");
199 ir_raw_event_store(sz->idev, &rawir);
200 wake = true;
201 len = kfifo_len(&sz->fifo);
202 }
203 if (sz->timer_running)
204 mod_timer(&sz->delay_timer, jiffies + delay);
205
206 } else {
207 sz->timer_running = false;
208 }
209
210 if (wake)
211 ir_raw_event_handle(sz->idev);
212
213 spin_unlock_irqrestore(&sz->timer_lock, flags);
214}
215
216static void streamzap_flush_delay_buffer(struct streamzap_ir *sz)
217{
218 struct ir_raw_event rawir = { .pulse = false, .duration = 0 };
219 bool wake = false;
220 int ret;
221
222 while (kfifo_len(&sz->fifo) > 0) {
223 ret = kfifo_out(&sz->fifo, &rawir, sizeof(rawir));
224 if (ret != sizeof(rawir))
225 dev_err(sz->dev, "Problem w/kfifo_out...\n");
226 ir_raw_event_store(sz->idev, &rawir);
227 wake = true;
228 }
229
230 if (wake)
231 ir_raw_event_handle(sz->idev);
232}
233
234static void sz_push(struct streamzap_ir *sz)
235{
236 struct ir_raw_event rawir = { .pulse = false, .duration = 0 };
237 unsigned long flags;
238 int ret;
239
240 spin_lock_irqsave(&sz->timer_lock, flags);
241 if (kfifo_len(&sz->fifo) >= sizeof(int) * SZ_BUF_LEN) {
242 ret = kfifo_out(&sz->fifo, &rawir, sizeof(rawir));
243 if (ret != sizeof(rawir))
244 dev_err(sz->dev, "Problem w/kfifo_out...\n");
245 ir_raw_event_store(sz->idev, &rawir);
246 }
247
248 kfifo_in(&sz->fifo, &sz->rawir, sizeof(rawir));
249
250 if (!sz->timer_running) {
251 sz->delay_timer.expires = jiffies + (HZ / 10);
252 add_timer(&sz->delay_timer);
253 sz->timer_running = true;
254 }
255
256 spin_unlock_irqrestore(&sz->timer_lock, flags);
257}
258
259static void sz_push_full_pulse(struct streamzap_ir *sz,
260 unsigned char value)
261{
262 if (sz->idle) {
263 long deltv;
264
265 sz->signal_last = sz->signal_start;
266 do_gettimeofday(&sz->signal_start);
267
268 deltv = sz->signal_start.tv_sec - sz->signal_last.tv_sec;
269 sz->rawir.pulse = false;
270 if (deltv > 15) {
271 /* really long time */
272 sz->rawir.duration = IR_MAX_DURATION;
273 } else {
274 sz->rawir.duration = (int)(deltv * 1000000 +
275 sz->signal_start.tv_usec -
276 sz->signal_last.tv_usec);
277 sz->rawir.duration -= sz->sum;
278 sz->rawir.duration *= 1000;
279 sz->rawir.duration &= IR_MAX_DURATION;
280 }
281 dev_dbg(sz->dev, "ls %u\n", sz->rawir.duration);
282 sz_push(sz);
283
284 sz->idle = 0;
285 sz->sum = 0;
286 }
287
288 sz->rawir.pulse = true;
289 sz->rawir.duration = ((int) value) * STREAMZAP_RESOLUTION;
290 sz->rawir.duration += STREAMZAP_RESOLUTION / 2;
291 sz->sum += sz->rawir.duration;
292 sz->rawir.duration *= 1000;
293 sz->rawir.duration &= IR_MAX_DURATION;
294 dev_dbg(sz->dev, "p %u\n", sz->rawir.duration);
295 sz_push(sz);
296}
297
298static void sz_push_half_pulse(struct streamzap_ir *sz,
299 unsigned char value)
300{
301 sz_push_full_pulse(sz, (value & STREAMZAP_PULSE_MASK) >> 4);
302}
303
304static void sz_push_full_space(struct streamzap_ir *sz,
305 unsigned char value)
306{
307 sz->rawir.pulse = false;
308 sz->rawir.duration = ((int) value) * STREAMZAP_RESOLUTION;
309 sz->rawir.duration += STREAMZAP_RESOLUTION / 2;
310 sz->sum += sz->rawir.duration;
311 sz->rawir.duration *= 1000;
312 dev_dbg(sz->dev, "s %u\n", sz->rawir.duration);
313 sz_push(sz);
314}
315
316static void sz_push_half_space(struct streamzap_ir *sz,
317 unsigned long value)
318{
319 sz_push_full_space(sz, value & STREAMZAP_SPACE_MASK);
320}
321
322/**
323 * streamzap_callback - usb IRQ handler callback
324 *
325 * This procedure is invoked on reception of data from
326 * the usb remote.
327 */
328static void streamzap_callback(struct urb *urb)
329{
330 struct streamzap_ir *sz;
331 unsigned int i;
332 int len;
333 #if 0
334 static int timeout = (((STREAMZAP_TIMEOUT * STREAMZAP_RESOLUTION) &
335 IR_MAX_DURATION) | 0x03000000);
336 #endif
337
338 if (!urb)
339 return;
340
341 sz = urb->context;
342 len = urb->actual_length;
343
344 switch (urb->status) {
345 case -ECONNRESET:
346 case -ENOENT:
347 case -ESHUTDOWN:
348 /*
349 * this urb is terminated, clean up.
350 * sz might already be invalid at this point
351 */
352 dev_err(sz->dev, "urb terminated, status: %d\n", urb->status);
353 return;
354 default:
355 break;
356 }
357
358 dev_dbg(sz->dev, "%s: received urb, len %d\n", __func__, len);
359 if (!sz->flush) {
360 for (i = 0; i < urb->actual_length; i++) {
361 dev_dbg(sz->dev, "%d: %x\n", i,
362 (unsigned char)sz->buf_in[i]);
363 switch (sz->decoder_state) {
364 case PulseSpace:
365 if ((sz->buf_in[i] & STREAMZAP_PULSE_MASK) ==
366 STREAMZAP_PULSE_MASK) {
367 sz->decoder_state = FullPulse;
368 continue;
369 } else if ((sz->buf_in[i] & STREAMZAP_SPACE_MASK)
370 == STREAMZAP_SPACE_MASK) {
371 sz_push_half_pulse(sz, sz->buf_in[i]);
372 sz->decoder_state = FullSpace;
373 continue;
374 } else {
375 sz_push_half_pulse(sz, sz->buf_in[i]);
376 sz_push_half_space(sz, sz->buf_in[i]);
377 }
378 break;
379 case FullPulse:
380 sz_push_full_pulse(sz, sz->buf_in[i]);
381 sz->decoder_state = IgnorePulse;
382 break;
383 case FullSpace:
384 if (sz->buf_in[i] == STREAMZAP_TIMEOUT) {
385 sz->idle = 1;
386 streamzap_stop_timer(sz);
387 #if 0
388 if (sz->timeout_enabled) {
389 sz->rawir.pulse = false;
390 sz->rawir.duration = timeout;
391 sz->rawir.duration *= 1000;
392 sz_push(sz);
393 }
394 #endif
395 streamzap_flush_delay_buffer(sz);
396 } else
397 sz_push_full_space(sz, sz->buf_in[i]);
398 sz->decoder_state = PulseSpace;
399 break;
400 case IgnorePulse:
401 if ((sz->buf_in[i]&STREAMZAP_SPACE_MASK) ==
402 STREAMZAP_SPACE_MASK) {
403 sz->decoder_state = FullSpace;
404 continue;
405 }
406 sz_push_half_space(sz, sz->buf_in[i]);
407 sz->decoder_state = PulseSpace;
408 break;
409 }
410 }
411 }
412
413 usb_submit_urb(urb, GFP_ATOMIC);
414
415 return;
416}
417
418static struct input_dev *streamzap_init_input_dev(struct streamzap_ir *sz)
419{
420 struct input_dev *idev;
421 struct ir_dev_props *props;
422 struct device *dev = sz->dev;
423 int ret;
424
425 idev = input_allocate_device();
426 if (!idev) {
427 dev_err(dev, "remote input dev allocation failed\n");
428 goto idev_alloc_failed;
429 }
430
431 props = kzalloc(sizeof(struct ir_dev_props), GFP_KERNEL);
432 if (!props) {
433 dev_err(dev, "remote ir dev props allocation failed\n");
434 goto props_alloc_failed;
435 }
436
437 snprintf(sz->name, sizeof(sz->name), "Streamzap PC Remote Infrared "
438 "Receiver (%04x:%04x)",
439 le16_to_cpu(sz->usbdev->descriptor.idVendor),
440 le16_to_cpu(sz->usbdev->descriptor.idProduct));
441
442 idev->name = sz->name;
443 usb_make_path(sz->usbdev, sz->phys, sizeof(sz->phys));
444 strlcat(sz->phys, "/input0", sizeof(sz->phys));
445 idev->phys = sz->phys;
446
447 props->priv = sz;
448 props->driver_type = RC_DRIVER_IR_RAW;
449 /* FIXME: not sure about supported protocols, check on this */
450 props->allowed_protos = IR_TYPE_RC5 | IR_TYPE_RC6;
451
452 sz->props = props;
453
454 ret = ir_input_register(idev, RC_MAP_RC5_STREAMZAP, props, DRIVER_NAME);
455 if (ret < 0) {
456 dev_err(dev, "remote input device register failed\n");
457 goto irdev_failed;
458 }
459
460 return idev;
461
462irdev_failed:
463 kfree(props);
464props_alloc_failed:
465 input_free_device(idev);
466idev_alloc_failed:
467 return NULL;
468}
469
470static int streamzap_delay_buf_init(struct streamzap_ir *sz)
471{
472 int ret;
473
474 ret = kfifo_alloc(&sz->fifo, sizeof(int) * SZ_BUF_LEN,
475 GFP_KERNEL);
476 if (ret == 0)
477 sz->fifo_initialized = 1;
478
479 return ret;
480}
481
482static void streamzap_start_flush_timer(struct streamzap_ir *sz)
483{
484 sz->flush_timer.expires = jiffies + HZ;
485 sz->flush = true;
486 add_timer(&sz->flush_timer);
487
488 sz->urb_in->dev = sz->usbdev;
489 if (usb_submit_urb(sz->urb_in, GFP_ATOMIC))
490 dev_err(sz->dev, "urb submit failed\n");
491}
492
493/**
494 * streamzap_probe
495 *
496 * Called by usb-core to associated with a candidate device
497 * On any failure the return value is the ERROR
498 * On success return 0
499 */
500static int __devinit streamzap_probe(struct usb_interface *intf,
501 const struct usb_device_id *id)
502{
503 struct usb_device *usbdev = interface_to_usbdev(intf);
504 struct usb_host_interface *iface_host;
505 struct streamzap_ir *sz = NULL;
506 char buf[63], name[128] = "";
507 int retval = -ENOMEM;
508 int pipe, maxp;
509
510 /* Allocate space for device driver specific data */
511 sz = kzalloc(sizeof(struct streamzap_ir), GFP_KERNEL);
512 if (!sz)
513 return -ENOMEM;
514
515 sz->usbdev = usbdev;
516 sz->interface = intf;
517
518 /* Check to ensure endpoint information matches requirements */
519 iface_host = intf->cur_altsetting;
520
521 if (iface_host->desc.bNumEndpoints != 1) {
522 dev_err(&intf->dev, "%s: Unexpected desc.bNumEndpoints (%d)\n",
523 __func__, iface_host->desc.bNumEndpoints);
524 retval = -ENODEV;
525 goto free_sz;
526 }
527
528 sz->endpoint = &(iface_host->endpoint[0].desc);
529 if ((sz->endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK)
530 != USB_DIR_IN) {
531 dev_err(&intf->dev, "%s: endpoint doesn't match input device "
532 "02%02x\n", __func__, sz->endpoint->bEndpointAddress);
533 retval = -ENODEV;
534 goto free_sz;
535 }
536
537 if ((sz->endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
538 != USB_ENDPOINT_XFER_INT) {
539 dev_err(&intf->dev, "%s: endpoint attributes don't match xfer "
540 "02%02x\n", __func__, sz->endpoint->bmAttributes);
541 retval = -ENODEV;
542 goto free_sz;
543 }
544
545 pipe = usb_rcvintpipe(usbdev, sz->endpoint->bEndpointAddress);
546 maxp = usb_maxpacket(usbdev, pipe, usb_pipeout(pipe));
547
548 if (maxp == 0) {
549 dev_err(&intf->dev, "%s: endpoint Max Packet Size is 0!?!\n",
550 __func__);
551 retval = -ENODEV;
552 goto free_sz;
553 }
554
555 /* Allocate the USB buffer and IRQ URB */
556 sz->buf_in = usb_alloc_coherent(usbdev, maxp, GFP_ATOMIC, &sz->dma_in);
557 if (!sz->buf_in)
558 goto free_sz;
559
560 sz->urb_in = usb_alloc_urb(0, GFP_KERNEL);
561 if (!sz->urb_in)
562 goto free_buf_in;
563
564 sz->dev = &intf->dev;
565 sz->buf_in_len = maxp;
566
567 if (usbdev->descriptor.iManufacturer
568 && usb_string(usbdev, usbdev->descriptor.iManufacturer,
569 buf, sizeof(buf)) > 0)
570 strlcpy(name, buf, sizeof(name));
571
572 if (usbdev->descriptor.iProduct
573 && usb_string(usbdev, usbdev->descriptor.iProduct,
574 buf, sizeof(buf)) > 0)
575 snprintf(name + strlen(name), sizeof(name) - strlen(name),
576 " %s", buf);
577
578 retval = streamzap_delay_buf_init(sz);
579 if (retval) {
580 dev_err(&intf->dev, "%s: delay buffer init failed\n", __func__);
581 goto free_urb_in;
582 }
583
584 sz->idev = streamzap_init_input_dev(sz);
585 if (!sz->idev)
586 goto input_dev_fail;
587
588 sz->idle = true;
589 sz->decoder_state = PulseSpace;
590 #if 0
591 /* not yet supported, depends on patches from maxim */
592 /* see also: LIRC_GET_REC_RESOLUTION and LIRC_SET_REC_TIMEOUT */
593 sz->timeout_enabled = false;
594 sz->min_timeout = STREAMZAP_TIMEOUT * STREAMZAP_RESOLUTION * 1000;
595 sz->max_timeout = STREAMZAP_TIMEOUT * STREAMZAP_RESOLUTION * 1000;
596 #endif
597
598 init_timer(&sz->delay_timer);
599 sz->delay_timer.function = streamzap_delay_timeout;
600 sz->delay_timer.data = (unsigned long)sz;
601 spin_lock_init(&sz->timer_lock);
602
603 init_timer(&sz->flush_timer);
604 sz->flush_timer.function = streamzap_flush_timeout;
605 sz->flush_timer.data = (unsigned long)sz;
606
607 do_gettimeofday(&sz->signal_start);
608
609 /* Complete final initialisations */
610 usb_fill_int_urb(sz->urb_in, usbdev, pipe, sz->buf_in,
611 maxp, (usb_complete_t)streamzap_callback,
612 sz, sz->endpoint->bInterval);
613 sz->urb_in->transfer_dma = sz->dma_in;
614 sz->urb_in->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
615
616 usb_set_intfdata(intf, sz);
617
618 streamzap_start_flush_timer(sz);
619
620 dev_info(sz->dev, "Registered %s on usb%d:%d\n", name,
621 usbdev->bus->busnum, usbdev->devnum);
622
623 return 0;
624
625input_dev_fail:
626 kfifo_free(&sz->fifo);
627free_urb_in:
628 usb_free_urb(sz->urb_in);
629free_buf_in:
630 usb_free_coherent(usbdev, maxp, sz->buf_in, sz->dma_in);
631free_sz:
632 kfree(sz);
633
634 return retval;
635}
636
637/**
638 * streamzap_disconnect
639 *
640 * Called by the usb core when the device is removed from the system.
641 *
642 * This routine guarantees that the driver will not submit any more urbs
643 * by clearing dev->usbdev. It is also supposed to terminate any currently
644 * active urbs. Unfortunately, usb_bulk_msg(), used in streamzap_read(),
645 * does not provide any way to do this.
646 */
647static void streamzap_disconnect(struct usb_interface *interface)
648{
649 struct streamzap_ir *sz = usb_get_intfdata(interface);
650 struct usb_device *usbdev = interface_to_usbdev(interface);
651
652 usb_set_intfdata(interface, NULL);
653
654 if (!sz)
655 return;
656
657 if (sz->flush) {
658 sz->flush = false;
659 del_timer_sync(&sz->flush_timer);
660 }
661
662 streamzap_stop_timer(sz);
663
664 sz->usbdev = NULL;
665 ir_input_unregister(sz->idev);
666 usb_kill_urb(sz->urb_in);
667 usb_free_urb(sz->urb_in);
668 usb_free_coherent(usbdev, sz->buf_in_len, sz->buf_in, sz->dma_in);
669
670 kfree(sz);
671}
672
673static int streamzap_suspend(struct usb_interface *intf, pm_message_t message)
674{
675 struct streamzap_ir *sz = usb_get_intfdata(intf);
676
677 if (sz->flush) {
678 sz->flush = false;
679 del_timer_sync(&sz->flush_timer);
680 }
681
682 streamzap_stop_timer(sz);
683
684 usb_kill_urb(sz->urb_in);
685
686 return 0;
687}
688
689static int streamzap_resume(struct usb_interface *intf)
690{
691 struct streamzap_ir *sz = usb_get_intfdata(intf);
692
693 if (sz->fifo_initialized)
694 kfifo_reset(&sz->fifo);
695
696 sz->flush_timer.expires = jiffies + HZ;
697 sz->flush = true;
698 add_timer(&sz->flush_timer);
699
700 if (usb_submit_urb(sz->urb_in, GFP_ATOMIC)) {
701 dev_err(sz->dev, "Error sumbiting urb\n");
702 return -EIO;
703 }
704
705 return 0;
706}
707
708/**
709 * streamzap_init
710 */
711static int __init streamzap_init(void)
712{
713 int ret;
714
715 /* register this driver with the USB subsystem */
716 ret = usb_register(&streamzap_driver);
717 if (ret < 0)
718 printk(KERN_ERR DRIVER_NAME ": usb register failed, "
719 "result = %d\n", ret);
720
721 return ret;
722}
723
724/**
725 * streamzap_exit
726 */
727static void __exit streamzap_exit(void)
728{
729 usb_deregister(&streamzap_driver);
730}
731
732
733module_init(streamzap_init);
734module_exit(streamzap_exit);
735
736MODULE_AUTHOR("Jarod Wilson <jarod@wilsonet.com>");
737MODULE_DESCRIPTION(DRIVER_DESC);
738MODULE_LICENSE("GPL");
739
740module_param(debug, bool, S_IRUGO | S_IWUSR);
741MODULE_PARM_DESC(debug, "Enable debugging messages");
diff --git a/drivers/media/common/tuners/Kconfig b/drivers/media/common/tuners/Kconfig
index 409a4261e5b5..b3ed5daaacf2 100644
--- a/drivers/media/common/tuners/Kconfig
+++ b/drivers/media/common/tuners/Kconfig
@@ -34,7 +34,7 @@ config MEDIA_TUNER
34menuconfig MEDIA_TUNER_CUSTOMISE 34menuconfig MEDIA_TUNER_CUSTOMISE
35 bool "Customize analog and hybrid tuner modules to build" 35 bool "Customize analog and hybrid tuner modules to build"
36 depends on MEDIA_TUNER 36 depends on MEDIA_TUNER
37 default n 37 default y if EMBEDDED
38 help 38 help
39 This allows the user to deselect tuner drivers unnecessary 39 This allows the user to deselect tuner drivers unnecessary
40 for their hardware from the build. Use this option with care 40 for their hardware from the build. Use this option with care
diff --git a/drivers/media/dvb/bt8xx/dst.c b/drivers/media/dvb/bt8xx/dst.c
index 248a2a9d8416..caa4e18ed1c1 100644
--- a/drivers/media/dvb/bt8xx/dst.c
+++ b/drivers/media/dvb/bt8xx/dst.c
@@ -1763,7 +1763,15 @@ static struct dvb_frontend_ops dst_dvbt_ops = {
1763 .frequency_min = 137000000, 1763 .frequency_min = 137000000,
1764 .frequency_max = 858000000, 1764 .frequency_max = 858000000,
1765 .frequency_stepsize = 166667, 1765 .frequency_stepsize = 166667,
1766 .caps = FE_CAN_FEC_AUTO | FE_CAN_QAM_AUTO | FE_CAN_TRANSMISSION_MODE_AUTO | FE_CAN_GUARD_INTERVAL_AUTO 1766 .caps = FE_CAN_FEC_AUTO |
1767 FE_CAN_QAM_AUTO |
1768 FE_CAN_QAM_16 |
1769 FE_CAN_QAM_32 |
1770 FE_CAN_QAM_64 |
1771 FE_CAN_QAM_128 |
1772 FE_CAN_QAM_256 |
1773 FE_CAN_TRANSMISSION_MODE_AUTO |
1774 FE_CAN_GUARD_INTERVAL_AUTO
1767 }, 1775 },
1768 1776
1769 .release = dst_release, 1777 .release = dst_release,
diff --git a/drivers/media/dvb/dm1105/Kconfig b/drivers/media/dvb/dm1105/Kconfig
index 695239227cb7..a6ceb08f1183 100644
--- a/drivers/media/dvb/dm1105/Kconfig
+++ b/drivers/media/dvb/dm1105/Kconfig
@@ -9,7 +9,7 @@ config DVB_DM1105
9 select DVB_CX24116 if !DVB_FE_CUSTOMISE 9 select DVB_CX24116 if !DVB_FE_CUSTOMISE
10 select DVB_SI21XX if !DVB_FE_CUSTOMISE 10 select DVB_SI21XX if !DVB_FE_CUSTOMISE
11 select DVB_DS3000 if !DVB_FE_CUSTOMISE 11 select DVB_DS3000 if !DVB_FE_CUSTOMISE
12 select VIDEO_IR 12 depends on VIDEO_IR
13 help 13 help
14 Support for cards based on the SDMC DM1105 PCI chip like 14 Support for cards based on the SDMC DM1105 PCI chip like
15 DvbWorld 2002 15 DvbWorld 2002
diff --git a/drivers/media/dvb/dvb-usb/Kconfig b/drivers/media/dvb/dvb-usb/Kconfig
index 553b48ac1919..fdc19bba2128 100644
--- a/drivers/media/dvb/dvb-usb/Kconfig
+++ b/drivers/media/dvb/dvb-usb/Kconfig
@@ -1,6 +1,6 @@
1config DVB_USB 1config DVB_USB
2 tristate "Support for various USB DVB devices" 2 tristate "Support for various USB DVB devices"
3 depends on DVB_CORE && USB && I2C && INPUT 3 depends on DVB_CORE && USB && I2C && IR_CORE
4 help 4 help
5 By enabling this you will be able to choose the various supported 5 By enabling this you will be able to choose the various supported
6 USB1.1 and USB2.0 DVB devices. 6 USB1.1 and USB2.0 DVB devices.
diff --git a/drivers/media/dvb/frontends/Kconfig b/drivers/media/dvb/frontends/Kconfig
index 51d578a758a7..b5f6a04f9c12 100644
--- a/drivers/media/dvb/frontends/Kconfig
+++ b/drivers/media/dvb/frontends/Kconfig
@@ -1,7 +1,7 @@
1config DVB_FE_CUSTOMISE 1config DVB_FE_CUSTOMISE
2 bool "Customise the frontend modules to build" 2 bool "Customise the frontend modules to build"
3 depends on DVB_CORE 3 depends on DVB_CORE
4 default N 4 default y if EMBEDDED
5 help 5 help
6 This allows the user to select/deselect frontend drivers for their 6 This allows the user to select/deselect frontend drivers for their
7 hardware from the build. 7 hardware from the build.
diff --git a/drivers/media/dvb/siano/Kconfig b/drivers/media/dvb/siano/Kconfig
index 85a222c4eaa0..e520bceee0af 100644
--- a/drivers/media/dvb/siano/Kconfig
+++ b/drivers/media/dvb/siano/Kconfig
@@ -4,7 +4,7 @@
4 4
5config SMS_SIANO_MDTV 5config SMS_SIANO_MDTV
6 tristate "Siano SMS1xxx based MDTV receiver" 6 tristate "Siano SMS1xxx based MDTV receiver"
7 depends on DVB_CORE && INPUT && HAS_DMA 7 depends on DVB_CORE && IR_CORE && HAS_DMA
8 ---help--- 8 ---help---
9 Choose Y or M here if you have MDTV receiver with a Siano chipset. 9 Choose Y or M here if you have MDTV receiver with a Siano chipset.
10 10
diff --git a/drivers/media/dvb/siano/smscoreapi.c b/drivers/media/dvb/siano/smscoreapi.c
index 7f2c94a15ab1..d93468cd3a85 100644
--- a/drivers/media/dvb/siano/smscoreapi.c
+++ b/drivers/media/dvb/siano/smscoreapi.c
@@ -1113,9 +1113,11 @@ struct smscore_buffer_t *smscore_getbuffer(struct smscore_device_t *coredev)
1113 */ 1113 */
1114 1114
1115 prepare_to_wait(&coredev->buffer_mng_waitq, &wait, TASK_INTERRUPTIBLE); 1115 prepare_to_wait(&coredev->buffer_mng_waitq, &wait, TASK_INTERRUPTIBLE);
1116 1116 if (list_empty(&coredev->buffers)) {
1117 if (list_empty(&coredev->buffers)) 1117 spin_unlock_irqrestore(&coredev->bufferslock, flags);
1118 schedule(); 1118 schedule();
1119 spin_lock_irqsave(&coredev->bufferslock, flags);
1120 }
1119 1121
1120 finish_wait(&coredev->buffer_mng_waitq, &wait); 1122 finish_wait(&coredev->buffer_mng_waitq, &wait);
1121 1123
diff --git a/drivers/media/dvb/ttpci/Kconfig b/drivers/media/dvb/ttpci/Kconfig
index 32a7ec65ec42..debea8d1d31c 100644
--- a/drivers/media/dvb/ttpci/Kconfig
+++ b/drivers/media/dvb/ttpci/Kconfig
@@ -98,7 +98,7 @@ config DVB_BUDGET_CI
98 select DVB_LNBP21 if !DVB_FE_CUSTOMISE 98 select DVB_LNBP21 if !DVB_FE_CUSTOMISE
99 select DVB_TDA10023 if !DVB_FE_CUSTOMISE 99 select DVB_TDA10023 if !DVB_FE_CUSTOMISE
100 select MEDIA_TUNER_TDA827X if !MEDIA_TUNER_CUSTOMISE 100 select MEDIA_TUNER_TDA827X if !MEDIA_TUNER_CUSTOMISE
101 select VIDEO_IR 101 depends on VIDEO_IR
102 help 102 help
103 Support for simple SAA7146 based DVB cards 103 Support for simple SAA7146 based DVB cards
104 (so called Budget- or Nova-PCI cards) without onboard 104 (so called Budget- or Nova-PCI cards) without onboard
diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index 2e15903b976d..f6e4d0475351 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -83,7 +83,7 @@ config VIDEO_FIXED_MINOR_RANGES
83 83
84config VIDEO_HELPER_CHIPS_AUTO 84config VIDEO_HELPER_CHIPS_AUTO
85 bool "Autoselect pertinent encoders/decoders and other helper chips" 85 bool "Autoselect pertinent encoders/decoders and other helper chips"
86 default y 86 default y if !EMBEDDED
87 ---help--- 87 ---help---
88 Most video cards may require additional modules to encode or 88 Most video cards may require additional modules to encode or
89 decode audio/video standards. This option will autoselect 89 decode audio/video standards. This option will autoselect
@@ -792,10 +792,11 @@ config SOC_CAMERA_MT9M001
792 and colour models. 792 and colour models.
793 793
794config SOC_CAMERA_MT9M111 794config SOC_CAMERA_MT9M111
795 tristate "mt9m111 and mt9m112 support" 795 tristate "mt9m111, mt9m112 and mt9m131 support"
796 depends on SOC_CAMERA && I2C 796 depends on SOC_CAMERA && I2C
797 help 797 help
798 This driver supports MT9M111 and MT9M112 cameras from Micron 798 This driver supports MT9M111, MT9M112 and MT9M131 cameras from
799 Micron/Aptina
799 800
800config SOC_CAMERA_MT9T031 801config SOC_CAMERA_MT9T031
801 tristate "mt9t031 support" 802 tristate "mt9t031 support"
@@ -1016,4 +1017,13 @@ config VIDEO_MEM2MEM_TESTDEV
1016 This is a virtual test device for the memory-to-memory driver 1017 This is a virtual test device for the memory-to-memory driver
1017 framework. 1018 framework.
1018 1019
1020config VIDEO_SAMSUNG_S5P_FIMC
1021 tristate "Samsung S5P FIMC (video postprocessor) driver"
1022 depends on VIDEO_DEV && VIDEO_V4L2 && PLAT_S5P
1023 select VIDEOBUF_DMA_CONTIG
1024 select V4L2_MEM2MEM_DEV
1025 help
1026 This is a v4l2 driver for the S5P camera interface
1027 (video postprocessor)
1028
1019endif # V4L_MEM2MEM_DRIVERS 1029endif # V4L_MEM2MEM_DRIVERS
diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile
index 1051ecc602e7..40f98fba5f88 100644
--- a/drivers/media/video/Makefile
+++ b/drivers/media/video/Makefile
@@ -11,7 +11,7 @@ stkwebcam-objs := stk-webcam.o stk-sensor.o
11omap2cam-objs := omap24xxcam.o omap24xxcam-dma.o 11omap2cam-objs := omap24xxcam.o omap24xxcam-dma.o
12 12
13videodev-objs := v4l2-dev.o v4l2-ioctl.o v4l2-device.o v4l2-fh.o \ 13videodev-objs := v4l2-dev.o v4l2-ioctl.o v4l2-device.o v4l2-fh.o \
14 v4l2-event.o 14 v4l2-event.o v4l2-ctrls.o
15 15
16# V4L2 core modules 16# V4L2 core modules
17 17
@@ -163,6 +163,7 @@ obj-$(CONFIG_VIDEO_MX3) += mx3_camera.o
163obj-$(CONFIG_VIDEO_PXA27x) += pxa_camera.o 163obj-$(CONFIG_VIDEO_PXA27x) += pxa_camera.o
164obj-$(CONFIG_VIDEO_SH_MOBILE_CSI2) += sh_mobile_csi2.o 164obj-$(CONFIG_VIDEO_SH_MOBILE_CSI2) += sh_mobile_csi2.o
165obj-$(CONFIG_VIDEO_SH_MOBILE_CEU) += sh_mobile_ceu_camera.o 165obj-$(CONFIG_VIDEO_SH_MOBILE_CEU) += sh_mobile_ceu_camera.o
166obj-$(CONFIG_VIDEO_SAMSUNG_S5P_FIMC) += s5p-fimc/
166 167
167obj-$(CONFIG_ARCH_DAVINCI) += davinci/ 168obj-$(CONFIG_ARCH_DAVINCI) += davinci/
168 169
diff --git a/drivers/media/video/bt8xx/Kconfig b/drivers/media/video/bt8xx/Kconfig
index 3077c45015f5..1a4a89fdf767 100644
--- a/drivers/media/video/bt8xx/Kconfig
+++ b/drivers/media/video/bt8xx/Kconfig
@@ -4,7 +4,7 @@ config VIDEO_BT848
4 select I2C_ALGOBIT 4 select I2C_ALGOBIT
5 select VIDEO_BTCX 5 select VIDEO_BTCX
6 select VIDEOBUF_DMA_SG 6 select VIDEOBUF_DMA_SG
7 select VIDEO_IR 7 depends on VIDEO_IR
8 select VIDEO_TUNER 8 select VIDEO_TUNER
9 select VIDEO_TVEEPROM 9 select VIDEO_TVEEPROM
10 select VIDEO_MSP3400 if VIDEO_HELPER_CHIPS_AUTO 10 select VIDEO_MSP3400 if VIDEO_HELPER_CHIPS_AUTO
diff --git a/drivers/media/video/bt8xx/bttv-i2c.c b/drivers/media/video/bt8xx/bttv-i2c.c
index 407fa61e4cda..685d6597ee79 100644
--- a/drivers/media/video/bt8xx/bttv-i2c.c
+++ b/drivers/media/video/bt8xx/bttv-i2c.c
@@ -411,7 +411,7 @@ void __devinit init_bttv_i2c_ir(struct bttv *btv)
411 411
412 memset(&info, 0, sizeof(struct i2c_board_info)); 412 memset(&info, 0, sizeof(struct i2c_board_info));
413 strlcpy(info.type, "ir_video", I2C_NAME_SIZE); 413 strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
414 i2c_new_probed_device(&btv->c.i2c_adap, &info, addr_list); 414 i2c_new_probed_device(&btv->c.i2c_adap, &info, addr_list, NULL);
415 } 415 }
416} 416}
417 417
diff --git a/drivers/media/video/cs53l32a.c b/drivers/media/video/cs53l32a.c
index 3cc135a98d82..cc9e84d75ea7 100644
--- a/drivers/media/video/cs53l32a.c
+++ b/drivers/media/video/cs53l32a.c
@@ -26,10 +26,10 @@
26#include <linux/ioctl.h> 26#include <linux/ioctl.h>
27#include <asm/uaccess.h> 27#include <asm/uaccess.h>
28#include <linux/i2c.h> 28#include <linux/i2c.h>
29#include <linux/i2c-id.h>
30#include <linux/videodev2.h> 29#include <linux/videodev2.h>
31#include <media/v4l2-device.h> 30#include <media/v4l2-device.h>
32#include <media/v4l2-chip-ident.h> 31#include <media/v4l2-chip-ident.h>
32#include <media/v4l2-ctrls.h>
33#include <media/v4l2-i2c-drv.h> 33#include <media/v4l2-i2c-drv.h>
34 34
35MODULE_DESCRIPTION("i2c device driver for cs53l32a Audio ADC"); 35MODULE_DESCRIPTION("i2c device driver for cs53l32a Audio ADC");
@@ -43,6 +43,21 @@ module_param(debug, bool, 0644);
43MODULE_PARM_DESC(debug, "Debugging messages, 0=Off (default), 1=On"); 43MODULE_PARM_DESC(debug, "Debugging messages, 0=Off (default), 1=On");
44 44
45 45
46struct cs53l32a_state {
47 struct v4l2_subdev sd;
48 struct v4l2_ctrl_handler hdl;
49};
50
51static inline struct cs53l32a_state *to_state(struct v4l2_subdev *sd)
52{
53 return container_of(sd, struct cs53l32a_state, sd);
54}
55
56static inline struct v4l2_subdev *to_sd(struct v4l2_ctrl *ctrl)
57{
58 return &container_of(ctrl->handler, struct cs53l32a_state, hdl)->sd;
59}
60
46/* ----------------------------------------------------------------------- */ 61/* ----------------------------------------------------------------------- */
47 62
48static int cs53l32a_write(struct v4l2_subdev *sd, u8 reg, u8 value) 63static int cs53l32a_write(struct v4l2_subdev *sd, u8 reg, u8 value)
@@ -74,31 +89,20 @@ static int cs53l32a_s_routing(struct v4l2_subdev *sd,
74 return 0; 89 return 0;
75} 90}
76 91
77static int cs53l32a_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) 92static int cs53l32a_s_ctrl(struct v4l2_ctrl *ctrl)
78{ 93{
79 if (ctrl->id == V4L2_CID_AUDIO_MUTE) { 94 struct v4l2_subdev *sd = to_sd(ctrl);
80 ctrl->value = (cs53l32a_read(sd, 0x03) & 0xc0) != 0;
81 return 0;
82 }
83 if (ctrl->id != V4L2_CID_AUDIO_VOLUME)
84 return -EINVAL;
85 ctrl->value = (s8)cs53l32a_read(sd, 0x04);
86 return 0;
87}
88 95
89static int cs53l32a_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) 96 switch (ctrl->id) {
90{ 97 case V4L2_CID_AUDIO_MUTE:
91 if (ctrl->id == V4L2_CID_AUDIO_MUTE) { 98 cs53l32a_write(sd, 0x03, ctrl->val ? 0xf0 : 0x30);
92 cs53l32a_write(sd, 0x03, ctrl->value ? 0xf0 : 0x30); 99 return 0;
100 case V4L2_CID_AUDIO_VOLUME:
101 cs53l32a_write(sd, 0x04, (u8)ctrl->val);
102 cs53l32a_write(sd, 0x05, (u8)ctrl->val);
93 return 0; 103 return 0;
94 } 104 }
95 if (ctrl->id != V4L2_CID_AUDIO_VOLUME) 105 return -EINVAL;
96 return -EINVAL;
97 if (ctrl->value > 12 || ctrl->value < -96)
98 return -EINVAL;
99 cs53l32a_write(sd, 0x04, (u8) ctrl->value);
100 cs53l32a_write(sd, 0x05, (u8) ctrl->value);
101 return 0;
102} 106}
103 107
104static int cs53l32a_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip) 108static int cs53l32a_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
@@ -111,23 +115,30 @@ static int cs53l32a_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_id
111 115
112static int cs53l32a_log_status(struct v4l2_subdev *sd) 116static int cs53l32a_log_status(struct v4l2_subdev *sd)
113{ 117{
118 struct cs53l32a_state *state = to_state(sd);
114 u8 v = cs53l32a_read(sd, 0x01); 119 u8 v = cs53l32a_read(sd, 0x01);
115 u8 m = cs53l32a_read(sd, 0x03);
116 s8 vol = cs53l32a_read(sd, 0x04);
117 120
118 v4l2_info(sd, "Input: %d%s\n", (v >> 4) & 3, 121 v4l2_info(sd, "Input: %d\n", (v >> 4) & 3);
119 (m & 0xC0) ? " (muted)" : ""); 122 v4l2_ctrl_handler_log_status(&state->hdl, sd->name);
120 v4l2_info(sd, "Volume: %d dB\n", vol);
121 return 0; 123 return 0;
122} 124}
123 125
124/* ----------------------------------------------------------------------- */ 126/* ----------------------------------------------------------------------- */
125 127
128static const struct v4l2_ctrl_ops cs53l32a_ctrl_ops = {
129 .s_ctrl = cs53l32a_s_ctrl,
130};
131
126static const struct v4l2_subdev_core_ops cs53l32a_core_ops = { 132static const struct v4l2_subdev_core_ops cs53l32a_core_ops = {
127 .log_status = cs53l32a_log_status, 133 .log_status = cs53l32a_log_status,
128 .g_chip_ident = cs53l32a_g_chip_ident, 134 .g_chip_ident = cs53l32a_g_chip_ident,
129 .g_ctrl = cs53l32a_g_ctrl, 135 .g_ext_ctrls = v4l2_subdev_g_ext_ctrls,
130 .s_ctrl = cs53l32a_s_ctrl, 136 .try_ext_ctrls = v4l2_subdev_try_ext_ctrls,
137 .s_ext_ctrls = v4l2_subdev_s_ext_ctrls,
138 .g_ctrl = v4l2_subdev_g_ctrl,
139 .s_ctrl = v4l2_subdev_s_ctrl,
140 .queryctrl = v4l2_subdev_queryctrl,
141 .querymenu = v4l2_subdev_querymenu,
131}; 142};
132 143
133static const struct v4l2_subdev_audio_ops cs53l32a_audio_ops = { 144static const struct v4l2_subdev_audio_ops cs53l32a_audio_ops = {
@@ -151,6 +162,7 @@ static const struct v4l2_subdev_ops cs53l32a_ops = {
151static int cs53l32a_probe(struct i2c_client *client, 162static int cs53l32a_probe(struct i2c_client *client,
152 const struct i2c_device_id *id) 163 const struct i2c_device_id *id)
153{ 164{
165 struct cs53l32a_state *state;
154 struct v4l2_subdev *sd; 166 struct v4l2_subdev *sd;
155 int i; 167 int i;
156 168
@@ -164,9 +176,10 @@ static int cs53l32a_probe(struct i2c_client *client,
164 v4l_info(client, "chip found @ 0x%x (%s)\n", 176 v4l_info(client, "chip found @ 0x%x (%s)\n",
165 client->addr << 1, client->adapter->name); 177 client->addr << 1, client->adapter->name);
166 178
167 sd = kmalloc(sizeof(struct v4l2_subdev), GFP_KERNEL); 179 state = kzalloc(sizeof(struct cs53l32a_state), GFP_KERNEL);
168 if (sd == NULL) 180 if (state == NULL)
169 return -ENOMEM; 181 return -ENOMEM;
182 sd = &state->sd;
170 v4l2_i2c_subdev_init(sd, client, &cs53l32a_ops); 183 v4l2_i2c_subdev_init(sd, client, &cs53l32a_ops);
171 184
172 for (i = 1; i <= 7; i++) { 185 for (i = 1; i <= 7; i++) {
@@ -175,15 +188,29 @@ static int cs53l32a_probe(struct i2c_client *client,
175 v4l2_dbg(1, debug, sd, "Read Reg %d %02x\n", i, v); 188 v4l2_dbg(1, debug, sd, "Read Reg %d %02x\n", i, v);
176 } 189 }
177 190
191 v4l2_ctrl_handler_init(&state->hdl, 2);
192 v4l2_ctrl_new_std(&state->hdl, &cs53l32a_ctrl_ops,
193 V4L2_CID_AUDIO_VOLUME, -96, 12, 1, 0);
194 v4l2_ctrl_new_std(&state->hdl, &cs53l32a_ctrl_ops,
195 V4L2_CID_AUDIO_MUTE, 0, 1, 1, 0);
196 sd->ctrl_handler = &state->hdl;
197 if (state->hdl.error) {
198 int err = state->hdl.error;
199
200 v4l2_ctrl_handler_free(&state->hdl);
201 kfree(state);
202 return err;
203 }
204
178 /* Set cs53l32a internal register for Adaptec 2010/2410 setup */ 205 /* Set cs53l32a internal register for Adaptec 2010/2410 setup */
179 206
180 cs53l32a_write(sd, 0x01, (u8) 0x21); 207 cs53l32a_write(sd, 0x01, 0x21);
181 cs53l32a_write(sd, 0x02, (u8) 0x29); 208 cs53l32a_write(sd, 0x02, 0x29);
182 cs53l32a_write(sd, 0x03, (u8) 0x30); 209 cs53l32a_write(sd, 0x03, 0x30);
183 cs53l32a_write(sd, 0x04, (u8) 0x00); 210 cs53l32a_write(sd, 0x04, 0x00);
184 cs53l32a_write(sd, 0x05, (u8) 0x00); 211 cs53l32a_write(sd, 0x05, 0x00);
185 cs53l32a_write(sd, 0x06, (u8) 0x00); 212 cs53l32a_write(sd, 0x06, 0x00);
186 cs53l32a_write(sd, 0x07, (u8) 0x00); 213 cs53l32a_write(sd, 0x07, 0x00);
187 214
188 /* Display results, should be 0x21,0x29,0x30,0x00,0x00,0x00,0x00 */ 215 /* Display results, should be 0x21,0x29,0x30,0x00,0x00,0x00,0x00 */
189 216
@@ -198,9 +225,11 @@ static int cs53l32a_probe(struct i2c_client *client,
198static int cs53l32a_remove(struct i2c_client *client) 225static int cs53l32a_remove(struct i2c_client *client)
199{ 226{
200 struct v4l2_subdev *sd = i2c_get_clientdata(client); 227 struct v4l2_subdev *sd = i2c_get_clientdata(client);
228 struct cs53l32a_state *state = to_state(sd);
201 229
202 v4l2_device_unregister_subdev(sd); 230 v4l2_device_unregister_subdev(sd);
203 kfree(sd); 231 v4l2_ctrl_handler_free(&state->hdl);
232 kfree(state);
204 return 0; 233 return 0;
205} 234}
206 235
diff --git a/drivers/media/video/cx18/Kconfig b/drivers/media/video/cx18/Kconfig
index baf7e91ee0f5..76c054d1eef9 100644
--- a/drivers/media/video/cx18/Kconfig
+++ b/drivers/media/video/cx18/Kconfig
@@ -3,7 +3,7 @@ config VIDEO_CX18
3 depends on VIDEO_V4L2 && DVB_CORE && PCI && I2C && EXPERIMENTAL 3 depends on VIDEO_V4L2 && DVB_CORE && PCI && I2C && EXPERIMENTAL
4 depends on INPUT # due to VIDEO_IR 4 depends on INPUT # due to VIDEO_IR
5 select I2C_ALGOBIT 5 select I2C_ALGOBIT
6 select VIDEO_IR 6 depends on VIDEO_IR
7 select VIDEO_TUNER 7 select VIDEO_TUNER
8 select VIDEO_TVEEPROM 8 select VIDEO_TVEEPROM
9 select VIDEO_CX2341X 9 select VIDEO_CX2341X
diff --git a/drivers/media/video/cx18/cx18-i2c.c b/drivers/media/video/cx18/cx18-i2c.c
index 809f7d37129c..73ce90c2f577 100644
--- a/drivers/media/video/cx18/cx18-i2c.c
+++ b/drivers/media/video/cx18/cx18-i2c.c
@@ -117,7 +117,8 @@ static int cx18_i2c_new_ir(struct cx18 *cx, struct i2c_adapter *adap, u32 hw,
117 break; 117 break;
118 } 118 }
119 119
120 return i2c_new_probed_device(adap, &info, addr_list) == NULL ? -1 : 0; 120 return i2c_new_probed_device(adap, &info, addr_list, NULL) == NULL ?
121 -1 : 0;
121} 122}
122 123
123int cx18_i2c_register(struct cx18 *cx, unsigned idx) 124int cx18_i2c_register(struct cx18 *cx, unsigned idx)
diff --git a/drivers/media/video/cx231xx/Kconfig b/drivers/media/video/cx231xx/Kconfig
index 477d4ab5e9ac..5ac7eceececa 100644
--- a/drivers/media/video/cx231xx/Kconfig
+++ b/drivers/media/video/cx231xx/Kconfig
@@ -3,7 +3,7 @@ config VIDEO_CX231XX
3 depends on VIDEO_DEV && I2C && INPUT 3 depends on VIDEO_DEV && I2C && INPUT
4 select VIDEO_TUNER 4 select VIDEO_TUNER
5 select VIDEO_TVEEPROM 5 select VIDEO_TVEEPROM
6 select VIDEO_IR 6 depends on VIDEO_IR
7 select VIDEOBUF_VMALLOC 7 select VIDEOBUF_VMALLOC
8 select VIDEO_CX25840 8 select VIDEO_CX25840
9 9
diff --git a/drivers/media/video/cx2341x.c b/drivers/media/video/cx2341x.c
index 2bf44ef10fec..e5c3c8da4be3 100644
--- a/drivers/media/video/cx2341x.c
+++ b/drivers/media/video/cx2341x.c
@@ -38,6 +38,145 @@ static int debug;
38module_param(debug, int, 0644); 38module_param(debug, int, 0644);
39MODULE_PARM_DESC(debug, "Debug level (0-1)"); 39MODULE_PARM_DESC(debug, "Debug level (0-1)");
40 40
41/********************** COMMON CODE *********************/
42
43/* definitions for audio properties bits 29-28 */
44#define CX2341X_AUDIO_ENCODING_METHOD_MPEG 0
45#define CX2341X_AUDIO_ENCODING_METHOD_AC3 1
46#define CX2341X_AUDIO_ENCODING_METHOD_LPCM 2
47
48static const char *cx2341x_get_name(u32 id)
49{
50 switch (id) {
51 case V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE:
52 return "Spatial Filter Mode";
53 case V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER:
54 return "Spatial Filter";
55 case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE:
56 return "Spatial Luma Filter Type";
57 case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE:
58 return "Spatial Chroma Filter Type";
59 case V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE:
60 return "Temporal Filter Mode";
61 case V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER:
62 return "Temporal Filter";
63 case V4L2_CID_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE:
64 return "Median Filter Type";
65 case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_TOP:
66 return "Median Luma Filter Maximum";
67 case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_BOTTOM:
68 return "Median Luma Filter Minimum";
69 case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_TOP:
70 return "Median Chroma Filter Maximum";
71 case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_BOTTOM:
72 return "Median Chroma Filter Minimum";
73 case V4L2_CID_MPEG_CX2341X_STREAM_INSERT_NAV_PACKETS:
74 return "Insert Navigation Packets";
75 }
76 return NULL;
77}
78
79static const char **cx2341x_get_menu(u32 id)
80{
81 static const char *cx2341x_video_spatial_filter_mode_menu[] = {
82 "Manual",
83 "Auto",
84 NULL
85 };
86
87 static const char *cx2341x_video_luma_spatial_filter_type_menu[] = {
88 "Off",
89 "1D Horizontal",
90 "1D Vertical",
91 "2D H/V Separable",
92 "2D Symmetric non-separable",
93 NULL
94 };
95
96 static const char *cx2341x_video_chroma_spatial_filter_type_menu[] = {
97 "Off",
98 "1D Horizontal",
99 NULL
100 };
101
102 static const char *cx2341x_video_temporal_filter_mode_menu[] = {
103 "Manual",
104 "Auto",
105 NULL
106 };
107
108 static const char *cx2341x_video_median_filter_type_menu[] = {
109 "Off",
110 "Horizontal",
111 "Vertical",
112 "Horizontal/Vertical",
113 "Diagonal",
114 NULL
115 };
116
117 switch (id) {
118 case V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE:
119 return cx2341x_video_spatial_filter_mode_menu;
120 case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE:
121 return cx2341x_video_luma_spatial_filter_type_menu;
122 case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE:
123 return cx2341x_video_chroma_spatial_filter_type_menu;
124 case V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE:
125 return cx2341x_video_temporal_filter_mode_menu;
126 case V4L2_CID_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE:
127 return cx2341x_video_median_filter_type_menu;
128 }
129 return NULL;
130}
131
132static void cx2341x_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
133 s32 *min, s32 *max, s32 *step, s32 *def, u32 *flags)
134{
135 *name = cx2341x_get_name(id);
136 *flags = 0;
137
138 switch (id) {
139 case V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE:
140 case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE:
141 case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE:
142 case V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE:
143 case V4L2_CID_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE:
144 *type = V4L2_CTRL_TYPE_MENU;
145 *min = 0;
146 *step = 0;
147 break;
148 case V4L2_CID_MPEG_CX2341X_STREAM_INSERT_NAV_PACKETS:
149 *type = V4L2_CTRL_TYPE_BOOLEAN;
150 *min = 0;
151 *max = *step = 1;
152 break;
153 default:
154 *type = V4L2_CTRL_TYPE_INTEGER;
155 break;
156 }
157 switch (id) {
158 case V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE:
159 case V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE:
160 case V4L2_CID_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE:
161 *flags |= V4L2_CTRL_FLAG_UPDATE;
162 break;
163 case V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER:
164 case V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER:
165 case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_TOP:
166 case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_BOTTOM:
167 case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_TOP:
168 case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_BOTTOM:
169 *flags |= V4L2_CTRL_FLAG_SLIDER;
170 break;
171 case V4L2_CID_MPEG_VIDEO_ENCODING:
172 *flags |= V4L2_CTRL_FLAG_READ_ONLY;
173 break;
174 }
175}
176
177
178/********************** OLD CODE *********************/
179
41/* Must be sorted from low to high control ID! */ 180/* Must be sorted from low to high control ID! */
42const u32 cx2341x_mpeg_ctrls[] = { 181const u32 cx2341x_mpeg_ctrls[] = {
43 V4L2_CID_MPEG_CLASS, 182 V4L2_CID_MPEG_CLASS,
@@ -134,8 +273,6 @@ static const struct cx2341x_mpeg_params default_params = {
134 .video_chroma_median_filter_top = 255, 273 .video_chroma_median_filter_top = 255,
135 .video_chroma_median_filter_bottom = 0, 274 .video_chroma_median_filter_bottom = 0,
136}; 275};
137
138
139/* Map the control ID to the correct field in the cx2341x_mpeg_params 276/* Map the control ID to the correct field in the cx2341x_mpeg_params
140 struct. Return -EINVAL if the ID is unknown, else return 0. */ 277 struct. Return -EINVAL if the ID is unknown, else return 0. */
141static int cx2341x_get_ctrl(const struct cx2341x_mpeg_params *params, 278static int cx2341x_get_ctrl(const struct cx2341x_mpeg_params *params,
@@ -415,83 +552,33 @@ static int cx2341x_ctrl_query_fill(struct v4l2_queryctrl *qctrl,
415{ 552{
416 const char *name; 553 const char *name;
417 554
418 qctrl->flags = 0;
419 switch (qctrl->id) { 555 switch (qctrl->id) {
420 /* MPEG controls */ 556 /* MPEG controls */
421 case V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE: 557 case V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE:
422 name = "Spatial Filter Mode";
423 break;
424 case V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER: 558 case V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER:
425 name = "Spatial Filter";
426 break;
427 case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE: 559 case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE:
428 name = "Spatial Luma Filter Type";
429 break;
430 case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE: 560 case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE:
431 name = "Spatial Chroma Filter Type";
432 break;
433 case V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE: 561 case V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE:
434 name = "Temporal Filter Mode";
435 break;
436 case V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER: 562 case V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER:
437 name = "Temporal Filter";
438 break;
439 case V4L2_CID_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE: 563 case V4L2_CID_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE:
440 name = "Median Filter Type";
441 break;
442 case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_TOP: 564 case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_TOP:
443 name = "Median Luma Filter Maximum";
444 break;
445 case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_BOTTOM: 565 case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_BOTTOM:
446 name = "Median Luma Filter Minimum";
447 break;
448 case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_TOP: 566 case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_TOP:
449 name = "Median Chroma Filter Maximum";
450 break;
451 case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_BOTTOM: 567 case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_BOTTOM:
452 name = "Median Chroma Filter Minimum";
453 break;
454 case V4L2_CID_MPEG_CX2341X_STREAM_INSERT_NAV_PACKETS: 568 case V4L2_CID_MPEG_CX2341X_STREAM_INSERT_NAV_PACKETS:
455 name = "Insert Navigation Packets"; 569 cx2341x_ctrl_fill(qctrl->id, &name, &qctrl->type,
456 break; 570 &min, &max, &step, &def, &qctrl->flags);
571 qctrl->minimum = min;
572 qctrl->maximum = max;
573 qctrl->step = step;
574 qctrl->default_value = def;
575 qctrl->reserved[0] = qctrl->reserved[1] = 0;
576 strlcpy(qctrl->name, name, sizeof(qctrl->name));
577 return 0;
457 578
458 default: 579 default:
459 return v4l2_ctrl_query_fill(qctrl, min, max, step, def); 580 return v4l2_ctrl_query_fill(qctrl, min, max, step, def);
460 } 581 }
461 switch (qctrl->id) {
462 case V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE:
463 case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE:
464 case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE:
465 case V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE:
466 case V4L2_CID_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE:
467 qctrl->type = V4L2_CTRL_TYPE_MENU;
468 min = 0;
469 step = 1;
470 break;
471 case V4L2_CID_MPEG_CX2341X_STREAM_INSERT_NAV_PACKETS:
472 qctrl->type = V4L2_CTRL_TYPE_BOOLEAN;
473 min = 0;
474 max = 1;
475 step = 1;
476 break;
477 default:
478 qctrl->type = V4L2_CTRL_TYPE_INTEGER;
479 break;
480 }
481 switch (qctrl->id) {
482 case V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE:
483 case V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE:
484 case V4L2_CID_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE:
485 qctrl->flags |= V4L2_CTRL_FLAG_UPDATE;
486 break;
487 }
488 qctrl->minimum = min;
489 qctrl->maximum = max;
490 qctrl->step = step;
491 qctrl->default_value = def;
492 qctrl->reserved[0] = qctrl->reserved[1] = 0;
493 snprintf(qctrl->name, sizeof(qctrl->name), name);
494 return 0;
495} 582}
496 583
497int cx2341x_ctrl_query(const struct cx2341x_mpeg_params *params, 584int cx2341x_ctrl_query(const struct cx2341x_mpeg_params *params,
@@ -797,42 +884,6 @@ const char **cx2341x_ctrl_get_menu(const struct cx2341x_mpeg_params *p, u32 id)
797 NULL 884 NULL
798 }; 885 };
799 886
800 static const char *cx2341x_video_spatial_filter_mode_menu[] = {
801 "Manual",
802 "Auto",
803 NULL
804 };
805
806 static const char *cx2341x_video_luma_spatial_filter_type_menu[] = {
807 "Off",
808 "1D Horizontal",
809 "1D Vertical",
810 "2D H/V Separable",
811 "2D Symmetric non-separable",
812 NULL
813 };
814
815 static const char *cx2341x_video_chroma_spatial_filter_type_menu[] = {
816 "Off",
817 "1D Horizontal",
818 NULL
819 };
820
821 static const char *cx2341x_video_temporal_filter_mode_menu[] = {
822 "Manual",
823 "Auto",
824 NULL
825 };
826
827 static const char *cx2341x_video_median_filter_type_menu[] = {
828 "Off",
829 "Horizontal",
830 "Vertical",
831 "Horizontal/Vertical",
832 "Diagonal",
833 NULL
834 };
835
836 switch (id) { 887 switch (id) {
837 case V4L2_CID_MPEG_STREAM_TYPE: 888 case V4L2_CID_MPEG_STREAM_TYPE:
838 return (p->capabilities & CX2341X_CAP_HAS_TS) ? 889 return (p->capabilities & CX2341X_CAP_HAS_TS) ?
@@ -844,26 +895,17 @@ const char **cx2341x_ctrl_get_menu(const struct cx2341x_mpeg_params *p, u32 id)
844 case V4L2_CID_MPEG_AUDIO_L3_BITRATE: 895 case V4L2_CID_MPEG_AUDIO_L3_BITRATE:
845 return NULL; 896 return NULL;
846 case V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE: 897 case V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE:
847 return cx2341x_video_spatial_filter_mode_menu;
848 case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE: 898 case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE:
849 return cx2341x_video_luma_spatial_filter_type_menu;
850 case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE: 899 case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE:
851 return cx2341x_video_chroma_spatial_filter_type_menu;
852 case V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE: 900 case V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE:
853 return cx2341x_video_temporal_filter_mode_menu;
854 case V4L2_CID_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE: 901 case V4L2_CID_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE:
855 return cx2341x_video_median_filter_type_menu; 902 return cx2341x_get_menu(id);
856 default: 903 default:
857 return v4l2_ctrl_get_menu(id); 904 return v4l2_ctrl_get_menu(id);
858 } 905 }
859} 906}
860EXPORT_SYMBOL(cx2341x_ctrl_get_menu); 907EXPORT_SYMBOL(cx2341x_ctrl_get_menu);
861 908
862/* definitions for audio properties bits 29-28 */
863#define CX2341X_AUDIO_ENCODING_METHOD_MPEG 0
864#define CX2341X_AUDIO_ENCODING_METHOD_AC3 1
865#define CX2341X_AUDIO_ENCODING_METHOD_LPCM 2
866
867static void cx2341x_calc_audio_properties(struct cx2341x_mpeg_params *params) 909static void cx2341x_calc_audio_properties(struct cx2341x_mpeg_params *params)
868{ 910{
869 params->audio_properties = 911 params->audio_properties =
@@ -1195,9 +1237,490 @@ void cx2341x_log_status(const struct cx2341x_mpeg_params *p, const char *prefix)
1195} 1237}
1196EXPORT_SYMBOL(cx2341x_log_status); 1238EXPORT_SYMBOL(cx2341x_log_status);
1197 1239
1198/*
1199 * Local variables:
1200 * c-basic-offset: 8
1201 * End:
1202 */
1203 1240
1241
1242/********************** NEW CODE *********************/
1243
1244static inline struct cx2341x_handler *to_cxhdl(struct v4l2_ctrl *ctrl)
1245{
1246 return container_of(ctrl->handler, struct cx2341x_handler, hdl);
1247}
1248
1249static int cx2341x_hdl_api(struct cx2341x_handler *hdl,
1250 u32 cmd, int args, ...)
1251{
1252 u32 data[CX2341X_MBOX_MAX_DATA];
1253 va_list vargs;
1254 int i;
1255
1256 va_start(vargs, args);
1257
1258 for (i = 0; i < args; i++)
1259 data[i] = va_arg(vargs, int);
1260 va_end(vargs);
1261 return hdl->func(hdl->priv, cmd, args, 0, data);
1262}
1263
1264/* ctrl->handler->lock is held, so it is safe to access cur.val */
1265static inline int cx2341x_neq(struct v4l2_ctrl *ctrl)
1266{
1267 return ctrl && ctrl->val != ctrl->cur.val;
1268}
1269
1270static int cx2341x_try_ctrl(struct v4l2_ctrl *ctrl)
1271{
1272 struct cx2341x_handler *hdl = to_cxhdl(ctrl);
1273 s32 val = ctrl->val;
1274
1275 switch (ctrl->id) {
1276 case V4L2_CID_MPEG_VIDEO_B_FRAMES: {
1277 /* video gop cluster */
1278 int b = val + 1;
1279 int gop = hdl->video_gop_size->val;
1280
1281 gop = b * ((gop + b - 1) / b);
1282
1283 /* Max GOP size = 34 */
1284 while (gop > 34)
1285 gop -= b;
1286 hdl->video_gop_size->val = gop;
1287 break;
1288 }
1289
1290 case V4L2_CID_MPEG_STREAM_TYPE:
1291 /* stream type cluster */
1292 hdl->video_encoding->val =
1293 (hdl->stream_type->val == V4L2_MPEG_STREAM_TYPE_MPEG1_SS ||
1294 hdl->stream_type->val == V4L2_MPEG_STREAM_TYPE_MPEG1_VCD) ?
1295 V4L2_MPEG_VIDEO_ENCODING_MPEG_1 :
1296 V4L2_MPEG_VIDEO_ENCODING_MPEG_2;
1297 if (hdl->video_encoding->val == V4L2_MPEG_VIDEO_ENCODING_MPEG_1)
1298 /* MPEG-1 implies CBR */
1299 hdl->video_bitrate_mode->val =
1300 V4L2_MPEG_VIDEO_BITRATE_MODE_CBR;
1301 /* peak bitrate shall be >= normal bitrate */
1302 if (hdl->video_bitrate_mode->val == V4L2_MPEG_VIDEO_BITRATE_MODE_VBR &&
1303 hdl->video_bitrate_peak->val < hdl->video_bitrate->val)
1304 hdl->video_bitrate_peak->val = hdl->video_bitrate->val;
1305 break;
1306 }
1307 return 0;
1308}
1309
1310static int cx2341x_s_ctrl(struct v4l2_ctrl *ctrl)
1311{
1312 static const int mpeg_stream_type[] = {
1313 0, /* MPEG-2 PS */
1314 1, /* MPEG-2 TS */
1315 2, /* MPEG-1 SS */
1316 14, /* DVD */
1317 11, /* VCD */
1318 12, /* SVCD */
1319 };
1320 struct cx2341x_handler *hdl = to_cxhdl(ctrl);
1321 s32 val = ctrl->val;
1322 u32 props;
1323 int err;
1324
1325 switch (ctrl->id) {
1326 case V4L2_CID_MPEG_STREAM_VBI_FMT:
1327 if (hdl->ops && hdl->ops->s_stream_vbi_fmt)
1328 return hdl->ops->s_stream_vbi_fmt(hdl, val);
1329 return 0;
1330
1331 case V4L2_CID_MPEG_VIDEO_ASPECT:
1332 return cx2341x_hdl_api(hdl,
1333 CX2341X_ENC_SET_ASPECT_RATIO, 1, val + 1);
1334
1335 case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE:
1336 return cx2341x_hdl_api(hdl, CX2341X_ENC_SET_GOP_CLOSURE, 1, val);
1337
1338 case V4L2_CID_MPEG_AUDIO_MUTE:
1339 return cx2341x_hdl_api(hdl, CX2341X_ENC_MUTE_AUDIO, 1, val);
1340
1341 case V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION:
1342 return cx2341x_hdl_api(hdl,
1343 CX2341X_ENC_SET_FRAME_DROP_RATE, 1, val);
1344
1345 case V4L2_CID_MPEG_CX2341X_STREAM_INSERT_NAV_PACKETS:
1346 return cx2341x_hdl_api(hdl, CX2341X_ENC_MISC, 2, 7, val);
1347
1348 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
1349 /* audio properties cluster */
1350 props = (hdl->audio_sampling_freq->val << 0) |
1351 (hdl->audio_mode->val << 8) |
1352 (hdl->audio_mode_extension->val << 10) |
1353 (hdl->audio_crc->val << 14);
1354 if (hdl->audio_emphasis->val == V4L2_MPEG_AUDIO_EMPHASIS_CCITT_J17)
1355 props |= 3 << 12;
1356 else
1357 props |= hdl->audio_emphasis->val << 12;
1358
1359 if (hdl->audio_encoding->val == V4L2_MPEG_AUDIO_ENCODING_AC3) {
1360 props |=
1361#if 1
1362 /* Not sure if this MPEG Layer II setting is required */
1363 ((3 - V4L2_MPEG_AUDIO_ENCODING_LAYER_2) << 2) |
1364#endif
1365 (hdl->audio_ac3_bitrate->val << 4) |
1366 (CX2341X_AUDIO_ENCODING_METHOD_AC3 << 28);
1367 } else {
1368 /* Assuming MPEG Layer II */
1369 props |=
1370 ((3 - hdl->audio_encoding->val) << 2) |
1371 ((1 + hdl->audio_l2_bitrate->val) << 4);
1372 }
1373 err = cx2341x_hdl_api(hdl,
1374 CX2341X_ENC_SET_AUDIO_PROPERTIES, 1, props);
1375 if (err)
1376 return err;
1377
1378 hdl->audio_properties = props;
1379 if (hdl->audio_ac3_bitrate) {
1380 int is_ac3 = hdl->audio_encoding->val ==
1381 V4L2_MPEG_AUDIO_ENCODING_AC3;
1382
1383 v4l2_ctrl_activate(hdl->audio_ac3_bitrate, is_ac3);
1384 v4l2_ctrl_activate(hdl->audio_l2_bitrate, !is_ac3);
1385 }
1386 v4l2_ctrl_activate(hdl->audio_mode_extension,
1387 hdl->audio_mode->val == V4L2_MPEG_AUDIO_MODE_JOINT_STEREO);
1388 if (cx2341x_neq(hdl->audio_sampling_freq) &&
1389 hdl->ops && hdl->ops->s_audio_sampling_freq)
1390 return hdl->ops->s_audio_sampling_freq(hdl, hdl->audio_sampling_freq->val);
1391 if (cx2341x_neq(hdl->audio_mode) &&
1392 hdl->ops && hdl->ops->s_audio_mode)
1393 return hdl->ops->s_audio_mode(hdl, hdl->audio_mode->val);
1394 return 0;
1395
1396 case V4L2_CID_MPEG_VIDEO_B_FRAMES:
1397 /* video gop cluster */
1398 return cx2341x_hdl_api(hdl, CX2341X_ENC_SET_GOP_PROPERTIES, 2,
1399 hdl->video_gop_size->val,
1400 hdl->video_b_frames->val + 1);
1401
1402 case V4L2_CID_MPEG_STREAM_TYPE:
1403 /* stream type cluster */
1404 err = cx2341x_hdl_api(hdl,
1405 CX2341X_ENC_SET_STREAM_TYPE, 1, mpeg_stream_type[val]);
1406 if (err)
1407 return err;
1408
1409 err = cx2341x_hdl_api(hdl, CX2341X_ENC_SET_BIT_RATE, 5,
1410 hdl->video_bitrate_mode->val,
1411 hdl->video_bitrate->val,
1412 hdl->video_bitrate_peak->val / 400, 0, 0);
1413 if (err)
1414 return err;
1415
1416 v4l2_ctrl_activate(hdl->video_bitrate_mode,
1417 hdl->video_encoding->val != V4L2_MPEG_VIDEO_ENCODING_MPEG_1);
1418 v4l2_ctrl_activate(hdl->video_bitrate_peak,
1419 hdl->video_bitrate_mode->val != V4L2_MPEG_VIDEO_BITRATE_MODE_CBR);
1420 if (cx2341x_neq(hdl->video_encoding) &&
1421 hdl->ops && hdl->ops->s_video_encoding)
1422 return hdl->ops->s_video_encoding(hdl, hdl->video_encoding->val);
1423 return 0;
1424
1425 case V4L2_CID_MPEG_VIDEO_MUTE:
1426 /* video mute cluster */
1427 return cx2341x_hdl_api(hdl, CX2341X_ENC_MUTE_VIDEO, 1,
1428 hdl->video_mute->val |
1429 (hdl->video_mute_yuv->val << 8));
1430
1431 case V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE: {
1432 int active_filter;
1433
1434 /* video filter mode */
1435 err = cx2341x_hdl_api(hdl, CX2341X_ENC_SET_DNR_FILTER_MODE, 2,
1436 hdl->video_spatial_filter_mode->val |
1437 (hdl->video_temporal_filter_mode->val << 1),
1438 hdl->video_median_filter_type->val);
1439 if (err)
1440 return err;
1441
1442 active_filter = hdl->video_spatial_filter_mode->val !=
1443 V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_AUTO;
1444 v4l2_ctrl_activate(hdl->video_spatial_filter, active_filter);
1445 v4l2_ctrl_activate(hdl->video_luma_spatial_filter_type, active_filter);
1446 v4l2_ctrl_activate(hdl->video_chroma_spatial_filter_type, active_filter);
1447 active_filter = hdl->video_temporal_filter_mode->val !=
1448 V4L2_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE_AUTO;
1449 v4l2_ctrl_activate(hdl->video_temporal_filter, active_filter);
1450 active_filter = hdl->video_median_filter_type->val !=
1451 V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_OFF;
1452 v4l2_ctrl_activate(hdl->video_luma_median_filter_bottom, active_filter);
1453 v4l2_ctrl_activate(hdl->video_luma_median_filter_top, active_filter);
1454 v4l2_ctrl_activate(hdl->video_chroma_median_filter_bottom, active_filter);
1455 v4l2_ctrl_activate(hdl->video_chroma_median_filter_top, active_filter);
1456 return 0;
1457 }
1458
1459 case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE:
1460 /* video filter type cluster */
1461 return cx2341x_hdl_api(hdl,
1462 CX2341X_ENC_SET_SPATIAL_FILTER_TYPE, 2,
1463 hdl->video_luma_spatial_filter_type->val,
1464 hdl->video_chroma_spatial_filter_type->val);
1465
1466 case V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER:
1467 /* video filter cluster */
1468 return cx2341x_hdl_api(hdl, CX2341X_ENC_SET_DNR_FILTER_PROPS, 2,
1469 hdl->video_spatial_filter->val,
1470 hdl->video_temporal_filter->val);
1471
1472 case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_TOP:
1473 /* video median cluster */
1474 return cx2341x_hdl_api(hdl, CX2341X_ENC_SET_CORING_LEVELS, 4,
1475 hdl->video_luma_median_filter_bottom->val,
1476 hdl->video_luma_median_filter_top->val,
1477 hdl->video_chroma_median_filter_bottom->val,
1478 hdl->video_chroma_median_filter_top->val);
1479 }
1480 return -EINVAL;
1481}
1482
1483static const struct v4l2_ctrl_ops cx2341x_ops = {
1484 .try_ctrl = cx2341x_try_ctrl,
1485 .s_ctrl = cx2341x_s_ctrl,
1486};
1487
1488static struct v4l2_ctrl *cx2341x_ctrl_new_custom(struct v4l2_ctrl_handler *hdl,
1489 u32 id, s32 min, s32 max, s32 step, s32 def)
1490{
1491 struct v4l2_ctrl_config cfg;
1492
1493 cx2341x_ctrl_fill(id, &cfg.name, &cfg.type, &min, &max, &step, &def, &cfg.flags);
1494 cfg.ops = &cx2341x_ops;
1495 cfg.id = id;
1496 cfg.min = min;
1497 cfg.max = max;
1498 cfg.def = def;
1499 if (cfg.type == V4L2_CTRL_TYPE_MENU) {
1500 cfg.step = 0;
1501 cfg.menu_skip_mask = step;
1502 cfg.qmenu = cx2341x_get_menu(id);
1503 } else {
1504 cfg.step = step;
1505 cfg.menu_skip_mask = 0;
1506 }
1507 return v4l2_ctrl_new_custom(hdl, &cfg, NULL);
1508}
1509
1510static struct v4l2_ctrl *cx2341x_ctrl_new_std(struct v4l2_ctrl_handler *hdl,
1511 u32 id, s32 min, s32 max, s32 step, s32 def)
1512{
1513 return v4l2_ctrl_new_std(hdl, &cx2341x_ops, id, min, max, step, def);
1514}
1515
1516static struct v4l2_ctrl *cx2341x_ctrl_new_menu(struct v4l2_ctrl_handler *hdl,
1517 u32 id, s32 max, s32 mask, s32 def)
1518{
1519 return v4l2_ctrl_new_std_menu(hdl, &cx2341x_ops, id, max, mask, def);
1520}
1521
1522int cx2341x_handler_init(struct cx2341x_handler *cxhdl,
1523 unsigned nr_of_controls_hint)
1524{
1525 struct v4l2_ctrl_handler *hdl = &cxhdl->hdl;
1526 u32 caps = cxhdl->capabilities;
1527 int has_sliced_vbi = caps & CX2341X_CAP_HAS_SLICED_VBI;
1528 int has_ac3 = caps & CX2341X_CAP_HAS_AC3;
1529 int has_ts = caps & CX2341X_CAP_HAS_TS;
1530
1531 cxhdl->width = 720;
1532 cxhdl->height = 480;
1533
1534 v4l2_ctrl_handler_init(hdl, nr_of_controls_hint);
1535
1536 /* Add controls in ascending control ID order for fastest
1537 insertion time. */
1538 cxhdl->stream_type = cx2341x_ctrl_new_menu(hdl,
1539 V4L2_CID_MPEG_STREAM_TYPE,
1540 V4L2_MPEG_STREAM_TYPE_MPEG2_SVCD, has_ts ? 0 : 2,
1541 V4L2_MPEG_STREAM_TYPE_MPEG2_PS);
1542 cxhdl->stream_vbi_fmt = cx2341x_ctrl_new_menu(hdl,
1543 V4L2_CID_MPEG_STREAM_VBI_FMT,
1544 V4L2_MPEG_STREAM_VBI_FMT_IVTV, has_sliced_vbi ? 0 : 2,
1545 V4L2_MPEG_STREAM_VBI_FMT_NONE);
1546 cxhdl->audio_sampling_freq = cx2341x_ctrl_new_menu(hdl,
1547 V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ,
1548 V4L2_MPEG_AUDIO_SAMPLING_FREQ_32000, 0,
1549 V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000);
1550 cxhdl->audio_encoding = cx2341x_ctrl_new_menu(hdl,
1551 V4L2_CID_MPEG_AUDIO_ENCODING,
1552 V4L2_MPEG_AUDIO_ENCODING_AC3, has_ac3 ? ~0x12 : ~0x2,
1553 V4L2_MPEG_AUDIO_ENCODING_LAYER_2);
1554 cxhdl->audio_l2_bitrate = cx2341x_ctrl_new_menu(hdl,
1555 V4L2_CID_MPEG_AUDIO_L2_BITRATE,
1556 V4L2_MPEG_AUDIO_L2_BITRATE_384K, 0x1ff,
1557 V4L2_MPEG_AUDIO_L2_BITRATE_224K);
1558 cxhdl->audio_mode = cx2341x_ctrl_new_menu(hdl,
1559 V4L2_CID_MPEG_AUDIO_MODE,
1560 V4L2_MPEG_AUDIO_MODE_MONO, 0,
1561 V4L2_MPEG_AUDIO_MODE_STEREO);
1562 cxhdl->audio_mode_extension = cx2341x_ctrl_new_menu(hdl,
1563 V4L2_CID_MPEG_AUDIO_MODE_EXTENSION,
1564 V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_16, 0,
1565 V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_4);
1566 cxhdl->audio_emphasis = cx2341x_ctrl_new_menu(hdl,
1567 V4L2_CID_MPEG_AUDIO_EMPHASIS,
1568 V4L2_MPEG_AUDIO_EMPHASIS_CCITT_J17, 0,
1569 V4L2_MPEG_AUDIO_EMPHASIS_NONE);
1570 cxhdl->audio_crc = cx2341x_ctrl_new_menu(hdl,
1571 V4L2_CID_MPEG_AUDIO_CRC,
1572 V4L2_MPEG_AUDIO_CRC_CRC16, 0,
1573 V4L2_MPEG_AUDIO_CRC_NONE);
1574
1575 cx2341x_ctrl_new_std(hdl, V4L2_CID_MPEG_AUDIO_MUTE, 0, 1, 1, 0);
1576 if (has_ac3)
1577 cxhdl->audio_ac3_bitrate = cx2341x_ctrl_new_menu(hdl,
1578 V4L2_CID_MPEG_AUDIO_AC3_BITRATE,
1579 V4L2_MPEG_AUDIO_AC3_BITRATE_448K, 0x03,
1580 V4L2_MPEG_AUDIO_AC3_BITRATE_224K);
1581 cxhdl->video_encoding = cx2341x_ctrl_new_menu(hdl,
1582 V4L2_CID_MPEG_VIDEO_ENCODING,
1583 V4L2_MPEG_VIDEO_ENCODING_MPEG_2, 0,
1584 V4L2_MPEG_VIDEO_ENCODING_MPEG_2);
1585 cx2341x_ctrl_new_menu(hdl,
1586 V4L2_CID_MPEG_VIDEO_ASPECT,
1587 V4L2_MPEG_VIDEO_ASPECT_221x100, 0,
1588 V4L2_MPEG_VIDEO_ASPECT_4x3);
1589 cxhdl->video_b_frames = cx2341x_ctrl_new_std(hdl,
1590 V4L2_CID_MPEG_VIDEO_B_FRAMES, 0, 33, 1, 2);
1591 cxhdl->video_gop_size = cx2341x_ctrl_new_std(hdl,
1592 V4L2_CID_MPEG_VIDEO_GOP_SIZE,
1593 1, 34, 1, cxhdl->is_50hz ? 12 : 15);
1594 cx2341x_ctrl_new_std(hdl, V4L2_CID_MPEG_VIDEO_GOP_CLOSURE, 0, 1, 1, 1);
1595 cxhdl->video_bitrate_mode = cx2341x_ctrl_new_menu(hdl,
1596 V4L2_CID_MPEG_VIDEO_BITRATE_MODE,
1597 V4L2_MPEG_VIDEO_BITRATE_MODE_CBR, 0,
1598 V4L2_MPEG_VIDEO_BITRATE_MODE_VBR);
1599 cxhdl->video_bitrate = cx2341x_ctrl_new_std(hdl,
1600 V4L2_CID_MPEG_VIDEO_BITRATE,
1601 0, 27000000, 1, 6000000);
1602 cxhdl->video_bitrate_peak = cx2341x_ctrl_new_std(hdl,
1603 V4L2_CID_MPEG_VIDEO_BITRATE_PEAK,
1604 0, 27000000, 1, 8000000);
1605 cx2341x_ctrl_new_std(hdl,
1606 V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION, 0, 255, 1, 0);
1607 cxhdl->video_mute = cx2341x_ctrl_new_std(hdl,
1608 V4L2_CID_MPEG_VIDEO_MUTE, 0, 1, 1, 0);
1609 cxhdl->video_mute_yuv = cx2341x_ctrl_new_std(hdl,
1610 V4L2_CID_MPEG_VIDEO_MUTE_YUV, 0, 0xffffff, 1, 0x008080);
1611
1612 /* CX23415/6 specific */
1613 cxhdl->video_spatial_filter_mode = cx2341x_ctrl_new_custom(hdl,
1614 V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE,
1615 V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_MANUAL,
1616 V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_AUTO, 0,
1617 V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_MANUAL);
1618 cxhdl->video_spatial_filter = cx2341x_ctrl_new_custom(hdl,
1619 V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER,
1620 0, 15, 1, 0);
1621 cxhdl->video_luma_spatial_filter_type = cx2341x_ctrl_new_custom(hdl,
1622 V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE,
1623 V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_OFF,
1624 V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_2D_SYM_NON_SEPARABLE,
1625 0,
1626 V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_1D_HOR);
1627 cxhdl->video_chroma_spatial_filter_type = cx2341x_ctrl_new_custom(hdl,
1628 V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE,
1629 V4L2_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE_OFF,
1630 V4L2_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE_1D_HOR,
1631 0,
1632 V4L2_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE_1D_HOR);
1633 cxhdl->video_temporal_filter_mode = cx2341x_ctrl_new_custom(hdl,
1634 V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE,
1635 V4L2_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE_MANUAL,
1636 V4L2_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE_AUTO,
1637 0,
1638 V4L2_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE_MANUAL);
1639 cxhdl->video_temporal_filter = cx2341x_ctrl_new_custom(hdl,
1640 V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER,
1641 0, 31, 1, 8);
1642 cxhdl->video_median_filter_type = cx2341x_ctrl_new_custom(hdl,
1643 V4L2_CID_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE,
1644 V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_OFF,
1645 V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_DIAG,
1646 0,
1647 V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_OFF);
1648 cxhdl->video_luma_median_filter_bottom = cx2341x_ctrl_new_custom(hdl,
1649 V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_BOTTOM,
1650 0, 255, 1, 0);
1651 cxhdl->video_luma_median_filter_top = cx2341x_ctrl_new_custom(hdl,
1652 V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_TOP,
1653 0, 255, 1, 255);
1654 cxhdl->video_chroma_median_filter_bottom = cx2341x_ctrl_new_custom(hdl,
1655 V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_BOTTOM,
1656 0, 255, 1, 0);
1657 cxhdl->video_chroma_median_filter_top = cx2341x_ctrl_new_custom(hdl,
1658 V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_TOP,
1659 0, 255, 1, 255);
1660 cx2341x_ctrl_new_custom(hdl, V4L2_CID_MPEG_CX2341X_STREAM_INSERT_NAV_PACKETS,
1661 0, 1, 1, 0);
1662
1663 if (hdl->error) {
1664 int err = hdl->error;
1665
1666 v4l2_ctrl_handler_free(hdl);
1667 return err;
1668 }
1669
1670 v4l2_ctrl_cluster(8, &cxhdl->audio_sampling_freq);
1671 v4l2_ctrl_cluster(2, &cxhdl->video_b_frames);
1672 v4l2_ctrl_cluster(5, &cxhdl->stream_type);
1673 v4l2_ctrl_cluster(2, &cxhdl->video_mute);
1674 v4l2_ctrl_cluster(3, &cxhdl->video_spatial_filter_mode);
1675 v4l2_ctrl_cluster(2, &cxhdl->video_luma_spatial_filter_type);
1676 v4l2_ctrl_cluster(2, &cxhdl->video_spatial_filter);
1677 v4l2_ctrl_cluster(4, &cxhdl->video_luma_median_filter_top);
1678
1679 return 0;
1680}
1681EXPORT_SYMBOL(cx2341x_handler_init);
1682
1683void cx2341x_handler_set_50hz(struct cx2341x_handler *cxhdl, int is_50hz)
1684{
1685 cxhdl->is_50hz = is_50hz;
1686 cxhdl->video_gop_size->default_value = cxhdl->is_50hz ? 12 : 15;
1687}
1688EXPORT_SYMBOL(cx2341x_handler_set_50hz);
1689
1690int cx2341x_handler_setup(struct cx2341x_handler *cxhdl)
1691{
1692 int h = cxhdl->height;
1693 int w = cxhdl->width;
1694 int err;
1695
1696 err = cx2341x_hdl_api(cxhdl, CX2341X_ENC_SET_OUTPUT_PORT, 2, cxhdl->port, 0);
1697 if (err)
1698 return err;
1699 err = cx2341x_hdl_api(cxhdl, CX2341X_ENC_SET_FRAME_RATE, 1, cxhdl->is_50hz);
1700 if (err)
1701 return err;
1702
1703 if (v4l2_ctrl_g_ctrl(cxhdl->video_encoding) == V4L2_MPEG_VIDEO_ENCODING_MPEG_1) {
1704 w /= 2;
1705 h /= 2;
1706 }
1707 err = cx2341x_hdl_api(cxhdl, CX2341X_ENC_SET_FRAME_SIZE, 2, h, w);
1708 if (err)
1709 return err;
1710 return v4l2_ctrl_handler_setup(&cxhdl->hdl);
1711}
1712EXPORT_SYMBOL(cx2341x_handler_setup);
1713
1714void cx2341x_handler_set_busy(struct cx2341x_handler *cxhdl, int busy)
1715{
1716 v4l2_ctrl_grab(cxhdl->audio_sampling_freq, busy);
1717 v4l2_ctrl_grab(cxhdl->audio_encoding, busy);
1718 v4l2_ctrl_grab(cxhdl->audio_l2_bitrate, busy);
1719 v4l2_ctrl_grab(cxhdl->audio_ac3_bitrate, busy);
1720 v4l2_ctrl_grab(cxhdl->stream_vbi_fmt, busy);
1721 v4l2_ctrl_grab(cxhdl->stream_type, busy);
1722 v4l2_ctrl_grab(cxhdl->video_bitrate_mode, busy);
1723 v4l2_ctrl_grab(cxhdl->video_bitrate, busy);
1724 v4l2_ctrl_grab(cxhdl->video_bitrate_peak, busy);
1725}
1726EXPORT_SYMBOL(cx2341x_handler_set_busy);
diff --git a/drivers/media/video/cx23885/Kconfig b/drivers/media/video/cx23885/Kconfig
index bcdda9a9aa96..e1367b35647a 100644
--- a/drivers/media/video/cx23885/Kconfig
+++ b/drivers/media/video/cx23885/Kconfig
@@ -5,7 +5,7 @@ config VIDEO_CX23885
5 select VIDEO_BTCX 5 select VIDEO_BTCX
6 select VIDEO_TUNER 6 select VIDEO_TUNER
7 select VIDEO_TVEEPROM 7 select VIDEO_TVEEPROM
8 select VIDEO_IR 8 depends on IR_CORE
9 select VIDEOBUF_DVB 9 select VIDEOBUF_DVB
10 select VIDEOBUF_DMA_SG 10 select VIDEOBUF_DMA_SG
11 select VIDEO_CX25840 11 select VIDEO_CX25840
diff --git a/drivers/media/video/cx23885/Makefile b/drivers/media/video/cx23885/Makefile
index 5787ae243631..e2ee95f660d8 100644
--- a/drivers/media/video/cx23885/Makefile
+++ b/drivers/media/video/cx23885/Makefile
@@ -1,7 +1,8 @@
1cx23885-objs := cx23885-cards.o cx23885-video.o cx23885-vbi.o \ 1cx23885-objs := cx23885-cards.o cx23885-video.o cx23885-vbi.o \
2 cx23885-core.o cx23885-i2c.o cx23885-dvb.o cx23885-417.o \ 2 cx23885-core.o cx23885-i2c.o cx23885-dvb.o cx23885-417.o \
3 cx23885-ioctl.o cx23885-ir.o cx23885-input.o cx23888-ir.o \ 3 cx23885-ioctl.o cx23885-ir.o cx23885-av.o cx23885-input.o \
4 netup-init.o cimax2.o netup-eeprom.o cx23885-f300.o 4 cx23888-ir.o netup-init.o cimax2.o netup-eeprom.o \
5 cx23885-f300.o
5 6
6obj-$(CONFIG_VIDEO_CX23885) += cx23885.o 7obj-$(CONFIG_VIDEO_CX23885) += cx23885.o
7 8
diff --git a/drivers/media/video/cx23885/cx23885-av.c b/drivers/media/video/cx23885/cx23885-av.c
new file mode 100644
index 000000000000..134ebddd860f
--- /dev/null
+++ b/drivers/media/video/cx23885/cx23885-av.c
@@ -0,0 +1,35 @@
1/*
2 * Driver for the Conexant CX23885/7/8 PCIe bridge
3 *
4 * AV device support routines - non-input, non-vl42_subdev routines
5 *
6 * Copyright (C) 2010 Andy Walls <awalls@md.metrocast.net>
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
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 * 02110-1301, USA.
22 */
23
24#include "cx23885.h"
25
26void cx23885_av_work_handler(struct work_struct *work)
27{
28 struct cx23885_dev *dev =
29 container_of(work, struct cx23885_dev, cx25840_work);
30 bool handled;
31
32 v4l2_subdev_call(dev->sd_cx25840, core, interrupt_service_routine,
33 PCI_MSK_AV_CORE, &handled);
34 cx23885_irq_enable(dev, PCI_MSK_AV_CORE);
35}
diff --git a/drivers/media/video/cx23885/cx23885-av.h b/drivers/media/video/cx23885/cx23885-av.h
new file mode 100644
index 000000000000..d2915c3e53a2
--- /dev/null
+++ b/drivers/media/video/cx23885/cx23885-av.h
@@ -0,0 +1,27 @@
1/*
2 * Driver for the Conexant CX23885/7/8 PCIe bridge
3 *
4 * AV device support routines - non-input, non-vl42_subdev routines
5 *
6 * Copyright (C) 2010 Andy Walls <awalls@md.metrocast.net>
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
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 * 02110-1301, USA.
22 */
23
24#ifndef _CX23885_AV_H_
25#define _CX23885_AV_H_
26void cx23885_av_work_handler(struct work_struct *work);
27#endif
diff --git a/drivers/media/video/cx23885/cx23885-cards.c b/drivers/media/video/cx23885/cx23885-cards.c
index 2014daedee8b..e76ce8709afd 100644
--- a/drivers/media/video/cx23885/cx23885-cards.c
+++ b/drivers/media/video/cx23885/cx23885-cards.c
@@ -30,6 +30,16 @@
30#include "netup-init.h" 30#include "netup-init.h"
31#include "cx23888-ir.h" 31#include "cx23888-ir.h"
32 32
33static unsigned int enable_885_ir;
34module_param(enable_885_ir, int, 0644);
35MODULE_PARM_DESC(enable_885_ir,
36 "Enable integrated IR controller for supported\n"
37 "\t\t CX2388[57] boards that are wired for it:\n"
38 "\t\t\tHVR-1250 (reported safe)\n"
39 "\t\t\tTeVii S470 (reported unsafe)\n"
40 "\t\t This can cause an interrupt storm with some cards.\n"
41 "\t\t Default: 0 [Disabled]");
42
33/* ------------------------------------------------------------------ */ 43/* ------------------------------------------------------------------ */
34/* board config info */ 44/* board config info */
35 45
@@ -626,6 +636,9 @@ static void hauppauge_eeprom(struct cx23885_dev *dev, u8 *eeprom_data)
626 case 79101: 636 case 79101:
627 /* WinTV-HVR1250 (PCIe, Retail, IR, half height, 637 /* WinTV-HVR1250 (PCIe, Retail, IR, half height,
628 ATSC and Basic analog */ 638 ATSC and Basic analog */
639 case 79501:
640 /* WinTV-HVR1250 (PCIe, No IR, half height,
641 ATSC [at least] and Basic analog) */
629 case 79561: 642 case 79561:
630 /* WinTV-HVR1250 (PCIe, OEM, No IR, half height, 643 /* WinTV-HVR1250 (PCIe, OEM, No IR, half height,
631 ATSC and Basic analog */ 644 ATSC and Basic analog */
@@ -959,9 +972,37 @@ void cx23885_gpio_setup(struct cx23885_dev *dev)
959 972
960int cx23885_ir_init(struct cx23885_dev *dev) 973int cx23885_ir_init(struct cx23885_dev *dev)
961{ 974{
975 static struct v4l2_subdev_io_pin_config ir_rxtx_pin_cfg[] = {
976 {
977 .flags = V4L2_SUBDEV_IO_PIN_INPUT,
978 .pin = CX23885_PIN_IR_RX_GPIO19,
979 .function = CX23885_PAD_IR_RX,
980 .value = 0,
981 .strength = CX25840_PIN_DRIVE_MEDIUM,
982 }, {
983 .flags = V4L2_SUBDEV_IO_PIN_OUTPUT,
984 .pin = CX23885_PIN_IR_TX_GPIO20,
985 .function = CX23885_PAD_IR_TX,
986 .value = 0,
987 .strength = CX25840_PIN_DRIVE_MEDIUM,
988 }
989 };
990 const size_t ir_rxtx_pin_cfg_count = ARRAY_SIZE(ir_rxtx_pin_cfg);
991
992 static struct v4l2_subdev_io_pin_config ir_rx_pin_cfg[] = {
993 {
994 .flags = V4L2_SUBDEV_IO_PIN_INPUT,
995 .pin = CX23885_PIN_IR_RX_GPIO19,
996 .function = CX23885_PAD_IR_RX,
997 .value = 0,
998 .strength = CX25840_PIN_DRIVE_MEDIUM,
999 }
1000 };
1001 const size_t ir_rx_pin_cfg_count = ARRAY_SIZE(ir_rx_pin_cfg);
1002
1003 struct v4l2_subdev_ir_parameters params;
962 int ret = 0; 1004 int ret = 0;
963 switch (dev->board) { 1005 switch (dev->board) {
964 case CX23885_BOARD_HAUPPAUGE_HVR1250:
965 case CX23885_BOARD_HAUPPAUGE_HVR1500: 1006 case CX23885_BOARD_HAUPPAUGE_HVR1500:
966 case CX23885_BOARD_HAUPPAUGE_HVR1500Q: 1007 case CX23885_BOARD_HAUPPAUGE_HVR1500Q:
967 case CX23885_BOARD_HAUPPAUGE_HVR1800: 1008 case CX23885_BOARD_HAUPPAUGE_HVR1800:
@@ -979,7 +1020,41 @@ int cx23885_ir_init(struct cx23885_dev *dev)
979 if (ret) 1020 if (ret)
980 break; 1021 break;
981 dev->sd_ir = cx23885_find_hw(dev, CX23885_HW_888_IR); 1022 dev->sd_ir = cx23885_find_hw(dev, CX23885_HW_888_IR);
982 dev->pci_irqmask |= PCI_MSK_IR; 1023 v4l2_subdev_call(dev->sd_cx25840, core, s_io_pin_config,
1024 ir_rxtx_pin_cfg_count, ir_rxtx_pin_cfg);
1025 /*
1026 * For these boards we need to invert the Tx output via the
1027 * IR controller to have the LED off while idle
1028 */
1029 v4l2_subdev_call(dev->sd_ir, ir, tx_g_parameters, &params);
1030 params.enable = false;
1031 params.shutdown = false;
1032 params.invert_level = true;
1033 v4l2_subdev_call(dev->sd_ir, ir, tx_s_parameters, &params);
1034 params.shutdown = true;
1035 v4l2_subdev_call(dev->sd_ir, ir, tx_s_parameters, &params);
1036 break;
1037 case CX23885_BOARD_TEVII_S470:
1038 if (!enable_885_ir)
1039 break;
1040 dev->sd_ir = cx23885_find_hw(dev, CX23885_HW_AV_CORE);
1041 if (dev->sd_ir == NULL) {
1042 ret = -ENODEV;
1043 break;
1044 }
1045 v4l2_subdev_call(dev->sd_cx25840, core, s_io_pin_config,
1046 ir_rx_pin_cfg_count, ir_rx_pin_cfg);
1047 break;
1048 case CX23885_BOARD_HAUPPAUGE_HVR1250:
1049 if (!enable_885_ir)
1050 break;
1051 dev->sd_ir = cx23885_find_hw(dev, CX23885_HW_AV_CORE);
1052 if (dev->sd_ir == NULL) {
1053 ret = -ENODEV;
1054 break;
1055 }
1056 v4l2_subdev_call(dev->sd_cx25840, core, s_io_pin_config,
1057 ir_rxtx_pin_cfg_count, ir_rxtx_pin_cfg);
983 break; 1058 break;
984 case CX23885_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL_EXP: 1059 case CX23885_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL_EXP:
985 request_module("ir-kbd-i2c"); 1060 request_module("ir-kbd-i2c");
@@ -994,11 +1069,16 @@ void cx23885_ir_fini(struct cx23885_dev *dev)
994 switch (dev->board) { 1069 switch (dev->board) {
995 case CX23885_BOARD_HAUPPAUGE_HVR1850: 1070 case CX23885_BOARD_HAUPPAUGE_HVR1850:
996 case CX23885_BOARD_HAUPPAUGE_HVR1290: 1071 case CX23885_BOARD_HAUPPAUGE_HVR1290:
997 dev->pci_irqmask &= ~PCI_MSK_IR; 1072 cx23885_irq_remove(dev, PCI_MSK_IR);
998 cx_clear(PCI_INT_MSK, PCI_MSK_IR);
999 cx23888_ir_remove(dev); 1073 cx23888_ir_remove(dev);
1000 dev->sd_ir = NULL; 1074 dev->sd_ir = NULL;
1001 break; 1075 break;
1076 case CX23885_BOARD_TEVII_S470:
1077 case CX23885_BOARD_HAUPPAUGE_HVR1250:
1078 cx23885_irq_remove(dev, PCI_MSK_AV_CORE);
1079 /* sd_ir is a duplicate pointer to the AV Core, just clear it */
1080 dev->sd_ir = NULL;
1081 break;
1002 } 1082 }
1003} 1083}
1004 1084
@@ -1007,8 +1087,13 @@ void cx23885_ir_pci_int_enable(struct cx23885_dev *dev)
1007 switch (dev->board) { 1087 switch (dev->board) {
1008 case CX23885_BOARD_HAUPPAUGE_HVR1850: 1088 case CX23885_BOARD_HAUPPAUGE_HVR1850:
1009 case CX23885_BOARD_HAUPPAUGE_HVR1290: 1089 case CX23885_BOARD_HAUPPAUGE_HVR1290:
1010 if (dev->sd_ir && (dev->pci_irqmask & PCI_MSK_IR)) 1090 if (dev->sd_ir)
1011 cx_set(PCI_INT_MSK, PCI_MSK_IR); 1091 cx23885_irq_add_enable(dev, PCI_MSK_IR);
1092 break;
1093 case CX23885_BOARD_TEVII_S470:
1094 case CX23885_BOARD_HAUPPAUGE_HVR1250:
1095 if (dev->sd_ir)
1096 cx23885_irq_add_enable(dev, PCI_MSK_AV_CORE);
1012 break; 1097 break;
1013 } 1098 }
1014} 1099}
@@ -1028,6 +1113,13 @@ void cx23885_card_setup(struct cx23885_dev *dev)
1028 1113
1029 switch (dev->board) { 1114 switch (dev->board) {
1030 case CX23885_BOARD_HAUPPAUGE_HVR1250: 1115 case CX23885_BOARD_HAUPPAUGE_HVR1250:
1116 if (dev->i2c_bus[0].i2c_rc == 0) {
1117 if (eeprom[0x80] != 0x84)
1118 hauppauge_eeprom(dev, eeprom+0xc0);
1119 else
1120 hauppauge_eeprom(dev, eeprom+0x80);
1121 }
1122 break;
1031 case CX23885_BOARD_HAUPPAUGE_HVR1500: 1123 case CX23885_BOARD_HAUPPAUGE_HVR1500:
1032 case CX23885_BOARD_HAUPPAUGE_HVR1500Q: 1124 case CX23885_BOARD_HAUPPAUGE_HVR1500Q:
1033 case CX23885_BOARD_HAUPPAUGE_HVR1400: 1125 case CX23885_BOARD_HAUPPAUGE_HVR1400:
@@ -1136,6 +1228,11 @@ void cx23885_card_setup(struct cx23885_dev *dev)
1136 * loaded, ensure this happens. 1228 * loaded, ensure this happens.
1137 */ 1229 */
1138 switch (dev->board) { 1230 switch (dev->board) {
1231 case CX23885_BOARD_TEVII_S470:
1232 case CX23885_BOARD_HAUPPAUGE_HVR1250:
1233 /* Currently only enabled for the integrated IR controller */
1234 if (!enable_885_ir)
1235 break;
1139 case CX23885_BOARD_HAUPPAUGE_HVR1800: 1236 case CX23885_BOARD_HAUPPAUGE_HVR1800:
1140 case CX23885_BOARD_HAUPPAUGE_HVR1800lp: 1237 case CX23885_BOARD_HAUPPAUGE_HVR1800lp:
1141 case CX23885_BOARD_HAUPPAUGE_HVR1700: 1238 case CX23885_BOARD_HAUPPAUGE_HVR1700:
@@ -1151,7 +1248,10 @@ void cx23885_card_setup(struct cx23885_dev *dev)
1151 dev->sd_cx25840 = v4l2_i2c_new_subdev(&dev->v4l2_dev, 1248 dev->sd_cx25840 = v4l2_i2c_new_subdev(&dev->v4l2_dev,
1152 &dev->i2c_bus[2].i2c_adap, 1249 &dev->i2c_bus[2].i2c_adap,
1153 "cx25840", "cx25840", 0x88 >> 1, NULL); 1250 "cx25840", "cx25840", 0x88 >> 1, NULL);
1154 v4l2_subdev_call(dev->sd_cx25840, core, load_fw); 1251 if (dev->sd_cx25840) {
1252 dev->sd_cx25840->grp_id = CX23885_HW_AV_CORE;
1253 v4l2_subdev_call(dev->sd_cx25840, core, load_fw);
1254 }
1155 break; 1255 break;
1156 } 1256 }
1157 1257
diff --git a/drivers/media/video/cx23885/cx23885-core.c b/drivers/media/video/cx23885/cx23885-core.c
index ff76f64edac1..f6b62e7398af 100644
--- a/drivers/media/video/cx23885/cx23885-core.c
+++ b/drivers/media/video/cx23885/cx23885-core.c
@@ -34,6 +34,7 @@
34#include "cimax2.h" 34#include "cimax2.h"
35#include "cx23888-ir.h" 35#include "cx23888-ir.h"
36#include "cx23885-ir.h" 36#include "cx23885-ir.h"
37#include "cx23885-av.h"
37#include "cx23885-input.h" 38#include "cx23885-input.h"
38 39
39MODULE_DESCRIPTION("Driver for cx23885 based TV cards"); 40MODULE_DESCRIPTION("Driver for cx23885 based TV cards");
@@ -299,6 +300,83 @@ static struct sram_channel cx23887_sram_channels[] = {
299 }, 300 },
300}; 301};
301 302
303void cx23885_irq_add(struct cx23885_dev *dev, u32 mask)
304{
305 unsigned long flags;
306 spin_lock_irqsave(&dev->pci_irqmask_lock, flags);
307
308 dev->pci_irqmask |= mask;
309
310 spin_unlock_irqrestore(&dev->pci_irqmask_lock, flags);
311}
312
313void cx23885_irq_add_enable(struct cx23885_dev *dev, u32 mask)
314{
315 unsigned long flags;
316 spin_lock_irqsave(&dev->pci_irqmask_lock, flags);
317
318 dev->pci_irqmask |= mask;
319 cx_set(PCI_INT_MSK, mask);
320
321 spin_unlock_irqrestore(&dev->pci_irqmask_lock, flags);
322}
323
324void cx23885_irq_enable(struct cx23885_dev *dev, u32 mask)
325{
326 u32 v;
327 unsigned long flags;
328 spin_lock_irqsave(&dev->pci_irqmask_lock, flags);
329
330 v = mask & dev->pci_irqmask;
331 if (v)
332 cx_set(PCI_INT_MSK, v);
333
334 spin_unlock_irqrestore(&dev->pci_irqmask_lock, flags);
335}
336
337static inline void cx23885_irq_enable_all(struct cx23885_dev *dev)
338{
339 cx23885_irq_enable(dev, 0xffffffff);
340}
341
342void cx23885_irq_disable(struct cx23885_dev *dev, u32 mask)
343{
344 unsigned long flags;
345 spin_lock_irqsave(&dev->pci_irqmask_lock, flags);
346
347 cx_clear(PCI_INT_MSK, mask);
348
349 spin_unlock_irqrestore(&dev->pci_irqmask_lock, flags);
350}
351
352static inline void cx23885_irq_disable_all(struct cx23885_dev *dev)
353{
354 cx23885_irq_disable(dev, 0xffffffff);
355}
356
357void cx23885_irq_remove(struct cx23885_dev *dev, u32 mask)
358{
359 unsigned long flags;
360 spin_lock_irqsave(&dev->pci_irqmask_lock, flags);
361
362 dev->pci_irqmask &= ~mask;
363 cx_clear(PCI_INT_MSK, mask);
364
365 spin_unlock_irqrestore(&dev->pci_irqmask_lock, flags);
366}
367
368static u32 cx23885_irq_get_mask(struct cx23885_dev *dev)
369{
370 u32 v;
371 unsigned long flags;
372 spin_lock_irqsave(&dev->pci_irqmask_lock, flags);
373
374 v = cx_read(PCI_INT_MSK);
375
376 spin_unlock_irqrestore(&dev->pci_irqmask_lock, flags);
377 return v;
378}
379
302static int cx23885_risc_decode(u32 risc) 380static int cx23885_risc_decode(u32 risc)
303{ 381{
304 static char *instr[16] = { 382 static char *instr[16] = {
@@ -548,7 +626,7 @@ static void cx23885_shutdown(struct cx23885_dev *dev)
548 cx_write(UART_CTL, 0); 626 cx_write(UART_CTL, 0);
549 627
550 /* Disable Interrupts */ 628 /* Disable Interrupts */
551 cx_write(PCI_INT_MSK, 0); 629 cx23885_irq_disable_all(dev);
552 cx_write(VID_A_INT_MSK, 0); 630 cx_write(VID_A_INT_MSK, 0);
553 cx_write(VID_B_INT_MSK, 0); 631 cx_write(VID_B_INT_MSK, 0);
554 cx_write(VID_C_INT_MSK, 0); 632 cx_write(VID_C_INT_MSK, 0);
@@ -774,6 +852,8 @@ static int cx23885_dev_setup(struct cx23885_dev *dev)
774{ 852{
775 int i; 853 int i;
776 854
855 spin_lock_init(&dev->pci_irqmask_lock);
856
777 mutex_init(&dev->lock); 857 mutex_init(&dev->lock);
778 mutex_init(&dev->gpio_lock); 858 mutex_init(&dev->gpio_lock);
779 859
@@ -820,9 +900,9 @@ static int cx23885_dev_setup(struct cx23885_dev *dev)
820 900
821 dev->pci_bus = dev->pci->bus->number; 901 dev->pci_bus = dev->pci->bus->number;
822 dev->pci_slot = PCI_SLOT(dev->pci->devfn); 902 dev->pci_slot = PCI_SLOT(dev->pci->devfn);
823 dev->pci_irqmask = 0x001f00; 903 cx23885_irq_add(dev, 0x001f00);
824 if (cx23885_boards[dev->board].cimax > 0) 904 if (cx23885_boards[dev->board].cimax > 0)
825 dev->pci_irqmask |= 0x01800000; /* for CiMaxes */ 905 cx23885_irq_add(dev, 0x01800000); /* for CiMaxes */
826 906
827 /* External Master 1 Bus */ 907 /* External Master 1 Bus */
828 dev->i2c_bus[0].nr = 0; 908 dev->i2c_bus[0].nr = 0;
@@ -1156,7 +1236,7 @@ static void cx23885_tsport_reg_dump(struct cx23885_tsport *port)
1156 dprintk(1, "%s() DEV_CNTRL2 0x%08X\n", __func__, 1236 dprintk(1, "%s() DEV_CNTRL2 0x%08X\n", __func__,
1157 cx_read(DEV_CNTRL2)); 1237 cx_read(DEV_CNTRL2));
1158 dprintk(1, "%s() PCI_INT_MSK 0x%08X\n", __func__, 1238 dprintk(1, "%s() PCI_INT_MSK 0x%08X\n", __func__,
1159 cx_read(PCI_INT_MSK)); 1239 cx23885_irq_get_mask(dev));
1160 dprintk(1, "%s() AUD_INT_INT_MSK 0x%08X\n", __func__, 1240 dprintk(1, "%s() AUD_INT_INT_MSK 0x%08X\n", __func__,
1161 cx_read(AUDIO_INT_INT_MSK)); 1241 cx_read(AUDIO_INT_INT_MSK));
1162 dprintk(1, "%s() AUD_INT_DMA_CTL 0x%08X\n", __func__, 1242 dprintk(1, "%s() AUD_INT_DMA_CTL 0x%08X\n", __func__,
@@ -1292,7 +1372,8 @@ static int cx23885_start_dma(struct cx23885_tsport *port,
1292 dprintk(1, "%s() enabling TS int's and DMA\n", __func__); 1372 dprintk(1, "%s() enabling TS int's and DMA\n", __func__);
1293 cx_set(port->reg_ts_int_msk, port->ts_int_msk_val); 1373 cx_set(port->reg_ts_int_msk, port->ts_int_msk_val);
1294 cx_set(port->reg_dma_ctl, port->dma_ctl_val); 1374 cx_set(port->reg_dma_ctl, port->dma_ctl_val);
1295 cx_set(PCI_INT_MSK, dev->pci_irqmask | port->pci_irqmask); 1375 cx23885_irq_add(dev, port->pci_irqmask);
1376 cx23885_irq_enable_all(dev);
1296 break; 1377 break;
1297 default: 1378 default:
1298 BUG(); 1379 BUG();
@@ -1650,10 +1731,10 @@ static irqreturn_t cx23885_irq(int irq, void *dev_id)
1650 u32 ts1_status, ts1_mask; 1731 u32 ts1_status, ts1_mask;
1651 u32 ts2_status, ts2_mask; 1732 u32 ts2_status, ts2_mask;
1652 int vida_count = 0, ts1_count = 0, ts2_count = 0, handled = 0; 1733 int vida_count = 0, ts1_count = 0, ts2_count = 0, handled = 0;
1653 bool ir_handled = false; 1734 bool subdev_handled;
1654 1735
1655 pci_status = cx_read(PCI_INT_STAT); 1736 pci_status = cx_read(PCI_INT_STAT);
1656 pci_mask = cx_read(PCI_INT_MSK); 1737 pci_mask = cx23885_irq_get_mask(dev);
1657 vida_status = cx_read(VID_A_INT_STAT); 1738 vida_status = cx_read(VID_A_INT_STAT);
1658 vida_mask = cx_read(VID_A_INT_MSK); 1739 vida_mask = cx_read(VID_A_INT_MSK);
1659 ts1_status = cx_read(VID_B_INT_STAT); 1740 ts1_status = cx_read(VID_B_INT_STAT);
@@ -1681,7 +1762,7 @@ static irqreturn_t cx23885_irq(int irq, void *dev_id)
1681 PCI_MSK_VID_C | PCI_MSK_VID_B | PCI_MSK_VID_A | 1762 PCI_MSK_VID_C | PCI_MSK_VID_B | PCI_MSK_VID_A |
1682 PCI_MSK_AUD_INT | PCI_MSK_AUD_EXT | 1763 PCI_MSK_AUD_INT | PCI_MSK_AUD_EXT |
1683 PCI_MSK_GPIO0 | PCI_MSK_GPIO1 | 1764 PCI_MSK_GPIO0 | PCI_MSK_GPIO1 |
1684 PCI_MSK_IR)) { 1765 PCI_MSK_AV_CORE | PCI_MSK_IR)) {
1685 1766
1686 if (pci_status & PCI_MSK_RISC_RD) 1767 if (pci_status & PCI_MSK_RISC_RD)
1687 dprintk(7, " (PCI_MSK_RISC_RD 0x%08x)\n", 1768 dprintk(7, " (PCI_MSK_RISC_RD 0x%08x)\n",
@@ -1731,6 +1812,10 @@ static irqreturn_t cx23885_irq(int irq, void *dev_id)
1731 dprintk(7, " (PCI_MSK_GPIO1 0x%08x)\n", 1812 dprintk(7, " (PCI_MSK_GPIO1 0x%08x)\n",
1732 PCI_MSK_GPIO1); 1813 PCI_MSK_GPIO1);
1733 1814
1815 if (pci_status & PCI_MSK_AV_CORE)
1816 dprintk(7, " (PCI_MSK_AV_CORE 0x%08x)\n",
1817 PCI_MSK_AV_CORE);
1818
1734 if (pci_status & PCI_MSK_IR) 1819 if (pci_status & PCI_MSK_IR)
1735 dprintk(7, " (PCI_MSK_IR 0x%08x)\n", 1820 dprintk(7, " (PCI_MSK_IR 0x%08x)\n",
1736 PCI_MSK_IR); 1821 PCI_MSK_IR);
@@ -1765,12 +1850,22 @@ static irqreturn_t cx23885_irq(int irq, void *dev_id)
1765 handled += cx23885_video_irq(dev, vida_status); 1850 handled += cx23885_video_irq(dev, vida_status);
1766 1851
1767 if (pci_status & PCI_MSK_IR) { 1852 if (pci_status & PCI_MSK_IR) {
1768 v4l2_subdev_call(dev->sd_ir, ir, interrupt_service_routine, 1853 subdev_handled = false;
1769 pci_status, &ir_handled); 1854 v4l2_subdev_call(dev->sd_ir, core, interrupt_service_routine,
1770 if (ir_handled) 1855 pci_status, &subdev_handled);
1856 if (subdev_handled)
1771 handled++; 1857 handled++;
1772 } 1858 }
1773 1859
1860 if ((pci_status & pci_mask) & PCI_MSK_AV_CORE) {
1861 cx23885_irq_disable(dev, PCI_MSK_AV_CORE);
1862 if (!schedule_work(&dev->cx25840_work))
1863 printk(KERN_ERR "%s: failed to set up deferred work for"
1864 " AV Core/IR interrupt. Interrupt is disabled"
1865 " and won't be re-enabled\n", dev->name);
1866 handled++;
1867 }
1868
1774 if (handled) 1869 if (handled)
1775 cx_write(PCI_INT_STAT, pci_status); 1870 cx_write(PCI_INT_STAT, pci_status);
1776out: 1871out:
@@ -1788,11 +1883,11 @@ static void cx23885_v4l2_dev_notify(struct v4l2_subdev *sd,
1788 dev = to_cx23885(sd->v4l2_dev); 1883 dev = to_cx23885(sd->v4l2_dev);
1789 1884
1790 switch (notification) { 1885 switch (notification) {
1791 case V4L2_SUBDEV_IR_RX_NOTIFY: /* Called in an IRQ context */ 1886 case V4L2_SUBDEV_IR_RX_NOTIFY: /* Possibly called in an IRQ context */
1792 if (sd == dev->sd_ir) 1887 if (sd == dev->sd_ir)
1793 cx23885_ir_rx_v4l2_dev_notify(sd, *(u32 *)arg); 1888 cx23885_ir_rx_v4l2_dev_notify(sd, *(u32 *)arg);
1794 break; 1889 break;
1795 case V4L2_SUBDEV_IR_TX_NOTIFY: /* Called in an IRQ context */ 1890 case V4L2_SUBDEV_IR_TX_NOTIFY: /* Possibly called in an IRQ context */
1796 if (sd == dev->sd_ir) 1891 if (sd == dev->sd_ir)
1797 cx23885_ir_tx_v4l2_dev_notify(sd, *(u32 *)arg); 1892 cx23885_ir_tx_v4l2_dev_notify(sd, *(u32 *)arg);
1798 break; 1893 break;
@@ -1801,6 +1896,7 @@ static void cx23885_v4l2_dev_notify(struct v4l2_subdev *sd,
1801 1896
1802static void cx23885_v4l2_dev_notify_init(struct cx23885_dev *dev) 1897static void cx23885_v4l2_dev_notify_init(struct cx23885_dev *dev)
1803{ 1898{
1899 INIT_WORK(&dev->cx25840_work, cx23885_av_work_handler);
1804 INIT_WORK(&dev->ir_rx_work, cx23885_ir_rx_work_handler); 1900 INIT_WORK(&dev->ir_rx_work, cx23885_ir_rx_work_handler);
1805 INIT_WORK(&dev->ir_tx_work, cx23885_ir_tx_work_handler); 1901 INIT_WORK(&dev->ir_tx_work, cx23885_ir_tx_work_handler);
1806 dev->v4l2_dev.notify = cx23885_v4l2_dev_notify; 1902 dev->v4l2_dev.notify = cx23885_v4l2_dev_notify;
@@ -1967,7 +2063,7 @@ static int __devinit cx23885_initdev(struct pci_dev *pci_dev,
1967 2063
1968 switch (dev->board) { 2064 switch (dev->board) {
1969 case CX23885_BOARD_NETUP_DUAL_DVBS2_CI: 2065 case CX23885_BOARD_NETUP_DUAL_DVBS2_CI:
1970 cx_set(PCI_INT_MSK, 0x01800000); /* for NetUP */ 2066 cx23885_irq_add_enable(dev, 0x01800000); /* for NetUP */
1971 break; 2067 break;
1972 } 2068 }
1973 2069
diff --git a/drivers/media/video/cx23885/cx23885-i2c.c b/drivers/media/video/cx23885/cx23885-i2c.c
index d4746e064516..ed3d8f55029b 100644
--- a/drivers/media/video/cx23885/cx23885-i2c.c
+++ b/drivers/media/video/cx23885/cx23885-i2c.c
@@ -99,7 +99,7 @@ static int i2c_sendbytes(struct i2c_adapter *i2c_adap,
99 if (!i2c_wait_done(i2c_adap)) 99 if (!i2c_wait_done(i2c_adap))
100 return -EIO; 100 return -EIO;
101 if (!i2c_slave_did_ack(i2c_adap)) 101 if (!i2c_slave_did_ack(i2c_adap))
102 return -EIO; 102 return -ENXIO;
103 103
104 dprintk(1, "%s() returns 0\n", __func__); 104 dprintk(1, "%s() returns 0\n", __func__);
105 return 0; 105 return 0;
@@ -120,11 +120,12 @@ static int i2c_sendbytes(struct i2c_adapter *i2c_adap,
120 cx_write(bus->reg_wdata, wdata); 120 cx_write(bus->reg_wdata, wdata);
121 cx_write(bus->reg_ctrl, ctrl); 121 cx_write(bus->reg_ctrl, ctrl);
122 122
123 retval = i2c_wait_done(i2c_adap); 123 if (!i2c_wait_done(i2c_adap))
124 if (retval < 0)
125 goto err;
126 if (retval == 0)
127 goto eio; 124 goto eio;
125 if (!i2c_slave_did_ack(i2c_adap)) {
126 retval = -ENXIO;
127 goto err;
128 }
128 if (i2c_debug) { 129 if (i2c_debug) {
129 printk(" <W %02x %02x", msg->addr << 1, msg->buf[0]); 130 printk(" <W %02x %02x", msg->addr << 1, msg->buf[0]);
130 if (!(ctrl & I2C_NOSTOP)) 131 if (!(ctrl & I2C_NOSTOP))
@@ -145,10 +146,7 @@ static int i2c_sendbytes(struct i2c_adapter *i2c_adap,
145 cx_write(bus->reg_wdata, wdata); 146 cx_write(bus->reg_wdata, wdata);
146 cx_write(bus->reg_ctrl, ctrl); 147 cx_write(bus->reg_ctrl, ctrl);
147 148
148 retval = i2c_wait_done(i2c_adap); 149 if (!i2c_wait_done(i2c_adap))
149 if (retval < 0)
150 goto err;
151 if (retval == 0)
152 goto eio; 150 goto eio;
153 if (i2c_debug) { 151 if (i2c_debug) {
154 dprintk(1, " %02x", msg->buf[cnt]); 152 dprintk(1, " %02x", msg->buf[cnt]);
@@ -185,7 +183,7 @@ static int i2c_readbytes(struct i2c_adapter *i2c_adap,
185 if (!i2c_wait_done(i2c_adap)) 183 if (!i2c_wait_done(i2c_adap))
186 return -EIO; 184 return -EIO;
187 if (!i2c_slave_did_ack(i2c_adap)) 185 if (!i2c_slave_did_ack(i2c_adap))
188 return -EIO; 186 return -ENXIO;
189 187
190 188
191 dprintk(1, "%s() returns 0\n", __func__); 189 dprintk(1, "%s() returns 0\n", __func__);
@@ -209,11 +207,12 @@ static int i2c_readbytes(struct i2c_adapter *i2c_adap,
209 cx_write(bus->reg_addr, msg->addr << 25); 207 cx_write(bus->reg_addr, msg->addr << 25);
210 cx_write(bus->reg_ctrl, ctrl); 208 cx_write(bus->reg_ctrl, ctrl);
211 209
212 retval = i2c_wait_done(i2c_adap); 210 if (!i2c_wait_done(i2c_adap))
213 if (retval < 0)
214 goto err;
215 if (retval == 0)
216 goto eio; 211 goto eio;
212 if (cnt == 0 && !i2c_slave_did_ack(i2c_adap)) {
213 retval = -ENXIO;
214 goto err;
215 }
217 msg->buf[cnt] = cx_read(bus->reg_rdata) & 0xff; 216 msg->buf[cnt] = cx_read(bus->reg_rdata) & 0xff;
218 if (i2c_debug) { 217 if (i2c_debug) {
219 dprintk(1, " %02x", msg->buf[cnt]); 218 dprintk(1, " %02x", msg->buf[cnt]);
@@ -365,17 +364,10 @@ int cx23885_i2c_register(struct cx23885_i2c *bus)
365 364
366 memset(&info, 0, sizeof(struct i2c_board_info)); 365 memset(&info, 0, sizeof(struct i2c_board_info));
367 strlcpy(info.type, "ir_video", I2C_NAME_SIZE); 366 strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
368 /* 367 /* Use quick read command for probe, some IR chips don't
369 * We can't call i2c_new_probed_device() because it uses 368 * support writes */
370 * quick writes for probing and the IR receiver device only 369 i2c_new_probed_device(&bus->i2c_adap, &info, addr_list,
371 * replies to reads. 370 i2c_probe_func_quick_read);
372 */
373 if (i2c_smbus_xfer(&bus->i2c_adap, addr_list[0], 0,
374 I2C_SMBUS_READ, 0, I2C_SMBUS_QUICK,
375 NULL) >= 0) {
376 info.addr = addr_list[0];
377 i2c_new_device(&bus->i2c_adap, &info);
378 }
379 } 371 }
380 372
381 return bus->i2c_rc; 373 return bus->i2c_rc;
diff --git a/drivers/media/video/cx23885/cx23885-input.c b/drivers/media/video/cx23885/cx23885-input.c
index d0b1613ede2f..bb61870b8d6e 100644
--- a/drivers/media/video/cx23885/cx23885-input.c
+++ b/drivers/media/video/cx23885/cx23885-input.c
@@ -44,40 +44,26 @@
44 44
45#define MODULE_NAME "cx23885" 45#define MODULE_NAME "cx23885"
46 46
47static void convert_measurement(u32 x, struct ir_raw_event *y)
48{
49 if (x == V4L2_SUBDEV_IR_PULSE_RX_SEQ_END) {
50 y->pulse = false;
51 y->duration = V4L2_SUBDEV_IR_PULSE_MAX_WIDTH_NS;
52 return;
53 }
54
55 y->pulse = (x & V4L2_SUBDEV_IR_PULSE_LEVEL_MASK) ? true : false;
56 y->duration = x & V4L2_SUBDEV_IR_PULSE_MAX_WIDTH_NS;
57}
58
59static void cx23885_input_process_measurements(struct cx23885_dev *dev, 47static void cx23885_input_process_measurements(struct cx23885_dev *dev,
60 bool overrun) 48 bool overrun)
61{ 49{
62 struct cx23885_kernel_ir *kernel_ir = dev->kernel_ir; 50 struct cx23885_kernel_ir *kernel_ir = dev->kernel_ir;
63 struct ir_raw_event kernel_ir_event;
64 51
65 u32 sd_ir_data[64];
66 ssize_t num; 52 ssize_t num;
67 int count, i; 53 int count, i;
68 bool handle = false; 54 bool handle = false;
55 struct ir_raw_event ir_core_event[64];
69 56
70 do { 57 do {
71 num = 0; 58 num = 0;
72 v4l2_subdev_call(dev->sd_ir, ir, rx_read, (u8 *) sd_ir_data, 59 v4l2_subdev_call(dev->sd_ir, ir, rx_read, (u8 *) ir_core_event,
73 sizeof(sd_ir_data), &num); 60 sizeof(ir_core_event), &num);
74 61
75 count = num / sizeof(u32); 62 count = num / sizeof(struct ir_raw_event);
76 63
77 for (i = 0; i < count; i++) { 64 for (i = 0; i < count; i++) {
78 convert_measurement(sd_ir_data[i], &kernel_ir_event);
79 ir_raw_event_store(kernel_ir->inp_dev, 65 ir_raw_event_store(kernel_ir->inp_dev,
80 &kernel_ir_event); 66 &ir_core_event[i]);
81 handle = true; 67 handle = true;
82 } 68 }
83 } while (num != 0); 69 } while (num != 0);
@@ -99,8 +85,10 @@ void cx23885_input_rx_work_handler(struct cx23885_dev *dev, u32 events)
99 switch (dev->board) { 85 switch (dev->board) {
100 case CX23885_BOARD_HAUPPAUGE_HVR1850: 86 case CX23885_BOARD_HAUPPAUGE_HVR1850:
101 case CX23885_BOARD_HAUPPAUGE_HVR1290: 87 case CX23885_BOARD_HAUPPAUGE_HVR1290:
88 case CX23885_BOARD_TEVII_S470:
89 case CX23885_BOARD_HAUPPAUGE_HVR1250:
102 /* 90 /*
103 * The only board we handle right now. However other boards 91 * The only boards we handle right now. However other boards
104 * using the CX2388x integrated IR controller should be similar 92 * using the CX2388x integrated IR controller should be similar
105 */ 93 */
106 break; 94 break;
@@ -148,6 +136,7 @@ static int cx23885_input_ir_start(struct cx23885_dev *dev)
148 switch (dev->board) { 136 switch (dev->board) {
149 case CX23885_BOARD_HAUPPAUGE_HVR1850: 137 case CX23885_BOARD_HAUPPAUGE_HVR1850:
150 case CX23885_BOARD_HAUPPAUGE_HVR1290: 138 case CX23885_BOARD_HAUPPAUGE_HVR1290:
139 case CX23885_BOARD_HAUPPAUGE_HVR1250:
151 /* 140 /*
152 * The IR controller on this board only returns pulse widths. 141 * The IR controller on this board only returns pulse widths.
153 * Any other mode setting will fail to set up the device. 142 * Any other mode setting will fail to set up the device.
@@ -170,7 +159,38 @@ static int cx23885_input_ir_start(struct cx23885_dev *dev)
170 * mark is received as low logic level; 159 * mark is received as low logic level;
171 * falling edges are detected as rising edges; etc. 160 * falling edges are detected as rising edges; etc.
172 */ 161 */
173 params.invert = true; 162 params.invert_level = true;
163 break;
164 case CX23885_BOARD_TEVII_S470:
165 /*
166 * The IR controller on this board only returns pulse widths.
167 * Any other mode setting will fail to set up the device.
168 */
169 params.mode = V4L2_SUBDEV_IR_MODE_PULSE_WIDTH;
170 params.enable = true;
171 params.interrupt_enable = true;
172 params.shutdown = false;
173
174 /* Setup for a standard NEC protocol */
175 params.carrier_freq = 37917; /* Hz, 455 kHz/12 for NEC */
176 params.carrier_range_lower = 33000; /* Hz */
177 params.carrier_range_upper = 43000; /* Hz */
178 params.duty_cycle = 33; /* percent, 33 percent for NEC */
179
180 /*
181 * NEC max pulse width: (64/3)/(455 kHz/12) * 16 nec_units
182 * (64/3)/(455 kHz/12) * 16 nec_units * 1.375 = 12378022 ns
183 */
184 params.max_pulse_width = 12378022; /* ns */
185
186 /*
187 * NEC noise filter min width: (64/3)/(455 kHz/12) * 1 nec_unit
188 * (64/3)/(455 kHz/12) * 1 nec_units * 0.625 = 351648 ns
189 */
190 params.noise_filter_min_width = 351648; /* ns */
191
192 params.modulation = false;
193 params.invert_level = true;
174 break; 194 break;
175 } 195 }
176 v4l2_subdev_call(dev->sd_ir, ir, rx_s_parameters, &params); 196 v4l2_subdev_call(dev->sd_ir, ir, rx_s_parameters, &params);
@@ -244,12 +264,20 @@ int cx23885_input_init(struct cx23885_dev *dev)
244 switch (dev->board) { 264 switch (dev->board) {
245 case CX23885_BOARD_HAUPPAUGE_HVR1850: 265 case CX23885_BOARD_HAUPPAUGE_HVR1850:
246 case CX23885_BOARD_HAUPPAUGE_HVR1290: 266 case CX23885_BOARD_HAUPPAUGE_HVR1290:
247 /* Integrated CX23888 IR controller */ 267 case CX23885_BOARD_HAUPPAUGE_HVR1250:
268 /* Integrated CX2388[58] IR controller */
248 driver_type = RC_DRIVER_IR_RAW; 269 driver_type = RC_DRIVER_IR_RAW;
249 allowed_protos = IR_TYPE_ALL; 270 allowed_protos = IR_TYPE_ALL;
250 /* The grey Hauppauge RC-5 remote */ 271 /* The grey Hauppauge RC-5 remote */
251 rc_map = RC_MAP_RC5_HAUPPAUGE_NEW; 272 rc_map = RC_MAP_RC5_HAUPPAUGE_NEW;
252 break; 273 break;
274 case CX23885_BOARD_TEVII_S470:
275 /* Integrated CX23885 IR controller */
276 driver_type = RC_DRIVER_IR_RAW;
277 allowed_protos = IR_TYPE_ALL;
278 /* A guess at the remote */
279 rc_map = RC_MAP_TEVII_NEC;
280 break;
253 default: 281 default:
254 return -ENODEV; 282 return -ENODEV;
255 } 283 }
diff --git a/drivers/media/video/cx23885/cx23885-ir.c b/drivers/media/video/cx23885/cx23885-ir.c
index 6ceabd4fba07..7125247dd255 100644
--- a/drivers/media/video/cx23885/cx23885-ir.c
+++ b/drivers/media/video/cx23885/cx23885-ir.c
@@ -72,7 +72,7 @@ void cx23885_ir_tx_work_handler(struct work_struct *work)
72 72
73} 73}
74 74
75/* Called in an IRQ context */ 75/* Possibly called in an IRQ context */
76void cx23885_ir_rx_v4l2_dev_notify(struct v4l2_subdev *sd, u32 events) 76void cx23885_ir_rx_v4l2_dev_notify(struct v4l2_subdev *sd, u32 events)
77{ 77{
78 struct cx23885_dev *dev = to_cx23885(sd->v4l2_dev); 78 struct cx23885_dev *dev = to_cx23885(sd->v4l2_dev);
@@ -86,10 +86,18 @@ void cx23885_ir_rx_v4l2_dev_notify(struct v4l2_subdev *sd, u32 events)
86 set_bit(CX23885_IR_RX_HW_FIFO_OVERRUN, notifications); 86 set_bit(CX23885_IR_RX_HW_FIFO_OVERRUN, notifications);
87 if (events & V4L2_SUBDEV_IR_RX_SW_FIFO_OVERRUN) 87 if (events & V4L2_SUBDEV_IR_RX_SW_FIFO_OVERRUN)
88 set_bit(CX23885_IR_RX_SW_FIFO_OVERRUN, notifications); 88 set_bit(CX23885_IR_RX_SW_FIFO_OVERRUN, notifications);
89 schedule_work(&dev->ir_rx_work); 89
90 /*
91 * For the integrated AV core, we are already in a workqueue context.
92 * For the CX23888 integrated IR, we are in an interrupt context.
93 */
94 if (sd == dev->sd_cx25840)
95 cx23885_ir_rx_work_handler(&dev->ir_rx_work);
96 else
97 schedule_work(&dev->ir_rx_work);
90} 98}
91 99
92/* Called in an IRQ context */ 100/* Possibly called in an IRQ context */
93void cx23885_ir_tx_v4l2_dev_notify(struct v4l2_subdev *sd, u32 events) 101void cx23885_ir_tx_v4l2_dev_notify(struct v4l2_subdev *sd, u32 events)
94{ 102{
95 struct cx23885_dev *dev = to_cx23885(sd->v4l2_dev); 103 struct cx23885_dev *dev = to_cx23885(sd->v4l2_dev);
@@ -97,5 +105,13 @@ void cx23885_ir_tx_v4l2_dev_notify(struct v4l2_subdev *sd, u32 events)
97 105
98 if (events & V4L2_SUBDEV_IR_TX_FIFO_SERVICE_REQ) 106 if (events & V4L2_SUBDEV_IR_TX_FIFO_SERVICE_REQ)
99 set_bit(CX23885_IR_TX_FIFO_SERVICE_REQ, notifications); 107 set_bit(CX23885_IR_TX_FIFO_SERVICE_REQ, notifications);
100 schedule_work(&dev->ir_tx_work); 108
109 /*
110 * For the integrated AV core, we are already in a workqueue context.
111 * For the CX23888 integrated IR, we are in an interrupt context.
112 */
113 if (sd == dev->sd_cx25840)
114 cx23885_ir_tx_work_handler(&dev->ir_tx_work);
115 else
116 schedule_work(&dev->ir_tx_work);
101} 117}
diff --git a/drivers/media/video/cx23885/cx23885-reg.h b/drivers/media/video/cx23885/cx23885-reg.h
index c0bc9a068954..a28772db11f0 100644
--- a/drivers/media/video/cx23885/cx23885-reg.h
+++ b/drivers/media/video/cx23885/cx23885-reg.h
@@ -213,6 +213,7 @@ Channel manager Data Structure entry = 20 DWORD
213#define DEV_CNTRL2 0x00040000 213#define DEV_CNTRL2 0x00040000
214 214
215#define PCI_MSK_IR (1 << 28) 215#define PCI_MSK_IR (1 << 28)
216#define PCI_MSK_AV_CORE (1 << 27)
216#define PCI_MSK_GPIO1 (1 << 24) 217#define PCI_MSK_GPIO1 (1 << 24)
217#define PCI_MSK_GPIO0 (1 << 23) 218#define PCI_MSK_GPIO0 (1 << 23)
218#define PCI_MSK_APB_DMA (1 << 12) 219#define PCI_MSK_APB_DMA (1 << 12)
diff --git a/drivers/media/video/cx23885/cx23885-vbi.c b/drivers/media/video/cx23885/cx23885-vbi.c
index 708a8c766d1a..c0b60382ad13 100644
--- a/drivers/media/video/cx23885/cx23885-vbi.c
+++ b/drivers/media/video/cx23885/cx23885-vbi.c
@@ -74,7 +74,7 @@ static int cx23885_start_vbi_dma(struct cx23885_dev *dev,
74 q->count = 1; 74 q->count = 1;
75 75
76 /* enable irqs */ 76 /* enable irqs */
77 cx_set(PCI_INT_MSK, cx_read(PCI_INT_MSK) | 0x01); 77 cx23885_irq_add_enable(dev, 0x01);
78 cx_set(VID_A_INT_MSK, 0x000022); 78 cx_set(VID_A_INT_MSK, 0x000022);
79 79
80 /* start dma */ 80 /* start dma */
diff --git a/drivers/media/video/cx23885/cx23885-video.c b/drivers/media/video/cx23885/cx23885-video.c
index 4e44dcda3875..da66e5f8d91d 100644
--- a/drivers/media/video/cx23885/cx23885-video.c
+++ b/drivers/media/video/cx23885/cx23885-video.c
@@ -441,7 +441,7 @@ static int cx23885_start_video_dma(struct cx23885_dev *dev,
441 q->count = 1; 441 q->count = 1;
442 442
443 /* enable irq */ 443 /* enable irq */
444 cx_set(PCI_INT_MSK, cx_read(PCI_INT_MSK) | 0x01); 444 cx23885_irq_add_enable(dev, 0x01);
445 cx_set(VID_A_INT_MSK, 0x000011); 445 cx_set(VID_A_INT_MSK, 0x000011);
446 446
447 /* start dma */ 447 /* start dma */
@@ -1205,6 +1205,21 @@ static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
1205 return 0; 1205 return 0;
1206} 1206}
1207 1207
1208static int vidioc_log_status(struct file *file, void *priv)
1209{
1210 struct cx23885_fh *fh = priv;
1211 struct cx23885_dev *dev = fh->dev;
1212
1213 printk(KERN_INFO
1214 "%s/0: ============ START LOG STATUS ============\n",
1215 dev->name);
1216 call_all(dev, core, log_status);
1217 printk(KERN_INFO
1218 "%s/0: ============= END LOG STATUS =============\n",
1219 dev->name);
1220 return 0;
1221}
1222
1208static int vidioc_queryctrl(struct file *file, void *priv, 1223static int vidioc_queryctrl(struct file *file, void *priv,
1209 struct v4l2_queryctrl *qctrl) 1224 struct v4l2_queryctrl *qctrl)
1210{ 1225{
@@ -1410,6 +1425,7 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
1410 .vidioc_enum_input = vidioc_enum_input, 1425 .vidioc_enum_input = vidioc_enum_input,
1411 .vidioc_g_input = vidioc_g_input, 1426 .vidioc_g_input = vidioc_g_input,
1412 .vidioc_s_input = vidioc_s_input, 1427 .vidioc_s_input = vidioc_s_input,
1428 .vidioc_log_status = vidioc_log_status,
1413 .vidioc_queryctrl = vidioc_queryctrl, 1429 .vidioc_queryctrl = vidioc_queryctrl,
1414 .vidioc_g_ctrl = vidioc_g_ctrl, 1430 .vidioc_g_ctrl = vidioc_g_ctrl,
1415 .vidioc_s_ctrl = vidioc_s_ctrl, 1431 .vidioc_s_ctrl = vidioc_s_ctrl,
@@ -1449,7 +1465,7 @@ static const struct v4l2_file_operations radio_fops = {
1449void cx23885_video_unregister(struct cx23885_dev *dev) 1465void cx23885_video_unregister(struct cx23885_dev *dev)
1450{ 1466{
1451 dprintk(1, "%s()\n", __func__); 1467 dprintk(1, "%s()\n", __func__);
1452 cx_clear(PCI_INT_MSK, 1); 1468 cx23885_irq_remove(dev, 0x01);
1453 1469
1454 if (dev->video_dev) { 1470 if (dev->video_dev) {
1455 if (video_is_registered(dev->video_dev)) 1471 if (video_is_registered(dev->video_dev))
@@ -1486,7 +1502,8 @@ int cx23885_video_register(struct cx23885_dev *dev)
1486 VID_A_DMA_CTL, 0x11, 0x00); 1502 VID_A_DMA_CTL, 0x11, 0x00);
1487 1503
1488 /* Don't enable VBI yet */ 1504 /* Don't enable VBI yet */
1489 cx_set(PCI_INT_MSK, 1); 1505
1506 cx23885_irq_add_enable(dev, 0x01);
1490 1507
1491 if (TUNER_ABSENT != dev->tuner_type) { 1508 if (TUNER_ABSENT != dev->tuner_type) {
1492 struct v4l2_subdev *sd = NULL; 1509 struct v4l2_subdev *sd = NULL;
diff --git a/drivers/media/video/cx23885/cx23885.h b/drivers/media/video/cx23885/cx23885.h
index a33f2b71467b..ed94b17dd8a5 100644
--- a/drivers/media/video/cx23885/cx23885.h
+++ b/drivers/media/video/cx23885/cx23885.h
@@ -325,6 +325,7 @@ struct cx23885_dev {
325 u32 __iomem *lmmio; 325 u32 __iomem *lmmio;
326 u8 __iomem *bmmio; 326 u8 __iomem *bmmio;
327 int pci_irqmask; 327 int pci_irqmask;
328 spinlock_t pci_irqmask_lock; /* protects mask reg too */
328 int hwrevision; 329 int hwrevision;
329 330
330 /* This valud is board specific and is used to configure the 331 /* This valud is board specific and is used to configure the
@@ -365,6 +366,7 @@ struct cx23885_dev {
365 unsigned char radio_addr; 366 unsigned char radio_addr;
366 unsigned int has_radio; 367 unsigned int has_radio;
367 struct v4l2_subdev *sd_cx25840; 368 struct v4l2_subdev *sd_cx25840;
369 struct work_struct cx25840_work;
368 370
369 /* Infrared */ 371 /* Infrared */
370 struct v4l2_subdev *sd_ir; 372 struct v4l2_subdev *sd_ir;
@@ -403,7 +405,8 @@ static inline struct cx23885_dev *to_cx23885(struct v4l2_device *v4l2_dev)
403#define call_all(dev, o, f, args...) \ 405#define call_all(dev, o, f, args...) \
404 v4l2_device_call_all(&dev->v4l2_dev, 0, o, f, ##args) 406 v4l2_device_call_all(&dev->v4l2_dev, 0, o, f, ##args)
405 407
406#define CX23885_HW_888_IR (1 << 0) 408#define CX23885_HW_888_IR (1 << 0)
409#define CX23885_HW_AV_CORE (1 << 1)
407 410
408#define call_hw(dev, grpid, o, f, args...) \ 411#define call_hw(dev, grpid, o, f, args...) \
409 v4l2_device_call_all(&dev->v4l2_dev, grpid, o, f, ##args) 412 v4l2_device_call_all(&dev->v4l2_dev, grpid, o, f, ##args)
@@ -484,6 +487,10 @@ extern u32 cx23885_gpio_get(struct cx23885_dev *dev, u32 mask);
484extern void cx23885_gpio_enable(struct cx23885_dev *dev, u32 mask, 487extern void cx23885_gpio_enable(struct cx23885_dev *dev, u32 mask,
485 int asoutput); 488 int asoutput);
486 489
490extern void cx23885_irq_add_enable(struct cx23885_dev *dev, u32 mask);
491extern void cx23885_irq_enable(struct cx23885_dev *dev, u32 mask);
492extern void cx23885_irq_disable(struct cx23885_dev *dev, u32 mask);
493extern void cx23885_irq_remove(struct cx23885_dev *dev, u32 mask);
487 494
488/* ----------------------------------------------------------- */ 495/* ----------------------------------------------------------- */
489/* cx23885-cards.c */ 496/* cx23885-cards.c */
diff --git a/drivers/media/video/cx23885/cx23888-ir.c b/drivers/media/video/cx23885/cx23888-ir.c
index f63d378257a7..2502a0a67097 100644
--- a/drivers/media/video/cx23885/cx23888-ir.c
+++ b/drivers/media/video/cx23885/cx23888-ir.c
@@ -26,6 +26,7 @@
26 26
27#include <media/v4l2-device.h> 27#include <media/v4l2-device.h>
28#include <media/v4l2-chip-ident.h> 28#include <media/v4l2-chip-ident.h>
29#include <media/ir-core.h>
29 30
30#include "cx23885.h" 31#include "cx23885.h"
31 32
@@ -60,6 +61,8 @@ MODULE_PARM_DESC(ir_888_debug, "enable debug messages [CX23888 IR controller]");
60#define CNTRL_CPL 0x00001000 61#define CNTRL_CPL 0x00001000
61#define CNTRL_LBM 0x00002000 62#define CNTRL_LBM 0x00002000
62#define CNTRL_R 0x00004000 63#define CNTRL_R 0x00004000
64/* CX23888 specific control flag */
65#define CNTRL_IVO 0x00008000
63 66
64#define CX23888_IR_TXCLK_REG 0x170004 67#define CX23888_IR_TXCLK_REG 0x170004
65#define TXCLK_TCD 0x0000FFFF 68#define TXCLK_TCD 0x0000FFFF
@@ -111,8 +114,18 @@ MODULE_PARM_DESC(ir_888_debug, "enable debug messages [CX23888 IR controller]");
111#define CX23888_VIDCLK_FREQ 108000000 /* 108 MHz, BT.656 */ 114#define CX23888_VIDCLK_FREQ 108000000 /* 108 MHz, BT.656 */
112#define CX23888_IR_REFCLK_FREQ (CX23888_VIDCLK_FREQ / 2) 115#define CX23888_IR_REFCLK_FREQ (CX23888_VIDCLK_FREQ / 2)
113 116
114#define CX23888_IR_RX_KFIFO_SIZE (512 * sizeof(u32)) 117/*
115#define CX23888_IR_TX_KFIFO_SIZE (512 * sizeof(u32)) 118 * We use this union internally for convenience, but callers to tx_write
119 * and rx_read will be expecting records of type struct ir_raw_event.
120 * Always ensure the size of this union is dictated by struct ir_raw_event.
121 */
122union cx23888_ir_fifo_rec {
123 u32 hw_fifo_data;
124 struct ir_raw_event ir_core_data;
125};
126
127#define CX23888_IR_RX_KFIFO_SIZE (256 * sizeof(union cx23888_ir_fifo_rec))
128#define CX23888_IR_TX_KFIFO_SIZE (256 * sizeof(union cx23888_ir_fifo_rec))
116 129
117struct cx23888_ir_state { 130struct cx23888_ir_state {
118 struct v4l2_subdev sd; 131 struct v4l2_subdev sd;
@@ -423,6 +436,13 @@ static inline void control_tx_polarity_invert(struct cx23885_dev *dev,
423 invert ? CNTRL_CPL : 0); 436 invert ? CNTRL_CPL : 0);
424} 437}
425 438
439static inline void control_tx_level_invert(struct cx23885_dev *dev,
440 bool invert)
441{
442 cx23888_ir_and_or4(dev, CX23888_IR_CNTRL_REG, ~CNTRL_IVO,
443 invert ? CNTRL_IVO : 0);
444}
445
426/* 446/*
427 * IR Rx & Tx Clock Register helpers 447 * IR Rx & Tx Clock Register helpers
428 */ 448 */
@@ -449,8 +469,8 @@ static u32 txclk_tx_s_max_pulse_width(struct cx23885_dev *dev, u32 ns,
449{ 469{
450 u64 pulse_clocks; 470 u64 pulse_clocks;
451 471
452 if (ns > V4L2_SUBDEV_IR_PULSE_MAX_WIDTH_NS) 472 if (ns > IR_MAX_DURATION)
453 ns = V4L2_SUBDEV_IR_PULSE_MAX_WIDTH_NS; 473 ns = IR_MAX_DURATION;
454 pulse_clocks = ns_to_pulse_clocks(ns); 474 pulse_clocks = ns_to_pulse_clocks(ns);
455 *divider = pulse_clocks_to_clock_divider(pulse_clocks); 475 *divider = pulse_clocks_to_clock_divider(pulse_clocks);
456 cx23888_ir_write4(dev, CX23888_IR_TXCLK_REG, *divider); 476 cx23888_ir_write4(dev, CX23888_IR_TXCLK_REG, *divider);
@@ -462,8 +482,8 @@ static u32 rxclk_rx_s_max_pulse_width(struct cx23885_dev *dev, u32 ns,
462{ 482{
463 u64 pulse_clocks; 483 u64 pulse_clocks;
464 484
465 if (ns > V4L2_SUBDEV_IR_PULSE_MAX_WIDTH_NS) 485 if (ns > IR_MAX_DURATION)
466 ns = V4L2_SUBDEV_IR_PULSE_MAX_WIDTH_NS; 486 ns = IR_MAX_DURATION;
467 pulse_clocks = ns_to_pulse_clocks(ns); 487 pulse_clocks = ns_to_pulse_clocks(ns);
468 *divider = pulse_clocks_to_clock_divider(pulse_clocks); 488 *divider = pulse_clocks_to_clock_divider(pulse_clocks);
469 cx23888_ir_write4(dev, CX23888_IR_RXCLK_REG, *divider); 489 cx23888_ir_write4(dev, CX23888_IR_RXCLK_REG, *divider);
@@ -526,8 +546,8 @@ static int cx23888_ir_irq_handler(struct v4l2_subdev *sd, u32 status,
526 u32 irqen = cx23888_ir_read4(dev, CX23888_IR_IRQEN_REG); 546 u32 irqen = cx23888_ir_read4(dev, CX23888_IR_IRQEN_REG);
527 u32 stats = cx23888_ir_read4(dev, CX23888_IR_STATS_REG); 547 u32 stats = cx23888_ir_read4(dev, CX23888_IR_STATS_REG);
528 548
529 u32 rx_data[FIFO_RX_DEPTH]; 549 union cx23888_ir_fifo_rec rx_data[FIFO_RX_DEPTH];
530 int i, j, k; 550 unsigned int i, j, k;
531 u32 events, v; 551 u32 events, v;
532 int tsr, rsr, rto, ror, tse, rse, rte, roe, kror; 552 int tsr, rsr, rto, ror, tse, rse, rte, roe, kror;
533 553
@@ -588,11 +608,12 @@ static int cx23888_ir_irq_handler(struct v4l2_subdev *sd, u32 status,
588 for (j = 0; 608 for (j = 0;
589 (v & FIFO_RX_NDV) && j < FIFO_RX_DEPTH; j++) { 609 (v & FIFO_RX_NDV) && j < FIFO_RX_DEPTH; j++) {
590 v = cx23888_ir_read4(dev, CX23888_IR_FIFO_REG); 610 v = cx23888_ir_read4(dev, CX23888_IR_FIFO_REG);
591 rx_data[i++] = v & ~FIFO_RX_NDV; 611 rx_data[i].hw_fifo_data = v & ~FIFO_RX_NDV;
612 i++;
592 } 613 }
593 if (i == 0) 614 if (i == 0)
594 break; 615 break;
595 j = i * sizeof(u32); 616 j = i * sizeof(union cx23888_ir_fifo_rec);
596 k = kfifo_in_locked(&state->rx_kfifo, 617 k = kfifo_in_locked(&state->rx_kfifo,
597 (unsigned char *) rx_data, j, 618 (unsigned char *) rx_data, j,
598 &state->rx_kfifo_lock); 619 &state->rx_kfifo_lock);
@@ -651,10 +672,11 @@ static int cx23888_ir_rx_read(struct v4l2_subdev *sd, u8 *buf, size_t count,
651 u16 divider = (u16) atomic_read(&state->rxclk_divider); 672 u16 divider = (u16) atomic_read(&state->rxclk_divider);
652 673
653 unsigned int i, n; 674 unsigned int i, n;
654 u32 *p; 675 union cx23888_ir_fifo_rec *p;
655 u32 u, v; 676 unsigned u, v;
656 677
657 n = count / sizeof(u32) * sizeof(u32); 678 n = count / sizeof(union cx23888_ir_fifo_rec)
679 * sizeof(union cx23888_ir_fifo_rec);
658 if (n == 0) { 680 if (n == 0) {
659 *num = 0; 681 *num = 0;
660 return 0; 682 return 0;
@@ -662,26 +684,28 @@ static int cx23888_ir_rx_read(struct v4l2_subdev *sd, u8 *buf, size_t count,
662 684
663 n = kfifo_out_locked(&state->rx_kfifo, buf, n, &state->rx_kfifo_lock); 685 n = kfifo_out_locked(&state->rx_kfifo, buf, n, &state->rx_kfifo_lock);
664 686
665 n /= sizeof(u32); 687 n /= sizeof(union cx23888_ir_fifo_rec);
666 *num = n * sizeof(u32); 688 *num = n * sizeof(union cx23888_ir_fifo_rec);
689
690 for (p = (union cx23888_ir_fifo_rec *) buf, i = 0; i < n; p++, i++) {
667 691
668 for (p = (u32 *) buf, i = 0; i < n; p++, i++) { 692 if ((p->hw_fifo_data & FIFO_RXTX_RTO) == FIFO_RXTX_RTO) {
669 if ((*p & FIFO_RXTX_RTO) == FIFO_RXTX_RTO) { 693 /* Assume RTO was because of no IR light input */
670 *p = V4L2_SUBDEV_IR_PULSE_RX_SEQ_END; 694 u = 0;
671 v4l2_dbg(2, ir_888_debug, sd, "rx read: end of rx\n"); 695 v4l2_dbg(2, ir_888_debug, sd, "rx read: end of rx\n");
672 continue; 696 } else {
697 u = (p->hw_fifo_data & FIFO_RXTX_LVL) ? 1 : 0;
698 if (invert)
699 u = u ? 0 : 1;
673 } 700 }
674 701
675 u = (*p & FIFO_RXTX_LVL) ? V4L2_SUBDEV_IR_PULSE_LEVEL_MASK : 0; 702 v = (unsigned) pulse_width_count_to_ns(
676 if (invert) 703 (u16) (p->hw_fifo_data & FIFO_RXTX), divider);
677 u = u ? 0 : V4L2_SUBDEV_IR_PULSE_LEVEL_MASK; 704 if (v > IR_MAX_DURATION)
705 v = IR_MAX_DURATION;
678 706
679 v = (u32) pulse_width_count_to_ns((u16) (*p & FIFO_RXTX), 707 p->ir_core_data.pulse = u;
680 divider); 708 p->ir_core_data.duration = v;
681 if (v >= V4L2_SUBDEV_IR_PULSE_MAX_WIDTH_NS)
682 v = V4L2_SUBDEV_IR_PULSE_MAX_WIDTH_NS - 1;
683
684 *p = u | v;
685 709
686 v4l2_dbg(2, ir_888_debug, sd, "rx read: %10u ns %s\n", 710 v4l2_dbg(2, ir_888_debug, sd, "rx read: %10u ns %s\n",
687 v, u ? "mark" : "space"); 711 v, u ? "mark" : "space");
@@ -740,7 +764,8 @@ static int cx23888_ir_rx_s_parameters(struct v4l2_subdev *sd,
740 764
741 o->mode = p->mode = V4L2_SUBDEV_IR_MODE_PULSE_WIDTH; 765 o->mode = p->mode = V4L2_SUBDEV_IR_MODE_PULSE_WIDTH;
742 766
743 o->bytes_per_data_element = p->bytes_per_data_element = sizeof(u32); 767 o->bytes_per_data_element = p->bytes_per_data_element
768 = sizeof(union cx23888_ir_fifo_rec);
744 769
745 /* Before we tweak the hardware, we have to disable the receiver */ 770 /* Before we tweak the hardware, we have to disable the receiver */
746 irqenable_rx(dev, 0); 771 irqenable_rx(dev, 0);
@@ -762,12 +787,15 @@ static int cx23888_ir_rx_s_parameters(struct v4l2_subdev *sd,
762 &p->carrier_range_upper); 787 &p->carrier_range_upper);
763 o->carrier_range_lower = p->carrier_range_lower; 788 o->carrier_range_lower = p->carrier_range_lower;
764 o->carrier_range_upper = p->carrier_range_upper; 789 o->carrier_range_upper = p->carrier_range_upper;
790
791 p->max_pulse_width =
792 (u32) pulse_width_count_to_ns(FIFO_RXTX, rxclk_divider);
765 } else { 793 } else {
766 p->max_pulse_width = 794 p->max_pulse_width =
767 rxclk_rx_s_max_pulse_width(dev, p->max_pulse_width, 795 rxclk_rx_s_max_pulse_width(dev, p->max_pulse_width,
768 &rxclk_divider); 796 &rxclk_divider);
769 o->max_pulse_width = p->max_pulse_width;
770 } 797 }
798 o->max_pulse_width = p->max_pulse_width;
771 atomic_set(&state->rxclk_divider, rxclk_divider); 799 atomic_set(&state->rxclk_divider, rxclk_divider);
772 800
773 p->noise_filter_min_width = 801 p->noise_filter_min_width =
@@ -782,8 +810,8 @@ static int cx23888_ir_rx_s_parameters(struct v4l2_subdev *sd,
782 810
783 control_rx_s_edge_detection(dev, CNTRL_EDG_BOTH); 811 control_rx_s_edge_detection(dev, CNTRL_EDG_BOTH);
784 812
785 o->invert = p->invert; 813 o->invert_level = p->invert_level;
786 atomic_set(&state->rx_invert, p->invert); 814 atomic_set(&state->rx_invert, p->invert_level);
787 815
788 o->interrupt_enable = p->interrupt_enable; 816 o->interrupt_enable = p->interrupt_enable;
789 o->enable = p->enable; 817 o->enable = p->enable;
@@ -864,7 +892,8 @@ static int cx23888_ir_tx_s_parameters(struct v4l2_subdev *sd,
864 892
865 o->mode = p->mode = V4L2_SUBDEV_IR_MODE_PULSE_WIDTH; 893 o->mode = p->mode = V4L2_SUBDEV_IR_MODE_PULSE_WIDTH;
866 894
867 o->bytes_per_data_element = p->bytes_per_data_element = sizeof(u32); 895 o->bytes_per_data_element = p->bytes_per_data_element
896 = sizeof(union cx23888_ir_fifo_rec);
868 897
869 /* Before we tweak the hardware, we have to disable the transmitter */ 898 /* Before we tweak the hardware, we have to disable the transmitter */
870 irqenable_tx(dev, 0); 899 irqenable_tx(dev, 0);
@@ -880,12 +909,15 @@ static int cx23888_ir_tx_s_parameters(struct v4l2_subdev *sd,
880 909
881 p->duty_cycle = cduty_tx_s_duty_cycle(dev, p->duty_cycle); 910 p->duty_cycle = cduty_tx_s_duty_cycle(dev, p->duty_cycle);
882 o->duty_cycle = p->duty_cycle; 911 o->duty_cycle = p->duty_cycle;
912
913 p->max_pulse_width =
914 (u32) pulse_width_count_to_ns(FIFO_RXTX, txclk_divider);
883 } else { 915 } else {
884 p->max_pulse_width = 916 p->max_pulse_width =
885 txclk_tx_s_max_pulse_width(dev, p->max_pulse_width, 917 txclk_tx_s_max_pulse_width(dev, p->max_pulse_width,
886 &txclk_divider); 918 &txclk_divider);
887 o->max_pulse_width = p->max_pulse_width;
888 } 919 }
920 o->max_pulse_width = p->max_pulse_width;
889 atomic_set(&state->txclk_divider, txclk_divider); 921 atomic_set(&state->txclk_divider, txclk_divider);
890 922
891 p->resolution = clock_divider_to_resolution(txclk_divider); 923 p->resolution = clock_divider_to_resolution(txclk_divider);
@@ -894,8 +926,11 @@ static int cx23888_ir_tx_s_parameters(struct v4l2_subdev *sd,
894 /* FIXME - make this dependent on resolution for better performance */ 926 /* FIXME - make this dependent on resolution for better performance */
895 control_tx_irq_watermark(dev, TX_FIFO_HALF_EMPTY); 927 control_tx_irq_watermark(dev, TX_FIFO_HALF_EMPTY);
896 928
897 control_tx_polarity_invert(dev, p->invert); 929 control_tx_polarity_invert(dev, p->invert_carrier_sense);
898 o->invert = p->invert; 930 o->invert_carrier_sense = p->invert_carrier_sense;
931
932 control_tx_level_invert(dev, p->invert_level);
933 o->invert_level = p->invert_level;
899 934
900 o->interrupt_enable = p->interrupt_enable; 935 o->interrupt_enable = p->interrupt_enable;
901 o->enable = p->enable; 936 o->enable = p->enable;
@@ -988,12 +1023,10 @@ static int cx23888_ir_log_status(struct v4l2_subdev *sd)
988 "-%1d/+%1d, %u to %u Hz\n", i, j, 1023 "-%1d/+%1d, %u to %u Hz\n", i, j,
989 clock_divider_to_freq(rxclk, 16 + j), 1024 clock_divider_to_freq(rxclk, 16 + j),
990 clock_divider_to_freq(rxclk, 16 - i)); 1025 clock_divider_to_freq(rxclk, 16 - i));
991 } else {
992 v4l2_info(sd, "\tMax measurable pulse width: %u us, "
993 "%llu ns\n",
994 pulse_width_count_to_us(FIFO_RXTX, rxclk),
995 pulse_width_count_to_ns(FIFO_RXTX, rxclk));
996 } 1026 }
1027 v4l2_info(sd, "\tMax measurable pulse width: %u us, %llu ns\n",
1028 pulse_width_count_to_us(FIFO_RXTX, rxclk),
1029 pulse_width_count_to_ns(FIFO_RXTX, rxclk));
997 v4l2_info(sd, "\tLow pass filter: %s\n", 1030 v4l2_info(sd, "\tLow pass filter: %s\n",
998 filtr ? "enabled" : "disabled"); 1031 filtr ? "enabled" : "disabled");
999 if (filtr) 1032 if (filtr)
@@ -1025,19 +1058,20 @@ static int cx23888_ir_log_status(struct v4l2_subdev *sd)
1025 cntrl & CNTRL_TFE ? "enabled" : "disabled"); 1058 cntrl & CNTRL_TFE ? "enabled" : "disabled");
1026 v4l2_info(sd, "\tFIFO interrupt watermark: %s\n", 1059 v4l2_info(sd, "\tFIFO interrupt watermark: %s\n",
1027 cntrl & CNTRL_TIC ? "not empty" : "half full or less"); 1060 cntrl & CNTRL_TIC ? "not empty" : "half full or less");
1028 v4l2_info(sd, "\tSignal polarity: %s\n", 1061 v4l2_info(sd, "\tOutput pin level inversion %s\n",
1029 cntrl & CNTRL_CPL ? "0:mark 1:space" : "0:space 1:mark"); 1062 cntrl & CNTRL_IVO ? "yes" : "no");
1063 v4l2_info(sd, "\tCarrier polarity: %s\n",
1064 cntrl & CNTRL_CPL ? "space:burst mark:noburst"
1065 : "space:noburst mark:burst");
1030 if (cntrl & CNTRL_MOD) { 1066 if (cntrl & CNTRL_MOD) {
1031 v4l2_info(sd, "\tCarrier (16 clocks): %u Hz\n", 1067 v4l2_info(sd, "\tCarrier (16 clocks): %u Hz\n",
1032 clock_divider_to_carrier_freq(txclk)); 1068 clock_divider_to_carrier_freq(txclk));
1033 v4l2_info(sd, "\tCarrier duty cycle: %2u/16\n", 1069 v4l2_info(sd, "\tCarrier duty cycle: %2u/16\n",
1034 cduty + 1); 1070 cduty + 1);
1035 } else {
1036 v4l2_info(sd, "\tMax pulse width: %u us, "
1037 "%llu ns\n",
1038 pulse_width_count_to_us(FIFO_RXTX, txclk),
1039 pulse_width_count_to_ns(FIFO_RXTX, txclk));
1040 } 1071 }
1072 v4l2_info(sd, "\tMax pulse width: %u us, %llu ns\n",
1073 pulse_width_count_to_us(FIFO_RXTX, txclk),
1074 pulse_width_count_to_ns(FIFO_RXTX, txclk));
1041 v4l2_info(sd, "\tBusy: %s\n", 1075 v4l2_info(sd, "\tBusy: %s\n",
1042 stats & STATS_TBY ? "yes" : "no"); 1076 stats & STATS_TBY ? "yes" : "no");
1043 v4l2_info(sd, "\tFIFO service requested: %s\n", 1077 v4l2_info(sd, "\tFIFO service requested: %s\n",
@@ -1111,11 +1145,10 @@ static const struct v4l2_subdev_core_ops cx23888_ir_core_ops = {
1111 .g_register = cx23888_ir_g_register, 1145 .g_register = cx23888_ir_g_register,
1112 .s_register = cx23888_ir_s_register, 1146 .s_register = cx23888_ir_s_register,
1113#endif 1147#endif
1148 .interrupt_service_routine = cx23888_ir_irq_handler,
1114}; 1149};
1115 1150
1116static const struct v4l2_subdev_ir_ops cx23888_ir_ir_ops = { 1151static const struct v4l2_subdev_ir_ops cx23888_ir_ir_ops = {
1117 .interrupt_service_routine = cx23888_ir_irq_handler,
1118
1119 .rx_read = cx23888_ir_rx_read, 1152 .rx_read = cx23888_ir_rx_read,
1120 .rx_g_parameters = cx23888_ir_rx_g_parameters, 1153 .rx_g_parameters = cx23888_ir_rx_g_parameters,
1121 .rx_s_parameters = cx23888_ir_rx_s_parameters, 1154 .rx_s_parameters = cx23888_ir_rx_s_parameters,
@@ -1131,7 +1164,7 @@ static const struct v4l2_subdev_ops cx23888_ir_controller_ops = {
1131}; 1164};
1132 1165
1133static const struct v4l2_subdev_ir_parameters default_rx_params = { 1166static const struct v4l2_subdev_ir_parameters default_rx_params = {
1134 .bytes_per_data_element = sizeof(u32), 1167 .bytes_per_data_element = sizeof(union cx23888_ir_fifo_rec),
1135 .mode = V4L2_SUBDEV_IR_MODE_PULSE_WIDTH, 1168 .mode = V4L2_SUBDEV_IR_MODE_PULSE_WIDTH,
1136 1169
1137 .enable = false, 1170 .enable = false,
@@ -1146,11 +1179,11 @@ static const struct v4l2_subdev_ir_parameters default_rx_params = {
1146 .noise_filter_min_width = 333333, /* ns */ 1179 .noise_filter_min_width = 333333, /* ns */
1147 .carrier_range_lower = 35000, 1180 .carrier_range_lower = 35000,
1148 .carrier_range_upper = 37000, 1181 .carrier_range_upper = 37000,
1149 .invert = false, 1182 .invert_level = false,
1150}; 1183};
1151 1184
1152static const struct v4l2_subdev_ir_parameters default_tx_params = { 1185static const struct v4l2_subdev_ir_parameters default_tx_params = {
1153 .bytes_per_data_element = sizeof(u32), 1186 .bytes_per_data_element = sizeof(union cx23888_ir_fifo_rec),
1154 .mode = V4L2_SUBDEV_IR_MODE_PULSE_WIDTH, 1187 .mode = V4L2_SUBDEV_IR_MODE_PULSE_WIDTH,
1155 1188
1156 .enable = false, 1189 .enable = false,
@@ -1160,7 +1193,8 @@ static const struct v4l2_subdev_ir_parameters default_tx_params = {
1160 .modulation = true, 1193 .modulation = true,
1161 .carrier_freq = 36000, /* 36 kHz - RC-5 carrier */ 1194 .carrier_freq = 36000, /* 36 kHz - RC-5 carrier */
1162 .duty_cycle = 25, /* 25 % - RC-5 carrier */ 1195 .duty_cycle = 25, /* 25 % - RC-5 carrier */
1163 .invert = false, 1196 .invert_level = false,
1197 .invert_carrier_sense = false,
1164}; 1198};
1165 1199
1166int cx23888_ir_probe(struct cx23885_dev *dev) 1200int cx23888_ir_probe(struct cx23885_dev *dev)
diff --git a/drivers/media/video/cx25840/Makefile b/drivers/media/video/cx25840/Makefile
index 6e8665be8954..2ee96d3973b8 100644
--- a/drivers/media/video/cx25840/Makefile
+++ b/drivers/media/video/cx25840/Makefile
@@ -1,5 +1,5 @@
1cx25840-objs := cx25840-core.o cx25840-audio.o cx25840-firmware.o \ 1cx25840-objs := cx25840-core.o cx25840-audio.o cx25840-firmware.o \
2 cx25840-vbi.o 2 cx25840-vbi.o cx25840-ir.o
3 3
4obj-$(CONFIG_VIDEO_CX25840) += cx25840.o 4obj-$(CONFIG_VIDEO_CX25840) += cx25840.o
5 5
diff --git a/drivers/media/video/cx25840/cx25840-audio.c b/drivers/media/video/cx25840/cx25840-audio.c
index 45608d50529c..6faad34df3ac 100644
--- a/drivers/media/video/cx25840/cx25840-audio.c
+++ b/drivers/media/video/cx25840/cx25840-audio.c
@@ -474,33 +474,10 @@ void cx25840_audio_set_path(struct i2c_client *client)
474 cx25840_and_or(client, 0x803, ~0x10, 0x10); 474 cx25840_and_or(client, 0x803, ~0x10, 0x10);
475} 475}
476 476
477static int get_volume(struct i2c_client *client)
478{
479 struct cx25840_state *state = to_state(i2c_get_clientdata(client));
480 int vol;
481
482 if (state->unmute_volume >= 0)
483 return state->unmute_volume;
484
485 /* Volume runs +18dB to -96dB in 1/2dB steps
486 * change to fit the msp3400 -114dB to +12dB range */
487
488 /* check PATH1_VOLUME */
489 vol = 228 - cx25840_read(client, 0x8d4);
490 vol = (vol / 2) + 23;
491 return vol << 9;
492}
493
494static void set_volume(struct i2c_client *client, int volume) 477static void set_volume(struct i2c_client *client, int volume)
495{ 478{
496 struct cx25840_state *state = to_state(i2c_get_clientdata(client));
497 int vol; 479 int vol;
498 480
499 if (state->unmute_volume >= 0) {
500 state->unmute_volume = volume;
501 return;
502 }
503
504 /* Convert the volume to msp3400 values (0-127) */ 481 /* Convert the volume to msp3400 values (0-127) */
505 vol = volume >> 9; 482 vol = volume >> 9;
506 483
@@ -517,52 +494,6 @@ static void set_volume(struct i2c_client *client, int volume)
517 cx25840_write(client, 0x8d4, 228 - (vol * 2)); 494 cx25840_write(client, 0x8d4, 228 - (vol * 2));
518} 495}
519 496
520static int get_bass(struct i2c_client *client)
521{
522 /* bass is 49 steps +12dB to -12dB */
523
524 /* check PATH1_EQ_BASS_VOL */
525 int bass = cx25840_read(client, 0x8d9) & 0x3f;
526 bass = (((48 - bass) * 0xffff) + 47) / 48;
527 return bass;
528}
529
530static void set_bass(struct i2c_client *client, int bass)
531{
532 /* PATH1_EQ_BASS_VOL */
533 cx25840_and_or(client, 0x8d9, ~0x3f, 48 - (bass * 48 / 0xffff));
534}
535
536static int get_treble(struct i2c_client *client)
537{
538 /* treble is 49 steps +12dB to -12dB */
539
540 /* check PATH1_EQ_TREBLE_VOL */
541 int treble = cx25840_read(client, 0x8db) & 0x3f;
542 treble = (((48 - treble) * 0xffff) + 47) / 48;
543 return treble;
544}
545
546static void set_treble(struct i2c_client *client, int treble)
547{
548 /* PATH1_EQ_TREBLE_VOL */
549 cx25840_and_or(client, 0x8db, ~0x3f, 48 - (treble * 48 / 0xffff));
550}
551
552static int get_balance(struct i2c_client *client)
553{
554 /* balance is 7 bit, 0 to -96dB */
555
556 /* check PATH1_BAL_LEVEL */
557 int balance = cx25840_read(client, 0x8d5) & 0x7f;
558 /* check PATH1_BAL_LEFT */
559 if ((cx25840_read(client, 0x8d5) & 0x80) == 0)
560 balance = 0x80 - balance;
561 else
562 balance = 0x80 + balance;
563 return balance << 8;
564}
565
566static void set_balance(struct i2c_client *client, int balance) 497static void set_balance(struct i2c_client *client, int balance)
567{ 498{
568 int bal = balance >> 8; 499 int bal = balance >> 8;
@@ -579,31 +510,6 @@ static void set_balance(struct i2c_client *client, int balance)
579 } 510 }
580} 511}
581 512
582static int get_mute(struct i2c_client *client)
583{
584 struct cx25840_state *state = to_state(i2c_get_clientdata(client));
585
586 return state->unmute_volume >= 0;
587}
588
589static void set_mute(struct i2c_client *client, int mute)
590{
591 struct cx25840_state *state = to_state(i2c_get_clientdata(client));
592
593 if (mute && state->unmute_volume == -1) {
594 int vol = get_volume(client);
595
596 set_volume(client, 0);
597 state->unmute_volume = vol;
598 }
599 else if (!mute && state->unmute_volume != -1) {
600 int vol = state->unmute_volume;
601
602 state->unmute_volume = -1;
603 set_volume(client, vol);
604 }
605}
606
607int cx25840_s_clock_freq(struct v4l2_subdev *sd, u32 freq) 513int cx25840_s_clock_freq(struct v4l2_subdev *sd, u32 freq)
608{ 514{
609 struct i2c_client *client = v4l2_get_subdevdata(sd); 515 struct i2c_client *client = v4l2_get_subdevdata(sd);
@@ -624,25 +530,31 @@ int cx25840_s_clock_freq(struct v4l2_subdev *sd, u32 freq)
624 return retval; 530 return retval;
625} 531}
626 532
627int cx25840_audio_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) 533static int cx25840_audio_s_ctrl(struct v4l2_ctrl *ctrl)
628{ 534{
535 struct v4l2_subdev *sd = to_sd(ctrl);
536 struct cx25840_state *state = to_state(sd);
629 struct i2c_client *client = v4l2_get_subdevdata(sd); 537 struct i2c_client *client = v4l2_get_subdevdata(sd);
630 538
631 switch (ctrl->id) { 539 switch (ctrl->id) {
632 case V4L2_CID_AUDIO_VOLUME: 540 case V4L2_CID_AUDIO_VOLUME:
633 ctrl->value = get_volume(client); 541 if (state->mute->val)
542 set_volume(client, 0);
543 else
544 set_volume(client, state->volume->val);
634 break; 545 break;
635 case V4L2_CID_AUDIO_BASS: 546 case V4L2_CID_AUDIO_BASS:
636 ctrl->value = get_bass(client); 547 /* PATH1_EQ_BASS_VOL */
548 cx25840_and_or(client, 0x8d9, ~0x3f,
549 48 - (ctrl->val * 48 / 0xffff));
637 break; 550 break;
638 case V4L2_CID_AUDIO_TREBLE: 551 case V4L2_CID_AUDIO_TREBLE:
639 ctrl->value = get_treble(client); 552 /* PATH1_EQ_TREBLE_VOL */
553 cx25840_and_or(client, 0x8db, ~0x3f,
554 48 - (ctrl->val * 48 / 0xffff));
640 break; 555 break;
641 case V4L2_CID_AUDIO_BALANCE: 556 case V4L2_CID_AUDIO_BALANCE:
642 ctrl->value = get_balance(client); 557 set_balance(client, ctrl->val);
643 break;
644 case V4L2_CID_AUDIO_MUTE:
645 ctrl->value = get_mute(client);
646 break; 558 break;
647 default: 559 default:
648 return -EINVAL; 560 return -EINVAL;
@@ -650,28 +562,6 @@ int cx25840_audio_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
650 return 0; 562 return 0;
651} 563}
652 564
653int cx25840_audio_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) 565const struct v4l2_ctrl_ops cx25840_audio_ctrl_ops = {
654{ 566 .s_ctrl = cx25840_audio_s_ctrl,
655 struct i2c_client *client = v4l2_get_subdevdata(sd); 567};
656
657 switch (ctrl->id) {
658 case V4L2_CID_AUDIO_VOLUME:
659 set_volume(client, ctrl->value);
660 break;
661 case V4L2_CID_AUDIO_BASS:
662 set_bass(client, ctrl->value);
663 break;
664 case V4L2_CID_AUDIO_TREBLE:
665 set_treble(client, ctrl->value);
666 break;
667 case V4L2_CID_AUDIO_BALANCE:
668 set_balance(client, ctrl->value);
669 break;
670 case V4L2_CID_AUDIO_MUTE:
671 set_mute(client, ctrl->value);
672 break;
673 default:
674 return -EINVAL;
675 }
676 return 0;
677}
diff --git a/drivers/media/video/cx25840/cx25840-core.c b/drivers/media/video/cx25840/cx25840-core.c
index bb4872b2ceb0..86ca8c2359dd 100644
--- a/drivers/media/video/cx25840/cx25840-core.c
+++ b/drivers/media/video/cx25840/cx25840-core.c
@@ -15,6 +15,9 @@
15 * 15 *
16 * CX23885 support by Steven Toth <stoth@linuxtv.org>. 16 * CX23885 support by Steven Toth <stoth@linuxtv.org>.
17 * 17 *
18 * CX2388[578] IRQ handling, IO Pin mux configuration and other small fixes are
19 * Copyright (C) 2010 Andy Walls <awalls@md.metrocast.net>
20 *
18 * This program is free software; you can redistribute it and/or 21 * This program is free software; you can redistribute it and/or
19 * modify it under the terms of the GNU General Public License 22 * modify it under the terms of the GNU General Public License
20 * as published by the Free Software Foundation; either version 2 23 * as published by the Free Software Foundation; either version 2
@@ -48,6 +51,28 @@ MODULE_DESCRIPTION("Conexant CX25840 audio/video decoder driver");
48MODULE_AUTHOR("Ulf Eklund, Chris Kennedy, Hans Verkuil, Tyler Trafford"); 51MODULE_AUTHOR("Ulf Eklund, Chris Kennedy, Hans Verkuil, Tyler Trafford");
49MODULE_LICENSE("GPL"); 52MODULE_LICENSE("GPL");
50 53
54#define CX25840_VID_INT_STAT_REG 0x410
55#define CX25840_VID_INT_STAT_BITS 0x0000ffff
56#define CX25840_VID_INT_MASK_BITS 0xffff0000
57#define CX25840_VID_INT_MASK_SHFT 16
58#define CX25840_VID_INT_MASK_REG 0x412
59
60#define CX23885_AUD_MC_INT_MASK_REG 0x80c
61#define CX23885_AUD_MC_INT_STAT_BITS 0xffff0000
62#define CX23885_AUD_MC_INT_CTRL_BITS 0x0000ffff
63#define CX23885_AUD_MC_INT_STAT_SHFT 16
64
65#define CX25840_AUD_INT_CTRL_REG 0x812
66#define CX25840_AUD_INT_STAT_REG 0x813
67
68#define CX23885_PIN_CTRL_IRQ_REG 0x123
69#define CX23885_PIN_CTRL_IRQ_IR_STAT 0x40
70#define CX23885_PIN_CTRL_IRQ_AUD_STAT 0x20
71#define CX23885_PIN_CTRL_IRQ_VID_STAT 0x10
72
73#define CX25840_IR_STATS_REG 0x210
74#define CX25840_IR_IRQEN_REG 0x214
75
51static int cx25840_debug; 76static int cx25840_debug;
52 77
53module_param_named(debug,cx25840_debug, int, 0644); 78module_param_named(debug,cx25840_debug, int, 0644);
@@ -80,33 +105,53 @@ int cx25840_write4(struct i2c_client *client, u16 addr, u32 value)
80 105
81u8 cx25840_read(struct i2c_client * client, u16 addr) 106u8 cx25840_read(struct i2c_client * client, u16 addr)
82{ 107{
83 u8 buffer[2]; 108 struct i2c_msg msgs[2];
84 buffer[0] = addr >> 8; 109 u8 tx_buf[2], rx_buf[1];
85 buffer[1] = addr & 0xff; 110
86 111 /* Write register address */
87 if (i2c_master_send(client, buffer, 2) < 2) 112 tx_buf[0] = addr >> 8;
88 return 0; 113 tx_buf[1] = addr & 0xff;
89 114 msgs[0].addr = client->addr;
90 if (i2c_master_recv(client, buffer, 1) < 1) 115 msgs[0].flags = 0;
116 msgs[0].len = 2;
117 msgs[0].buf = (char *) tx_buf;
118
119 /* Read data from register */
120 msgs[1].addr = client->addr;
121 msgs[1].flags = I2C_M_RD;
122 msgs[1].len = 1;
123 msgs[1].buf = (char *) rx_buf;
124
125 if (i2c_transfer(client->adapter, msgs, 2) < 2)
91 return 0; 126 return 0;
92 127
93 return buffer[0]; 128 return rx_buf[0];
94} 129}
95 130
96u32 cx25840_read4(struct i2c_client * client, u16 addr) 131u32 cx25840_read4(struct i2c_client * client, u16 addr)
97{ 132{
98 u8 buffer[4]; 133 struct i2c_msg msgs[2];
99 buffer[0] = addr >> 8; 134 u8 tx_buf[2], rx_buf[4];
100 buffer[1] = addr & 0xff; 135
101 136 /* Write register address */
102 if (i2c_master_send(client, buffer, 2) < 2) 137 tx_buf[0] = addr >> 8;
103 return 0; 138 tx_buf[1] = addr & 0xff;
104 139 msgs[0].addr = client->addr;
105 if (i2c_master_recv(client, buffer, 4) < 4) 140 msgs[0].flags = 0;
141 msgs[0].len = 2;
142 msgs[0].buf = (char *) tx_buf;
143
144 /* Read data from registers */
145 msgs[1].addr = client->addr;
146 msgs[1].flags = I2C_M_RD;
147 msgs[1].len = 4;
148 msgs[1].buf = (char *) rx_buf;
149
150 if (i2c_transfer(client->adapter, msgs, 2) < 2)
106 return 0; 151 return 0;
107 152
108 return (buffer[3] << 24) | (buffer[2] << 16) | 153 return (rx_buf[3] << 24) | (rx_buf[2] << 16) | (rx_buf[1] << 8) |
109 (buffer[1] << 8) | buffer[0]; 154 rx_buf[0];
110} 155}
111 156
112int cx25840_and_or(struct i2c_client *client, u16 addr, unsigned and_mask, 157int cx25840_and_or(struct i2c_client *client, u16 addr, unsigned and_mask,
@@ -117,6 +162,14 @@ int cx25840_and_or(struct i2c_client *client, u16 addr, unsigned and_mask,
117 or_value); 162 or_value);
118} 163}
119 164
165int cx25840_and_or4(struct i2c_client *client, u16 addr, u32 and_mask,
166 u32 or_value)
167{
168 return cx25840_write4(client, addr,
169 (cx25840_read4(client, addr) & and_mask) |
170 or_value);
171}
172
120/* ----------------------------------------------------------------------- */ 173/* ----------------------------------------------------------------------- */
121 174
122static int set_input(struct i2c_client *client, enum cx25840_video_input vid_input, 175static int set_input(struct i2c_client *client, enum cx25840_video_input vid_input,
@@ -124,6 +177,158 @@ static int set_input(struct i2c_client *client, enum cx25840_video_input vid_inp
124 177
125/* ----------------------------------------------------------------------- */ 178/* ----------------------------------------------------------------------- */
126 179
180static int cx23885_s_io_pin_config(struct v4l2_subdev *sd, size_t n,
181 struct v4l2_subdev_io_pin_config *p)
182{
183 struct i2c_client *client = v4l2_get_subdevdata(sd);
184 int i;
185 u32 pin_ctrl;
186 u8 gpio_oe, gpio_data, strength;
187
188 pin_ctrl = cx25840_read4(client, 0x120);
189 gpio_oe = cx25840_read(client, 0x160);
190 gpio_data = cx25840_read(client, 0x164);
191
192 for (i = 0; i < n; i++) {
193 strength = p[i].strength;
194 if (strength > CX25840_PIN_DRIVE_FAST)
195 strength = CX25840_PIN_DRIVE_FAST;
196
197 switch (p[i].pin) {
198 case CX23885_PIN_IRQ_N_GPIO16:
199 if (p[i].function != CX23885_PAD_IRQ_N) {
200 /* GPIO16 */
201 pin_ctrl &= ~(0x1 << 25);
202 } else {
203 /* IRQ_N */
204 if (p[i].flags &
205 (V4L2_SUBDEV_IO_PIN_DISABLE |
206 V4L2_SUBDEV_IO_PIN_INPUT)) {
207 pin_ctrl &= ~(0x1 << 25);
208 } else {
209 pin_ctrl |= (0x1 << 25);
210 }
211 if (p[i].flags &
212 V4L2_SUBDEV_IO_PIN_ACTIVE_LOW) {
213 pin_ctrl &= ~(0x1 << 24);
214 } else {
215 pin_ctrl |= (0x1 << 24);
216 }
217 }
218 break;
219 case CX23885_PIN_IR_RX_GPIO19:
220 if (p[i].function != CX23885_PAD_GPIO19) {
221 /* IR_RX */
222 gpio_oe |= (0x1 << 0);
223 pin_ctrl &= ~(0x3 << 18);
224 pin_ctrl |= (strength << 18);
225 } else {
226 /* GPIO19 */
227 gpio_oe &= ~(0x1 << 0);
228 if (p[i].flags & V4L2_SUBDEV_IO_PIN_SET_VALUE) {
229 gpio_data &= ~(0x1 << 0);
230 gpio_data |= ((p[i].value & 0x1) << 0);
231 }
232 pin_ctrl &= ~(0x3 << 12);
233 pin_ctrl |= (strength << 12);
234 }
235 break;
236 case CX23885_PIN_IR_TX_GPIO20:
237 if (p[i].function != CX23885_PAD_GPIO20) {
238 /* IR_TX */
239 gpio_oe |= (0x1 << 1);
240 if (p[i].flags & V4L2_SUBDEV_IO_PIN_DISABLE)
241 pin_ctrl &= ~(0x1 << 10);
242 else
243 pin_ctrl |= (0x1 << 10);
244 pin_ctrl &= ~(0x3 << 18);
245 pin_ctrl |= (strength << 18);
246 } else {
247 /* GPIO20 */
248 gpio_oe &= ~(0x1 << 1);
249 if (p[i].flags & V4L2_SUBDEV_IO_PIN_SET_VALUE) {
250 gpio_data &= ~(0x1 << 1);
251 gpio_data |= ((p[i].value & 0x1) << 1);
252 }
253 pin_ctrl &= ~(0x3 << 12);
254 pin_ctrl |= (strength << 12);
255 }
256 break;
257 case CX23885_PIN_I2S_SDAT_GPIO21:
258 if (p[i].function != CX23885_PAD_GPIO21) {
259 /* I2S_SDAT */
260 /* TODO: Input or Output config */
261 gpio_oe |= (0x1 << 2);
262 pin_ctrl &= ~(0x3 << 22);
263 pin_ctrl |= (strength << 22);
264 } else {
265 /* GPIO21 */
266 gpio_oe &= ~(0x1 << 2);
267 if (p[i].flags & V4L2_SUBDEV_IO_PIN_SET_VALUE) {
268 gpio_data &= ~(0x1 << 2);
269 gpio_data |= ((p[i].value & 0x1) << 2);
270 }
271 pin_ctrl &= ~(0x3 << 12);
272 pin_ctrl |= (strength << 12);
273 }
274 break;
275 case CX23885_PIN_I2S_WCLK_GPIO22:
276 if (p[i].function != CX23885_PAD_GPIO22) {
277 /* I2S_WCLK */
278 /* TODO: Input or Output config */
279 gpio_oe |= (0x1 << 3);
280 pin_ctrl &= ~(0x3 << 22);
281 pin_ctrl |= (strength << 22);
282 } else {
283 /* GPIO22 */
284 gpio_oe &= ~(0x1 << 3);
285 if (p[i].flags & V4L2_SUBDEV_IO_PIN_SET_VALUE) {
286 gpio_data &= ~(0x1 << 3);
287 gpio_data |= ((p[i].value & 0x1) << 3);
288 }
289 pin_ctrl &= ~(0x3 << 12);
290 pin_ctrl |= (strength << 12);
291 }
292 break;
293 case CX23885_PIN_I2S_BCLK_GPIO23:
294 if (p[i].function != CX23885_PAD_GPIO23) {
295 /* I2S_BCLK */
296 /* TODO: Input or Output config */
297 gpio_oe |= (0x1 << 4);
298 pin_ctrl &= ~(0x3 << 22);
299 pin_ctrl |= (strength << 22);
300 } else {
301 /* GPIO23 */
302 gpio_oe &= ~(0x1 << 4);
303 if (p[i].flags & V4L2_SUBDEV_IO_PIN_SET_VALUE) {
304 gpio_data &= ~(0x1 << 4);
305 gpio_data |= ((p[i].value & 0x1) << 4);
306 }
307 pin_ctrl &= ~(0x3 << 12);
308 pin_ctrl |= (strength << 12);
309 }
310 break;
311 }
312 }
313
314 cx25840_write(client, 0x164, gpio_data);
315 cx25840_write(client, 0x160, gpio_oe);
316 cx25840_write4(client, 0x120, pin_ctrl);
317 return 0;
318}
319
320static int common_s_io_pin_config(struct v4l2_subdev *sd, size_t n,
321 struct v4l2_subdev_io_pin_config *pincfg)
322{
323 struct cx25840_state *state = to_state(sd);
324
325 if (is_cx2388x(state))
326 return cx23885_s_io_pin_config(sd, n, pincfg);
327 return 0;
328}
329
330/* ----------------------------------------------------------------------- */
331
127static void init_dll1(struct i2c_client *client) 332static void init_dll1(struct i2c_client *client)
128{ 333{
129 /* This is the Hauppauge sequence used to 334 /* This is the Hauppauge sequence used to
@@ -420,6 +625,13 @@ static void cx23885_initialize(struct i2c_client *client)
420 625
421 /* start microcontroller */ 626 /* start microcontroller */
422 cx25840_and_or(client, 0x803, ~0x10, 0x10); 627 cx25840_and_or(client, 0x803, ~0x10, 0x10);
628
629 /* Disable and clear video interrupts - we don't use them */
630 cx25840_write4(client, CX25840_VID_INT_STAT_REG, 0xffffffff);
631
632 /* Disable and clear audio interrupts - we don't use them */
633 cx25840_write(client, CX25840_AUD_INT_CTRL_REG, 0xff);
634 cx25840_write(client, CX25840_AUD_INT_STAT_REG, 0xff);
423} 635}
424 636
425/* ----------------------------------------------------------------------- */ 637/* ----------------------------------------------------------------------- */
@@ -909,102 +1121,29 @@ static int set_v4lstd(struct i2c_client *client)
909 1121
910/* ----------------------------------------------------------------------- */ 1122/* ----------------------------------------------------------------------- */
911 1123
912static int cx25840_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) 1124static int cx25840_s_ctrl(struct v4l2_ctrl *ctrl)
913{ 1125{
914 struct cx25840_state *state = to_state(sd); 1126 struct v4l2_subdev *sd = to_sd(ctrl);
915 struct i2c_client *client = v4l2_get_subdevdata(sd); 1127 struct i2c_client *client = v4l2_get_subdevdata(sd);
916 1128
917 switch (ctrl->id) { 1129 switch (ctrl->id) {
918 case CX25840_CID_ENABLE_PVR150_WORKAROUND:
919 state->pvr150_workaround = ctrl->value;
920 set_input(client, state->vid_input, state->aud_input);
921 break;
922
923 case V4L2_CID_BRIGHTNESS: 1130 case V4L2_CID_BRIGHTNESS:
924 if (ctrl->value < 0 || ctrl->value > 255) { 1131 cx25840_write(client, 0x414, ctrl->val - 128);
925 v4l_err(client, "invalid brightness setting %d\n",
926 ctrl->value);
927 return -ERANGE;
928 }
929
930 cx25840_write(client, 0x414, ctrl->value - 128);
931 break; 1132 break;
932 1133
933 case V4L2_CID_CONTRAST: 1134 case V4L2_CID_CONTRAST:
934 if (ctrl->value < 0 || ctrl->value > 127) { 1135 cx25840_write(client, 0x415, ctrl->val << 1);
935 v4l_err(client, "invalid contrast setting %d\n",
936 ctrl->value);
937 return -ERANGE;
938 }
939
940 cx25840_write(client, 0x415, ctrl->value << 1);
941 break; 1136 break;
942 1137
943 case V4L2_CID_SATURATION: 1138 case V4L2_CID_SATURATION:
944 if (ctrl->value < 0 || ctrl->value > 127) { 1139 cx25840_write(client, 0x420, ctrl->val << 1);
945 v4l_err(client, "invalid saturation setting %d\n", 1140 cx25840_write(client, 0x421, ctrl->val << 1);
946 ctrl->value);
947 return -ERANGE;
948 }
949
950 cx25840_write(client, 0x420, ctrl->value << 1);
951 cx25840_write(client, 0x421, ctrl->value << 1);
952 break; 1141 break;
953 1142
954 case V4L2_CID_HUE: 1143 case V4L2_CID_HUE:
955 if (ctrl->value < -128 || ctrl->value > 127) { 1144 cx25840_write(client, 0x422, ctrl->val);
956 v4l_err(client, "invalid hue setting %d\n", ctrl->value);
957 return -ERANGE;
958 }
959
960 cx25840_write(client, 0x422, ctrl->value);
961 break; 1145 break;
962 1146
963 case V4L2_CID_AUDIO_VOLUME:
964 case V4L2_CID_AUDIO_BASS:
965 case V4L2_CID_AUDIO_TREBLE:
966 case V4L2_CID_AUDIO_BALANCE:
967 case V4L2_CID_AUDIO_MUTE:
968 if (is_cx2583x(state))
969 return -EINVAL;
970 return cx25840_audio_s_ctrl(sd, ctrl);
971
972 default:
973 return -EINVAL;
974 }
975
976 return 0;
977}
978
979static int cx25840_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
980{
981 struct cx25840_state *state = to_state(sd);
982 struct i2c_client *client = v4l2_get_subdevdata(sd);
983
984 switch (ctrl->id) {
985 case CX25840_CID_ENABLE_PVR150_WORKAROUND:
986 ctrl->value = state->pvr150_workaround;
987 break;
988 case V4L2_CID_BRIGHTNESS:
989 ctrl->value = (s8)cx25840_read(client, 0x414) + 128;
990 break;
991 case V4L2_CID_CONTRAST:
992 ctrl->value = cx25840_read(client, 0x415) >> 1;
993 break;
994 case V4L2_CID_SATURATION:
995 ctrl->value = cx25840_read(client, 0x420) >> 1;
996 break;
997 case V4L2_CID_HUE:
998 ctrl->value = (s8)cx25840_read(client, 0x422);
999 break;
1000 case V4L2_CID_AUDIO_VOLUME:
1001 case V4L2_CID_AUDIO_BASS:
1002 case V4L2_CID_AUDIO_TREBLE:
1003 case V4L2_CID_AUDIO_BALANCE:
1004 case V4L2_CID_AUDIO_MUTE:
1005 if (is_cx2583x(state))
1006 return -EINVAL;
1007 return cx25840_audio_g_ctrl(sd, ctrl);
1008 default: 1147 default:
1009 return -EINVAL; 1148 return -EINVAL;
1010 } 1149 }
@@ -1163,8 +1302,6 @@ static void log_audio_status(struct i2c_client *client)
1163 default: p = "not defined"; 1302 default: p = "not defined";
1164 } 1303 }
1165 v4l_info(client, "Detected audio standard: %s\n", p); 1304 v4l_info(client, "Detected audio standard: %s\n", p);
1166 v4l_info(client, "Audio muted: %s\n",
1167 (state->unmute_volume >= 0) ? "yes" : "no");
1168 v4l_info(client, "Audio microcontroller: %s\n", 1305 v4l_info(client, "Audio microcontroller: %s\n",
1169 (download_ctl & 0x10) ? 1306 (download_ctl & 0x10) ?
1170 ((mute_ctl & 0x2) ? "detecting" : "running") : "stopped"); 1307 ((mute_ctl & 0x2) ? "detecting" : "running") : "stopped");
@@ -1381,40 +1518,6 @@ static int cx25840_s_stream(struct v4l2_subdev *sd, int enable)
1381 return 0; 1518 return 0;
1382} 1519}
1383 1520
1384static int cx25840_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc)
1385{
1386 struct cx25840_state *state = to_state(sd);
1387
1388 switch (qc->id) {
1389 case V4L2_CID_BRIGHTNESS:
1390 return v4l2_ctrl_query_fill(qc, 0, 255, 1, 128);
1391 case V4L2_CID_CONTRAST:
1392 case V4L2_CID_SATURATION:
1393 return v4l2_ctrl_query_fill(qc, 0, 127, 1, 64);
1394 case V4L2_CID_HUE:
1395 return v4l2_ctrl_query_fill(qc, -128, 127, 1, 0);
1396 default:
1397 break;
1398 }
1399 if (is_cx2583x(state))
1400 return -EINVAL;
1401
1402 switch (qc->id) {
1403 case V4L2_CID_AUDIO_VOLUME:
1404 return v4l2_ctrl_query_fill(qc, 0, 65535,
1405 65535 / 100, state->default_volume);
1406 case V4L2_CID_AUDIO_MUTE:
1407 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 0);
1408 case V4L2_CID_AUDIO_BALANCE:
1409 case V4L2_CID_AUDIO_BASS:
1410 case V4L2_CID_AUDIO_TREBLE:
1411 return v4l2_ctrl_query_fill(qc, 0, 65535, 65535 / 100, 32768);
1412 default:
1413 return -EINVAL;
1414 }
1415 return -EINVAL;
1416}
1417
1418static int cx25840_s_std(struct v4l2_subdev *sd, v4l2_std_id std) 1521static int cx25840_s_std(struct v4l2_subdev *sd, v4l2_std_id std)
1419{ 1522{
1420 struct cx25840_state *state = to_state(sd); 1523 struct cx25840_state *state = to_state(sd);
@@ -1576,24 +1679,134 @@ static int cx25840_log_status(struct v4l2_subdev *sd)
1576 log_video_status(client); 1679 log_video_status(client);
1577 if (!is_cx2583x(state)) 1680 if (!is_cx2583x(state))
1578 log_audio_status(client); 1681 log_audio_status(client);
1682 cx25840_ir_log_status(sd);
1683 v4l2_ctrl_handler_log_status(&state->hdl, sd->name);
1684 return 0;
1685}
1686
1687static int cx25840_s_config(struct v4l2_subdev *sd, int irq, void *platform_data)
1688{
1689 struct cx25840_state *state = to_state(sd);
1690 struct i2c_client *client = v4l2_get_subdevdata(sd);
1691
1692 if (platform_data) {
1693 struct cx25840_platform_data *pdata = platform_data;
1694
1695 state->pvr150_workaround = pdata->pvr150_workaround;
1696 set_input(client, state->vid_input, state->aud_input);
1697 }
1579 return 0; 1698 return 0;
1580} 1699}
1581 1700
1701static int cx23885_irq_handler(struct v4l2_subdev *sd, u32 status,
1702 bool *handled)
1703{
1704 struct cx25840_state *state = to_state(sd);
1705 struct i2c_client *c = v4l2_get_subdevdata(sd);
1706 u8 irq_stat, aud_stat, aud_en, ir_stat, ir_en;
1707 u32 vid_stat, aud_mc_stat;
1708 bool block_handled;
1709 int ret = 0;
1710
1711 irq_stat = cx25840_read(c, CX23885_PIN_CTRL_IRQ_REG);
1712 v4l_dbg(2, cx25840_debug, c, "AV Core IRQ status (entry): %s %s %s\n",
1713 irq_stat & CX23885_PIN_CTRL_IRQ_IR_STAT ? "ir" : " ",
1714 irq_stat & CX23885_PIN_CTRL_IRQ_AUD_STAT ? "aud" : " ",
1715 irq_stat & CX23885_PIN_CTRL_IRQ_VID_STAT ? "vid" : " ");
1716
1717 if ((is_cx23885(state) || is_cx23887(state))) {
1718 ir_stat = cx25840_read(c, CX25840_IR_STATS_REG);
1719 ir_en = cx25840_read(c, CX25840_IR_IRQEN_REG);
1720 v4l_dbg(2, cx25840_debug, c,
1721 "AV Core ir IRQ status: %#04x disables: %#04x\n",
1722 ir_stat, ir_en);
1723 if (irq_stat & CX23885_PIN_CTRL_IRQ_IR_STAT) {
1724 block_handled = false;
1725 ret = cx25840_ir_irq_handler(sd,
1726 status, &block_handled);
1727 if (block_handled)
1728 *handled = true;
1729 }
1730 }
1731
1732 aud_stat = cx25840_read(c, CX25840_AUD_INT_STAT_REG);
1733 aud_en = cx25840_read(c, CX25840_AUD_INT_CTRL_REG);
1734 v4l_dbg(2, cx25840_debug, c,
1735 "AV Core audio IRQ status: %#04x disables: %#04x\n",
1736 aud_stat, aud_en);
1737 aud_mc_stat = cx25840_read4(c, CX23885_AUD_MC_INT_MASK_REG);
1738 v4l_dbg(2, cx25840_debug, c,
1739 "AV Core audio MC IRQ status: %#06x enables: %#06x\n",
1740 aud_mc_stat >> CX23885_AUD_MC_INT_STAT_SHFT,
1741 aud_mc_stat & CX23885_AUD_MC_INT_CTRL_BITS);
1742 if (irq_stat & CX23885_PIN_CTRL_IRQ_AUD_STAT) {
1743 if (aud_stat) {
1744 cx25840_write(c, CX25840_AUD_INT_STAT_REG, aud_stat);
1745 *handled = true;
1746 }
1747 }
1748
1749 vid_stat = cx25840_read4(c, CX25840_VID_INT_STAT_REG);
1750 v4l_dbg(2, cx25840_debug, c,
1751 "AV Core video IRQ status: %#06x disables: %#06x\n",
1752 vid_stat & CX25840_VID_INT_STAT_BITS,
1753 vid_stat >> CX25840_VID_INT_MASK_SHFT);
1754 if (irq_stat & CX23885_PIN_CTRL_IRQ_VID_STAT) {
1755 if (vid_stat & CX25840_VID_INT_STAT_BITS) {
1756 cx25840_write4(c, CX25840_VID_INT_STAT_REG, vid_stat);
1757 *handled = true;
1758 }
1759 }
1760
1761 irq_stat = cx25840_read(c, CX23885_PIN_CTRL_IRQ_REG);
1762 v4l_dbg(2, cx25840_debug, c, "AV Core IRQ status (exit): %s %s %s\n",
1763 irq_stat & CX23885_PIN_CTRL_IRQ_IR_STAT ? "ir" : " ",
1764 irq_stat & CX23885_PIN_CTRL_IRQ_AUD_STAT ? "aud" : " ",
1765 irq_stat & CX23885_PIN_CTRL_IRQ_VID_STAT ? "vid" : " ");
1766
1767 return ret;
1768}
1769
1770static int cx25840_irq_handler(struct v4l2_subdev *sd, u32 status,
1771 bool *handled)
1772{
1773 struct cx25840_state *state = to_state(sd);
1774
1775 *handled = false;
1776
1777 /* Only support the CX2388[578] AV Core for now */
1778 if (is_cx2388x(state))
1779 return cx23885_irq_handler(sd, status, handled);
1780
1781 return -ENODEV;
1782}
1783
1582/* ----------------------------------------------------------------------- */ 1784/* ----------------------------------------------------------------------- */
1583 1785
1786static const struct v4l2_ctrl_ops cx25840_ctrl_ops = {
1787 .s_ctrl = cx25840_s_ctrl,
1788};
1789
1584static const struct v4l2_subdev_core_ops cx25840_core_ops = { 1790static const struct v4l2_subdev_core_ops cx25840_core_ops = {
1585 .log_status = cx25840_log_status, 1791 .log_status = cx25840_log_status,
1792 .s_config = cx25840_s_config,
1586 .g_chip_ident = cx25840_g_chip_ident, 1793 .g_chip_ident = cx25840_g_chip_ident,
1587 .g_ctrl = cx25840_g_ctrl, 1794 .g_ctrl = v4l2_subdev_g_ctrl,
1588 .s_ctrl = cx25840_s_ctrl, 1795 .s_ctrl = v4l2_subdev_s_ctrl,
1589 .queryctrl = cx25840_queryctrl, 1796 .s_ext_ctrls = v4l2_subdev_s_ext_ctrls,
1797 .try_ext_ctrls = v4l2_subdev_try_ext_ctrls,
1798 .g_ext_ctrls = v4l2_subdev_g_ext_ctrls,
1799 .queryctrl = v4l2_subdev_queryctrl,
1800 .querymenu = v4l2_subdev_querymenu,
1590 .s_std = cx25840_s_std, 1801 .s_std = cx25840_s_std,
1591 .reset = cx25840_reset, 1802 .reset = cx25840_reset,
1592 .load_fw = cx25840_load_fw, 1803 .load_fw = cx25840_load_fw,
1804 .s_io_pin_config = common_s_io_pin_config,
1593#ifdef CONFIG_VIDEO_ADV_DEBUG 1805#ifdef CONFIG_VIDEO_ADV_DEBUG
1594 .g_register = cx25840_g_register, 1806 .g_register = cx25840_g_register,
1595 .s_register = cx25840_s_register, 1807 .s_register = cx25840_s_register,
1596#endif 1808#endif
1809 .interrupt_service_routine = cx25840_irq_handler,
1597}; 1810};
1598 1811
1599static const struct v4l2_subdev_tuner_ops cx25840_tuner_ops = { 1812static const struct v4l2_subdev_tuner_ops cx25840_tuner_ops = {
@@ -1628,6 +1841,7 @@ static const struct v4l2_subdev_ops cx25840_ops = {
1628 .audio = &cx25840_audio_ops, 1841 .audio = &cx25840_audio_ops,
1629 .video = &cx25840_video_ops, 1842 .video = &cx25840_video_ops,
1630 .vbi = &cx25840_vbi_ops, 1843 .vbi = &cx25840_vbi_ops,
1844 .ir = &cx25840_ir_ops,
1631}; 1845};
1632 1846
1633/* ----------------------------------------------------------------------- */ 1847/* ----------------------------------------------------------------------- */
@@ -1675,6 +1889,7 @@ static int cx25840_probe(struct i2c_client *client,
1675{ 1889{
1676 struct cx25840_state *state; 1890 struct cx25840_state *state;
1677 struct v4l2_subdev *sd; 1891 struct v4l2_subdev *sd;
1892 int default_volume;
1678 u32 id = V4L2_IDENT_NONE; 1893 u32 id = V4L2_IDENT_NONE;
1679 u16 device_id; 1894 u16 device_id;
1680 1895
@@ -1718,6 +1933,7 @@ static int cx25840_probe(struct i2c_client *client,
1718 1933
1719 sd = &state->sd; 1934 sd = &state->sd;
1720 v4l2_i2c_subdev_init(sd, client, &cx25840_ops); 1935 v4l2_i2c_subdev_init(sd, client, &cx25840_ops);
1936
1721 switch (id) { 1937 switch (id) {
1722 case V4L2_IDENT_CX23885_AV: 1938 case V4L2_IDENT_CX23885_AV:
1723 v4l_info(client, "cx23885 A/V decoder found @ 0x%x (%s)\n", 1939 v4l_info(client, "cx23885 A/V decoder found @ 0x%x (%s)\n",
@@ -1762,22 +1978,62 @@ static int cx25840_probe(struct i2c_client *client,
1762 state->audclk_freq = 48000; 1978 state->audclk_freq = 48000;
1763 state->pvr150_workaround = 0; 1979 state->pvr150_workaround = 0;
1764 state->audmode = V4L2_TUNER_MODE_LANG1; 1980 state->audmode = V4L2_TUNER_MODE_LANG1;
1765 state->unmute_volume = -1;
1766 state->default_volume = 228 - cx25840_read(client, 0x8d4);
1767 state->default_volume = ((state->default_volume / 2) + 23) << 9;
1768 state->vbi_line_offset = 8; 1981 state->vbi_line_offset = 8;
1769 state->id = id; 1982 state->id = id;
1770 state->rev = device_id; 1983 state->rev = device_id;
1984 v4l2_ctrl_handler_init(&state->hdl, 9);
1985 v4l2_ctrl_new_std(&state->hdl, &cx25840_ctrl_ops,
1986 V4L2_CID_BRIGHTNESS, 0, 255, 1, 128);
1987 v4l2_ctrl_new_std(&state->hdl, &cx25840_ctrl_ops,
1988 V4L2_CID_CONTRAST, 0, 127, 1, 64);
1989 v4l2_ctrl_new_std(&state->hdl, &cx25840_ctrl_ops,
1990 V4L2_CID_SATURATION, 0, 127, 1, 64);
1991 v4l2_ctrl_new_std(&state->hdl, &cx25840_ctrl_ops,
1992 V4L2_CID_HUE, -128, 127, 1, 0);
1993 if (!is_cx2583x(state)) {
1994 default_volume = 228 - cx25840_read(client, 0x8d4);
1995 default_volume = ((default_volume / 2) + 23) << 9;
1996
1997 state->volume = v4l2_ctrl_new_std(&state->hdl,
1998 &cx25840_audio_ctrl_ops, V4L2_CID_AUDIO_VOLUME,
1999 0, 65335, 65535 / 100, default_volume);
2000 state->mute = v4l2_ctrl_new_std(&state->hdl,
2001 &cx25840_audio_ctrl_ops, V4L2_CID_AUDIO_MUTE,
2002 0, 1, 1, 0);
2003 v4l2_ctrl_new_std(&state->hdl, &cx25840_audio_ctrl_ops,
2004 V4L2_CID_AUDIO_BALANCE,
2005 0, 65535, 65535 / 100, 32768);
2006 v4l2_ctrl_new_std(&state->hdl, &cx25840_audio_ctrl_ops,
2007 V4L2_CID_AUDIO_BASS,
2008 0, 65535, 65535 / 100, 32768);
2009 v4l2_ctrl_new_std(&state->hdl, &cx25840_audio_ctrl_ops,
2010 V4L2_CID_AUDIO_TREBLE,
2011 0, 65535, 65535 / 100, 32768);
2012 }
2013 sd->ctrl_handler = &state->hdl;
2014 if (state->hdl.error) {
2015 int err = state->hdl.error;
2016
2017 v4l2_ctrl_handler_free(&state->hdl);
2018 kfree(state);
2019 return err;
2020 }
2021 v4l2_ctrl_cluster(2, &state->volume);
2022 v4l2_ctrl_handler_setup(&state->hdl);
1771 2023
2024 cx25840_ir_probe(sd);
1772 return 0; 2025 return 0;
1773} 2026}
1774 2027
1775static int cx25840_remove(struct i2c_client *client) 2028static int cx25840_remove(struct i2c_client *client)
1776{ 2029{
1777 struct v4l2_subdev *sd = i2c_get_clientdata(client); 2030 struct v4l2_subdev *sd = i2c_get_clientdata(client);
2031 struct cx25840_state *state = to_state(sd);
1778 2032
2033 cx25840_ir_remove(sd);
1779 v4l2_device_unregister_subdev(sd); 2034 v4l2_device_unregister_subdev(sd);
1780 kfree(to_state(sd)); 2035 v4l2_ctrl_handler_free(&state->hdl);
2036 kfree(state);
1781 return 0; 2037 return 0;
1782} 2038}
1783 2039
diff --git a/drivers/media/video/cx25840/cx25840-core.h b/drivers/media/video/cx25840/cx25840-core.h
index 04393b971567..bd4ada28b490 100644
--- a/drivers/media/video/cx25840/cx25840-core.h
+++ b/drivers/media/video/cx25840/cx25840-core.h
@@ -24,19 +24,20 @@
24#include <linux/videodev2.h> 24#include <linux/videodev2.h>
25#include <media/v4l2-device.h> 25#include <media/v4l2-device.h>
26#include <media/v4l2-chip-ident.h> 26#include <media/v4l2-chip-ident.h>
27#include <media/v4l2-ctrls.h>
27#include <linux/i2c.h> 28#include <linux/i2c.h>
28 29
29/* ENABLE_PVR150_WORKAROUND activates a workaround for a hardware bug that is 30struct cx25840_ir_state;
30 present in Hauppauge PVR-150 (and possibly PVR-500) cards that have
31 certain NTSC tuners (tveeprom tuner model numbers 85, 99 and 112). The
32 audio autodetect fails on some channels for these models and the workaround
33 is to select the audio standard explicitly. Many thanks to Hauppauge for
34 providing this information. */
35#define CX25840_CID_ENABLE_PVR150_WORKAROUND (V4L2_CID_PRIVATE_BASE+0)
36 31
37struct cx25840_state { 32struct cx25840_state {
38 struct i2c_client *c; 33 struct i2c_client *c;
39 struct v4l2_subdev sd; 34 struct v4l2_subdev sd;
35 struct v4l2_ctrl_handler hdl;
36 struct {
37 /* volume cluster */
38 struct v4l2_ctrl *volume;
39 struct v4l2_ctrl *mute;
40 };
40 int pvr150_workaround; 41 int pvr150_workaround;
41 int radio; 42 int radio;
42 v4l2_std_id std; 43 v4l2_std_id std;
@@ -44,14 +45,13 @@ struct cx25840_state {
44 enum cx25840_audio_input aud_input; 45 enum cx25840_audio_input aud_input;
45 u32 audclk_freq; 46 u32 audclk_freq;
46 int audmode; 47 int audmode;
47 int unmute_volume; /* -1 if not muted */
48 int default_volume;
49 int vbi_line_offset; 48 int vbi_line_offset;
50 u32 id; 49 u32 id;
51 u32 rev; 50 u32 rev;
52 int is_initialized; 51 int is_initialized;
53 wait_queue_head_t fw_wait; /* wake up when the fw load is finished */ 52 wait_queue_head_t fw_wait; /* wake up when the fw load is finished */
54 struct work_struct fw_work; /* work entry for fw load */ 53 struct work_struct fw_work; /* work entry for fw load */
54 struct cx25840_ir_state *ir_state;
55}; 55};
56 56
57static inline struct cx25840_state *to_state(struct v4l2_subdev *sd) 57static inline struct cx25840_state *to_state(struct v4l2_subdev *sd)
@@ -59,6 +59,11 @@ static inline struct cx25840_state *to_state(struct v4l2_subdev *sd)
59 return container_of(sd, struct cx25840_state, sd); 59 return container_of(sd, struct cx25840_state, sd);
60} 60}
61 61
62static inline struct v4l2_subdev *to_sd(struct v4l2_ctrl *ctrl)
63{
64 return &container_of(ctrl->handler, struct cx25840_state, hdl)->sd;
65}
66
62static inline bool is_cx2583x(struct cx25840_state *state) 67static inline bool is_cx2583x(struct cx25840_state *state)
63{ 68{
64 return state->id == V4L2_IDENT_CX25836 || 69 return state->id == V4L2_IDENT_CX25836 ||
@@ -77,6 +82,21 @@ static inline bool is_cx2388x(struct cx25840_state *state)
77 state->id == V4L2_IDENT_CX23888_AV; 82 state->id == V4L2_IDENT_CX23888_AV;
78} 83}
79 84
85static inline bool is_cx23885(struct cx25840_state *state)
86{
87 return state->id == V4L2_IDENT_CX23885_AV;
88}
89
90static inline bool is_cx23887(struct cx25840_state *state)
91{
92 return state->id == V4L2_IDENT_CX23887_AV;
93}
94
95static inline bool is_cx23888(struct cx25840_state *state)
96{
97 return state->id == V4L2_IDENT_CX23888_AV;
98}
99
80/* ----------------------------------------------------------------------- */ 100/* ----------------------------------------------------------------------- */
81/* cx25850-core.c */ 101/* cx25850-core.c */
82int cx25840_write(struct i2c_client *client, u16 addr, u8 value); 102int cx25840_write(struct i2c_client *client, u16 addr, u8 value);
@@ -84,6 +104,8 @@ int cx25840_write4(struct i2c_client *client, u16 addr, u32 value);
84u8 cx25840_read(struct i2c_client *client, u16 addr); 104u8 cx25840_read(struct i2c_client *client, u16 addr);
85u32 cx25840_read4(struct i2c_client *client, u16 addr); 105u32 cx25840_read4(struct i2c_client *client, u16 addr);
86int cx25840_and_or(struct i2c_client *client, u16 addr, unsigned mask, u8 value); 106int cx25840_and_or(struct i2c_client *client, u16 addr, unsigned mask, u8 value);
107int cx25840_and_or4(struct i2c_client *client, u16 addr, u32 and_mask,
108 u32 or_value);
87void cx25840_std_setup(struct i2c_client *client); 109void cx25840_std_setup(struct i2c_client *client);
88 110
89/* ----------------------------------------------------------------------- */ 111/* ----------------------------------------------------------------------- */
@@ -94,8 +116,8 @@ int cx25840_loadfw(struct i2c_client *client);
94/* cx25850-audio.c */ 116/* cx25850-audio.c */
95void cx25840_audio_set_path(struct i2c_client *client); 117void cx25840_audio_set_path(struct i2c_client *client);
96int cx25840_s_clock_freq(struct v4l2_subdev *sd, u32 freq); 118int cx25840_s_clock_freq(struct v4l2_subdev *sd, u32 freq);
97int cx25840_audio_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl); 119
98int cx25840_audio_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl); 120extern const struct v4l2_ctrl_ops cx25840_audio_ctrl_ops;
99 121
100/* ----------------------------------------------------------------------- */ 122/* ----------------------------------------------------------------------- */
101/* cx25850-vbi.c */ 123/* cx25850-vbi.c */
@@ -104,4 +126,12 @@ int cx25840_s_sliced_fmt(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *
104int cx25840_g_sliced_fmt(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *fmt); 126int cx25840_g_sliced_fmt(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *fmt);
105int cx25840_decode_vbi_line(struct v4l2_subdev *sd, struct v4l2_decode_vbi_line *vbi); 127int cx25840_decode_vbi_line(struct v4l2_subdev *sd, struct v4l2_decode_vbi_line *vbi);
106 128
129/* ----------------------------------------------------------------------- */
130/* cx25850-ir.c */
131extern const struct v4l2_subdev_ir_ops cx25840_ir_ops;
132int cx25840_ir_log_status(struct v4l2_subdev *sd);
133int cx25840_ir_irq_handler(struct v4l2_subdev *sd, u32 status, bool *handled);
134int cx25840_ir_probe(struct v4l2_subdev *sd);
135int cx25840_ir_remove(struct v4l2_subdev *sd);
136
107#endif 137#endif
diff --git a/drivers/media/video/cx25840/cx25840-ir.c b/drivers/media/video/cx25840/cx25840-ir.c
new file mode 100644
index 000000000000..c2b4c14dc9ab
--- /dev/null
+++ b/drivers/media/video/cx25840/cx25840-ir.c
@@ -0,0 +1,1279 @@
1/*
2 * Driver for the Conexant CX2584x Audio/Video decoder chip and related cores
3 *
4 * Integrated Consumer Infrared Controller
5 *
6 * Copyright (C) 2010 Andy Walls <awalls@md.metrocast.net>
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
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 * 02110-1301, USA.
22 */
23
24#include <linux/slab.h>
25#include <linux/kfifo.h>
26#include <media/cx25840.h>
27#include <media/ir-core.h>
28
29#include "cx25840-core.h"
30
31static unsigned int ir_debug;
32module_param(ir_debug, int, 0644);
33MODULE_PARM_DESC(ir_debug, "enable integrated IR debug messages");
34
35#define CX25840_IR_REG_BASE 0x200
36
37#define CX25840_IR_CNTRL_REG 0x200
38#define CNTRL_WIN_3_3 0x00000000
39#define CNTRL_WIN_4_3 0x00000001
40#define CNTRL_WIN_3_4 0x00000002
41#define CNTRL_WIN_4_4 0x00000003
42#define CNTRL_WIN 0x00000003
43#define CNTRL_EDG_NONE 0x00000000
44#define CNTRL_EDG_FALL 0x00000004
45#define CNTRL_EDG_RISE 0x00000008
46#define CNTRL_EDG_BOTH 0x0000000C
47#define CNTRL_EDG 0x0000000C
48#define CNTRL_DMD 0x00000010
49#define CNTRL_MOD 0x00000020
50#define CNTRL_RFE 0x00000040
51#define CNTRL_TFE 0x00000080
52#define CNTRL_RXE 0x00000100
53#define CNTRL_TXE 0x00000200
54#define CNTRL_RIC 0x00000400
55#define CNTRL_TIC 0x00000800
56#define CNTRL_CPL 0x00001000
57#define CNTRL_LBM 0x00002000
58#define CNTRL_R 0x00004000
59
60#define CX25840_IR_TXCLK_REG 0x204
61#define TXCLK_TCD 0x0000FFFF
62
63#define CX25840_IR_RXCLK_REG 0x208
64#define RXCLK_RCD 0x0000FFFF
65
66#define CX25840_IR_CDUTY_REG 0x20C
67#define CDUTY_CDC 0x0000000F
68
69#define CX25840_IR_STATS_REG 0x210
70#define STATS_RTO 0x00000001
71#define STATS_ROR 0x00000002
72#define STATS_RBY 0x00000004
73#define STATS_TBY 0x00000008
74#define STATS_RSR 0x00000010
75#define STATS_TSR 0x00000020
76
77#define CX25840_IR_IRQEN_REG 0x214
78#define IRQEN_RTE 0x00000001
79#define IRQEN_ROE 0x00000002
80#define IRQEN_RSE 0x00000010
81#define IRQEN_TSE 0x00000020
82#define IRQEN_MSK 0x00000033
83
84#define CX25840_IR_FILTR_REG 0x218
85#define FILTR_LPF 0x0000FFFF
86
87#define CX25840_IR_FIFO_REG 0x23C
88#define FIFO_RXTX 0x0000FFFF
89#define FIFO_RXTX_LVL 0x00010000
90#define FIFO_RXTX_RTO 0x0001FFFF
91#define FIFO_RX_NDV 0x00020000
92#define FIFO_RX_DEPTH 8
93#define FIFO_TX_DEPTH 8
94
95#define CX25840_VIDCLK_FREQ 108000000 /* 108 MHz, BT.656 */
96#define CX25840_IR_REFCLK_FREQ (CX25840_VIDCLK_FREQ / 2)
97
98/*
99 * We use this union internally for convenience, but callers to tx_write
100 * and rx_read will be expecting records of type struct ir_raw_event.
101 * Always ensure the size of this union is dictated by struct ir_raw_event.
102 */
103union cx25840_ir_fifo_rec {
104 u32 hw_fifo_data;
105 struct ir_raw_event ir_core_data;
106};
107
108#define CX25840_IR_RX_KFIFO_SIZE (256 * sizeof(union cx25840_ir_fifo_rec))
109#define CX25840_IR_TX_KFIFO_SIZE (256 * sizeof(union cx25840_ir_fifo_rec))
110
111struct cx25840_ir_state {
112 struct i2c_client *c;
113
114 struct v4l2_subdev_ir_parameters rx_params;
115 struct mutex rx_params_lock; /* protects Rx parameter settings cache */
116 atomic_t rxclk_divider;
117 atomic_t rx_invert;
118
119 struct kfifo rx_kfifo;
120 spinlock_t rx_kfifo_lock; /* protect Rx data kfifo */
121
122 struct v4l2_subdev_ir_parameters tx_params;
123 struct mutex tx_params_lock; /* protects Tx parameter settings cache */
124 atomic_t txclk_divider;
125};
126
127static inline struct cx25840_ir_state *to_ir_state(struct v4l2_subdev *sd)
128{
129 struct cx25840_state *state = to_state(sd);
130 return state ? state->ir_state : NULL;
131}
132
133
134/*
135 * Rx and Tx Clock Divider register computations
136 *
137 * Note the largest clock divider value of 0xffff corresponds to:
138 * (0xffff + 1) * 1000 / 108/2 MHz = 1,213,629.629... ns
139 * which fits in 21 bits, so we'll use unsigned int for time arguments.
140 */
141static inline u16 count_to_clock_divider(unsigned int d)
142{
143 if (d > RXCLK_RCD + 1)
144 d = RXCLK_RCD;
145 else if (d < 2)
146 d = 1;
147 else
148 d--;
149 return (u16) d;
150}
151
152static inline u16 ns_to_clock_divider(unsigned int ns)
153{
154 return count_to_clock_divider(
155 DIV_ROUND_CLOSEST(CX25840_IR_REFCLK_FREQ / 1000000 * ns, 1000));
156}
157
158static inline unsigned int clock_divider_to_ns(unsigned int divider)
159{
160 /* Period of the Rx or Tx clock in ns */
161 return DIV_ROUND_CLOSEST((divider + 1) * 1000,
162 CX25840_IR_REFCLK_FREQ / 1000000);
163}
164
165static inline u16 carrier_freq_to_clock_divider(unsigned int freq)
166{
167 return count_to_clock_divider(
168 DIV_ROUND_CLOSEST(CX25840_IR_REFCLK_FREQ, freq * 16));
169}
170
171static inline unsigned int clock_divider_to_carrier_freq(unsigned int divider)
172{
173 return DIV_ROUND_CLOSEST(CX25840_IR_REFCLK_FREQ, (divider + 1) * 16);
174}
175
176static inline u16 freq_to_clock_divider(unsigned int freq,
177 unsigned int rollovers)
178{
179 return count_to_clock_divider(
180 DIV_ROUND_CLOSEST(CX25840_IR_REFCLK_FREQ, freq * rollovers));
181}
182
183static inline unsigned int clock_divider_to_freq(unsigned int divider,
184 unsigned int rollovers)
185{
186 return DIV_ROUND_CLOSEST(CX25840_IR_REFCLK_FREQ,
187 (divider + 1) * rollovers);
188}
189
190/*
191 * Low Pass Filter register calculations
192 *
193 * Note the largest count value of 0xffff corresponds to:
194 * 0xffff * 1000 / 108/2 MHz = 1,213,611.11... ns
195 * which fits in 21 bits, so we'll use unsigned int for time arguments.
196 */
197static inline u16 count_to_lpf_count(unsigned int d)
198{
199 if (d > FILTR_LPF)
200 d = FILTR_LPF;
201 else if (d < 4)
202 d = 0;
203 return (u16) d;
204}
205
206static inline u16 ns_to_lpf_count(unsigned int ns)
207{
208 return count_to_lpf_count(
209 DIV_ROUND_CLOSEST(CX25840_IR_REFCLK_FREQ / 1000000 * ns, 1000));
210}
211
212static inline unsigned int lpf_count_to_ns(unsigned int count)
213{
214 /* Duration of the Low Pass Filter rejection window in ns */
215 return DIV_ROUND_CLOSEST(count * 1000,
216 CX25840_IR_REFCLK_FREQ / 1000000);
217}
218
219static inline unsigned int lpf_count_to_us(unsigned int count)
220{
221 /* Duration of the Low Pass Filter rejection window in us */
222 return DIV_ROUND_CLOSEST(count, CX25840_IR_REFCLK_FREQ / 1000000);
223}
224
225/*
226 * FIFO register pulse width count compuations
227 */
228static u32 clock_divider_to_resolution(u16 divider)
229{
230 /*
231 * Resolution is the duration of 1 tick of the readable portion of
232 * of the pulse width counter as read from the FIFO. The two lsb's are
233 * not readable, hence the << 2. This function returns ns.
234 */
235 return DIV_ROUND_CLOSEST((1 << 2) * ((u32) divider + 1) * 1000,
236 CX25840_IR_REFCLK_FREQ / 1000000);
237}
238
239static u64 pulse_width_count_to_ns(u16 count, u16 divider)
240{
241 u64 n;
242 u32 rem;
243
244 /*
245 * The 2 lsb's of the pulse width timer count are not readable, hence
246 * the (count << 2) | 0x3
247 */
248 n = (((u64) count << 2) | 0x3) * (divider + 1) * 1000; /* millicycles */
249 rem = do_div(n, CX25840_IR_REFCLK_FREQ / 1000000); /* / MHz => ns */
250 if (rem >= CX25840_IR_REFCLK_FREQ / 1000000 / 2)
251 n++;
252 return n;
253}
254
255#if 0
256/* Keep as we will need this for Transmit functionality */
257static u16 ns_to_pulse_width_count(u32 ns, u16 divider)
258{
259 u64 n;
260 u32 d;
261 u32 rem;
262
263 /*
264 * The 2 lsb's of the pulse width timer count are not accessable, hence
265 * the (1 << 2)
266 */
267 n = ((u64) ns) * CX25840_IR_REFCLK_FREQ / 1000000; /* millicycles */
268 d = (1 << 2) * ((u32) divider + 1) * 1000; /* millicycles/count */
269 rem = do_div(n, d);
270 if (rem >= d / 2)
271 n++;
272
273 if (n > FIFO_RXTX)
274 n = FIFO_RXTX;
275 else if (n == 0)
276 n = 1;
277 return (u16) n;
278}
279
280#endif
281static unsigned int pulse_width_count_to_us(u16 count, u16 divider)
282{
283 u64 n;
284 u32 rem;
285
286 /*
287 * The 2 lsb's of the pulse width timer count are not readable, hence
288 * the (count << 2) | 0x3
289 */
290 n = (((u64) count << 2) | 0x3) * (divider + 1); /* cycles */
291 rem = do_div(n, CX25840_IR_REFCLK_FREQ / 1000000); /* / MHz => us */
292 if (rem >= CX25840_IR_REFCLK_FREQ / 1000000 / 2)
293 n++;
294 return (unsigned int) n;
295}
296
297/*
298 * Pulse Clocks computations: Combined Pulse Width Count & Rx Clock Counts
299 *
300 * The total pulse clock count is an 18 bit pulse width timer count as the most
301 * significant part and (up to) 16 bit clock divider count as a modulus.
302 * When the Rx clock divider ticks down to 0, it increments the 18 bit pulse
303 * width timer count's least significant bit.
304 */
305static u64 ns_to_pulse_clocks(u32 ns)
306{
307 u64 clocks;
308 u32 rem;
309 clocks = CX25840_IR_REFCLK_FREQ / 1000000 * (u64) ns; /* millicycles */
310 rem = do_div(clocks, 1000); /* /1000 = cycles */
311 if (rem >= 1000 / 2)
312 clocks++;
313 return clocks;
314}
315
316static u16 pulse_clocks_to_clock_divider(u64 count)
317{
318 u32 rem;
319
320 rem = do_div(count, (FIFO_RXTX << 2) | 0x3);
321
322 /* net result needs to be rounded down and decremented by 1 */
323 if (count > RXCLK_RCD + 1)
324 count = RXCLK_RCD;
325 else if (count < 2)
326 count = 1;
327 else
328 count--;
329 return (u16) count;
330}
331
332/*
333 * IR Control Register helpers
334 */
335enum tx_fifo_watermark {
336 TX_FIFO_HALF_EMPTY = 0,
337 TX_FIFO_EMPTY = CNTRL_TIC,
338};
339
340enum rx_fifo_watermark {
341 RX_FIFO_HALF_FULL = 0,
342 RX_FIFO_NOT_EMPTY = CNTRL_RIC,
343};
344
345static inline void control_tx_irq_watermark(struct i2c_client *c,
346 enum tx_fifo_watermark level)
347{
348 cx25840_and_or4(c, CX25840_IR_CNTRL_REG, ~CNTRL_TIC, level);
349}
350
351static inline void control_rx_irq_watermark(struct i2c_client *c,
352 enum rx_fifo_watermark level)
353{
354 cx25840_and_or4(c, CX25840_IR_CNTRL_REG, ~CNTRL_RIC, level);
355}
356
357static inline void control_tx_enable(struct i2c_client *c, bool enable)
358{
359 cx25840_and_or4(c, CX25840_IR_CNTRL_REG, ~(CNTRL_TXE | CNTRL_TFE),
360 enable ? (CNTRL_TXE | CNTRL_TFE) : 0);
361}
362
363static inline void control_rx_enable(struct i2c_client *c, bool enable)
364{
365 cx25840_and_or4(c, CX25840_IR_CNTRL_REG, ~(CNTRL_RXE | CNTRL_RFE),
366 enable ? (CNTRL_RXE | CNTRL_RFE) : 0);
367}
368
369static inline void control_tx_modulation_enable(struct i2c_client *c,
370 bool enable)
371{
372 cx25840_and_or4(c, CX25840_IR_CNTRL_REG, ~CNTRL_MOD,
373 enable ? CNTRL_MOD : 0);
374}
375
376static inline void control_rx_demodulation_enable(struct i2c_client *c,
377 bool enable)
378{
379 cx25840_and_or4(c, CX25840_IR_CNTRL_REG, ~CNTRL_DMD,
380 enable ? CNTRL_DMD : 0);
381}
382
383static inline void control_rx_s_edge_detection(struct i2c_client *c,
384 u32 edge_types)
385{
386 cx25840_and_or4(c, CX25840_IR_CNTRL_REG, ~CNTRL_EDG_BOTH,
387 edge_types & CNTRL_EDG_BOTH);
388}
389
390static void control_rx_s_carrier_window(struct i2c_client *c,
391 unsigned int carrier,
392 unsigned int *carrier_range_low,
393 unsigned int *carrier_range_high)
394{
395 u32 v;
396 unsigned int c16 = carrier * 16;
397
398 if (*carrier_range_low < DIV_ROUND_CLOSEST(c16, 16 + 3)) {
399 v = CNTRL_WIN_3_4;
400 *carrier_range_low = DIV_ROUND_CLOSEST(c16, 16 + 4);
401 } else {
402 v = CNTRL_WIN_3_3;
403 *carrier_range_low = DIV_ROUND_CLOSEST(c16, 16 + 3);
404 }
405
406 if (*carrier_range_high > DIV_ROUND_CLOSEST(c16, 16 - 3)) {
407 v |= CNTRL_WIN_4_3;
408 *carrier_range_high = DIV_ROUND_CLOSEST(c16, 16 - 4);
409 } else {
410 v |= CNTRL_WIN_3_3;
411 *carrier_range_high = DIV_ROUND_CLOSEST(c16, 16 - 3);
412 }
413 cx25840_and_or4(c, CX25840_IR_CNTRL_REG, ~CNTRL_WIN, v);
414}
415
416static inline void control_tx_polarity_invert(struct i2c_client *c,
417 bool invert)
418{
419 cx25840_and_or4(c, CX25840_IR_CNTRL_REG, ~CNTRL_CPL,
420 invert ? CNTRL_CPL : 0);
421}
422
423/*
424 * IR Rx & Tx Clock Register helpers
425 */
426static unsigned int txclk_tx_s_carrier(struct i2c_client *c,
427 unsigned int freq,
428 u16 *divider)
429{
430 *divider = carrier_freq_to_clock_divider(freq);
431 cx25840_write4(c, CX25840_IR_TXCLK_REG, *divider);
432 return clock_divider_to_carrier_freq(*divider);
433}
434
435static unsigned int rxclk_rx_s_carrier(struct i2c_client *c,
436 unsigned int freq,
437 u16 *divider)
438{
439 *divider = carrier_freq_to_clock_divider(freq);
440 cx25840_write4(c, CX25840_IR_RXCLK_REG, *divider);
441 return clock_divider_to_carrier_freq(*divider);
442}
443
444static u32 txclk_tx_s_max_pulse_width(struct i2c_client *c, u32 ns,
445 u16 *divider)
446{
447 u64 pulse_clocks;
448
449 if (ns > IR_MAX_DURATION)
450 ns = IR_MAX_DURATION;
451 pulse_clocks = ns_to_pulse_clocks(ns);
452 *divider = pulse_clocks_to_clock_divider(pulse_clocks);
453 cx25840_write4(c, CX25840_IR_TXCLK_REG, *divider);
454 return (u32) pulse_width_count_to_ns(FIFO_RXTX, *divider);
455}
456
457static u32 rxclk_rx_s_max_pulse_width(struct i2c_client *c, u32 ns,
458 u16 *divider)
459{
460 u64 pulse_clocks;
461
462 if (ns > IR_MAX_DURATION)
463 ns = IR_MAX_DURATION;
464 pulse_clocks = ns_to_pulse_clocks(ns);
465 *divider = pulse_clocks_to_clock_divider(pulse_clocks);
466 cx25840_write4(c, CX25840_IR_RXCLK_REG, *divider);
467 return (u32) pulse_width_count_to_ns(FIFO_RXTX, *divider);
468}
469
470/*
471 * IR Tx Carrier Duty Cycle register helpers
472 */
473static unsigned int cduty_tx_s_duty_cycle(struct i2c_client *c,
474 unsigned int duty_cycle)
475{
476 u32 n;
477 n = DIV_ROUND_CLOSEST(duty_cycle * 100, 625); /* 16ths of 100% */
478 if (n != 0)
479 n--;
480 if (n > 15)
481 n = 15;
482 cx25840_write4(c, CX25840_IR_CDUTY_REG, n);
483 return DIV_ROUND_CLOSEST((n + 1) * 100, 16);
484}
485
486/*
487 * IR Filter Register helpers
488 */
489static u32 filter_rx_s_min_width(struct i2c_client *c, u32 min_width_ns)
490{
491 u32 count = ns_to_lpf_count(min_width_ns);
492 cx25840_write4(c, CX25840_IR_FILTR_REG, count);
493 return lpf_count_to_ns(count);
494}
495
496/*
497 * IR IRQ Enable Register helpers
498 */
499static inline void irqenable_rx(struct v4l2_subdev *sd, u32 mask)
500{
501 struct cx25840_state *state = to_state(sd);
502
503 if (is_cx23885(state) || is_cx23887(state))
504 mask ^= IRQEN_MSK;
505 mask &= (IRQEN_RTE | IRQEN_ROE | IRQEN_RSE);
506 cx25840_and_or4(state->c, CX25840_IR_IRQEN_REG,
507 ~(IRQEN_RTE | IRQEN_ROE | IRQEN_RSE), mask);
508}
509
510static inline void irqenable_tx(struct v4l2_subdev *sd, u32 mask)
511{
512 struct cx25840_state *state = to_state(sd);
513
514 if (is_cx23885(state) || is_cx23887(state))
515 mask ^= IRQEN_MSK;
516 mask &= IRQEN_TSE;
517 cx25840_and_or4(state->c, CX25840_IR_IRQEN_REG, ~IRQEN_TSE, mask);
518}
519
520/*
521 * V4L2 Subdevice IR Ops
522 */
523int cx25840_ir_irq_handler(struct v4l2_subdev *sd, u32 status, bool *handled)
524{
525 struct cx25840_state *state = to_state(sd);
526 struct cx25840_ir_state *ir_state = to_ir_state(sd);
527 struct i2c_client *c = NULL;
528 unsigned long flags;
529
530 union cx25840_ir_fifo_rec rx_data[FIFO_RX_DEPTH];
531 unsigned int i, j, k;
532 u32 events, v;
533 int tsr, rsr, rto, ror, tse, rse, rte, roe, kror;
534 u32 cntrl, irqen, stats;
535
536 *handled = false;
537 if (ir_state == NULL)
538 return -ENODEV;
539
540 c = ir_state->c;
541
542 /* Only support the IR controller for the CX2388[57] AV Core for now */
543 if (!(is_cx23885(state) || is_cx23887(state)))
544 return -ENODEV;
545
546 cntrl = cx25840_read4(c, CX25840_IR_CNTRL_REG);
547 irqen = cx25840_read4(c, CX25840_IR_IRQEN_REG);
548 if (is_cx23885(state) || is_cx23887(state))
549 irqen ^= IRQEN_MSK;
550 stats = cx25840_read4(c, CX25840_IR_STATS_REG);
551
552 tsr = stats & STATS_TSR; /* Tx FIFO Service Request */
553 rsr = stats & STATS_RSR; /* Rx FIFO Service Request */
554 rto = stats & STATS_RTO; /* Rx Pulse Width Timer Time Out */
555 ror = stats & STATS_ROR; /* Rx FIFO Over Run */
556
557 tse = irqen & IRQEN_TSE; /* Tx FIFO Service Request IRQ Enable */
558 rse = irqen & IRQEN_RSE; /* Rx FIFO Service Reuqest IRQ Enable */
559 rte = irqen & IRQEN_RTE; /* Rx Pulse Width Timer Time Out IRQ Enable */
560 roe = irqen & IRQEN_ROE; /* Rx FIFO Over Run IRQ Enable */
561
562 v4l2_dbg(2, ir_debug, sd, "IR IRQ Status: %s %s %s %s %s %s\n",
563 tsr ? "tsr" : " ", rsr ? "rsr" : " ",
564 rto ? "rto" : " ", ror ? "ror" : " ",
565 stats & STATS_TBY ? "tby" : " ",
566 stats & STATS_RBY ? "rby" : " ");
567
568 v4l2_dbg(2, ir_debug, sd, "IR IRQ Enables: %s %s %s %s\n",
569 tse ? "tse" : " ", rse ? "rse" : " ",
570 rte ? "rte" : " ", roe ? "roe" : " ");
571
572 /*
573 * Transmitter interrupt service
574 */
575 if (tse && tsr) {
576 /*
577 * TODO:
578 * Check the watermark threshold setting
579 * Pull FIFO_TX_DEPTH or FIFO_TX_DEPTH/2 entries from tx_kfifo
580 * Push the data to the hardware FIFO.
581 * If there was nothing more to send in the tx_kfifo, disable
582 * the TSR IRQ and notify the v4l2_device.
583 * If there was something in the tx_kfifo, check the tx_kfifo
584 * level and notify the v4l2_device, if it is low.
585 */
586 /* For now, inhibit TSR interrupt until Tx is implemented */
587 irqenable_tx(sd, 0);
588 events = V4L2_SUBDEV_IR_TX_FIFO_SERVICE_REQ;
589 v4l2_subdev_notify(sd, V4L2_SUBDEV_IR_TX_NOTIFY, &events);
590 *handled = true;
591 }
592
593 /*
594 * Receiver interrupt service
595 */
596 kror = 0;
597 if ((rse && rsr) || (rte && rto)) {
598 /*
599 * Receive data on RSR to clear the STATS_RSR.
600 * Receive data on RTO, since we may not have yet hit the RSR
601 * watermark when we receive the RTO.
602 */
603 for (i = 0, v = FIFO_RX_NDV;
604 (v & FIFO_RX_NDV) && !kror; i = 0) {
605 for (j = 0;
606 (v & FIFO_RX_NDV) && j < FIFO_RX_DEPTH; j++) {
607 v = cx25840_read4(c, CX25840_IR_FIFO_REG);
608 rx_data[i].hw_fifo_data = v & ~FIFO_RX_NDV;
609 i++;
610 }
611 if (i == 0)
612 break;
613 j = i * sizeof(union cx25840_ir_fifo_rec);
614 k = kfifo_in_locked(&ir_state->rx_kfifo,
615 (unsigned char *) rx_data, j,
616 &ir_state->rx_kfifo_lock);
617 if (k != j)
618 kror++; /* rx_kfifo over run */
619 }
620 *handled = true;
621 }
622
623 events = 0;
624 v = 0;
625 if (kror) {
626 events |= V4L2_SUBDEV_IR_RX_SW_FIFO_OVERRUN;
627 v4l2_err(sd, "IR receiver software FIFO overrun\n");
628 }
629 if (roe && ror) {
630 /*
631 * The RX FIFO Enable (CNTRL_RFE) must be toggled to clear
632 * the Rx FIFO Over Run status (STATS_ROR)
633 */
634 v |= CNTRL_RFE;
635 events |= V4L2_SUBDEV_IR_RX_HW_FIFO_OVERRUN;
636 v4l2_err(sd, "IR receiver hardware FIFO overrun\n");
637 }
638 if (rte && rto) {
639 /*
640 * The IR Receiver Enable (CNTRL_RXE) must be toggled to clear
641 * the Rx Pulse Width Timer Time Out (STATS_RTO)
642 */
643 v |= CNTRL_RXE;
644 events |= V4L2_SUBDEV_IR_RX_END_OF_RX_DETECTED;
645 }
646 if (v) {
647 /* Clear STATS_ROR & STATS_RTO as needed by reseting hardware */
648 cx25840_write4(c, CX25840_IR_CNTRL_REG, cntrl & ~v);
649 cx25840_write4(c, CX25840_IR_CNTRL_REG, cntrl);
650 *handled = true;
651 }
652 spin_lock_irqsave(&ir_state->rx_kfifo_lock, flags);
653 if (kfifo_len(&ir_state->rx_kfifo) >= CX25840_IR_RX_KFIFO_SIZE / 2)
654 events |= V4L2_SUBDEV_IR_RX_FIFO_SERVICE_REQ;
655 spin_unlock_irqrestore(&ir_state->rx_kfifo_lock, flags);
656
657 if (events)
658 v4l2_subdev_notify(sd, V4L2_SUBDEV_IR_RX_NOTIFY, &events);
659 return 0;
660}
661
662/* Receiver */
663static int cx25840_ir_rx_read(struct v4l2_subdev *sd, u8 *buf, size_t count,
664 ssize_t *num)
665{
666 struct cx25840_ir_state *ir_state = to_ir_state(sd);
667 bool invert;
668 u16 divider;
669 unsigned int i, n;
670 union cx25840_ir_fifo_rec *p;
671 unsigned u, v;
672
673 if (ir_state == NULL)
674 return -ENODEV;
675
676 invert = (bool) atomic_read(&ir_state->rx_invert);
677 divider = (u16) atomic_read(&ir_state->rxclk_divider);
678
679 n = count / sizeof(union cx25840_ir_fifo_rec)
680 * sizeof(union cx25840_ir_fifo_rec);
681 if (n == 0) {
682 *num = 0;
683 return 0;
684 }
685
686 n = kfifo_out_locked(&ir_state->rx_kfifo, buf, n,
687 &ir_state->rx_kfifo_lock);
688
689 n /= sizeof(union cx25840_ir_fifo_rec);
690 *num = n * sizeof(union cx25840_ir_fifo_rec);
691
692 for (p = (union cx25840_ir_fifo_rec *) buf, i = 0; i < n; p++, i++) {
693
694 if ((p->hw_fifo_data & FIFO_RXTX_RTO) == FIFO_RXTX_RTO) {
695 /* Assume RTO was because of no IR light input */
696 u = 0;
697 v4l2_dbg(2, ir_debug, sd, "rx read: end of rx\n");
698 } else {
699 u = (p->hw_fifo_data & FIFO_RXTX_LVL) ? 1 : 0;
700 if (invert)
701 u = u ? 0 : 1;
702 }
703
704 v = (unsigned) pulse_width_count_to_ns(
705 (u16) (p->hw_fifo_data & FIFO_RXTX), divider);
706 if (v > IR_MAX_DURATION)
707 v = IR_MAX_DURATION;
708
709 p->ir_core_data.pulse = u;
710 p->ir_core_data.duration = v;
711
712 v4l2_dbg(2, ir_debug, sd, "rx read: %10u ns %s\n",
713 v, u ? "mark" : "space");
714 }
715 return 0;
716}
717
718static int cx25840_ir_rx_g_parameters(struct v4l2_subdev *sd,
719 struct v4l2_subdev_ir_parameters *p)
720{
721 struct cx25840_ir_state *ir_state = to_ir_state(sd);
722
723 if (ir_state == NULL)
724 return -ENODEV;
725
726 mutex_lock(&ir_state->rx_params_lock);
727 memcpy(p, &ir_state->rx_params,
728 sizeof(struct v4l2_subdev_ir_parameters));
729 mutex_unlock(&ir_state->rx_params_lock);
730 return 0;
731}
732
733static int cx25840_ir_rx_shutdown(struct v4l2_subdev *sd)
734{
735 struct cx25840_ir_state *ir_state = to_ir_state(sd);
736 struct i2c_client *c;
737
738 if (ir_state == NULL)
739 return -ENODEV;
740
741 c = ir_state->c;
742 mutex_lock(&ir_state->rx_params_lock);
743
744 /* Disable or slow down all IR Rx circuits and counters */
745 irqenable_rx(sd, 0);
746 control_rx_enable(c, false);
747 control_rx_demodulation_enable(c, false);
748 control_rx_s_edge_detection(c, CNTRL_EDG_NONE);
749 filter_rx_s_min_width(c, 0);
750 cx25840_write4(c, CX25840_IR_RXCLK_REG, RXCLK_RCD);
751
752 ir_state->rx_params.shutdown = true;
753
754 mutex_unlock(&ir_state->rx_params_lock);
755 return 0;
756}
757
758static int cx25840_ir_rx_s_parameters(struct v4l2_subdev *sd,
759 struct v4l2_subdev_ir_parameters *p)
760{
761 struct cx25840_ir_state *ir_state = to_ir_state(sd);
762 struct i2c_client *c;
763 struct v4l2_subdev_ir_parameters *o;
764 u16 rxclk_divider;
765
766 if (ir_state == NULL)
767 return -ENODEV;
768
769 if (p->shutdown)
770 return cx25840_ir_rx_shutdown(sd);
771
772 if (p->mode != V4L2_SUBDEV_IR_MODE_PULSE_WIDTH)
773 return -ENOSYS;
774
775 c = ir_state->c;
776 o = &ir_state->rx_params;
777
778 mutex_lock(&ir_state->rx_params_lock);
779
780 o->shutdown = p->shutdown;
781
782 p->mode = V4L2_SUBDEV_IR_MODE_PULSE_WIDTH;
783 o->mode = p->mode;
784
785 p->bytes_per_data_element = sizeof(union cx25840_ir_fifo_rec);
786 o->bytes_per_data_element = p->bytes_per_data_element;
787
788 /* Before we tweak the hardware, we have to disable the receiver */
789 irqenable_rx(sd, 0);
790 control_rx_enable(c, false);
791
792 control_rx_demodulation_enable(c, p->modulation);
793 o->modulation = p->modulation;
794
795 if (p->modulation) {
796 p->carrier_freq = rxclk_rx_s_carrier(c, p->carrier_freq,
797 &rxclk_divider);
798
799 o->carrier_freq = p->carrier_freq;
800
801 p->duty_cycle = 50;
802 o->duty_cycle = p->duty_cycle;
803
804 control_rx_s_carrier_window(c, p->carrier_freq,
805 &p->carrier_range_lower,
806 &p->carrier_range_upper);
807 o->carrier_range_lower = p->carrier_range_lower;
808 o->carrier_range_upper = p->carrier_range_upper;
809
810 p->max_pulse_width =
811 (u32) pulse_width_count_to_ns(FIFO_RXTX, rxclk_divider);
812 } else {
813 p->max_pulse_width =
814 rxclk_rx_s_max_pulse_width(c, p->max_pulse_width,
815 &rxclk_divider);
816 }
817 o->max_pulse_width = p->max_pulse_width;
818 atomic_set(&ir_state->rxclk_divider, rxclk_divider);
819
820 p->noise_filter_min_width =
821 filter_rx_s_min_width(c, p->noise_filter_min_width);
822 o->noise_filter_min_width = p->noise_filter_min_width;
823
824 p->resolution = clock_divider_to_resolution(rxclk_divider);
825 o->resolution = p->resolution;
826
827 /* FIXME - make this dependent on resolution for better performance */
828 control_rx_irq_watermark(c, RX_FIFO_HALF_FULL);
829
830 control_rx_s_edge_detection(c, CNTRL_EDG_BOTH);
831
832 o->invert_level = p->invert_level;
833 atomic_set(&ir_state->rx_invert, p->invert_level);
834
835 o->interrupt_enable = p->interrupt_enable;
836 o->enable = p->enable;
837 if (p->enable) {
838 unsigned long flags;
839
840 spin_lock_irqsave(&ir_state->rx_kfifo_lock, flags);
841 kfifo_reset(&ir_state->rx_kfifo);
842 spin_unlock_irqrestore(&ir_state->rx_kfifo_lock, flags);
843 if (p->interrupt_enable)
844 irqenable_rx(sd, IRQEN_RSE | IRQEN_RTE | IRQEN_ROE);
845 control_rx_enable(c, p->enable);
846 }
847
848 mutex_unlock(&ir_state->rx_params_lock);
849 return 0;
850}
851
852/* Transmitter */
853static int cx25840_ir_tx_write(struct v4l2_subdev *sd, u8 *buf, size_t count,
854 ssize_t *num)
855{
856 struct cx25840_ir_state *ir_state = to_ir_state(sd);
857 struct i2c_client *c;
858
859 if (ir_state == NULL)
860 return -ENODEV;
861
862 c = ir_state->c;
863#if 0
864 /*
865 * FIXME - the code below is an incomplete and untested sketch of what
866 * may need to be done. The critical part is to get 4 (or 8) pulses
867 * from the tx_kfifo, or converted from ns to the proper units from the
868 * input, and push them off to the hardware Tx FIFO right away, if the
869 * HW TX fifo needs service. The rest can be pushed to the tx_kfifo in
870 * a less critical timeframe. Also watch out for overruning the
871 * tx_kfifo - don't let it happen and let the caller know not all his
872 * pulses were written.
873 */
874 u32 *ns_pulse = (u32 *) buf;
875 unsigned int n;
876 u32 fifo_pulse[FIFO_TX_DEPTH];
877 u32 mark;
878
879 /* Compute how much we can fit in the tx kfifo */
880 n = CX25840_IR_TX_KFIFO_SIZE - kfifo_len(ir_state->tx_kfifo);
881 n = min(n, (unsigned int) count);
882 n /= sizeof(u32);
883
884 /* FIXME - turn on Tx Fifo service interrupt
885 * check hardware fifo level, and other stuff
886 */
887 for (i = 0; i < n; ) {
888 for (j = 0; j < FIFO_TX_DEPTH / 2 && i < n; j++) {
889 mark = ns_pulse[i] & LEVEL_MASK;
890 fifo_pulse[j] = ns_to_pulse_width_count(
891 ns_pulse[i] &
892 ~LEVEL_MASK,
893 ir_state->txclk_divider);
894 if (mark)
895 fifo_pulse[j] &= FIFO_RXTX_LVL;
896 i++;
897 }
898 kfifo_put(ir_state->tx_kfifo, (u8 *) fifo_pulse,
899 j * sizeof(u32));
900 }
901 *num = n * sizeof(u32);
902#else
903 /* For now enable the Tx FIFO Service interrupt & pretend we did work */
904 irqenable_tx(sd, IRQEN_TSE);
905 *num = count;
906#endif
907 return 0;
908}
909
910static int cx25840_ir_tx_g_parameters(struct v4l2_subdev *sd,
911 struct v4l2_subdev_ir_parameters *p)
912{
913 struct cx25840_ir_state *ir_state = to_ir_state(sd);
914
915 if (ir_state == NULL)
916 return -ENODEV;
917
918 mutex_lock(&ir_state->tx_params_lock);
919 memcpy(p, &ir_state->tx_params,
920 sizeof(struct v4l2_subdev_ir_parameters));
921 mutex_unlock(&ir_state->tx_params_lock);
922 return 0;
923}
924
925static int cx25840_ir_tx_shutdown(struct v4l2_subdev *sd)
926{
927 struct cx25840_ir_state *ir_state = to_ir_state(sd);
928 struct i2c_client *c;
929
930 if (ir_state == NULL)
931 return -ENODEV;
932
933 c = ir_state->c;
934 mutex_lock(&ir_state->tx_params_lock);
935
936 /* Disable or slow down all IR Tx circuits and counters */
937 irqenable_tx(sd, 0);
938 control_tx_enable(c, false);
939 control_tx_modulation_enable(c, false);
940 cx25840_write4(c, CX25840_IR_TXCLK_REG, TXCLK_TCD);
941
942 ir_state->tx_params.shutdown = true;
943
944 mutex_unlock(&ir_state->tx_params_lock);
945 return 0;
946}
947
948static int cx25840_ir_tx_s_parameters(struct v4l2_subdev *sd,
949 struct v4l2_subdev_ir_parameters *p)
950{
951 struct cx25840_ir_state *ir_state = to_ir_state(sd);
952 struct i2c_client *c;
953 struct v4l2_subdev_ir_parameters *o;
954 u16 txclk_divider;
955
956 if (ir_state == NULL)
957 return -ENODEV;
958
959 if (p->shutdown)
960 return cx25840_ir_tx_shutdown(sd);
961
962 if (p->mode != V4L2_SUBDEV_IR_MODE_PULSE_WIDTH)
963 return -ENOSYS;
964
965 c = ir_state->c;
966 o = &ir_state->tx_params;
967 mutex_lock(&ir_state->tx_params_lock);
968
969 o->shutdown = p->shutdown;
970
971 p->mode = V4L2_SUBDEV_IR_MODE_PULSE_WIDTH;
972 o->mode = p->mode;
973
974 p->bytes_per_data_element = sizeof(union cx25840_ir_fifo_rec);
975 o->bytes_per_data_element = p->bytes_per_data_element;
976
977 /* Before we tweak the hardware, we have to disable the transmitter */
978 irqenable_tx(sd, 0);
979 control_tx_enable(c, false);
980
981 control_tx_modulation_enable(c, p->modulation);
982 o->modulation = p->modulation;
983
984 if (p->modulation) {
985 p->carrier_freq = txclk_tx_s_carrier(c, p->carrier_freq,
986 &txclk_divider);
987 o->carrier_freq = p->carrier_freq;
988
989 p->duty_cycle = cduty_tx_s_duty_cycle(c, p->duty_cycle);
990 o->duty_cycle = p->duty_cycle;
991
992 p->max_pulse_width =
993 (u32) pulse_width_count_to_ns(FIFO_RXTX, txclk_divider);
994 } else {
995 p->max_pulse_width =
996 txclk_tx_s_max_pulse_width(c, p->max_pulse_width,
997 &txclk_divider);
998 }
999 o->max_pulse_width = p->max_pulse_width;
1000 atomic_set(&ir_state->txclk_divider, txclk_divider);
1001
1002 p->resolution = clock_divider_to_resolution(txclk_divider);
1003 o->resolution = p->resolution;
1004
1005 /* FIXME - make this dependent on resolution for better performance */
1006 control_tx_irq_watermark(c, TX_FIFO_HALF_EMPTY);
1007
1008 control_tx_polarity_invert(c, p->invert_carrier_sense);
1009 o->invert_carrier_sense = p->invert_carrier_sense;
1010
1011 /*
1012 * FIXME: we don't have hardware help for IO pin level inversion
1013 * here like we have on the CX23888.
1014 * Act on this with some mix of logical inversion of data levels,
1015 * carrier polarity, and carrier duty cycle.
1016 */
1017 o->invert_level = p->invert_level;
1018
1019 o->interrupt_enable = p->interrupt_enable;
1020 o->enable = p->enable;
1021 if (p->enable) {
1022 /* reset tx_fifo here */
1023 if (p->interrupt_enable)
1024 irqenable_tx(sd, IRQEN_TSE);
1025 control_tx_enable(c, p->enable);
1026 }
1027
1028 mutex_unlock(&ir_state->tx_params_lock);
1029 return 0;
1030}
1031
1032
1033/*
1034 * V4L2 Subdevice Core Ops support
1035 */
1036int cx25840_ir_log_status(struct v4l2_subdev *sd)
1037{
1038 struct cx25840_state *state = to_state(sd);
1039 struct i2c_client *c = state->c;
1040 char *s;
1041 int i, j;
1042 u32 cntrl, txclk, rxclk, cduty, stats, irqen, filtr;
1043
1044 /* The CX23888 chip doesn't have an IR controller on the A/V core */
1045 if (is_cx23888(state))
1046 return 0;
1047
1048 cntrl = cx25840_read4(c, CX25840_IR_CNTRL_REG);
1049 txclk = cx25840_read4(c, CX25840_IR_TXCLK_REG) & TXCLK_TCD;
1050 rxclk = cx25840_read4(c, CX25840_IR_RXCLK_REG) & RXCLK_RCD;
1051 cduty = cx25840_read4(c, CX25840_IR_CDUTY_REG) & CDUTY_CDC;
1052 stats = cx25840_read4(c, CX25840_IR_STATS_REG);
1053 irqen = cx25840_read4(c, CX25840_IR_IRQEN_REG);
1054 if (is_cx23885(state) || is_cx23887(state))
1055 irqen ^= IRQEN_MSK;
1056 filtr = cx25840_read4(c, CX25840_IR_FILTR_REG) & FILTR_LPF;
1057
1058 v4l2_info(sd, "IR Receiver:\n");
1059 v4l2_info(sd, "\tEnabled: %s\n",
1060 cntrl & CNTRL_RXE ? "yes" : "no");
1061 v4l2_info(sd, "\tDemodulation from a carrier: %s\n",
1062 cntrl & CNTRL_DMD ? "enabled" : "disabled");
1063 v4l2_info(sd, "\tFIFO: %s\n",
1064 cntrl & CNTRL_RFE ? "enabled" : "disabled");
1065 switch (cntrl & CNTRL_EDG) {
1066 case CNTRL_EDG_NONE:
1067 s = "disabled";
1068 break;
1069 case CNTRL_EDG_FALL:
1070 s = "falling edge";
1071 break;
1072 case CNTRL_EDG_RISE:
1073 s = "rising edge";
1074 break;
1075 case CNTRL_EDG_BOTH:
1076 s = "rising & falling edges";
1077 break;
1078 default:
1079 s = "??? edge";
1080 break;
1081 }
1082 v4l2_info(sd, "\tPulse timers' start/stop trigger: %s\n", s);
1083 v4l2_info(sd, "\tFIFO data on pulse timer overflow: %s\n",
1084 cntrl & CNTRL_R ? "not loaded" : "overflow marker");
1085 v4l2_info(sd, "\tFIFO interrupt watermark: %s\n",
1086 cntrl & CNTRL_RIC ? "not empty" : "half full or greater");
1087 v4l2_info(sd, "\tLoopback mode: %s\n",
1088 cntrl & CNTRL_LBM ? "loopback active" : "normal receive");
1089 if (cntrl & CNTRL_DMD) {
1090 v4l2_info(sd, "\tExpected carrier (16 clocks): %u Hz\n",
1091 clock_divider_to_carrier_freq(rxclk));
1092 switch (cntrl & CNTRL_WIN) {
1093 case CNTRL_WIN_3_3:
1094 i = 3;
1095 j = 3;
1096 break;
1097 case CNTRL_WIN_4_3:
1098 i = 4;
1099 j = 3;
1100 break;
1101 case CNTRL_WIN_3_4:
1102 i = 3;
1103 j = 4;
1104 break;
1105 case CNTRL_WIN_4_4:
1106 i = 4;
1107 j = 4;
1108 break;
1109 default:
1110 i = 0;
1111 j = 0;
1112 break;
1113 }
1114 v4l2_info(sd, "\tNext carrier edge window: 16 clocks "
1115 "-%1d/+%1d, %u to %u Hz\n", i, j,
1116 clock_divider_to_freq(rxclk, 16 + j),
1117 clock_divider_to_freq(rxclk, 16 - i));
1118 }
1119 v4l2_info(sd, "\tMax measurable pulse width: %u us, %llu ns\n",
1120 pulse_width_count_to_us(FIFO_RXTX, rxclk),
1121 pulse_width_count_to_ns(FIFO_RXTX, rxclk));
1122 v4l2_info(sd, "\tLow pass filter: %s\n",
1123 filtr ? "enabled" : "disabled");
1124 if (filtr)
1125 v4l2_info(sd, "\tMin acceptable pulse width (LPF): %u us, "
1126 "%u ns\n",
1127 lpf_count_to_us(filtr),
1128 lpf_count_to_ns(filtr));
1129 v4l2_info(sd, "\tPulse width timer timed-out: %s\n",
1130 stats & STATS_RTO ? "yes" : "no");
1131 v4l2_info(sd, "\tPulse width timer time-out intr: %s\n",
1132 irqen & IRQEN_RTE ? "enabled" : "disabled");
1133 v4l2_info(sd, "\tFIFO overrun: %s\n",
1134 stats & STATS_ROR ? "yes" : "no");
1135 v4l2_info(sd, "\tFIFO overrun interrupt: %s\n",
1136 irqen & IRQEN_ROE ? "enabled" : "disabled");
1137 v4l2_info(sd, "\tBusy: %s\n",
1138 stats & STATS_RBY ? "yes" : "no");
1139 v4l2_info(sd, "\tFIFO service requested: %s\n",
1140 stats & STATS_RSR ? "yes" : "no");
1141 v4l2_info(sd, "\tFIFO service request interrupt: %s\n",
1142 irqen & IRQEN_RSE ? "enabled" : "disabled");
1143
1144 v4l2_info(sd, "IR Transmitter:\n");
1145 v4l2_info(sd, "\tEnabled: %s\n",
1146 cntrl & CNTRL_TXE ? "yes" : "no");
1147 v4l2_info(sd, "\tModulation onto a carrier: %s\n",
1148 cntrl & CNTRL_MOD ? "enabled" : "disabled");
1149 v4l2_info(sd, "\tFIFO: %s\n",
1150 cntrl & CNTRL_TFE ? "enabled" : "disabled");
1151 v4l2_info(sd, "\tFIFO interrupt watermark: %s\n",
1152 cntrl & CNTRL_TIC ? "not empty" : "half full or less");
1153 v4l2_info(sd, "\tCarrier polarity: %s\n",
1154 cntrl & CNTRL_CPL ? "space:burst mark:noburst"
1155 : "space:noburst mark:burst");
1156 if (cntrl & CNTRL_MOD) {
1157 v4l2_info(sd, "\tCarrier (16 clocks): %u Hz\n",
1158 clock_divider_to_carrier_freq(txclk));
1159 v4l2_info(sd, "\tCarrier duty cycle: %2u/16\n",
1160 cduty + 1);
1161 }
1162 v4l2_info(sd, "\tMax pulse width: %u us, %llu ns\n",
1163 pulse_width_count_to_us(FIFO_RXTX, txclk),
1164 pulse_width_count_to_ns(FIFO_RXTX, txclk));
1165 v4l2_info(sd, "\tBusy: %s\n",
1166 stats & STATS_TBY ? "yes" : "no");
1167 v4l2_info(sd, "\tFIFO service requested: %s\n",
1168 stats & STATS_TSR ? "yes" : "no");
1169 v4l2_info(sd, "\tFIFO service request interrupt: %s\n",
1170 irqen & IRQEN_TSE ? "enabled" : "disabled");
1171
1172 return 0;
1173}
1174
1175
1176const struct v4l2_subdev_ir_ops cx25840_ir_ops = {
1177 .rx_read = cx25840_ir_rx_read,
1178 .rx_g_parameters = cx25840_ir_rx_g_parameters,
1179 .rx_s_parameters = cx25840_ir_rx_s_parameters,
1180
1181 .tx_write = cx25840_ir_tx_write,
1182 .tx_g_parameters = cx25840_ir_tx_g_parameters,
1183 .tx_s_parameters = cx25840_ir_tx_s_parameters,
1184};
1185
1186
1187static const struct v4l2_subdev_ir_parameters default_rx_params = {
1188 .bytes_per_data_element = sizeof(union cx25840_ir_fifo_rec),
1189 .mode = V4L2_SUBDEV_IR_MODE_PULSE_WIDTH,
1190
1191 .enable = false,
1192 .interrupt_enable = false,
1193 .shutdown = true,
1194
1195 .modulation = true,
1196 .carrier_freq = 36000, /* 36 kHz - RC-5, and RC-6 carrier */
1197
1198 /* RC-5: 666,667 ns = 1/36 kHz * 32 cycles * 1 mark * 0.75 */
1199 /* RC-6: 333,333 ns = 1/36 kHz * 16 cycles * 1 mark * 0.75 */
1200 .noise_filter_min_width = 333333, /* ns */
1201 .carrier_range_lower = 35000,
1202 .carrier_range_upper = 37000,
1203 .invert_level = false,
1204};
1205
1206static const struct v4l2_subdev_ir_parameters default_tx_params = {
1207 .bytes_per_data_element = sizeof(union cx25840_ir_fifo_rec),
1208 .mode = V4L2_SUBDEV_IR_MODE_PULSE_WIDTH,
1209
1210 .enable = false,
1211 .interrupt_enable = false,
1212 .shutdown = true,
1213
1214 .modulation = true,
1215 .carrier_freq = 36000, /* 36 kHz - RC-5 carrier */
1216 .duty_cycle = 25, /* 25 % - RC-5 carrier */
1217 .invert_level = false,
1218 .invert_carrier_sense = false,
1219};
1220
1221int cx25840_ir_probe(struct v4l2_subdev *sd)
1222{
1223 struct cx25840_state *state = to_state(sd);
1224 struct cx25840_ir_state *ir_state;
1225 struct v4l2_subdev_ir_parameters default_params;
1226
1227 /* Only init the IR controller for the CX2388[57] AV Core for now */
1228 if (!(is_cx23885(state) || is_cx23887(state)))
1229 return 0;
1230
1231 ir_state = kzalloc(sizeof(struct cx25840_ir_state), GFP_KERNEL);
1232 if (ir_state == NULL)
1233 return -ENOMEM;
1234
1235 spin_lock_init(&ir_state->rx_kfifo_lock);
1236 if (kfifo_alloc(&ir_state->rx_kfifo,
1237 CX25840_IR_RX_KFIFO_SIZE, GFP_KERNEL)) {
1238 kfree(ir_state);
1239 return -ENOMEM;
1240 }
1241
1242 ir_state->c = state->c;
1243 state->ir_state = ir_state;
1244
1245 /* Ensure no interrupts arrive yet */
1246 if (is_cx23885(state) || is_cx23887(state))
1247 cx25840_write4(ir_state->c, CX25840_IR_IRQEN_REG, IRQEN_MSK);
1248 else
1249 cx25840_write4(ir_state->c, CX25840_IR_IRQEN_REG, 0);
1250
1251 mutex_init(&ir_state->rx_params_lock);
1252 memcpy(&default_params, &default_rx_params,
1253 sizeof(struct v4l2_subdev_ir_parameters));
1254 v4l2_subdev_call(sd, ir, rx_s_parameters, &default_params);
1255
1256 mutex_init(&ir_state->tx_params_lock);
1257 memcpy(&default_params, &default_tx_params,
1258 sizeof(struct v4l2_subdev_ir_parameters));
1259 v4l2_subdev_call(sd, ir, tx_s_parameters, &default_params);
1260
1261 return 0;
1262}
1263
1264int cx25840_ir_remove(struct v4l2_subdev *sd)
1265{
1266 struct cx25840_state *state = to_state(sd);
1267 struct cx25840_ir_state *ir_state = to_ir_state(sd);
1268
1269 if (ir_state == NULL)
1270 return -ENODEV;
1271
1272 cx25840_ir_rx_shutdown(sd);
1273 cx25840_ir_tx_shutdown(sd);
1274
1275 kfifo_free(&ir_state->rx_kfifo);
1276 kfree(ir_state);
1277 state->ir_state = NULL;
1278 return 0;
1279}
diff --git a/drivers/media/video/cx88/Kconfig b/drivers/media/video/cx88/Kconfig
index c7e5851d3486..99dbae117591 100644
--- a/drivers/media/video/cx88/Kconfig
+++ b/drivers/media/video/cx88/Kconfig
@@ -6,7 +6,7 @@ config VIDEO_CX88
6 select VIDEOBUF_DMA_SG 6 select VIDEOBUF_DMA_SG
7 select VIDEO_TUNER 7 select VIDEO_TUNER
8 select VIDEO_TVEEPROM 8 select VIDEO_TVEEPROM
9 select VIDEO_IR 9 depends on VIDEO_IR
10 select VIDEO_WM8775 if VIDEO_HELPER_CHIPS_AUTO 10 select VIDEO_WM8775 if VIDEO_HELPER_CHIPS_AUTO
11 ---help--- 11 ---help---
12 This is a video4linux driver for Conexant 2388x based 12 This is a video4linux driver for Conexant 2388x based
diff --git a/drivers/media/video/cx88/cx88-i2c.c b/drivers/media/video/cx88/cx88-i2c.c
index 375ad53f7961..82db555b22dd 100644
--- a/drivers/media/video/cx88/cx88-i2c.c
+++ b/drivers/media/video/cx88/cx88-i2c.c
@@ -193,24 +193,13 @@ void cx88_i2c_init_ir(struct cx88_core *core)
193 0x18, 0x6b, 0x71, 193 0x18, 0x6b, 0x71,
194 I2C_CLIENT_END 194 I2C_CLIENT_END
195 }; 195 };
196 const unsigned short *addrp;
197 196
198 memset(&info, 0, sizeof(struct i2c_board_info)); 197 memset(&info, 0, sizeof(struct i2c_board_info));
199 strlcpy(info.type, "ir_video", I2C_NAME_SIZE); 198 strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
200 /* 199 /* Use quick read command for probe, some IR chips don't
201 * We can't call i2c_new_probed_device() because it uses 200 * support writes */
202 * quick writes for probing and at least some R receiver 201 i2c_new_probed_device(&core->i2c_adap, &info, addr_list,
203 * devices only reply to reads. 202 i2c_probe_func_quick_read);
204 */
205 for (addrp = addr_list; *addrp != I2C_CLIENT_END; addrp++) {
206 if (i2c_smbus_xfer(&core->i2c_adap, *addrp, 0,
207 I2C_SMBUS_READ, 0,
208 I2C_SMBUS_QUICK, NULL) >= 0) {
209 info.addr = *addrp;
210 i2c_new_device(&core->i2c_adap, &info);
211 break;
212 }
213 }
214 } 203 }
215} 204}
216 205
diff --git a/drivers/media/video/em28xx/Kconfig b/drivers/media/video/em28xx/Kconfig
index c7be0e097828..66aefd6eef55 100644
--- a/drivers/media/video/em28xx/Kconfig
+++ b/drivers/media/video/em28xx/Kconfig
@@ -3,7 +3,7 @@ config VIDEO_EM28XX
3 depends on VIDEO_DEV && I2C && INPUT 3 depends on VIDEO_DEV && I2C && INPUT
4 select VIDEO_TUNER 4 select VIDEO_TUNER
5 select VIDEO_TVEEPROM 5 select VIDEO_TVEEPROM
6 select VIDEO_IR 6 depends on VIDEO_IR
7 select VIDEOBUF_VMALLOC 7 select VIDEOBUF_VMALLOC
8 select VIDEO_SAA711X if VIDEO_HELPER_CHIPS_AUTO 8 select VIDEO_SAA711X if VIDEO_HELPER_CHIPS_AUTO
9 select VIDEO_TVP5150 if VIDEO_HELPER_CHIPS_AUTO 9 select VIDEO_TVP5150 if VIDEO_HELPER_CHIPS_AUTO
diff --git a/drivers/media/video/em28xx/em28xx-cards.c b/drivers/media/video/em28xx/em28xx-cards.c
index ffbe544e30f4..e7efb4bffabd 100644
--- a/drivers/media/video/em28xx/em28xx-cards.c
+++ b/drivers/media/video/em28xx/em28xx-cards.c
@@ -2385,7 +2385,7 @@ void em28xx_register_i2c_ir(struct em28xx *dev)
2385 2385
2386 if (dev->init_data.name) 2386 if (dev->init_data.name)
2387 info.platform_data = &dev->init_data; 2387 info.platform_data = &dev->init_data;
2388 i2c_new_probed_device(&dev->i2c_adap, &info, addr_list); 2388 i2c_new_probed_device(&dev->i2c_adap, &info, addr_list, NULL);
2389} 2389}
2390 2390
2391void em28xx_card_setup(struct em28xx *dev) 2391void em28xx_card_setup(struct em28xx *dev)
diff --git a/drivers/media/video/fsl-viu.c b/drivers/media/video/fsl-viu.c
index 8f1c94f7e00c..43d208f1f586 100644
--- a/drivers/media/video/fsl-viu.c
+++ b/drivers/media/video/fsl-viu.c
@@ -1418,7 +1418,7 @@ static struct video_device viu_template = {
1418 .current_norm = V4L2_STD_NTSC_M, 1418 .current_norm = V4L2_STD_NTSC_M,
1419}; 1419};
1420 1420
1421static int __devinit viu_of_probe(struct of_device *op, 1421static int __devinit viu_of_probe(struct platform_device *op,
1422 const struct of_device_id *match) 1422 const struct of_device_id *match)
1423{ 1423{
1424 struct viu_dev *viu_dev; 1424 struct viu_dev *viu_dev;
@@ -1549,7 +1549,7 @@ err:
1549 return ret; 1549 return ret;
1550} 1550}
1551 1551
1552static int __devexit viu_of_remove(struct of_device *op) 1552static int __devexit viu_of_remove(struct platform_device *op)
1553{ 1553{
1554 struct v4l2_device *v4l2_dev = dev_get_drvdata(&op->dev); 1554 struct v4l2_device *v4l2_dev = dev_get_drvdata(&op->dev);
1555 struct viu_dev *dev = container_of(v4l2_dev, struct viu_dev, v4l2_dev); 1555 struct viu_dev *dev = container_of(v4l2_dev, struct viu_dev, v4l2_dev);
@@ -1570,7 +1570,7 @@ static int __devexit viu_of_remove(struct of_device *op)
1570} 1570}
1571 1571
1572#ifdef CONFIG_PM 1572#ifdef CONFIG_PM
1573static int viu_suspend(struct of_device *op, pm_message_t state) 1573static int viu_suspend(struct platform_device *op, pm_message_t state)
1574{ 1574{
1575 struct v4l2_device *v4l2_dev = dev_get_drvdata(&op->dev); 1575 struct v4l2_device *v4l2_dev = dev_get_drvdata(&op->dev);
1576 struct viu_dev *dev = container_of(v4l2_dev, struct viu_dev, v4l2_dev); 1576 struct viu_dev *dev = container_of(v4l2_dev, struct viu_dev, v4l2_dev);
@@ -1579,7 +1579,7 @@ static int viu_suspend(struct of_device *op, pm_message_t state)
1579 return 0; 1579 return 0;
1580} 1580}
1581 1581
1582static int viu_resume(struct of_device *op) 1582static int viu_resume(struct platform_device *op)
1583{ 1583{
1584 struct v4l2_device *v4l2_dev = dev_get_drvdata(&op->dev); 1584 struct v4l2_device *v4l2_dev = dev_get_drvdata(&op->dev);
1585 struct viu_dev *dev = container_of(v4l2_dev, struct viu_dev, v4l2_dev); 1585 struct viu_dev *dev = container_of(v4l2_dev, struct viu_dev, v4l2_dev);
diff --git a/drivers/media/video/gspca/gspca.c b/drivers/media/video/gspca/gspca.c
index d951b0f0e053..b9846106913e 100644
--- a/drivers/media/video/gspca/gspca.c
+++ b/drivers/media/video/gspca/gspca.c
@@ -55,7 +55,7 @@ MODULE_AUTHOR("Jean-François Moine <http://moinejf.free.fr>");
55MODULE_DESCRIPTION("GSPCA USB Camera Driver"); 55MODULE_DESCRIPTION("GSPCA USB Camera Driver");
56MODULE_LICENSE("GPL"); 56MODULE_LICENSE("GPL");
57 57
58#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 9, 0) 58#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 10, 0)
59 59
60#ifdef GSPCA_DEBUG 60#ifdef GSPCA_DEBUG
61int gspca_debug = D_ERR | D_PROBE; 61int gspca_debug = D_ERR | D_PROBE;
@@ -440,10 +440,15 @@ void gspca_frame_add(struct gspca_dev *gspca_dev,
440 frame->v4l2_buf.sequence = ++gspca_dev->sequence; 440 frame->v4l2_buf.sequence = ++gspca_dev->sequence;
441 gspca_dev->image = frame->data; 441 gspca_dev->image = frame->data;
442 gspca_dev->image_len = 0; 442 gspca_dev->image_len = 0;
443 } else if (gspca_dev->last_packet_type == DISCARD_PACKET) { 443 } else {
444 if (packet_type == LAST_PACKET) 444 switch (gspca_dev->last_packet_type) {
445 gspca_dev->last_packet_type = packet_type; 445 case DISCARD_PACKET:
446 return; 446 if (packet_type == LAST_PACKET)
447 gspca_dev->last_packet_type = packet_type;
448 return;
449 case LAST_PACKET:
450 return;
451 }
447 } 452 }
448 453
449 /* append the packet to the frame buffer */ 454 /* append the packet to the frame buffer */
@@ -454,6 +459,12 @@ void gspca_frame_add(struct gspca_dev *gspca_dev,
454 gspca_dev->frsz); 459 gspca_dev->frsz);
455 packet_type = DISCARD_PACKET; 460 packet_type = DISCARD_PACKET;
456 } else { 461 } else {
462/* !! image is NULL only when last pkt is LAST or DISCARD
463 if (gspca_dev->image == NULL) {
464 err("gspca_frame_add() image == NULL");
465 return;
466 }
467 */
457 memcpy(gspca_dev->image + gspca_dev->image_len, 468 memcpy(gspca_dev->image + gspca_dev->image_len,
458 data, len); 469 data, len);
459 gspca_dev->image_len += len; 470 gspca_dev->image_len += len;
diff --git a/drivers/media/video/gspca/sonixj.c b/drivers/media/video/gspca/sonixj.c
index ee17b034bf6b..370544361be2 100644
--- a/drivers/media/video/gspca/sonixj.c
+++ b/drivers/media/video/gspca/sonixj.c
@@ -66,7 +66,11 @@ struct sd {
66#define BRIDGE_SN9C110 2 66#define BRIDGE_SN9C110 2
67#define BRIDGE_SN9C120 3 67#define BRIDGE_SN9C120 3
68 u8 sensor; /* Type of image sensor chip */ 68 u8 sensor; /* Type of image sensor chip */
69enum { 69 u8 i2c_addr;
70
71 u8 jpeg_hdr[JPEG_HDR_SZ];
72};
73enum sensors {
70 SENSOR_ADCM1700, 74 SENSOR_ADCM1700,
71 SENSOR_GC0307, 75 SENSOR_GC0307,
72 SENSOR_HV7131R, 76 SENSOR_HV7131R,
@@ -81,10 +85,6 @@ enum {
81 SENSOR_PO2030N, 85 SENSOR_PO2030N,
82 SENSOR_SOI768, 86 SENSOR_SOI768,
83 SENSOR_SP80708, 87 SENSOR_SP80708,
84} sensors;
85 u8 i2c_addr;
86
87 u8 jpeg_hdr[JPEG_HDR_SZ];
88}; 88};
89 89
90/* V4L2 controls supported by the driver */ 90/* V4L2 controls supported by the driver */
diff --git a/drivers/media/video/gspca/sq930x.c b/drivers/media/video/gspca/sq930x.c
index 37cee5e063cf..7ae6522d4edf 100644
--- a/drivers/media/video/gspca/sq930x.c
+++ b/drivers/media/video/gspca/sq930x.c
@@ -23,7 +23,6 @@
23#define MODULE_NAME "sq930x" 23#define MODULE_NAME "sq930x"
24 24
25#include "gspca.h" 25#include "gspca.h"
26#include "jpeg.h"
27 26
28MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>\n" 27MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>\n"
29 "Gerard Klaver <gerard at gkall dot hobby dot nl\n" 28 "Gerard Klaver <gerard at gkall dot hobby dot nl\n"
@@ -31,8 +30,6 @@ MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>\n"
31MODULE_DESCRIPTION("GSPCA/SQ930x USB Camera Driver"); 30MODULE_DESCRIPTION("GSPCA/SQ930x USB Camera Driver");
32MODULE_LICENSE("GPL"); 31MODULE_LICENSE("GPL");
33 32
34#define BULK_TRANSFER_LEN 5128
35
36/* Structure to hold all of our device specific stuff */ 33/* Structure to hold all of our device specific stuff */
37struct sd { 34struct sd {
38 struct gspca_dev gspca_dev; /* !! must be the first item */ 35 struct gspca_dev gspca_dev; /* !! must be the first item */
@@ -40,28 +37,20 @@ struct sd {
40 u16 expo; 37 u16 expo;
41 u8 gain; 38 u8 gain;
42 39
43 u8 quality; /* webcam quality 0..3 */
44#define QUALITY_DEF 1
45
46 u8 gpio[2];
47
48 u8 eof_len;
49 u8 do_ctrl; 40 u8 do_ctrl;
50 41 u8 gpio[2];
51 u8 sensor; 42 u8 sensor;
52enum { 43 u8 type;
44#define Generic 0
45#define Creative_live_motion 1
46};
47enum sensors {
53 SENSOR_ICX098BQ, 48 SENSOR_ICX098BQ,
54 SENSOR_LZ24BP, 49 SENSOR_LZ24BP,
55 SENSOR_MI0360, 50 SENSOR_MI0360,
56 SENSOR_MT9V111, 51 SENSOR_MT9V111, /* = MI360SOC */
57 SENSOR_OV7660, 52 SENSOR_OV7660,
58 SENSOR_OV9630, 53 SENSOR_OV9630,
59} sensors;
60 u8 type;
61#define Generic 0
62#define Creative_live_motion 1
63
64 u8 jpeg_hdr[JPEG_HDR_SZ];
65}; 54};
66 55
67static int sd_setexpo(struct gspca_dev *gspca_dev, __s32 val); 56static int sd_setexpo(struct gspca_dev *gspca_dev, __s32 val);
@@ -78,7 +67,7 @@ static const struct ctrl sd_ctrls[] = {
78 .minimum = 0x0001, 67 .minimum = 0x0001,
79 .maximum = 0x0fff, 68 .maximum = 0x0fff,
80 .step = 1, 69 .step = 1,
81#define EXPO_DEF 0x027d 70#define EXPO_DEF 0x0356
82 .default_value = EXPO_DEF, 71 .default_value = EXPO_DEF,
83 }, 72 },
84 .set = sd_setexpo, 73 .set = sd_setexpo,
@@ -92,7 +81,7 @@ static const struct ctrl sd_ctrls[] = {
92 .minimum = 0x01, 81 .minimum = 0x01,
93 .maximum = 0xff, 82 .maximum = 0xff,
94 .step = 1, 83 .step = 1,
95#define GAIN_DEF 0x61 84#define GAIN_DEF 0x8d
96 .default_value = GAIN_DEF, 85 .default_value = GAIN_DEF,
97 }, 86 },
98 .set = sd_setgain, 87 .set = sd_setgain,
@@ -101,30 +90,18 @@ static const struct ctrl sd_ctrls[] = {
101}; 90};
102 91
103static struct v4l2_pix_format vga_mode[] = { 92static struct v4l2_pix_format vga_mode[] = {
104 {160, 120, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, 93 {320, 240, V4L2_PIX_FMT_SRGGB8, V4L2_FIELD_NONE,
105 .bytesperline = 160,
106 .sizeimage = 160 * 120 * 5 / 8 + 590,
107 .colorspace = V4L2_COLORSPACE_JPEG,
108 .priv = 0},
109 {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
110 .bytesperline = 320, 94 .bytesperline = 320,
111 .sizeimage = 320 * 240 * 4 / 8 + 590, 95 .sizeimage = 320 * 240,
112 .colorspace = V4L2_COLORSPACE_JPEG, 96 .colorspace = V4L2_COLORSPACE_SRGB,
113 .priv = 1}, 97 .priv = 0},
114 {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, 98 {640, 480, V4L2_PIX_FMT_SRGGB8, V4L2_FIELD_NONE,
115 .bytesperline = 640, 99 .bytesperline = 640,
116 .sizeimage = 640 * 480 * 3 / 8 + 590, 100 .sizeimage = 640 * 480,
117 .colorspace = V4L2_COLORSPACE_JPEG, 101 .colorspace = V4L2_COLORSPACE_SRGB,
118 .priv = 2}, 102 .priv = 1},
119}; 103};
120 104
121/* JPEG quality indexed by webcam quality */
122#define QUAL_0 90
123#define QUAL_1 85
124#define QUAL_2 75
125#define QUAL_3 70
126static const u8 quality_tb[4] = { QUAL_0, QUAL_1, QUAL_2, QUAL_3 };
127
128/* sq930x registers */ 105/* sq930x registers */
129#define SQ930_CTRL_UCBUS_IO 0x0001 106#define SQ930_CTRL_UCBUS_IO 0x0001
130#define SQ930_CTRL_I2C_IO 0x0002 107#define SQ930_CTRL_I2C_IO 0x0002
@@ -302,7 +279,7 @@ static const struct i2c_write_cmd mt9v111_init_0[] = {
302 {0x01, 0x0001}, /* select IFP/SOC registers */ 279 {0x01, 0x0001}, /* select IFP/SOC registers */
303 {0x06, 0x300c}, /* operating mode control */ 280 {0x06, 0x300c}, /* operating mode control */
304 {0x08, 0xcc00}, /* output format control (RGB) */ 281 {0x08, 0xcc00}, /* output format control (RGB) */
305 {0x01, 0x0004}, /* select core registers */ 282 {0x01, 0x0004}, /* select sensor core registers */
306}; 283};
307static const struct i2c_write_cmd mt9v111_init_1[] = { 284static const struct i2c_write_cmd mt9v111_init_1[] = {
308 {0x03, 0x01e5}, /* window height */ 285 {0x03, 0x01e5}, /* window height */
@@ -330,7 +307,8 @@ static const struct i2c_write_cmd mt9v111_init_3[] = {
330 {0x62, 0x0405}, 307 {0x62, 0x0405},
331}; 308};
332static const struct i2c_write_cmd mt9v111_init_4[] = { 309static const struct i2c_write_cmd mt9v111_init_4[] = {
333 {0x05, 0x00ce}, /* horizontal blanking */ 310/* {0x05, 0x00ce}, */
311 {0x05, 0x005d}, /* horizontal blanking */
334}; 312};
335 313
336static const struct ucbus_write_cmd ov7660_start_0[] = { 314static const struct ucbus_write_cmd ov7660_start_0[] = {
@@ -343,78 +321,58 @@ static const struct ucbus_write_cmd ov9630_start_0[] = {
343 {0xf334, 0x3e}, {0xf335, 0xf8}, {0xf33f, 0x03} 321 {0xf334, 0x3e}, {0xf335, 0xf8}, {0xf33f, 0x03}
344}; 322};
345 323
324/* start parameters indexed by [sensor][mode] */
346static const struct cap_s { 325static const struct cap_s {
347 u8 cc_sizeid; 326 u8 cc_sizeid;
348 u8 cc_bytes[32]; 327 u8 cc_bytes[32];
349} capconfig[4][3] = { 328} capconfig[4][2] = {
350 [SENSOR_ICX098BQ] = { 329 [SENSOR_ICX098BQ] = {
351 {0, /* JPEG, 160x120 */ 330 {2, /* Bayer 320x240 */
331 {0x05, 0x1f, 0x20, 0x0e, 0x00, 0x9f, 0x02, 0xee,
332 0x01, 0x01, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
333 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0,
334 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} },
335 {4, /* Bayer 640x480 */
352 {0x01, 0x1f, 0x20, 0x0e, 0x00, 0x9f, 0x02, 0xee, 336 {0x01, 0x1f, 0x20, 0x0e, 0x00, 0x9f, 0x02, 0xee,
353 0x01, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8, 337 0x01, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
354 0x02, 0x8b, 0x00, 0x8b, 0x00, 0x41, 0x01, 0x41, 338 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
355 0x01, 0x41, 0x01, 0x05, 0x40, 0x01, 0xf0, 0x00} }, 339 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} },
356 {2, /* JPEG, 320x240 */
357 {0x01, 0x1f, 0x20, 0x0e, 0x00, 0x9f, 0x02, 0xee,
358 0x01, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
359 0x02, 0xdf, 0x01, 0x00, 0x00, 0x3f, 0x01, 0x3f,
360 0x01, 0x00, 0x00, 0x05, 0x40, 0x01, 0xf0, 0x00} },
361 {4, /* JPEG, 640x480 */
362 {0x01, 0x22, 0x20, 0x0e, 0x00, 0xa2, 0x02, 0xf0,
363 0x01, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
364 0x07, 0xe1, 0x01, 0xe1, 0x01, 0x3f, 0x01, 0x3f,
365 0x01, 0x3f, 0x01, 0x05, 0x80, 0x02, 0xe0, 0x01} },
366 }, 340 },
367 [SENSOR_LZ24BP] = { 341 [SENSOR_LZ24BP] = {
368 {0, /* JPEG, 160x120 */ 342 {2, /* Bayer 320x240 */
369 {0x01, 0x1f, 0x20, 0x0e, 0x00, 0x9f, 0x02, 0xee, 343 {0x05, 0x22, 0x20, 0x0e, 0x00, 0xa2, 0x02, 0xee,
370 0x01, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8, 344 0x01, 0x01, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
371 0x02, 0x8b, 0x00, 0x8b, 0x00, 0x41, 0x01, 0x41, 345 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
372 0x01, 0x41, 0x01, 0x05, 0x40, 0x01, 0xf0, 0x00} }, 346 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} },
373 {2, /* JPEG, 320x240 */ 347 {4, /* Bayer 640x480 */
374 {0x01, 0x22, 0x20, 0x0e, 0x00, 0xa2, 0x02, 0xee, 348 {0x01, 0x22, 0x20, 0x0e, 0x00, 0xa2, 0x02, 0xee,
375 0x01, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8, 349 0x01, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
376 0x02, 0xdf, 0x01, 0x00, 0x00, 0x3f, 0x01, 0x3f, 350 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
377 0x01, 0x00, 0x00, 0x05, 0x40, 0x01, 0xf0, 0x00} }, 351 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} },
378 {4, /* JPEG, 640x480 */
379 {0x01, 0x22, 0x20, 0x0e, 0x00, 0xa2, 0x02, 0xf0,
380 0x01, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
381 0x07, 0xe1, 0x01, 0xe1, 0x01, 0x3f, 0x01, 0x3f,
382 0x01, 0x3f, 0x01, 0x05, 0x80, 0x02, 0xe0, 0x01} },
383 }, 352 },
384 [SENSOR_MI0360] = { 353 [SENSOR_MI0360] = {
385 {0, /* JPEG, 160x120 */ 354 {2, /* Bayer 320x240 */
386 {0x05, 0x3d, 0x20, 0x0b, 0x00, 0xbd, 0x02, 0x0b, 355 {0x05, 0x02, 0x20, 0x01, 0x20, 0x82, 0x02, 0xe1,
387 0x02, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8, 356 0x01, 0x01, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
388 0x02, 0x01, 0x01, 0x01, 0x01, 0x9f, 0x00, 0x9f, 357 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
389 0x00, 0x9f, 0x01, 0x05, 0xa0, 0x00, 0x80, 0x00} }, 358 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} },
390 {2, /* JPEG, 320x240 */ 359 {4, /* Bayer 640x480 */
391 {0x01, 0x02, 0x20, 0x01, 0x20, 0x82, 0x02, 0xe1, 360 {0x01, 0x02, 0x20, 0x01, 0x20, 0x82, 0x02, 0xe1,
392/*fixme 03 e3 */
393 0x01, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8, 361 0x01, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
394 0x02, 0xdf, 0x01, 0x00, 0x00, 0x3f, 0x01, 0x3f, 362 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
395 0x01, 0x00, 0x00, 0x05, 0x40, 0x01, 0xf0, 0x00} }, 363 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} },
396 {4, /* JPEG, 640x480 */
397 {0x01, 0x02, 0x20, 0x01, 0x20, 0x82, 0x02, 0xe3,
398 0x01, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
399 0x07, 0xe1, 0x01, 0xe1, 0x01, 0x3f, 0x01, 0x3f,
400 0x01, 0x3f, 0x01, 0x05, 0x80, 0x02, 0xe0, 0x01} },
401 }, 364 },
402 [SENSOR_MT9V111] = { 365 [SENSOR_MT9V111] = {
403 {0, /* JPEG, 160x120 */ 366 {2, /* Bayer 320x240 */
404 {0x05, 0x3d, 0x20, 0x0b, 0x00, 0xbd, 0x02, 0x0b, 367 {0x05, 0x02, 0x20, 0x01, 0x20, 0x82, 0x02, 0xe1,
405 0x02, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8, 368 0x01, 0x01, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
406 0x02, 0x01, 0x01, 0x01, 0x01, 0x9f, 0x00, 0x9f, 369 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
407 0x00, 0x9f, 0x01, 0x05, 0xa0, 0x00, 0x80, 0x00} }, 370 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} },
408 {2, /* JPEG, 320x240 */ 371 {4, /* Bayer 640x480 */
409 {0x01, 0x02, 0x20, 0x03, 0x20, 0x82, 0x02, 0xe3, 372 {0x01, 0x02, 0x20, 0x01, 0x20, 0x82, 0x02, 0xe1,
410 0x01, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
411 0x02, 0xdf, 0x01, 0x00, 0x00, 0x3f, 0x01, 0x3f,
412 0x01, 0x00, 0x00, 0x05, 0x40, 0x01, 0xf0, 0x00} },
413 {4, /* JPEG, 640x480 */
414 {0x01, 0x02, 0x20, 0x03, 0x20, 0x82, 0x02, 0xe3,
415 0x01, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8, 373 0x01, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
416 0x07, 0xe1, 0x01, 0xe1, 0x01, 0x3f, 0x01, 0x3f, 374 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
417 0x01, 0x3f, 0x01, 0x05, 0x80, 0x02, 0xe0, 0x01} }, 375 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} },
418 }, 376 },
419}; 377};
420 378
@@ -864,7 +822,7 @@ static void setexposure(struct gspca_dev *gspca_dev)
864 buf[i++] = 0x35; /* reg = global gain */ 822 buf[i++] = 0x35; /* reg = global gain */
865 buf[i++] = 0x00; /* val H */ 823 buf[i++] = 0x00; /* val H */
866 buf[i++] = sensor->i2c_dum; 824 buf[i++] = sensor->i2c_dum;
867 buf[i++] = sd->gain; /* val L */ 825 buf[i++] = 0x80 + sd->gain / 2; /* val L */
868 buf[i++] = 0x00; 826 buf[i++] = 0x00;
869 buf[i++] = 0x00; 827 buf[i++] = 0x00;
870 buf[i++] = 0x00; 828 buf[i++] = 0x00;
@@ -889,10 +847,7 @@ static int sd_config(struct gspca_dev *gspca_dev,
889 cam->nmodes = ARRAY_SIZE(vga_mode); 847 cam->nmodes = ARRAY_SIZE(vga_mode);
890 848
891 cam->bulk = 1; 849 cam->bulk = 1;
892 cam->bulk_size = BULK_TRANSFER_LEN;
893/* cam->bulk_nurbs = 2; fixme: if no setexpo sync */
894 850
895 sd->quality = QUALITY_DEF;
896 sd->gain = GAIN_DEF; 851 sd->gain = GAIN_DEF;
897 sd->expo = EXPO_DEF; 852 sd->expo = EXPO_DEF;
898 853
@@ -945,13 +900,10 @@ static int sd_init(struct gspca_dev *gspca_dev)
945 if (sd->sensor == SENSOR_MI0360) { 900 if (sd->sensor == SENSOR_MI0360) {
946 901
947 /* no sensor probe for icam tracer */ 902 /* no sensor probe for icam tracer */
948 if (gspca_dev->usb_buf[5] == 0xf6) { /* if CMOS */ 903 if (gspca_dev->usb_buf[5] == 0xf6) /* if CMOS */
949 sd->sensor = SENSOR_ICX098BQ; 904 sd->sensor = SENSOR_ICX098BQ;
950 gspca_dev->cam.cam_mode = &vga_mode[1]; 905 else
951 gspca_dev->cam.nmodes = 1; /* only 320x240 */
952 } else {
953 cmos_probe(gspca_dev); 906 cmos_probe(gspca_dev);
954 }
955 } 907 }
956 908
957 PDEBUG(D_PROBE, "Sensor %s", sensor_tb[sd->sensor].name); 909 PDEBUG(D_PROBE, "Sensor %s", sensor_tb[sd->sensor].name);
@@ -960,51 +912,24 @@ static int sd_init(struct gspca_dev *gspca_dev)
960 return gspca_dev->usb_err; 912 return gspca_dev->usb_err;
961} 913}
962 914
963/* special function to create the quantization tables of the JPEG header */
964static void sd_jpeg_set_qual(u8 *jpeg_hdr,
965 int quality)
966{
967 int i, sc1, sc2;
968
969 quality = quality_tb[quality]; /* convert to JPEG quality */
970/*
971 * approximative qualities for Y and U/V:
972 * quant = 0:94%/91% 1:91%/87% 2:82%/73% 3:69%/56%
973 * should have:
974 * quant = 0:94%/91% 1:91%/87.5% 2:81.5%/72% 3:69%/54.5%
975 */
976 sc1 = 200 - quality * 2;
977 quality = quality * 7 / 5 - 40; /* UV quality */
978 sc2 = 200 - quality * 2;
979 for (i = 0; i < 64; i++) {
980 jpeg_hdr[JPEG_QT0_OFFSET + i] =
981 (jpeg_head[JPEG_QT0_OFFSET + i] * sc1 + 50) / 100;
982 jpeg_hdr[JPEG_QT1_OFFSET + i] =
983 (jpeg_head[JPEG_QT1_OFFSET + i] * sc2 + 50) / 100;
984 }
985}
986
987/* send the start/stop commands to the webcam */ 915/* send the start/stop commands to the webcam */
988static void send_start(struct gspca_dev *gspca_dev) 916static void send_start(struct gspca_dev *gspca_dev)
989{ 917{
990 struct sd *sd = (struct sd *) gspca_dev; 918 struct sd *sd = (struct sd *) gspca_dev;
991 const struct cap_s *cap; 919 const struct cap_s *cap;
992 int mode, quality; 920 int mode;
993 921
994 mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv; 922 mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
995 cap = &capconfig[sd->sensor][mode]; 923 cap = &capconfig[sd->sensor][mode];
996 quality = sd->quality; 924 reg_wb(gspca_dev, 0x0900 | SQ930_CTRL_CAP_START,
997 reg_wb(gspca_dev, (quality << 12) 925 0x0a00 | cap->cc_sizeid,
998 | 0x0a00 /* 900 for Bayer */
999 | SQ930_CTRL_CAP_START,
1000 0x0500 /* a00 for Bayer */
1001 | cap->cc_sizeid,
1002 cap->cc_bytes, 32); 926 cap->cc_bytes, 32);
1003}; 927}
928
1004static void send_stop(struct gspca_dev *gspca_dev) 929static void send_stop(struct gspca_dev *gspca_dev)
1005{ 930{
1006 reg_w(gspca_dev, SQ930_CTRL_CAP_STOP, 0); 931 reg_w(gspca_dev, SQ930_CTRL_CAP_STOP, 0);
1007}; 932}
1008 933
1009/* function called at start time before URB creation */ 934/* function called at start time before URB creation */
1010static int sd_isoc_init(struct gspca_dev *gspca_dev) 935static int sd_isoc_init(struct gspca_dev *gspca_dev)
@@ -1013,6 +938,7 @@ static int sd_isoc_init(struct gspca_dev *gspca_dev)
1013 938
1014 gspca_dev->cam.bulk_nurbs = 1; /* there must be one URB only */ 939 gspca_dev->cam.bulk_nurbs = 1; /* there must be one URB only */
1015 sd->do_ctrl = 0; 940 sd->do_ctrl = 0;
941 gspca_dev->cam.bulk_size = gspca_dev->width * gspca_dev->height + 8;
1016 return 0; 942 return 0;
1017} 943}
1018 944
@@ -1022,11 +948,6 @@ static int sd_start(struct gspca_dev *gspca_dev)
1022 struct sd *sd = (struct sd *) gspca_dev; 948 struct sd *sd = (struct sd *) gspca_dev;
1023 int mode; 949 int mode;
1024 950
1025 /* initialize the JPEG header */
1026 jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
1027 0x21); /* JPEG 422 */
1028 sd_jpeg_set_qual(sd->jpeg_hdr, sd->quality);
1029
1030 bridge_init(sd); 951 bridge_init(sd);
1031 global_init(sd, 0); 952 global_init(sd, 0);
1032 msleep(100); 953 msleep(100);
@@ -1071,7 +992,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
1071 ARRAY_SIZE(lz24bp_start_2), 992 ARRAY_SIZE(lz24bp_start_2),
1072 6); 993 6);
1073 mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv; 994 mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
1074 lz24bp_ppl(sd, mode == 2 ? 0x0564 : 0x0310); 995 lz24bp_ppl(sd, mode == 1 ? 0x0564 : 0x0310);
1075 msleep(10); 996 msleep(10);
1076 break; 997 break;
1077 case SENSOR_MI0360: 998 case SENSOR_MI0360:
@@ -1095,7 +1016,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
1095 /* 1st start */ 1016 /* 1st start */
1096 send_start(gspca_dev); 1017 send_start(gspca_dev);
1097 msleep(60); 1018 msleep(60);
1098 reg_w(gspca_dev, SQ930_CTRL_CAP_STOP, 0x0000); 1019 send_stop(gspca_dev);
1099 1020
1100 i2c_write(sd, 1021 i2c_write(sd,
1101 mi0360_start_4, ARRAY_SIZE(mi0360_start_4)); 1022 mi0360_start_4, ARRAY_SIZE(mi0360_start_4));
@@ -1113,7 +1034,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
1113 ARRAY_SIZE(mt9v111_init_2)); 1034 ARRAY_SIZE(mt9v111_init_2));
1114 ucbus_write(gspca_dev, mt9v111_start_1, 1035 ucbus_write(gspca_dev, mt9v111_start_1,
1115 ARRAY_SIZE(mt9v111_start_1), 1036 ARRAY_SIZE(mt9v111_start_1),
1116 8); 1037 5);
1117 i2c_write(sd, mt9v111_init_3, 1038 i2c_write(sd, mt9v111_init_3,
1118 ARRAY_SIZE(mt9v111_init_3)); 1039 ARRAY_SIZE(mt9v111_init_3));
1119 i2c_write(sd, mt9v111_init_4, 1040 i2c_write(sd, mt9v111_init_4,
@@ -1125,8 +1046,6 @@ static int sd_start(struct gspca_dev *gspca_dev)
1125out: 1046out:
1126 msleep(1000); 1047 msleep(1000);
1127 1048
1128 sd->eof_len = 0; /* init packet scan */
1129
1130 if (sd->sensor == SENSOR_MT9V111) 1049 if (sd->sensor == SENSOR_MT9V111)
1131 gpio_set(sd, SQ930_GPIO_DFL_LED, SQ930_GPIO_DFL_LED); 1050 gpio_set(sd, SQ930_GPIO_DFL_LED, SQ930_GPIO_DFL_LED);
1132 1051
@@ -1166,94 +1085,17 @@ static void sd_dq_callback(struct gspca_dev *gspca_dev)
1166 msleep(100); 1085 msleep(100);
1167} 1086}
1168 1087
1169/* move a packet adding 0x00 after 0xff */
1170static void add_packet(struct gspca_dev *gspca_dev,
1171 u8 *data,
1172 int len)
1173{
1174 int i;
1175
1176 i = 0;
1177 do {
1178 if (data[i] == 0xff) {
1179 gspca_frame_add(gspca_dev, INTER_PACKET,
1180 data, i + 1);
1181 len -= i;
1182 data += i;
1183 *data = 0x00;
1184 i = 0;
1185 }
1186 } while (++i < len);
1187 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
1188}
1189
1190/* end a frame and start a new one */
1191static void eof_sof(struct gspca_dev *gspca_dev)
1192{
1193 struct sd *sd = (struct sd *) gspca_dev;
1194 static const u8 ffd9[] = {0xff, 0xd9};
1195
1196 /* if control set, stop bulk transfer */
1197 if (sd->do_ctrl
1198 && gspca_dev->last_packet_type == INTER_PACKET)
1199 gspca_dev->cam.bulk_nurbs = 0;
1200 gspca_frame_add(gspca_dev, LAST_PACKET,
1201 ffd9, 2);
1202 gspca_frame_add(gspca_dev, FIRST_PACKET,
1203 sd->jpeg_hdr, JPEG_HDR_SZ);
1204}
1205
1206static void sd_pkt_scan(struct gspca_dev *gspca_dev, 1088static void sd_pkt_scan(struct gspca_dev *gspca_dev,
1207 u8 *data, /* isoc packet */ 1089 u8 *data, /* isoc packet */
1208 int len) /* iso packet length */ 1090 int len) /* iso packet length */
1209{ 1091{
1210 struct sd *sd = (struct sd *) gspca_dev; 1092 struct sd *sd = (struct sd *) gspca_dev;
1211 u8 *p; 1093
1212 int l; 1094 if (sd->do_ctrl)
1213 1095 gspca_dev->cam.bulk_nurbs = 0;
1214 len -= 8; /* ignore last 8 bytes (00 00 55 aa 55 aa 00 00) */ 1096 gspca_frame_add(gspca_dev, FIRST_PACKET, NULL, 0);
1215 1097 gspca_frame_add(gspca_dev, INTER_PACKET, data, len - 8);
1216 /* 1098 gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0);
1217 * the end/start of frame is indicated by
1218 * 0x00 * 16 - 0xab * 8
1219 * aligned on 8 bytes boundary
1220 */
1221 if (sd->eof_len != 0) { /* if 'abababab' in previous pkt */
1222 if (*((u32 *) data) == 0xabababab) {
1223 /*fixme: should remove previous 0000ababab*/
1224 eof_sof(gspca_dev);
1225 data += 4;
1226 len -= 4;
1227 }
1228 sd->eof_len = 0;
1229 }
1230 p = data;
1231 l = len;
1232 for (;;) {
1233 if (*((u32 *) p) == 0xabababab) {
1234 if (l < 8) { /* (may be 4 only) */
1235 sd->eof_len = 1;
1236 break;
1237 }
1238 if (*((u32 *) p + 1) == 0xabababab) {
1239 add_packet(gspca_dev, data, p - data - 16);
1240 /* remove previous zeros */
1241 eof_sof(gspca_dev);
1242 p += 8;
1243 l -= 8;
1244 if (l <= 0)
1245 return;
1246 len = l;
1247 data = p;
1248 continue;
1249 }
1250 }
1251 p += 4;
1252 l -= 4;
1253 if (l <= 0)
1254 break;
1255 }
1256 add_packet(gspca_dev, data, len);
1257} 1099}
1258 1100
1259static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val) 1101static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val)
@@ -1291,45 +1133,6 @@ static int sd_getexpo(struct gspca_dev *gspca_dev, __s32 *val)
1291 return 0; 1133 return 0;
1292} 1134}
1293 1135
1294static int sd_set_jcomp(struct gspca_dev *gspca_dev,
1295 struct v4l2_jpegcompression *jcomp)
1296{
1297 struct sd *sd = (struct sd *) gspca_dev;
1298 int quality;
1299
1300 if (jcomp->quality >= (QUAL_0 + QUAL_1) / 2)
1301 quality = 0;
1302 else if (jcomp->quality >= (QUAL_1 + QUAL_2) / 2)
1303 quality = 1;
1304 else if (jcomp->quality >= (QUAL_2 + QUAL_3) / 2)
1305 quality = 2;
1306 else
1307 quality = 3;
1308
1309 if (quality != sd->quality) {
1310 sd->quality = quality;
1311 if (gspca_dev->streaming) {
1312 send_stop(gspca_dev);
1313 sd_jpeg_set_qual(sd->jpeg_hdr, sd->quality);
1314 msleep(70);
1315 send_start(gspca_dev);
1316 }
1317 }
1318 return gspca_dev->usb_err;
1319}
1320
1321static int sd_get_jcomp(struct gspca_dev *gspca_dev,
1322 struct v4l2_jpegcompression *jcomp)
1323{
1324 struct sd *sd = (struct sd *) gspca_dev;
1325
1326 memset(jcomp, 0, sizeof *jcomp);
1327 jcomp->quality = quality_tb[sd->quality];
1328 jcomp->jpeg_markers = V4L2_JPEG_MARKER_DHT
1329 | V4L2_JPEG_MARKER_DQT;
1330 return 0;
1331}
1332
1333/* sub-driver description */ 1136/* sub-driver description */
1334static const struct sd_desc sd_desc = { 1137static const struct sd_desc sd_desc = {
1335 .name = MODULE_NAME, 1138 .name = MODULE_NAME,
@@ -1342,8 +1145,6 @@ static const struct sd_desc sd_desc = {
1342 .stopN = sd_stopN, 1145 .stopN = sd_stopN,
1343 .pkt_scan = sd_pkt_scan, 1146 .pkt_scan = sd_pkt_scan,
1344 .dq_callback = sd_dq_callback, 1147 .dq_callback = sd_dq_callback,
1345 .get_jcomp = sd_get_jcomp,
1346 .set_jcomp = sd_set_jcomp,
1347}; 1148};
1348 1149
1349/* Table of supported USB devices */ 1150/* Table of supported USB devices */
diff --git a/drivers/media/video/gspca/t613.c b/drivers/media/video/gspca/t613.c
index 2a0f12d55e48..3b3b983f2b9d 100644
--- a/drivers/media/video/gspca/t613.c
+++ b/drivers/media/video/gspca/t613.c
@@ -55,12 +55,12 @@ struct sd {
55 u8 effect; 55 u8 effect;
56 56
57 u8 sensor; 57 u8 sensor;
58enum { 58};
59enum sensors {
59 SENSOR_OM6802, 60 SENSOR_OM6802,
60 SENSOR_OTHER, 61 SENSOR_OTHER,
61 SENSOR_TAS5130A, 62 SENSOR_TAS5130A,
62 SENSOR_LT168G, /* must verify if this is the actual model */ 63 SENSOR_LT168G, /* must verify if this is the actual model */
63} sensors;
64}; 64};
65 65
66/* V4L2 controls supported by the driver */ 66/* V4L2 controls supported by the driver */
diff --git a/drivers/media/video/gspca/vc032x.c b/drivers/media/video/gspca/vc032x.c
index 031266a4081b..b16fd47e8ced 100644
--- a/drivers/media/video/gspca/vc032x.c
+++ b/drivers/media/video/gspca/vc032x.c
@@ -39,6 +39,10 @@ struct sd {
39 u8 vflip; 39 u8 vflip;
40 u8 lightfreq; 40 u8 lightfreq;
41 s8 sharpness; 41 s8 sharpness;
42 u16 exposure;
43 u8 gain;
44 u8 autogain;
45 u8 backlight;
42 46
43 u8 image_offset; 47 u8 image_offset;
44 48
@@ -77,6 +81,14 @@ static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val);
77static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val); 81static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val);
78static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val); 82static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val);
79static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val); 83static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val);
84static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val);
85static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val);
86static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val);
87static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val);
88static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
89static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);
90static int sd_setbacklight(struct gspca_dev *gspca_dev, __s32 val);
91static int sd_getbacklight(struct gspca_dev *gspca_dev, __s32 *val);
80 92
81static const struct ctrl sd_ctrls[] = { 93static const struct ctrl sd_ctrls[] = {
82#define BRIGHTNESS_IDX 0 94#define BRIGHTNESS_IDX 0
@@ -185,6 +197,66 @@ static const struct ctrl sd_ctrls[] = {
185 .set = sd_setsharpness, 197 .set = sd_setsharpness,
186 .get = sd_getsharpness, 198 .get = sd_getsharpness,
187 }, 199 },
200#define GAIN_IDX 7
201 {
202 {
203 .id = V4L2_CID_GAIN,
204 .type = V4L2_CTRL_TYPE_INTEGER,
205 .name = "Gain",
206 .minimum = 0,
207 .maximum = 78,
208 .step = 1,
209#define GAIN_DEF 0
210 .default_value = GAIN_DEF,
211 },
212 .set = sd_setgain,
213 .get = sd_getgain,
214 },
215#define EXPOSURE_IDX 8
216 {
217 {
218 .id = V4L2_CID_EXPOSURE,
219 .type = V4L2_CTRL_TYPE_INTEGER,
220 .name = "Exposure",
221#define EXPOSURE_DEF 450
222 .minimum = 0,
223 .maximum = 4095,
224 .step = 1,
225 .default_value = EXPOSURE_DEF,
226 },
227 .set = sd_setexposure,
228 .get = sd_getexposure,
229 },
230#define AUTOGAIN_IDX 9
231 {
232 {
233 .id = V4L2_CID_AUTOGAIN,
234 .type = V4L2_CTRL_TYPE_BOOLEAN,
235 .name = "Automatic Gain and Exposure",
236 .minimum = 0,
237 .maximum = 1,
238 .step = 1,
239#define AUTOGAIN_DEF 1
240 .default_value = AUTOGAIN_DEF,
241 },
242 .set = sd_setautogain,
243 .get = sd_getautogain,
244 },
245#define BACKLIGHT_IDX 10
246 {
247 {
248 .id = V4L2_CID_BACKLIGHT_COMPENSATION,
249 .type = V4L2_CTRL_TYPE_BOOLEAN,
250 .name = "Backlight Compensation",
251 .minimum = 0,
252 .maximum = 15,
253 .step = 1,
254#define BACKLIGHT_DEF 15
255 .default_value = BACKLIGHT_DEF,
256 },
257 .set = sd_setbacklight,
258 .get = sd_getbacklight,
259 },
188}; 260};
189 261
190/* table of the disabled controls */ 262/* table of the disabled controls */
@@ -192,33 +264,51 @@ static u32 ctrl_dis[] = {
192/* SENSOR_HV7131R 0 */ 264/* SENSOR_HV7131R 0 */
193 (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX) 265 (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX)
194 | (1 << HFLIP_IDX) | (1 << VFLIP_IDX) | (1 << LIGHTFREQ_IDX) 266 | (1 << HFLIP_IDX) | (1 << VFLIP_IDX) | (1 << LIGHTFREQ_IDX)
195 | (1 << SHARPNESS_IDX), 267 | (1 << SHARPNESS_IDX)
268 | (1 << GAIN_IDX) | (1 << EXPOSURE_IDX)
269 | (1 << AUTOGAIN_IDX) | (1 << BACKLIGHT_IDX),
196/* SENSOR_MI0360 1 */ 270/* SENSOR_MI0360 1 */
197 (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX) 271 (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX)
198 | (1 << HFLIP_IDX) | (1 << VFLIP_IDX) | (1 << LIGHTFREQ_IDX) 272 | (1 << HFLIP_IDX) | (1 << VFLIP_IDX) | (1 << LIGHTFREQ_IDX)
199 | (1 << SHARPNESS_IDX), 273 | (1 << SHARPNESS_IDX)
274 | (1 << GAIN_IDX) | (1 << EXPOSURE_IDX)
275 | (1 << AUTOGAIN_IDX) | (1 << BACKLIGHT_IDX),
200/* SENSOR_MI1310_SOC 2 */ 276/* SENSOR_MI1310_SOC 2 */
201 (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX) 277 (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX)
202 | (1 << LIGHTFREQ_IDX) | (1 << SHARPNESS_IDX), 278 | (1 << LIGHTFREQ_IDX) | (1 << SHARPNESS_IDX)
279 | (1 << GAIN_IDX) | (1 << EXPOSURE_IDX)
280 | (1 << AUTOGAIN_IDX) | (1 << BACKLIGHT_IDX),
203/* SENSOR_MI1320 3 */ 281/* SENSOR_MI1320 3 */
204 (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX) 282 (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX)
205 | (1 << LIGHTFREQ_IDX) | (1 << SHARPNESS_IDX), 283 | (1 << LIGHTFREQ_IDX) | (1 << SHARPNESS_IDX)
284 | (1 << GAIN_IDX) | (1 << EXPOSURE_IDX)
285 | (1 << AUTOGAIN_IDX) | (1 << BACKLIGHT_IDX),
206/* SENSOR_MI1320_SOC 4 */ 286/* SENSOR_MI1320_SOC 4 */
207 (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX) 287 (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX)
208 | (1 << LIGHTFREQ_IDX) | (1 << SHARPNESS_IDX), 288 | (1 << LIGHTFREQ_IDX) | (1 << SHARPNESS_IDX)
289 | (1 << GAIN_IDX) | (1 << EXPOSURE_IDX)
290 | (1 << AUTOGAIN_IDX) | (1 << BACKLIGHT_IDX),
209/* SENSOR_OV7660 5 */ 291/* SENSOR_OV7660 5 */
210 (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX) 292 (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX)
211 | (1 << LIGHTFREQ_IDX) | (1 << SHARPNESS_IDX), 293 | (1 << LIGHTFREQ_IDX) | (1 << SHARPNESS_IDX)
294 | (1 << GAIN_IDX) | (1 << EXPOSURE_IDX)
295 | (1 << AUTOGAIN_IDX) | (1 << BACKLIGHT_IDX),
212/* SENSOR_OV7670 6 */ 296/* SENSOR_OV7670 6 */
213 (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX) 297 (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX)
214 | (1 << SHARPNESS_IDX), 298 | (1 << SHARPNESS_IDX)
299 | (1 << GAIN_IDX) | (1 << EXPOSURE_IDX)
300 | (1 << AUTOGAIN_IDX) | (1 << BACKLIGHT_IDX),
215/* SENSOR_PO1200 7 */ 301/* SENSOR_PO1200 7 */
216 (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX) 302 (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX)
217 | (1 << LIGHTFREQ_IDX), 303 | (1 << LIGHTFREQ_IDX)
304 | (1 << GAIN_IDX) | (1 << EXPOSURE_IDX)
305 | (1 << AUTOGAIN_IDX) | (1 << BACKLIGHT_IDX),
218/* SENSOR_PO3130NC 8 */ 306/* SENSOR_PO3130NC 8 */
219 (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX) 307 (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX)
220 | (1 << HFLIP_IDX) | (1 << VFLIP_IDX) | (1 << LIGHTFREQ_IDX) 308 | (1 << HFLIP_IDX) | (1 << VFLIP_IDX) | (1 << LIGHTFREQ_IDX)
221 | (1 << SHARPNESS_IDX), 309 | (1 << SHARPNESS_IDX)
310 | (1 << GAIN_IDX) | (1 << EXPOSURE_IDX)
311 | (1 << AUTOGAIN_IDX) | (1 << BACKLIGHT_IDX),
222/* SENSOR_POxxxx 9 */ 312/* SENSOR_POxxxx 9 */
223 (1 << HFLIP_IDX) | (1 << VFLIP_IDX) | (1 << LIGHTFREQ_IDX), 313 (1 << HFLIP_IDX) | (1 << VFLIP_IDX) | (1 << LIGHTFREQ_IDX),
224}; 314};
@@ -2825,7 +2915,9 @@ static const u8 poxxxx_init_common[][4] = {
2825 {0x00, 0x1e, 0xc6, 0xaa}, 2915 {0x00, 0x1e, 0xc6, 0xaa},
2826 {0x00, 0x00, 0x40, 0xdd}, 2916 {0x00, 0x00, 0x40, 0xdd},
2827 {0x00, 0x1d, 0x05, 0xaa}, 2917 {0x00, 0x1d, 0x05, 0xaa},
2828 2918 {}
2919};
2920static const u8 poxxxx_gamma[][4] = {
2829 {0x00, 0xd6, 0x22, 0xaa}, /* gamma 0 */ 2921 {0x00, 0xd6, 0x22, 0xaa}, /* gamma 0 */
2830 {0x00, 0x73, 0x00, 0xaa}, 2922 {0x00, 0x73, 0x00, 0xaa},
2831 {0x00, 0x74, 0x0a, 0xaa}, 2923 {0x00, 0x74, 0x0a, 0xaa},
@@ -2867,19 +2959,9 @@ static const u8 poxxxx_init_common[][4] = {
2867 {0x00, 0x7c, 0xba, 0xaa}, 2959 {0x00, 0x7c, 0xba, 0xaa},
2868 {0x00, 0x7d, 0xd4, 0xaa}, 2960 {0x00, 0x7d, 0xd4, 0xaa},
2869 {0x00, 0x7e, 0xea, 0xaa}, 2961 {0x00, 0x7e, 0xea, 0xaa},
2870 2962 {}
2871 {0x00, 0xaa, 0xff, 0xaa}, /* back light comp */ 2963};
2872 {0x00, 0xc4, 0x03, 0xaa}, 2964static const u8 poxxxx_init_start_3[][4] = {
2873 {0x00, 0xc5, 0x19, 0xaa},
2874 {0x00, 0xc6, 0x03, 0xaa},
2875 {0x00, 0xc7, 0x91, 0xaa},
2876 {0x00, 0xc8, 0x01, 0xaa},
2877 {0x00, 0xc9, 0xdd, 0xaa},
2878 {0x00, 0xca, 0x02, 0xaa},
2879 {0x00, 0xcb, 0x37, 0xaa},
2880
2881/* read d1 */
2882 {0x00, 0xd1, 0x3c, 0xaa},
2883 {0x00, 0xb8, 0x28, 0xaa}, 2965 {0x00, 0xb8, 0x28, 0xaa},
2884 {0x00, 0xb9, 0x1e, 0xaa}, 2966 {0x00, 0xb9, 0x1e, 0xaa},
2885 {0x00, 0xb6, 0x14, 0xaa}, 2967 {0x00, 0xb6, 0x14, 0xaa},
@@ -2959,9 +3041,6 @@ static const u8 poxxxx_init_end_1[][4] = {
2959 {0x00, 0xb3, 0x08, 0xaa}, 3041 {0x00, 0xb3, 0x08, 0xaa},
2960 {0x00, 0xb4, 0x0b, 0xaa}, 3042 {0x00, 0xb4, 0x0b, 0xaa},
2961 {0x00, 0xb5, 0x0d, 0xaa}, 3043 {0x00, 0xb5, 0x0d, 0xaa},
2962 {0x00, 0x59, 0x7e, 0xaa}, /* sharpness */
2963 {0x00, 0x16, 0x00, 0xaa}, /* white balance */
2964 {0x00, 0x18, 0x00, 0xaa},
2965 {} 3044 {}
2966}; 3045};
2967static const u8 poxxxx_init_end_2[][4] = { 3046static const u8 poxxxx_init_end_2[][4] = {
@@ -3312,6 +3391,33 @@ static int sd_config(struct gspca_dev *gspca_dev,
3312 const struct usb_device_id *id) 3391 const struct usb_device_id *id)
3313{ 3392{
3314 struct sd *sd = (struct sd *) gspca_dev; 3393 struct sd *sd = (struct sd *) gspca_dev;
3394
3395 sd->bridge = id->driver_info >> 8;
3396 sd->flags = id->driver_info & 0xff;
3397
3398 if (id->idVendor == 0x046d &&
3399 (id->idProduct == 0x0892 || id->idProduct == 0x0896))
3400 sd->sensor = SENSOR_POxxxx; /* no probe */
3401
3402 sd->brightness = BRIGHTNESS_DEF;
3403 sd->contrast = CONTRAST_DEF;
3404 sd->colors = COLOR_DEF;
3405 sd->hflip = HFLIP_DEF;
3406 sd->vflip = VFLIP_DEF;
3407 sd->lightfreq = FREQ_DEF;
3408 sd->sharpness = SHARPNESS_DEF;
3409 sd->gain = GAIN_DEF;
3410 sd->exposure = EXPOSURE_DEF;
3411 sd->autogain = AUTOGAIN_DEF;
3412 sd->backlight = BACKLIGHT_DEF;
3413
3414 return 0;
3415}
3416
3417/* this function is called at probe and resume time */
3418static int sd_init(struct gspca_dev *gspca_dev)
3419{
3420 struct sd *sd = (struct sd *) gspca_dev;
3315 struct cam *cam; 3421 struct cam *cam;
3316 int sensor; 3422 int sensor;
3317 static u8 npkt[] = { /* number of packets per ISOC message */ 3423 static u8 npkt[] = { /* number of packets per ISOC message */
@@ -3327,14 +3433,11 @@ static int sd_config(struct gspca_dev *gspca_dev,
3327 128, /* POxxxx 9 */ 3433 128, /* POxxxx 9 */
3328 }; 3434 };
3329 3435
3330 cam = &gspca_dev->cam; 3436 if (sd->sensor != SENSOR_POxxxx)
3331 sd->bridge = id->driver_info >> 8;
3332 sd->flags = id->driver_info & 0xff;
3333 if (id->idVendor == 0x046d &&
3334 (id->idProduct == 0x0892 || id->idProduct == 0x0896))
3335 sensor = SENSOR_POxxxx;
3336 else
3337 sensor = vc032x_probe_sensor(gspca_dev); 3437 sensor = vc032x_probe_sensor(gspca_dev);
3438 else
3439 sensor = sd->sensor;
3440
3338 switch (sensor) { 3441 switch (sensor) {
3339 case -1: 3442 case -1:
3340 PDEBUG(D_PROBE, "Unknown sensor..."); 3443 PDEBUG(D_PROBE, "Unknown sensor...");
@@ -3373,6 +3476,7 @@ static int sd_config(struct gspca_dev *gspca_dev,
3373 } 3476 }
3374 sd->sensor = sensor; 3477 sd->sensor = sensor;
3375 3478
3479 cam = &gspca_dev->cam;
3376 if (sd->bridge == BRIDGE_VC0321) { 3480 if (sd->bridge == BRIDGE_VC0321) {
3377 cam->cam_mode = vc0321_mode; 3481 cam->cam_mode = vc0321_mode;
3378 cam->nmodes = ARRAY_SIZE(vc0321_mode); 3482 cam->nmodes = ARRAY_SIZE(vc0321_mode);
@@ -3401,28 +3505,11 @@ static int sd_config(struct gspca_dev *gspca_dev,
3401 } 3505 }
3402 } 3506 }
3403 cam->npkt = npkt[sd->sensor]; 3507 cam->npkt = npkt[sd->sensor];
3404
3405 sd->brightness = BRIGHTNESS_DEF;
3406 sd->contrast = CONTRAST_DEF;
3407 sd->colors = COLOR_DEF;
3408 sd->hflip = HFLIP_DEF;
3409 sd->vflip = VFLIP_DEF;
3410 sd->lightfreq = FREQ_DEF;
3411 sd->sharpness = SHARPNESS_DEF;
3412
3413 gspca_dev->ctrl_dis = ctrl_dis[sd->sensor]; 3508 gspca_dev->ctrl_dis = ctrl_dis[sd->sensor];
3414 3509
3415 if (sd->sensor == SENSOR_OV7670) 3510 if (sd->sensor == SENSOR_OV7670)
3416 sd->flags |= FL_HFLIP | FL_VFLIP; 3511 sd->flags |= FL_HFLIP | FL_VFLIP;
3417 3512
3418 return 0;
3419}
3420
3421/* this function is called at probe and resume time */
3422static int sd_init(struct gspca_dev *gspca_dev)
3423{
3424 struct sd *sd = (struct sd *) gspca_dev;
3425
3426 if (sd->bridge == BRIDGE_VC0321) { 3513 if (sd->bridge == BRIDGE_VC0321) {
3427 reg_r(gspca_dev, 0x8a, 0, 3); 3514 reg_r(gspca_dev, 0x8a, 0, 3);
3428 reg_w(gspca_dev, 0x87, 0x00, 0x0f0f); 3515 reg_w(gspca_dev, 0x87, 0x00, 0x0f0f);
@@ -3433,8 +3520,8 @@ static int sd_init(struct gspca_dev *gspca_dev)
3433 if (gspca_dev->usb_buf[0] != 0) { 3520 if (gspca_dev->usb_buf[0] != 0) {
3434 reg_w(gspca_dev, 0xa0, 0x26, 0xb300); 3521 reg_w(gspca_dev, 0xa0, 0x26, 0xb300);
3435 reg_w(gspca_dev, 0xa0, 0x04, 0xb300); 3522 reg_w(gspca_dev, 0xa0, 0x04, 0xb300);
3436 reg_w(gspca_dev, 0xa0, 0x00, 0xb300);
3437 } 3523 }
3524 reg_w(gspca_dev, 0xa0, 0x00, 0xb300);
3438 } 3525 }
3439 } 3526 }
3440 return gspca_dev->usb_err; 3527 return gspca_dev->usb_err;
@@ -3551,6 +3638,82 @@ static void setsharpness(struct gspca_dev *gspca_dev)
3551 break; 3638 break;
3552 } 3639 }
3553} 3640}
3641static void setgain(struct gspca_dev *gspca_dev)
3642{
3643 struct sd *sd = (struct sd *) gspca_dev;
3644
3645 if (gspca_dev->ctrl_dis & (1 << GAIN_IDX))
3646 return;
3647 i2c_write(gspca_dev, 0x15, &sd->gain, 1);
3648}
3649
3650static void setexposure(struct gspca_dev *gspca_dev)
3651{
3652 struct sd *sd = (struct sd *) gspca_dev;
3653 u8 data;
3654
3655 if (gspca_dev->ctrl_dis & (1 << EXPOSURE_IDX))
3656 return;
3657 data = sd->exposure >> 8;
3658 i2c_write(gspca_dev, 0x1a, &data, 1);
3659 data = sd->exposure;
3660 i2c_write(gspca_dev, 0x1b, &data, 1);
3661}
3662
3663static void setautogain(struct gspca_dev *gspca_dev)
3664{
3665 struct sd *sd = (struct sd *) gspca_dev;
3666 static const u8 data[2] = {0x28, 0x3c};
3667
3668 if (gspca_dev->ctrl_dis & (1 << AUTOGAIN_IDX))
3669 return;
3670 i2c_write(gspca_dev, 0xd1, &data[sd->autogain], 1);
3671}
3672
3673static void setgamma(struct gspca_dev *gspca_dev)
3674{
3675/*fixme:to do */
3676 usb_exchange(gspca_dev, poxxxx_gamma);
3677}
3678
3679static void setbacklight(struct gspca_dev *gspca_dev)
3680{
3681 struct sd *sd = (struct sd *) gspca_dev;
3682 u16 v;
3683 u8 data;
3684
3685 data = (sd->backlight << 4) | 0x0f;
3686 i2c_write(gspca_dev, 0xaa, &data, 1);
3687 v = 613 + 12 * sd->backlight;
3688 data = v >> 8;
3689 i2c_write(gspca_dev, 0xc4, &data, 1);
3690 data = v;
3691 i2c_write(gspca_dev, 0xc5, &data, 1);
3692 v = 1093 - 12 * sd->backlight;
3693 data = v >> 8;
3694 i2c_write(gspca_dev, 0xc6, &data, 1);
3695 data = v;
3696 i2c_write(gspca_dev, 0xc7, &data, 1);
3697 v = 342 + 9 * sd->backlight;
3698 data = v >> 8;
3699 i2c_write(gspca_dev, 0xc8, &data, 1);
3700 data = v;
3701 i2c_write(gspca_dev, 0xc9, &data, 1);
3702 v = 702 - 9 * sd->backlight;
3703 data = v >> 8;
3704 i2c_write(gspca_dev, 0xca, &data, 1);
3705 data = v;
3706 i2c_write(gspca_dev, 0xcb, &data, 1);
3707}
3708
3709static void setwb(struct gspca_dev *gspca_dev)
3710{
3711/*fixme:to do - valid when reg d1 = 0x1c - (reg16 + reg15 = 0xa3)*/
3712 static const u8 data[2] = {0x00, 0x00};
3713
3714 i2c_write(gspca_dev, 0x16, &data[0], 1);
3715 i2c_write(gspca_dev, 0x18, &data[1], 1);
3716}
3554 3717
3555static int sd_start(struct gspca_dev *gspca_dev) 3718static int sd_start(struct gspca_dev *gspca_dev)
3556{ 3719{
@@ -3662,6 +3825,16 @@ static int sd_start(struct gspca_dev *gspca_dev)
3662 default: 3825 default:
3663/* case SENSOR_POxxxx: */ 3826/* case SENSOR_POxxxx: */
3664 usb_exchange(gspca_dev, poxxxx_init_common); 3827 usb_exchange(gspca_dev, poxxxx_init_common);
3828 setgamma(gspca_dev);
3829 setbacklight(gspca_dev);
3830 setbrightness(gspca_dev);
3831 setcontrast(gspca_dev);
3832 setcolors(gspca_dev);
3833 setsharpness(gspca_dev);
3834 setautogain(gspca_dev);
3835 setexposure(gspca_dev);
3836 setgain(gspca_dev);
3837 usb_exchange(gspca_dev, poxxxx_init_start_3);
3665 if (mode) 3838 if (mode)
3666 init = poxxxx_initQVGA; 3839 init = poxxxx_initQVGA;
3667 else 3840 else
@@ -3693,7 +3866,6 @@ static int sd_start(struct gspca_dev *gspca_dev)
3693 break; 3866 break;
3694 } 3867 }
3695 msleep(100); 3868 msleep(100);
3696 setsharpness(gspca_dev);
3697 sethvflip(gspca_dev); 3869 sethvflip(gspca_dev);
3698 setlightfreq(gspca_dev); 3870 setlightfreq(gspca_dev);
3699 } 3871 }
@@ -3704,14 +3876,10 @@ static int sd_start(struct gspca_dev *gspca_dev)
3704 reg_w(gspca_dev, 0xa0, 0x0000, 0xbfff); 3876 reg_w(gspca_dev, 0xa0, 0x0000, 0xbfff);
3705 break; 3877 break;
3706 case SENSOR_POxxxx: 3878 case SENSOR_POxxxx:
3707 setcolors(gspca_dev);
3708 setbrightness(gspca_dev);
3709 setcontrast(gspca_dev);
3710
3711 /* led on */
3712 msleep(80);
3713 reg_w(gspca_dev, 0x89, 0xffff, 0xfdff);
3714 usb_exchange(gspca_dev, poxxxx_init_end_2); 3879 usb_exchange(gspca_dev, poxxxx_init_end_2);
3880 setwb(gspca_dev);
3881 msleep(80); /* led on */
3882 reg_w(gspca_dev, 0x89, 0xffff, 0xfdff);
3715 break; 3883 break;
3716 } 3884 }
3717 return gspca_dev->usb_err; 3885 return gspca_dev->usb_err;
@@ -3911,6 +4079,80 @@ static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val)
3911 return 0; 4079 return 0;
3912} 4080}
3913 4081
4082static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val)
4083{
4084 struct sd *sd = (struct sd *) gspca_dev;
4085
4086 sd->gain = val;
4087 if (gspca_dev->streaming)
4088 setgain(gspca_dev);
4089 return gspca_dev->usb_err;
4090}
4091
4092static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val)
4093{
4094 struct sd *sd = (struct sd *) gspca_dev;
4095
4096 *val = sd->gain;
4097 return 0;
4098}
4099
4100static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val)
4101{
4102 struct sd *sd = (struct sd *) gspca_dev;
4103
4104 sd->exposure = val;
4105 if (gspca_dev->streaming)
4106 setexposure(gspca_dev);
4107 return gspca_dev->usb_err;
4108}
4109
4110static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val)
4111{
4112 struct sd *sd = (struct sd *) gspca_dev;
4113
4114 *val = sd->exposure;
4115 return 0;
4116}
4117
4118static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
4119{
4120 struct sd *sd = (struct sd *) gspca_dev;
4121
4122 sd->autogain = val;
4123 if (gspca_dev->streaming)
4124 setautogain(gspca_dev);
4125
4126 return gspca_dev->usb_err;
4127}
4128
4129static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
4130{
4131 struct sd *sd = (struct sd *) gspca_dev;
4132
4133 *val = sd->autogain;
4134 return 0;
4135}
4136
4137static int sd_setbacklight(struct gspca_dev *gspca_dev, __s32 val)
4138{
4139 struct sd *sd = (struct sd *) gspca_dev;
4140
4141 sd->backlight = val;
4142 if (gspca_dev->streaming)
4143 setbacklight(gspca_dev);
4144
4145 return gspca_dev->usb_err;
4146}
4147
4148static int sd_getbacklight(struct gspca_dev *gspca_dev, __s32 *val)
4149{
4150 struct sd *sd = (struct sd *) gspca_dev;
4151
4152 *val = sd->backlight;
4153 return 0;
4154}
4155
3914static int sd_querymenu(struct gspca_dev *gspca_dev, 4156static int sd_querymenu(struct gspca_dev *gspca_dev,
3915 struct v4l2_querymenu *menu) 4157 struct v4l2_querymenu *menu)
3916{ 4158{
diff --git a/drivers/media/video/gspca/zc3xx.c b/drivers/media/video/gspca/zc3xx.c
index 4473f0fb8b73..0666038a51b0 100644
--- a/drivers/media/video/gspca/zc3xx.c
+++ b/drivers/media/video/gspca/zc3xx.c
@@ -21,7 +21,9 @@
21 21
22#define MODULE_NAME "zc3xx" 22#define MODULE_NAME "zc3xx"
23 23
24#ifdef CONFIG_INPUT
24#include <linux/input.h> 25#include <linux/input.h>
26#endif
25#include "gspca.h" 27#include "gspca.h"
26#include "jpeg.h" 28#include "jpeg.h"
27 29
@@ -50,33 +52,38 @@ struct sd {
50#define QUALITY_MAX 80 52#define QUALITY_MAX 80
51#define QUALITY_DEF 70 53#define QUALITY_DEF 70
52 54
55 u8 bridge;
53 u8 sensor; /* Type of image sensor chip */ 56 u8 sensor; /* Type of image sensor chip */
54/* !! values used in different tables */ 57 u16 chip_revision;
55#define SENSOR_ADCM2700 0
56#define SENSOR_CS2102 1
57#define SENSOR_CS2102K 2
58#define SENSOR_GC0305 3
59#define SENSOR_HDCS2020b 4
60#define SENSOR_HV7131B 5
61#define SENSOR_HV7131C 6
62#define SENSOR_ICM105A 7
63#define SENSOR_MC501CB 8
64#define SENSOR_MI0360SOC 9
65#define SENSOR_OV7620 10
66/*#define SENSOR_OV7648 10 - same values */
67#define SENSOR_OV7630C 11
68#define SENSOR_PAS106 12
69#define SENSOR_PAS202B 13
70#define SENSOR_PB0330 14 /* (MI0360) */
71#define SENSOR_PO2030 15
72#define SENSOR_TAS5130CK 16
73#define SENSOR_TAS5130CXX 17
74#define SENSOR_TAS5130C_VF0250 18
75#define SENSOR_MAX 19
76 unsigned short chip_revision;
77 58
78 u8 jpeg_hdr[JPEG_HDR_SZ]; 59 u8 jpeg_hdr[JPEG_HDR_SZ];
79}; 60};
61enum bridges {
62 BRIDGE_ZC301,
63 BRIDGE_ZC303,
64};
65enum sensors {
66 SENSOR_ADCM2700,
67 SENSOR_CS2102,
68 SENSOR_CS2102K,
69 SENSOR_GC0305,
70 SENSOR_HDCS2020b,
71 SENSOR_HV7131B,
72 SENSOR_HV7131R,
73 SENSOR_ICM105A,
74 SENSOR_MC501CB,
75 SENSOR_MT9V111_1, /* (mi360soc) zc301 */
76 SENSOR_MT9V111_3, /* (mi360soc) zc303 */
77 SENSOR_OV7620, /* OV7648 - same values */
78 SENSOR_OV7630C,
79 SENSOR_PAS106,
80 SENSOR_PAS202B,
81 SENSOR_PB0330,
82 SENSOR_PO2030,
83 SENSOR_TAS5130C,
84 SENSOR_TAS5130C_VF0250,
85 SENSOR_MAX
86};
80 87
81/* V4L2 controls supported by the driver */ 88/* V4L2 controls supported by the driver */
82static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val); 89static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
@@ -2074,6 +2081,7 @@ static const struct usb_action hv7131b_NoFlikerScale[] = { /* 320x240 */
2074 {} 2081 {}
2075}; 2082};
2076 2083
2084/* from lPEPI264v.inf (hv7131b!) */
2077static const struct usb_action hv7131r_InitialScale[] = { 2085static const struct usb_action hv7131r_InitialScale[] = {
2078 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, 2086 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL},
2079 {0xa0, 0x10, ZC3XX_R002_CLOCKSELECT}, 2087 {0xa0, 0x10, ZC3XX_R002_CLOCKSELECT},
@@ -2081,8 +2089,8 @@ static const struct usb_action hv7131r_InitialScale[] = {
2081 {0xa0, 0x01, ZC3XX_R001_SYSTEMOPERATING}, 2089 {0xa0, 0x01, ZC3XX_R001_SYSTEMOPERATING},
2082 {0xa0, 0x77, ZC3XX_R101_SENSORCORRECTION}, 2090 {0xa0, 0x77, ZC3XX_R101_SENSORCORRECTION},
2083 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING}, 2091 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING},
2084 {0xa0, 0x05, ZC3XX_R012_VIDEOCONTROLFUNC},
2085 {0xa0, 0x07, ZC3XX_R012_VIDEOCONTROLFUNC}, 2092 {0xa0, 0x07, ZC3XX_R012_VIDEOCONTROLFUNC},
2093 {0xa0, 0x01, ZC3XX_R012_VIDEOCONTROLFUNC},
2086 {0xa0, 0x02, ZC3XX_R003_FRAMEWIDTHHIGH}, 2094 {0xa0, 0x02, ZC3XX_R003_FRAMEWIDTHHIGH},
2087 {0xa0, 0x80, ZC3XX_R004_FRAMEWIDTHLOW}, 2095 {0xa0, 0x80, ZC3XX_R004_FRAMEWIDTHLOW},
2088 {0xa0, 0x01, ZC3XX_R005_FRAMEHEIGHTHIGH}, 2096 {0xa0, 0x01, ZC3XX_R005_FRAMEHEIGHTHIGH},
@@ -2095,6 +2103,8 @@ static const struct usb_action hv7131r_InitialScale[] = {
2095 {0xa0, 0x88, ZC3XX_R09E_WINWIDTHLOW}, 2103 {0xa0, 0x88, ZC3XX_R09E_WINWIDTHLOW},
2096 {0xa0, 0x00, ZC3XX_R11A_FIRSTYLOW}, 2104 {0xa0, 0x00, ZC3XX_R11A_FIRSTYLOW},
2097 {0xa0, 0x00, ZC3XX_R11C_FIRSTXLOW}, 2105 {0xa0, 0x00, ZC3XX_R11C_FIRSTXLOW},
2106 {0xa0, 0x07, ZC3XX_R012_VIDEOCONTROLFUNC},
2107 {0xdd, 0x00, 0x0200},
2098 {0xa0, 0x05, ZC3XX_R012_VIDEOCONTROLFUNC}, 2108 {0xa0, 0x05, ZC3XX_R012_VIDEOCONTROLFUNC},
2099 {0xaa, 0x01, 0x000c}, 2109 {0xaa, 0x01, 0x000c},
2100 {0xaa, 0x11, 0x0000}, 2110 {0xaa, 0x11, 0x0000},
@@ -2103,10 +2113,10 @@ static const struct usb_action hv7131r_InitialScale[] = {
2103 {0xaa, 0x15, 0x00e8}, 2113 {0xaa, 0x15, 0x00e8},
2104 {0xaa, 0x16, 0x0002}, 2114 {0xaa, 0x16, 0x0002},
2105 {0xaa, 0x17, 0x0088}, 2115 {0xaa, 0x17, 0x0088},
2106 2116 {0xaa, 0x30, 0x000b},
2107 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, 2117 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS},
2108 {0xa0, 0x0d, ZC3XX_R100_OPERATIONMODE}, 2118 {0xa0, 0x0d, ZC3XX_R100_OPERATIONMODE},
2109 {0xa0, 0x89, ZC3XX_R18D_YTARGET}, 2119 {0xa0, 0x78, ZC3XX_R18D_YTARGET},
2110 {0xa0, 0x50, ZC3XX_R1A8_DIGITALGAIN}, 2120 {0xa0, 0x50, ZC3XX_R1A8_DIGITALGAIN},
2111 {0xa0, 0x00, 0x01ad}, 2121 {0xa0, 0x00, 0x01ad},
2112 {0xa0, 0xc0, 0x019b}, 2122 {0xa0, 0xc0, 0x019b},
@@ -2116,96 +2126,44 @@ static const struct usb_action hv7131r_InitialScale[] = {
2116 {0xa0, 0x13, ZC3XX_R1CB_SHARPNESS05}, 2126 {0xa0, 0x13, ZC3XX_R1CB_SHARPNESS05},
2117 {0xa0, 0x08, ZC3XX_R250_DEADPIXELSMODE}, 2127 {0xa0, 0x08, ZC3XX_R250_DEADPIXELSMODE},
2118 {0xa0, 0x08, ZC3XX_R301_EEPROMACCESS}, 2128 {0xa0, 0x08, ZC3XX_R301_EEPROMACCESS},
2119 {0xa1, 0x01, 0x0002},
2120 {0xa0, 0x00, ZC3XX_R092_I2CADDRESSSELECT},
2121 {0xa0, 0x02, ZC3XX_R090_I2CCOMMAND},
2122 {0xa1, 0x01, 0x0091},
2123 {0xa1, 0x01, 0x0095},
2124 {0xa1, 0x01, 0x0096},
2125
2126 {0xa1, 0x01, 0x0008},
2127 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING}, /* clock ? */
2128 {0xa0, 0x08, ZC3XX_R1C6_SHARPNESS00}, /* sharpness+ */
2129 {0xa1, 0x01, 0x01c8},
2130 {0xa1, 0x01, 0x01c9},
2131 {0xa1, 0x01, 0x01ca},
2132 {0xa0, 0x0f, ZC3XX_R1CB_SHARPNESS05}, /* sharpness- */
2133
2134 {0xa0, 0x60, ZC3XX_R10A_RGB00}, /* matrix */
2135 {0xa0, 0xf0, ZC3XX_R10B_RGB01},
2136 {0xa0, 0xf0, ZC3XX_R10C_RGB02},
2137 {0xa0, 0xf0, ZC3XX_R10D_RGB10},
2138 {0xa0, 0x60, ZC3XX_R10E_RGB11},
2139 {0xa0, 0xf0, ZC3XX_R10F_RGB12},
2140 {0xa0, 0xf0, ZC3XX_R110_RGB20},
2141 {0xa0, 0xf0, ZC3XX_R111_RGB21},
2142 {0xa0, 0x60, ZC3XX_R112_RGB22},
2143 {0xa1, 0x01, 0x0180},
2144 {0xa0, 0x10, ZC3XX_R180_AUTOCORRECTENABLE},
2145 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS},
2146 {0xaa, 0x25, 0x0007},
2147 {0xaa, 0x26, 0x0053},
2148 {0xaa, 0x27, 0x0000},
2149
2150 {0xa0, 0x10, ZC3XX_R190_EXPOSURELIMITHIGH}, /* 2f */
2151 {0xa0, 0x04, ZC3XX_R191_EXPOSURELIMITMID}, /* 9b */
2152 {0xa0, 0x60, ZC3XX_R192_EXPOSURELIMITLOW}, /* 80 */
2153 {0xa0, 0x01, ZC3XX_R195_ANTIFLICKERHIGH},
2154 {0xa0, 0xd4, ZC3XX_R196_ANTIFLICKERMID},
2155 {0xa0, 0xc0, ZC3XX_R197_ANTIFLICKERLOW},
2156 {0xa0, 0x10, ZC3XX_R18C_AEFREEZE},
2157 {0xa0, 0x20, ZC3XX_R18F_AEUNFREEZE},
2158 {0xa0, 0x60, ZC3XX_R1A8_DIGITALGAIN},
2159 {0xa0, 0x10, ZC3XX_R1A9_DIGITALLIMITDIFF},
2160 {0xa0, 0x13, ZC3XX_R1AA_DIGITALGAINSTEP},
2161 {0xa1, 0x01, 0x001d},
2162 {0xa1, 0x01, 0x001e},
2163 {0xa1, 0x01, 0x001f},
2164 {0xa1, 0x01, 0x0020},
2165 {0xa0, 0x40, ZC3XX_R180_AUTOCORRECTENABLE},
2166 {0xa1, 0x01, 0x0180},
2167 {0xa0, 0x42, ZC3XX_R180_AUTOCORRECTENABLE},
2168 {} 2129 {}
2169}; 2130};
2170
2171static const struct usb_action hv7131r_Initial[] = { 2131static const struct usb_action hv7131r_Initial[] = {
2172 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, 2132 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL},
2173 2133 {0xa0, 0x00, ZC3XX_R002_CLOCKSELECT},
2174 {0xa0, 0x00, ZC3XX_R002_CLOCKSELECT}, /* diff */
2175 {0xa0, 0x01, ZC3XX_R010_CMOSSENSORSELECT}, 2134 {0xa0, 0x01, ZC3XX_R010_CMOSSENSORSELECT},
2176 {0xa0, 0x01, ZC3XX_R001_SYSTEMOPERATING}, 2135 {0xa0, 0x01, ZC3XX_R001_SYSTEMOPERATING},
2177 {0xa0, 0x77, ZC3XX_R101_SENSORCORRECTION}, 2136 {0xa0, 0x77, ZC3XX_R101_SENSORCORRECTION},
2178 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING}, 2137 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING},
2179
2180 {0xa0, 0x05, ZC3XX_R012_VIDEOCONTROLFUNC},
2181 {0xa0, 0x07, ZC3XX_R012_VIDEOCONTROLFUNC}, 2138 {0xa0, 0x07, ZC3XX_R012_VIDEOCONTROLFUNC},
2182 2139 {0xa0, 0x01, ZC3XX_R012_VIDEOCONTROLFUNC},
2183 {0xa0, 0x02, ZC3XX_R003_FRAMEWIDTHHIGH}, 2140 {0xa0, 0x02, ZC3XX_R003_FRAMEWIDTHHIGH},
2184 {0xa0, 0x80, ZC3XX_R004_FRAMEWIDTHLOW}, 2141 {0xa0, 0x80, ZC3XX_R004_FRAMEWIDTHLOW},
2185 {0xa0, 0x01, ZC3XX_R005_FRAMEHEIGHTHIGH}, 2142 {0xa0, 0x01, ZC3XX_R005_FRAMEHEIGHTHIGH},
2186 {0xa0, 0xe0, ZC3XX_R006_FRAMEHEIGHTLOW}, /* 1e0 */ 2143 {0xa0, 0xe0, ZC3XX_R006_FRAMEHEIGHTLOW},
2187 2144
2188 {0xa0, 0x00, ZC3XX_R098_WINYSTARTLOW}, 2145 {0xa0, 0x00, ZC3XX_R098_WINYSTARTLOW},
2189 {0xa0, 0x00, ZC3XX_R09A_WINXSTARTLOW}, 2146 {0xa0, 0x00, ZC3XX_R09A_WINXSTARTLOW},
2190 {0xa0, 0x01, ZC3XX_R09B_WINHEIGHTHIGH}, 2147 {0xa0, 0x01, ZC3XX_R09B_WINHEIGHTHIGH},
2191 {0xa0, 0xe8, ZC3XX_R09C_WINHEIGHTLOW}, 2148 {0xa0, 0xe6, ZC3XX_R09C_WINHEIGHTLOW},
2192 {0xa0, 0x02, ZC3XX_R09D_WINWIDTHHIGH}, 2149 {0xa0, 0x02, ZC3XX_R09D_WINWIDTHHIGH},
2193 {0xa0, 0x88, ZC3XX_R09E_WINWIDTHLOW}, 2150 {0xa0, 0x86, ZC3XX_R09E_WINWIDTHLOW},
2194 {0xa0, 0x00, ZC3XX_R11A_FIRSTYLOW}, 2151 {0xa0, 0x00, ZC3XX_R11A_FIRSTYLOW},
2195 {0xa0, 0x00, ZC3XX_R11C_FIRSTXLOW}, 2152 {0xa0, 0x00, ZC3XX_R11C_FIRSTXLOW},
2153 {0xa0, 0x07, ZC3XX_R012_VIDEOCONTROLFUNC},
2154 {0xdd, 0x00, 0x0200},
2196 {0xa0, 0x05, ZC3XX_R012_VIDEOCONTROLFUNC}, 2155 {0xa0, 0x05, ZC3XX_R012_VIDEOCONTROLFUNC},
2197 {0xaa, 0x01, 0x000c}, 2156 {0xaa, 0x01, 0x000c},
2198 {0xaa, 0x11, 0x0000}, 2157 {0xaa, 0x11, 0x0000},
2199 {0xaa, 0x13, 0x0000}, 2158 {0xaa, 0x13, 0x0000},
2200 {0xaa, 0x14, 0x0001}, 2159 {0xaa, 0x14, 0x0001},
2201 {0xaa, 0x15, 0x00e8}, 2160 {0xaa, 0x15, 0x00e6},
2202 {0xaa, 0x16, 0x0002}, 2161 {0xaa, 0x16, 0x0002},
2203 {0xaa, 0x17, 0x0088}, 2162 {0xaa, 0x17, 0x0086},
2204 2163 {0xaa, 0x30, 0x000b},
2205 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, /* 00 */ 2164 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS},
2206
2207 {0xa0, 0x0d, ZC3XX_R100_OPERATIONMODE}, 2165 {0xa0, 0x0d, ZC3XX_R100_OPERATIONMODE},
2208 {0xa0, 0x89, ZC3XX_R18D_YTARGET}, 2166 {0xa0, 0x78, ZC3XX_R18D_YTARGET},
2209 {0xa0, 0x50, ZC3XX_R1A8_DIGITALGAIN}, 2167 {0xa0, 0x50, ZC3XX_R1A8_DIGITALGAIN},
2210 {0xa0, 0x00, 0x01ad}, 2168 {0xa0, 0x00, 0x01ad},
2211 {0xa0, 0xc0, 0x019b}, 2169 {0xa0, 0xc0, 0x019b},
@@ -2215,58 +2173,114 @@ static const struct usb_action hv7131r_Initial[] = {
2215 {0xa0, 0x13, ZC3XX_R1CB_SHARPNESS05}, 2173 {0xa0, 0x13, ZC3XX_R1CB_SHARPNESS05},
2216 {0xa0, 0x08, ZC3XX_R250_DEADPIXELSMODE}, 2174 {0xa0, 0x08, ZC3XX_R250_DEADPIXELSMODE},
2217 {0xa0, 0x08, ZC3XX_R301_EEPROMACCESS}, 2175 {0xa0, 0x08, ZC3XX_R301_EEPROMACCESS},
2218 {0xa1, 0x01, 0x0002}, 2176 {}
2219 {0xa0, 0x00, ZC3XX_R092_I2CADDRESSSELECT}, 2177};
2220 /* read the i2c chips ident */ 2178static const struct usb_action hv7131r_50HZ[] = {
2221 {0xa0, 0x02, ZC3XX_R090_I2CCOMMAND},
2222 {0xa1, 0x01, 0x0091},
2223 {0xa1, 0x01, 0x0095},
2224 {0xa1, 0x01, 0x0096},
2225
2226 {0xa1, 0x01, 0x0008},
2227 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING}, /* clock ? */
2228 {0xa0, 0x08, ZC3XX_R1C6_SHARPNESS00}, /* sharpness+ */
2229 {0xa1, 0x01, 0x01c8},
2230 {0xa1, 0x01, 0x01c9},
2231 {0xa1, 0x01, 0x01ca},
2232 {0xa0, 0x0f, ZC3XX_R1CB_SHARPNESS05}, /* sharpness- */
2233
2234 {0xa0, 0x60, ZC3XX_R10A_RGB00}, /* matrix */
2235 {0xa0, 0xf0, ZC3XX_R10B_RGB01},
2236 {0xa0, 0xf0, ZC3XX_R10C_RGB02},
2237 {0xa0, 0xf0, ZC3XX_R10D_RGB10},
2238 {0xa0, 0x60, ZC3XX_R10E_RGB11},
2239 {0xa0, 0xf0, ZC3XX_R10F_RGB12},
2240 {0xa0, 0xf0, ZC3XX_R110_RGB20},
2241 {0xa0, 0xf0, ZC3XX_R111_RGB21},
2242 {0xa0, 0x60, ZC3XX_R112_RGB22},
2243 {0xa1, 0x01, 0x0180},
2244 {0xa0, 0x10, ZC3XX_R180_AUTOCORRECTENABLE},
2245 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, 2179 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS},
2246 {0xaa, 0x25, 0x0007}, 2180 {0xa0, 0x06, ZC3XX_R190_EXPOSURELIMITHIGH},
2247 {0xaa, 0x26, 0x0053}, 2181 {0xa0, 0x68, ZC3XX_R191_EXPOSURELIMITMID},
2248 {0xaa, 0x27, 0x0000}, 2182 {0xa0, 0xa0, ZC3XX_R192_EXPOSURELIMITLOW},
2249 2183 {0xa0, 0x00, ZC3XX_R195_ANTIFLICKERHIGH},
2250 {0xa0, 0x10, ZC3XX_R190_EXPOSURELIMITHIGH}, /* 2f */ 2184 {0xa0, 0xea, ZC3XX_R196_ANTIFLICKERMID},
2251 {0xa0, 0x04, ZC3XX_R191_EXPOSURELIMITMID}, /* 9b */ 2185 {0xa0, 0x60, ZC3XX_R197_ANTIFLICKERLOW},
2252 {0xa0, 0x60, ZC3XX_R192_EXPOSURELIMITLOW}, /* 80 */ 2186 {0xa0, 0x18, ZC3XX_R18C_AEFREEZE},
2253 2187 {0xa0, 0x20, ZC3XX_R18F_AEUNFREEZE},
2188 {0xa0, 0x10, ZC3XX_R1A9_DIGITALLIMITDIFF},
2189 {0xa0, 0x66, ZC3XX_R1AA_DIGITALGAINSTEP},
2190 {0xa0, 0x00, ZC3XX_R01D_HSYNC_0},
2191 {0xa0, 0xd0, ZC3XX_R01E_HSYNC_1},
2192 {0xa0, 0x00, ZC3XX_R01F_HSYNC_2},
2193 {0xa0, 0x08, ZC3XX_R020_HSYNC_3},
2194 {}
2195};
2196static const struct usb_action hv7131r_50HZScale[] = {
2197 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS},
2198 {0xa0, 0x0c, ZC3XX_R190_EXPOSURELIMITHIGH},
2199 {0xa0, 0xd1, ZC3XX_R191_EXPOSURELIMITMID},
2200 {0xa0, 0x40, ZC3XX_R192_EXPOSURELIMITLOW},
2254 {0xa0, 0x01, ZC3XX_R195_ANTIFLICKERHIGH}, 2201 {0xa0, 0x01, ZC3XX_R195_ANTIFLICKERHIGH},
2255 {0xa0, 0xd4, ZC3XX_R196_ANTIFLICKERMID}, 2202 {0xa0, 0xd4, ZC3XX_R196_ANTIFLICKERMID},
2256 {0xa0, 0xc0, ZC3XX_R197_ANTIFLICKERLOW}, 2203 {0xa0, 0xc0, ZC3XX_R197_ANTIFLICKERLOW},
2257 2204 {0xa0, 0x18, ZC3XX_R18C_AEFREEZE},
2258 {0xa0, 0x10, ZC3XX_R18C_AEFREEZE},
2259 {0xa0, 0x20, ZC3XX_R18F_AEUNFREEZE}, 2205 {0xa0, 0x20, ZC3XX_R18F_AEUNFREEZE},
2260 {0xa0, 0x60, ZC3XX_R1A8_DIGITALGAIN},
2261 {0xa0, 0x10, ZC3XX_R1A9_DIGITALLIMITDIFF}, 2206 {0xa0, 0x10, ZC3XX_R1A9_DIGITALLIMITDIFF},
2262 {0xa0, 0x13, ZC3XX_R1AA_DIGITALGAINSTEP}, 2207 {0xa0, 0x66, ZC3XX_R1AA_DIGITALGAINSTEP},
2263 {0xa1, 0x01, 0x001d}, 2208 {0xa0, 0x00, ZC3XX_R01D_HSYNC_0},
2264 {0xa1, 0x01, 0x001e}, 2209 {0xa0, 0xd0, ZC3XX_R01E_HSYNC_1},
2265 {0xa1, 0x01, 0x001f}, 2210 {0xa0, 0x00, ZC3XX_R01F_HSYNC_2},
2266 {0xa1, 0x01, 0x0020}, 2211 {0xa0, 0x08, ZC3XX_R020_HSYNC_3},
2267 {0xa0, 0x40, ZC3XX_R180_AUTOCORRECTENABLE}, 2212 {}
2268 {0xa1, 0x01, 0x0180}, 2213};
2269 {0xa0, 0x42, ZC3XX_R180_AUTOCORRECTENABLE}, 2214static const struct usb_action hv7131r_60HZ[] = {
2215 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS},
2216 {0xa0, 0x06, ZC3XX_R190_EXPOSURELIMITHIGH},
2217 {0xa0, 0x1a, ZC3XX_R191_EXPOSURELIMITMID},
2218 {0xa0, 0x80, ZC3XX_R192_EXPOSURELIMITLOW},
2219 {0xa0, 0x00, ZC3XX_R195_ANTIFLICKERHIGH},
2220 {0xa0, 0xc3, ZC3XX_R196_ANTIFLICKERMID},
2221 {0xa0, 0x50, ZC3XX_R197_ANTIFLICKERLOW},
2222 {0xa0, 0x18, ZC3XX_R18C_AEFREEZE},
2223 {0xa0, 0x20, ZC3XX_R18F_AEUNFREEZE},
2224 {0xa0, 0x10, ZC3XX_R1A9_DIGITALLIMITDIFF},
2225 {0xa0, 0x66, ZC3XX_R1AA_DIGITALGAINSTEP},
2226 {0xa0, 0x00, ZC3XX_R01D_HSYNC_0},
2227 {0xa0, 0xd0, ZC3XX_R01E_HSYNC_1},
2228 {0xa0, 0x00, ZC3XX_R01F_HSYNC_2},
2229 {0xa0, 0x08, ZC3XX_R020_HSYNC_3},
2230 {}
2231};
2232static const struct usb_action hv7131r_60HZScale[] = {
2233 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS},
2234 {0xa0, 0x0c, ZC3XX_R190_EXPOSURELIMITHIGH},
2235 {0xa0, 0x35, ZC3XX_R191_EXPOSURELIMITMID},
2236 {0xa0, 0x00, ZC3XX_R192_EXPOSURELIMITLOW},
2237 {0xa0, 0x01, ZC3XX_R195_ANTIFLICKERHIGH},
2238 {0xa0, 0x86, ZC3XX_R196_ANTIFLICKERMID},
2239 {0xa0, 0xa0, ZC3XX_R197_ANTIFLICKERLOW},
2240 {0xa0, 0x18, ZC3XX_R18C_AEFREEZE},
2241 {0xa0, 0x20, ZC3XX_R18F_AEUNFREEZE},
2242 {0xa0, 0x10, ZC3XX_R1A9_DIGITALLIMITDIFF},
2243 {0xa0, 0x66, ZC3XX_R1AA_DIGITALGAINSTEP},
2244 {0xa0, 0x00, ZC3XX_R01D_HSYNC_0},
2245 {0xa0, 0xd0, ZC3XX_R01E_HSYNC_1},
2246 {0xa0, 0x00, ZC3XX_R01F_HSYNC_2},
2247 {0xa0, 0x08, ZC3XX_R020_HSYNC_3},
2248 {}
2249};
2250static const struct usb_action hv7131r_NoFliker[] = {
2251 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS},
2252 {0xa0, 0x2f, ZC3XX_R190_EXPOSURELIMITHIGH},
2253 {0xa0, 0xf8, ZC3XX_R191_EXPOSURELIMITMID},
2254 {0xa0, 0x00, ZC3XX_R192_EXPOSURELIMITLOW},
2255 {0xa0, 0x00, ZC3XX_R195_ANTIFLICKERHIGH},
2256 {0xa0, 0x02, ZC3XX_R196_ANTIFLICKERMID},
2257 {0xa0, 0x58, ZC3XX_R197_ANTIFLICKERLOW},
2258 {0xa0, 0x0c, ZC3XX_R18C_AEFREEZE},
2259 {0xa0, 0x18, ZC3XX_R18F_AEUNFREEZE},
2260 {0xa0, 0x00, ZC3XX_R1A9_DIGITALLIMITDIFF},
2261 {0xa0, 0x00, ZC3XX_R1AA_DIGITALGAINSTEP},
2262 {0xa0, 0x00, ZC3XX_R01D_HSYNC_0},
2263 {0xa0, 0xd0, ZC3XX_R01E_HSYNC_1},
2264 {0xa0, 0x00, ZC3XX_R01F_HSYNC_2},
2265 {0xa0, 0x08, ZC3XX_R020_HSYNC_3},
2266 {}
2267};
2268static const struct usb_action hv7131r_NoFlikerScale[] = {
2269 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS},
2270 {0xa0, 0x2f, ZC3XX_R190_EXPOSURELIMITHIGH},
2271 {0xa0, 0xf8, ZC3XX_R191_EXPOSURELIMITMID},
2272 {0xa0, 0x00, ZC3XX_R192_EXPOSURELIMITLOW},
2273 {0xa0, 0x00, ZC3XX_R195_ANTIFLICKERHIGH},
2274 {0xa0, 0x04, ZC3XX_R196_ANTIFLICKERMID},
2275 {0xa0, 0xb0, ZC3XX_R197_ANTIFLICKERLOW},
2276 {0xa0, 0x0c, ZC3XX_R18C_AEFREEZE},
2277 {0xa0, 0x18, ZC3XX_R18F_AEUNFREEZE},
2278 {0xa0, 0x00, ZC3XX_R1A9_DIGITALLIMITDIFF},
2279 {0xa0, 0x00, ZC3XX_R1AA_DIGITALGAINSTEP},
2280 {0xa0, 0x00, ZC3XX_R01D_HSYNC_0},
2281 {0xa0, 0xd0, ZC3XX_R01E_HSYNC_1},
2282 {0xa0, 0x00, ZC3XX_R01F_HSYNC_2},
2283 {0xa0, 0x08, ZC3XX_R020_HSYNC_3},
2270 {} 2284 {}
2271}; 2285};
2272 2286
@@ -3350,7 +3364,7 @@ static const struct usb_action ov7620_NoFliker[] = {
3350 {0xa0, 0x00, ZC3XX_R196_ANTIFLICKERMID}, /* 01,96,00,cc */ 3364 {0xa0, 0x00, ZC3XX_R196_ANTIFLICKERMID}, /* 01,96,00,cc */
3351 {0xa0, 0x01, ZC3XX_R197_ANTIFLICKERLOW}, /* 01,97,01,cc */ 3365 {0xa0, 0x01, ZC3XX_R197_ANTIFLICKERLOW}, /* 01,97,01,cc */
3352/* {0xa0, 0x44, ZC3XX_R002_CLOCKSELECT}, * 00,02,44,cc 3366/* {0xa0, 0x44, ZC3XX_R002_CLOCKSELECT}, * 00,02,44,cc
3353 - if mode1 (320x240) */ 3367 * if mode1 (320x240) */
3354/* ?? was 3368/* ?? was
3355 {0xa0, 0x00, 0x0039}, * 00,00,00,dd * 3369 {0xa0, 0x00, 0x0039}, * 00,00,00,dd *
3356 {0xa1, 0x01, 0x0037}, */ 3370 {0xa1, 0x01, 0x0037}, */
@@ -3439,7 +3453,6 @@ static const struct usb_action ov7630c_InitialScale[] = {
3439 {0xa0, 0xf8, ZC3XX_R110_RGB20}, 3453 {0xa0, 0xf8, ZC3XX_R110_RGB20},
3440 {0xa0, 0xf8, ZC3XX_R111_RGB21}, 3454 {0xa0, 0xf8, ZC3XX_R111_RGB21},
3441 {0xa0, 0x50, ZC3XX_R112_RGB22}, 3455 {0xa0, 0x50, ZC3XX_R112_RGB22},
3442/* 0x03, */
3443 {0xa1, 0x01, 0x0008}, 3456 {0xa1, 0x01, 0x0008},
3444 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING}, /* clock ? */ 3457 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING}, /* clock ? */
3445 {0xa0, 0x08, ZC3XX_R1C6_SHARPNESS00}, /* sharpness+ */ 3458 {0xa0, 0x08, ZC3XX_R1C6_SHARPNESS00}, /* sharpness+ */
@@ -3719,7 +3732,7 @@ static const struct usb_action pas106b_InitialScale[] = { /* 176x144 */
3719 {0xaa, 0x0e, 0x0002}, 3732 {0xaa, 0x0e, 0x0002},
3720 {0xaa, 0x14, 0x0081}, 3733 {0xaa, 0x14, 0x0081},
3721 3734
3722/* Other registors */ 3735/* Other registers */
3723 {0xa0, 0x37, ZC3XX_R101_SENSORCORRECTION}, 3736 {0xa0, 0x37, ZC3XX_R101_SENSORCORRECTION},
3724/* Frame retreiving */ 3737/* Frame retreiving */
3725 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, 3738 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS},
@@ -3730,7 +3743,7 @@ static const struct usb_action pas106b_InitialScale[] = { /* 176x144 */
3730/* Sharpness */ 3743/* Sharpness */
3731 {0xa0, 0x03, ZC3XX_R1C5_SHARPNESSMODE}, 3744 {0xa0, 0x03, ZC3XX_R1C5_SHARPNESSMODE},
3732 {0xa0, 0x13, ZC3XX_R1CB_SHARPNESS05}, 3745 {0xa0, 0x13, ZC3XX_R1CB_SHARPNESS05},
3733/* Other registors */ 3746/* Other registers */
3734 {0xa0, 0x0d, ZC3XX_R100_OPERATIONMODE}, 3747 {0xa0, 0x0d, ZC3XX_R100_OPERATIONMODE},
3735/* Auto exposure and white balance */ 3748/* Auto exposure and white balance */
3736 {0xa0, 0x06, ZC3XX_R189_AWBSTATUS}, 3749 {0xa0, 0x06, ZC3XX_R189_AWBSTATUS},
@@ -3837,7 +3850,7 @@ static const struct usb_action pas106b_Initial[] = { /* 352x288 */
3837 {0xaa, 0x0e, 0x0002}, 3850 {0xaa, 0x0e, 0x0002},
3838 {0xaa, 0x14, 0x0081}, 3851 {0xaa, 0x14, 0x0081},
3839 3852
3840/* Other registors */ 3853/* Other registers */
3841 {0xa0, 0x37, ZC3XX_R101_SENSORCORRECTION}, 3854 {0xa0, 0x37, ZC3XX_R101_SENSORCORRECTION},
3842/* Frame retreiving */ 3855/* Frame retreiving */
3843 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, 3856 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS},
@@ -3848,7 +3861,7 @@ static const struct usb_action pas106b_Initial[] = { /* 352x288 */
3848/* Sharpness */ 3861/* Sharpness */
3849 {0xa0, 0x03, ZC3XX_R1C5_SHARPNESSMODE}, 3862 {0xa0, 0x03, ZC3XX_R1C5_SHARPNESSMODE},
3850 {0xa0, 0x13, ZC3XX_R1CB_SHARPNESS05}, 3863 {0xa0, 0x13, ZC3XX_R1CB_SHARPNESS05},
3851/* Other registors */ 3864/* Other registers */
3852 {0xa0, 0x0d, ZC3XX_R100_OPERATIONMODE}, 3865 {0xa0, 0x0d, ZC3XX_R100_OPERATIONMODE},
3853/* Auto exposure and white balance */ 3866/* Auto exposure and white balance */
3854 {0xa0, 0x06, ZC3XX_R189_AWBSTATUS}, 3867 {0xa0, 0x06, ZC3XX_R189_AWBSTATUS},
@@ -4241,8 +4254,8 @@ static const struct usb_action pas202b_NoFlikerScale[] = {
4241 {} 4254 {}
4242}; 4255};
4243 4256
4244/* mi0360soc and pb0330 from vm30x.inf for 0ac8:301b and 0ac8:303b 07/02/13 */ 4257/* mt9v111 (mi0360soc) and pb0330 from vm30x.inf 0ac8:301b 07/02/13 */
4245static const struct usb_action mi0360soc_Initial[] = { /* 640x480 */ 4258static const struct usb_action mt9v111_1_Initial[] = { /* 640x480 */
4246 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, 4259 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL},
4247 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING}, 4260 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING},
4248 {0xa0, 0x0a, ZC3XX_R010_CMOSSENSORSELECT}, 4261 {0xa0, 0x0a, ZC3XX_R010_CMOSSENSORSELECT},
@@ -4253,14 +4266,14 @@ static const struct usb_action mi0360soc_Initial[] = { /* 640x480 */
4253 {0xa0, 0xe0, ZC3XX_R006_FRAMEHEIGHTLOW}, 4266 {0xa0, 0xe0, ZC3XX_R006_FRAMEHEIGHTLOW},
4254 {0xa0, 0xdc, ZC3XX_R08B_I2CDEVICEADDR}, 4267 {0xa0, 0xdc, ZC3XX_R08B_I2CDEVICEADDR},
4255 {0xa0, 0x01, ZC3XX_R001_SYSTEMOPERATING}, 4268 {0xa0, 0x01, ZC3XX_R001_SYSTEMOPERATING},
4256 {0xa0, 0x07, ZC3XX_R012_VIDEOCONTROLFUNC}, /*jfm: was 03*/ 4269 {0xa0, 0x07, ZC3XX_R012_VIDEOCONTROLFUNC},
4257/* {0xa0, 0x01, ZC3XX_R012_VIDEOCONTROLFUNC}, */
4258 {0xa0, 0x00, ZC3XX_R098_WINYSTARTLOW}, 4270 {0xa0, 0x00, ZC3XX_R098_WINYSTARTLOW},
4259 {0xa0, 0x00, ZC3XX_R09A_WINXSTARTLOW}, 4271 {0xa0, 0x00, ZC3XX_R09A_WINXSTARTLOW},
4260 {0xa0, 0x00, ZC3XX_R11A_FIRSTYLOW}, 4272 {0xa0, 0x00, ZC3XX_R11A_FIRSTYLOW},
4261 {0xa0, 0x00, ZC3XX_R11C_FIRSTXLOW}, 4273 {0xa0, 0x00, ZC3XX_R11C_FIRSTXLOW},
4262 {0xa0, 0xdc, ZC3XX_R08B_I2CDEVICEADDR}, 4274 {0xa0, 0xdc, ZC3XX_R08B_I2CDEVICEADDR},
4263 {0xdd, 0x00, 0x0200}, 4275 {0xdd, 0x00, 0x0200},
4276 {0xa0, 0x05, ZC3XX_R012_VIDEOCONTROLFUNC},
4264 {0xaa, 0x01, 0x0001}, 4277 {0xaa, 0x01, 0x0001},
4265 {0xaa, 0x06, 0x0000}, 4278 {0xaa, 0x06, 0x0000},
4266 {0xaa, 0x08, 0x0483}, 4279 {0xaa, 0x08, 0x0483},
@@ -4270,18 +4283,18 @@ static const struct usb_action mi0360soc_Initial[] = { /* 640x480 */
4270 {0xaa, 0x03, 0x01e5}, /*jfm: was 01e7*/ 4283 {0xaa, 0x03, 0x01e5}, /*jfm: was 01e7*/
4271 {0xaa, 0x04, 0x0285}, /*jfm: was 0287*/ 4284 {0xaa, 0x04, 0x0285}, /*jfm: was 0287*/
4272 {0xaa, 0x07, 0x3002}, 4285 {0xaa, 0x07, 0x3002},
4273 {0xaa, 0x20, 0x5100}, /*jfm: was 1100*/ 4286 {0xaa, 0x20, 0x5100},
4274 {0xaa, 0x35, 0x507f}, /*jfm: was 0050*/ 4287 {0xaa, 0x35, 0x507f},
4275 {0xaa, 0x30, 0x0005}, 4288 {0xaa, 0x30, 0x0005},
4276 {0xaa, 0x31, 0x0000}, 4289 {0xaa, 0x31, 0x0000},
4277 {0xaa, 0x58, 0x0078}, 4290 {0xaa, 0x58, 0x0078},
4278 {0xaa, 0x62, 0x0411}, 4291 {0xaa, 0x62, 0x0411},
4279 {0xaa, 0x2b, 0x0028}, 4292 {0xaa, 0x2b, 0x007f},
4280 {0xaa, 0x2c, 0x007f}, /*jfm: was 0030*/ 4293 {0xaa, 0x2c, 0x007f}, /*jfm: was 0030*/
4281 {0xaa, 0x2d, 0x007f}, /*jfm: was 0030*/ 4294 {0xaa, 0x2d, 0x007f}, /*jfm: was 0030*/
4282 {0xaa, 0x2e, 0x007f}, /*jfm: was 0030*/ 4295 {0xaa, 0x2e, 0x007f}, /*jfm: was 0030*/
4283 {0xa0, 0x10, ZC3XX_R087_EXPTIMEMID}, 4296 {0xa0, 0x10, ZC3XX_R087_EXPTIMEMID},
4284 {0xa0, 0xb7, ZC3XX_R101_SENSORCORRECTION}, /*jfm: was 37*/ 4297 {0xa0, 0xb7, ZC3XX_R101_SENSORCORRECTION},
4285 {0xa0, 0x05, ZC3XX_R012_VIDEOCONTROLFUNC}, 4298 {0xa0, 0x05, ZC3XX_R012_VIDEOCONTROLFUNC},
4286 {0xa0, 0x0d, ZC3XX_R100_OPERATIONMODE}, 4299 {0xa0, 0x0d, ZC3XX_R100_OPERATIONMODE},
4287 {0xa0, 0x06, ZC3XX_R189_AWBSTATUS}, 4300 {0xa0, 0x06, ZC3XX_R189_AWBSTATUS},
@@ -4291,12 +4304,12 @@ static const struct usb_action mi0360soc_Initial[] = { /* 640x480 */
4291 {0xa0, 0x08, ZC3XX_R250_DEADPIXELSMODE}, 4304 {0xa0, 0x08, ZC3XX_R250_DEADPIXELSMODE},
4292 {0xa0, 0x08, ZC3XX_R301_EEPROMACCESS}, 4305 {0xa0, 0x08, ZC3XX_R301_EEPROMACCESS},
4293 {0xa0, 0x60, ZC3XX_R1A8_DIGITALGAIN}, 4306 {0xa0, 0x60, ZC3XX_R1A8_DIGITALGAIN},
4294 {0xa0, 0x6c, ZC3XX_R18D_YTARGET}, /* jfm: was 78 */ 4307 {0xa0, 0x6c, ZC3XX_R18D_YTARGET},
4295 {0xa0, 0x61, ZC3XX_R116_RGAIN}, 4308 {0xa0, 0x61, ZC3XX_R116_RGAIN},
4296 {0xa0, 0x65, ZC3XX_R118_BGAIN}, 4309 {0xa0, 0x65, ZC3XX_R118_BGAIN},
4297 {} 4310 {}
4298}; 4311};
4299static const struct usb_action mi0360soc_InitialScale[] = { /* 320x240 */ 4312static const struct usb_action mt9v111_1_InitialScale[] = { /* 320x240 */
4300 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, 4313 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL},
4301 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING}, 4314 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING},
4302 {0xa0, 0x0a, ZC3XX_R010_CMOSSENSORSELECT}, 4315 {0xa0, 0x0a, ZC3XX_R010_CMOSSENSORSELECT},
@@ -4307,14 +4320,14 @@ static const struct usb_action mi0360soc_InitialScale[] = { /* 320x240 */
4307 {0xa0, 0xe0, ZC3XX_R006_FRAMEHEIGHTLOW}, 4320 {0xa0, 0xe0, ZC3XX_R006_FRAMEHEIGHTLOW},
4308 {0xa0, 0xdc, ZC3XX_R08B_I2CDEVICEADDR}, 4321 {0xa0, 0xdc, ZC3XX_R08B_I2CDEVICEADDR},
4309 {0xa0, 0x01, ZC3XX_R001_SYSTEMOPERATING}, 4322 {0xa0, 0x01, ZC3XX_R001_SYSTEMOPERATING},
4310 {0xa0, 0x07, ZC3XX_R012_VIDEOCONTROLFUNC}, /*jfm: was 03*/ 4323 {0xa0, 0x07, ZC3XX_R012_VIDEOCONTROLFUNC},
4311/* {0xa0, 0x01, ZC3XX_R012_VIDEOCONTROLFUNC}, */
4312 {0xa0, 0x00, ZC3XX_R098_WINYSTARTLOW}, 4324 {0xa0, 0x00, ZC3XX_R098_WINYSTARTLOW},
4313 {0xa0, 0x00, ZC3XX_R09A_WINXSTARTLOW}, 4325 {0xa0, 0x00, ZC3XX_R09A_WINXSTARTLOW},
4314 {0xa0, 0x00, ZC3XX_R11A_FIRSTYLOW}, 4326 {0xa0, 0x00, ZC3XX_R11A_FIRSTYLOW},
4315 {0xa0, 0x00, ZC3XX_R11C_FIRSTXLOW}, 4327 {0xa0, 0x00, ZC3XX_R11C_FIRSTXLOW},
4316 {0xa0, 0xdc, ZC3XX_R08B_I2CDEVICEADDR}, 4328 {0xa0, 0xdc, ZC3XX_R08B_I2CDEVICEADDR},
4317 {0xdd, 0x00, 0x0200}, 4329 {0xdd, 0x00, 0x0200},
4330 {0xa0, 0x05, ZC3XX_R012_VIDEOCONTROLFUNC},
4318 {0xaa, 0x01, 0x0001}, 4331 {0xaa, 0x01, 0x0001},
4319 {0xaa, 0x06, 0x0000}, 4332 {0xaa, 0x06, 0x0000},
4320 {0xaa, 0x08, 0x0483}, 4333 {0xaa, 0x08, 0x0483},
@@ -4324,7 +4337,7 @@ static const struct usb_action mi0360soc_InitialScale[] = { /* 320x240 */
4324 {0xaa, 0x03, 0x01e7}, 4337 {0xaa, 0x03, 0x01e7},
4325 {0xaa, 0x04, 0x0287}, 4338 {0xaa, 0x04, 0x0287},
4326 {0xaa, 0x07, 0x3002}, 4339 {0xaa, 0x07, 0x3002},
4327 {0xaa, 0x20, 0x5100}, /*jfm: was 1100*/ 4340 {0xaa, 0x20, 0x5100},
4328 {0xaa, 0x35, 0x007f}, /*jfm: was 0050*/ 4341 {0xaa, 0x35, 0x007f}, /*jfm: was 0050*/
4329 {0xaa, 0x30, 0x0005}, 4342 {0xaa, 0x30, 0x0005},
4330 {0xaa, 0x31, 0x0000}, 4343 {0xaa, 0x31, 0x0000},
@@ -4335,7 +4348,7 @@ static const struct usb_action mi0360soc_InitialScale[] = { /* 320x240 */
4335 {0xaa, 0x2d, 0x007f}, /*jfm: was 30*/ 4348 {0xaa, 0x2d, 0x007f}, /*jfm: was 30*/
4336 {0xaa, 0x2e, 0x007f}, /*jfm: was 28*/ 4349 {0xaa, 0x2e, 0x007f}, /*jfm: was 28*/
4337 {0xa0, 0x10, ZC3XX_R087_EXPTIMEMID}, 4350 {0xa0, 0x10, ZC3XX_R087_EXPTIMEMID},
4338 {0xa0, 0xb7, ZC3XX_R101_SENSORCORRECTION}, /*jfm: was 37*/ 4351 {0xa0, 0xb7, ZC3XX_R101_SENSORCORRECTION},
4339 {0xa0, 0x05, ZC3XX_R012_VIDEOCONTROLFUNC}, 4352 {0xa0, 0x05, ZC3XX_R012_VIDEOCONTROLFUNC},
4340 {0xa0, 0x0d, ZC3XX_R100_OPERATIONMODE}, 4353 {0xa0, 0x0d, ZC3XX_R100_OPERATIONMODE},
4341 {0xa0, 0x06, ZC3XX_R189_AWBSTATUS}, 4354 {0xa0, 0x06, ZC3XX_R189_AWBSTATUS},
@@ -4345,12 +4358,12 @@ static const struct usb_action mi0360soc_InitialScale[] = { /* 320x240 */
4345 {0xa0, 0x08, ZC3XX_R250_DEADPIXELSMODE}, 4358 {0xa0, 0x08, ZC3XX_R250_DEADPIXELSMODE},
4346 {0xa0, 0x08, ZC3XX_R301_EEPROMACCESS}, 4359 {0xa0, 0x08, ZC3XX_R301_EEPROMACCESS},
4347 {0xa0, 0x60, ZC3XX_R1A8_DIGITALGAIN}, 4360 {0xa0, 0x60, ZC3XX_R1A8_DIGITALGAIN},
4348 {0xa0, 0x6c, ZC3XX_R18D_YTARGET}, /*jfm: was 78*/ 4361 {0xa0, 0x6c, ZC3XX_R18D_YTARGET},
4349 {0xa0, 0x61, ZC3XX_R116_RGAIN}, 4362 {0xa0, 0x61, ZC3XX_R116_RGAIN},
4350 {0xa0, 0x65, ZC3XX_R118_BGAIN}, 4363 {0xa0, 0x65, ZC3XX_R118_BGAIN},
4351 {} 4364 {}
4352}; 4365};
4353static const struct usb_action mi360soc_AE50HZ[] = { 4366static const struct usb_action mt9v111_1_AE50HZ[] = {
4354 {0xa0, 0x00, ZC3XX_R180_AUTOCORRECTENABLE}, 4367 {0xa0, 0x00, ZC3XX_R180_AUTOCORRECTENABLE},
4355 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, 4368 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS},
4356 {0xbb, 0x00, 0x0562}, 4369 {0xbb, 0x00, 0x0562},
@@ -4373,7 +4386,7 @@ static const struct usb_action mi360soc_AE50HZ[] = {
4373 {0xa0, 0x42, ZC3XX_R180_AUTOCORRECTENABLE}, 4386 {0xa0, 0x42, ZC3XX_R180_AUTOCORRECTENABLE},
4374 {} 4387 {}
4375}; 4388};
4376static const struct usb_action mi360soc_AE50HZScale[] = { 4389static const struct usb_action mt9v111_1_AE50HZScale[] = {
4377 {0xa0, 0x00, ZC3XX_R180_AUTOCORRECTENABLE}, 4390 {0xa0, 0x00, ZC3XX_R180_AUTOCORRECTENABLE},
4378 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, 4391 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS},
4379 {0xbb, 0x00, 0x0509}, 4392 {0xbb, 0x00, 0x0509},
@@ -4395,11 +4408,11 @@ static const struct usb_action mi360soc_AE50HZScale[] = {
4395 {0xa0, 0x42, ZC3XX_R180_AUTOCORRECTENABLE}, 4408 {0xa0, 0x42, ZC3XX_R180_AUTOCORRECTENABLE},
4396 {} 4409 {}
4397}; 4410};
4398static const struct usb_action mi360soc_AE60HZ[] = { 4411static const struct usb_action mt9v111_1_AE60HZ[] = {
4399 {0xa0, 0x00, ZC3XX_R180_AUTOCORRECTENABLE}, 4412 {0xa0, 0x00, ZC3XX_R180_AUTOCORRECTENABLE},
4400 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, 4413 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS},
4401 {0xbb, 0x00, 0x053d}, 4414 {0xaa, 0x05, 0x003d},
4402 {0xbb, 0x01, 0x096e}, 4415 {0xaa, 0x09, 0x016e},
4403 {0xa0, 0x00, ZC3XX_R190_EXPOSURELIMITHIGH}, 4416 {0xa0, 0x00, ZC3XX_R190_EXPOSURELIMITHIGH},
4404 {0xa0, 0x07, ZC3XX_R191_EXPOSURELIMITMID}, 4417 {0xa0, 0x07, ZC3XX_R191_EXPOSURELIMITMID},
4405 {0xa0, 0xdd, ZC3XX_R192_EXPOSURELIMITLOW}, 4418 {0xa0, 0xdd, ZC3XX_R192_EXPOSURELIMITLOW},
@@ -4418,7 +4431,7 @@ static const struct usb_action mi360soc_AE60HZ[] = {
4418 {0xa0, 0x42, ZC3XX_R180_AUTOCORRECTENABLE}, 4431 {0xa0, 0x42, ZC3XX_R180_AUTOCORRECTENABLE},
4419 {} 4432 {}
4420}; 4433};
4421static const struct usb_action mi360soc_AE60HZScale[] = { 4434static const struct usb_action mt9v111_1_AE60HZScale[] = {
4422 {0xa0, 0x00, ZC3XX_R180_AUTOCORRECTENABLE}, 4435 {0xa0, 0x00, ZC3XX_R180_AUTOCORRECTENABLE},
4423 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, 4436 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS},
4424 {0xbb, 0x00, 0x0509}, 4437 {0xbb, 0x00, 0x0509},
@@ -4440,7 +4453,7 @@ static const struct usb_action mi360soc_AE60HZScale[] = {
4440 {0xa0, 0x42, ZC3XX_R180_AUTOCORRECTENABLE}, 4453 {0xa0, 0x42, ZC3XX_R180_AUTOCORRECTENABLE},
4441 {} 4454 {}
4442}; 4455};
4443static const struct usb_action mi360soc_AENoFliker[] = { 4456static const struct usb_action mt9v111_1_AENoFliker[] = {
4444 {0xa0, 0x00, ZC3XX_R180_AUTOCORRECTENABLE}, 4457 {0xa0, 0x00, ZC3XX_R180_AUTOCORRECTENABLE},
4445 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, 4458 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS},
4446 {0xbb, 0x00, 0x0509}, 4459 {0xbb, 0x00, 0x0509},
@@ -4463,7 +4476,7 @@ static const struct usb_action mi360soc_AENoFliker[] = {
4463 {0xa0, 0x42, ZC3XX_R180_AUTOCORRECTENABLE}, 4476 {0xa0, 0x42, ZC3XX_R180_AUTOCORRECTENABLE},
4464 {} 4477 {}
4465}; 4478};
4466static const struct usb_action mi360soc_AENoFlikerScale[] = { 4479static const struct usb_action mt9v111_1_AENoFlikerScale[] = {
4467 {0xa0, 0x00, ZC3XX_R180_AUTOCORRECTENABLE}, 4480 {0xa0, 0x00, ZC3XX_R180_AUTOCORRECTENABLE},
4468 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, 4481 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS},
4469 {0xbb, 0x00, 0x0534}, 4482 {0xbb, 0x00, 0x0534},
@@ -4486,6 +4499,251 @@ static const struct usb_action mi360soc_AENoFlikerScale[] = {
4486 {0xa0, 0x42, ZC3XX_R180_AUTOCORRECTENABLE}, 4499 {0xa0, 0x42, ZC3XX_R180_AUTOCORRECTENABLE},
4487 {} 4500 {}
4488}; 4501};
4502/* from usbvm303.inf 0ac8:303b 07/03/25 (3 - tas5130c) */
4503static const struct usb_action mt9v111_3_Initial[] = {
4504 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL},
4505 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING},
4506 {0xa0, 0x0a, ZC3XX_R010_CMOSSENSORSELECT},
4507 {0xa0, 0x04, ZC3XX_R002_CLOCKSELECT},
4508 {0xa0, 0x02, ZC3XX_R003_FRAMEWIDTHHIGH},
4509 {0xa0, 0x80, ZC3XX_R004_FRAMEWIDTHLOW},
4510 {0xa0, 0x01, ZC3XX_R005_FRAMEHEIGHTHIGH},
4511 {0xa0, 0xe0, ZC3XX_R006_FRAMEHEIGHTLOW},
4512 {0xa0, 0xdc, ZC3XX_R08B_I2CDEVICEADDR},
4513 {0xa0, 0x01, ZC3XX_R001_SYSTEMOPERATING},
4514 {0xa0, 0x07, ZC3XX_R012_VIDEOCONTROLFUNC},
4515 {0xa0, 0x00, ZC3XX_R098_WINYSTARTLOW},
4516 {0xa0, 0x00, ZC3XX_R09A_WINXSTARTLOW},
4517 {0xa0, 0x00, ZC3XX_R11A_FIRSTYLOW},
4518 {0xa0, 0x00, ZC3XX_R11C_FIRSTXLOW},
4519 {0xa0, 0xdc, ZC3XX_R08B_I2CDEVICEADDR},
4520 {0xdd, 0x00, 0x0200},
4521 {0xa0, 0x05, ZC3XX_R012_VIDEOCONTROLFUNC},
4522 {0xaa, 0x01, 0x0001}, /* select IFP/SOC registers */
4523 {0xaa, 0x06, 0x0000}, /* operating mode control */
4524 {0xaa, 0x08, 0x0483}, /* output format control */
4525 /* H red first, V red or blue first,
4526 * raw Bayer, auto flicker */
4527 {0xaa, 0x01, 0x0004}, /* select sensor core registers */
4528 {0xaa, 0x08, 0x0006}, /* row start */
4529 {0xaa, 0x02, 0x0011}, /* column start */
4530 {0xaa, 0x03, 0x01e5}, /* window height - 1 */
4531 {0xaa, 0x04, 0x0285}, /* window width - 1 */
4532 {0xaa, 0x07, 0x3002}, /* output control */
4533 {0xaa, 0x20, 0x1100}, /* read mode: bits 8 & 12 (?) */
4534 {0xaa, 0x35, 0x007f}, /* global gain */
4535 {0xaa, 0x30, 0x0005},
4536 {0xaa, 0x31, 0x0000},
4537 {0xaa, 0x58, 0x0078},
4538 {0xaa, 0x62, 0x0411},
4539 {0xaa, 0x2b, 0x007f}, /* green1 gain */
4540 {0xaa, 0x2c, 0x007f}, /* blue gain */
4541 {0xaa, 0x2d, 0x007f}, /* red gain */
4542 {0xaa, 0x2e, 0x007f}, /* green2 gain */
4543 {0xa0, 0x10, ZC3XX_R087_EXPTIMEMID},
4544 {0xa0, 0x37, ZC3XX_R101_SENSORCORRECTION},
4545 {0xa0, 0x05, ZC3XX_R012_VIDEOCONTROLFUNC},
4546 {0xa0, 0x0d, ZC3XX_R100_OPERATIONMODE},
4547 {0xa0, 0x06, ZC3XX_R189_AWBSTATUS},
4548 {0xa0, 0x00, 0x01ad},
4549 {0xa0, 0x03, ZC3XX_R1C5_SHARPNESSMODE},
4550 {0xa0, 0x13, ZC3XX_R1CB_SHARPNESS05},
4551 {0xa0, 0x08, ZC3XX_R250_DEADPIXELSMODE},
4552 {0xa0, 0x08, ZC3XX_R301_EEPROMACCESS},
4553 {0xa0, 0x60, ZC3XX_R1A8_DIGITALGAIN},
4554 {0xa0, 0x80, ZC3XX_R18D_YTARGET},
4555 {0xa0, 0x61, ZC3XX_R116_RGAIN},
4556 {0xa0, 0x65, ZC3XX_R118_BGAIN},
4557 {}
4558};
4559static const struct usb_action mt9v111_3_InitialScale[] = {
4560 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL},
4561 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING},
4562 {0xa0, 0x0a, ZC3XX_R010_CMOSSENSORSELECT},
4563 {0xa0, 0x10, ZC3XX_R002_CLOCKSELECT},
4564 {0xa0, 0x02, ZC3XX_R003_FRAMEWIDTHHIGH},
4565 {0xa0, 0x80, ZC3XX_R004_FRAMEWIDTHLOW},
4566 {0xa0, 0x01, ZC3XX_R005_FRAMEHEIGHTHIGH},
4567 {0xa0, 0xe0, ZC3XX_R006_FRAMEHEIGHTLOW},
4568 {0xa0, 0xdc, ZC3XX_R08B_I2CDEVICEADDR},
4569 {0xa0, 0x01, ZC3XX_R001_SYSTEMOPERATING},
4570 {0xa0, 0x07, ZC3XX_R012_VIDEOCONTROLFUNC},
4571 {0xa0, 0x00, ZC3XX_R098_WINYSTARTLOW},
4572 {0xa0, 0x00, ZC3XX_R09A_WINXSTARTLOW},
4573 {0xa0, 0x00, ZC3XX_R11A_FIRSTYLOW},
4574 {0xa0, 0x00, ZC3XX_R11C_FIRSTXLOW},
4575 {0xa0, 0xdc, ZC3XX_R08B_I2CDEVICEADDR},
4576 {0xdd, 0x00, 0x0200},
4577 {0xa0, 0x05, ZC3XX_R012_VIDEOCONTROLFUNC},
4578 {0xaa, 0x01, 0x0001},
4579 {0xaa, 0x06, 0x0000},
4580 {0xaa, 0x08, 0x0483},
4581 {0xaa, 0x01, 0x0004},
4582 {0xaa, 0x08, 0x0006},
4583 {0xaa, 0x02, 0x0011},
4584 {0xaa, 0x03, 0x01e7},
4585 {0xaa, 0x04, 0x0287},
4586 {0xaa, 0x07, 0x3002},
4587 {0xaa, 0x20, 0x1100},
4588 {0xaa, 0x35, 0x007f},
4589 {0xaa, 0x30, 0x0005},
4590 {0xaa, 0x31, 0x0000},
4591 {0xaa, 0x58, 0x0078},
4592 {0xaa, 0x62, 0x0411},
4593 {0xaa, 0x2b, 0x007f},
4594 {0xaa, 0x2c, 0x007f},
4595 {0xaa, 0x2d, 0x007f},
4596 {0xaa, 0x2e, 0x007f},
4597 {0xa0, 0x10, ZC3XX_R087_EXPTIMEMID},
4598 {0xa0, 0x37, ZC3XX_R101_SENSORCORRECTION},
4599 {0xa0, 0x05, ZC3XX_R012_VIDEOCONTROLFUNC},
4600 {0xa0, 0x0d, ZC3XX_R100_OPERATIONMODE},
4601 {0xa0, 0x06, ZC3XX_R189_AWBSTATUS},
4602 {0xa0, 0x00, 0x01ad},
4603 {0xa0, 0x03, ZC3XX_R1C5_SHARPNESSMODE},
4604 {0xa0, 0x13, ZC3XX_R1CB_SHARPNESS05},
4605 {0xa0, 0x08, ZC3XX_R250_DEADPIXELSMODE},
4606 {0xa0, 0x08, ZC3XX_R301_EEPROMACCESS},
4607 {0xa0, 0x60, ZC3XX_R1A8_DIGITALGAIN},
4608 {0xa0, 0x80, ZC3XX_R18D_YTARGET},
4609 {0xa0, 0x61, ZC3XX_R116_RGAIN},
4610 {0xa0, 0x65, ZC3XX_R118_BGAIN},
4611 {}
4612};
4613static const struct usb_action mt9v111_3_AE50HZ[] = {
4614 {0xa0, 0x00, ZC3XX_R180_AUTOCORRECTENABLE},
4615 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS},
4616 {0xaa, 0x05, 0x0009}, /* horizontal blanking */
4617 {0xaa, 0x09, 0x01ce}, /* shutter width */
4618 {0xa0, 0x00, ZC3XX_R190_EXPOSURELIMITHIGH},
4619 {0xa0, 0x07, ZC3XX_R191_EXPOSURELIMITMID},
4620 {0xa0, 0xd2, ZC3XX_R192_EXPOSURELIMITLOW},
4621 {0xa0, 0x00, ZC3XX_R195_ANTIFLICKERHIGH},
4622 {0xa0, 0x00, ZC3XX_R196_ANTIFLICKERMID},
4623 {0xa0, 0x9a, ZC3XX_R197_ANTIFLICKERLOW},
4624 {0xa0, 0x0e, ZC3XX_R18C_AEFREEZE},
4625 {0xa0, 0x1c, ZC3XX_R18F_AEUNFREEZE},
4626 {0xa0, 0x14, ZC3XX_R1A9_DIGITALLIMITDIFF},
4627 {0xa0, 0x24, ZC3XX_R1AA_DIGITALGAINSTEP},
4628 {0xa0, 0xd7, ZC3XX_R01D_HSYNC_0},
4629 {0xa0, 0xf4, ZC3XX_R01E_HSYNC_1},
4630 {0xa0, 0xf9, ZC3XX_R01F_HSYNC_2},
4631 {0xa0, 0xff, ZC3XX_R020_HSYNC_3},
4632 {0xa0, 0x42, ZC3XX_R180_AUTOCORRECTENABLE},
4633 {}
4634};
4635static const struct usb_action mt9v111_3_AE50HZScale[] = {
4636 {0xa0, 0x00, ZC3XX_R180_AUTOCORRECTENABLE},
4637 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS},
4638 {0xaa, 0x05, 0x0009},
4639 {0xaa, 0x09, 0x01ce},
4640 {0xa0, 0x00, ZC3XX_R190_EXPOSURELIMITHIGH},
4641 {0xa0, 0x07, ZC3XX_R191_EXPOSURELIMITMID},
4642 {0xa0, 0xd2, ZC3XX_R192_EXPOSURELIMITLOW},
4643 {0xa0, 0x00, ZC3XX_R195_ANTIFLICKERHIGH},
4644 {0xa0, 0x00, ZC3XX_R196_ANTIFLICKERMID},
4645 {0xa0, 0x9a, ZC3XX_R197_ANTIFLICKERLOW},
4646 {0xa0, 0x0e, ZC3XX_R18C_AEFREEZE},
4647 {0xa0, 0x1c, ZC3XX_R18F_AEUNFREEZE},
4648 {0xa0, 0x14, ZC3XX_R1A9_DIGITALLIMITDIFF},
4649 {0xa0, 0x24, ZC3XX_R1AA_DIGITALGAINSTEP},
4650 {0xa0, 0xd7, ZC3XX_R01D_HSYNC_0},
4651 {0xa0, 0xf4, ZC3XX_R01E_HSYNC_1},
4652 {0xa0, 0xf9, ZC3XX_R01F_HSYNC_2},
4653 {0xa0, 0xff, ZC3XX_R020_HSYNC_3},
4654 {0xa0, 0x42, ZC3XX_R180_AUTOCORRECTENABLE},
4655 {}
4656};
4657static const struct usb_action mt9v111_3_AE60HZ[] = {
4658 {0xa0, 0x00, ZC3XX_R180_AUTOCORRECTENABLE},
4659 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS},
4660 {0xaa, 0x05, 0x0009},
4661 {0xaa, 0x09, 0x0083},
4662 {0xa0, 0x00, ZC3XX_R190_EXPOSURELIMITHIGH},
4663 {0xa0, 0x07, ZC3XX_R191_EXPOSURELIMITMID},
4664 {0xa0, 0x8f, ZC3XX_R192_EXPOSURELIMITLOW},
4665 {0xa0, 0x00, ZC3XX_R195_ANTIFLICKERHIGH},
4666 {0xa0, 0x00, ZC3XX_R196_ANTIFLICKERMID},
4667 {0xa0, 0x81, ZC3XX_R197_ANTIFLICKERLOW},
4668 {0xa0, 0x0e, ZC3XX_R18C_AEFREEZE},
4669 {0xa0, 0x1c, ZC3XX_R18F_AEUNFREEZE},
4670 {0xa0, 0x14, ZC3XX_R1A9_DIGITALLIMITDIFF},
4671 {0xa0, 0x24, ZC3XX_R1AA_DIGITALGAINSTEP},
4672 {0xa0, 0xd7, ZC3XX_R01D_HSYNC_0},
4673 {0xa0, 0xf4, ZC3XX_R01E_HSYNC_1},
4674 {0xa0, 0xf9, ZC3XX_R01F_HSYNC_2},
4675 {0xa0, 0xff, ZC3XX_R020_HSYNC_3},
4676 {0xa0, 0x42, ZC3XX_R180_AUTOCORRECTENABLE},
4677 {}
4678};
4679static const struct usb_action mt9v111_3_AE60HZScale[] = {
4680 {0xa0, 0x00, ZC3XX_R180_AUTOCORRECTENABLE},
4681 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS},
4682 {0xaa, 0x05, 0x0009},
4683 {0xaa, 0x09, 0x0083},
4684 {0xa0, 0x00, ZC3XX_R190_EXPOSURELIMITHIGH},
4685 {0xa0, 0x07, ZC3XX_R191_EXPOSURELIMITMID},
4686 {0xa0, 0x8f, ZC3XX_R192_EXPOSURELIMITLOW},
4687 {0xa0, 0x00, ZC3XX_R195_ANTIFLICKERHIGH},
4688 {0xa0, 0x00, ZC3XX_R196_ANTIFLICKERMID},
4689 {0xa0, 0x81, ZC3XX_R197_ANTIFLICKERLOW},
4690 {0xa0, 0x0e, ZC3XX_R18C_AEFREEZE},
4691 {0xa0, 0x1c, ZC3XX_R18F_AEUNFREEZE},
4692 {0xa0, 0x14, ZC3XX_R1A9_DIGITALLIMITDIFF},
4693 {0xa0, 0x24, ZC3XX_R1AA_DIGITALGAINSTEP},
4694 {0xa0, 0xd7, ZC3XX_R01D_HSYNC_0},
4695 {0xa0, 0xf4, ZC3XX_R01E_HSYNC_1},
4696 {0xa0, 0xf9, ZC3XX_R01F_HSYNC_2},
4697 {0xa0, 0xff, ZC3XX_R020_HSYNC_3},
4698 {0xa0, 0x42, ZC3XX_R180_AUTOCORRECTENABLE},
4699 {}
4700};
4701static const struct usb_action mt9v111_3_AENoFliker[] = {
4702 {0xa0, 0x00, ZC3XX_R180_AUTOCORRECTENABLE},
4703 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS},
4704 {0xaa, 0x05, 0x0034},
4705 {0xaa, 0x09, 0x0260},
4706 {0xa0, 0x00, ZC3XX_R190_EXPOSURELIMITHIGH},
4707 {0xa0, 0x07, ZC3XX_R191_EXPOSURELIMITMID},
4708 {0xa0, 0xf0, ZC3XX_R192_EXPOSURELIMITLOW},
4709 {0xa0, 0x00, ZC3XX_R195_ANTIFLICKERHIGH},
4710 {0xa0, 0x00, ZC3XX_R196_ANTIFLICKERMID},
4711 {0xa0, 0x04, ZC3XX_R197_ANTIFLICKERLOW},
4712 {0xa0, 0x0e, ZC3XX_R18C_AEFREEZE},
4713 {0xa0, 0x1c, ZC3XX_R18F_AEUNFREEZE},
4714 {0xa0, 0x00, ZC3XX_R1A9_DIGITALLIMITDIFF},
4715 {0xa0, 0x00, ZC3XX_R1AA_DIGITALGAINSTEP},
4716 {0xa0, 0x34, ZC3XX_R01D_HSYNC_0},
4717 {0xa0, 0x60, ZC3XX_R01E_HSYNC_1},
4718 {0xa0, 0x90, ZC3XX_R01F_HSYNC_2},
4719 {0xa0, 0xe0, ZC3XX_R020_HSYNC_3},
4720 {0xa0, 0x60, ZC3XX_R11D_GLOBALGAIN},
4721 {0xa0, 0x42, ZC3XX_R180_AUTOCORRECTENABLE},
4722 {}
4723};
4724static const struct usb_action mt9v111_3_AENoFlikerScale[] = {
4725 {0xa0, 0x00, ZC3XX_R180_AUTOCORRECTENABLE},
4726 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS},
4727 {0xaa, 0x05, 0x0034},
4728 {0xaa, 0x09, 0x0260},
4729 {0xa0, 0x00, ZC3XX_R190_EXPOSURELIMITHIGH},
4730 {0xa0, 0x07, ZC3XX_R191_EXPOSURELIMITMID},
4731 {0xa0, 0xf0, ZC3XX_R192_EXPOSURELIMITLOW},
4732 {0xa0, 0x00, ZC3XX_R195_ANTIFLICKERHIGH},
4733 {0xa0, 0x00, ZC3XX_R196_ANTIFLICKERMID},
4734 {0xa0, 0x04, ZC3XX_R197_ANTIFLICKERLOW},
4735 {0xa0, 0x0e, ZC3XX_R18C_AEFREEZE},
4736 {0xa0, 0x1c, ZC3XX_R18F_AEUNFREEZE},
4737 {0xa0, 0x00, ZC3XX_R1A9_DIGITALLIMITDIFF},
4738 {0xa0, 0x00, ZC3XX_R1AA_DIGITALGAINSTEP},
4739 {0xa0, 0x34, ZC3XX_R01D_HSYNC_0},
4740 {0xa0, 0x60, ZC3XX_R01E_HSYNC_1},
4741 {0xa0, 0x90, ZC3XX_R01F_HSYNC_2},
4742 {0xa0, 0xe0, ZC3XX_R020_HSYNC_3},
4743 {0xa0, 0x60, ZC3XX_R11D_GLOBALGAIN},
4744 {0xa0, 0x42, ZC3XX_R180_AUTOCORRECTENABLE},
4745 {}
4746};
4489 4747
4490static const struct usb_action pb0330_Initial[] = { /* 640x480 */ 4748static const struct usb_action pb0330_Initial[] = { /* 640x480 */
4491 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, 4749 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL},
@@ -4928,419 +5186,7 @@ static const struct usb_action po2030_NoFliker[] = {
4928 {} 5186 {}
4929}; 5187};
4930 5188
4931/* TEST */ 5189static const struct usb_action tas5130c_InitialScale[] = { /* 320x240 */
4932static const struct usb_action tas5130cK_InitialScale[] = {
4933 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL},
4934 {0xa0, 0x01, 0x003b},
4935 {0xa0, 0x0e, 0x003a},
4936 {0xa0, 0x01, 0x0038},
4937 {0xa0, 0x0b, 0x0039},
4938 {0xa0, 0x00, 0x0038},
4939 {0xa0, 0x0b, 0x0039},
4940 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL},
4941 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING},
4942 {0xa0, 0x0a, ZC3XX_R010_CMOSSENSORSELECT},
4943 {0xa0, 0x10, ZC3XX_R002_CLOCKSELECT},
4944 {0xa0, 0x02, ZC3XX_R003_FRAMEWIDTHHIGH},
4945 {0xa0, 0x80, ZC3XX_R004_FRAMEWIDTHLOW},
4946 {0xa0, 0x01, ZC3XX_R005_FRAMEHEIGHTHIGH},
4947 {0xa0, 0xe0, ZC3XX_R006_FRAMEHEIGHTLOW},
4948 {0xa0, 0xdc, ZC3XX_R08B_I2CDEVICEADDR},
4949 {0xa0, 0x01, ZC3XX_R001_SYSTEMOPERATING},
4950 {0xa0, 0x07, ZC3XX_R012_VIDEOCONTROLFUNC},
4951 {0xa0, 0x00, ZC3XX_R098_WINYSTARTLOW},
4952 {0xa0, 0x00, ZC3XX_R09A_WINXSTARTLOW},
4953 {0xa0, 0x00, ZC3XX_R11A_FIRSTYLOW},
4954 {0xa0, 0x00, ZC3XX_R11C_FIRSTXLOW},
4955 {0xa0, 0xdc, ZC3XX_R08B_I2CDEVICEADDR},
4956 {0xa0, 0x05, ZC3XX_R012_VIDEOCONTROLFUNC},
4957 {0xa0, 0x01, ZC3XX_R092_I2CADDRESSSELECT},
4958 {0xa0, 0x01, ZC3XX_R093_I2CSETVALUE},
4959 {0xa0, 0x00, ZC3XX_R094_I2CWRITEACK},
4960 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
4961 {0xa0, 0x06, ZC3XX_R092_I2CADDRESSSELECT},
4962 {0xa0, 0x00, ZC3XX_R093_I2CSETVALUE},
4963 {0xa0, 0x00, ZC3XX_R094_I2CWRITEACK},
4964 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
4965 {0xa0, 0x08, ZC3XX_R092_I2CADDRESSSELECT},
4966 {0xa0, 0x83, ZC3XX_R093_I2CSETVALUE},
4967 {0xa0, 0x04, ZC3XX_R094_I2CWRITEACK},
4968 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
4969 {0xa0, 0x01, ZC3XX_R092_I2CADDRESSSELECT},
4970 {0xa0, 0x04, ZC3XX_R093_I2CSETVALUE},
4971 {0xa0, 0x00, ZC3XX_R094_I2CWRITEACK},
4972 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
4973 {0xa0, 0x08, ZC3XX_R092_I2CADDRESSSELECT},
4974 {0xa0, 0x06, ZC3XX_R093_I2CSETVALUE},
4975 {0xa0, 0x00, ZC3XX_R094_I2CWRITEACK},
4976 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
4977 {0xa0, 0x02, ZC3XX_R092_I2CADDRESSSELECT},
4978 {0xa0, 0x11, ZC3XX_R093_I2CSETVALUE},
4979 {0xa0, 0x00, ZC3XX_R094_I2CWRITEACK},
4980 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
4981 {0xa0, 0x03, ZC3XX_R092_I2CADDRESSSELECT},
4982 {0xa0, 0xE7, ZC3XX_R093_I2CSETVALUE},
4983 {0xa0, 0x01, ZC3XX_R094_I2CWRITEACK},
4984 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
4985 {0xa0, 0x04, ZC3XX_R092_I2CADDRESSSELECT},
4986 {0xa0, 0x87, ZC3XX_R093_I2CSETVALUE},
4987 {0xa0, 0x02, ZC3XX_R094_I2CWRITEACK},
4988 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
4989 {0xa0, 0x07, ZC3XX_R092_I2CADDRESSSELECT},
4990 {0xa0, 0x02, ZC3XX_R093_I2CSETVALUE},
4991 {0xa0, 0x30, ZC3XX_R094_I2CWRITEACK},
4992 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
4993 {0xa0, 0x20, ZC3XX_R092_I2CADDRESSSELECT},
4994 {0xa0, 0x00, ZC3XX_R093_I2CSETVALUE},
4995 {0xa0, 0x51, ZC3XX_R094_I2CWRITEACK},
4996 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
4997 {0xa0, 0x35, ZC3XX_R092_I2CADDRESSSELECT},
4998 {0xa0, 0x7F, ZC3XX_R093_I2CSETVALUE},
4999 {0xa0, 0x00, ZC3XX_R094_I2CWRITEACK},
5000 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
5001 {0xa0, 0x30, ZC3XX_R092_I2CADDRESSSELECT},
5002 {0xa0, 0x05, ZC3XX_R093_I2CSETVALUE},
5003 {0xa0, 0x00, ZC3XX_R094_I2CWRITEACK},
5004 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
5005 {0xa0, 0x31, ZC3XX_R092_I2CADDRESSSELECT},
5006 {0xa0, 0x00, ZC3XX_R093_I2CSETVALUE},
5007 {0xa0, 0x00, ZC3XX_R094_I2CWRITEACK},
5008 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
5009 {0xa0, 0x58, ZC3XX_R092_I2CADDRESSSELECT},
5010 {0xa0, 0x78, ZC3XX_R093_I2CSETVALUE},
5011 {0xa0, 0x00, ZC3XX_R094_I2CWRITEACK},
5012 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
5013 {0xa0, 0x62, ZC3XX_R092_I2CADDRESSSELECT},
5014 {0xa0, 0x11, ZC3XX_R093_I2CSETVALUE},
5015 {0xa0, 0x04, ZC3XX_R094_I2CWRITEACK},
5016 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
5017 {0xa0, 0x2B, ZC3XX_R092_I2CADDRESSSELECT},
5018 {0xa0, 0x7f, ZC3XX_R093_I2CSETVALUE},
5019 {0xa0, 0x00, ZC3XX_R094_I2CWRITEACK},
5020 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
5021 {0xa0, 0x2c, ZC3XX_R092_I2CADDRESSSELECT},
5022 {0xa0, 0x7f, ZC3XX_R093_I2CSETVALUE},
5023 {0xa0, 0x00, ZC3XX_R094_I2CWRITEACK},
5024 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
5025 {0xa0, 0x2D, ZC3XX_R092_I2CADDRESSSELECT},
5026 {0xa0, 0x7f, ZC3XX_R093_I2CSETVALUE},
5027 {0xa0, 0x00, ZC3XX_R094_I2CWRITEACK},
5028 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
5029 {0xa0, 0x2e, ZC3XX_R092_I2CADDRESSSELECT},
5030 {0xa0, 0x7f, ZC3XX_R093_I2CSETVALUE},
5031 {0xa0, 0x00, ZC3XX_R094_I2CWRITEACK},
5032 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
5033 {0xa0, 0x10, ZC3XX_R087_EXPTIMEMID},
5034 {0xa0, 0xb7, ZC3XX_R101_SENSORCORRECTION},
5035 {0xa0, 0x05, ZC3XX_R012_VIDEOCONTROLFUNC},
5036 {0xa0, 0x0d, ZC3XX_R100_OPERATIONMODE},
5037 {0xa0, 0x06, ZC3XX_R189_AWBSTATUS},
5038 {0xa0, 0x09, 0x01ad},
5039 {0xa0, 0x03, ZC3XX_R1C5_SHARPNESSMODE},
5040 {0xa0, 0x13, ZC3XX_R1CB_SHARPNESS05},
5041 {0xa0, 0x08, ZC3XX_R250_DEADPIXELSMODE},
5042 {0xa0, 0x08, ZC3XX_R301_EEPROMACCESS},
5043 {0xa0, 0x60, ZC3XX_R1A8_DIGITALGAIN},
5044 {0xa0, 0x6c, ZC3XX_R18D_YTARGET},
5045 {0xa0, 0x61, ZC3XX_R116_RGAIN},
5046 {0xa0, 0x65, ZC3XX_R118_BGAIN},
5047 {0xa0, 0x09, 0x01ad},
5048 {0xa0, 0x15, 0x01ae},
5049 {0xa0, 0x4c, ZC3XX_R10A_RGB00}, /* matrix */
5050 {0xa0, 0xf1, ZC3XX_R10B_RGB01},
5051 {0xa0, 0x03, ZC3XX_R10C_RGB02},
5052 {0xa0, 0xfe, ZC3XX_R10D_RGB10},
5053 {0xa0, 0x51, ZC3XX_R10E_RGB11},
5054 {0xa0, 0xf1, ZC3XX_R10F_RGB12},
5055 {0xa0, 0xec, ZC3XX_R110_RGB20},
5056 {0xa0, 0x03, ZC3XX_R111_RGB21},
5057 {0xa0, 0x51, ZC3XX_R112_RGB22},
5058 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING},
5059 {0xa0, 0x08, ZC3XX_R1C6_SHARPNESS00}, /* sharpness+ */
5060 {0xa0, 0x0f, ZC3XX_R1CB_SHARPNESS05}, /* sharpness- */
5061 {0xa0, 0x38, ZC3XX_R120_GAMMA00}, /* gamma > 5 */
5062 {0xa0, 0x51, ZC3XX_R121_GAMMA01},
5063 {0xa0, 0x6e, ZC3XX_R122_GAMMA02},
5064 {0xa0, 0x8c, ZC3XX_R123_GAMMA03},
5065 {0xa0, 0xa2, ZC3XX_R124_GAMMA04},
5066 {0xa0, 0xb6, ZC3XX_R125_GAMMA05},
5067 {0xa0, 0xc8, ZC3XX_R126_GAMMA06},
5068 {0xa0, 0xd6, ZC3XX_R127_GAMMA07},
5069 {0xa0, 0xe2, ZC3XX_R128_GAMMA08},
5070 {0xa0, 0xed, ZC3XX_R129_GAMMA09},
5071 {0xa0, 0xf5, ZC3XX_R12A_GAMMA0A},
5072 {0xa0, 0xfc, ZC3XX_R12B_GAMMA0B},
5073 {0xa0, 0xff, ZC3XX_R12C_GAMMA0C},
5074 {0xa0, 0xff, ZC3XX_R12D_GAMMA0D},
5075 {0xa0, 0xff, ZC3XX_R12E_GAMMA0E},
5076 {0xa0, 0xff, ZC3XX_R12F_GAMMA0F},
5077 {0xa0, 0x12, ZC3XX_R130_GAMMA10},
5078 {0xa0, 0x1b, ZC3XX_R131_GAMMA11},
5079 {0xa0, 0x1d, ZC3XX_R132_GAMMA12},
5080 {0xa0, 0x1a, ZC3XX_R133_GAMMA13},
5081 {0xa0, 0x15, ZC3XX_R134_GAMMA14},
5082 {0xa0, 0x12, ZC3XX_R135_GAMMA15},
5083 {0xa0, 0x0f, ZC3XX_R136_GAMMA16},
5084 {0xa0, 0x0d, ZC3XX_R137_GAMMA17},
5085 {0xa0, 0x0b, ZC3XX_R138_GAMMA18},
5086 {0xa0, 0x09, ZC3XX_R139_GAMMA19},
5087 {0xa0, 0x07, ZC3XX_R13A_GAMMA1A},
5088 {0xa0, 0x05, ZC3XX_R13B_GAMMA1B},
5089 {0xa0, 0x00, ZC3XX_R13C_GAMMA1C},
5090 {0xa0, 0x00, ZC3XX_R13D_GAMMA1D},
5091 {0xa0, 0x00, ZC3XX_R13E_GAMMA1E},
5092 {0xa0, 0x01, ZC3XX_R13F_GAMMA1F},
5093 {0xa0, 0x4c, ZC3XX_R10A_RGB00}, /* matrix */
5094 {0xa0, 0xf1, ZC3XX_R10B_RGB01},
5095 {0xa0, 0x03, ZC3XX_R10C_RGB02},
5096 {0xa0, 0xfe, ZC3XX_R10D_RGB10},
5097 {0xa0, 0x51, ZC3XX_R10E_RGB11},
5098 {0xa0, 0xf1, ZC3XX_R10F_RGB12},
5099 {0xa0, 0xec, ZC3XX_R110_RGB20},
5100 {0xa0, 0x03, ZC3XX_R111_RGB21},
5101 {0xa0, 0x51, ZC3XX_R112_RGB22},
5102 {0xa0, 0x10, ZC3XX_R180_AUTOCORRECTENABLE},
5103 {0xa0, 0x00, ZC3XX_R180_AUTOCORRECTENABLE},
5104 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS},
5105 {0xa0, 0x05, ZC3XX_R092_I2CADDRESSSELECT},
5106 {0xa0, 0x09, ZC3XX_R093_I2CSETVALUE},
5107 {0xa0, 0x00, ZC3XX_R094_I2CWRITEACK},
5108 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
5109 {0xa0, 0x09, ZC3XX_R092_I2CADDRESSSELECT},
5110 {0xa0, 0x34, ZC3XX_R093_I2CSETVALUE},
5111 {0xa0, 0x01, ZC3XX_R094_I2CWRITEACK},
5112 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
5113 {0xa0, 0x00, ZC3XX_R190_EXPOSURELIMITHIGH},
5114 {0xa0, 0x07, ZC3XX_R191_EXPOSURELIMITMID},
5115 {0xa0, 0xd2, ZC3XX_R192_EXPOSURELIMITLOW},
5116 {0xa0, 0x00, ZC3XX_R195_ANTIFLICKERHIGH},
5117 {0xa0, 0x00, ZC3XX_R196_ANTIFLICKERMID},
5118 {0xa0, 0x9a, ZC3XX_R197_ANTIFLICKERLOW},
5119 {0xa0, 0x0e, ZC3XX_R18C_AEFREEZE},
5120 {0xa0, 0x1c, ZC3XX_R18F_AEUNFREEZE},
5121 {0xa0, 0x14, ZC3XX_R1A9_DIGITALLIMITDIFF},
5122 {0xa0, 0x66, ZC3XX_R1AA_DIGITALGAINSTEP},
5123 {0xa0, 0xd7, ZC3XX_R01D_HSYNC_0},
5124 {0xa0, 0xf4, ZC3XX_R01E_HSYNC_1},
5125 {0xa0, 0xf9, ZC3XX_R01F_HSYNC_2},
5126 {0xa0, 0xff, ZC3XX_R020_HSYNC_3},
5127 {0xa0, 0x42, ZC3XX_R180_AUTOCORRECTENABLE},
5128 {0xa0, 0x09, 0x01ad},
5129 {0xa0, 0x15, 0x01ae},
5130 {0xa0, 0x40, ZC3XX_R180_AUTOCORRECTENABLE},
5131 {0xa0, 0x42, ZC3XX_R180_AUTOCORRECTENABLE},
5132 {}
5133};
5134
5135static const struct usb_action tas5130cK_Initial[] = {
5136 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL},
5137 {0xa0, 0x01, 0x003b},
5138 {0xa0, 0x0e, 0x003a},
5139 {0xa0, 0x01, 0x0038},
5140 {0xa0, 0x0b, 0x0039},
5141 {0xa0, 0x00, 0x0038},
5142 {0xa0, 0x0b, 0x0039},
5143 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL},
5144 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING},
5145 {0xa0, 0x0a, ZC3XX_R010_CMOSSENSORSELECT},
5146 {0xa0, 0x00, ZC3XX_R002_CLOCKSELECT},
5147 {0xa0, 0x02, ZC3XX_R003_FRAMEWIDTHHIGH},
5148 {0xa0, 0x80, ZC3XX_R004_FRAMEWIDTHLOW},
5149 {0xa0, 0x01, ZC3XX_R005_FRAMEHEIGHTHIGH},
5150 {0xa0, 0xe0, ZC3XX_R006_FRAMEHEIGHTLOW},
5151 {0xa0, 0xdc, ZC3XX_R08B_I2CDEVICEADDR},
5152 {0xa0, 0x01, ZC3XX_R001_SYSTEMOPERATING},
5153 {0xa0, 0x07, ZC3XX_R012_VIDEOCONTROLFUNC},
5154 {0xa0, 0x00, ZC3XX_R098_WINYSTARTLOW},
5155 {0xa0, 0x00, ZC3XX_R09A_WINXSTARTLOW},
5156 {0xa0, 0x00, ZC3XX_R11A_FIRSTYLOW},
5157 {0xa0, 0x00, ZC3XX_R11C_FIRSTXLOW},
5158 {0xa0, 0xdc, ZC3XX_R08B_I2CDEVICEADDR},
5159 {0xa0, 0x05, ZC3XX_R012_VIDEOCONTROLFUNC},
5160 {0xa0, 0x01, ZC3XX_R092_I2CADDRESSSELECT},
5161 {0xa0, 0x01, ZC3XX_R093_I2CSETVALUE},
5162 {0xa0, 0x00, ZC3XX_R094_I2CWRITEACK},
5163 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
5164 {0xa0, 0x06, ZC3XX_R092_I2CADDRESSSELECT},
5165 {0xa0, 0x00, ZC3XX_R093_I2CSETVALUE},
5166 {0xa0, 0x00, ZC3XX_R094_I2CWRITEACK},
5167 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
5168 {0xa0, 0x08, ZC3XX_R092_I2CADDRESSSELECT},
5169 {0xa0, 0x83, ZC3XX_R093_I2CSETVALUE},
5170 {0xa0, 0x04, ZC3XX_R094_I2CWRITEACK},
5171 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
5172 {0xa0, 0x01, ZC3XX_R092_I2CADDRESSSELECT},
5173 {0xa0, 0x04, ZC3XX_R093_I2CSETVALUE},
5174 {0xa0, 0x00, ZC3XX_R094_I2CWRITEACK},
5175 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
5176 {0xa0, 0x08, ZC3XX_R092_I2CADDRESSSELECT},
5177 {0xa0, 0x06, ZC3XX_R093_I2CSETVALUE},
5178 {0xa0, 0x00, ZC3XX_R094_I2CWRITEACK},
5179 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
5180 {0xa0, 0x02, ZC3XX_R092_I2CADDRESSSELECT},
5181 {0xa0, 0x11, ZC3XX_R093_I2CSETVALUE},
5182 {0xa0, 0x00, ZC3XX_R094_I2CWRITEACK},
5183 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
5184 {0xa0, 0x03, ZC3XX_R092_I2CADDRESSSELECT},
5185 {0xa0, 0xe5, ZC3XX_R093_I2CSETVALUE},
5186 {0xa0, 0x01, ZC3XX_R094_I2CWRITEACK},
5187 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
5188 {0xa0, 0x04, ZC3XX_R092_I2CADDRESSSELECT},
5189 {0xa0, 0x85, ZC3XX_R093_I2CSETVALUE},
5190 {0xa0, 0x02, ZC3XX_R094_I2CWRITEACK},
5191 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
5192 {0xa0, 0x07, ZC3XX_R092_I2CADDRESSSELECT},
5193 {0xa0, 0x02, ZC3XX_R093_I2CSETVALUE},
5194 {0xa0, 0x30, ZC3XX_R094_I2CWRITEACK},
5195 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
5196 {0xa0, 0x20, ZC3XX_R092_I2CADDRESSSELECT},
5197 {0xa0, 0x00, ZC3XX_R093_I2CSETVALUE},
5198 {0xa0, 0x51, ZC3XX_R094_I2CWRITEACK},
5199 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
5200 {0xa0, 0x35, ZC3XX_R092_I2CADDRESSSELECT},
5201 {0xa0, 0x7F, ZC3XX_R093_I2CSETVALUE},
5202 {0xa0, 0x50, ZC3XX_R094_I2CWRITEACK},
5203 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
5204 {0xa0, 0x30, ZC3XX_R092_I2CADDRESSSELECT},
5205 {0xa0, 0x05, ZC3XX_R093_I2CSETVALUE},
5206 {0xa0, 0x00, ZC3XX_R094_I2CWRITEACK},
5207 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
5208 {0xa0, 0x31, ZC3XX_R092_I2CADDRESSSELECT},
5209 {0xa0, 0x00, ZC3XX_R093_I2CSETVALUE},
5210 {0xa0, 0x00, ZC3XX_R094_I2CWRITEACK},
5211 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
5212 {0xa0, 0x58, ZC3XX_R092_I2CADDRESSSELECT},
5213 {0xa0, 0x78, ZC3XX_R093_I2CSETVALUE},
5214 {0xa0, 0x00, ZC3XX_R094_I2CWRITEACK},
5215 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
5216 {0xa0, 0x62, ZC3XX_R092_I2CADDRESSSELECT},
5217 {0xa0, 0x11, ZC3XX_R093_I2CSETVALUE},
5218 {0xa0, 0x04, ZC3XX_R094_I2CWRITEACK},
5219 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
5220 {0xa0, 0x2B, ZC3XX_R092_I2CADDRESSSELECT},
5221 {0xa0, 0x7f, ZC3XX_R093_I2CSETVALUE},
5222 {0xa0, 0x00, ZC3XX_R094_I2CWRITEACK},
5223 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
5224 {0xa0, 0x2C, ZC3XX_R092_I2CADDRESSSELECT},
5225 {0xa0, 0x7F, ZC3XX_R093_I2CSETVALUE},
5226 {0xa0, 0x00, ZC3XX_R094_I2CWRITEACK},
5227 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
5228 {0xa0, 0x2D, ZC3XX_R092_I2CADDRESSSELECT},
5229 {0xa0, 0x7f, ZC3XX_R093_I2CSETVALUE},
5230 {0xa0, 0x00, ZC3XX_R094_I2CWRITEACK},
5231 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
5232 {0xa0, 0x2e, ZC3XX_R092_I2CADDRESSSELECT},
5233 {0xa0, 0x7f, ZC3XX_R093_I2CSETVALUE},
5234 {0xa0, 0x00, ZC3XX_R094_I2CWRITEACK},
5235 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
5236 {0xa0, 0x10, ZC3XX_R087_EXPTIMEMID},
5237 {0xa0, 0xb7, ZC3XX_R101_SENSORCORRECTION},
5238 {0xa0, 0x05, ZC3XX_R012_VIDEOCONTROLFUNC},
5239 {0xa0, 0x0d, ZC3XX_R100_OPERATIONMODE},
5240 {0xa0, 0x06, ZC3XX_R189_AWBSTATUS},
5241 {0xa0, 0x09, 0x01ad},
5242 {0xa0, 0x03, ZC3XX_R1C5_SHARPNESSMODE},
5243 {0xa0, 0x13, ZC3XX_R1CB_SHARPNESS05},
5244 {0xa0, 0x08, ZC3XX_R250_DEADPIXELSMODE},
5245 {0xa0, 0x08, ZC3XX_R301_EEPROMACCESS},
5246 {0xa0, 0x60, ZC3XX_R1A8_DIGITALGAIN},
5247 {0xa0, 0x6c, ZC3XX_R18D_YTARGET},
5248 {0xa0, 0x61, ZC3XX_R116_RGAIN},
5249 {0xa0, 0x65, ZC3XX_R118_BGAIN},
5250 {0xa0, 0x09, 0x01ad},
5251 {0xa0, 0x15, 0x01ae},
5252 {0xa0, 0x4c, ZC3XX_R10A_RGB00}, /* matrix */
5253 {0xa0, 0xf1, ZC3XX_R10B_RGB01},
5254 {0xa0, 0x03, ZC3XX_R10C_RGB02},
5255 {0xa0, 0xfe, ZC3XX_R10D_RGB10},
5256 {0xa0, 0x51, ZC3XX_R10E_RGB11},
5257 {0xa0, 0xf1, ZC3XX_R10F_RGB12},
5258 {0xa0, 0xec, ZC3XX_R110_RGB20},
5259 {0xa0, 0x03, ZC3XX_R111_RGB21},
5260 {0xa0, 0x51, ZC3XX_R112_RGB22},
5261 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING},
5262 {0xa0, 0x08, ZC3XX_R1C6_SHARPNESS00}, /* sharpness+ */
5263 {0xa0, 0x0f, ZC3XX_R1CB_SHARPNESS05}, /* sharpness- */
5264 {0xa0, 0x38, ZC3XX_R120_GAMMA00}, /* gamma > 5 */
5265 {0xa0, 0x51, ZC3XX_R121_GAMMA01},
5266 {0xa0, 0x6e, ZC3XX_R122_GAMMA02},
5267 {0xa0, 0x8c, ZC3XX_R123_GAMMA03},
5268 {0xa0, 0xa2, ZC3XX_R124_GAMMA04},
5269 {0xa0, 0xb6, ZC3XX_R125_GAMMA05},
5270 {0xa0, 0xc8, ZC3XX_R126_GAMMA06},
5271 {0xa0, 0xd6, ZC3XX_R127_GAMMA07},
5272 {0xa0, 0xe2, ZC3XX_R128_GAMMA08},
5273 {0xa0, 0xed, ZC3XX_R129_GAMMA09},
5274 {0xa0, 0xf5, ZC3XX_R12A_GAMMA0A},
5275 {0xa0, 0xfc, ZC3XX_R12B_GAMMA0B},
5276 {0xa0, 0xff, ZC3XX_R12C_GAMMA0C},
5277 {0xa0, 0xff, ZC3XX_R12D_GAMMA0D},
5278 {0xa0, 0xff, ZC3XX_R12E_GAMMA0E},
5279 {0xa0, 0xff, ZC3XX_R12F_GAMMA0F},
5280 {0xa0, 0x12, ZC3XX_R130_GAMMA10},
5281 {0xa0, 0x1b, ZC3XX_R131_GAMMA11},
5282 {0xa0, 0x1d, ZC3XX_R132_GAMMA12},
5283 {0xa0, 0x1a, ZC3XX_R133_GAMMA13},
5284 {0xa0, 0x15, ZC3XX_R134_GAMMA14},
5285 {0xa0, 0x12, ZC3XX_R135_GAMMA15},
5286 {0xa0, 0x0f, ZC3XX_R136_GAMMA16},
5287 {0xa0, 0x0d, ZC3XX_R137_GAMMA17},
5288 {0xa0, 0x0b, ZC3XX_R138_GAMMA18},
5289 {0xa0, 0x09, ZC3XX_R139_GAMMA19},
5290 {0xa0, 0x07, ZC3XX_R13A_GAMMA1A},
5291 {0xa0, 0x05, ZC3XX_R13B_GAMMA1B},
5292 {0xa0, 0x00, ZC3XX_R13C_GAMMA1C},
5293 {0xa0, 0x00, ZC3XX_R13D_GAMMA1D},
5294 {0xa0, 0x00, ZC3XX_R13E_GAMMA1E},
5295 {0xa0, 0x01, ZC3XX_R13F_GAMMA1F},
5296 {0xa0, 0x4c, ZC3XX_R10A_RGB00}, /* matrix */
5297 {0xa0, 0xf1, ZC3XX_R10B_RGB01},
5298 {0xa0, 0x03, ZC3XX_R10C_RGB02},
5299 {0xa0, 0xfe, ZC3XX_R10D_RGB10},
5300 {0xa0, 0x51, ZC3XX_R10E_RGB11},
5301 {0xa0, 0xf1, ZC3XX_R10F_RGB12},
5302 {0xa0, 0xec, ZC3XX_R110_RGB20},
5303 {0xa0, 0x03, ZC3XX_R111_RGB21},
5304 {0xa0, 0x51, ZC3XX_R112_RGB22},
5305 {0xa0, 0x10, ZC3XX_R180_AUTOCORRECTENABLE},
5306 {0xa0, 0x00, ZC3XX_R180_AUTOCORRECTENABLE},
5307 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS},
5308 {0xa0, 0x05, ZC3XX_R092_I2CADDRESSSELECT},
5309 {0xa0, 0x62, ZC3XX_R093_I2CSETVALUE},
5310 {0xa0, 0x00, ZC3XX_R094_I2CWRITEACK},
5311 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
5312 {0xa0, 0x09, ZC3XX_R092_I2CADDRESSSELECT},
5313 {0xa0, 0xaa, ZC3XX_R093_I2CSETVALUE},
5314 {0xa0, 0x01, ZC3XX_R094_I2CWRITEACK},
5315 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
5316 {0xa0, 0x00, ZC3XX_R190_EXPOSURELIMITHIGH},
5317 {0xa0, 0x03, ZC3XX_R191_EXPOSURELIMITMID},
5318 {0xa0, 0x9b, ZC3XX_R192_EXPOSURELIMITLOW},
5319 {0xa0, 0x00, ZC3XX_R195_ANTIFLICKERHIGH},
5320 {0xa0, 0x00, ZC3XX_R196_ANTIFLICKERMID},
5321 {0xa0, 0x47, ZC3XX_R197_ANTIFLICKERLOW},
5322 {0xa0, 0x0e, ZC3XX_R18C_AEFREEZE},
5323 {0xa0, 0x1c, ZC3XX_R18F_AEUNFREEZE},
5324 {0xa0, 0x14, ZC3XX_R1A9_DIGITALLIMITDIFF},
5325 {0xa0, 0x66, ZC3XX_R1AA_DIGITALGAINSTEP},
5326 {0xa0, 0x62, ZC3XX_R01D_HSYNC_0},
5327 {0xa0, 0x90, ZC3XX_R01E_HSYNC_1},
5328 {0xa0, 0xc8, ZC3XX_R01F_HSYNC_2},
5329 {0xa0, 0xff, ZC3XX_R020_HSYNC_3},
5330 {0xa0, 0x60, ZC3XX_R11D_GLOBALGAIN},
5331 {0xa0, 0x42, ZC3XX_R180_AUTOCORRECTENABLE},
5332 {0xa0, 0x09, 0x01ad},
5333 {0xa0, 0x15, 0x01ae},
5334 {0xa0, 0x40, ZC3XX_R180_AUTOCORRECTENABLE},
5335 {0xa0, 0x42, ZC3XX_R180_AUTOCORRECTENABLE},
5336 {0xa0, 0x30, 0x0007},
5337 {0xa0, 0x02, ZC3XX_R008_CLOCKSETTING},
5338 {0xa0, 0x00, 0x0007},
5339 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING},
5340 {}
5341};
5342
5343static const struct usb_action tas5130cxx_InitialScale[] = { /* 320x240 */
5344 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, 5190 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL},
5345 {0xa0, 0x50, ZC3XX_R002_CLOCKSELECT}, 5191 {0xa0, 0x50, ZC3XX_R002_CLOCKSELECT},
5346 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING}, 5192 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING},
@@ -5377,7 +5223,7 @@ static const struct usb_action tas5130cxx_InitialScale[] = { /* 320x240 */
5377 {0xa0, 0x02, ZC3XX_R0A6_EXPOSUREBLACKLVL}, 5223 {0xa0, 0x02, ZC3XX_R0A6_EXPOSUREBLACKLVL},
5378 {} 5224 {}
5379}; 5225};
5380static const struct usb_action tas5130cxx_Initial[] = { /* 640x480 */ 5226static const struct usb_action tas5130c_Initial[] = { /* 640x480 */
5381 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, 5227 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL},
5382 {0xa0, 0x40, ZC3XX_R002_CLOCKSELECT}, 5228 {0xa0, 0x40, ZC3XX_R002_CLOCKSELECT},
5383 {0xa0, 0x00, ZC3XX_R008_CLOCKSETTING}, 5229 {0xa0, 0x00, ZC3XX_R008_CLOCKSETTING},
@@ -5413,7 +5259,7 @@ static const struct usb_action tas5130cxx_Initial[] = { /* 640x480 */
5413 {0xa0, 0x02, ZC3XX_R0A6_EXPOSUREBLACKLVL}, 5259 {0xa0, 0x02, ZC3XX_R0A6_EXPOSUREBLACKLVL},
5414 {} 5260 {}
5415}; 5261};
5416static const struct usb_action tas5130cxx_50HZ[] = { 5262static const struct usb_action tas5130c_50HZ[] = {
5417 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, /* 00,19,00,cc */ 5263 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, /* 00,19,00,cc */
5418 {0xaa, 0xa3, 0x0001}, /* 00,a3,01,aa */ 5264 {0xaa, 0xa3, 0x0001}, /* 00,a3,01,aa */
5419 {0xaa, 0xa4, 0x0063}, /* 00,a4,63,aa */ 5265 {0xaa, 0xa4, 0x0063}, /* 00,a4,63,aa */
@@ -5438,7 +5284,7 @@ static const struct usb_action tas5130cxx_50HZ[] = {
5438 {0xa0, 0x50, ZC3XX_R11D_GLOBALGAIN}, 5284 {0xa0, 0x50, ZC3XX_R11D_GLOBALGAIN},
5439 {} 5285 {}
5440}; 5286};
5441static const struct usb_action tas5130cxx_50HZScale[] = { 5287static const struct usb_action tas5130c_50HZScale[] = {
5442 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, /* 00,19,00,cc */ 5288 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, /* 00,19,00,cc */
5443 {0xaa, 0xa3, 0x0001}, /* 00,a3,01,aa */ 5289 {0xaa, 0xa3, 0x0001}, /* 00,a3,01,aa */
5444 {0xaa, 0xa4, 0x0077}, /* 00,a4,77,aa */ 5290 {0xaa, 0xa4, 0x0077}, /* 00,a4,77,aa */
@@ -5463,7 +5309,7 @@ static const struct usb_action tas5130cxx_50HZScale[] = {
5463 {0xa0, 0x50, ZC3XX_R11D_GLOBALGAIN}, 5309 {0xa0, 0x50, ZC3XX_R11D_GLOBALGAIN},
5464 {} 5310 {}
5465}; 5311};
5466static const struct usb_action tas5130cxx_60HZ[] = { 5312static const struct usb_action tas5130c_60HZ[] = {
5467 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, /* 00,19,00,cc */ 5313 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, /* 00,19,00,cc */
5468 {0xaa, 0xa3, 0x0001}, /* 00,a3,01,aa */ 5314 {0xaa, 0xa3, 0x0001}, /* 00,a3,01,aa */
5469 {0xaa, 0xa4, 0x0036}, /* 00,a4,36,aa */ 5315 {0xaa, 0xa4, 0x0036}, /* 00,a4,36,aa */
@@ -5488,7 +5334,7 @@ static const struct usb_action tas5130cxx_60HZ[] = {
5488 {0xa0, 0x50, ZC3XX_R11D_GLOBALGAIN}, 5334 {0xa0, 0x50, ZC3XX_R11D_GLOBALGAIN},
5489 {} 5335 {}
5490}; 5336};
5491static const struct usb_action tas5130cxx_60HZScale[] = { 5337static const struct usb_action tas5130c_60HZScale[] = {
5492 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, /* 00,19,00,cc */ 5338 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, /* 00,19,00,cc */
5493 {0xaa, 0xa3, 0x0001}, /* 00,a3,01,aa */ 5339 {0xaa, 0xa3, 0x0001}, /* 00,a3,01,aa */
5494 {0xaa, 0xa4, 0x0077}, /* 00,a4,77,aa */ 5340 {0xaa, 0xa4, 0x0077}, /* 00,a4,77,aa */
@@ -5513,7 +5359,7 @@ static const struct usb_action tas5130cxx_60HZScale[] = {
5513 {0xa0, 0x50, ZC3XX_R11D_GLOBALGAIN}, 5359 {0xa0, 0x50, ZC3XX_R11D_GLOBALGAIN},
5514 {} 5360 {}
5515}; 5361};
5516static const struct usb_action tas5130cxx_NoFliker[] = { 5362static const struct usb_action tas5130c_NoFliker[] = {
5517 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, /* 00,19,00,cc */ 5363 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, /* 00,19,00,cc */
5518 {0xaa, 0xa3, 0x0001}, /* 00,a3,01,aa */ 5364 {0xaa, 0xa3, 0x0001}, /* 00,a3,01,aa */
5519 {0xaa, 0xa4, 0x0040}, /* 00,a4,40,aa */ 5365 {0xaa, 0xa4, 0x0040}, /* 00,a4,40,aa */
@@ -5539,7 +5385,7 @@ static const struct usb_action tas5130cxx_NoFliker[] = {
5539 {} 5385 {}
5540}; 5386};
5541 5387
5542static const struct usb_action tas5130cxx_NoFlikerScale[] = { 5388static const struct usb_action tas5130c_NoFlikerScale[] = {
5543 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, /* 00,19,00,cc */ 5389 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, /* 00,19,00,cc */
5544 {0xaa, 0xa3, 0x0001}, /* 00,a3,01,aa */ 5390 {0xaa, 0xa3, 0x0001}, /* 00,a3,01,aa */
5545 {0xaa, 0xa4, 0x0090}, /* 00,a4,90,aa */ 5391 {0xaa, 0xa4, 0x0090}, /* 00,a4,90,aa */
@@ -5840,13 +5686,22 @@ static const struct usb_action tas5130c_vf0250_NoFliker[] = {
5840static u8 reg_r_i(struct gspca_dev *gspca_dev, 5686static u8 reg_r_i(struct gspca_dev *gspca_dev,
5841 u16 index) 5687 u16 index)
5842{ 5688{
5843 usb_control_msg(gspca_dev->dev, 5689 int ret;
5690
5691 if (gspca_dev->usb_err < 0)
5692 return 0;
5693 ret = usb_control_msg(gspca_dev->dev,
5844 usb_rcvctrlpipe(gspca_dev->dev, 0), 5694 usb_rcvctrlpipe(gspca_dev->dev, 0),
5845 0xa1, 5695 0xa1,
5846 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 5696 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
5847 0x01, /* value */ 5697 0x01, /* value */
5848 index, gspca_dev->usb_buf, 1, 5698 index, gspca_dev->usb_buf, 1,
5849 500); 5699 500);
5700 if (ret < 0) {
5701 PDEBUG(D_ERR, "reg_r_i err %d", ret);
5702 gspca_dev->usb_err = ret;
5703 return 0;
5704 }
5850 return gspca_dev->usb_buf[0]; 5705 return gspca_dev->usb_buf[0];
5851} 5706}
5852 5707
@@ -5860,24 +5715,32 @@ static u8 reg_r(struct gspca_dev *gspca_dev,
5860 return ret; 5715 return ret;
5861} 5716}
5862 5717
5863static void reg_w_i(struct usb_device *dev, 5718static void reg_w_i(struct gspca_dev *gspca_dev,
5864 u8 value, 5719 u8 value,
5865 u16 index) 5720 u16 index)
5866{ 5721{
5867 usb_control_msg(dev, 5722 int ret;
5868 usb_sndctrlpipe(dev, 0), 5723
5724 if (gspca_dev->usb_err < 0)
5725 return;
5726 ret = usb_control_msg(gspca_dev->dev,
5727 usb_sndctrlpipe(gspca_dev->dev, 0),
5869 0xa0, 5728 0xa0,
5870 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 5729 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
5871 value, index, NULL, 0, 5730 value, index, NULL, 0,
5872 500); 5731 500);
5732 if (ret < 0) {
5733 PDEBUG(D_ERR, "reg_w_i err %d", ret);
5734 gspca_dev->usb_err = ret;
5735 }
5873} 5736}
5874 5737
5875static void reg_w(struct usb_device *dev, 5738static void reg_w(struct gspca_dev *gspca_dev,
5876 u8 value, 5739 u8 value,
5877 u16 index) 5740 u16 index)
5878{ 5741{
5879 PDEBUG(D_USBO, "reg w [%04x] = %02x", index, value); 5742 PDEBUG(D_USBO, "reg w [%04x] = %02x", index, value);
5880 reg_w_i(dev, value, index); 5743 reg_w_i(gspca_dev, value, index);
5881} 5744}
5882 5745
5883static u16 i2c_read(struct gspca_dev *gspca_dev, 5746static u16 i2c_read(struct gspca_dev *gspca_dev,
@@ -5886,8 +5749,10 @@ static u16 i2c_read(struct gspca_dev *gspca_dev,
5886 u8 retbyte; 5749 u8 retbyte;
5887 u16 retval; 5750 u16 retval;
5888 5751
5889 reg_w_i(gspca_dev->dev, reg, 0x0092); 5752 if (gspca_dev->usb_err < 0)
5890 reg_w_i(gspca_dev->dev, 0x02, 0x0090); /* <- read command */ 5753 return 0;
5754 reg_w_i(gspca_dev, reg, 0x0092);
5755 reg_w_i(gspca_dev, 0x02, 0x0090); /* <- read command */
5891 msleep(20); 5756 msleep(20);
5892 retbyte = reg_r_i(gspca_dev, 0x0091); /* read status */ 5757 retbyte = reg_r_i(gspca_dev, 0x0091); /* read status */
5893 if (retbyte != 0x00) 5758 if (retbyte != 0x00)
@@ -5906,10 +5771,12 @@ static u8 i2c_write(struct gspca_dev *gspca_dev,
5906{ 5771{
5907 u8 retbyte; 5772 u8 retbyte;
5908 5773
5909 reg_w_i(gspca_dev->dev, reg, 0x92); 5774 if (gspca_dev->usb_err < 0)
5910 reg_w_i(gspca_dev->dev, valL, 0x93); 5775 return 0;
5911 reg_w_i(gspca_dev->dev, valH, 0x94); 5776 reg_w_i(gspca_dev, reg, 0x92);
5912 reg_w_i(gspca_dev->dev, 0x01, 0x90); /* <- write command */ 5777 reg_w_i(gspca_dev, valL, 0x93);
5778 reg_w_i(gspca_dev, valH, 0x94);
5779 reg_w_i(gspca_dev, 0x01, 0x90); /* <- write command */
5913 msleep(1); 5780 msleep(1);
5914 retbyte = reg_r_i(gspca_dev, 0x0091); /* read status */ 5781 retbyte = reg_r_i(gspca_dev, 0x0091); /* read status */
5915 if (retbyte != 0x00) 5782 if (retbyte != 0x00)
@@ -5925,7 +5792,7 @@ static void usb_exchange(struct gspca_dev *gspca_dev,
5925 while (action->req) { 5792 while (action->req) {
5926 switch (action->req) { 5793 switch (action->req) {
5927 case 0xa0: /* write register */ 5794 case 0xa0: /* write register */
5928 reg_w(gspca_dev->dev, action->val, action->idx); 5795 reg_w(gspca_dev, action->val, action->idx);
5929 break; 5796 break;
5930 case 0xa1: /* read status */ 5797 case 0xa1: /* read status */
5931 reg_r(gspca_dev, action->idx); 5798 reg_r(gspca_dev, action->idx);
@@ -5974,38 +5841,37 @@ static void setmatrix(struct gspca_dev *gspca_dev)
5974 static const u8 vf0250_matrix[9] = 5841 static const u8 vf0250_matrix[9] =
5975 {0x7b, 0xea, 0xea, 0xea, 0x7b, 0xea, 0xea, 0xea, 0x7b}; 5842 {0x7b, 0xea, 0xea, 0xea, 0x7b, 0xea, 0xea, 0xea, 0x7b};
5976 static const u8 *matrix_tb[SENSOR_MAX] = { 5843 static const u8 *matrix_tb[SENSOR_MAX] = {
5977 adcm2700_matrix, /* SENSOR_ADCM2700 0 */ 5844 [SENSOR_ADCM2700] = adcm2700_matrix,
5978 ov7620_matrix, /* SENSOR_CS2102 1 */ 5845 [SENSOR_CS2102] = ov7620_matrix,
5979 NULL, /* SENSOR_CS2102K 2 */ 5846 [SENSOR_CS2102K] = NULL,
5980 gc0305_matrix, /* SENSOR_GC0305 3 */ 5847 [SENSOR_GC0305] = gc0305_matrix,
5981 NULL, /* SENSOR_HDCS2020b 4 */ 5848 [SENSOR_HDCS2020b] = NULL,
5982 NULL, /* SENSOR_HV7131B 5 */ 5849 [SENSOR_HV7131B] = NULL,
5983 NULL, /* SENSOR_HV7131C 6 */ 5850 [SENSOR_HV7131R] = NULL,
5984 NULL, /* SENSOR_ICM105A 7 */ 5851 [SENSOR_ICM105A] = po2030_matrix,
5985 NULL, /* SENSOR_MC501CB 8 */ 5852 [SENSOR_MC501CB] = NULL,
5986 gc0305_matrix, /* SENSOR_MI0360SOC 9 */ 5853 [SENSOR_MT9V111_1] = gc0305_matrix,
5987 ov7620_matrix, /* SENSOR_OV7620 10 */ 5854 [SENSOR_MT9V111_3] = gc0305_matrix,
5988 NULL, /* SENSOR_OV7630C 11 */ 5855 [SENSOR_OV7620] = ov7620_matrix,
5989 NULL, /* SENSOR_PAS106 12 */ 5856 [SENSOR_OV7630C] = NULL,
5990 pas202b_matrix, /* SENSOR_PAS202B 13 */ 5857 [SENSOR_PAS106] = NULL,
5991 gc0305_matrix, /* SENSOR_PB0330 14 */ 5858 [SENSOR_PAS202B] = pas202b_matrix,
5992 po2030_matrix, /* SENSOR_PO2030 15 */ 5859 [SENSOR_PB0330] = gc0305_matrix,
5993 NULL, /* SENSOR_TAS5130CK 16 */ 5860 [SENSOR_PO2030] = po2030_matrix,
5994 tas5130c_matrix, /* SENSOR_TAS5130CXX 17 */ 5861 [SENSOR_TAS5130C] = tas5130c_matrix,
5995 vf0250_matrix, /* SENSOR_TAS5130C_VF0250 18 */ 5862 [SENSOR_TAS5130C_VF0250] = vf0250_matrix,
5996 }; 5863 };
5997 5864
5998 matrix = matrix_tb[sd->sensor]; 5865 matrix = matrix_tb[sd->sensor];
5999 if (matrix == NULL) 5866 if (matrix == NULL)
6000 return; /* matrix already loaded */ 5867 return; /* matrix already loaded */
6001 for (i = 0; i < ARRAY_SIZE(ov7620_matrix); i++) 5868 for (i = 0; i < ARRAY_SIZE(ov7620_matrix); i++)
6002 reg_w(gspca_dev->dev, matrix[i], 0x010a + i); 5869 reg_w(gspca_dev, matrix[i], 0x010a + i);
6003} 5870}
6004 5871
6005static void setsharpness(struct gspca_dev *gspca_dev) 5872static void setsharpness(struct gspca_dev *gspca_dev)
6006{ 5873{
6007 struct sd *sd = (struct sd *) gspca_dev; 5874 struct sd *sd = (struct sd *) gspca_dev;
6008 struct usb_device *dev = gspca_dev->dev;
6009 int sharpness; 5875 int sharpness;
6010 static const u8 sharpness_tb[][2] = { 5876 static const u8 sharpness_tb[][2] = {
6011 {0x02, 0x03}, 5877 {0x02, 0x03},
@@ -6015,17 +5881,16 @@ static void setsharpness(struct gspca_dev *gspca_dev)
6015 }; 5881 };
6016 5882
6017 sharpness = sd->sharpness; 5883 sharpness = sd->sharpness;
6018 reg_w(dev, sharpness_tb[sharpness][0], 0x01c6); 5884 reg_w(gspca_dev, sharpness_tb[sharpness][0], 0x01c6);
6019 reg_r(gspca_dev, 0x01c8); 5885 reg_r(gspca_dev, 0x01c8);
6020 reg_r(gspca_dev, 0x01c9); 5886 reg_r(gspca_dev, 0x01c9);
6021 reg_r(gspca_dev, 0x01ca); 5887 reg_r(gspca_dev, 0x01ca);
6022 reg_w(dev, sharpness_tb[sharpness][1], 0x01cb); 5888 reg_w(gspca_dev, sharpness_tb[sharpness][1], 0x01cb);
6023} 5889}
6024 5890
6025static void setcontrast(struct gspca_dev *gspca_dev) 5891static void setcontrast(struct gspca_dev *gspca_dev)
6026{ 5892{
6027 struct sd *sd = (struct sd *) gspca_dev; 5893 struct sd *sd = (struct sd *) gspca_dev;
6028 struct usb_device *dev = gspca_dev->dev;
6029 const u8 *Tgamma; 5894 const u8 *Tgamma;
6030 int g, i, brightness, contrast, adj, gp1, gp2; 5895 int g, i, brightness, contrast, adj, gp1, gp2;
6031 u8 gr[16]; 5896 u8 gr[16];
@@ -6063,7 +5928,7 @@ static void setcontrast(struct gspca_dev *gspca_dev)
6063 g = 0xff; 5928 g = 0xff;
6064 else if (g < 0) 5929 else if (g < 0)
6065 g = 0; 5930 g = 0;
6066 reg_w(dev, g, 0x0120 + i); /* gamma */ 5931 reg_w(gspca_dev, g, 0x0120 + i); /* gamma */
6067 if (contrast > 0) 5932 if (contrast > 0)
6068 adj--; 5933 adj--;
6069 else if (contrast < 0) 5934 else if (contrast < 0)
@@ -6077,13 +5942,12 @@ static void setcontrast(struct gspca_dev *gspca_dev)
6077 } 5942 }
6078 gr[15] = (0xff - gp2) / 2; 5943 gr[15] = (0xff - gp2) / 2;
6079 for (i = 0; i < 16; i++) 5944 for (i = 0; i < 16; i++)
6080 reg_w(dev, gr[i], 0x0130 + i); /* gradient */ 5945 reg_w(gspca_dev, gr[i], 0x0130 + i); /* gradient */
6081} 5946}
6082 5947
6083static void setquality(struct gspca_dev *gspca_dev) 5948static void setquality(struct gspca_dev *gspca_dev)
6084{ 5949{
6085 struct sd *sd = (struct sd *) gspca_dev; 5950 struct sd *sd = (struct sd *) gspca_dev;
6086 struct usb_device *dev = gspca_dev->dev;
6087 u8 frxt; 5951 u8 frxt;
6088 5952
6089 switch (sd->sensor) { 5953 switch (sd->sensor) {
@@ -6096,9 +5960,9 @@ static void setquality(struct gspca_dev *gspca_dev)
6096 return; 5960 return;
6097 } 5961 }
6098/*fixme: is it really 0008 0007 0018 for all other sensors? */ 5962/*fixme: is it really 0008 0007 0018 for all other sensors? */
6099 reg_w(dev, QUANT_VAL, 0x0008); 5963 reg_w(gspca_dev, QUANT_VAL, 0x0008);
6100 frxt = 0x30; 5964 frxt = 0x30;
6101 reg_w(dev, frxt, 0x0007); 5965 reg_w(gspca_dev, frxt, 0x0007);
6102#if QUANT_VAL == 0 || QUANT_VAL == 1 || QUANT_VAL == 2 5966#if QUANT_VAL == 0 || QUANT_VAL == 1 || QUANT_VAL == 2
6103 frxt = 0xff; 5967 frxt = 0xff;
6104#elif QUANT_VAL == 3 5968#elif QUANT_VAL == 3
@@ -6108,7 +5972,7 @@ static void setquality(struct gspca_dev *gspca_dev)
6108#else 5972#else
6109 frxt = 0x20; 5973 frxt = 0x20;
6110#endif 5974#endif
6111 reg_w(dev, frxt, 0x0018); 5975 reg_w(gspca_dev, frxt, 0x0018);
6112} 5976}
6113 5977
6114/* Matches the sensor's internal frame rate to the lighting frequency. 5978/* Matches the sensor's internal frame rate to the lighting frequency.
@@ -6116,87 +5980,86 @@ static void setquality(struct gspca_dev *gspca_dev)
6116 * 50Hz, for European and Asian lighting (default) 5980 * 50Hz, for European and Asian lighting (default)
6117 * 60Hz, for American lighting 5981 * 60Hz, for American lighting
6118 * 0 = No Fliker (for outdoore usage) 5982 * 0 = No Fliker (for outdoore usage)
6119 * Returns: 0 for success
6120 */ 5983 */
6121static int setlightfreq(struct gspca_dev *gspca_dev) 5984static void setlightfreq(struct gspca_dev *gspca_dev)
6122{ 5985{
6123 struct sd *sd = (struct sd *) gspca_dev; 5986 struct sd *sd = (struct sd *) gspca_dev;
6124 int i, mode; 5987 int i, mode;
6125 const struct usb_action *zc3_freq; 5988 const struct usb_action *zc3_freq;
6126 static const struct usb_action *freq_tb[SENSOR_MAX][6] = { 5989 static const struct usb_action *freq_tb[SENSOR_MAX][6] = {
6127/* SENSOR_ADCM2700 0 */ 5990 [SENSOR_ADCM2700] =
6128 {adcm2700_NoFliker, adcm2700_NoFliker, 5991 {adcm2700_NoFliker, adcm2700_NoFliker,
6129 adcm2700_50HZ, adcm2700_50HZ, 5992 adcm2700_50HZ, adcm2700_50HZ,
6130 adcm2700_60HZ, adcm2700_60HZ}, 5993 adcm2700_60HZ, adcm2700_60HZ},
6131/* SENSOR_CS2102 1 */ 5994 [SENSOR_CS2102] =
6132 {cs2102_NoFliker, cs2102_NoFlikerScale, 5995 {cs2102_NoFliker, cs2102_NoFlikerScale,
6133 cs2102_50HZ, cs2102_50HZScale, 5996 cs2102_50HZ, cs2102_50HZScale,
6134 cs2102_60HZ, cs2102_60HZScale}, 5997 cs2102_60HZ, cs2102_60HZScale},
6135/* SENSOR_CS2102K 2 */ 5998 [SENSOR_CS2102K] =
6136 {cs2102_NoFliker, cs2102_NoFlikerScale, 5999 {cs2102_NoFliker, cs2102_NoFlikerScale,
6137 NULL, NULL, /* currently disabled */ 6000 NULL, NULL, /* currently disabled */
6138 NULL, NULL}, 6001 NULL, NULL},
6139/* SENSOR_GC0305 3 */ 6002 [SENSOR_GC0305] =
6140 {gc0305_NoFliker, gc0305_NoFliker, 6003 {gc0305_NoFliker, gc0305_NoFliker,
6141 gc0305_50HZ, gc0305_50HZ, 6004 gc0305_50HZ, gc0305_50HZ,
6142 gc0305_60HZ, gc0305_60HZ}, 6005 gc0305_60HZ, gc0305_60HZ},
6143/* SENSOR_HDCS2020b 4 */ 6006 [SENSOR_HDCS2020b] =
6144 {hdcs2020b_NoFliker, hdcs2020b_NoFliker, 6007 {hdcs2020b_NoFliker, hdcs2020b_NoFliker,
6145 hdcs2020b_50HZ, hdcs2020b_50HZ, 6008 hdcs2020b_50HZ, hdcs2020b_50HZ,
6146 hdcs2020b_60HZ, hdcs2020b_60HZ}, 6009 hdcs2020b_60HZ, hdcs2020b_60HZ},
6147/* SENSOR_HV7131B 5 */ 6010 [SENSOR_HV7131B] =
6148 {hv7131b_NoFliker, hv7131b_NoFlikerScale, 6011 {hv7131b_NoFliker, hv7131b_NoFlikerScale,
6149 hv7131b_50HZ, hv7131b_50HZScale, 6012 hv7131b_50HZ, hv7131b_50HZScale,
6150 hv7131b_60HZ, hv7131b_60HZScale}, 6013 hv7131b_60HZ, hv7131b_60HZScale},
6151/* SENSOR_HV7131C 6 */ 6014 [SENSOR_HV7131R] =
6152 {NULL, NULL, 6015 {hv7131r_NoFliker, hv7131r_NoFlikerScale,
6153 NULL, NULL, 6016 hv7131r_50HZ, hv7131r_50HZScale,
6154 NULL, NULL}, 6017 hv7131r_60HZ, hv7131r_60HZScale},
6155/* SENSOR_ICM105A 7 */ 6018 [SENSOR_ICM105A] =
6156 {icm105a_NoFliker, icm105a_NoFlikerScale, 6019 {icm105a_NoFliker, icm105a_NoFlikerScale,
6157 icm105a_50HZ, icm105a_50HZScale, 6020 icm105a_50HZ, icm105a_50HZScale,
6158 icm105a_60HZ, icm105a_60HZScale}, 6021 icm105a_60HZ, icm105a_60HZScale},
6159/* SENSOR_MC501CB 8 */ 6022 [SENSOR_MC501CB] =
6160 {mc501cb_NoFliker, mc501cb_NoFlikerScale, 6023 {mc501cb_NoFliker, mc501cb_NoFlikerScale,
6161 mc501cb_50HZ, mc501cb_50HZScale, 6024 mc501cb_50HZ, mc501cb_50HZScale,
6162 mc501cb_60HZ, mc501cb_60HZScale}, 6025 mc501cb_60HZ, mc501cb_60HZScale},
6163/* SENSOR_MI0360SOC 9 */ 6026 [SENSOR_MT9V111_1] =
6164 {mi360soc_AENoFliker, mi360soc_AENoFlikerScale, 6027 {mt9v111_1_AENoFliker, mt9v111_1_AENoFlikerScale,
6165 mi360soc_AE50HZ, mi360soc_AE50HZScale, 6028 mt9v111_1_AE50HZ, mt9v111_1_AE50HZScale,
6166 mi360soc_AE60HZ, mi360soc_AE60HZScale}, 6029 mt9v111_1_AE60HZ, mt9v111_1_AE60HZScale},
6167/* SENSOR_OV7620 10 */ 6030 [SENSOR_MT9V111_3] =
6031 {mt9v111_3_AENoFliker, mt9v111_3_AENoFlikerScale,
6032 mt9v111_3_AE50HZ, mt9v111_3_AE50HZScale,
6033 mt9v111_3_AE60HZ, mt9v111_3_AE60HZScale},
6034 [SENSOR_OV7620] =
6168 {ov7620_NoFliker, ov7620_NoFliker, 6035 {ov7620_NoFliker, ov7620_NoFliker,
6169 ov7620_50HZ, ov7620_50HZ, 6036 ov7620_50HZ, ov7620_50HZ,
6170 ov7620_60HZ, ov7620_60HZ}, 6037 ov7620_60HZ, ov7620_60HZ},
6171/* SENSOR_OV7630C 11 */ 6038 [SENSOR_OV7630C] =
6172 {NULL, NULL, 6039 {NULL, NULL,
6173 NULL, NULL, 6040 NULL, NULL,
6174 NULL, NULL}, 6041 NULL, NULL},
6175/* SENSOR_PAS106 12 */ 6042 [SENSOR_PAS106] =
6176 {pas106b_NoFliker, pas106b_NoFliker, 6043 {pas106b_NoFliker, pas106b_NoFliker,
6177 pas106b_50HZ, pas106b_50HZ, 6044 pas106b_50HZ, pas106b_50HZ,
6178 pas106b_60HZ, pas106b_60HZ}, 6045 pas106b_60HZ, pas106b_60HZ},
6179/* SENSOR_PAS202B 13 */ 6046 [SENSOR_PAS202B] =
6180 {pas202b_NoFliker, pas202b_NoFlikerScale, 6047 {pas202b_NoFliker, pas202b_NoFlikerScale,
6181 pas202b_50HZ, pas202b_50HZScale, 6048 pas202b_50HZ, pas202b_50HZScale,
6182 pas202b_60HZ, pas202b_60HZScale}, 6049 pas202b_60HZ, pas202b_60HZScale},
6183/* SENSOR_PB0330 14 */ 6050 [SENSOR_PB0330] =
6184 {pb0330_NoFliker, pb0330_NoFlikerScale, 6051 {pb0330_NoFliker, pb0330_NoFlikerScale,
6185 pb0330_50HZ, pb0330_50HZScale, 6052 pb0330_50HZ, pb0330_50HZScale,
6186 pb0330_60HZ, pb0330_60HZScale}, 6053 pb0330_60HZ, pb0330_60HZScale},
6187/* SENSOR_PO2030 15 */ 6054 [SENSOR_PO2030] =
6188 {po2030_NoFliker, po2030_NoFliker, 6055 {po2030_NoFliker, po2030_NoFliker,
6189 po2030_50HZ, po2030_50HZ, 6056 po2030_50HZ, po2030_50HZ,
6190 po2030_60HZ, po2030_60HZ}, 6057 po2030_60HZ, po2030_60HZ},
6191/* SENSOR_TAS5130CK 16 */ 6058 [SENSOR_TAS5130C] =
6192 {tas5130cxx_NoFliker, tas5130cxx_NoFlikerScale, 6059 {tas5130c_NoFliker, tas5130c_NoFlikerScale,
6193 tas5130cxx_50HZ, tas5130cxx_50HZScale, 6060 tas5130c_50HZ, tas5130c_50HZScale,
6194 tas5130cxx_60HZ, tas5130cxx_60HZScale}, 6061 tas5130c_60HZ, tas5130c_60HZScale},
6195/* SENSOR_TAS5130CXX 17 */ 6062 [SENSOR_TAS5130C_VF0250] =
6196 {tas5130cxx_NoFliker, tas5130cxx_NoFlikerScale,
6197 tas5130cxx_50HZ, tas5130cxx_50HZScale,
6198 tas5130cxx_60HZ, tas5130cxx_60HZScale},
6199/* SENSOR_TAS5130C_VF0250 18 */
6200 {tas5130c_vf0250_NoFliker, tas5130c_vf0250_NoFlikerScale, 6063 {tas5130c_vf0250_NoFliker, tas5130c_vf0250_NoFlikerScale,
6201 tas5130c_vf0250_50HZ, tas5130c_vf0250_50HZScale, 6064 tas5130c_vf0250_50HZ, tas5130c_vf0250_50HZScale,
6202 tas5130c_vf0250_60HZ, tas5130c_vf0250_60HZScale}, 6065 tas5130c_vf0250_60HZ, tas5130c_vf0250_60HZScale},
@@ -6207,29 +6070,28 @@ static int setlightfreq(struct gspca_dev *gspca_dev)
6207 if (mode) 6070 if (mode)
6208 i++; /* 320x240 */ 6071 i++; /* 320x240 */
6209 zc3_freq = freq_tb[sd->sensor][i]; 6072 zc3_freq = freq_tb[sd->sensor][i];
6210 if (zc3_freq != NULL) { 6073 if (zc3_freq == NULL)
6211 usb_exchange(gspca_dev, zc3_freq); 6074 return;
6212 switch (sd->sensor) { 6075 usb_exchange(gspca_dev, zc3_freq);
6213 case SENSOR_GC0305: 6076 switch (sd->sensor) {
6214 if (mode /* if 320x240 */ 6077 case SENSOR_GC0305:
6215 && sd->lightfreq == 1) /* and 50Hz */ 6078 if (mode /* if 320x240 */
6216 reg_w(gspca_dev->dev, 0x85, 0x018d); 6079 && sd->lightfreq == 1) /* and 50Hz */
6217 /* win: 0x80, 0x018d */ 6080 reg_w(gspca_dev, 0x85, 0x018d);
6218 break; 6081 /* win: 0x80, 0x018d */
6219 case SENSOR_OV7620: 6082 break;
6220 if (!mode) { /* if 640x480 */ 6083 case SENSOR_OV7620:
6221 if (sd->lightfreq != 0) /* and 50 or 60 Hz */ 6084 if (!mode) { /* if 640x480 */
6222 reg_w(gspca_dev->dev, 0x40, 0x0002); 6085 if (sd->lightfreq != 0) /* and 50 or 60 Hz */
6223 else 6086 reg_w(gspca_dev, 0x40, 0x0002);
6224 reg_w(gspca_dev->dev, 0x44, 0x0002); 6087 else
6225 } 6088 reg_w(gspca_dev, 0x44, 0x0002);
6226 break;
6227 case SENSOR_PAS202B:
6228 reg_w(gspca_dev->dev, 0x00, 0x01a7);
6229 break;
6230 } 6089 }
6090 break;
6091 case SENSOR_PAS202B:
6092 reg_w(gspca_dev, 0x00, 0x01a7);
6093 break;
6231 } 6094 }
6232 return 0;
6233} 6095}
6234 6096
6235static void setautogain(struct gspca_dev *gspca_dev) 6097static void setautogain(struct gspca_dev *gspca_dev)
@@ -6241,45 +6103,46 @@ static void setautogain(struct gspca_dev *gspca_dev)
6241 autoval = 0x42; 6103 autoval = 0x42;
6242 else 6104 else
6243 autoval = 0x02; 6105 autoval = 0x02;
6244 reg_w(gspca_dev->dev, autoval, 0x0180); 6106 reg_w(gspca_dev, autoval, 0x0180);
6245} 6107}
6246 6108
6247static void send_unknown(struct usb_device *dev, int sensor) 6109static void send_unknown(struct gspca_dev *gspca_dev, int sensor)
6248{ 6110{
6249 reg_w(dev, 0x01, 0x0000); /* led off */ 6111 reg_w(gspca_dev, 0x01, 0x0000); /* led off */
6250 switch (sensor) { 6112 switch (sensor) {
6251 case SENSOR_PAS106: 6113 case SENSOR_PAS106:
6252 reg_w(dev, 0x03, 0x003a); 6114 reg_w(gspca_dev, 0x03, 0x003a);
6253 reg_w(dev, 0x0c, 0x003b); 6115 reg_w(gspca_dev, 0x0c, 0x003b);
6254 reg_w(dev, 0x08, 0x0038); 6116 reg_w(gspca_dev, 0x08, 0x0038);
6255 break; 6117 break;
6256 case SENSOR_ADCM2700: 6118 case SENSOR_ADCM2700:
6257 case SENSOR_GC0305: 6119 case SENSOR_GC0305:
6258 case SENSOR_OV7620: 6120 case SENSOR_OV7620:
6259 case SENSOR_MI0360SOC: 6121 case SENSOR_MT9V111_1:
6122 case SENSOR_MT9V111_3:
6260 case SENSOR_PB0330: 6123 case SENSOR_PB0330:
6261 case SENSOR_PO2030: 6124 case SENSOR_PO2030:
6262 reg_w(dev, 0x0d, 0x003a); 6125 reg_w(gspca_dev, 0x0d, 0x003a);
6263 reg_w(dev, 0x02, 0x003b); 6126 reg_w(gspca_dev, 0x02, 0x003b);
6264 reg_w(dev, 0x00, 0x0038); 6127 reg_w(gspca_dev, 0x00, 0x0038);
6265 break; 6128 break;
6266 case SENSOR_PAS202B: 6129 case SENSOR_PAS202B:
6267 reg_w(dev, 0x03, 0x003b); 6130 reg_w(gspca_dev, 0x03, 0x003b);
6268 reg_w(dev, 0x0c, 0x003a); 6131 reg_w(gspca_dev, 0x0c, 0x003a);
6269 reg_w(dev, 0x0b, 0x0039); 6132 reg_w(gspca_dev, 0x0b, 0x0039);
6270 reg_w(dev, 0x0b, 0x0038); 6133 reg_w(gspca_dev, 0x0b, 0x0038);
6271 break; 6134 break;
6272 } 6135 }
6273} 6136}
6274 6137
6275/* start probe 2 wires */ 6138/* start probe 2 wires */
6276static void start_2wr_probe(struct usb_device *dev, int sensor) 6139static void start_2wr_probe(struct gspca_dev *gspca_dev, int sensor)
6277{ 6140{
6278 reg_w(dev, 0x01, 0x0000); 6141 reg_w(gspca_dev, 0x01, 0x0000);
6279 reg_w(dev, sensor, 0x0010); 6142 reg_w(gspca_dev, sensor, 0x0010);
6280 reg_w(dev, 0x01, 0x0001); 6143 reg_w(gspca_dev, 0x01, 0x0001);
6281 reg_w(dev, 0x03, 0x0012); 6144 reg_w(gspca_dev, 0x03, 0x0012);
6282 reg_w(dev, 0x01, 0x0012); 6145 reg_w(gspca_dev, 0x01, 0x0012);
6283/* msleep(2); */ 6146/* msleep(2); */
6284} 6147}
6285 6148
@@ -6287,14 +6150,14 @@ static int sif_probe(struct gspca_dev *gspca_dev)
6287{ 6150{
6288 u16 checkword; 6151 u16 checkword;
6289 6152
6290 start_2wr_probe(gspca_dev->dev, 0x0f); /* PAS106 */ 6153 start_2wr_probe(gspca_dev, 0x0f); /* PAS106 */
6291 reg_w(gspca_dev->dev, 0x08, 0x008d); 6154 reg_w(gspca_dev, 0x08, 0x008d);
6292 msleep(150); 6155 msleep(150);
6293 checkword = ((i2c_read(gspca_dev, 0x00) & 0x0f) << 4) 6156 checkword = ((i2c_read(gspca_dev, 0x00) & 0x0f) << 4)
6294 | ((i2c_read(gspca_dev, 0x01) & 0xf0) >> 4); 6157 | ((i2c_read(gspca_dev, 0x01) & 0xf0) >> 4);
6295 PDEBUG(D_PROBE, "probe sif 0x%04x", checkword); 6158 PDEBUG(D_PROBE, "probe sif 0x%04x", checkword);
6296 if (checkword == 0x0007) { 6159 if (checkword == 0x0007) {
6297 send_unknown(gspca_dev->dev, SENSOR_PAS106); 6160 send_unknown(gspca_dev, SENSOR_PAS106);
6298 return 0x0f; /* PAS106 */ 6161 return 0x0f; /* PAS106 */
6299 } 6162 }
6300 return -1; 6163 return -1;
@@ -6302,23 +6165,22 @@ static int sif_probe(struct gspca_dev *gspca_dev)
6302 6165
6303static int vga_2wr_probe(struct gspca_dev *gspca_dev) 6166static int vga_2wr_probe(struct gspca_dev *gspca_dev)
6304{ 6167{
6305 struct usb_device *dev = gspca_dev->dev;
6306 u16 retword; 6168 u16 retword;
6307 6169
6308 start_2wr_probe(dev, 0x00); /* HV7131B */ 6170 start_2wr_probe(gspca_dev, 0x00); /* HV7131B */
6309 i2c_write(gspca_dev, 0x01, 0xaa, 0x00); 6171 i2c_write(gspca_dev, 0x01, 0xaa, 0x00);
6310 retword = i2c_read(gspca_dev, 0x01); 6172 retword = i2c_read(gspca_dev, 0x01);
6311 if (retword != 0) 6173 if (retword != 0)
6312 return 0x00; /* HV7131B */ 6174 return 0x00; /* HV7131B */
6313 6175
6314 start_2wr_probe(dev, 0x04); /* CS2102 */ 6176 start_2wr_probe(gspca_dev, 0x04); /* CS2102 */
6315 i2c_write(gspca_dev, 0x01, 0xaa, 0x00); 6177 i2c_write(gspca_dev, 0x01, 0xaa, 0x00);
6316 retword = i2c_read(gspca_dev, 0x01); 6178 retword = i2c_read(gspca_dev, 0x01);
6317 if (retword != 0) 6179 if (retword != 0)
6318 return 0x04; /* CS2102 */ 6180 return 0x04; /* CS2102 */
6319 6181
6320 start_2wr_probe(dev, 0x06); /* OmniVision */ 6182 start_2wr_probe(gspca_dev, 0x06); /* OmniVision */
6321 reg_w(dev, 0x08, 0x008d); 6183 reg_w(gspca_dev, 0x08, 0x008d);
6322 i2c_write(gspca_dev, 0x11, 0xaa, 0x00); 6184 i2c_write(gspca_dev, 0x11, 0xaa, 0x00);
6323 retword = i2c_read(gspca_dev, 0x11); 6185 retword = i2c_read(gspca_dev, 0x11);
6324 if (retword != 0) { 6186 if (retword != 0) {
@@ -6327,14 +6189,14 @@ static int vga_2wr_probe(struct gspca_dev *gspca_dev)
6327 goto ov_check; 6189 goto ov_check;
6328 } 6190 }
6329 6191
6330 start_2wr_probe(dev, 0x08); /* HDCS2020 */ 6192 start_2wr_probe(gspca_dev, 0x08); /* HDCS2020 */
6331 i2c_write(gspca_dev, 0x1c, 0x00, 0x00); 6193 i2c_write(gspca_dev, 0x1c, 0x00, 0x00);
6332 i2c_write(gspca_dev, 0x15, 0xaa, 0x00); 6194 i2c_write(gspca_dev, 0x15, 0xaa, 0x00);
6333 retword = i2c_read(gspca_dev, 0x15); 6195 retword = i2c_read(gspca_dev, 0x15);
6334 if (retword != 0) 6196 if (retword != 0)
6335 return 0x08; /* HDCS2020 */ 6197 return 0x08; /* HDCS2020 */
6336 6198
6337 start_2wr_probe(dev, 0x0a); /* PB0330 */ 6199 start_2wr_probe(gspca_dev, 0x0a); /* PB0330 */
6338 i2c_write(gspca_dev, 0x07, 0xaa, 0xaa); 6200 i2c_write(gspca_dev, 0x07, 0xaa, 0xaa);
6339 retword = i2c_read(gspca_dev, 0x07); 6201 retword = i2c_read(gspca_dev, 0x07);
6340 if (retword != 0) 6202 if (retword != 0)
@@ -6346,23 +6208,23 @@ static int vga_2wr_probe(struct gspca_dev *gspca_dev)
6346 if (retword != 0) 6208 if (retword != 0)
6347 return 0x0a; /* PB0330 ?? */ 6209 return 0x0a; /* PB0330 ?? */
6348 6210
6349 start_2wr_probe(dev, 0x0c); /* ICM105A */ 6211 start_2wr_probe(gspca_dev, 0x0c); /* ICM105A */
6350 i2c_write(gspca_dev, 0x01, 0x11, 0x00); 6212 i2c_write(gspca_dev, 0x01, 0x11, 0x00);
6351 retword = i2c_read(gspca_dev, 0x01); 6213 retword = i2c_read(gspca_dev, 0x01);
6352 if (retword != 0) 6214 if (retword != 0)
6353 return 0x0c; /* ICM105A */ 6215 return 0x0c; /* ICM105A */
6354 6216
6355 start_2wr_probe(dev, 0x0e); /* PAS202BCB */ 6217 start_2wr_probe(gspca_dev, 0x0e); /* PAS202BCB */
6356 reg_w(dev, 0x08, 0x008d); 6218 reg_w(gspca_dev, 0x08, 0x008d);
6357 i2c_write(gspca_dev, 0x03, 0xaa, 0x00); 6219 i2c_write(gspca_dev, 0x03, 0xaa, 0x00);
6358 msleep(50); 6220 msleep(50);
6359 retword = i2c_read(gspca_dev, 0x03); 6221 retword = i2c_read(gspca_dev, 0x03);
6360 if (retword != 0) { 6222 if (retword != 0) {
6361 send_unknown(dev, SENSOR_PAS202B); 6223 send_unknown(gspca_dev, SENSOR_PAS202B);
6362 return 0x0e; /* PAS202BCB */ 6224 return 0x0e; /* PAS202BCB */
6363 } 6225 }
6364 6226
6365 start_2wr_probe(dev, 0x02); /* TAS5130C */ 6227 start_2wr_probe(gspca_dev, 0x02); /* TAS5130C */
6366 i2c_write(gspca_dev, 0x01, 0xaa, 0x00); 6228 i2c_write(gspca_dev, 0x01, 0xaa, 0x00);
6367 retword = i2c_read(gspca_dev, 0x01); 6229 retword = i2c_read(gspca_dev, 0x01);
6368 if (retword != 0) 6230 if (retword != 0)
@@ -6371,20 +6233,20 @@ ov_check:
6371 reg_r(gspca_dev, 0x0010); /* ?? */ 6233 reg_r(gspca_dev, 0x0010); /* ?? */
6372 reg_r(gspca_dev, 0x0010); 6234 reg_r(gspca_dev, 0x0010);
6373 6235
6374 reg_w(dev, 0x01, 0x0000); 6236 reg_w(gspca_dev, 0x01, 0x0000);
6375 reg_w(dev, 0x01, 0x0001); 6237 reg_w(gspca_dev, 0x01, 0x0001);
6376 reg_w(dev, 0x06, 0x0010); /* OmniVision */ 6238 reg_w(gspca_dev, 0x06, 0x0010); /* OmniVision */
6377 reg_w(dev, 0xa1, 0x008b); 6239 reg_w(gspca_dev, 0xa1, 0x008b);
6378 reg_w(dev, 0x08, 0x008d); 6240 reg_w(gspca_dev, 0x08, 0x008d);
6379 msleep(500); 6241 msleep(500);
6380 reg_w(dev, 0x01, 0x0012); 6242 reg_w(gspca_dev, 0x01, 0x0012);
6381 i2c_write(gspca_dev, 0x12, 0x80, 0x00); /* sensor reset */ 6243 i2c_write(gspca_dev, 0x12, 0x80, 0x00); /* sensor reset */
6382 retword = i2c_read(gspca_dev, 0x0a) << 8; 6244 retword = i2c_read(gspca_dev, 0x0a) << 8;
6383 retword |= i2c_read(gspca_dev, 0x0b); 6245 retword |= i2c_read(gspca_dev, 0x0b);
6384 PDEBUG(D_PROBE, "probe 2wr ov vga 0x%04x", retword); 6246 PDEBUG(D_PROBE, "probe 2wr ov vga 0x%04x", retword);
6385 switch (retword) { 6247 switch (retword) {
6386 case 0x7631: /* OV7630C */ 6248 case 0x7631: /* OV7630C */
6387 reg_w(dev, 0x06, 0x0010); 6249 reg_w(gspca_dev, 0x06, 0x0010);
6388 break; 6250 break;
6389 case 0x7620: /* OV7620 */ 6251 case 0x7620: /* OV7620 */
6390 case 0x7648: /* OV7648 */ 6252 case 0x7648: /* OV7648 */
@@ -6401,32 +6263,31 @@ struct sensor_by_chipset_revision {
6401}; 6263};
6402static const struct sensor_by_chipset_revision chipset_revision_sensor[] = { 6264static const struct sensor_by_chipset_revision chipset_revision_sensor[] = {
6403 {0xc000, 0x12}, /* TAS5130C */ 6265 {0xc000, 0x12}, /* TAS5130C */
6404 {0xc001, 0x13}, /* MI0360SOC */ 6266 {0xc001, 0x13}, /* MT9V111 */
6405 {0xe001, 0x13}, 6267 {0xe001, 0x13},
6406 {0x8001, 0x13}, 6268 {0x8001, 0x13},
6407 {0x8000, 0x14}, /* CS2102K */ 6269 {0x8000, 0x14}, /* CS2102K */
6408 {0x8400, 0x15}, /* TAS5130K */ 6270 {0x8400, 0x15}, /* MT9V111 */
6409 {0xe400, 0x15}, 6271 {0xe400, 0x15},
6410}; 6272};
6411 6273
6412static int vga_3wr_probe(struct gspca_dev *gspca_dev) 6274static int vga_3wr_probe(struct gspca_dev *gspca_dev)
6413{ 6275{
6414 struct sd *sd = (struct sd *) gspca_dev; 6276 struct sd *sd = (struct sd *) gspca_dev;
6415 struct usb_device *dev = gspca_dev->dev;
6416 int i; 6277 int i;
6417 u8 retbyte; 6278 u8 retbyte;
6418 u16 retword; 6279 u16 retword;
6419 6280
6420/*fixme: lack of 8b=b3 (11,12)-> 10, 8b=e0 (14,15,16)-> 12 found in gspcav1*/ 6281/*fixme: lack of 8b=b3 (11,12)-> 10, 8b=e0 (14,15,16)-> 12 found in gspcav1*/
6421 reg_w(dev, 0x02, 0x0010); 6282 reg_w(gspca_dev, 0x02, 0x0010);
6422 reg_r(gspca_dev, 0x0010); 6283 reg_r(gspca_dev, 0x0010);
6423 reg_w(dev, 0x01, 0x0000); 6284 reg_w(gspca_dev, 0x01, 0x0000);
6424 reg_w(dev, 0x00, 0x0010); 6285 reg_w(gspca_dev, 0x00, 0x0010);
6425 reg_w(dev, 0x01, 0x0001); 6286 reg_w(gspca_dev, 0x01, 0x0001);
6426 reg_w(dev, 0x91, 0x008b); 6287 reg_w(gspca_dev, 0x91, 0x008b);
6427 reg_w(dev, 0x03, 0x0012); 6288 reg_w(gspca_dev, 0x03, 0x0012);
6428 reg_w(dev, 0x01, 0x0012); 6289 reg_w(gspca_dev, 0x01, 0x0012);
6429 reg_w(dev, 0x05, 0x0012); 6290 reg_w(gspca_dev, 0x05, 0x0012);
6430 retword = i2c_read(gspca_dev, 0x14); 6291 retword = i2c_read(gspca_dev, 0x14);
6431 if (retword != 0) 6292 if (retword != 0)
6432 return 0x11; /* HV7131R */ 6293 return 0x11; /* HV7131R */
@@ -6437,93 +6298,90 @@ static int vga_3wr_probe(struct gspca_dev *gspca_dev)
6437 if (retword != 0) 6298 if (retword != 0)
6438 return 0x11; /* HV7131R */ 6299 return 0x11; /* HV7131R */
6439 6300
6440 reg_w(dev, 0x02, 0x0010); 6301 reg_w(gspca_dev, 0x02, 0x0010);
6441 retword = reg_r(gspca_dev, 0x000b) << 8; 6302 retword = reg_r(gspca_dev, 0x000b) << 8;
6442 retword |= reg_r(gspca_dev, 0x000a); 6303 retword |= reg_r(gspca_dev, 0x000a);
6443 PDEBUG(D_PROBE, "probe 3wr vga 1 0x%04x", retword); 6304 PDEBUG(D_PROBE, "probe 3wr vga 1 0x%04x", retword);
6444 reg_r(gspca_dev, 0x0010); 6305 reg_r(gspca_dev, 0x0010);
6445 /* value 0x4001 is meaningless */ 6306 if ((retword & 0xff00) == 0x6400)
6446 if (retword != 0x4001) { 6307 return 0x02; /* TAS5130C */
6447 if ((retword & 0xff00) == 0x6400) 6308 for (i = 0; i < ARRAY_SIZE(chipset_revision_sensor); i++) {
6448 return 0x02; /* TAS5130C */ 6309 if (chipset_revision_sensor[i].revision == retword) {
6449 for (i = 0; i < ARRAY_SIZE(chipset_revision_sensor); i++) { 6310 sd->chip_revision = retword;
6450 if (chipset_revision_sensor[i].revision == retword) { 6311 send_unknown(gspca_dev, SENSOR_PB0330);
6451 sd->chip_revision = retword; 6312 return chipset_revision_sensor[i]
6452 send_unknown(dev, SENSOR_PB0330); 6313 .internal_sensor_id;
6453 return chipset_revision_sensor[i]
6454 .internal_sensor_id;
6455 }
6456 } 6314 }
6457 } 6315 }
6458 6316
6459 reg_w(dev, 0x01, 0x0000); /* check PB0330 */ 6317 reg_w(gspca_dev, 0x01, 0x0000); /* check PB0330 */
6460 reg_w(dev, 0x01, 0x0001); 6318 reg_w(gspca_dev, 0x01, 0x0001);
6461 reg_w(dev, 0xdd, 0x008b); 6319 reg_w(gspca_dev, 0xdd, 0x008b);
6462 reg_w(dev, 0x0a, 0x0010); 6320 reg_w(gspca_dev, 0x0a, 0x0010);
6463 reg_w(dev, 0x03, 0x0012); 6321 reg_w(gspca_dev, 0x03, 0x0012);
6464 reg_w(dev, 0x01, 0x0012); 6322 reg_w(gspca_dev, 0x01, 0x0012);
6465 retword = i2c_read(gspca_dev, 0x00); 6323 retword = i2c_read(gspca_dev, 0x00);
6466 if (retword != 0) { 6324 if (retword != 0) {
6467 PDEBUG(D_PROBE, "probe 3wr vga type 0a ?"); 6325 PDEBUG(D_PROBE, "probe 3wr vga type 0a");
6468 return 0x0a; /* PB0330 */ 6326 return 0x0a; /* PB0330 */
6469 } 6327 }
6470 6328
6471 reg_w(dev, 0x01, 0x0000); 6329 reg_w(gspca_dev, 0x01, 0x0000);
6472 reg_w(dev, 0x01, 0x0001); 6330 reg_w(gspca_dev, 0x01, 0x0001);
6473 reg_w(dev, 0x98, 0x008b); 6331 reg_w(gspca_dev, 0x98, 0x008b);
6474 reg_w(dev, 0x01, 0x0010); 6332 reg_w(gspca_dev, 0x01, 0x0010);
6475 reg_w(dev, 0x03, 0x0012); 6333 reg_w(gspca_dev, 0x03, 0x0012);
6476 msleep(2); 6334 msleep(2);
6477 reg_w(dev, 0x01, 0x0012); 6335 reg_w(gspca_dev, 0x01, 0x0012);
6478 retword = i2c_read(gspca_dev, 0x00); 6336 retword = i2c_read(gspca_dev, 0x00);
6479 if (retword != 0) { 6337 if (retword != 0) {
6480 PDEBUG(D_PROBE, "probe 3wr vga type %02x", retword); 6338 PDEBUG(D_PROBE, "probe 3wr vga type %02x", retword);
6481 if (retword == 0x0011) /* VF0250 */ 6339 if (retword == 0x0011) /* VF0250 */
6482 return 0x0250; 6340 return 0x0250;
6483 if (retword == 0x0029) /* gc0305 */ 6341 if (retword == 0x0029) /* gc0305 */
6484 send_unknown(dev, SENSOR_GC0305); 6342 send_unknown(gspca_dev, SENSOR_GC0305);
6485 return retword; 6343 return retword;
6486 } 6344 }
6487 6345
6488 reg_w(dev, 0x01, 0x0000); /* check OmniVision */ 6346 reg_w(gspca_dev, 0x01, 0x0000); /* check OmniVision */
6489 reg_w(dev, 0x01, 0x0001); 6347 reg_w(gspca_dev, 0x01, 0x0001);
6490 reg_w(dev, 0xa1, 0x008b); 6348 reg_w(gspca_dev, 0xa1, 0x008b);
6491 reg_w(dev, 0x08, 0x008d); 6349 reg_w(gspca_dev, 0x08, 0x008d);
6492 reg_w(dev, 0x06, 0x0010); 6350 reg_w(gspca_dev, 0x06, 0x0010);
6493 reg_w(dev, 0x01, 0x0012); 6351 reg_w(gspca_dev, 0x01, 0x0012);
6494 reg_w(dev, 0x05, 0x0012); 6352 reg_w(gspca_dev, 0x05, 0x0012);
6495 if (i2c_read(gspca_dev, 0x1c) == 0x007f /* OV7610 - manufacturer ID */ 6353 if (i2c_read(gspca_dev, 0x1c) == 0x007f /* OV7610 - manufacturer ID */
6496 && i2c_read(gspca_dev, 0x1d) == 0x00a2) { 6354 && i2c_read(gspca_dev, 0x1d) == 0x00a2) {
6497 send_unknown(dev, SENSOR_OV7620); 6355 send_unknown(gspca_dev, SENSOR_OV7620);
6498 return 0x06; /* OmniVision confirm ? */ 6356 return 0x06; /* OmniVision confirm ? */
6499 } 6357 }
6500 6358
6501 reg_w(dev, 0x01, 0x0000); 6359 reg_w(gspca_dev, 0x01, 0x0000);
6502 reg_w(dev, 0x00, 0x0002); 6360 reg_w(gspca_dev, 0x00, 0x0002);
6503 reg_w(dev, 0x01, 0x0010); 6361 reg_w(gspca_dev, 0x01, 0x0010);
6504 reg_w(dev, 0x01, 0x0001); 6362 reg_w(gspca_dev, 0x01, 0x0001);
6505 reg_w(dev, 0xee, 0x008b); 6363 reg_w(gspca_dev, 0xee, 0x008b);
6506 reg_w(dev, 0x03, 0x0012); 6364 reg_w(gspca_dev, 0x03, 0x0012);
6507 reg_w(dev, 0x01, 0x0012); 6365 reg_w(gspca_dev, 0x01, 0x0012);
6508 reg_w(dev, 0x05, 0x0012); 6366 reg_w(gspca_dev, 0x05, 0x0012);
6509 retword = i2c_read(gspca_dev, 0x00) << 8; /* ID 0 */ 6367 retword = i2c_read(gspca_dev, 0x00) << 8; /* ID 0 */
6510 retword |= i2c_read(gspca_dev, 0x01); /* ID 1 */ 6368 retword |= i2c_read(gspca_dev, 0x01); /* ID 1 */
6511 PDEBUG(D_PROBE, "probe 3wr vga 2 0x%04x", retword); 6369 PDEBUG(D_PROBE, "probe 3wr vga 2 0x%04x", retword);
6512 if (retword == 0x2030) { 6370 if (retword == 0x2030) {
6513 retbyte = i2c_read(gspca_dev, 0x02); /* revision number */ 6371 retbyte = i2c_read(gspca_dev, 0x02); /* revision number */
6514 PDEBUG(D_PROBE, "sensor PO2030 rev 0x%02x", retbyte); 6372 PDEBUG(D_PROBE, "sensor PO2030 rev 0x%02x", retbyte);
6515 send_unknown(dev, SENSOR_PO2030); 6373 send_unknown(gspca_dev, SENSOR_PO2030);
6516 return retword; 6374 return retword;
6517 } 6375 }
6518 6376
6519 reg_w(dev, 0x01, 0x0000); 6377 reg_w(gspca_dev, 0x01, 0x0000);
6520 reg_w(dev, 0x0a, 0x0010); 6378 reg_w(gspca_dev, 0x0a, 0x0010);
6521 reg_w(dev, 0xd3, 0x008b); 6379 reg_w(gspca_dev, 0xd3, 0x008b);
6522 reg_w(dev, 0x01, 0x0001); 6380 reg_w(gspca_dev, 0x01, 0x0001);
6523 reg_w(dev, 0x03, 0x0012); 6381 reg_w(gspca_dev, 0x03, 0x0012);
6524 reg_w(dev, 0x01, 0x0012); 6382 reg_w(gspca_dev, 0x01, 0x0012);
6525 reg_w(dev, 0x05, 0x0012); 6383 reg_w(gspca_dev, 0x05, 0x0012);
6526 reg_w(dev, 0xd3, 0x008b); 6384 reg_w(gspca_dev, 0xd3, 0x008b);
6527 retword = i2c_read(gspca_dev, 0x01); 6385 retword = i2c_read(gspca_dev, 0x01);
6528 if (retword != 0) { 6386 if (retword != 0) {
6529 PDEBUG(D_PROBE, "probe 3wr vga type 0a ? ret: %04x", retword); 6387 PDEBUG(D_PROBE, "probe 3wr vga type 0a ? ret: %04x", retword);
@@ -6560,54 +6418,74 @@ static int sd_config(struct gspca_dev *gspca_dev,
6560 const struct usb_device_id *id) 6418 const struct usb_device_id *id)
6561{ 6419{
6562 struct sd *sd = (struct sd *) gspca_dev; 6420 struct sd *sd = (struct sd *) gspca_dev;
6421
6422 if (id->idProduct == 0x301b)
6423 sd->bridge = BRIDGE_ZC301;
6424 else
6425 sd->bridge = BRIDGE_ZC303;
6426
6427 /* define some sensors from the vendor/product */
6428 sd->sensor = id->driver_info;
6429
6430 sd->sharpness = SHARPNESS_DEF;
6431 sd->brightness = BRIGHTNESS_DEF;
6432 sd->contrast = CONTRAST_DEF;
6433 sd->autogain = AUTOGAIN_DEF;
6434 sd->lightfreq = FREQ_DEF;
6435 sd->quality = QUALITY_DEF;
6436
6437 return 0;
6438}
6439
6440/* this function is called at probe and resume time */
6441static int sd_init(struct gspca_dev *gspca_dev)
6442{
6443 struct sd *sd = (struct sd *) gspca_dev;
6563 struct cam *cam; 6444 struct cam *cam;
6564 int sensor; 6445 int sensor;
6565 static const u8 gamma[SENSOR_MAX] = { 6446 static const u8 gamma[SENSOR_MAX] = {
6566 4, /* SENSOR_ADCM2700 0 */ 6447 [SENSOR_ADCM2700] = 4,
6567 4, /* SENSOR_CS2102 1 */ 6448 [SENSOR_CS2102] = 4,
6568 5, /* SENSOR_CS2102K 2 */ 6449 [SENSOR_CS2102K] = 5,
6569 4, /* SENSOR_GC0305 3 */ 6450 [SENSOR_GC0305] = 4,
6570 4, /* SENSOR_HDCS2020b 4 */ 6451 [SENSOR_HDCS2020b] = 4,
6571 4, /* SENSOR_HV7131B 5 */ 6452 [SENSOR_HV7131B] = 4,
6572 4, /* SENSOR_HV7131C 6 */ 6453 [SENSOR_HV7131R] = 4,
6573 4, /* SENSOR_ICM105A 7 */ 6454 [SENSOR_ICM105A] = 4,
6574 4, /* SENSOR_MC501CB 8 */ 6455 [SENSOR_MC501CB] = 4,
6575 4, /* SENSOR_MI0360SOC 9 */ 6456 [SENSOR_MT9V111_1] = 4,
6576 3, /* SENSOR_OV7620 10 */ 6457 [SENSOR_MT9V111_3] = 4,
6577 4, /* SENSOR_OV7630C 11 */ 6458 [SENSOR_OV7620] = 3,
6578 4, /* SENSOR_PAS106 12 */ 6459 [SENSOR_OV7630C] = 4,
6579 4, /* SENSOR_PAS202B 13 */ 6460 [SENSOR_PAS106] = 4,
6580 4, /* SENSOR_PB0330 14 */ 6461 [SENSOR_PAS202B] = 4,
6581 4, /* SENSOR_PO2030 15 */ 6462 [SENSOR_PB0330] = 4,
6582 4, /* SENSOR_TAS5130CK 16 */ 6463 [SENSOR_PO2030] = 4,
6583 3, /* SENSOR_TAS5130CXX 17 */ 6464 [SENSOR_TAS5130C] = 3,
6584 3, /* SENSOR_TAS5130C_VF0250 18 */ 6465 [SENSOR_TAS5130C_VF0250] = 3,
6585 }; 6466 };
6586 static const u8 mode_tb[SENSOR_MAX] = { 6467 static const u8 mode_tb[SENSOR_MAX] = {
6587 2, /* SENSOR_ADCM2700 0 */ 6468 [SENSOR_ADCM2700] = 2,
6588 1, /* SENSOR_CS2102 1 */ 6469 [SENSOR_CS2102] = 1,
6589 1, /* SENSOR_CS2102K 2 */ 6470 [SENSOR_CS2102K] = 1,
6590 1, /* SENSOR_GC0305 3 */ 6471 [SENSOR_GC0305] = 1,
6591 1, /* SENSOR_HDCS2020b 4 */ 6472 [SENSOR_HDCS2020b] = 1,
6592 1, /* SENSOR_HV7131B 5 */ 6473 [SENSOR_HV7131B] = 1,
6593 1, /* SENSOR_HV7131C 6 */ 6474 [SENSOR_HV7131R] = 1,
6594 1, /* SENSOR_ICM105A 7 */ 6475 [SENSOR_ICM105A] = 1,
6595 2, /* SENSOR_MC501CB 8 */ 6476 [SENSOR_MC501CB] = 2,
6596 1, /* SENSOR_MI0360SOC 9 */ 6477 [SENSOR_MT9V111_1] = 1,
6597 2, /* SENSOR_OV7620 10 */ 6478 [SENSOR_MT9V111_3] = 1,
6598 1, /* SENSOR_OV7630C 11 */ 6479 [SENSOR_OV7620] = 2,
6599 0, /* SENSOR_PAS106 12 */ 6480 [SENSOR_OV7630C] = 1,
6600 1, /* SENSOR_PAS202B 13 */ 6481 [SENSOR_PAS106] = 0,
6601 1, /* SENSOR_PB0330 14 */ 6482 [SENSOR_PAS202B] = 1,
6602 1, /* SENSOR_PO2030 15 */ 6483 [SENSOR_PB0330] = 1,
6603 1, /* SENSOR_TAS5130CK 16 */ 6484 [SENSOR_PO2030] = 1,
6604 1, /* SENSOR_TAS5130CXX 17 */ 6485 [SENSOR_TAS5130C] = 1,
6605 1, /* SENSOR_TAS5130C_VF0250 18 */ 6486 [SENSOR_TAS5130C_VF0250] = 1,
6606 }; 6487 };
6607 6488
6608 /* define some sensors from the vendor/product */
6609 sd->sharpness = SHARPNESS_DEF;
6610 sd->sensor = id->driver_info;
6611 sensor = zcxx_probeSensor(gspca_dev); 6489 sensor = zcxx_probeSensor(gspca_dev);
6612 if (sensor >= 0) 6490 if (sensor >= 0)
6613 PDEBUG(D_PROBE, "probe sensor -> %04x", sensor); 6491 PDEBUG(D_PROBE, "probe sensor -> %04x", sensor);
@@ -6626,8 +6504,8 @@ static int sd_config(struct gspca_dev *gspca_dev,
6626 break; 6504 break;
6627 default: 6505 default:
6628 PDEBUG(D_PROBE, 6506 PDEBUG(D_PROBE,
6629 "Sensor UNKNOWN_0 force Tas5130"); 6507 "Unknown sensor - set to TAS5130C");
6630 sd->sensor = SENSOR_TAS5130CXX; 6508 sd->sensor = SENSOR_TAS5130C;
6631 } 6509 }
6632 break; 6510 break;
6633 case 0: 6511 case 0:
@@ -6642,14 +6520,14 @@ static int sd_config(struct gspca_dev *gspca_dev,
6642 break; 6520 break;
6643 default: 6521 default:
6644/* case 2: * hv7131r */ 6522/* case 2: * hv7131r */
6645 PDEBUG(D_PROBE, "Find Sensor HV7131R(c)"); 6523 PDEBUG(D_PROBE, "Find Sensor HV7131R");
6646 sd->sensor = SENSOR_HV7131C; 6524 sd->sensor = SENSOR_HV7131R;
6647 break; 6525 break;
6648 } 6526 }
6649 break; 6527 break;
6650 case 0x02: 6528 case 0x02:
6651 PDEBUG(D_PROBE, "Sensor TAS5130C"); 6529 PDEBUG(D_PROBE, "Sensor TAS5130C");
6652 sd->sensor = SENSOR_TAS5130CXX; 6530 sd->sensor = SENSOR_TAS5130C;
6653 break; 6531 break;
6654 case 0x04: 6532 case 0x04:
6655 PDEBUG(D_PROBE, "Find Sensor CS2102"); 6533 PDEBUG(D_PROBE, "Find Sensor CS2102");
@@ -6681,17 +6559,20 @@ static int sd_config(struct gspca_dev *gspca_dev,
6681 case 0x10: 6559 case 0x10:
6682 case 0x12: 6560 case 0x12:
6683 PDEBUG(D_PROBE, "Find Sensor TAS5130C"); 6561 PDEBUG(D_PROBE, "Find Sensor TAS5130C");
6684 sd->sensor = SENSOR_TAS5130CXX; 6562 sd->sensor = SENSOR_TAS5130C;
6685 break; 6563 break;
6686 case 0x11: 6564 case 0x11:
6687 PDEBUG(D_PROBE, "Find Sensor HV7131R(c)"); 6565 PDEBUG(D_PROBE, "Find Sensor HV7131R");
6688 sd->sensor = SENSOR_HV7131C; 6566 sd->sensor = SENSOR_HV7131R;
6689 break; 6567 break;
6690 case 0x13: 6568 case 0x13:
6569 case 0x15:
6691 PDEBUG(D_PROBE, 6570 PDEBUG(D_PROBE,
6692 "Find Sensor MI0360SOC. Chip revision %x", 6571 "Sensor MT9V111. Chip revision %04x",
6693 sd->chip_revision); 6572 sd->chip_revision);
6694 sd->sensor = SENSOR_MI0360SOC; 6573 sd->sensor = sd->bridge == BRIDGE_ZC301
6574 ? SENSOR_MT9V111_1
6575 : SENSOR_MT9V111_3;
6695 break; 6576 break;
6696 case 0x14: 6577 case 0x14:
6697 PDEBUG(D_PROBE, 6578 PDEBUG(D_PROBE,
@@ -6699,12 +6580,6 @@ static int sd_config(struct gspca_dev *gspca_dev,
6699 sd->chip_revision); 6580 sd->chip_revision);
6700 sd->sensor = SENSOR_CS2102K; 6581 sd->sensor = SENSOR_CS2102K;
6701 break; 6582 break;
6702 case 0x15:
6703 PDEBUG(D_PROBE,
6704 "Find Sensor TAS5130CK?. Chip revision %x",
6705 sd->chip_revision);
6706 sd->sensor = SENSOR_TAS5130CK;
6707 break;
6708 case 0x16: 6583 case 0x16:
6709 PDEBUG(D_PROBE, "Find Sensor ADCM2700"); 6584 PDEBUG(D_PROBE, "Find Sensor ADCM2700");
6710 sd->sensor = SENSOR_ADCM2700; 6585 sd->sensor = SENSOR_ADCM2700;
@@ -6741,13 +6616,11 @@ static int sd_config(struct gspca_dev *gspca_dev,
6741 } 6616 }
6742 if (sensor < 0x20) { 6617 if (sensor < 0x20) {
6743 if (sensor == -1 || sensor == 0x10 || sensor == 0x12) 6618 if (sensor == -1 || sensor == 0x10 || sensor == 0x12)
6744 reg_w(gspca_dev->dev, 0x02, 0x0010); 6619 reg_w(gspca_dev, 0x02, 0x0010);
6745 reg_r(gspca_dev, 0x0010); 6620 reg_r(gspca_dev, 0x0010);
6746 } 6621 }
6747 6622
6748 cam = &gspca_dev->cam; 6623 cam = &gspca_dev->cam;
6749/*fixme:test*/
6750 gspca_dev->nbalt--;
6751 switch (mode_tb[sd->sensor]) { 6624 switch (mode_tb[sd->sensor]) {
6752 case 0: 6625 case 0:
6753 cam->cam_mode = sif_mode; 6626 cam->cam_mode = sif_mode;
@@ -6763,58 +6636,62 @@ static int sd_config(struct gspca_dev *gspca_dev,
6763 cam->nmodes = ARRAY_SIZE(broken_vga_mode); 6636 cam->nmodes = ARRAY_SIZE(broken_vga_mode);
6764 break; 6637 break;
6765 } 6638 }
6766 sd->brightness = BRIGHTNESS_DEF;
6767 sd->contrast = CONTRAST_DEF;
6768 sd->gamma = gamma[sd->sensor]; 6639 sd->gamma = gamma[sd->sensor];
6769 sd->autogain = AUTOGAIN_DEF;
6770 sd->lightfreq = FREQ_DEF;
6771 sd->quality = QUALITY_DEF;
6772 6640
6773 switch (sd->sensor) { 6641 switch (sd->sensor) {
6774 case SENSOR_HV7131B:
6775 case SENSOR_HV7131C:
6776 case SENSOR_OV7630C: 6642 case SENSOR_OV7630C:
6777 gspca_dev->ctrl_dis = (1 << LIGHTFREQ_IDX); 6643 gspca_dev->ctrl_dis = (1 << LIGHTFREQ_IDX);
6778 break; 6644 break;
6779 } 6645 }
6780 6646
6781 return 0;
6782}
6783
6784/* this function is called at probe and resume time */
6785static int sd_init(struct gspca_dev *gspca_dev)
6786{
6787 /* switch off the led */ 6647 /* switch off the led */
6788 reg_w(gspca_dev->dev, 0x01, 0x0000); 6648 reg_w(gspca_dev, 0x01, 0x0000);
6789 return 0; 6649 return gspca_dev->usb_err;
6790} 6650}
6791 6651
6792static int sd_start(struct gspca_dev *gspca_dev) 6652static int sd_start(struct gspca_dev *gspca_dev)
6793{ 6653{
6794 struct sd *sd = (struct sd *) gspca_dev; 6654 struct sd *sd = (struct sd *) gspca_dev;
6795 struct usb_device *dev = gspca_dev->dev;
6796 int mode; 6655 int mode;
6797 static const struct usb_action *init_tb[SENSOR_MAX][2] = { 6656 static const struct usb_action *init_tb[SENSOR_MAX][2] = {
6798 {adcm2700_Initial, adcm2700_InitialScale}, /* 0 */ 6657 [SENSOR_ADCM2700] =
6799 {cs2102_Initial, cs2102_InitialScale}, /* 1 */ 6658 {adcm2700_Initial, adcm2700_InitialScale},
6800 {cs2102K_Initial, cs2102K_InitialScale}, /* 2 */ 6659 [SENSOR_CS2102] =
6801 {gc0305_Initial, gc0305_InitialScale}, /* 3 */ 6660 {cs2102_Initial, cs2102_InitialScale},
6802 {hdcs2020b_Initial, hdcs2020b_InitialScale}, /* 4 */ 6661 [SENSOR_CS2102K] =
6803 {hv7131b_Initial, hv7131b_InitialScale}, /* 5 */ 6662 {cs2102K_Initial, cs2102K_InitialScale},
6804 {hv7131r_Initial, hv7131r_InitialScale}, /* 6 */ 6663 [SENSOR_GC0305] =
6805 {icm105a_Initial, icm105a_InitialScale}, /* 7 */ 6664 {gc0305_Initial, gc0305_InitialScale},
6806 {mc501cb_Initial, mc501cb_InitialScale}, /* 8 */ 6665 [SENSOR_HDCS2020b] =
6807 {mi0360soc_Initial, mi0360soc_InitialScale}, /* 9 */ 6666 {hdcs2020b_Initial, hdcs2020b_InitialScale},
6808 {ov7620_Initial, ov7620_InitialScale}, /* 10 */ 6667 [SENSOR_HV7131B] =
6809 {ov7630c_Initial, ov7630c_InitialScale}, /* 11 */ 6668 {hv7131b_Initial, hv7131b_InitialScale},
6810 {pas106b_Initial, pas106b_InitialScale}, /* 12 */ 6669 [SENSOR_HV7131R] =
6811 {pas202b_Initial, pas202b_InitialScale}, /* 13 */ 6670 {hv7131r_Initial, hv7131r_InitialScale},
6812 {pb0330_Initial, pb0330_InitialScale}, /* 14 */ 6671 [SENSOR_ICM105A] =
6813 {po2030_Initial, po2030_InitialScale}, /* 15 */ 6672 {icm105a_Initial, icm105a_InitialScale},
6814 {tas5130cK_Initial, tas5130cK_InitialScale}, /* 16 */ 6673 [SENSOR_MC501CB] =
6815 {tas5130cxx_Initial, tas5130cxx_InitialScale}, /* 17 */ 6674 {mc501cb_Initial, mc501cb_InitialScale},
6675 [SENSOR_MT9V111_1] =
6676 {mt9v111_1_Initial, mt9v111_1_InitialScale},
6677 [SENSOR_MT9V111_3] =
6678 {mt9v111_3_Initial, mt9v111_3_InitialScale},
6679 [SENSOR_OV7620] =
6680 {ov7620_Initial, ov7620_InitialScale},
6681 [SENSOR_OV7630C] =
6682 {ov7630c_Initial, ov7630c_InitialScale},
6683 [SENSOR_PAS106] =
6684 {pas106b_Initial, pas106b_InitialScale},
6685 [SENSOR_PAS202B] =
6686 {pas202b_Initial, pas202b_InitialScale},
6687 [SENSOR_PB0330] =
6688 {pb0330_Initial, pb0330_InitialScale},
6689 [SENSOR_PO2030] =
6690 {po2030_Initial, po2030_InitialScale},
6691 [SENSOR_TAS5130C] =
6692 {tas5130c_Initial, tas5130c_InitialScale},
6693 [SENSOR_TAS5130C_VF0250] =
6816 {tas5130c_vf0250_Initial, tas5130c_vf0250_InitialScale}, 6694 {tas5130c_vf0250_Initial, tas5130c_vf0250_InitialScale},
6817 /* 18 */
6818 }; 6695 };
6819 6696
6820 /* create the JPEG header */ 6697 /* create the JPEG header */
@@ -6824,7 +6701,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
6824 6701
6825 mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv; 6702 mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
6826 switch (sd->sensor) { 6703 switch (sd->sensor) {
6827 case SENSOR_HV7131C: 6704 case SENSOR_HV7131R:
6828 zcxx_probeSensor(gspca_dev); 6705 zcxx_probeSensor(gspca_dev);
6829 break; 6706 break;
6830 case SENSOR_PAS106: 6707 case SENSOR_PAS106:
@@ -6838,22 +6715,22 @@ static int sd_start(struct gspca_dev *gspca_dev)
6838 case SENSOR_GC0305: 6715 case SENSOR_GC0305:
6839 case SENSOR_OV7620: 6716 case SENSOR_OV7620:
6840 case SENSOR_PO2030: 6717 case SENSOR_PO2030:
6841 case SENSOR_TAS5130CXX: 6718 case SENSOR_TAS5130C:
6842 case SENSOR_TAS5130C_VF0250: 6719 case SENSOR_TAS5130C_VF0250:
6843/* msleep(100); * ?? */ 6720/* msleep(100); * ?? */
6844 reg_r(gspca_dev, 0x0002); /* --> 0x40 */ 6721 reg_r(gspca_dev, 0x0002); /* --> 0x40 */
6845 reg_w(dev, 0x09, 0x01ad); /* (from win traces) */ 6722 reg_w(gspca_dev, 0x09, 0x01ad); /* (from win traces) */
6846 reg_w(dev, 0x15, 0x01ae); 6723 reg_w(gspca_dev, 0x15, 0x01ae);
6847 if (sd->sensor == SENSOR_TAS5130CXX) 6724 if (sd->sensor == SENSOR_TAS5130C)
6848 break; 6725 break;
6849 reg_w(dev, 0x0d, 0x003a); 6726 reg_w(gspca_dev, 0x0d, 0x003a);
6850 reg_w(dev, 0x02, 0x003b); 6727 reg_w(gspca_dev, 0x02, 0x003b);
6851 reg_w(dev, 0x00, 0x0038); 6728 reg_w(gspca_dev, 0x00, 0x0038);
6852 break; 6729 break;
6853 case SENSOR_PAS202B: 6730 case SENSOR_PAS202B:
6854 reg_w(dev, 0x03, 0x003b); 6731 reg_w(gspca_dev, 0x03, 0x003b);
6855 reg_w(dev, 0x0c, 0x003a); 6732 reg_w(gspca_dev, 0x0c, 0x003a);
6856 reg_w(dev, 0x0b, 0x0039); 6733 reg_w(gspca_dev, 0x0b, 0x0039);
6857 break; 6734 break;
6858 } 6735 }
6859 6736
@@ -6862,15 +6739,15 @@ static int sd_start(struct gspca_dev *gspca_dev)
6862 case SENSOR_ADCM2700: 6739 case SENSOR_ADCM2700:
6863 case SENSOR_OV7620: 6740 case SENSOR_OV7620:
6864 reg_r(gspca_dev, 0x0008); 6741 reg_r(gspca_dev, 0x0008);
6865 reg_w(dev, 0x00, 0x0008); 6742 reg_w(gspca_dev, 0x00, 0x0008);
6866 break; 6743 break;
6867 case SENSOR_PAS202B: 6744 case SENSOR_PAS202B:
6868 case SENSOR_GC0305: 6745 case SENSOR_GC0305:
6869 case SENSOR_TAS5130CXX: 6746 case SENSOR_TAS5130C:
6870 reg_r(gspca_dev, 0x0008); 6747 reg_r(gspca_dev, 0x0008);
6871 /* fall thru */ 6748 /* fall thru */
6872 case SENSOR_PO2030: 6749 case SENSOR_PO2030:
6873 reg_w(dev, 0x03, 0x0008); 6750 reg_w(gspca_dev, 0x03, 0x0008);
6874 break; 6751 break;
6875 } 6752 }
6876 setsharpness(gspca_dev); 6753 setsharpness(gspca_dev);
@@ -6880,7 +6757,6 @@ static int sd_start(struct gspca_dev *gspca_dev)
6880 case SENSOR_CS2102K: /* gamma set in xxx_Initial */ 6757 case SENSOR_CS2102K: /* gamma set in xxx_Initial */
6881 case SENSOR_HDCS2020b: 6758 case SENSOR_HDCS2020b:
6882 case SENSOR_OV7630C: 6759 case SENSOR_OV7630C:
6883 case SENSOR_TAS5130CK:
6884 break; 6760 break;
6885 default: 6761 default:
6886 setcontrast(gspca_dev); 6762 setcontrast(gspca_dev);
@@ -6891,7 +6767,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
6891 case SENSOR_OV7620: 6767 case SENSOR_OV7620:
6892 case SENSOR_PAS202B: 6768 case SENSOR_PAS202B:
6893 reg_r(gspca_dev, 0x0180); /* from win */ 6769 reg_r(gspca_dev, 0x0180); /* from win */
6894 reg_w(dev, 0x00, 0x0180); 6770 reg_w(gspca_dev, 0x00, 0x0180);
6895 break; 6771 break;
6896 default: 6772 default:
6897 setquality(gspca_dev); 6773 setquality(gspca_dev);
@@ -6901,29 +6777,29 @@ static int sd_start(struct gspca_dev *gspca_dev)
6901 6777
6902 switch (sd->sensor) { 6778 switch (sd->sensor) {
6903 case SENSOR_ADCM2700: 6779 case SENSOR_ADCM2700:
6904 reg_w(dev, 0x09, 0x01ad); /* (from win traces) */ 6780 reg_w(gspca_dev, 0x09, 0x01ad); /* (from win traces) */
6905 reg_w(dev, 0x15, 0x01ae); 6781 reg_w(gspca_dev, 0x15, 0x01ae);
6906 reg_w(dev, 0x02, 0x0180); 6782 reg_w(gspca_dev, 0x02, 0x0180);
6907 /* ms-win + */ 6783 /* ms-win + */
6908 reg_w(dev, 0x40, 0x0117); 6784 reg_w(gspca_dev, 0x40, 0x0117);
6909 break; 6785 break;
6910 case SENSOR_GC0305: 6786 case SENSOR_GC0305:
6911 case SENSOR_TAS5130CXX: 6787 case SENSOR_TAS5130C:
6912 reg_w(dev, 0x09, 0x01ad); /* (from win traces) */ 6788 reg_w(gspca_dev, 0x09, 0x01ad); /* (from win traces) */
6913 reg_w(dev, 0x15, 0x01ae); 6789 reg_w(gspca_dev, 0x15, 0x01ae);
6914 /* fall thru */ 6790 /* fall thru */
6915 case SENSOR_PAS202B: 6791 case SENSOR_PAS202B:
6916 case SENSOR_PO2030: 6792 case SENSOR_PO2030:
6917/* reg_w(dev, 0x40, ZC3XX_R117_GGAIN); * (from win traces) */ 6793/* reg_w(gspca_dev, 0x40, ZC3XX_R117_GGAIN); * (from win traces) */
6918 reg_r(gspca_dev, 0x0180); 6794 reg_r(gspca_dev, 0x0180);
6919 break; 6795 break;
6920 case SENSOR_OV7620: 6796 case SENSOR_OV7620:
6921 reg_w(dev, 0x09, 0x01ad); 6797 reg_w(gspca_dev, 0x09, 0x01ad);
6922 reg_w(dev, 0x15, 0x01ae); 6798 reg_w(gspca_dev, 0x15, 0x01ae);
6923 i2c_read(gspca_dev, 0x13); /*fixme: returns 0xa3 */ 6799 i2c_read(gspca_dev, 0x13); /*fixme: returns 0xa3 */
6924 i2c_write(gspca_dev, 0x13, 0xa3, 0x00); 6800 i2c_write(gspca_dev, 0x13, 0xa3, 0x00);
6925 /*fixme: returned value to send? */ 6801 /*fixme: returned value to send? */
6926 reg_w(dev, 0x40, 0x0117); 6802 reg_w(gspca_dev, 0x40, 0x0117);
6927 reg_r(gspca_dev, 0x0180); 6803 reg_r(gspca_dev, 0x0180);
6928 break; 6804 break;
6929 } 6805 }
@@ -6932,11 +6808,11 @@ static int sd_start(struct gspca_dev *gspca_dev)
6932 switch (sd->sensor) { 6808 switch (sd->sensor) {
6933 case SENSOR_PO2030: 6809 case SENSOR_PO2030:
6934 msleep(50); 6810 msleep(50);
6935 reg_w(dev, 0x00, 0x0007); /* (from win traces) */ 6811 reg_w(gspca_dev, 0x00, 0x0007); /* (from win traces) */
6936 reg_w(dev, 0x02, ZC3XX_R008_CLOCKSETTING); 6812 reg_w(gspca_dev, 0x02, ZC3XX_R008_CLOCKSETTING);
6937 break; 6813 break;
6938 } 6814 }
6939 return 0; 6815 return gspca_dev->usb_err;
6940} 6816}
6941 6817
6942/* called on streamoff with alt 0 and on disconnect */ 6818/* called on streamoff with alt 0 and on disconnect */
@@ -6946,7 +6822,7 @@ static void sd_stop0(struct gspca_dev *gspca_dev)
6946 6822
6947 if (!gspca_dev->present) 6823 if (!gspca_dev->present)
6948 return; 6824 return;
6949 send_unknown(gspca_dev->dev, sd->sensor); 6825 send_unknown(gspca_dev, sd->sensor);
6950} 6826}
6951 6827
6952static void sd_pkt_scan(struct gspca_dev *gspca_dev, 6828static void sd_pkt_scan(struct gspca_dev *gspca_dev,
@@ -6981,7 +6857,7 @@ static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
6981 sd->brightness = val; 6857 sd->brightness = val;
6982 if (gspca_dev->streaming) 6858 if (gspca_dev->streaming)
6983 setcontrast(gspca_dev); 6859 setcontrast(gspca_dev);
6984 return 0; 6860 return gspca_dev->usb_err;
6985} 6861}
6986 6862
6987static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val) 6863static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
@@ -6999,7 +6875,7 @@ static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
6999 sd->contrast = val; 6875 sd->contrast = val;
7000 if (gspca_dev->streaming) 6876 if (gspca_dev->streaming)
7001 setcontrast(gspca_dev); 6877 setcontrast(gspca_dev);
7002 return 0; 6878 return gspca_dev->usb_err;
7003} 6879}
7004 6880
7005static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val) 6881static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
@@ -7017,7 +6893,7 @@ static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
7017 sd->autogain = val; 6893 sd->autogain = val;
7018 if (gspca_dev->streaming) 6894 if (gspca_dev->streaming)
7019 setautogain(gspca_dev); 6895 setautogain(gspca_dev);
7020 return 0; 6896 return gspca_dev->usb_err;
7021} 6897}
7022 6898
7023static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val) 6899static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
@@ -7035,7 +6911,7 @@ static int sd_setgamma(struct gspca_dev *gspca_dev, __s32 val)
7035 sd->gamma = val; 6911 sd->gamma = val;
7036 if (gspca_dev->streaming) 6912 if (gspca_dev->streaming)
7037 setcontrast(gspca_dev); 6913 setcontrast(gspca_dev);
7038 return 0; 6914 return gspca_dev->usb_err;
7039} 6915}
7040 6916
7041static int sd_getgamma(struct gspca_dev *gspca_dev, __s32 *val) 6917static int sd_getgamma(struct gspca_dev *gspca_dev, __s32 *val)
@@ -7053,7 +6929,7 @@ static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val)
7053 sd->lightfreq = val; 6929 sd->lightfreq = val;
7054 if (gspca_dev->streaming) 6930 if (gspca_dev->streaming)
7055 setlightfreq(gspca_dev); 6931 setlightfreq(gspca_dev);
7056 return 0; 6932 return gspca_dev->usb_err;
7057} 6933}
7058 6934
7059static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val) 6935static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val)
@@ -7071,7 +6947,7 @@ static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val)
7071 sd->sharpness = val; 6947 sd->sharpness = val;
7072 if (gspca_dev->streaming) 6948 if (gspca_dev->streaming)
7073 setsharpness(gspca_dev); 6949 setsharpness(gspca_dev);
7074 return 0; 6950 return gspca_dev->usb_err;
7075} 6951}
7076 6952
7077static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val) 6953static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val)
@@ -7116,7 +6992,7 @@ static int sd_set_jcomp(struct gspca_dev *gspca_dev,
7116 sd->quality = jcomp->quality; 6992 sd->quality = jcomp->quality;
7117 if (gspca_dev->streaming) 6993 if (gspca_dev->streaming)
7118 jpeg_set_qual(sd->jpeg_hdr, sd->quality); 6994 jpeg_set_qual(sd->jpeg_hdr, sd->quality);
7119 return 0; 6995 return gspca_dev->usb_err;
7120} 6996}
7121 6997
7122static int sd_get_jcomp(struct gspca_dev *gspca_dev, 6998static int sd_get_jcomp(struct gspca_dev *gspca_dev,
@@ -7220,7 +7096,6 @@ static const __devinitdata struct usb_device_id device_table[] = {
7220 {USB_DEVICE(0x10fd, 0x8050)}, 7096 {USB_DEVICE(0x10fd, 0x8050)},
7221 {} /* end of entry */ 7097 {} /* end of entry */
7222}; 7098};
7223#undef DVNAME
7224MODULE_DEVICE_TABLE(usb, device_table); 7099MODULE_DEVICE_TABLE(usb, device_table);
7225 7100
7226/* -- device connect -- */ 7101/* -- device connect -- */
diff --git a/drivers/media/video/ivtv/Kconfig b/drivers/media/video/ivtv/Kconfig
index c46bfb1569e3..be4af1fa557e 100644
--- a/drivers/media/video/ivtv/Kconfig
+++ b/drivers/media/video/ivtv/Kconfig
@@ -3,7 +3,7 @@ config VIDEO_IVTV
3 depends on VIDEO_V4L2 && PCI && I2C 3 depends on VIDEO_V4L2 && PCI && I2C
4 depends on INPUT # due to VIDEO_IR 4 depends on INPUT # due to VIDEO_IR
5 select I2C_ALGOBIT 5 select I2C_ALGOBIT
6 select VIDEO_IR 6 depends on VIDEO_IR
7 select VIDEO_TUNER 7 select VIDEO_TUNER
8 select VIDEO_TVEEPROM 8 select VIDEO_TVEEPROM
9 select VIDEO_CX2341X 9 select VIDEO_CX2341X
diff --git a/drivers/media/video/ivtv/ivtv-controls.c b/drivers/media/video/ivtv/ivtv-controls.c
index b588e30cbcf0..b31ee1bceef8 100644
--- a/drivers/media/video/ivtv/ivtv-controls.c
+++ b/drivers/media/video/ivtv/ivtv-controls.c
@@ -17,163 +17,14 @@
17 along with this program; if not, write to the Free Software 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 18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */ 19 */
20#include <linux/kernel.h>
21#include <linux/slab.h>
22 20
23#include "ivtv-driver.h" 21#include "ivtv-driver.h"
24#include "ivtv-cards.h"
25#include "ivtv-ioctl.h" 22#include "ivtv-ioctl.h"
26#include "ivtv-routing.h"
27#include "ivtv-i2c.h"
28#include "ivtv-mailbox.h"
29#include "ivtv-controls.h" 23#include "ivtv-controls.h"
30 24
31/* Must be sorted from low to high control ID! */ 25static int ivtv_s_stream_vbi_fmt(struct cx2341x_handler *cxhdl, u32 fmt)
32static const u32 user_ctrls[] = {
33 V4L2_CID_USER_CLASS,
34 V4L2_CID_BRIGHTNESS,
35 V4L2_CID_CONTRAST,
36 V4L2_CID_SATURATION,
37 V4L2_CID_HUE,
38 V4L2_CID_AUDIO_VOLUME,
39 V4L2_CID_AUDIO_BALANCE,
40 V4L2_CID_AUDIO_BASS,
41 V4L2_CID_AUDIO_TREBLE,
42 V4L2_CID_AUDIO_MUTE,
43 V4L2_CID_AUDIO_LOUDNESS,
44 0
45};
46
47static const u32 *ctrl_classes[] = {
48 user_ctrls,
49 cx2341x_mpeg_ctrls,
50 NULL
51};
52
53
54int ivtv_queryctrl(struct file *file, void *fh, struct v4l2_queryctrl *qctrl)
55{
56 struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
57 const char *name;
58
59 qctrl->id = v4l2_ctrl_next(ctrl_classes, qctrl->id);
60 if (qctrl->id == 0)
61 return -EINVAL;
62
63 switch (qctrl->id) {
64 /* Standard V4L2 controls */
65 case V4L2_CID_USER_CLASS:
66 return v4l2_ctrl_query_fill(qctrl, 0, 0, 0, 0);
67 case V4L2_CID_BRIGHTNESS:
68 case V4L2_CID_HUE:
69 case V4L2_CID_SATURATION:
70 case V4L2_CID_CONTRAST:
71 if (v4l2_subdev_call(itv->sd_video, core, queryctrl, qctrl))
72 qctrl->flags |= V4L2_CTRL_FLAG_DISABLED;
73 return 0;
74
75 case V4L2_CID_AUDIO_VOLUME:
76 case V4L2_CID_AUDIO_MUTE:
77 case V4L2_CID_AUDIO_BALANCE:
78 case V4L2_CID_AUDIO_BASS:
79 case V4L2_CID_AUDIO_TREBLE:
80 case V4L2_CID_AUDIO_LOUDNESS:
81 if (v4l2_subdev_call(itv->sd_audio, core, queryctrl, qctrl))
82 qctrl->flags |= V4L2_CTRL_FLAG_DISABLED;
83 return 0;
84
85 default:
86 if (cx2341x_ctrl_query(&itv->params, qctrl))
87 qctrl->flags |= V4L2_CTRL_FLAG_DISABLED;
88 return 0;
89 }
90 strncpy(qctrl->name, name, sizeof(qctrl->name) - 1);
91 qctrl->name[sizeof(qctrl->name) - 1] = 0;
92 return 0;
93}
94
95int ivtv_querymenu(struct file *file, void *fh, struct v4l2_querymenu *qmenu)
96{
97 struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
98 struct v4l2_queryctrl qctrl;
99
100 qctrl.id = qmenu->id;
101 ivtv_queryctrl(file, fh, &qctrl);
102 return v4l2_ctrl_query_menu(qmenu, &qctrl,
103 cx2341x_ctrl_get_menu(&itv->params, qmenu->id));
104}
105
106static int ivtv_try_ctrl(struct file *file, void *fh,
107 struct v4l2_ext_control *vctrl)
108{
109 struct v4l2_queryctrl qctrl;
110 const char **menu_items = NULL;
111 int err;
112
113 qctrl.id = vctrl->id;
114 err = ivtv_queryctrl(file, fh, &qctrl);
115 if (err)
116 return err;
117 if (qctrl.type == V4L2_CTRL_TYPE_MENU)
118 menu_items = v4l2_ctrl_get_menu(qctrl.id);
119 return v4l2_ctrl_check(vctrl, &qctrl, menu_items);
120}
121
122static int ivtv_s_ctrl(struct ivtv *itv, struct v4l2_control *vctrl)
123{
124 switch (vctrl->id) {
125 /* Standard V4L2 controls */
126 case V4L2_CID_BRIGHTNESS:
127 case V4L2_CID_HUE:
128 case V4L2_CID_SATURATION:
129 case V4L2_CID_CONTRAST:
130 return v4l2_subdev_call(itv->sd_video, core, s_ctrl, vctrl);
131
132 case V4L2_CID_AUDIO_VOLUME:
133 case V4L2_CID_AUDIO_MUTE:
134 case V4L2_CID_AUDIO_BALANCE:
135 case V4L2_CID_AUDIO_BASS:
136 case V4L2_CID_AUDIO_TREBLE:
137 case V4L2_CID_AUDIO_LOUDNESS:
138 return v4l2_subdev_call(itv->sd_audio, core, s_ctrl, vctrl);
139
140 default:
141 IVTV_DEBUG_IOCTL("invalid control 0x%x\n", vctrl->id);
142 return -EINVAL;
143 }
144 return 0;
145}
146
147static int ivtv_g_ctrl(struct ivtv *itv, struct v4l2_control *vctrl)
148{ 26{
149 switch (vctrl->id) { 27 struct ivtv *itv = container_of(cxhdl, struct ivtv, cxhdl);
150 /* Standard V4L2 controls */
151 case V4L2_CID_BRIGHTNESS:
152 case V4L2_CID_HUE:
153 case V4L2_CID_SATURATION:
154 case V4L2_CID_CONTRAST:
155 return v4l2_subdev_call(itv->sd_video, core, g_ctrl, vctrl);
156
157 case V4L2_CID_AUDIO_VOLUME:
158 case V4L2_CID_AUDIO_MUTE:
159 case V4L2_CID_AUDIO_BALANCE:
160 case V4L2_CID_AUDIO_BASS:
161 case V4L2_CID_AUDIO_TREBLE:
162 case V4L2_CID_AUDIO_LOUDNESS:
163 return v4l2_subdev_call(itv->sd_audio, core, g_ctrl, vctrl);
164 default:
165 IVTV_DEBUG_IOCTL("invalid control 0x%x\n", vctrl->id);
166 return -EINVAL;
167 }
168 return 0;
169}
170
171static int ivtv_setup_vbi_fmt(struct ivtv *itv, enum v4l2_mpeg_stream_vbi_fmt fmt)
172{
173 if (!(itv->v4l2_cap & V4L2_CAP_SLICED_VBI_CAPTURE))
174 return -EINVAL;
175 if (atomic_read(&itv->capturing) > 0)
176 return -EBUSY;
177 28
178 /* First try to allocate sliced VBI buffers if needed. */ 29 /* First try to allocate sliced VBI buffers if needed. */
179 if (fmt && itv->vbi.sliced_mpeg_data[0] == NULL) { 30 if (fmt && itv->vbi.sliced_mpeg_data[0] == NULL) {
@@ -208,106 +59,43 @@ static int ivtv_setup_vbi_fmt(struct ivtv *itv, enum v4l2_mpeg_stream_vbi_fmt fm
208 return 0; 59 return 0;
209} 60}
210 61
211int ivtv_g_ext_ctrls(struct file *file, void *fh, struct v4l2_ext_controls *c) 62static int ivtv_s_video_encoding(struct cx2341x_handler *cxhdl, u32 val)
212{ 63{
213 struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv; 64 struct ivtv *itv = container_of(cxhdl, struct ivtv, cxhdl);
214 struct v4l2_control ctrl; 65 int is_mpeg1 = val == V4L2_MPEG_VIDEO_ENCODING_MPEG_1;
215 66 struct v4l2_mbus_framefmt fmt;
216 if (c->ctrl_class == V4L2_CTRL_CLASS_USER) { 67
217 int i; 68 /* fix videodecoder resolution */
218 int err = 0; 69 fmt.width = cxhdl->width / (is_mpeg1 ? 2 : 1);
219 70 fmt.height = cxhdl->height;
220 for (i = 0; i < c->count; i++) { 71 fmt.code = V4L2_MBUS_FMT_FIXED;
221 ctrl.id = c->controls[i].id; 72 v4l2_subdev_call(itv->sd_video, video, s_mbus_fmt, &fmt);
222 ctrl.value = c->controls[i].value; 73 return 0;
223 err = ivtv_g_ctrl(itv, &ctrl);
224 c->controls[i].value = ctrl.value;
225 if (err) {
226 c->error_idx = i;
227 break;
228 }
229 }
230 return err;
231 }
232 if (c->ctrl_class == V4L2_CTRL_CLASS_MPEG)
233 return cx2341x_ext_ctrls(&itv->params, 0, c, VIDIOC_G_EXT_CTRLS);
234 return -EINVAL;
235} 74}
236 75
237int ivtv_s_ext_ctrls(struct file *file, void *fh, struct v4l2_ext_controls *c) 76static int ivtv_s_audio_sampling_freq(struct cx2341x_handler *cxhdl, u32 idx)
238{ 77{
239 struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv; 78 static const u32 freqs[3] = { 44100, 48000, 32000 };
240 struct v4l2_control ctrl; 79 struct ivtv *itv = container_of(cxhdl, struct ivtv, cxhdl);
241
242 if (c->ctrl_class == V4L2_CTRL_CLASS_USER) {
243 int i;
244 int err = 0;
245
246 for (i = 0; i < c->count; i++) {
247 ctrl.id = c->controls[i].id;
248 ctrl.value = c->controls[i].value;
249 err = ivtv_s_ctrl(itv, &ctrl);
250 c->controls[i].value = ctrl.value;
251 if (err) {
252 c->error_idx = i;
253 break;
254 }
255 }
256 return err;
257 }
258 if (c->ctrl_class == V4L2_CTRL_CLASS_MPEG) {
259 static u32 freqs[3] = { 44100, 48000, 32000 };
260 struct cx2341x_mpeg_params p = itv->params;
261 int err = cx2341x_ext_ctrls(&p, atomic_read(&itv->capturing), c, VIDIOC_S_EXT_CTRLS);
262 unsigned idx;
263
264 if (err)
265 return err;
266 80
267 if (p.video_encoding != itv->params.video_encoding) { 81 /* The audio clock of the digitizer must match the codec sample
268 int is_mpeg1 = p.video_encoding == 82 rate otherwise you get some very strange effects. */
269 V4L2_MPEG_VIDEO_ENCODING_MPEG_1; 83 if (idx < ARRAY_SIZE(freqs))
270 struct v4l2_mbus_framefmt fmt; 84 ivtv_call_all(itv, audio, s_clock_freq, freqs[idx]);
271 85 return 0;
272 /* fix videodecoder resolution */
273 fmt.width = itv->params.width / (is_mpeg1 ? 2 : 1);
274 fmt.height = itv->params.height;
275 fmt.code = V4L2_MBUS_FMT_FIXED;
276 v4l2_subdev_call(itv->sd_video, video, s_mbus_fmt, &fmt);
277 }
278 err = cx2341x_update(itv, ivtv_api_func, &itv->params, &p);
279 if (!err && itv->params.stream_vbi_fmt != p.stream_vbi_fmt)
280 err = ivtv_setup_vbi_fmt(itv, p.stream_vbi_fmt);
281 itv->params = p;
282 itv->dualwatch_stereo_mode = p.audio_properties & 0x0300;
283 idx = p.audio_properties & 0x03;
284 /* The audio clock of the digitizer must match the codec sample
285 rate otherwise you get some very strange effects. */
286 if (idx < ARRAY_SIZE(freqs))
287 ivtv_call_all(itv, audio, s_clock_freq, freqs[idx]);
288 return err;
289 }
290 return -EINVAL;
291} 86}
292 87
293int ivtv_try_ext_ctrls(struct file *file, void *fh, struct v4l2_ext_controls *c) 88static int ivtv_s_audio_mode(struct cx2341x_handler *cxhdl, u32 val)
294{ 89{
295 struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv; 90 struct ivtv *itv = container_of(cxhdl, struct ivtv, cxhdl);
296 91
297 if (c->ctrl_class == V4L2_CTRL_CLASS_USER) { 92 itv->dualwatch_stereo_mode = val;
298 int i; 93 return 0;
299 int err = 0;
300
301 for (i = 0; i < c->count; i++) {
302 err = ivtv_try_ctrl(file, fh, &c->controls[i]);
303 if (err) {
304 c->error_idx = i;
305 break;
306 }
307 }
308 return err;
309 }
310 if (c->ctrl_class == V4L2_CTRL_CLASS_MPEG)
311 return cx2341x_ext_ctrls(&itv->params, atomic_read(&itv->capturing), c, VIDIOC_TRY_EXT_CTRLS);
312 return -EINVAL;
313} 94}
95
96struct cx2341x_handler_ops ivtv_cxhdl_ops = {
97 .s_audio_mode = ivtv_s_audio_mode,
98 .s_audio_sampling_freq = ivtv_s_audio_sampling_freq,
99 .s_video_encoding = ivtv_s_video_encoding,
100 .s_stream_vbi_fmt = ivtv_s_stream_vbi_fmt,
101};
diff --git a/drivers/media/video/ivtv/ivtv-controls.h b/drivers/media/video/ivtv/ivtv-controls.h
index 1c7721e23c9b..d12893dd0183 100644
--- a/drivers/media/video/ivtv/ivtv-controls.h
+++ b/drivers/media/video/ivtv/ivtv-controls.h
@@ -21,10 +21,6 @@
21#ifndef IVTV_CONTROLS_H 21#ifndef IVTV_CONTROLS_H
22#define IVTV_CONTROLS_H 22#define IVTV_CONTROLS_H
23 23
24int ivtv_queryctrl(struct file *file, void *fh, struct v4l2_queryctrl *a); 24extern struct cx2341x_handler_ops ivtv_cxhdl_ops;
25int ivtv_g_ext_ctrls(struct file *file, void *fh, struct v4l2_ext_controls *a);
26int ivtv_s_ext_ctrls(struct file *file, void *fh, struct v4l2_ext_controls *a);
27int ivtv_try_ext_ctrls(struct file *file, void *fh, struct v4l2_ext_controls *a);
28int ivtv_querymenu(struct file *file, void *fh, struct v4l2_querymenu *a);
29 25
30#endif 26#endif
diff --git a/drivers/media/video/ivtv/ivtv-driver.c b/drivers/media/video/ivtv/ivtv-driver.c
index 07c5c18a25cb..e421d15b0f5c 100644
--- a/drivers/media/video/ivtv/ivtv-driver.c
+++ b/drivers/media/video/ivtv/ivtv-driver.c
@@ -53,6 +53,7 @@
53#include "ivtv-cards.h" 53#include "ivtv-cards.h"
54#include "ivtv-vbi.h" 54#include "ivtv-vbi.h"
55#include "ivtv-routing.h" 55#include "ivtv-routing.h"
56#include "ivtv-controls.h"
56#include "ivtv-gpio.h" 57#include "ivtv-gpio.h"
57 58
58#include <media/tveeprom.h> 59#include <media/tveeprom.h>
@@ -734,9 +735,8 @@ static int __devinit ivtv_init_struct1(struct ivtv *itv)
734 itv->open_id = 1; 735 itv->open_id = 1;
735 736
736 /* Initial settings */ 737 /* Initial settings */
737 cx2341x_fill_defaults(&itv->params); 738 itv->cxhdl.port = CX2341X_PORT_MEMORY;
738 itv->params.port = CX2341X_PORT_MEMORY; 739 itv->cxhdl.capabilities = CX2341X_CAP_HAS_SLICED_VBI;
739 itv->params.capabilities = CX2341X_CAP_HAS_SLICED_VBI;
740 init_waitqueue_head(&itv->eos_waitq); 740 init_waitqueue_head(&itv->eos_waitq);
741 init_waitqueue_head(&itv->event_waitq); 741 init_waitqueue_head(&itv->event_waitq);
742 init_waitqueue_head(&itv->vsync_waitq); 742 init_waitqueue_head(&itv->vsync_waitq);
@@ -1006,6 +1006,13 @@ static int __devinit ivtv_probe(struct pci_dev *pdev,
1006 retval = -ENOMEM; 1006 retval = -ENOMEM;
1007 goto err; 1007 goto err;
1008 } 1008 }
1009 retval = cx2341x_handler_init(&itv->cxhdl, 50);
1010 if (retval)
1011 goto err;
1012 itv->v4l2_dev.ctrl_handler = &itv->cxhdl.hdl;
1013 itv->cxhdl.ops = &ivtv_cxhdl_ops;
1014 itv->cxhdl.priv = itv;
1015 itv->cxhdl.func = ivtv_api_func;
1009 1016
1010 IVTV_DEBUG_INFO("base addr: 0x%08x\n", itv->base_addr); 1017 IVTV_DEBUG_INFO("base addr: 0x%08x\n", itv->base_addr);
1011 1018
@@ -1127,7 +1134,7 @@ static int __devinit ivtv_probe(struct pci_dev *pdev,
1127 itv->yuv_info.v4l2_src_w = itv->yuv_info.osd_full_w; 1134 itv->yuv_info.v4l2_src_w = itv->yuv_info.osd_full_w;
1128 itv->yuv_info.v4l2_src_h = itv->yuv_info.osd_full_h; 1135 itv->yuv_info.v4l2_src_h = itv->yuv_info.osd_full_h;
1129 1136
1130 itv->params.video_gop_size = itv->is_60hz ? 15 : 12; 1137 cx2341x_handler_set_50hz(&itv->cxhdl, itv->is_50hz);
1131 1138
1132 itv->stream_buf_size[IVTV_ENC_STREAM_TYPE_MPG] = 0x08000; 1139 itv->stream_buf_size[IVTV_ENC_STREAM_TYPE_MPG] = 0x08000;
1133 itv->stream_buf_size[IVTV_ENC_STREAM_TYPE_PCM] = 0x01200; 1140 itv->stream_buf_size[IVTV_ENC_STREAM_TYPE_PCM] = 0x01200;
@@ -1269,15 +1276,8 @@ int ivtv_init_on_first_open(struct ivtv *itv)
1269 IVTV_DEBUG_INFO("Getting firmware version..\n"); 1276 IVTV_DEBUG_INFO("Getting firmware version..\n");
1270 ivtv_firmware_versions(itv); 1277 ivtv_firmware_versions(itv);
1271 1278
1272 if (itv->card->hw_all & IVTV_HW_CX25840) { 1279 if (itv->card->hw_all & IVTV_HW_CX25840)
1273 struct v4l2_control ctrl;
1274
1275 v4l2_subdev_call(itv->sd_video, core, load_fw); 1280 v4l2_subdev_call(itv->sd_video, core, load_fw);
1276 /* CX25840_CID_ENABLE_PVR150_WORKAROUND */
1277 ctrl.id = V4L2_CID_PRIVATE_BASE;
1278 ctrl.value = itv->pvr150_workaround;
1279 v4l2_subdev_call(itv->sd_video, core, s_ctrl, &ctrl);
1280 }
1281 1281
1282 vf.tuner = 0; 1282 vf.tuner = 0;
1283 vf.type = V4L2_TUNER_ANALOG_TV; 1283 vf.type = V4L2_TUNER_ANALOG_TV;
@@ -1329,6 +1329,8 @@ int ivtv_init_on_first_open(struct ivtv *itv)
1329 /* For cards with video out, this call needs interrupts enabled */ 1329 /* For cards with video out, this call needs interrupts enabled */
1330 ivtv_s_std(NULL, &fh, &itv->tuner_std); 1330 ivtv_s_std(NULL, &fh, &itv->tuner_std);
1331 1331
1332 /* Setup initial controls */
1333 cx2341x_handler_setup(&itv->cxhdl);
1332 return 0; 1334 return 0;
1333} 1335}
1334 1336
diff --git a/drivers/media/video/ivtv/ivtv-driver.h b/drivers/media/video/ivtv/ivtv-driver.h
index 102071246218..75803141481e 100644
--- a/drivers/media/video/ivtv/ivtv-driver.h
+++ b/drivers/media/video/ivtv/ivtv-driver.h
@@ -62,6 +62,7 @@
62#include <linux/dvb/audio.h> 62#include <linux/dvb/audio.h>
63#include <media/v4l2-common.h> 63#include <media/v4l2-common.h>
64#include <media/v4l2-ioctl.h> 64#include <media/v4l2-ioctl.h>
65#include <media/v4l2-ctrls.h>
65#include <media/v4l2-device.h> 66#include <media/v4l2-device.h>
66#include <media/v4l2-fh.h> 67#include <media/v4l2-fh.h>
67#include <media/tuner.h> 68#include <media/tuner.h>
@@ -631,6 +632,8 @@ struct ivtv {
631 struct ivtv_options options; /* user options */ 632 struct ivtv_options options; /* user options */
632 633
633 struct v4l2_device v4l2_dev; 634 struct v4l2_device v4l2_dev;
635 struct cx2341x_handler cxhdl;
636 struct v4l2_ctrl_handler hdl_gpio;
634 struct v4l2_subdev sd_gpio; /* GPIO sub-device */ 637 struct v4l2_subdev sd_gpio; /* GPIO sub-device */
635 u16 instance; 638 u16 instance;
636 639
@@ -648,7 +651,6 @@ struct ivtv {
648 v4l2_std_id std_out; /* current TV output standard */ 651 v4l2_std_id std_out; /* current TV output standard */
649 u8 audio_stereo_mode; /* decoder setting how to handle stereo MPEG audio */ 652 u8 audio_stereo_mode; /* decoder setting how to handle stereo MPEG audio */
650 u8 audio_bilingual_mode; /* decoder setting how to handle bilingual MPEG audio */ 653 u8 audio_bilingual_mode; /* decoder setting how to handle bilingual MPEG audio */
651 struct cx2341x_mpeg_params params; /* current encoder parameters */
652 654
653 655
654 /* Locking */ 656 /* Locking */
diff --git a/drivers/media/video/ivtv/ivtv-fileops.c b/drivers/media/video/ivtv/ivtv-fileops.c
index a6a2cdb81566..d727485da886 100644
--- a/drivers/media/video/ivtv/ivtv-fileops.c
+++ b/drivers/media/video/ivtv/ivtv-fileops.c
@@ -150,12 +150,10 @@ void ivtv_release_stream(struct ivtv_stream *s)
150static void ivtv_dualwatch(struct ivtv *itv) 150static void ivtv_dualwatch(struct ivtv *itv)
151{ 151{
152 struct v4l2_tuner vt; 152 struct v4l2_tuner vt;
153 u32 new_bitmap;
154 u32 new_stereo_mode; 153 u32 new_stereo_mode;
155 const u32 stereo_mask = 0x0300; 154 const u32 dual = 0x02;
156 const u32 dual = 0x0200;
157 155
158 new_stereo_mode = itv->params.audio_properties & stereo_mask; 156 new_stereo_mode = v4l2_ctrl_g_ctrl(itv->cxhdl.audio_mode);
159 memset(&vt, 0, sizeof(vt)); 157 memset(&vt, 0, sizeof(vt));
160 ivtv_call_all(itv, tuner, g_tuner, &vt); 158 ivtv_call_all(itv, tuner, g_tuner, &vt);
161 if (vt.audmode == V4L2_TUNER_MODE_LANG1_LANG2 && (vt.rxsubchans & V4L2_TUNER_SUB_LANG2)) 159 if (vt.audmode == V4L2_TUNER_MODE_LANG1_LANG2 && (vt.rxsubchans & V4L2_TUNER_SUB_LANG2))
@@ -164,16 +162,10 @@ static void ivtv_dualwatch(struct ivtv *itv)
164 if (new_stereo_mode == itv->dualwatch_stereo_mode) 162 if (new_stereo_mode == itv->dualwatch_stereo_mode)
165 return; 163 return;
166 164
167 new_bitmap = new_stereo_mode | (itv->params.audio_properties & ~stereo_mask); 165 IVTV_DEBUG_INFO("dualwatch: change stereo flag from 0x%x to 0x%x.\n",
168 166 itv->dualwatch_stereo_mode, new_stereo_mode);
169 IVTV_DEBUG_INFO("dualwatch: change stereo flag from 0x%x to 0x%x. new audio_bitmask=0x%ux\n", 167 if (v4l2_ctrl_s_ctrl(itv->cxhdl.audio_mode, new_stereo_mode))
170 itv->dualwatch_stereo_mode, new_stereo_mode, new_bitmap); 168 IVTV_DEBUG_INFO("dualwatch: changing stereo flag failed\n");
171
172 if (ivtv_vapi(itv, CX2341X_ENC_SET_AUDIO_PROPERTIES, 1, new_bitmap) == 0) {
173 itv->dualwatch_stereo_mode = new_stereo_mode;
174 return;
175 }
176 IVTV_DEBUG_INFO("dualwatch: changing stereo flag failed\n");
177} 169}
178 170
179static void ivtv_update_pgm_info(struct ivtv *itv) 171static void ivtv_update_pgm_info(struct ivtv *itv)
@@ -894,7 +886,8 @@ int ivtv_v4l2_close(struct file *filp)
894 if (atomic_read(&itv->capturing) > 0) { 886 if (atomic_read(&itv->capturing) > 0) {
895 /* Undo video mute */ 887 /* Undo video mute */
896 ivtv_vapi(itv, CX2341X_ENC_MUTE_VIDEO, 1, 888 ivtv_vapi(itv, CX2341X_ENC_MUTE_VIDEO, 1,
897 itv->params.video_mute | (itv->params.video_mute_yuv << 8)); 889 v4l2_ctrl_g_ctrl(itv->cxhdl.video_mute) |
890 (v4l2_ctrl_g_ctrl(itv->cxhdl.video_mute_yuv) << 8));
898 } 891 }
899 /* Done! Unmute and continue. */ 892 /* Done! Unmute and continue. */
900 ivtv_unmute(itv); 893 ivtv_unmute(itv);
diff --git a/drivers/media/video/ivtv/ivtv-firmware.c b/drivers/media/video/ivtv/ivtv-firmware.c
index d8bf2b01729d..4df01947a7df 100644
--- a/drivers/media/video/ivtv/ivtv-firmware.c
+++ b/drivers/media/video/ivtv/ivtv-firmware.c
@@ -248,9 +248,9 @@ void ivtv_init_mpeg_decoder(struct ivtv *itv)
248 volatile u8 __iomem *mem_offset; 248 volatile u8 __iomem *mem_offset;
249 249
250 data[0] = 0; 250 data[0] = 0;
251 data[1] = itv->params.width; /* YUV source width */ 251 data[1] = itv->cxhdl.width; /* YUV source width */
252 data[2] = itv->params.height; 252 data[2] = itv->cxhdl.height;
253 data[3] = itv->params.audio_properties; /* Audio settings to use, 253 data[3] = itv->cxhdl.audio_properties; /* Audio settings to use,
254 bitmap. see docs. */ 254 bitmap. see docs. */
255 if (ivtv_api(itv, CX2341X_DEC_SET_DECODER_SOURCE, 4, data)) { 255 if (ivtv_api(itv, CX2341X_DEC_SET_DECODER_SOURCE, 4, data)) {
256 IVTV_ERR("ivtv_init_mpeg_decoder failed to set decoder source\n"); 256 IVTV_ERR("ivtv_init_mpeg_decoder failed to set decoder source\n");
diff --git a/drivers/media/video/ivtv/ivtv-gpio.c b/drivers/media/video/ivtv/ivtv-gpio.c
index aede061cae5d..8f0d07789053 100644
--- a/drivers/media/video/ivtv/ivtv-gpio.c
+++ b/drivers/media/video/ivtv/ivtv-gpio.c
@@ -24,6 +24,7 @@
24#include "ivtv-gpio.h" 24#include "ivtv-gpio.h"
25#include "tuner-xc2028.h" 25#include "tuner-xc2028.h"
26#include <media/tuner.h> 26#include <media/tuner.h>
27#include <media/v4l2-ctrls.h>
27 28
28/* 29/*
29 * GPIO assignment of Yuan MPG600/MPG160 30 * GPIO assignment of Yuan MPG600/MPG160
@@ -149,16 +150,10 @@ static inline struct ivtv *sd_to_ivtv(struct v4l2_subdev *sd)
149 return container_of(sd, struct ivtv, sd_gpio); 150 return container_of(sd, struct ivtv, sd_gpio);
150} 151}
151 152
152static struct v4l2_queryctrl gpio_ctrl_mute = { 153static inline struct v4l2_subdev *to_sd(struct v4l2_ctrl *ctrl)
153 .id = V4L2_CID_AUDIO_MUTE, 154{
154 .type = V4L2_CTRL_TYPE_BOOLEAN, 155 return &container_of(ctrl->handler, struct ivtv, hdl_gpio)->sd_gpio;
155 .name = "Mute", 156}
156 .minimum = 0,
157 .maximum = 1,
158 .step = 1,
159 .default_value = 1,
160 .flags = 0,
161};
162 157
163static int subdev_s_clock_freq(struct v4l2_subdev *sd, u32 freq) 158static int subdev_s_clock_freq(struct v4l2_subdev *sd, u32 freq)
164{ 159{
@@ -262,40 +257,24 @@ static int subdev_s_audio_routing(struct v4l2_subdev *sd,
262 return 0; 257 return 0;
263} 258}
264 259
265static int subdev_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) 260static int subdev_s_ctrl(struct v4l2_ctrl *ctrl)
266{ 261{
262 struct v4l2_subdev *sd = to_sd(ctrl);
267 struct ivtv *itv = sd_to_ivtv(sd); 263 struct ivtv *itv = sd_to_ivtv(sd);
268 u16 mask, data; 264 u16 mask, data;
269 265
270 if (ctrl->id != V4L2_CID_AUDIO_MUTE) 266 switch (ctrl->id) {
271 return -EINVAL; 267 case V4L2_CID_AUDIO_MUTE:
272 mask = itv->card->gpio_audio_mute.mask; 268 mask = itv->card->gpio_audio_mute.mask;
273 data = itv->card->gpio_audio_mute.mute; 269 data = ctrl->val ? itv->card->gpio_audio_mute.mute : 0;
274 ctrl->value = (read_reg(IVTV_REG_GPIO_OUT) & mask) == data; 270 if (mask)
275 return 0; 271 write_reg((read_reg(IVTV_REG_GPIO_OUT) & ~mask) |
276} 272 (data & mask), IVTV_REG_GPIO_OUT);
277 273 return 0;
278static int subdev_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) 274 }
279{ 275 return -EINVAL;
280 struct ivtv *itv = sd_to_ivtv(sd);
281 u16 mask, data;
282
283 if (ctrl->id != V4L2_CID_AUDIO_MUTE)
284 return -EINVAL;
285 mask = itv->card->gpio_audio_mute.mask;
286 data = ctrl->value ? itv->card->gpio_audio_mute.mute : 0;
287 if (mask)
288 write_reg((read_reg(IVTV_REG_GPIO_OUT) & ~mask) | (data & mask), IVTV_REG_GPIO_OUT);
289 return 0;
290} 276}
291 277
292static int subdev_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc)
293{
294 if (qc->id != V4L2_CID_AUDIO_MUTE)
295 return -EINVAL;
296 *qc = gpio_ctrl_mute;
297 return 0;
298}
299 278
300static int subdev_log_status(struct v4l2_subdev *sd) 279static int subdev_log_status(struct v4l2_subdev *sd)
301{ 280{
@@ -304,6 +283,7 @@ static int subdev_log_status(struct v4l2_subdev *sd)
304 IVTV_INFO("GPIO status: DIR=0x%04x OUT=0x%04x IN=0x%04x\n", 283 IVTV_INFO("GPIO status: DIR=0x%04x OUT=0x%04x IN=0x%04x\n",
305 read_reg(IVTV_REG_GPIO_DIR), read_reg(IVTV_REG_GPIO_OUT), 284 read_reg(IVTV_REG_GPIO_DIR), read_reg(IVTV_REG_GPIO_OUT),
306 read_reg(IVTV_REG_GPIO_IN)); 285 read_reg(IVTV_REG_GPIO_IN));
286 v4l2_ctrl_handler_log_status(&itv->hdl_gpio, sd->name);
307 return 0; 287 return 0;
308} 288}
309 289
@@ -327,11 +307,19 @@ static int subdev_s_video_routing(struct v4l2_subdev *sd,
327 return 0; 307 return 0;
328} 308}
329 309
310static const struct v4l2_ctrl_ops gpio_ctrl_ops = {
311 .s_ctrl = subdev_s_ctrl,
312};
313
330static const struct v4l2_subdev_core_ops subdev_core_ops = { 314static const struct v4l2_subdev_core_ops subdev_core_ops = {
331 .log_status = subdev_log_status, 315 .log_status = subdev_log_status,
332 .g_ctrl = subdev_g_ctrl, 316 .g_ext_ctrls = v4l2_subdev_g_ext_ctrls,
333 .s_ctrl = subdev_s_ctrl, 317 .try_ext_ctrls = v4l2_subdev_try_ext_ctrls,
334 .queryctrl = subdev_queryctrl, 318 .s_ext_ctrls = v4l2_subdev_s_ext_ctrls,
319 .g_ctrl = v4l2_subdev_g_ctrl,
320 .s_ctrl = v4l2_subdev_s_ctrl,
321 .queryctrl = v4l2_subdev_queryctrl,
322 .querymenu = v4l2_subdev_querymenu,
335}; 323};
336 324
337static const struct v4l2_subdev_tuner_ops subdev_tuner_ops = { 325static const struct v4l2_subdev_tuner_ops subdev_tuner_ops = {
@@ -375,5 +363,12 @@ int ivtv_gpio_init(struct ivtv *itv)
375 v4l2_subdev_init(&itv->sd_gpio, &subdev_ops); 363 v4l2_subdev_init(&itv->sd_gpio, &subdev_ops);
376 snprintf(itv->sd_gpio.name, sizeof(itv->sd_gpio.name), "%s-gpio", itv->v4l2_dev.name); 364 snprintf(itv->sd_gpio.name, sizeof(itv->sd_gpio.name), "%s-gpio", itv->v4l2_dev.name);
377 itv->sd_gpio.grp_id = IVTV_HW_GPIO; 365 itv->sd_gpio.grp_id = IVTV_HW_GPIO;
366 v4l2_ctrl_handler_init(&itv->hdl_gpio, 1);
367 v4l2_ctrl_new_std(&itv->hdl_gpio, &gpio_ctrl_ops,
368 V4L2_CID_AUDIO_MUTE, 0, 1, 1, 0);
369 if (itv->hdl_gpio.error)
370 return itv->hdl_gpio.error;
371 itv->sd_gpio.ctrl_handler = &itv->hdl_gpio;
372 v4l2_ctrl_handler_setup(&itv->hdl_gpio);
378 return v4l2_device_register_subdev(&itv->v4l2_dev, &itv->sd_gpio); 373 return v4l2_device_register_subdev(&itv->v4l2_dev, &itv->sd_gpio);
379} 374}
diff --git a/drivers/media/video/ivtv/ivtv-i2c.c b/drivers/media/video/ivtv/ivtv-i2c.c
index a5b92d109c6c..a74fa099c565 100644
--- a/drivers/media/video/ivtv/ivtv-i2c.c
+++ b/drivers/media/video/ivtv/ivtv-i2c.c
@@ -63,6 +63,7 @@
63#include "ivtv-cards.h" 63#include "ivtv-cards.h"
64#include "ivtv-gpio.h" 64#include "ivtv-gpio.h"
65#include "ivtv-i2c.h" 65#include "ivtv-i2c.h"
66#include <media/cx25840.h>
66 67
67/* i2c implementation for cx23415/6 chip, ivtv project. 68/* i2c implementation for cx23415/6 chip, ivtv project.
68 * Author: Kevin Thayer (nufan_wfk at yahoo.com) 69 * Author: Kevin Thayer (nufan_wfk at yahoo.com)
@@ -182,8 +183,8 @@ static int ivtv_i2c_new_ir(struct ivtv *itv, u32 hw, const char *type, u8 addr)
182 return -1; 183 return -1;
183 memset(&info, 0, sizeof(struct i2c_board_info)); 184 memset(&info, 0, sizeof(struct i2c_board_info));
184 strlcpy(info.type, type, I2C_NAME_SIZE); 185 strlcpy(info.type, type, I2C_NAME_SIZE);
185 return i2c_new_probed_device(adap, &info, addr_list) == NULL 186 return i2c_new_probed_device(adap, &info, addr_list, NULL)
186 ? -1 : 0; 187 == NULL ? -1 : 0;
187 } 188 }
188 189
189 /* Only allow one IR receiver to be registered per board */ 190 /* Only allow one IR receiver to be registered per board */
@@ -220,7 +221,8 @@ static int ivtv_i2c_new_ir(struct ivtv *itv, u32 hw, const char *type, u8 addr)
220 info.platform_data = init_data; 221 info.platform_data = init_data;
221 strlcpy(info.type, type, I2C_NAME_SIZE); 222 strlcpy(info.type, type, I2C_NAME_SIZE);
222 223
223 return i2c_new_probed_device(adap, &info, addr_list) == NULL ? -1 : 0; 224 return i2c_new_probed_device(adap, &info, addr_list, NULL) == NULL ?
225 -1 : 0;
224} 226}
225 227
226/* Instantiate the IR receiver device using probing -- undesirable */ 228/* Instantiate the IR receiver device using probing -- undesirable */
@@ -248,7 +250,7 @@ struct i2c_client *ivtv_i2c_new_ir_legacy(struct ivtv *itv)
248 250
249 memset(&info, 0, sizeof(struct i2c_board_info)); 251 memset(&info, 0, sizeof(struct i2c_board_info));
250 strlcpy(info.type, "ir_video", I2C_NAME_SIZE); 252 strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
251 return i2c_new_probed_device(&itv->i2c_adap, &info, addr_list); 253 return i2c_new_probed_device(&itv->i2c_adap, &info, addr_list, NULL);
252} 254}
253 255
254int ivtv_i2c_register(struct ivtv *itv, unsigned idx) 256int ivtv_i2c_register(struct ivtv *itv, unsigned idx)
@@ -292,6 +294,12 @@ int ivtv_i2c_register(struct ivtv *itv, unsigned idx)
292 if (hw == IVTV_HW_UPD64031A || hw == IVTV_HW_UPD6408X) { 294 if (hw == IVTV_HW_UPD64031A || hw == IVTV_HW_UPD6408X) {
293 sd = v4l2_i2c_new_subdev(&itv->v4l2_dev, 295 sd = v4l2_i2c_new_subdev(&itv->v4l2_dev,
294 adap, mod, type, 0, I2C_ADDRS(hw_addrs[idx])); 296 adap, mod, type, 0, I2C_ADDRS(hw_addrs[idx]));
297 } else if (hw == IVTV_HW_CX25840) {
298 struct cx25840_platform_data pdata;
299
300 pdata.pvr150_workaround = itv->pvr150_workaround;
301 sd = v4l2_i2c_new_subdev_cfg(&itv->v4l2_dev,
302 adap, mod, type, 0, &pdata, hw_addrs[idx], NULL);
295 } else { 303 } else {
296 sd = v4l2_i2c_new_subdev(&itv->v4l2_dev, 304 sd = v4l2_i2c_new_subdev(&itv->v4l2_dev,
297 adap, mod, type, hw_addrs[idx], NULL); 305 adap, mod, type, hw_addrs[idx], NULL);
diff --git a/drivers/media/video/ivtv/ivtv-ioctl.c b/drivers/media/video/ivtv/ivtv-ioctl.c
index 11ac2fa33ef7..4eed9123683e 100644
--- a/drivers/media/video/ivtv/ivtv-ioctl.c
+++ b/drivers/media/video/ivtv/ivtv-ioctl.c
@@ -162,7 +162,7 @@ int ivtv_set_speed(struct ivtv *itv, int speed)
162 data[0] |= (speed > 1000 || speed < -1500) ? 0x40000000 : 0; 162 data[0] |= (speed > 1000 || speed < -1500) ? 0x40000000 : 0;
163 data[1] = (speed < 0); 163 data[1] = (speed < 0);
164 data[2] = speed < 0 ? 3 : 7; 164 data[2] = speed < 0 ? 3 : 7;
165 data[3] = itv->params.video_b_frames; 165 data[3] = v4l2_ctrl_g_ctrl(itv->cxhdl.video_b_frames);
166 data[4] = (speed == 1500 || speed == 500) ? itv->speed_mute_audio : 0; 166 data[4] = (speed == 1500 || speed == 500) ? itv->speed_mute_audio : 0;
167 data[5] = 0; 167 data[5] = 0;
168 data[6] = 0; 168 data[6] = 0;
@@ -339,8 +339,8 @@ static int ivtv_g_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *f
339 struct ivtv *itv = id->itv; 339 struct ivtv *itv = id->itv;
340 struct v4l2_pix_format *pixfmt = &fmt->fmt.pix; 340 struct v4l2_pix_format *pixfmt = &fmt->fmt.pix;
341 341
342 pixfmt->width = itv->params.width; 342 pixfmt->width = itv->cxhdl.width;
343 pixfmt->height = itv->params.height; 343 pixfmt->height = itv->cxhdl.height;
344 pixfmt->colorspace = V4L2_COLORSPACE_SMPTE170M; 344 pixfmt->colorspace = V4L2_COLORSPACE_SMPTE170M;
345 pixfmt->field = V4L2_FIELD_INTERLACED; 345 pixfmt->field = V4L2_FIELD_INTERLACED;
346 pixfmt->priv = 0; 346 pixfmt->priv = 0;
@@ -568,7 +568,6 @@ static int ivtv_s_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *f
568{ 568{
569 struct ivtv_open_id *id = fh; 569 struct ivtv_open_id *id = fh;
570 struct ivtv *itv = id->itv; 570 struct ivtv *itv = id->itv;
571 struct cx2341x_mpeg_params *p = &itv->params;
572 struct v4l2_mbus_framefmt mbus_fmt; 571 struct v4l2_mbus_framefmt mbus_fmt;
573 int ret = ivtv_try_fmt_vid_cap(file, fh, fmt); 572 int ret = ivtv_try_fmt_vid_cap(file, fh, fmt);
574 int w = fmt->fmt.pix.width; 573 int w = fmt->fmt.pix.width;
@@ -577,15 +576,15 @@ static int ivtv_s_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *f
577 if (ret) 576 if (ret)
578 return ret; 577 return ret;
579 578
580 if (p->width == w && p->height == h) 579 if (itv->cxhdl.width == w && itv->cxhdl.height == h)
581 return 0; 580 return 0;
582 581
583 if (atomic_read(&itv->capturing) > 0) 582 if (atomic_read(&itv->capturing) > 0)
584 return -EBUSY; 583 return -EBUSY;
585 584
586 p->width = w; 585 itv->cxhdl.width = w;
587 p->height = h; 586 itv->cxhdl.height = h;
588 if (p->video_encoding == V4L2_MPEG_VIDEO_ENCODING_MPEG_1) 587 if (v4l2_ctrl_g_ctrl(itv->cxhdl.video_encoding) == V4L2_MPEG_VIDEO_ENCODING_MPEG_1)
589 fmt->fmt.pix.width /= 2; 588 fmt->fmt.pix.width /= 2;
590 mbus_fmt.width = fmt->fmt.pix.width; 589 mbus_fmt.width = fmt->fmt.pix.width;
591 mbus_fmt.height = h; 590 mbus_fmt.height = h;
@@ -1114,9 +1113,10 @@ int ivtv_s_std(struct file *file, void *fh, v4l2_std_id *std)
1114 1113
1115 itv->std = *std; 1114 itv->std = *std;
1116 itv->is_60hz = (*std & V4L2_STD_525_60) ? 1 : 0; 1115 itv->is_60hz = (*std & V4L2_STD_525_60) ? 1 : 0;
1117 itv->params.is_50hz = itv->is_50hz = !itv->is_60hz; 1116 itv->is_50hz = !itv->is_60hz;
1118 itv->params.width = 720; 1117 cx2341x_handler_set_50hz(&itv->cxhdl, itv->is_50hz);
1119 itv->params.height = itv->is_50hz ? 576 : 480; 1118 itv->cxhdl.width = 720;
1119 itv->cxhdl.height = itv->is_50hz ? 576 : 480;
1120 itv->vbi.count = itv->is_50hz ? 18 : 12; 1120 itv->vbi.count = itv->is_50hz ? 18 : 12;
1121 itv->vbi.start[0] = itv->is_50hz ? 6 : 10; 1121 itv->vbi.start[0] = itv->is_50hz ? 6 : 10;
1122 itv->vbi.start[1] = itv->is_50hz ? 318 : 273; 1122 itv->vbi.start[1] = itv->is_50hz ? 318 : 273;
@@ -1157,7 +1157,7 @@ int ivtv_s_std(struct file *file, void *fh, v4l2_std_id *std)
1157 ivtv_vapi(itv, CX2341X_DEC_SET_STANDARD, 1, itv->is_out_50hz); 1157 ivtv_vapi(itv, CX2341X_DEC_SET_STANDARD, 1, itv->is_out_50hz);
1158 itv->main_rect.left = itv->main_rect.top = 0; 1158 itv->main_rect.left = itv->main_rect.top = 0;
1159 itv->main_rect.width = 720; 1159 itv->main_rect.width = 720;
1160 itv->main_rect.height = itv->params.height; 1160 itv->main_rect.height = itv->cxhdl.height;
1161 ivtv_vapi(itv, CX2341X_OSD_SET_FRAMEBUFFER_WINDOW, 4, 1161 ivtv_vapi(itv, CX2341X_OSD_SET_FRAMEBUFFER_WINDOW, 4,
1162 720, itv->main_rect.height, 0, 0); 1162 720, itv->main_rect.height, 0, 0);
1163 yi->main_rect = itv->main_rect; 1163 yi->main_rect = itv->main_rect;
@@ -1554,7 +1554,7 @@ static int ivtv_log_status(struct file *file, void *fh)
1554 } 1554 }
1555 IVTV_INFO("Tuner: %s\n", 1555 IVTV_INFO("Tuner: %s\n",
1556 test_bit(IVTV_F_I_RADIO_USER, &itv->i_flags) ? "Radio" : "TV"); 1556 test_bit(IVTV_F_I_RADIO_USER, &itv->i_flags) ? "Radio" : "TV");
1557 cx2341x_log_status(&itv->params, itv->v4l2_dev.name); 1557 v4l2_ctrl_handler_log_status(&itv->cxhdl.hdl, itv->v4l2_dev.name);
1558 IVTV_INFO("Status flags: 0x%08lx\n", itv->i_flags); 1558 IVTV_INFO("Status flags: 0x%08lx\n", itv->i_flags);
1559 for (i = 0; i < IVTV_MAX_STREAMS; i++) { 1559 for (i = 0; i < IVTV_MAX_STREAMS; i++) {
1560 struct ivtv_stream *s = &itv->streams[i]; 1560 struct ivtv_stream *s = &itv->streams[i];
@@ -1942,11 +1942,6 @@ static const struct v4l2_ioctl_ops ivtv_ioctl_ops = {
1942 .vidioc_s_register = ivtv_s_register, 1942 .vidioc_s_register = ivtv_s_register,
1943#endif 1943#endif
1944 .vidioc_default = ivtv_default, 1944 .vidioc_default = ivtv_default,
1945 .vidioc_queryctrl = ivtv_queryctrl,
1946 .vidioc_querymenu = ivtv_querymenu,
1947 .vidioc_g_ext_ctrls = ivtv_g_ext_ctrls,
1948 .vidioc_s_ext_ctrls = ivtv_s_ext_ctrls,
1949 .vidioc_try_ext_ctrls = ivtv_try_ext_ctrls,
1950 .vidioc_subscribe_event = ivtv_subscribe_event, 1945 .vidioc_subscribe_event = ivtv_subscribe_event,
1951 .vidioc_unsubscribe_event = v4l2_event_unsubscribe, 1946 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
1952}; 1947};
diff --git a/drivers/media/video/ivtv/ivtv-streams.c b/drivers/media/video/ivtv/ivtv-streams.c
index 55df4190c28d..512607e0cda3 100644
--- a/drivers/media/video/ivtv/ivtv-streams.c
+++ b/drivers/media/video/ivtv/ivtv-streams.c
@@ -210,6 +210,7 @@ static int ivtv_prep_dev(struct ivtv *itv, int type)
210 210
211 s->vdev->num = num; 211 s->vdev->num = num;
212 s->vdev->v4l2_dev = &itv->v4l2_dev; 212 s->vdev->v4l2_dev = &itv->v4l2_dev;
213 s->vdev->ctrl_handler = itv->v4l2_dev.ctrl_handler;
213 s->vdev->fops = ivtv_stream_info[type].fops; 214 s->vdev->fops = ivtv_stream_info[type].fops;
214 s->vdev->release = video_device_release; 215 s->vdev->release = video_device_release;
215 s->vdev->tvnorms = V4L2_STD_ALL; 216 s->vdev->tvnorms = V4L2_STD_ALL;
@@ -451,7 +452,6 @@ int ivtv_start_v4l2_encode_stream(struct ivtv_stream *s)
451{ 452{
452 u32 data[CX2341X_MBOX_MAX_DATA]; 453 u32 data[CX2341X_MBOX_MAX_DATA];
453 struct ivtv *itv = s->itv; 454 struct ivtv *itv = s->itv;
454 struct cx2341x_mpeg_params *p = &itv->params;
455 int captype = 0, subtype = 0; 455 int captype = 0, subtype = 0;
456 int enable_passthrough = 0; 456 int enable_passthrough = 0;
457 457
@@ -472,7 +472,7 @@ int ivtv_start_v4l2_encode_stream(struct ivtv_stream *s)
472 } 472 }
473 itv->mpg_data_received = itv->vbi_data_inserted = 0; 473 itv->mpg_data_received = itv->vbi_data_inserted = 0;
474 itv->dualwatch_jiffies = jiffies; 474 itv->dualwatch_jiffies = jiffies;
475 itv->dualwatch_stereo_mode = p->audio_properties & 0x0300; 475 itv->dualwatch_stereo_mode = v4l2_ctrl_g_ctrl(itv->cxhdl.audio_mode);
476 itv->search_pack_header = 0; 476 itv->search_pack_header = 0;
477 break; 477 break;
478 478
@@ -560,12 +560,12 @@ int ivtv_start_v4l2_encode_stream(struct ivtv_stream *s)
560 itv->pgm_info_offset, itv->pgm_info_num); 560 itv->pgm_info_offset, itv->pgm_info_num);
561 561
562 /* Setup API for Stream */ 562 /* Setup API for Stream */
563 cx2341x_update(itv, ivtv_api_func, NULL, p); 563 cx2341x_handler_setup(&itv->cxhdl);
564 564
565 /* mute if capturing radio */ 565 /* mute if capturing radio */
566 if (test_bit(IVTV_F_I_RADIO_USER, &itv->i_flags)) 566 if (test_bit(IVTV_F_I_RADIO_USER, &itv->i_flags))
567 ivtv_vapi(itv, CX2341X_ENC_MUTE_VIDEO, 1, 567 ivtv_vapi(itv, CX2341X_ENC_MUTE_VIDEO, 1,
568 1 | (p->video_mute_yuv << 8)); 568 1 | (v4l2_ctrl_g_ctrl(itv->cxhdl.video_mute_yuv) << 8));
569 } 569 }
570 570
571 /* Vsync Setup */ 571 /* Vsync Setup */
@@ -581,6 +581,8 @@ int ivtv_start_v4l2_encode_stream(struct ivtv_stream *s)
581 581
582 clear_bit(IVTV_F_I_EOS, &itv->i_flags); 582 clear_bit(IVTV_F_I_EOS, &itv->i_flags);
583 583
584 cx2341x_handler_set_busy(&itv->cxhdl, 1);
585
584 /* Initialize Digitizer for Capture */ 586 /* Initialize Digitizer for Capture */
585 /* Avoid tinny audio problem - ensure audio clocks are going */ 587 /* Avoid tinny audio problem - ensure audio clocks are going */
586 v4l2_subdev_call(itv->sd_audio, audio, s_stream, 1); 588 v4l2_subdev_call(itv->sd_audio, audio, s_stream, 1);
@@ -617,7 +619,6 @@ static int ivtv_setup_v4l2_decode_stream(struct ivtv_stream *s)
617{ 619{
618 u32 data[CX2341X_MBOX_MAX_DATA]; 620 u32 data[CX2341X_MBOX_MAX_DATA];
619 struct ivtv *itv = s->itv; 621 struct ivtv *itv = s->itv;
620 struct cx2341x_mpeg_params *p = &itv->params;
621 int datatype; 622 int datatype;
622 u16 width; 623 u16 width;
623 u16 height; 624 u16 height;
@@ -627,8 +628,8 @@ static int ivtv_setup_v4l2_decode_stream(struct ivtv_stream *s)
627 628
628 IVTV_DEBUG_INFO("Setting some initial decoder settings\n"); 629 IVTV_DEBUG_INFO("Setting some initial decoder settings\n");
629 630
630 width = p->width; 631 width = itv->cxhdl.width;
631 height = p->height; 632 height = itv->cxhdl.height;
632 633
633 /* set audio mode to left/stereo for dual/stereo mode. */ 634 /* set audio mode to left/stereo for dual/stereo mode. */
634 ivtv_vapi(itv, CX2341X_DEC_SET_AUDIO_MODE, 2, itv->audio_bilingual_mode, itv->audio_stereo_mode); 635 ivtv_vapi(itv, CX2341X_DEC_SET_AUDIO_MODE, 2, itv->audio_bilingual_mode, itv->audio_stereo_mode);
@@ -668,7 +669,7 @@ static int ivtv_setup_v4l2_decode_stream(struct ivtv_stream *s)
668 break; 669 break;
669 } 670 }
670 if (ivtv_vapi(itv, CX2341X_DEC_SET_DECODER_SOURCE, 4, datatype, 671 if (ivtv_vapi(itv, CX2341X_DEC_SET_DECODER_SOURCE, 4, datatype,
671 width, height, p->audio_properties)) { 672 width, height, itv->cxhdl.audio_properties)) {
672 IVTV_DEBUG_WARN("Couldn't initialize decoder source\n"); 673 IVTV_DEBUG_WARN("Couldn't initialize decoder source\n");
673 } 674 }
674 675
@@ -847,6 +848,8 @@ int ivtv_stop_v4l2_encode_stream(struct ivtv_stream *s, int gop_end)
847 return 0; 848 return 0;
848 } 849 }
849 850
851 cx2341x_handler_set_busy(&itv->cxhdl, 0);
852
850 /* Set the following Interrupt mask bits for capture */ 853 /* Set the following Interrupt mask bits for capture */
851 ivtv_set_irq_mask(itv, IVTV_IRQ_MASK_CAPTURE); 854 ivtv_set_irq_mask(itv, IVTV_IRQ_MASK_CAPTURE);
852 del_timer(&itv->dma_timer); 855 del_timer(&itv->dma_timer);
@@ -967,7 +970,8 @@ int ivtv_passthrough_mode(struct ivtv *itv, int enable)
967 970
968 /* Setup capture if not already done */ 971 /* Setup capture if not already done */
969 if (atomic_read(&itv->capturing) == 0) { 972 if (atomic_read(&itv->capturing) == 0) {
970 cx2341x_update(itv, ivtv_api_func, NULL, &itv->params); 973 cx2341x_handler_setup(&itv->cxhdl);
974 cx2341x_handler_set_busy(&itv->cxhdl, 1);
971 } 975 }
972 976
973 /* Start Passthrough Mode */ 977 /* Start Passthrough Mode */
@@ -988,6 +992,8 @@ int ivtv_passthrough_mode(struct ivtv *itv, int enable)
988 clear_bit(IVTV_F_S_PASSTHROUGH, &dec_stream->s_flags); 992 clear_bit(IVTV_F_S_PASSTHROUGH, &dec_stream->s_flags);
989 clear_bit(IVTV_F_S_STREAMING, &dec_stream->s_flags); 993 clear_bit(IVTV_F_S_STREAMING, &dec_stream->s_flags);
990 itv->output_mode = OUT_NONE; 994 itv->output_mode = OUT_NONE;
995 if (atomic_read(&itv->capturing) == 0)
996 cx2341x_handler_set_busy(&itv->cxhdl, 0);
991 997
992 return 0; 998 return 0;
993} 999}
diff --git a/drivers/media/video/msp3400-driver.c b/drivers/media/video/msp3400-driver.c
index e9df3cb02cc1..0e412131da7c 100644
--- a/drivers/media/video/msp3400-driver.c
+++ b/drivers/media/video/msp3400-driver.c
@@ -283,51 +283,6 @@ void msp_set_scart(struct i2c_client *client, int in, int out)
283 msp_write_dem(client, 0x40, state->i2s_mode); 283 msp_write_dem(client, 0x40, state->i2s_mode);
284} 284}
285 285
286void msp_set_audio(struct i2c_client *client)
287{
288 struct msp_state *state = to_state(i2c_get_clientdata(client));
289 int bal = 0, bass, treble, loudness;
290 int val = 0;
291 int reallymuted = state->muted | state->scan_in_progress;
292
293 if (!reallymuted)
294 val = (state->volume * 0x7f / 65535) << 8;
295
296 v4l_dbg(1, msp_debug, client, "mute=%s scanning=%s volume=%d\n",
297 state->muted ? "on" : "off",
298 state->scan_in_progress ? "yes" : "no",
299 state->volume);
300
301 msp_write_dsp(client, 0x0000, val);
302 msp_write_dsp(client, 0x0007, reallymuted ? 0x1 : (val | 0x1));
303 if (state->has_scart2_out_volume)
304 msp_write_dsp(client, 0x0040, reallymuted ? 0x1 : (val | 0x1));
305 if (state->has_headphones)
306 msp_write_dsp(client, 0x0006, val);
307 if (!state->has_sound_processing)
308 return;
309
310 if (val)
311 bal = (u8)((state->balance / 256) - 128);
312 bass = ((state->bass - 32768) * 0x60 / 65535) << 8;
313 treble = ((state->treble - 32768) * 0x60 / 65535) << 8;
314 loudness = state->loudness ? ((5 * 4) << 8) : 0;
315
316 v4l_dbg(1, msp_debug, client, "balance=%d bass=%d treble=%d loudness=%d\n",
317 state->balance, state->bass, state->treble, state->loudness);
318
319 msp_write_dsp(client, 0x0001, bal << 8);
320 msp_write_dsp(client, 0x0002, bass);
321 msp_write_dsp(client, 0x0003, treble);
322 msp_write_dsp(client, 0x0004, loudness);
323 if (!state->has_headphones)
324 return;
325 msp_write_dsp(client, 0x0030, bal << 8);
326 msp_write_dsp(client, 0x0031, bass);
327 msp_write_dsp(client, 0x0032, treble);
328 msp_write_dsp(client, 0x0033, loudness);
329}
330
331/* ------------------------------------------------------------------------ */ 286/* ------------------------------------------------------------------------ */
332 287
333static void msp_wake_thread(struct i2c_client *client) 288static void msp_wake_thread(struct i2c_client *client)
@@ -363,98 +318,73 @@ int msp_sleep(struct msp_state *state, int timeout)
363 318
364/* ------------------------------------------------------------------------ */ 319/* ------------------------------------------------------------------------ */
365 320
366static int msp_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) 321static int msp_s_ctrl(struct v4l2_ctrl *ctrl)
367{ 322{
368 struct msp_state *state = to_state(sd); 323 struct msp_state *state = ctrl_to_state(ctrl);
324 struct i2c_client *client = v4l2_get_subdevdata(&state->sd);
325 int val = ctrl->val;
369 326
370 switch (ctrl->id) { 327 switch (ctrl->id) {
371 case V4L2_CID_AUDIO_VOLUME: 328 case V4L2_CID_AUDIO_VOLUME: {
372 ctrl->value = state->volume; 329 /* audio volume cluster */
373 break; 330 int reallymuted = state->muted->val | state->scan_in_progress;
374 331
375 case V4L2_CID_AUDIO_MUTE: 332 if (!reallymuted)
376 ctrl->value = state->muted; 333 val = (val * 0x7f / 65535) << 8;
377 break; 334
378 335 v4l_dbg(1, msp_debug, client, "mute=%s scanning=%s volume=%d\n",
379 case V4L2_CID_AUDIO_BALANCE: 336 state->muted->val ? "on" : "off",
380 if (!state->has_sound_processing) 337 state->scan_in_progress ? "yes" : "no",
381 return -EINVAL; 338 state->volume->val);
382 ctrl->value = state->balance; 339
383 break; 340 msp_write_dsp(client, 0x0000, val);
384 341 msp_write_dsp(client, 0x0007, reallymuted ? 0x1 : (val | 0x1));
385 case V4L2_CID_AUDIO_BASS: 342 if (state->has_scart2_out_volume)
386 if (!state->has_sound_processing) 343 msp_write_dsp(client, 0x0040, reallymuted ? 0x1 : (val | 0x1));
387 return -EINVAL; 344 if (state->has_headphones)
388 ctrl->value = state->bass; 345 msp_write_dsp(client, 0x0006, val);
389 break; 346 break;
390
391 case V4L2_CID_AUDIO_TREBLE:
392 if (!state->has_sound_processing)
393 return -EINVAL;
394 ctrl->value = state->treble;
395 break;
396
397 case V4L2_CID_AUDIO_LOUDNESS:
398 if (!state->has_sound_processing)
399 return -EINVAL;
400 ctrl->value = state->loudness;
401 break;
402
403 default:
404 return -EINVAL;
405 } 347 }
406 return 0;
407}
408
409static int msp_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
410{
411 struct msp_state *state = to_state(sd);
412 struct i2c_client *client = v4l2_get_subdevdata(sd);
413
414 switch (ctrl->id) {
415 case V4L2_CID_AUDIO_VOLUME:
416 state->volume = ctrl->value;
417 if (state->volume == 0)
418 state->balance = 32768;
419 break;
420
421 case V4L2_CID_AUDIO_MUTE:
422 if (ctrl->value < 0 || ctrl->value >= 2)
423 return -ERANGE;
424 state->muted = ctrl->value;
425 break;
426 348
427 case V4L2_CID_AUDIO_BASS: 349 case V4L2_CID_AUDIO_BASS:
428 if (!state->has_sound_processing) 350 val = ((val - 32768) * 0x60 / 65535) << 8;
429 return -EINVAL; 351 msp_write_dsp(client, 0x0002, val);
430 state->bass = ctrl->value; 352 if (state->has_headphones)
353 msp_write_dsp(client, 0x0031, val);
431 break; 354 break;
432 355
433 case V4L2_CID_AUDIO_TREBLE: 356 case V4L2_CID_AUDIO_TREBLE:
434 if (!state->has_sound_processing) 357 val = ((val - 32768) * 0x60 / 65535) << 8;
435 return -EINVAL; 358 msp_write_dsp(client, 0x0003, val);
436 state->treble = ctrl->value; 359 if (state->has_headphones)
360 msp_write_dsp(client, 0x0032, val);
437 break; 361 break;
438 362
439 case V4L2_CID_AUDIO_LOUDNESS: 363 case V4L2_CID_AUDIO_LOUDNESS:
440 if (!state->has_sound_processing) 364 val = val ? ((5 * 4) << 8) : 0;
441 return -EINVAL; 365 msp_write_dsp(client, 0x0004, val);
442 state->loudness = ctrl->value; 366 if (state->has_headphones)
367 msp_write_dsp(client, 0x0033, val);
443 break; 368 break;
444 369
445 case V4L2_CID_AUDIO_BALANCE: 370 case V4L2_CID_AUDIO_BALANCE:
446 if (!state->has_sound_processing) 371 val = (u8)((val / 256) - 128);
447 return -EINVAL; 372 msp_write_dsp(client, 0x0001, val << 8);
448 state->balance = ctrl->value; 373 if (state->has_headphones)
374 msp_write_dsp(client, 0x0030, val << 8);
449 break; 375 break;
450 376
451 default: 377 default:
452 return -EINVAL; 378 return -EINVAL;
453 } 379 }
454 msp_set_audio(client);
455 return 0; 380 return 0;
456} 381}
457 382
383void msp_update_volume(struct msp_state *state)
384{
385 v4l2_ctrl_s_ctrl(state->volume, v4l2_ctrl_g_ctrl(state->volume));
386}
387
458/* --- v4l2 ioctls --- */ 388/* --- v4l2 ioctls --- */
459static int msp_s_radio(struct v4l2_subdev *sd) 389static int msp_s_radio(struct v4l2_subdev *sd)
460{ 390{
@@ -472,7 +402,7 @@ static int msp_s_radio(struct v4l2_subdev *sd)
472 msp3400c_set_mode(client, MSP_MODE_FM_RADIO); 402 msp3400c_set_mode(client, MSP_MODE_FM_RADIO);
473 msp3400c_set_carrier(client, MSP_CARRIER(10.7), 403 msp3400c_set_carrier(client, MSP_CARRIER(10.7),
474 MSP_CARRIER(10.7)); 404 MSP_CARRIER(10.7));
475 msp_set_audio(client); 405 msp_update_volume(state);
476 break; 406 break;
477 case OPMODE_AUTODETECT: 407 case OPMODE_AUTODETECT:
478 case OPMODE_AUTOSELECT: 408 case OPMODE_AUTOSELECT:
@@ -592,33 +522,6 @@ static int msp_s_i2s_clock_freq(struct v4l2_subdev *sd, u32 freq)
592 return 0; 522 return 0;
593} 523}
594 524
595static int msp_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc)
596{
597 struct msp_state *state = to_state(sd);
598
599 switch (qc->id) {
600 case V4L2_CID_AUDIO_VOLUME:
601 return v4l2_ctrl_query_fill(qc, 0, 65535, 65535 / 100, 58880);
602 case V4L2_CID_AUDIO_MUTE:
603 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 0);
604 default:
605 break;
606 }
607 if (!state->has_sound_processing)
608 return -EINVAL;
609 switch (qc->id) {
610 case V4L2_CID_AUDIO_LOUDNESS:
611 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 0);
612 case V4L2_CID_AUDIO_BALANCE:
613 case V4L2_CID_AUDIO_BASS:
614 case V4L2_CID_AUDIO_TREBLE:
615 return v4l2_ctrl_query_fill(qc, 0, 65535, 65535 / 100, 32768);
616 default:
617 return -EINVAL;
618 }
619 return 0;
620}
621
622static int msp_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip) 525static int msp_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
623{ 526{
624 struct msp_state *state = to_state(sd); 527 struct msp_state *state = to_state(sd);
@@ -633,19 +536,14 @@ static int msp_log_status(struct v4l2_subdev *sd)
633 struct msp_state *state = to_state(sd); 536 struct msp_state *state = to_state(sd);
634 struct i2c_client *client = v4l2_get_subdevdata(sd); 537 struct i2c_client *client = v4l2_get_subdevdata(sd);
635 const char *p; 538 const char *p;
539 char prefix[V4L2_SUBDEV_NAME_SIZE + 20];
636 540
637 if (state->opmode == OPMODE_AUTOSELECT) 541 if (state->opmode == OPMODE_AUTOSELECT)
638 msp_detect_stereo(client); 542 msp_detect_stereo(client);
639 v4l_info(client, "%s rev1 = 0x%04x rev2 = 0x%04x\n", 543 v4l_info(client, "%s rev1 = 0x%04x rev2 = 0x%04x\n",
640 client->name, state->rev1, state->rev2); 544 client->name, state->rev1, state->rev2);
641 v4l_info(client, "Audio: volume %d%s\n", 545 snprintf(prefix, sizeof(prefix), "%s: Audio: ", sd->name);
642 state->volume, state->muted ? " (muted)" : ""); 546 v4l2_ctrl_handler_log_status(&state->hdl, prefix);
643 if (state->has_sound_processing) {
644 v4l_info(client, "Audio: balance %d bass %d treble %d loudness %s\n",
645 state->balance, state->bass,
646 state->treble,
647 state->loudness ? "on" : "off");
648 }
649 switch (state->mode) { 547 switch (state->mode) {
650 case MSP_MODE_AM_DETECT: p = "AM (for carrier detect)"; break; 548 case MSP_MODE_AM_DETECT: p = "AM (for carrier detect)"; break;
651 case MSP_MODE_FM_RADIO: p = "FM Radio"; break; 549 case MSP_MODE_FM_RADIO: p = "FM Radio"; break;
@@ -695,12 +593,20 @@ static int msp_resume(struct i2c_client *client)
695 593
696/* ----------------------------------------------------------------------- */ 594/* ----------------------------------------------------------------------- */
697 595
596static const struct v4l2_ctrl_ops msp_ctrl_ops = {
597 .s_ctrl = msp_s_ctrl,
598};
599
698static const struct v4l2_subdev_core_ops msp_core_ops = { 600static const struct v4l2_subdev_core_ops msp_core_ops = {
699 .log_status = msp_log_status, 601 .log_status = msp_log_status,
700 .g_chip_ident = msp_g_chip_ident, 602 .g_chip_ident = msp_g_chip_ident,
701 .g_ctrl = msp_g_ctrl, 603 .g_ext_ctrls = v4l2_subdev_g_ext_ctrls,
702 .s_ctrl = msp_s_ctrl, 604 .try_ext_ctrls = v4l2_subdev_try_ext_ctrls,
703 .queryctrl = msp_queryctrl, 605 .s_ext_ctrls = v4l2_subdev_s_ext_ctrls,
606 .g_ctrl = v4l2_subdev_g_ctrl,
607 .s_ctrl = v4l2_subdev_s_ctrl,
608 .queryctrl = v4l2_subdev_queryctrl,
609 .querymenu = v4l2_subdev_querymenu,
704 .s_std = msp_s_std, 610 .s_std = msp_s_std,
705}; 611};
706 612
@@ -728,6 +634,7 @@ static int msp_probe(struct i2c_client *client, const struct i2c_device_id *id)
728{ 634{
729 struct msp_state *state; 635 struct msp_state *state;
730 struct v4l2_subdev *sd; 636 struct v4l2_subdev *sd;
637 struct v4l2_ctrl_handler *hdl;
731 int (*thread_func)(void *data) = NULL; 638 int (*thread_func)(void *data) = NULL;
732 int msp_hard; 639 int msp_hard;
733 int msp_family; 640 int msp_family;
@@ -752,13 +659,7 @@ static int msp_probe(struct i2c_client *client, const struct i2c_device_id *id)
752 659
753 state->v4l2_std = V4L2_STD_NTSC; 660 state->v4l2_std = V4L2_STD_NTSC;
754 state->audmode = V4L2_TUNER_MODE_STEREO; 661 state->audmode = V4L2_TUNER_MODE_STEREO;
755 state->volume = 58880; /* 0db gain */
756 state->balance = 32768; /* 0db gain */
757 state->bass = 32768;
758 state->treble = 32768;
759 state->loudness = 0;
760 state->input = -1; 662 state->input = -1;
761 state->muted = 0;
762 state->i2s_mode = 0; 663 state->i2s_mode = 0;
763 init_waitqueue_head(&state->wq); 664 init_waitqueue_head(&state->wq);
764 /* These are the reset input/output positions */ 665 /* These are the reset input/output positions */
@@ -777,8 +678,6 @@ static int msp_probe(struct i2c_client *client, const struct i2c_device_id *id)
777 return -ENODEV; 678 return -ENODEV;
778 } 679 }
779 680
780 msp_set_audio(client);
781
782 msp_family = ((state->rev1 >> 4) & 0x0f) + 3; 681 msp_family = ((state->rev1 >> 4) & 0x0f) + 3;
783 msp_product = (state->rev2 >> 8) & 0xff; 682 msp_product = (state->rev2 >> 8) & 0xff;
784 msp_prod_hi = msp_product / 10; 683 msp_prod_hi = msp_product / 10;
@@ -849,6 +748,34 @@ static int msp_probe(struct i2c_client *client, const struct i2c_device_id *id)
849 state->opmode = OPMODE_MANUAL; 748 state->opmode = OPMODE_MANUAL;
850 } 749 }
851 750
751 hdl = &state->hdl;
752 v4l2_ctrl_handler_init(hdl, 6);
753 if (state->has_sound_processing) {
754 v4l2_ctrl_new_std(hdl, &msp_ctrl_ops,
755 V4L2_CID_AUDIO_BASS, 0, 65535, 65535 / 100, 32768);
756 v4l2_ctrl_new_std(hdl, &msp_ctrl_ops,
757 V4L2_CID_AUDIO_TREBLE, 0, 65535, 65535 / 100, 32768);
758 v4l2_ctrl_new_std(hdl, &msp_ctrl_ops,
759 V4L2_CID_AUDIO_LOUDNESS, 0, 1, 1, 0);
760 }
761 state->volume = v4l2_ctrl_new_std(hdl, &msp_ctrl_ops,
762 V4L2_CID_AUDIO_VOLUME, 0, 65535, 65535 / 100, 58880);
763 v4l2_ctrl_new_std(hdl, &msp_ctrl_ops,
764 V4L2_CID_AUDIO_BALANCE, 0, 65535, 65535 / 100, 32768);
765 state->muted = v4l2_ctrl_new_std(hdl, &msp_ctrl_ops,
766 V4L2_CID_AUDIO_MUTE, 0, 1, 1, 0);
767 sd->ctrl_handler = hdl;
768 if (hdl->error) {
769 int err = hdl->error;
770
771 v4l2_ctrl_handler_free(hdl);
772 kfree(state);
773 return err;
774 }
775
776 v4l2_ctrl_cluster(2, &state->volume);
777 v4l2_ctrl_handler_setup(hdl);
778
852 /* hello world :-) */ 779 /* hello world :-) */
853 v4l_info(client, "MSP%d4%02d%c-%c%d found @ 0x%x (%s)\n", 780 v4l_info(client, "MSP%d4%02d%c-%c%d found @ 0x%x (%s)\n",
854 msp_family, msp_product, 781 msp_family, msp_product,
@@ -903,6 +830,7 @@ static int msp_remove(struct i2c_client *client)
903 } 830 }
904 msp_reset(client); 831 msp_reset(client);
905 832
833 v4l2_ctrl_handler_free(&state->hdl);
906 kfree(state); 834 kfree(state);
907 return 0; 835 return 0;
908} 836}
diff --git a/drivers/media/video/msp3400-driver.h b/drivers/media/video/msp3400-driver.h
index d6b3e6d0eef7..32a478e532f3 100644
--- a/drivers/media/video/msp3400-driver.h
+++ b/drivers/media/video/msp3400-driver.h
@@ -6,6 +6,7 @@
6 6
7#include <media/msp3400.h> 7#include <media/msp3400.h>
8#include <media/v4l2-device.h> 8#include <media/v4l2-device.h>
9#include <media/v4l2-ctrls.h>
9 10
10/* ---------------------------------------------------------------------- */ 11/* ---------------------------------------------------------------------- */
11 12
@@ -51,6 +52,7 @@ extern int msp_stereo_thresh;
51 52
52struct msp_state { 53struct msp_state {
53 struct v4l2_subdev sd; 54 struct v4l2_subdev sd;
55 struct v4l2_ctrl_handler hdl;
54 int rev1, rev2; 56 int rev1, rev2;
55 int ident; 57 int ident;
56 u8 has_nicam; 58 u8 has_nicam;
@@ -87,9 +89,12 @@ struct msp_state {
87 int audmode; 89 int audmode;
88 int rxsubchans; 90 int rxsubchans;
89 91
90 int volume, muted; 92 struct {
91 int balance, loudness; 93 /* volume cluster */
92 int bass, treble; 94 struct v4l2_ctrl *volume;
95 struct v4l2_ctrl *muted;
96 };
97
93 int scan_in_progress; 98 int scan_in_progress;
94 99
95 /* thread */ 100 /* thread */
@@ -104,6 +109,11 @@ static inline struct msp_state *to_state(struct v4l2_subdev *sd)
104 return container_of(sd, struct msp_state, sd); 109 return container_of(sd, struct msp_state, sd);
105} 110}
106 111
112static inline struct msp_state *ctrl_to_state(struct v4l2_ctrl *ctrl)
113{
114 return container_of(ctrl->handler, struct msp_state, hdl);
115}
116
107/* msp3400-driver.c */ 117/* msp3400-driver.c */
108int msp_write_dem(struct i2c_client *client, int addr, int val); 118int msp_write_dem(struct i2c_client *client, int addr, int val);
109int msp_write_dsp(struct i2c_client *client, int addr, int val); 119int msp_write_dsp(struct i2c_client *client, int addr, int val);
@@ -111,7 +121,7 @@ int msp_read_dem(struct i2c_client *client, int addr);
111int msp_read_dsp(struct i2c_client *client, int addr); 121int msp_read_dsp(struct i2c_client *client, int addr);
112int msp_reset(struct i2c_client *client); 122int msp_reset(struct i2c_client *client);
113void msp_set_scart(struct i2c_client *client, int in, int out); 123void msp_set_scart(struct i2c_client *client, int in, int out);
114void msp_set_audio(struct i2c_client *client); 124void msp_update_volume(struct msp_state *state);
115int msp_sleep(struct msp_state *state, int timeout); 125int msp_sleep(struct msp_state *state, int timeout);
116 126
117/* msp3400-kthreads.c */ 127/* msp3400-kthreads.c */
diff --git a/drivers/media/video/msp3400-kthreads.c b/drivers/media/video/msp3400-kthreads.c
index d5a69c5ee5e4..b376fcdee652 100644
--- a/drivers/media/video/msp3400-kthreads.c
+++ b/drivers/media/video/msp3400-kthreads.c
@@ -496,13 +496,13 @@ restart:
496 v4l_dbg(1, msp_debug, client, 496 v4l_dbg(1, msp_debug, client,
497 "thread: no carrier scan\n"); 497 "thread: no carrier scan\n");
498 state->scan_in_progress = 0; 498 state->scan_in_progress = 0;
499 msp_set_audio(client); 499 msp_update_volume(state);
500 continue; 500 continue;
501 } 501 }
502 502
503 /* mute audio */ 503 /* mute audio */
504 state->scan_in_progress = 1; 504 state->scan_in_progress = 1;
505 msp_set_audio(client); 505 msp_update_volume(state);
506 506
507 msp3400c_set_mode(client, MSP_MODE_AM_DETECT); 507 msp3400c_set_mode(client, MSP_MODE_AM_DETECT);
508 val1 = val2 = 0; 508 val1 = val2 = 0;
@@ -634,7 +634,7 @@ no_second:
634 /* unmute */ 634 /* unmute */
635 state->scan_in_progress = 0; 635 state->scan_in_progress = 0;
636 msp3400c_set_audmode(client); 636 msp3400c_set_audmode(client);
637 msp_set_audio(client); 637 msp_update_volume(state);
638 638
639 if (msp_debug) 639 if (msp_debug)
640 msp3400c_print_mode(client); 640 msp3400c_print_mode(client);
@@ -679,13 +679,13 @@ restart:
679 v4l_dbg(1, msp_debug, client, 679 v4l_dbg(1, msp_debug, client,
680 "thread: no carrier scan\n"); 680 "thread: no carrier scan\n");
681 state->scan_in_progress = 0; 681 state->scan_in_progress = 0;
682 msp_set_audio(client); 682 msp_update_volume(state);
683 continue; 683 continue;
684 } 684 }
685 685
686 /* mute audio */ 686 /* mute audio */
687 state->scan_in_progress = 1; 687 state->scan_in_progress = 1;
688 msp_set_audio(client); 688 msp_update_volume(state);
689 689
690 /* start autodetect. Note: autodetect is not supported for 690 /* start autodetect. Note: autodetect is not supported for
691 NTSC-M and radio, hence we force the standard in those 691 NTSC-M and radio, hence we force the standard in those
@@ -797,7 +797,7 @@ restart:
797 /* unmute */ 797 /* unmute */
798 msp3400c_set_audmode(client); 798 msp3400c_set_audmode(client);
799 state->scan_in_progress = 0; 799 state->scan_in_progress = 0;
800 msp_set_audio(client); 800 msp_update_volume(state);
801 801
802 /* monitor tv audio mode, the first time don't wait 802 /* monitor tv audio mode, the first time don't wait
803 so long to get a quick stereo/bilingual result */ 803 so long to get a quick stereo/bilingual result */
@@ -974,7 +974,7 @@ restart:
974 v4l_dbg(1, msp_debug, client, 974 v4l_dbg(1, msp_debug, client,
975 "thread: no carrier scan\n"); 975 "thread: no carrier scan\n");
976 state->scan_in_progress = 0; 976 state->scan_in_progress = 0;
977 msp_set_audio(client); 977 msp_update_volume(state);
978 continue; 978 continue;
979 } 979 }
980 980
@@ -1020,7 +1020,7 @@ unmute:
1020 } 1020 }
1021 1021
1022 /* unmute: dispatch sound to scart output, set scart volume */ 1022 /* unmute: dispatch sound to scart output, set scart volume */
1023 msp_set_audio(client); 1023 msp_update_volume(state);
1024 1024
1025 /* restore ACB */ 1025 /* restore ACB */
1026 if (msp_write_dsp(client, 0x13, state->acb)) 1026 if (msp_write_dsp(client, 0x13, state->acb))
diff --git a/drivers/media/video/mt9m111.c b/drivers/media/video/mt9m111.c
index 31cc3d04bcc4..758a4db27d65 100644
--- a/drivers/media/video/mt9m111.c
+++ b/drivers/media/video/mt9m111.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Driver for MT9M111/MT9M112 CMOS Image Sensor from Micron 2 * Driver for MT9M111/MT9M112/MT9M131 CMOS Image Sensor from Micron/Aptina
3 * 3 *
4 * Copyright (C) 2008, Robert Jarzmik <robert.jarzmik@free.fr> 4 * Copyright (C) 2008, Robert Jarzmik <robert.jarzmik@free.fr>
5 * 5 *
@@ -19,11 +19,14 @@
19#include <media/soc_camera.h> 19#include <media/soc_camera.h>
20 20
21/* 21/*
22 * mt9m111 and mt9m112 i2c address is 0x5d or 0x48 (depending on SAddr pin) 22 * MT9M111, MT9M112 and MT9M131:
23 * i2c address is 0x48 or 0x5d (depending on SADDR pin)
23 * The platform has to define i2c_board_info and call i2c_register_board_info() 24 * The platform has to define i2c_board_info and call i2c_register_board_info()
24 */ 25 */
25 26
26/* mt9m111: Sensor register addresses */ 27/*
28 * Sensor core register addresses (0x000..0x0ff)
29 */
27#define MT9M111_CHIP_VERSION 0x000 30#define MT9M111_CHIP_VERSION 0x000
28#define MT9M111_ROW_START 0x001 31#define MT9M111_ROW_START 0x001
29#define MT9M111_COLUMN_START 0x002 32#define MT9M111_COLUMN_START 0x002
@@ -72,8 +75,9 @@
72#define MT9M111_CTXT_CTRL_LED_FLASH_EN (1 << 2) 75#define MT9M111_CTXT_CTRL_LED_FLASH_EN (1 << 2)
73#define MT9M111_CTXT_CTRL_VBLANK_SEL_B (1 << 1) 76#define MT9M111_CTXT_CTRL_VBLANK_SEL_B (1 << 1)
74#define MT9M111_CTXT_CTRL_HBLANK_SEL_B (1 << 0) 77#define MT9M111_CTXT_CTRL_HBLANK_SEL_B (1 << 0)
78
75/* 79/*
76 * mt9m111: Colorpipe register addresses (0x100..0x1ff) 80 * Colorpipe register addresses (0x100..0x1ff)
77 */ 81 */
78#define MT9M111_OPER_MODE_CTRL 0x106 82#define MT9M111_OPER_MODE_CTRL 0x106
79#define MT9M111_OUTPUT_FORMAT_CTRL 0x108 83#define MT9M111_OUTPUT_FORMAT_CTRL 0x108
@@ -109,8 +113,9 @@
109#define MT9M111_OUTFMT_SWAP_YCbCr_C_Y (1 << 1) 113#define MT9M111_OUTFMT_SWAP_YCbCr_C_Y (1 << 1)
110#define MT9M111_OUTFMT_SWAP_RGB_EVEN (1 << 1) 114#define MT9M111_OUTFMT_SWAP_RGB_EVEN (1 << 1)
111#define MT9M111_OUTFMT_SWAP_YCbCr_Cb_Cr (1 << 0) 115#define MT9M111_OUTFMT_SWAP_YCbCr_Cb_Cr (1 << 0)
116
112/* 117/*
113 * mt9m111: Camera control register addresses (0x200..0x2ff not implemented) 118 * Camera control register addresses (0x200..0x2ff not implemented)
114 */ 119 */
115 120
116#define reg_read(reg) mt9m111_reg_read(client, MT9M111_##reg) 121#define reg_read(reg) mt9m111_reg_read(client, MT9M111_##reg)
@@ -160,7 +165,8 @@ enum mt9m111_context {
160 165
161struct mt9m111 { 166struct mt9m111 {
162 struct v4l2_subdev subdev; 167 struct v4l2_subdev subdev;
163 int model; /* V4L2_IDENT_MT9M11x* codes from v4l2-chip-ident.h */ 168 int model; /* V4L2_IDENT_MT9M111 or V4L2_IDENT_MT9M112 code
169 * from v4l2-chip-ident.h */
164 enum mt9m111_context context; 170 enum mt9m111_context context;
165 struct v4l2_rect rect; 171 struct v4l2_rect rect;
166 const struct mt9m111_datafmt *fmt; 172 const struct mt9m111_datafmt *fmt;
@@ -934,7 +940,7 @@ static int mt9m111_init(struct i2c_client *client)
934 if (!ret) 940 if (!ret)
935 ret = mt9m111_set_autoexposure(client, mt9m111->autoexposure); 941 ret = mt9m111_set_autoexposure(client, mt9m111->autoexposure);
936 if (ret) 942 if (ret)
937 dev_err(&client->dev, "mt9m11x init failed: %d\n", ret); 943 dev_err(&client->dev, "mt9m111 init failed: %d\n", ret);
938 return ret; 944 return ret;
939} 945}
940 946
@@ -963,27 +969,27 @@ static int mt9m111_video_probe(struct soc_camera_device *icd,
963 mt9m111->swap_rgb_even_odd = 1; 969 mt9m111->swap_rgb_even_odd = 1;
964 mt9m111->swap_rgb_red_blue = 1; 970 mt9m111->swap_rgb_red_blue = 1;
965 971
966 ret = mt9m111_init(client);
967 if (ret)
968 goto ei2c;
969
970 data = reg_read(CHIP_VERSION); 972 data = reg_read(CHIP_VERSION);
971 973
972 switch (data) { 974 switch (data) {
973 case 0x143a: /* MT9M111 */ 975 case 0x143a: /* MT9M111 or MT9M131 */
974 mt9m111->model = V4L2_IDENT_MT9M111; 976 mt9m111->model = V4L2_IDENT_MT9M111;
977 dev_info(&client->dev,
978 "Detected a MT9M111/MT9M131 chip ID %x\n", data);
975 break; 979 break;
976 case 0x148c: /* MT9M112 */ 980 case 0x148c: /* MT9M112 */
977 mt9m111->model = V4L2_IDENT_MT9M112; 981 mt9m111->model = V4L2_IDENT_MT9M112;
982 dev_info(&client->dev, "Detected a MT9M112 chip ID %x\n", data);
978 break; 983 break;
979 default: 984 default:
980 ret = -ENODEV; 985 ret = -ENODEV;
981 dev_err(&client->dev, 986 dev_err(&client->dev,
982 "No MT9M11x chip detected, register read %x\n", data); 987 "No MT9M111/MT9M112/MT9M131 chip detected register read %x\n",
988 data);
983 goto ei2c; 989 goto ei2c;
984 } 990 }
985 991
986 dev_info(&client->dev, "Detected a MT9M11x chip ID %x\n", data); 992 ret = mt9m111_init(client);
987 993
988ei2c: 994ei2c:
989 return ret; 995 return ret;
@@ -1034,13 +1040,13 @@ static int mt9m111_probe(struct i2c_client *client,
1034 int ret; 1040 int ret;
1035 1041
1036 if (!icd) { 1042 if (!icd) {
1037 dev_err(&client->dev, "MT9M11x: missing soc-camera data!\n"); 1043 dev_err(&client->dev, "mt9m111: soc-camera data missing!\n");
1038 return -EINVAL; 1044 return -EINVAL;
1039 } 1045 }
1040 1046
1041 icl = to_soc_camera_link(icd); 1047 icl = to_soc_camera_link(icd);
1042 if (!icl) { 1048 if (!icl) {
1043 dev_err(&client->dev, "MT9M11x driver needs platform data\n"); 1049 dev_err(&client->dev, "mt9m111: driver needs platform data\n");
1044 return -EINVAL; 1050 return -EINVAL;
1045 } 1051 }
1046 1052
@@ -1114,6 +1120,6 @@ static void __exit mt9m111_mod_exit(void)
1114module_init(mt9m111_mod_init); 1120module_init(mt9m111_mod_init);
1115module_exit(mt9m111_mod_exit); 1121module_exit(mt9m111_mod_exit);
1116 1122
1117MODULE_DESCRIPTION("Micron MT9M111/MT9M112 Camera driver"); 1123MODULE_DESCRIPTION("Micron/Aptina MT9M111/MT9M112/MT9M131 Camera driver");
1118MODULE_AUTHOR("Robert Jarzmik"); 1124MODULE_AUTHOR("Robert Jarzmik");
1119MODULE_LICENSE("GPL"); 1125MODULE_LICENSE("GPL");
diff --git a/drivers/media/video/mx2_camera.c b/drivers/media/video/mx2_camera.c
index 026bef0ba403..66ff174151b5 100644
--- a/drivers/media/video/mx2_camera.c
+++ b/drivers/media/video/mx2_camera.c
@@ -785,6 +785,8 @@ static int mx2_camera_set_bus_param(struct soc_camera_device *icd,
785 if (ret < 0) 785 if (ret < 0)
786 return ret; 786 return ret;
787 787
788 if (common_flags & SOCAM_PCLK_SAMPLE_RISING)
789 csicr1 |= CSICR1_REDGE;
788 if (common_flags & SOCAM_PCLK_SAMPLE_FALLING) 790 if (common_flags & SOCAM_PCLK_SAMPLE_FALLING)
789 csicr1 |= CSICR1_INV_PCLK; 791 csicr1 |= CSICR1_INV_PCLK;
790 if (common_flags & SOCAM_VSYNC_ACTIVE_HIGH) 792 if (common_flags & SOCAM_VSYNC_ACTIVE_HIGH)
@@ -1201,7 +1203,7 @@ static void mx27_camera_frame_done_emma(struct mx2_camera_dev *pcdev,
1201 buf = list_entry(pcdev->capture.next, 1203 buf = list_entry(pcdev->capture.next,
1202 struct mx2_buffer, vb.queue); 1204 struct mx2_buffer, vb.queue);
1203 1205
1204 buf->bufnum = bufnum; 1206 buf->bufnum = !bufnum;
1205 1207
1206 list_move_tail(pcdev->capture.next, &pcdev->active_bufs); 1208 list_move_tail(pcdev->capture.next, &pcdev->active_bufs);
1207 1209
diff --git a/drivers/media/video/pvrusb2/pvrusb2-debugifc.c b/drivers/media/video/pvrusb2/pvrusb2-debugifc.c
index e9b11e119f62..4279ebb811a1 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-debugifc.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-debugifc.c
@@ -94,8 +94,6 @@ static int debugifc_parse_unsigned_number(const char *buf,unsigned int count,
94 u32 *num_ptr) 94 u32 *num_ptr)
95{ 95{
96 u32 result = 0; 96 u32 result = 0;
97 u32 val;
98 int ch;
99 int radix = 10; 97 int radix = 10;
100 if ((count >= 2) && (buf[0] == '0') && 98 if ((count >= 2) && (buf[0] == '0') &&
101 ((buf[1] == 'x') || (buf[1] == 'X'))) { 99 ((buf[1] == 'x') || (buf[1] == 'X'))) {
@@ -107,17 +105,9 @@ static int debugifc_parse_unsigned_number(const char *buf,unsigned int count,
107 } 105 }
108 106
109 while (count--) { 107 while (count--) {
110 ch = *buf++; 108 int val = hex_to_bin(*buf++);
111 if ((ch >= '0') && (ch <= '9')) { 109 if (val < 0 || val >= radix)
112 val = ch - '0';
113 } else if ((ch >= 'a') && (ch <= 'f')) {
114 val = ch - 'a' + 10;
115 } else if ((ch >= 'A') && (ch <= 'F')) {
116 val = ch - 'A' + 10;
117 } else {
118 return -EINVAL; 110 return -EINVAL;
119 }
120 if (val >= radix) return -EINVAL;
121 result *= radix; 111 result *= radix;
122 result += val; 112 result += val;
123 } 113 }
diff --git a/drivers/media/video/s5p-fimc/Makefile b/drivers/media/video/s5p-fimc/Makefile
new file mode 100644
index 000000000000..0d9d54132ecc
--- /dev/null
+++ b/drivers/media/video/s5p-fimc/Makefile
@@ -0,0 +1,3 @@
1
2obj-$(CONFIG_VIDEO_SAMSUNG_S5P_FIMC) := s5p-fimc.o
3s5p-fimc-y := fimc-core.o fimc-reg.o
diff --git a/drivers/media/video/s5p-fimc/fimc-core.c b/drivers/media/video/s5p-fimc/fimc-core.c
new file mode 100644
index 000000000000..b151c7be8a50
--- /dev/null
+++ b/drivers/media/video/s5p-fimc/fimc-core.c
@@ -0,0 +1,1586 @@
1/*
2 * S5P camera interface (video postprocessor) driver
3 *
4 * Copyright (c) 2010 Samsung Electronics
5 *
6 * Sylwester Nawrocki, <s.nawrocki@samsung.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
10 * by the Free Software Foundation, either version 2 of the License,
11 * or (at your option) any later version.
12 */
13
14#include <linux/module.h>
15#include <linux/kernel.h>
16#include <linux/version.h>
17#include <linux/types.h>
18#include <linux/errno.h>
19#include <linux/bug.h>
20#include <linux/interrupt.h>
21#include <linux/device.h>
22#include <linux/platform_device.h>
23#include <linux/list.h>
24#include <linux/io.h>
25#include <linux/slab.h>
26#include <linux/clk.h>
27#include <media/v4l2-ioctl.h>
28#include <media/videobuf-dma-contig.h>
29
30#include "fimc-core.h"
31
32static char *fimc_clock_name[NUM_FIMC_CLOCKS] = { "sclk_fimc", "fimc" };
33
34static struct fimc_fmt fimc_formats[] = {
35 {
36 .name = "RGB565",
37 .fourcc = V4L2_PIX_FMT_RGB565X,
38 .depth = 16,
39 .color = S5P_FIMC_RGB565,
40 .buff_cnt = 1,
41 .planes_cnt = 1
42 }, {
43 .name = "BGR666",
44 .fourcc = V4L2_PIX_FMT_BGR666,
45 .depth = 32,
46 .color = S5P_FIMC_RGB666,
47 .buff_cnt = 1,
48 .planes_cnt = 1
49 }, {
50 .name = "XRGB-8-8-8-8, 24 bpp",
51 .fourcc = V4L2_PIX_FMT_RGB24,
52 .depth = 32,
53 .color = S5P_FIMC_RGB888,
54 .buff_cnt = 1,
55 .planes_cnt = 1
56 }, {
57 .name = "YUV 4:2:2 packed, YCbYCr",
58 .fourcc = V4L2_PIX_FMT_YUYV,
59 .depth = 16,
60 .color = S5P_FIMC_YCBYCR422,
61 .buff_cnt = 1,
62 .planes_cnt = 1
63 }, {
64 .name = "YUV 4:2:2 packed, CbYCrY",
65 .fourcc = V4L2_PIX_FMT_UYVY,
66 .depth = 16,
67 .color = S5P_FIMC_CBYCRY422,
68 .buff_cnt = 1,
69 .planes_cnt = 1
70 }, {
71 .name = "YUV 4:2:2 packed, CrYCbY",
72 .fourcc = V4L2_PIX_FMT_VYUY,
73 .depth = 16,
74 .color = S5P_FIMC_CRYCBY422,
75 .buff_cnt = 1,
76 .planes_cnt = 1
77 }, {
78 .name = "YUV 4:2:2 packed, YCrYCb",
79 .fourcc = V4L2_PIX_FMT_YVYU,
80 .depth = 16,
81 .color = S5P_FIMC_YCRYCB422,
82 .buff_cnt = 1,
83 .planes_cnt = 1
84 }, {
85 .name = "YUV 4:2:2 planar, Y/Cb/Cr",
86 .fourcc = V4L2_PIX_FMT_YUV422P,
87 .depth = 12,
88 .color = S5P_FIMC_YCBCR422,
89 .buff_cnt = 1,
90 .planes_cnt = 3
91 }, {
92 .name = "YUV 4:2:2 planar, Y/CbCr",
93 .fourcc = V4L2_PIX_FMT_NV16,
94 .depth = 16,
95 .color = S5P_FIMC_YCBCR422,
96 .buff_cnt = 1,
97 .planes_cnt = 2
98 }, {
99 .name = "YUV 4:2:2 planar, Y/CrCb",
100 .fourcc = V4L2_PIX_FMT_NV61,
101 .depth = 16,
102 .color = S5P_FIMC_RGB565,
103 .buff_cnt = 1,
104 .planes_cnt = 2
105 }, {
106 .name = "YUV 4:2:0 planar, YCbCr",
107 .fourcc = V4L2_PIX_FMT_YUV420,
108 .depth = 12,
109 .color = S5P_FIMC_YCBCR420,
110 .buff_cnt = 1,
111 .planes_cnt = 3
112 }, {
113 .name = "YUV 4:2:0 planar, Y/CbCr",
114 .fourcc = V4L2_PIX_FMT_NV12,
115 .depth = 12,
116 .color = S5P_FIMC_YCBCR420,
117 .buff_cnt = 1,
118 .planes_cnt = 2
119 }
120 };
121
122static struct v4l2_queryctrl fimc_ctrls[] = {
123 {
124 .id = V4L2_CID_HFLIP,
125 .type = V4L2_CTRL_TYPE_BOOLEAN,
126 .name = "Horizontal flip",
127 .minimum = 0,
128 .maximum = 1,
129 .default_value = 0,
130 },
131 {
132 .id = V4L2_CID_VFLIP,
133 .type = V4L2_CTRL_TYPE_BOOLEAN,
134 .name = "Vertical flip",
135 .minimum = 0,
136 .maximum = 1,
137 .default_value = 0,
138 },
139 {
140 .id = V4L2_CID_ROTATE,
141 .type = V4L2_CTRL_TYPE_INTEGER,
142 .name = "Rotation (CCW)",
143 .minimum = 0,
144 .maximum = 270,
145 .step = 90,
146 .default_value = 0,
147 },
148};
149
150
151static struct v4l2_queryctrl *get_ctrl(int id)
152{
153 int i;
154
155 for (i = 0; i < ARRAY_SIZE(fimc_ctrls); ++i)
156 if (id == fimc_ctrls[i].id)
157 return &fimc_ctrls[i];
158 return NULL;
159}
160
161static int fimc_check_scaler_ratio(struct v4l2_rect *r, struct fimc_frame *f)
162{
163 if (r->width > f->width) {
164 if (f->width > (r->width * SCALER_MAX_HRATIO))
165 return -EINVAL;
166 } else {
167 if ((f->width * SCALER_MAX_HRATIO) < r->width)
168 return -EINVAL;
169 }
170
171 if (r->height > f->height) {
172 if (f->height > (r->height * SCALER_MAX_VRATIO))
173 return -EINVAL;
174 } else {
175 if ((f->height * SCALER_MAX_VRATIO) < r->height)
176 return -EINVAL;
177 }
178
179 return 0;
180}
181
182static int fimc_get_scaler_factor(u32 src, u32 tar, u32 *ratio, u32 *shift)
183{
184 if (src >= tar * 64) {
185 return -EINVAL;
186 } else if (src >= tar * 32) {
187 *ratio = 32;
188 *shift = 5;
189 } else if (src >= tar * 16) {
190 *ratio = 16;
191 *shift = 4;
192 } else if (src >= tar * 8) {
193 *ratio = 8;
194 *shift = 3;
195 } else if (src >= tar * 4) {
196 *ratio = 4;
197 *shift = 2;
198 } else if (src >= tar * 2) {
199 *ratio = 2;
200 *shift = 1;
201 } else {
202 *ratio = 1;
203 *shift = 0;
204 }
205
206 return 0;
207}
208
209static int fimc_set_scaler_info(struct fimc_ctx *ctx)
210{
211 struct fimc_scaler *sc = &ctx->scaler;
212 struct fimc_frame *s_frame = &ctx->s_frame;
213 struct fimc_frame *d_frame = &ctx->d_frame;
214 int tx, ty, sx, sy;
215 int ret;
216
217 tx = d_frame->width;
218 ty = d_frame->height;
219 if (tx <= 0 || ty <= 0) {
220 v4l2_err(&ctx->fimc_dev->m2m.v4l2_dev,
221 "invalid target size: %d x %d", tx, ty);
222 return -EINVAL;
223 }
224
225 sx = s_frame->width;
226 sy = s_frame->height;
227 if (sx <= 0 || sy <= 0) {
228 err("invalid source size: %d x %d", sx, sy);
229 return -EINVAL;
230 }
231
232 sc->real_width = sx;
233 sc->real_height = sy;
234 dbg("sx= %d, sy= %d, tx= %d, ty= %d", sx, sy, tx, ty);
235
236 ret = fimc_get_scaler_factor(sx, tx, &sc->pre_hratio, &sc->hfactor);
237 if (ret)
238 return ret;
239
240 ret = fimc_get_scaler_factor(sy, ty, &sc->pre_vratio, &sc->vfactor);
241 if (ret)
242 return ret;
243
244 sc->pre_dst_width = sx / sc->pre_hratio;
245 sc->pre_dst_height = sy / sc->pre_vratio;
246
247 sc->main_hratio = (sx << 8) / (tx << sc->hfactor);
248 sc->main_vratio = (sy << 8) / (ty << sc->vfactor);
249
250 sc->scaleup_h = (tx >= sx) ? 1 : 0;
251 sc->scaleup_v = (ty >= sy) ? 1 : 0;
252
253 /* check to see if input and output size/format differ */
254 if (s_frame->fmt->color == d_frame->fmt->color
255 && s_frame->width == d_frame->width
256 && s_frame->height == d_frame->height)
257 sc->copy_mode = 1;
258 else
259 sc->copy_mode = 0;
260
261 return 0;
262}
263
264
265static irqreturn_t fimc_isr(int irq, void *priv)
266{
267 struct fimc_vid_buffer *src_buf, *dst_buf;
268 struct fimc_dev *fimc = (struct fimc_dev *)priv;
269 struct fimc_ctx *ctx;
270
271 BUG_ON(!fimc);
272 fimc_hw_clear_irq(fimc);
273
274 spin_lock(&fimc->slock);
275
276 if (test_and_clear_bit(ST_M2M_PEND, &fimc->state)) {
277 ctx = v4l2_m2m_get_curr_priv(fimc->m2m.m2m_dev);
278 if (!ctx || !ctx->m2m_ctx)
279 goto isr_unlock;
280 src_buf = v4l2_m2m_src_buf_remove(ctx->m2m_ctx);
281 dst_buf = v4l2_m2m_dst_buf_remove(ctx->m2m_ctx);
282 if (src_buf && dst_buf) {
283 spin_lock(&fimc->irqlock);
284 src_buf->vb.state = dst_buf->vb.state = VIDEOBUF_DONE;
285 wake_up(&src_buf->vb.done);
286 wake_up(&dst_buf->vb.done);
287 spin_unlock(&fimc->irqlock);
288 v4l2_m2m_job_finish(fimc->m2m.m2m_dev, ctx->m2m_ctx);
289 }
290 }
291
292isr_unlock:
293 spin_unlock(&fimc->slock);
294 return IRQ_HANDLED;
295}
296
297/* The color format (planes_cnt, buff_cnt) must be already configured. */
298static int fimc_prepare_addr(struct fimc_ctx *ctx,
299 struct fimc_vid_buffer *buf, enum v4l2_buf_type type)
300{
301 struct fimc_frame *frame;
302 struct fimc_addr *paddr;
303 u32 pix_size;
304 int ret = 0;
305
306 frame = ctx_m2m_get_frame(ctx, type);
307 if (IS_ERR(frame))
308 return PTR_ERR(frame);
309 paddr = &frame->paddr;
310
311 if (!buf)
312 return -EINVAL;
313
314 pix_size = frame->width * frame->height;
315
316 dbg("buff_cnt= %d, planes_cnt= %d, frame->size= %d, pix_size= %d",
317 frame->fmt->buff_cnt, frame->fmt->planes_cnt,
318 frame->size, pix_size);
319
320 if (frame->fmt->buff_cnt == 1) {
321 paddr->y = videobuf_to_dma_contig(&buf->vb);
322 switch (frame->fmt->planes_cnt) {
323 case 1:
324 paddr->cb = 0;
325 paddr->cr = 0;
326 break;
327 case 2:
328 /* decompose Y into Y/Cb */
329 paddr->cb = (u32)(paddr->y + pix_size);
330 paddr->cr = 0;
331 break;
332 case 3:
333 paddr->cb = (u32)(paddr->y + pix_size);
334 /* decompose Y into Y/Cb/Cr */
335 if (S5P_FIMC_YCBCR420 == frame->fmt->color)
336 paddr->cr = (u32)(paddr->cb
337 + (pix_size >> 2));
338 else /* 422 */
339 paddr->cr = (u32)(paddr->cb
340 + (pix_size >> 1));
341 break;
342 default:
343 return -EINVAL;
344 }
345 }
346
347 dbg("PHYS_ADDR: type= %d, y= 0x%X cb= 0x%X cr= 0x%X ret= %d",
348 type, paddr->y, paddr->cb, paddr->cr, ret);
349
350 return ret;
351}
352
353/* Set order for 1 and 2 plane YCBCR 4:2:2 formats. */
354static void fimc_set_yuv_order(struct fimc_ctx *ctx)
355{
356 /* The one only mode supported in SoC. */
357 ctx->in_order_2p = S5P_FIMC_LSB_CRCB;
358 ctx->out_order_2p = S5P_FIMC_LSB_CRCB;
359
360 /* Set order for 1 plane input formats. */
361 switch (ctx->s_frame.fmt->color) {
362 case S5P_FIMC_YCRYCB422:
363 ctx->in_order_1p = S5P_FIMC_IN_YCRYCB;
364 break;
365 case S5P_FIMC_CBYCRY422:
366 ctx->in_order_1p = S5P_FIMC_IN_CBYCRY;
367 break;
368 case S5P_FIMC_CRYCBY422:
369 ctx->in_order_1p = S5P_FIMC_IN_CRYCBY;
370 break;
371 case S5P_FIMC_YCBYCR422:
372 default:
373 ctx->in_order_1p = S5P_FIMC_IN_YCBYCR;
374 break;
375 }
376 dbg("ctx->in_order_1p= %d", ctx->in_order_1p);
377
378 switch (ctx->d_frame.fmt->color) {
379 case S5P_FIMC_YCRYCB422:
380 ctx->out_order_1p = S5P_FIMC_OUT_YCRYCB;
381 break;
382 case S5P_FIMC_CBYCRY422:
383 ctx->out_order_1p = S5P_FIMC_OUT_CBYCRY;
384 break;
385 case S5P_FIMC_CRYCBY422:
386 ctx->out_order_1p = S5P_FIMC_OUT_CRYCBY;
387 break;
388 case S5P_FIMC_YCBYCR422:
389 default:
390 ctx->out_order_1p = S5P_FIMC_OUT_YCBYCR;
391 break;
392 }
393 dbg("ctx->out_order_1p= %d", ctx->out_order_1p);
394}
395
396/**
397 * fimc_prepare_config - check dimensions, operation and color mode
398 * and pre-calculate offset and the scaling coefficients.
399 *
400 * @ctx: hardware context information
401 * @flags: flags indicating which parameters to check/update
402 *
403 * Return: 0 if dimensions are valid or non zero otherwise.
404 */
405static int fimc_prepare_config(struct fimc_ctx *ctx, u32 flags)
406{
407 struct fimc_frame *s_frame, *d_frame;
408 struct fimc_vid_buffer *buf = NULL;
409 struct samsung_fimc_variant *variant = ctx->fimc_dev->variant;
410 int ret = 0;
411
412 s_frame = &ctx->s_frame;
413 d_frame = &ctx->d_frame;
414
415 if (flags & FIMC_PARAMS) {
416 if ((ctx->out_path == FIMC_DMA) &&
417 (ctx->rotation == 90 || ctx->rotation == 270)) {
418 swap(d_frame->f_width, d_frame->f_height);
419 swap(d_frame->width, d_frame->height);
420 }
421
422 /* Prepare the output offset ratios for scaler. */
423 d_frame->dma_offset.y_h = d_frame->offs_h;
424 if (!variant->pix_hoff)
425 d_frame->dma_offset.y_h *= (d_frame->fmt->depth >> 3);
426
427 d_frame->dma_offset.y_v = d_frame->offs_v;
428
429 d_frame->dma_offset.cb_h = d_frame->offs_h;
430 d_frame->dma_offset.cb_v = d_frame->offs_v;
431
432 d_frame->dma_offset.cr_h = d_frame->offs_h;
433 d_frame->dma_offset.cr_v = d_frame->offs_v;
434
435 if (!variant->pix_hoff && d_frame->fmt->planes_cnt == 3) {
436 d_frame->dma_offset.cb_h >>= 1;
437 d_frame->dma_offset.cb_v >>= 1;
438 d_frame->dma_offset.cr_h >>= 1;
439 d_frame->dma_offset.cr_v >>= 1;
440 }
441
442 dbg("out offset: color= %d, y_h= %d, y_v= %d",
443 d_frame->fmt->color,
444 d_frame->dma_offset.y_h, d_frame->dma_offset.y_v);
445
446 /* Prepare the input offset ratios for scaler. */
447 s_frame->dma_offset.y_h = s_frame->offs_h;
448 if (!variant->pix_hoff)
449 s_frame->dma_offset.y_h *= (s_frame->fmt->depth >> 3);
450 s_frame->dma_offset.y_v = s_frame->offs_v;
451
452 s_frame->dma_offset.cb_h = s_frame->offs_h;
453 s_frame->dma_offset.cb_v = s_frame->offs_v;
454
455 s_frame->dma_offset.cr_h = s_frame->offs_h;
456 s_frame->dma_offset.cr_v = s_frame->offs_v;
457
458 if (!variant->pix_hoff && s_frame->fmt->planes_cnt == 3) {
459 s_frame->dma_offset.cb_h >>= 1;
460 s_frame->dma_offset.cb_v >>= 1;
461 s_frame->dma_offset.cr_h >>= 1;
462 s_frame->dma_offset.cr_v >>= 1;
463 }
464
465 dbg("in offset: color= %d, y_h= %d, y_v= %d",
466 s_frame->fmt->color, s_frame->dma_offset.y_h,
467 s_frame->dma_offset.y_v);
468
469 fimc_set_yuv_order(ctx);
470
471 /* Check against the scaler ratio. */
472 if (s_frame->height > (SCALER_MAX_VRATIO * d_frame->height) ||
473 s_frame->width > (SCALER_MAX_HRATIO * d_frame->width)) {
474 err("out of scaler range");
475 return -EINVAL;
476 }
477 }
478
479 /* Input DMA mode is not allowed when the scaler is disabled. */
480 ctx->scaler.enabled = 1;
481
482 if (flags & FIMC_SRC_ADDR) {
483 buf = v4l2_m2m_next_src_buf(ctx->m2m_ctx);
484 ret = fimc_prepare_addr(ctx, buf,
485 V4L2_BUF_TYPE_VIDEO_OUTPUT);
486 if (ret)
487 return ret;
488 }
489
490 if (flags & FIMC_DST_ADDR) {
491 buf = v4l2_m2m_next_dst_buf(ctx->m2m_ctx);
492 ret = fimc_prepare_addr(ctx, buf,
493 V4L2_BUF_TYPE_VIDEO_CAPTURE);
494 }
495
496 return ret;
497}
498
499static void fimc_dma_run(void *priv)
500{
501 struct fimc_ctx *ctx = priv;
502 struct fimc_dev *fimc;
503 unsigned long flags;
504 u32 ret;
505
506 if (WARN(!ctx, "null hardware context"))
507 return;
508
509 fimc = ctx->fimc_dev;
510
511 spin_lock_irqsave(&ctx->slock, flags);
512 set_bit(ST_M2M_PEND, &fimc->state);
513
514 ctx->state |= (FIMC_SRC_ADDR | FIMC_DST_ADDR);
515 ret = fimc_prepare_config(ctx, ctx->state);
516 if (ret) {
517 err("general configuration error");
518 goto dma_unlock;
519 }
520
521 if (fimc->m2m.ctx != ctx)
522 ctx->state |= FIMC_PARAMS;
523
524 fimc_hw_set_input_addr(fimc, &ctx->s_frame.paddr);
525
526 if (ctx->state & FIMC_PARAMS) {
527 fimc_hw_set_input_path(ctx);
528 fimc_hw_set_in_dma(ctx);
529 if (fimc_set_scaler_info(ctx)) {
530 err("scaler configuration error");
531 goto dma_unlock;
532 }
533 fimc_hw_set_prescaler(ctx);
534 fimc_hw_set_scaler(ctx);
535 fimc_hw_set_target_format(ctx);
536 fimc_hw_set_rotation(ctx);
537 fimc_hw_set_effect(ctx);
538 }
539
540 fimc_hw_set_output_path(ctx);
541 if (ctx->state & (FIMC_DST_ADDR | FIMC_PARAMS))
542 fimc_hw_set_output_addr(fimc, &ctx->d_frame.paddr);
543
544 if (ctx->state & FIMC_PARAMS)
545 fimc_hw_set_out_dma(ctx);
546
547 if (ctx->scaler.enabled)
548 fimc_hw_start_scaler(fimc);
549 fimc_hw_en_capture(ctx);
550
551 ctx->state = 0;
552 fimc_hw_start_in_dma(fimc);
553
554 fimc->m2m.ctx = ctx;
555
556dma_unlock:
557 spin_unlock_irqrestore(&ctx->slock, flags);
558}
559
560static void fimc_job_abort(void *priv)
561{
562 /* Nothing done in job_abort. */
563}
564
565static void fimc_buf_release(struct videobuf_queue *vq,
566 struct videobuf_buffer *vb)
567{
568 videobuf_dma_contig_free(vq, vb);
569 vb->state = VIDEOBUF_NEEDS_INIT;
570}
571
572static int fimc_buf_setup(struct videobuf_queue *vq, unsigned int *count,
573 unsigned int *size)
574{
575 struct fimc_ctx *ctx = vq->priv_data;
576 struct fimc_frame *frame;
577
578 frame = ctx_m2m_get_frame(ctx, vq->type);
579 if (IS_ERR(frame))
580 return PTR_ERR(frame);
581
582 *size = (frame->width * frame->height * frame->fmt->depth) >> 3;
583 if (0 == *count)
584 *count = 1;
585 return 0;
586}
587
588static int fimc_buf_prepare(struct videobuf_queue *vq,
589 struct videobuf_buffer *vb, enum v4l2_field field)
590{
591 struct fimc_ctx *ctx = vq->priv_data;
592 struct v4l2_device *v4l2_dev = &ctx->fimc_dev->m2m.v4l2_dev;
593 struct fimc_frame *frame;
594 int ret;
595
596 frame = ctx_m2m_get_frame(ctx, vq->type);
597 if (IS_ERR(frame))
598 return PTR_ERR(frame);
599
600 if (vb->baddr) {
601 if (vb->bsize < frame->size) {
602 v4l2_err(v4l2_dev,
603 "User-provided buffer too small (%d < %d)\n",
604 vb->bsize, frame->size);
605 WARN_ON(1);
606 return -EINVAL;
607 }
608 } else if (vb->state != VIDEOBUF_NEEDS_INIT
609 && vb->bsize < frame->size) {
610 return -EINVAL;
611 }
612
613 vb->width = frame->width;
614 vb->height = frame->height;
615 vb->bytesperline = (frame->width * frame->fmt->depth) >> 3;
616 vb->size = frame->size;
617 vb->field = field;
618
619 if (VIDEOBUF_NEEDS_INIT == vb->state) {
620 ret = videobuf_iolock(vq, vb, NULL);
621 if (ret) {
622 v4l2_err(v4l2_dev, "Iolock failed\n");
623 fimc_buf_release(vq, vb);
624 return ret;
625 }
626 }
627 vb->state = VIDEOBUF_PREPARED;
628
629 return 0;
630}
631
632static void fimc_buf_queue(struct videobuf_queue *vq,
633 struct videobuf_buffer *vb)
634{
635 struct fimc_ctx *ctx = vq->priv_data;
636 v4l2_m2m_buf_queue(ctx->m2m_ctx, vq, vb);
637}
638
639static struct videobuf_queue_ops fimc_qops = {
640 .buf_setup = fimc_buf_setup,
641 .buf_prepare = fimc_buf_prepare,
642 .buf_queue = fimc_buf_queue,
643 .buf_release = fimc_buf_release,
644};
645
646static int fimc_m2m_querycap(struct file *file, void *priv,
647 struct v4l2_capability *cap)
648{
649 struct fimc_ctx *ctx = file->private_data;
650 struct fimc_dev *fimc = ctx->fimc_dev;
651
652 strncpy(cap->driver, fimc->pdev->name, sizeof(cap->driver) - 1);
653 strncpy(cap->card, fimc->pdev->name, sizeof(cap->card) - 1);
654 cap->bus_info[0] = 0;
655 cap->version = KERNEL_VERSION(1, 0, 0);
656 cap->capabilities = V4L2_CAP_STREAMING |
657 V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_OUTPUT;
658
659 return 0;
660}
661
662static int fimc_m2m_enum_fmt(struct file *file, void *priv,
663 struct v4l2_fmtdesc *f)
664{
665 struct fimc_fmt *fmt;
666
667 if (f->index >= ARRAY_SIZE(fimc_formats))
668 return -EINVAL;
669
670 fmt = &fimc_formats[f->index];
671 strncpy(f->description, fmt->name, sizeof(f->description) - 1);
672 f->pixelformat = fmt->fourcc;
673 return 0;
674}
675
676static int fimc_m2m_g_fmt(struct file *file, void *priv, struct v4l2_format *f)
677{
678 struct fimc_ctx *ctx = priv;
679 struct fimc_frame *frame;
680
681 frame = ctx_m2m_get_frame(ctx, f->type);
682 if (IS_ERR(frame))
683 return PTR_ERR(frame);
684
685 f->fmt.pix.width = frame->width;
686 f->fmt.pix.height = frame->height;
687 f->fmt.pix.field = V4L2_FIELD_NONE;
688 f->fmt.pix.pixelformat = frame->fmt->fourcc;
689
690 return 0;
691}
692
693static struct fimc_fmt *find_format(struct v4l2_format *f)
694{
695 struct fimc_fmt *fmt;
696 unsigned int i;
697
698 for (i = 0; i < ARRAY_SIZE(fimc_formats); ++i) {
699 fmt = &fimc_formats[i];
700 if (fmt->fourcc == f->fmt.pix.pixelformat)
701 break;
702 }
703 if (i == ARRAY_SIZE(fimc_formats))
704 return NULL;
705
706 return fmt;
707}
708
709static int fimc_m2m_try_fmt(struct file *file, void *priv,
710 struct v4l2_format *f)
711{
712 struct fimc_fmt *fmt;
713 u32 max_width, max_height, mod_x, mod_y;
714 struct fimc_ctx *ctx = priv;
715 struct fimc_dev *fimc = ctx->fimc_dev;
716 struct v4l2_pix_format *pix = &f->fmt.pix;
717 struct samsung_fimc_variant *variant = fimc->variant;
718
719 fmt = find_format(f);
720 if (!fmt) {
721 v4l2_err(&fimc->m2m.v4l2_dev,
722 "Fourcc format (0x%X) invalid.\n", pix->pixelformat);
723 return -EINVAL;
724 }
725
726 if (pix->field == V4L2_FIELD_ANY)
727 pix->field = V4L2_FIELD_NONE;
728 else if (V4L2_FIELD_NONE != pix->field)
729 return -EINVAL;
730
731 if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) {
732 max_width = variant->scaler_dis_w;
733 max_height = variant->scaler_dis_w;
734 mod_x = variant->min_inp_pixsize;
735 mod_y = variant->min_inp_pixsize;
736 } else if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
737 max_width = variant->out_rot_dis_w;
738 max_height = variant->out_rot_dis_w;
739 mod_x = variant->min_out_pixsize;
740 mod_y = variant->min_out_pixsize;
741 } else {
742 err("Wrong stream type (%d)", f->type);
743 return -EINVAL;
744 }
745
746 dbg("max_w= %d, max_h= %d", max_width, max_height);
747
748 if (pix->height > max_height)
749 pix->height = max_height;
750 if (pix->width > max_width)
751 pix->width = max_width;
752
753 if (tiled_fmt(fmt)) {
754 mod_x = 64; /* 64x32 tile */
755 mod_y = 32;
756 }
757
758 dbg("mod_x= 0x%X, mod_y= 0x%X", mod_x, mod_y);
759
760 pix->width = (pix->width == 0) ? mod_x : ALIGN(pix->width, mod_x);
761 pix->height = (pix->height == 0) ? mod_y : ALIGN(pix->height, mod_y);
762
763 if (pix->bytesperline == 0 ||
764 pix->bytesperline * 8 / fmt->depth > pix->width)
765 pix->bytesperline = (pix->width * fmt->depth) >> 3;
766
767 if (pix->sizeimage == 0)
768 pix->sizeimage = pix->height * pix->bytesperline;
769
770 dbg("pix->bytesperline= %d, fmt->depth= %d",
771 pix->bytesperline, fmt->depth);
772
773 return 0;
774}
775
776
777static int fimc_m2m_s_fmt(struct file *file, void *priv, struct v4l2_format *f)
778{
779 struct fimc_ctx *ctx = priv;
780 struct v4l2_device *v4l2_dev = &ctx->fimc_dev->m2m.v4l2_dev;
781 struct videobuf_queue *src_vq, *dst_vq;
782 struct fimc_frame *frame;
783 struct v4l2_pix_format *pix;
784 unsigned long flags;
785 int ret = 0;
786
787 BUG_ON(!ctx);
788
789 ret = fimc_m2m_try_fmt(file, priv, f);
790 if (ret)
791 return ret;
792
793 mutex_lock(&ctx->fimc_dev->lock);
794
795 src_vq = v4l2_m2m_get_src_vq(ctx->m2m_ctx);
796 dst_vq = v4l2_m2m_get_dst_vq(ctx->m2m_ctx);
797
798 mutex_lock(&src_vq->vb_lock);
799 mutex_lock(&dst_vq->vb_lock);
800
801 if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) {
802 if (videobuf_queue_is_busy(src_vq)) {
803 v4l2_err(v4l2_dev, "%s queue busy\n", __func__);
804 ret = -EBUSY;
805 goto s_fmt_out;
806 }
807 frame = &ctx->s_frame;
808 spin_lock_irqsave(&ctx->slock, flags);
809 ctx->state |= FIMC_SRC_FMT;
810 spin_unlock_irqrestore(&ctx->slock, flags);
811
812 } else if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
813 if (videobuf_queue_is_busy(dst_vq)) {
814 v4l2_err(v4l2_dev, "%s queue busy\n", __func__);
815 ret = -EBUSY;
816 goto s_fmt_out;
817 }
818 frame = &ctx->d_frame;
819 spin_lock_irqsave(&ctx->slock, flags);
820 ctx->state |= FIMC_DST_FMT;
821 spin_unlock_irqrestore(&ctx->slock, flags);
822 } else {
823 v4l2_err(&ctx->fimc_dev->m2m.v4l2_dev,
824 "Wrong buffer/video queue type (%d)\n", f->type);
825 return -EINVAL;
826 }
827
828 pix = &f->fmt.pix;
829 frame->fmt = find_format(f);
830 if (!frame->fmt) {
831 ret = -EINVAL;
832 goto s_fmt_out;
833 }
834
835 frame->f_width = pix->bytesperline * 8 / frame->fmt->depth;
836 frame->f_height = pix->sizeimage/pix->bytesperline;
837 frame->width = pix->width;
838 frame->height = pix->height;
839 frame->o_width = pix->width;
840 frame->o_height = pix->height;
841 frame->offs_h = 0;
842 frame->offs_v = 0;
843 frame->size = (pix->width * pix->height * frame->fmt->depth) >> 3;
844 src_vq->field = dst_vq->field = pix->field;
845 spin_lock_irqsave(&ctx->slock, flags);
846 ctx->state |= FIMC_PARAMS;
847 spin_unlock_irqrestore(&ctx->slock, flags);
848
849 dbg("f_width= %d, f_height= %d", frame->f_width, frame->f_height);
850
851s_fmt_out:
852 mutex_unlock(&dst_vq->vb_lock);
853 mutex_unlock(&src_vq->vb_lock);
854 mutex_unlock(&ctx->fimc_dev->lock);
855 return ret;
856}
857
858static int fimc_m2m_reqbufs(struct file *file, void *priv,
859 struct v4l2_requestbuffers *reqbufs)
860{
861 struct fimc_ctx *ctx = priv;
862 return v4l2_m2m_reqbufs(file, ctx->m2m_ctx, reqbufs);
863}
864
865static int fimc_m2m_querybuf(struct file *file, void *priv,
866 struct v4l2_buffer *buf)
867{
868 struct fimc_ctx *ctx = priv;
869 return v4l2_m2m_querybuf(file, ctx->m2m_ctx, buf);
870}
871
872static int fimc_m2m_qbuf(struct file *file, void *priv,
873 struct v4l2_buffer *buf)
874{
875 struct fimc_ctx *ctx = priv;
876
877 return v4l2_m2m_qbuf(file, ctx->m2m_ctx, buf);
878}
879
880static int fimc_m2m_dqbuf(struct file *file, void *priv,
881 struct v4l2_buffer *buf)
882{
883 struct fimc_ctx *ctx = priv;
884 return v4l2_m2m_dqbuf(file, ctx->m2m_ctx, buf);
885}
886
887static int fimc_m2m_streamon(struct file *file, void *priv,
888 enum v4l2_buf_type type)
889{
890 struct fimc_ctx *ctx = priv;
891 return v4l2_m2m_streamon(file, ctx->m2m_ctx, type);
892}
893
894static int fimc_m2m_streamoff(struct file *file, void *priv,
895 enum v4l2_buf_type type)
896{
897 struct fimc_ctx *ctx = priv;
898 return v4l2_m2m_streamoff(file, ctx->m2m_ctx, type);
899}
900
901int fimc_m2m_queryctrl(struct file *file, void *priv,
902 struct v4l2_queryctrl *qc)
903{
904 struct v4l2_queryctrl *c;
905 c = get_ctrl(qc->id);
906 if (!c)
907 return -EINVAL;
908 *qc = *c;
909 return 0;
910}
911
912int fimc_m2m_g_ctrl(struct file *file, void *priv,
913 struct v4l2_control *ctrl)
914{
915 struct fimc_ctx *ctx = priv;
916
917 switch (ctrl->id) {
918 case V4L2_CID_HFLIP:
919 ctrl->value = (FLIP_X_AXIS & ctx->flip) ? 1 : 0;
920 break;
921 case V4L2_CID_VFLIP:
922 ctrl->value = (FLIP_Y_AXIS & ctx->flip) ? 1 : 0;
923 break;
924 case V4L2_CID_ROTATE:
925 ctrl->value = ctx->rotation;
926 break;
927 default:
928 v4l2_err(&ctx->fimc_dev->m2m.v4l2_dev, "Invalid control\n");
929 return -EINVAL;
930 }
931 dbg("ctrl->value= %d", ctrl->value);
932 return 0;
933}
934
935static int check_ctrl_val(struct fimc_ctx *ctx,
936 struct v4l2_control *ctrl)
937{
938 struct v4l2_queryctrl *c;
939 c = get_ctrl(ctrl->id);
940 if (!c)
941 return -EINVAL;
942
943 if (ctrl->value < c->minimum || ctrl->value > c->maximum
944 || (c->step != 0 && ctrl->value % c->step != 0)) {
945 v4l2_err(&ctx->fimc_dev->m2m.v4l2_dev,
946 "Invalid control value\n");
947 return -ERANGE;
948 }
949
950 return 0;
951}
952
953int fimc_m2m_s_ctrl(struct file *file, void *priv,
954 struct v4l2_control *ctrl)
955{
956 struct fimc_ctx *ctx = priv;
957 struct samsung_fimc_variant *variant = ctx->fimc_dev->variant;
958 unsigned long flags;
959 int ret = 0;
960
961 ret = check_ctrl_val(ctx, ctrl);
962 if (ret)
963 return ret;
964
965 switch (ctrl->id) {
966 case V4L2_CID_HFLIP:
967 if (ctx->rotation != 0)
968 return 0;
969 if (ctrl->value)
970 ctx->flip |= FLIP_X_AXIS;
971 else
972 ctx->flip &= ~FLIP_X_AXIS;
973 break;
974
975 case V4L2_CID_VFLIP:
976 if (ctx->rotation != 0)
977 return 0;
978 if (ctrl->value)
979 ctx->flip |= FLIP_Y_AXIS;
980 else
981 ctx->flip &= ~FLIP_Y_AXIS;
982 break;
983
984 case V4L2_CID_ROTATE:
985 if (ctrl->value == 90 || ctrl->value == 270) {
986 if (ctx->out_path == FIMC_LCDFIFO &&
987 !variant->has_inp_rot) {
988 return -EINVAL;
989 } else if (ctx->in_path == FIMC_DMA &&
990 !variant->has_out_rot) {
991 return -EINVAL;
992 }
993 }
994 ctx->rotation = ctrl->value;
995 if (ctrl->value == 180)
996 ctx->flip = FLIP_XY_AXIS;
997 break;
998
999 default:
1000 v4l2_err(&ctx->fimc_dev->m2m.v4l2_dev, "Invalid control\n");
1001 return -EINVAL;
1002 }
1003 spin_lock_irqsave(&ctx->slock, flags);
1004 ctx->state |= FIMC_PARAMS;
1005 spin_unlock_irqrestore(&ctx->slock, flags);
1006 return 0;
1007}
1008
1009
1010static int fimc_m2m_cropcap(struct file *file, void *fh,
1011 struct v4l2_cropcap *cr)
1012{
1013 struct fimc_frame *frame;
1014 struct fimc_ctx *ctx = fh;
1015
1016 frame = ctx_m2m_get_frame(ctx, cr->type);
1017 if (IS_ERR(frame))
1018 return PTR_ERR(frame);
1019
1020 cr->bounds.left = 0;
1021 cr->bounds.top = 0;
1022 cr->bounds.width = frame->f_width;
1023 cr->bounds.height = frame->f_height;
1024 cr->defrect.left = frame->offs_h;
1025 cr->defrect.top = frame->offs_v;
1026 cr->defrect.width = frame->o_width;
1027 cr->defrect.height = frame->o_height;
1028 return 0;
1029}
1030
1031static int fimc_m2m_g_crop(struct file *file, void *fh, struct v4l2_crop *cr)
1032{
1033 struct fimc_frame *frame;
1034 struct fimc_ctx *ctx = file->private_data;
1035
1036 frame = ctx_m2m_get_frame(ctx, cr->type);
1037 if (IS_ERR(frame))
1038 return PTR_ERR(frame);
1039
1040 cr->c.left = frame->offs_h;
1041 cr->c.top = frame->offs_v;
1042 cr->c.width = frame->width;
1043 cr->c.height = frame->height;
1044
1045 return 0;
1046}
1047
1048static int fimc_m2m_s_crop(struct file *file, void *fh, struct v4l2_crop *cr)
1049{
1050 struct fimc_ctx *ctx = file->private_data;
1051 struct fimc_dev *fimc = ctx->fimc_dev;
1052 unsigned long flags;
1053 struct fimc_frame *f;
1054 u32 min_size;
1055 int ret = 0;
1056
1057 if (cr->c.top < 0 || cr->c.left < 0) {
1058 v4l2_err(&fimc->m2m.v4l2_dev,
1059 "doesn't support negative values for top & left\n");
1060 return -EINVAL;
1061 }
1062
1063 if (cr->c.width <= 0 || cr->c.height <= 0) {
1064 v4l2_err(&fimc->m2m.v4l2_dev,
1065 "crop width and height must be greater than 0\n");
1066 return -EINVAL;
1067 }
1068
1069 f = ctx_m2m_get_frame(ctx, cr->type);
1070 if (IS_ERR(f))
1071 return PTR_ERR(f);
1072
1073 /* Adjust to required pixel boundary. */
1074 min_size = (cr->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) ?
1075 fimc->variant->min_inp_pixsize : fimc->variant->min_out_pixsize;
1076
1077 cr->c.width = round_down(cr->c.width, min_size);
1078 cr->c.height = round_down(cr->c.height, min_size);
1079 cr->c.left = round_down(cr->c.left + 1, min_size);
1080 cr->c.top = round_down(cr->c.top + 1, min_size);
1081
1082 if ((cr->c.left + cr->c.width > f->o_width)
1083 || (cr->c.top + cr->c.height > f->o_height)) {
1084 v4l2_err(&fimc->m2m.v4l2_dev, "Error in S_CROP params\n");
1085 return -EINVAL;
1086 }
1087
1088 spin_lock_irqsave(&ctx->slock, flags);
1089 if ((ctx->state & FIMC_SRC_FMT) && (ctx->state & FIMC_DST_FMT)) {
1090 /* Check for the pixel scaling ratio when cropping input img. */
1091 if (cr->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
1092 ret = fimc_check_scaler_ratio(&cr->c, &ctx->d_frame);
1093 else if (cr->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
1094 ret = fimc_check_scaler_ratio(&cr->c, &ctx->s_frame);
1095
1096 if (ret) {
1097 spin_unlock_irqrestore(&ctx->slock, flags);
1098 v4l2_err(&fimc->m2m.v4l2_dev, "Out of scaler range");
1099 return -EINVAL;
1100 }
1101 }
1102 ctx->state |= FIMC_PARAMS;
1103 spin_unlock_irqrestore(&ctx->slock, flags);
1104
1105 f->offs_h = cr->c.left;
1106 f->offs_v = cr->c.top;
1107 f->width = cr->c.width;
1108 f->height = cr->c.height;
1109 return 0;
1110}
1111
1112static const struct v4l2_ioctl_ops fimc_m2m_ioctl_ops = {
1113 .vidioc_querycap = fimc_m2m_querycap,
1114
1115 .vidioc_enum_fmt_vid_cap = fimc_m2m_enum_fmt,
1116 .vidioc_enum_fmt_vid_out = fimc_m2m_enum_fmt,
1117
1118 .vidioc_g_fmt_vid_cap = fimc_m2m_g_fmt,
1119 .vidioc_g_fmt_vid_out = fimc_m2m_g_fmt,
1120
1121 .vidioc_try_fmt_vid_cap = fimc_m2m_try_fmt,
1122 .vidioc_try_fmt_vid_out = fimc_m2m_try_fmt,
1123
1124 .vidioc_s_fmt_vid_cap = fimc_m2m_s_fmt,
1125 .vidioc_s_fmt_vid_out = fimc_m2m_s_fmt,
1126
1127 .vidioc_reqbufs = fimc_m2m_reqbufs,
1128 .vidioc_querybuf = fimc_m2m_querybuf,
1129
1130 .vidioc_qbuf = fimc_m2m_qbuf,
1131 .vidioc_dqbuf = fimc_m2m_dqbuf,
1132
1133 .vidioc_streamon = fimc_m2m_streamon,
1134 .vidioc_streamoff = fimc_m2m_streamoff,
1135
1136 .vidioc_queryctrl = fimc_m2m_queryctrl,
1137 .vidioc_g_ctrl = fimc_m2m_g_ctrl,
1138 .vidioc_s_ctrl = fimc_m2m_s_ctrl,
1139
1140 .vidioc_g_crop = fimc_m2m_g_crop,
1141 .vidioc_s_crop = fimc_m2m_s_crop,
1142 .vidioc_cropcap = fimc_m2m_cropcap
1143
1144};
1145
1146static void queue_init(void *priv, struct videobuf_queue *vq,
1147 enum v4l2_buf_type type)
1148{
1149 struct fimc_ctx *ctx = priv;
1150 struct fimc_dev *fimc = ctx->fimc_dev;
1151
1152 videobuf_queue_dma_contig_init(vq, &fimc_qops,
1153 fimc->m2m.v4l2_dev.dev,
1154 &fimc->irqlock, type, V4L2_FIELD_NONE,
1155 sizeof(struct fimc_vid_buffer), priv);
1156}
1157
1158static int fimc_m2m_open(struct file *file)
1159{
1160 struct fimc_dev *fimc = video_drvdata(file);
1161 struct fimc_ctx *ctx = NULL;
1162 int err = 0;
1163
1164 mutex_lock(&fimc->lock);
1165 fimc->m2m.refcnt++;
1166 set_bit(ST_OUTDMA_RUN, &fimc->state);
1167 mutex_unlock(&fimc->lock);
1168
1169
1170 ctx = kzalloc(sizeof *ctx, GFP_KERNEL);
1171 if (!ctx)
1172 return -ENOMEM;
1173
1174 file->private_data = ctx;
1175 ctx->fimc_dev = fimc;
1176 /* default format */
1177 ctx->s_frame.fmt = &fimc_formats[0];
1178 ctx->d_frame.fmt = &fimc_formats[0];
1179 /* per user process device context initialization */
1180 ctx->state = 0;
1181 ctx->flags = 0;
1182 ctx->effect.type = S5P_FIMC_EFFECT_ORIGINAL;
1183 ctx->in_path = FIMC_DMA;
1184 ctx->out_path = FIMC_DMA;
1185 spin_lock_init(&ctx->slock);
1186
1187 ctx->m2m_ctx = v4l2_m2m_ctx_init(ctx, fimc->m2m.m2m_dev, queue_init);
1188 if (IS_ERR(ctx->m2m_ctx)) {
1189 err = PTR_ERR(ctx->m2m_ctx);
1190 kfree(ctx);
1191 }
1192 return err;
1193}
1194
1195static int fimc_m2m_release(struct file *file)
1196{
1197 struct fimc_ctx *ctx = file->private_data;
1198 struct fimc_dev *fimc = ctx->fimc_dev;
1199
1200 v4l2_m2m_ctx_release(ctx->m2m_ctx);
1201 kfree(ctx);
1202 mutex_lock(&fimc->lock);
1203 if (--fimc->m2m.refcnt <= 0)
1204 clear_bit(ST_OUTDMA_RUN, &fimc->state);
1205 mutex_unlock(&fimc->lock);
1206 return 0;
1207}
1208
1209static unsigned int fimc_m2m_poll(struct file *file,
1210 struct poll_table_struct *wait)
1211{
1212 struct fimc_ctx *ctx = file->private_data;
1213 return v4l2_m2m_poll(file, ctx->m2m_ctx, wait);
1214}
1215
1216
1217static int fimc_m2m_mmap(struct file *file, struct vm_area_struct *vma)
1218{
1219 struct fimc_ctx *ctx = file->private_data;
1220 return v4l2_m2m_mmap(file, ctx->m2m_ctx, vma);
1221}
1222
1223static const struct v4l2_file_operations fimc_m2m_fops = {
1224 .owner = THIS_MODULE,
1225 .open = fimc_m2m_open,
1226 .release = fimc_m2m_release,
1227 .poll = fimc_m2m_poll,
1228 .ioctl = video_ioctl2,
1229 .mmap = fimc_m2m_mmap,
1230};
1231
1232static struct v4l2_m2m_ops m2m_ops = {
1233 .device_run = fimc_dma_run,
1234 .job_abort = fimc_job_abort,
1235};
1236
1237
1238static int fimc_register_m2m_device(struct fimc_dev *fimc)
1239{
1240 struct video_device *vfd;
1241 struct platform_device *pdev;
1242 struct v4l2_device *v4l2_dev;
1243 int ret = 0;
1244
1245 if (!fimc)
1246 return -ENODEV;
1247
1248 pdev = fimc->pdev;
1249 v4l2_dev = &fimc->m2m.v4l2_dev;
1250
1251 /* set name if it is empty */
1252 if (!v4l2_dev->name[0])
1253 snprintf(v4l2_dev->name, sizeof(v4l2_dev->name),
1254 "%s.m2m", dev_name(&pdev->dev));
1255
1256 ret = v4l2_device_register(&pdev->dev, v4l2_dev);
1257 if (ret)
1258 return ret;;
1259
1260 vfd = video_device_alloc();
1261 if (!vfd) {
1262 v4l2_err(v4l2_dev, "Failed to allocate video device\n");
1263 goto err_m2m_r1;
1264 }
1265
1266 vfd->fops = &fimc_m2m_fops;
1267 vfd->ioctl_ops = &fimc_m2m_ioctl_ops;
1268 vfd->minor = -1;
1269 vfd->release = video_device_release;
1270
1271 snprintf(vfd->name, sizeof(vfd->name), "%s:m2m", dev_name(&pdev->dev));
1272
1273 video_set_drvdata(vfd, fimc);
1274 platform_set_drvdata(pdev, fimc);
1275
1276 fimc->m2m.vfd = vfd;
1277 fimc->m2m.m2m_dev = v4l2_m2m_init(&m2m_ops);
1278 if (IS_ERR(fimc->m2m.m2m_dev)) {
1279 v4l2_err(v4l2_dev, "failed to initialize v4l2-m2m device\n");
1280 ret = PTR_ERR(fimc->m2m.m2m_dev);
1281 goto err_m2m_r2;
1282 }
1283
1284 ret = video_register_device(vfd, VFL_TYPE_GRABBER, -1);
1285 if (ret) {
1286 v4l2_err(v4l2_dev,
1287 "%s(): failed to register video device\n", __func__);
1288 goto err_m2m_r3;
1289 }
1290 v4l2_info(v4l2_dev,
1291 "FIMC m2m driver registered as /dev/video%d\n", vfd->num);
1292
1293 return 0;
1294
1295err_m2m_r3:
1296 v4l2_m2m_release(fimc->m2m.m2m_dev);
1297err_m2m_r2:
1298 video_device_release(fimc->m2m.vfd);
1299err_m2m_r1:
1300 v4l2_device_unregister(v4l2_dev);
1301
1302 return ret;
1303}
1304
1305static void fimc_unregister_m2m_device(struct fimc_dev *fimc)
1306{
1307 if (fimc) {
1308 v4l2_m2m_release(fimc->m2m.m2m_dev);
1309 video_unregister_device(fimc->m2m.vfd);
1310 video_device_release(fimc->m2m.vfd);
1311 v4l2_device_unregister(&fimc->m2m.v4l2_dev);
1312 }
1313}
1314
1315static void fimc_clk_release(struct fimc_dev *fimc)
1316{
1317 int i;
1318 for (i = 0; i < NUM_FIMC_CLOCKS; i++) {
1319 if (fimc->clock[i]) {
1320 clk_disable(fimc->clock[i]);
1321 clk_put(fimc->clock[i]);
1322 }
1323 }
1324}
1325
1326static int fimc_clk_get(struct fimc_dev *fimc)
1327{
1328 int i;
1329 for (i = 0; i < NUM_FIMC_CLOCKS; i++) {
1330 fimc->clock[i] = clk_get(&fimc->pdev->dev, fimc_clock_name[i]);
1331 if (IS_ERR(fimc->clock[i])) {
1332 dev_err(&fimc->pdev->dev,
1333 "failed to get fimc clock: %s\n",
1334 fimc_clock_name[i]);
1335 return -ENXIO;
1336 }
1337 clk_enable(fimc->clock[i]);
1338 }
1339 return 0;
1340}
1341
1342static int fimc_probe(struct platform_device *pdev)
1343{
1344 struct fimc_dev *fimc;
1345 struct resource *res;
1346 struct samsung_fimc_driverdata *drv_data;
1347 int ret = 0;
1348
1349 dev_dbg(&pdev->dev, "%s():\n", __func__);
1350
1351 drv_data = (struct samsung_fimc_driverdata *)
1352 platform_get_device_id(pdev)->driver_data;
1353
1354 if (pdev->id >= drv_data->devs_cnt) {
1355 dev_err(&pdev->dev, "Invalid platform device id: %d\n",
1356 pdev->id);
1357 return -EINVAL;
1358 }
1359
1360 fimc = kzalloc(sizeof(struct fimc_dev), GFP_KERNEL);
1361 if (!fimc)
1362 return -ENOMEM;
1363
1364 fimc->id = pdev->id;
1365 fimc->variant = drv_data->variant[fimc->id];
1366 fimc->pdev = pdev;
1367 fimc->state = ST_IDLE;
1368
1369 spin_lock_init(&fimc->irqlock);
1370 spin_lock_init(&fimc->slock);
1371
1372 mutex_init(&fimc->lock);
1373
1374 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1375 if (!res) {
1376 dev_err(&pdev->dev, "failed to find the registers\n");
1377 ret = -ENOENT;
1378 goto err_info;
1379 }
1380
1381 fimc->regs_res = request_mem_region(res->start, resource_size(res),
1382 dev_name(&pdev->dev));
1383 if (!fimc->regs_res) {
1384 dev_err(&pdev->dev, "failed to obtain register region\n");
1385 ret = -ENOENT;
1386 goto err_info;
1387 }
1388
1389 fimc->regs = ioremap(res->start, resource_size(res));
1390 if (!fimc->regs) {
1391 dev_err(&pdev->dev, "failed to map registers\n");
1392 ret = -ENXIO;
1393 goto err_req_region;
1394 }
1395
1396 ret = fimc_clk_get(fimc);
1397 if (ret)
1398 goto err_regs_unmap;
1399
1400 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
1401 if (!res) {
1402 dev_err(&pdev->dev, "failed to get IRQ resource\n");
1403 ret = -ENXIO;
1404 goto err_clk;
1405 }
1406 fimc->irq = res->start;
1407
1408 fimc_hw_reset(fimc);
1409
1410 ret = request_irq(fimc->irq, fimc_isr, 0, pdev->name, fimc);
1411 if (ret) {
1412 dev_err(&pdev->dev, "failed to install irq (%d)\n", ret);
1413 goto err_clk;
1414 }
1415
1416 fimc->work_queue = create_workqueue(dev_name(&fimc->pdev->dev));
1417 if (!fimc->work_queue)
1418 goto err_irq;
1419
1420 ret = fimc_register_m2m_device(fimc);
1421 if (ret)
1422 goto err_wq;
1423
1424 fimc_hw_en_lastirq(fimc, true);
1425
1426 dev_dbg(&pdev->dev, "%s(): fimc-%d registered successfully\n",
1427 __func__, fimc->id);
1428
1429 return 0;
1430
1431err_wq:
1432 destroy_workqueue(fimc->work_queue);
1433err_irq:
1434 free_irq(fimc->irq, fimc);
1435err_clk:
1436 fimc_clk_release(fimc);
1437err_regs_unmap:
1438 iounmap(fimc->regs);
1439err_req_region:
1440 release_resource(fimc->regs_res);
1441 kfree(fimc->regs_res);
1442err_info:
1443 kfree(fimc);
1444 dev_err(&pdev->dev, "failed to install\n");
1445 return ret;
1446}
1447
1448static int __devexit fimc_remove(struct platform_device *pdev)
1449{
1450 struct fimc_dev *fimc =
1451 (struct fimc_dev *)platform_get_drvdata(pdev);
1452
1453 v4l2_info(&fimc->m2m.v4l2_dev, "Removing %s\n", pdev->name);
1454
1455 free_irq(fimc->irq, fimc);
1456
1457 fimc_hw_reset(fimc);
1458
1459 fimc_unregister_m2m_device(fimc);
1460 fimc_clk_release(fimc);
1461 iounmap(fimc->regs);
1462 release_resource(fimc->regs_res);
1463 kfree(fimc->regs_res);
1464 kfree(fimc);
1465 return 0;
1466}
1467
1468static struct samsung_fimc_variant fimc01_variant_s5p = {
1469 .has_inp_rot = 1,
1470 .has_out_rot = 1,
1471 .min_inp_pixsize = 16,
1472 .min_out_pixsize = 16,
1473
1474 .scaler_en_w = 3264,
1475 .scaler_dis_w = 8192,
1476 .in_rot_en_h = 1920,
1477 .in_rot_dis_w = 8192,
1478 .out_rot_en_w = 1920,
1479 .out_rot_dis_w = 4224,
1480};
1481
1482static struct samsung_fimc_variant fimc2_variant_s5p = {
1483 .min_inp_pixsize = 16,
1484 .min_out_pixsize = 16,
1485
1486 .scaler_en_w = 4224,
1487 .scaler_dis_w = 8192,
1488 .in_rot_en_h = 1920,
1489 .in_rot_dis_w = 8192,
1490 .out_rot_en_w = 1920,
1491 .out_rot_dis_w = 4224,
1492};
1493
1494static struct samsung_fimc_variant fimc01_variant_s5pv210 = {
1495 .has_inp_rot = 1,
1496 .has_out_rot = 1,
1497 .min_inp_pixsize = 16,
1498 .min_out_pixsize = 32,
1499
1500 .scaler_en_w = 4224,
1501 .scaler_dis_w = 8192,
1502 .in_rot_en_h = 1920,
1503 .in_rot_dis_w = 8192,
1504 .out_rot_en_w = 1920,
1505 .out_rot_dis_w = 4224,
1506};
1507
1508static struct samsung_fimc_variant fimc2_variant_s5pv210 = {
1509 .min_inp_pixsize = 16,
1510 .min_out_pixsize = 32,
1511
1512 .scaler_en_w = 1920,
1513 .scaler_dis_w = 8192,
1514 .in_rot_en_h = 1280,
1515 .in_rot_dis_w = 8192,
1516 .out_rot_en_w = 1280,
1517 .out_rot_dis_w = 1920,
1518};
1519
1520static struct samsung_fimc_driverdata fimc_drvdata_s5p = {
1521 .variant = {
1522 [0] = &fimc01_variant_s5p,
1523 [1] = &fimc01_variant_s5p,
1524 [2] = &fimc2_variant_s5p,
1525 },
1526 .devs_cnt = 3
1527};
1528
1529static struct samsung_fimc_driverdata fimc_drvdata_s5pv210 = {
1530 .variant = {
1531 [0] = &fimc01_variant_s5pv210,
1532 [1] = &fimc01_variant_s5pv210,
1533 [2] = &fimc2_variant_s5pv210,
1534 },
1535 .devs_cnt = 3
1536};
1537
1538static struct platform_device_id fimc_driver_ids[] = {
1539 {
1540 .name = "s5p-fimc",
1541 .driver_data = (unsigned long)&fimc_drvdata_s5p,
1542 }, {
1543 .name = "s5pv210-fimc",
1544 .driver_data = (unsigned long)&fimc_drvdata_s5pv210,
1545 },
1546 {},
1547};
1548MODULE_DEVICE_TABLE(platform, fimc_driver_ids);
1549
1550static struct platform_driver fimc_driver = {
1551 .probe = fimc_probe,
1552 .remove = __devexit_p(fimc_remove),
1553 .id_table = fimc_driver_ids,
1554 .driver = {
1555 .name = MODULE_NAME,
1556 .owner = THIS_MODULE,
1557 }
1558};
1559
1560static char banner[] __initdata = KERN_INFO
1561 "S5PC Camera Interface V4L2 Driver, (c) 2010 Samsung Electronics\n";
1562
1563static int __init fimc_init(void)
1564{
1565 u32 ret;
1566 printk(banner);
1567
1568 ret = platform_driver_register(&fimc_driver);
1569 if (ret) {
1570 printk(KERN_ERR "FIMC platform driver register failed\n");
1571 return -1;
1572 }
1573 return 0;
1574}
1575
1576static void __exit fimc_exit(void)
1577{
1578 platform_driver_unregister(&fimc_driver);
1579}
1580
1581module_init(fimc_init);
1582module_exit(fimc_exit);
1583
1584MODULE_AUTHOR("Sylwester Nawrocki, s.nawrocki@samsung.com");
1585MODULE_DESCRIPTION("S3C/S5P FIMC (video postprocessor) driver");
1586MODULE_LICENSE("GPL");
diff --git a/drivers/media/video/s5p-fimc/fimc-core.h b/drivers/media/video/s5p-fimc/fimc-core.h
new file mode 100644
index 000000000000..6b3e0cd73cdd
--- /dev/null
+++ b/drivers/media/video/s5p-fimc/fimc-core.h
@@ -0,0 +1,471 @@
1/*
2 * Copyright (c) 2010 Samsung Electronics
3 *
4 * Sylwester Nawrocki, <s.nawrocki@samsung.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 version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#ifndef FIMC_CORE_H_
12#define FIMC_CORE_H_
13
14#include <linux/types.h>
15#include <media/videobuf-core.h>
16#include <media/v4l2-device.h>
17#include <media/v4l2-mem2mem.h>
18#include <linux/videodev2.h>
19#include "regs-fimc.h"
20
21#define err(fmt, args...) \
22 printk(KERN_ERR "%s:%d: " fmt "\n", __func__, __LINE__, ##args)
23
24#ifdef DEBUG
25#define dbg(fmt, args...) \
26 printk(KERN_DEBUG "%s:%d: " fmt "\n", __func__, __LINE__, ##args)
27#else
28#define dbg(fmt, args...)
29#endif
30
31#define NUM_FIMC_CLOCKS 2
32#define MODULE_NAME "s5p-fimc"
33#define FIMC_MAX_DEVS 3
34#define FIMC_MAX_OUT_BUFS 4
35#define SCALER_MAX_HRATIO 64
36#define SCALER_MAX_VRATIO 64
37
38enum {
39 ST_IDLE,
40 ST_OUTDMA_RUN,
41 ST_M2M_PEND,
42};
43
44#define fimc_m2m_active(dev) test_bit(ST_OUTDMA_RUN, &(dev)->state)
45#define fimc_m2m_pending(dev) test_bit(ST_M2M_PEND, &(dev)->state)
46
47enum fimc_datapath {
48 FIMC_ITU_CAM_A,
49 FIMC_ITU_CAM_B,
50 FIMC_MIPI_CAM,
51 FIMC_DMA,
52 FIMC_LCDFIFO,
53 FIMC_WRITEBACK
54};
55
56enum fimc_color_fmt {
57 S5P_FIMC_RGB565,
58 S5P_FIMC_RGB666,
59 S5P_FIMC_RGB888,
60 S5P_FIMC_YCBCR420,
61 S5P_FIMC_YCBCR422,
62 S5P_FIMC_YCBYCR422,
63 S5P_FIMC_YCRYCB422,
64 S5P_FIMC_CBYCRY422,
65 S5P_FIMC_CRYCBY422,
66 S5P_FIMC_RGB30_LOCAL,
67 S5P_FIMC_YCBCR444_LOCAL,
68 S5P_FIMC_MAX_COLOR = S5P_FIMC_YCBCR444_LOCAL,
69 S5P_FIMC_COLOR_MASK = 0x0F,
70};
71
72/* Y/Cb/Cr components order at DMA output for 1 plane YCbCr 4:2:2 formats. */
73#define S5P_FIMC_OUT_CRYCBY S5P_CIOCTRL_ORDER422_CRYCBY
74#define S5P_FIMC_OUT_CBYCRY S5P_CIOCTRL_ORDER422_YCRYCB
75#define S5P_FIMC_OUT_YCRYCB S5P_CIOCTRL_ORDER422_CBYCRY
76#define S5P_FIMC_OUT_YCBYCR S5P_CIOCTRL_ORDER422_YCBYCR
77
78/* Input Y/Cb/Cr components order for 1 plane YCbCr 4:2:2 color formats. */
79#define S5P_FIMC_IN_CRYCBY S5P_MSCTRL_ORDER422_CRYCBY
80#define S5P_FIMC_IN_CBYCRY S5P_MSCTRL_ORDER422_YCRYCB
81#define S5P_FIMC_IN_YCRYCB S5P_MSCTRL_ORDER422_CBYCRY
82#define S5P_FIMC_IN_YCBYCR S5P_MSCTRL_ORDER422_YCBYCR
83
84/* Cb/Cr chrominance components order for 2 plane Y/CbCr 4:2:2 formats. */
85#define S5P_FIMC_LSB_CRCB S5P_CIOCTRL_ORDER422_2P_LSB_CRCB
86
87/* The embedded image effect selection */
88#define S5P_FIMC_EFFECT_ORIGINAL S5P_CIIMGEFF_FIN_BYPASS
89#define S5P_FIMC_EFFECT_ARBITRARY S5P_CIIMGEFF_FIN_ARBITRARY
90#define S5P_FIMC_EFFECT_NEGATIVE S5P_CIIMGEFF_FIN_NEGATIVE
91#define S5P_FIMC_EFFECT_ARTFREEZE S5P_CIIMGEFF_FIN_ARTFREEZE
92#define S5P_FIMC_EFFECT_EMBOSSING S5P_CIIMGEFF_FIN_EMBOSSING
93#define S5P_FIMC_EFFECT_SIKHOUETTE S5P_CIIMGEFF_FIN_SILHOUETTE
94
95/* The hardware context state. */
96#define FIMC_PARAMS (1 << 0)
97#define FIMC_SRC_ADDR (1 << 1)
98#define FIMC_DST_ADDR (1 << 2)
99#define FIMC_SRC_FMT (1 << 3)
100#define FIMC_DST_FMT (1 << 4)
101
102/* Image conversion flags */
103#define FIMC_IN_DMA_ACCESS_TILED (1 << 0)
104#define FIMC_IN_DMA_ACCESS_LINEAR (0 << 0)
105#define FIMC_OUT_DMA_ACCESS_TILED (1 << 1)
106#define FIMC_OUT_DMA_ACCESS_LINEAR (0 << 1)
107#define FIMC_SCAN_MODE_PROGRESSIVE (0 << 2)
108#define FIMC_SCAN_MODE_INTERLACED (1 << 2)
109/* YCbCr data dynamic range for RGB-YUV color conversion. Y/Cb/Cr: (0 ~ 255) */
110#define FIMC_COLOR_RANGE_WIDE (0 << 3)
111/* Y (16 ~ 235), Cb/Cr (16 ~ 240) */
112#define FIMC_COLOR_RANGE_NARROW (1 << 3)
113
114#define FLIP_NONE 0
115#define FLIP_X_AXIS 1
116#define FLIP_Y_AXIS 2
117#define FLIP_XY_AXIS (FLIP_X_AXIS | FLIP_Y_AXIS)
118
119/**
120 * struct fimc_fmt - the driver's internal color format data
121 * @name: format description
122 * @fourcc: the fourcc code for this format
123 * @color: the corresponding fimc_color_fmt
124 * @depth: number of bits per pixel
125 * @buff_cnt: number of physically non-contiguous data planes
126 * @planes_cnt: number of physically contiguous data planes
127 */
128struct fimc_fmt {
129 char *name;
130 u32 fourcc;
131 u32 color;
132 u32 depth;
133 u16 buff_cnt;
134 u16 planes_cnt;
135};
136
137/**
138 * struct fimc_dma_offset - pixel offset information for DMA
139 * @y_h: y value horizontal offset
140 * @y_v: y value vertical offset
141 * @cb_h: cb value horizontal offset
142 * @cb_v: cb value vertical offset
143 * @cr_h: cr value horizontal offset
144 * @cr_v: cr value vertical offset
145 */
146struct fimc_dma_offset {
147 int y_h;
148 int y_v;
149 int cb_h;
150 int cb_v;
151 int cr_h;
152 int cr_v;
153};
154
155/**
156 * struct fimc_effect - the configuration data for the "Arbitrary" image effect
157 * @type: effect type
158 * @pat_cb: cr value when type is "arbitrary"
159 * @pat_cr: cr value when type is "arbitrary"
160 */
161struct fimc_effect {
162 u32 type;
163 u8 pat_cb;
164 u8 pat_cr;
165};
166
167/**
168 * struct fimc_scaler - the configuration data for FIMC inetrnal scaler
169 *
170 * @enabled: the flag set when the scaler is used
171 * @hfactor: horizontal shift factor
172 * @vfactor: vertical shift factor
173 * @pre_hratio: horizontal ratio of the prescaler
174 * @pre_vratio: vertical ratio of the prescaler
175 * @pre_dst_width: the prescaler's destination width
176 * @pre_dst_height: the prescaler's destination height
177 * @scaleup_h: flag indicating scaling up horizontally
178 * @scaleup_v: flag indicating scaling up vertically
179 * @main_hratio: the main scaler's horizontal ratio
180 * @main_vratio: the main scaler's vertical ratio
181 * @real_width: source width - offset
182 * @real_height: source height - offset
183 * @copy_mode: flag set if one-to-one mode is used, i.e. no scaling
184 * and color format conversion
185 */
186struct fimc_scaler {
187 u32 enabled;
188 u32 hfactor;
189 u32 vfactor;
190 u32 pre_hratio;
191 u32 pre_vratio;
192 u32 pre_dst_width;
193 u32 pre_dst_height;
194 u32 scaleup_h;
195 u32 scaleup_v;
196 u32 main_hratio;
197 u32 main_vratio;
198 u32 real_width;
199 u32 real_height;
200 u32 copy_mode;
201};
202
203/**
204 * struct fimc_addr - the FIMC physical address set for DMA
205 *
206 * @y: luminance plane physical address
207 * @cb: Cb plane physical address
208 * @cr: Cr plane physical address
209 */
210struct fimc_addr {
211 u32 y;
212 u32 cb;
213 u32 cr;
214};
215
216/**
217 * struct fimc_vid_buffer - the driver's video buffer
218 * @vb: v4l videobuf buffer
219 */
220struct fimc_vid_buffer {
221 struct videobuf_buffer vb;
222};
223
224/**
225 * struct fimc_frame - input/output frame format properties
226 *
227 * @f_width: image full width (virtual screen size)
228 * @f_height: image full height (virtual screen size)
229 * @o_width: original image width as set by S_FMT
230 * @o_height: original image height as set by S_FMT
231 * @offs_h: image horizontal pixel offset
232 * @offs_v: image vertical pixel offset
233 * @width: image pixel width
234 * @height: image pixel weight
235 * @paddr: image frame buffer physical addresses
236 * @buf_cnt: number of buffers depending on a color format
237 * @size: image size in bytes
238 * @color: color format
239 * @dma_offset: DMA offset in bytes
240 */
241struct fimc_frame {
242 u32 f_width;
243 u32 f_height;
244 u32 o_width;
245 u32 o_height;
246 u32 offs_h;
247 u32 offs_v;
248 u32 width;
249 u32 height;
250 u32 size;
251 struct fimc_addr paddr;
252 struct fimc_dma_offset dma_offset;
253 struct fimc_fmt *fmt;
254};
255
256/**
257 * struct fimc_m2m_device - v4l2 memory-to-memory device data
258 * @vfd: the video device node for v4l2 m2m mode
259 * @v4l2_dev: v4l2 device for m2m mode
260 * @m2m_dev: v4l2 memory-to-memory device data
261 * @ctx: hardware context data
262 * @refcnt: the reference counter
263 */
264struct fimc_m2m_device {
265 struct video_device *vfd;
266 struct v4l2_device v4l2_dev;
267 struct v4l2_m2m_dev *m2m_dev;
268 struct fimc_ctx *ctx;
269 int refcnt;
270};
271
272/**
273 * struct samsung_fimc_variant - camera interface variant information
274 *
275 * @pix_hoff: indicate whether horizontal offset is in pixels or in bytes
276 * @has_inp_rot: set if has input rotator
277 * @has_out_rot: set if has output rotator
278 * @min_inp_pixsize: minimum input pixel size
279 * @min_out_pixsize: minimum output pixel size
280 * @scaler_en_w: maximum input pixel width when the scaler is enabled
281 * @scaler_dis_w: maximum input pixel width when the scaler is disabled
282 * @in_rot_en_h: maximum input width when the input rotator is used
283 * @in_rot_dis_w: maximum input width when the input rotator is used
284 * @out_rot_en_w: maximum output width for the output rotator enabled
285 * @out_rot_dis_w: maximum output width for the output rotator enabled
286 */
287struct samsung_fimc_variant {
288 unsigned int pix_hoff:1;
289 unsigned int has_inp_rot:1;
290 unsigned int has_out_rot:1;
291
292 u16 min_inp_pixsize;
293 u16 min_out_pixsize;
294 u16 scaler_en_w;
295 u16 scaler_dis_w;
296 u16 in_rot_en_h;
297 u16 in_rot_dis_w;
298 u16 out_rot_en_w;
299 u16 out_rot_dis_w;
300};
301
302/**
303 * struct samsung_fimc_driverdata - per-device type driver data for init time.
304 *
305 * @variant: the variant information for this driver.
306 * @dev_cnt: number of fimc sub-devices available in SoC
307 */
308struct samsung_fimc_driverdata {
309 struct samsung_fimc_variant *variant[FIMC_MAX_DEVS];
310 int devs_cnt;
311};
312
313struct fimc_ctx;
314
315/**
316 * struct fimc_subdev - abstraction for a FIMC entity
317 *
318 * @slock: the spinlock protecting this data structure
319 * @lock: the mutex protecting this data structure
320 * @pdev: pointer to the FIMC platform device
321 * @id: FIMC device index (0..2)
322 * @clock[]: the clocks required for FIMC operation
323 * @regs: the mapped hardware registers
324 * @regs_res: the resource claimed for IO registers
325 * @irq: interrupt number of the FIMC subdevice
326 * @irqlock: spinlock protecting videbuffer queue
327 * @m2m: memory-to-memory V4L2 device information
328 * @state: the FIMC device state flags
329 */
330struct fimc_dev {
331 spinlock_t slock;
332 struct mutex lock;
333 struct platform_device *pdev;
334 struct samsung_fimc_variant *variant;
335 int id;
336 struct clk *clock[NUM_FIMC_CLOCKS];
337 void __iomem *regs;
338 struct resource *regs_res;
339 int irq;
340 spinlock_t irqlock;
341 struct workqueue_struct *work_queue;
342 struct fimc_m2m_device m2m;
343 unsigned long state;
344};
345
346/**
347 * fimc_ctx - the device context data
348 *
349 * @lock: mutex protecting this data structure
350 * @s_frame: source frame properties
351 * @d_frame: destination frame properties
352 * @out_order_1p: output 1-plane YCBCR order
353 * @out_order_2p: output 2-plane YCBCR order
354 * @in_order_1p input 1-plane YCBCR order
355 * @in_order_2p: input 2-plane YCBCR order
356 * @in_path: input mode (DMA or camera)
357 * @out_path: output mode (DMA or FIFO)
358 * @scaler: image scaler properties
359 * @effect: image effect
360 * @rotation: image clockwise rotation in degrees
361 * @flip: image flip mode
362 * @flags: an additional flags for image conversion
363 * @state: flags to keep track of user configuration
364 * @fimc_dev: the FIMC device this context applies to
365 * @m2m_ctx: memory-to-memory device context
366 */
367struct fimc_ctx {
368 spinlock_t slock;
369 struct fimc_frame s_frame;
370 struct fimc_frame d_frame;
371 u32 out_order_1p;
372 u32 out_order_2p;
373 u32 in_order_1p;
374 u32 in_order_2p;
375 enum fimc_datapath in_path;
376 enum fimc_datapath out_path;
377 struct fimc_scaler scaler;
378 struct fimc_effect effect;
379 int rotation;
380 u32 flip;
381 u32 flags;
382 u32 state;
383 struct fimc_dev *fimc_dev;
384 struct v4l2_m2m_ctx *m2m_ctx;
385};
386
387
388static inline int tiled_fmt(struct fimc_fmt *fmt)
389{
390 return 0;
391}
392
393static inline void fimc_hw_clear_irq(struct fimc_dev *dev)
394{
395 u32 cfg = readl(dev->regs + S5P_CIGCTRL);
396 cfg |= S5P_CIGCTRL_IRQ_CLR;
397 writel(cfg, dev->regs + S5P_CIGCTRL);
398}
399
400static inline void fimc_hw_start_scaler(struct fimc_dev *dev)
401{
402 u32 cfg = readl(dev->regs + S5P_CISCCTRL);
403 cfg |= S5P_CISCCTRL_SCALERSTART;
404 writel(cfg, dev->regs + S5P_CISCCTRL);
405}
406
407static inline void fimc_hw_stop_scaler(struct fimc_dev *dev)
408{
409 u32 cfg = readl(dev->regs + S5P_CISCCTRL);
410 cfg &= ~S5P_CISCCTRL_SCALERSTART;
411 writel(cfg, dev->regs + S5P_CISCCTRL);
412}
413
414static inline void fimc_hw_dis_capture(struct fimc_dev *dev)
415{
416 u32 cfg = readl(dev->regs + S5P_CIIMGCPT);
417 cfg &= ~(S5P_CIIMGCPT_IMGCPTEN | S5P_CIIMGCPT_IMGCPTEN_SC);
418 writel(cfg, dev->regs + S5P_CIIMGCPT);
419}
420
421static inline void fimc_hw_start_in_dma(struct fimc_dev *dev)
422{
423 u32 cfg = readl(dev->regs + S5P_MSCTRL);
424 cfg |= S5P_MSCTRL_ENVID;
425 writel(cfg, dev->regs + S5P_MSCTRL);
426}
427
428static inline void fimc_hw_stop_in_dma(struct fimc_dev *dev)
429{
430 u32 cfg = readl(dev->regs + S5P_MSCTRL);
431 cfg &= ~S5P_MSCTRL_ENVID;
432 writel(cfg, dev->regs + S5P_MSCTRL);
433}
434
435static inline struct fimc_frame *ctx_m2m_get_frame(struct fimc_ctx *ctx,
436 enum v4l2_buf_type type)
437{
438 struct fimc_frame *frame;
439
440 if (V4L2_BUF_TYPE_VIDEO_OUTPUT == type) {
441 frame = &ctx->s_frame;
442 } else if (V4L2_BUF_TYPE_VIDEO_CAPTURE == type) {
443 frame = &ctx->d_frame;
444 } else {
445 v4l2_err(&ctx->fimc_dev->m2m.v4l2_dev,
446 "Wrong buffer/video queue type (%d)\n", type);
447 return ERR_PTR(-EINVAL);
448 }
449
450 return frame;
451}
452
453/* -----------------------------------------------------*/
454/* fimc-reg.c */
455void fimc_hw_reset(struct fimc_dev *dev);
456void fimc_hw_set_rotation(struct fimc_ctx *ctx);
457void fimc_hw_set_target_format(struct fimc_ctx *ctx);
458void fimc_hw_set_out_dma(struct fimc_ctx *ctx);
459void fimc_hw_en_lastirq(struct fimc_dev *dev, int enable);
460void fimc_hw_en_irq(struct fimc_dev *dev, int enable);
461void fimc_hw_set_prescaler(struct fimc_ctx *ctx);
462void fimc_hw_set_scaler(struct fimc_ctx *ctx);
463void fimc_hw_en_capture(struct fimc_ctx *ctx);
464void fimc_hw_set_effect(struct fimc_ctx *ctx);
465void fimc_hw_set_in_dma(struct fimc_ctx *ctx);
466void fimc_hw_set_input_path(struct fimc_ctx *ctx);
467void fimc_hw_set_output_path(struct fimc_ctx *ctx);
468void fimc_hw_set_input_addr(struct fimc_dev *dev, struct fimc_addr *paddr);
469void fimc_hw_set_output_addr(struct fimc_dev *dev, struct fimc_addr *paddr);
470
471#endif /* FIMC_CORE_H_ */
diff --git a/drivers/media/video/s5p-fimc/fimc-reg.c b/drivers/media/video/s5p-fimc/fimc-reg.c
new file mode 100644
index 000000000000..5570f1ce0c9c
--- /dev/null
+++ b/drivers/media/video/s5p-fimc/fimc-reg.c
@@ -0,0 +1,527 @@
1/*
2 * Register interface file for Samsung Camera Interface (FIMC) driver
3 *
4 * Copyright (c) 2010 Samsung Electronics
5 *
6 * Sylwester Nawrocki, s.nawrocki@samsung.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 version 2 as
10 * published by the Free Software Foundation.
11*/
12
13#include <linux/io.h>
14#include <linux/delay.h>
15#include <mach/map.h>
16
17#include "fimc-core.h"
18
19
20void fimc_hw_reset(struct fimc_dev *dev)
21{
22 u32 cfg;
23
24 cfg = readl(dev->regs + S5P_CISRCFMT);
25 cfg |= S5P_CISRCFMT_ITU601_8BIT;
26 writel(cfg, dev->regs + S5P_CISRCFMT);
27
28 /* Software reset. */
29 cfg = readl(dev->regs + S5P_CIGCTRL);
30 cfg |= (S5P_CIGCTRL_SWRST | S5P_CIGCTRL_IRQ_LEVEL);
31 writel(cfg, dev->regs + S5P_CIGCTRL);
32 msleep(1);
33
34 cfg = readl(dev->regs + S5P_CIGCTRL);
35 cfg &= ~S5P_CIGCTRL_SWRST;
36 writel(cfg, dev->regs + S5P_CIGCTRL);
37
38}
39
40void fimc_hw_set_rotation(struct fimc_ctx *ctx)
41{
42 u32 cfg, flip;
43 struct fimc_dev *dev = ctx->fimc_dev;
44
45 cfg = readl(dev->regs + S5P_CITRGFMT);
46 cfg &= ~(S5P_CITRGFMT_INROT90 | S5P_CITRGFMT_OUTROT90);
47
48 flip = readl(dev->regs + S5P_MSCTRL);
49 flip &= ~S5P_MSCTRL_FLIP_MASK;
50
51 /*
52 * The input and output rotator cannot work simultaneously.
53 * Use the output rotator in output DMA mode or the input rotator
54 * in direct fifo output mode.
55 */
56 if (ctx->rotation == 90 || ctx->rotation == 270) {
57 if (ctx->out_path == FIMC_LCDFIFO) {
58 cfg |= S5P_CITRGFMT_INROT90;
59 if (ctx->rotation == 270)
60 flip |= S5P_MSCTRL_FLIP_180;
61 } else {
62 cfg |= S5P_CITRGFMT_OUTROT90;
63 if (ctx->rotation == 270)
64 cfg |= S5P_CITRGFMT_FLIP_180;
65 }
66 } else if (ctx->rotation == 180) {
67 if (ctx->out_path == FIMC_LCDFIFO)
68 flip |= S5P_MSCTRL_FLIP_180;
69 else
70 cfg |= S5P_CITRGFMT_FLIP_180;
71 }
72 if (ctx->rotation == 180 || ctx->rotation == 270)
73 writel(flip, dev->regs + S5P_MSCTRL);
74 writel(cfg, dev->regs + S5P_CITRGFMT);
75}
76
77static u32 fimc_hw_get_in_flip(u32 ctx_flip)
78{
79 u32 flip = S5P_MSCTRL_FLIP_NORMAL;
80
81 switch (ctx_flip) {
82 case FLIP_X_AXIS:
83 flip = S5P_MSCTRL_FLIP_X_MIRROR;
84 break;
85 case FLIP_Y_AXIS:
86 flip = S5P_MSCTRL_FLIP_Y_MIRROR;
87 break;
88 case FLIP_XY_AXIS:
89 flip = S5P_MSCTRL_FLIP_180;
90 break;
91 }
92
93 return flip;
94}
95
96static u32 fimc_hw_get_target_flip(u32 ctx_flip)
97{
98 u32 flip = S5P_CITRGFMT_FLIP_NORMAL;
99
100 switch (ctx_flip) {
101 case FLIP_X_AXIS:
102 flip = S5P_CITRGFMT_FLIP_X_MIRROR;
103 break;
104 case FLIP_Y_AXIS:
105 flip = S5P_CITRGFMT_FLIP_Y_MIRROR;
106 break;
107 case FLIP_XY_AXIS:
108 flip = S5P_CITRGFMT_FLIP_180;
109 break;
110 case FLIP_NONE:
111 break;
112
113 }
114 return flip;
115}
116
117void fimc_hw_set_target_format(struct fimc_ctx *ctx)
118{
119 u32 cfg;
120 struct fimc_dev *dev = ctx->fimc_dev;
121 struct fimc_frame *frame = &ctx->d_frame;
122
123 dbg("w= %d, h= %d color: %d", frame->width,
124 frame->height, frame->fmt->color);
125
126 cfg = readl(dev->regs + S5P_CITRGFMT);
127 cfg &= ~(S5P_CITRGFMT_FMT_MASK | S5P_CITRGFMT_HSIZE_MASK |
128 S5P_CITRGFMT_VSIZE_MASK);
129
130 switch (frame->fmt->color) {
131 case S5P_FIMC_RGB565:
132 case S5P_FIMC_RGB666:
133 case S5P_FIMC_RGB888:
134 cfg |= S5P_CITRGFMT_RGB;
135 break;
136 case S5P_FIMC_YCBCR420:
137 cfg |= S5P_CITRGFMT_YCBCR420;
138 break;
139 case S5P_FIMC_YCBYCR422:
140 case S5P_FIMC_YCRYCB422:
141 case S5P_FIMC_CBYCRY422:
142 case S5P_FIMC_CRYCBY422:
143 if (frame->fmt->planes_cnt == 1)
144 cfg |= S5P_CITRGFMT_YCBCR422_1P;
145 else
146 cfg |= S5P_CITRGFMT_YCBCR422;
147 break;
148 default:
149 break;
150 }
151
152 cfg |= S5P_CITRGFMT_HSIZE(frame->width);
153 cfg |= S5P_CITRGFMT_VSIZE(frame->height);
154
155 if (ctx->rotation == 0) {
156 cfg &= ~S5P_CITRGFMT_FLIP_MASK;
157 cfg |= fimc_hw_get_target_flip(ctx->flip);
158 }
159 writel(cfg, dev->regs + S5P_CITRGFMT);
160
161 cfg = readl(dev->regs + S5P_CITAREA) & ~S5P_CITAREA_MASK;
162 cfg |= (frame->width * frame->height);
163 writel(cfg, dev->regs + S5P_CITAREA);
164}
165
166static void fimc_hw_set_out_dma_size(struct fimc_ctx *ctx)
167{
168 struct fimc_dev *dev = ctx->fimc_dev;
169 struct fimc_frame *frame = &ctx->d_frame;
170 u32 cfg = 0;
171
172 if (ctx->rotation == 90 || ctx->rotation == 270) {
173 cfg |= S5P_ORIG_SIZE_HOR(frame->f_height);
174 cfg |= S5P_ORIG_SIZE_VER(frame->f_width);
175 } else {
176 cfg |= S5P_ORIG_SIZE_HOR(frame->f_width);
177 cfg |= S5P_ORIG_SIZE_VER(frame->f_height);
178 }
179 writel(cfg, dev->regs + S5P_ORGOSIZE);
180}
181
182void fimc_hw_set_out_dma(struct fimc_ctx *ctx)
183{
184 u32 cfg;
185 struct fimc_dev *dev = ctx->fimc_dev;
186 struct fimc_frame *frame = &ctx->d_frame;
187 struct fimc_dma_offset *offset = &frame->dma_offset;
188
189 /* Set the input dma offsets. */
190 cfg = 0;
191 cfg |= S5P_CIO_OFFS_HOR(offset->y_h);
192 cfg |= S5P_CIO_OFFS_VER(offset->y_v);
193 writel(cfg, dev->regs + S5P_CIOYOFF);
194
195 cfg = 0;
196 cfg |= S5P_CIO_OFFS_HOR(offset->cb_h);
197 cfg |= S5P_CIO_OFFS_VER(offset->cb_v);
198 writel(cfg, dev->regs + S5P_CIOCBOFF);
199
200 cfg = 0;
201 cfg |= S5P_CIO_OFFS_HOR(offset->cr_h);
202 cfg |= S5P_CIO_OFFS_VER(offset->cr_v);
203 writel(cfg, dev->regs + S5P_CIOCROFF);
204
205 fimc_hw_set_out_dma_size(ctx);
206
207 /* Configure chroma components order. */
208 cfg = readl(dev->regs + S5P_CIOCTRL);
209
210 cfg &= ~(S5P_CIOCTRL_ORDER2P_MASK | S5P_CIOCTRL_ORDER422_MASK |
211 S5P_CIOCTRL_YCBCR_PLANE_MASK);
212
213 if (frame->fmt->planes_cnt == 1)
214 cfg |= ctx->out_order_1p;
215 else if (frame->fmt->planes_cnt == 2)
216 cfg |= ctx->out_order_2p | S5P_CIOCTRL_YCBCR_2PLANE;
217 else if (frame->fmt->planes_cnt == 3)
218 cfg |= S5P_CIOCTRL_YCBCR_3PLANE;
219
220 writel(cfg, dev->regs + S5P_CIOCTRL);
221}
222
223static void fimc_hw_en_autoload(struct fimc_dev *dev, int enable)
224{
225 u32 cfg = readl(dev->regs + S5P_ORGISIZE);
226 if (enable)
227 cfg |= S5P_CIREAL_ISIZE_AUTOLOAD_EN;
228 else
229 cfg &= ~S5P_CIREAL_ISIZE_AUTOLOAD_EN;
230 writel(cfg, dev->regs + S5P_ORGISIZE);
231}
232
233void fimc_hw_en_lastirq(struct fimc_dev *dev, int enable)
234{
235 unsigned long flags;
236 u32 cfg;
237
238 spin_lock_irqsave(&dev->slock, flags);
239
240 cfg = readl(dev->regs + S5P_CIOCTRL);
241 if (enable)
242 cfg |= S5P_CIOCTRL_LASTIRQ_ENABLE;
243 else
244 cfg &= ~S5P_CIOCTRL_LASTIRQ_ENABLE;
245 writel(cfg, dev->regs + S5P_CIOCTRL);
246
247 spin_unlock_irqrestore(&dev->slock, flags);
248}
249
250void fimc_hw_set_prescaler(struct fimc_ctx *ctx)
251{
252 struct fimc_dev *dev = ctx->fimc_dev;
253 struct fimc_scaler *sc = &ctx->scaler;
254 u32 cfg = 0, shfactor;
255
256 shfactor = 10 - (sc->hfactor + sc->vfactor);
257
258 cfg |= S5P_CISCPRERATIO_SHFACTOR(shfactor);
259 cfg |= S5P_CISCPRERATIO_HOR(sc->pre_hratio);
260 cfg |= S5P_CISCPRERATIO_VER(sc->pre_vratio);
261 writel(cfg, dev->regs + S5P_CISCPRERATIO);
262
263 cfg = 0;
264 cfg |= S5P_CISCPREDST_WIDTH(sc->pre_dst_width);
265 cfg |= S5P_CISCPREDST_HEIGHT(sc->pre_dst_height);
266 writel(cfg, dev->regs + S5P_CISCPREDST);
267}
268
269void fimc_hw_set_scaler(struct fimc_ctx *ctx)
270{
271 struct fimc_dev *dev = ctx->fimc_dev;
272 struct fimc_scaler *sc = &ctx->scaler;
273 struct fimc_frame *src_frame = &ctx->s_frame;
274 struct fimc_frame *dst_frame = &ctx->d_frame;
275 u32 cfg = 0;
276
277 if (!(ctx->flags & FIMC_COLOR_RANGE_NARROW))
278 cfg |= (S5P_CISCCTRL_CSCR2Y_WIDE | S5P_CISCCTRL_CSCY2R_WIDE);
279
280 if (!sc->enabled)
281 cfg |= S5P_CISCCTRL_SCALERBYPASS;
282
283 if (sc->scaleup_h)
284 cfg |= S5P_CISCCTRL_SCALEUP_H;
285
286 if (sc->scaleup_v)
287 cfg |= S5P_CISCCTRL_SCALEUP_V;
288
289 if (sc->copy_mode)
290 cfg |= S5P_CISCCTRL_ONE2ONE;
291
292
293 if (ctx->in_path == FIMC_DMA) {
294 if (src_frame->fmt->color == S5P_FIMC_RGB565)
295 cfg |= S5P_CISCCTRL_INRGB_FMT_RGB565;
296 else if (src_frame->fmt->color == S5P_FIMC_RGB666)
297 cfg |= S5P_CISCCTRL_INRGB_FMT_RGB666;
298 else if (src_frame->fmt->color == S5P_FIMC_RGB888)
299 cfg |= S5P_CISCCTRL_INRGB_FMT_RGB888;
300 }
301
302 if (ctx->out_path == FIMC_DMA) {
303 if (dst_frame->fmt->color == S5P_FIMC_RGB565)
304 cfg |= S5P_CISCCTRL_OUTRGB_FMT_RGB565;
305 else if (dst_frame->fmt->color == S5P_FIMC_RGB666)
306 cfg |= S5P_CISCCTRL_OUTRGB_FMT_RGB666;
307 else if (dst_frame->fmt->color == S5P_FIMC_RGB888)
308 cfg |= S5P_CISCCTRL_OUTRGB_FMT_RGB888;
309 } else {
310 cfg |= S5P_CISCCTRL_OUTRGB_FMT_RGB888;
311
312 if (ctx->flags & FIMC_SCAN_MODE_INTERLACED)
313 cfg |= S5P_CISCCTRL_INTERLACE;
314 }
315
316 dbg("main_hratio= 0x%X main_vratio= 0x%X",
317 sc->main_hratio, sc->main_vratio);
318
319 cfg |= S5P_CISCCTRL_SC_HORRATIO(sc->main_hratio);
320 cfg |= S5P_CISCCTRL_SC_VERRATIO(sc->main_vratio);
321
322 writel(cfg, dev->regs + S5P_CISCCTRL);
323}
324
325void fimc_hw_en_capture(struct fimc_ctx *ctx)
326{
327 struct fimc_dev *dev = ctx->fimc_dev;
328 u32 cfg;
329
330 cfg = readl(dev->regs + S5P_CIIMGCPT);
331 /* One shot mode for output DMA or freerun for FIFO. */
332 if (ctx->out_path == FIMC_DMA)
333 cfg |= S5P_CIIMGCPT_CPT_FREN_ENABLE;
334 else
335 cfg &= ~S5P_CIIMGCPT_CPT_FREN_ENABLE;
336
337 if (ctx->scaler.enabled)
338 cfg |= S5P_CIIMGCPT_IMGCPTEN_SC;
339
340 writel(cfg | S5P_CIIMGCPT_IMGCPTEN, dev->regs + S5P_CIIMGCPT);
341}
342
343void fimc_hw_set_effect(struct fimc_ctx *ctx)
344{
345 struct fimc_dev *dev = ctx->fimc_dev;
346 struct fimc_effect *effect = &ctx->effect;
347 u32 cfg = (S5P_CIIMGEFF_IE_ENABLE | S5P_CIIMGEFF_IE_SC_AFTER);
348
349 cfg |= effect->type;
350
351 if (effect->type == S5P_FIMC_EFFECT_ARBITRARY) {
352 cfg |= S5P_CIIMGEFF_PAT_CB(effect->pat_cb);
353 cfg |= S5P_CIIMGEFF_PAT_CR(effect->pat_cr);
354 }
355
356 writel(cfg, dev->regs + S5P_CIIMGEFF);
357}
358
359static void fimc_hw_set_in_dma_size(struct fimc_ctx *ctx)
360{
361 struct fimc_dev *dev = ctx->fimc_dev;
362 struct fimc_frame *frame = &ctx->s_frame;
363 u32 cfg_o = 0;
364 u32 cfg_r = 0;
365
366 if (FIMC_LCDFIFO == ctx->out_path)
367 cfg_r |= S5P_CIREAL_ISIZE_AUTOLOAD_EN;
368
369 cfg_o |= S5P_ORIG_SIZE_HOR(frame->f_width);
370 cfg_o |= S5P_ORIG_SIZE_VER(frame->f_height);
371 cfg_r |= S5P_CIREAL_ISIZE_WIDTH(frame->width);
372 cfg_r |= S5P_CIREAL_ISIZE_HEIGHT(frame->height);
373
374 writel(cfg_o, dev->regs + S5P_ORGISIZE);
375 writel(cfg_r, dev->regs + S5P_CIREAL_ISIZE);
376}
377
378void fimc_hw_set_in_dma(struct fimc_ctx *ctx)
379{
380 struct fimc_dev *dev = ctx->fimc_dev;
381 struct fimc_frame *frame = &ctx->s_frame;
382 struct fimc_dma_offset *offset = &frame->dma_offset;
383 u32 cfg = 0;
384
385 /* Set the pixel offsets. */
386 cfg |= S5P_CIO_OFFS_HOR(offset->y_h);
387 cfg |= S5P_CIO_OFFS_VER(offset->y_v);
388 writel(cfg, dev->regs + S5P_CIIYOFF);
389
390 cfg = 0;
391 cfg |= S5P_CIO_OFFS_HOR(offset->cb_h);
392 cfg |= S5P_CIO_OFFS_VER(offset->cb_v);
393 writel(cfg, dev->regs + S5P_CIICBOFF);
394
395 cfg = 0;
396 cfg |= S5P_CIO_OFFS_HOR(offset->cr_h);
397 cfg |= S5P_CIO_OFFS_VER(offset->cr_v);
398 writel(cfg, dev->regs + S5P_CIICROFF);
399
400 /* Input original and real size. */
401 fimc_hw_set_in_dma_size(ctx);
402
403 /* Autoload is used currently only in FIFO mode. */
404 fimc_hw_en_autoload(dev, ctx->out_path == FIMC_LCDFIFO);
405
406 /* Set the input DMA to process single frame only. */
407 cfg = readl(dev->regs + S5P_MSCTRL);
408 cfg &= ~(S5P_MSCTRL_FLIP_MASK
409 | S5P_MSCTRL_INFORMAT_MASK
410 | S5P_MSCTRL_IN_BURST_COUNT_MASK
411 | S5P_MSCTRL_INPUT_MASK
412 | S5P_MSCTRL_C_INT_IN_MASK
413 | S5P_MSCTRL_2P_IN_ORDER_MASK);
414
415 cfg |= (S5P_MSCTRL_FRAME_COUNT(1) | S5P_MSCTRL_INPUT_MEMORY);
416
417 switch (frame->fmt->color) {
418 case S5P_FIMC_RGB565:
419 case S5P_FIMC_RGB666:
420 case S5P_FIMC_RGB888:
421 cfg |= S5P_MSCTRL_INFORMAT_RGB;
422 break;
423 case S5P_FIMC_YCBCR420:
424 cfg |= S5P_MSCTRL_INFORMAT_YCBCR420;
425
426 if (frame->fmt->planes_cnt == 2)
427 cfg |= ctx->in_order_2p | S5P_MSCTRL_C_INT_IN_2PLANE;
428 else
429 cfg |= S5P_MSCTRL_C_INT_IN_3PLANE;
430
431 break;
432 case S5P_FIMC_YCBYCR422:
433 case S5P_FIMC_YCRYCB422:
434 case S5P_FIMC_CBYCRY422:
435 case S5P_FIMC_CRYCBY422:
436 if (frame->fmt->planes_cnt == 1) {
437 cfg |= ctx->in_order_1p
438 | S5P_MSCTRL_INFORMAT_YCBCR422_1P;
439 } else {
440 cfg |= S5P_MSCTRL_INFORMAT_YCBCR422;
441
442 if (frame->fmt->planes_cnt == 2)
443 cfg |= ctx->in_order_2p
444 | S5P_MSCTRL_C_INT_IN_2PLANE;
445 else
446 cfg |= S5P_MSCTRL_C_INT_IN_3PLANE;
447 }
448 break;
449 default:
450 break;
451 }
452
453 /*
454 * Input DMA flip mode (and rotation).
455 * Do not allow simultaneous rotation and flipping.
456 */
457 if (!ctx->rotation && ctx->out_path == FIMC_LCDFIFO)
458 cfg |= fimc_hw_get_in_flip(ctx->flip);
459
460 writel(cfg, dev->regs + S5P_MSCTRL);
461
462 /* Input/output DMA linear/tiled mode. */
463 cfg = readl(dev->regs + S5P_CIDMAPARAM);
464 cfg &= ~S5P_CIDMAPARAM_TILE_MASK;
465
466 if (tiled_fmt(ctx->s_frame.fmt))
467 cfg |= S5P_CIDMAPARAM_R_64X32;
468
469 if (tiled_fmt(ctx->d_frame.fmt))
470 cfg |= S5P_CIDMAPARAM_W_64X32;
471
472 writel(cfg, dev->regs + S5P_CIDMAPARAM);
473}
474
475
476void fimc_hw_set_input_path(struct fimc_ctx *ctx)
477{
478 struct fimc_dev *dev = ctx->fimc_dev;
479
480 u32 cfg = readl(dev->regs + S5P_MSCTRL);
481 cfg &= ~S5P_MSCTRL_INPUT_MASK;
482
483 if (ctx->in_path == FIMC_DMA)
484 cfg |= S5P_MSCTRL_INPUT_MEMORY;
485 else
486 cfg |= S5P_MSCTRL_INPUT_EXTCAM;
487
488 writel(cfg, dev->regs + S5P_MSCTRL);
489}
490
491void fimc_hw_set_output_path(struct fimc_ctx *ctx)
492{
493 struct fimc_dev *dev = ctx->fimc_dev;
494
495 u32 cfg = readl(dev->regs + S5P_CISCCTRL);
496 cfg &= ~S5P_CISCCTRL_LCDPATHEN_FIFO;
497 if (ctx->out_path == FIMC_LCDFIFO)
498 cfg |= S5P_CISCCTRL_LCDPATHEN_FIFO;
499 writel(cfg, dev->regs + S5P_CISCCTRL);
500}
501
502void fimc_hw_set_input_addr(struct fimc_dev *dev, struct fimc_addr *paddr)
503{
504 u32 cfg = 0;
505
506 cfg = readl(dev->regs + S5P_CIREAL_ISIZE);
507 cfg |= S5P_CIREAL_ISIZE_ADDR_CH_DIS;
508 writel(cfg, dev->regs + S5P_CIREAL_ISIZE);
509
510 writel(paddr->y, dev->regs + S5P_CIIYSA0);
511 writel(paddr->cb, dev->regs + S5P_CIICBSA0);
512 writel(paddr->cr, dev->regs + S5P_CIICRSA0);
513
514 cfg &= ~S5P_CIREAL_ISIZE_ADDR_CH_DIS;
515 writel(cfg, dev->regs + S5P_CIREAL_ISIZE);
516}
517
518void fimc_hw_set_output_addr(struct fimc_dev *dev, struct fimc_addr *paddr)
519{
520 int i;
521 /* Set all the output register sets to point to single video buffer. */
522 for (i = 0; i < FIMC_MAX_OUT_BUFS; i++) {
523 writel(paddr->y, dev->regs + S5P_CIOYSA(i));
524 writel(paddr->cb, dev->regs + S5P_CIOCBSA(i));
525 writel(paddr->cr, dev->regs + S5P_CIOCRSA(i));
526 }
527}
diff --git a/drivers/media/video/s5p-fimc/regs-fimc.h b/drivers/media/video/s5p-fimc/regs-fimc.h
new file mode 100644
index 000000000000..a3cfe824db00
--- /dev/null
+++ b/drivers/media/video/s5p-fimc/regs-fimc.h
@@ -0,0 +1,293 @@
1/*
2 * Register definition file for Samsung Camera Interface (FIMC) driver
3 *
4 * Copyright (c) 2010 Samsung Electronics
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#ifndef REGS_FIMC_H_
12#define REGS_FIMC_H_
13
14#define S5P_CIOYSA(__x) (0x18 + (__x) * 4)
15#define S5P_CIOCBSA(__x) (0x28 + (__x) * 4)
16#define S5P_CIOCRSA(__x) (0x38 + (__x) * 4)
17
18/* Input source format */
19#define S5P_CISRCFMT 0x00
20#define S5P_CISRCFMT_ITU601_8BIT (1 << 31)
21#define S5P_CISRCFMT_ITU601_16BIT (1 << 29)
22#define S5P_CISRCFMT_ORDER422_YCBYCR (0 << 14)
23#define S5P_CISRCFMT_ORDER422_YCRYCB (1 << 14)
24#define S5P_CISRCFMT_ORDER422_CBYCRY (2 << 14)
25#define S5P_CISRCFMT_ORDER422_CRYCBY (3 << 14)
26#define S5P_CISRCFMT_HSIZE(x) ((x) << 16)
27#define S5P_CISRCFMT_VSIZE(x) ((x) << 0)
28
29/* Window offset */
30#define S5P_CIWDOFST 0x04
31#define S5P_CIWDOFST_WINOFSEN (1 << 31)
32#define S5P_CIWDOFST_CLROVFIY (1 << 30)
33#define S5P_CIWDOFST_CLROVRLB (1 << 29)
34#define S5P_CIWDOFST_WINHOROFST_MASK (0x7ff << 16)
35#define S5P_CIWDOFST_CLROVFICB (1 << 15)
36#define S5P_CIWDOFST_CLROVFICR (1 << 14)
37#define S5P_CIWDOFST_WINHOROFST(x) ((x) << 16)
38#define S5P_CIWDOFST_WINVEROFST(x) ((x) << 0)
39#define S5P_CIWDOFST_WINVEROFST_MASK (0xfff << 0)
40
41/* Global control */
42#define S5P_CIGCTRL 0x08
43#define S5P_CIGCTRL_SWRST (1 << 31)
44#define S5P_CIGCTRL_CAMRST_A (1 << 30)
45#define S5P_CIGCTRL_SELCAM_ITU_A (1 << 29)
46#define S5P_CIGCTRL_SELCAM_ITU_MASK (1 << 29)
47#define S5P_CIGCTRL_TESTPAT_NORMAL (0 << 27)
48#define S5P_CIGCTRL_TESTPAT_COLOR_BAR (1 << 27)
49#define S5P_CIGCTRL_TESTPAT_HOR_INC (2 << 27)
50#define S5P_CIGCTRL_TESTPAT_VER_INC (3 << 27)
51#define S5P_CIGCTRL_TESTPAT_MASK (3 << 27)
52#define S5P_CIGCTRL_TESTPAT_SHIFT (27)
53#define S5P_CIGCTRL_INVPOLPCLK (1 << 26)
54#define S5P_CIGCTRL_INVPOLVSYNC (1 << 25)
55#define S5P_CIGCTRL_INVPOLHREF (1 << 24)
56#define S5P_CIGCTRL_IRQ_OVFEN (1 << 22)
57#define S5P_CIGCTRL_HREF_MASK (1 << 21)
58#define S5P_CIGCTRL_IRQ_LEVEL (1 << 20)
59#define S5P_CIGCTRL_IRQ_CLR (1 << 19)
60#define S5P_CIGCTRL_IRQ_ENABLE (1 << 16)
61#define S5P_CIGCTRL_SHDW_DISABLE (1 << 12)
62#define S5P_CIGCTRL_SELCAM_MIPI_A (1 << 7)
63#define S5P_CIGCTRL_CAMIF_SELWB (1 << 6)
64#define S5P_CIGCTRL_INVPOLHSYNC (1 << 4)
65#define S5P_CIGCTRL_SELCAM_MIPI (1 << 3)
66#define S5P_CIGCTRL_INTERLACE (1 << 0)
67
68/* Window offset 2 */
69#define S5P_CIWDOFST2 0x14
70#define S5P_CIWDOFST2_HOROFF_MASK (0xfff << 16)
71#define S5P_CIWDOFST2_VEROFF_MASK (0xfff << 0)
72#define S5P_CIWDOFST2_HOROFF(x) ((x) << 16)
73#define S5P_CIWDOFST2_VEROFF(x) ((x) << 0)
74
75/* Output DMA Y plane start address */
76#define S5P_CIOYSA1 0x18
77#define S5P_CIOYSA2 0x1c
78#define S5P_CIOYSA3 0x20
79#define S5P_CIOYSA4 0x24
80
81/* Output DMA Cb plane start address */
82#define S5P_CIOCBSA1 0x28
83#define S5P_CIOCBSA2 0x2c
84#define S5P_CIOCBSA3 0x30
85#define S5P_CIOCBSA4 0x34
86
87/* Output DMA Cr plane start address */
88#define S5P_CIOCRSA1 0x38
89#define S5P_CIOCRSA2 0x3c
90#define S5P_CIOCRSA3 0x40
91#define S5P_CIOCRSA4 0x44
92
93/* Target image format */
94#define S5P_CITRGFMT 0x48
95#define S5P_CITRGFMT_INROT90 (1 << 31)
96#define S5P_CITRGFMT_YCBCR420 (0 << 29)
97#define S5P_CITRGFMT_YCBCR422 (1 << 29)
98#define S5P_CITRGFMT_YCBCR422_1P (2 << 29)
99#define S5P_CITRGFMT_RGB (3 << 29)
100#define S5P_CITRGFMT_FMT_MASK (3 << 29)
101#define S5P_CITRGFMT_HSIZE_MASK (0xfff << 16)
102#define S5P_CITRGFMT_FLIP_SHIFT (14)
103#define S5P_CITRGFMT_FLIP_NORMAL (0 << 14)
104#define S5P_CITRGFMT_FLIP_X_MIRROR (1 << 14)
105#define S5P_CITRGFMT_FLIP_Y_MIRROR (2 << 14)
106#define S5P_CITRGFMT_FLIP_180 (3 << 14)
107#define S5P_CITRGFMT_FLIP_MASK (3 << 14)
108#define S5P_CITRGFMT_OUTROT90 (1 << 13)
109#define S5P_CITRGFMT_VSIZE_MASK (0xfff << 0)
110#define S5P_CITRGFMT_HSIZE(x) ((x) << 16)
111#define S5P_CITRGFMT_VSIZE(x) ((x) << 0)
112
113/* Output DMA control */
114#define S5P_CIOCTRL 0x4c
115#define S5P_CIOCTRL_ORDER422_MASK (3 << 0)
116#define S5P_CIOCTRL_ORDER422_CRYCBY (0 << 0)
117#define S5P_CIOCTRL_ORDER422_YCRYCB (1 << 0)
118#define S5P_CIOCTRL_ORDER422_CBYCRY (2 << 0)
119#define S5P_CIOCTRL_ORDER422_YCBYCR (3 << 0)
120#define S5P_CIOCTRL_LASTIRQ_ENABLE (1 << 2)
121#define S5P_CIOCTRL_YCBCR_3PLANE (0 << 3)
122#define S5P_CIOCTRL_YCBCR_2PLANE (1 << 3)
123#define S5P_CIOCTRL_YCBCR_PLANE_MASK (1 << 3)
124#define S5P_CIOCTRL_ORDER2P_SHIFT (24)
125#define S5P_CIOCTRL_ORDER2P_MASK (3 << 24)
126#define S5P_CIOCTRL_ORDER422_2P_LSB_CRCB (0 << 24)
127
128/* Pre-scaler control 1 */
129#define S5P_CISCPRERATIO 0x50
130#define S5P_CISCPRERATIO_SHFACTOR(x) ((x) << 28)
131#define S5P_CISCPRERATIO_HOR(x) ((x) << 16)
132#define S5P_CISCPRERATIO_VER(x) ((x) << 0)
133
134#define S5P_CISCPREDST 0x54
135#define S5P_CISCPREDST_WIDTH(x) ((x) << 16)
136#define S5P_CISCPREDST_HEIGHT(x) ((x) << 0)
137
138/* Main scaler control */
139#define S5P_CISCCTRL 0x58
140#define S5P_CISCCTRL_SCALERBYPASS (1 << 31)
141#define S5P_CISCCTRL_SCALEUP_H (1 << 30)
142#define S5P_CISCCTRL_SCALEUP_V (1 << 29)
143#define S5P_CISCCTRL_CSCR2Y_WIDE (1 << 28)
144#define S5P_CISCCTRL_CSCY2R_WIDE (1 << 27)
145#define S5P_CISCCTRL_LCDPATHEN_FIFO (1 << 26)
146#define S5P_CISCCTRL_INTERLACE (1 << 25)
147#define S5P_CISCCTRL_SCALERSTART (1 << 15)
148#define S5P_CISCCTRL_INRGB_FMT_RGB565 (0 << 13)
149#define S5P_CISCCTRL_INRGB_FMT_RGB666 (1 << 13)
150#define S5P_CISCCTRL_INRGB_FMT_RGB888 (2 << 13)
151#define S5P_CISCCTRL_INRGB_FMT_MASK (3 << 13)
152#define S5P_CISCCTRL_OUTRGB_FMT_RGB565 (0 << 11)
153#define S5P_CISCCTRL_OUTRGB_FMT_RGB666 (1 << 11)
154#define S5P_CISCCTRL_OUTRGB_FMT_RGB888 (2 << 11)
155#define S5P_CISCCTRL_OUTRGB_FMT_MASK (3 << 11)
156#define S5P_CISCCTRL_RGB_EXT (1 << 10)
157#define S5P_CISCCTRL_ONE2ONE (1 << 9)
158#define S5P_CISCCTRL_SC_HORRATIO(x) ((x) << 16)
159#define S5P_CISCCTRL_SC_VERRATIO(x) ((x) << 0)
160
161/* Target area */
162#define S5P_CITAREA 0x5c
163#define S5P_CITAREA_MASK 0x0fffffff
164
165/* General status */
166#define S5P_CISTATUS 0x64
167#define S5P_CISTATUS_OVFIY (1 << 31)
168#define S5P_CISTATUS_OVFICB (1 << 30)
169#define S5P_CISTATUS_OVFICR (1 << 29)
170#define S5P_CISTATUS_VSYNC (1 << 28)
171#define S5P_CISTATUS_WINOFF_EN (1 << 25)
172#define S5P_CISTATUS_IMGCPT_EN (1 << 22)
173#define S5P_CISTATUS_IMGCPT_SCEN (1 << 21)
174#define S5P_CISTATUS_VSYNC_A (1 << 20)
175#define S5P_CISTATUS_VSYNC_B (1 << 19)
176#define S5P_CISTATUS_OVRLB (1 << 18)
177#define S5P_CISTATUS_FRAME_END (1 << 17)
178#define S5P_CISTATUS_LASTCAPT_END (1 << 16)
179#define S5P_CISTATUS_VVALID_A (1 << 15)
180#define S5P_CISTATUS_VVALID_B (1 << 14)
181
182/* Image capture control */
183#define S5P_CIIMGCPT 0xc0
184#define S5P_CIIMGCPT_IMGCPTEN (1 << 31)
185#define S5P_CIIMGCPT_IMGCPTEN_SC (1 << 30)
186#define S5P_CIIMGCPT_CPT_FREN_ENABLE (1 << 25)
187#define S5P_CIIMGCPT_CPT_FRMOD_CNT (1 << 18)
188
189/* Frame capture sequence */
190#define S5P_CICPTSEQ 0xc4
191
192/* Image effect */
193#define S5P_CIIMGEFF 0xd0
194#define S5P_CIIMGEFF_IE_DISABLE (0 << 30)
195#define S5P_CIIMGEFF_IE_ENABLE (1 << 30)
196#define S5P_CIIMGEFF_IE_SC_BEFORE (0 << 29)
197#define S5P_CIIMGEFF_IE_SC_AFTER (1 << 29)
198#define S5P_CIIMGEFF_FIN_BYPASS (0 << 26)
199#define S5P_CIIMGEFF_FIN_ARBITRARY (1 << 26)
200#define S5P_CIIMGEFF_FIN_NEGATIVE (2 << 26)
201#define S5P_CIIMGEFF_FIN_ARTFREEZE (3 << 26)
202#define S5P_CIIMGEFF_FIN_EMBOSSING (4 << 26)
203#define S5P_CIIMGEFF_FIN_SILHOUETTE (5 << 26)
204#define S5P_CIIMGEFF_FIN_MASK (7 << 26)
205#define S5P_CIIMGEFF_PAT_CBCR_MASK ((0xff < 13) | (0xff < 0))
206#define S5P_CIIMGEFF_PAT_CB(x) ((x) << 13)
207#define S5P_CIIMGEFF_PAT_CR(x) ((x) << 0)
208
209/* Input DMA Y/Cb/Cr plane start address 0 */
210#define S5P_CIIYSA0 0xd4
211#define S5P_CIICBSA0 0xd8
212#define S5P_CIICRSA0 0xdc
213
214/* Real input DMA image size */
215#define S5P_CIREAL_ISIZE 0xf8
216#define S5P_CIREAL_ISIZE_AUTOLOAD_EN (1 << 31)
217#define S5P_CIREAL_ISIZE_ADDR_CH_DIS (1 << 30)
218#define S5P_CIREAL_ISIZE_HEIGHT(x) ((x) << 16)
219#define S5P_CIREAL_ISIZE_WIDTH(x) ((x) << 0)
220
221
222/* Input DMA control */
223#define S5P_MSCTRL 0xfc
224#define S5P_MSCTRL_IN_BURST_COUNT_MASK (3 << 24)
225#define S5P_MSCTRL_2P_IN_ORDER_MASK (3 << 16)
226#define S5P_MSCTRL_2P_IN_ORDER_SHIFT 16
227#define S5P_MSCTRL_C_INT_IN_3PLANE (0 << 15)
228#define S5P_MSCTRL_C_INT_IN_2PLANE (1 << 15)
229#define S5P_MSCTRL_C_INT_IN_MASK (1 << 15)
230#define S5P_MSCTRL_FLIP_SHIFT 13
231#define S5P_MSCTRL_FLIP_MASK (3 << 13)
232#define S5P_MSCTRL_FLIP_NORMAL (0 << 13)
233#define S5P_MSCTRL_FLIP_X_MIRROR (1 << 13)
234#define S5P_MSCTRL_FLIP_Y_MIRROR (2 << 13)
235#define S5P_MSCTRL_FLIP_180 (3 << 13)
236#define S5P_MSCTRL_ORDER422_SHIFT 4
237#define S5P_MSCTRL_ORDER422_CRYCBY (0 << 4)
238#define S5P_MSCTRL_ORDER422_YCRYCB (1 << 4)
239#define S5P_MSCTRL_ORDER422_CBYCRY (2 << 4)
240#define S5P_MSCTRL_ORDER422_YCBYCR (3 << 4)
241#define S5P_MSCTRL_ORDER422_MASK (3 << 4)
242#define S5P_MSCTRL_INPUT_EXTCAM (0 << 3)
243#define S5P_MSCTRL_INPUT_MEMORY (1 << 3)
244#define S5P_MSCTRL_INPUT_MASK (1 << 3)
245#define S5P_MSCTRL_INFORMAT_YCBCR420 (0 << 1)
246#define S5P_MSCTRL_INFORMAT_YCBCR422 (1 << 1)
247#define S5P_MSCTRL_INFORMAT_YCBCR422_1P (2 << 1)
248#define S5P_MSCTRL_INFORMAT_RGB (3 << 1)
249#define S5P_MSCTRL_INFORMAT_MASK (3 << 1)
250#define S5P_MSCTRL_ENVID (1 << 0)
251#define S5P_MSCTRL_FRAME_COUNT(x) ((x) << 24)
252
253/* Input DMA Y/Cb/Cr plane start address 1 */
254#define S5P_CIIYSA1 0x144
255#define S5P_CIICBSA1 0x148
256#define S5P_CIICRSA1 0x14c
257
258/* Output DMA Y/Cb/Cr offset */
259#define S5P_CIOYOFF 0x168
260#define S5P_CIOCBOFF 0x16c
261#define S5P_CIOCROFF 0x170
262
263/* Input DMA Y/Cb/Cr offset */
264#define S5P_CIIYOFF 0x174
265#define S5P_CIICBOFF 0x178
266#define S5P_CIICROFF 0x17c
267
268#define S5P_CIO_OFFS_VER(x) ((x) << 16)
269#define S5P_CIO_OFFS_HOR(x) ((x) << 0)
270
271/* Input DMA original image size */
272#define S5P_ORGISIZE 0x180
273
274/* Output DMA original image size */
275#define S5P_ORGOSIZE 0x184
276
277#define S5P_ORIG_SIZE_VER(x) ((x) << 16)
278#define S5P_ORIG_SIZE_HOR(x) ((x) << 0)
279
280/* Real output DMA image size (extension register) */
281#define S5P_CIEXTEN 0x188
282
283#define S5P_CIDMAPARAM 0x18c
284#define S5P_CIDMAPARAM_R_LINEAR (0 << 29)
285#define S5P_CIDMAPARAM_R_64X32 (3 << 29)
286#define S5P_CIDMAPARAM_W_LINEAR (0 << 13)
287#define S5P_CIDMAPARAM_W_64X32 (3 << 13)
288#define S5P_CIDMAPARAM_TILE_MASK ((3 << 29) | (3 << 13))
289
290/* MIPI CSI image format */
291#define S5P_CSIIMGFMT 0x194
292
293#endif /* REGS_FIMC_H_ */
diff --git a/drivers/media/video/saa7115.c b/drivers/media/video/saa7115.c
index 76da74368680..ee963f4d01bc 100644
--- a/drivers/media/video/saa7115.c
+++ b/drivers/media/video/saa7115.c
@@ -45,6 +45,7 @@
45#include <linux/i2c.h> 45#include <linux/i2c.h>
46#include <linux/videodev2.h> 46#include <linux/videodev2.h>
47#include <media/v4l2-device.h> 47#include <media/v4l2-device.h>
48#include <media/v4l2-ctrls.h>
48#include <media/v4l2-chip-ident.h> 49#include <media/v4l2-chip-ident.h>
49#include <media/v4l2-i2c-drv.h> 50#include <media/v4l2-i2c-drv.h>
50#include <media/saa7115.h> 51#include <media/saa7115.h>
@@ -65,16 +66,19 @@ MODULE_PARM_DESC(debug, "Debug level (0-1)");
65 66
66struct saa711x_state { 67struct saa711x_state {
67 struct v4l2_subdev sd; 68 struct v4l2_subdev sd;
69 struct v4l2_ctrl_handler hdl;
70
71 struct {
72 /* chroma gain control cluster */
73 struct v4l2_ctrl *agc;
74 struct v4l2_ctrl *gain;
75 };
76
68 v4l2_std_id std; 77 v4l2_std_id std;
69 int input; 78 int input;
70 int output; 79 int output;
71 int enable; 80 int enable;
72 int radio; 81 int radio;
73 int bright;
74 int contrast;
75 int hue;
76 int sat;
77 int chroma_agc;
78 int width; 82 int width;
79 int height; 83 int height;
80 u32 ident; 84 u32 ident;
@@ -90,6 +94,11 @@ static inline struct saa711x_state *to_state(struct v4l2_subdev *sd)
90 return container_of(sd, struct saa711x_state, sd); 94 return container_of(sd, struct saa711x_state, sd);
91} 95}
92 96
97static inline struct v4l2_subdev *to_sd(struct v4l2_ctrl *ctrl)
98{
99 return &container_of(ctrl->handler, struct saa711x_state, hdl)->sd;
100}
101
93/* ----------------------------------------------------------------------- */ 102/* ----------------------------------------------------------------------- */
94 103
95static inline int saa711x_write(struct v4l2_subdev *sd, u8 reg, u8 value) 104static inline int saa711x_write(struct v4l2_subdev *sd, u8 reg, u8 value)
@@ -741,96 +750,53 @@ static int saa711x_s_clock_freq(struct v4l2_subdev *sd, u32 freq)
741 return 0; 750 return 0;
742} 751}
743 752
744static int saa711x_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) 753static int saa711x_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
745{ 754{
755 struct v4l2_subdev *sd = to_sd(ctrl);
746 struct saa711x_state *state = to_state(sd); 756 struct saa711x_state *state = to_state(sd);
747 u8 val;
748 757
749 switch (ctrl->id) { 758 switch (ctrl->id) {
750 case V4L2_CID_BRIGHTNESS:
751 if (ctrl->value < 0 || ctrl->value > 255) {
752 v4l2_err(sd, "invalid brightness setting %d\n", ctrl->value);
753 return -ERANGE;
754 }
755
756 state->bright = ctrl->value;
757 saa711x_write(sd, R_0A_LUMA_BRIGHT_CNTL, state->bright);
758 break;
759
760 case V4L2_CID_CONTRAST:
761 if (ctrl->value < 0 || ctrl->value > 127) {
762 v4l2_err(sd, "invalid contrast setting %d\n", ctrl->value);
763 return -ERANGE;
764 }
765
766 state->contrast = ctrl->value;
767 saa711x_write(sd, R_0B_LUMA_CONTRAST_CNTL, state->contrast);
768 break;
769
770 case V4L2_CID_SATURATION:
771 if (ctrl->value < 0 || ctrl->value > 127) {
772 v4l2_err(sd, "invalid saturation setting %d\n", ctrl->value);
773 return -ERANGE;
774 }
775
776 state->sat = ctrl->value;
777 saa711x_write(sd, R_0C_CHROMA_SAT_CNTL, state->sat);
778 break;
779
780 case V4L2_CID_HUE:
781 if (ctrl->value < -128 || ctrl->value > 127) {
782 v4l2_err(sd, "invalid hue setting %d\n", ctrl->value);
783 return -ERANGE;
784 }
785
786 state->hue = ctrl->value;
787 saa711x_write(sd, R_0D_CHROMA_HUE_CNTL, state->hue);
788 break;
789 case V4L2_CID_CHROMA_AGC: 759 case V4L2_CID_CHROMA_AGC:
790 val = saa711x_read(sd, R_0F_CHROMA_GAIN_CNTL); 760 /* chroma gain cluster */
791 state->chroma_agc = ctrl->value; 761 if (state->agc->cur.val)
792 if (ctrl->value) 762 state->gain->cur.val =
793 val &= 0x7f; 763 saa711x_read(sd, R_0F_CHROMA_GAIN_CNTL) & 0x7f;
794 else
795 val |= 0x80;
796 saa711x_write(sd, R_0F_CHROMA_GAIN_CNTL, val);
797 break; 764 break;
798 case V4L2_CID_CHROMA_GAIN:
799 /* Chroma gain cannot be set when AGC is enabled */
800 if (state->chroma_agc == 1)
801 return -EINVAL;
802 saa711x_write(sd, R_0F_CHROMA_GAIN_CNTL, ctrl->value | 0x80);
803 break;
804 default:
805 return -EINVAL;
806 } 765 }
807
808 return 0; 766 return 0;
809} 767}
810 768
811static int saa711x_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) 769static int saa711x_s_ctrl(struct v4l2_ctrl *ctrl)
812{ 770{
771 struct v4l2_subdev *sd = to_sd(ctrl);
813 struct saa711x_state *state = to_state(sd); 772 struct saa711x_state *state = to_state(sd);
814 773
815 switch (ctrl->id) { 774 switch (ctrl->id) {
816 case V4L2_CID_BRIGHTNESS: 775 case V4L2_CID_BRIGHTNESS:
817 ctrl->value = state->bright; 776 saa711x_write(sd, R_0A_LUMA_BRIGHT_CNTL, ctrl->val);
818 break; 777 break;
778
819 case V4L2_CID_CONTRAST: 779 case V4L2_CID_CONTRAST:
820 ctrl->value = state->contrast; 780 saa711x_write(sd, R_0B_LUMA_CONTRAST_CNTL, ctrl->val);
821 break; 781 break;
782
822 case V4L2_CID_SATURATION: 783 case V4L2_CID_SATURATION:
823 ctrl->value = state->sat; 784 saa711x_write(sd, R_0C_CHROMA_SAT_CNTL, ctrl->val);
824 break; 785 break;
786
825 case V4L2_CID_HUE: 787 case V4L2_CID_HUE:
826 ctrl->value = state->hue; 788 saa711x_write(sd, R_0D_CHROMA_HUE_CNTL, ctrl->val);
827 break; 789 break;
790
828 case V4L2_CID_CHROMA_AGC: 791 case V4L2_CID_CHROMA_AGC:
829 ctrl->value = state->chroma_agc; 792 /* chroma gain cluster */
830 break; 793 if (state->agc->val)
831 case V4L2_CID_CHROMA_GAIN: 794 saa711x_write(sd, R_0F_CHROMA_GAIN_CNTL, state->gain->val);
832 ctrl->value = saa711x_read(sd, R_0F_CHROMA_GAIN_CNTL) & 0x7f; 795 else
796 saa711x_write(sd, R_0F_CHROMA_GAIN_CNTL, state->gain->val | 0x80);
797 v4l2_ctrl_activate(state->gain, !state->agc->val);
833 break; 798 break;
799
834 default: 800 default:
835 return -EINVAL; 801 return -EINVAL;
836 } 802 }
@@ -1223,25 +1189,6 @@ static int saa711x_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
1223 return 0; 1189 return 0;
1224} 1190}
1225 1191
1226static int saa711x_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc)
1227{
1228 switch (qc->id) {
1229 case V4L2_CID_BRIGHTNESS:
1230 return v4l2_ctrl_query_fill(qc, 0, 255, 1, 128);
1231 case V4L2_CID_CONTRAST:
1232 case V4L2_CID_SATURATION:
1233 return v4l2_ctrl_query_fill(qc, 0, 127, 1, 64);
1234 case V4L2_CID_HUE:
1235 return v4l2_ctrl_query_fill(qc, -128, 127, 1, 0);
1236 case V4L2_CID_CHROMA_AGC:
1237 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1);
1238 case V4L2_CID_CHROMA_GAIN:
1239 return v4l2_ctrl_query_fill(qc, 0, 127, 1, 48);
1240 default:
1241 return -EINVAL;
1242 }
1243}
1244
1245static int saa711x_s_std(struct v4l2_subdev *sd, v4l2_std_id std) 1192static int saa711x_s_std(struct v4l2_subdev *sd, v4l2_std_id std)
1246{ 1193{
1247 struct saa711x_state *state = to_state(sd); 1194 struct saa711x_state *state = to_state(sd);
@@ -1518,17 +1465,27 @@ static int saa711x_log_status(struct v4l2_subdev *sd)
1518 break; 1465 break;
1519 } 1466 }
1520 v4l2_info(sd, "Width, Height: %d, %d\n", state->width, state->height); 1467 v4l2_info(sd, "Width, Height: %d, %d\n", state->width, state->height);
1468 v4l2_ctrl_handler_log_status(&state->hdl, sd->name);
1521 return 0; 1469 return 0;
1522} 1470}
1523 1471
1524/* ----------------------------------------------------------------------- */ 1472/* ----------------------------------------------------------------------- */
1525 1473
1474static const struct v4l2_ctrl_ops saa711x_ctrl_ops = {
1475 .s_ctrl = saa711x_s_ctrl,
1476 .g_volatile_ctrl = saa711x_g_volatile_ctrl,
1477};
1478
1526static const struct v4l2_subdev_core_ops saa711x_core_ops = { 1479static const struct v4l2_subdev_core_ops saa711x_core_ops = {
1527 .log_status = saa711x_log_status, 1480 .log_status = saa711x_log_status,
1528 .g_chip_ident = saa711x_g_chip_ident, 1481 .g_chip_ident = saa711x_g_chip_ident,
1529 .g_ctrl = saa711x_g_ctrl, 1482 .g_ext_ctrls = v4l2_subdev_g_ext_ctrls,
1530 .s_ctrl = saa711x_s_ctrl, 1483 .try_ext_ctrls = v4l2_subdev_try_ext_ctrls,
1531 .queryctrl = saa711x_queryctrl, 1484 .s_ext_ctrls = v4l2_subdev_s_ext_ctrls,
1485 .g_ctrl = v4l2_subdev_g_ctrl,
1486 .s_ctrl = v4l2_subdev_s_ctrl,
1487 .queryctrl = v4l2_subdev_queryctrl,
1488 .querymenu = v4l2_subdev_querymenu,
1532 .s_std = saa711x_s_std, 1489 .s_std = saa711x_s_std,
1533 .reset = saa711x_reset, 1490 .reset = saa711x_reset,
1534 .s_gpio = saa711x_s_gpio, 1491 .s_gpio = saa711x_s_gpio,
@@ -1579,8 +1536,9 @@ static int saa711x_probe(struct i2c_client *client,
1579{ 1536{
1580 struct saa711x_state *state; 1537 struct saa711x_state *state;
1581 struct v4l2_subdev *sd; 1538 struct v4l2_subdev *sd;
1582 int i; 1539 struct v4l2_ctrl_handler *hdl;
1583 char name[17]; 1540 int i;
1541 char name[17];
1584 char chip_id; 1542 char chip_id;
1585 int autodetect = !id || id->driver_data == 1; 1543 int autodetect = !id || id->driver_data == 1;
1586 1544
@@ -1619,15 +1577,38 @@ static int saa711x_probe(struct i2c_client *client,
1619 return -ENOMEM; 1577 return -ENOMEM;
1620 sd = &state->sd; 1578 sd = &state->sd;
1621 v4l2_i2c_subdev_init(sd, client, &saa711x_ops); 1579 v4l2_i2c_subdev_init(sd, client, &saa711x_ops);
1580
1581 hdl = &state->hdl;
1582 v4l2_ctrl_handler_init(hdl, 6);
1583 /* add in ascending ID order */
1584 v4l2_ctrl_new_std(hdl, &saa711x_ctrl_ops,
1585 V4L2_CID_BRIGHTNESS, 0, 255, 1, 128);
1586 v4l2_ctrl_new_std(hdl, &saa711x_ctrl_ops,
1587 V4L2_CID_CONTRAST, 0, 127, 1, 64);
1588 v4l2_ctrl_new_std(hdl, &saa711x_ctrl_ops,
1589 V4L2_CID_SATURATION, 0, 127, 1, 64);
1590 v4l2_ctrl_new_std(hdl, &saa711x_ctrl_ops,
1591 V4L2_CID_HUE, -128, 127, 1, 0);
1592 state->agc = v4l2_ctrl_new_std(hdl, &saa711x_ctrl_ops,
1593 V4L2_CID_CHROMA_AGC, 0, 1, 1, 1);
1594 state->gain = v4l2_ctrl_new_std(hdl, &saa711x_ctrl_ops,
1595 V4L2_CID_CHROMA_GAIN, 0, 127, 1, 40);
1596 state->gain->is_volatile = 1;
1597 sd->ctrl_handler = hdl;
1598 if (hdl->error) {
1599 int err = hdl->error;
1600
1601 v4l2_ctrl_handler_free(hdl);
1602 kfree(state);
1603 return err;
1604 }
1605 state->agc->flags |= V4L2_CTRL_FLAG_UPDATE;
1606 v4l2_ctrl_cluster(2, &state->agc);
1607
1622 state->input = -1; 1608 state->input = -1;
1623 state->output = SAA7115_IPORT_ON; 1609 state->output = SAA7115_IPORT_ON;
1624 state->enable = 1; 1610 state->enable = 1;
1625 state->radio = 0; 1611 state->radio = 0;
1626 state->bright = 128;
1627 state->contrast = 64;
1628 state->hue = 0;
1629 state->sat = 64;
1630 state->chroma_agc = 1;
1631 switch (chip_id) { 1612 switch (chip_id) {
1632 case '1': 1613 case '1':
1633 state->ident = V4L2_IDENT_SAA7111; 1614 state->ident = V4L2_IDENT_SAA7111;
@@ -1675,6 +1656,7 @@ static int saa711x_probe(struct i2c_client *client,
1675 if (state->ident > V4L2_IDENT_SAA7111A) 1656 if (state->ident > V4L2_IDENT_SAA7111A)
1676 saa711x_writeregs(sd, saa7115_init_misc); 1657 saa711x_writeregs(sd, saa7115_init_misc);
1677 saa711x_set_v4lstd(sd, V4L2_STD_NTSC); 1658 saa711x_set_v4lstd(sd, V4L2_STD_NTSC);
1659 v4l2_ctrl_handler_setup(hdl);
1678 1660
1679 v4l2_dbg(1, debug, sd, "status: (1E) 0x%02x, (1F) 0x%02x\n", 1661 v4l2_dbg(1, debug, sd, "status: (1E) 0x%02x, (1F) 0x%02x\n",
1680 saa711x_read(sd, R_1E_STATUS_BYTE_1_VD_DEC), 1662 saa711x_read(sd, R_1E_STATUS_BYTE_1_VD_DEC),
@@ -1689,6 +1671,7 @@ static int saa711x_remove(struct i2c_client *client)
1689 struct v4l2_subdev *sd = i2c_get_clientdata(client); 1671 struct v4l2_subdev *sd = i2c_get_clientdata(client);
1690 1672
1691 v4l2_device_unregister_subdev(sd); 1673 v4l2_device_unregister_subdev(sd);
1674 v4l2_ctrl_handler_free(sd->ctrl_handler);
1692 kfree(to_state(sd)); 1675 kfree(to_state(sd));
1693 return 0; 1676 return 0;
1694} 1677}
diff --git a/drivers/media/video/saa7134/Kconfig b/drivers/media/video/saa7134/Kconfig
index 22bfd62c9551..fda005e01670 100644
--- a/drivers/media/video/saa7134/Kconfig
+++ b/drivers/media/video/saa7134/Kconfig
@@ -2,7 +2,7 @@ config VIDEO_SAA7134
2 tristate "Philips SAA7134 support" 2 tristate "Philips SAA7134 support"
3 depends on VIDEO_DEV && PCI && I2C && INPUT 3 depends on VIDEO_DEV && PCI && I2C && INPUT
4 select VIDEOBUF_DMA_SG 4 select VIDEOBUF_DMA_SG
5 select VIDEO_IR 5 depends on VIDEO_IR
6 select VIDEO_TUNER 6 select VIDEO_TUNER
7 select VIDEO_TVEEPROM 7 select VIDEO_TVEEPROM
8 select CRC32 8 select CRC32
diff --git a/drivers/media/video/saa717x.c b/drivers/media/video/saa717x.c
index 78d69950c00a..45f8bfc1342e 100644
--- a/drivers/media/video/saa717x.c
+++ b/drivers/media/video/saa717x.c
@@ -38,6 +38,7 @@
38#include <linux/videodev2.h> 38#include <linux/videodev2.h>
39#include <linux/i2c.h> 39#include <linux/i2c.h>
40#include <media/v4l2-device.h> 40#include <media/v4l2-device.h>
41#include <media/v4l2-ctrls.h>
41#include <media/v4l2-i2c-drv.h> 42#include <media/v4l2-i2c-drv.h>
42 43
43MODULE_DESCRIPTION("Philips SAA717x audio/video decoder driver"); 44MODULE_DESCRIPTION("Philips SAA717x audio/video decoder driver");
@@ -55,14 +56,11 @@ MODULE_PARM_DESC(debug, "Debug level (0-1)");
55 56
56struct saa717x_state { 57struct saa717x_state {
57 struct v4l2_subdev sd; 58 struct v4l2_subdev sd;
59 struct v4l2_ctrl_handler hdl;
58 v4l2_std_id std; 60 v4l2_std_id std;
59 int input; 61 int input;
60 int enable; 62 int enable;
61 int radio; 63 int radio;
62 int bright;
63 int contrast;
64 int hue;
65 int sat;
66 int playback; 64 int playback;
67 int audio; 65 int audio;
68 int tuner_audio_mode; 66 int tuner_audio_mode;
@@ -81,6 +79,11 @@ static inline struct saa717x_state *to_state(struct v4l2_subdev *sd)
81 return container_of(sd, struct saa717x_state, sd); 79 return container_of(sd, struct saa717x_state, sd);
82} 80}
83 81
82static inline struct v4l2_subdev *to_sd(struct v4l2_ctrl *ctrl)
83{
84 return &container_of(ctrl->handler, struct saa717x_state, hdl)->sd;
85}
86
84/* ----------------------------------------------------------------------- */ 87/* ----------------------------------------------------------------------- */
85 88
86/* for audio mode */ 89/* for audio mode */
@@ -774,29 +777,6 @@ static void set_audio_mode(struct v4l2_subdev *sd, int audio_mode)
774 saa717x_write(sd, 0x470, reg_set_audio_template[audio_mode][1]); 777 saa717x_write(sd, 0x470, reg_set_audio_template[audio_mode][1]);
775} 778}
776 779
777/* write regs to video output level (bright,contrast,hue,sat) */
778static void set_video_output_level_regs(struct v4l2_subdev *sd,
779 struct saa717x_state *decoder)
780{
781 /* brightness ffh (bright) - 80h (ITU level) - 00h (dark) */
782 saa717x_write(sd, 0x10a, decoder->bright);
783
784 /* contrast 7fh (max: 1.984) - 44h (ITU) - 40h (1.0) -
785 0h (luminance off) 40: i2c dump
786 c0h (-1.0 inverse chrominance)
787 80h (-2.0 inverse chrominance) */
788 saa717x_write(sd, 0x10b, decoder->contrast);
789
790 /* saturation? 7fh(max)-40h(ITU)-0h(color off)
791 c0h (-1.0 inverse chrominance)
792 80h (-2.0 inverse chrominance) */
793 saa717x_write(sd, 0x10c, decoder->sat);
794
795 /* color hue (phase) control
796 7fh (+178.6) - 0h (0 normal) - 80h (-180.0) */
797 saa717x_write(sd, 0x10d, decoder->hue);
798}
799
800/* write regs to set audio volume, bass and treble */ 780/* write regs to set audio volume, bass and treble */
801static int set_audio_regs(struct v4l2_subdev *sd, 781static int set_audio_regs(struct v4l2_subdev *sd,
802 struct saa717x_state *decoder) 782 struct saa717x_state *decoder)
@@ -829,9 +809,9 @@ static int set_audio_regs(struct v4l2_subdev *sd,
829 809
830 saa717x_write(sd, 0x480, val); 810 saa717x_write(sd, 0x480, val);
831 811
832 /* bass and treble; go to another function */
833 /* set bass and treble */ 812 /* set bass and treble */
834 val = decoder->audio_main_bass | (decoder->audio_main_treble << 8); 813 val = decoder->audio_main_bass & 0x1f;
814 val |= (decoder->audio_main_treble & 0x1f) << 5;
835 saa717x_write(sd, 0x488, val); 815 saa717x_write(sd, 0x488, val);
836 return 0; 816 return 0;
837} 817}
@@ -893,218 +873,55 @@ static void set_v_scale(struct v4l2_subdev *sd, int task, int yscale)
893 saa717x_write(sd, 0x71 + task_shift, yscale >> 8); 873 saa717x_write(sd, 0x71 + task_shift, yscale >> 8);
894} 874}
895 875
896static int saa717x_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) 876static int saa717x_s_ctrl(struct v4l2_ctrl *ctrl)
897{
898 struct saa717x_state *state = to_state(sd);
899
900 switch (ctrl->id) {
901 case V4L2_CID_BRIGHTNESS:
902 if (ctrl->value < 0 || ctrl->value > 255) {
903 v4l2_err(sd, "invalid brightness setting %d\n", ctrl->value);
904 return -ERANGE;
905 }
906
907 state->bright = ctrl->value;
908 v4l2_dbg(1, debug, sd, "bright:%d\n", state->bright);
909 saa717x_write(sd, 0x10a, state->bright);
910 break;
911
912 case V4L2_CID_CONTRAST:
913 if (ctrl->value < 0 || ctrl->value > 127) {
914 v4l2_err(sd, "invalid contrast setting %d\n", ctrl->value);
915 return -ERANGE;
916 }
917
918 state->contrast = ctrl->value;
919 v4l2_dbg(1, debug, sd, "contrast:%d\n", state->contrast);
920 saa717x_write(sd, 0x10b, state->contrast);
921 break;
922
923 case V4L2_CID_SATURATION:
924 if (ctrl->value < 0 || ctrl->value > 127) {
925 v4l2_err(sd, "invalid saturation setting %d\n", ctrl->value);
926 return -ERANGE;
927 }
928
929 state->sat = ctrl->value;
930 v4l2_dbg(1, debug, sd, "sat:%d\n", state->sat);
931 saa717x_write(sd, 0x10c, state->sat);
932 break;
933
934 case V4L2_CID_HUE:
935 if (ctrl->value < -128 || ctrl->value > 127) {
936 v4l2_err(sd, "invalid hue setting %d\n", ctrl->value);
937 return -ERANGE;
938 }
939
940 state->hue = ctrl->value;
941 v4l2_dbg(1, debug, sd, "hue:%d\n", state->hue);
942 saa717x_write(sd, 0x10d, state->hue);
943 break;
944
945 case V4L2_CID_AUDIO_MUTE:
946 state->audio_main_mute = ctrl->value;
947 set_audio_regs(sd, state);
948 break;
949
950 case V4L2_CID_AUDIO_VOLUME:
951 state->audio_main_volume = ctrl->value;
952 set_audio_regs(sd, state);
953 break;
954
955 case V4L2_CID_AUDIO_BALANCE:
956 state->audio_main_balance = ctrl->value;
957 set_audio_regs(sd, state);
958 break;
959
960 case V4L2_CID_AUDIO_TREBLE:
961 state->audio_main_treble = ctrl->value;
962 set_audio_regs(sd, state);
963 break;
964
965 case V4L2_CID_AUDIO_BASS:
966 state->audio_main_bass = ctrl->value;
967 set_audio_regs(sd, state);
968 break;
969
970 default:
971 return -EINVAL;
972 }
973
974 return 0;
975}
976
977static int saa717x_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
978{ 877{
878 struct v4l2_subdev *sd = to_sd(ctrl);
979 struct saa717x_state *state = to_state(sd); 879 struct saa717x_state *state = to_state(sd);
980 880
981 switch (ctrl->id) { 881 switch (ctrl->id) {
982 case V4L2_CID_BRIGHTNESS: 882 case V4L2_CID_BRIGHTNESS:
983 ctrl->value = state->bright; 883 saa717x_write(sd, 0x10a, ctrl->val);
984 break; 884 return 0;
985 885
986 case V4L2_CID_CONTRAST: 886 case V4L2_CID_CONTRAST:
987 ctrl->value = state->contrast; 887 saa717x_write(sd, 0x10b, ctrl->val);
988 break; 888 return 0;
989 889
990 case V4L2_CID_SATURATION: 890 case V4L2_CID_SATURATION:
991 ctrl->value = state->sat; 891 saa717x_write(sd, 0x10c, ctrl->val);
992 break; 892 return 0;
993 893
994 case V4L2_CID_HUE: 894 case V4L2_CID_HUE:
995 ctrl->value = state->hue; 895 saa717x_write(sd, 0x10d, ctrl->val);
996 break; 896 return 0;
997 897
998 case V4L2_CID_AUDIO_MUTE: 898 case V4L2_CID_AUDIO_MUTE:
999 ctrl->value = state->audio_main_mute; 899 state->audio_main_mute = ctrl->val;
1000 break; 900 break;
1001 901
1002 case V4L2_CID_AUDIO_VOLUME: 902 case V4L2_CID_AUDIO_VOLUME:
1003 ctrl->value = state->audio_main_volume; 903 state->audio_main_volume = ctrl->val;
1004 break; 904 break;
1005 905
1006 case V4L2_CID_AUDIO_BALANCE: 906 case V4L2_CID_AUDIO_BALANCE:
1007 ctrl->value = state->audio_main_balance; 907 state->audio_main_balance = ctrl->val;
1008 break; 908 break;
1009 909
1010 case V4L2_CID_AUDIO_TREBLE: 910 case V4L2_CID_AUDIO_TREBLE:
1011 ctrl->value = state->audio_main_treble; 911 state->audio_main_treble = ctrl->val;
1012 break; 912 break;
1013 913
1014 case V4L2_CID_AUDIO_BASS: 914 case V4L2_CID_AUDIO_BASS:
1015 ctrl->value = state->audio_main_bass; 915 state->audio_main_bass = ctrl->val;
1016 break; 916 break;
1017 917
1018 default: 918 default:
1019 return -EINVAL; 919 return 0;
1020 } 920 }
1021 921 set_audio_regs(sd, state);
1022 return 0; 922 return 0;
1023} 923}
1024 924
1025static struct v4l2_queryctrl saa717x_qctrl[] = {
1026 {
1027 .id = V4L2_CID_BRIGHTNESS,
1028 .type = V4L2_CTRL_TYPE_INTEGER,
1029 .name = "Brightness",
1030 .minimum = 0,
1031 .maximum = 255,
1032 .step = 1,
1033 .default_value = 128,
1034 .flags = 0,
1035 }, {
1036 .id = V4L2_CID_CONTRAST,
1037 .type = V4L2_CTRL_TYPE_INTEGER,
1038 .name = "Contrast",
1039 .minimum = 0,
1040 .maximum = 255,
1041 .step = 1,
1042 .default_value = 64,
1043 .flags = 0,
1044 }, {
1045 .id = V4L2_CID_SATURATION,
1046 .type = V4L2_CTRL_TYPE_INTEGER,
1047 .name = "Saturation",
1048 .minimum = 0,
1049 .maximum = 255,
1050 .step = 1,
1051 .default_value = 64,
1052 .flags = 0,
1053 }, {
1054 .id = V4L2_CID_HUE,
1055 .type = V4L2_CTRL_TYPE_INTEGER,
1056 .name = "Hue",
1057 .minimum = -128,
1058 .maximum = 127,
1059 .step = 1,
1060 .default_value = 0,
1061 .flags = 0,
1062 }, {
1063 .id = V4L2_CID_AUDIO_VOLUME,
1064 .type = V4L2_CTRL_TYPE_INTEGER,
1065 .name = "Volume",
1066 .minimum = 0,
1067 .maximum = 65535,
1068 .step = 65535 / 100,
1069 .default_value = 58880,
1070 .flags = 0,
1071 }, {
1072 .id = V4L2_CID_AUDIO_BALANCE,
1073 .type = V4L2_CTRL_TYPE_INTEGER,
1074 .name = "Balance",
1075 .minimum = 0,
1076 .maximum = 65535,
1077 .step = 65535 / 100,
1078 .default_value = 32768,
1079 .flags = 0,
1080 }, {
1081 .id = V4L2_CID_AUDIO_MUTE,
1082 .type = V4L2_CTRL_TYPE_BOOLEAN,
1083 .name = "Mute",
1084 .minimum = 0,
1085 .maximum = 1,
1086 .step = 1,
1087 .default_value = 1,
1088 .flags = 0,
1089 }, {
1090 .id = V4L2_CID_AUDIO_BASS,
1091 .type = V4L2_CTRL_TYPE_INTEGER,
1092 .name = "Bass",
1093 .minimum = 0,
1094 .maximum = 65535,
1095 .step = 65535 / 100,
1096 .default_value = 32768,
1097 }, {
1098 .id = V4L2_CID_AUDIO_TREBLE,
1099 .type = V4L2_CTRL_TYPE_INTEGER,
1100 .name = "Treble",
1101 .minimum = 0,
1102 .maximum = 65535,
1103 .step = 65535 / 100,
1104 .default_value = 32768,
1105 },
1106};
1107
1108static int saa717x_s_video_routing(struct v4l2_subdev *sd, 925static int saa717x_s_video_routing(struct v4l2_subdev *sd,
1109 u32 input, u32 output, u32 config) 926 u32 input, u32 output, u32 config)
1110{ 927{
@@ -1158,18 +975,6 @@ static int saa717x_s_video_routing(struct v4l2_subdev *sd,
1158 return 0; 975 return 0;
1159} 976}
1160 977
1161static int saa717x_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc)
1162{
1163 int i;
1164
1165 for (i = 0; i < ARRAY_SIZE(saa717x_qctrl); i++)
1166 if (qc->id && qc->id == saa717x_qctrl[i].id) {
1167 memcpy(qc, &saa717x_qctrl[i], sizeof(*qc));
1168 return 0;
1169 }
1170 return -EINVAL;
1171}
1172
1173#ifdef CONFIG_VIDEO_ADV_DEBUG 978#ifdef CONFIG_VIDEO_ADV_DEBUG
1174static int saa717x_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) 979static int saa717x_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg)
1175{ 980{
@@ -1386,17 +1191,34 @@ static int saa717x_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
1386 return 0; 1191 return 0;
1387} 1192}
1388 1193
1194static int saa717x_log_status(struct v4l2_subdev *sd)
1195{
1196 struct saa717x_state *state = to_state(sd);
1197
1198 v4l2_ctrl_handler_log_status(&state->hdl, sd->name);
1199 return 0;
1200}
1201
1389/* ----------------------------------------------------------------------- */ 1202/* ----------------------------------------------------------------------- */
1390 1203
1204static const struct v4l2_ctrl_ops saa717x_ctrl_ops = {
1205 .s_ctrl = saa717x_s_ctrl,
1206};
1207
1391static const struct v4l2_subdev_core_ops saa717x_core_ops = { 1208static const struct v4l2_subdev_core_ops saa717x_core_ops = {
1392#ifdef CONFIG_VIDEO_ADV_DEBUG 1209#ifdef CONFIG_VIDEO_ADV_DEBUG
1393 .g_register = saa717x_g_register, 1210 .g_register = saa717x_g_register,
1394 .s_register = saa717x_s_register, 1211 .s_register = saa717x_s_register,
1395#endif 1212#endif
1396 .queryctrl = saa717x_queryctrl,
1397 .g_ctrl = saa717x_g_ctrl,
1398 .s_ctrl = saa717x_s_ctrl,
1399 .s_std = saa717x_s_std, 1213 .s_std = saa717x_s_std,
1214 .g_ext_ctrls = v4l2_subdev_g_ext_ctrls,
1215 .try_ext_ctrls = v4l2_subdev_try_ext_ctrls,
1216 .s_ext_ctrls = v4l2_subdev_s_ext_ctrls,
1217 .g_ctrl = v4l2_subdev_g_ctrl,
1218 .s_ctrl = v4l2_subdev_s_ctrl,
1219 .queryctrl = v4l2_subdev_queryctrl,
1220 .querymenu = v4l2_subdev_querymenu,
1221 .log_status = saa717x_log_status,
1400}; 1222};
1401 1223
1402static const struct v4l2_subdev_tuner_ops saa717x_tuner_ops = { 1224static const struct v4l2_subdev_tuner_ops saa717x_tuner_ops = {
@@ -1432,6 +1254,7 @@ static int saa717x_probe(struct i2c_client *client,
1432 const struct i2c_device_id *did) 1254 const struct i2c_device_id *did)
1433{ 1255{
1434 struct saa717x_state *decoder; 1256 struct saa717x_state *decoder;
1257 struct v4l2_ctrl_handler *hdl;
1435 struct v4l2_subdev *sd; 1258 struct v4l2_subdev *sd;
1436 u8 id = 0; 1259 u8 id = 0;
1437 char *p = ""; 1260 char *p = "";
@@ -1467,16 +1290,41 @@ static int saa717x_probe(struct i2c_client *client,
1467 p = "saa7171"; 1290 p = "saa7171";
1468 v4l2_info(sd, "%s found @ 0x%x (%s)\n", p, 1291 v4l2_info(sd, "%s found @ 0x%x (%s)\n", p,
1469 client->addr << 1, client->adapter->name); 1292 client->addr << 1, client->adapter->name);
1293
1294 hdl = &decoder->hdl;
1295 v4l2_ctrl_handler_init(hdl, 9);
1296 /* add in ascending ID order */
1297 v4l2_ctrl_new_std(hdl, &saa717x_ctrl_ops,
1298 V4L2_CID_BRIGHTNESS, 0, 255, 1, 128);
1299 v4l2_ctrl_new_std(hdl, &saa717x_ctrl_ops,
1300 V4L2_CID_CONTRAST, 0, 255, 1, 68);
1301 v4l2_ctrl_new_std(hdl, &saa717x_ctrl_ops,
1302 V4L2_CID_SATURATION, 0, 255, 1, 64);
1303 v4l2_ctrl_new_std(hdl, &saa717x_ctrl_ops,
1304 V4L2_CID_HUE, -128, 127, 1, 0);
1305 v4l2_ctrl_new_std(hdl, &saa717x_ctrl_ops,
1306 V4L2_CID_AUDIO_VOLUME, 0, 65535, 65535 / 100, 42000);
1307 v4l2_ctrl_new_std(hdl, &saa717x_ctrl_ops,
1308 V4L2_CID_AUDIO_BALANCE, 0, 65535, 65535 / 100, 32768);
1309 v4l2_ctrl_new_std(hdl, &saa717x_ctrl_ops,
1310 V4L2_CID_AUDIO_BASS, -16, 15, 1, 0);
1311 v4l2_ctrl_new_std(hdl, &saa717x_ctrl_ops,
1312 V4L2_CID_AUDIO_TREBLE, -16, 15, 1, 0);
1313 v4l2_ctrl_new_std(hdl, &saa717x_ctrl_ops,
1314 V4L2_CID_AUDIO_MUTE, 0, 1, 1, 0);
1315 sd->ctrl_handler = hdl;
1316 if (hdl->error) {
1317 int err = hdl->error;
1318
1319 v4l2_ctrl_handler_free(hdl);
1320 kfree(decoder);
1321 return err;
1322 }
1323
1470 decoder->std = V4L2_STD_NTSC; 1324 decoder->std = V4L2_STD_NTSC;
1471 decoder->input = -1; 1325 decoder->input = -1;
1472 decoder->enable = 1; 1326 decoder->enable = 1;
1473 1327
1474 /* tune these parameters */
1475 decoder->bright = 0x80;
1476 decoder->contrast = 0x44;
1477 decoder->sat = 0x40;
1478 decoder->hue = 0x00;
1479
1480 /* FIXME!! */ 1328 /* FIXME!! */
1481 decoder->playback = 0; /* initially capture mode used */ 1329 decoder->playback = 0; /* initially capture mode used */
1482 decoder->audio = 1; /* DECODER_AUDIO_48_KHZ */ 1330 decoder->audio = 1; /* DECODER_AUDIO_48_KHZ */
@@ -1487,23 +1335,13 @@ static int saa717x_probe(struct i2c_client *client,
1487 /* set volume, bass and treble */ 1335 /* set volume, bass and treble */
1488 decoder->audio_main_vol_l = 6; 1336 decoder->audio_main_vol_l = 6;
1489 decoder->audio_main_vol_r = 6; 1337 decoder->audio_main_vol_r = 6;
1490 decoder->audio_main_bass = 0;
1491 decoder->audio_main_treble = 0;
1492 decoder->audio_main_mute = 0;
1493 decoder->audio_main_balance = 32768;
1494 /* normalize (24 to -40 (not -84) -> 65535 to 0) */
1495 decoder->audio_main_volume =
1496 (decoder->audio_main_vol_r + 41) * 65535 / (24 - (-40));
1497 1338
1498 v4l2_dbg(1, debug, sd, "writing init values\n"); 1339 v4l2_dbg(1, debug, sd, "writing init values\n");
1499 1340
1500 /* FIXME!! */ 1341 /* FIXME!! */
1501 saa717x_write_regs(sd, reg_init_initialize); 1342 saa717x_write_regs(sd, reg_init_initialize);
1502 set_video_output_level_regs(sd, decoder); 1343
1503 /* set bass,treble to 0db 20041101 K.Ohta */ 1344 v4l2_ctrl_handler_setup(hdl);
1504 decoder->audio_main_bass = 0;
1505 decoder->audio_main_treble = 0;
1506 set_audio_regs(sd, decoder);
1507 1345
1508 set_current_state(TASK_INTERRUPTIBLE); 1346 set_current_state(TASK_INTERRUPTIBLE);
1509 schedule_timeout(2*HZ); 1347 schedule_timeout(2*HZ);
@@ -1515,6 +1353,7 @@ static int saa717x_remove(struct i2c_client *client)
1515 struct v4l2_subdev *sd = i2c_get_clientdata(client); 1353 struct v4l2_subdev *sd = i2c_get_clientdata(client);
1516 1354
1517 v4l2_device_unregister_subdev(sd); 1355 v4l2_device_unregister_subdev(sd);
1356 v4l2_ctrl_handler_free(sd->ctrl_handler);
1518 kfree(to_state(sd)); 1357 kfree(to_state(sd));
1519 return 0; 1358 return 0;
1520} 1359}
diff --git a/drivers/media/video/soc_camera.c b/drivers/media/video/soc_camera.c
index f2032939fd4b..a499cacec1f3 100644
--- a/drivers/media/video/soc_camera.c
+++ b/drivers/media/video/soc_camera.c
@@ -779,9 +779,12 @@ static int soc_camera_s_crop(struct file *file, void *fh,
779 ret = ici->ops->get_crop(icd, &current_crop); 779 ret = ici->ops->get_crop(icd, &current_crop);
780 780
781 /* Prohibit window size change with initialised buffers */ 781 /* Prohibit window size change with initialised buffers */
782 if (icf->vb_vidq.bufs[0] && !ret && 782 if (ret < 0) {
783 (a->c.width != current_crop.c.width || 783 dev_err(&icd->dev,
784 a->c.height != current_crop.c.height)) { 784 "S_CROP denied: getting current crop failed\n");
785 } else if (icf->vb_vidq.bufs[0] &&
786 (a->c.width != current_crop.c.width ||
787 a->c.height != current_crop.c.height)) {
785 dev_err(&icd->dev, 788 dev_err(&icd->dev,
786 "S_CROP denied: queue initialised and sizes differ\n"); 789 "S_CROP denied: queue initialised and sizes differ\n");
787 ret = -EBUSY; 790 ret = -EBUSY;
diff --git a/drivers/media/video/tlg2300/Kconfig b/drivers/media/video/tlg2300/Kconfig
index 2c29ec659b4e..1686ebfa6951 100644
--- a/drivers/media/video/tlg2300/Kconfig
+++ b/drivers/media/video/tlg2300/Kconfig
@@ -3,7 +3,7 @@ config VIDEO_TLG2300
3 depends on VIDEO_DEV && I2C && INPUT && SND && DVB_CORE 3 depends on VIDEO_DEV && I2C && INPUT && SND && DVB_CORE
4 select VIDEO_TUNER 4 select VIDEO_TUNER
5 select VIDEO_TVEEPROM 5 select VIDEO_TVEEPROM
6 select VIDEO_IR 6 depends on VIDEO_IR
7 select VIDEOBUF_VMALLOC 7 select VIDEOBUF_VMALLOC
8 select SND_PCM 8 select SND_PCM
9 select VIDEOBUF_DVB 9 select VIDEOBUF_DVB
diff --git a/drivers/media/video/tvp7002.c b/drivers/media/video/tvp7002.c
index 8085ac392446..48f5c76ab521 100644
--- a/drivers/media/video/tvp7002.c
+++ b/drivers/media/video/tvp7002.c
@@ -179,7 +179,7 @@ static const struct i2c_reg_value tvp7002_init_default[] = {
179/* Register parameters for 480P */ 179/* Register parameters for 480P */
180static const struct i2c_reg_value tvp7002_parms_480P[] = { 180static const struct i2c_reg_value tvp7002_parms_480P[] = {
181 { TVP7002_HPLL_FDBK_DIV_MSBS, 0x35, TVP7002_WRITE }, 181 { TVP7002_HPLL_FDBK_DIV_MSBS, 0x35, TVP7002_WRITE },
182 { TVP7002_HPLL_FDBK_DIV_LSBS, 0x0a, TVP7002_WRITE }, 182 { TVP7002_HPLL_FDBK_DIV_LSBS, 0xa0, TVP7002_WRITE },
183 { TVP7002_HPLL_CRTL, 0x02, TVP7002_WRITE }, 183 { TVP7002_HPLL_CRTL, 0x02, TVP7002_WRITE },
184 { TVP7002_HPLL_PHASE_SEL, 0x14, TVP7002_WRITE }, 184 { TVP7002_HPLL_PHASE_SEL, 0x14, TVP7002_WRITE },
185 { TVP7002_AVID_START_PIXEL_LSBS, 0x91, TVP7002_WRITE }, 185 { TVP7002_AVID_START_PIXEL_LSBS, 0x91, TVP7002_WRITE },
@@ -223,7 +223,7 @@ static const struct i2c_reg_value tvp7002_parms_576P[] = {
223/* Register parameters for 1080I60 */ 223/* Register parameters for 1080I60 */
224static const struct i2c_reg_value tvp7002_parms_1080I60[] = { 224static const struct i2c_reg_value tvp7002_parms_1080I60[] = {
225 { TVP7002_HPLL_FDBK_DIV_MSBS, 0x89, TVP7002_WRITE }, 225 { TVP7002_HPLL_FDBK_DIV_MSBS, 0x89, TVP7002_WRITE },
226 { TVP7002_HPLL_FDBK_DIV_LSBS, 0x08, TVP7002_WRITE }, 226 { TVP7002_HPLL_FDBK_DIV_LSBS, 0x80, TVP7002_WRITE },
227 { TVP7002_HPLL_CRTL, 0x98, TVP7002_WRITE }, 227 { TVP7002_HPLL_CRTL, 0x98, TVP7002_WRITE },
228 { TVP7002_HPLL_PHASE_SEL, 0x14, TVP7002_WRITE }, 228 { TVP7002_HPLL_PHASE_SEL, 0x14, TVP7002_WRITE },
229 { TVP7002_AVID_START_PIXEL_LSBS, 0x06, TVP7002_WRITE }, 229 { TVP7002_AVID_START_PIXEL_LSBS, 0x06, TVP7002_WRITE },
@@ -245,7 +245,7 @@ static const struct i2c_reg_value tvp7002_parms_1080I60[] = {
245/* Register parameters for 1080P60 */ 245/* Register parameters for 1080P60 */
246static const struct i2c_reg_value tvp7002_parms_1080P60[] = { 246static const struct i2c_reg_value tvp7002_parms_1080P60[] = {
247 { TVP7002_HPLL_FDBK_DIV_MSBS, 0x89, TVP7002_WRITE }, 247 { TVP7002_HPLL_FDBK_DIV_MSBS, 0x89, TVP7002_WRITE },
248 { TVP7002_HPLL_FDBK_DIV_LSBS, 0x08, TVP7002_WRITE }, 248 { TVP7002_HPLL_FDBK_DIV_LSBS, 0x80, TVP7002_WRITE },
249 { TVP7002_HPLL_CRTL, 0xE0, TVP7002_WRITE }, 249 { TVP7002_HPLL_CRTL, 0xE0, TVP7002_WRITE },
250 { TVP7002_HPLL_PHASE_SEL, 0x14, TVP7002_WRITE }, 250 { TVP7002_HPLL_PHASE_SEL, 0x14, TVP7002_WRITE },
251 { TVP7002_AVID_START_PIXEL_LSBS, 0x06, TVP7002_WRITE }, 251 { TVP7002_AVID_START_PIXEL_LSBS, 0x06, TVP7002_WRITE },
@@ -289,7 +289,7 @@ static const struct i2c_reg_value tvp7002_parms_1080I50[] = {
289/* Register parameters for 720P60 */ 289/* Register parameters for 720P60 */
290static const struct i2c_reg_value tvp7002_parms_720P60[] = { 290static const struct i2c_reg_value tvp7002_parms_720P60[] = {
291 { TVP7002_HPLL_FDBK_DIV_MSBS, 0x67, TVP7002_WRITE }, 291 { TVP7002_HPLL_FDBK_DIV_MSBS, 0x67, TVP7002_WRITE },
292 { TVP7002_HPLL_FDBK_DIV_LSBS, 0x02, TVP7002_WRITE }, 292 { TVP7002_HPLL_FDBK_DIV_LSBS, 0x20, TVP7002_WRITE },
293 { TVP7002_HPLL_CRTL, 0xa0, TVP7002_WRITE }, 293 { TVP7002_HPLL_CRTL, 0xa0, TVP7002_WRITE },
294 { TVP7002_HPLL_PHASE_SEL, 0x16, TVP7002_WRITE }, 294 { TVP7002_HPLL_PHASE_SEL, 0x16, TVP7002_WRITE },
295 { TVP7002_AVID_START_PIXEL_LSBS, 0x47, TVP7002_WRITE }, 295 { TVP7002_AVID_START_PIXEL_LSBS, 0x47, TVP7002_WRITE },
@@ -311,7 +311,7 @@ static const struct i2c_reg_value tvp7002_parms_720P60[] = {
311/* Register parameters for 720P50 */ 311/* Register parameters for 720P50 */
312static const struct i2c_reg_value tvp7002_parms_720P50[] = { 312static const struct i2c_reg_value tvp7002_parms_720P50[] = {
313 { TVP7002_HPLL_FDBK_DIV_MSBS, 0x7b, TVP7002_WRITE }, 313 { TVP7002_HPLL_FDBK_DIV_MSBS, 0x7b, TVP7002_WRITE },
314 { TVP7002_HPLL_FDBK_DIV_LSBS, 0x0c, TVP7002_WRITE }, 314 { TVP7002_HPLL_FDBK_DIV_LSBS, 0xc0, TVP7002_WRITE },
315 { TVP7002_HPLL_CRTL, 0x98, TVP7002_WRITE }, 315 { TVP7002_HPLL_CRTL, 0x98, TVP7002_WRITE },
316 { TVP7002_HPLL_PHASE_SEL, 0x16, TVP7002_WRITE }, 316 { TVP7002_HPLL_PHASE_SEL, 0x16, TVP7002_WRITE },
317 { TVP7002_AVID_START_PIXEL_LSBS, 0x47, TVP7002_WRITE }, 317 { TVP7002_AVID_START_PIXEL_LSBS, 0x47, TVP7002_WRITE },
diff --git a/drivers/media/video/usbvideo/usbvideo.c b/drivers/media/video/usbvideo/usbvideo.c
index 5ac37c6c4313..f1fcf9744961 100644
--- a/drivers/media/video/usbvideo/usbvideo.c
+++ b/drivers/media/video/usbvideo/usbvideo.c
@@ -282,19 +282,15 @@ static void usbvideo_OverlayChar(struct uvd *uvd, struct usbvideo_frame *frame,
282 }; 282 };
283 unsigned short digit; 283 unsigned short digit;
284 int ix, iy; 284 int ix, iy;
285 int value;
285 286
286 if ((uvd == NULL) || (frame == NULL)) 287 if ((uvd == NULL) || (frame == NULL))
287 return; 288 return;
288 289
289 if (ch >= '0' && ch <= '9') 290 value = hex_to_bin(ch);
290 ch -= '0'; 291 if (value < 0)
291 else if (ch >= 'A' && ch <= 'F')
292 ch = 10 + (ch - 'A');
293 else if (ch >= 'a' && ch <= 'f')
294 ch = 10 + (ch - 'a');
295 else
296 return; 292 return;
297 digit = digits[ch]; 293 digit = digits[value];
298 294
299 for (iy=0; iy < 5; iy++) { 295 for (iy=0; iy < 5; iy++) {
300 for (ix=0; ix < 3; ix++) { 296 for (ix=0; ix < 3; ix++) {
diff --git a/drivers/media/video/uvc/uvc_driver.c b/drivers/media/video/uvc/uvc_driver.c
index 7eaf99b22a48..8bdd940f32e6 100644
--- a/drivers/media/video/uvc/uvc_driver.c
+++ b/drivers/media/video/uvc/uvc_driver.c
@@ -2145,6 +2145,15 @@ static struct usb_device_id uvc_ids[] = {
2145 .bInterfaceSubClass = 1, 2145 .bInterfaceSubClass = 1,
2146 .bInterfaceProtocol = 0, 2146 .bInterfaceProtocol = 0,
2147 .driver_info = UVC_QUIRK_STREAM_NO_FID }, 2147 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2148 /* Miricle 307K */
2149 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2150 | USB_DEVICE_ID_MATCH_INT_INFO,
2151 .idVendor = 0x17dc,
2152 .idProduct = 0x0202,
2153 .bInterfaceClass = USB_CLASS_VIDEO,
2154 .bInterfaceSubClass = 1,
2155 .bInterfaceProtocol = 0,
2156 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2148 /* Lenovo Thinkpad SL400/SL500 */ 2157 /* Lenovo Thinkpad SL400/SL500 */
2149 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 2158 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2150 | USB_DEVICE_ID_MATCH_INT_INFO, 2159 | USB_DEVICE_ID_MATCH_INT_INFO,
diff --git a/drivers/media/video/uvc/uvc_queue.c b/drivers/media/video/uvc/uvc_queue.c
index 133c78d113ac..e9928a415086 100644
--- a/drivers/media/video/uvc/uvc_queue.c
+++ b/drivers/media/video/uvc/uvc_queue.c
@@ -78,12 +78,14 @@
78 * 78 *
79 */ 79 */
80 80
81void uvc_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type) 81void uvc_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type,
82 int drop_corrupted)
82{ 83{
83 mutex_init(&queue->mutex); 84 mutex_init(&queue->mutex);
84 spin_lock_init(&queue->irqlock); 85 spin_lock_init(&queue->irqlock);
85 INIT_LIST_HEAD(&queue->mainqueue); 86 INIT_LIST_HEAD(&queue->mainqueue);
86 INIT_LIST_HEAD(&queue->irqqueue); 87 INIT_LIST_HEAD(&queue->irqqueue);
88 queue->flags = drop_corrupted ? UVC_QUEUE_DROP_CORRUPTED : 0;
87 queue->type = type; 89 queue->type = type;
88} 90}
89 91
@@ -435,8 +437,10 @@ int uvc_queue_enable(struct uvc_video_queue *queue, int enable)
435 uvc_queue_cancel(queue, 0); 437 uvc_queue_cancel(queue, 0);
436 INIT_LIST_HEAD(&queue->mainqueue); 438 INIT_LIST_HEAD(&queue->mainqueue);
437 439
438 for (i = 0; i < queue->count; ++i) 440 for (i = 0; i < queue->count; ++i) {
441 queue->buffer[i].error = 0;
439 queue->buffer[i].state = UVC_BUF_STATE_IDLE; 442 queue->buffer[i].state = UVC_BUF_STATE_IDLE;
443 }
440 444
441 queue->flags &= ~UVC_QUEUE_STREAMING; 445 queue->flags &= ~UVC_QUEUE_STREAMING;
442 } 446 }
@@ -488,8 +492,8 @@ struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue,
488 struct uvc_buffer *nextbuf; 492 struct uvc_buffer *nextbuf;
489 unsigned long flags; 493 unsigned long flags;
490 494
491 if ((queue->flags & UVC_QUEUE_DROP_INCOMPLETE) && 495 if ((queue->flags & UVC_QUEUE_DROP_CORRUPTED) && buf->error) {
492 buf->buf.length != buf->buf.bytesused) { 496 buf->error = 0;
493 buf->state = UVC_BUF_STATE_QUEUED; 497 buf->state = UVC_BUF_STATE_QUEUED;
494 buf->buf.bytesused = 0; 498 buf->buf.bytesused = 0;
495 return buf; 499 return buf;
@@ -497,6 +501,7 @@ struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue,
497 501
498 spin_lock_irqsave(&queue->irqlock, flags); 502 spin_lock_irqsave(&queue->irqlock, flags);
499 list_del(&buf->queue); 503 list_del(&buf->queue);
504 buf->error = 0;
500 buf->state = UVC_BUF_STATE_DONE; 505 buf->state = UVC_BUF_STATE_DONE;
501 if (!list_empty(&queue->irqqueue)) 506 if (!list_empty(&queue->irqqueue))
502 nextbuf = list_first_entry(&queue->irqqueue, struct uvc_buffer, 507 nextbuf = list_first_entry(&queue->irqqueue, struct uvc_buffer,
diff --git a/drivers/media/video/uvc/uvc_video.c b/drivers/media/video/uvc/uvc_video.c
index 53f3ef4635eb..e27cf0d3b6d9 100644
--- a/drivers/media/video/uvc/uvc_video.c
+++ b/drivers/media/video/uvc/uvc_video.c
@@ -555,6 +555,9 @@ static void uvc_video_decode_isoc(struct urb *urb, struct uvc_streaming *stream,
555 if (urb->iso_frame_desc[i].status < 0) { 555 if (urb->iso_frame_desc[i].status < 0) {
556 uvc_trace(UVC_TRACE_FRAME, "USB isochronous frame " 556 uvc_trace(UVC_TRACE_FRAME, "USB isochronous frame "
557 "lost (%d).\n", urb->iso_frame_desc[i].status); 557 "lost (%d).\n", urb->iso_frame_desc[i].status);
558 /* Mark the buffer as faulty. */
559 if (buf != NULL)
560 buf->error = 1;
558 continue; 561 continue;
559 } 562 }
560 563
@@ -579,8 +582,14 @@ static void uvc_video_decode_isoc(struct urb *urb, struct uvc_streaming *stream,
579 uvc_video_decode_end(stream, buf, mem, 582 uvc_video_decode_end(stream, buf, mem,
580 urb->iso_frame_desc[i].actual_length); 583 urb->iso_frame_desc[i].actual_length);
581 584
582 if (buf->state == UVC_BUF_STATE_READY) 585 if (buf->state == UVC_BUF_STATE_READY) {
586 if (buf->buf.length != buf->buf.bytesused &&
587 !(stream->cur_format->flags &
588 UVC_FMT_FLAG_COMPRESSED))
589 buf->error = 1;
590
583 buf = uvc_queue_next_buffer(&stream->queue, buf); 591 buf = uvc_queue_next_buffer(&stream->queue, buf);
592 }
584 } 593 }
585} 594}
586 595
@@ -1104,7 +1113,7 @@ int uvc_video_init(struct uvc_streaming *stream)
1104 atomic_set(&stream->active, 0); 1113 atomic_set(&stream->active, 0);
1105 1114
1106 /* Initialize the video buffers queue. */ 1115 /* Initialize the video buffers queue. */
1107 uvc_queue_init(&stream->queue, stream->type); 1116 uvc_queue_init(&stream->queue, stream->type, !uvc_no_drop_param);
1108 1117
1109 /* Alternate setting 0 should be the default, yet the XBox Live Vision 1118 /* Alternate setting 0 should be the default, yet the XBox Live Vision
1110 * Cam (and possibly other devices) crash or otherwise misbehave if 1119 * Cam (and possibly other devices) crash or otherwise misbehave if
@@ -1197,12 +1206,6 @@ int uvc_video_enable(struct uvc_streaming *stream, int enable)
1197 return 0; 1206 return 0;
1198 } 1207 }
1199 1208
1200 if ((stream->cur_format->flags & UVC_FMT_FLAG_COMPRESSED) ||
1201 uvc_no_drop_param)
1202 stream->queue.flags &= ~UVC_QUEUE_DROP_INCOMPLETE;
1203 else
1204 stream->queue.flags |= UVC_QUEUE_DROP_INCOMPLETE;
1205
1206 ret = uvc_queue_enable(&stream->queue, 1); 1209 ret = uvc_queue_enable(&stream->queue, 1);
1207 if (ret < 0) 1210 if (ret < 0)
1208 return ret; 1211 return ret;
diff --git a/drivers/media/video/uvc/uvcvideo.h b/drivers/media/video/uvc/uvcvideo.h
index ac272456fbfd..bdacf3beabf5 100644
--- a/drivers/media/video/uvc/uvcvideo.h
+++ b/drivers/media/video/uvc/uvcvideo.h
@@ -379,11 +379,12 @@ struct uvc_buffer {
379 struct list_head queue; 379 struct list_head queue;
380 wait_queue_head_t wait; 380 wait_queue_head_t wait;
381 enum uvc_buffer_state state; 381 enum uvc_buffer_state state;
382 unsigned int error;
382}; 383};
383 384
384#define UVC_QUEUE_STREAMING (1 << 0) 385#define UVC_QUEUE_STREAMING (1 << 0)
385#define UVC_QUEUE_DISCONNECTED (1 << 1) 386#define UVC_QUEUE_DISCONNECTED (1 << 1)
386#define UVC_QUEUE_DROP_INCOMPLETE (1 << 2) 387#define UVC_QUEUE_DROP_CORRUPTED (1 << 2)
387 388
388struct uvc_video_queue { 389struct uvc_video_queue {
389 enum v4l2_buf_type type; 390 enum v4l2_buf_type type;
@@ -562,7 +563,7 @@ extern struct uvc_driver uvc_driver;
562 563
563/* Video buffers queue management. */ 564/* Video buffers queue management. */
564extern void uvc_queue_init(struct uvc_video_queue *queue, 565extern void uvc_queue_init(struct uvc_video_queue *queue,
565 enum v4l2_buf_type type); 566 enum v4l2_buf_type type, int drop_corrupted);
566extern int uvc_alloc_buffers(struct uvc_video_queue *queue, 567extern int uvc_alloc_buffers(struct uvc_video_queue *queue,
567 unsigned int nbuffers, unsigned int buflength); 568 unsigned int nbuffers, unsigned int buflength);
568extern int uvc_free_buffers(struct uvc_video_queue *queue); 569extern int uvc_free_buffers(struct uvc_video_queue *queue);
diff --git a/drivers/media/video/v4l2-common.c b/drivers/media/video/v4l2-common.c
index 4e53b0b3339c..8ee1179be926 100644
--- a/drivers/media/video/v4l2-common.c
+++ b/drivers/media/video/v4l2-common.c
@@ -62,6 +62,7 @@
62#define __OLD_VIDIOC_ /* To allow fixing old calls*/ 62#define __OLD_VIDIOC_ /* To allow fixing old calls*/
63#include <media/v4l2-common.h> 63#include <media/v4l2-common.h>
64#include <media/v4l2-device.h> 64#include <media/v4l2-device.h>
65#include <media/v4l2-ctrls.h>
65#include <media/v4l2-chip-ident.h> 66#include <media/v4l2-chip-ident.h>
66 67
67#include <linux/videodev2.h> 68#include <linux/videodev2.h>
@@ -172,487 +173,17 @@ int v4l2_ctrl_check(struct v4l2_ext_control *ctrl, struct v4l2_queryctrl *qctrl,
172} 173}
173EXPORT_SYMBOL(v4l2_ctrl_check); 174EXPORT_SYMBOL(v4l2_ctrl_check);
174 175
175/* Returns NULL or a character pointer array containing the menu for
176 the given control ID. The pointer array ends with a NULL pointer.
177 An empty string signifies a menu entry that is invalid. This allows
178 drivers to disable certain options if it is not supported. */
179const char **v4l2_ctrl_get_menu(u32 id)
180{
181 static const char *mpeg_audio_sampling_freq[] = {
182 "44.1 kHz",
183 "48 kHz",
184 "32 kHz",
185 NULL
186 };
187 static const char *mpeg_audio_encoding[] = {
188 "MPEG-1/2 Layer I",
189 "MPEG-1/2 Layer II",
190 "MPEG-1/2 Layer III",
191 "MPEG-2/4 AAC",
192 "AC-3",
193 NULL
194 };
195 static const char *mpeg_audio_l1_bitrate[] = {
196 "32 kbps",
197 "64 kbps",
198 "96 kbps",
199 "128 kbps",
200 "160 kbps",
201 "192 kbps",
202 "224 kbps",
203 "256 kbps",
204 "288 kbps",
205 "320 kbps",
206 "352 kbps",
207 "384 kbps",
208 "416 kbps",
209 "448 kbps",
210 NULL
211 };
212 static const char *mpeg_audio_l2_bitrate[] = {
213 "32 kbps",
214 "48 kbps",
215 "56 kbps",
216 "64 kbps",
217 "80 kbps",
218 "96 kbps",
219 "112 kbps",
220 "128 kbps",
221 "160 kbps",
222 "192 kbps",
223 "224 kbps",
224 "256 kbps",
225 "320 kbps",
226 "384 kbps",
227 NULL
228 };
229 static const char *mpeg_audio_l3_bitrate[] = {
230 "32 kbps",
231 "40 kbps",
232 "48 kbps",
233 "56 kbps",
234 "64 kbps",
235 "80 kbps",
236 "96 kbps",
237 "112 kbps",
238 "128 kbps",
239 "160 kbps",
240 "192 kbps",
241 "224 kbps",
242 "256 kbps",
243 "320 kbps",
244 NULL
245 };
246 static const char *mpeg_audio_ac3_bitrate[] = {
247 "32 kbps",
248 "40 kbps",
249 "48 kbps",
250 "56 kbps",
251 "64 kbps",
252 "80 kbps",
253 "96 kbps",
254 "112 kbps",
255 "128 kbps",
256 "160 kbps",
257 "192 kbps",
258 "224 kbps",
259 "256 kbps",
260 "320 kbps",
261 "384 kbps",
262 "448 kbps",
263 "512 kbps",
264 "576 kbps",
265 "640 kbps",
266 NULL
267 };
268 static const char *mpeg_audio_mode[] = {
269 "Stereo",
270 "Joint Stereo",
271 "Dual",
272 "Mono",
273 NULL
274 };
275 static const char *mpeg_audio_mode_extension[] = {
276 "Bound 4",
277 "Bound 8",
278 "Bound 12",
279 "Bound 16",
280 NULL
281 };
282 static const char *mpeg_audio_emphasis[] = {
283 "No Emphasis",
284 "50/15 us",
285 "CCITT J17",
286 NULL
287 };
288 static const char *mpeg_audio_crc[] = {
289 "No CRC",
290 "16-bit CRC",
291 NULL
292 };
293 static const char *mpeg_video_encoding[] = {
294 "MPEG-1",
295 "MPEG-2",
296 "MPEG-4 AVC",
297 NULL
298 };
299 static const char *mpeg_video_aspect[] = {
300 "1x1",
301 "4x3",
302 "16x9",
303 "2.21x1",
304 NULL
305 };
306 static const char *mpeg_video_bitrate_mode[] = {
307 "Variable Bitrate",
308 "Constant Bitrate",
309 NULL
310 };
311 static const char *mpeg_stream_type[] = {
312 "MPEG-2 Program Stream",
313 "MPEG-2 Transport Stream",
314 "MPEG-1 System Stream",
315 "MPEG-2 DVD-compatible Stream",
316 "MPEG-1 VCD-compatible Stream",
317 "MPEG-2 SVCD-compatible Stream",
318 NULL
319 };
320 static const char *mpeg_stream_vbi_fmt[] = {
321 "No VBI",
322 "Private packet, IVTV format",
323 NULL
324 };
325 static const char *camera_power_line_frequency[] = {
326 "Disabled",
327 "50 Hz",
328 "60 Hz",
329 NULL
330 };
331 static const char *camera_exposure_auto[] = {
332 "Auto Mode",
333 "Manual Mode",
334 "Shutter Priority Mode",
335 "Aperture Priority Mode",
336 NULL
337 };
338 static const char *colorfx[] = {
339 "None",
340 "Black & White",
341 "Sepia",
342 "Negative",
343 "Emboss",
344 "Sketch",
345 "Sky blue",
346 "Grass green",
347 "Skin whiten",
348 "Vivid",
349 NULL
350 };
351 static const char *tune_preemphasis[] = {
352 "No preemphasis",
353 "50 useconds",
354 "75 useconds",
355 NULL,
356 };
357
358 switch (id) {
359 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
360 return mpeg_audio_sampling_freq;
361 case V4L2_CID_MPEG_AUDIO_ENCODING:
362 return mpeg_audio_encoding;
363 case V4L2_CID_MPEG_AUDIO_L1_BITRATE:
364 return mpeg_audio_l1_bitrate;
365 case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
366 return mpeg_audio_l2_bitrate;
367 case V4L2_CID_MPEG_AUDIO_L3_BITRATE:
368 return mpeg_audio_l3_bitrate;
369 case V4L2_CID_MPEG_AUDIO_AC3_BITRATE:
370 return mpeg_audio_ac3_bitrate;
371 case V4L2_CID_MPEG_AUDIO_MODE:
372 return mpeg_audio_mode;
373 case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION:
374 return mpeg_audio_mode_extension;
375 case V4L2_CID_MPEG_AUDIO_EMPHASIS:
376 return mpeg_audio_emphasis;
377 case V4L2_CID_MPEG_AUDIO_CRC:
378 return mpeg_audio_crc;
379 case V4L2_CID_MPEG_VIDEO_ENCODING:
380 return mpeg_video_encoding;
381 case V4L2_CID_MPEG_VIDEO_ASPECT:
382 return mpeg_video_aspect;
383 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
384 return mpeg_video_bitrate_mode;
385 case V4L2_CID_MPEG_STREAM_TYPE:
386 return mpeg_stream_type;
387 case V4L2_CID_MPEG_STREAM_VBI_FMT:
388 return mpeg_stream_vbi_fmt;
389 case V4L2_CID_POWER_LINE_FREQUENCY:
390 return camera_power_line_frequency;
391 case V4L2_CID_EXPOSURE_AUTO:
392 return camera_exposure_auto;
393 case V4L2_CID_COLORFX:
394 return colorfx;
395 case V4L2_CID_TUNE_PREEMPHASIS:
396 return tune_preemphasis;
397 default:
398 return NULL;
399 }
400}
401EXPORT_SYMBOL(v4l2_ctrl_get_menu);
402
403/* Return the control name. */
404const char *v4l2_ctrl_get_name(u32 id)
405{
406 switch (id) {
407 /* USER controls */
408 case V4L2_CID_USER_CLASS: return "User Controls";
409 case V4L2_CID_BRIGHTNESS: return "Brightness";
410 case V4L2_CID_CONTRAST: return "Contrast";
411 case V4L2_CID_SATURATION: return "Saturation";
412 case V4L2_CID_HUE: return "Hue";
413 case V4L2_CID_AUDIO_VOLUME: return "Volume";
414 case V4L2_CID_AUDIO_BALANCE: return "Balance";
415 case V4L2_CID_AUDIO_BASS: return "Bass";
416 case V4L2_CID_AUDIO_TREBLE: return "Treble";
417 case V4L2_CID_AUDIO_MUTE: return "Mute";
418 case V4L2_CID_AUDIO_LOUDNESS: return "Loudness";
419 case V4L2_CID_BLACK_LEVEL: return "Black Level";
420 case V4L2_CID_AUTO_WHITE_BALANCE: return "White Balance, Automatic";
421 case V4L2_CID_DO_WHITE_BALANCE: return "Do White Balance";
422 case V4L2_CID_RED_BALANCE: return "Red Balance";
423 case V4L2_CID_BLUE_BALANCE: return "Blue Balance";
424 case V4L2_CID_GAMMA: return "Gamma";
425 case V4L2_CID_EXPOSURE: return "Exposure";
426 case V4L2_CID_AUTOGAIN: return "Gain, Automatic";
427 case V4L2_CID_GAIN: return "Gain";
428 case V4L2_CID_HFLIP: return "Horizontal Flip";
429 case V4L2_CID_VFLIP: return "Vertical Flip";
430 case V4L2_CID_HCENTER: return "Horizontal Center";
431 case V4L2_CID_VCENTER: return "Vertical Center";
432 case V4L2_CID_POWER_LINE_FREQUENCY: return "Power Line Frequency";
433 case V4L2_CID_HUE_AUTO: return "Hue, Automatic";
434 case V4L2_CID_WHITE_BALANCE_TEMPERATURE: return "White Balance Temperature";
435 case V4L2_CID_SHARPNESS: return "Sharpness";
436 case V4L2_CID_BACKLIGHT_COMPENSATION: return "Backlight Compensation";
437 case V4L2_CID_CHROMA_AGC: return "Chroma AGC";
438 case V4L2_CID_CHROMA_GAIN: return "Chroma Gain";
439 case V4L2_CID_COLOR_KILLER: return "Color Killer";
440 case V4L2_CID_COLORFX: return "Color Effects";
441 case V4L2_CID_AUTOBRIGHTNESS: return "Brightness, Automatic";
442 case V4L2_CID_BAND_STOP_FILTER: return "Band-Stop Filter";
443 case V4L2_CID_ROTATE: return "Rotate";
444 case V4L2_CID_BG_COLOR: return "Background Color";
445
446 /* MPEG controls */
447 case V4L2_CID_MPEG_CLASS: return "MPEG Encoder Controls";
448 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ: return "Audio Sampling Frequency";
449 case V4L2_CID_MPEG_AUDIO_ENCODING: return "Audio Encoding";
450 case V4L2_CID_MPEG_AUDIO_L1_BITRATE: return "Audio Layer I Bitrate";
451 case V4L2_CID_MPEG_AUDIO_L2_BITRATE: return "Audio Layer II Bitrate";
452 case V4L2_CID_MPEG_AUDIO_L3_BITRATE: return "Audio Layer III Bitrate";
453 case V4L2_CID_MPEG_AUDIO_AAC_BITRATE: return "Audio AAC Bitrate";
454 case V4L2_CID_MPEG_AUDIO_AC3_BITRATE: return "Audio AC-3 Bitrate";
455 case V4L2_CID_MPEG_AUDIO_MODE: return "Audio Stereo Mode";
456 case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION: return "Audio Stereo Mode Extension";
457 case V4L2_CID_MPEG_AUDIO_EMPHASIS: return "Audio Emphasis";
458 case V4L2_CID_MPEG_AUDIO_CRC: return "Audio CRC";
459 case V4L2_CID_MPEG_AUDIO_MUTE: return "Audio Mute";
460 case V4L2_CID_MPEG_VIDEO_ENCODING: return "Video Encoding";
461 case V4L2_CID_MPEG_VIDEO_ASPECT: return "Video Aspect";
462 case V4L2_CID_MPEG_VIDEO_B_FRAMES: return "Video B Frames";
463 case V4L2_CID_MPEG_VIDEO_GOP_SIZE: return "Video GOP Size";
464 case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE: return "Video GOP Closure";
465 case V4L2_CID_MPEG_VIDEO_PULLDOWN: return "Video Pulldown";
466 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: return "Video Bitrate Mode";
467 case V4L2_CID_MPEG_VIDEO_BITRATE: return "Video Bitrate";
468 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK: return "Video Peak Bitrate";
469 case V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION: return "Video Temporal Decimation";
470 case V4L2_CID_MPEG_VIDEO_MUTE: return "Video Mute";
471 case V4L2_CID_MPEG_VIDEO_MUTE_YUV: return "Video Mute YUV";
472 case V4L2_CID_MPEG_STREAM_TYPE: return "Stream Type";
473 case V4L2_CID_MPEG_STREAM_PID_PMT: return "Stream PMT Program ID";
474 case V4L2_CID_MPEG_STREAM_PID_AUDIO: return "Stream Audio Program ID";
475 case V4L2_CID_MPEG_STREAM_PID_VIDEO: return "Stream Video Program ID";
476 case V4L2_CID_MPEG_STREAM_PID_PCR: return "Stream PCR Program ID";
477 case V4L2_CID_MPEG_STREAM_PES_ID_AUDIO: return "Stream PES Audio ID";
478 case V4L2_CID_MPEG_STREAM_PES_ID_VIDEO: return "Stream PES Video ID";
479 case V4L2_CID_MPEG_STREAM_VBI_FMT: return "Stream VBI Format";
480
481 /* CAMERA controls */
482 case V4L2_CID_CAMERA_CLASS: return "Camera Controls";
483 case V4L2_CID_EXPOSURE_AUTO: return "Auto Exposure";
484 case V4L2_CID_EXPOSURE_ABSOLUTE: return "Exposure Time, Absolute";
485 case V4L2_CID_EXPOSURE_AUTO_PRIORITY: return "Exposure, Dynamic Framerate";
486 case V4L2_CID_PAN_RELATIVE: return "Pan, Relative";
487 case V4L2_CID_TILT_RELATIVE: return "Tilt, Relative";
488 case V4L2_CID_PAN_RESET: return "Pan, Reset";
489 case V4L2_CID_TILT_RESET: return "Tilt, Reset";
490 case V4L2_CID_PAN_ABSOLUTE: return "Pan, Absolute";
491 case V4L2_CID_TILT_ABSOLUTE: return "Tilt, Absolute";
492 case V4L2_CID_FOCUS_ABSOLUTE: return "Focus, Absolute";
493 case V4L2_CID_FOCUS_RELATIVE: return "Focus, Relative";
494 case V4L2_CID_FOCUS_AUTO: return "Focus, Automatic";
495 case V4L2_CID_IRIS_ABSOLUTE: return "Iris, Absolute";
496 case V4L2_CID_IRIS_RELATIVE: return "Iris, Relative";
497 case V4L2_CID_ZOOM_ABSOLUTE: return "Zoom, Absolute";
498 case V4L2_CID_ZOOM_RELATIVE: return "Zoom, Relative";
499 case V4L2_CID_ZOOM_CONTINUOUS: return "Zoom, Continuous";
500 case V4L2_CID_PRIVACY: return "Privacy";
501
502 /* FM Radio Modulator control */
503 case V4L2_CID_FM_TX_CLASS: return "FM Radio Modulator Controls";
504 case V4L2_CID_RDS_TX_DEVIATION: return "RDS Signal Deviation";
505 case V4L2_CID_RDS_TX_PI: return "RDS Program ID";
506 case V4L2_CID_RDS_TX_PTY: return "RDS Program Type";
507 case V4L2_CID_RDS_TX_PS_NAME: return "RDS PS Name";
508 case V4L2_CID_RDS_TX_RADIO_TEXT: return "RDS Radio Text";
509 case V4L2_CID_AUDIO_LIMITER_ENABLED: return "Audio Limiter Feature Enabled";
510 case V4L2_CID_AUDIO_LIMITER_RELEASE_TIME: return "Audio Limiter Release Time";
511 case V4L2_CID_AUDIO_LIMITER_DEVIATION: return "Audio Limiter Deviation";
512 case V4L2_CID_AUDIO_COMPRESSION_ENABLED: return "Audio Compression Feature Enabled";
513 case V4L2_CID_AUDIO_COMPRESSION_GAIN: return "Audio Compression Gain";
514 case V4L2_CID_AUDIO_COMPRESSION_THRESHOLD: return "Audio Compression Threshold";
515 case V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME: return "Audio Compression Attack Time";
516 case V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME: return "Audio Compression Release Time";
517 case V4L2_CID_PILOT_TONE_ENABLED: return "Pilot Tone Feature Enabled";
518 case V4L2_CID_PILOT_TONE_DEVIATION: return "Pilot Tone Deviation";
519 case V4L2_CID_PILOT_TONE_FREQUENCY: return "Pilot Tone Frequency";
520 case V4L2_CID_TUNE_PREEMPHASIS: return "Pre-emphasis settings";
521 case V4L2_CID_TUNE_POWER_LEVEL: return "Tune Power Level";
522 case V4L2_CID_TUNE_ANTENNA_CAPACITOR: return "Tune Antenna Capacitor";
523
524 default:
525 return NULL;
526 }
527}
528EXPORT_SYMBOL(v4l2_ctrl_get_name);
529
530/* Fill in a struct v4l2_queryctrl */ 176/* Fill in a struct v4l2_queryctrl */
531int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 min, s32 max, s32 step, s32 def) 177int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 min, s32 max, s32 step, s32 def)
532{ 178{
533 const char *name = v4l2_ctrl_get_name(qctrl->id); 179 const char *name;
180
181 v4l2_ctrl_fill(qctrl->id, &name, &qctrl->type,
182 &min, &max, &step, &def, &qctrl->flags);
534 183
535 qctrl->flags = 0;
536 if (name == NULL) 184 if (name == NULL)
537 return -EINVAL; 185 return -EINVAL;
538 186
539 switch (qctrl->id) {
540 case V4L2_CID_AUDIO_MUTE:
541 case V4L2_CID_AUDIO_LOUDNESS:
542 case V4L2_CID_AUTO_WHITE_BALANCE:
543 case V4L2_CID_AUTOGAIN:
544 case V4L2_CID_HFLIP:
545 case V4L2_CID_VFLIP:
546 case V4L2_CID_HUE_AUTO:
547 case V4L2_CID_CHROMA_AGC:
548 case V4L2_CID_COLOR_KILLER:
549 case V4L2_CID_MPEG_AUDIO_MUTE:
550 case V4L2_CID_MPEG_VIDEO_MUTE:
551 case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE:
552 case V4L2_CID_MPEG_VIDEO_PULLDOWN:
553 case V4L2_CID_EXPOSURE_AUTO_PRIORITY:
554 case V4L2_CID_FOCUS_AUTO:
555 case V4L2_CID_PRIVACY:
556 case V4L2_CID_AUDIO_LIMITER_ENABLED:
557 case V4L2_CID_AUDIO_COMPRESSION_ENABLED:
558 case V4L2_CID_PILOT_TONE_ENABLED:
559 qctrl->type = V4L2_CTRL_TYPE_BOOLEAN;
560 min = 0;
561 max = step = 1;
562 break;
563 case V4L2_CID_PAN_RESET:
564 case V4L2_CID_TILT_RESET:
565 qctrl->type = V4L2_CTRL_TYPE_BUTTON;
566 qctrl->flags |= V4L2_CTRL_FLAG_WRITE_ONLY;
567 min = max = step = def = 0;
568 break;
569 case V4L2_CID_POWER_LINE_FREQUENCY:
570 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
571 case V4L2_CID_MPEG_AUDIO_ENCODING:
572 case V4L2_CID_MPEG_AUDIO_L1_BITRATE:
573 case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
574 case V4L2_CID_MPEG_AUDIO_L3_BITRATE:
575 case V4L2_CID_MPEG_AUDIO_AC3_BITRATE:
576 case V4L2_CID_MPEG_AUDIO_MODE:
577 case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION:
578 case V4L2_CID_MPEG_AUDIO_EMPHASIS:
579 case V4L2_CID_MPEG_AUDIO_CRC:
580 case V4L2_CID_MPEG_VIDEO_ENCODING:
581 case V4L2_CID_MPEG_VIDEO_ASPECT:
582 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
583 case V4L2_CID_MPEG_STREAM_TYPE:
584 case V4L2_CID_MPEG_STREAM_VBI_FMT:
585 case V4L2_CID_EXPOSURE_AUTO:
586 case V4L2_CID_COLORFX:
587 case V4L2_CID_TUNE_PREEMPHASIS:
588 qctrl->type = V4L2_CTRL_TYPE_MENU;
589 step = 1;
590 break;
591 case V4L2_CID_RDS_TX_PS_NAME:
592 case V4L2_CID_RDS_TX_RADIO_TEXT:
593 qctrl->type = V4L2_CTRL_TYPE_STRING;
594 break;
595 case V4L2_CID_USER_CLASS:
596 case V4L2_CID_CAMERA_CLASS:
597 case V4L2_CID_MPEG_CLASS:
598 case V4L2_CID_FM_TX_CLASS:
599 qctrl->type = V4L2_CTRL_TYPE_CTRL_CLASS;
600 qctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY;
601 min = max = step = def = 0;
602 break;
603 case V4L2_CID_BG_COLOR:
604 qctrl->type = V4L2_CTRL_TYPE_INTEGER;
605 step = 1;
606 min = 0;
607 /* Max is calculated as RGB888 that is 2^24 */
608 max = 0xFFFFFF;
609 break;
610 default:
611 qctrl->type = V4L2_CTRL_TYPE_INTEGER;
612 break;
613 }
614 switch (qctrl->id) {
615 case V4L2_CID_MPEG_AUDIO_ENCODING:
616 case V4L2_CID_MPEG_AUDIO_MODE:
617 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
618 case V4L2_CID_MPEG_VIDEO_B_FRAMES:
619 case V4L2_CID_MPEG_STREAM_TYPE:
620 qctrl->flags |= V4L2_CTRL_FLAG_UPDATE;
621 break;
622 case V4L2_CID_AUDIO_VOLUME:
623 case V4L2_CID_AUDIO_BALANCE:
624 case V4L2_CID_AUDIO_BASS:
625 case V4L2_CID_AUDIO_TREBLE:
626 case V4L2_CID_BRIGHTNESS:
627 case V4L2_CID_CONTRAST:
628 case V4L2_CID_SATURATION:
629 case V4L2_CID_HUE:
630 case V4L2_CID_RED_BALANCE:
631 case V4L2_CID_BLUE_BALANCE:
632 case V4L2_CID_GAMMA:
633 case V4L2_CID_SHARPNESS:
634 case V4L2_CID_CHROMA_GAIN:
635 case V4L2_CID_RDS_TX_DEVIATION:
636 case V4L2_CID_AUDIO_LIMITER_RELEASE_TIME:
637 case V4L2_CID_AUDIO_LIMITER_DEVIATION:
638 case V4L2_CID_AUDIO_COMPRESSION_GAIN:
639 case V4L2_CID_AUDIO_COMPRESSION_THRESHOLD:
640 case V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME:
641 case V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME:
642 case V4L2_CID_PILOT_TONE_DEVIATION:
643 case V4L2_CID_PILOT_TONE_FREQUENCY:
644 case V4L2_CID_TUNE_POWER_LEVEL:
645 case V4L2_CID_TUNE_ANTENNA_CAPACITOR:
646 qctrl->flags |= V4L2_CTRL_FLAG_SLIDER;
647 break;
648 case V4L2_CID_PAN_RELATIVE:
649 case V4L2_CID_TILT_RELATIVE:
650 case V4L2_CID_FOCUS_RELATIVE:
651 case V4L2_CID_IRIS_RELATIVE:
652 case V4L2_CID_ZOOM_RELATIVE:
653 qctrl->flags |= V4L2_CTRL_FLAG_WRITE_ONLY;
654 break;
655 }
656 qctrl->minimum = min; 187 qctrl->minimum = min;
657 qctrl->maximum = max; 188 qctrl->maximum = max;
658 qctrl->step = step; 189 qctrl->step = step;
@@ -850,7 +381,8 @@ struct v4l2_subdev *v4l2_i2c_new_subdev_board(struct v4l2_device *v4l2_dev,
850 381
851 /* Create the i2c client */ 382 /* Create the i2c client */
852 if (info->addr == 0 && probe_addrs) 383 if (info->addr == 0 && probe_addrs)
853 client = i2c_new_probed_device(adapter, info, probe_addrs); 384 client = i2c_new_probed_device(adapter, info, probe_addrs,
385 NULL);
854 else 386 else
855 client = i2c_new_device(adapter, info); 387 client = i2c_new_device(adapter, info);
856 388
diff --git a/drivers/media/video/v4l2-compat-ioctl32.c b/drivers/media/video/v4l2-compat-ioctl32.c
index d2f20c2acae2..073f01390cdd 100644
--- a/drivers/media/video/v4l2-compat-ioctl32.c
+++ b/drivers/media/video/v4l2-compat-ioctl32.c
@@ -228,11 +228,6 @@ static long native_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
228 228
229 if (file->f_op->unlocked_ioctl) 229 if (file->f_op->unlocked_ioctl)
230 ret = file->f_op->unlocked_ioctl(file, cmd, arg); 230 ret = file->f_op->unlocked_ioctl(file, cmd, arg);
231 else if (file->f_op->ioctl) {
232 lock_kernel();
233 ret = file->f_op->ioctl(file->f_path.dentry->d_inode, file, cmd, arg);
234 unlock_kernel();
235 }
236 231
237 return ret; 232 return ret;
238} 233}
@@ -973,7 +968,7 @@ long v4l2_compat_ioctl32(struct file *file, unsigned int cmd, unsigned long arg)
973{ 968{
974 long ret = -ENOIOCTLCMD; 969 long ret = -ENOIOCTLCMD;
975 970
976 if (!file->f_op->ioctl && !file->f_op->unlocked_ioctl) 971 if (!file->f_op->unlocked_ioctl)
977 return ret; 972 return ret;
978 973
979 switch (cmd) { 974 switch (cmd) {
diff --git a/drivers/media/video/v4l2-ctrls.c b/drivers/media/video/v4l2-ctrls.c
new file mode 100644
index 000000000000..ea8d32cd425d
--- /dev/null
+++ b/drivers/media/video/v4l2-ctrls.c
@@ -0,0 +1,1852 @@
1/*
2 V4L2 controls framework implementation.
3
4 Copyright (C) 2010 Hans Verkuil <hverkuil@xs4all.nl>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#include <linux/ctype.h>
22#include <linux/slab.h>
23#include <media/v4l2-ioctl.h>
24#include <media/v4l2-device.h>
25#include <media/v4l2-ctrls.h>
26#include <media/v4l2-dev.h>
27
28/* Internal temporary helper struct, one for each v4l2_ext_control */
29struct ctrl_helper {
30 /* The control corresponding to the v4l2_ext_control ID field. */
31 struct v4l2_ctrl *ctrl;
32 /* Used internally to mark whether this control was already
33 processed. */
34 bool handled;
35};
36
37/* Returns NULL or a character pointer array containing the menu for
38 the given control ID. The pointer array ends with a NULL pointer.
39 An empty string signifies a menu entry that is invalid. This allows
40 drivers to disable certain options if it is not supported. */
41const char **v4l2_ctrl_get_menu(u32 id)
42{
43 static const char *mpeg_audio_sampling_freq[] = {
44 "44.1 kHz",
45 "48 kHz",
46 "32 kHz",
47 NULL
48 };
49 static const char *mpeg_audio_encoding[] = {
50 "MPEG-1/2 Layer I",
51 "MPEG-1/2 Layer II",
52 "MPEG-1/2 Layer III",
53 "MPEG-2/4 AAC",
54 "AC-3",
55 NULL
56 };
57 static const char *mpeg_audio_l1_bitrate[] = {
58 "32 kbps",
59 "64 kbps",
60 "96 kbps",
61 "128 kbps",
62 "160 kbps",
63 "192 kbps",
64 "224 kbps",
65 "256 kbps",
66 "288 kbps",
67 "320 kbps",
68 "352 kbps",
69 "384 kbps",
70 "416 kbps",
71 "448 kbps",
72 NULL
73 };
74 static const char *mpeg_audio_l2_bitrate[] = {
75 "32 kbps",
76 "48 kbps",
77 "56 kbps",
78 "64 kbps",
79 "80 kbps",
80 "96 kbps",
81 "112 kbps",
82 "128 kbps",
83 "160 kbps",
84 "192 kbps",
85 "224 kbps",
86 "256 kbps",
87 "320 kbps",
88 "384 kbps",
89 NULL
90 };
91 static const char *mpeg_audio_l3_bitrate[] = {
92 "32 kbps",
93 "40 kbps",
94 "48 kbps",
95 "56 kbps",
96 "64 kbps",
97 "80 kbps",
98 "96 kbps",
99 "112 kbps",
100 "128 kbps",
101 "160 kbps",
102 "192 kbps",
103 "224 kbps",
104 "256 kbps",
105 "320 kbps",
106 NULL
107 };
108 static const char *mpeg_audio_ac3_bitrate[] = {
109 "32 kbps",
110 "40 kbps",
111 "48 kbps",
112 "56 kbps",
113 "64 kbps",
114 "80 kbps",
115 "96 kbps",
116 "112 kbps",
117 "128 kbps",
118 "160 kbps",
119 "192 kbps",
120 "224 kbps",
121 "256 kbps",
122 "320 kbps",
123 "384 kbps",
124 "448 kbps",
125 "512 kbps",
126 "576 kbps",
127 "640 kbps",
128 NULL
129 };
130 static const char *mpeg_audio_mode[] = {
131 "Stereo",
132 "Joint Stereo",
133 "Dual",
134 "Mono",
135 NULL
136 };
137 static const char *mpeg_audio_mode_extension[] = {
138 "Bound 4",
139 "Bound 8",
140 "Bound 12",
141 "Bound 16",
142 NULL
143 };
144 static const char *mpeg_audio_emphasis[] = {
145 "No Emphasis",
146 "50/15 us",
147 "CCITT J17",
148 NULL
149 };
150 static const char *mpeg_audio_crc[] = {
151 "No CRC",
152 "16-bit CRC",
153 NULL
154 };
155 static const char *mpeg_video_encoding[] = {
156 "MPEG-1",
157 "MPEG-2",
158 "MPEG-4 AVC",
159 NULL
160 };
161 static const char *mpeg_video_aspect[] = {
162 "1x1",
163 "4x3",
164 "16x9",
165 "2.21x1",
166 NULL
167 };
168 static const char *mpeg_video_bitrate_mode[] = {
169 "Variable Bitrate",
170 "Constant Bitrate",
171 NULL
172 };
173 static const char *mpeg_stream_type[] = {
174 "MPEG-2 Program Stream",
175 "MPEG-2 Transport Stream",
176 "MPEG-1 System Stream",
177 "MPEG-2 DVD-compatible Stream",
178 "MPEG-1 VCD-compatible Stream",
179 "MPEG-2 SVCD-compatible Stream",
180 NULL
181 };
182 static const char *mpeg_stream_vbi_fmt[] = {
183 "No VBI",
184 "Private packet, IVTV format",
185 NULL
186 };
187 static const char *camera_power_line_frequency[] = {
188 "Disabled",
189 "50 Hz",
190 "60 Hz",
191 NULL
192 };
193 static const char *camera_exposure_auto[] = {
194 "Auto Mode",
195 "Manual Mode",
196 "Shutter Priority Mode",
197 "Aperture Priority Mode",
198 NULL
199 };
200 static const char *colorfx[] = {
201 "None",
202 "Black & White",
203 "Sepia",
204 "Negative",
205 "Emboss",
206 "Sketch",
207 "Sky blue",
208 "Grass green",
209 "Skin whiten",
210 "Vivid",
211 NULL
212 };
213 static const char *tune_preemphasis[] = {
214 "No preemphasis",
215 "50 useconds",
216 "75 useconds",
217 NULL,
218 };
219
220 switch (id) {
221 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
222 return mpeg_audio_sampling_freq;
223 case V4L2_CID_MPEG_AUDIO_ENCODING:
224 return mpeg_audio_encoding;
225 case V4L2_CID_MPEG_AUDIO_L1_BITRATE:
226 return mpeg_audio_l1_bitrate;
227 case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
228 return mpeg_audio_l2_bitrate;
229 case V4L2_CID_MPEG_AUDIO_L3_BITRATE:
230 return mpeg_audio_l3_bitrate;
231 case V4L2_CID_MPEG_AUDIO_AC3_BITRATE:
232 return mpeg_audio_ac3_bitrate;
233 case V4L2_CID_MPEG_AUDIO_MODE:
234 return mpeg_audio_mode;
235 case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION:
236 return mpeg_audio_mode_extension;
237 case V4L2_CID_MPEG_AUDIO_EMPHASIS:
238 return mpeg_audio_emphasis;
239 case V4L2_CID_MPEG_AUDIO_CRC:
240 return mpeg_audio_crc;
241 case V4L2_CID_MPEG_VIDEO_ENCODING:
242 return mpeg_video_encoding;
243 case V4L2_CID_MPEG_VIDEO_ASPECT:
244 return mpeg_video_aspect;
245 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
246 return mpeg_video_bitrate_mode;
247 case V4L2_CID_MPEG_STREAM_TYPE:
248 return mpeg_stream_type;
249 case V4L2_CID_MPEG_STREAM_VBI_FMT:
250 return mpeg_stream_vbi_fmt;
251 case V4L2_CID_POWER_LINE_FREQUENCY:
252 return camera_power_line_frequency;
253 case V4L2_CID_EXPOSURE_AUTO:
254 return camera_exposure_auto;
255 case V4L2_CID_COLORFX:
256 return colorfx;
257 case V4L2_CID_TUNE_PREEMPHASIS:
258 return tune_preemphasis;
259 default:
260 return NULL;
261 }
262}
263EXPORT_SYMBOL(v4l2_ctrl_get_menu);
264
265/* Return the control name. */
266const char *v4l2_ctrl_get_name(u32 id)
267{
268 switch (id) {
269 /* USER controls */
270 /* Keep the order of the 'case's the same as in videodev2.h! */
271 case V4L2_CID_USER_CLASS: return "User Controls";
272 case V4L2_CID_BRIGHTNESS: return "Brightness";
273 case V4L2_CID_CONTRAST: return "Contrast";
274 case V4L2_CID_SATURATION: return "Saturation";
275 case V4L2_CID_HUE: return "Hue";
276 case V4L2_CID_AUDIO_VOLUME: return "Volume";
277 case V4L2_CID_AUDIO_BALANCE: return "Balance";
278 case V4L2_CID_AUDIO_BASS: return "Bass";
279 case V4L2_CID_AUDIO_TREBLE: return "Treble";
280 case V4L2_CID_AUDIO_MUTE: return "Mute";
281 case V4L2_CID_AUDIO_LOUDNESS: return "Loudness";
282 case V4L2_CID_BLACK_LEVEL: return "Black Level";
283 case V4L2_CID_AUTO_WHITE_BALANCE: return "White Balance, Automatic";
284 case V4L2_CID_DO_WHITE_BALANCE: return "Do White Balance";
285 case V4L2_CID_RED_BALANCE: return "Red Balance";
286 case V4L2_CID_BLUE_BALANCE: return "Blue Balance";
287 case V4L2_CID_GAMMA: return "Gamma";
288 case V4L2_CID_EXPOSURE: return "Exposure";
289 case V4L2_CID_AUTOGAIN: return "Gain, Automatic";
290 case V4L2_CID_GAIN: return "Gain";
291 case V4L2_CID_HFLIP: return "Horizontal Flip";
292 case V4L2_CID_VFLIP: return "Vertical Flip";
293 case V4L2_CID_HCENTER: return "Horizontal Center";
294 case V4L2_CID_VCENTER: return "Vertical Center";
295 case V4L2_CID_POWER_LINE_FREQUENCY: return "Power Line Frequency";
296 case V4L2_CID_HUE_AUTO: return "Hue, Automatic";
297 case V4L2_CID_WHITE_BALANCE_TEMPERATURE: return "White Balance Temperature";
298 case V4L2_CID_SHARPNESS: return "Sharpness";
299 case V4L2_CID_BACKLIGHT_COMPENSATION: return "Backlight Compensation";
300 case V4L2_CID_CHROMA_AGC: return "Chroma AGC";
301 case V4L2_CID_COLOR_KILLER: return "Color Killer";
302 case V4L2_CID_COLORFX: return "Color Effects";
303 case V4L2_CID_AUTOBRIGHTNESS: return "Brightness, Automatic";
304 case V4L2_CID_BAND_STOP_FILTER: return "Band-Stop Filter";
305 case V4L2_CID_ROTATE: return "Rotate";
306 case V4L2_CID_BG_COLOR: return "Background Color";
307 case V4L2_CID_CHROMA_GAIN: return "Chroma Gain";
308
309 /* MPEG controls */
310 /* Keep the order of the 'case's the same as in videodev2.h! */
311 case V4L2_CID_MPEG_CLASS: return "MPEG Encoder Controls";
312 case V4L2_CID_MPEG_STREAM_TYPE: return "Stream Type";
313 case V4L2_CID_MPEG_STREAM_PID_PMT: return "Stream PMT Program ID";
314 case V4L2_CID_MPEG_STREAM_PID_AUDIO: return "Stream Audio Program ID";
315 case V4L2_CID_MPEG_STREAM_PID_VIDEO: return "Stream Video Program ID";
316 case V4L2_CID_MPEG_STREAM_PID_PCR: return "Stream PCR Program ID";
317 case V4L2_CID_MPEG_STREAM_PES_ID_AUDIO: return "Stream PES Audio ID";
318 case V4L2_CID_MPEG_STREAM_PES_ID_VIDEO: return "Stream PES Video ID";
319 case V4L2_CID_MPEG_STREAM_VBI_FMT: return "Stream VBI Format";
320 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ: return "Audio Sampling Frequency";
321 case V4L2_CID_MPEG_AUDIO_ENCODING: return "Audio Encoding";
322 case V4L2_CID_MPEG_AUDIO_L1_BITRATE: return "Audio Layer I Bitrate";
323 case V4L2_CID_MPEG_AUDIO_L2_BITRATE: return "Audio Layer II Bitrate";
324 case V4L2_CID_MPEG_AUDIO_L3_BITRATE: return "Audio Layer III Bitrate";
325 case V4L2_CID_MPEG_AUDIO_MODE: return "Audio Stereo Mode";
326 case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION: return "Audio Stereo Mode Extension";
327 case V4L2_CID_MPEG_AUDIO_EMPHASIS: return "Audio Emphasis";
328 case V4L2_CID_MPEG_AUDIO_CRC: return "Audio CRC";
329 case V4L2_CID_MPEG_AUDIO_MUTE: return "Audio Mute";
330 case V4L2_CID_MPEG_AUDIO_AAC_BITRATE: return "Audio AAC Bitrate";
331 case V4L2_CID_MPEG_AUDIO_AC3_BITRATE: return "Audio AC-3 Bitrate";
332 case V4L2_CID_MPEG_VIDEO_ENCODING: return "Video Encoding";
333 case V4L2_CID_MPEG_VIDEO_ASPECT: return "Video Aspect";
334 case V4L2_CID_MPEG_VIDEO_B_FRAMES: return "Video B Frames";
335 case V4L2_CID_MPEG_VIDEO_GOP_SIZE: return "Video GOP Size";
336 case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE: return "Video GOP Closure";
337 case V4L2_CID_MPEG_VIDEO_PULLDOWN: return "Video Pulldown";
338 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: return "Video Bitrate Mode";
339 case V4L2_CID_MPEG_VIDEO_BITRATE: return "Video Bitrate";
340 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK: return "Video Peak Bitrate";
341 case V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION: return "Video Temporal Decimation";
342 case V4L2_CID_MPEG_VIDEO_MUTE: return "Video Mute";
343 case V4L2_CID_MPEG_VIDEO_MUTE_YUV: return "Video Mute YUV";
344
345 /* CAMERA controls */
346 /* Keep the order of the 'case's the same as in videodev2.h! */
347 case V4L2_CID_CAMERA_CLASS: return "Camera Controls";
348 case V4L2_CID_EXPOSURE_AUTO: return "Auto Exposure";
349 case V4L2_CID_EXPOSURE_ABSOLUTE: return "Exposure Time, Absolute";
350 case V4L2_CID_EXPOSURE_AUTO_PRIORITY: return "Exposure, Dynamic Framerate";
351 case V4L2_CID_PAN_RELATIVE: return "Pan, Relative";
352 case V4L2_CID_TILT_RELATIVE: return "Tilt, Relative";
353 case V4L2_CID_PAN_RESET: return "Pan, Reset";
354 case V4L2_CID_TILT_RESET: return "Tilt, Reset";
355 case V4L2_CID_PAN_ABSOLUTE: return "Pan, Absolute";
356 case V4L2_CID_TILT_ABSOLUTE: return "Tilt, Absolute";
357 case V4L2_CID_FOCUS_ABSOLUTE: return "Focus, Absolute";
358 case V4L2_CID_FOCUS_RELATIVE: return "Focus, Relative";
359 case V4L2_CID_FOCUS_AUTO: return "Focus, Automatic";
360 case V4L2_CID_ZOOM_ABSOLUTE: return "Zoom, Absolute";
361 case V4L2_CID_ZOOM_RELATIVE: return "Zoom, Relative";
362 case V4L2_CID_ZOOM_CONTINUOUS: return "Zoom, Continuous";
363 case V4L2_CID_PRIVACY: return "Privacy";
364 case V4L2_CID_IRIS_ABSOLUTE: return "Iris, Absolute";
365 case V4L2_CID_IRIS_RELATIVE: return "Iris, Relative";
366
367 /* FM Radio Modulator control */
368 /* Keep the order of the 'case's the same as in videodev2.h! */
369 case V4L2_CID_FM_TX_CLASS: return "FM Radio Modulator Controls";
370 case V4L2_CID_RDS_TX_DEVIATION: return "RDS Signal Deviation";
371 case V4L2_CID_RDS_TX_PI: return "RDS Program ID";
372 case V4L2_CID_RDS_TX_PTY: return "RDS Program Type";
373 case V4L2_CID_RDS_TX_PS_NAME: return "RDS PS Name";
374 case V4L2_CID_RDS_TX_RADIO_TEXT: return "RDS Radio Text";
375 case V4L2_CID_AUDIO_LIMITER_ENABLED: return "Audio Limiter Feature Enabled";
376 case V4L2_CID_AUDIO_LIMITER_RELEASE_TIME: return "Audio Limiter Release Time";
377 case V4L2_CID_AUDIO_LIMITER_DEVIATION: return "Audio Limiter Deviation";
378 case V4L2_CID_AUDIO_COMPRESSION_ENABLED: return "Audio Compression Feature Enabled";
379 case V4L2_CID_AUDIO_COMPRESSION_GAIN: return "Audio Compression Gain";
380 case V4L2_CID_AUDIO_COMPRESSION_THRESHOLD: return "Audio Compression Threshold";
381 case V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME: return "Audio Compression Attack Time";
382 case V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME: return "Audio Compression Release Time";
383 case V4L2_CID_PILOT_TONE_ENABLED: return "Pilot Tone Feature Enabled";
384 case V4L2_CID_PILOT_TONE_DEVIATION: return "Pilot Tone Deviation";
385 case V4L2_CID_PILOT_TONE_FREQUENCY: return "Pilot Tone Frequency";
386 case V4L2_CID_TUNE_PREEMPHASIS: return "Pre-emphasis settings";
387 case V4L2_CID_TUNE_POWER_LEVEL: return "Tune Power Level";
388 case V4L2_CID_TUNE_ANTENNA_CAPACITOR: return "Tune Antenna Capacitor";
389
390 default:
391 return NULL;
392 }
393}
394EXPORT_SYMBOL(v4l2_ctrl_get_name);
395
396void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
397 s32 *min, s32 *max, s32 *step, s32 *def, u32 *flags)
398{
399 *name = v4l2_ctrl_get_name(id);
400 *flags = 0;
401
402 switch (id) {
403 case V4L2_CID_AUDIO_MUTE:
404 case V4L2_CID_AUDIO_LOUDNESS:
405 case V4L2_CID_AUTO_WHITE_BALANCE:
406 case V4L2_CID_AUTOGAIN:
407 case V4L2_CID_HFLIP:
408 case V4L2_CID_VFLIP:
409 case V4L2_CID_HUE_AUTO:
410 case V4L2_CID_CHROMA_AGC:
411 case V4L2_CID_COLOR_KILLER:
412 case V4L2_CID_MPEG_AUDIO_MUTE:
413 case V4L2_CID_MPEG_VIDEO_MUTE:
414 case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE:
415 case V4L2_CID_MPEG_VIDEO_PULLDOWN:
416 case V4L2_CID_EXPOSURE_AUTO_PRIORITY:
417 case V4L2_CID_FOCUS_AUTO:
418 case V4L2_CID_PRIVACY:
419 case V4L2_CID_AUDIO_LIMITER_ENABLED:
420 case V4L2_CID_AUDIO_COMPRESSION_ENABLED:
421 case V4L2_CID_PILOT_TONE_ENABLED:
422 *type = V4L2_CTRL_TYPE_BOOLEAN;
423 *min = 0;
424 *max = *step = 1;
425 break;
426 case V4L2_CID_PAN_RESET:
427 case V4L2_CID_TILT_RESET:
428 *type = V4L2_CTRL_TYPE_BUTTON;
429 *flags |= V4L2_CTRL_FLAG_WRITE_ONLY;
430 *min = *max = *step = *def = 0;
431 break;
432 case V4L2_CID_POWER_LINE_FREQUENCY:
433 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
434 case V4L2_CID_MPEG_AUDIO_ENCODING:
435 case V4L2_CID_MPEG_AUDIO_L1_BITRATE:
436 case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
437 case V4L2_CID_MPEG_AUDIO_L3_BITRATE:
438 case V4L2_CID_MPEG_AUDIO_AC3_BITRATE:
439 case V4L2_CID_MPEG_AUDIO_MODE:
440 case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION:
441 case V4L2_CID_MPEG_AUDIO_EMPHASIS:
442 case V4L2_CID_MPEG_AUDIO_CRC:
443 case V4L2_CID_MPEG_VIDEO_ENCODING:
444 case V4L2_CID_MPEG_VIDEO_ASPECT:
445 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
446 case V4L2_CID_MPEG_STREAM_TYPE:
447 case V4L2_CID_MPEG_STREAM_VBI_FMT:
448 case V4L2_CID_EXPOSURE_AUTO:
449 case V4L2_CID_COLORFX:
450 case V4L2_CID_TUNE_PREEMPHASIS:
451 *type = V4L2_CTRL_TYPE_MENU;
452 break;
453 case V4L2_CID_RDS_TX_PS_NAME:
454 case V4L2_CID_RDS_TX_RADIO_TEXT:
455 *type = V4L2_CTRL_TYPE_STRING;
456 break;
457 case V4L2_CID_USER_CLASS:
458 case V4L2_CID_CAMERA_CLASS:
459 case V4L2_CID_MPEG_CLASS:
460 case V4L2_CID_FM_TX_CLASS:
461 *type = V4L2_CTRL_TYPE_CTRL_CLASS;
462 /* You can neither read not write these */
463 *flags |= V4L2_CTRL_FLAG_READ_ONLY | V4L2_CTRL_FLAG_WRITE_ONLY;
464 *min = *max = *step = *def = 0;
465 break;
466 case V4L2_CID_BG_COLOR:
467 *type = V4L2_CTRL_TYPE_INTEGER;
468 *step = 1;
469 *min = 0;
470 /* Max is calculated as RGB888 that is 2^24 */
471 *max = 0xFFFFFF;
472 break;
473 default:
474 *type = V4L2_CTRL_TYPE_INTEGER;
475 break;
476 }
477 switch (id) {
478 case V4L2_CID_MPEG_AUDIO_ENCODING:
479 case V4L2_CID_MPEG_AUDIO_MODE:
480 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
481 case V4L2_CID_MPEG_VIDEO_B_FRAMES:
482 case V4L2_CID_MPEG_STREAM_TYPE:
483 *flags |= V4L2_CTRL_FLAG_UPDATE;
484 break;
485 case V4L2_CID_AUDIO_VOLUME:
486 case V4L2_CID_AUDIO_BALANCE:
487 case V4L2_CID_AUDIO_BASS:
488 case V4L2_CID_AUDIO_TREBLE:
489 case V4L2_CID_BRIGHTNESS:
490 case V4L2_CID_CONTRAST:
491 case V4L2_CID_SATURATION:
492 case V4L2_CID_HUE:
493 case V4L2_CID_RED_BALANCE:
494 case V4L2_CID_BLUE_BALANCE:
495 case V4L2_CID_GAMMA:
496 case V4L2_CID_SHARPNESS:
497 case V4L2_CID_CHROMA_GAIN:
498 case V4L2_CID_RDS_TX_DEVIATION:
499 case V4L2_CID_AUDIO_LIMITER_RELEASE_TIME:
500 case V4L2_CID_AUDIO_LIMITER_DEVIATION:
501 case V4L2_CID_AUDIO_COMPRESSION_GAIN:
502 case V4L2_CID_AUDIO_COMPRESSION_THRESHOLD:
503 case V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME:
504 case V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME:
505 case V4L2_CID_PILOT_TONE_DEVIATION:
506 case V4L2_CID_PILOT_TONE_FREQUENCY:
507 case V4L2_CID_TUNE_POWER_LEVEL:
508 case V4L2_CID_TUNE_ANTENNA_CAPACITOR:
509 *flags |= V4L2_CTRL_FLAG_SLIDER;
510 break;
511 case V4L2_CID_PAN_RELATIVE:
512 case V4L2_CID_TILT_RELATIVE:
513 case V4L2_CID_FOCUS_RELATIVE:
514 case V4L2_CID_IRIS_RELATIVE:
515 case V4L2_CID_ZOOM_RELATIVE:
516 *flags |= V4L2_CTRL_FLAG_WRITE_ONLY;
517 break;
518 }
519}
520EXPORT_SYMBOL(v4l2_ctrl_fill);
521
522/* Helper function to determine whether the control type is compatible with
523 VIDIOC_G/S_CTRL. */
524static bool type_is_int(const struct v4l2_ctrl *ctrl)
525{
526 switch (ctrl->type) {
527 case V4L2_CTRL_TYPE_INTEGER64:
528 case V4L2_CTRL_TYPE_STRING:
529 /* Nope, these need v4l2_ext_control */
530 return false;
531 default:
532 return true;
533 }
534}
535
536/* Helper function: copy the current control value back to the caller */
537static int cur_to_user(struct v4l2_ext_control *c,
538 struct v4l2_ctrl *ctrl)
539{
540 u32 len;
541
542 switch (ctrl->type) {
543 case V4L2_CTRL_TYPE_STRING:
544 len = strlen(ctrl->cur.string);
545 if (c->size < len + 1) {
546 c->size = len + 1;
547 return -ENOSPC;
548 }
549 return copy_to_user(c->string, ctrl->cur.string,
550 len + 1) ? -EFAULT : 0;
551 case V4L2_CTRL_TYPE_INTEGER64:
552 c->value64 = ctrl->cur.val64;
553 break;
554 default:
555 c->value = ctrl->cur.val;
556 break;
557 }
558 return 0;
559}
560
561/* Helper function: copy the caller-provider value as the new control value */
562static int user_to_new(struct v4l2_ext_control *c,
563 struct v4l2_ctrl *ctrl)
564{
565 int ret;
566 u32 size;
567
568 ctrl->has_new = 1;
569 switch (ctrl->type) {
570 case V4L2_CTRL_TYPE_INTEGER64:
571 ctrl->val64 = c->value64;
572 break;
573 case V4L2_CTRL_TYPE_STRING:
574 size = c->size;
575 if (size == 0)
576 return -ERANGE;
577 if (size > ctrl->maximum + 1)
578 size = ctrl->maximum + 1;
579 ret = copy_from_user(ctrl->string, c->string, size);
580 if (!ret) {
581 char last = ctrl->string[size - 1];
582
583 ctrl->string[size - 1] = 0;
584 /* If the string was longer than ctrl->maximum,
585 then return an error. */
586 if (strlen(ctrl->string) == ctrl->maximum && last)
587 return -ERANGE;
588 }
589 return ret ? -EFAULT : 0;
590 default:
591 ctrl->val = c->value;
592 break;
593 }
594 return 0;
595}
596
597/* Helper function: copy the new control value back to the caller */
598static int new_to_user(struct v4l2_ext_control *c,
599 struct v4l2_ctrl *ctrl)
600{
601 u32 len;
602
603 switch (ctrl->type) {
604 case V4L2_CTRL_TYPE_STRING:
605 len = strlen(ctrl->string);
606 if (c->size < len + 1) {
607 c->size = ctrl->maximum + 1;
608 return -ENOSPC;
609 }
610 return copy_to_user(c->string, ctrl->string,
611 len + 1) ? -EFAULT : 0;
612 case V4L2_CTRL_TYPE_INTEGER64:
613 c->value64 = ctrl->val64;
614 break;
615 default:
616 c->value = ctrl->val;
617 break;
618 }
619 return 0;
620}
621
622/* Copy the new value to the current value. */
623static void new_to_cur(struct v4l2_ctrl *ctrl)
624{
625 if (ctrl == NULL)
626 return;
627 switch (ctrl->type) {
628 case V4L2_CTRL_TYPE_STRING:
629 /* strings are always 0-terminated */
630 strcpy(ctrl->cur.string, ctrl->string);
631 break;
632 case V4L2_CTRL_TYPE_INTEGER64:
633 ctrl->cur.val64 = ctrl->val64;
634 break;
635 default:
636 ctrl->cur.val = ctrl->val;
637 break;
638 }
639}
640
641/* Copy the current value to the new value */
642static void cur_to_new(struct v4l2_ctrl *ctrl)
643{
644 if (ctrl == NULL)
645 return;
646 switch (ctrl->type) {
647 case V4L2_CTRL_TYPE_STRING:
648 /* strings are always 0-terminated */
649 strcpy(ctrl->string, ctrl->cur.string);
650 break;
651 case V4L2_CTRL_TYPE_INTEGER64:
652 ctrl->val64 = ctrl->cur.val64;
653 break;
654 default:
655 ctrl->val = ctrl->cur.val;
656 break;
657 }
658}
659
660/* Return non-zero if one or more of the controls in the cluster has a new
661 value that differs from the current value. */
662static int cluster_changed(struct v4l2_ctrl *master)
663{
664 int diff = 0;
665 int i;
666
667 for (i = 0; !diff && i < master->ncontrols; i++) {
668 struct v4l2_ctrl *ctrl = master->cluster[i];
669
670 if (ctrl == NULL)
671 continue;
672 switch (ctrl->type) {
673 case V4L2_CTRL_TYPE_BUTTON:
674 /* Button controls are always 'different' */
675 return 1;
676 case V4L2_CTRL_TYPE_STRING:
677 /* strings are always 0-terminated */
678 diff = strcmp(ctrl->string, ctrl->cur.string);
679 break;
680 case V4L2_CTRL_TYPE_INTEGER64:
681 diff = ctrl->val64 != ctrl->cur.val64;
682 break;
683 default:
684 diff = ctrl->val != ctrl->cur.val;
685 break;
686 }
687 }
688 return diff;
689}
690
691/* Validate a new control */
692static int validate_new(struct v4l2_ctrl *ctrl)
693{
694 s32 val = ctrl->val;
695 char *s = ctrl->string;
696 u32 offset;
697 size_t len;
698
699 switch (ctrl->type) {
700 case V4L2_CTRL_TYPE_INTEGER:
701 /* Round towards the closest legal value */
702 val += ctrl->step / 2;
703 if (val < ctrl->minimum)
704 val = ctrl->minimum;
705 if (val > ctrl->maximum)
706 val = ctrl->maximum;
707 offset = val - ctrl->minimum;
708 offset = ctrl->step * (offset / ctrl->step);
709 val = ctrl->minimum + offset;
710 ctrl->val = val;
711 return 0;
712
713 case V4L2_CTRL_TYPE_BOOLEAN:
714 ctrl->val = !!ctrl->val;
715 return 0;
716
717 case V4L2_CTRL_TYPE_MENU:
718 if (val < ctrl->minimum || val > ctrl->maximum)
719 return -ERANGE;
720 if (ctrl->qmenu[val][0] == '\0' ||
721 (ctrl->menu_skip_mask & (1 << val)))
722 return -EINVAL;
723 return 0;
724
725 case V4L2_CTRL_TYPE_BUTTON:
726 case V4L2_CTRL_TYPE_CTRL_CLASS:
727 ctrl->val64 = 0;
728 return 0;
729
730 case V4L2_CTRL_TYPE_INTEGER64:
731 return 0;
732
733 case V4L2_CTRL_TYPE_STRING:
734 len = strlen(s);
735 if (len < ctrl->minimum)
736 return -ERANGE;
737 if ((len - ctrl->minimum) % ctrl->step)
738 return -ERANGE;
739 return 0;
740
741 default:
742 return -EINVAL;
743 }
744}
745
746static inline u32 node2id(struct list_head *node)
747{
748 return list_entry(node, struct v4l2_ctrl_ref, node)->ctrl->id;
749}
750
751/* Set the handler's error code if it wasn't set earlier already */
752static inline int handler_set_err(struct v4l2_ctrl_handler *hdl, int err)
753{
754 if (hdl->error == 0)
755 hdl->error = err;
756 return err;
757}
758
759/* Initialize the handler */
760int v4l2_ctrl_handler_init(struct v4l2_ctrl_handler *hdl,
761 unsigned nr_of_controls_hint)
762{
763 mutex_init(&hdl->lock);
764 INIT_LIST_HEAD(&hdl->ctrls);
765 INIT_LIST_HEAD(&hdl->ctrl_refs);
766 hdl->nr_of_buckets = 1 + nr_of_controls_hint / 8;
767 hdl->buckets = kzalloc(sizeof(hdl->buckets[0]) * hdl->nr_of_buckets,
768 GFP_KERNEL);
769 hdl->error = hdl->buckets ? 0 : -ENOMEM;
770 return hdl->error;
771}
772EXPORT_SYMBOL(v4l2_ctrl_handler_init);
773
774/* Free all controls and control refs */
775void v4l2_ctrl_handler_free(struct v4l2_ctrl_handler *hdl)
776{
777 struct v4l2_ctrl_ref *ref, *next_ref;
778 struct v4l2_ctrl *ctrl, *next_ctrl;
779
780 if (hdl == NULL || hdl->buckets == NULL)
781 return;
782
783 mutex_lock(&hdl->lock);
784 /* Free all nodes */
785 list_for_each_entry_safe(ref, next_ref, &hdl->ctrl_refs, node) {
786 list_del(&ref->node);
787 kfree(ref);
788 }
789 /* Free all controls owned by the handler */
790 list_for_each_entry_safe(ctrl, next_ctrl, &hdl->ctrls, node) {
791 list_del(&ctrl->node);
792 kfree(ctrl);
793 }
794 kfree(hdl->buckets);
795 hdl->buckets = NULL;
796 hdl->cached = NULL;
797 hdl->error = 0;
798 mutex_unlock(&hdl->lock);
799}
800EXPORT_SYMBOL(v4l2_ctrl_handler_free);
801
802/* For backwards compatibility: V4L2_CID_PRIVATE_BASE should no longer
803 be used except in G_CTRL, S_CTRL, QUERYCTRL and QUERYMENU when dealing
804 with applications that do not use the NEXT_CTRL flag.
805
806 We just find the n-th private user control. It's O(N), but that should not
807 be an issue in this particular case. */
808static struct v4l2_ctrl_ref *find_private_ref(
809 struct v4l2_ctrl_handler *hdl, u32 id)
810{
811 struct v4l2_ctrl_ref *ref;
812
813 id -= V4L2_CID_PRIVATE_BASE;
814 list_for_each_entry(ref, &hdl->ctrl_refs, node) {
815 /* Search for private user controls that are compatible with
816 VIDIOC_G/S_CTRL. */
817 if (V4L2_CTRL_ID2CLASS(ref->ctrl->id) == V4L2_CTRL_CLASS_USER &&
818 V4L2_CTRL_DRIVER_PRIV(ref->ctrl->id)) {
819 if (!type_is_int(ref->ctrl))
820 continue;
821 if (id == 0)
822 return ref;
823 id--;
824 }
825 }
826 return NULL;
827}
828
829/* Find a control with the given ID. */
830static struct v4l2_ctrl_ref *find_ref(struct v4l2_ctrl_handler *hdl, u32 id)
831{
832 struct v4l2_ctrl_ref *ref;
833 int bucket;
834
835 id &= V4L2_CTRL_ID_MASK;
836
837 /* Old-style private controls need special handling */
838 if (id >= V4L2_CID_PRIVATE_BASE)
839 return find_private_ref(hdl, id);
840 bucket = id % hdl->nr_of_buckets;
841
842 /* Simple optimization: cache the last control found */
843 if (hdl->cached && hdl->cached->ctrl->id == id)
844 return hdl->cached;
845
846 /* Not in cache, search the hash */
847 ref = hdl->buckets ? hdl->buckets[bucket] : NULL;
848 while (ref && ref->ctrl->id != id)
849 ref = ref->next;
850
851 if (ref)
852 hdl->cached = ref; /* cache it! */
853 return ref;
854}
855
856/* Find a control with the given ID. Take the handler's lock first. */
857static struct v4l2_ctrl_ref *find_ref_lock(
858 struct v4l2_ctrl_handler *hdl, u32 id)
859{
860 struct v4l2_ctrl_ref *ref = NULL;
861
862 if (hdl) {
863 mutex_lock(&hdl->lock);
864 ref = find_ref(hdl, id);
865 mutex_unlock(&hdl->lock);
866 }
867 return ref;
868}
869
870/* Find a control with the given ID. */
871struct v4l2_ctrl *v4l2_ctrl_find(struct v4l2_ctrl_handler *hdl, u32 id)
872{
873 struct v4l2_ctrl_ref *ref = find_ref_lock(hdl, id);
874
875 return ref ? ref->ctrl : NULL;
876}
877EXPORT_SYMBOL(v4l2_ctrl_find);
878
879/* Allocate a new v4l2_ctrl_ref and hook it into the handler. */
880static int handler_new_ref(struct v4l2_ctrl_handler *hdl,
881 struct v4l2_ctrl *ctrl)
882{
883 struct v4l2_ctrl_ref *ref;
884 struct v4l2_ctrl_ref *new_ref;
885 u32 id = ctrl->id;
886 u32 class_ctrl = V4L2_CTRL_ID2CLASS(id) | 1;
887 int bucket = id % hdl->nr_of_buckets; /* which bucket to use */
888
889 /* Automatically add the control class if it is not yet present. */
890 if (id != class_ctrl && find_ref_lock(hdl, class_ctrl) == NULL)
891 if (!v4l2_ctrl_new_std(hdl, NULL, class_ctrl, 0, 0, 0, 0))
892 return hdl->error;
893
894 if (hdl->error)
895 return hdl->error;
896
897 new_ref = kzalloc(sizeof(*new_ref), GFP_KERNEL);
898 if (!new_ref)
899 return handler_set_err(hdl, -ENOMEM);
900 new_ref->ctrl = ctrl;
901 if (ctrl->handler == hdl) {
902 /* By default each control starts in a cluster of its own.
903 new_ref->ctrl is basically a cluster array with one
904 element, so that's perfect to use as the cluster pointer.
905 But only do this for the handler that owns the control. */
906 ctrl->cluster = &new_ref->ctrl;
907 ctrl->ncontrols = 1;
908 }
909
910 INIT_LIST_HEAD(&new_ref->node);
911
912 mutex_lock(&hdl->lock);
913
914 /* Add immediately at the end of the list if the list is empty, or if
915 the last element in the list has a lower ID.
916 This ensures that when elements are added in ascending order the
917 insertion is an O(1) operation. */
918 if (list_empty(&hdl->ctrl_refs) || id > node2id(hdl->ctrl_refs.prev)) {
919 list_add_tail(&new_ref->node, &hdl->ctrl_refs);
920 goto insert_in_hash;
921 }
922
923 /* Find insert position in sorted list */
924 list_for_each_entry(ref, &hdl->ctrl_refs, node) {
925 if (ref->ctrl->id < id)
926 continue;
927 /* Don't add duplicates */
928 if (ref->ctrl->id == id) {
929 kfree(new_ref);
930 goto unlock;
931 }
932 list_add(&new_ref->node, ref->node.prev);
933 break;
934 }
935
936insert_in_hash:
937 /* Insert the control node in the hash */
938 new_ref->next = hdl->buckets[bucket];
939 hdl->buckets[bucket] = new_ref;
940
941unlock:
942 mutex_unlock(&hdl->lock);
943 return 0;
944}
945
946/* Add a new control */
947static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl,
948 const struct v4l2_ctrl_ops *ops,
949 u32 id, const char *name, enum v4l2_ctrl_type type,
950 s32 min, s32 max, u32 step, s32 def,
951 u32 flags, const char **qmenu, void *priv)
952{
953 struct v4l2_ctrl *ctrl;
954 unsigned sz_extra = 0;
955
956 if (hdl->error)
957 return NULL;
958
959 /* Sanity checks */
960 if (id == 0 || name == NULL || id >= V4L2_CID_PRIVATE_BASE ||
961 def < min || def > max || max < min ||
962 (type == V4L2_CTRL_TYPE_INTEGER && step == 0) ||
963 (type == V4L2_CTRL_TYPE_MENU && qmenu == NULL) ||
964 (type == V4L2_CTRL_TYPE_STRING && max == 0)) {
965 handler_set_err(hdl, -ERANGE);
966 return NULL;
967 }
968
969 if (type == V4L2_CTRL_TYPE_BUTTON)
970 flags |= V4L2_CTRL_FLAG_WRITE_ONLY;
971 else if (type == V4L2_CTRL_TYPE_CTRL_CLASS)
972 flags |= V4L2_CTRL_FLAG_READ_ONLY;
973 else if (type == V4L2_CTRL_TYPE_STRING)
974 sz_extra += 2 * (max + 1);
975
976 ctrl = kzalloc(sizeof(*ctrl) + sz_extra, GFP_KERNEL);
977 if (ctrl == NULL) {
978 handler_set_err(hdl, -ENOMEM);
979 return NULL;
980 }
981
982 INIT_LIST_HEAD(&ctrl->node);
983 ctrl->handler = hdl;
984 ctrl->ops = ops;
985 ctrl->id = id;
986 ctrl->name = name;
987 ctrl->type = type;
988 ctrl->flags = flags;
989 ctrl->minimum = min;
990 ctrl->maximum = max;
991 ctrl->step = step;
992 ctrl->qmenu = qmenu;
993 ctrl->priv = priv;
994 ctrl->cur.val = ctrl->val = ctrl->default_value = def;
995
996 if (ctrl->type == V4L2_CTRL_TYPE_STRING) {
997 ctrl->cur.string = (char *)&ctrl[1] + sz_extra - (max + 1);
998 ctrl->string = (char *)&ctrl[1] + sz_extra - 2 * (max + 1);
999 if (ctrl->minimum)
1000 memset(ctrl->cur.string, ' ', ctrl->minimum);
1001 }
1002 if (handler_new_ref(hdl, ctrl)) {
1003 kfree(ctrl);
1004 return NULL;
1005 }
1006 mutex_lock(&hdl->lock);
1007 list_add_tail(&ctrl->node, &hdl->ctrls);
1008 mutex_unlock(&hdl->lock);
1009 return ctrl;
1010}
1011
1012struct v4l2_ctrl *v4l2_ctrl_new_custom(struct v4l2_ctrl_handler *hdl,
1013 const struct v4l2_ctrl_config *cfg, void *priv)
1014{
1015 bool is_menu;
1016 struct v4l2_ctrl *ctrl;
1017 const char *name = cfg->name;
1018 const char **qmenu = cfg->qmenu;
1019 enum v4l2_ctrl_type type = cfg->type;
1020 u32 flags = cfg->flags;
1021 s32 min = cfg->min;
1022 s32 max = cfg->max;
1023 u32 step = cfg->step;
1024 s32 def = cfg->def;
1025
1026 if (name == NULL)
1027 v4l2_ctrl_fill(cfg->id, &name, &type, &min, &max, &step,
1028 &def, &flags);
1029
1030 is_menu = (cfg->type == V4L2_CTRL_TYPE_MENU);
1031 if (is_menu)
1032 WARN_ON(step);
1033 else
1034 WARN_ON(cfg->menu_skip_mask);
1035 if (is_menu && qmenu == NULL)
1036 qmenu = v4l2_ctrl_get_menu(cfg->id);
1037
1038 ctrl = v4l2_ctrl_new(hdl, cfg->ops, cfg->id, name,
1039 type, min, max,
1040 is_menu ? cfg->menu_skip_mask : step,
1041 def, flags, qmenu, priv);
1042 if (ctrl) {
1043 ctrl->is_private = cfg->is_private;
1044 ctrl->is_volatile = cfg->is_volatile;
1045 }
1046 return ctrl;
1047}
1048EXPORT_SYMBOL(v4l2_ctrl_new_custom);
1049
1050/* Helper function for standard non-menu controls */
1051struct v4l2_ctrl *v4l2_ctrl_new_std(struct v4l2_ctrl_handler *hdl,
1052 const struct v4l2_ctrl_ops *ops,
1053 u32 id, s32 min, s32 max, u32 step, s32 def)
1054{
1055 const char *name;
1056 enum v4l2_ctrl_type type;
1057 u32 flags;
1058
1059 v4l2_ctrl_fill(id, &name, &type, &min, &max, &step, &def, &flags);
1060 if (type == V4L2_CTRL_TYPE_MENU) {
1061 handler_set_err(hdl, -EINVAL);
1062 return NULL;
1063 }
1064 return v4l2_ctrl_new(hdl, ops, id, name, type,
1065 min, max, step, def, flags, NULL, NULL);
1066}
1067EXPORT_SYMBOL(v4l2_ctrl_new_std);
1068
1069/* Helper function for standard menu controls */
1070struct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_ctrl_handler *hdl,
1071 const struct v4l2_ctrl_ops *ops,
1072 u32 id, s32 max, s32 mask, s32 def)
1073{
1074 const char **qmenu = v4l2_ctrl_get_menu(id);
1075 const char *name;
1076 enum v4l2_ctrl_type type;
1077 s32 min;
1078 s32 step;
1079 u32 flags;
1080
1081 v4l2_ctrl_fill(id, &name, &type, &min, &max, &step, &def, &flags);
1082 if (type != V4L2_CTRL_TYPE_MENU) {
1083 handler_set_err(hdl, -EINVAL);
1084 return NULL;
1085 }
1086 return v4l2_ctrl_new(hdl, ops, id, name, type,
1087 0, max, mask, def, flags, qmenu, NULL);
1088}
1089EXPORT_SYMBOL(v4l2_ctrl_new_std_menu);
1090
1091/* Add a control from another handler to this handler */
1092struct v4l2_ctrl *v4l2_ctrl_add_ctrl(struct v4l2_ctrl_handler *hdl,
1093 struct v4l2_ctrl *ctrl)
1094{
1095 if (hdl == NULL || hdl->error)
1096 return NULL;
1097 if (ctrl == NULL) {
1098 handler_set_err(hdl, -EINVAL);
1099 return NULL;
1100 }
1101 if (ctrl->handler == hdl)
1102 return ctrl;
1103 return handler_new_ref(hdl, ctrl) ? NULL : ctrl;
1104}
1105EXPORT_SYMBOL(v4l2_ctrl_add_ctrl);
1106
1107/* Add the controls from another handler to our own. */
1108int v4l2_ctrl_add_handler(struct v4l2_ctrl_handler *hdl,
1109 struct v4l2_ctrl_handler *add)
1110{
1111 struct v4l2_ctrl *ctrl;
1112 int ret = 0;
1113
1114 /* Do nothing if either handler is NULL or if they are the same */
1115 if (!hdl || !add || hdl == add)
1116 return 0;
1117 if (hdl->error)
1118 return hdl->error;
1119 mutex_lock(&add->lock);
1120 list_for_each_entry(ctrl, &add->ctrls, node) {
1121 /* Skip handler-private controls. */
1122 if (ctrl->is_private)
1123 continue;
1124 ret = handler_new_ref(hdl, ctrl);
1125 if (ret)
1126 break;
1127 }
1128 mutex_unlock(&add->lock);
1129 return ret;
1130}
1131EXPORT_SYMBOL(v4l2_ctrl_add_handler);
1132
1133/* Cluster controls */
1134void v4l2_ctrl_cluster(unsigned ncontrols, struct v4l2_ctrl **controls)
1135{
1136 int i;
1137
1138 /* The first control is the master control and it must not be NULL */
1139 BUG_ON(controls[0] == NULL);
1140
1141 for (i = 0; i < ncontrols; i++) {
1142 if (controls[i]) {
1143 controls[i]->cluster = controls;
1144 controls[i]->ncontrols = ncontrols;
1145 }
1146 }
1147}
1148EXPORT_SYMBOL(v4l2_ctrl_cluster);
1149
1150/* Activate/deactivate a control. */
1151void v4l2_ctrl_activate(struct v4l2_ctrl *ctrl, bool active)
1152{
1153 if (ctrl == NULL)
1154 return;
1155
1156 if (!active)
1157 /* set V4L2_CTRL_FLAG_INACTIVE */
1158 set_bit(4, &ctrl->flags);
1159 else
1160 /* clear V4L2_CTRL_FLAG_INACTIVE */
1161 clear_bit(4, &ctrl->flags);
1162}
1163EXPORT_SYMBOL(v4l2_ctrl_activate);
1164
1165/* Grab/ungrab a control.
1166 Typically used when streaming starts and you want to grab controls,
1167 preventing the user from changing them.
1168
1169 Just call this and the framework will block any attempts to change
1170 these controls. */
1171void v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed)
1172{
1173 if (ctrl == NULL)
1174 return;
1175
1176 if (grabbed)
1177 /* set V4L2_CTRL_FLAG_GRABBED */
1178 set_bit(1, &ctrl->flags);
1179 else
1180 /* clear V4L2_CTRL_FLAG_GRABBED */
1181 clear_bit(1, &ctrl->flags);
1182}
1183EXPORT_SYMBOL(v4l2_ctrl_grab);
1184
1185/* Log the control name and value */
1186static void log_ctrl(const struct v4l2_ctrl *ctrl,
1187 const char *prefix, const char *colon)
1188{
1189 int fl_inact = ctrl->flags & V4L2_CTRL_FLAG_INACTIVE;
1190 int fl_grabbed = ctrl->flags & V4L2_CTRL_FLAG_GRABBED;
1191
1192 if (ctrl->flags & (V4L2_CTRL_FLAG_DISABLED | V4L2_CTRL_FLAG_WRITE_ONLY))
1193 return;
1194 if (ctrl->type == V4L2_CTRL_TYPE_CTRL_CLASS)
1195 return;
1196
1197 printk(KERN_INFO "%s%s%s: ", prefix, colon, ctrl->name);
1198
1199 switch (ctrl->type) {
1200 case V4L2_CTRL_TYPE_INTEGER:
1201 printk(KERN_CONT "%d", ctrl->cur.val);
1202 break;
1203 case V4L2_CTRL_TYPE_BOOLEAN:
1204 printk(KERN_CONT "%s", ctrl->cur.val ? "true" : "false");
1205 break;
1206 case V4L2_CTRL_TYPE_MENU:
1207 printk(KERN_CONT "%s", ctrl->qmenu[ctrl->cur.val]);
1208 break;
1209 case V4L2_CTRL_TYPE_INTEGER64:
1210 printk(KERN_CONT "%lld", ctrl->cur.val64);
1211 break;
1212 case V4L2_CTRL_TYPE_STRING:
1213 printk(KERN_CONT "%s", ctrl->cur.string);
1214 break;
1215 default:
1216 printk(KERN_CONT "unknown type %d", ctrl->type);
1217 break;
1218 }
1219 if (fl_inact && fl_grabbed)
1220 printk(KERN_CONT " (inactive, grabbed)\n");
1221 else if (fl_inact)
1222 printk(KERN_CONT " (inactive)\n");
1223 else if (fl_grabbed)
1224 printk(KERN_CONT " (grabbed)\n");
1225 else
1226 printk(KERN_CONT "\n");
1227}
1228
1229/* Log all controls owned by the handler */
1230void v4l2_ctrl_handler_log_status(struct v4l2_ctrl_handler *hdl,
1231 const char *prefix)
1232{
1233 struct v4l2_ctrl *ctrl;
1234 const char *colon = "";
1235 int len;
1236
1237 if (hdl == NULL)
1238 return;
1239 if (prefix == NULL)
1240 prefix = "";
1241 len = strlen(prefix);
1242 if (len && prefix[len - 1] != ' ')
1243 colon = ": ";
1244 mutex_lock(&hdl->lock);
1245 list_for_each_entry(ctrl, &hdl->ctrls, node)
1246 if (!(ctrl->flags & V4L2_CTRL_FLAG_DISABLED))
1247 log_ctrl(ctrl, prefix, colon);
1248 mutex_unlock(&hdl->lock);
1249}
1250EXPORT_SYMBOL(v4l2_ctrl_handler_log_status);
1251
1252/* Call s_ctrl for all controls owned by the handler */
1253int v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl)
1254{
1255 struct v4l2_ctrl *ctrl;
1256 int ret = 0;
1257
1258 if (hdl == NULL)
1259 return 0;
1260 mutex_lock(&hdl->lock);
1261 list_for_each_entry(ctrl, &hdl->ctrls, node)
1262 ctrl->done = false;
1263
1264 list_for_each_entry(ctrl, &hdl->ctrls, node) {
1265 struct v4l2_ctrl *master = ctrl->cluster[0];
1266 int i;
1267
1268 /* Skip if this control was already handled by a cluster. */
1269 if (ctrl->done)
1270 continue;
1271
1272 for (i = 0; i < master->ncontrols; i++)
1273 cur_to_new(master->cluster[i]);
1274
1275 /* Skip button controls and read-only controls. */
1276 if (ctrl->type == V4L2_CTRL_TYPE_BUTTON ||
1277 (ctrl->flags & V4L2_CTRL_FLAG_READ_ONLY))
1278 continue;
1279 ret = master->ops->s_ctrl(master);
1280 if (ret)
1281 break;
1282 for (i = 0; i < master->ncontrols; i++)
1283 if (master->cluster[i])
1284 master->cluster[i]->done = true;
1285 }
1286 mutex_unlock(&hdl->lock);
1287 return ret;
1288}
1289EXPORT_SYMBOL(v4l2_ctrl_handler_setup);
1290
1291/* Implement VIDIOC_QUERYCTRL */
1292int v4l2_queryctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_queryctrl *qc)
1293{
1294 u32 id = qc->id & V4L2_CTRL_ID_MASK;
1295 struct v4l2_ctrl_ref *ref;
1296 struct v4l2_ctrl *ctrl;
1297
1298 if (hdl == NULL)
1299 return -EINVAL;
1300
1301 mutex_lock(&hdl->lock);
1302
1303 /* Try to find it */
1304 ref = find_ref(hdl, id);
1305
1306 if ((qc->id & V4L2_CTRL_FLAG_NEXT_CTRL) && !list_empty(&hdl->ctrl_refs)) {
1307 /* Find the next control with ID > qc->id */
1308
1309 /* Did we reach the end of the control list? */
1310 if (id >= node2id(hdl->ctrl_refs.prev)) {
1311 ref = NULL; /* Yes, so there is no next control */
1312 } else if (ref) {
1313 /* We found a control with the given ID, so just get
1314 the next one in the list. */
1315 ref = list_entry(ref->node.next, typeof(*ref), node);
1316 } else {
1317 /* No control with the given ID exists, so start
1318 searching for the next largest ID. We know there
1319 is one, otherwise the first 'if' above would have
1320 been true. */
1321 list_for_each_entry(ref, &hdl->ctrl_refs, node)
1322 if (id < ref->ctrl->id)
1323 break;
1324 }
1325 }
1326 mutex_unlock(&hdl->lock);
1327 if (!ref)
1328 return -EINVAL;
1329
1330 ctrl = ref->ctrl;
1331 memset(qc, 0, sizeof(*qc));
1332 qc->id = ctrl->id;
1333 strlcpy(qc->name, ctrl->name, sizeof(qc->name));
1334 qc->minimum = ctrl->minimum;
1335 qc->maximum = ctrl->maximum;
1336 qc->default_value = ctrl->default_value;
1337 if (qc->type == V4L2_CTRL_TYPE_MENU)
1338 qc->step = 1;
1339 else
1340 qc->step = ctrl->step;
1341 qc->flags = ctrl->flags;
1342 qc->type = ctrl->type;
1343 return 0;
1344}
1345EXPORT_SYMBOL(v4l2_queryctrl);
1346
1347int v4l2_subdev_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc)
1348{
1349 return v4l2_queryctrl(sd->ctrl_handler, qc);
1350}
1351EXPORT_SYMBOL(v4l2_subdev_queryctrl);
1352
1353/* Implement VIDIOC_QUERYMENU */
1354int v4l2_querymenu(struct v4l2_ctrl_handler *hdl, struct v4l2_querymenu *qm)
1355{
1356 struct v4l2_ctrl *ctrl;
1357 u32 i = qm->index;
1358
1359 ctrl = v4l2_ctrl_find(hdl, qm->id);
1360 if (!ctrl)
1361 return -EINVAL;
1362
1363 qm->reserved = 0;
1364 /* Sanity checks */
1365 if (ctrl->qmenu == NULL ||
1366 i < ctrl->minimum || i > ctrl->maximum)
1367 return -EINVAL;
1368 /* Use mask to see if this menu item should be skipped */
1369 if (ctrl->menu_skip_mask & (1 << i))
1370 return -EINVAL;
1371 /* Empty menu items should also be skipped */
1372 if (ctrl->qmenu[i] == NULL || ctrl->qmenu[i][0] == '\0')
1373 return -EINVAL;
1374 strlcpy(qm->name, ctrl->qmenu[i], sizeof(qm->name));
1375 return 0;
1376}
1377EXPORT_SYMBOL(v4l2_querymenu);
1378
1379int v4l2_subdev_querymenu(struct v4l2_subdev *sd, struct v4l2_querymenu *qm)
1380{
1381 return v4l2_querymenu(sd->ctrl_handler, qm);
1382}
1383EXPORT_SYMBOL(v4l2_subdev_querymenu);
1384
1385
1386
1387/* Some general notes on the atomic requirements of VIDIOC_G/TRY/S_EXT_CTRLS:
1388
1389 It is not a fully atomic operation, just best-effort only. After all, if
1390 multiple controls have to be set through multiple i2c writes (for example)
1391 then some initial writes may succeed while others fail. Thus leaving the
1392 system in an inconsistent state. The question is how much effort you are
1393 willing to spend on trying to make something atomic that really isn't.
1394
1395 From the point of view of an application the main requirement is that
1396 when you call VIDIOC_S_EXT_CTRLS and some values are invalid then an
1397 error should be returned without actually affecting any controls.
1398
1399 If all the values are correct, then it is acceptable to just give up
1400 in case of low-level errors.
1401
1402 It is important though that the application can tell when only a partial
1403 configuration was done. The way we do that is through the error_idx field
1404 of struct v4l2_ext_controls: if that is equal to the count field then no
1405 controls were affected. Otherwise all controls before that index were
1406 successful in performing their 'get' or 'set' operation, the control at
1407 the given index failed, and you don't know what happened with the controls
1408 after the failed one. Since if they were part of a control cluster they
1409 could have been successfully processed (if a cluster member was encountered
1410 at index < error_idx), they could have failed (if a cluster member was at
1411 error_idx), or they may not have been processed yet (if the first cluster
1412 member appeared after error_idx).
1413
1414 It is all fairly theoretical, though. In practice all you can do is to
1415 bail out. If error_idx == count, then it is an application bug. If
1416 error_idx < count then it is only an application bug if the error code was
1417 EBUSY. That usually means that something started streaming just when you
1418 tried to set the controls. In all other cases it is a driver/hardware
1419 problem and all you can do is to retry or bail out.
1420
1421 Note that these rules do not apply to VIDIOC_TRY_EXT_CTRLS: since that
1422 never modifies controls the error_idx is just set to whatever control
1423 has an invalid value.
1424 */
1425
1426/* Prepare for the extended g/s/try functions.
1427 Find the controls in the control array and do some basic checks. */
1428static int prepare_ext_ctrls(struct v4l2_ctrl_handler *hdl,
1429 struct v4l2_ext_controls *cs,
1430 struct ctrl_helper *helpers,
1431 bool try)
1432{
1433 u32 i;
1434
1435 for (i = 0; i < cs->count; i++) {
1436 struct v4l2_ext_control *c = &cs->controls[i];
1437 struct v4l2_ctrl *ctrl;
1438 u32 id = c->id & V4L2_CTRL_ID_MASK;
1439
1440 if (try)
1441 cs->error_idx = i;
1442
1443 if (cs->ctrl_class && V4L2_CTRL_ID2CLASS(id) != cs->ctrl_class)
1444 return -EINVAL;
1445
1446 /* Old-style private controls are not allowed for
1447 extended controls */
1448 if (id >= V4L2_CID_PRIVATE_BASE)
1449 return -EINVAL;
1450 ctrl = v4l2_ctrl_find(hdl, id);
1451 if (ctrl == NULL)
1452 return -EINVAL;
1453 if (ctrl->flags & V4L2_CTRL_FLAG_DISABLED)
1454 return -EINVAL;
1455
1456 helpers[i].ctrl = ctrl;
1457 helpers[i].handled = false;
1458 }
1459 return 0;
1460}
1461
1462typedef int (*cluster_func)(struct v4l2_ext_control *c,
1463 struct v4l2_ctrl *ctrl);
1464
1465/* Walk over all controls in v4l2_ext_controls belonging to the same cluster
1466 and call the provided function. */
1467static int cluster_walk(unsigned from,
1468 struct v4l2_ext_controls *cs,
1469 struct ctrl_helper *helpers,
1470 cluster_func f)
1471{
1472 struct v4l2_ctrl **cluster = helpers[from].ctrl->cluster;
1473 int ret = 0;
1474 int i;
1475
1476 /* Find any controls from the same cluster and call the function */
1477 for (i = from; !ret && i < cs->count; i++) {
1478 struct v4l2_ctrl *ctrl = helpers[i].ctrl;
1479
1480 if (!helpers[i].handled && ctrl->cluster == cluster)
1481 ret = f(&cs->controls[i], ctrl);
1482 }
1483 return ret;
1484}
1485
1486static void cluster_done(unsigned from,
1487 struct v4l2_ext_controls *cs,
1488 struct ctrl_helper *helpers)
1489{
1490 struct v4l2_ctrl **cluster = helpers[from].ctrl->cluster;
1491 int i;
1492
1493 /* Find any controls from the same cluster and mark them as handled */
1494 for (i = from; i < cs->count; i++)
1495 if (helpers[i].ctrl->cluster == cluster)
1496 helpers[i].handled = true;
1497}
1498
1499/* Handles the corner case where cs->count == 0. It checks whether the
1500 specified control class exists. If that class ID is 0, then it checks
1501 whether there are any controls at all. */
1502static int class_check(struct v4l2_ctrl_handler *hdl, u32 ctrl_class)
1503{
1504 if (ctrl_class == 0)
1505 return list_empty(&hdl->ctrl_refs) ? -EINVAL : 0;
1506 return find_ref_lock(hdl, ctrl_class | 1) ? 0 : -EINVAL;
1507}
1508
1509
1510
1511/* Get extended controls. Allocates the helpers array if needed. */
1512int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *cs)
1513{
1514 struct ctrl_helper helper[4];
1515 struct ctrl_helper *helpers = helper;
1516 int ret;
1517 int i;
1518
1519 cs->error_idx = cs->count;
1520 cs->ctrl_class = V4L2_CTRL_ID2CLASS(cs->ctrl_class);
1521
1522 if (hdl == NULL)
1523 return -EINVAL;
1524
1525 if (cs->count == 0)
1526 return class_check(hdl, cs->ctrl_class);
1527
1528 if (cs->count > ARRAY_SIZE(helper)) {
1529 helpers = kmalloc(sizeof(helper[0]) * cs->count, GFP_KERNEL);
1530 if (helpers == NULL)
1531 return -ENOMEM;
1532 }
1533
1534 ret = prepare_ext_ctrls(hdl, cs, helpers, false);
1535
1536 for (i = 0; !ret && i < cs->count; i++)
1537 if (helpers[i].ctrl->flags & V4L2_CTRL_FLAG_WRITE_ONLY)
1538 ret = -EACCES;
1539
1540 for (i = 0; !ret && i < cs->count; i++) {
1541 struct v4l2_ctrl *ctrl = helpers[i].ctrl;
1542 struct v4l2_ctrl *master = ctrl->cluster[0];
1543
1544 if (helpers[i].handled)
1545 continue;
1546
1547 cs->error_idx = i;
1548
1549 v4l2_ctrl_lock(master);
1550 /* g_volatile_ctrl will update the current control values */
1551 if (ctrl->is_volatile && master->ops->g_volatile_ctrl)
1552 ret = master->ops->g_volatile_ctrl(master);
1553 /* If OK, then copy the current control values to the caller */
1554 if (!ret)
1555 ret = cluster_walk(i, cs, helpers, cur_to_user);
1556 v4l2_ctrl_unlock(master);
1557 cluster_done(i, cs, helpers);
1558 }
1559
1560 if (cs->count > ARRAY_SIZE(helper))
1561 kfree(helpers);
1562 return ret;
1563}
1564EXPORT_SYMBOL(v4l2_g_ext_ctrls);
1565
1566int v4l2_subdev_g_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *cs)
1567{
1568 return v4l2_g_ext_ctrls(sd->ctrl_handler, cs);
1569}
1570EXPORT_SYMBOL(v4l2_subdev_g_ext_ctrls);
1571
1572/* Helper function to get a single control */
1573static int get_ctrl(struct v4l2_ctrl *ctrl, s32 *val)
1574{
1575 struct v4l2_ctrl *master = ctrl->cluster[0];
1576 int ret = 0;
1577
1578 if (ctrl->flags & V4L2_CTRL_FLAG_WRITE_ONLY)
1579 return -EACCES;
1580
1581 v4l2_ctrl_lock(master);
1582 /* g_volatile_ctrl will update the current control values */
1583 if (ctrl->is_volatile && master->ops->g_volatile_ctrl)
1584 ret = master->ops->g_volatile_ctrl(master);
1585 *val = ctrl->cur.val;
1586 v4l2_ctrl_unlock(master);
1587 return ret;
1588}
1589
1590int v4l2_g_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_control *control)
1591{
1592 struct v4l2_ctrl *ctrl = v4l2_ctrl_find(hdl, control->id);
1593
1594 if (ctrl == NULL || !type_is_int(ctrl))
1595 return -EINVAL;
1596 return get_ctrl(ctrl, &control->value);
1597}
1598EXPORT_SYMBOL(v4l2_g_ctrl);
1599
1600int v4l2_subdev_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *control)
1601{
1602 return v4l2_g_ctrl(sd->ctrl_handler, control);
1603}
1604EXPORT_SYMBOL(v4l2_subdev_g_ctrl);
1605
1606s32 v4l2_ctrl_g_ctrl(struct v4l2_ctrl *ctrl)
1607{
1608 s32 val = 0;
1609
1610 /* It's a driver bug if this happens. */
1611 WARN_ON(!type_is_int(ctrl));
1612 get_ctrl(ctrl, &val);
1613 return val;
1614}
1615EXPORT_SYMBOL(v4l2_ctrl_g_ctrl);
1616
1617
1618/* Core function that calls try/s_ctrl and ensures that the new value is
1619 copied to the current value on a set.
1620 Must be called with ctrl->handler->lock held. */
1621static int try_or_set_control_cluster(struct v4l2_ctrl *master, bool set)
1622{
1623 bool try = !set;
1624 int ret = 0;
1625 int i;
1626
1627 /* Go through the cluster and either validate the new value or
1628 (if no new value was set), copy the current value to the new
1629 value, ensuring a consistent view for the control ops when
1630 called. */
1631 for (i = 0; !ret && i < master->ncontrols; i++) {
1632 struct v4l2_ctrl *ctrl = master->cluster[i];
1633
1634 if (ctrl == NULL)
1635 continue;
1636
1637 if (ctrl->has_new) {
1638 /* Double check this: it may have changed since the
1639 last check in try_or_set_ext_ctrls(). */
1640 if (set && (ctrl->flags & V4L2_CTRL_FLAG_GRABBED))
1641 return -EBUSY;
1642
1643 /* Validate if required */
1644 if (!set)
1645 ret = validate_new(ctrl);
1646 continue;
1647 }
1648 /* No new value was set, so copy the current and force
1649 a call to try_ctrl later, since the values for the cluster
1650 may now have changed and the end result might be invalid. */
1651 try = true;
1652 cur_to_new(ctrl);
1653 }
1654
1655 /* For larger clusters you have to call try_ctrl again to
1656 verify that the controls are still valid after the
1657 'cur_to_new' above. */
1658 if (!ret && master->ops->try_ctrl && try)
1659 ret = master->ops->try_ctrl(master);
1660
1661 /* Don't set if there is no change */
1662 if (!ret && set && cluster_changed(master)) {
1663 ret = master->ops->s_ctrl(master);
1664 /* If OK, then make the new values permanent. */
1665 if (!ret)
1666 for (i = 0; i < master->ncontrols; i++)
1667 new_to_cur(master->cluster[i]);
1668 }
1669 return ret;
1670}
1671
1672/* Try or set controls. */
1673static int try_or_set_ext_ctrls(struct v4l2_ctrl_handler *hdl,
1674 struct v4l2_ext_controls *cs,
1675 struct ctrl_helper *helpers,
1676 bool set)
1677{
1678 unsigned i, j;
1679 int ret = 0;
1680
1681 cs->error_idx = cs->count;
1682 for (i = 0; i < cs->count; i++) {
1683 struct v4l2_ctrl *ctrl = helpers[i].ctrl;
1684
1685 if (!set)
1686 cs->error_idx = i;
1687
1688 if (ctrl->flags & V4L2_CTRL_FLAG_READ_ONLY)
1689 return -EACCES;
1690 /* This test is also done in try_set_control_cluster() which
1691 is called in atomic context, so that has the final say,
1692 but it makes sense to do an up-front check as well. Once
1693 an error occurs in try_set_control_cluster() some other
1694 controls may have been set already and we want to do a
1695 best-effort to avoid that. */
1696 if (set && (ctrl->flags & V4L2_CTRL_FLAG_GRABBED))
1697 return -EBUSY;
1698 }
1699
1700 for (i = 0; !ret && i < cs->count; i++) {
1701 struct v4l2_ctrl *ctrl = helpers[i].ctrl;
1702 struct v4l2_ctrl *master = ctrl->cluster[0];
1703
1704 cs->error_idx = i;
1705
1706 if (helpers[i].handled)
1707 continue;
1708
1709 v4l2_ctrl_lock(ctrl);
1710
1711 /* Reset the 'has_new' flags of the cluster */
1712 for (j = 0; j < master->ncontrols; j++)
1713 if (master->cluster[j])
1714 master->cluster[j]->has_new = 0;
1715
1716 /* Copy the new caller-supplied control values.
1717 user_to_new() sets 'has_new' to 1. */
1718 ret = cluster_walk(i, cs, helpers, user_to_new);
1719
1720 if (!ret)
1721 ret = try_or_set_control_cluster(master, set);
1722
1723 /* Copy the new values back to userspace. */
1724 if (!ret)
1725 ret = cluster_walk(i, cs, helpers, new_to_user);
1726
1727 v4l2_ctrl_unlock(ctrl);
1728 cluster_done(i, cs, helpers);
1729 }
1730 return ret;
1731}
1732
1733/* Try or try-and-set controls */
1734static int try_set_ext_ctrls(struct v4l2_ctrl_handler *hdl,
1735 struct v4l2_ext_controls *cs,
1736 bool set)
1737{
1738 struct ctrl_helper helper[4];
1739 struct ctrl_helper *helpers = helper;
1740 int ret;
1741 int i;
1742
1743 cs->error_idx = cs->count;
1744 cs->ctrl_class = V4L2_CTRL_ID2CLASS(cs->ctrl_class);
1745
1746 if (hdl == NULL)
1747 return -EINVAL;
1748
1749 if (cs->count == 0)
1750 return class_check(hdl, cs->ctrl_class);
1751
1752 if (cs->count > ARRAY_SIZE(helper)) {
1753 helpers = kmalloc(sizeof(helper[0]) * cs->count, GFP_KERNEL);
1754 if (!helpers)
1755 return -ENOMEM;
1756 }
1757 ret = prepare_ext_ctrls(hdl, cs, helpers, !set);
1758 if (ret)
1759 goto free;
1760
1761 /* First 'try' all controls and abort on error */
1762 ret = try_or_set_ext_ctrls(hdl, cs, helpers, false);
1763 /* If this is a 'set' operation and the initial 'try' failed,
1764 then set error_idx to count to tell the application that no
1765 controls changed value yet. */
1766 if (set)
1767 cs->error_idx = cs->count;
1768 if (!ret && set) {
1769 /* Reset 'handled' state */
1770 for (i = 0; i < cs->count; i++)
1771 helpers[i].handled = false;
1772 ret = try_or_set_ext_ctrls(hdl, cs, helpers, true);
1773 }
1774
1775free:
1776 if (cs->count > ARRAY_SIZE(helper))
1777 kfree(helpers);
1778 return ret;
1779}
1780
1781int v4l2_try_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *cs)
1782{
1783 return try_set_ext_ctrls(hdl, cs, false);
1784}
1785EXPORT_SYMBOL(v4l2_try_ext_ctrls);
1786
1787int v4l2_s_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *cs)
1788{
1789 return try_set_ext_ctrls(hdl, cs, true);
1790}
1791EXPORT_SYMBOL(v4l2_s_ext_ctrls);
1792
1793int v4l2_subdev_try_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *cs)
1794{
1795 return try_set_ext_ctrls(sd->ctrl_handler, cs, false);
1796}
1797EXPORT_SYMBOL(v4l2_subdev_try_ext_ctrls);
1798
1799int v4l2_subdev_s_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *cs)
1800{
1801 return try_set_ext_ctrls(sd->ctrl_handler, cs, true);
1802}
1803EXPORT_SYMBOL(v4l2_subdev_s_ext_ctrls);
1804
1805/* Helper function for VIDIOC_S_CTRL compatibility */
1806static int set_ctrl(struct v4l2_ctrl *ctrl, s32 *val)
1807{
1808 struct v4l2_ctrl *master = ctrl->cluster[0];
1809 int ret;
1810 int i;
1811
1812 v4l2_ctrl_lock(ctrl);
1813
1814 /* Reset the 'has_new' flags of the cluster */
1815 for (i = 0; i < master->ncontrols; i++)
1816 if (master->cluster[i])
1817 master->cluster[i]->has_new = 0;
1818
1819 ctrl->val = *val;
1820 ctrl->has_new = 1;
1821 ret = try_or_set_control_cluster(master, false);
1822 if (!ret)
1823 ret = try_or_set_control_cluster(master, true);
1824 *val = ctrl->cur.val;
1825 v4l2_ctrl_unlock(ctrl);
1826 return ret;
1827}
1828
1829int v4l2_s_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_control *control)
1830{
1831 struct v4l2_ctrl *ctrl = v4l2_ctrl_find(hdl, control->id);
1832
1833 if (ctrl == NULL || !type_is_int(ctrl))
1834 return -EINVAL;
1835
1836 return set_ctrl(ctrl, &control->value);
1837}
1838EXPORT_SYMBOL(v4l2_s_ctrl);
1839
1840int v4l2_subdev_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *control)
1841{
1842 return v4l2_s_ctrl(sd->ctrl_handler, control);
1843}
1844EXPORT_SYMBOL(v4l2_subdev_s_ctrl);
1845
1846int v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val)
1847{
1848 /* It's a driver bug if this happens. */
1849 WARN_ON(!type_is_int(ctrl));
1850 return set_ctrl(ctrl, &val);
1851}
1852EXPORT_SYMBOL(v4l2_ctrl_s_ctrl);
diff --git a/drivers/media/video/v4l2-dev.c b/drivers/media/video/v4l2-dev.c
index 9e89bf617790..cb77197d480e 100644
--- a/drivers/media/video/v4l2-dev.c
+++ b/drivers/media/video/v4l2-dev.c
@@ -25,6 +25,7 @@
25#include <linux/init.h> 25#include <linux/init.h>
26#include <linux/kmod.h> 26#include <linux/kmod.h>
27#include <linux/slab.h> 27#include <linux/slab.h>
28#include <linux/smp_lock.h>
28#include <asm/uaccess.h> 29#include <asm/uaccess.h>
29#include <asm/system.h> 30#include <asm/system.h>
30 31
@@ -215,28 +216,24 @@ static unsigned int v4l2_poll(struct file *filp, struct poll_table_struct *poll)
215 return vdev->fops->poll(filp, poll); 216 return vdev->fops->poll(filp, poll);
216} 217}
217 218
218static int v4l2_ioctl(struct inode *inode, struct file *filp, 219static long v4l2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
219 unsigned int cmd, unsigned long arg)
220{ 220{
221 struct video_device *vdev = video_devdata(filp); 221 struct video_device *vdev = video_devdata(filp);
222 int ret;
222 223
223 if (!vdev->fops->ioctl)
224 return -ENOTTY;
225 /* Allow ioctl to continue even if the device was unregistered. 224 /* Allow ioctl to continue even if the device was unregistered.
226 Things like dequeueing buffers might still be useful. */ 225 Things like dequeueing buffers might still be useful. */
227 return vdev->fops->ioctl(filp, cmd, arg); 226 if (vdev->fops->unlocked_ioctl) {
228} 227 ret = vdev->fops->unlocked_ioctl(filp, cmd, arg);
229 228 } else if (vdev->fops->ioctl) {
230static long v4l2_unlocked_ioctl(struct file *filp, 229 /* TODO: convert all drivers to unlocked_ioctl */
231 unsigned int cmd, unsigned long arg) 230 lock_kernel();
232{ 231 ret = vdev->fops->ioctl(filp, cmd, arg);
233 struct video_device *vdev = video_devdata(filp); 232 unlock_kernel();
233 } else
234 ret = -ENOTTY;
234 235
235 if (!vdev->fops->unlocked_ioctl) 236 return ret;
236 return -ENOTTY;
237 /* Allow ioctl to continue even if the device was unregistered.
238 Things like dequeueing buffers might still be useful. */
239 return vdev->fops->unlocked_ioctl(filp, cmd, arg);
240} 237}
241 238
242#ifdef CONFIG_MMU 239#ifdef CONFIG_MMU
@@ -307,22 +304,6 @@ static int v4l2_release(struct inode *inode, struct file *filp)
307 return ret; 304 return ret;
308} 305}
309 306
310static const struct file_operations v4l2_unlocked_fops = {
311 .owner = THIS_MODULE,
312 .read = v4l2_read,
313 .write = v4l2_write,
314 .open = v4l2_open,
315 .get_unmapped_area = v4l2_get_unmapped_area,
316 .mmap = v4l2_mmap,
317 .unlocked_ioctl = v4l2_unlocked_ioctl,
318#ifdef CONFIG_COMPAT
319 .compat_ioctl = v4l2_compat_ioctl32,
320#endif
321 .release = v4l2_release,
322 .poll = v4l2_poll,
323 .llseek = no_llseek,
324};
325
326static const struct file_operations v4l2_fops = { 307static const struct file_operations v4l2_fops = {
327 .owner = THIS_MODULE, 308 .owner = THIS_MODULE,
328 .read = v4l2_read, 309 .read = v4l2_read,
@@ -330,7 +311,7 @@ static const struct file_operations v4l2_fops = {
330 .open = v4l2_open, 311 .open = v4l2_open,
331 .get_unmapped_area = v4l2_get_unmapped_area, 312 .get_unmapped_area = v4l2_get_unmapped_area,
332 .mmap = v4l2_mmap, 313 .mmap = v4l2_mmap,
333 .ioctl = v4l2_ioctl, 314 .unlocked_ioctl = v4l2_ioctl,
334#ifdef CONFIG_COMPAT 315#ifdef CONFIG_COMPAT
335 .compat_ioctl = v4l2_compat_ioctl32, 316 .compat_ioctl = v4l2_compat_ioctl32,
336#endif 317#endif
@@ -447,8 +428,12 @@ static int __video_register_device(struct video_device *vdev, int type, int nr,
447 428
448 vdev->vfl_type = type; 429 vdev->vfl_type = type;
449 vdev->cdev = NULL; 430 vdev->cdev = NULL;
450 if (vdev->v4l2_dev && vdev->v4l2_dev->dev) 431 if (vdev->v4l2_dev) {
451 vdev->parent = vdev->v4l2_dev->dev; 432 if (vdev->v4l2_dev->dev)
433 vdev->parent = vdev->v4l2_dev->dev;
434 if (vdev->ctrl_handler == NULL)
435 vdev->ctrl_handler = vdev->v4l2_dev->ctrl_handler;
436 }
452 437
453 /* Part 2: find a free minor, device node number and device index. */ 438 /* Part 2: find a free minor, device node number and device index. */
454#ifdef CONFIG_VIDEO_FIXED_MINOR_RANGES 439#ifdef CONFIG_VIDEO_FIXED_MINOR_RANGES
@@ -521,10 +506,7 @@ static int __video_register_device(struct video_device *vdev, int type, int nr,
521 ret = -ENOMEM; 506 ret = -ENOMEM;
522 goto cleanup; 507 goto cleanup;
523 } 508 }
524 if (vdev->fops->unlocked_ioctl) 509 vdev->cdev->ops = &v4l2_fops;
525 vdev->cdev->ops = &v4l2_unlocked_fops;
526 else
527 vdev->cdev->ops = &v4l2_fops;
528 vdev->cdev->owner = vdev->fops->owner; 510 vdev->cdev->owner = vdev->fops->owner;
529 ret = cdev_add(vdev->cdev, MKDEV(VIDEO_MAJOR, vdev->minor), 1); 511 ret = cdev_add(vdev->cdev, MKDEV(VIDEO_MAJOR, vdev->minor), 1);
530 if (ret < 0) { 512 if (ret < 0) {
diff --git a/drivers/media/video/v4l2-device.c b/drivers/media/video/v4l2-device.c
index 5a7dc4afe92a..0b08f96b74a5 100644
--- a/drivers/media/video/v4l2-device.c
+++ b/drivers/media/video/v4l2-device.c
@@ -26,6 +26,7 @@
26#endif 26#endif
27#include <linux/videodev2.h> 27#include <linux/videodev2.h>
28#include <media/v4l2-device.h> 28#include <media/v4l2-device.h>
29#include <media/v4l2-ctrls.h>
29 30
30int v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev) 31int v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev)
31{ 32{
@@ -115,6 +116,8 @@ EXPORT_SYMBOL_GPL(v4l2_device_unregister);
115int v4l2_device_register_subdev(struct v4l2_device *v4l2_dev, 116int v4l2_device_register_subdev(struct v4l2_device *v4l2_dev,
116 struct v4l2_subdev *sd) 117 struct v4l2_subdev *sd)
117{ 118{
119 int err;
120
118 /* Check for valid input */ 121 /* Check for valid input */
119 if (v4l2_dev == NULL || sd == NULL || !sd->name[0]) 122 if (v4l2_dev == NULL || sd == NULL || !sd->name[0])
120 return -EINVAL; 123 return -EINVAL;
@@ -122,6 +125,10 @@ int v4l2_device_register_subdev(struct v4l2_device *v4l2_dev,
122 WARN_ON(sd->v4l2_dev != NULL); 125 WARN_ON(sd->v4l2_dev != NULL);
123 if (!try_module_get(sd->owner)) 126 if (!try_module_get(sd->owner))
124 return -ENODEV; 127 return -ENODEV;
128 /* This just returns 0 if either of the two args is NULL */
129 err = v4l2_ctrl_add_handler(v4l2_dev->ctrl_handler, sd->ctrl_handler);
130 if (err)
131 return err;
125 sd->v4l2_dev = v4l2_dev; 132 sd->v4l2_dev = v4l2_dev;
126 spin_lock(&v4l2_dev->lock); 133 spin_lock(&v4l2_dev->lock);
127 list_add_tail(&sd->list, &v4l2_dev->subdevs); 134 list_add_tail(&sd->list, &v4l2_dev->subdevs);
diff --git a/drivers/media/video/v4l2-ioctl.c b/drivers/media/video/v4l2-ioctl.c
index 0eeceae50329..dd9283fcb564 100644
--- a/drivers/media/video/v4l2-ioctl.c
+++ b/drivers/media/video/v4l2-ioctl.c
@@ -26,6 +26,7 @@
26#endif 26#endif
27#include <media/v4l2-common.h> 27#include <media/v4l2-common.h>
28#include <media/v4l2-ioctl.h> 28#include <media/v4l2-ioctl.h>
29#include <media/v4l2-ctrls.h>
29#include <media/v4l2-fh.h> 30#include <media/v4l2-fh.h>
30#include <media/v4l2-event.h> 31#include <media/v4l2-event.h>
31#include <media/v4l2-chip-ident.h> 32#include <media/v4l2-chip-ident.h>
@@ -1259,9 +1260,12 @@ static long __video_do_ioctl(struct file *file,
1259 { 1260 {
1260 struct v4l2_queryctrl *p = arg; 1261 struct v4l2_queryctrl *p = arg;
1261 1262
1262 if (!ops->vidioc_queryctrl) 1263 if (vfd->ctrl_handler)
1264 ret = v4l2_queryctrl(vfd->ctrl_handler, p);
1265 else if (ops->vidioc_queryctrl)
1266 ret = ops->vidioc_queryctrl(file, fh, p);
1267 else
1263 break; 1268 break;
1264 ret = ops->vidioc_queryctrl(file, fh, p);
1265 if (!ret) 1269 if (!ret)
1266 dbgarg(cmd, "id=0x%x, type=%d, name=%s, min/max=%d/%d, " 1270 dbgarg(cmd, "id=0x%x, type=%d, name=%s, min/max=%d/%d, "
1267 "step=%d, default=%d, flags=0x%08x\n", 1271 "step=%d, default=%d, flags=0x%08x\n",
@@ -1276,7 +1280,9 @@ static long __video_do_ioctl(struct file *file,
1276 { 1280 {
1277 struct v4l2_control *p = arg; 1281 struct v4l2_control *p = arg;
1278 1282
1279 if (ops->vidioc_g_ctrl) 1283 if (vfd->ctrl_handler)
1284 ret = v4l2_g_ctrl(vfd->ctrl_handler, p);
1285 else if (ops->vidioc_g_ctrl)
1280 ret = ops->vidioc_g_ctrl(file, fh, p); 1286 ret = ops->vidioc_g_ctrl(file, fh, p);
1281 else if (ops->vidioc_g_ext_ctrls) { 1287 else if (ops->vidioc_g_ext_ctrls) {
1282 struct v4l2_ext_controls ctrls; 1288 struct v4l2_ext_controls ctrls;
@@ -1306,11 +1312,16 @@ static long __video_do_ioctl(struct file *file,
1306 struct v4l2_ext_controls ctrls; 1312 struct v4l2_ext_controls ctrls;
1307 struct v4l2_ext_control ctrl; 1313 struct v4l2_ext_control ctrl;
1308 1314
1309 if (!ops->vidioc_s_ctrl && !ops->vidioc_s_ext_ctrls) 1315 if (!vfd->ctrl_handler &&
1316 !ops->vidioc_s_ctrl && !ops->vidioc_s_ext_ctrls)
1310 break; 1317 break;
1311 1318
1312 dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value); 1319 dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
1313 1320
1321 if (vfd->ctrl_handler) {
1322 ret = v4l2_s_ctrl(vfd->ctrl_handler, p);
1323 break;
1324 }
1314 if (ops->vidioc_s_ctrl) { 1325 if (ops->vidioc_s_ctrl) {
1315 ret = ops->vidioc_s_ctrl(file, fh, p); 1326 ret = ops->vidioc_s_ctrl(file, fh, p);
1316 break; 1327 break;
@@ -1332,10 +1343,12 @@ static long __video_do_ioctl(struct file *file,
1332 struct v4l2_ext_controls *p = arg; 1343 struct v4l2_ext_controls *p = arg;
1333 1344
1334 p->error_idx = p->count; 1345 p->error_idx = p->count;
1335 if (!ops->vidioc_g_ext_ctrls) 1346 if (vfd->ctrl_handler)
1336 break; 1347 ret = v4l2_g_ext_ctrls(vfd->ctrl_handler, p);
1337 if (check_ext_ctrls(p, 0)) 1348 else if (ops->vidioc_g_ext_ctrls && check_ext_ctrls(p, 0))
1338 ret = ops->vidioc_g_ext_ctrls(file, fh, p); 1349 ret = ops->vidioc_g_ext_ctrls(file, fh, p);
1350 else
1351 break;
1339 v4l_print_ext_ctrls(cmd, vfd, p, !ret); 1352 v4l_print_ext_ctrls(cmd, vfd, p, !ret);
1340 break; 1353 break;
1341 } 1354 }
@@ -1344,10 +1357,12 @@ static long __video_do_ioctl(struct file *file,
1344 struct v4l2_ext_controls *p = arg; 1357 struct v4l2_ext_controls *p = arg;
1345 1358
1346 p->error_idx = p->count; 1359 p->error_idx = p->count;
1347 if (!ops->vidioc_s_ext_ctrls) 1360 if (!vfd->ctrl_handler && !ops->vidioc_s_ext_ctrls)
1348 break; 1361 break;
1349 v4l_print_ext_ctrls(cmd, vfd, p, 1); 1362 v4l_print_ext_ctrls(cmd, vfd, p, 1);
1350 if (check_ext_ctrls(p, 0)) 1363 if (vfd->ctrl_handler)
1364 ret = v4l2_s_ext_ctrls(vfd->ctrl_handler, p);
1365 else if (check_ext_ctrls(p, 0))
1351 ret = ops->vidioc_s_ext_ctrls(file, fh, p); 1366 ret = ops->vidioc_s_ext_ctrls(file, fh, p);
1352 break; 1367 break;
1353 } 1368 }
@@ -1356,10 +1371,12 @@ static long __video_do_ioctl(struct file *file,
1356 struct v4l2_ext_controls *p = arg; 1371 struct v4l2_ext_controls *p = arg;
1357 1372
1358 p->error_idx = p->count; 1373 p->error_idx = p->count;
1359 if (!ops->vidioc_try_ext_ctrls) 1374 if (!vfd->ctrl_handler && !ops->vidioc_try_ext_ctrls)
1360 break; 1375 break;
1361 v4l_print_ext_ctrls(cmd, vfd, p, 1); 1376 v4l_print_ext_ctrls(cmd, vfd, p, 1);
1362 if (check_ext_ctrls(p, 0)) 1377 if (vfd->ctrl_handler)
1378 ret = v4l2_try_ext_ctrls(vfd->ctrl_handler, p);
1379 else if (check_ext_ctrls(p, 0))
1363 ret = ops->vidioc_try_ext_ctrls(file, fh, p); 1380 ret = ops->vidioc_try_ext_ctrls(file, fh, p);
1364 break; 1381 break;
1365 } 1382 }
@@ -1367,9 +1384,12 @@ static long __video_do_ioctl(struct file *file,
1367 { 1384 {
1368 struct v4l2_querymenu *p = arg; 1385 struct v4l2_querymenu *p = arg;
1369 1386
1370 if (!ops->vidioc_querymenu) 1387 if (vfd->ctrl_handler)
1388 ret = v4l2_querymenu(vfd->ctrl_handler, p);
1389 else if (ops->vidioc_querymenu)
1390 ret = ops->vidioc_querymenu(file, fh, p);
1391 else
1371 break; 1392 break;
1372 ret = ops->vidioc_querymenu(file, fh, p);
1373 if (!ret) 1393 if (!ret)
1374 dbgarg(cmd, "id=0x%x, index=%d, name=%s\n", 1394 dbgarg(cmd, "id=0x%x, index=%d, name=%s\n",
1375 p->id, p->index, p->name); 1395 p->id, p->index, p->name);
diff --git a/drivers/media/video/wm8739.c b/drivers/media/video/wm8739.c
index a11b99b4226b..d5965543ecab 100644
--- a/drivers/media/video/wm8739.c
+++ b/drivers/media/video/wm8739.c
@@ -27,11 +27,11 @@
27#include <linux/ioctl.h> 27#include <linux/ioctl.h>
28#include <asm/uaccess.h> 28#include <asm/uaccess.h>
29#include <linux/i2c.h> 29#include <linux/i2c.h>
30#include <linux/i2c-id.h>
31#include <linux/videodev2.h> 30#include <linux/videodev2.h>
32#include <media/v4l2-device.h> 31#include <media/v4l2-device.h>
33#include <media/v4l2-chip-ident.h> 32#include <media/v4l2-chip-ident.h>
34#include <media/v4l2-i2c-drv.h> 33#include <media/v4l2-i2c-drv.h>
34#include <media/v4l2-ctrls.h>
35 35
36MODULE_DESCRIPTION("wm8739 driver"); 36MODULE_DESCRIPTION("wm8739 driver");
37MODULE_AUTHOR("T. Adachi, Hans Verkuil"); 37MODULE_AUTHOR("T. Adachi, Hans Verkuil");
@@ -54,12 +54,14 @@ enum {
54 54
55struct wm8739_state { 55struct wm8739_state {
56 struct v4l2_subdev sd; 56 struct v4l2_subdev sd;
57 struct v4l2_ctrl_handler hdl;
58 struct {
59 /* audio cluster */
60 struct v4l2_ctrl *volume;
61 struct v4l2_ctrl *mute;
62 struct v4l2_ctrl *balance;
63 };
57 u32 clock_freq; 64 u32 clock_freq;
58 u8 muted;
59 u16 volume;
60 u16 balance;
61 u8 vol_l; /* +12dB to -34.5dB 1.5dB step (5bit) def:0dB */
62 u8 vol_r; /* +12dB to -34.5dB 1.5dB step (5bit) def:0dB */
63}; 65};
64 66
65static inline struct wm8739_state *to_state(struct v4l2_subdev *sd) 67static inline struct wm8739_state *to_state(struct v4l2_subdev *sd)
@@ -67,6 +69,11 @@ static inline struct wm8739_state *to_state(struct v4l2_subdev *sd)
67 return container_of(sd, struct wm8739_state, sd); 69 return container_of(sd, struct wm8739_state, sd);
68} 70}
69 71
72static inline struct v4l2_subdev *to_sd(struct v4l2_ctrl *ctrl)
73{
74 return &container_of(ctrl->handler, struct wm8739_state, hdl)->sd;
75}
76
70/* ------------------------------------------------------------------------ */ 77/* ------------------------------------------------------------------------ */
71 78
72static int wm8739_write(struct v4l2_subdev *sd, int reg, u16 val) 79static int wm8739_write(struct v4l2_subdev *sd, int reg, u16 val)
@@ -89,58 +96,17 @@ static int wm8739_write(struct v4l2_subdev *sd, int reg, u16 val)
89 return -1; 96 return -1;
90} 97}
91 98
92/* write regs to set audio volume etc */ 99static int wm8739_s_ctrl(struct v4l2_ctrl *ctrl)
93static void wm8739_set_audio(struct v4l2_subdev *sd)
94{
95 struct wm8739_state *state = to_state(sd);
96 u16 mute = state->muted ? 0x80 : 0;
97
98 /* Volume setting: bits 0-4, 0x1f = 12 dB, 0x00 = -34.5 dB
99 * Default setting: 0x17 = 0 dB
100 */
101 wm8739_write(sd, R0, (state->vol_l & 0x1f) | mute);
102 wm8739_write(sd, R1, (state->vol_r & 0x1f) | mute);
103}
104
105static int wm8739_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
106{
107 struct wm8739_state *state = to_state(sd);
108
109 switch (ctrl->id) {
110 case V4L2_CID_AUDIO_MUTE:
111 ctrl->value = state->muted;
112 break;
113
114 case V4L2_CID_AUDIO_VOLUME:
115 ctrl->value = state->volume;
116 break;
117
118 case V4L2_CID_AUDIO_BALANCE:
119 ctrl->value = state->balance;
120 break;
121
122 default:
123 return -EINVAL;
124 }
125 return 0;
126}
127
128static int wm8739_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
129{ 100{
101 struct v4l2_subdev *sd = to_sd(ctrl);
130 struct wm8739_state *state = to_state(sd); 102 struct wm8739_state *state = to_state(sd);
131 unsigned int work_l, work_r; 103 unsigned int work_l, work_r;
104 u8 vol_l; /* +12dB to -34.5dB 1.5dB step (5bit) def:0dB */
105 u8 vol_r; /* +12dB to -34.5dB 1.5dB step (5bit) def:0dB */
106 u16 mute;
132 107
133 switch (ctrl->id) { 108 switch (ctrl->id) {
134 case V4L2_CID_AUDIO_MUTE:
135 state->muted = ctrl->value;
136 break;
137
138 case V4L2_CID_AUDIO_VOLUME: 109 case V4L2_CID_AUDIO_VOLUME:
139 state->volume = ctrl->value;
140 break;
141
142 case V4L2_CID_AUDIO_BALANCE:
143 state->balance = ctrl->value;
144 break; 110 break;
145 111
146 default: 112 default:
@@ -148,52 +114,25 @@ static int wm8739_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
148 } 114 }
149 115
150 /* normalize ( 65535 to 0 -> 31 to 0 (12dB to -34.5dB) ) */ 116 /* normalize ( 65535 to 0 -> 31 to 0 (12dB to -34.5dB) ) */
151 work_l = (min(65536 - state->balance, 32768) * state->volume) / 32768; 117 work_l = (min(65536 - state->balance->val, 32768) * state->volume->val) / 32768;
152 work_r = (min(state->balance, (u16)32768) * state->volume) / 32768; 118 work_r = (min(state->balance->val, 32768) * state->volume->val) / 32768;
153 119
154 state->vol_l = (long)work_l * 31 / 65535; 120 vol_l = (long)work_l * 31 / 65535;
155 state->vol_r = (long)work_r * 31 / 65535; 121 vol_r = (long)work_r * 31 / 65535;
156 122
157 /* set audio volume etc. */ 123 /* set audio volume etc. */
158 wm8739_set_audio(sd); 124 mute = state->mute->val ? 0x80 : 0;
125
126 /* Volume setting: bits 0-4, 0x1f = 12 dB, 0x00 = -34.5 dB
127 * Default setting: 0x17 = 0 dB
128 */
129 wm8739_write(sd, R0, (vol_l & 0x1f) | mute);
130 wm8739_write(sd, R1, (vol_r & 0x1f) | mute);
159 return 0; 131 return 0;
160} 132}
161 133
162/* ------------------------------------------------------------------------ */ 134/* ------------------------------------------------------------------------ */
163 135
164static struct v4l2_queryctrl wm8739_qctrl[] = {
165 {
166 .id = V4L2_CID_AUDIO_VOLUME,
167 .name = "Volume",
168 .minimum = 0,
169 .maximum = 65535,
170 .step = 65535/100,
171 .default_value = 58880,
172 .flags = 0,
173 .type = V4L2_CTRL_TYPE_INTEGER,
174 }, {
175 .id = V4L2_CID_AUDIO_MUTE,
176 .name = "Mute",
177 .minimum = 0,
178 .maximum = 1,
179 .step = 1,
180 .default_value = 1,
181 .flags = 0,
182 .type = V4L2_CTRL_TYPE_BOOLEAN,
183 }, {
184 .id = V4L2_CID_AUDIO_BALANCE,
185 .name = "Balance",
186 .minimum = 0,
187 .maximum = 65535,
188 .step = 65535/100,
189 .default_value = 32768,
190 .flags = 0,
191 .type = V4L2_CTRL_TYPE_INTEGER,
192 }
193};
194
195/* ------------------------------------------------------------------------ */
196
197static int wm8739_s_clock_freq(struct v4l2_subdev *sd, u32 audiofreq) 136static int wm8739_s_clock_freq(struct v4l2_subdev *sd, u32 audiofreq)
198{ 137{
199 struct wm8739_state *state = to_state(sd); 138 struct wm8739_state *state = to_state(sd);
@@ -222,18 +161,6 @@ static int wm8739_s_clock_freq(struct v4l2_subdev *sd, u32 audiofreq)
222 return 0; 161 return 0;
223} 162}
224 163
225static int wm8739_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc)
226{
227 int i;
228
229 for (i = 0; i < ARRAY_SIZE(wm8739_qctrl); i++)
230 if (qc->id && qc->id == wm8739_qctrl[i].id) {
231 memcpy(qc, &wm8739_qctrl[i], sizeof(*qc));
232 return 0;
233 }
234 return -EINVAL;
235}
236
237static int wm8739_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip) 164static int wm8739_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
238{ 165{
239 struct i2c_client *client = v4l2_get_subdevdata(sd); 166 struct i2c_client *client = v4l2_get_subdevdata(sd);
@@ -246,21 +173,26 @@ static int wm8739_log_status(struct v4l2_subdev *sd)
246 struct wm8739_state *state = to_state(sd); 173 struct wm8739_state *state = to_state(sd);
247 174
248 v4l2_info(sd, "Frequency: %u Hz\n", state->clock_freq); 175 v4l2_info(sd, "Frequency: %u Hz\n", state->clock_freq);
249 v4l2_info(sd, "Volume L: %02x%s\n", state->vol_l & 0x1f, 176 v4l2_ctrl_handler_log_status(&state->hdl, sd->name);
250 state->muted ? " (muted)" : "");
251 v4l2_info(sd, "Volume R: %02x%s\n", state->vol_r & 0x1f,
252 state->muted ? " (muted)" : "");
253 return 0; 177 return 0;
254} 178}
255 179
256/* ----------------------------------------------------------------------- */ 180/* ----------------------------------------------------------------------- */
257 181
182static const struct v4l2_ctrl_ops wm8739_ctrl_ops = {
183 .s_ctrl = wm8739_s_ctrl,
184};
185
258static const struct v4l2_subdev_core_ops wm8739_core_ops = { 186static const struct v4l2_subdev_core_ops wm8739_core_ops = {
259 .log_status = wm8739_log_status, 187 .log_status = wm8739_log_status,
260 .g_chip_ident = wm8739_g_chip_ident, 188 .g_chip_ident = wm8739_g_chip_ident,
261 .queryctrl = wm8739_queryctrl, 189 .g_ext_ctrls = v4l2_subdev_g_ext_ctrls,
262 .g_ctrl = wm8739_g_ctrl, 190 .try_ext_ctrls = v4l2_subdev_try_ext_ctrls,
263 .s_ctrl = wm8739_s_ctrl, 191 .s_ext_ctrls = v4l2_subdev_s_ext_ctrls,
192 .g_ctrl = v4l2_subdev_g_ctrl,
193 .s_ctrl = v4l2_subdev_s_ctrl,
194 .queryctrl = v4l2_subdev_queryctrl,
195 .querymenu = v4l2_subdev_querymenu,
264}; 196};
265 197
266static const struct v4l2_subdev_audio_ops wm8739_audio_ops = { 198static const struct v4l2_subdev_audio_ops wm8739_audio_ops = {
@@ -289,17 +221,28 @@ static int wm8739_probe(struct i2c_client *client,
289 v4l_info(client, "chip found @ 0x%x (%s)\n", 221 v4l_info(client, "chip found @ 0x%x (%s)\n",
290 client->addr << 1, client->adapter->name); 222 client->addr << 1, client->adapter->name);
291 223
292 state = kmalloc(sizeof(struct wm8739_state), GFP_KERNEL); 224 state = kzalloc(sizeof(struct wm8739_state), GFP_KERNEL);
293 if (state == NULL) 225 if (state == NULL)
294 return -ENOMEM; 226 return -ENOMEM;
295 sd = &state->sd; 227 sd = &state->sd;
296 v4l2_i2c_subdev_init(sd, client, &wm8739_ops); 228 v4l2_i2c_subdev_init(sd, client, &wm8739_ops);
297 state->vol_l = 0x17; /* 0dB */ 229 v4l2_ctrl_handler_init(&state->hdl, 2);
298 state->vol_r = 0x17; /* 0dB */ 230 state->volume = v4l2_ctrl_new_std(&state->hdl, &wm8739_ctrl_ops,
299 state->muted = 0; 231 V4L2_CID_AUDIO_VOLUME, 0, 65535, 65535 / 100, 50736);
300 state->balance = 32768; 232 state->mute = v4l2_ctrl_new_std(&state->hdl, &wm8739_ctrl_ops,
301 /* normalize (12dB(31) to -34.5dB(0) [0dB(23)] -> 65535 to 0) */ 233 V4L2_CID_AUDIO_MUTE, 0, 1, 1, 0);
302 state->volume = ((long)state->vol_l + 1) * 65535 / 31; 234 state->balance = v4l2_ctrl_new_std(&state->hdl, &wm8739_ctrl_ops,
235 V4L2_CID_AUDIO_BALANCE, 0, 65535, 65535 / 100, 32768);
236 sd->ctrl_handler = &state->hdl;
237 if (state->hdl.error) {
238 int err = state->hdl.error;
239
240 v4l2_ctrl_handler_free(&state->hdl);
241 kfree(state);
242 return err;
243 }
244 v4l2_ctrl_cluster(3, &state->volume);
245
303 state->clock_freq = 48000; 246 state->clock_freq = 48000;
304 247
305 /* Initialize wm8739 */ 248 /* Initialize wm8739 */
@@ -318,15 +261,17 @@ static int wm8739_probe(struct i2c_client *client,
318 /* activate */ 261 /* activate */
319 wm8739_write(sd, R9, 0x001); 262 wm8739_write(sd, R9, 0x001);
320 /* set volume/mute */ 263 /* set volume/mute */
321 wm8739_set_audio(sd); 264 v4l2_ctrl_handler_setup(&state->hdl);
322 return 0; 265 return 0;
323} 266}
324 267
325static int wm8739_remove(struct i2c_client *client) 268static int wm8739_remove(struct i2c_client *client)
326{ 269{
327 struct v4l2_subdev *sd = i2c_get_clientdata(client); 270 struct v4l2_subdev *sd = i2c_get_clientdata(client);
271 struct wm8739_state *state = to_state(sd);
328 272
329 v4l2_device_unregister_subdev(sd); 273 v4l2_device_unregister_subdev(sd);
274 v4l2_ctrl_handler_free(&state->hdl);
330 kfree(to_state(sd)); 275 kfree(to_state(sd));
331 return 0; 276 return 0;
332} 277}
diff --git a/drivers/media/video/wm8775.c b/drivers/media/video/wm8775.c
index 5c2ba599c0c7..23bad3fd6dc5 100644
--- a/drivers/media/video/wm8775.c
+++ b/drivers/media/video/wm8775.c
@@ -35,6 +35,7 @@
35#include <linux/videodev2.h> 35#include <linux/videodev2.h>
36#include <media/v4l2-device.h> 36#include <media/v4l2-device.h>
37#include <media/v4l2-chip-ident.h> 37#include <media/v4l2-chip-ident.h>
38#include <media/v4l2-ctrls.h>
38#include <media/v4l2-i2c-drv.h> 39#include <media/v4l2-i2c-drv.h>
39 40
40MODULE_DESCRIPTION("wm8775 driver"); 41MODULE_DESCRIPTION("wm8775 driver");
@@ -53,8 +54,9 @@ enum {
53 54
54struct wm8775_state { 55struct wm8775_state {
55 struct v4l2_subdev sd; 56 struct v4l2_subdev sd;
57 struct v4l2_ctrl_handler hdl;
58 struct v4l2_ctrl *mute;
56 u8 input; /* Last selected input (0-0xf) */ 59 u8 input; /* Last selected input (0-0xf) */
57 u8 muted;
58}; 60};
59 61
60static inline struct wm8775_state *to_state(struct v4l2_subdev *sd) 62static inline struct wm8775_state *to_state(struct v4l2_subdev *sd)
@@ -62,6 +64,11 @@ static inline struct wm8775_state *to_state(struct v4l2_subdev *sd)
62 return container_of(sd, struct wm8775_state, sd); 64 return container_of(sd, struct wm8775_state, sd);
63} 65}
64 66
67static inline struct v4l2_subdev *to_sd(struct v4l2_ctrl *ctrl)
68{
69 return &container_of(ctrl->handler, struct wm8775_state, hdl)->sd;
70}
71
65static int wm8775_write(struct v4l2_subdev *sd, int reg, u16 val) 72static int wm8775_write(struct v4l2_subdev *sd, int reg, u16 val)
66{ 73{
67 struct i2c_client *client = v4l2_get_subdevdata(sd); 74 struct i2c_client *client = v4l2_get_subdevdata(sd);
@@ -95,7 +102,7 @@ static int wm8775_s_routing(struct v4l2_subdev *sd,
95 return -EINVAL; 102 return -EINVAL;
96 } 103 }
97 state->input = input; 104 state->input = input;
98 if (state->muted) 105 if (!v4l2_ctrl_g_ctrl(state->mute))
99 return 0; 106 return 0;
100 wm8775_write(sd, R21, 0x0c0); 107 wm8775_write(sd, R21, 0x0c0);
101 wm8775_write(sd, R14, 0x1d4); 108 wm8775_write(sd, R14, 0x1d4);
@@ -104,29 +111,21 @@ static int wm8775_s_routing(struct v4l2_subdev *sd,
104 return 0; 111 return 0;
105} 112}
106 113
107static int wm8775_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) 114static int wm8775_s_ctrl(struct v4l2_ctrl *ctrl)
108{ 115{
116 struct v4l2_subdev *sd = to_sd(ctrl);
109 struct wm8775_state *state = to_state(sd); 117 struct wm8775_state *state = to_state(sd);
110 118
111 if (ctrl->id != V4L2_CID_AUDIO_MUTE) 119 switch (ctrl->id) {
112 return -EINVAL; 120 case V4L2_CID_AUDIO_MUTE:
113 ctrl->value = state->muted; 121 wm8775_write(sd, R21, 0x0c0);
114 return 0; 122 wm8775_write(sd, R14, 0x1d4);
115} 123 wm8775_write(sd, R15, 0x1d4);
116 124 if (!ctrl->val)
117static int wm8775_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) 125 wm8775_write(sd, R21, 0x100 + state->input);
118{ 126 return 0;
119 struct wm8775_state *state = to_state(sd); 127 }
120 128 return -EINVAL;
121 if (ctrl->id != V4L2_CID_AUDIO_MUTE)
122 return -EINVAL;
123 state->muted = ctrl->value;
124 wm8775_write(sd, R21, 0x0c0);
125 wm8775_write(sd, R14, 0x1d4);
126 wm8775_write(sd, R15, 0x1d4);
127 if (!state->muted)
128 wm8775_write(sd, R21, 0x100 + state->input);
129 return 0;
130} 129}
131 130
132static int wm8775_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip) 131static int wm8775_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
@@ -140,8 +139,8 @@ static int wm8775_log_status(struct v4l2_subdev *sd)
140{ 139{
141 struct wm8775_state *state = to_state(sd); 140 struct wm8775_state *state = to_state(sd);
142 141
143 v4l2_info(sd, "Input: %d%s\n", state->input, 142 v4l2_info(sd, "Input: %d\n", state->input);
144 state->muted ? " (muted)" : ""); 143 v4l2_ctrl_handler_log_status(&state->hdl, sd->name);
145 return 0; 144 return 0;
146} 145}
147 146
@@ -162,11 +161,20 @@ static int wm8775_s_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *fre
162 161
163/* ----------------------------------------------------------------------- */ 162/* ----------------------------------------------------------------------- */
164 163
164static const struct v4l2_ctrl_ops wm8775_ctrl_ops = {
165 .s_ctrl = wm8775_s_ctrl,
166};
167
165static const struct v4l2_subdev_core_ops wm8775_core_ops = { 168static const struct v4l2_subdev_core_ops wm8775_core_ops = {
166 .log_status = wm8775_log_status, 169 .log_status = wm8775_log_status,
167 .g_chip_ident = wm8775_g_chip_ident, 170 .g_chip_ident = wm8775_g_chip_ident,
168 .g_ctrl = wm8775_g_ctrl, 171 .g_ext_ctrls = v4l2_subdev_g_ext_ctrls,
169 .s_ctrl = wm8775_s_ctrl, 172 .try_ext_ctrls = v4l2_subdev_try_ext_ctrls,
173 .s_ext_ctrls = v4l2_subdev_s_ext_ctrls,
174 .g_ctrl = v4l2_subdev_g_ctrl,
175 .s_ctrl = v4l2_subdev_s_ctrl,
176 .queryctrl = v4l2_subdev_queryctrl,
177 .querymenu = v4l2_subdev_querymenu,
170}; 178};
171 179
172static const struct v4l2_subdev_tuner_ops wm8775_tuner_ops = { 180static const struct v4l2_subdev_tuner_ops wm8775_tuner_ops = {
@@ -205,13 +213,24 @@ static int wm8775_probe(struct i2c_client *client,
205 v4l_info(client, "chip found @ 0x%02x (%s)\n", 213 v4l_info(client, "chip found @ 0x%02x (%s)\n",
206 client->addr << 1, client->adapter->name); 214 client->addr << 1, client->adapter->name);
207 215
208 state = kmalloc(sizeof(struct wm8775_state), GFP_KERNEL); 216 state = kzalloc(sizeof(struct wm8775_state), GFP_KERNEL);
209 if (state == NULL) 217 if (state == NULL)
210 return -ENOMEM; 218 return -ENOMEM;
211 sd = &state->sd; 219 sd = &state->sd;
212 v4l2_i2c_subdev_init(sd, client, &wm8775_ops); 220 v4l2_i2c_subdev_init(sd, client, &wm8775_ops);
213 state->input = 2; 221 state->input = 2;
214 state->muted = 0; 222
223 v4l2_ctrl_handler_init(&state->hdl, 1);
224 state->mute = v4l2_ctrl_new_std(&state->hdl, &wm8775_ctrl_ops,
225 V4L2_CID_AUDIO_MUTE, 0, 1, 1, 0);
226 sd->ctrl_handler = &state->hdl;
227 if (state->hdl.error) {
228 int err = state->hdl.error;
229
230 v4l2_ctrl_handler_free(&state->hdl);
231 kfree(state);
232 return err;
233 }
215 234
216 /* Initialize wm8775 */ 235 /* Initialize wm8775 */
217 236
@@ -248,9 +267,11 @@ static int wm8775_probe(struct i2c_client *client,
248static int wm8775_remove(struct i2c_client *client) 267static int wm8775_remove(struct i2c_client *client)
249{ 268{
250 struct v4l2_subdev *sd = i2c_get_clientdata(client); 269 struct v4l2_subdev *sd = i2c_get_clientdata(client);
270 struct wm8775_state *state = to_state(sd);
251 271
252 v4l2_device_unregister_subdev(sd); 272 v4l2_device_unregister_subdev(sd);
253 kfree(to_state(sd)); 273 v4l2_ctrl_handler_free(&state->hdl);
274 kfree(state);
254 return 0; 275 return 0;
255} 276}
256 277
diff --git a/drivers/memstick/core/mspro_block.c b/drivers/memstick/core/mspro_block.c
index 8327e248520a..d3f1a087eced 100644
--- a/drivers/memstick/core/mspro_block.c
+++ b/drivers/memstick/core/mspro_block.c
@@ -18,6 +18,7 @@
18#include <linux/kthread.h> 18#include <linux/kthread.h>
19#include <linux/delay.h> 19#include <linux/delay.h>
20#include <linux/slab.h> 20#include <linux/slab.h>
21#include <linux/smp_lock.h>
21#include <linux/memstick.h> 22#include <linux/memstick.h>
22 23
23#define DRIVER_NAME "mspro_block" 24#define DRIVER_NAME "mspro_block"
@@ -179,6 +180,7 @@ static int mspro_block_bd_open(struct block_device *bdev, fmode_t mode)
179 struct mspro_block_data *msb = disk->private_data; 180 struct mspro_block_data *msb = disk->private_data;
180 int rc = -ENXIO; 181 int rc = -ENXIO;
181 182
183 lock_kernel();
182 mutex_lock(&mspro_block_disk_lock); 184 mutex_lock(&mspro_block_disk_lock);
183 185
184 if (msb && msb->card) { 186 if (msb && msb->card) {
@@ -190,6 +192,7 @@ static int mspro_block_bd_open(struct block_device *bdev, fmode_t mode)
190 } 192 }
191 193
192 mutex_unlock(&mspro_block_disk_lock); 194 mutex_unlock(&mspro_block_disk_lock);
195 unlock_kernel();
193 196
194 return rc; 197 return rc;
195} 198}
@@ -221,7 +224,11 @@ static int mspro_block_disk_release(struct gendisk *disk)
221 224
222static int mspro_block_bd_release(struct gendisk *disk, fmode_t mode) 225static int mspro_block_bd_release(struct gendisk *disk, fmode_t mode)
223{ 226{
224 return mspro_block_disk_release(disk); 227 int ret;
228 lock_kernel();
229 ret = mspro_block_disk_release(disk);
230 unlock_kernel();
231 return ret;
225} 232}
226 233
227static int mspro_block_bd_getgeo(struct block_device *bdev, 234static int mspro_block_bd_getgeo(struct block_device *bdev,
@@ -805,7 +812,8 @@ static void mspro_block_start(struct memstick_dev *card)
805 812
806static int mspro_block_prepare_req(struct request_queue *q, struct request *req) 813static int mspro_block_prepare_req(struct request_queue *q, struct request *req)
807{ 814{
808 if (!blk_fs_request(req) && !blk_pc_request(req)) { 815 if (req->cmd_type != REQ_TYPE_FS &&
816 req->cmd_type != REQ_TYPE_BLOCK_PC) {
809 blk_dump_rq_flags(req, "MSPro unsupported request"); 817 blk_dump_rq_flags(req, "MSPro unsupported request");
810 return BLKPREP_KILL; 818 return BLKPREP_KILL;
811 } 819 }
@@ -1040,6 +1048,7 @@ static int mspro_block_read_attributes(struct memstick_dev *card)
1040 snprintf(s_attr->name, sizeof(s_attr->name), 1048 snprintf(s_attr->name, sizeof(s_attr->name),
1041 "attr_x%02x", attr->entries[cnt].id); 1049 "attr_x%02x", attr->entries[cnt].id);
1042 1050
1051 sysfs_attr_init(&s_attr->dev_attr.attr);
1043 s_attr->dev_attr.attr.name = s_attr->name; 1052 s_attr->dev_attr.attr.name = s_attr->name;
1044 s_attr->dev_attr.attr.mode = S_IRUGO; 1053 s_attr->dev_attr.attr.mode = S_IRUGO;
1045 s_attr->dev_attr.show = mspro_block_attr_show(s_attr->id); 1054 s_attr->dev_attr.show = mspro_block_attr_show(s_attr->id);
@@ -1330,13 +1339,14 @@ static void mspro_block_remove(struct memstick_dev *card)
1330 struct mspro_block_data *msb = memstick_get_drvdata(card); 1339 struct mspro_block_data *msb = memstick_get_drvdata(card);
1331 unsigned long flags; 1340 unsigned long flags;
1332 1341
1333 del_gendisk(msb->disk);
1334 dev_dbg(&card->dev, "mspro block remove\n");
1335 spin_lock_irqsave(&msb->q_lock, flags); 1342 spin_lock_irqsave(&msb->q_lock, flags);
1336 msb->eject = 1; 1343 msb->eject = 1;
1337 blk_start_queue(msb->queue); 1344 blk_start_queue(msb->queue);
1338 spin_unlock_irqrestore(&msb->q_lock, flags); 1345 spin_unlock_irqrestore(&msb->q_lock, flags);
1339 1346
1347 del_gendisk(msb->disk);
1348 dev_dbg(&card->dev, "mspro block remove\n");
1349
1340 blk_cleanup_queue(msb->queue); 1350 blk_cleanup_queue(msb->queue);
1341 msb->queue = NULL; 1351 msb->queue = NULL;
1342 1352
diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
index b88a244a1edd..6837a8ef9371 100644
--- a/drivers/message/fusion/mptbase.c
+++ b/drivers/message/fusion/mptbase.c
@@ -50,6 +50,7 @@
50#include <linux/module.h> 50#include <linux/module.h>
51#include <linux/errno.h> 51#include <linux/errno.h>
52#include <linux/init.h> 52#include <linux/init.h>
53#include <linux/seq_file.h>
53#include <linux/slab.h> 54#include <linux/slab.h>
54#include <linux/types.h> 55#include <linux/types.h>
55#include <linux/pci.h> 56#include <linux/pci.h>
@@ -109,8 +110,7 @@ MODULE_PARM_DESC(mpt_debug_level, " debug level - refer to mptdebug.h \
109 110
110int mpt_fwfault_debug; 111int mpt_fwfault_debug;
111EXPORT_SYMBOL(mpt_fwfault_debug); 112EXPORT_SYMBOL(mpt_fwfault_debug);
112module_param_call(mpt_fwfault_debug, param_set_int, param_get_int, 113module_param(mpt_fwfault_debug, int, 0600);
113 &mpt_fwfault_debug, 0600);
114MODULE_PARM_DESC(mpt_fwfault_debug, "Enable detection of Firmware fault" 114MODULE_PARM_DESC(mpt_fwfault_debug, "Enable detection of Firmware fault"
115 " and halt Firmware on fault - (default=0)"); 115 " and halt Firmware on fault - (default=0)");
116 116
@@ -200,12 +200,9 @@ static int mpt_host_page_access_control(MPT_ADAPTER *ioc, u8 access_control_valu
200static int mpt_host_page_alloc(MPT_ADAPTER *ioc, pIOCInit_t ioc_init); 200static int mpt_host_page_alloc(MPT_ADAPTER *ioc, pIOCInit_t ioc_init);
201 201
202#ifdef CONFIG_PROC_FS 202#ifdef CONFIG_PROC_FS
203static int procmpt_summary_read(char *buf, char **start, off_t offset, 203static const struct file_operations mpt_summary_proc_fops;
204 int request, int *eof, void *data); 204static const struct file_operations mpt_version_proc_fops;
205static int procmpt_version_read(char *buf, char **start, off_t offset, 205static const struct file_operations mpt_iocinfo_proc_fops;
206 int request, int *eof, void *data);
207static int procmpt_iocinfo_read(char *buf, char **start, off_t offset,
208 int request, int *eof, void *data);
209#endif 206#endif
210static void mpt_get_fw_exp_ver(char *buf, MPT_ADAPTER *ioc); 207static void mpt_get_fw_exp_ver(char *buf, MPT_ADAPTER *ioc);
211 208
@@ -629,6 +626,7 @@ mptbase_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req, MPT_FRAME_HDR *reply)
629 * mpt_register - Register protocol-specific main callback handler. 626 * mpt_register - Register protocol-specific main callback handler.
630 * @cbfunc: callback function pointer 627 * @cbfunc: callback function pointer
631 * @dclass: Protocol driver's class (%MPT_DRIVER_CLASS enum value) 628 * @dclass: Protocol driver's class (%MPT_DRIVER_CLASS enum value)
629 * @func_name: call function's name
632 * 630 *
633 * This routine is called by a protocol-specific driver (SCSI host, 631 * This routine is called by a protocol-specific driver (SCSI host,
634 * LAN, SCSI target) to register its reply callback routine. Each 632 * LAN, SCSI target) to register its reply callback routine. Each
@@ -1725,7 +1723,7 @@ mpt_attach(struct pci_dev *pdev, const struct pci_device_id *id)
1725 u8 pcixcmd; 1723 u8 pcixcmd;
1726 static int mpt_ids = 0; 1724 static int mpt_ids = 0;
1727#ifdef CONFIG_PROC_FS 1725#ifdef CONFIG_PROC_FS
1728 struct proc_dir_entry *dent, *ent; 1726 struct proc_dir_entry *dent;
1729#endif 1727#endif
1730 1728
1731 ioc = kzalloc(sizeof(MPT_ADAPTER), GFP_ATOMIC); 1729 ioc = kzalloc(sizeof(MPT_ADAPTER), GFP_ATOMIC);
@@ -1980,16 +1978,8 @@ mpt_attach(struct pci_dev *pdev, const struct pci_device_id *id)
1980 */ 1978 */
1981 dent = proc_mkdir(ioc->name, mpt_proc_root_dir); 1979 dent = proc_mkdir(ioc->name, mpt_proc_root_dir);
1982 if (dent) { 1980 if (dent) {
1983 ent = create_proc_entry("info", S_IFREG|S_IRUGO, dent); 1981 proc_create_data("info", S_IRUGO, dent, &mpt_iocinfo_proc_fops, ioc);
1984 if (ent) { 1982 proc_create_data("summary", S_IRUGO, dent, &mpt_summary_proc_fops, ioc);
1985 ent->read_proc = procmpt_iocinfo_read;
1986 ent->data = ioc;
1987 }
1988 ent = create_proc_entry("summary", S_IFREG|S_IRUGO, dent);
1989 if (ent) {
1990 ent->read_proc = procmpt_summary_read;
1991 ent->data = ioc;
1992 }
1993 } 1983 }
1994#endif 1984#endif
1995 1985
@@ -6546,20 +6536,12 @@ mpt_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
6546static int 6536static int
6547procmpt_create(void) 6537procmpt_create(void)
6548{ 6538{
6549 struct proc_dir_entry *ent;
6550
6551 mpt_proc_root_dir = proc_mkdir(MPT_PROCFS_MPTBASEDIR, NULL); 6539 mpt_proc_root_dir = proc_mkdir(MPT_PROCFS_MPTBASEDIR, NULL);
6552 if (mpt_proc_root_dir == NULL) 6540 if (mpt_proc_root_dir == NULL)
6553 return -ENOTDIR; 6541 return -ENOTDIR;
6554 6542
6555 ent = create_proc_entry("summary", S_IFREG|S_IRUGO, mpt_proc_root_dir); 6543 proc_create("summary", S_IRUGO, mpt_proc_root_dir, &mpt_summary_proc_fops);
6556 if (ent) 6544 proc_create("version", S_IRUGO, mpt_proc_root_dir, &mpt_version_proc_fops);
6557 ent->read_proc = procmpt_summary_read;
6558
6559 ent = create_proc_entry("version", S_IFREG|S_IRUGO, mpt_proc_root_dir);
6560 if (ent)
6561 ent->read_proc = procmpt_version_read;
6562
6563 return 0; 6545 return 0;
6564} 6546}
6565 6547
@@ -6578,71 +6560,47 @@ procmpt_destroy(void)
6578} 6560}
6579 6561
6580/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 6562/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
6581/** 6563/*
6582 * procmpt_summary_read - Handle read request of a summary file
6583 * @buf: Pointer to area to write information
6584 * @start: Pointer to start pointer
6585 * @offset: Offset to start writing
6586 * @request: Amount of read data requested
6587 * @eof: Pointer to EOF integer
6588 * @data: Pointer
6589 *
6590 * Handles read request from /proc/mpt/summary or /proc/mpt/iocN/summary. 6564 * Handles read request from /proc/mpt/summary or /proc/mpt/iocN/summary.
6591 * Returns number of characters written to process performing the read.
6592 */ 6565 */
6593static int 6566static void seq_mpt_print_ioc_summary(MPT_ADAPTER *ioc, struct seq_file *m, int showlan);
6594procmpt_summary_read(char *buf, char **start, off_t offset, int request, int *eof, void *data)
6595{
6596 MPT_ADAPTER *ioc;
6597 char *out = buf;
6598 int len;
6599
6600 if (data) {
6601 int more = 0;
6602 6567
6603 ioc = data; 6568static int mpt_summary_proc_show(struct seq_file *m, void *v)
6604 mpt_print_ioc_summary(ioc, out, &more, 0, 1); 6569{
6570 MPT_ADAPTER *ioc = m->private;
6605 6571
6606 out += more; 6572 if (ioc) {
6573 seq_mpt_print_ioc_summary(ioc, m, 1);
6607 } else { 6574 } else {
6608 list_for_each_entry(ioc, &ioc_list, list) { 6575 list_for_each_entry(ioc, &ioc_list, list) {
6609 int more = 0; 6576 seq_mpt_print_ioc_summary(ioc, m, 1);
6610
6611 mpt_print_ioc_summary(ioc, out, &more, 0, 1);
6612
6613 out += more;
6614 if ((out-buf) >= request)
6615 break;
6616 } 6577 }
6617 } 6578 }
6618 6579
6619 len = out - buf; 6580 return 0;
6581}
6620 6582
6621 MPT_PROC_READ_RETURN(buf,start,offset,request,eof,len); 6583static int mpt_summary_proc_open(struct inode *inode, struct file *file)
6584{
6585 return single_open(file, mpt_summary_proc_show, PDE(inode)->data);
6622} 6586}
6623 6587
6624/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 6588static const struct file_operations mpt_summary_proc_fops = {
6625/** 6589 .owner = THIS_MODULE,
6626 * procmpt_version_read - Handle read request from /proc/mpt/version. 6590 .open = mpt_summary_proc_open,
6627 * @buf: Pointer to area to write information 6591 .read = seq_read,
6628 * @start: Pointer to start pointer 6592 .llseek = seq_lseek,
6629 * @offset: Offset to start writing 6593 .release = single_release,
6630 * @request: Amount of read data requested 6594};
6631 * @eof: Pointer to EOF integer 6595
6632 * @data: Pointer 6596static int mpt_version_proc_show(struct seq_file *m, void *v)
6633 *
6634 * Returns number of characters written to process performing the read.
6635 */
6636static int
6637procmpt_version_read(char *buf, char **start, off_t offset, int request, int *eof, void *data)
6638{ 6597{
6639 u8 cb_idx; 6598 u8 cb_idx;
6640 int scsi, fc, sas, lan, ctl, targ, dmp; 6599 int scsi, fc, sas, lan, ctl, targ, dmp;
6641 char *drvname; 6600 char *drvname;
6642 int len;
6643 6601
6644 len = sprintf(buf, "%s-%s\n", "mptlinux", MPT_LINUX_VERSION_COMMON); 6602 seq_printf(m, "%s-%s\n", "mptlinux", MPT_LINUX_VERSION_COMMON);
6645 len += sprintf(buf+len, " Fusion MPT base driver\n"); 6603 seq_printf(m, " Fusion MPT base driver\n");
6646 6604
6647 scsi = fc = sas = lan = ctl = targ = dmp = 0; 6605 scsi = fc = sas = lan = ctl = targ = dmp = 0;
6648 for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) { 6606 for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
@@ -6670,98 +6628,97 @@ procmpt_version_read(char *buf, char **start, off_t offset, int request, int *eo
6670 } 6628 }
6671 6629
6672 if (drvname) 6630 if (drvname)
6673 len += sprintf(buf+len, " Fusion MPT %s driver\n", drvname); 6631 seq_printf(m, " Fusion MPT %s driver\n", drvname);
6674 } 6632 }
6675 } 6633 }
6676 6634
6677 MPT_PROC_READ_RETURN(buf,start,offset,request,eof,len); 6635 return 0;
6678} 6636}
6679 6637
6680/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 6638static int mpt_version_proc_open(struct inode *inode, struct file *file)
6681/** 6639{
6682 * procmpt_iocinfo_read - Handle read request from /proc/mpt/iocN/info. 6640 return single_open(file, mpt_version_proc_show, NULL);
6683 * @buf: Pointer to area to write information 6641}
6684 * @start: Pointer to start pointer 6642
6685 * @offset: Offset to start writing 6643static const struct file_operations mpt_version_proc_fops = {
6686 * @request: Amount of read data requested 6644 .owner = THIS_MODULE,
6687 * @eof: Pointer to EOF integer 6645 .open = mpt_version_proc_open,
6688 * @data: Pointer 6646 .read = seq_read,
6689 * 6647 .llseek = seq_lseek,
6690 * Returns number of characters written to process performing the read. 6648 .release = single_release,
6691 */ 6649};
6692static int 6650
6693procmpt_iocinfo_read(char *buf, char **start, off_t offset, int request, int *eof, void *data) 6651static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
6694{ 6652{
6695 MPT_ADAPTER *ioc = data; 6653 MPT_ADAPTER *ioc = m->private;
6696 int len;
6697 char expVer[32]; 6654 char expVer[32];
6698 int sz; 6655 int sz;
6699 int p; 6656 int p;
6700 6657
6701 mpt_get_fw_exp_ver(expVer, ioc); 6658 mpt_get_fw_exp_ver(expVer, ioc);
6702 6659
6703 len = sprintf(buf, "%s:", ioc->name); 6660 seq_printf(m, "%s:", ioc->name);
6704 if (ioc->facts.Flags & MPI_IOCFACTS_FLAGS_FW_DOWNLOAD_BOOT) 6661 if (ioc->facts.Flags & MPI_IOCFACTS_FLAGS_FW_DOWNLOAD_BOOT)
6705 len += sprintf(buf+len, " (f/w download boot flag set)"); 6662 seq_printf(m, " (f/w download boot flag set)");
6706// if (ioc->facts.IOCExceptions & MPI_IOCFACTS_EXCEPT_CONFIG_CHECKSUM_FAIL) 6663// if (ioc->facts.IOCExceptions & MPI_IOCFACTS_EXCEPT_CONFIG_CHECKSUM_FAIL)
6707// len += sprintf(buf+len, " CONFIG_CHECKSUM_FAIL!"); 6664// seq_printf(m, " CONFIG_CHECKSUM_FAIL!");
6708 6665
6709 len += sprintf(buf+len, "\n ProductID = 0x%04x (%s)\n", 6666 seq_printf(m, "\n ProductID = 0x%04x (%s)\n",
6710 ioc->facts.ProductID, 6667 ioc->facts.ProductID,
6711 ioc->prod_name); 6668 ioc->prod_name);
6712 len += sprintf(buf+len, " FWVersion = 0x%08x%s", ioc->facts.FWVersion.Word, expVer); 6669 seq_printf(m, " FWVersion = 0x%08x%s", ioc->facts.FWVersion.Word, expVer);
6713 if (ioc->facts.FWImageSize) 6670 if (ioc->facts.FWImageSize)
6714 len += sprintf(buf+len, " (fw_size=%d)", ioc->facts.FWImageSize); 6671 seq_printf(m, " (fw_size=%d)", ioc->facts.FWImageSize);
6715 len += sprintf(buf+len, "\n MsgVersion = 0x%04x\n", ioc->facts.MsgVersion); 6672 seq_printf(m, "\n MsgVersion = 0x%04x\n", ioc->facts.MsgVersion);
6716 len += sprintf(buf+len, " FirstWhoInit = 0x%02x\n", ioc->FirstWhoInit); 6673 seq_printf(m, " FirstWhoInit = 0x%02x\n", ioc->FirstWhoInit);
6717 len += sprintf(buf+len, " EventState = 0x%02x\n", ioc->facts.EventState); 6674 seq_printf(m, " EventState = 0x%02x\n", ioc->facts.EventState);
6718 6675
6719 len += sprintf(buf+len, " CurrentHostMfaHighAddr = 0x%08x\n", 6676 seq_printf(m, " CurrentHostMfaHighAddr = 0x%08x\n",
6720 ioc->facts.CurrentHostMfaHighAddr); 6677 ioc->facts.CurrentHostMfaHighAddr);
6721 len += sprintf(buf+len, " CurrentSenseBufferHighAddr = 0x%08x\n", 6678 seq_printf(m, " CurrentSenseBufferHighAddr = 0x%08x\n",
6722 ioc->facts.CurrentSenseBufferHighAddr); 6679 ioc->facts.CurrentSenseBufferHighAddr);
6723 6680
6724 len += sprintf(buf+len, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth); 6681 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
6725 len += sprintf(buf+len, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize); 6682 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
6726 6683
6727 len += sprintf(buf+len, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", 6684 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
6728 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma); 6685 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
6729 /* 6686 /*
6730 * Rounding UP to nearest 4-kB boundary here... 6687 * Rounding UP to nearest 4-kB boundary here...
6731 */ 6688 */
6732 sz = (ioc->req_sz * ioc->req_depth) + 128; 6689 sz = (ioc->req_sz * ioc->req_depth) + 128;
6733 sz = ((sz + 0x1000UL - 1UL) / 0x1000) * 0x1000; 6690 sz = ((sz + 0x1000UL - 1UL) / 0x1000) * 0x1000;
6734 len += sprintf(buf+len, " {CurReqSz=%d} x {CurReqDepth=%d} = %d bytes ^= 0x%x\n", 6691 seq_printf(m, " {CurReqSz=%d} x {CurReqDepth=%d} = %d bytes ^= 0x%x\n",
6735 ioc->req_sz, ioc->req_depth, ioc->req_sz*ioc->req_depth, sz); 6692 ioc->req_sz, ioc->req_depth, ioc->req_sz*ioc->req_depth, sz);
6736 len += sprintf(buf+len, " {MaxReqSz=%d} {MaxReqDepth=%d}\n", 6693 seq_printf(m, " {MaxReqSz=%d} {MaxReqDepth=%d}\n",
6737 4*ioc->facts.RequestFrameSize, 6694 4*ioc->facts.RequestFrameSize,
6738 ioc->facts.GlobalCredits); 6695 ioc->facts.GlobalCredits);
6739 6696
6740 len += sprintf(buf+len, " Frames @ 0x%p (Dma @ 0x%p)\n", 6697 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
6741 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma); 6698 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
6742 sz = (ioc->reply_sz * ioc->reply_depth) + 128; 6699 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
6743 len += sprintf(buf+len, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n", 6700 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
6744 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz); 6701 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
6745 len += sprintf(buf+len, " {MaxRepSz=%d} {MaxRepDepth=%d}\n", 6702 seq_printf(m, " {MaxRepSz=%d} {MaxRepDepth=%d}\n",
6746 ioc->facts.CurReplyFrameSize, 6703 ioc->facts.CurReplyFrameSize,
6747 ioc->facts.ReplyQueueDepth); 6704 ioc->facts.ReplyQueueDepth);
6748 6705
6749 len += sprintf(buf+len, " MaxDevices = %d\n", 6706 seq_printf(m, " MaxDevices = %d\n",
6750 (ioc->facts.MaxDevices==0) ? 255 : ioc->facts.MaxDevices); 6707 (ioc->facts.MaxDevices==0) ? 255 : ioc->facts.MaxDevices);
6751 len += sprintf(buf+len, " MaxBuses = %d\n", ioc->facts.MaxBuses); 6708 seq_printf(m, " MaxBuses = %d\n", ioc->facts.MaxBuses);
6752 6709
6753 /* per-port info */ 6710 /* per-port info */
6754 for (p=0; p < ioc->facts.NumberOfPorts; p++) { 6711 for (p=0; p < ioc->facts.NumberOfPorts; p++) {
6755 len += sprintf(buf+len, " PortNumber = %d (of %d)\n", 6712 seq_printf(m, " PortNumber = %d (of %d)\n",
6756 p+1, 6713 p+1,
6757 ioc->facts.NumberOfPorts); 6714 ioc->facts.NumberOfPorts);
6758 if (ioc->bus_type == FC) { 6715 if (ioc->bus_type == FC) {
6759 if (ioc->pfacts[p].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN) { 6716 if (ioc->pfacts[p].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN) {
6760 u8 *a = (u8*)&ioc->lan_cnfg_page1.HardwareAddressLow; 6717 u8 *a = (u8*)&ioc->lan_cnfg_page1.HardwareAddressLow;
6761 len += sprintf(buf+len, " LanAddr = %02X:%02X:%02X:%02X:%02X:%02X\n", 6718 seq_printf(m, " LanAddr = %02X:%02X:%02X:%02X:%02X:%02X\n",
6762 a[5], a[4], a[3], a[2], a[1], a[0]); 6719 a[5], a[4], a[3], a[2], a[1], a[0]);
6763 } 6720 }
6764 len += sprintf(buf+len, " WWN = %08X%08X:%08X%08X\n", 6721 seq_printf(m, " WWN = %08X%08X:%08X%08X\n",
6765 ioc->fc_port_page0[p].WWNN.High, 6722 ioc->fc_port_page0[p].WWNN.High,
6766 ioc->fc_port_page0[p].WWNN.Low, 6723 ioc->fc_port_page0[p].WWNN.Low,
6767 ioc->fc_port_page0[p].WWPN.High, 6724 ioc->fc_port_page0[p].WWPN.High,
@@ -6769,9 +6726,21 @@ procmpt_iocinfo_read(char *buf, char **start, off_t offset, int request, int *eo
6769 } 6726 }
6770 } 6727 }
6771 6728
6772 MPT_PROC_READ_RETURN(buf,start,offset,request,eof,len); 6729 return 0;
6773} 6730}
6774 6731
6732static int mpt_iocinfo_proc_open(struct inode *inode, struct file *file)
6733{
6734 return single_open(file, mpt_iocinfo_proc_show, PDE(inode)->data);
6735}
6736
6737static const struct file_operations mpt_iocinfo_proc_fops = {
6738 .owner = THIS_MODULE,
6739 .open = mpt_iocinfo_proc_open,
6740 .read = seq_read,
6741 .llseek = seq_lseek,
6742 .release = single_release,
6743};
6775#endif /* CONFIG_PROC_FS } */ 6744#endif /* CONFIG_PROC_FS } */
6776 6745
6777/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 6746/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
@@ -6837,6 +6806,39 @@ mpt_print_ioc_summary(MPT_ADAPTER *ioc, char *buffer, int *size, int len, int sh
6837 6806
6838 *size = y; 6807 *size = y;
6839} 6808}
6809
6810static void seq_mpt_print_ioc_summary(MPT_ADAPTER *ioc, struct seq_file *m, int showlan)
6811{
6812 char expVer[32];
6813
6814 mpt_get_fw_exp_ver(expVer, ioc);
6815
6816 /*
6817 * Shorter summary of attached ioc's...
6818 */
6819 seq_printf(m, "%s: %s, %s%08xh%s, Ports=%d, MaxQ=%d",
6820 ioc->name,
6821 ioc->prod_name,
6822 MPT_FW_REV_MAGIC_ID_STRING, /* "FwRev=" or somesuch */
6823 ioc->facts.FWVersion.Word,
6824 expVer,
6825 ioc->facts.NumberOfPorts,
6826 ioc->req_depth);
6827
6828 if (showlan && (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN)) {
6829 u8 *a = (u8*)&ioc->lan_cnfg_page1.HardwareAddressLow;
6830 seq_printf(m, ", LanAddr=%02X:%02X:%02X:%02X:%02X:%02X",
6831 a[5], a[4], a[3], a[2], a[1], a[0]);
6832 }
6833
6834 seq_printf(m, ", IRQ=%d", ioc->pci_irq);
6835
6836 if (!ioc->active)
6837 seq_printf(m, " (disabled)");
6838
6839 seq_putc(m, '\n');
6840}
6841
6840/** 6842/**
6841 * mpt_set_taskmgmt_in_progress_flag - set flags associated with task management 6843 * mpt_set_taskmgmt_in_progress_flag - set flags associated with task management
6842 * @ioc: Pointer to MPT_ADAPTER structure 6844 * @ioc: Pointer to MPT_ADAPTER structure
@@ -6922,7 +6924,6 @@ EXPORT_SYMBOL(mpt_halt_firmware);
6922 * mpt_SoftResetHandler - Issues a less expensive reset 6924 * mpt_SoftResetHandler - Issues a less expensive reset
6923 * @ioc: Pointer to MPT_ADAPTER structure 6925 * @ioc: Pointer to MPT_ADAPTER structure
6924 * @sleepFlag: Indicates if sleep or schedule must be called. 6926 * @sleepFlag: Indicates if sleep or schedule must be called.
6925
6926 * 6927 *
6927 * Returns 0 for SUCCESS or -1 if FAILED. 6928 * Returns 0 for SUCCESS or -1 if FAILED.
6928 * 6929 *
@@ -7067,7 +7068,6 @@ mpt_SoftResetHandler(MPT_ADAPTER *ioc, int sleepFlag)
7067 * mpt_Soft_Hard_ResetHandler - Try less expensive reset 7068 * mpt_Soft_Hard_ResetHandler - Try less expensive reset
7068 * @ioc: Pointer to MPT_ADAPTER structure 7069 * @ioc: Pointer to MPT_ADAPTER structure
7069 * @sleepFlag: Indicates if sleep or schedule must be called. 7070 * @sleepFlag: Indicates if sleep or schedule must be called.
7070
7071 * 7071 *
7072 * Returns 0 for SUCCESS or -1 if FAILED. 7072 * Returns 0 for SUCCESS or -1 if FAILED.
7073 * Try for softreset first, only if it fails go for expensive 7073 * Try for softreset first, only if it fails go for expensive
@@ -8004,6 +8004,7 @@ mpt_spi_log_info(MPT_ADAPTER *ioc, u32 log_info)
8004 * mpt_sas_log_info - Log information returned from SAS IOC. 8004 * mpt_sas_log_info - Log information returned from SAS IOC.
8005 * @ioc: Pointer to MPT_ADAPTER structure 8005 * @ioc: Pointer to MPT_ADAPTER structure
8006 * @log_info: U32 LogInfo reply word from the IOC 8006 * @log_info: U32 LogInfo reply word from the IOC
8007 * @cb_idx: callback function's handle
8007 * 8008 *
8008 * Refer to lsi/mpi_log_sas.h. 8009 * Refer to lsi/mpi_log_sas.h.
8009 **/ 8010 **/
@@ -8050,7 +8051,7 @@ union loginfo_type {
8050 code_desc = ir_code_str[sas_loginfo.dw.code]; 8051 code_desc = ir_code_str[sas_loginfo.dw.code];
8051 if (sas_loginfo.dw.subcode >= 8052 if (sas_loginfo.dw.subcode >=
8052 ARRAY_SIZE(raid_sub_code_str)) 8053 ARRAY_SIZE(raid_sub_code_str))
8053 break; 8054 break;
8054 if (sas_loginfo.dw.code == 0) 8055 if (sas_loginfo.dw.code == 0)
8055 sub_code_desc = 8056 sub_code_desc =
8056 raid_sub_code_str[sas_loginfo.dw.subcode]; 8057 raid_sub_code_str[sas_loginfo.dw.subcode];
diff --git a/drivers/message/fusion/mptbase.h b/drivers/message/fusion/mptbase.h
index 23ed3dec72a5..f71f22948477 100644
--- a/drivers/message/fusion/mptbase.h
+++ b/drivers/message/fusion/mptbase.h
@@ -420,31 +420,6 @@ typedef struct _VirtDevice {
420#define MPT_TARGET_FLAGS_LED_ON 0x80 420#define MPT_TARGET_FLAGS_LED_ON 0x80
421 421
422/* 422/*
423 * /proc/mpt interface
424 */
425typedef struct {
426 const char *name;
427 mode_t mode;
428 int pad;
429 read_proc_t *read_proc;
430 write_proc_t *write_proc;
431} mpt_proc_entry_t;
432
433#define MPT_PROC_READ_RETURN(buf,start,offset,request,eof,len) \
434do { \
435 len -= offset; \
436 if (len < request) { \
437 *eof = 1; \
438 if (len <= 0) \
439 return 0; \
440 } else \
441 len = request; \
442 *start = buf + offset; \
443 return len; \
444} while (0)
445
446
447/*
448 * IOCTL structure and associated defines 423 * IOCTL structure and associated defines
449 */ 424 */
450 425
diff --git a/drivers/message/i2o/exec-osm.c b/drivers/message/i2o/exec-osm.c
index 06c655c55587..a3970e56ae53 100644
--- a/drivers/message/i2o/exec-osm.c
+++ b/drivers/message/i2o/exec-osm.c
@@ -389,12 +389,16 @@ static int i2o_exec_lct_notify(struct i2o_controller *c, u32 change_ind)
389 dev = &c->pdev->dev; 389 dev = &c->pdev->dev;
390 390
391 if (i2o_dma_realloc(dev, &c->dlct, 391 if (i2o_dma_realloc(dev, &c->dlct,
392 le32_to_cpu(sb->expected_lct_size))) 392 le32_to_cpu(sb->expected_lct_size))) {
393 mutex_unlock(&c->lct_lock);
393 return -ENOMEM; 394 return -ENOMEM;
395 }
394 396
395 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET); 397 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
396 if (IS_ERR(msg)) 398 if (IS_ERR(msg)) {
399 mutex_unlock(&c->lct_lock);
397 return PTR_ERR(msg); 400 return PTR_ERR(msg);
401 }
398 402
399 msg->u.head[0] = cpu_to_le32(EIGHT_WORD_MSG_SIZE | SGL_OFFSET_6); 403 msg->u.head[0] = cpu_to_le32(EIGHT_WORD_MSG_SIZE | SGL_OFFSET_6);
400 msg->u.head[1] = cpu_to_le32(I2O_CMD_LCT_NOTIFY << 24 | HOST_TID << 12 | 404 msg->u.head[1] = cpu_to_le32(I2O_CMD_LCT_NOTIFY << 24 | HOST_TID << 12 |
diff --git a/drivers/message/i2o/i2o_block.c b/drivers/message/i2o/i2o_block.c
index fc593fbab696..f0f1e667000f 100644
--- a/drivers/message/i2o/i2o_block.c
+++ b/drivers/message/i2o/i2o_block.c
@@ -53,6 +53,7 @@
53#include <linux/module.h> 53#include <linux/module.h>
54#include <linux/slab.h> 54#include <linux/slab.h>
55#include <linux/i2o.h> 55#include <linux/i2o.h>
56#include <linux/smp_lock.h>
56 57
57#include <linux/mempool.h> 58#include <linux/mempool.h>
58 59
@@ -577,6 +578,7 @@ static int i2o_block_open(struct block_device *bdev, fmode_t mode)
577 if (!dev->i2o_dev) 578 if (!dev->i2o_dev)
578 return -ENODEV; 579 return -ENODEV;
579 580
581 lock_kernel();
580 if (dev->power > 0x1f) 582 if (dev->power > 0x1f)
581 i2o_block_device_power(dev, 0x02); 583 i2o_block_device_power(dev, 0x02);
582 584
@@ -585,6 +587,7 @@ static int i2o_block_open(struct block_device *bdev, fmode_t mode)
585 i2o_block_device_lock(dev->i2o_dev, -1); 587 i2o_block_device_lock(dev->i2o_dev, -1);
586 588
587 osm_debug("Ready.\n"); 589 osm_debug("Ready.\n");
590 unlock_kernel();
588 591
589 return 0; 592 return 0;
590}; 593};
@@ -615,6 +618,7 @@ static int i2o_block_release(struct gendisk *disk, fmode_t mode)
615 if (!dev->i2o_dev) 618 if (!dev->i2o_dev)
616 return 0; 619 return 0;
617 620
621 lock_kernel();
618 i2o_block_device_flush(dev->i2o_dev); 622 i2o_block_device_flush(dev->i2o_dev);
619 623
620 i2o_block_device_unlock(dev->i2o_dev, -1); 624 i2o_block_device_unlock(dev->i2o_dev, -1);
@@ -625,6 +629,7 @@ static int i2o_block_release(struct gendisk *disk, fmode_t mode)
625 operation = 0x24; 629 operation = 0x24;
626 630
627 i2o_block_device_power(dev, operation); 631 i2o_block_device_power(dev, operation);
632 unlock_kernel();
628 633
629 return 0; 634 return 0;
630} 635}
@@ -652,30 +657,40 @@ static int i2o_block_ioctl(struct block_device *bdev, fmode_t mode,
652{ 657{
653 struct gendisk *disk = bdev->bd_disk; 658 struct gendisk *disk = bdev->bd_disk;
654 struct i2o_block_device *dev = disk->private_data; 659 struct i2o_block_device *dev = disk->private_data;
660 int ret = -ENOTTY;
655 661
656 /* Anyone capable of this syscall can do *real bad* things */ 662 /* Anyone capable of this syscall can do *real bad* things */
657 663
658 if (!capable(CAP_SYS_ADMIN)) 664 if (!capable(CAP_SYS_ADMIN))
659 return -EPERM; 665 return -EPERM;
660 666
667 lock_kernel();
661 switch (cmd) { 668 switch (cmd) {
662 case BLKI2OGRSTRAT: 669 case BLKI2OGRSTRAT:
663 return put_user(dev->rcache, (int __user *)arg); 670 ret = put_user(dev->rcache, (int __user *)arg);
671 break;
664 case BLKI2OGWSTRAT: 672 case BLKI2OGWSTRAT:
665 return put_user(dev->wcache, (int __user *)arg); 673 ret = put_user(dev->wcache, (int __user *)arg);
674 break;
666 case BLKI2OSRSTRAT: 675 case BLKI2OSRSTRAT:
676 ret = -EINVAL;
667 if (arg < 0 || arg > CACHE_SMARTFETCH) 677 if (arg < 0 || arg > CACHE_SMARTFETCH)
668 return -EINVAL; 678 break;
669 dev->rcache = arg; 679 dev->rcache = arg;
680 ret = 0;
670 break; 681 break;
671 case BLKI2OSWSTRAT: 682 case BLKI2OSWSTRAT:
683 ret = -EINVAL;
672 if (arg != 0 684 if (arg != 0
673 && (arg < CACHE_WRITETHROUGH || arg > CACHE_SMARTBACK)) 685 && (arg < CACHE_WRITETHROUGH || arg > CACHE_SMARTBACK))
674 return -EINVAL; 686 break;
675 dev->wcache = arg; 687 dev->wcache = arg;
688 ret = 0;
676 break; 689 break;
677 } 690 }
678 return -ENOTTY; 691 unlock_kernel();
692
693 return ret;
679}; 694};
680 695
681/** 696/**
@@ -712,7 +727,7 @@ static int i2o_block_transfer(struct request *req)
712{ 727{
713 struct i2o_block_device *dev = req->rq_disk->private_data; 728 struct i2o_block_device *dev = req->rq_disk->private_data;
714 struct i2o_controller *c; 729 struct i2o_controller *c;
715 u32 tid = dev->i2o_dev->lct_data.tid; 730 u32 tid;
716 struct i2o_message *msg; 731 struct i2o_message *msg;
717 u32 *mptr; 732 u32 *mptr;
718 struct i2o_block_request *ireq = req->special; 733 struct i2o_block_request *ireq = req->special;
@@ -728,6 +743,7 @@ static int i2o_block_transfer(struct request *req)
728 goto exit; 743 goto exit;
729 } 744 }
730 745
746 tid = dev->i2o_dev->lct_data.tid;
731 c = dev->i2o_dev->iop; 747 c = dev->i2o_dev->iop;
732 748
733 msg = i2o_msg_get(c); 749 msg = i2o_msg_get(c);
@@ -883,7 +899,7 @@ static void i2o_block_request_fn(struct request_queue *q)
883 if (!req) 899 if (!req)
884 break; 900 break;
885 901
886 if (blk_fs_request(req)) { 902 if (req->cmd_type == REQ_TYPE_FS) {
887 struct i2o_block_delayed_request *dreq; 903 struct i2o_block_delayed_request *dreq;
888 struct i2o_block_request *ireq = req->special; 904 struct i2o_block_request *ireq = req->special;
889 unsigned int queue_depth; 905 unsigned int queue_depth;
@@ -930,7 +946,8 @@ static const struct block_device_operations i2o_block_fops = {
930 .owner = THIS_MODULE, 946 .owner = THIS_MODULE,
931 .open = i2o_block_open, 947 .open = i2o_block_open,
932 .release = i2o_block_release, 948 .release = i2o_block_release,
933 .locked_ioctl = i2o_block_ioctl, 949 .ioctl = i2o_block_ioctl,
950 .compat_ioctl = i2o_block_ioctl,
934 .getgeo = i2o_block_getgeo, 951 .getgeo = i2o_block_getgeo,
935 .media_changed = i2o_block_media_changed 952 .media_changed = i2o_block_media_changed
936}; 953};
diff --git a/drivers/message/i2o/i2o_config.c b/drivers/message/i2o/i2o_config.c
index c4b117f5fb70..068ba0785bb4 100644
--- a/drivers/message/i2o/i2o_config.c
+++ b/drivers/message/i2o/i2o_config.c
@@ -111,11 +111,11 @@ static int i2o_cfg_gethrt(unsigned long arg)
111 111
112 len = 8 + ((hrt->entry_len * hrt->num_entries) << 2); 112 len = 8 + ((hrt->entry_len * hrt->num_entries) << 2);
113 113
114 /* We did a get user...so assuming mem is ok...is this bad? */ 114 if (put_user(len, kcmd.reslen))
115 put_user(len, kcmd.reslen); 115 ret = -EFAULT;
116 if (len > reslen) 116 else if (len > reslen)
117 ret = -ENOBUFS; 117 ret = -ENOBUFS;
118 if (copy_to_user(kcmd.resbuf, (void *)hrt, len)) 118 else if (copy_to_user(kcmd.resbuf, (void *)hrt, len))
119 ret = -EFAULT; 119 ret = -EFAULT;
120 120
121 return ret; 121 return ret;
@@ -147,8 +147,9 @@ static int i2o_cfg_getlct(unsigned long arg)
147 lct = (i2o_lct *) c->lct; 147 lct = (i2o_lct *) c->lct;
148 148
149 len = (unsigned int)lct->table_size << 2; 149 len = (unsigned int)lct->table_size << 2;
150 put_user(len, kcmd.reslen); 150 if (put_user(len, kcmd.reslen))
151 if (len > reslen) 151 ret = -EFAULT;
152 else if (len > reslen)
152 ret = -ENOBUFS; 153 ret = -ENOBUFS;
153 else if (copy_to_user(kcmd.resbuf, lct, len)) 154 else if (copy_to_user(kcmd.resbuf, lct, len))
154 ret = -EFAULT; 155 ret = -EFAULT;
@@ -208,8 +209,9 @@ static int i2o_cfg_parms(unsigned long arg, unsigned int type)
208 return -EAGAIN; 209 return -EAGAIN;
209 } 210 }
210 211
211 put_user(len, kcmd.reslen); 212 if (put_user(len, kcmd.reslen))
212 if (len > reslen) 213 ret = -EFAULT;
214 else if (len > reslen)
213 ret = -ENOBUFS; 215 ret = -ENOBUFS;
214 else if (copy_to_user(kcmd.resbuf, res, len)) 216 else if (copy_to_user(kcmd.resbuf, res, len))
215 ret = -EFAULT; 217 ret = -EFAULT;
diff --git a/drivers/message/i2o/i2o_scsi.c b/drivers/message/i2o/i2o_scsi.c
index 3d45817e6dcd..ea6b2197da8a 100644
--- a/drivers/message/i2o/i2o_scsi.c
+++ b/drivers/message/i2o/i2o_scsi.c
@@ -528,7 +528,6 @@ static int i2o_scsi_queuecommand(struct scsi_cmnd *SCpnt,
528 * Do the incoming paperwork 528 * Do the incoming paperwork
529 */ 529 */
530 i2o_dev = SCpnt->device->hostdata; 530 i2o_dev = SCpnt->device->hostdata;
531 c = i2o_dev->iop;
532 531
533 SCpnt->scsi_done = done; 532 SCpnt->scsi_done = done;
534 533
@@ -538,7 +537,7 @@ static int i2o_scsi_queuecommand(struct scsi_cmnd *SCpnt,
538 done(SCpnt); 537 done(SCpnt);
539 goto exit; 538 goto exit;
540 } 539 }
541 540 c = i2o_dev->iop;
542 tid = i2o_dev->lct_data.tid; 541 tid = i2o_dev->lct_data.tid;
543 542
544 osm_debug("qcmd: Tid = %03x\n", tid); 543 osm_debug("qcmd: Tid = %03x\n", tid);
diff --git a/drivers/mfd/88pm860x-core.c b/drivers/mfd/88pm860x-core.c
index 2c65a2c57294..07933f3f7e4c 100644
--- a/drivers/mfd/88pm860x-core.c
+++ b/drivers/mfd/88pm860x-core.c
@@ -74,12 +74,12 @@ static struct mfd_cell backlight_devs[] = {
74} 74}
75 75
76static struct resource led_resources[] = { 76static struct resource led_resources[] = {
77 PM8606_LED_RESOURCE(PM8606_LED1_RED, RGB2B), 77 PM8606_LED_RESOURCE(PM8606_LED1_RED, RGB1B),
78 PM8606_LED_RESOURCE(PM8606_LED1_GREEN, RGB2C), 78 PM8606_LED_RESOURCE(PM8606_LED1_GREEN, RGB1C),
79 PM8606_LED_RESOURCE(PM8606_LED1_BLUE, RGB2D), 79 PM8606_LED_RESOURCE(PM8606_LED1_BLUE, RGB1D),
80 PM8606_LED_RESOURCE(PM8606_LED2_RED, RGB1B), 80 PM8606_LED_RESOURCE(PM8606_LED2_RED, RGB2B),
81 PM8606_LED_RESOURCE(PM8606_LED2_GREEN, RGB1C), 81 PM8606_LED_RESOURCE(PM8606_LED2_GREEN, RGB2C),
82 PM8606_LED_RESOURCE(PM8606_LED2_BLUE, RGB1D), 82 PM8606_LED_RESOURCE(PM8606_LED2_BLUE, RGB2D),
83}; 83};
84 84
85#define PM8606_LED_DEVS(_i) \ 85#define PM8606_LED_DEVS(_i) \
@@ -428,52 +428,44 @@ static int __devinit device_gpadc_init(struct pm860x_chip *chip,
428{ 428{
429 struct i2c_client *i2c = (chip->id == CHIP_PM8607) ? chip->client \ 429 struct i2c_client *i2c = (chip->id == CHIP_PM8607) ? chip->client \
430 : chip->companion; 430 : chip->companion;
431 int use_gpadc = 0, data, ret; 431 int data;
432 int ret;
432 433
433 /* initialize GPADC without activating it */ 434 /* initialize GPADC without activating it */
434 435
435 if (pdata && pdata->touch) { 436 if (!pdata || !pdata->touch)
436 /* set GPADC MISC1 register */ 437 return -EINVAL;
437 data = 0;
438 data |= (pdata->touch->gpadc_prebias << 1)
439 & PM8607_GPADC_PREBIAS_MASK;
440 data |= (pdata->touch->slot_cycle << 3)
441 & PM8607_GPADC_SLOT_CYCLE_MASK;
442 data |= (pdata->touch->off_scale << 5)
443 & PM8607_GPADC_OFF_SCALE_MASK;
444 data |= (pdata->touch->sw_cal << 7)
445 & PM8607_GPADC_SW_CAL_MASK;
446 if (data) {
447 ret = pm860x_reg_write(i2c, PM8607_GPADC_MISC1, data);
448 if (ret < 0)
449 goto out;
450 }
451 /* set tsi prebias time */
452 if (pdata->touch->tsi_prebias) {
453 data = pdata->touch->tsi_prebias;
454 ret = pm860x_reg_write(i2c, PM8607_TSI_PREBIAS, data);
455 if (ret < 0)
456 goto out;
457 }
458 /* set prebias & prechg time of pen detect */
459 data = 0;
460 data |= pdata->touch->pen_prebias & PM8607_PD_PREBIAS_MASK;
461 data |= (pdata->touch->pen_prechg << 5)
462 & PM8607_PD_PRECHG_MASK;
463 if (data) {
464 ret = pm860x_reg_write(i2c, PM8607_PD_PREBIAS, data);
465 if (ret < 0)
466 goto out;
467 }
468 438
469 use_gpadc = 1; 439 /* set GPADC MISC1 register */
440 data = 0;
441 data |= (pdata->touch->gpadc_prebias << 1) & PM8607_GPADC_PREBIAS_MASK;
442 data |= (pdata->touch->slot_cycle << 3) & PM8607_GPADC_SLOT_CYCLE_MASK;
443 data |= (pdata->touch->off_scale << 5) & PM8607_GPADC_OFF_SCALE_MASK;
444 data |= (pdata->touch->sw_cal << 7) & PM8607_GPADC_SW_CAL_MASK;
445 if (data) {
446 ret = pm860x_reg_write(i2c, PM8607_GPADC_MISC1, data);
447 if (ret < 0)
448 goto out;
470 } 449 }
471 450 /* set tsi prebias time */
472 /* turn on GPADC */ 451 if (pdata->touch->tsi_prebias) {
473 if (use_gpadc) { 452 data = pdata->touch->tsi_prebias;
474 ret = pm860x_set_bits(i2c, PM8607_GPADC_MISC1, 453 ret = pm860x_reg_write(i2c, PM8607_TSI_PREBIAS, data);
475 PM8607_GPADC_EN, PM8607_GPADC_EN); 454 if (ret < 0)
455 goto out;
476 } 456 }
457 /* set prebias & prechg time of pen detect */
458 data = 0;
459 data |= pdata->touch->pen_prebias & PM8607_PD_PREBIAS_MASK;
460 data |= (pdata->touch->pen_prechg << 5) & PM8607_PD_PRECHG_MASK;
461 if (data) {
462 ret = pm860x_reg_write(i2c, PM8607_PD_PREBIAS, data);
463 if (ret < 0)
464 goto out;
465 }
466
467 ret = pm860x_set_bits(i2c, PM8607_GPADC_MISC1,
468 PM8607_GPADC_EN, PM8607_GPADC_EN);
477out: 469out:
478 return ret; 470 return ret;
479} 471}
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 9da0e504bbe9..db51ea1c6082 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -7,7 +7,16 @@ menuconfig MFD_SUPPORT
7 depends on HAS_IOMEM 7 depends on HAS_IOMEM
8 default y 8 default y
9 help 9 help
10 Configure MFD device drivers. 10 Multifunction devices embed several functions (e.g. GPIOs,
11 touchscreens, keyboards, current regulators, power management chips,
12 etc...) in one single integrated circuit. They usually talk to the
13 main CPU through one or more IRQ lines and low speed data busses (SPI,
14 I2C, etc..). They appear as one single device to the main system
15 through the data bus and the MFD framework allows for sub devices
16 (a.k.a. functions) to appear as discrete platform devices.
17 MFDs are typically found on embedded platforms.
18
19 This option alone does not add any kernel code.
11 20
12if MFD_SUPPORT 21if MFD_SUPPORT
13 22
@@ -177,6 +186,38 @@ config TWL4030_CODEC
177 select MFD_CORE 186 select MFD_CORE
178 default n 187 default n
179 188
189config TWL6030_PWM
190 tristate "TWL6030 PWM (Pulse Width Modulator) Support"
191 depends on TWL4030_CORE
192 select HAVE_PWM
193 default n
194 help
195 Say yes here if you want support for TWL6030 PWM.
196 This is used to control charging LED brightness.
197
198config MFD_STMPE
199 bool "Support STMicroelectronics STMPE"
200 depends on I2C=y && GENERIC_HARDIRQS
201 select MFD_CORE
202 help
203 Support for the STMPE family of I/O Expanders from
204 STMicroelectronics.
205
206 Currently supported devices are:
207
208 STMPE811: GPIO, Touchscreen
209 STMPE1601: GPIO, Keypad
210 STMPE2401: GPIO, Keypad
211 STMPE2403: GPIO, Keypad
212
213 This driver provides common support for accessing the device,
214 additional drivers must be enabled in order to use the functionality
215 of the device. Currently available sub drivers are:
216
217 GPIO: stmpe-gpio
218 Keypad: stmpe-keypad
219 Touchscreen: stmpe-ts
220
180config MFD_TC35892 221config MFD_TC35892
181 bool "Support Toshiba TC35892" 222 bool "Support Toshiba TC35892"
182 depends on I2C=y && GENERIC_HARDIRQS 223 depends on I2C=y && GENERIC_HARDIRQS
@@ -252,6 +293,16 @@ config MFD_MAX8925
252 accessing the device, additional drivers must be enabled in order 293 accessing the device, additional drivers must be enabled in order
253 to use the functionality of the device. 294 to use the functionality of the device.
254 295
296config MFD_MAX8998
297 bool "Maxim Semiconductor MAX8998 PMIC Support"
298 depends on I2C=y
299 select MFD_CORE
300 help
301 Say yes here to support for Maxim Semiconductor MAX8998. This is
302 a Power Management IC. This driver provies common support for
303 accessing the device, additional drivers must be enabled in order
304 to use the functionality of the device.
305
255config MFD_WM8400 306config MFD_WM8400
256 tristate "Support Wolfson Microelectronics WM8400" 307 tristate "Support Wolfson Microelectronics WM8400"
257 select MFD_CORE 308 select MFD_CORE
@@ -482,6 +533,28 @@ config MFD_JANZ_CMODIO
482 host many different types of MODULbus daughterboards, including 533 host many different types of MODULbus daughterboards, including
483 CAN and GPIO controllers. 534 CAN and GPIO controllers.
484 535
536config MFD_JZ4740_ADC
537 tristate "Support for the JZ4740 SoC ADC core"
538 select MFD_CORE
539 depends on MACH_JZ4740
540 help
541 Say yes here if you want support for the ADC unit in the JZ4740 SoC.
542 This driver is necessary for jz4740-battery and jz4740-hwmon driver.
543
544config MFD_TPS6586X
545 tristate "TPS6586x Power Management chips"
546 depends on I2C && GPIOLIB
547 select MFD_CORE
548 help
549 If you say yes here you get support for the TPS6586X series of
550 Power Management chips.
551 This driver provides common support for accessing the device,
552 additional drivers must be enabled in order to use the
553 functionality of the device.
554
555 This driver can also be built as a module. If so, the module
556 will be called tps6586x.
557
485endif # MFD_SUPPORT 558endif # MFD_SUPPORT
486 559
487menu "Multimedia Capabilities Port drivers" 560menu "Multimedia Capabilities Port drivers"
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index fb503e77dc60..feaeeaeeddb7 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -15,6 +15,7 @@ obj-$(CONFIG_HTC_I2CPLD) += htc-i2cpld.o
15obj-$(CONFIG_MFD_DAVINCI_VOICECODEC) += davinci_voicecodec.o 15obj-$(CONFIG_MFD_DAVINCI_VOICECODEC) += davinci_voicecodec.o
16obj-$(CONFIG_MFD_DM355EVM_MSP) += dm355evm_msp.o 16obj-$(CONFIG_MFD_DM355EVM_MSP) += dm355evm_msp.o
17 17
18obj-$(CONFIG_MFD_STMPE) += stmpe.o
18obj-$(CONFIG_MFD_TC35892) += tc35892.o 19obj-$(CONFIG_MFD_TC35892) += tc35892.o
19obj-$(CONFIG_MFD_T7L66XB) += t7l66xb.o tmio_core.o 20obj-$(CONFIG_MFD_T7L66XB) += t7l66xb.o tmio_core.o
20obj-$(CONFIG_MFD_TC6387XB) += tc6387xb.o tmio_core.o 21obj-$(CONFIG_MFD_TC6387XB) += tc6387xb.o tmio_core.o
@@ -36,6 +37,7 @@ obj-$(CONFIG_MENELAUS) += menelaus.o
36obj-$(CONFIG_TWL4030_CORE) += twl-core.o twl4030-irq.o twl6030-irq.o 37obj-$(CONFIG_TWL4030_CORE) += twl-core.o twl4030-irq.o twl6030-irq.o
37obj-$(CONFIG_TWL4030_POWER) += twl4030-power.o 38obj-$(CONFIG_TWL4030_POWER) += twl4030-power.o
38obj-$(CONFIG_TWL4030_CODEC) += twl4030-codec.o 39obj-$(CONFIG_TWL4030_CODEC) += twl4030-codec.o
40obj-$(CONFIG_TWL6030_PWM) += twl6030-pwm.o
39 41
40obj-$(CONFIG_MFD_MC13783) += mc13783-core.o 42obj-$(CONFIG_MFD_MC13783) += mc13783-core.o
41 43
@@ -56,6 +58,7 @@ obj-$(CONFIG_UCB1400_CORE) += ucb1400_core.o
56obj-$(CONFIG_PMIC_DA903X) += da903x.o 58obj-$(CONFIG_PMIC_DA903X) += da903x.o
57max8925-objs := max8925-core.o max8925-i2c.o 59max8925-objs := max8925-core.o max8925-i2c.o
58obj-$(CONFIG_MFD_MAX8925) += max8925.o 60obj-$(CONFIG_MFD_MAX8925) += max8925.o
61obj-$(CONFIG_MFD_MAX8998) += max8998.o
59 62
60pcf50633-objs := pcf50633-core.o pcf50633-irq.o 63pcf50633-objs := pcf50633-core.o pcf50633-irq.o
61obj-$(CONFIG_MFD_PCF50633) += pcf50633.o 64obj-$(CONFIG_MFD_PCF50633) += pcf50633.o
@@ -71,3 +74,5 @@ obj-$(CONFIG_PMIC_ADP5520) += adp5520.o
71obj-$(CONFIG_LPC_SCH) += lpc_sch.o 74obj-$(CONFIG_LPC_SCH) += lpc_sch.o
72obj-$(CONFIG_MFD_RDC321X) += rdc321x-southbridge.o 75obj-$(CONFIG_MFD_RDC321X) += rdc321x-southbridge.o
73obj-$(CONFIG_MFD_JANZ_CMODIO) += janz-cmodio.o 76obj-$(CONFIG_MFD_JANZ_CMODIO) += janz-cmodio.o
77obj-$(CONFIG_MFD_JZ4740_ADC) += jz4740-adc.o
78obj-$(CONFIG_MFD_TPS6586X) += tps6586x.o
diff --git a/drivers/mfd/ab3100-otp.c b/drivers/mfd/ab3100-otp.c
index 63d2b727ddbb..8440010eb2b8 100644
--- a/drivers/mfd/ab3100-otp.c
+++ b/drivers/mfd/ab3100-otp.c
@@ -199,7 +199,7 @@ static int __init ab3100_otp_probe(struct platform_device *pdev)
199 199
200 err = ab3100_otp_read(otp); 200 err = ab3100_otp_read(otp);
201 if (err) 201 if (err)
202 return err; 202 goto err_otp_read;
203 203
204 dev_info(&pdev->dev, "AB3100 OTP readout registered\n"); 204 dev_info(&pdev->dev, "AB3100 OTP readout registered\n");
205 205
@@ -208,21 +208,21 @@ static int __init ab3100_otp_probe(struct platform_device *pdev)
208 err = device_create_file(&pdev->dev, 208 err = device_create_file(&pdev->dev,
209 &ab3100_otp_attrs[i]); 209 &ab3100_otp_attrs[i]);
210 if (err) 210 if (err)
211 goto out_no_sysfs; 211 goto err_create_file;
212 } 212 }
213 213
214 /* debugfs entries */ 214 /* debugfs entries */
215 err = ab3100_otp_init_debugfs(&pdev->dev, otp); 215 err = ab3100_otp_init_debugfs(&pdev->dev, otp);
216 if (err) 216 if (err)
217 goto out_no_debugfs; 217 goto err_init_debugfs;
218 218
219 return 0; 219 return 0;
220 220
221out_no_sysfs: 221err_init_debugfs:
222 for (i = 0; i < ARRAY_SIZE(ab3100_otp_attrs); i++) 222err_create_file:
223 device_remove_file(&pdev->dev, 223 while (--i >= 0)
224 &ab3100_otp_attrs[i]); 224 device_remove_file(&pdev->dev, &ab3100_otp_attrs[i]);
225out_no_debugfs: 225err_otp_read:
226 kfree(otp); 226 kfree(otp);
227 return err; 227 return err;
228} 228}
diff --git a/drivers/mfd/ab3550-core.c b/drivers/mfd/ab3550-core.c
index f54ab62e7bc6..8a98739e6d9c 100644
--- a/drivers/mfd/ab3550-core.c
+++ b/drivers/mfd/ab3550-core.c
@@ -589,16 +589,16 @@ static bool reg_read_allowed(const struct ab3550_reg_ranges *ranges, u8 reg)
589} 589}
590 590
591/* 591/*
592 * The exported register access functionality. 592 * The register access functionality.
593 */ 593 */
594int ab3550_get_chip_id(struct device *dev) 594static int ab3550_get_chip_id(struct device *dev)
595{ 595{
596 struct ab3550 *ab = dev_get_drvdata(dev->parent); 596 struct ab3550 *ab = dev_get_drvdata(dev->parent);
597 return (int)ab->chip_id; 597 return (int)ab->chip_id;
598} 598}
599 599
600int ab3550_mask_and_set_register_interruptible(struct device *dev, u8 bank, 600static int ab3550_mask_and_set_register_interruptible(struct device *dev,
601 u8 reg, u8 bitmask, u8 bitvalues) 601 u8 bank, u8 reg, u8 bitmask, u8 bitvalues)
602{ 602{
603 struct ab3550 *ab; 603 struct ab3550 *ab;
604 struct platform_device *pdev = to_platform_device(dev); 604 struct platform_device *pdev = to_platform_device(dev);
@@ -612,15 +612,15 @@ int ab3550_mask_and_set_register_interruptible(struct device *dev, u8 bank,
612 bitmask, bitvalues); 612 bitmask, bitvalues);
613} 613}
614 614
615int ab3550_set_register_interruptible(struct device *dev, u8 bank, u8 reg, 615static int ab3550_set_register_interruptible(struct device *dev, u8 bank,
616 u8 value) 616 u8 reg, u8 value)
617{ 617{
618 return ab3550_mask_and_set_register_interruptible(dev, bank, reg, 0xFF, 618 return ab3550_mask_and_set_register_interruptible(dev, bank, reg, 0xFF,
619 value); 619 value);
620} 620}
621 621
622int ab3550_get_register_interruptible(struct device *dev, u8 bank, u8 reg, 622static int ab3550_get_register_interruptible(struct device *dev, u8 bank,
623 u8 *value) 623 u8 reg, u8 *value)
624{ 624{
625 struct ab3550 *ab; 625 struct ab3550 *ab;
626 struct platform_device *pdev = to_platform_device(dev); 626 struct platform_device *pdev = to_platform_device(dev);
@@ -633,7 +633,7 @@ int ab3550_get_register_interruptible(struct device *dev, u8 bank, u8 reg,
633 return get_register_interruptible(ab, bank, reg, value); 633 return get_register_interruptible(ab, bank, reg, value);
634} 634}
635 635
636int ab3550_get_register_page_interruptible(struct device *dev, u8 bank, 636static int ab3550_get_register_page_interruptible(struct device *dev, u8 bank,
637 u8 first_reg, u8 *regvals, u8 numregs) 637 u8 first_reg, u8 *regvals, u8 numregs)
638{ 638{
639 struct ab3550 *ab; 639 struct ab3550 *ab;
@@ -649,7 +649,8 @@ int ab3550_get_register_page_interruptible(struct device *dev, u8 bank,
649 numregs); 649 numregs);
650} 650}
651 651
652int ab3550_event_registers_startup_state_get(struct device *dev, u8 *event) 652static int ab3550_event_registers_startup_state_get(struct device *dev,
653 u8 *event)
653{ 654{
654 struct ab3550 *ab; 655 struct ab3550 *ab;
655 656
@@ -661,7 +662,7 @@ int ab3550_event_registers_startup_state_get(struct device *dev, u8 *event)
661 return 0; 662 return 0;
662} 663}
663 664
664int ab3550_startup_irq_enabled(struct device *dev, unsigned int irq) 665static int ab3550_startup_irq_enabled(struct device *dev, unsigned int irq)
665{ 666{
666 struct ab3550 *ab; 667 struct ab3550 *ab;
667 struct ab3550_platform_data *plf_data; 668 struct ab3550_platform_data *plf_data;
diff --git a/drivers/mfd/ab8500-core.c b/drivers/mfd/ab8500-core.c
index f3d26fa9c34d..defa786dee34 100644
--- a/drivers/mfd/ab8500-core.c
+++ b/drivers/mfd/ab8500-core.c
@@ -16,6 +16,7 @@
16#include <linux/platform_device.h> 16#include <linux/platform_device.h>
17#include <linux/mfd/core.h> 17#include <linux/mfd/core.h>
18#include <linux/mfd/ab8500.h> 18#include <linux/mfd/ab8500.h>
19#include <linux/regulator/ab8500.h>
19 20
20/* 21/*
21 * Interrupt register offsets 22 * Interrupt register offsets
@@ -352,6 +353,7 @@ static struct mfd_cell ab8500_devs[] = {
352 { .name = "ab8500-audio", }, 353 { .name = "ab8500-audio", },
353 { .name = "ab8500-usb", }, 354 { .name = "ab8500-usb", },
354 { .name = "ab8500-pwm", }, 355 { .name = "ab8500-pwm", },
356 { .name = "ab8500-regulator", },
355}; 357};
356 358
357int __devinit ab8500_init(struct ab8500 *ab8500) 359int __devinit ab8500_init(struct ab8500 *ab8500)
@@ -411,7 +413,7 @@ int __devinit ab8500_init(struct ab8500 *ab8500)
411 goto out_removeirq; 413 goto out_removeirq;
412 } 414 }
413 415
414 ret = mfd_add_devices(ab8500->dev, -1, ab8500_devs, 416 ret = mfd_add_devices(ab8500->dev, 0, ab8500_devs,
415 ARRAY_SIZE(ab8500_devs), NULL, 417 ARRAY_SIZE(ab8500_devs), NULL,
416 ab8500->irq_base); 418 ab8500->irq_base);
417 if (ret) 419 if (ret)
diff --git a/drivers/mfd/ab8500-spi.c b/drivers/mfd/ab8500-spi.c
index b81d4f768ef6..e1c8b62b086d 100644
--- a/drivers/mfd/ab8500-spi.c
+++ b/drivers/mfd/ab8500-spi.c
@@ -68,7 +68,12 @@ static int ab8500_spi_read(struct ab8500 *ab8500, u16 addr)
68 68
69 ret = spi_sync(spi, &msg); 69 ret = spi_sync(spi, &msg);
70 if (!ret) 70 if (!ret)
71 ret = ab8500->rx_buf[0]; 71 /*
72 * Only the 8 lowermost bytes are
73 * defined with value, the rest may
74 * vary depending on chip/board noise.
75 */
76 ret = ab8500->rx_buf[0] & 0xFFU;
72 77
73 return ret; 78 return ret;
74} 79}
diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
index 3b3b97ec32a7..f12720dbe126 100644
--- a/drivers/mfd/abx500-core.c
+++ b/drivers/mfd/abx500-core.c
@@ -36,7 +36,7 @@ int abx500_register_ops(struct device *dev, struct abx500_ops *ops)
36 struct abx500_device_entry *dev_entry; 36 struct abx500_device_entry *dev_entry;
37 37
38 dev_entry = kzalloc(sizeof(struct abx500_device_entry), GFP_KERNEL); 38 dev_entry = kzalloc(sizeof(struct abx500_device_entry), GFP_KERNEL);
39 if (IS_ERR(dev_entry)) { 39 if (!dev_entry) {
40 dev_err(dev, "register_ops kzalloc failed"); 40 dev_err(dev, "register_ops kzalloc failed");
41 return -ENOMEM; 41 return -ENOMEM;
42 } 42 }
diff --git a/drivers/mfd/davinci_voicecodec.c b/drivers/mfd/davinci_voicecodec.c
index 3e75f02e4778..33c923d215c7 100644
--- a/drivers/mfd/davinci_voicecodec.c
+++ b/drivers/mfd/davinci_voicecodec.c
@@ -94,7 +94,8 @@ static int __init davinci_vc_probe(struct platform_device *pdev)
94 res = platform_get_resource(pdev, IORESOURCE_DMA, 0); 94 res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
95 if (!res) { 95 if (!res) {
96 dev_err(&pdev->dev, "no DMA resource\n"); 96 dev_err(&pdev->dev, "no DMA resource\n");
97 return -ENXIO; 97 ret = -ENXIO;
98 goto fail4;
98 } 99 }
99 100
100 davinci_vc->davinci_vcif.dma_tx_channel = res->start; 101 davinci_vc->davinci_vcif.dma_tx_channel = res->start;
@@ -104,7 +105,8 @@ static int __init davinci_vc_probe(struct platform_device *pdev)
104 res = platform_get_resource(pdev, IORESOURCE_DMA, 1); 105 res = platform_get_resource(pdev, IORESOURCE_DMA, 1);
105 if (!res) { 106 if (!res) {
106 dev_err(&pdev->dev, "no DMA resource\n"); 107 dev_err(&pdev->dev, "no DMA resource\n");
107 return -ENXIO; 108 ret = -ENXIO;
109 goto fail4;
108 } 110 }
109 111
110 davinci_vc->davinci_vcif.dma_rx_channel = res->start; 112 davinci_vc->davinci_vcif.dma_rx_channel = res->start;
diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
index 9ed630799acc..36a166bcdb08 100644
--- a/drivers/mfd/janz-cmodio.c
+++ b/drivers/mfd/janz-cmodio.c
@@ -18,6 +18,7 @@
18#include <linux/interrupt.h> 18#include <linux/interrupt.h>
19#include <linux/delay.h> 19#include <linux/delay.h>
20#include <linux/platform_device.h> 20#include <linux/platform_device.h>
21#include <linux/slab.h>
21#include <linux/mfd/core.h> 22#include <linux/mfd/core.h>
22 23
23#include <linux/mfd/janz.h> 24#include <linux/mfd/janz.h>
diff --git a/drivers/mfd/jz4740-adc.c b/drivers/mfd/jz4740-adc.c
new file mode 100644
index 000000000000..3ad492cb6c41
--- /dev/null
+++ b/drivers/mfd/jz4740-adc.c
@@ -0,0 +1,394 @@
1/*
2 * Copyright (C) 2009-2010, Lars-Peter Clausen <lars@metafoo.de>
3 * JZ4740 SoC ADC driver
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; either version 2 of the License, or (at your
8 * option) any later version.
9 *
10 * You should have received a copy of the GNU General Public License along
11 * with this program; if not, write to the Free Software Foundation, Inc.,
12 * 675 Mass Ave, Cambridge, MA 02139, USA.
13 *
14 * This driver synchronizes access to the JZ4740 ADC core between the
15 * JZ4740 battery and hwmon drivers.
16 */
17
18#include <linux/err.h>
19#include <linux/irq.h>
20#include <linux/interrupt.h>
21#include <linux/kernel.h>
22#include <linux/module.h>
23#include <linux/platform_device.h>
24#include <linux/slab.h>
25#include <linux/spinlock.h>
26
27#include <linux/clk.h>
28#include <linux/mfd/core.h>
29
30#include <linux/jz4740-adc.h>
31
32
33#define JZ_REG_ADC_ENABLE 0x00
34#define JZ_REG_ADC_CFG 0x04
35#define JZ_REG_ADC_CTRL 0x08
36#define JZ_REG_ADC_STATUS 0x0c
37
38#define JZ_REG_ADC_TOUCHSCREEN_BASE 0x10
39#define JZ_REG_ADC_BATTERY_BASE 0x1c
40#define JZ_REG_ADC_HWMON_BASE 0x20
41
42#define JZ_ADC_ENABLE_TOUCH BIT(2)
43#define JZ_ADC_ENABLE_BATTERY BIT(1)
44#define JZ_ADC_ENABLE_ADCIN BIT(0)
45
46enum {
47 JZ_ADC_IRQ_ADCIN = 0,
48 JZ_ADC_IRQ_BATTERY,
49 JZ_ADC_IRQ_TOUCH,
50 JZ_ADC_IRQ_PENUP,
51 JZ_ADC_IRQ_PENDOWN,
52};
53
54struct jz4740_adc {
55 struct resource *mem;
56 void __iomem *base;
57
58 int irq;
59 int irq_base;
60
61 struct clk *clk;
62 atomic_t clk_ref;
63
64 spinlock_t lock;
65};
66
67static inline void jz4740_adc_irq_set_masked(struct jz4740_adc *adc, int irq,
68 bool masked)
69{
70 unsigned long flags;
71 uint8_t val;
72
73 irq -= adc->irq_base;
74
75 spin_lock_irqsave(&adc->lock, flags);
76
77 val = readb(adc->base + JZ_REG_ADC_CTRL);
78 if (masked)
79 val |= BIT(irq);
80 else
81 val &= ~BIT(irq);
82 writeb(val, adc->base + JZ_REG_ADC_CTRL);
83
84 spin_unlock_irqrestore(&adc->lock, flags);
85}
86
87static void jz4740_adc_irq_mask(unsigned int irq)
88{
89 struct jz4740_adc *adc = get_irq_chip_data(irq);
90 jz4740_adc_irq_set_masked(adc, irq, true);
91}
92
93static void jz4740_adc_irq_unmask(unsigned int irq)
94{
95 struct jz4740_adc *adc = get_irq_chip_data(irq);
96 jz4740_adc_irq_set_masked(adc, irq, false);
97}
98
99static void jz4740_adc_irq_ack(unsigned int irq)
100{
101 struct jz4740_adc *adc = get_irq_chip_data(irq);
102
103 irq -= adc->irq_base;
104 writeb(BIT(irq), adc->base + JZ_REG_ADC_STATUS);
105}
106
107static struct irq_chip jz4740_adc_irq_chip = {
108 .name = "jz4740-adc",
109 .mask = jz4740_adc_irq_mask,
110 .unmask = jz4740_adc_irq_unmask,
111 .ack = jz4740_adc_irq_ack,
112};
113
114static void jz4740_adc_irq_demux(unsigned int irq, struct irq_desc *desc)
115{
116 struct jz4740_adc *adc = get_irq_desc_data(desc);
117 uint8_t status;
118 unsigned int i;
119
120 status = readb(adc->base + JZ_REG_ADC_STATUS);
121
122 for (i = 0; i < 5; ++i) {
123 if (status & BIT(i))
124 generic_handle_irq(adc->irq_base + i);
125 }
126}
127
128
129/* Refcounting for the ADC clock is done in here instead of in the clock
130 * framework, because it is the only clock which is shared between multiple
131 * devices and thus is the only clock which needs refcounting */
132static inline void jz4740_adc_clk_enable(struct jz4740_adc *adc)
133{
134 if (atomic_inc_return(&adc->clk_ref) == 1)
135 clk_enable(adc->clk);
136}
137
138static inline void jz4740_adc_clk_disable(struct jz4740_adc *adc)
139{
140 if (atomic_dec_return(&adc->clk_ref) == 0)
141 clk_disable(adc->clk);
142}
143
144static inline void jz4740_adc_set_enabled(struct jz4740_adc *adc, int engine,
145 bool enabled)
146{
147 unsigned long flags;
148 uint8_t val;
149
150 spin_lock_irqsave(&adc->lock, flags);
151
152 val = readb(adc->base + JZ_REG_ADC_ENABLE);
153 if (enabled)
154 val |= BIT(engine);
155 else
156 val &= BIT(engine);
157 writeb(val, adc->base + JZ_REG_ADC_ENABLE);
158
159 spin_unlock_irqrestore(&adc->lock, flags);
160}
161
162static int jz4740_adc_cell_enable(struct platform_device *pdev)
163{
164 struct jz4740_adc *adc = dev_get_drvdata(pdev->dev.parent);
165
166 jz4740_adc_clk_enable(adc);
167 jz4740_adc_set_enabled(adc, pdev->id, true);
168
169 return 0;
170}
171
172static int jz4740_adc_cell_disable(struct platform_device *pdev)
173{
174 struct jz4740_adc *adc = dev_get_drvdata(pdev->dev.parent);
175
176 jz4740_adc_set_enabled(adc, pdev->id, false);
177 jz4740_adc_clk_disable(adc);
178
179 return 0;
180}
181
182int jz4740_adc_set_config(struct device *dev, uint32_t mask, uint32_t val)
183{
184 struct jz4740_adc *adc = dev_get_drvdata(dev);
185 unsigned long flags;
186 uint32_t cfg;
187
188 if (!adc)
189 return -ENODEV;
190
191 spin_lock_irqsave(&adc->lock, flags);
192
193 cfg = readl(adc->base + JZ_REG_ADC_CFG);
194
195 cfg &= ~mask;
196 cfg |= val;
197
198 writel(cfg, adc->base + JZ_REG_ADC_CFG);
199
200 spin_unlock_irqrestore(&adc->lock, flags);
201
202 return 0;
203}
204EXPORT_SYMBOL_GPL(jz4740_adc_set_config);
205
206static struct resource jz4740_hwmon_resources[] = {
207 {
208 .start = JZ_ADC_IRQ_ADCIN,
209 .flags = IORESOURCE_IRQ,
210 },
211 {
212 .start = JZ_REG_ADC_HWMON_BASE,
213 .end = JZ_REG_ADC_HWMON_BASE + 3,
214 .flags = IORESOURCE_MEM,
215 },
216};
217
218static struct resource jz4740_battery_resources[] = {
219 {
220 .start = JZ_ADC_IRQ_BATTERY,
221 .flags = IORESOURCE_IRQ,
222 },
223 {
224 .start = JZ_REG_ADC_BATTERY_BASE,
225 .end = JZ_REG_ADC_BATTERY_BASE + 3,
226 .flags = IORESOURCE_MEM,
227 },
228};
229
230const struct mfd_cell jz4740_adc_cells[] = {
231 {
232 .id = 0,
233 .name = "jz4740-hwmon",
234 .num_resources = ARRAY_SIZE(jz4740_hwmon_resources),
235 .resources = jz4740_hwmon_resources,
236 .platform_data = (void *)&jz4740_adc_cells[0],
237 .data_size = sizeof(struct mfd_cell),
238
239 .enable = jz4740_adc_cell_enable,
240 .disable = jz4740_adc_cell_disable,
241 },
242 {
243 .id = 1,
244 .name = "jz4740-battery",
245 .num_resources = ARRAY_SIZE(jz4740_battery_resources),
246 .resources = jz4740_battery_resources,
247 .platform_data = (void *)&jz4740_adc_cells[1],
248 .data_size = sizeof(struct mfd_cell),
249
250 .enable = jz4740_adc_cell_enable,
251 .disable = jz4740_adc_cell_disable,
252 },
253};
254
255static int __devinit jz4740_adc_probe(struct platform_device *pdev)
256{
257 int ret;
258 struct jz4740_adc *adc;
259 struct resource *mem_base;
260 int irq;
261
262 adc = kmalloc(sizeof(*adc), GFP_KERNEL);
263 if (!adc) {
264 dev_err(&pdev->dev, "Failed to allocate driver structure\n");
265 return -ENOMEM;
266 }
267
268 adc->irq = platform_get_irq(pdev, 0);
269 if (adc->irq < 0) {
270 ret = adc->irq;
271 dev_err(&pdev->dev, "Failed to get platform irq: %d\n", ret);
272 goto err_free;
273 }
274
275 adc->irq_base = platform_get_irq(pdev, 1);
276 if (adc->irq_base < 0) {
277 ret = adc->irq_base;
278 dev_err(&pdev->dev, "Failed to get irq base: %d\n", ret);
279 goto err_free;
280 }
281
282 mem_base = platform_get_resource(pdev, IORESOURCE_MEM, 0);
283 if (!mem_base) {
284 ret = -ENOENT;
285 dev_err(&pdev->dev, "Failed to get platform mmio resource\n");
286 goto err_free;
287 }
288
289 /* Only request the shared registers for the MFD driver */
290 adc->mem = request_mem_region(mem_base->start, JZ_REG_ADC_STATUS,
291 pdev->name);
292 if (!adc->mem) {
293 ret = -EBUSY;
294 dev_err(&pdev->dev, "Failed to request mmio memory region\n");
295 goto err_free;
296 }
297
298 adc->base = ioremap_nocache(adc->mem->start, resource_size(adc->mem));
299 if (!adc->base) {
300 ret = -EBUSY;
301 dev_err(&pdev->dev, "Failed to ioremap mmio memory\n");
302 goto err_release_mem_region;
303 }
304
305 adc->clk = clk_get(&pdev->dev, "adc");
306 if (IS_ERR(adc->clk)) {
307 ret = PTR_ERR(adc->clk);
308 dev_err(&pdev->dev, "Failed to get clock: %d\n", ret);
309 goto err_iounmap;
310 }
311
312 spin_lock_init(&adc->lock);
313 atomic_set(&adc->clk_ref, 0);
314
315 platform_set_drvdata(pdev, adc);
316
317 for (irq = adc->irq_base; irq < adc->irq_base + 5; ++irq) {
318 set_irq_chip_data(irq, adc);
319 set_irq_chip_and_handler(irq, &jz4740_adc_irq_chip,
320 handle_level_irq);
321 }
322
323 set_irq_data(adc->irq, adc);
324 set_irq_chained_handler(adc->irq, jz4740_adc_irq_demux);
325
326 writeb(0x00, adc->base + JZ_REG_ADC_ENABLE);
327 writeb(0xff, adc->base + JZ_REG_ADC_CTRL);
328
329 ret = mfd_add_devices(&pdev->dev, 0, jz4740_adc_cells,
330 ARRAY_SIZE(jz4740_adc_cells), mem_base, adc->irq_base);
331 if (ret < 0)
332 goto err_clk_put;
333
334 return 0;
335
336err_clk_put:
337 clk_put(adc->clk);
338err_iounmap:
339 platform_set_drvdata(pdev, NULL);
340 iounmap(adc->base);
341err_release_mem_region:
342 release_mem_region(adc->mem->start, resource_size(adc->mem));
343err_free:
344 kfree(adc);
345
346 return ret;
347}
348
349static int __devexit jz4740_adc_remove(struct platform_device *pdev)
350{
351 struct jz4740_adc *adc = platform_get_drvdata(pdev);
352
353 mfd_remove_devices(&pdev->dev);
354
355 set_irq_data(adc->irq, NULL);
356 set_irq_chained_handler(adc->irq, NULL);
357
358 iounmap(adc->base);
359 release_mem_region(adc->mem->start, resource_size(adc->mem));
360
361 clk_put(adc->clk);
362
363 platform_set_drvdata(pdev, NULL);
364
365 kfree(adc);
366
367 return 0;
368}
369
370struct platform_driver jz4740_adc_driver = {
371 .probe = jz4740_adc_probe,
372 .remove = __devexit_p(jz4740_adc_remove),
373 .driver = {
374 .name = "jz4740-adc",
375 .owner = THIS_MODULE,
376 },
377};
378
379static int __init jz4740_adc_init(void)
380{
381 return platform_driver_register(&jz4740_adc_driver);
382}
383module_init(jz4740_adc_init);
384
385static void __exit jz4740_adc_exit(void)
386{
387 platform_driver_unregister(&jz4740_adc_driver);
388}
389module_exit(jz4740_adc_exit);
390
391MODULE_DESCRIPTION("JZ4740 SoC ADC driver");
392MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
393MODULE_LICENSE("GPL");
394MODULE_ALIAS("platform:jz4740-adc");
diff --git a/drivers/mfd/max8925-core.c b/drivers/mfd/max8925-core.c
index f621bcea3d02..04028a9ee082 100644
--- a/drivers/mfd/max8925-core.c
+++ b/drivers/mfd/max8925-core.c
@@ -90,6 +90,24 @@ static struct mfd_cell rtc_devs[] = {
90 }, 90 },
91}; 91};
92 92
93static struct resource onkey_resources[] = {
94 {
95 .name = "max8925-onkey",
96 .start = MAX8925_IRQ_GPM_SW_3SEC,
97 .end = MAX8925_IRQ_GPM_SW_3SEC,
98 .flags = IORESOURCE_IRQ,
99 },
100};
101
102static struct mfd_cell onkey_devs[] = {
103 {
104 .name = "max8925-onkey",
105 .num_resources = 1,
106 .resources = &onkey_resources[0],
107 .id = -1,
108 },
109};
110
93#define MAX8925_REG_RESOURCE(_start, _end) \ 111#define MAX8925_REG_RESOURCE(_start, _end) \
94{ \ 112{ \
95 .start = MAX8925_##_start, \ 113 .start = MAX8925_##_start, \
@@ -596,6 +614,15 @@ int __devinit max8925_device_init(struct max8925_chip *chip,
596 dev_err(chip->dev, "Failed to add rtc subdev\n"); 614 dev_err(chip->dev, "Failed to add rtc subdev\n");
597 goto out; 615 goto out;
598 } 616 }
617
618 ret = mfd_add_devices(chip->dev, 0, &onkey_devs[0],
619 ARRAY_SIZE(onkey_devs),
620 &onkey_resources[0], 0);
621 if (ret < 0) {
622 dev_err(chip->dev, "Failed to add onkey subdev\n");
623 goto out_dev;
624 }
625
599 if (pdata && pdata->regulator[0]) { 626 if (pdata && pdata->regulator[0]) {
600 ret = mfd_add_devices(chip->dev, 0, &regulator_devs[0], 627 ret = mfd_add_devices(chip->dev, 0, &regulator_devs[0],
601 ARRAY_SIZE(regulator_devs), 628 ARRAY_SIZE(regulator_devs),
diff --git a/drivers/mfd/max8998.c b/drivers/mfd/max8998.c
new file mode 100644
index 000000000000..73e6f5c4efc9
--- /dev/null
+++ b/drivers/mfd/max8998.c
@@ -0,0 +1,158 @@
1/*
2 * max8698.c - mfd core driver for the Maxim 8998
3 *
4 * Copyright (C) 2009-2010 Samsung Electronics
5 * Kyungmin Park <kyungmin.park@samsung.com>
6 * Marek Szyprowski <m.szyprowski@samsung.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 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23#include <linux/module.h>
24#include <linux/moduleparam.h>
25#include <linux/init.h>
26#include <linux/slab.h>
27#include <linux/i2c.h>
28#include <linux/mutex.h>
29#include <linux/mfd/core.h>
30#include <linux/mfd/max8998.h>
31#include <linux/mfd/max8998-private.h>
32
33static struct mfd_cell max8998_devs[] = {
34 {
35 .name = "max8998-pmic",
36 }
37};
38
39static int max8998_i2c_device_read(struct max8998_dev *max8998, u8 reg, u8 *dest)
40{
41 struct i2c_client *client = max8998->i2c_client;
42 int ret;
43
44 mutex_lock(&max8998->iolock);
45 ret = i2c_smbus_read_byte_data(client, reg);
46 mutex_unlock(&max8998->iolock);
47 if (ret < 0)
48 return ret;
49
50 ret &= 0xff;
51 *dest = ret;
52 return 0;
53}
54
55static int max8998_i2c_device_write(struct max8998_dev *max8998, u8 reg, u8 value)
56{
57 struct i2c_client *client = max8998->i2c_client;
58 int ret;
59
60 mutex_lock(&max8998->iolock);
61 ret = i2c_smbus_write_byte_data(client, reg, value);
62 mutex_unlock(&max8998->iolock);
63 return ret;
64}
65
66static int max8998_i2c_device_update(struct max8998_dev *max8998, u8 reg,
67 u8 val, u8 mask)
68{
69 struct i2c_client *client = max8998->i2c_client;
70 int ret;
71
72 mutex_lock(&max8998->iolock);
73 ret = i2c_smbus_read_byte_data(client, reg);
74 if (ret >= 0) {
75 u8 old_val = ret & 0xff;
76 u8 new_val = (val & mask) | (old_val & (~mask));
77 ret = i2c_smbus_write_byte_data(client, reg, new_val);
78 if (ret >= 0)
79 ret = 0;
80 }
81 mutex_unlock(&max8998->iolock);
82 return ret;
83}
84
85static int max8998_i2c_probe(struct i2c_client *i2c,
86 const struct i2c_device_id *id)
87{
88 struct max8998_dev *max8998;
89 int ret = 0;
90
91 max8998 = kzalloc(sizeof(struct max8998_dev), GFP_KERNEL);
92 if (max8998 == NULL)
93 return -ENOMEM;
94
95 i2c_set_clientdata(i2c, max8998);
96 max8998->dev = &i2c->dev;
97 max8998->i2c_client = i2c;
98 max8998->dev_read = max8998_i2c_device_read;
99 max8998->dev_write = max8998_i2c_device_write;
100 max8998->dev_update = max8998_i2c_device_update;
101 mutex_init(&max8998->iolock);
102
103 ret = mfd_add_devices(max8998->dev, -1,
104 max8998_devs, ARRAY_SIZE(max8998_devs),
105 NULL, 0);
106 if (ret < 0)
107 goto err;
108
109 return ret;
110
111err:
112 mfd_remove_devices(max8998->dev);
113 kfree(max8998);
114 return ret;
115}
116
117static int max8998_i2c_remove(struct i2c_client *i2c)
118{
119 struct max8998_dev *max8998 = i2c_get_clientdata(i2c);
120
121 mfd_remove_devices(max8998->dev);
122 kfree(max8998);
123
124 return 0;
125}
126
127static const struct i2c_device_id max8998_i2c_id[] = {
128 { "max8998", 0 },
129 { }
130};
131MODULE_DEVICE_TABLE(i2c, max8998_i2c_id);
132
133static struct i2c_driver max8998_i2c_driver = {
134 .driver = {
135 .name = "max8998",
136 .owner = THIS_MODULE,
137 },
138 .probe = max8998_i2c_probe,
139 .remove = max8998_i2c_remove,
140 .id_table = max8998_i2c_id,
141};
142
143static int __init max8998_i2c_init(void)
144{
145 return i2c_add_driver(&max8998_i2c_driver);
146}
147/* init early so consumer devices can complete system boot */
148subsys_initcall(max8998_i2c_init);
149
150static void __exit max8998_i2c_exit(void)
151{
152 i2c_del_driver(&max8998_i2c_driver);
153}
154module_exit(max8998_i2c_exit);
155
156MODULE_DESCRIPTION("MAXIM 8998 multi-function core driver");
157MODULE_AUTHOR("Kyungmin Park <kyungmin.park@samsung.com>");
158MODULE_LICENSE("GPL");
diff --git a/drivers/mfd/mc13783-core.c b/drivers/mfd/mc13783-core.c
index fecf38a4f025..6df34989c1f6 100644
--- a/drivers/mfd/mc13783-core.c
+++ b/drivers/mfd/mc13783-core.c
@@ -11,9 +11,31 @@
11 */ 11 */
12#include <linux/slab.h> 12#include <linux/slab.h>
13#include <linux/module.h> 13#include <linux/module.h>
14#include <linux/platform_device.h>
15#include <linux/mutex.h>
16#include <linux/interrupt.h>
14#include <linux/spi/spi.h> 17#include <linux/spi/spi.h>
15#include <linux/mfd/core.h> 18#include <linux/mfd/core.h>
16#include <linux/mfd/mc13783-private.h> 19#include <linux/mfd/mc13783.h>
20
21struct mc13783 {
22 struct spi_device *spidev;
23 struct mutex lock;
24 int irq;
25 int flags;
26
27 irq_handler_t irqhandler[MC13783_NUM_IRQ];
28 void *irqdata[MC13783_NUM_IRQ];
29
30 /* XXX these should go as platformdata to the regulator subdevice */
31 struct mc13783_regulator_init_data *regulators;
32 int num_regulators;
33};
34
35#define MC13783_REG_REVISION 7
36#define MC13783_REG_ADC_0 43
37#define MC13783_REG_ADC_1 44
38#define MC13783_REG_ADC_2 45
17 39
18#define MC13783_IRQSTAT0 0 40#define MC13783_IRQSTAT0 0
19#define MC13783_IRQSTAT0_ADCDONEI (1 << 0) 41#define MC13783_IRQSTAT0_ADCDONEI (1 << 0)
@@ -226,6 +248,12 @@ int mc13783_reg_rmw(struct mc13783 *mc13783, unsigned int offset,
226} 248}
227EXPORT_SYMBOL(mc13783_reg_rmw); 249EXPORT_SYMBOL(mc13783_reg_rmw);
228 250
251int mc13783_get_flags(struct mc13783 *mc13783)
252{
253 return mc13783->flags;
254}
255EXPORT_SYMBOL(mc13783_get_flags);
256
229int mc13783_irq_mask(struct mc13783 *mc13783, int irq) 257int mc13783_irq_mask(struct mc13783 *mc13783, int irq)
230{ 258{
231 int ret; 259 int ret;
diff --git a/drivers/mfd/menelaus.c b/drivers/mfd/menelaus.c
index a3fb4bcb9889..4ba85bbdb4c1 100644
--- a/drivers/mfd/menelaus.c
+++ b/drivers/mfd/menelaus.c
@@ -128,6 +128,39 @@
128#define MENELAUS_RESERVED14_IRQ 14 /* Reserved */ 128#define MENELAUS_RESERVED14_IRQ 14 /* Reserved */
129#define MENELAUS_RESERVED15_IRQ 15 /* Reserved */ 129#define MENELAUS_RESERVED15_IRQ 15 /* Reserved */
130 130
131/* VCORE_CTRL1 register */
132#define VCORE_CTRL1_BYP_COMP (1 << 5)
133#define VCORE_CTRL1_HW_NSW (1 << 7)
134
135/* GPIO_CTRL register */
136#define GPIO_CTRL_SLOTSELEN (1 << 5)
137#define GPIO_CTRL_SLPCTLEN (1 << 6)
138#define GPIO1_DIR_INPUT (1 << 0)
139#define GPIO2_DIR_INPUT (1 << 1)
140#define GPIO3_DIR_INPUT (1 << 2)
141
142/* MCT_CTRL1 register */
143#define MCT_CTRL1_S1_CMD_OD (1 << 2)
144#define MCT_CTRL1_S2_CMD_OD (1 << 3)
145
146/* MCT_CTRL2 register */
147#define MCT_CTRL2_VS2_SEL_D0 (1 << 0)
148#define MCT_CTRL2_VS2_SEL_D1 (1 << 1)
149#define MCT_CTRL2_S1CD_BUFEN (1 << 4)
150#define MCT_CTRL2_S2CD_BUFEN (1 << 5)
151#define MCT_CTRL2_S1CD_DBEN (1 << 6)
152#define MCT_CTRL2_S2CD_BEN (1 << 7)
153
154/* MCT_CTRL3 register */
155#define MCT_CTRL3_SLOT1_EN (1 << 0)
156#define MCT_CTRL3_SLOT2_EN (1 << 1)
157#define MCT_CTRL3_S1_AUTO_EN (1 << 2)
158#define MCT_CTRL3_S2_AUTO_EN (1 << 3)
159
160/* MCT_PIN_ST register */
161#define MCT_PIN_ST_S1_CD_ST (1 << 0)
162#define MCT_PIN_ST_S2_CD_ST (1 << 1)
163
131static void menelaus_work(struct work_struct *_menelaus); 164static void menelaus_work(struct work_struct *_menelaus);
132 165
133struct menelaus_chip { 166struct menelaus_chip {
@@ -249,10 +282,10 @@ static void menelaus_mmc_cd_work(struct menelaus_chip *menelaus_hw)
249 return; 282 return;
250 283
251 if (!(reg & 0x1)) 284 if (!(reg & 0x1))
252 card_mask |= (1 << 0); 285 card_mask |= MCT_PIN_ST_S1_CD_ST;
253 286
254 if (!(reg & 0x2)) 287 if (!(reg & 0x2))
255 card_mask |= (1 << 1); 288 card_mask |= MCT_PIN_ST_S2_CD_ST;
256 289
257 if (menelaus_hw->mmc_callback) 290 if (menelaus_hw->mmc_callback)
258 menelaus_hw->mmc_callback(menelaus_hw->mmc_callback_data, 291 menelaus_hw->mmc_callback(menelaus_hw->mmc_callback_data,
@@ -277,14 +310,14 @@ int menelaus_set_mmc_opendrain(int slot, int enable)
277 val = ret; 310 val = ret;
278 if (slot == 1) { 311 if (slot == 1) {
279 if (enable) 312 if (enable)
280 val |= 1 << 2; 313 val |= MCT_CTRL1_S1_CMD_OD;
281 else 314 else
282 val &= ~(1 << 2); 315 val &= ~MCT_CTRL1_S1_CMD_OD;
283 } else { 316 } else {
284 if (enable) 317 if (enable)
285 val |= 1 << 3; 318 val |= MCT_CTRL1_S2_CMD_OD;
286 else 319 else
287 val &= ~(1 << 3); 320 val &= ~MCT_CTRL1_S2_CMD_OD;
288 } 321 }
289 ret = menelaus_write_reg(MENELAUS_MCT_CTRL1, val); 322 ret = menelaus_write_reg(MENELAUS_MCT_CTRL1, val);
290 mutex_unlock(&the_menelaus->lock); 323 mutex_unlock(&the_menelaus->lock);
@@ -301,11 +334,11 @@ int menelaus_set_slot_sel(int enable)
301 ret = menelaus_read_reg(MENELAUS_GPIO_CTRL); 334 ret = menelaus_read_reg(MENELAUS_GPIO_CTRL);
302 if (ret < 0) 335 if (ret < 0)
303 goto out; 336 goto out;
304 ret |= 0x02; 337 ret |= GPIO2_DIR_INPUT;
305 if (enable) 338 if (enable)
306 ret |= 1 << 5; 339 ret |= GPIO_CTRL_SLOTSELEN;
307 else 340 else
308 ret &= ~(1 << 5); 341 ret &= ~GPIO_CTRL_SLOTSELEN;
309 ret = menelaus_write_reg(MENELAUS_GPIO_CTRL, ret); 342 ret = menelaus_write_reg(MENELAUS_GPIO_CTRL, ret);
310out: 343out:
311 mutex_unlock(&the_menelaus->lock); 344 mutex_unlock(&the_menelaus->lock);
@@ -330,14 +363,14 @@ int menelaus_set_mmc_slot(int slot, int enable, int power, int cd_en)
330 val = ret; 363 val = ret;
331 if (slot == 1) { 364 if (slot == 1) {
332 if (cd_en) 365 if (cd_en)
333 val |= (1 << 4) | (1 << 6); 366 val |= MCT_CTRL2_S1CD_BUFEN | MCT_CTRL2_S1CD_DBEN;
334 else 367 else
335 val &= ~((1 << 4) | (1 << 6)); 368 val &= ~(MCT_CTRL2_S1CD_BUFEN | MCT_CTRL2_S1CD_DBEN);
336 } else { 369 } else {
337 if (cd_en) 370 if (cd_en)
338 val |= (1 << 5) | (1 << 7); 371 val |= MCT_CTRL2_S2CD_BUFEN | MCT_CTRL2_S2CD_BEN;
339 else 372 else
340 val &= ~((1 << 5) | (1 << 7)); 373 val &= ~(MCT_CTRL2_S2CD_BUFEN | MCT_CTRL2_S2CD_BEN);
341 } 374 }
342 ret = menelaus_write_reg(MENELAUS_MCT_CTRL2, val); 375 ret = menelaus_write_reg(MENELAUS_MCT_CTRL2, val);
343 if (ret < 0) 376 if (ret < 0)
@@ -349,25 +382,25 @@ int menelaus_set_mmc_slot(int slot, int enable, int power, int cd_en)
349 val = ret; 382 val = ret;
350 if (slot == 1) { 383 if (slot == 1) {
351 if (enable) 384 if (enable)
352 val |= 1 << 0; 385 val |= MCT_CTRL3_SLOT1_EN;
353 else 386 else
354 val &= ~(1 << 0); 387 val &= ~MCT_CTRL3_SLOT1_EN;
355 } else { 388 } else {
356 int b; 389 int b;
357 390
358 if (enable) 391 if (enable)
359 ret |= 1 << 1; 392 val |= MCT_CTRL3_SLOT2_EN;
360 else 393 else
361 ret &= ~(1 << 1); 394 val &= ~MCT_CTRL3_SLOT2_EN;
362 b = menelaus_read_reg(MENELAUS_MCT_CTRL2); 395 b = menelaus_read_reg(MENELAUS_MCT_CTRL2);
363 b &= ~0x03; 396 b &= ~(MCT_CTRL2_VS2_SEL_D0 | MCT_CTRL2_VS2_SEL_D1);
364 b |= power; 397 b |= power;
365 ret = menelaus_write_reg(MENELAUS_MCT_CTRL2, b); 398 ret = menelaus_write_reg(MENELAUS_MCT_CTRL2, b);
366 if (ret < 0) 399 if (ret < 0)
367 goto out; 400 goto out;
368 } 401 }
369 /* Disable autonomous shutdown */ 402 /* Disable autonomous shutdown */
370 val &= ~(0x03 << 2); 403 val &= ~(MCT_CTRL3_S1_AUTO_EN | MCT_CTRL3_S2_AUTO_EN);
371 ret = menelaus_write_reg(MENELAUS_MCT_CTRL3, val); 404 ret = menelaus_write_reg(MENELAUS_MCT_CTRL3, val);
372out: 405out:
373 mutex_unlock(&the_menelaus->lock); 406 mutex_unlock(&the_menelaus->lock);
@@ -552,7 +585,7 @@ int menelaus_set_vcore_hw(unsigned int roof_mV, unsigned int floor_mV)
552 if (!the_menelaus->vcore_hw_mode) { 585 if (!the_menelaus->vcore_hw_mode) {
553 val = menelaus_read_reg(MENELAUS_VCORE_CTRL1); 586 val = menelaus_read_reg(MENELAUS_VCORE_CTRL1);
554 /* HW mode, turn OFF byte comparator */ 587 /* HW mode, turn OFF byte comparator */
555 val |= ((1 << 7) | (1 << 5)); 588 val |= (VCORE_CTRL1_HW_NSW | VCORE_CTRL1_BYP_COMP);
556 ret = menelaus_write_reg(MENELAUS_VCORE_CTRL1, val); 589 ret = menelaus_write_reg(MENELAUS_VCORE_CTRL1, val);
557 the_menelaus->vcore_hw_mode = 1; 590 the_menelaus->vcore_hw_mode = 1;
558 } 591 }
@@ -749,7 +782,7 @@ int menelaus_set_regulator_sleep(int enable, u32 val)
749 ret = menelaus_read_reg(MENELAUS_GPIO_CTRL); 782 ret = menelaus_read_reg(MENELAUS_GPIO_CTRL);
750 if (ret < 0) 783 if (ret < 0)
751 goto out; 784 goto out;
752 t = ((1 << 6) | 0x04); 785 t = (GPIO_CTRL_SLPCTLEN | GPIO3_DIR_INPUT);
753 if (enable) 786 if (enable)
754 ret |= t; 787 ret |= t;
755 else 788 else
diff --git a/drivers/mfd/mfd-core.c b/drivers/mfd/mfd-core.c
index 7dd76bceaae8..1823a57b7d8f 100644
--- a/drivers/mfd/mfd-core.c
+++ b/drivers/mfd/mfd-core.c
@@ -70,7 +70,9 @@ static int mfd_add_device(struct device *parent, int id,
70 goto fail_res; 70 goto fail_res;
71 } 71 }
72 72
73 platform_device_add_resources(pdev, res, cell->num_resources); 73 ret = platform_device_add_resources(pdev, res, cell->num_resources);
74 if (ret)
75 goto fail_res;
74 76
75 ret = platform_device_add(pdev); 77 ret = platform_device_add(pdev);
76 if (ret) 78 if (ret)
diff --git a/drivers/mfd/stmpe.c b/drivers/mfd/stmpe.c
new file mode 100644
index 000000000000..0754c5e91995
--- /dev/null
+++ b/drivers/mfd/stmpe.c
@@ -0,0 +1,985 @@
1/*
2 * Copyright (C) ST-Ericsson SA 2010
3 *
4 * License Terms: GNU General Public License, version 2
5 * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
6 */
7
8#include <linux/kernel.h>
9#include <linux/module.h>
10#include <linux/interrupt.h>
11#include <linux/irq.h>
12#include <linux/slab.h>
13#include <linux/i2c.h>
14#include <linux/mfd/core.h>
15#include <linux/mfd/stmpe.h>
16#include "stmpe.h"
17
18static int __stmpe_enable(struct stmpe *stmpe, unsigned int blocks)
19{
20 return stmpe->variant->enable(stmpe, blocks, true);
21}
22
23static int __stmpe_disable(struct stmpe *stmpe, unsigned int blocks)
24{
25 return stmpe->variant->enable(stmpe, blocks, false);
26}
27
28static int __stmpe_reg_read(struct stmpe *stmpe, u8 reg)
29{
30 int ret;
31
32 ret = i2c_smbus_read_byte_data(stmpe->i2c, reg);
33 if (ret < 0)
34 dev_err(stmpe->dev, "failed to read reg %#x: %d\n",
35 reg, ret);
36
37 dev_vdbg(stmpe->dev, "rd: reg %#x => data %#x\n", reg, ret);
38
39 return ret;
40}
41
42static int __stmpe_reg_write(struct stmpe *stmpe, u8 reg, u8 val)
43{
44 int ret;
45
46 dev_vdbg(stmpe->dev, "wr: reg %#x <= %#x\n", reg, val);
47
48 ret = i2c_smbus_write_byte_data(stmpe->i2c, reg, val);
49 if (ret < 0)
50 dev_err(stmpe->dev, "failed to write reg %#x: %d\n",
51 reg, ret);
52
53 return ret;
54}
55
56static int __stmpe_set_bits(struct stmpe *stmpe, u8 reg, u8 mask, u8 val)
57{
58 int ret;
59
60 ret = __stmpe_reg_read(stmpe, reg);
61 if (ret < 0)
62 return ret;
63
64 ret &= ~mask;
65 ret |= val;
66
67 return __stmpe_reg_write(stmpe, reg, ret);
68}
69
70static int __stmpe_block_read(struct stmpe *stmpe, u8 reg, u8 length,
71 u8 *values)
72{
73 int ret;
74
75 ret = i2c_smbus_read_i2c_block_data(stmpe->i2c, reg, length, values);
76 if (ret < 0)
77 dev_err(stmpe->dev, "failed to read regs %#x: %d\n",
78 reg, ret);
79
80 dev_vdbg(stmpe->dev, "rd: reg %#x (%d) => ret %#x\n", reg, length, ret);
81 stmpe_dump_bytes("stmpe rd: ", values, length);
82
83 return ret;
84}
85
86static int __stmpe_block_write(struct stmpe *stmpe, u8 reg, u8 length,
87 const u8 *values)
88{
89 int ret;
90
91 dev_vdbg(stmpe->dev, "wr: regs %#x (%d)\n", reg, length);
92 stmpe_dump_bytes("stmpe wr: ", values, length);
93
94 ret = i2c_smbus_write_i2c_block_data(stmpe->i2c, reg, length,
95 values);
96 if (ret < 0)
97 dev_err(stmpe->dev, "failed to write regs %#x: %d\n",
98 reg, ret);
99
100 return ret;
101}
102
103/**
104 * stmpe_enable - enable blocks on an STMPE device
105 * @stmpe: Device to work on
106 * @blocks: Mask of blocks (enum stmpe_block values) to enable
107 */
108int stmpe_enable(struct stmpe *stmpe, unsigned int blocks)
109{
110 int ret;
111
112 mutex_lock(&stmpe->lock);
113 ret = __stmpe_enable(stmpe, blocks);
114 mutex_unlock(&stmpe->lock);
115
116 return ret;
117}
118EXPORT_SYMBOL_GPL(stmpe_enable);
119
120/**
121 * stmpe_disable - disable blocks on an STMPE device
122 * @stmpe: Device to work on
123 * @blocks: Mask of blocks (enum stmpe_block values) to enable
124 */
125int stmpe_disable(struct stmpe *stmpe, unsigned int blocks)
126{
127 int ret;
128
129 mutex_lock(&stmpe->lock);
130 ret = __stmpe_disable(stmpe, blocks);
131 mutex_unlock(&stmpe->lock);
132
133 return ret;
134}
135EXPORT_SYMBOL_GPL(stmpe_disable);
136
137/**
138 * stmpe_reg_read() - read a single STMPE register
139 * @stmpe: Device to read from
140 * @reg: Register to read
141 */
142int stmpe_reg_read(struct stmpe *stmpe, u8 reg)
143{
144 int ret;
145
146 mutex_lock(&stmpe->lock);
147 ret = __stmpe_reg_read(stmpe, reg);
148 mutex_unlock(&stmpe->lock);
149
150 return ret;
151}
152EXPORT_SYMBOL_GPL(stmpe_reg_read);
153
154/**
155 * stmpe_reg_write() - write a single STMPE register
156 * @stmpe: Device to write to
157 * @reg: Register to write
158 * @val: Value to write
159 */
160int stmpe_reg_write(struct stmpe *stmpe, u8 reg, u8 val)
161{
162 int ret;
163
164 mutex_lock(&stmpe->lock);
165 ret = __stmpe_reg_write(stmpe, reg, val);
166 mutex_unlock(&stmpe->lock);
167
168 return ret;
169}
170EXPORT_SYMBOL_GPL(stmpe_reg_write);
171
172/**
173 * stmpe_set_bits() - set the value of a bitfield in a STMPE register
174 * @stmpe: Device to write to
175 * @reg: Register to write
176 * @mask: Mask of bits to set
177 * @val: Value to set
178 */
179int stmpe_set_bits(struct stmpe *stmpe, u8 reg, u8 mask, u8 val)
180{
181 int ret;
182
183 mutex_lock(&stmpe->lock);
184 ret = __stmpe_set_bits(stmpe, reg, mask, val);
185 mutex_unlock(&stmpe->lock);
186
187 return ret;
188}
189EXPORT_SYMBOL_GPL(stmpe_set_bits);
190
191/**
192 * stmpe_block_read() - read multiple STMPE registers
193 * @stmpe: Device to read from
194 * @reg: First register
195 * @length: Number of registers
196 * @values: Buffer to write to
197 */
198int stmpe_block_read(struct stmpe *stmpe, u8 reg, u8 length, u8 *values)
199{
200 int ret;
201
202 mutex_lock(&stmpe->lock);
203 ret = __stmpe_block_read(stmpe, reg, length, values);
204 mutex_unlock(&stmpe->lock);
205
206 return ret;
207}
208EXPORT_SYMBOL_GPL(stmpe_block_read);
209
210/**
211 * stmpe_block_write() - write multiple STMPE registers
212 * @stmpe: Device to write to
213 * @reg: First register
214 * @length: Number of registers
215 * @values: Values to write
216 */
217int stmpe_block_write(struct stmpe *stmpe, u8 reg, u8 length,
218 const u8 *values)
219{
220 int ret;
221
222 mutex_lock(&stmpe->lock);
223 ret = __stmpe_block_write(stmpe, reg, length, values);
224 mutex_unlock(&stmpe->lock);
225
226 return ret;
227}
228EXPORT_SYMBOL_GPL(stmpe_block_write);
229
230/**
231 * stmpe_set_altfunc: set the alternate function for STMPE pins
232 * @stmpe: Device to configure
233 * @pins: Bitmask of pins to affect
234 * @block: block to enable alternate functions for
235 *
236 * @pins is assumed to have a bit set for each of the bits whose alternate
237 * function is to be changed, numbered according to the GPIOXY numbers.
238 *
239 * If the GPIO module is not enabled, this function automatically enables it in
240 * order to perform the change.
241 */
242int stmpe_set_altfunc(struct stmpe *stmpe, u32 pins, enum stmpe_block block)
243{
244 struct stmpe_variant_info *variant = stmpe->variant;
245 u8 regaddr = stmpe->regs[STMPE_IDX_GPAFR_U_MSB];
246 int af_bits = variant->af_bits;
247 int numregs = DIV_ROUND_UP(stmpe->num_gpios * af_bits, 8);
248 int afperreg = 8 / af_bits;
249 int mask = (1 << af_bits) - 1;
250 u8 regs[numregs];
251 int af;
252 int ret;
253
254 mutex_lock(&stmpe->lock);
255
256 ret = __stmpe_enable(stmpe, STMPE_BLOCK_GPIO);
257 if (ret < 0)
258 goto out;
259
260 ret = __stmpe_block_read(stmpe, regaddr, numregs, regs);
261 if (ret < 0)
262 goto out;
263
264 af = variant->get_altfunc(stmpe, block);
265
266 while (pins) {
267 int pin = __ffs(pins);
268 int regoffset = numregs - (pin / afperreg) - 1;
269 int pos = (pin % afperreg) * (8 / afperreg);
270
271 regs[regoffset] &= ~(mask << pos);
272 regs[regoffset] |= af << pos;
273
274 pins &= ~(1 << pin);
275 }
276
277 ret = __stmpe_block_write(stmpe, regaddr, numregs, regs);
278
279out:
280 mutex_unlock(&stmpe->lock);
281 return ret;
282}
283EXPORT_SYMBOL_GPL(stmpe_set_altfunc);
284
285/*
286 * GPIO (all variants)
287 */
288
289static struct resource stmpe_gpio_resources[] = {
290 /* Start and end filled dynamically */
291 {
292 .flags = IORESOURCE_IRQ,
293 },
294};
295
296static struct mfd_cell stmpe_gpio_cell = {
297 .name = "stmpe-gpio",
298 .resources = stmpe_gpio_resources,
299 .num_resources = ARRAY_SIZE(stmpe_gpio_resources),
300};
301
302/*
303 * Keypad (1601, 2401, 2403)
304 */
305
306static struct resource stmpe_keypad_resources[] = {
307 {
308 .name = "KEYPAD",
309 .start = 0,
310 .end = 0,
311 .flags = IORESOURCE_IRQ,
312 },
313 {
314 .name = "KEYPAD_OVER",
315 .start = 1,
316 .end = 1,
317 .flags = IORESOURCE_IRQ,
318 },
319};
320
321static struct mfd_cell stmpe_keypad_cell = {
322 .name = "stmpe-keypad",
323 .resources = stmpe_keypad_resources,
324 .num_resources = ARRAY_SIZE(stmpe_keypad_resources),
325};
326
327/*
328 * Touchscreen (STMPE811)
329 */
330
331static struct resource stmpe_ts_resources[] = {
332 {
333 .name = "TOUCH_DET",
334 .start = 0,
335 .end = 0,
336 .flags = IORESOURCE_IRQ,
337 },
338 {
339 .name = "FIFO_TH",
340 .start = 1,
341 .end = 1,
342 .flags = IORESOURCE_IRQ,
343 },
344};
345
346static struct mfd_cell stmpe_ts_cell = {
347 .name = "stmpe-ts",
348 .resources = stmpe_ts_resources,
349 .num_resources = ARRAY_SIZE(stmpe_ts_resources),
350};
351
352/*
353 * STMPE811
354 */
355
356static const u8 stmpe811_regs[] = {
357 [STMPE_IDX_CHIP_ID] = STMPE811_REG_CHIP_ID,
358 [STMPE_IDX_ICR_LSB] = STMPE811_REG_INT_CTRL,
359 [STMPE_IDX_IER_LSB] = STMPE811_REG_INT_EN,
360 [STMPE_IDX_ISR_MSB] = STMPE811_REG_INT_STA,
361 [STMPE_IDX_GPMR_LSB] = STMPE811_REG_GPIO_MP_STA,
362 [STMPE_IDX_GPSR_LSB] = STMPE811_REG_GPIO_SET_PIN,
363 [STMPE_IDX_GPCR_LSB] = STMPE811_REG_GPIO_CLR_PIN,
364 [STMPE_IDX_GPDR_LSB] = STMPE811_REG_GPIO_DIR,
365 [STMPE_IDX_GPRER_LSB] = STMPE811_REG_GPIO_RE,
366 [STMPE_IDX_GPFER_LSB] = STMPE811_REG_GPIO_FE,
367 [STMPE_IDX_GPAFR_U_MSB] = STMPE811_REG_GPIO_AF,
368 [STMPE_IDX_IEGPIOR_LSB] = STMPE811_REG_GPIO_INT_EN,
369 [STMPE_IDX_ISGPIOR_MSB] = STMPE811_REG_GPIO_INT_STA,
370 [STMPE_IDX_GPEDR_MSB] = STMPE811_REG_GPIO_ED,
371};
372
373static struct stmpe_variant_block stmpe811_blocks[] = {
374 {
375 .cell = &stmpe_gpio_cell,
376 .irq = STMPE811_IRQ_GPIOC,
377 .block = STMPE_BLOCK_GPIO,
378 },
379 {
380 .cell = &stmpe_ts_cell,
381 .irq = STMPE811_IRQ_TOUCH_DET,
382 .block = STMPE_BLOCK_TOUCHSCREEN,
383 },
384};
385
386static int stmpe811_enable(struct stmpe *stmpe, unsigned int blocks,
387 bool enable)
388{
389 unsigned int mask = 0;
390
391 if (blocks & STMPE_BLOCK_GPIO)
392 mask |= STMPE811_SYS_CTRL2_GPIO_OFF;
393
394 if (blocks & STMPE_BLOCK_ADC)
395 mask |= STMPE811_SYS_CTRL2_ADC_OFF;
396
397 if (blocks & STMPE_BLOCK_TOUCHSCREEN)
398 mask |= STMPE811_SYS_CTRL2_TSC_OFF;
399
400 return __stmpe_set_bits(stmpe, STMPE811_REG_SYS_CTRL2, mask,
401 enable ? 0 : mask);
402}
403
404static int stmpe811_get_altfunc(struct stmpe *stmpe, enum stmpe_block block)
405{
406 /* 0 for touchscreen, 1 for GPIO */
407 return block != STMPE_BLOCK_TOUCHSCREEN;
408}
409
410static struct stmpe_variant_info stmpe811 = {
411 .name = "stmpe811",
412 .id_val = 0x0811,
413 .id_mask = 0xffff,
414 .num_gpios = 8,
415 .af_bits = 1,
416 .regs = stmpe811_regs,
417 .blocks = stmpe811_blocks,
418 .num_blocks = ARRAY_SIZE(stmpe811_blocks),
419 .num_irqs = STMPE811_NR_INTERNAL_IRQS,
420 .enable = stmpe811_enable,
421 .get_altfunc = stmpe811_get_altfunc,
422};
423
424/*
425 * STMPE1601
426 */
427
428static const u8 stmpe1601_regs[] = {
429 [STMPE_IDX_CHIP_ID] = STMPE1601_REG_CHIP_ID,
430 [STMPE_IDX_ICR_LSB] = STMPE1601_REG_ICR_LSB,
431 [STMPE_IDX_IER_LSB] = STMPE1601_REG_IER_LSB,
432 [STMPE_IDX_ISR_MSB] = STMPE1601_REG_ISR_MSB,
433 [STMPE_IDX_GPMR_LSB] = STMPE1601_REG_GPIO_MP_LSB,
434 [STMPE_IDX_GPSR_LSB] = STMPE1601_REG_GPIO_SET_LSB,
435 [STMPE_IDX_GPCR_LSB] = STMPE1601_REG_GPIO_CLR_LSB,
436 [STMPE_IDX_GPDR_LSB] = STMPE1601_REG_GPIO_SET_DIR_LSB,
437 [STMPE_IDX_GPRER_LSB] = STMPE1601_REG_GPIO_RE_LSB,
438 [STMPE_IDX_GPFER_LSB] = STMPE1601_REG_GPIO_FE_LSB,
439 [STMPE_IDX_GPAFR_U_MSB] = STMPE1601_REG_GPIO_AF_U_MSB,
440 [STMPE_IDX_IEGPIOR_LSB] = STMPE1601_REG_INT_EN_GPIO_MASK_LSB,
441 [STMPE_IDX_ISGPIOR_MSB] = STMPE1601_REG_INT_STA_GPIO_MSB,
442 [STMPE_IDX_GPEDR_MSB] = STMPE1601_REG_GPIO_ED_MSB,
443};
444
445static struct stmpe_variant_block stmpe1601_blocks[] = {
446 {
447 .cell = &stmpe_gpio_cell,
448 .irq = STMPE24XX_IRQ_GPIOC,
449 .block = STMPE_BLOCK_GPIO,
450 },
451 {
452 .cell = &stmpe_keypad_cell,
453 .irq = STMPE24XX_IRQ_KEYPAD,
454 .block = STMPE_BLOCK_KEYPAD,
455 },
456};
457
458/* supported autosleep timeout delay (in msecs) */
459static const int stmpe_autosleep_delay[] = {
460 4, 16, 32, 64, 128, 256, 512, 1024,
461};
462
463static int stmpe_round_timeout(int timeout)
464{
465 int i;
466
467 for (i = 0; i < ARRAY_SIZE(stmpe_autosleep_delay); i++) {
468 if (stmpe_autosleep_delay[i] >= timeout)
469 return i;
470 }
471
472 /*
473 * requests for delays longer than supported should not return the
474 * longest supported delay
475 */
476 return -EINVAL;
477}
478
479static int stmpe_autosleep(struct stmpe *stmpe, int autosleep_timeout)
480{
481 int ret;
482
483 if (!stmpe->variant->enable_autosleep)
484 return -ENOSYS;
485
486 mutex_lock(&stmpe->lock);
487 ret = stmpe->variant->enable_autosleep(stmpe, autosleep_timeout);
488 mutex_unlock(&stmpe->lock);
489
490 return ret;
491}
492
493/*
494 * Both stmpe 1601/2403 support same layout for autosleep
495 */
496static int stmpe1601_autosleep(struct stmpe *stmpe,
497 int autosleep_timeout)
498{
499 int ret, timeout;
500
501 /* choose the best available timeout */
502 timeout = stmpe_round_timeout(autosleep_timeout);
503 if (timeout < 0) {
504 dev_err(stmpe->dev, "invalid timeout\n");
505 return timeout;
506 }
507
508 ret = __stmpe_set_bits(stmpe, STMPE1601_REG_SYS_CTRL2,
509 STMPE1601_AUTOSLEEP_TIMEOUT_MASK,
510 timeout);
511 if (ret < 0)
512 return ret;
513
514 return __stmpe_set_bits(stmpe, STMPE1601_REG_SYS_CTRL2,
515 STPME1601_AUTOSLEEP_ENABLE,
516 STPME1601_AUTOSLEEP_ENABLE);
517}
518
519static int stmpe1601_enable(struct stmpe *stmpe, unsigned int blocks,
520 bool enable)
521{
522 unsigned int mask = 0;
523
524 if (blocks & STMPE_BLOCK_GPIO)
525 mask |= STMPE1601_SYS_CTRL_ENABLE_GPIO;
526
527 if (blocks & STMPE_BLOCK_KEYPAD)
528 mask |= STMPE1601_SYS_CTRL_ENABLE_KPC;
529
530 return __stmpe_set_bits(stmpe, STMPE1601_REG_SYS_CTRL, mask,
531 enable ? mask : 0);
532}
533
534static int stmpe1601_get_altfunc(struct stmpe *stmpe, enum stmpe_block block)
535{
536 switch (block) {
537 case STMPE_BLOCK_PWM:
538 return 2;
539
540 case STMPE_BLOCK_KEYPAD:
541 return 1;
542
543 case STMPE_BLOCK_GPIO:
544 default:
545 return 0;
546 }
547}
548
549static struct stmpe_variant_info stmpe1601 = {
550 .name = "stmpe1601",
551 .id_val = 0x0210,
552 .id_mask = 0xfff0, /* at least 0x0210 and 0x0212 */
553 .num_gpios = 16,
554 .af_bits = 2,
555 .regs = stmpe1601_regs,
556 .blocks = stmpe1601_blocks,
557 .num_blocks = ARRAY_SIZE(stmpe1601_blocks),
558 .num_irqs = STMPE1601_NR_INTERNAL_IRQS,
559 .enable = stmpe1601_enable,
560 .get_altfunc = stmpe1601_get_altfunc,
561 .enable_autosleep = stmpe1601_autosleep,
562};
563
564/*
565 * STMPE24XX
566 */
567
568static const u8 stmpe24xx_regs[] = {
569 [STMPE_IDX_CHIP_ID] = STMPE24XX_REG_CHIP_ID,
570 [STMPE_IDX_ICR_LSB] = STMPE24XX_REG_ICR_LSB,
571 [STMPE_IDX_IER_LSB] = STMPE24XX_REG_IER_LSB,
572 [STMPE_IDX_ISR_MSB] = STMPE24XX_REG_ISR_MSB,
573 [STMPE_IDX_GPMR_LSB] = STMPE24XX_REG_GPMR_LSB,
574 [STMPE_IDX_GPSR_LSB] = STMPE24XX_REG_GPSR_LSB,
575 [STMPE_IDX_GPCR_LSB] = STMPE24XX_REG_GPCR_LSB,
576 [STMPE_IDX_GPDR_LSB] = STMPE24XX_REG_GPDR_LSB,
577 [STMPE_IDX_GPRER_LSB] = STMPE24XX_REG_GPRER_LSB,
578 [STMPE_IDX_GPFER_LSB] = STMPE24XX_REG_GPFER_LSB,
579 [STMPE_IDX_GPAFR_U_MSB] = STMPE24XX_REG_GPAFR_U_MSB,
580 [STMPE_IDX_IEGPIOR_LSB] = STMPE24XX_REG_IEGPIOR_LSB,
581 [STMPE_IDX_ISGPIOR_MSB] = STMPE24XX_REG_ISGPIOR_MSB,
582 [STMPE_IDX_GPEDR_MSB] = STMPE24XX_REG_GPEDR_MSB,
583};
584
585static struct stmpe_variant_block stmpe24xx_blocks[] = {
586 {
587 .cell = &stmpe_gpio_cell,
588 .irq = STMPE24XX_IRQ_GPIOC,
589 .block = STMPE_BLOCK_GPIO,
590 },
591 {
592 .cell = &stmpe_keypad_cell,
593 .irq = STMPE24XX_IRQ_KEYPAD,
594 .block = STMPE_BLOCK_KEYPAD,
595 },
596};
597
598static int stmpe24xx_enable(struct stmpe *stmpe, unsigned int blocks,
599 bool enable)
600{
601 unsigned int mask = 0;
602
603 if (blocks & STMPE_BLOCK_GPIO)
604 mask |= STMPE24XX_SYS_CTRL_ENABLE_GPIO;
605
606 if (blocks & STMPE_BLOCK_KEYPAD)
607 mask |= STMPE24XX_SYS_CTRL_ENABLE_KPC;
608
609 return __stmpe_set_bits(stmpe, STMPE24XX_REG_SYS_CTRL, mask,
610 enable ? mask : 0);
611}
612
613static int stmpe24xx_get_altfunc(struct stmpe *stmpe, enum stmpe_block block)
614{
615 switch (block) {
616 case STMPE_BLOCK_ROTATOR:
617 return 2;
618
619 case STMPE_BLOCK_KEYPAD:
620 return 1;
621
622 case STMPE_BLOCK_GPIO:
623 default:
624 return 0;
625 }
626}
627
628static struct stmpe_variant_info stmpe2401 = {
629 .name = "stmpe2401",
630 .id_val = 0x0101,
631 .id_mask = 0xffff,
632 .num_gpios = 24,
633 .af_bits = 2,
634 .regs = stmpe24xx_regs,
635 .blocks = stmpe24xx_blocks,
636 .num_blocks = ARRAY_SIZE(stmpe24xx_blocks),
637 .num_irqs = STMPE24XX_NR_INTERNAL_IRQS,
638 .enable = stmpe24xx_enable,
639 .get_altfunc = stmpe24xx_get_altfunc,
640};
641
642static struct stmpe_variant_info stmpe2403 = {
643 .name = "stmpe2403",
644 .id_val = 0x0120,
645 .id_mask = 0xffff,
646 .num_gpios = 24,
647 .af_bits = 2,
648 .regs = stmpe24xx_regs,
649 .blocks = stmpe24xx_blocks,
650 .num_blocks = ARRAY_SIZE(stmpe24xx_blocks),
651 .num_irqs = STMPE24XX_NR_INTERNAL_IRQS,
652 .enable = stmpe24xx_enable,
653 .get_altfunc = stmpe24xx_get_altfunc,
654 .enable_autosleep = stmpe1601_autosleep, /* same as stmpe1601 */
655};
656
657static struct stmpe_variant_info *stmpe_variant_info[] = {
658 [STMPE811] = &stmpe811,
659 [STMPE1601] = &stmpe1601,
660 [STMPE2401] = &stmpe2401,
661 [STMPE2403] = &stmpe2403,
662};
663
664static irqreturn_t stmpe_irq(int irq, void *data)
665{
666 struct stmpe *stmpe = data;
667 struct stmpe_variant_info *variant = stmpe->variant;
668 int num = DIV_ROUND_UP(variant->num_irqs, 8);
669 u8 israddr = stmpe->regs[STMPE_IDX_ISR_MSB];
670 u8 isr[num];
671 int ret;
672 int i;
673
674 ret = stmpe_block_read(stmpe, israddr, num, isr);
675 if (ret < 0)
676 return IRQ_NONE;
677
678 for (i = 0; i < num; i++) {
679 int bank = num - i - 1;
680 u8 status = isr[i];
681 u8 clear;
682
683 status &= stmpe->ier[bank];
684 if (!status)
685 continue;
686
687 clear = status;
688 while (status) {
689 int bit = __ffs(status);
690 int line = bank * 8 + bit;
691
692 handle_nested_irq(stmpe->irq_base + line);
693 status &= ~(1 << bit);
694 }
695
696 stmpe_reg_write(stmpe, israddr + i, clear);
697 }
698
699 return IRQ_HANDLED;
700}
701
702static void stmpe_irq_lock(unsigned int irq)
703{
704 struct stmpe *stmpe = get_irq_chip_data(irq);
705
706 mutex_lock(&stmpe->irq_lock);
707}
708
709static void stmpe_irq_sync_unlock(unsigned int irq)
710{
711 struct stmpe *stmpe = get_irq_chip_data(irq);
712 struct stmpe_variant_info *variant = stmpe->variant;
713 int num = DIV_ROUND_UP(variant->num_irqs, 8);
714 int i;
715
716 for (i = 0; i < num; i++) {
717 u8 new = stmpe->ier[i];
718 u8 old = stmpe->oldier[i];
719
720 if (new == old)
721 continue;
722
723 stmpe->oldier[i] = new;
724 stmpe_reg_write(stmpe, stmpe->regs[STMPE_IDX_IER_LSB] - i, new);
725 }
726
727 mutex_unlock(&stmpe->irq_lock);
728}
729
730static void stmpe_irq_mask(unsigned int irq)
731{
732 struct stmpe *stmpe = get_irq_chip_data(irq);
733 int offset = irq - stmpe->irq_base;
734 int regoffset = offset / 8;
735 int mask = 1 << (offset % 8);
736
737 stmpe->ier[regoffset] &= ~mask;
738}
739
740static void stmpe_irq_unmask(unsigned int irq)
741{
742 struct stmpe *stmpe = get_irq_chip_data(irq);
743 int offset = irq - stmpe->irq_base;
744 int regoffset = offset / 8;
745 int mask = 1 << (offset % 8);
746
747 stmpe->ier[regoffset] |= mask;
748}
749
750static struct irq_chip stmpe_irq_chip = {
751 .name = "stmpe",
752 .bus_lock = stmpe_irq_lock,
753 .bus_sync_unlock = stmpe_irq_sync_unlock,
754 .mask = stmpe_irq_mask,
755 .unmask = stmpe_irq_unmask,
756};
757
758static int __devinit stmpe_irq_init(struct stmpe *stmpe)
759{
760 int num_irqs = stmpe->variant->num_irqs;
761 int base = stmpe->irq_base;
762 int irq;
763
764 for (irq = base; irq < base + num_irqs; irq++) {
765 set_irq_chip_data(irq, stmpe);
766 set_irq_chip_and_handler(irq, &stmpe_irq_chip,
767 handle_edge_irq);
768 set_irq_nested_thread(irq, 1);
769#ifdef CONFIG_ARM
770 set_irq_flags(irq, IRQF_VALID);
771#else
772 set_irq_noprobe(irq);
773#endif
774 }
775
776 return 0;
777}
778
779static void stmpe_irq_remove(struct stmpe *stmpe)
780{
781 int num_irqs = stmpe->variant->num_irqs;
782 int base = stmpe->irq_base;
783 int irq;
784
785 for (irq = base; irq < base + num_irqs; irq++) {
786#ifdef CONFIG_ARM
787 set_irq_flags(irq, 0);
788#endif
789 set_irq_chip_and_handler(irq, NULL, NULL);
790 set_irq_chip_data(irq, NULL);
791 }
792}
793
794static int __devinit stmpe_chip_init(struct stmpe *stmpe)
795{
796 unsigned int irq_trigger = stmpe->pdata->irq_trigger;
797 int autosleep_timeout = stmpe->pdata->autosleep_timeout;
798 struct stmpe_variant_info *variant = stmpe->variant;
799 u8 icr = STMPE_ICR_LSB_GIM;
800 unsigned int id;
801 u8 data[2];
802 int ret;
803
804 ret = stmpe_block_read(stmpe, stmpe->regs[STMPE_IDX_CHIP_ID],
805 ARRAY_SIZE(data), data);
806 if (ret < 0)
807 return ret;
808
809 id = (data[0] << 8) | data[1];
810 if ((id & variant->id_mask) != variant->id_val) {
811 dev_err(stmpe->dev, "unknown chip id: %#x\n", id);
812 return -EINVAL;
813 }
814
815 dev_info(stmpe->dev, "%s detected, chip id: %#x\n", variant->name, id);
816
817 /* Disable all modules -- subdrivers should enable what they need. */
818 ret = stmpe_disable(stmpe, ~0);
819 if (ret)
820 return ret;
821
822 if (irq_trigger == IRQF_TRIGGER_FALLING ||
823 irq_trigger == IRQF_TRIGGER_RISING)
824 icr |= STMPE_ICR_LSB_EDGE;
825
826 if (irq_trigger == IRQF_TRIGGER_RISING ||
827 irq_trigger == IRQF_TRIGGER_HIGH)
828 icr |= STMPE_ICR_LSB_HIGH;
829
830 if (stmpe->pdata->irq_invert_polarity)
831 icr ^= STMPE_ICR_LSB_HIGH;
832
833 if (stmpe->pdata->autosleep) {
834 ret = stmpe_autosleep(stmpe, autosleep_timeout);
835 if (ret)
836 return ret;
837 }
838
839 return stmpe_reg_write(stmpe, stmpe->regs[STMPE_IDX_ICR_LSB], icr);
840}
841
842static int __devinit stmpe_add_device(struct stmpe *stmpe,
843 struct mfd_cell *cell, int irq)
844{
845 return mfd_add_devices(stmpe->dev, stmpe->pdata->id, cell, 1,
846 NULL, stmpe->irq_base + irq);
847}
848
849static int __devinit stmpe_devices_init(struct stmpe *stmpe)
850{
851 struct stmpe_variant_info *variant = stmpe->variant;
852 unsigned int platform_blocks = stmpe->pdata->blocks;
853 int ret = -EINVAL;
854 int i;
855
856 for (i = 0; i < variant->num_blocks; i++) {
857 struct stmpe_variant_block *block = &variant->blocks[i];
858
859 if (!(platform_blocks & block->block))
860 continue;
861
862 platform_blocks &= ~block->block;
863 ret = stmpe_add_device(stmpe, block->cell, block->irq);
864 if (ret)
865 return ret;
866 }
867
868 if (platform_blocks)
869 dev_warn(stmpe->dev,
870 "platform wants blocks (%#x) not present on variant",
871 platform_blocks);
872
873 return ret;
874}
875
876static int __devinit stmpe_probe(struct i2c_client *i2c,
877 const struct i2c_device_id *id)
878{
879 struct stmpe_platform_data *pdata = i2c->dev.platform_data;
880 struct stmpe *stmpe;
881 int ret;
882
883 if (!pdata)
884 return -EINVAL;
885
886 stmpe = kzalloc(sizeof(struct stmpe), GFP_KERNEL);
887 if (!stmpe)
888 return -ENOMEM;
889
890 mutex_init(&stmpe->irq_lock);
891 mutex_init(&stmpe->lock);
892
893 stmpe->dev = &i2c->dev;
894 stmpe->i2c = i2c;
895
896 stmpe->pdata = pdata;
897 stmpe->irq_base = pdata->irq_base;
898
899 stmpe->partnum = id->driver_data;
900 stmpe->variant = stmpe_variant_info[stmpe->partnum];
901 stmpe->regs = stmpe->variant->regs;
902 stmpe->num_gpios = stmpe->variant->num_gpios;
903
904 i2c_set_clientdata(i2c, stmpe);
905
906 ret = stmpe_chip_init(stmpe);
907 if (ret)
908 goto out_free;
909
910 ret = stmpe_irq_init(stmpe);
911 if (ret)
912 goto out_free;
913
914 ret = request_threaded_irq(stmpe->i2c->irq, NULL, stmpe_irq,
915 pdata->irq_trigger | IRQF_ONESHOT,
916 "stmpe", stmpe);
917 if (ret) {
918 dev_err(stmpe->dev, "failed to request IRQ: %d\n", ret);
919 goto out_removeirq;
920 }
921
922 ret = stmpe_devices_init(stmpe);
923 if (ret) {
924 dev_err(stmpe->dev, "failed to add children\n");
925 goto out_removedevs;
926 }
927
928 return 0;
929
930out_removedevs:
931 mfd_remove_devices(stmpe->dev);
932 free_irq(stmpe->i2c->irq, stmpe);
933out_removeirq:
934 stmpe_irq_remove(stmpe);
935out_free:
936 kfree(stmpe);
937 return ret;
938}
939
940static int __devexit stmpe_remove(struct i2c_client *client)
941{
942 struct stmpe *stmpe = i2c_get_clientdata(client);
943
944 mfd_remove_devices(stmpe->dev);
945
946 free_irq(stmpe->i2c->irq, stmpe);
947 stmpe_irq_remove(stmpe);
948
949 kfree(stmpe);
950
951 return 0;
952}
953
954static const struct i2c_device_id stmpe_id[] = {
955 { "stmpe811", STMPE811 },
956 { "stmpe1601", STMPE1601 },
957 { "stmpe2401", STMPE2401 },
958 { "stmpe2403", STMPE2403 },
959 { }
960};
961MODULE_DEVICE_TABLE(i2c, stmpe_id);
962
963static struct i2c_driver stmpe_driver = {
964 .driver.name = "stmpe",
965 .driver.owner = THIS_MODULE,
966 .probe = stmpe_probe,
967 .remove = __devexit_p(stmpe_remove),
968 .id_table = stmpe_id,
969};
970
971static int __init stmpe_init(void)
972{
973 return i2c_add_driver(&stmpe_driver);
974}
975subsys_initcall(stmpe_init);
976
977static void __exit stmpe_exit(void)
978{
979 i2c_del_driver(&stmpe_driver);
980}
981module_exit(stmpe_exit);
982
983MODULE_LICENSE("GPL v2");
984MODULE_DESCRIPTION("STMPE MFD core driver");
985MODULE_AUTHOR("Rabin Vincent <rabin.vincent@stericsson.com>");
diff --git a/drivers/mfd/stmpe.h b/drivers/mfd/stmpe.h
new file mode 100644
index 000000000000..0dbdc4e8cd77
--- /dev/null
+++ b/drivers/mfd/stmpe.h
@@ -0,0 +1,183 @@
1/*
2 * Copyright (C) ST-Ericsson SA 2010
3 *
4 * License Terms: GNU General Public License, version 2
5 * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
6 */
7
8#ifndef __STMPE_H
9#define __STMPE_H
10
11#ifdef STMPE_DUMP_BYTES
12static inline void stmpe_dump_bytes(const char *str, const void *buf,
13 size_t len)
14{
15 print_hex_dump_bytes(str, DUMP_PREFIX_OFFSET, buf, len);
16}
17#else
18static inline void stmpe_dump_bytes(const char *str, const void *buf,
19 size_t len)
20{
21}
22#endif
23
24/**
25 * struct stmpe_variant_block - information about block
26 * @cell: base mfd cell
27 * @irq: interrupt number to be added to each IORESOURCE_IRQ
28 * in the cell
29 * @block: block id; used for identification with platform data and for
30 * enable and altfunc callbacks
31 */
32struct stmpe_variant_block {
33 struct mfd_cell *cell;
34 int irq;
35 enum stmpe_block block;
36};
37
38/**
39 * struct stmpe_variant_info - variant-specific information
40 * @name: part name
41 * @id_val: content of CHIPID register
42 * @id_mask: bits valid in CHIPID register for comparison with id_val
43 * @num_gpios: number of GPIOS
44 * @af_bits: number of bits used to specify the alternate function
45 * @blocks: list of blocks present on this device
46 * @num_blocks: number of blocks present on this device
47 * @num_irqs: number of internal IRQs available on this device
48 * @enable: callback to enable the specified blocks.
49 * Called with the I/O lock held.
50 * @get_altfunc: callback to get the alternate function number for the
51 * specific block
52 * @enable_autosleep: callback to configure autosleep with specified timeout
53 */
54struct stmpe_variant_info {
55 const char *name;
56 u16 id_val;
57 u16 id_mask;
58 int num_gpios;
59 int af_bits;
60 const u8 *regs;
61 struct stmpe_variant_block *blocks;
62 int num_blocks;
63 int num_irqs;
64 int (*enable)(struct stmpe *stmpe, unsigned int blocks, bool enable);
65 int (*get_altfunc)(struct stmpe *stmpe, enum stmpe_block block);
66 int (*enable_autosleep)(struct stmpe *stmpe, int autosleep_timeout);
67};
68
69#define STMPE_ICR_LSB_HIGH (1 << 2)
70#define STMPE_ICR_LSB_EDGE (1 << 1)
71#define STMPE_ICR_LSB_GIM (1 << 0)
72
73/*
74 * STMPE811
75 */
76
77#define STMPE811_IRQ_TOUCH_DET 0
78#define STMPE811_IRQ_FIFO_TH 1
79#define STMPE811_IRQ_FIFO_OFLOW 2
80#define STMPE811_IRQ_FIFO_FULL 3
81#define STMPE811_IRQ_FIFO_EMPTY 4
82#define STMPE811_IRQ_TEMP_SENS 5
83#define STMPE811_IRQ_ADC 6
84#define STMPE811_IRQ_GPIOC 7
85#define STMPE811_NR_INTERNAL_IRQS 8
86
87#define STMPE811_REG_CHIP_ID 0x00
88#define STMPE811_REG_SYS_CTRL2 0x04
89#define STMPE811_REG_INT_CTRL 0x09
90#define STMPE811_REG_INT_EN 0x0A
91#define STMPE811_REG_INT_STA 0x0B
92#define STMPE811_REG_GPIO_INT_EN 0x0C
93#define STMPE811_REG_GPIO_INT_STA 0x0D
94#define STMPE811_REG_GPIO_SET_PIN 0x10
95#define STMPE811_REG_GPIO_CLR_PIN 0x11
96#define STMPE811_REG_GPIO_MP_STA 0x12
97#define STMPE811_REG_GPIO_DIR 0x13
98#define STMPE811_REG_GPIO_ED 0x14
99#define STMPE811_REG_GPIO_RE 0x15
100#define STMPE811_REG_GPIO_FE 0x16
101#define STMPE811_REG_GPIO_AF 0x17
102
103#define STMPE811_SYS_CTRL2_ADC_OFF (1 << 0)
104#define STMPE811_SYS_CTRL2_TSC_OFF (1 << 1)
105#define STMPE811_SYS_CTRL2_GPIO_OFF (1 << 2)
106#define STMPE811_SYS_CTRL2_TS_OFF (1 << 3)
107
108/*
109 * STMPE1601
110 */
111
112#define STMPE1601_IRQ_GPIOC 8
113#define STMPE1601_IRQ_PWM3 7
114#define STMPE1601_IRQ_PWM2 6
115#define STMPE1601_IRQ_PWM1 5
116#define STMPE1601_IRQ_PWM0 4
117#define STMPE1601_IRQ_KEYPAD_OVER 2
118#define STMPE1601_IRQ_KEYPAD 1
119#define STMPE1601_IRQ_WAKEUP 0
120#define STMPE1601_NR_INTERNAL_IRQS 9
121
122#define STMPE1601_REG_SYS_CTRL 0x02
123#define STMPE1601_REG_SYS_CTRL2 0x03
124#define STMPE1601_REG_ICR_LSB 0x11
125#define STMPE1601_REG_IER_LSB 0x13
126#define STMPE1601_REG_ISR_MSB 0x14
127#define STMPE1601_REG_CHIP_ID 0x80
128#define STMPE1601_REG_INT_EN_GPIO_MASK_LSB 0x17
129#define STMPE1601_REG_INT_STA_GPIO_MSB 0x18
130#define STMPE1601_REG_GPIO_MP_LSB 0x87
131#define STMPE1601_REG_GPIO_SET_LSB 0x83
132#define STMPE1601_REG_GPIO_CLR_LSB 0x85
133#define STMPE1601_REG_GPIO_SET_DIR_LSB 0x89
134#define STMPE1601_REG_GPIO_ED_MSB 0x8A
135#define STMPE1601_REG_GPIO_RE_LSB 0x8D
136#define STMPE1601_REG_GPIO_FE_LSB 0x8F
137#define STMPE1601_REG_GPIO_AF_U_MSB 0x92
138
139#define STMPE1601_SYS_CTRL_ENABLE_GPIO (1 << 3)
140#define STMPE1601_SYS_CTRL_ENABLE_KPC (1 << 1)
141#define STMPE1601_SYSCON_ENABLE_SPWM (1 << 0)
142
143/* The 1601/2403 share the same masks */
144#define STMPE1601_AUTOSLEEP_TIMEOUT_MASK (0x7)
145#define STPME1601_AUTOSLEEP_ENABLE (1 << 3)
146
147/*
148 * STMPE24xx
149 */
150
151#define STMPE24XX_IRQ_GPIOC 8
152#define STMPE24XX_IRQ_PWM2 7
153#define STMPE24XX_IRQ_PWM1 6
154#define STMPE24XX_IRQ_PWM0 5
155#define STMPE24XX_IRQ_ROT_OVER 4
156#define STMPE24XX_IRQ_ROT 3
157#define STMPE24XX_IRQ_KEYPAD_OVER 2
158#define STMPE24XX_IRQ_KEYPAD 1
159#define STMPE24XX_IRQ_WAKEUP 0
160#define STMPE24XX_NR_INTERNAL_IRQS 9
161
162#define STMPE24XX_REG_SYS_CTRL 0x02
163#define STMPE24XX_REG_ICR_LSB 0x11
164#define STMPE24XX_REG_IER_LSB 0x13
165#define STMPE24XX_REG_ISR_MSB 0x14
166#define STMPE24XX_REG_CHIP_ID 0x80
167#define STMPE24XX_REG_IEGPIOR_LSB 0x18
168#define STMPE24XX_REG_ISGPIOR_MSB 0x19
169#define STMPE24XX_REG_GPMR_LSB 0xA5
170#define STMPE24XX_REG_GPSR_LSB 0x85
171#define STMPE24XX_REG_GPCR_LSB 0x88
172#define STMPE24XX_REG_GPDR_LSB 0x8B
173#define STMPE24XX_REG_GPEDR_MSB 0x8C
174#define STMPE24XX_REG_GPRER_LSB 0x91
175#define STMPE24XX_REG_GPFER_LSB 0x94
176#define STMPE24XX_REG_GPAFR_U_MSB 0x9B
177
178#define STMPE24XX_SYS_CTRL_ENABLE_GPIO (1 << 3)
179#define STMPE24XX_SYSCON_ENABLE_PWM (1 << 2)
180#define STMPE24XX_SYS_CTRL_ENABLE_KPC (1 << 1)
181#define STMPE24XX_SYSCON_ENABLE_ROT (1 << 0)
182
183#endif
diff --git a/drivers/mfd/t7l66xb.c b/drivers/mfd/t7l66xb.c
index 5041d33adf0b..006c121f3f0d 100644
--- a/drivers/mfd/t7l66xb.c
+++ b/drivers/mfd/t7l66xb.c
@@ -350,7 +350,6 @@ static int t7l66xb_probe(struct platform_device *dev)
350 t7l66xb->clk48m = clk_get(&dev->dev, "CLK_CK48M"); 350 t7l66xb->clk48m = clk_get(&dev->dev, "CLK_CK48M");
351 if (IS_ERR(t7l66xb->clk48m)) { 351 if (IS_ERR(t7l66xb->clk48m)) {
352 ret = PTR_ERR(t7l66xb->clk48m); 352 ret = PTR_ERR(t7l66xb->clk48m);
353 clk_put(t7l66xb->clk32k);
354 goto err_clk48m_get; 353 goto err_clk48m_get;
355 } 354 }
356 355
@@ -425,6 +424,8 @@ static int t7l66xb_remove(struct platform_device *dev)
425 ret = pdata->disable(dev); 424 ret = pdata->disable(dev);
426 clk_disable(t7l66xb->clk48m); 425 clk_disable(t7l66xb->clk48m);
427 clk_put(t7l66xb->clk48m); 426 clk_put(t7l66xb->clk48m);
427 clk_disable(t7l66xb->clk32k);
428 clk_put(t7l66xb->clk32k);
428 t7l66xb_detach_irq(dev); 429 t7l66xb_detach_irq(dev);
429 iounmap(t7l66xb->scr); 430 iounmap(t7l66xb->scr);
430 release_resource(&t7l66xb->rscr); 431 release_resource(&t7l66xb->rscr);
diff --git a/drivers/mfd/tc6387xb.c b/drivers/mfd/tc6387xb.c
index 517f9bcdeaac..6315f63f017d 100644
--- a/drivers/mfd/tc6387xb.c
+++ b/drivers/mfd/tc6387xb.c
@@ -137,7 +137,7 @@ static struct mfd_cell tc6387xb_cells[] = {
137 }, 137 },
138}; 138};
139 139
140static int tc6387xb_probe(struct platform_device *dev) 140static int __devinit tc6387xb_probe(struct platform_device *dev)
141{ 141{
142 struct tc6387xb_platform_data *pdata = dev->dev.platform_data; 142 struct tc6387xb_platform_data *pdata = dev->dev.platform_data;
143 struct resource *iomem, *rscr; 143 struct resource *iomem, *rscr;
@@ -201,6 +201,7 @@ static int tc6387xb_probe(struct platform_device *dev)
201 if (!ret) 201 if (!ret)
202 return 0; 202 return 0;
203 203
204 iounmap(tc6387xb->scr);
204err_ioremap: 205err_ioremap:
205 release_resource(&tc6387xb->rscr); 206 release_resource(&tc6387xb->rscr);
206err_resource: 207err_resource:
@@ -211,14 +212,17 @@ err_no_irq:
211 return ret; 212 return ret;
212} 213}
213 214
214static int tc6387xb_remove(struct platform_device *dev) 215static int __devexit tc6387xb_remove(struct platform_device *dev)
215{ 216{
216 struct clk *clk32k = platform_get_drvdata(dev); 217 struct tc6387xb *tc6387xb = platform_get_drvdata(dev);
217 218
218 mfd_remove_devices(&dev->dev); 219 mfd_remove_devices(&dev->dev);
219 clk_disable(clk32k); 220 iounmap(tc6387xb->scr);
220 clk_put(clk32k); 221 release_resource(&tc6387xb->rscr);
222 clk_disable(tc6387xb->clk32k);
223 clk_put(tc6387xb->clk32k);
221 platform_set_drvdata(dev, NULL); 224 platform_set_drvdata(dev, NULL);
225 kfree(tc6387xb);
222 226
223 return 0; 227 return 0;
224} 228}
@@ -229,7 +233,7 @@ static struct platform_driver tc6387xb_platform_driver = {
229 .name = "tc6387xb", 233 .name = "tc6387xb",
230 }, 234 },
231 .probe = tc6387xb_probe, 235 .probe = tc6387xb_probe,
232 .remove = tc6387xb_remove, 236 .remove = __devexit_p(tc6387xb_remove),
233 .suspend = tc6387xb_suspend, 237 .suspend = tc6387xb_suspend,
234 .resume = tc6387xb_resume, 238 .resume = tc6387xb_resume,
235}; 239};
diff --git a/drivers/mfd/tc6393xb.c b/drivers/mfd/tc6393xb.c
index fcf9068810fb..ef6c42c8917a 100644
--- a/drivers/mfd/tc6393xb.c
+++ b/drivers/mfd/tc6393xb.c
@@ -732,9 +732,9 @@ err_gpio_add:
732 if (tc6393xb->gpio.base != -1) 732 if (tc6393xb->gpio.base != -1)
733 temp = gpiochip_remove(&tc6393xb->gpio); 733 temp = gpiochip_remove(&tc6393xb->gpio);
734 tcpd->disable(dev); 734 tcpd->disable(dev);
735err_clk_enable:
736 clk_disable(tc6393xb->clk);
737err_enable: 735err_enable:
736 clk_disable(tc6393xb->clk);
737err_clk_enable:
738 iounmap(tc6393xb->scr); 738 iounmap(tc6393xb->scr);
739err_ioremap: 739err_ioremap:
740 release_resource(&tc6393xb->rscr); 740 release_resource(&tc6393xb->rscr);
diff --git a/drivers/mfd/tps6507x.c b/drivers/mfd/tps6507x.c
index d859dffed39f..fc0197649281 100644
--- a/drivers/mfd/tps6507x.c
+++ b/drivers/mfd/tps6507x.c
@@ -89,10 +89,8 @@ static int tps6507x_i2c_probe(struct i2c_client *i2c,
89 int ret = 0; 89 int ret = 0;
90 90
91 tps6507x = kzalloc(sizeof(struct tps6507x_dev), GFP_KERNEL); 91 tps6507x = kzalloc(sizeof(struct tps6507x_dev), GFP_KERNEL);
92 if (tps6507x == NULL) { 92 if (tps6507x == NULL)
93 kfree(i2c);
94 return -ENOMEM; 93 return -ENOMEM;
95 }
96 94
97 i2c_set_clientdata(i2c, tps6507x); 95 i2c_set_clientdata(i2c, tps6507x);
98 tps6507x->dev = &i2c->dev; 96 tps6507x->dev = &i2c->dev;
diff --git a/drivers/mfd/tps6586x.c b/drivers/mfd/tps6586x.c
new file mode 100644
index 000000000000..4cde31e6a252
--- /dev/null
+++ b/drivers/mfd/tps6586x.c
@@ -0,0 +1,375 @@
1/*
2 * Core driver for TI TPS6586x PMIC family
3 *
4 * Copyright (c) 2010 CompuLab Ltd.
5 * Mike Rapoport <mike@compulab.co.il>
6 *
7 * Based on da903x.c.
8 * Copyright (C) 2008 Compulab, Ltd.
9 * Mike Rapoport <mike@compulab.co.il>
10 * Copyright (C) 2006-2008 Marvell International Ltd.
11 * Eric Miao <eric.miao@marvell.com>
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License version 2 as
15 * published by the Free Software Foundation.
16 */
17
18#include <linux/kernel.h>
19#include <linux/module.h>
20#include <linux/mutex.h>
21#include <linux/slab.h>
22#include <linux/gpio.h>
23#include <linux/i2c.h>
24
25#include <linux/mfd/core.h>
26#include <linux/mfd/tps6586x.h>
27
28/* GPIO control registers */
29#define TPS6586X_GPIOSET1 0x5d
30#define TPS6586X_GPIOSET2 0x5e
31
32/* device id */
33#define TPS6586X_VERSIONCRC 0xcd
34#define TPS658621A_VERSIONCRC 0x15
35
36struct tps6586x {
37 struct mutex lock;
38 struct device *dev;
39 struct i2c_client *client;
40
41 struct gpio_chip gpio;
42};
43
44static inline int __tps6586x_read(struct i2c_client *client,
45 int reg, uint8_t *val)
46{
47 int ret;
48
49 ret = i2c_smbus_read_byte_data(client, reg);
50 if (ret < 0) {
51 dev_err(&client->dev, "failed reading at 0x%02x\n", reg);
52 return ret;
53 }
54
55 *val = (uint8_t)ret;
56
57 return 0;
58}
59
60static inline int __tps6586x_reads(struct i2c_client *client, int reg,
61 int len, uint8_t *val)
62{
63 int ret;
64
65 ret = i2c_smbus_read_i2c_block_data(client, reg, len, val);
66 if (ret < 0) {
67 dev_err(&client->dev, "failed reading from 0x%02x\n", reg);
68 return ret;
69 }
70
71 return 0;
72}
73
74static inline int __tps6586x_write(struct i2c_client *client,
75 int reg, uint8_t val)
76{
77 int ret;
78
79 ret = i2c_smbus_write_byte_data(client, reg, val);
80 if (ret < 0) {
81 dev_err(&client->dev, "failed writing 0x%02x to 0x%02x\n",
82 val, reg);
83 return ret;
84 }
85
86 return 0;
87}
88
89static inline int __tps6586x_writes(struct i2c_client *client, int reg,
90 int len, uint8_t *val)
91{
92 int ret;
93
94 ret = i2c_smbus_write_i2c_block_data(client, reg, len, val);
95 if (ret < 0) {
96 dev_err(&client->dev, "failed writings to 0x%02x\n", reg);
97 return ret;
98 }
99
100 return 0;
101}
102
103int tps6586x_write(struct device *dev, int reg, uint8_t val)
104{
105 return __tps6586x_write(to_i2c_client(dev), reg, val);
106}
107EXPORT_SYMBOL_GPL(tps6586x_write);
108
109int tps6586x_writes(struct device *dev, int reg, int len, uint8_t *val)
110{
111 return __tps6586x_writes(to_i2c_client(dev), reg, len, val);
112}
113EXPORT_SYMBOL_GPL(tps6586x_writes);
114
115int tps6586x_read(struct device *dev, int reg, uint8_t *val)
116{
117 return __tps6586x_read(to_i2c_client(dev), reg, val);
118}
119EXPORT_SYMBOL_GPL(tps6586x_read);
120
121int tps6586x_reads(struct device *dev, int reg, int len, uint8_t *val)
122{
123 return __tps6586x_reads(to_i2c_client(dev), reg, len, val);
124}
125EXPORT_SYMBOL_GPL(tps6586x_reads);
126
127int tps6586x_set_bits(struct device *dev, int reg, uint8_t bit_mask)
128{
129 struct tps6586x *tps6586x = dev_get_drvdata(dev);
130 uint8_t reg_val;
131 int ret = 0;
132
133 mutex_lock(&tps6586x->lock);
134
135 ret = __tps6586x_read(to_i2c_client(dev), reg, &reg_val);
136 if (ret)
137 goto out;
138
139 if ((reg_val & bit_mask) == 0) {
140 reg_val |= bit_mask;
141 ret = __tps6586x_write(to_i2c_client(dev), reg, reg_val);
142 }
143out:
144 mutex_unlock(&tps6586x->lock);
145 return ret;
146}
147EXPORT_SYMBOL_GPL(tps6586x_set_bits);
148
149int tps6586x_clr_bits(struct device *dev, int reg, uint8_t bit_mask)
150{
151 struct tps6586x *tps6586x = dev_get_drvdata(dev);
152 uint8_t reg_val;
153 int ret = 0;
154
155 mutex_lock(&tps6586x->lock);
156
157 ret = __tps6586x_read(to_i2c_client(dev), reg, &reg_val);
158 if (ret)
159 goto out;
160
161 if (reg_val & bit_mask) {
162 reg_val &= ~bit_mask;
163 ret = __tps6586x_write(to_i2c_client(dev), reg, reg_val);
164 }
165out:
166 mutex_unlock(&tps6586x->lock);
167 return ret;
168}
169EXPORT_SYMBOL_GPL(tps6586x_clr_bits);
170
171int tps6586x_update(struct device *dev, int reg, uint8_t val, uint8_t mask)
172{
173 struct tps6586x *tps6586x = dev_get_drvdata(dev);
174 uint8_t reg_val;
175 int ret = 0;
176
177 mutex_lock(&tps6586x->lock);
178
179 ret = __tps6586x_read(tps6586x->client, reg, &reg_val);
180 if (ret)
181 goto out;
182
183 if ((reg_val & mask) != val) {
184 reg_val = (reg_val & ~mask) | val;
185 ret = __tps6586x_write(tps6586x->client, reg, reg_val);
186 }
187out:
188 mutex_unlock(&tps6586x->lock);
189 return ret;
190}
191EXPORT_SYMBOL_GPL(tps6586x_update);
192
193static int tps6586x_gpio_get(struct gpio_chip *gc, unsigned offset)
194{
195 struct tps6586x *tps6586x = container_of(gc, struct tps6586x, gpio);
196 uint8_t val;
197 int ret;
198
199 ret = __tps6586x_read(tps6586x->client, TPS6586X_GPIOSET2, &val);
200 if (ret)
201 return ret;
202
203 return !!(val & (1 << offset));
204}
205
206
207static void tps6586x_gpio_set(struct gpio_chip *chip, unsigned offset,
208 int value)
209{
210 struct tps6586x *tps6586x = container_of(chip, struct tps6586x, gpio);
211
212 __tps6586x_write(tps6586x->client, TPS6586X_GPIOSET2,
213 value << offset);
214}
215
216static int tps6586x_gpio_output(struct gpio_chip *gc, unsigned offset,
217 int value)
218{
219 struct tps6586x *tps6586x = container_of(gc, struct tps6586x, gpio);
220 uint8_t val, mask;
221
222 tps6586x_gpio_set(gc, offset, value);
223
224 val = 0x1 << (offset * 2);
225 mask = 0x3 << (offset * 2);
226
227 return tps6586x_update(tps6586x->dev, TPS6586X_GPIOSET1, val, mask);
228}
229
230static void tps6586x_gpio_init(struct tps6586x *tps6586x, int gpio_base)
231{
232 int ret;
233
234 if (!gpio_base)
235 return;
236
237 tps6586x->gpio.owner = THIS_MODULE;
238 tps6586x->gpio.label = tps6586x->client->name;
239 tps6586x->gpio.dev = tps6586x->dev;
240 tps6586x->gpio.base = gpio_base;
241 tps6586x->gpio.ngpio = 4;
242 tps6586x->gpio.can_sleep = 1;
243
244 /* FIXME: add handling of GPIOs as dedicated inputs */
245 tps6586x->gpio.direction_output = tps6586x_gpio_output;
246 tps6586x->gpio.set = tps6586x_gpio_set;
247 tps6586x->gpio.get = tps6586x_gpio_get;
248
249 ret = gpiochip_add(&tps6586x->gpio);
250 if (ret)
251 dev_warn(tps6586x->dev, "GPIO registration failed: %d\n", ret);
252}
253
254static int __remove_subdev(struct device *dev, void *unused)
255{
256 platform_device_unregister(to_platform_device(dev));
257 return 0;
258}
259
260static int tps6586x_remove_subdevs(struct tps6586x *tps6586x)
261{
262 return device_for_each_child(tps6586x->dev, NULL, __remove_subdev);
263}
264
265static int __devinit tps6586x_add_subdevs(struct tps6586x *tps6586x,
266 struct tps6586x_platform_data *pdata)
267{
268 struct tps6586x_subdev_info *subdev;
269 struct platform_device *pdev;
270 int i, ret = 0;
271
272 for (i = 0; i < pdata->num_subdevs; i++) {
273 subdev = &pdata->subdevs[i];
274
275 pdev = platform_device_alloc(subdev->name, subdev->id);
276
277 pdev->dev.parent = tps6586x->dev;
278 pdev->dev.platform_data = subdev->platform_data;
279
280 ret = platform_device_add(pdev);
281 if (ret)
282 goto failed;
283 }
284 return 0;
285
286failed:
287 tps6586x_remove_subdevs(tps6586x);
288 return ret;
289}
290
291static int __devinit tps6586x_i2c_probe(struct i2c_client *client,
292 const struct i2c_device_id *id)
293{
294 struct tps6586x_platform_data *pdata = client->dev.platform_data;
295 struct tps6586x *tps6586x;
296 int ret;
297
298 if (!pdata) {
299 dev_err(&client->dev, "tps6586x requires platform data\n");
300 return -ENOTSUPP;
301 }
302
303 ret = i2c_smbus_read_byte_data(client, TPS6586X_VERSIONCRC);
304 if (ret < 0) {
305 dev_err(&client->dev, "Chip ID read failed: %d\n", ret);
306 return -EIO;
307 }
308
309 if (ret != TPS658621A_VERSIONCRC) {
310 dev_err(&client->dev, "Unsupported chip ID: %x\n", ret);
311 return -ENODEV;
312 }
313
314 tps6586x = kzalloc(sizeof(struct tps6586x), GFP_KERNEL);
315 if (tps6586x == NULL)
316 return -ENOMEM;
317
318 tps6586x->client = client;
319 tps6586x->dev = &client->dev;
320 i2c_set_clientdata(client, tps6586x);
321
322 mutex_init(&tps6586x->lock);
323
324 ret = tps6586x_add_subdevs(tps6586x, pdata);
325 if (ret) {
326 dev_err(&client->dev, "add devices failed: %d\n", ret);
327 goto err_add_devs;
328 }
329
330 tps6586x_gpio_init(tps6586x, pdata->gpio_base);
331
332 return 0;
333
334err_add_devs:
335 kfree(tps6586x);
336 return ret;
337}
338
339static int __devexit tps6586x_i2c_remove(struct i2c_client *client)
340{
341 return 0;
342}
343
344static const struct i2c_device_id tps6586x_id_table[] = {
345 { "tps6586x", 0 },
346 { },
347};
348MODULE_DEVICE_TABLE(i2c, tps6586x_id_table);
349
350static struct i2c_driver tps6586x_driver = {
351 .driver = {
352 .name = "tps6586x",
353 .owner = THIS_MODULE,
354 },
355 .probe = tps6586x_i2c_probe,
356 .remove = __devexit_p(tps6586x_i2c_remove),
357 .id_table = tps6586x_id_table,
358};
359
360static int __init tps6586x_init(void)
361{
362 return i2c_add_driver(&tps6586x_driver);
363}
364subsys_initcall(tps6586x_init);
365
366static void __exit tps6586x_exit(void)
367{
368 i2c_del_driver(&tps6586x_driver);
369}
370module_exit(tps6586x_exit);
371
372MODULE_DESCRIPTION("TPS6586X core driver");
373MODULE_AUTHOR("Mike Rapoport <mike@compulab.co.il>");
374MODULE_LICENSE("GPL");
375
diff --git a/drivers/mfd/twl6030-pwm.c b/drivers/mfd/twl6030-pwm.c
new file mode 100644
index 000000000000..5d25bdc78424
--- /dev/null
+++ b/drivers/mfd/twl6030-pwm.c
@@ -0,0 +1,163 @@
1/*
2 * twl6030_pwm.c
3 * Driver for PHOENIX (TWL6030) Pulse Width Modulator
4 *
5 * Copyright (C) 2010 Texas Instruments
6 * Author: Hemanth V <hemanthv@ti.com>
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 version 2 as published by
10 * the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include <linux/module.h>
22#include <linux/platform_device.h>
23#include <linux/i2c/twl.h>
24#include <linux/slab.h>
25
26#define LED_PWM_CTRL1 0xF4
27#define LED_PWM_CTRL2 0xF5
28
29/* Max value for CTRL1 register */
30#define PWM_CTRL1_MAX 255
31
32/* Pull down disable */
33#define PWM_CTRL2_DIS_PD (1 << 6)
34
35/* Current control 2.5 milli Amps */
36#define PWM_CTRL2_CURR_02 (2 << 4)
37
38/* LED supply source */
39#define PWM_CTRL2_SRC_VAC (1 << 2)
40
41/* LED modes */
42#define PWM_CTRL2_MODE_HW (0 << 0)
43#define PWM_CTRL2_MODE_SW (1 << 0)
44#define PWM_CTRL2_MODE_DIS (2 << 0)
45
46#define PWM_CTRL2_MODE_MASK 0x3
47
48struct pwm_device {
49 const char *label;
50 unsigned int pwm_id;
51};
52
53int pwm_config(struct pwm_device *pwm, int duty_ns, int period_ns)
54{
55 u8 duty_cycle;
56 int ret;
57
58 if (pwm == NULL || period_ns == 0 || duty_ns > period_ns)
59 return -EINVAL;
60
61 duty_cycle = (duty_ns * PWM_CTRL1_MAX) / period_ns;
62
63 ret = twl_i2c_write_u8(TWL6030_MODULE_ID1, duty_cycle, LED_PWM_CTRL1);
64
65 if (ret < 0) {
66 pr_err("%s: Failed to configure PWM, Error %d\n",
67 pwm->label, ret);
68 return ret;
69 }
70 return 0;
71}
72EXPORT_SYMBOL(pwm_config);
73
74int pwm_enable(struct pwm_device *pwm)
75{
76 u8 val;
77 int ret;
78
79 ret = twl_i2c_read_u8(TWL6030_MODULE_ID1, &val, LED_PWM_CTRL2);
80 if (ret < 0) {
81 pr_err("%s: Failed to enable PWM, Error %d\n", pwm->label, ret);
82 return ret;
83 }
84
85 /* Change mode to software control */
86 val &= ~PWM_CTRL2_MODE_MASK;
87 val |= PWM_CTRL2_MODE_SW;
88
89 ret = twl_i2c_write_u8(TWL6030_MODULE_ID1, val, LED_PWM_CTRL2);
90 if (ret < 0) {
91 pr_err("%s: Failed to enable PWM, Error %d\n", pwm->label, ret);
92 return ret;
93 }
94
95 twl_i2c_read_u8(TWL6030_MODULE_ID1, &val, LED_PWM_CTRL2);
96 return 0;
97}
98EXPORT_SYMBOL(pwm_enable);
99
100void pwm_disable(struct pwm_device *pwm)
101{
102 u8 val;
103 int ret;
104
105 ret = twl_i2c_read_u8(TWL6030_MODULE_ID1, &val, LED_PWM_CTRL2);
106 if (ret < 0) {
107 pr_err("%s: Failed to disable PWM, Error %d\n",
108 pwm->label, ret);
109 return;
110 }
111
112 val &= ~PWM_CTRL2_MODE_MASK;
113 val |= PWM_CTRL2_MODE_HW;
114
115 ret = twl_i2c_write_u8(TWL6030_MODULE_ID1, val, LED_PWM_CTRL2);
116 if (ret < 0) {
117 pr_err("%s: Failed to disable PWM, Error %d\n",
118 pwm->label, ret);
119 return;
120 }
121 return;
122}
123EXPORT_SYMBOL(pwm_disable);
124
125struct pwm_device *pwm_request(int pwm_id, const char *label)
126{
127 u8 val;
128 int ret;
129 struct pwm_device *pwm;
130
131 pwm = kzalloc(sizeof(struct pwm_device), GFP_KERNEL);
132 if (pwm == NULL) {
133 pr_err("%s: failed to allocate memory\n", label);
134 return NULL;
135 }
136
137 pwm->label = label;
138 pwm->pwm_id = pwm_id;
139
140 /* Configure PWM */
141 val = PWM_CTRL2_DIS_PD | PWM_CTRL2_CURR_02 | PWM_CTRL2_SRC_VAC |
142 PWM_CTRL2_MODE_HW;
143
144 ret = twl_i2c_write_u8(TWL6030_MODULE_ID1, val, LED_PWM_CTRL2);
145
146 if (ret < 0) {
147 pr_err("%s: Failed to configure PWM, Error %d\n",
148 pwm->label, ret);
149
150 kfree(pwm);
151 return NULL;
152 }
153
154 return pwm;
155}
156EXPORT_SYMBOL(pwm_request);
157
158void pwm_free(struct pwm_device *pwm)
159{
160 pwm_disable(pwm);
161 kfree(pwm);
162}
163EXPORT_SYMBOL(pwm_free);
diff --git a/drivers/mfd/ucb1400_core.c b/drivers/mfd/ucb1400_core.c
index dbe280153f9e..d73f84ba0f08 100644
--- a/drivers/mfd/ucb1400_core.c
+++ b/drivers/mfd/ucb1400_core.c
@@ -114,7 +114,7 @@ static int ucb1400_core_probe(struct device *dev)
114err3: 114err3:
115 platform_device_put(ucb->ucb1400_ts); 115 platform_device_put(ucb->ucb1400_ts);
116err2: 116err2:
117 platform_device_unregister(ucb->ucb1400_gpio); 117 platform_device_del(ucb->ucb1400_gpio);
118err1: 118err1:
119 platform_device_put(ucb->ucb1400_gpio); 119 platform_device_put(ucb->ucb1400_gpio);
120err0: 120err0:
diff --git a/drivers/mfd/wm831x-core.c b/drivers/mfd/wm831x-core.c
index 1a968f34d679..1e7aaaf6cc6f 100644
--- a/drivers/mfd/wm831x-core.c
+++ b/drivers/mfd/wm831x-core.c
@@ -95,6 +95,7 @@ enum wm831x_parent {
95 WM8311 = 0x8311, 95 WM8311 = 0x8311,
96 WM8312 = 0x8312, 96 WM8312 = 0x8312,
97 WM8320 = 0x8320, 97 WM8320 = 0x8320,
98 WM8321 = 0x8321,
98}; 99};
99 100
100static int wm831x_reg_locked(struct wm831x *wm831x, unsigned short reg) 101static int wm831x_reg_locked(struct wm831x *wm831x, unsigned short reg)
@@ -1533,6 +1534,12 @@ static int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq)
1533 dev_info(wm831x->dev, "WM8320 revision %c\n", 'A' + rev); 1534 dev_info(wm831x->dev, "WM8320 revision %c\n", 'A' + rev);
1534 break; 1535 break;
1535 1536
1537 case WM8321:
1538 parent = WM8321;
1539 wm831x->num_gpio = 12;
1540 dev_info(wm831x->dev, "WM8321 revision %c\n", 'A' + rev);
1541 break;
1542
1536 default: 1543 default:
1537 dev_err(wm831x->dev, "Unknown WM831x device %04x\n", ret); 1544 dev_err(wm831x->dev, "Unknown WM831x device %04x\n", ret);
1538 ret = -EINVAL; 1545 ret = -EINVAL;
@@ -1607,6 +1614,12 @@ static int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq)
1607 NULL, 0); 1614 NULL, 0);
1608 break; 1615 break;
1609 1616
1617 case WM8321:
1618 ret = mfd_add_devices(wm831x->dev, -1,
1619 wm8320_devs, ARRAY_SIZE(wm8320_devs),
1620 NULL, 0);
1621 break;
1622
1610 default: 1623 default:
1611 /* If this happens the bus probe function is buggy */ 1624 /* If this happens the bus probe function is buggy */
1612 BUG(); 1625 BUG();
@@ -1744,10 +1757,8 @@ static int wm831x_i2c_probe(struct i2c_client *i2c,
1744 struct wm831x *wm831x; 1757 struct wm831x *wm831x;
1745 1758
1746 wm831x = kzalloc(sizeof(struct wm831x), GFP_KERNEL); 1759 wm831x = kzalloc(sizeof(struct wm831x), GFP_KERNEL);
1747 if (wm831x == NULL) { 1760 if (wm831x == NULL)
1748 kfree(i2c);
1749 return -ENOMEM; 1761 return -ENOMEM;
1750 }
1751 1762
1752 i2c_set_clientdata(i2c, wm831x); 1763 i2c_set_clientdata(i2c, wm831x);
1753 wm831x->dev = &i2c->dev; 1764 wm831x->dev = &i2c->dev;
@@ -1779,6 +1790,7 @@ static const struct i2c_device_id wm831x_i2c_id[] = {
1779 { "wm8311", WM8311 }, 1790 { "wm8311", WM8311 },
1780 { "wm8312", WM8312 }, 1791 { "wm8312", WM8312 },
1781 { "wm8320", WM8320 }, 1792 { "wm8320", WM8320 },
1793 { "wm8321", WM8321 },
1782 { } 1794 { }
1783}; 1795};
1784MODULE_DEVICE_TABLE(i2c, wm831x_i2c_id); 1796MODULE_DEVICE_TABLE(i2c, wm831x_i2c_id);
diff --git a/drivers/mfd/wm8350-core.c b/drivers/mfd/wm8350-core.c
index b5807484b4c9..e81cc31e4202 100644
--- a/drivers/mfd/wm8350-core.c
+++ b/drivers/mfd/wm8350-core.c
@@ -536,6 +536,7 @@ static int wm8350_create_cache(struct wm8350 *wm8350, int type, int mode)
536 } 536 }
537 537
538out: 538out:
539 kfree(wm8350->reg_cache);
539 return ret; 540 return ret;
540} 541}
541 542
@@ -700,7 +701,7 @@ int wm8350_device_init(struct wm8350 *wm8350, int irq,
700 701
701 ret = wm8350_irq_init(wm8350, irq, pdata); 702 ret = wm8350_irq_init(wm8350, irq, pdata);
702 if (ret < 0) 703 if (ret < 0)
703 goto err; 704 goto err_free;
704 705
705 if (wm8350->irq_base) { 706 if (wm8350->irq_base) {
706 ret = request_threaded_irq(wm8350->irq_base + 707 ret = request_threaded_irq(wm8350->irq_base +
@@ -738,8 +739,9 @@ int wm8350_device_init(struct wm8350 *wm8350, int irq,
738 739
739err_irq: 740err_irq:
740 wm8350_irq_exit(wm8350); 741 wm8350_irq_exit(wm8350);
741err: 742err_free:
742 kfree(wm8350->reg_cache); 743 kfree(wm8350->reg_cache);
744err:
743 return ret; 745 return ret;
744} 746}
745EXPORT_SYMBOL_GPL(wm8350_device_init); 747EXPORT_SYMBOL_GPL(wm8350_device_init);
diff --git a/drivers/mfd/wm8994-core.c b/drivers/mfd/wm8994-core.c
index ec71c9368906..b3b2aaf89dbe 100644
--- a/drivers/mfd/wm8994-core.c
+++ b/drivers/mfd/wm8994-core.c
@@ -326,8 +326,10 @@ static int wm8994_device_init(struct wm8994 *wm8994, unsigned long id, int irq)
326 wm8994->supplies = kzalloc(sizeof(struct regulator_bulk_data) * 326 wm8994->supplies = kzalloc(sizeof(struct regulator_bulk_data) *
327 ARRAY_SIZE(wm8994_main_supplies), 327 ARRAY_SIZE(wm8994_main_supplies),
328 GFP_KERNEL); 328 GFP_KERNEL);
329 if (!wm8994->supplies) 329 if (!wm8994->supplies) {
330 ret = -ENOMEM;
330 goto err; 331 goto err;
332 }
331 333
332 for (i = 0; i < ARRAY_SIZE(wm8994_main_supplies); i++) 334 for (i = 0; i < ARRAY_SIZE(wm8994_main_supplies); i++)
333 wm8994->supplies[i].supply = wm8994_main_supplies[i]; 335 wm8994->supplies[i].supply = wm8994_main_supplies[i];
@@ -495,10 +497,8 @@ static int wm8994_i2c_probe(struct i2c_client *i2c,
495 struct wm8994 *wm8994; 497 struct wm8994 *wm8994;
496 498
497 wm8994 = kzalloc(sizeof(struct wm8994), GFP_KERNEL); 499 wm8994 = kzalloc(sizeof(struct wm8994), GFP_KERNEL);
498 if (wm8994 == NULL) { 500 if (wm8994 == NULL)
499 kfree(i2c);
500 return -ENOMEM; 501 return -ENOMEM;
501 }
502 502
503 i2c_set_clientdata(i2c, wm8994); 503 i2c_set_clientdata(i2c, wm8994);
504 wm8994->dev = &i2c->dev; 504 wm8994->dev = &i2c->dev;
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 488f25472291..0b591b658243 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -304,6 +304,23 @@ config SENSORS_TSL2550
304 This driver can also be built as a module. If so, the module 304 This driver can also be built as a module. If so, the module
305 will be called tsl2550. 305 will be called tsl2550.
306 306
307config SENSORS_BH1780
308 tristate "ROHM BH1780GLI ambient light sensor"
309 depends on I2C && SYSFS
310 help
311 If you say yes here you get support for the ROHM BH1780GLI
312 ambient light sensor.
313
314 This driver can also be built as a module. If so, the module
315 will be called bh1780gli.
316
317config HMC6352
318 tristate "Honeywell HMC6352 compass"
319 depends on I2C
320 help
321 This driver provides support for the Honeywell HMC6352 compass,
322 providing configuration and heading data via sysfs.
323
307config EP93XX_PWM 324config EP93XX_PWM
308 tristate "EP93xx PWM support" 325 tristate "EP93xx PWM support"
309 depends on ARCH_EP93XX 326 depends on ARCH_EP93XX
@@ -363,6 +380,16 @@ config ARM_CHARLCD
363 line and the Linux version on the second line, but that's 380 line and the Linux version on the second line, but that's
364 still useful. 381 still useful.
365 382
383config BMP085
384 tristate "BMP085 digital pressure sensor"
385 depends on I2C && SYSFS
386 help
387 If you say yes here you get support for the Bosch Sensortec
388 BMP086 digital pressure sensor.
389
390 To compile this driver as a module, choose M here: the
391 module will be called bmp085.
392
366source "drivers/misc/c2port/Kconfig" 393source "drivers/misc/c2port/Kconfig"
367source "drivers/misc/eeprom/Kconfig" 394source "drivers/misc/eeprom/Kconfig"
368source "drivers/misc/cb710/Kconfig" 395source "drivers/misc/cb710/Kconfig"
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 67552d6e9327..255a80dc9d73 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -9,11 +9,13 @@ obj-$(CONFIG_AD525X_DPOT_SPI) += ad525x_dpot-spi.o
9obj-$(CONFIG_ATMEL_PWM) += atmel_pwm.o 9obj-$(CONFIG_ATMEL_PWM) += atmel_pwm.o
10obj-$(CONFIG_ATMEL_SSC) += atmel-ssc.o 10obj-$(CONFIG_ATMEL_SSC) += atmel-ssc.o
11obj-$(CONFIG_ATMEL_TCLIB) += atmel_tclib.o 11obj-$(CONFIG_ATMEL_TCLIB) += atmel_tclib.o
12obj-$(CONFIG_BMP085) += bmp085.o
12obj-$(CONFIG_ICS932S401) += ics932s401.o 13obj-$(CONFIG_ICS932S401) += ics932s401.o
13obj-$(CONFIG_LKDTM) += lkdtm.o 14obj-$(CONFIG_LKDTM) += lkdtm.o
14obj-$(CONFIG_TIFM_CORE) += tifm_core.o 15obj-$(CONFIG_TIFM_CORE) += tifm_core.o
15obj-$(CONFIG_TIFM_7XX1) += tifm_7xx1.o 16obj-$(CONFIG_TIFM_7XX1) += tifm_7xx1.o
16obj-$(CONFIG_PHANTOM) += phantom.o 17obj-$(CONFIG_PHANTOM) += phantom.o
18obj-$(CONFIG_SENSORS_BH1780) += bh1780gli.o
17obj-$(CONFIG_SGI_IOC4) += ioc4.o 19obj-$(CONFIG_SGI_IOC4) += ioc4.o
18obj-$(CONFIG_ENCLOSURE_SERVICES) += enclosure.o 20obj-$(CONFIG_ENCLOSURE_SERVICES) += enclosure.o
19obj-$(CONFIG_KGDB_TESTS) += kgdbts.o 21obj-$(CONFIG_KGDB_TESTS) += kgdbts.o
@@ -28,6 +30,7 @@ obj-$(CONFIG_DS1682) += ds1682.o
28obj-$(CONFIG_TI_DAC7512) += ti_dac7512.o 30obj-$(CONFIG_TI_DAC7512) += ti_dac7512.o
29obj-$(CONFIG_C2PORT) += c2port/ 31obj-$(CONFIG_C2PORT) += c2port/
30obj-$(CONFIG_IWMC3200TOP) += iwmc3200top/ 32obj-$(CONFIG_IWMC3200TOP) += iwmc3200top/
33obj-$(CONFIG_HMC6352) += hmc6352.o
31obj-y += eeprom/ 34obj-y += eeprom/
32obj-y += cb710/ 35obj-y += cb710/
33obj-$(CONFIG_VMWARE_BALLOON) += vmware_balloon.o 36obj-$(CONFIG_VMWARE_BALLOON) += vmware_balloon.o
diff --git a/drivers/misc/bh1780gli.c b/drivers/misc/bh1780gli.c
new file mode 100644
index 000000000000..714c6b487313
--- /dev/null
+++ b/drivers/misc/bh1780gli.c
@@ -0,0 +1,273 @@
1/*
2 * bh1780gli.c
3 * ROHM Ambient Light Sensor Driver
4 *
5 * Copyright (C) 2010 Texas Instruments
6 * Author: Hemanth V <hemanthv@ti.com>
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 version 2 as published by
10 * the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20#include <linux/i2c.h>
21#include <linux/slab.h>
22#include <linux/mutex.h>
23#include <linux/platform_device.h>
24#include <linux/delay.h>
25
26#define BH1780_REG_CONTROL 0x80
27#define BH1780_REG_PARTID 0x8A
28#define BH1780_REG_MANFID 0x8B
29#define BH1780_REG_DLOW 0x8C
30#define BH1780_REG_DHIGH 0x8D
31
32#define BH1780_REVMASK (0xf)
33#define BH1780_POWMASK (0x3)
34#define BH1780_POFF (0x0)
35#define BH1780_PON (0x3)
36
37/* power on settling time in ms */
38#define BH1780_PON_DELAY 2
39
40struct bh1780_data {
41 struct i2c_client *client;
42 int power_state;
43 /* lock for sysfs operations */
44 struct mutex lock;
45};
46
47static int bh1780_write(struct bh1780_data *ddata, u8 reg, u8 val, char *msg)
48{
49 int ret = i2c_smbus_write_byte_data(ddata->client, reg, val);
50 if (ret < 0)
51 dev_err(&ddata->client->dev,
52 "i2c_smbus_write_byte_data failed error %d\
53 Register (%s)\n", ret, msg);
54 return ret;
55}
56
57static int bh1780_read(struct bh1780_data *ddata, u8 reg, char *msg)
58{
59 int ret = i2c_smbus_read_byte_data(ddata->client, reg);
60 if (ret < 0)
61 dev_err(&ddata->client->dev,
62 "i2c_smbus_read_byte_data failed error %d\
63 Register (%s)\n", ret, msg);
64 return ret;
65}
66
67static ssize_t bh1780_show_lux(struct device *dev,
68 struct device_attribute *attr, char *buf)
69{
70 struct platform_device *pdev = to_platform_device(dev);
71 struct bh1780_data *ddata = platform_get_drvdata(pdev);
72 int lsb, msb;
73
74 lsb = bh1780_read(ddata, BH1780_REG_DLOW, "DLOW");
75 if (lsb < 0)
76 return lsb;
77
78 msb = bh1780_read(ddata, BH1780_REG_DHIGH, "DHIGH");
79 if (msb < 0)
80 return msb;
81
82 return sprintf(buf, "%d\n", (msb << 8) | lsb);
83}
84
85static ssize_t bh1780_show_power_state(struct device *dev,
86 struct device_attribute *attr,
87 char *buf)
88{
89 struct platform_device *pdev = to_platform_device(dev);
90 struct bh1780_data *ddata = platform_get_drvdata(pdev);
91 int state;
92
93 state = bh1780_read(ddata, BH1780_REG_CONTROL, "CONTROL");
94 if (state < 0)
95 return state;
96
97 return sprintf(buf, "%d\n", state & BH1780_POWMASK);
98}
99
100static ssize_t bh1780_store_power_state(struct device *dev,
101 struct device_attribute *attr,
102 const char *buf, size_t count)
103{
104 struct platform_device *pdev = to_platform_device(dev);
105 struct bh1780_data *ddata = platform_get_drvdata(pdev);
106 unsigned long val;
107 int error;
108
109 error = strict_strtoul(buf, 0, &val);
110 if (error)
111 return error;
112
113 if (val < BH1780_POFF || val > BH1780_PON)
114 return -EINVAL;
115
116 mutex_lock(&ddata->lock);
117
118 error = bh1780_write(ddata, BH1780_REG_CONTROL, val, "CONTROL");
119 if (error < 0) {
120 mutex_unlock(&ddata->lock);
121 return error;
122 }
123
124 msleep(BH1780_PON_DELAY);
125 ddata->power_state = val;
126 mutex_unlock(&ddata->lock);
127
128 return count;
129}
130
131static DEVICE_ATTR(lux, S_IRUGO, bh1780_show_lux, NULL);
132
133static DEVICE_ATTR(power_state, S_IWUSR | S_IRUGO,
134 bh1780_show_power_state, bh1780_store_power_state);
135
136static struct attribute *bh1780_attributes[] = {
137 &dev_attr_power_state.attr,
138 &dev_attr_lux.attr,
139 NULL
140};
141
142static const struct attribute_group bh1780_attr_group = {
143 .attrs = bh1780_attributes,
144};
145
146static int __devinit bh1780_probe(struct i2c_client *client,
147 const struct i2c_device_id *id)
148{
149 int ret;
150 struct bh1780_data *ddata = NULL;
151 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
152
153 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE)) {
154 ret = -EIO;
155 goto err_op_failed;
156 }
157
158 ddata = kzalloc(sizeof(struct bh1780_data), GFP_KERNEL);
159 if (ddata == NULL) {
160 ret = -ENOMEM;
161 goto err_op_failed;
162 }
163
164 ddata->client = client;
165 i2c_set_clientdata(client, ddata);
166
167 ret = bh1780_read(ddata, BH1780_REG_PARTID, "PART ID");
168 if (ret < 0)
169 goto err_op_failed;
170
171 dev_info(&client->dev, "Ambient Light Sensor, Rev : %d\n",
172 (ret & BH1780_REVMASK));
173
174 mutex_init(&ddata->lock);
175
176 ret = sysfs_create_group(&client->dev.kobj, &bh1780_attr_group);
177 if (ret)
178 goto err_op_failed;
179
180 return 0;
181
182err_op_failed:
183 kfree(ddata);
184 return ret;
185}
186
187static int __devexit bh1780_remove(struct i2c_client *client)
188{
189 struct bh1780_data *ddata;
190
191 ddata = i2c_get_clientdata(client);
192 sysfs_remove_group(&client->dev.kobj, &bh1780_attr_group);
193 i2c_set_clientdata(client, NULL);
194 kfree(ddata);
195
196 return 0;
197}
198
199#ifdef CONFIG_PM
200static int bh1780_suspend(struct i2c_client *client, pm_message_t mesg)
201{
202 struct bh1780_data *ddata;
203 int state, ret;
204
205 ddata = i2c_get_clientdata(client);
206 state = bh1780_read(ddata, BH1780_REG_CONTROL, "CONTROL");
207 if (state < 0)
208 return state;
209
210 ddata->power_state = state & BH1780_POWMASK;
211
212 ret = bh1780_write(ddata, BH1780_REG_CONTROL, BH1780_POFF,
213 "CONTROL");
214
215 if (ret < 0)
216 return ret;
217
218 return 0;
219}
220
221static int bh1780_resume(struct i2c_client *client)
222{
223 struct bh1780_data *ddata;
224 int state, ret;
225
226 ddata = i2c_get_clientdata(client);
227 state = ddata->power_state;
228
229 ret = bh1780_write(ddata, BH1780_REG_CONTROL, state,
230 "CONTROL");
231
232 if (ret < 0)
233 return ret;
234
235 return 0;
236}
237#else
238#define bh1780_suspend NULL
239#define bh1780_resume NULL
240#endif /* CONFIG_PM */
241
242static const struct i2c_device_id bh1780_id[] = {
243 { "bh1780", 0 },
244 { },
245};
246
247static struct i2c_driver bh1780_driver = {
248 .probe = bh1780_probe,
249 .remove = bh1780_remove,
250 .id_table = bh1780_id,
251 .suspend = bh1780_suspend,
252 .resume = bh1780_resume,
253 .driver = {
254 .name = "bh1780"
255 },
256};
257
258static int __init bh1780_init(void)
259{
260 return i2c_add_driver(&bh1780_driver);
261}
262
263static void __exit bh1780_exit(void)
264{
265 i2c_del_driver(&bh1780_driver);
266}
267
268module_init(bh1780_init)
269module_exit(bh1780_exit)
270
271MODULE_DESCRIPTION("BH1780GLI Ambient Light Sensor Driver");
272MODULE_LICENSE("GPL");
273MODULE_AUTHOR("Hemanth V <hemanthv@ti.com>");
diff --git a/drivers/misc/bmp085.c b/drivers/misc/bmp085.c
new file mode 100644
index 000000000000..63ee4c1a5315
--- /dev/null
+++ b/drivers/misc/bmp085.c
@@ -0,0 +1,482 @@
1/* Copyright (c) 2010 Christoph Mair <christoph.mair@gmail.com>
2
3 This driver supports the bmp085 digital barometric pressure
4 and temperature sensor from Bosch Sensortec. The datasheet
5 is avaliable from their website:
6 http://www.bosch-sensortec.com/content/language1/downloads/BST-BMP085-DS000-05.pdf
7
8 A pressure measurement is issued by reading from pressure0_input.
9 The return value ranges from 30000 to 110000 pascal with a resulution
10 of 1 pascal (0.01 millibar) which enables measurements from 9000m above
11 to 500m below sea level.
12
13 The temperature can be read from temp0_input. Values range from
14 -400 to 850 representing the ambient temperature in degree celsius
15 multiplied by 10.The resolution is 0.1 celsius.
16
17 Because ambient pressure is temperature dependent, a temperature
18 measurement will be executed automatically even if the user is reading
19 from pressure0_input. This happens if the last temperature measurement
20 has been executed more then one second ago.
21
22 To decrease RMS noise from pressure measurements, the bmp085 can
23 autonomously calculate the average of up to eight samples. This is
24 set up by writing to the oversampling sysfs file. Accepted values
25 are 0, 1, 2 and 3. 2^x when x is the value written to this file
26 specifies the number of samples used to calculate the ambient pressure.
27 RMS noise is specified with six pascal (without averaging) and decreases
28 down to 3 pascal when using an oversampling setting of 3.
29
30 This program is free software; you can redistribute it and/or modify
31 it under the terms of the GNU General Public License as published by
32 the Free Software Foundation; either version 2 of the License, or
33 (at your option) any later version.
34
35 This program is distributed in the hope that it will be useful,
36 but WITHOUT ANY WARRANTY; without even the implied warranty of
37 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38 GNU General Public License for more details.
39
40 You should have received a copy of the GNU General Public License
41 along with this program; if not, write to the Free Software
42 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
43*/
44
45
46#include <linux/module.h>
47#include <linux/init.h>
48#include <linux/i2c.h>
49#include <linux/slab.h>
50#include <linux/delay.h>
51
52
53#define BMP085_I2C_ADDRESS 0x77
54#define BMP085_CHIP_ID 0x55
55
56#define BMP085_CALIBRATION_DATA_START 0xAA
57#define BMP085_CALIBRATION_DATA_LENGTH 11 /* 16 bit values */
58#define BMP085_CHIP_ID_REG 0xD0
59#define BMP085_VERSION_REG 0xD1
60#define BMP085_CTRL_REG 0xF4
61#define BMP085_TEMP_MEASUREMENT 0x2E
62#define BMP085_PRESSURE_MEASUREMENT 0x34
63#define BMP085_CONVERSION_REGISTER_MSB 0xF6
64#define BMP085_CONVERSION_REGISTER_LSB 0xF7
65#define BMP085_CONVERSION_REGISTER_XLSB 0xF8
66#define BMP085_TEMP_CONVERSION_TIME 5
67
68#define BMP085_CLIENT_NAME "bmp085"
69
70
71static const unsigned short normal_i2c[] = { BMP085_I2C_ADDRESS,
72 I2C_CLIENT_END };
73
74struct bmp085_calibration_data {
75 s16 AC1, AC2, AC3;
76 u16 AC4, AC5, AC6;
77 s16 B1, B2;
78 s16 MB, MC, MD;
79};
80
81
82/* Each client has this additional data */
83struct bmp085_data {
84 struct i2c_client *client;
85 struct mutex lock;
86 struct bmp085_calibration_data calibration;
87 u32 raw_temperature;
88 u32 raw_pressure;
89 unsigned char oversampling_setting;
90 u32 last_temp_measurement;
91 s32 b6; /* calculated temperature correction coefficient */
92};
93
94
95static s32 bmp085_read_calibration_data(struct i2c_client *client)
96{
97 u16 tmp[BMP085_CALIBRATION_DATA_LENGTH];
98 struct bmp085_data *data = i2c_get_clientdata(client);
99 struct bmp085_calibration_data *cali = &(data->calibration);
100 s32 status = i2c_smbus_read_i2c_block_data(client,
101 BMP085_CALIBRATION_DATA_START,
102 BMP085_CALIBRATION_DATA_LENGTH*sizeof(u16),
103 (u8 *)tmp);
104 if (status < 0)
105 return status;
106
107 if (status != BMP085_CALIBRATION_DATA_LENGTH*sizeof(u16))
108 return -EIO;
109
110 cali->AC1 = be16_to_cpu(tmp[0]);
111 cali->AC2 = be16_to_cpu(tmp[1]);
112 cali->AC3 = be16_to_cpu(tmp[2]);
113 cali->AC4 = be16_to_cpu(tmp[3]);
114 cali->AC5 = be16_to_cpu(tmp[4]);
115 cali->AC6 = be16_to_cpu(tmp[5]);
116 cali->B1 = be16_to_cpu(tmp[6]);
117 cali->B2 = be16_to_cpu(tmp[7]);
118 cali->MB = be16_to_cpu(tmp[8]);
119 cali->MC = be16_to_cpu(tmp[9]);
120 cali->MD = be16_to_cpu(tmp[10]);
121 return 0;
122}
123
124
125static s32 bmp085_update_raw_temperature(struct bmp085_data *data)
126{
127 u16 tmp;
128 s32 status;
129
130 mutex_lock(&data->lock);
131 status = i2c_smbus_write_byte_data(data->client, BMP085_CTRL_REG,
132 BMP085_TEMP_MEASUREMENT);
133 if (status != 0) {
134 dev_err(&data->client->dev,
135 "Error while requesting temperature measurement.\n");
136 goto exit;
137 }
138 msleep(BMP085_TEMP_CONVERSION_TIME);
139
140 status = i2c_smbus_read_i2c_block_data(data->client,
141 BMP085_CONVERSION_REGISTER_MSB, sizeof(tmp), (u8 *)&tmp);
142 if (status < 0)
143 goto exit;
144 if (status != sizeof(tmp)) {
145 dev_err(&data->client->dev,
146 "Error while reading temperature measurement result\n");
147 status = -EIO;
148 goto exit;
149 }
150 data->raw_temperature = be16_to_cpu(tmp);
151 data->last_temp_measurement = jiffies;
152 status = 0; /* everything ok, return 0 */
153
154exit:
155 mutex_unlock(&data->lock);
156 return status;
157}
158
159static s32 bmp085_update_raw_pressure(struct bmp085_data *data)
160{
161 u32 tmp = 0;
162 s32 status;
163
164 mutex_lock(&data->lock);
165 status = i2c_smbus_write_byte_data(data->client, BMP085_CTRL_REG,
166 BMP085_PRESSURE_MEASUREMENT + (data->oversampling_setting<<6));
167 if (status != 0) {
168 dev_err(&data->client->dev,
169 "Error while requesting pressure measurement.\n");
170 goto exit;
171 }
172
173 /* wait for the end of conversion */
174 msleep(2+(3 << data->oversampling_setting));
175
176 /* copy data into a u32 (4 bytes), but skip the first byte. */
177 status = i2c_smbus_read_i2c_block_data(data->client,
178 BMP085_CONVERSION_REGISTER_MSB, 3, ((u8 *)&tmp)+1);
179 if (status < 0)
180 goto exit;
181 if (status != 3) {
182 dev_err(&data->client->dev,
183 "Error while reading pressure measurement results\n");
184 status = -EIO;
185 goto exit;
186 }
187 data->raw_pressure = be32_to_cpu((tmp));
188 data->raw_pressure >>= (8-data->oversampling_setting);
189 status = 0; /* everything ok, return 0 */
190
191exit:
192 mutex_unlock(&data->lock);
193 return status;
194}
195
196
197/*
198 * This function starts the temperature measurement and returns the value
199 * in tenth of a degree celsius.
200 */
201static s32 bmp085_get_temperature(struct bmp085_data *data, int *temperature)
202{
203 struct bmp085_calibration_data *cali = &data->calibration;
204 long x1, x2;
205 int status;
206
207 status = bmp085_update_raw_temperature(data);
208 if (status != 0)
209 goto exit;
210
211 x1 = ((data->raw_temperature - cali->AC6) * cali->AC5) >> 15;
212 x2 = (cali->MC << 11) / (x1 + cali->MD);
213 data->b6 = x1 + x2 - 4000;
214 /* if NULL just update b6. Used for pressure only measurements */
215 if (temperature != NULL)
216 *temperature = (x1+x2+8) >> 4;
217
218exit:
219 return status;;
220}
221
222/*
223 * This function starts the pressure measurement and returns the value
224 * in millibar. Since the pressure depends on the ambient temperature,
225 * a temperature measurement is executed if the last known value is older
226 * than one second.
227 */
228static s32 bmp085_get_pressure(struct bmp085_data *data, int *pressure)
229{
230 struct bmp085_calibration_data *cali = &data->calibration;
231 s32 x1, x2, x3, b3;
232 u32 b4, b7;
233 s32 p;
234 int status;
235
236 /* alt least every second force an update of the ambient temperature */
237 if (data->last_temp_measurement + 1*HZ < jiffies) {
238 status = bmp085_get_temperature(data, NULL);
239 if (status != 0)
240 goto exit;
241 }
242
243 status = bmp085_update_raw_pressure(data);
244 if (status != 0)
245 goto exit;
246
247 x1 = (data->b6 * data->b6) >> 12;
248 x1 *= cali->B2;
249 x1 >>= 11;
250
251 x2 = cali->AC2 * data->b6;
252 x2 >>= 11;
253
254 x3 = x1 + x2;
255
256 b3 = (((((s32)cali->AC1) * 4 + x3) << data->oversampling_setting) + 2);
257 b3 >>= 2;
258
259 x1 = (cali->AC3 * data->b6) >> 13;
260 x2 = (cali->B1 * ((data->b6 * data->b6) >> 12)) >> 16;
261 x3 = (x1 + x2 + 2) >> 2;
262 b4 = (cali->AC4 * (u32)(x3 + 32768)) >> 15;
263
264 b7 = ((u32)data->raw_pressure - b3) *
265 (50000 >> data->oversampling_setting);
266 p = ((b7 < 0x80000000) ? ((b7 << 1) / b4) : ((b7 / b4) * 2));
267
268 x1 = p >> 8;
269 x1 *= x1;
270 x1 = (x1 * 3038) >> 16;
271 x2 = (-7357 * p) >> 16;
272 p += (x1 + x2 + 3791) >> 4;
273
274 *pressure = p;
275
276exit:
277 return status;
278}
279
280/*
281 * This function sets the chip-internal oversampling. Valid values are 0..3.
282 * The chip will use 2^oversampling samples for internal averaging.
283 * This influences the measurement time and the accuracy; larger values
284 * increase both. The datasheet gives on overview on how measurement time,
285 * accuracy and noise correlate.
286 */
287static void bmp085_set_oversampling(struct bmp085_data *data,
288 unsigned char oversampling)
289{
290 if (oversampling > 3)
291 oversampling = 3;
292 data->oversampling_setting = oversampling;
293}
294
295/*
296 * Returns the currently selected oversampling. Range: 0..3
297 */
298static unsigned char bmp085_get_oversampling(struct bmp085_data *data)
299{
300 return data->oversampling_setting;
301}
302
303/* sysfs callbacks */
304static ssize_t set_oversampling(struct device *dev,
305 struct device_attribute *attr,
306 const char *buf, size_t count)
307{
308 struct i2c_client *client = to_i2c_client(dev);
309 struct bmp085_data *data = i2c_get_clientdata(client);
310 unsigned long oversampling;
311 int success = strict_strtoul(buf, 10, &oversampling);
312 if (success == 0) {
313 bmp085_set_oversampling(data, oversampling);
314 return count;
315 }
316 return success;
317}
318
319static ssize_t show_oversampling(struct device *dev,
320 struct device_attribute *attr, char *buf)
321{
322 struct i2c_client *client = to_i2c_client(dev);
323 struct bmp085_data *data = i2c_get_clientdata(client);
324 return sprintf(buf, "%u\n", bmp085_get_oversampling(data));
325}
326static DEVICE_ATTR(oversampling, S_IWUSR | S_IRUGO,
327 show_oversampling, set_oversampling);
328
329
330static ssize_t show_temperature(struct device *dev,
331 struct device_attribute *attr, char *buf)
332{
333 int temperature;
334 int status;
335 struct i2c_client *client = to_i2c_client(dev);
336 struct bmp085_data *data = i2c_get_clientdata(client);
337
338 status = bmp085_get_temperature(data, &temperature);
339 if (status != 0)
340 return status;
341 else
342 return sprintf(buf, "%d\n", temperature);
343}
344static DEVICE_ATTR(temp0_input, S_IRUGO, show_temperature, NULL);
345
346
347static ssize_t show_pressure(struct device *dev,
348 struct device_attribute *attr, char *buf)
349{
350 int pressure;
351 int status;
352 struct i2c_client *client = to_i2c_client(dev);
353 struct bmp085_data *data = i2c_get_clientdata(client);
354
355 status = bmp085_get_pressure(data, &pressure);
356 if (status != 0)
357 return status;
358 else
359 return sprintf(buf, "%d\n", pressure);
360}
361static DEVICE_ATTR(pressure0_input, S_IRUGO, show_pressure, NULL);
362
363
364static struct attribute *bmp085_attributes[] = {
365 &dev_attr_temp0_input.attr,
366 &dev_attr_pressure0_input.attr,
367 &dev_attr_oversampling.attr,
368 NULL
369};
370
371static const struct attribute_group bmp085_attr_group = {
372 .attrs = bmp085_attributes,
373};
374
375static int bmp085_detect(struct i2c_client *client, struct i2c_board_info *info)
376{
377 if (client->addr != BMP085_I2C_ADDRESS)
378 return -ENODEV;
379
380 if (i2c_smbus_read_byte_data(client, BMP085_CHIP_ID_REG) != BMP085_CHIP_ID)
381 return -ENODEV;
382
383 return 0;
384}
385
386static int bmp085_init_client(struct i2c_client *client)
387{
388 unsigned char version;
389 int status;
390 struct bmp085_data *data = i2c_get_clientdata(client);
391 data->client = client;
392 status = bmp085_read_calibration_data(client);
393 if (status != 0)
394 goto exit;
395 version = i2c_smbus_read_byte_data(client, BMP085_VERSION_REG);
396 data->last_temp_measurement = 0;
397 data->oversampling_setting = 3;
398 mutex_init(&data->lock);
399 dev_info(&data->client->dev, "BMP085 ver. %d.%d found.\n",
400 (version & 0x0F), (version & 0xF0) >> 4);
401exit:
402 return status;
403}
404
405static int bmp085_probe(struct i2c_client *client,
406 const struct i2c_device_id *id)
407{
408 struct bmp085_data *data;
409 int err = 0;
410
411 data = kzalloc(sizeof(struct bmp085_data), GFP_KERNEL);
412 if (!data) {
413 err = -ENOMEM;
414 goto exit;
415 }
416
417 /* default settings after POR */
418 data->oversampling_setting = 0x00;
419
420 i2c_set_clientdata(client, data);
421
422 /* Initialize the BMP085 chip */
423 err = bmp085_init_client(client);
424 if (err != 0)
425 goto exit_free;
426
427 /* Register sysfs hooks */
428 err = sysfs_create_group(&client->dev.kobj, &bmp085_attr_group);
429 if (err)
430 goto exit_free;
431
432 dev_info(&data->client->dev, "Succesfully initialized bmp085!\n");
433 goto exit;
434
435exit_free:
436 kfree(data);
437exit:
438 return err;
439}
440
441static int bmp085_remove(struct i2c_client *client)
442{
443 sysfs_remove_group(&client->dev.kobj, &bmp085_attr_group);
444 kfree(i2c_get_clientdata(client));
445 return 0;
446}
447
448static const struct i2c_device_id bmp085_id[] = {
449 { "bmp085", 0 },
450 { }
451};
452
453static struct i2c_driver bmp085_driver = {
454 .driver = {
455 .owner = THIS_MODULE,
456 .name = "bmp085"
457 },
458 .id_table = bmp085_id,
459 .probe = bmp085_probe,
460 .remove = bmp085_remove,
461
462 .detect = bmp085_detect,
463 .address_list = normal_i2c
464};
465
466static int __init bmp085_init(void)
467{
468 return i2c_add_driver(&bmp085_driver);
469}
470
471static void __exit bmp085_exit(void)
472{
473 i2c_del_driver(&bmp085_driver);
474}
475
476
477MODULE_AUTHOR("Christoph Mair <christoph.mair@gmail.com");
478MODULE_DESCRIPTION("BMP085 driver");
479MODULE_LICENSE("GPL");
480
481module_init(bmp085_init);
482module_exit(bmp085_exit);
diff --git a/drivers/misc/cs5535-mfgpt.c b/drivers/misc/cs5535-mfgpt.c
index 2d44b3300104..6f6218061b0d 100644
--- a/drivers/misc/cs5535-mfgpt.c
+++ b/drivers/misc/cs5535-mfgpt.c
@@ -211,6 +211,17 @@ EXPORT_SYMBOL_GPL(cs5535_mfgpt_alloc_timer);
211 */ 211 */
212void cs5535_mfgpt_free_timer(struct cs5535_mfgpt_timer *timer) 212void cs5535_mfgpt_free_timer(struct cs5535_mfgpt_timer *timer)
213{ 213{
214 unsigned long flags;
215 uint16_t val;
216
217 /* timer can be made available again only if never set up */
218 val = cs5535_mfgpt_read(timer, MFGPT_REG_SETUP);
219 if (!(val & MFGPT_SETUP_SETUP)) {
220 spin_lock_irqsave(&timer->chip->lock, flags);
221 __set_bit(timer->nr, timer->chip->avail);
222 spin_unlock_irqrestore(&timer->chip->lock, flags);
223 }
224
214 kfree(timer); 225 kfree(timer);
215} 226}
216EXPORT_SYMBOL_GPL(cs5535_mfgpt_free_timer); 227EXPORT_SYMBOL_GPL(cs5535_mfgpt_free_timer);
diff --git a/drivers/misc/hmc6352.c b/drivers/misc/hmc6352.c
new file mode 100644
index 000000000000..234bfcaf2099
--- /dev/null
+++ b/drivers/misc/hmc6352.c
@@ -0,0 +1,166 @@
1/*
2 * hmc6352.c - Honeywell Compass Driver
3 *
4 * Copyright (C) 2009 Intel Corp
5 *
6 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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; version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
21 *
22 */
23
24#include <linux/module.h>
25#include <linux/init.h>
26#include <linux/slab.h>
27#include <linux/i2c.h>
28#include <linux/err.h>
29#include <linux/delay.h>
30#include <linux/sysfs.h>
31
32static DEFINE_MUTEX(compass_mutex);
33
34static int compass_command(struct i2c_client *c, u8 cmd)
35{
36 int ret = i2c_master_send(c, &cmd, 1);
37 if (ret < 0)
38 dev_warn(&c->dev, "command '%c' failed.\n", cmd);
39 return ret;
40}
41
42static int compass_store(struct device *dev, const char *buf, size_t count,
43 const char *map)
44{
45 struct i2c_client *c = to_i2c_client(dev);
46 int ret;
47 unsigned long val;
48
49 if (strict_strtoul(buf, 10, &val))
50 return -EINVAL;
51 if (val >= strlen(map))
52 return -EINVAL;
53 mutex_lock(&compass_mutex);
54 ret = compass_command(c, map[val]);
55 mutex_unlock(&compass_mutex);
56 if (ret < 0)
57 return ret;
58 return count;
59}
60
61static ssize_t compass_calibration_store(struct device *dev,
62 struct device_attribute *attr, const char *buf, size_t count)
63{
64 return compass_store(dev, buf, count, "EC");
65}
66
67static ssize_t compass_power_mode_store(struct device *dev,
68 struct device_attribute *attr, const char *buf, size_t count)
69{
70 return compass_store(dev, buf, count, "SW");
71}
72
73static ssize_t compass_heading_data_show(struct device *dev,
74 struct device_attribute *attr, char *buf)
75{
76 struct i2c_client *client = to_i2c_client(dev);
77 unsigned char i2c_data[2];
78 unsigned int ret;
79
80 mutex_lock(&compass_mutex);
81 ret = compass_command(client, 'A');
82 if (ret != 1) {
83 mutex_unlock(&compass_mutex);
84 return ret;
85 }
86 msleep(10); /* sending 'A' cmd we need to wait for 7-10 millisecs */
87 ret = i2c_master_recv(client, i2c_data, 2);
88 mutex_unlock(&compass_mutex);
89 if (ret != 1) {
90 dev_warn(dev, "i2c read data cmd failed\n");
91 return ret;
92 }
93 ret = (i2c_data[0] << 8) | i2c_data[1];
94 return sprintf(buf, "%d.%d\n", ret/10, ret%10);
95}
96
97
98static DEVICE_ATTR(heading0_input, S_IRUGO, compass_heading_data_show, NULL);
99static DEVICE_ATTR(calibration, S_IWUSR, NULL, compass_calibration_store);
100static DEVICE_ATTR(power_state, S_IWUSR, NULL, compass_power_mode_store);
101
102static struct attribute *mid_att_compass[] = {
103 &dev_attr_heading0_input.attr,
104 &dev_attr_calibration.attr,
105 &dev_attr_power_state.attr,
106 NULL
107};
108
109static const struct attribute_group m_compass_gr = {
110 .name = "hmc6352",
111 .attrs = mid_att_compass
112};
113
114static int hmc6352_probe(struct i2c_client *client,
115 const struct i2c_device_id *id)
116{
117 int res;
118
119 res = sysfs_create_group(&client->dev.kobj, &m_compass_gr);
120 if (res) {
121 dev_err(&client->dev, "device_create_file failed\n");
122 return res;
123 }
124 dev_info(&client->dev, "%s HMC6352 compass chip found\n",
125 client->name);
126 return 0;
127}
128
129static int hmc6352_remove(struct i2c_client *client)
130{
131 sysfs_remove_group(&client->dev.kobj, &m_compass_gr);
132 return 0;
133}
134
135static struct i2c_device_id hmc6352_id[] = {
136 { "hmc6352", 0 },
137 { }
138};
139
140MODULE_DEVICE_TABLE(i2c, hmc6352_id);
141
142static struct i2c_driver hmc6352_driver = {
143 .driver = {
144 .name = "hmc6352",
145 },
146 .probe = hmc6352_probe,
147 .remove = hmc6352_remove,
148 .id_table = hmc6352_id,
149};
150
151static int __init sensor_hmc6352_init(void)
152{
153 return i2c_add_driver(&hmc6352_driver);
154}
155
156static void __exit sensor_hmc6352_exit(void)
157{
158 i2c_del_driver(&hmc6352_driver);
159}
160
161module_init(sensor_hmc6352_init);
162module_exit(sensor_hmc6352_exit);
163
164MODULE_AUTHOR("Kalhan Trisal <kalhan.trisal@intel.com");
165MODULE_DESCRIPTION("hmc6352 Compass Driver");
166MODULE_LICENSE("GPL v2");
diff --git a/drivers/misc/hpilo.c b/drivers/misc/hpilo.c
index 98ad0120aa9b..557a8c2a7336 100644
--- a/drivers/misc/hpilo.c
+++ b/drivers/misc/hpilo.c
@@ -256,7 +256,8 @@ static void ilo_ccb_close(struct pci_dev *pdev, struct ccb_data *data)
256 256
257static int ilo_ccb_setup(struct ilo_hwinfo *hw, struct ccb_data *data, int slot) 257static int ilo_ccb_setup(struct ilo_hwinfo *hw, struct ccb_data *data, int slot)
258{ 258{
259 char *dma_va, *dma_pa; 259 char *dma_va;
260 dma_addr_t dma_pa;
260 struct ccb *driver_ccb, *ilo_ccb; 261 struct ccb *driver_ccb, *ilo_ccb;
261 262
262 driver_ccb = &data->driver_ccb; 263 driver_ccb = &data->driver_ccb;
@@ -272,12 +273,12 @@ static int ilo_ccb_setup(struct ilo_hwinfo *hw, struct ccb_data *data, int slot)
272 return -ENOMEM; 273 return -ENOMEM;
273 274
274 dma_va = (char *)data->dma_va; 275 dma_va = (char *)data->dma_va;
275 dma_pa = (char *)data->dma_pa; 276 dma_pa = data->dma_pa;
276 277
277 memset(dma_va, 0, data->dma_size); 278 memset(dma_va, 0, data->dma_size);
278 279
279 dma_va = (char *)roundup((unsigned long)dma_va, ILO_START_ALIGN); 280 dma_va = (char *)roundup((unsigned long)dma_va, ILO_START_ALIGN);
280 dma_pa = (char *)roundup((unsigned long)dma_pa, ILO_START_ALIGN); 281 dma_pa = roundup(dma_pa, ILO_START_ALIGN);
281 282
282 /* 283 /*
283 * Create two ccb's, one with virt addrs, one with phys addrs. 284 * Create two ccb's, one with virt addrs, one with phys addrs.
@@ -288,26 +289,26 @@ static int ilo_ccb_setup(struct ilo_hwinfo *hw, struct ccb_data *data, int slot)
288 289
289 fifo_setup(dma_va, NR_QENTRY); 290 fifo_setup(dma_va, NR_QENTRY);
290 driver_ccb->ccb_u1.send_fifobar = dma_va + FIFOHANDLESIZE; 291 driver_ccb->ccb_u1.send_fifobar = dma_va + FIFOHANDLESIZE;
291 ilo_ccb->ccb_u1.send_fifobar = dma_pa + FIFOHANDLESIZE; 292 ilo_ccb->ccb_u1.send_fifobar_pa = dma_pa + FIFOHANDLESIZE;
292 dma_va += fifo_sz(NR_QENTRY); 293 dma_va += fifo_sz(NR_QENTRY);
293 dma_pa += fifo_sz(NR_QENTRY); 294 dma_pa += fifo_sz(NR_QENTRY);
294 295
295 dma_va = (char *)roundup((unsigned long)dma_va, ILO_CACHE_SZ); 296 dma_va = (char *)roundup((unsigned long)dma_va, ILO_CACHE_SZ);
296 dma_pa = (char *)roundup((unsigned long)dma_pa, ILO_CACHE_SZ); 297 dma_pa = roundup(dma_pa, ILO_CACHE_SZ);
297 298
298 fifo_setup(dma_va, NR_QENTRY); 299 fifo_setup(dma_va, NR_QENTRY);
299 driver_ccb->ccb_u3.recv_fifobar = dma_va + FIFOHANDLESIZE; 300 driver_ccb->ccb_u3.recv_fifobar = dma_va + FIFOHANDLESIZE;
300 ilo_ccb->ccb_u3.recv_fifobar = dma_pa + FIFOHANDLESIZE; 301 ilo_ccb->ccb_u3.recv_fifobar_pa = dma_pa + FIFOHANDLESIZE;
301 dma_va += fifo_sz(NR_QENTRY); 302 dma_va += fifo_sz(NR_QENTRY);
302 dma_pa += fifo_sz(NR_QENTRY); 303 dma_pa += fifo_sz(NR_QENTRY);
303 304
304 driver_ccb->ccb_u2.send_desc = dma_va; 305 driver_ccb->ccb_u2.send_desc = dma_va;
305 ilo_ccb->ccb_u2.send_desc = dma_pa; 306 ilo_ccb->ccb_u2.send_desc_pa = dma_pa;
306 dma_pa += desc_mem_sz(NR_QENTRY); 307 dma_pa += desc_mem_sz(NR_QENTRY);
307 dma_va += desc_mem_sz(NR_QENTRY); 308 dma_va += desc_mem_sz(NR_QENTRY);
308 309
309 driver_ccb->ccb_u4.recv_desc = dma_va; 310 driver_ccb->ccb_u4.recv_desc = dma_va;
310 ilo_ccb->ccb_u4.recv_desc = dma_pa; 311 ilo_ccb->ccb_u4.recv_desc_pa = dma_pa;
311 312
312 driver_ccb->channel = slot; 313 driver_ccb->channel = slot;
313 ilo_ccb->channel = slot; 314 ilo_ccb->channel = slot;
diff --git a/drivers/misc/hpilo.h b/drivers/misc/hpilo.h
index 247eb386a973..54e43adbdea1 100644
--- a/drivers/misc/hpilo.h
+++ b/drivers/misc/hpilo.h
@@ -79,21 +79,21 @@ struct ilo_hwinfo {
79struct ccb { 79struct ccb {
80 union { 80 union {
81 char *send_fifobar; 81 char *send_fifobar;
82 u64 padding1; 82 u64 send_fifobar_pa;
83 } ccb_u1; 83 } ccb_u1;
84 union { 84 union {
85 char *send_desc; 85 char *send_desc;
86 u64 padding2; 86 u64 send_desc_pa;
87 } ccb_u2; 87 } ccb_u2;
88 u64 send_ctrl; 88 u64 send_ctrl;
89 89
90 union { 90 union {
91 char *recv_fifobar; 91 char *recv_fifobar;
92 u64 padding3; 92 u64 recv_fifobar_pa;
93 } ccb_u3; 93 } ccb_u3;
94 union { 94 union {
95 char *recv_desc; 95 char *recv_desc;
96 u64 padding4; 96 u64 recv_desc_pa;
97 } ccb_u4; 97 } ccb_u4;
98 u64 recv_ctrl; 98 u64 recv_ctrl;
99 99
diff --git a/drivers/misc/lkdtm.c b/drivers/misc/lkdtm.c
index 5bfb2a2041b8..ef34de7a8026 100644
--- a/drivers/misc/lkdtm.c
+++ b/drivers/misc/lkdtm.c
@@ -124,9 +124,9 @@ static int count = DEFAULT_COUNT;
124module_param(recur_count, int, 0644); 124module_param(recur_count, int, 0644);
125MODULE_PARM_DESC(recur_count, " Recursion level for the stack overflow test, "\ 125MODULE_PARM_DESC(recur_count, " Recursion level for the stack overflow test, "\
126 "default is 10"); 126 "default is 10");
127module_param(cpoint_name, charp, 0644); 127module_param(cpoint_name, charp, 0444);
128MODULE_PARM_DESC(cpoint_name, " Crash Point, where kernel is to be crashed"); 128MODULE_PARM_DESC(cpoint_name, " Crash Point, where kernel is to be crashed");
129module_param(cpoint_type, charp, 0644); 129module_param(cpoint_type, charp, 0444);
130MODULE_PARM_DESC(cpoint_type, " Crash Point Type, action to be taken on "\ 130MODULE_PARM_DESC(cpoint_type, " Crash Point Type, action to be taken on "\
131 "hitting the crash point"); 131 "hitting the crash point");
132module_param(cpoint_count, int, 0644); 132module_param(cpoint_count, int, 0644);
diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
index cb9fbc83b090..d545f79f6000 100644
--- a/drivers/mmc/card/block.c
+++ b/drivers/mmc/card/block.c
@@ -29,6 +29,7 @@
29#include <linux/kdev_t.h> 29#include <linux/kdev_t.h>
30#include <linux/blkdev.h> 30#include <linux/blkdev.h>
31#include <linux/mutex.h> 31#include <linux/mutex.h>
32#include <linux/smp_lock.h>
32#include <linux/scatterlist.h> 33#include <linux/scatterlist.h>
33#include <linux/string_helpers.h> 34#include <linux/string_helpers.h>
34 35
@@ -107,6 +108,7 @@ static int mmc_blk_open(struct block_device *bdev, fmode_t mode)
107 struct mmc_blk_data *md = mmc_blk_get(bdev->bd_disk); 108 struct mmc_blk_data *md = mmc_blk_get(bdev->bd_disk);
108 int ret = -ENXIO; 109 int ret = -ENXIO;
109 110
111 lock_kernel();
110 if (md) { 112 if (md) {
111 if (md->usage == 2) 113 if (md->usage == 2)
112 check_disk_change(bdev); 114 check_disk_change(bdev);
@@ -117,6 +119,7 @@ static int mmc_blk_open(struct block_device *bdev, fmode_t mode)
117 ret = -EROFS; 119 ret = -EROFS;
118 } 120 }
119 } 121 }
122 unlock_kernel();
120 123
121 return ret; 124 return ret;
122} 125}
@@ -125,7 +128,9 @@ static int mmc_blk_release(struct gendisk *disk, fmode_t mode)
125{ 128{
126 struct mmc_blk_data *md = disk->private_data; 129 struct mmc_blk_data *md = disk->private_data;
127 130
131 lock_kernel();
128 mmc_blk_put(md); 132 mmc_blk_put(md);
133 unlock_kernel();
129 return 0; 134 return 0;
130} 135}
131 136
@@ -242,7 +247,76 @@ static u32 get_card_status(struct mmc_card *card, struct request *req)
242 return cmd.resp[0]; 247 return cmd.resp[0];
243} 248}
244 249
245static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req) 250static int mmc_blk_issue_discard_rq(struct mmc_queue *mq, struct request *req)
251{
252 struct mmc_blk_data *md = mq->data;
253 struct mmc_card *card = md->queue.card;
254 unsigned int from, nr, arg;
255 int err = 0;
256
257 mmc_claim_host(card->host);
258
259 if (!mmc_can_erase(card)) {
260 err = -EOPNOTSUPP;
261 goto out;
262 }
263
264 from = blk_rq_pos(req);
265 nr = blk_rq_sectors(req);
266
267 if (mmc_can_trim(card))
268 arg = MMC_TRIM_ARG;
269 else
270 arg = MMC_ERASE_ARG;
271
272 err = mmc_erase(card, from, nr, arg);
273out:
274 spin_lock_irq(&md->lock);
275 __blk_end_request(req, err, blk_rq_bytes(req));
276 spin_unlock_irq(&md->lock);
277
278 mmc_release_host(card->host);
279
280 return err ? 0 : 1;
281}
282
283static int mmc_blk_issue_secdiscard_rq(struct mmc_queue *mq,
284 struct request *req)
285{
286 struct mmc_blk_data *md = mq->data;
287 struct mmc_card *card = md->queue.card;
288 unsigned int from, nr, arg;
289 int err = 0;
290
291 mmc_claim_host(card->host);
292
293 if (!mmc_can_secure_erase_trim(card)) {
294 err = -EOPNOTSUPP;
295 goto out;
296 }
297
298 from = blk_rq_pos(req);
299 nr = blk_rq_sectors(req);
300
301 if (mmc_can_trim(card) && !mmc_erase_group_aligned(card, from, nr))
302 arg = MMC_SECURE_TRIM1_ARG;
303 else
304 arg = MMC_SECURE_ERASE_ARG;
305
306 err = mmc_erase(card, from, nr, arg);
307 if (!err && arg == MMC_SECURE_TRIM1_ARG)
308 err = mmc_erase(card, from, nr, MMC_SECURE_TRIM2_ARG);
309out:
310 spin_lock_irq(&md->lock);
311 __blk_end_request(req, err, blk_rq_bytes(req));
312 spin_unlock_irq(&md->lock);
313
314 mmc_release_host(card->host);
315
316 return err ? 0 : 1;
317}
318
319static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *req)
246{ 320{
247 struct mmc_blk_data *md = mq->data; 321 struct mmc_blk_data *md = mq->data;
248 struct mmc_card *card = md->queue.card; 322 struct mmc_card *card = md->queue.card;
@@ -470,6 +544,17 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
470 return 0; 544 return 0;
471} 545}
472 546
547static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
548{
549 if (req->cmd_flags & REQ_DISCARD) {
550 if (req->cmd_flags & REQ_SECURE)
551 return mmc_blk_issue_secdiscard_rq(mq, req);
552 else
553 return mmc_blk_issue_discard_rq(mq, req);
554 } else {
555 return mmc_blk_issue_rw_rq(mq, req);
556 }
557}
473 558
474static inline int mmc_blk_readonly(struct mmc_card *card) 559static inline int mmc_blk_readonly(struct mmc_card *card)
475{ 560{
diff --git a/drivers/mmc/card/mmc_test.c b/drivers/mmc/card/mmc_test.c
index 445d7db2277e..5dd8576b5c18 100644
--- a/drivers/mmc/card/mmc_test.c
+++ b/drivers/mmc/card/mmc_test.c
@@ -16,6 +16,7 @@
16#include <linux/slab.h> 16#include <linux/slab.h>
17 17
18#include <linux/scatterlist.h> 18#include <linux/scatterlist.h>
19#include <linux/swap.h> /* For nr_free_buffer_pages() */
19 20
20#define RESULT_OK 0 21#define RESULT_OK 0
21#define RESULT_FAIL 1 22#define RESULT_FAIL 1
@@ -25,6 +26,60 @@
25#define BUFFER_ORDER 2 26#define BUFFER_ORDER 2
26#define BUFFER_SIZE (PAGE_SIZE << BUFFER_ORDER) 27#define BUFFER_SIZE (PAGE_SIZE << BUFFER_ORDER)
27 28
29/*
30 * Limit the test area size to the maximum MMC HC erase group size. Note that
31 * the maximum SD allocation unit size is just 4MiB.
32 */
33#define TEST_AREA_MAX_SIZE (128 * 1024 * 1024)
34
35/**
36 * struct mmc_test_pages - pages allocated by 'alloc_pages()'.
37 * @page: first page in the allocation
38 * @order: order of the number of pages allocated
39 */
40struct mmc_test_pages {
41 struct page *page;
42 unsigned int order;
43};
44
45/**
46 * struct mmc_test_mem - allocated memory.
47 * @arr: array of allocations
48 * @cnt: number of allocations
49 */
50struct mmc_test_mem {
51 struct mmc_test_pages *arr;
52 unsigned int cnt;
53};
54
55/**
56 * struct mmc_test_area - information for performance tests.
57 * @max_sz: test area size (in bytes)
58 * @dev_addr: address on card at which to do performance tests
59 * @max_segs: maximum segments in scatterlist @sg
60 * @blocks: number of (512 byte) blocks currently mapped by @sg
61 * @sg_len: length of currently mapped scatterlist @sg
62 * @mem: allocated memory
63 * @sg: scatterlist
64 */
65struct mmc_test_area {
66 unsigned long max_sz;
67 unsigned int dev_addr;
68 unsigned int max_segs;
69 unsigned int blocks;
70 unsigned int sg_len;
71 struct mmc_test_mem *mem;
72 struct scatterlist *sg;
73};
74
75/**
76 * struct mmc_test_card - test information.
77 * @card: card under test
78 * @scratch: transfer buffer
79 * @buffer: transfer buffer
80 * @highmem: buffer for highmem tests
81 * @area: information for performance tests
82 */
28struct mmc_test_card { 83struct mmc_test_card {
29 struct mmc_card *card; 84 struct mmc_card *card;
30 85
@@ -33,6 +88,7 @@ struct mmc_test_card {
33#ifdef CONFIG_HIGHMEM 88#ifdef CONFIG_HIGHMEM
34 struct page *highmem; 89 struct page *highmem;
35#endif 90#endif
91 struct mmc_test_area area;
36}; 92};
37 93
38/*******************************************************************/ 94/*******************************************************************/
@@ -97,6 +153,12 @@ static void mmc_test_prepare_mrq(struct mmc_test_card *test,
97 mmc_set_data_timeout(mrq->data, test->card); 153 mmc_set_data_timeout(mrq->data, test->card);
98} 154}
99 155
156static int mmc_test_busy(struct mmc_command *cmd)
157{
158 return !(cmd->resp[0] & R1_READY_FOR_DATA) ||
159 (R1_CURRENT_STATE(cmd->resp[0]) == 7);
160}
161
100/* 162/*
101 * Wait for the card to finish the busy state 163 * Wait for the card to finish the busy state
102 */ 164 */
@@ -117,13 +179,13 @@ static int mmc_test_wait_busy(struct mmc_test_card *test)
117 if (ret) 179 if (ret)
118 break; 180 break;
119 181
120 if (!busy && !(cmd.resp[0] & R1_READY_FOR_DATA)) { 182 if (!busy && mmc_test_busy(&cmd)) {
121 busy = 1; 183 busy = 1;
122 printk(KERN_INFO "%s: Warning: Host did not " 184 printk(KERN_INFO "%s: Warning: Host did not "
123 "wait for busy state to end.\n", 185 "wait for busy state to end.\n",
124 mmc_hostname(test->card->host)); 186 mmc_hostname(test->card->host));
125 } 187 }
126 } while (!(cmd.resp[0] & R1_READY_FOR_DATA)); 188 } while (mmc_test_busy(&cmd));
127 189
128 return ret; 190 return ret;
129} 191}
@@ -170,6 +232,248 @@ static int mmc_test_buffer_transfer(struct mmc_test_card *test,
170 return 0; 232 return 0;
171} 233}
172 234
235static void mmc_test_free_mem(struct mmc_test_mem *mem)
236{
237 if (!mem)
238 return;
239 while (mem->cnt--)
240 __free_pages(mem->arr[mem->cnt].page,
241 mem->arr[mem->cnt].order);
242 kfree(mem->arr);
243 kfree(mem);
244}
245
246/*
247 * Allocate a lot of memory, preferrably max_sz but at least min_sz. In case
248 * there isn't much memory do not exceed 1/16th total lowmem pages.
249 */
250static struct mmc_test_mem *mmc_test_alloc_mem(unsigned long min_sz,
251 unsigned long max_sz)
252{
253 unsigned long max_page_cnt = DIV_ROUND_UP(max_sz, PAGE_SIZE);
254 unsigned long min_page_cnt = DIV_ROUND_UP(min_sz, PAGE_SIZE);
255 unsigned long page_cnt = 0;
256 unsigned long limit = nr_free_buffer_pages() >> 4;
257 struct mmc_test_mem *mem;
258
259 if (max_page_cnt > limit)
260 max_page_cnt = limit;
261 if (max_page_cnt < min_page_cnt)
262 max_page_cnt = min_page_cnt;
263
264 mem = kzalloc(sizeof(struct mmc_test_mem), GFP_KERNEL);
265 if (!mem)
266 return NULL;
267
268 mem->arr = kzalloc(sizeof(struct mmc_test_pages) * max_page_cnt,
269 GFP_KERNEL);
270 if (!mem->arr)
271 goto out_free;
272
273 while (max_page_cnt) {
274 struct page *page;
275 unsigned int order;
276 gfp_t flags = GFP_KERNEL | GFP_DMA | __GFP_NOWARN |
277 __GFP_NORETRY;
278
279 order = get_order(max_page_cnt << PAGE_SHIFT);
280 while (1) {
281 page = alloc_pages(flags, order);
282 if (page || !order)
283 break;
284 order -= 1;
285 }
286 if (!page) {
287 if (page_cnt < min_page_cnt)
288 goto out_free;
289 break;
290 }
291 mem->arr[mem->cnt].page = page;
292 mem->arr[mem->cnt].order = order;
293 mem->cnt += 1;
294 if (max_page_cnt <= (1UL << order))
295 break;
296 max_page_cnt -= 1UL << order;
297 page_cnt += 1UL << order;
298 }
299
300 return mem;
301
302out_free:
303 mmc_test_free_mem(mem);
304 return NULL;
305}
306
307/*
308 * Map memory into a scatterlist. Optionally allow the same memory to be
309 * mapped more than once.
310 */
311static int mmc_test_map_sg(struct mmc_test_mem *mem, unsigned long sz,
312 struct scatterlist *sglist, int repeat,
313 unsigned int max_segs, unsigned int *sg_len)
314{
315 struct scatterlist *sg = NULL;
316 unsigned int i;
317
318 sg_init_table(sglist, max_segs);
319
320 *sg_len = 0;
321 do {
322 for (i = 0; i < mem->cnt; i++) {
323 unsigned long len = PAGE_SIZE << mem->arr[i].order;
324
325 if (sz < len)
326 len = sz;
327 if (sg)
328 sg = sg_next(sg);
329 else
330 sg = sglist;
331 if (!sg)
332 return -EINVAL;
333 sg_set_page(sg, mem->arr[i].page, len, 0);
334 sz -= len;
335 *sg_len += 1;
336 if (!sz)
337 break;
338 }
339 } while (sz && repeat);
340
341 if (sz)
342 return -EINVAL;
343
344 if (sg)
345 sg_mark_end(sg);
346
347 return 0;
348}
349
350/*
351 * Map memory into a scatterlist so that no pages are contiguous. Allow the
352 * same memory to be mapped more than once.
353 */
354static int mmc_test_map_sg_max_scatter(struct mmc_test_mem *mem,
355 unsigned long sz,
356 struct scatterlist *sglist,
357 unsigned int max_segs,
358 unsigned int *sg_len)
359{
360 struct scatterlist *sg = NULL;
361 unsigned int i = mem->cnt, cnt;
362 unsigned long len;
363 void *base, *addr, *last_addr = NULL;
364
365 sg_init_table(sglist, max_segs);
366
367 *sg_len = 0;
368 while (sz && i) {
369 base = page_address(mem->arr[--i].page);
370 cnt = 1 << mem->arr[i].order;
371 while (sz && cnt) {
372 addr = base + PAGE_SIZE * --cnt;
373 if (last_addr && last_addr + PAGE_SIZE == addr)
374 continue;
375 last_addr = addr;
376 len = PAGE_SIZE;
377 if (sz < len)
378 len = sz;
379 if (sg)
380 sg = sg_next(sg);
381 else
382 sg = sglist;
383 if (!sg)
384 return -EINVAL;
385 sg_set_page(sg, virt_to_page(addr), len, 0);
386 sz -= len;
387 *sg_len += 1;
388 }
389 }
390
391 if (sg)
392 sg_mark_end(sg);
393
394 return 0;
395}
396
397/*
398 * Calculate transfer rate in bytes per second.
399 */
400static unsigned int mmc_test_rate(uint64_t bytes, struct timespec *ts)
401{
402 uint64_t ns;
403
404 ns = ts->tv_sec;
405 ns *= 1000000000;
406 ns += ts->tv_nsec;
407
408 bytes *= 1000000000;
409
410 while (ns > UINT_MAX) {
411 bytes >>= 1;
412 ns >>= 1;
413 }
414
415 if (!ns)
416 return 0;
417
418 do_div(bytes, (uint32_t)ns);
419
420 return bytes;
421}
422
423/*
424 * Print the transfer rate.
425 */
426static void mmc_test_print_rate(struct mmc_test_card *test, uint64_t bytes,
427 struct timespec *ts1, struct timespec *ts2)
428{
429 unsigned int rate, sectors = bytes >> 9;
430 struct timespec ts;
431
432 ts = timespec_sub(*ts2, *ts1);
433
434 rate = mmc_test_rate(bytes, &ts);
435
436 printk(KERN_INFO "%s: Transfer of %u sectors (%u%s KiB) took %lu.%09lu "
437 "seconds (%u kB/s, %u KiB/s)\n",
438 mmc_hostname(test->card->host), sectors, sectors >> 1,
439 (sectors == 1 ? ".5" : ""), (unsigned long)ts.tv_sec,
440 (unsigned long)ts.tv_nsec, rate / 1000, rate / 1024);
441}
442
443/*
444 * Print the average transfer rate.
445 */
446static void mmc_test_print_avg_rate(struct mmc_test_card *test, uint64_t bytes,
447 unsigned int count, struct timespec *ts1,
448 struct timespec *ts2)
449{
450 unsigned int rate, sectors = bytes >> 9;
451 uint64_t tot = bytes * count;
452 struct timespec ts;
453
454 ts = timespec_sub(*ts2, *ts1);
455
456 rate = mmc_test_rate(tot, &ts);
457
458 printk(KERN_INFO "%s: Transfer of %u x %u sectors (%u x %u%s KiB) took "
459 "%lu.%09lu seconds (%u kB/s, %u KiB/s)\n",
460 mmc_hostname(test->card->host), count, sectors, count,
461 sectors >> 1, (sectors == 1 ? ".5" : ""),
462 (unsigned long)ts.tv_sec, (unsigned long)ts.tv_nsec,
463 rate / 1000, rate / 1024);
464}
465
466/*
467 * Return the card size in sectors.
468 */
469static unsigned int mmc_test_capacity(struct mmc_card *card)
470{
471 if (!mmc_card_sd(card) && mmc_card_blockaddr(card))
472 return card->ext_csd.sectors;
473 else
474 return card->csd.capacity << (card->csd.read_blkbits - 9);
475}
476
173/*******************************************************************/ 477/*******************************************************************/
174/* Test preparation and cleanup */ 478/* Test preparation and cleanup */
175/*******************************************************************/ 479/*******************************************************************/
@@ -893,8 +1197,419 @@ static int mmc_test_multi_read_high(struct mmc_test_card *test)
893 return 0; 1197 return 0;
894} 1198}
895 1199
1200#else
1201
1202static int mmc_test_no_highmem(struct mmc_test_card *test)
1203{
1204 printk(KERN_INFO "%s: Highmem not configured - test skipped\n",
1205 mmc_hostname(test->card->host));
1206 return 0;
1207}
1208
896#endif /* CONFIG_HIGHMEM */ 1209#endif /* CONFIG_HIGHMEM */
897 1210
1211/*
1212 * Map sz bytes so that it can be transferred.
1213 */
1214static int mmc_test_area_map(struct mmc_test_card *test, unsigned long sz,
1215 int max_scatter)
1216{
1217 struct mmc_test_area *t = &test->area;
1218
1219 t->blocks = sz >> 9;
1220
1221 if (max_scatter) {
1222 return mmc_test_map_sg_max_scatter(t->mem, sz, t->sg,
1223 t->max_segs, &t->sg_len);
1224 } else {
1225 return mmc_test_map_sg(t->mem, sz, t->sg, 1, t->max_segs,
1226 &t->sg_len);
1227 }
1228}
1229
1230/*
1231 * Transfer bytes mapped by mmc_test_area_map().
1232 */
1233static int mmc_test_area_transfer(struct mmc_test_card *test,
1234 unsigned int dev_addr, int write)
1235{
1236 struct mmc_test_area *t = &test->area;
1237
1238 return mmc_test_simple_transfer(test, t->sg, t->sg_len, dev_addr,
1239 t->blocks, 512, write);
1240}
1241
1242/*
1243 * Map and transfer bytes.
1244 */
1245static int mmc_test_area_io(struct mmc_test_card *test, unsigned long sz,
1246 unsigned int dev_addr, int write, int max_scatter,
1247 int timed)
1248{
1249 struct timespec ts1, ts2;
1250 int ret;
1251
1252 ret = mmc_test_area_map(test, sz, max_scatter);
1253 if (ret)
1254 return ret;
1255
1256 if (timed)
1257 getnstimeofday(&ts1);
1258
1259 ret = mmc_test_area_transfer(test, dev_addr, write);
1260 if (ret)
1261 return ret;
1262
1263 if (timed)
1264 getnstimeofday(&ts2);
1265
1266 if (timed)
1267 mmc_test_print_rate(test, sz, &ts1, &ts2);
1268
1269 return 0;
1270}
1271
1272/*
1273 * Write the test area entirely.
1274 */
1275static int mmc_test_area_fill(struct mmc_test_card *test)
1276{
1277 return mmc_test_area_io(test, test->area.max_sz, test->area.dev_addr,
1278 1, 0, 0);
1279}
1280
1281/*
1282 * Erase the test area entirely.
1283 */
1284static int mmc_test_area_erase(struct mmc_test_card *test)
1285{
1286 struct mmc_test_area *t = &test->area;
1287
1288 if (!mmc_can_erase(test->card))
1289 return 0;
1290
1291 return mmc_erase(test->card, t->dev_addr, test->area.max_sz >> 9,
1292 MMC_ERASE_ARG);
1293}
1294
1295/*
1296 * Cleanup struct mmc_test_area.
1297 */
1298static int mmc_test_area_cleanup(struct mmc_test_card *test)
1299{
1300 struct mmc_test_area *t = &test->area;
1301
1302 kfree(t->sg);
1303 mmc_test_free_mem(t->mem);
1304
1305 return 0;
1306}
1307
1308/*
1309 * Initialize an area for testing large transfers. The size of the area is the
1310 * preferred erase size which is a good size for optimal transfer speed. Note
1311 * that is typically 4MiB for modern cards. The test area is set to the middle
1312 * of the card because cards may have different charateristics at the front
1313 * (for FAT file system optimization). Optionally, the area is erased (if the
1314 * card supports it) which may improve write performance. Optionally, the area
1315 * is filled with data for subsequent read tests.
1316 */
1317static int mmc_test_area_init(struct mmc_test_card *test, int erase, int fill)
1318{
1319 struct mmc_test_area *t = &test->area;
1320 unsigned long min_sz = 64 * 1024;
1321 int ret;
1322
1323 ret = mmc_test_set_blksize(test, 512);
1324 if (ret)
1325 return ret;
1326
1327 if (test->card->pref_erase > TEST_AREA_MAX_SIZE >> 9)
1328 t->max_sz = TEST_AREA_MAX_SIZE;
1329 else
1330 t->max_sz = (unsigned long)test->card->pref_erase << 9;
1331 /*
1332 * Try to allocate enough memory for the whole area. Less is OK
1333 * because the same memory can be mapped into the scatterlist more than
1334 * once.
1335 */
1336 t->mem = mmc_test_alloc_mem(min_sz, t->max_sz);
1337 if (!t->mem)
1338 return -ENOMEM;
1339
1340 t->max_segs = DIV_ROUND_UP(t->max_sz, PAGE_SIZE);
1341 t->sg = kmalloc(sizeof(struct scatterlist) * t->max_segs, GFP_KERNEL);
1342 if (!t->sg) {
1343 ret = -ENOMEM;
1344 goto out_free;
1345 }
1346
1347 t->dev_addr = mmc_test_capacity(test->card) / 2;
1348 t->dev_addr -= t->dev_addr % (t->max_sz >> 9);
1349
1350 if (erase) {
1351 ret = mmc_test_area_erase(test);
1352 if (ret)
1353 goto out_free;
1354 }
1355
1356 if (fill) {
1357 ret = mmc_test_area_fill(test);
1358 if (ret)
1359 goto out_free;
1360 }
1361
1362 return 0;
1363
1364out_free:
1365 mmc_test_area_cleanup(test);
1366 return ret;
1367}
1368
1369/*
1370 * Prepare for large transfers. Do not erase the test area.
1371 */
1372static int mmc_test_area_prepare(struct mmc_test_card *test)
1373{
1374 return mmc_test_area_init(test, 0, 0);
1375}
1376
1377/*
1378 * Prepare for large transfers. Do erase the test area.
1379 */
1380static int mmc_test_area_prepare_erase(struct mmc_test_card *test)
1381{
1382 return mmc_test_area_init(test, 1, 0);
1383}
1384
1385/*
1386 * Prepare for large transfers. Erase and fill the test area.
1387 */
1388static int mmc_test_area_prepare_fill(struct mmc_test_card *test)
1389{
1390 return mmc_test_area_init(test, 1, 1);
1391}
1392
1393/*
1394 * Test best-case performance. Best-case performance is expected from
1395 * a single large transfer.
1396 *
1397 * An additional option (max_scatter) allows the measurement of the same
1398 * transfer but with no contiguous pages in the scatter list. This tests
1399 * the efficiency of DMA to handle scattered pages.
1400 */
1401static int mmc_test_best_performance(struct mmc_test_card *test, int write,
1402 int max_scatter)
1403{
1404 return mmc_test_area_io(test, test->area.max_sz, test->area.dev_addr,
1405 write, max_scatter, 1);
1406}
1407
1408/*
1409 * Best-case read performance.
1410 */
1411static int mmc_test_best_read_performance(struct mmc_test_card *test)
1412{
1413 return mmc_test_best_performance(test, 0, 0);
1414}
1415
1416/*
1417 * Best-case write performance.
1418 */
1419static int mmc_test_best_write_performance(struct mmc_test_card *test)
1420{
1421 return mmc_test_best_performance(test, 1, 0);
1422}
1423
1424/*
1425 * Best-case read performance into scattered pages.
1426 */
1427static int mmc_test_best_read_perf_max_scatter(struct mmc_test_card *test)
1428{
1429 return mmc_test_best_performance(test, 0, 1);
1430}
1431
1432/*
1433 * Best-case write performance from scattered pages.
1434 */
1435static int mmc_test_best_write_perf_max_scatter(struct mmc_test_card *test)
1436{
1437 return mmc_test_best_performance(test, 1, 1);
1438}
1439
1440/*
1441 * Single read performance by transfer size.
1442 */
1443static int mmc_test_profile_read_perf(struct mmc_test_card *test)
1444{
1445 unsigned long sz;
1446 unsigned int dev_addr;
1447 int ret;
1448
1449 for (sz = 512; sz < test->area.max_sz; sz <<= 1) {
1450 dev_addr = test->area.dev_addr + (sz >> 9);
1451 ret = mmc_test_area_io(test, sz, dev_addr, 0, 0, 1);
1452 if (ret)
1453 return ret;
1454 }
1455 dev_addr = test->area.dev_addr;
1456 return mmc_test_area_io(test, sz, dev_addr, 0, 0, 1);
1457}
1458
1459/*
1460 * Single write performance by transfer size.
1461 */
1462static int mmc_test_profile_write_perf(struct mmc_test_card *test)
1463{
1464 unsigned long sz;
1465 unsigned int dev_addr;
1466 int ret;
1467
1468 ret = mmc_test_area_erase(test);
1469 if (ret)
1470 return ret;
1471 for (sz = 512; sz < test->area.max_sz; sz <<= 1) {
1472 dev_addr = test->area.dev_addr + (sz >> 9);
1473 ret = mmc_test_area_io(test, sz, dev_addr, 1, 0, 1);
1474 if (ret)
1475 return ret;
1476 }
1477 ret = mmc_test_area_erase(test);
1478 if (ret)
1479 return ret;
1480 dev_addr = test->area.dev_addr;
1481 return mmc_test_area_io(test, sz, dev_addr, 1, 0, 1);
1482}
1483
1484/*
1485 * Single trim performance by transfer size.
1486 */
1487static int mmc_test_profile_trim_perf(struct mmc_test_card *test)
1488{
1489 unsigned long sz;
1490 unsigned int dev_addr;
1491 struct timespec ts1, ts2;
1492 int ret;
1493
1494 if (!mmc_can_trim(test->card))
1495 return RESULT_UNSUP_CARD;
1496
1497 if (!mmc_can_erase(test->card))
1498 return RESULT_UNSUP_HOST;
1499
1500 for (sz = 512; sz < test->area.max_sz; sz <<= 1) {
1501 dev_addr = test->area.dev_addr + (sz >> 9);
1502 getnstimeofday(&ts1);
1503 ret = mmc_erase(test->card, dev_addr, sz >> 9, MMC_TRIM_ARG);
1504 if (ret)
1505 return ret;
1506 getnstimeofday(&ts2);
1507 mmc_test_print_rate(test, sz, &ts1, &ts2);
1508 }
1509 dev_addr = test->area.dev_addr;
1510 getnstimeofday(&ts1);
1511 ret = mmc_erase(test->card, dev_addr, sz >> 9, MMC_TRIM_ARG);
1512 if (ret)
1513 return ret;
1514 getnstimeofday(&ts2);
1515 mmc_test_print_rate(test, sz, &ts1, &ts2);
1516 return 0;
1517}
1518
1519/*
1520 * Consecutive read performance by transfer size.
1521 */
1522static int mmc_test_profile_seq_read_perf(struct mmc_test_card *test)
1523{
1524 unsigned long sz;
1525 unsigned int dev_addr, i, cnt;
1526 struct timespec ts1, ts2;
1527 int ret;
1528
1529 for (sz = 512; sz <= test->area.max_sz; sz <<= 1) {
1530 cnt = test->area.max_sz / sz;
1531 dev_addr = test->area.dev_addr;
1532 getnstimeofday(&ts1);
1533 for (i = 0; i < cnt; i++) {
1534 ret = mmc_test_area_io(test, sz, dev_addr, 0, 0, 0);
1535 if (ret)
1536 return ret;
1537 dev_addr += (sz >> 9);
1538 }
1539 getnstimeofday(&ts2);
1540 mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2);
1541 }
1542 return 0;
1543}
1544
1545/*
1546 * Consecutive write performance by transfer size.
1547 */
1548static int mmc_test_profile_seq_write_perf(struct mmc_test_card *test)
1549{
1550 unsigned long sz;
1551 unsigned int dev_addr, i, cnt;
1552 struct timespec ts1, ts2;
1553 int ret;
1554
1555 for (sz = 512; sz <= test->area.max_sz; sz <<= 1) {
1556 ret = mmc_test_area_erase(test);
1557 if (ret)
1558 return ret;
1559 cnt = test->area.max_sz / sz;
1560 dev_addr = test->area.dev_addr;
1561 getnstimeofday(&ts1);
1562 for (i = 0; i < cnt; i++) {
1563 ret = mmc_test_area_io(test, sz, dev_addr, 1, 0, 0);
1564 if (ret)
1565 return ret;
1566 dev_addr += (sz >> 9);
1567 }
1568 getnstimeofday(&ts2);
1569 mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2);
1570 }
1571 return 0;
1572}
1573
1574/*
1575 * Consecutive trim performance by transfer size.
1576 */
1577static int mmc_test_profile_seq_trim_perf(struct mmc_test_card *test)
1578{
1579 unsigned long sz;
1580 unsigned int dev_addr, i, cnt;
1581 struct timespec ts1, ts2;
1582 int ret;
1583
1584 if (!mmc_can_trim(test->card))
1585 return RESULT_UNSUP_CARD;
1586
1587 if (!mmc_can_erase(test->card))
1588 return RESULT_UNSUP_HOST;
1589
1590 for (sz = 512; sz <= test->area.max_sz; sz <<= 1) {
1591 ret = mmc_test_area_erase(test);
1592 if (ret)
1593 return ret;
1594 ret = mmc_test_area_fill(test);
1595 if (ret)
1596 return ret;
1597 cnt = test->area.max_sz / sz;
1598 dev_addr = test->area.dev_addr;
1599 getnstimeofday(&ts1);
1600 for (i = 0; i < cnt; i++) {
1601 ret = mmc_erase(test->card, dev_addr, sz >> 9,
1602 MMC_TRIM_ARG);
1603 if (ret)
1604 return ret;
1605 dev_addr += (sz >> 9);
1606 }
1607 getnstimeofday(&ts2);
1608 mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2);
1609 }
1610 return 0;
1611}
1612
898static const struct mmc_test_case mmc_test_cases[] = { 1613static const struct mmc_test_case mmc_test_cases[] = {
899 { 1614 {
900 .name = "Basic write (no data verification)", 1615 .name = "Basic write (no data verification)",
@@ -1040,8 +1755,100 @@ static const struct mmc_test_case mmc_test_cases[] = {
1040 .cleanup = mmc_test_cleanup, 1755 .cleanup = mmc_test_cleanup,
1041 }, 1756 },
1042 1757
1758#else
1759
1760 {
1761 .name = "Highmem write",
1762 .run = mmc_test_no_highmem,
1763 },
1764
1765 {
1766 .name = "Highmem read",
1767 .run = mmc_test_no_highmem,
1768 },
1769
1770 {
1771 .name = "Multi-block highmem write",
1772 .run = mmc_test_no_highmem,
1773 },
1774
1775 {
1776 .name = "Multi-block highmem read",
1777 .run = mmc_test_no_highmem,
1778 },
1779
1043#endif /* CONFIG_HIGHMEM */ 1780#endif /* CONFIG_HIGHMEM */
1044 1781
1782 {
1783 .name = "Best-case read performance",
1784 .prepare = mmc_test_area_prepare_fill,
1785 .run = mmc_test_best_read_performance,
1786 .cleanup = mmc_test_area_cleanup,
1787 },
1788
1789 {
1790 .name = "Best-case write performance",
1791 .prepare = mmc_test_area_prepare_erase,
1792 .run = mmc_test_best_write_performance,
1793 .cleanup = mmc_test_area_cleanup,
1794 },
1795
1796 {
1797 .name = "Best-case read performance into scattered pages",
1798 .prepare = mmc_test_area_prepare_fill,
1799 .run = mmc_test_best_read_perf_max_scatter,
1800 .cleanup = mmc_test_area_cleanup,
1801 },
1802
1803 {
1804 .name = "Best-case write performance from scattered pages",
1805 .prepare = mmc_test_area_prepare_erase,
1806 .run = mmc_test_best_write_perf_max_scatter,
1807 .cleanup = mmc_test_area_cleanup,
1808 },
1809
1810 {
1811 .name = "Single read performance by transfer size",
1812 .prepare = mmc_test_area_prepare_fill,
1813 .run = mmc_test_profile_read_perf,
1814 .cleanup = mmc_test_area_cleanup,
1815 },
1816
1817 {
1818 .name = "Single write performance by transfer size",
1819 .prepare = mmc_test_area_prepare,
1820 .run = mmc_test_profile_write_perf,
1821 .cleanup = mmc_test_area_cleanup,
1822 },
1823
1824 {
1825 .name = "Single trim performance by transfer size",
1826 .prepare = mmc_test_area_prepare_fill,
1827 .run = mmc_test_profile_trim_perf,
1828 .cleanup = mmc_test_area_cleanup,
1829 },
1830
1831 {
1832 .name = "Consecutive read performance by transfer size",
1833 .prepare = mmc_test_area_prepare_fill,
1834 .run = mmc_test_profile_seq_read_perf,
1835 .cleanup = mmc_test_area_cleanup,
1836 },
1837
1838 {
1839 .name = "Consecutive write performance by transfer size",
1840 .prepare = mmc_test_area_prepare,
1841 .run = mmc_test_profile_seq_write_perf,
1842 .cleanup = mmc_test_area_cleanup,
1843 },
1844
1845 {
1846 .name = "Consecutive trim performance by transfer size",
1847 .prepare = mmc_test_area_prepare,
1848 .run = mmc_test_profile_seq_trim_perf,
1849 .cleanup = mmc_test_area_cleanup,
1850 },
1851
1045}; 1852};
1046 1853
1047static DEFINE_MUTEX(mmc_test_lock); 1854static DEFINE_MUTEX(mmc_test_lock);
diff --git a/drivers/mmc/card/queue.c b/drivers/mmc/card/queue.c
index d6ded247d941..e876678176be 100644
--- a/drivers/mmc/card/queue.c
+++ b/drivers/mmc/card/queue.c
@@ -30,9 +30,9 @@
30static int mmc_prep_request(struct request_queue *q, struct request *req) 30static int mmc_prep_request(struct request_queue *q, struct request *req)
31{ 31{
32 /* 32 /*
33 * We only like normal block requests. 33 * We only like normal block requests and discards.
34 */ 34 */
35 if (!blk_fs_request(req)) { 35 if (req->cmd_type != REQ_TYPE_FS && !(req->cmd_flags & REQ_DISCARD)) {
36 blk_dump_rq_flags(req, "MMC bad request"); 36 blk_dump_rq_flags(req, "MMC bad request");
37 return BLKPREP_KILL; 37 return BLKPREP_KILL;
38 } 38 }
@@ -128,8 +128,23 @@ int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card, spinlock_t *lock
128 mq->req = NULL; 128 mq->req = NULL;
129 129
130 blk_queue_prep_rq(mq->queue, mmc_prep_request); 130 blk_queue_prep_rq(mq->queue, mmc_prep_request);
131 blk_queue_ordered(mq->queue, QUEUE_ORDERED_DRAIN, NULL); 131 blk_queue_ordered(mq->queue, QUEUE_ORDERED_DRAIN);
132 queue_flag_set_unlocked(QUEUE_FLAG_NONROT, mq->queue); 132 queue_flag_set_unlocked(QUEUE_FLAG_NONROT, mq->queue);
133 if (mmc_can_erase(card)) {
134 queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, mq->queue);
135 mq->queue->limits.max_discard_sectors = UINT_MAX;
136 if (card->erased_byte == 0)
137 mq->queue->limits.discard_zeroes_data = 1;
138 if (!mmc_can_trim(card) && is_power_of_2(card->erase_size)) {
139 mq->queue->limits.discard_granularity =
140 card->erase_size << 9;
141 mq->queue->limits.discard_alignment =
142 card->erase_size << 9;
143 }
144 if (mmc_can_secure_erase_trim(card))
145 queue_flag_set_unlocked(QUEUE_FLAG_SECDISCARD,
146 mq->queue);
147 }
133 148
134#ifdef CONFIG_MMC_BLOCK_BOUNCE 149#ifdef CONFIG_MMC_BLOCK_BOUNCE
135 if (host->max_hw_segs == 1) { 150 if (host->max_hw_segs == 1) {
diff --git a/drivers/mmc/core/bus.c b/drivers/mmc/core/bus.c
index 49d9dcaeca49..7cd9749dc21d 100644
--- a/drivers/mmc/core/bus.c
+++ b/drivers/mmc/core/bus.c
@@ -37,6 +37,8 @@ static ssize_t mmc_type_show(struct device *dev,
37 return sprintf(buf, "SD\n"); 37 return sprintf(buf, "SD\n");
38 case MMC_TYPE_SDIO: 38 case MMC_TYPE_SDIO:
39 return sprintf(buf, "SDIO\n"); 39 return sprintf(buf, "SDIO\n");
40 case MMC_TYPE_SD_COMBO:
41 return sprintf(buf, "SDcombo\n");
40 default: 42 default:
41 return -EFAULT; 43 return -EFAULT;
42 } 44 }
@@ -74,6 +76,9 @@ mmc_bus_uevent(struct device *dev, struct kobj_uevent_env *env)
74 case MMC_TYPE_SDIO: 76 case MMC_TYPE_SDIO:
75 type = "SDIO"; 77 type = "SDIO";
76 break; 78 break;
79 case MMC_TYPE_SD_COMBO:
80 type = "SDcombo";
81 break;
77 default: 82 default:
78 type = NULL; 83 type = NULL;
79 } 84 }
@@ -239,6 +244,10 @@ int mmc_add_card(struct mmc_card *card)
239 case MMC_TYPE_SDIO: 244 case MMC_TYPE_SDIO:
240 type = "SDIO"; 245 type = "SDIO";
241 break; 246 break;
247 case MMC_TYPE_SD_COMBO:
248 type = "SD-combo";
249 if (mmc_card_blockaddr(card))
250 type = "SDHC-combo";
242 default: 251 default:
243 type = "?"; 252 type = "?";
244 break; 253 break;
diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 569e94da844c..5db49b124ffa 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -1050,6 +1050,352 @@ void mmc_detect_change(struct mmc_host *host, unsigned long delay)
1050 1050
1051EXPORT_SYMBOL(mmc_detect_change); 1051EXPORT_SYMBOL(mmc_detect_change);
1052 1052
1053void mmc_init_erase(struct mmc_card *card)
1054{
1055 unsigned int sz;
1056
1057 if (is_power_of_2(card->erase_size))
1058 card->erase_shift = ffs(card->erase_size) - 1;
1059 else
1060 card->erase_shift = 0;
1061
1062 /*
1063 * It is possible to erase an arbitrarily large area of an SD or MMC
1064 * card. That is not desirable because it can take a long time
1065 * (minutes) potentially delaying more important I/O, and also the
1066 * timeout calculations become increasingly hugely over-estimated.
1067 * Consequently, 'pref_erase' is defined as a guide to limit erases
1068 * to that size and alignment.
1069 *
1070 * For SD cards that define Allocation Unit size, limit erases to one
1071 * Allocation Unit at a time. For MMC cards that define High Capacity
1072 * Erase Size, whether it is switched on or not, limit to that size.
1073 * Otherwise just have a stab at a good value. For modern cards it
1074 * will end up being 4MiB. Note that if the value is too small, it
1075 * can end up taking longer to erase.
1076 */
1077 if (mmc_card_sd(card) && card->ssr.au) {
1078 card->pref_erase = card->ssr.au;
1079 card->erase_shift = ffs(card->ssr.au) - 1;
1080 } else if (card->ext_csd.hc_erase_size) {
1081 card->pref_erase = card->ext_csd.hc_erase_size;
1082 } else {
1083 sz = (card->csd.capacity << (card->csd.read_blkbits - 9)) >> 11;
1084 if (sz < 128)
1085 card->pref_erase = 512 * 1024 / 512;
1086 else if (sz < 512)
1087 card->pref_erase = 1024 * 1024 / 512;
1088 else if (sz < 1024)
1089 card->pref_erase = 2 * 1024 * 1024 / 512;
1090 else
1091 card->pref_erase = 4 * 1024 * 1024 / 512;
1092 if (card->pref_erase < card->erase_size)
1093 card->pref_erase = card->erase_size;
1094 else {
1095 sz = card->pref_erase % card->erase_size;
1096 if (sz)
1097 card->pref_erase += card->erase_size - sz;
1098 }
1099 }
1100}
1101
1102static void mmc_set_mmc_erase_timeout(struct mmc_card *card,
1103 struct mmc_command *cmd,
1104 unsigned int arg, unsigned int qty)
1105{
1106 unsigned int erase_timeout;
1107
1108 if (card->ext_csd.erase_group_def & 1) {
1109 /* High Capacity Erase Group Size uses HC timeouts */
1110 if (arg == MMC_TRIM_ARG)
1111 erase_timeout = card->ext_csd.trim_timeout;
1112 else
1113 erase_timeout = card->ext_csd.hc_erase_timeout;
1114 } else {
1115 /* CSD Erase Group Size uses write timeout */
1116 unsigned int mult = (10 << card->csd.r2w_factor);
1117 unsigned int timeout_clks = card->csd.tacc_clks * mult;
1118 unsigned int timeout_us;
1119
1120 /* Avoid overflow: e.g. tacc_ns=80000000 mult=1280 */
1121 if (card->csd.tacc_ns < 1000000)
1122 timeout_us = (card->csd.tacc_ns * mult) / 1000;
1123 else
1124 timeout_us = (card->csd.tacc_ns / 1000) * mult;
1125
1126 /*
1127 * ios.clock is only a target. The real clock rate might be
1128 * less but not that much less, so fudge it by multiplying by 2.
1129 */
1130 timeout_clks <<= 1;
1131 timeout_us += (timeout_clks * 1000) /
1132 (card->host->ios.clock / 1000);
1133
1134 erase_timeout = timeout_us / 1000;
1135
1136 /*
1137 * Theoretically, the calculation could underflow so round up
1138 * to 1ms in that case.
1139 */
1140 if (!erase_timeout)
1141 erase_timeout = 1;
1142 }
1143
1144 /* Multiplier for secure operations */
1145 if (arg & MMC_SECURE_ARGS) {
1146 if (arg == MMC_SECURE_ERASE_ARG)
1147 erase_timeout *= card->ext_csd.sec_erase_mult;
1148 else
1149 erase_timeout *= card->ext_csd.sec_trim_mult;
1150 }
1151
1152 erase_timeout *= qty;
1153
1154 /*
1155 * Ensure at least a 1 second timeout for SPI as per
1156 * 'mmc_set_data_timeout()'
1157 */
1158 if (mmc_host_is_spi(card->host) && erase_timeout < 1000)
1159 erase_timeout = 1000;
1160
1161 cmd->erase_timeout = erase_timeout;
1162}
1163
1164static void mmc_set_sd_erase_timeout(struct mmc_card *card,
1165 struct mmc_command *cmd, unsigned int arg,
1166 unsigned int qty)
1167{
1168 if (card->ssr.erase_timeout) {
1169 /* Erase timeout specified in SD Status Register (SSR) */
1170 cmd->erase_timeout = card->ssr.erase_timeout * qty +
1171 card->ssr.erase_offset;
1172 } else {
1173 /*
1174 * Erase timeout not specified in SD Status Register (SSR) so
1175 * use 250ms per write block.
1176 */
1177 cmd->erase_timeout = 250 * qty;
1178 }
1179
1180 /* Must not be less than 1 second */
1181 if (cmd->erase_timeout < 1000)
1182 cmd->erase_timeout = 1000;
1183}
1184
1185static void mmc_set_erase_timeout(struct mmc_card *card,
1186 struct mmc_command *cmd, unsigned int arg,
1187 unsigned int qty)
1188{
1189 if (mmc_card_sd(card))
1190 mmc_set_sd_erase_timeout(card, cmd, arg, qty);
1191 else
1192 mmc_set_mmc_erase_timeout(card, cmd, arg, qty);
1193}
1194
1195static int mmc_do_erase(struct mmc_card *card, unsigned int from,
1196 unsigned int to, unsigned int arg)
1197{
1198 struct mmc_command cmd;
1199 unsigned int qty = 0;
1200 int err;
1201
1202 /*
1203 * qty is used to calculate the erase timeout which depends on how many
1204 * erase groups (or allocation units in SD terminology) are affected.
1205 * We count erasing part of an erase group as one erase group.
1206 * For SD, the allocation units are always a power of 2. For MMC, the
1207 * erase group size is almost certainly also power of 2, but it does not
1208 * seem to insist on that in the JEDEC standard, so we fall back to
1209 * division in that case. SD may not specify an allocation unit size,
1210 * in which case the timeout is based on the number of write blocks.
1211 *
1212 * Note that the timeout for secure trim 2 will only be correct if the
1213 * number of erase groups specified is the same as the total of all
1214 * preceding secure trim 1 commands. Since the power may have been
1215 * lost since the secure trim 1 commands occurred, it is generally
1216 * impossible to calculate the secure trim 2 timeout correctly.
1217 */
1218 if (card->erase_shift)
1219 qty += ((to >> card->erase_shift) -
1220 (from >> card->erase_shift)) + 1;
1221 else if (mmc_card_sd(card))
1222 qty += to - from + 1;
1223 else
1224 qty += ((to / card->erase_size) -
1225 (from / card->erase_size)) + 1;
1226
1227 if (!mmc_card_blockaddr(card)) {
1228 from <<= 9;
1229 to <<= 9;
1230 }
1231
1232 memset(&cmd, 0, sizeof(struct mmc_command));
1233 if (mmc_card_sd(card))
1234 cmd.opcode = SD_ERASE_WR_BLK_START;
1235 else
1236 cmd.opcode = MMC_ERASE_GROUP_START;
1237 cmd.arg = from;
1238 cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC;
1239 err = mmc_wait_for_cmd(card->host, &cmd, 0);
1240 if (err) {
1241 printk(KERN_ERR "mmc_erase: group start error %d, "
1242 "status %#x\n", err, cmd.resp[0]);
1243 err = -EINVAL;
1244 goto out;
1245 }
1246
1247 memset(&cmd, 0, sizeof(struct mmc_command));
1248 if (mmc_card_sd(card))
1249 cmd.opcode = SD_ERASE_WR_BLK_END;
1250 else
1251 cmd.opcode = MMC_ERASE_GROUP_END;
1252 cmd.arg = to;
1253 cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC;
1254 err = mmc_wait_for_cmd(card->host, &cmd, 0);
1255 if (err) {
1256 printk(KERN_ERR "mmc_erase: group end error %d, status %#x\n",
1257 err, cmd.resp[0]);
1258 err = -EINVAL;
1259 goto out;
1260 }
1261
1262 memset(&cmd, 0, sizeof(struct mmc_command));
1263 cmd.opcode = MMC_ERASE;
1264 cmd.arg = arg;
1265 cmd.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC;
1266 mmc_set_erase_timeout(card, &cmd, arg, qty);
1267 err = mmc_wait_for_cmd(card->host, &cmd, 0);
1268 if (err) {
1269 printk(KERN_ERR "mmc_erase: erase error %d, status %#x\n",
1270 err, cmd.resp[0]);
1271 err = -EIO;
1272 goto out;
1273 }
1274
1275 if (mmc_host_is_spi(card->host))
1276 goto out;
1277
1278 do {
1279 memset(&cmd, 0, sizeof(struct mmc_command));
1280 cmd.opcode = MMC_SEND_STATUS;
1281 cmd.arg = card->rca << 16;
1282 cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
1283 /* Do not retry else we can't see errors */
1284 err = mmc_wait_for_cmd(card->host, &cmd, 0);
1285 if (err || (cmd.resp[0] & 0xFDF92000)) {
1286 printk(KERN_ERR "error %d requesting status %#x\n",
1287 err, cmd.resp[0]);
1288 err = -EIO;
1289 goto out;
1290 }
1291 } while (!(cmd.resp[0] & R1_READY_FOR_DATA) ||
1292 R1_CURRENT_STATE(cmd.resp[0]) == 7);
1293out:
1294 return err;
1295}
1296
1297/**
1298 * mmc_erase - erase sectors.
1299 * @card: card to erase
1300 * @from: first sector to erase
1301 * @nr: number of sectors to erase
1302 * @arg: erase command argument (SD supports only %MMC_ERASE_ARG)
1303 *
1304 * Caller must claim host before calling this function.
1305 */
1306int mmc_erase(struct mmc_card *card, unsigned int from, unsigned int nr,
1307 unsigned int arg)
1308{
1309 unsigned int rem, to = from + nr;
1310
1311 if (!(card->host->caps & MMC_CAP_ERASE) ||
1312 !(card->csd.cmdclass & CCC_ERASE))
1313 return -EOPNOTSUPP;
1314
1315 if (!card->erase_size)
1316 return -EOPNOTSUPP;
1317
1318 if (mmc_card_sd(card) && arg != MMC_ERASE_ARG)
1319 return -EOPNOTSUPP;
1320
1321 if ((arg & MMC_SECURE_ARGS) &&
1322 !(card->ext_csd.sec_feature_support & EXT_CSD_SEC_ER_EN))
1323 return -EOPNOTSUPP;
1324
1325 if ((arg & MMC_TRIM_ARGS) &&
1326 !(card->ext_csd.sec_feature_support & EXT_CSD_SEC_GB_CL_EN))
1327 return -EOPNOTSUPP;
1328
1329 if (arg == MMC_SECURE_ERASE_ARG) {
1330 if (from % card->erase_size || nr % card->erase_size)
1331 return -EINVAL;
1332 }
1333
1334 if (arg == MMC_ERASE_ARG) {
1335 rem = from % card->erase_size;
1336 if (rem) {
1337 rem = card->erase_size - rem;
1338 from += rem;
1339 if (nr > rem)
1340 nr -= rem;
1341 else
1342 return 0;
1343 }
1344 rem = nr % card->erase_size;
1345 if (rem)
1346 nr -= rem;
1347 }
1348
1349 if (nr == 0)
1350 return 0;
1351
1352 to = from + nr;
1353
1354 if (to <= from)
1355 return -EINVAL;
1356
1357 /* 'from' and 'to' are inclusive */
1358 to -= 1;
1359
1360 return mmc_do_erase(card, from, to, arg);
1361}
1362EXPORT_SYMBOL(mmc_erase);
1363
1364int mmc_can_erase(struct mmc_card *card)
1365{
1366 if ((card->host->caps & MMC_CAP_ERASE) &&
1367 (card->csd.cmdclass & CCC_ERASE) && card->erase_size)
1368 return 1;
1369 return 0;
1370}
1371EXPORT_SYMBOL(mmc_can_erase);
1372
1373int mmc_can_trim(struct mmc_card *card)
1374{
1375 if (card->ext_csd.sec_feature_support & EXT_CSD_SEC_GB_CL_EN)
1376 return 1;
1377 return 0;
1378}
1379EXPORT_SYMBOL(mmc_can_trim);
1380
1381int mmc_can_secure_erase_trim(struct mmc_card *card)
1382{
1383 if (card->ext_csd.sec_feature_support & EXT_CSD_SEC_ER_EN)
1384 return 1;
1385 return 0;
1386}
1387EXPORT_SYMBOL(mmc_can_secure_erase_trim);
1388
1389int mmc_erase_group_aligned(struct mmc_card *card, unsigned int from,
1390 unsigned int nr)
1391{
1392 if (!card->erase_size)
1393 return 0;
1394 if (from % card->erase_size || nr % card->erase_size)
1395 return 0;
1396 return 1;
1397}
1398EXPORT_SYMBOL(mmc_erase_group_aligned);
1053 1399
1054void mmc_rescan(struct work_struct *work) 1400void mmc_rescan(struct work_struct *work)
1055{ 1401{
@@ -1057,6 +1403,17 @@ void mmc_rescan(struct work_struct *work)
1057 container_of(work, struct mmc_host, detect.work); 1403 container_of(work, struct mmc_host, detect.work);
1058 u32 ocr; 1404 u32 ocr;
1059 int err; 1405 int err;
1406 unsigned long flags;
1407
1408 spin_lock_irqsave(&host->lock, flags);
1409
1410 if (host->rescan_disable) {
1411 spin_unlock_irqrestore(&host->lock, flags);
1412 return;
1413 }
1414
1415 spin_unlock_irqrestore(&host->lock, flags);
1416
1060 1417
1061 mmc_bus_get(host); 1418 mmc_bus_get(host);
1062 1419
@@ -1099,8 +1456,15 @@ void mmc_rescan(struct work_struct *work)
1099 */ 1456 */
1100 err = mmc_send_io_op_cond(host, 0, &ocr); 1457 err = mmc_send_io_op_cond(host, 0, &ocr);
1101 if (!err) { 1458 if (!err) {
1102 if (mmc_attach_sdio(host, ocr)) 1459 if (mmc_attach_sdio(host, ocr)) {
1103 mmc_power_off(host); 1460 mmc_claim_host(host);
1461 /* try SDMEM (but not MMC) even if SDIO is broken */
1462 if (mmc_send_app_op_cond(host, 0, &ocr))
1463 goto out_fail;
1464
1465 if (mmc_attach_sd(host, ocr))
1466 mmc_power_off(host);
1467 }
1104 goto out; 1468 goto out;
1105 } 1469 }
1106 1470
@@ -1124,6 +1488,7 @@ void mmc_rescan(struct work_struct *work)
1124 goto out; 1488 goto out;
1125 } 1489 }
1126 1490
1491out_fail:
1127 mmc_release_host(host); 1492 mmc_release_host(host);
1128 mmc_power_off(host); 1493 mmc_power_off(host);
1129 1494
@@ -1266,19 +1631,6 @@ int mmc_suspend_host(struct mmc_host *host)
1266 if (host->bus_ops && !host->bus_dead) { 1631 if (host->bus_ops && !host->bus_dead) {
1267 if (host->bus_ops->suspend) 1632 if (host->bus_ops->suspend)
1268 err = host->bus_ops->suspend(host); 1633 err = host->bus_ops->suspend(host);
1269 if (err == -ENOSYS || !host->bus_ops->resume) {
1270 /*
1271 * We simply "remove" the card in this case.
1272 * It will be redetected on resume.
1273 */
1274 if (host->bus_ops->remove)
1275 host->bus_ops->remove(host);
1276 mmc_claim_host(host);
1277 mmc_detach_bus(host);
1278 mmc_release_host(host);
1279 host->pm_flags = 0;
1280 err = 0;
1281 }
1282 } 1634 }
1283 mmc_bus_put(host); 1635 mmc_bus_put(host);
1284 1636
@@ -1310,28 +1662,61 @@ int mmc_resume_host(struct mmc_host *host)
1310 printk(KERN_WARNING "%s: error %d during resume " 1662 printk(KERN_WARNING "%s: error %d during resume "
1311 "(card was removed?)\n", 1663 "(card was removed?)\n",
1312 mmc_hostname(host), err); 1664 mmc_hostname(host), err);
1313 if (host->bus_ops->remove)
1314 host->bus_ops->remove(host);
1315 mmc_claim_host(host);
1316 mmc_detach_bus(host);
1317 mmc_release_host(host);
1318 /* no need to bother upper layers */
1319 err = 0; 1665 err = 0;
1320 } 1666 }
1321 } 1667 }
1322 mmc_bus_put(host); 1668 mmc_bus_put(host);
1323 1669
1324 /*
1325 * We add a slight delay here so that resume can progress
1326 * in parallel.
1327 */
1328 mmc_detect_change(host, 1);
1329
1330 return err; 1670 return err;
1331} 1671}
1332
1333EXPORT_SYMBOL(mmc_resume_host); 1672EXPORT_SYMBOL(mmc_resume_host);
1334 1673
1674/* Do the card removal on suspend if card is assumed removeable
1675 * Do that in pm notifier while userspace isn't yet frozen, so we will be able
1676 to sync the card.
1677*/
1678int mmc_pm_notify(struct notifier_block *notify_block,
1679 unsigned long mode, void *unused)
1680{
1681 struct mmc_host *host = container_of(
1682 notify_block, struct mmc_host, pm_notify);
1683 unsigned long flags;
1684
1685
1686 switch (mode) {
1687 case PM_HIBERNATION_PREPARE:
1688 case PM_SUSPEND_PREPARE:
1689
1690 spin_lock_irqsave(&host->lock, flags);
1691 host->rescan_disable = 1;
1692 spin_unlock_irqrestore(&host->lock, flags);
1693 cancel_delayed_work_sync(&host->detect);
1694
1695 if (!host->bus_ops || host->bus_ops->suspend)
1696 break;
1697
1698 mmc_claim_host(host);
1699
1700 if (host->bus_ops->remove)
1701 host->bus_ops->remove(host);
1702
1703 mmc_detach_bus(host);
1704 mmc_release_host(host);
1705 host->pm_flags = 0;
1706 break;
1707
1708 case PM_POST_SUSPEND:
1709 case PM_POST_HIBERNATION:
1710
1711 spin_lock_irqsave(&host->lock, flags);
1712 host->rescan_disable = 0;
1713 spin_unlock_irqrestore(&host->lock, flags);
1714 mmc_detect_change(host, 0);
1715
1716 }
1717
1718 return 0;
1719}
1335#endif 1720#endif
1336 1721
1337static int __init mmc_init(void) 1722static int __init mmc_init(void)
diff --git a/drivers/mmc/core/core.h b/drivers/mmc/core/core.h
index a811c52a1659..9d9eef50e5d1 100644
--- a/drivers/mmc/core/core.h
+++ b/drivers/mmc/core/core.h
@@ -29,6 +29,8 @@ struct mmc_bus_ops {
29void mmc_attach_bus(struct mmc_host *host, const struct mmc_bus_ops *ops); 29void mmc_attach_bus(struct mmc_host *host, const struct mmc_bus_ops *ops);
30void mmc_detach_bus(struct mmc_host *host); 30void mmc_detach_bus(struct mmc_host *host);
31 31
32void mmc_init_erase(struct mmc_card *card);
33
32void mmc_set_chip_select(struct mmc_host *host, int mode); 34void mmc_set_chip_select(struct mmc_host *host, int mode);
33void mmc_set_clock(struct mmc_host *host, unsigned int hz); 35void mmc_set_clock(struct mmc_host *host, unsigned int hz);
34void mmc_set_bus_mode(struct mmc_host *host, unsigned int mode); 36void mmc_set_bus_mode(struct mmc_host *host, unsigned int mode);
diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c
index 47353909e345..0efe631e50ca 100644
--- a/drivers/mmc/core/host.c
+++ b/drivers/mmc/core/host.c
@@ -17,6 +17,7 @@
17#include <linux/pagemap.h> 17#include <linux/pagemap.h>
18#include <linux/leds.h> 18#include <linux/leds.h>
19#include <linux/slab.h> 19#include <linux/slab.h>
20#include <linux/suspend.h>
20 21
21#include <linux/mmc/host.h> 22#include <linux/mmc/host.h>
22 23
@@ -85,6 +86,7 @@ struct mmc_host *mmc_alloc_host(int extra, struct device *dev)
85 init_waitqueue_head(&host->wq); 86 init_waitqueue_head(&host->wq);
86 INIT_DELAYED_WORK(&host->detect, mmc_rescan); 87 INIT_DELAYED_WORK(&host->detect, mmc_rescan);
87 INIT_DELAYED_WORK_DEFERRABLE(&host->disable, mmc_host_deeper_disable); 88 INIT_DELAYED_WORK_DEFERRABLE(&host->disable, mmc_host_deeper_disable);
89 host->pm_notify.notifier_call = mmc_pm_notify;
88 90
89 /* 91 /*
90 * By default, hosts do not support SGIO or large requests. 92 * By default, hosts do not support SGIO or large requests.
@@ -133,6 +135,7 @@ int mmc_add_host(struct mmc_host *host)
133#endif 135#endif
134 136
135 mmc_start_host(host); 137 mmc_start_host(host);
138 register_pm_notifier(&host->pm_notify);
136 139
137 return 0; 140 return 0;
138} 141}
@@ -149,6 +152,7 @@ EXPORT_SYMBOL(mmc_add_host);
149 */ 152 */
150void mmc_remove_host(struct mmc_host *host) 153void mmc_remove_host(struct mmc_host *host)
151{ 154{
155 unregister_pm_notifier(&host->pm_notify);
152 mmc_stop_host(host); 156 mmc_stop_host(host);
153 157
154#ifdef CONFIG_DEBUG_FS 158#ifdef CONFIG_DEBUG_FS
diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
index 89f7a25b7ac1..6909a54c39be 100644
--- a/drivers/mmc/core/mmc.c
+++ b/drivers/mmc/core/mmc.c
@@ -108,23 +108,34 @@ static int mmc_decode_cid(struct mmc_card *card)
108 return 0; 108 return 0;
109} 109}
110 110
111static void mmc_set_erase_size(struct mmc_card *card)
112{
113 if (card->ext_csd.erase_group_def & 1)
114 card->erase_size = card->ext_csd.hc_erase_size;
115 else
116 card->erase_size = card->csd.erase_size;
117
118 mmc_init_erase(card);
119}
120
111/* 121/*
112 * Given a 128-bit response, decode to our card CSD structure. 122 * Given a 128-bit response, decode to our card CSD structure.
113 */ 123 */
114static int mmc_decode_csd(struct mmc_card *card) 124static int mmc_decode_csd(struct mmc_card *card)
115{ 125{
116 struct mmc_csd *csd = &card->csd; 126 struct mmc_csd *csd = &card->csd;
117 unsigned int e, m, csd_struct; 127 unsigned int e, m, a, b;
118 u32 *resp = card->raw_csd; 128 u32 *resp = card->raw_csd;
119 129
120 /* 130 /*
121 * We only understand CSD structure v1.1 and v1.2. 131 * We only understand CSD structure v1.1 and v1.2.
122 * v1.2 has extra information in bits 15, 11 and 10. 132 * v1.2 has extra information in bits 15, 11 and 10.
133 * We also support eMMC v4.4 & v4.41.
123 */ 134 */
124 csd_struct = UNSTUFF_BITS(resp, 126, 2); 135 csd->structure = UNSTUFF_BITS(resp, 126, 2);
125 if (csd_struct != 1 && csd_struct != 2) { 136 if (csd->structure == 0) {
126 printk(KERN_ERR "%s: unrecognised CSD structure version %d\n", 137 printk(KERN_ERR "%s: unrecognised CSD structure version %d\n",
127 mmc_hostname(card->host), csd_struct); 138 mmc_hostname(card->host), csd->structure);
128 return -EINVAL; 139 return -EINVAL;
129 } 140 }
130 141
@@ -151,6 +162,13 @@ static int mmc_decode_csd(struct mmc_card *card)
151 csd->write_blkbits = UNSTUFF_BITS(resp, 22, 4); 162 csd->write_blkbits = UNSTUFF_BITS(resp, 22, 4);
152 csd->write_partial = UNSTUFF_BITS(resp, 21, 1); 163 csd->write_partial = UNSTUFF_BITS(resp, 21, 1);
153 164
165 if (csd->write_blkbits >= 9) {
166 a = UNSTUFF_BITS(resp, 42, 5);
167 b = UNSTUFF_BITS(resp, 37, 5);
168 csd->erase_size = (a + 1) * (b + 1);
169 csd->erase_size <<= csd->write_blkbits - 9;
170 }
171
154 return 0; 172 return 0;
155} 173}
156 174
@@ -207,11 +225,22 @@ static int mmc_read_ext_csd(struct mmc_card *card)
207 goto out; 225 goto out;
208 } 226 }
209 227
228 /* Version is coded in the CSD_STRUCTURE byte in the EXT_CSD register */
229 if (card->csd.structure == 3) {
230 int ext_csd_struct = ext_csd[EXT_CSD_STRUCTURE];
231 if (ext_csd_struct > 2) {
232 printk(KERN_ERR "%s: unrecognised EXT_CSD structure "
233 "version %d\n", mmc_hostname(card->host),
234 ext_csd_struct);
235 err = -EINVAL;
236 goto out;
237 }
238 }
239
210 card->ext_csd.rev = ext_csd[EXT_CSD_REV]; 240 card->ext_csd.rev = ext_csd[EXT_CSD_REV];
211 if (card->ext_csd.rev > 5) { 241 if (card->ext_csd.rev > 5) {
212 printk(KERN_ERR "%s: unrecognised EXT_CSD structure " 242 printk(KERN_ERR "%s: unrecognised EXT_CSD revision %d\n",
213 "version %d\n", mmc_hostname(card->host), 243 mmc_hostname(card->host), card->ext_csd.rev);
214 card->ext_csd.rev);
215 err = -EINVAL; 244 err = -EINVAL;
216 goto out; 245 goto out;
217 } 246 }
@@ -222,7 +251,9 @@ static int mmc_read_ext_csd(struct mmc_card *card)
222 ext_csd[EXT_CSD_SEC_CNT + 1] << 8 | 251 ext_csd[EXT_CSD_SEC_CNT + 1] << 8 |
223 ext_csd[EXT_CSD_SEC_CNT + 2] << 16 | 252 ext_csd[EXT_CSD_SEC_CNT + 2] << 16 |
224 ext_csd[EXT_CSD_SEC_CNT + 3] << 24; 253 ext_csd[EXT_CSD_SEC_CNT + 3] << 24;
225 if (card->ext_csd.sectors) 254
255 /* Cards with density > 2GiB are sector addressed */
256 if (card->ext_csd.sectors > (2u * 1024 * 1024 * 1024) / 512)
226 mmc_card_set_blockaddr(card); 257 mmc_card_set_blockaddr(card);
227 } 258 }
228 259
@@ -247,8 +278,30 @@ static int mmc_read_ext_csd(struct mmc_card *card)
247 if (sa_shift > 0 && sa_shift <= 0x17) 278 if (sa_shift > 0 && sa_shift <= 0x17)
248 card->ext_csd.sa_timeout = 279 card->ext_csd.sa_timeout =
249 1 << ext_csd[EXT_CSD_S_A_TIMEOUT]; 280 1 << ext_csd[EXT_CSD_S_A_TIMEOUT];
281 card->ext_csd.erase_group_def =
282 ext_csd[EXT_CSD_ERASE_GROUP_DEF];
283 card->ext_csd.hc_erase_timeout = 300 *
284 ext_csd[EXT_CSD_ERASE_TIMEOUT_MULT];
285 card->ext_csd.hc_erase_size =
286 ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE] << 10;
250 } 287 }
251 288
289 if (card->ext_csd.rev >= 4) {
290 card->ext_csd.sec_trim_mult =
291 ext_csd[EXT_CSD_SEC_TRIM_MULT];
292 card->ext_csd.sec_erase_mult =
293 ext_csd[EXT_CSD_SEC_ERASE_MULT];
294 card->ext_csd.sec_feature_support =
295 ext_csd[EXT_CSD_SEC_FEATURE_SUPPORT];
296 card->ext_csd.trim_timeout = 300 *
297 ext_csd[EXT_CSD_TRIM_MULT];
298 }
299
300 if (ext_csd[EXT_CSD_ERASED_MEM_CONT])
301 card->erased_byte = 0xFF;
302 else
303 card->erased_byte = 0x0;
304
252out: 305out:
253 kfree(ext_csd); 306 kfree(ext_csd);
254 307
@@ -260,6 +313,8 @@ MMC_DEV_ATTR(cid, "%08x%08x%08x%08x\n", card->raw_cid[0], card->raw_cid[1],
260MMC_DEV_ATTR(csd, "%08x%08x%08x%08x\n", card->raw_csd[0], card->raw_csd[1], 313MMC_DEV_ATTR(csd, "%08x%08x%08x%08x\n", card->raw_csd[0], card->raw_csd[1],
261 card->raw_csd[2], card->raw_csd[3]); 314 card->raw_csd[2], card->raw_csd[3]);
262MMC_DEV_ATTR(date, "%02d/%04d\n", card->cid.month, card->cid.year); 315MMC_DEV_ATTR(date, "%02d/%04d\n", card->cid.month, card->cid.year);
316MMC_DEV_ATTR(erase_size, "%u\n", card->erase_size << 9);
317MMC_DEV_ATTR(preferred_erase_size, "%u\n", card->pref_erase << 9);
263MMC_DEV_ATTR(fwrev, "0x%x\n", card->cid.fwrev); 318MMC_DEV_ATTR(fwrev, "0x%x\n", card->cid.fwrev);
264MMC_DEV_ATTR(hwrev, "0x%x\n", card->cid.hwrev); 319MMC_DEV_ATTR(hwrev, "0x%x\n", card->cid.hwrev);
265MMC_DEV_ATTR(manfid, "0x%06x\n", card->cid.manfid); 320MMC_DEV_ATTR(manfid, "0x%06x\n", card->cid.manfid);
@@ -271,6 +326,8 @@ static struct attribute *mmc_std_attrs[] = {
271 &dev_attr_cid.attr, 326 &dev_attr_cid.attr,
272 &dev_attr_csd.attr, 327 &dev_attr_csd.attr,
273 &dev_attr_date.attr, 328 &dev_attr_date.attr,
329 &dev_attr_erase_size.attr,
330 &dev_attr_preferred_erase_size.attr,
274 &dev_attr_fwrev.attr, 331 &dev_attr_fwrev.attr,
275 &dev_attr_hwrev.attr, 332 &dev_attr_hwrev.attr,
276 &dev_attr_manfid.attr, 333 &dev_attr_manfid.attr,
@@ -407,6 +464,8 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
407 err = mmc_read_ext_csd(card); 464 err = mmc_read_ext_csd(card);
408 if (err) 465 if (err)
409 goto free_card; 466 goto free_card;
467 /* Erase size depends on CSD and Extended CSD */
468 mmc_set_erase_size(card);
410 } 469 }
411 470
412 /* 471 /*
diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c
index 5eac21df4809..0f5241085557 100644
--- a/drivers/mmc/core/sd.c
+++ b/drivers/mmc/core/sd.c
@@ -59,7 +59,7 @@ static const unsigned int tacc_mant[] = {
59/* 59/*
60 * Given the decoded CSD structure, decode the raw CID to our CID structure. 60 * Given the decoded CSD structure, decode the raw CID to our CID structure.
61 */ 61 */
62static void mmc_decode_cid(struct mmc_card *card) 62void mmc_decode_cid(struct mmc_card *card)
63{ 63{
64 u32 *resp = card->raw_cid; 64 u32 *resp = card->raw_cid;
65 65
@@ -119,6 +119,13 @@ static int mmc_decode_csd(struct mmc_card *card)
119 csd->r2w_factor = UNSTUFF_BITS(resp, 26, 3); 119 csd->r2w_factor = UNSTUFF_BITS(resp, 26, 3);
120 csd->write_blkbits = UNSTUFF_BITS(resp, 22, 4); 120 csd->write_blkbits = UNSTUFF_BITS(resp, 22, 4);
121 csd->write_partial = UNSTUFF_BITS(resp, 21, 1); 121 csd->write_partial = UNSTUFF_BITS(resp, 21, 1);
122
123 if (UNSTUFF_BITS(resp, 46, 1)) {
124 csd->erase_size = 1;
125 } else if (csd->write_blkbits >= 9) {
126 csd->erase_size = UNSTUFF_BITS(resp, 39, 7) + 1;
127 csd->erase_size <<= csd->write_blkbits - 9;
128 }
122 break; 129 break;
123 case 1: 130 case 1:
124 /* 131 /*
@@ -147,6 +154,7 @@ static int mmc_decode_csd(struct mmc_card *card)
147 csd->r2w_factor = 4; /* Unused */ 154 csd->r2w_factor = 4; /* Unused */
148 csd->write_blkbits = 9; 155 csd->write_blkbits = 9;
149 csd->write_partial = 0; 156 csd->write_partial = 0;
157 csd->erase_size = 1;
150 break; 158 break;
151 default: 159 default:
152 printk(KERN_ERR "%s: unrecognised CSD structure version %d\n", 160 printk(KERN_ERR "%s: unrecognised CSD structure version %d\n",
@@ -154,6 +162,8 @@ static int mmc_decode_csd(struct mmc_card *card)
154 return -EINVAL; 162 return -EINVAL;
155 } 163 }
156 164
165 card->erase_size = csd->erase_size;
166
157 return 0; 167 return 0;
158} 168}
159 169
@@ -179,10 +189,68 @@ static int mmc_decode_scr(struct mmc_card *card)
179 scr->sda_vsn = UNSTUFF_BITS(resp, 56, 4); 189 scr->sda_vsn = UNSTUFF_BITS(resp, 56, 4);
180 scr->bus_widths = UNSTUFF_BITS(resp, 48, 4); 190 scr->bus_widths = UNSTUFF_BITS(resp, 48, 4);
181 191
192 if (UNSTUFF_BITS(resp, 55, 1))
193 card->erased_byte = 0xFF;
194 else
195 card->erased_byte = 0x0;
196
182 return 0; 197 return 0;
183} 198}
184 199
185/* 200/*
201 * Fetch and process SD Status register.
202 */
203static int mmc_read_ssr(struct mmc_card *card)
204{
205 unsigned int au, es, et, eo;
206 int err, i;
207 u32 *ssr;
208
209 if (!(card->csd.cmdclass & CCC_APP_SPEC)) {
210 printk(KERN_WARNING "%s: card lacks mandatory SD Status "
211 "function.\n", mmc_hostname(card->host));
212 return 0;
213 }
214
215 ssr = kmalloc(64, GFP_KERNEL);
216 if (!ssr)
217 return -ENOMEM;
218
219 err = mmc_app_sd_status(card, ssr);
220 if (err) {
221 printk(KERN_WARNING "%s: problem reading SD Status "
222 "register.\n", mmc_hostname(card->host));
223 err = 0;
224 goto out;
225 }
226
227 for (i = 0; i < 16; i++)
228 ssr[i] = be32_to_cpu(ssr[i]);
229
230 /*
231 * UNSTUFF_BITS only works with four u32s so we have to offset the
232 * bitfield positions accordingly.
233 */
234 au = UNSTUFF_BITS(ssr, 428 - 384, 4);
235 if (au > 0 || au <= 9) {
236 card->ssr.au = 1 << (au + 4);
237 es = UNSTUFF_BITS(ssr, 408 - 384, 16);
238 et = UNSTUFF_BITS(ssr, 402 - 384, 6);
239 eo = UNSTUFF_BITS(ssr, 400 - 384, 2);
240 if (es && et) {
241 card->ssr.erase_timeout = (et * 1000) / es;
242 card->ssr.erase_offset = eo * 1000;
243 }
244 } else {
245 printk(KERN_WARNING "%s: SD Status: Invalid Allocation Unit "
246 "size.\n", mmc_hostname(card->host));
247 }
248out:
249 kfree(ssr);
250 return err;
251}
252
253/*
186 * Fetches and decodes switch information 254 * Fetches and decodes switch information
187 */ 255 */
188static int mmc_read_switch(struct mmc_card *card) 256static int mmc_read_switch(struct mmc_card *card)
@@ -238,7 +306,7 @@ out:
238/* 306/*
239 * Test if the card supports high-speed mode and, if so, switch to it. 307 * Test if the card supports high-speed mode and, if so, switch to it.
240 */ 308 */
241static int mmc_switch_hs(struct mmc_card *card) 309int mmc_sd_switch_hs(struct mmc_card *card)
242{ 310{
243 int err; 311 int err;
244 u8 *status; 312 u8 *status;
@@ -272,9 +340,9 @@ static int mmc_switch_hs(struct mmc_card *card)
272 printk(KERN_WARNING "%s: Problem switching card " 340 printk(KERN_WARNING "%s: Problem switching card "
273 "into high-speed mode!\n", 341 "into high-speed mode!\n",
274 mmc_hostname(card->host)); 342 mmc_hostname(card->host));
343 err = 0;
275 } else { 344 } else {
276 mmc_card_set_highspeed(card); 345 err = 1;
277 mmc_set_timing(card->host, MMC_TIMING_SD_HS);
278 } 346 }
279 347
280out: 348out:
@@ -289,6 +357,8 @@ MMC_DEV_ATTR(csd, "%08x%08x%08x%08x\n", card->raw_csd[0], card->raw_csd[1],
289 card->raw_csd[2], card->raw_csd[3]); 357 card->raw_csd[2], card->raw_csd[3]);
290MMC_DEV_ATTR(scr, "%08x%08x\n", card->raw_scr[0], card->raw_scr[1]); 358MMC_DEV_ATTR(scr, "%08x%08x\n", card->raw_scr[0], card->raw_scr[1]);
291MMC_DEV_ATTR(date, "%02d/%04d\n", card->cid.month, card->cid.year); 359MMC_DEV_ATTR(date, "%02d/%04d\n", card->cid.month, card->cid.year);
360MMC_DEV_ATTR(erase_size, "%u\n", card->erase_size << 9);
361MMC_DEV_ATTR(preferred_erase_size, "%u\n", card->pref_erase << 9);
292MMC_DEV_ATTR(fwrev, "0x%x\n", card->cid.fwrev); 362MMC_DEV_ATTR(fwrev, "0x%x\n", card->cid.fwrev);
293MMC_DEV_ATTR(hwrev, "0x%x\n", card->cid.hwrev); 363MMC_DEV_ATTR(hwrev, "0x%x\n", card->cid.hwrev);
294MMC_DEV_ATTR(manfid, "0x%06x\n", card->cid.manfid); 364MMC_DEV_ATTR(manfid, "0x%06x\n", card->cid.manfid);
@@ -302,6 +372,8 @@ static struct attribute *sd_std_attrs[] = {
302 &dev_attr_csd.attr, 372 &dev_attr_csd.attr,
303 &dev_attr_scr.attr, 373 &dev_attr_scr.attr,
304 &dev_attr_date.attr, 374 &dev_attr_date.attr,
375 &dev_attr_erase_size.attr,
376 &dev_attr_preferred_erase_size.attr,
305 &dev_attr_fwrev.attr, 377 &dev_attr_fwrev.attr,
306 &dev_attr_hwrev.attr, 378 &dev_attr_hwrev.attr,
307 &dev_attr_manfid.attr, 379 &dev_attr_manfid.attr,
@@ -320,26 +392,16 @@ static const struct attribute_group *sd_attr_groups[] = {
320 NULL, 392 NULL,
321}; 393};
322 394
323static struct device_type sd_type = { 395struct device_type sd_type = {
324 .groups = sd_attr_groups, 396 .groups = sd_attr_groups,
325}; 397};
326 398
327/* 399/*
328 * Handle the detection and initialisation of a card. 400 * Fetch CID from card.
329 *
330 * In the case of a resume, "oldcard" will contain the card
331 * we're trying to reinitialise.
332 */ 401 */
333static int mmc_sd_init_card(struct mmc_host *host, u32 ocr, 402int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid)
334 struct mmc_card *oldcard)
335{ 403{
336 struct mmc_card *card;
337 int err; 404 int err;
338 u32 cid[4];
339 unsigned int max_dtr;
340
341 BUG_ON(!host);
342 WARN_ON(!host->claimed);
343 405
344 /* 406 /*
345 * Since we're changing the OCR value, we seem to 407 * Since we're changing the OCR value, we seem to
@@ -361,92 +423,67 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
361 423
362 err = mmc_send_app_op_cond(host, ocr, NULL); 424 err = mmc_send_app_op_cond(host, ocr, NULL);
363 if (err) 425 if (err)
364 goto err; 426 return err;
365 427
366 /*
367 * Fetch CID from card.
368 */
369 if (mmc_host_is_spi(host)) 428 if (mmc_host_is_spi(host))
370 err = mmc_send_cid(host, cid); 429 err = mmc_send_cid(host, cid);
371 else 430 else
372 err = mmc_all_send_cid(host, cid); 431 err = mmc_all_send_cid(host, cid);
373 if (err)
374 goto err;
375 432
376 if (oldcard) { 433 return err;
377 if (memcmp(cid, oldcard->raw_cid, sizeof(cid)) != 0) { 434}
378 err = -ENOENT;
379 goto err;
380 }
381
382 card = oldcard;
383 } else {
384 /*
385 * Allocate card structure.
386 */
387 card = mmc_alloc_card(host, &sd_type);
388 if (IS_ERR(card)) {
389 err = PTR_ERR(card);
390 goto err;
391 }
392 435
393 card->type = MMC_TYPE_SD; 436int mmc_sd_get_csd(struct mmc_host *host, struct mmc_card *card)
394 memcpy(card->raw_cid, cid, sizeof(card->raw_cid)); 437{
395 } 438 int err;
396 439
397 /* 440 /*
398 * For native busses: get card RCA and quit open drain mode. 441 * Fetch CSD from card.
399 */ 442 */
400 if (!mmc_host_is_spi(host)) { 443 err = mmc_send_csd(card, card->raw_csd);
401 err = mmc_send_relative_addr(host, &card->rca); 444 if (err)
402 if (err) 445 return err;
403 goto free_card;
404 446
405 mmc_set_bus_mode(host, MMC_BUSMODE_PUSHPULL); 447 err = mmc_decode_csd(card);
406 } 448 if (err)
449 return err;
407 450
408 if (!oldcard) { 451 return 0;
452}
453
454int mmc_sd_setup_card(struct mmc_host *host, struct mmc_card *card,
455 bool reinit)
456{
457 int err;
458
459 if (!reinit) {
409 /* 460 /*
410 * Fetch CSD from card. 461 * Fetch SCR from card.
411 */ 462 */
412 err = mmc_send_csd(card, card->raw_csd); 463 err = mmc_app_send_scr(card, card->raw_scr);
413 if (err)
414 goto free_card;
415
416 err = mmc_decode_csd(card);
417 if (err) 464 if (err)
418 goto free_card; 465 return err;
419
420 mmc_decode_cid(card);
421 }
422 466
423 /* 467 err = mmc_decode_scr(card);
424 * Select card, as all following commands rely on that.
425 */
426 if (!mmc_host_is_spi(host)) {
427 err = mmc_select_card(card);
428 if (err) 468 if (err)
429 goto free_card; 469 return err;
430 }
431 470
432 if (!oldcard) {
433 /* 471 /*
434 * Fetch SCR from card. 472 * Fetch and process SD Status register.
435 */ 473 */
436 err = mmc_app_send_scr(card, card->raw_scr); 474 err = mmc_read_ssr(card);
437 if (err) 475 if (err)
438 goto free_card; 476 return err;
439 477
440 err = mmc_decode_scr(card); 478 /* Erase init depends on CSD and SSR */
441 if (err < 0) 479 mmc_init_erase(card);
442 goto free_card;
443 480
444 /* 481 /*
445 * Fetch switch information from card. 482 * Fetch switch information from card.
446 */ 483 */
447 err = mmc_read_switch(card); 484 err = mmc_read_switch(card);
448 if (err) 485 if (err)
449 goto free_card; 486 return err;
450 } 487 }
451 488
452 /* 489 /*
@@ -458,20 +495,34 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
458 if (mmc_host_is_spi(host)) { 495 if (mmc_host_is_spi(host)) {
459 err = mmc_spi_set_crc(host, use_spi_crc); 496 err = mmc_spi_set_crc(host, use_spi_crc);
460 if (err) 497 if (err)
461 goto free_card; 498 return err;
462 } 499 }
463 500
464 /* 501 /*
465 * Attempt to change to high-speed (if supported) 502 * Check if read-only switch is active.
466 */ 503 */
467 err = mmc_switch_hs(card); 504 if (!reinit) {
468 if (err) 505 int ro = -1;
469 goto free_card;
470 506
471 /* 507 if (host->ops->get_ro)
472 * Compute bus speed. 508 ro = host->ops->get_ro(host);
473 */ 509
474 max_dtr = (unsigned int)-1; 510 if (ro < 0) {
511 printk(KERN_WARNING "%s: host does not "
512 "support reading read-only "
513 "switch. assuming write-enable.\n",
514 mmc_hostname(host));
515 } else if (ro > 0) {
516 mmc_card_set_readonly(card);
517 }
518 }
519
520 return 0;
521}
522
523unsigned mmc_sd_get_max_clock(struct mmc_card *card)
524{
525 unsigned max_dtr = (unsigned int)-1;
475 526
476 if (mmc_card_highspeed(card)) { 527 if (mmc_card_highspeed(card)) {
477 if (max_dtr > card->sw_caps.hs_max_dtr) 528 if (max_dtr > card->sw_caps.hs_max_dtr)
@@ -480,7 +531,97 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
480 max_dtr = card->csd.max_dtr; 531 max_dtr = card->csd.max_dtr;
481 } 532 }
482 533
483 mmc_set_clock(host, max_dtr); 534 return max_dtr;
535}
536
537void mmc_sd_go_highspeed(struct mmc_card *card)
538{
539 mmc_card_set_highspeed(card);
540 mmc_set_timing(card->host, MMC_TIMING_SD_HS);
541}
542
543/*
544 * Handle the detection and initialisation of a card.
545 *
546 * In the case of a resume, "oldcard" will contain the card
547 * we're trying to reinitialise.
548 */
549static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
550 struct mmc_card *oldcard)
551{
552 struct mmc_card *card;
553 int err;
554 u32 cid[4];
555
556 BUG_ON(!host);
557 WARN_ON(!host->claimed);
558
559 err = mmc_sd_get_cid(host, ocr, cid);
560 if (err)
561 return err;
562
563 if (oldcard) {
564 if (memcmp(cid, oldcard->raw_cid, sizeof(cid)) != 0)
565 return -ENOENT;
566
567 card = oldcard;
568 } else {
569 /*
570 * Allocate card structure.
571 */
572 card = mmc_alloc_card(host, &sd_type);
573 if (IS_ERR(card))
574 return PTR_ERR(card);
575
576 card->type = MMC_TYPE_SD;
577 memcpy(card->raw_cid, cid, sizeof(card->raw_cid));
578 }
579
580 /*
581 * For native busses: get card RCA and quit open drain mode.
582 */
583 if (!mmc_host_is_spi(host)) {
584 err = mmc_send_relative_addr(host, &card->rca);
585 if (err)
586 return err;
587
588 mmc_set_bus_mode(host, MMC_BUSMODE_PUSHPULL);
589 }
590
591 if (!oldcard) {
592 err = mmc_sd_get_csd(host, card);
593 if (err)
594 return err;
595
596 mmc_decode_cid(card);
597 }
598
599 /*
600 * Select card, as all following commands rely on that.
601 */
602 if (!mmc_host_is_spi(host)) {
603 err = mmc_select_card(card);
604 if (err)
605 return err;
606 }
607
608 err = mmc_sd_setup_card(host, card, oldcard != NULL);
609 if (err)
610 goto free_card;
611
612 /*
613 * Attempt to change to high-speed (if supported)
614 */
615 err = mmc_sd_switch_hs(card);
616 if (err > 0)
617 mmc_sd_go_highspeed(card);
618 else if (err)
619 goto free_card;
620
621 /*
622 * Set bus speed.
623 */
624 mmc_set_clock(host, mmc_sd_get_max_clock(card));
484 625
485 /* 626 /*
486 * Switch to wider bus (if supported). 627 * Switch to wider bus (if supported).
@@ -494,30 +635,12 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
494 mmc_set_bus_width(host, MMC_BUS_WIDTH_4); 635 mmc_set_bus_width(host, MMC_BUS_WIDTH_4);
495 } 636 }
496 637
497 /* 638 host->card = card;
498 * Check if read-only switch is active.
499 */
500 if (!oldcard) {
501 if (!host->ops->get_ro || host->ops->get_ro(host) < 0) {
502 printk(KERN_WARNING "%s: host does not "
503 "support reading read-only "
504 "switch. assuming write-enable.\n",
505 mmc_hostname(host));
506 } else {
507 if (host->ops->get_ro(host) > 0)
508 mmc_card_set_readonly(card);
509 }
510 }
511
512 if (!oldcard)
513 host->card = card;
514
515 return 0; 639 return 0;
516 640
517free_card: 641free_card:
518 if (!oldcard) 642 if (!oldcard)
519 mmc_remove_card(card); 643 mmc_remove_card(card);
520err:
521 644
522 return err; 645 return err;
523} 646}
diff --git a/drivers/mmc/core/sd.h b/drivers/mmc/core/sd.h
new file mode 100644
index 000000000000..3d8800fa7600
--- /dev/null
+++ b/drivers/mmc/core/sd.h
@@ -0,0 +1,17 @@
1#ifndef _MMC_CORE_SD_H
2#define _MMC_CORE_SD_H
3
4#include <linux/mmc/card.h>
5
6extern struct device_type sd_type;
7
8int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid);
9int mmc_sd_get_csd(struct mmc_host *host, struct mmc_card *card);
10void mmc_decode_cid(struct mmc_card *card);
11int mmc_sd_setup_card(struct mmc_host *host, struct mmc_card *card,
12 bool reinit);
13unsigned mmc_sd_get_max_clock(struct mmc_card *card);
14int mmc_sd_switch_hs(struct mmc_card *card);
15void mmc_sd_go_highspeed(struct mmc_card *card);
16
17#endif
diff --git a/drivers/mmc/core/sd_ops.c b/drivers/mmc/core/sd_ops.c
index 63772e7e7608..797cdb5887fd 100644
--- a/drivers/mmc/core/sd_ops.c
+++ b/drivers/mmc/core/sd_ops.c
@@ -346,3 +346,51 @@ int mmc_sd_switch(struct mmc_card *card, int mode, int group,
346 return 0; 346 return 0;
347} 347}
348 348
349int mmc_app_sd_status(struct mmc_card *card, void *ssr)
350{
351 int err;
352 struct mmc_request mrq;
353 struct mmc_command cmd;
354 struct mmc_data data;
355 struct scatterlist sg;
356
357 BUG_ON(!card);
358 BUG_ON(!card->host);
359 BUG_ON(!ssr);
360
361 /* NOTE: caller guarantees ssr is heap-allocated */
362
363 err = mmc_app_cmd(card->host, card);
364 if (err)
365 return err;
366
367 memset(&mrq, 0, sizeof(struct mmc_request));
368 memset(&cmd, 0, sizeof(struct mmc_command));
369 memset(&data, 0, sizeof(struct mmc_data));
370
371 mrq.cmd = &cmd;
372 mrq.data = &data;
373
374 cmd.opcode = SD_APP_SD_STATUS;
375 cmd.arg = 0;
376 cmd.flags = MMC_RSP_SPI_R2 | MMC_RSP_R1 | MMC_CMD_ADTC;
377
378 data.blksz = 64;
379 data.blocks = 1;
380 data.flags = MMC_DATA_READ;
381 data.sg = &sg;
382 data.sg_len = 1;
383
384 sg_init_one(&sg, ssr, 64);
385
386 mmc_set_data_timeout(&data, card);
387
388 mmc_wait_for_req(card->host, &mrq);
389
390 if (cmd.error)
391 return cmd.error;
392 if (data.error)
393 return data.error;
394
395 return 0;
396}
diff --git a/drivers/mmc/core/sd_ops.h b/drivers/mmc/core/sd_ops.h
index 9742d8a30664..ffc2305d905f 100644
--- a/drivers/mmc/core/sd_ops.h
+++ b/drivers/mmc/core/sd_ops.h
@@ -19,6 +19,7 @@ int mmc_send_relative_addr(struct mmc_host *host, unsigned int *rca);
19int mmc_app_send_scr(struct mmc_card *card, u32 *scr); 19int mmc_app_send_scr(struct mmc_card *card, u32 *scr);
20int mmc_sd_switch(struct mmc_card *card, int mode, int group, 20int mmc_sd_switch(struct mmc_card *card, int mode, int group,
21 u8 value, u8 *resp); 21 u8 value, u8 *resp);
22int mmc_app_sd_status(struct mmc_card *card, void *ssr);
22 23
23#endif 24#endif
24 25
diff --git a/drivers/mmc/core/sdio.c b/drivers/mmc/core/sdio.c
index b9dee28ee7d0..bd2755e8d9a3 100644
--- a/drivers/mmc/core/sdio.c
+++ b/drivers/mmc/core/sdio.c
@@ -18,6 +18,7 @@
18 18
19#include "core.h" 19#include "core.h"
20#include "bus.h" 20#include "bus.h"
21#include "sd.h"
21#include "sdio_bus.h" 22#include "sdio_bus.h"
22#include "mmc_ops.h" 23#include "mmc_ops.h"
23#include "sd_ops.h" 24#include "sd_ops.h"
@@ -62,13 +63,19 @@ static int sdio_init_func(struct mmc_card *card, unsigned int fn)
62 63
63 func->num = fn; 64 func->num = fn;
64 65
65 ret = sdio_read_fbr(func); 66 if (!(card->quirks & MMC_QUIRK_NONSTD_SDIO)) {
66 if (ret) 67 ret = sdio_read_fbr(func);
67 goto fail; 68 if (ret)
69 goto fail;
68 70
69 ret = sdio_read_func_cis(func); 71 ret = sdio_read_func_cis(func);
70 if (ret) 72 if (ret)
71 goto fail; 73 goto fail;
74 } else {
75 func->vendor = func->card->cis.vendor;
76 func->device = func->card->cis.device;
77 func->max_blksize = func->card->cis.blksize;
78 }
72 79
73 card->sdio_func[fn - 1] = func; 80 card->sdio_func[fn - 1] = func;
74 81
@@ -159,9 +166,7 @@ static int sdio_enable_wide(struct mmc_card *card)
159 if (ret) 166 if (ret)
160 return ret; 167 return ret;
161 168
162 mmc_set_bus_width(card->host, MMC_BUS_WIDTH_4); 169 return 1;
163
164 return 0;
165} 170}
166 171
167/* 172/*
@@ -221,10 +226,34 @@ static int sdio_disable_wide(struct mmc_card *card)
221 return 0; 226 return 0;
222} 227}
223 228
229
230static int sdio_enable_4bit_bus(struct mmc_card *card)
231{
232 int err;
233
234 if (card->type == MMC_TYPE_SDIO)
235 return sdio_enable_wide(card);
236
237 if ((card->host->caps & MMC_CAP_4_BIT_DATA) &&
238 (card->scr.bus_widths & SD_SCR_BUS_WIDTH_4)) {
239 err = mmc_app_set_bus_width(card, MMC_BUS_WIDTH_4);
240 if (err)
241 return err;
242 } else
243 return 0;
244
245 err = sdio_enable_wide(card);
246 if (err <= 0)
247 mmc_app_set_bus_width(card, MMC_BUS_WIDTH_1);
248
249 return err;
250}
251
252
224/* 253/*
225 * Test if the card supports high-speed mode and, if so, switch to it. 254 * Test if the card supports high-speed mode and, if so, switch to it.
226 */ 255 */
227static int sdio_enable_hs(struct mmc_card *card) 256static int mmc_sdio_switch_hs(struct mmc_card *card, int enable)
228{ 257{
229 int ret; 258 int ret;
230 u8 speed; 259 u8 speed;
@@ -239,16 +268,56 @@ static int sdio_enable_hs(struct mmc_card *card)
239 if (ret) 268 if (ret)
240 return ret; 269 return ret;
241 270
242 speed |= SDIO_SPEED_EHS; 271 if (enable)
272 speed |= SDIO_SPEED_EHS;
273 else
274 speed &= ~SDIO_SPEED_EHS;
243 275
244 ret = mmc_io_rw_direct(card, 1, 0, SDIO_CCCR_SPEED, speed, NULL); 276 ret = mmc_io_rw_direct(card, 1, 0, SDIO_CCCR_SPEED, speed, NULL);
245 if (ret) 277 if (ret)
246 return ret; 278 return ret;
247 279
248 mmc_card_set_highspeed(card); 280 return 1;
249 mmc_set_timing(card->host, MMC_TIMING_SD_HS); 281}
250 282
251 return 0; 283/*
284 * Enable SDIO/combo card's high-speed mode. Return 0/1 if [not]supported.
285 */
286static int sdio_enable_hs(struct mmc_card *card)
287{
288 int ret;
289
290 ret = mmc_sdio_switch_hs(card, true);
291 if (ret <= 0 || card->type == MMC_TYPE_SDIO)
292 return ret;
293
294 ret = mmc_sd_switch_hs(card);
295 if (ret <= 0)
296 mmc_sdio_switch_hs(card, false);
297
298 return ret;
299}
300
301static unsigned mmc_sdio_get_max_clock(struct mmc_card *card)
302{
303 unsigned max_dtr;
304
305 if (mmc_card_highspeed(card)) {
306 /*
307 * The SDIO specification doesn't mention how
308 * the CIS transfer speed register relates to
309 * high-speed, but it seems that 50 MHz is
310 * mandatory.
311 */
312 max_dtr = 50000000;
313 } else {
314 max_dtr = card->cis.max_dtr;
315 }
316
317 if (card->type == MMC_TYPE_SD_COMBO)
318 max_dtr = min(max_dtr, mmc_sd_get_max_clock(card));
319
320 return max_dtr;
252} 321}
253 322
254/* 323/*
@@ -293,7 +362,24 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr,
293 goto err; 362 goto err;
294 } 363 }
295 364
296 card->type = MMC_TYPE_SDIO; 365 err = mmc_sd_get_cid(host, host->ocr & ocr, card->raw_cid);
366
367 if (!err) {
368 card->type = MMC_TYPE_SD_COMBO;
369
370 if (oldcard && (oldcard->type != MMC_TYPE_SD_COMBO ||
371 memcmp(card->raw_cid, oldcard->raw_cid, sizeof(card->raw_cid)) != 0)) {
372 mmc_remove_card(card);
373 return -ENOENT;
374 }
375 } else {
376 card->type = MMC_TYPE_SDIO;
377
378 if (oldcard && oldcard->type != MMC_TYPE_SDIO) {
379 mmc_remove_card(card);
380 return -ENOENT;
381 }
382 }
297 383
298 /* 384 /*
299 * Call the optional HC's init_card function to handle quirks. 385 * Call the optional HC's init_card function to handle quirks.
@@ -313,6 +399,17 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr,
313 } 399 }
314 400
315 /* 401 /*
402 * Read CSD, before selecting the card
403 */
404 if (!oldcard && card->type == MMC_TYPE_SD_COMBO) {
405 err = mmc_sd_get_csd(host, card);
406 if (err)
407 return err;
408
409 mmc_decode_cid(card);
410 }
411
412 /*
316 * Select card, as all following commands rely on that. 413 * Select card, as all following commands rely on that.
317 */ 414 */
318 if (!powered_resume && !mmc_host_is_spi(host)) { 415 if (!powered_resume && !mmc_host_is_spi(host)) {
@@ -321,6 +418,23 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr,
321 goto remove; 418 goto remove;
322 } 419 }
323 420
421 if (card->quirks & MMC_QUIRK_NONSTD_SDIO) {
422 /*
423 * This is non-standard SDIO device, meaning it doesn't
424 * have any CIA (Common I/O area) registers present.
425 * It's host's responsibility to fill cccr and cis
426 * structures in init_card().
427 */
428 mmc_set_clock(host, card->cis.max_dtr);
429
430 if (card->cccr.high_speed) {
431 mmc_card_set_highspeed(card);
432 mmc_set_timing(card->host, MMC_TIMING_SD_HS);
433 }
434
435 goto finish;
436 }
437
324 /* 438 /*
325 * Read the common registers. 439 * Read the common registers.
326 */ 440 */
@@ -339,43 +453,57 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr,
339 int same = (card->cis.vendor == oldcard->cis.vendor && 453 int same = (card->cis.vendor == oldcard->cis.vendor &&
340 card->cis.device == oldcard->cis.device); 454 card->cis.device == oldcard->cis.device);
341 mmc_remove_card(card); 455 mmc_remove_card(card);
342 if (!same) { 456 if (!same)
343 err = -ENOENT; 457 return -ENOENT;
344 goto err; 458
345 }
346 card = oldcard; 459 card = oldcard;
347 return 0; 460 return 0;
348 } 461 }
349 462
463 if (card->type == MMC_TYPE_SD_COMBO) {
464 err = mmc_sd_setup_card(host, card, oldcard != NULL);
465 /* handle as SDIO-only card if memory init failed */
466 if (err) {
467 mmc_go_idle(host);
468 if (mmc_host_is_spi(host))
469 /* should not fail, as it worked previously */
470 mmc_spi_set_crc(host, use_spi_crc);
471 card->type = MMC_TYPE_SDIO;
472 } else
473 card->dev.type = &sd_type;
474 }
475
476 /*
477 * If needed, disconnect card detection pull-up resistor.
478 */
479 err = sdio_disable_cd(card);
480 if (err)
481 goto remove;
482
350 /* 483 /*
351 * Switch to high-speed (if supported). 484 * Switch to high-speed (if supported).
352 */ 485 */
353 err = sdio_enable_hs(card); 486 err = sdio_enable_hs(card);
354 if (err) 487 if (err > 0)
488 mmc_sd_go_highspeed(card);
489 else if (err)
355 goto remove; 490 goto remove;
356 491
357 /* 492 /*
358 * Change to the card's maximum speed. 493 * Change to the card's maximum speed.
359 */ 494 */
360 if (mmc_card_highspeed(card)) { 495 mmc_set_clock(host, mmc_sdio_get_max_clock(card));
361 /*
362 * The SDIO specification doesn't mention how
363 * the CIS transfer speed register relates to
364 * high-speed, but it seems that 50 MHz is
365 * mandatory.
366 */
367 mmc_set_clock(host, 50000000);
368 } else {
369 mmc_set_clock(host, card->cis.max_dtr);
370 }
371 496
372 /* 497 /*
373 * Switch to wider bus (if supported). 498 * Switch to wider bus (if supported).
374 */ 499 */
375 err = sdio_enable_wide(card); 500 err = sdio_enable_4bit_bus(card);
376 if (err) 501 if (err > 0)
502 mmc_set_bus_width(card->host, MMC_BUS_WIDTH_4);
503 else if (err)
377 goto remove; 504 goto remove;
378 505
506finish:
379 if (!oldcard) 507 if (!oldcard)
380 host->card = card; 508 host->card = card;
381 return 0; 509 return 0;
@@ -487,9 +615,14 @@ static int mmc_sdio_resume(struct mmc_host *host)
487 mmc_claim_host(host); 615 mmc_claim_host(host);
488 err = mmc_sdio_init_card(host, host->ocr, host->card, 616 err = mmc_sdio_init_card(host, host->ocr, host->card,
489 (host->pm_flags & MMC_PM_KEEP_POWER)); 617 (host->pm_flags & MMC_PM_KEEP_POWER));
490 if (!err) 618 if (!err) {
491 /* We may have switched to 1-bit mode during suspend. */ 619 /* We may have switched to 1-bit mode during suspend. */
492 err = sdio_enable_wide(host->card); 620 err = sdio_enable_4bit_bus(host->card);
621 if (err > 0) {
622 mmc_set_bus_width(host, MMC_BUS_WIDTH_4);
623 err = 0;
624 }
625 }
493 if (!err && host->sdio_irqs) 626 if (!err && host->sdio_irqs)
494 mmc_signal_sdio_irq(host); 627 mmc_signal_sdio_irq(host);
495 mmc_release_host(host); 628 mmc_release_host(host);
@@ -574,13 +707,6 @@ int mmc_attach_sdio(struct mmc_host *host, u32 ocr)
574 card->sdio_funcs = 0; 707 card->sdio_funcs = 0;
575 708
576 /* 709 /*
577 * If needed, disconnect card detection pull-up resistor.
578 */
579 err = sdio_disable_cd(card);
580 if (err)
581 goto remove;
582
583 /*
584 * Initialize (but don't add) all present functions. 710 * Initialize (but don't add) all present functions.
585 */ 711 */
586 for (i = 0; i < funcs; i++, card->sdio_funcs++) { 712 for (i = 0; i < funcs; i++, card->sdio_funcs++) {
diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig
index d25e22cee4c4..283190bc2a40 100644
--- a/drivers/mmc/host/Kconfig
+++ b/drivers/mmc/host/Kconfig
@@ -121,6 +121,15 @@ config MMC_SDHCI_PLTFM
121 121
122 If unsure, say N. 122 If unsure, say N.
123 123
124config MMC_SDHCI_CNS3XXX
125 bool "SDHCI support on the Cavium Networks CNS3xxx SoC"
126 depends on ARCH_CNS3XXX
127 depends on MMC_SDHCI_PLTFM
128 help
129 This selects the SDHCI support for CNS3xxx System-on-Chip devices.
130
131 If unsure, say N.
132
124config MMC_SDHCI_S3C 133config MMC_SDHCI_S3C
125 tristate "SDHCI support on Samsung S3C SoC" 134 tristate "SDHCI support on Samsung S3C SoC"
126 depends on MMC_SDHCI && (PLAT_S3C24XX || PLAT_S3C64XX) 135 depends on MMC_SDHCI && (PLAT_S3C24XX || PLAT_S3C64XX)
@@ -247,12 +256,13 @@ config MMC_IMX
247 256
248 If unsure, say N. 257 If unsure, say N.
249 258
250config MMC_MSM7X00A 259config MMC_MSM
251 tristate "Qualcomm MSM 7X00A SDCC Controller Support" 260 tristate "Qualcomm SDCC Controller Support"
252 depends on MMC && ARCH_MSM && !ARCH_MSM7X30 261 depends on MMC && ARCH_MSM
253 help 262 help
254 This provides support for the SD/MMC cell found in the 263 This provides support for the SD/MMC cell found in the
255 MSM 7X00A controllers from Qualcomm. 264 MSM and QSD SOCs from Qualcomm. The controller also has
265 support for SDIO devices.
256 266
257config MMC_MXC 267config MMC_MXC
258 tristate "Freescale i.MX2/3 Multimedia Card Interface support" 268 tristate "Freescale i.MX2/3 Multimedia Card Interface support"
diff --git a/drivers/mmc/host/Makefile b/drivers/mmc/host/Makefile
index f4e53c98d944..840bcb52d82f 100644
--- a/drivers/mmc/host/Makefile
+++ b/drivers/mmc/host/Makefile
@@ -12,7 +12,6 @@ obj-$(CONFIG_MMC_IMX) += imxmmc.o
12obj-$(CONFIG_MMC_MXC) += mxcmmc.o 12obj-$(CONFIG_MMC_MXC) += mxcmmc.o
13obj-$(CONFIG_MMC_SDHCI) += sdhci.o 13obj-$(CONFIG_MMC_SDHCI) += sdhci.o
14obj-$(CONFIG_MMC_SDHCI_PCI) += sdhci-pci.o 14obj-$(CONFIG_MMC_SDHCI_PCI) += sdhci-pci.o
15obj-$(CONFIG_MMC_SDHCI_PLTFM) += sdhci-pltfm.o
16obj-$(CONFIG_MMC_SDHCI_S3C) += sdhci-s3c.o 15obj-$(CONFIG_MMC_SDHCI_S3C) += sdhci-s3c.o
17obj-$(CONFIG_MMC_SDHCI_SPEAR) += sdhci-spear.o 16obj-$(CONFIG_MMC_SDHCI_SPEAR) += sdhci-spear.o
18obj-$(CONFIG_MMC_WBSD) += wbsd.o 17obj-$(CONFIG_MMC_WBSD) += wbsd.o
@@ -22,7 +21,7 @@ obj-$(CONFIG_MMC_OMAP_HS) += omap_hsmmc.o
22obj-$(CONFIG_MMC_AT91) += at91_mci.o 21obj-$(CONFIG_MMC_AT91) += at91_mci.o
23obj-$(CONFIG_MMC_ATMELMCI) += atmel-mci.o 22obj-$(CONFIG_MMC_ATMELMCI) += atmel-mci.o
24obj-$(CONFIG_MMC_TIFM_SD) += tifm_sd.o 23obj-$(CONFIG_MMC_TIFM_SD) += tifm_sd.o
25obj-$(CONFIG_MMC_MSM7X00A) += msm_sdcc.o 24obj-$(CONFIG_MMC_MSM) += msm_sdcc.o
26obj-$(CONFIG_MMC_MVSDIO) += mvsdio.o 25obj-$(CONFIG_MMC_MVSDIO) += mvsdio.o
27obj-$(CONFIG_MMC_DAVINCI) += davinci_mmc.o 26obj-$(CONFIG_MMC_DAVINCI) += davinci_mmc.o
28obj-$(CONFIG_MMC_SPI) += mmc_spi.o 27obj-$(CONFIG_MMC_SPI) += mmc_spi.o
@@ -38,6 +37,10 @@ obj-$(CONFIG_SDH_BFIN) += bfin_sdh.o
38obj-$(CONFIG_MMC_SH_MMCIF) += sh_mmcif.o 37obj-$(CONFIG_MMC_SH_MMCIF) += sh_mmcif.o
39obj-$(CONFIG_MMC_JZ4740) += jz4740_mmc.o 38obj-$(CONFIG_MMC_JZ4740) += jz4740_mmc.o
40 39
40obj-$(CONFIG_MMC_SDHCI_PLTFM) += sdhci-platform.o
41sdhci-platform-y := sdhci-pltfm.o
42sdhci-platform-$(CONFIG_MMC_SDHCI_CNS3XXX) += sdhci-cns3xxx.o
43
41obj-$(CONFIG_MMC_SDHCI_OF) += sdhci-of.o 44obj-$(CONFIG_MMC_SDHCI_OF) += sdhci-of.o
42sdhci-of-y := sdhci-of-core.o 45sdhci-of-y := sdhci-of-core.o
43sdhci-of-$(CONFIG_MMC_SDHCI_OF_ESDHC) += sdhci-of-esdhc.o 46sdhci-of-$(CONFIG_MMC_SDHCI_OF_ESDHC) += sdhci-of-esdhc.o
diff --git a/drivers/mmc/host/mmc_spi.c b/drivers/mmc/host/mmc_spi.c
index 7b0f3ef50f96..62a35822003e 100644
--- a/drivers/mmc/host/mmc_spi.c
+++ b/drivers/mmc/host/mmc_spi.c
@@ -182,7 +182,7 @@ mmc_spi_readbytes(struct mmc_spi_host *host, unsigned len)
182 host->data_dma, sizeof(*host->data), 182 host->data_dma, sizeof(*host->data),
183 DMA_FROM_DEVICE); 183 DMA_FROM_DEVICE);
184 184
185 status = spi_sync(host->spi, &host->readback); 185 status = spi_sync_locked(host->spi, &host->readback);
186 186
187 if (host->dma_dev) 187 if (host->dma_dev)
188 dma_sync_single_for_cpu(host->dma_dev, 188 dma_sync_single_for_cpu(host->dma_dev,
@@ -541,7 +541,7 @@ mmc_spi_command_send(struct mmc_spi_host *host,
541 host->data_dma, sizeof(*host->data), 541 host->data_dma, sizeof(*host->data),
542 DMA_BIDIRECTIONAL); 542 DMA_BIDIRECTIONAL);
543 } 543 }
544 status = spi_sync(host->spi, &host->m); 544 status = spi_sync_locked(host->spi, &host->m);
545 545
546 if (host->dma_dev) 546 if (host->dma_dev)
547 dma_sync_single_for_cpu(host->dma_dev, 547 dma_sync_single_for_cpu(host->dma_dev,
@@ -685,7 +685,7 @@ mmc_spi_writeblock(struct mmc_spi_host *host, struct spi_transfer *t,
685 host->data_dma, sizeof(*scratch), 685 host->data_dma, sizeof(*scratch),
686 DMA_BIDIRECTIONAL); 686 DMA_BIDIRECTIONAL);
687 687
688 status = spi_sync(spi, &host->m); 688 status = spi_sync_locked(spi, &host->m);
689 689
690 if (status != 0) { 690 if (status != 0) {
691 dev_dbg(&spi->dev, "write error (%d)\n", status); 691 dev_dbg(&spi->dev, "write error (%d)\n", status);
@@ -822,7 +822,7 @@ mmc_spi_readblock(struct mmc_spi_host *host, struct spi_transfer *t,
822 DMA_FROM_DEVICE); 822 DMA_FROM_DEVICE);
823 } 823 }
824 824
825 status = spi_sync(spi, &host->m); 825 status = spi_sync_locked(spi, &host->m);
826 826
827 if (host->dma_dev) { 827 if (host->dma_dev) {
828 dma_sync_single_for_cpu(host->dma_dev, 828 dma_sync_single_for_cpu(host->dma_dev,
@@ -1018,7 +1018,7 @@ mmc_spi_data_do(struct mmc_spi_host *host, struct mmc_command *cmd,
1018 host->data_dma, sizeof(*scratch), 1018 host->data_dma, sizeof(*scratch),
1019 DMA_BIDIRECTIONAL); 1019 DMA_BIDIRECTIONAL);
1020 1020
1021 tmp = spi_sync(spi, &host->m); 1021 tmp = spi_sync_locked(spi, &host->m);
1022 1022
1023 if (host->dma_dev) 1023 if (host->dma_dev)
1024 dma_sync_single_for_cpu(host->dma_dev, 1024 dma_sync_single_for_cpu(host->dma_dev,
@@ -1084,6 +1084,9 @@ static void mmc_spi_request(struct mmc_host *mmc, struct mmc_request *mrq)
1084 } 1084 }
1085#endif 1085#endif
1086 1086
1087 /* request exclusive bus access */
1088 spi_bus_lock(host->spi->master);
1089
1087 /* issue command; then optionally data and stop */ 1090 /* issue command; then optionally data and stop */
1088 status = mmc_spi_command_send(host, mrq, mrq->cmd, mrq->data != NULL); 1091 status = mmc_spi_command_send(host, mrq, mrq->cmd, mrq->data != NULL);
1089 if (status == 0 && mrq->data) { 1092 if (status == 0 && mrq->data) {
@@ -1094,6 +1097,9 @@ static void mmc_spi_request(struct mmc_host *mmc, struct mmc_request *mrq)
1094 mmc_cs_off(host); 1097 mmc_cs_off(host);
1095 } 1098 }
1096 1099
1100 /* release the bus */
1101 spi_bus_unlock(host->spi->master);
1102
1097 mmc_request_done(host->mmc, mrq); 1103 mmc_request_done(host->mmc, mrq);
1098} 1104}
1099 1105
@@ -1290,23 +1296,6 @@ mmc_spi_detect_irq(int irq, void *mmc)
1290 return IRQ_HANDLED; 1296 return IRQ_HANDLED;
1291} 1297}
1292 1298
1293struct count_children {
1294 unsigned n;
1295 struct bus_type *bus;
1296};
1297
1298static int maybe_count_child(struct device *dev, void *c)
1299{
1300 struct count_children *ccp = c;
1301
1302 if (dev->bus == ccp->bus) {
1303 if (ccp->n)
1304 return -EBUSY;
1305 ccp->n++;
1306 }
1307 return 0;
1308}
1309
1310static int mmc_spi_probe(struct spi_device *spi) 1299static int mmc_spi_probe(struct spi_device *spi)
1311{ 1300{
1312 void *ones; 1301 void *ones;
@@ -1338,32 +1327,6 @@ static int mmc_spi_probe(struct spi_device *spi)
1338 return status; 1327 return status;
1339 } 1328 }
1340 1329
1341 /* We can use the bus safely iff nobody else will interfere with us.
1342 * Most commands consist of one SPI message to issue a command, then
1343 * several more to collect its response, then possibly more for data
1344 * transfer. Clocking access to other devices during that period will
1345 * corrupt the command execution.
1346 *
1347 * Until we have software primitives which guarantee non-interference,
1348 * we'll aim for a hardware-level guarantee.
1349 *
1350 * REVISIT we can't guarantee another device won't be added later...
1351 */
1352 if (spi->master->num_chipselect > 1) {
1353 struct count_children cc;
1354
1355 cc.n = 0;
1356 cc.bus = spi->dev.bus;
1357 status = device_for_each_child(spi->dev.parent, &cc,
1358 maybe_count_child);
1359 if (status < 0) {
1360 dev_err(&spi->dev, "can't share SPI bus\n");
1361 return status;
1362 }
1363
1364 dev_warn(&spi->dev, "ASSUMING SPI bus stays unshared!\n");
1365 }
1366
1367 /* We need a supply of ones to transmit. This is the only time 1330 /* We need a supply of ones to transmit. This is the only time
1368 * the CPU touches these, so cache coherency isn't a concern. 1331 * the CPU touches these, so cache coherency isn't a concern.
1369 * 1332 *
@@ -1536,6 +1499,7 @@ static int __devexit mmc_spi_remove(struct spi_device *spi)
1536#if defined(CONFIG_OF) 1499#if defined(CONFIG_OF)
1537static struct of_device_id mmc_spi_of_match_table[] __devinitdata = { 1500static struct of_device_id mmc_spi_of_match_table[] __devinitdata = {
1538 { .compatible = "mmc-spi-slot", }, 1501 { .compatible = "mmc-spi-slot", },
1502 {},
1539}; 1503};
1540#endif 1504#endif
1541 1505
diff --git a/drivers/mmc/host/msm_sdcc.c b/drivers/mmc/host/msm_sdcc.c
index 24e09454e522..ff7752348b11 100644
--- a/drivers/mmc/host/msm_sdcc.c
+++ b/drivers/mmc/host/msm_sdcc.c
@@ -160,18 +160,7 @@ msmsdcc_stop_data(struct msmsdcc_host *host)
160 160
161uint32_t msmsdcc_fifo_addr(struct msmsdcc_host *host) 161uint32_t msmsdcc_fifo_addr(struct msmsdcc_host *host)
162{ 162{
163 switch (host->pdev_id) { 163 return host->memres->start + MMCIFIFO;
164 case 1:
165 return MSM_SDC1_PHYS + MMCIFIFO;
166 case 2:
167 return MSM_SDC2_PHYS + MMCIFIFO;
168 case 3:
169 return MSM_SDC3_PHYS + MMCIFIFO;
170 case 4:
171 return MSM_SDC4_PHYS + MMCIFIFO;
172 }
173 BUG();
174 return 0;
175} 164}
176 165
177static inline void 166static inline void
@@ -1057,26 +1046,10 @@ msmsdcc_init_dma(struct msmsdcc_host *host)
1057 return 0; 1046 return 0;
1058} 1047}
1059 1048
1060#ifdef CONFIG_MMC_MSM7X00A_RESUME_IN_WQ
1061static void
1062do_resume_work(struct work_struct *work)
1063{
1064 struct msmsdcc_host *host =
1065 container_of(work, struct msmsdcc_host, resume_task);
1066 struct mmc_host *mmc = host->mmc;
1067
1068 if (mmc) {
1069 mmc_resume_host(mmc);
1070 if (host->stat_irq)
1071 enable_irq(host->stat_irq);
1072 }
1073}
1074#endif
1075
1076static int 1049static int
1077msmsdcc_probe(struct platform_device *pdev) 1050msmsdcc_probe(struct platform_device *pdev)
1078{ 1051{
1079 struct mmc_platform_data *plat = pdev->dev.platform_data; 1052 struct msm_mmc_platform_data *plat = pdev->dev.platform_data;
1080 struct msmsdcc_host *host; 1053 struct msmsdcc_host *host;
1081 struct mmc_host *mmc; 1054 struct mmc_host *mmc;
1082 struct resource *cmd_irqres = NULL; 1055 struct resource *cmd_irqres = NULL;
@@ -1145,15 +1118,6 @@ msmsdcc_probe(struct platform_device *pdev)
1145 host->dmares = dmares; 1118 host->dmares = dmares;
1146 spin_lock_init(&host->lock); 1119 spin_lock_init(&host->lock);
1147 1120
1148#ifdef CONFIG_MMC_EMBEDDED_SDIO
1149 if (plat->embedded_sdio)
1150 mmc_set_embedded_sdio_data(mmc,
1151 &plat->embedded_sdio->cis,
1152 &plat->embedded_sdio->cccr,
1153 plat->embedded_sdio->funcs,
1154 plat->embedded_sdio->num_funcs);
1155#endif
1156
1157 /* 1121 /*
1158 * Setup DMA 1122 * Setup DMA
1159 */ 1123 */
@@ -1314,6 +1278,24 @@ msmsdcc_probe(struct platform_device *pdev)
1314 return ret; 1278 return ret;
1315} 1279}
1316 1280
1281#ifdef CONFIG_PM
1282#ifdef CONFIG_MMC_MSM7X00A_RESUME_IN_WQ
1283static void
1284do_resume_work(struct work_struct *work)
1285{
1286 struct msmsdcc_host *host =
1287 container_of(work, struct msmsdcc_host, resume_task);
1288 struct mmc_host *mmc = host->mmc;
1289
1290 if (mmc) {
1291 mmc_resume_host(mmc);
1292 if (host->stat_irq)
1293 enable_irq(host->stat_irq);
1294 }
1295}
1296#endif
1297
1298
1317static int 1299static int
1318msmsdcc_suspend(struct platform_device *dev, pm_message_t state) 1300msmsdcc_suspend(struct platform_device *dev, pm_message_t state)
1319{ 1301{
@@ -1358,6 +1340,10 @@ msmsdcc_resume(struct platform_device *dev)
1358 } 1340 }
1359 return 0; 1341 return 0;
1360} 1342}
1343#else
1344#define msmsdcc_suspend 0
1345#define msmsdcc_resume 0
1346#endif
1361 1347
1362static struct platform_driver msmsdcc_driver = { 1348static struct platform_driver msmsdcc_driver = {
1363 .probe = msmsdcc_probe, 1349 .probe = msmsdcc_probe,
diff --git a/drivers/mmc/host/msm_sdcc.h b/drivers/mmc/host/msm_sdcc.h
index da0039c9285e..ff2b0f74f6f4 100644
--- a/drivers/mmc/host/msm_sdcc.h
+++ b/drivers/mmc/host/msm_sdcc.h
@@ -225,7 +225,7 @@ struct msmsdcc_host {
225 225
226 u32 pwr; 226 u32 pwr;
227 u32 saved_irq0mask; /* MMCIMASK0 reg value */ 227 u32 saved_irq0mask; /* MMCIMASK0 reg value */
228 struct mmc_platform_data *plat; 228 struct msm_mmc_platform_data *plat;
229 229
230 struct timer_list timer; 230 struct timer_list timer;
231 unsigned int oldstat; 231 unsigned int oldstat;
@@ -235,10 +235,6 @@ struct msmsdcc_host {
235 int cmdpoll; 235 int cmdpoll;
236 struct msmsdcc_stats stats; 236 struct msmsdcc_stats stats;
237 237
238#ifdef CONFIG_MMC_MSM7X00A_RESUME_IN_WQ
239 struct work_struct resume_task;
240#endif
241
242 /* Command parameters */ 238 /* Command parameters */
243 unsigned int cmd_timeout; 239 unsigned int cmd_timeout;
244 unsigned int cmd_pio_irqmask; 240 unsigned int cmd_pio_irqmask;
diff --git a/drivers/mmc/host/omap_hsmmc.c b/drivers/mmc/host/omap_hsmmc.c
index b032828c6126..4a8776f8afdd 100644
--- a/drivers/mmc/host/omap_hsmmc.c
+++ b/drivers/mmc/host/omap_hsmmc.c
@@ -28,6 +28,7 @@
28#include <linux/clk.h> 28#include <linux/clk.h>
29#include <linux/mmc/host.h> 29#include <linux/mmc/host.h>
30#include <linux/mmc/core.h> 30#include <linux/mmc/core.h>
31#include <linux/mmc/mmc.h>
31#include <linux/io.h> 32#include <linux/io.h>
32#include <linux/semaphore.h> 33#include <linux/semaphore.h>
33#include <linux/gpio.h> 34#include <linux/gpio.h>
@@ -78,6 +79,7 @@
78#define INT_EN_MASK 0x307F0033 79#define INT_EN_MASK 0x307F0033
79#define BWR_ENABLE (1 << 4) 80#define BWR_ENABLE (1 << 4)
80#define BRR_ENABLE (1 << 5) 81#define BRR_ENABLE (1 << 5)
82#define DTO_ENABLE (1 << 20)
81#define INIT_STREAM (1 << 1) 83#define INIT_STREAM (1 << 1)
82#define DP_SELECT (1 << 21) 84#define DP_SELECT (1 << 21)
83#define DDIR (1 << 4) 85#define DDIR (1 << 4)
@@ -523,7 +525,8 @@ static void omap_hsmmc_stop_clock(struct omap_hsmmc_host *host)
523 dev_dbg(mmc_dev(host->mmc), "MMC Clock is not stoped\n"); 525 dev_dbg(mmc_dev(host->mmc), "MMC Clock is not stoped\n");
524} 526}
525 527
526static void omap_hsmmc_enable_irq(struct omap_hsmmc_host *host) 528static void omap_hsmmc_enable_irq(struct omap_hsmmc_host *host,
529 struct mmc_command *cmd)
527{ 530{
528 unsigned int irq_mask; 531 unsigned int irq_mask;
529 532
@@ -532,6 +535,10 @@ static void omap_hsmmc_enable_irq(struct omap_hsmmc_host *host)
532 else 535 else
533 irq_mask = INT_EN_MASK; 536 irq_mask = INT_EN_MASK;
534 537
538 /* Disable timeout for erases */
539 if (cmd->opcode == MMC_ERASE)
540 irq_mask &= ~DTO_ENABLE;
541
535 OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR); 542 OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR);
536 OMAP_HSMMC_WRITE(host->base, ISE, irq_mask); 543 OMAP_HSMMC_WRITE(host->base, ISE, irq_mask);
537 OMAP_HSMMC_WRITE(host->base, IE, irq_mask); 544 OMAP_HSMMC_WRITE(host->base, IE, irq_mask);
@@ -782,7 +789,7 @@ omap_hsmmc_start_command(struct omap_hsmmc_host *host, struct mmc_command *cmd,
782 mmc_hostname(host->mmc), cmd->opcode, cmd->arg); 789 mmc_hostname(host->mmc), cmd->opcode, cmd->arg);
783 host->cmd = cmd; 790 host->cmd = cmd;
784 791
785 omap_hsmmc_enable_irq(host); 792 omap_hsmmc_enable_irq(host, cmd);
786 793
787 host->response_busy = 0; 794 host->response_busy = 0;
788 if (cmd->flags & MMC_RSP_PRESENT) { 795 if (cmd->flags & MMC_RSP_PRESENT) {
@@ -1273,8 +1280,11 @@ static void omap_hsmmc_dma_cb(int lch, u16 ch_status, void *cb_data)
1273 struct mmc_data *data = host->mrq->data; 1280 struct mmc_data *data = host->mrq->data;
1274 int dma_ch, req_in_progress; 1281 int dma_ch, req_in_progress;
1275 1282
1276 if (ch_status & OMAP2_DMA_MISALIGNED_ERR_IRQ) 1283 if (!(ch_status & OMAP_DMA_BLOCK_IRQ)) {
1277 dev_dbg(mmc_dev(host->mmc), "MISALIGNED_ADRS_ERR\n"); 1284 dev_warn(mmc_dev(host->mmc), "unexpected dma status %x\n",
1285 ch_status);
1286 return;
1287 }
1278 1288
1279 spin_lock(&host->irq_lock); 1289 spin_lock(&host->irq_lock);
1280 if (host->dma_ch < 0) { 1290 if (host->dma_ch < 0) {
@@ -1598,6 +1608,14 @@ static int omap_hsmmc_get_ro(struct mmc_host *mmc)
1598 return mmc_slot(host).get_ro(host->dev, 0); 1608 return mmc_slot(host).get_ro(host->dev, 0);
1599} 1609}
1600 1610
1611static void omap_hsmmc_init_card(struct mmc_host *mmc, struct mmc_card *card)
1612{
1613 struct omap_hsmmc_host *host = mmc_priv(mmc);
1614
1615 if (mmc_slot(host).init_card)
1616 mmc_slot(host).init_card(card);
1617}
1618
1601static void omap_hsmmc_conf_bus_power(struct omap_hsmmc_host *host) 1619static void omap_hsmmc_conf_bus_power(struct omap_hsmmc_host *host)
1602{ 1620{
1603 u32 hctl, capa, value; 1621 u32 hctl, capa, value;
@@ -1869,6 +1887,7 @@ static const struct mmc_host_ops omap_hsmmc_ops = {
1869 .set_ios = omap_hsmmc_set_ios, 1887 .set_ios = omap_hsmmc_set_ios,
1870 .get_cd = omap_hsmmc_get_cd, 1888 .get_cd = omap_hsmmc_get_cd,
1871 .get_ro = omap_hsmmc_get_ro, 1889 .get_ro = omap_hsmmc_get_ro,
1890 .init_card = omap_hsmmc_init_card,
1872 /* NYET -- enable_sdio_irq */ 1891 /* NYET -- enable_sdio_irq */
1873}; 1892};
1874 1893
@@ -1879,6 +1898,7 @@ static const struct mmc_host_ops omap_hsmmc_ps_ops = {
1879 .set_ios = omap_hsmmc_set_ios, 1898 .set_ios = omap_hsmmc_set_ios,
1880 .get_cd = omap_hsmmc_get_cd, 1899 .get_cd = omap_hsmmc_get_cd,
1881 .get_ro = omap_hsmmc_get_ro, 1900 .get_ro = omap_hsmmc_get_ro,
1901 .init_card = omap_hsmmc_init_card,
1882 /* NYET -- enable_sdio_irq */ 1902 /* NYET -- enable_sdio_irq */
1883}; 1903};
1884 1904
@@ -2094,12 +2114,25 @@ static int __init omap_hsmmc_probe(struct platform_device *pdev)
2094 mmc->max_seg_size = mmc->max_req_size; 2114 mmc->max_seg_size = mmc->max_req_size;
2095 2115
2096 mmc->caps |= MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED | 2116 mmc->caps |= MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED |
2097 MMC_CAP_WAIT_WHILE_BUSY; 2117 MMC_CAP_WAIT_WHILE_BUSY | MMC_CAP_ERASE;
2098 2118
2099 if (mmc_slot(host).wires >= 8) 2119 switch (mmc_slot(host).wires) {
2120 case 8:
2100 mmc->caps |= MMC_CAP_8_BIT_DATA; 2121 mmc->caps |= MMC_CAP_8_BIT_DATA;
2101 else if (mmc_slot(host).wires >= 4) 2122 /* Fall through */
2123 case 4:
2102 mmc->caps |= MMC_CAP_4_BIT_DATA; 2124 mmc->caps |= MMC_CAP_4_BIT_DATA;
2125 break;
2126 case 1:
2127 /* Nothing to crib here */
2128 case 0:
2129 /* Assuming nothing was given by board, Core use's 1-Bit */
2130 break;
2131 default:
2132 /* Completely unexpected.. Core goes with 1-Bit Width */
2133 dev_crit(mmc_dev(host->mmc), "Invalid width %d\n used!"
2134 "using 1 instead\n", mmc_slot(host).wires);
2135 }
2103 2136
2104 if (mmc_slot(host).nonremovable) 2137 if (mmc_slot(host).nonremovable)
2105 mmc->caps |= MMC_CAP_NONREMOVABLE; 2138 mmc->caps |= MMC_CAP_NONREMOVABLE;
diff --git a/drivers/mmc/host/sdhci-cns3xxx.c b/drivers/mmc/host/sdhci-cns3xxx.c
new file mode 100644
index 000000000000..b7050b380d5f
--- /dev/null
+++ b/drivers/mmc/host/sdhci-cns3xxx.c
@@ -0,0 +1,97 @@
1/*
2 * SDHCI support for CNS3xxx SoC
3 *
4 * Copyright 2008 Cavium Networks
5 * Copyright 2010 MontaVista Software, LLC.
6 *
7 * Authors: Scott Shu
8 * Anton Vorontsov <avorontsov@mvista.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 */
14
15#include <linux/delay.h>
16#include <linux/device.h>
17#include <linux/mmc/host.h>
18#include <linux/sdhci-pltfm.h>
19#include <mach/cns3xxx.h>
20#include "sdhci.h"
21#include "sdhci-pltfm.h"
22
23static unsigned int sdhci_cns3xxx_get_max_clk(struct sdhci_host *host)
24{
25 return 150000000;
26}
27
28static void sdhci_cns3xxx_set_clock(struct sdhci_host *host, unsigned int clock)
29{
30 struct device *dev = mmc_dev(host->mmc);
31 int div = 1;
32 u16 clk;
33 unsigned long timeout;
34
35 if (clock == host->clock)
36 return;
37
38 sdhci_writew(host, 0, SDHCI_CLOCK_CONTROL);
39
40 if (clock == 0)
41 goto out;
42
43 while (host->max_clk / div > clock) {
44 /*
45 * On CNS3xxx divider grows linearly up to 4, and then
46 * exponentially up to 256.
47 */
48 if (div < 4)
49 div += 1;
50 else if (div < 256)
51 div *= 2;
52 else
53 break;
54 }
55
56 dev_dbg(dev, "desired SD clock: %d, actual: %d\n",
57 clock, host->max_clk / div);
58
59 /* Divide by 3 is special. */
60 if (div != 3)
61 div >>= 1;
62
63 clk = div << SDHCI_DIVIDER_SHIFT;
64 clk |= SDHCI_CLOCK_INT_EN;
65 sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
66
67 timeout = 20;
68 while (!((clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL))
69 & SDHCI_CLOCK_INT_STABLE)) {
70 if (timeout == 0) {
71 dev_warn(dev, "clock is unstable");
72 break;
73 }
74 timeout--;
75 mdelay(1);
76 }
77
78 clk |= SDHCI_CLOCK_CARD_EN;
79 sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
80out:
81 host->clock = clock;
82}
83
84static struct sdhci_ops sdhci_cns3xxx_ops = {
85 .get_max_clock = sdhci_cns3xxx_get_max_clk,
86 .set_clock = sdhci_cns3xxx_set_clock,
87};
88
89struct sdhci_pltfm_data sdhci_cns3xxx_pdata = {
90 .ops = &sdhci_cns3xxx_ops,
91 .quirks = SDHCI_QUIRK_BROKEN_DMA |
92 SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK |
93 SDHCI_QUIRK_INVERTED_WRITE_PROTECT |
94 SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN |
95 SDHCI_QUIRK_BROKEN_TIMEOUT_VAL |
96 SDHCI_QUIRK_NONSTANDARD_CLOCK,
97};
diff --git a/drivers/mmc/host/sdhci-of-core.c b/drivers/mmc/host/sdhci-of-core.c
index a2e9820cd42f..c51b71174c1d 100644
--- a/drivers/mmc/host/sdhci-of-core.c
+++ b/drivers/mmc/host/sdhci-of-core.c
@@ -85,14 +85,14 @@ void sdhci_be32bs_writeb(struct sdhci_host *host, u8 val, int reg)
85 85
86#ifdef CONFIG_PM 86#ifdef CONFIG_PM
87 87
88static int sdhci_of_suspend(struct of_device *ofdev, pm_message_t state) 88static int sdhci_of_suspend(struct platform_device *ofdev, pm_message_t state)
89{ 89{
90 struct sdhci_host *host = dev_get_drvdata(&ofdev->dev); 90 struct sdhci_host *host = dev_get_drvdata(&ofdev->dev);
91 91
92 return mmc_suspend_host(host->mmc); 92 return mmc_suspend_host(host->mmc);
93} 93}
94 94
95static int sdhci_of_resume(struct of_device *ofdev) 95static int sdhci_of_resume(struct platform_device *ofdev)
96{ 96{
97 struct sdhci_host *host = dev_get_drvdata(&ofdev->dev); 97 struct sdhci_host *host = dev_get_drvdata(&ofdev->dev);
98 98
@@ -115,7 +115,7 @@ static bool __devinit sdhci_of_wp_inverted(struct device_node *np)
115 return machine_is(mpc837x_rdb) || machine_is(mpc837x_mds); 115 return machine_is(mpc837x_rdb) || machine_is(mpc837x_mds);
116} 116}
117 117
118static int __devinit sdhci_of_probe(struct of_device *ofdev, 118static int __devinit sdhci_of_probe(struct platform_device *ofdev,
119 const struct of_device_id *match) 119 const struct of_device_id *match)
120{ 120{
121 struct device_node *np = ofdev->dev.of_node; 121 struct device_node *np = ofdev->dev.of_node;
@@ -154,6 +154,10 @@ static int __devinit sdhci_of_probe(struct of_device *ofdev,
154 host->ops = &sdhci_of_data->ops; 154 host->ops = &sdhci_of_data->ops;
155 } 155 }
156 156
157 if (of_get_property(np, "sdhci,auto-cmd12", NULL))
158 host->quirks |= SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12;
159
160
157 if (of_get_property(np, "sdhci,1-bit-only", NULL)) 161 if (of_get_property(np, "sdhci,1-bit-only", NULL))
158 host->quirks |= SDHCI_QUIRK_FORCE_1_BIT_DATA; 162 host->quirks |= SDHCI_QUIRK_FORCE_1_BIT_DATA;
159 163
@@ -179,7 +183,7 @@ err_addr_map:
179 return ret; 183 return ret;
180} 184}
181 185
182static int __devexit sdhci_of_remove(struct of_device *ofdev) 186static int __devexit sdhci_of_remove(struct platform_device *ofdev)
183{ 187{
184 struct sdhci_host *host = dev_get_drvdata(&ofdev->dev); 188 struct sdhci_host *host = dev_get_drvdata(&ofdev->dev);
185 189
diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
index 65483fdea45b..e8aa99deae9a 100644
--- a/drivers/mmc/host/sdhci-pci.c
+++ b/drivers/mmc/host/sdhci-pci.c
@@ -17,6 +17,7 @@
17#include <linux/pci.h> 17#include <linux/pci.h>
18#include <linux/dma-mapping.h> 18#include <linux/dma-mapping.h>
19#include <linux/slab.h> 19#include <linux/slab.h>
20#include <linux/device.h>
20 21
21#include <linux/mmc/host.h> 22#include <linux/mmc/host.h>
22 23
@@ -84,7 +85,30 @@ static int ricoh_probe(struct sdhci_pci_chip *chip)
84 if (chip->pdev->subsystem_vendor == PCI_VENDOR_ID_SAMSUNG || 85 if (chip->pdev->subsystem_vendor == PCI_VENDOR_ID_SAMSUNG ||
85 chip->pdev->subsystem_vendor == PCI_VENDOR_ID_SONY) 86 chip->pdev->subsystem_vendor == PCI_VENDOR_ID_SONY)
86 chip->quirks |= SDHCI_QUIRK_NO_CARD_NO_RESET; 87 chip->quirks |= SDHCI_QUIRK_NO_CARD_NO_RESET;
88 return 0;
89}
90
91static int ricoh_mmc_probe_slot(struct sdhci_pci_slot *slot)
92{
93 slot->host->caps =
94 ((0x21 << SDHCI_TIMEOUT_CLK_SHIFT)
95 & SDHCI_TIMEOUT_CLK_MASK) |
96
97 ((0x21 << SDHCI_CLOCK_BASE_SHIFT)
98 & SDHCI_CLOCK_BASE_MASK) |
87 99
100 SDHCI_TIMEOUT_CLK_UNIT |
101 SDHCI_CAN_VDD_330 |
102 SDHCI_CAN_DO_SDMA;
103 return 0;
104}
105
106static int ricoh_mmc_resume(struct sdhci_pci_chip *chip)
107{
108 /* Apply a delay to allow controller to settle */
109 /* Otherwise it becomes confused if card state changed
110 during suspend */
111 msleep(500);
88 return 0; 112 return 0;
89} 113}
90 114
@@ -95,6 +119,15 @@ static const struct sdhci_pci_fixes sdhci_ricoh = {
95 SDHCI_QUIRK_CLOCK_BEFORE_RESET, 119 SDHCI_QUIRK_CLOCK_BEFORE_RESET,
96}; 120};
97 121
122static const struct sdhci_pci_fixes sdhci_ricoh_mmc = {
123 .probe_slot = ricoh_mmc_probe_slot,
124 .resume = ricoh_mmc_resume,
125 .quirks = SDHCI_QUIRK_32BIT_DMA_ADDR |
126 SDHCI_QUIRK_CLOCK_BEFORE_RESET |
127 SDHCI_QUIRK_NO_CARD_NO_RESET |
128 SDHCI_QUIRK_MISSING_CAPS
129};
130
98static const struct sdhci_pci_fixes sdhci_ene_712 = { 131static const struct sdhci_pci_fixes sdhci_ene_712 = {
99 .quirks = SDHCI_QUIRK_SINGLE_POWER_WRITE | 132 .quirks = SDHCI_QUIRK_SINGLE_POWER_WRITE |
100 SDHCI_QUIRK_BROKEN_DMA, 133 SDHCI_QUIRK_BROKEN_DMA,
@@ -374,6 +407,22 @@ static const struct pci_device_id pci_ids[] __devinitdata = {
374 }, 407 },
375 408
376 { 409 {
410 .vendor = PCI_VENDOR_ID_RICOH,
411 .device = 0x843,
412 .subvendor = PCI_ANY_ID,
413 .subdevice = PCI_ANY_ID,
414 .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc,
415 },
416
417 {
418 .vendor = PCI_VENDOR_ID_RICOH,
419 .device = 0xe822,
420 .subvendor = PCI_ANY_ID,
421 .subdevice = PCI_ANY_ID,
422 .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc,
423 },
424
425 {
377 .vendor = PCI_VENDOR_ID_ENE, 426 .vendor = PCI_VENDOR_ID_ENE,
378 .device = PCI_DEVICE_ID_ENE_CB712_SD, 427 .device = PCI_DEVICE_ID_ENE_CB712_SD,
379 .subvendor = PCI_ANY_ID, 428 .subvendor = PCI_ANY_ID,
diff --git a/drivers/mmc/host/sdhci-pltfm.c b/drivers/mmc/host/sdhci-pltfm.c
index b6ee0d719698..e045e3c61dde 100644
--- a/drivers/mmc/host/sdhci-pltfm.c
+++ b/drivers/mmc/host/sdhci-pltfm.c
@@ -24,6 +24,7 @@
24 24
25#include <linux/delay.h> 25#include <linux/delay.h>
26#include <linux/highmem.h> 26#include <linux/highmem.h>
27#include <linux/mod_devicetable.h>
27#include <linux/platform_device.h> 28#include <linux/platform_device.h>
28 29
29#include <linux/mmc/host.h> 30#include <linux/mmc/host.h>
@@ -32,6 +33,7 @@
32#include <linux/sdhci-pltfm.h> 33#include <linux/sdhci-pltfm.h>
33 34
34#include "sdhci.h" 35#include "sdhci.h"
36#include "sdhci-pltfm.h"
35 37
36/*****************************************************************************\ 38/*****************************************************************************\
37 * * 39 * *
@@ -51,10 +53,14 @@ static struct sdhci_ops sdhci_pltfm_ops = {
51static int __devinit sdhci_pltfm_probe(struct platform_device *pdev) 53static int __devinit sdhci_pltfm_probe(struct platform_device *pdev)
52{ 54{
53 struct sdhci_pltfm_data *pdata = pdev->dev.platform_data; 55 struct sdhci_pltfm_data *pdata = pdev->dev.platform_data;
56 const struct platform_device_id *platid = platform_get_device_id(pdev);
54 struct sdhci_host *host; 57 struct sdhci_host *host;
55 struct resource *iomem; 58 struct resource *iomem;
56 int ret; 59 int ret;
57 60
61 if (!pdata && platid && platid->driver_data)
62 pdata = (void *)platid->driver_data;
63
58 iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 64 iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
59 if (!iomem) { 65 if (!iomem) {
60 ret = -ENOMEM; 66 ret = -ENOMEM;
@@ -150,6 +156,15 @@ static int __devexit sdhci_pltfm_remove(struct platform_device *pdev)
150 return 0; 156 return 0;
151} 157}
152 158
159static const struct platform_device_id sdhci_pltfm_ids[] = {
160 { "sdhci", },
161#ifdef CONFIG_MMC_SDHCI_CNS3XXX
162 { "sdhci-cns3xxx", (kernel_ulong_t)&sdhci_cns3xxx_pdata },
163#endif
164 { },
165};
166MODULE_DEVICE_TABLE(platform, sdhci_pltfm_ids);
167
153static struct platform_driver sdhci_pltfm_driver = { 168static struct platform_driver sdhci_pltfm_driver = {
154 .driver = { 169 .driver = {
155 .name = "sdhci", 170 .name = "sdhci",
@@ -157,6 +172,7 @@ static struct platform_driver sdhci_pltfm_driver = {
157 }, 172 },
158 .probe = sdhci_pltfm_probe, 173 .probe = sdhci_pltfm_probe,
159 .remove = __devexit_p(sdhci_pltfm_remove), 174 .remove = __devexit_p(sdhci_pltfm_remove),
175 .id_table = sdhci_pltfm_ids,
160}; 176};
161 177
162/*****************************************************************************\ 178/*****************************************************************************\
@@ -181,4 +197,3 @@ module_exit(sdhci_drv_exit);
181MODULE_DESCRIPTION("Secure Digital Host Controller Interface platform driver"); 197MODULE_DESCRIPTION("Secure Digital Host Controller Interface platform driver");
182MODULE_AUTHOR("Mocean Laboratories <info@mocean-labs.com>"); 198MODULE_AUTHOR("Mocean Laboratories <info@mocean-labs.com>");
183MODULE_LICENSE("GPL v2"); 199MODULE_LICENSE("GPL v2");
184MODULE_ALIAS("platform:sdhci");
diff --git a/drivers/mmc/host/sdhci-pltfm.h b/drivers/mmc/host/sdhci-pltfm.h
new file mode 100644
index 000000000000..900f32902f73
--- /dev/null
+++ b/drivers/mmc/host/sdhci-pltfm.h
@@ -0,0 +1,18 @@
1/*
2 * Copyright 2010 MontaVista Software, LLC.
3 *
4 * Author: Anton Vorontsov <avorontsov@ru.mvista.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 version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#ifndef _DRIVERS_MMC_SDHCI_PLTFM_H
12#define _DRIVERS_MMC_SDHCI_PLTFM_H
13
14#include <linux/sdhci-pltfm.h>
15
16extern struct sdhci_pltfm_data sdhci_cns3xxx_pdata;
17
18#endif /* _DRIVERS_MMC_SDHCI_PLTFM_H */
diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
index ad30f074ee15..0a7f2614c6f0 100644
--- a/drivers/mmc/host/sdhci-s3c.c
+++ b/drivers/mmc/host/sdhci-s3c.c
@@ -18,6 +18,7 @@
18#include <linux/slab.h> 18#include <linux/slab.h>
19#include <linux/clk.h> 19#include <linux/clk.h>
20#include <linux/io.h> 20#include <linux/io.h>
21#include <linux/gpio.h>
21 22
22#include <linux/mmc/host.h> 23#include <linux/mmc/host.h>
23 24
@@ -44,6 +45,8 @@ struct sdhci_s3c {
44 struct resource *ioarea; 45 struct resource *ioarea;
45 struct s3c_sdhci_platdata *pdata; 46 struct s3c_sdhci_platdata *pdata;
46 unsigned int cur_clk; 47 unsigned int cur_clk;
48 int ext_cd_irq;
49 int ext_cd_gpio;
47 50
48 struct clk *clk_io; 51 struct clk *clk_io;
49 struct clk *clk_bus[MAX_BUS_CLK]; 52 struct clk *clk_bus[MAX_BUS_CLK];
@@ -110,11 +113,6 @@ static unsigned int sdhci_s3c_get_max_clk(struct sdhci_host *host)
110 return max; 113 return max;
111} 114}
112 115
113static unsigned int sdhci_s3c_get_timeout_clk(struct sdhci_host *host)
114{
115 return sdhci_s3c_get_max_clk(host) / 1000000;
116}
117
118/** 116/**
119 * sdhci_s3c_consider_clock - consider one the bus clocks for current setting 117 * sdhci_s3c_consider_clock - consider one the bus clocks for current setting
120 * @ourhost: Our SDHCI instance. 118 * @ourhost: Our SDHCI instance.
@@ -188,7 +186,6 @@ static void sdhci_s3c_set_clock(struct sdhci_host *host, unsigned int clock)
188 186
189 ourhost->cur_clk = best_src; 187 ourhost->cur_clk = best_src;
190 host->max_clk = clk_get_rate(clk); 188 host->max_clk = clk_get_rate(clk);
191 host->timeout_clk = sdhci_s3c_get_timeout_clk(host);
192 189
193 ctrl = readl(host->ioaddr + S3C_SDHCI_CONTROL2); 190 ctrl = readl(host->ioaddr + S3C_SDHCI_CONTROL2);
194 ctrl &= ~S3C_SDHCI_CTRL2_SELBASECLK_MASK; 191 ctrl &= ~S3C_SDHCI_CTRL2_SELBASECLK_MASK;
@@ -209,12 +206,93 @@ static void sdhci_s3c_set_clock(struct sdhci_host *host, unsigned int clock)
209 } 206 }
210} 207}
211 208
209/**
210 * sdhci_s3c_get_min_clock - callback to get minimal supported clock value
211 * @host: The SDHCI host being queried
212 *
213 * To init mmc host properly a minimal clock value is needed. For high system
214 * bus clock's values the standard formula gives values out of allowed range.
215 * The clock still can be set to lower values, if clock source other then
216 * system bus is selected.
217*/
218static unsigned int sdhci_s3c_get_min_clock(struct sdhci_host *host)
219{
220 struct sdhci_s3c *ourhost = to_s3c(host);
221 unsigned int delta, min = UINT_MAX;
222 int src;
223
224 for (src = 0; src < MAX_BUS_CLK; src++) {
225 delta = sdhci_s3c_consider_clock(ourhost, src, 0);
226 if (delta == UINT_MAX)
227 continue;
228 /* delta is a negative value in this case */
229 if (-delta < min)
230 min = -delta;
231 }
232 return min;
233}
234
212static struct sdhci_ops sdhci_s3c_ops = { 235static struct sdhci_ops sdhci_s3c_ops = {
213 .get_max_clock = sdhci_s3c_get_max_clk, 236 .get_max_clock = sdhci_s3c_get_max_clk,
214 .get_timeout_clock = sdhci_s3c_get_timeout_clk,
215 .set_clock = sdhci_s3c_set_clock, 237 .set_clock = sdhci_s3c_set_clock,
238 .get_min_clock = sdhci_s3c_get_min_clock,
216}; 239};
217 240
241static void sdhci_s3c_notify_change(struct platform_device *dev, int state)
242{
243 struct sdhci_host *host = platform_get_drvdata(dev);
244 if (host) {
245 mutex_lock(&host->lock);
246 if (state) {
247 dev_dbg(&dev->dev, "card inserted.\n");
248 host->flags &= ~SDHCI_DEVICE_DEAD;
249 host->quirks |= SDHCI_QUIRK_BROKEN_CARD_DETECTION;
250 } else {
251 dev_dbg(&dev->dev, "card removed.\n");
252 host->flags |= SDHCI_DEVICE_DEAD;
253 host->quirks &= ~SDHCI_QUIRK_BROKEN_CARD_DETECTION;
254 }
255 sdhci_card_detect(host);
256 mutex_unlock(&host->lock);
257 }
258}
259
260static irqreturn_t sdhci_s3c_gpio_card_detect_thread(int irq, void *dev_id)
261{
262 struct sdhci_s3c *sc = dev_id;
263 int status = gpio_get_value(sc->ext_cd_gpio);
264 if (sc->pdata->ext_cd_gpio_invert)
265 status = !status;
266 sdhci_s3c_notify_change(sc->pdev, status);
267 return IRQ_HANDLED;
268}
269
270static void sdhci_s3c_setup_card_detect_gpio(struct sdhci_s3c *sc)
271{
272 struct s3c_sdhci_platdata *pdata = sc->pdata;
273 struct device *dev = &sc->pdev->dev;
274
275 if (gpio_request(pdata->ext_cd_gpio, "SDHCI EXT CD") == 0) {
276 sc->ext_cd_gpio = pdata->ext_cd_gpio;
277 sc->ext_cd_irq = gpio_to_irq(pdata->ext_cd_gpio);
278 if (sc->ext_cd_irq &&
279 request_threaded_irq(sc->ext_cd_irq, NULL,
280 sdhci_s3c_gpio_card_detect_thread,
281 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
282 dev_name(dev), sc) == 0) {
283 int status = gpio_get_value(sc->ext_cd_gpio);
284 if (pdata->ext_cd_gpio_invert)
285 status = !status;
286 sdhci_s3c_notify_change(sc->pdev, status);
287 } else {
288 dev_warn(dev, "cannot request irq for card detect\n");
289 sc->ext_cd_irq = 0;
290 }
291 } else {
292 dev_err(dev, "cannot request gpio for card detect\n");
293 }
294}
295
218static int __devinit sdhci_s3c_probe(struct platform_device *pdev) 296static int __devinit sdhci_s3c_probe(struct platform_device *pdev)
219{ 297{
220 struct s3c_sdhci_platdata *pdata = pdev->dev.platform_data; 298 struct s3c_sdhci_platdata *pdata = pdev->dev.platform_data;
@@ -252,6 +330,7 @@ static int __devinit sdhci_s3c_probe(struct platform_device *pdev)
252 sc->host = host; 330 sc->host = host;
253 sc->pdev = pdev; 331 sc->pdev = pdev;
254 sc->pdata = pdata; 332 sc->pdata = pdata;
333 sc->ext_cd_gpio = -1; /* invalid gpio number */
255 334
256 platform_set_drvdata(pdev, host); 335 platform_set_drvdata(pdev, host);
257 336
@@ -318,6 +397,7 @@ static int __devinit sdhci_s3c_probe(struct platform_device *pdev)
318 397
319 /* Setup quirks for the controller */ 398 /* Setup quirks for the controller */
320 host->quirks |= SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC; 399 host->quirks |= SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC;
400 host->quirks |= SDHCI_QUIRK_NO_HISPD_BIT;
321 401
322#ifndef CONFIG_MMC_SDHCI_S3C_DMA 402#ifndef CONFIG_MMC_SDHCI_S3C_DMA
323 403
@@ -332,15 +412,34 @@ static int __devinit sdhci_s3c_probe(struct platform_device *pdev)
332 * SDHCI block, or a missing configuration that needs to be set. */ 412 * SDHCI block, or a missing configuration that needs to be set. */
333 host->quirks |= SDHCI_QUIRK_NO_BUSY_IRQ; 413 host->quirks |= SDHCI_QUIRK_NO_BUSY_IRQ;
334 414
415 if (pdata->cd_type == S3C_SDHCI_CD_NONE ||
416 pdata->cd_type == S3C_SDHCI_CD_PERMANENT)
417 host->quirks |= SDHCI_QUIRK_BROKEN_CARD_DETECTION;
418
419 if (pdata->cd_type == S3C_SDHCI_CD_PERMANENT)
420 host->mmc->caps = MMC_CAP_NONREMOVABLE;
421
335 host->quirks |= (SDHCI_QUIRK_32BIT_DMA_ADDR | 422 host->quirks |= (SDHCI_QUIRK_32BIT_DMA_ADDR |
336 SDHCI_QUIRK_32BIT_DMA_SIZE); 423 SDHCI_QUIRK_32BIT_DMA_SIZE);
337 424
425 /* HSMMC on Samsung SoCs uses SDCLK as timeout clock */
426 host->quirks |= SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK;
427
338 ret = sdhci_add_host(host); 428 ret = sdhci_add_host(host);
339 if (ret) { 429 if (ret) {
340 dev_err(dev, "sdhci_add_host() failed\n"); 430 dev_err(dev, "sdhci_add_host() failed\n");
341 goto err_add_host; 431 goto err_add_host;
342 } 432 }
343 433
434 /* The following two methods of card detection might call
435 sdhci_s3c_notify_change() immediately, so they can be called
436 only after sdhci_add_host(). Setup errors are ignored. */
437 if (pdata->cd_type == S3C_SDHCI_CD_EXTERNAL && pdata->ext_cd_init)
438 pdata->ext_cd_init(&sdhci_s3c_notify_change);
439 if (pdata->cd_type == S3C_SDHCI_CD_GPIO &&
440 gpio_is_valid(pdata->ext_cd_gpio))
441 sdhci_s3c_setup_card_detect_gpio(sc);
442
344 return 0; 443 return 0;
345 444
346 err_add_host: 445 err_add_host:
@@ -365,10 +464,20 @@ static int __devinit sdhci_s3c_probe(struct platform_device *pdev)
365 464
366static int __devexit sdhci_s3c_remove(struct platform_device *pdev) 465static int __devexit sdhci_s3c_remove(struct platform_device *pdev)
367{ 466{
467 struct s3c_sdhci_platdata *pdata = pdev->dev.platform_data;
368 struct sdhci_host *host = platform_get_drvdata(pdev); 468 struct sdhci_host *host = platform_get_drvdata(pdev);
369 struct sdhci_s3c *sc = sdhci_priv(host); 469 struct sdhci_s3c *sc = sdhci_priv(host);
370 int ptr; 470 int ptr;
371 471
472 if (pdata->cd_type == S3C_SDHCI_CD_EXTERNAL && pdata->ext_cd_cleanup)
473 pdata->ext_cd_cleanup(&sdhci_s3c_notify_change);
474
475 if (sc->ext_cd_irq)
476 free_irq(sc->ext_cd_irq, sc);
477
478 if (gpio_is_valid(sc->ext_cd_gpio))
479 gpio_free(sc->ext_cd_gpio);
480
372 sdhci_remove_host(host, 1); 481 sdhci_remove_host(host, 1);
373 482
374 for (ptr = 0; ptr < 3; ptr++) { 483 for (ptr = 0; ptr < 3; ptr++) {
diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index c6d1bd8d4ac4..785512133b50 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -19,6 +19,7 @@
19#include <linux/dma-mapping.h> 19#include <linux/dma-mapping.h>
20#include <linux/slab.h> 20#include <linux/slab.h>
21#include <linux/scatterlist.h> 21#include <linux/scatterlist.h>
22#include <linux/regulator/consumer.h>
22 23
23#include <linux/leds.h> 24#include <linux/leds.h>
24 25
@@ -817,8 +818,12 @@ static void sdhci_set_transfer_mode(struct sdhci_host *host,
817 WARN_ON(!host->data); 818 WARN_ON(!host->data);
818 819
819 mode = SDHCI_TRNS_BLK_CNT_EN; 820 mode = SDHCI_TRNS_BLK_CNT_EN;
820 if (data->blocks > 1) 821 if (data->blocks > 1) {
821 mode |= SDHCI_TRNS_MULTI; 822 if (host->quirks & SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12)
823 mode |= SDHCI_TRNS_MULTI | SDHCI_TRNS_ACMD12;
824 else
825 mode |= SDHCI_TRNS_MULTI;
826 }
822 if (data->flags & MMC_DATA_READ) 827 if (data->flags & MMC_DATA_READ)
823 mode |= SDHCI_TRNS_READ; 828 mode |= SDHCI_TRNS_READ;
824 if (host->flags & SDHCI_REQ_USE_DMA) 829 if (host->flags & SDHCI_REQ_USE_DMA)
@@ -1108,6 +1113,12 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
1108#ifndef SDHCI_USE_LEDS_CLASS 1113#ifndef SDHCI_USE_LEDS_CLASS
1109 sdhci_activate_led(host); 1114 sdhci_activate_led(host);
1110#endif 1115#endif
1116 if (host->quirks & SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12) {
1117 if (mrq->stop) {
1118 mrq->data->stop = NULL;
1119 mrq->stop = NULL;
1120 }
1121 }
1111 1122
1112 host->mrq = mrq; 1123 host->mrq = mrq;
1113 1124
@@ -1159,6 +1170,11 @@ static void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
1159 1170
1160 ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL); 1171 ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL);
1161 1172
1173 if (ios->bus_width == MMC_BUS_WIDTH_8)
1174 ctrl |= SDHCI_CTRL_8BITBUS;
1175 else
1176 ctrl &= ~SDHCI_CTRL_8BITBUS;
1177
1162 if (ios->bus_width == MMC_BUS_WIDTH_4) 1178 if (ios->bus_width == MMC_BUS_WIDTH_4)
1163 ctrl |= SDHCI_CTRL_4BITBUS; 1179 ctrl |= SDHCI_CTRL_4BITBUS;
1164 else 1180 else
@@ -1603,7 +1619,10 @@ int sdhci_suspend_host(struct sdhci_host *host, pm_message_t state)
1603 1619
1604 free_irq(host->irq, host); 1620 free_irq(host->irq, host);
1605 1621
1606 return 0; 1622 if (host->vmmc)
1623 ret = regulator_disable(host->vmmc);
1624
1625 return ret;
1607} 1626}
1608 1627
1609EXPORT_SYMBOL_GPL(sdhci_suspend_host); 1628EXPORT_SYMBOL_GPL(sdhci_suspend_host);
@@ -1612,6 +1631,13 @@ int sdhci_resume_host(struct sdhci_host *host)
1612{ 1631{
1613 int ret; 1632 int ret;
1614 1633
1634 if (host->vmmc) {
1635 int ret = regulator_enable(host->vmmc);
1636 if (ret)
1637 return ret;
1638 }
1639
1640
1615 if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) { 1641 if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) {
1616 if (host->ops->enable_dma) 1642 if (host->ops->enable_dma)
1617 host->ops->enable_dma(host); 1643 host->ops->enable_dma(host);
@@ -1687,7 +1713,8 @@ int sdhci_add_host(struct sdhci_host *host)
1687 host->version); 1713 host->version);
1688 } 1714 }
1689 1715
1690 caps = sdhci_readl(host, SDHCI_CAPABILITIES); 1716 caps = (host->quirks & SDHCI_QUIRK_MISSING_CAPS) ? host->caps :
1717 sdhci_readl(host, SDHCI_CAPABILITIES);
1691 1718
1692 if (host->quirks & SDHCI_QUIRK_FORCE_DMA) 1719 if (host->quirks & SDHCI_QUIRK_FORCE_DMA)
1693 host->flags |= SDHCI_USE_SDMA; 1720 host->flags |= SDHCI_USE_SDMA;
@@ -1785,13 +1812,12 @@ int sdhci_add_host(struct sdhci_host *host)
1785 * Set host parameters. 1812 * Set host parameters.
1786 */ 1813 */
1787 mmc->ops = &sdhci_ops; 1814 mmc->ops = &sdhci_ops;
1788 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK && 1815 if (host->ops->get_min_clock)
1789 host->ops->set_clock && host->ops->get_min_clock)
1790 mmc->f_min = host->ops->get_min_clock(host); 1816 mmc->f_min = host->ops->get_min_clock(host);
1791 else 1817 else
1792 mmc->f_min = host->max_clk / 256; 1818 mmc->f_min = host->max_clk / 256;
1793 mmc->f_max = host->max_clk; 1819 mmc->f_max = host->max_clk;
1794 mmc->caps = MMC_CAP_SDIO_IRQ; 1820 mmc->caps |= MMC_CAP_SDIO_IRQ;
1795 1821
1796 if (!(host->quirks & SDHCI_QUIRK_FORCE_1_BIT_DATA)) 1822 if (!(host->quirks & SDHCI_QUIRK_FORCE_1_BIT_DATA))
1797 mmc->caps |= MMC_CAP_4_BIT_DATA; 1823 mmc->caps |= MMC_CAP_4_BIT_DATA;
@@ -1884,6 +1910,14 @@ int sdhci_add_host(struct sdhci_host *host)
1884 if (ret) 1910 if (ret)
1885 goto untasklet; 1911 goto untasklet;
1886 1912
1913 host->vmmc = regulator_get(mmc_dev(mmc), "vmmc");
1914 if (IS_ERR(host->vmmc)) {
1915 printk(KERN_INFO "%s: no vmmc regulator found\n", mmc_hostname(mmc));
1916 host->vmmc = NULL;
1917 } else {
1918 regulator_enable(host->vmmc);
1919 }
1920
1887 sdhci_init(host, 0); 1921 sdhci_init(host, 0);
1888 1922
1889#ifdef CONFIG_MMC_DEBUG 1923#ifdef CONFIG_MMC_DEBUG
@@ -1968,6 +2002,11 @@ void sdhci_remove_host(struct sdhci_host *host, int dead)
1968 tasklet_kill(&host->card_tasklet); 2002 tasklet_kill(&host->card_tasklet);
1969 tasklet_kill(&host->finish_tasklet); 2003 tasklet_kill(&host->finish_tasklet);
1970 2004
2005 if (host->vmmc) {
2006 regulator_disable(host->vmmc);
2007 regulator_put(host->vmmc);
2008 }
2009
1971 kfree(host->adma_desc); 2010 kfree(host->adma_desc);
1972 kfree(host->align_buffer); 2011 kfree(host->align_buffer);
1973 2012
diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h
index c8468134adc9..036cfae76368 100644
--- a/drivers/mmc/host/sdhci.h
+++ b/drivers/mmc/host/sdhci.h
@@ -72,6 +72,7 @@
72#define SDHCI_CTRL_ADMA1 0x08 72#define SDHCI_CTRL_ADMA1 0x08
73#define SDHCI_CTRL_ADMA32 0x10 73#define SDHCI_CTRL_ADMA32 0x10
74#define SDHCI_CTRL_ADMA64 0x18 74#define SDHCI_CTRL_ADMA64 0x18
75#define SDHCI_CTRL_8BITBUS 0x20
75 76
76#define SDHCI_POWER_CONTROL 0x29 77#define SDHCI_POWER_CONTROL 0x29
77#define SDHCI_POWER_ON 0x01 78#define SDHCI_POWER_ON 0x01
@@ -240,12 +241,18 @@ struct sdhci_host {
240#define SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN (1<<25) 241#define SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN (1<<25)
241/* Controller cannot support End Attribute in NOP ADMA descriptor */ 242/* Controller cannot support End Attribute in NOP ADMA descriptor */
242#define SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC (1<<26) 243#define SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC (1<<26)
244/* Controller is missing device caps. Use caps provided by host */
245#define SDHCI_QUIRK_MISSING_CAPS (1<<27)
246/* Controller uses Auto CMD12 command to stop the transfer */
247#define SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12 (1<<28)
243 248
244 int irq; /* Device IRQ */ 249 int irq; /* Device IRQ */
245 void __iomem * ioaddr; /* Mapped address */ 250 void __iomem * ioaddr; /* Mapped address */
246 251
247 const struct sdhci_ops *ops; /* Low level hw interface */ 252 const struct sdhci_ops *ops; /* Low level hw interface */
248 253
254 struct regulator *vmmc; /* Power regulator */
255
249 /* Internal data */ 256 /* Internal data */
250 struct mmc_host *mmc; /* MMC structure */ 257 struct mmc_host *mmc; /* MMC structure */
251 u64 dma_mask; /* custom DMA mask */ 258 u64 dma_mask; /* custom DMA mask */
@@ -292,6 +299,8 @@ struct sdhci_host {
292 299
293 struct timer_list timer; /* Timer for timeouts */ 300 struct timer_list timer; /* Timer for timeouts */
294 301
302 unsigned int caps; /* Alternative capabilities */
303
295 unsigned long private[0] ____cacheline_aligned; 304 unsigned long private[0] ____cacheline_aligned;
296}; 305};
297 306
@@ -407,6 +416,7 @@ static inline void *sdhci_priv(struct sdhci_host *host)
407 return (void *)host->private; 416 return (void *)host->private;
408} 417}
409 418
419extern void sdhci_card_detect(struct sdhci_host *host);
410extern int sdhci_add_host(struct sdhci_host *host); 420extern int sdhci_add_host(struct sdhci_host *host);
411extern void sdhci_remove_host(struct sdhci_host *host, int dead); 421extern void sdhci_remove_host(struct sdhci_host *host, int dead);
412 422
diff --git a/drivers/mtd/Kconfig b/drivers/mtd/Kconfig
index f8210bf2d241..1e2cbf5d9aa1 100644
--- a/drivers/mtd/Kconfig
+++ b/drivers/mtd/Kconfig
@@ -311,15 +311,17 @@ config SM_FTL
311 select MTD_BLKDEVS 311 select MTD_BLKDEVS
312 select MTD_NAND_ECC 312 select MTD_NAND_ECC
313 help 313 help
314 This enables new and very EXPERMENTAL support for SmartMedia/xD 314 This enables EXPERIMENTAL R/W support for SmartMedia/xD
315 FTL (Flash translation layer). 315 FTL (Flash translation layer).
316 Write support isn't yet well tested, therefore this code IS likely to 316 Write support is only lightly tested, therefore this driver
317 eat your card, so please don't use it together with valuable data. 317 isn't recommended to use with valuable data (anyway if you have
318 Use readonly driver (CONFIG_SSFDC) instead. 318 valuable data, do backups regardless of software/hardware you
319 use, because you never know what will eat your data...)
320 If you only need R/O access, you can use older R/O driver
321 (CONFIG_SSFDC)
319 322
320config MTD_OOPS 323config MTD_OOPS
321 tristate "Log panic/oops to an MTD buffer" 324 tristate "Log panic/oops to an MTD buffer"
322 depends on MTD
323 help 325 help
324 This enables panic and oops messages to be logged to a circular 326 This enables panic and oops messages to be logged to a circular
325 buffer in a flash partition where it can be read back at some 327 buffer in a flash partition where it can be read back at some
diff --git a/drivers/mtd/afs.c b/drivers/mtd/afs.c
index cec7ab98b2a9..302372c08b56 100644
--- a/drivers/mtd/afs.c
+++ b/drivers/mtd/afs.c
@@ -2,7 +2,7 @@
2 2
3 drivers/mtd/afs.c: ARM Flash Layout/Partitioning 3 drivers/mtd/afs.c: ARM Flash Layout/Partitioning
4 4
5 Copyright (C) 2000 ARM Limited 5 Copyright © 2000 ARM Limited
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 as published by 8 it under the terms of the GNU General Public License as published by
diff --git a/drivers/mtd/chips/cfi_cmdset_0001.c b/drivers/mtd/chips/cfi_cmdset_0001.c
index 62f3ea9de848..9e2b7e9e0ad9 100644
--- a/drivers/mtd/chips/cfi_cmdset_0001.c
+++ b/drivers/mtd/chips/cfi_cmdset_0001.c
@@ -34,7 +34,6 @@
34#include <linux/mtd/xip.h> 34#include <linux/mtd/xip.h>
35#include <linux/mtd/map.h> 35#include <linux/mtd/map.h>
36#include <linux/mtd/mtd.h> 36#include <linux/mtd/mtd.h>
37#include <linux/mtd/compatmac.h>
38#include <linux/mtd/cfi.h> 37#include <linux/mtd/cfi.h>
39 38
40/* #define CMDSET0001_DISABLE_ERASE_SUSPEND_ON_WRITE */ 39/* #define CMDSET0001_DISABLE_ERASE_SUSPEND_ON_WRITE */
@@ -63,6 +62,8 @@ static int cfi_intelext_erase_varsize(struct mtd_info *, struct erase_info *);
63static void cfi_intelext_sync (struct mtd_info *); 62static void cfi_intelext_sync (struct mtd_info *);
64static int cfi_intelext_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len); 63static int cfi_intelext_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len);
65static int cfi_intelext_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len); 64static int cfi_intelext_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len);
65static int cfi_intelext_is_locked(struct mtd_info *mtd, loff_t ofs,
66 uint64_t len);
66#ifdef CONFIG_MTD_OTP 67#ifdef CONFIG_MTD_OTP
67static int cfi_intelext_read_fact_prot_reg (struct mtd_info *, loff_t, size_t, size_t *, u_char *); 68static int cfi_intelext_read_fact_prot_reg (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
68static int cfi_intelext_read_user_prot_reg (struct mtd_info *, loff_t, size_t, size_t *, u_char *); 69static int cfi_intelext_read_user_prot_reg (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
@@ -448,6 +449,7 @@ struct mtd_info *cfi_cmdset_0001(struct map_info *map, int primary)
448 mtd->sync = cfi_intelext_sync; 449 mtd->sync = cfi_intelext_sync;
449 mtd->lock = cfi_intelext_lock; 450 mtd->lock = cfi_intelext_lock;
450 mtd->unlock = cfi_intelext_unlock; 451 mtd->unlock = cfi_intelext_unlock;
452 mtd->is_locked = cfi_intelext_is_locked;
451 mtd->suspend = cfi_intelext_suspend; 453 mtd->suspend = cfi_intelext_suspend;
452 mtd->resume = cfi_intelext_resume; 454 mtd->resume = cfi_intelext_resume;
453 mtd->flags = MTD_CAP_NORFLASH; 455 mtd->flags = MTD_CAP_NORFLASH;
@@ -717,7 +719,7 @@ static int cfi_intelext_partition_fixup(struct mtd_info *mtd,
717 chip = &newcfi->chips[0]; 719 chip = &newcfi->chips[0];
718 for (i = 0; i < cfi->numchips; i++) { 720 for (i = 0; i < cfi->numchips; i++) {
719 shared[i].writing = shared[i].erasing = NULL; 721 shared[i].writing = shared[i].erasing = NULL;
720 spin_lock_init(&shared[i].lock); 722 mutex_init(&shared[i].lock);
721 for (j = 0; j < numparts; j++) { 723 for (j = 0; j < numparts; j++) {
722 *chip = cfi->chips[i]; 724 *chip = cfi->chips[i];
723 chip->start += j << partshift; 725 chip->start += j << partshift;
@@ -886,7 +888,7 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr
886 */ 888 */
887 struct flchip_shared *shared = chip->priv; 889 struct flchip_shared *shared = chip->priv;
888 struct flchip *contender; 890 struct flchip *contender;
889 spin_lock(&shared->lock); 891 mutex_lock(&shared->lock);
890 contender = shared->writing; 892 contender = shared->writing;
891 if (contender && contender != chip) { 893 if (contender && contender != chip) {
892 /* 894 /*
@@ -899,7 +901,7 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr
899 * get_chip returns success we're clear to go ahead. 901 * get_chip returns success we're clear to go ahead.
900 */ 902 */
901 ret = mutex_trylock(&contender->mutex); 903 ret = mutex_trylock(&contender->mutex);
902 spin_unlock(&shared->lock); 904 mutex_unlock(&shared->lock);
903 if (!ret) 905 if (!ret)
904 goto retry; 906 goto retry;
905 mutex_unlock(&chip->mutex); 907 mutex_unlock(&chip->mutex);
@@ -914,7 +916,7 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr
914 mutex_unlock(&contender->mutex); 916 mutex_unlock(&contender->mutex);
915 return ret; 917 return ret;
916 } 918 }
917 spin_lock(&shared->lock); 919 mutex_lock(&shared->lock);
918 920
919 /* We should not own chip if it is already 921 /* We should not own chip if it is already
920 * in FL_SYNCING state. Put contender and retry. */ 922 * in FL_SYNCING state. Put contender and retry. */
@@ -930,7 +932,7 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr
930 * on this chip. Sleep. */ 932 * on this chip. Sleep. */
931 if (mode == FL_ERASING && shared->erasing 933 if (mode == FL_ERASING && shared->erasing
932 && shared->erasing->oldstate == FL_ERASING) { 934 && shared->erasing->oldstate == FL_ERASING) {
933 spin_unlock(&shared->lock); 935 mutex_unlock(&shared->lock);
934 set_current_state(TASK_UNINTERRUPTIBLE); 936 set_current_state(TASK_UNINTERRUPTIBLE);
935 add_wait_queue(&chip->wq, &wait); 937 add_wait_queue(&chip->wq, &wait);
936 mutex_unlock(&chip->mutex); 938 mutex_unlock(&chip->mutex);
@@ -944,7 +946,7 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr
944 shared->writing = chip; 946 shared->writing = chip;
945 if (mode == FL_ERASING) 947 if (mode == FL_ERASING)
946 shared->erasing = chip; 948 shared->erasing = chip;
947 spin_unlock(&shared->lock); 949 mutex_unlock(&shared->lock);
948 } 950 }
949 ret = chip_ready(map, chip, adr, mode); 951 ret = chip_ready(map, chip, adr, mode);
950 if (ret == -EAGAIN) 952 if (ret == -EAGAIN)
@@ -959,7 +961,7 @@ static void put_chip(struct map_info *map, struct flchip *chip, unsigned long ad
959 961
960 if (chip->priv) { 962 if (chip->priv) {
961 struct flchip_shared *shared = chip->priv; 963 struct flchip_shared *shared = chip->priv;
962 spin_lock(&shared->lock); 964 mutex_lock(&shared->lock);
963 if (shared->writing == chip && chip->oldstate == FL_READY) { 965 if (shared->writing == chip && chip->oldstate == FL_READY) {
964 /* We own the ability to write, but we're done */ 966 /* We own the ability to write, but we're done */
965 shared->writing = shared->erasing; 967 shared->writing = shared->erasing;
@@ -967,7 +969,7 @@ static void put_chip(struct map_info *map, struct flchip *chip, unsigned long ad
967 /* give back ownership to who we loaned it from */ 969 /* give back ownership to who we loaned it from */
968 struct flchip *loaner = shared->writing; 970 struct flchip *loaner = shared->writing;
969 mutex_lock(&loaner->mutex); 971 mutex_lock(&loaner->mutex);
970 spin_unlock(&shared->lock); 972 mutex_unlock(&shared->lock);
971 mutex_unlock(&chip->mutex); 973 mutex_unlock(&chip->mutex);
972 put_chip(map, loaner, loaner->start); 974 put_chip(map, loaner, loaner->start);
973 mutex_lock(&chip->mutex); 975 mutex_lock(&chip->mutex);
@@ -985,11 +987,11 @@ static void put_chip(struct map_info *map, struct flchip *chip, unsigned long ad
985 * Don't let the switch below mess things up since 987 * Don't let the switch below mess things up since
986 * we don't have ownership to resume anything. 988 * we don't have ownership to resume anything.
987 */ 989 */
988 spin_unlock(&shared->lock); 990 mutex_unlock(&shared->lock);
989 wake_up(&chip->wq); 991 wake_up(&chip->wq);
990 return; 992 return;
991 } 993 }
992 spin_unlock(&shared->lock); 994 mutex_unlock(&shared->lock);
993 } 995 }
994 996
995 switch(chip->oldstate) { 997 switch(chip->oldstate) {
@@ -2139,6 +2141,13 @@ static int cfi_intelext_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
2139 return ret; 2141 return ret;
2140} 2142}
2141 2143
2144static int cfi_intelext_is_locked(struct mtd_info *mtd, loff_t ofs,
2145 uint64_t len)
2146{
2147 return cfi_varsize_frob(mtd, do_getlockstatus_oneblock,
2148 ofs, len, NULL) ? 1 : 0;
2149}
2150
2142#ifdef CONFIG_MTD_OTP 2151#ifdef CONFIG_MTD_OTP
2143 2152
2144typedef int (*otp_op_t)(struct map_info *map, struct flchip *chip, 2153typedef int (*otp_op_t)(struct map_info *map, struct flchip *chip,
diff --git a/drivers/mtd/chips/cfi_cmdset_0002.c b/drivers/mtd/chips/cfi_cmdset_0002.c
index d81079ef91a5..3e6c47bdce53 100644
--- a/drivers/mtd/chips/cfi_cmdset_0002.c
+++ b/drivers/mtd/chips/cfi_cmdset_0002.c
@@ -33,7 +33,6 @@
33#include <linux/delay.h> 33#include <linux/delay.h>
34#include <linux/interrupt.h> 34#include <linux/interrupt.h>
35#include <linux/reboot.h> 35#include <linux/reboot.h>
36#include <linux/mtd/compatmac.h>
37#include <linux/mtd/map.h> 36#include <linux/mtd/map.h>
38#include <linux/mtd/mtd.h> 37#include <linux/mtd/mtd.h>
39#include <linux/mtd/cfi.h> 38#include <linux/mtd/cfi.h>
@@ -417,16 +416,26 @@ struct mtd_info *cfi_cmdset_0002(struct map_info *map, int primary)
417 */ 416 */
418 cfi_fixup_major_minor(cfi, extp); 417 cfi_fixup_major_minor(cfi, extp);
419 418
419 /*
420 * Valid primary extension versions are: 1.0, 1.1, 1.2, 1.3, 1.4
421 * see: http://www.amd.com/us-en/assets/content_type/DownloadableAssets/cfi_r20.pdf, page 19
422 * http://www.amd.com/us-en/assets/content_type/DownloadableAssets/cfi_100_20011201.pdf
423 * http://www.spansion.com/Support/Datasheets/s29ws-p_00_a12_e.pdf
424 */
420 if (extp->MajorVersion != '1' || 425 if (extp->MajorVersion != '1' ||
421 (extp->MinorVersion < '0' || extp->MinorVersion > '4')) { 426 (extp->MajorVersion == '1' && (extp->MinorVersion < '0' || extp->MinorVersion > '4'))) {
422 printk(KERN_ERR " Unknown Amd/Fujitsu Extended Query " 427 printk(KERN_ERR " Unknown Amd/Fujitsu Extended Query "
423 "version %c.%c.\n", extp->MajorVersion, 428 "version %c.%c (%#02x/%#02x).\n",
424 extp->MinorVersion); 429 extp->MajorVersion, extp->MinorVersion,
430 extp->MajorVersion, extp->MinorVersion);
425 kfree(extp); 431 kfree(extp);
426 kfree(mtd); 432 kfree(mtd);
427 return NULL; 433 return NULL;
428 } 434 }
429 435
436 printk(KERN_INFO " Amd/Fujitsu Extended Query version %c.%c.\n",
437 extp->MajorVersion, extp->MinorVersion);
438
430 /* Install our own private info structure */ 439 /* Install our own private info structure */
431 cfi->cmdset_priv = extp; 440 cfi->cmdset_priv = extp;
432 441
diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
index e54e8c169d76..314af1f5a370 100644
--- a/drivers/mtd/chips/cfi_cmdset_0020.c
+++ b/drivers/mtd/chips/cfi_cmdset_0020.c
@@ -33,7 +33,6 @@
33#include <linux/mtd/map.h> 33#include <linux/mtd/map.h>
34#include <linux/mtd/cfi.h> 34#include <linux/mtd/cfi.h>
35#include <linux/mtd/mtd.h> 35#include <linux/mtd/mtd.h>
36#include <linux/mtd/compatmac.h>
37 36
38 37
39static int cfi_staa_read(struct mtd_info *, loff_t, size_t, size_t *, u_char *); 38static int cfi_staa_read(struct mtd_info *, loff_t, size_t, size_t *, u_char *);
diff --git a/drivers/mtd/chips/cfi_probe.c b/drivers/mtd/chips/cfi_probe.c
index b2acd32f4fbf..8f5b96aa87a0 100644
--- a/drivers/mtd/chips/cfi_probe.c
+++ b/drivers/mtd/chips/cfi_probe.c
@@ -235,9 +235,9 @@ static int __xipram cfi_chip_setup(struct map_info *map,
235 cfi_qry_mode_off(base, map, cfi); 235 cfi_qry_mode_off(base, map, cfi);
236 xip_allowed(base, map); 236 xip_allowed(base, map);
237 237
238 printk(KERN_INFO "%s: Found %d x%d devices at 0x%x in %d-bit bank\n", 238 printk(KERN_INFO "%s: Found %d x%d devices at 0x%x in %d-bit bank. Manufacturer ID %#08x Chip ID %#08x\n",
239 map->name, cfi->interleave, cfi->device_type*8, base, 239 map->name, cfi->interleave, cfi->device_type*8, base,
240 map->bankwidth*8); 240 map->bankwidth*8, cfi->mfr, cfi->id);
241 241
242 return 1; 242 return 1;
243} 243}
diff --git a/drivers/mtd/chips/cfi_util.c b/drivers/mtd/chips/cfi_util.c
index d7c2c672757e..e503b2ca894d 100644
--- a/drivers/mtd/chips/cfi_util.c
+++ b/drivers/mtd/chips/cfi_util.c
@@ -22,7 +22,6 @@
22#include <linux/mtd/mtd.h> 22#include <linux/mtd/mtd.h>
23#include <linux/mtd/map.h> 23#include <linux/mtd/map.h>
24#include <linux/mtd/cfi.h> 24#include <linux/mtd/cfi.h>
25#include <linux/mtd/compatmac.h>
26 25
27int __xipram cfi_qry_present(struct map_info *map, __u32 base, 26int __xipram cfi_qry_present(struct map_info *map, __u32 base,
28 struct cfi_private *cfi) 27 struct cfi_private *cfi)
diff --git a/drivers/mtd/chips/chipreg.c b/drivers/mtd/chips/chipreg.c
index c85760968227..da1f96f385c7 100644
--- a/drivers/mtd/chips/chipreg.c
+++ b/drivers/mtd/chips/chipreg.c
@@ -10,7 +10,6 @@
10#include <linux/slab.h> 10#include <linux/slab.h>
11#include <linux/mtd/map.h> 11#include <linux/mtd/map.h>
12#include <linux/mtd/mtd.h> 12#include <linux/mtd/mtd.h>
13#include <linux/mtd/compatmac.h>
14 13
15static DEFINE_SPINLOCK(chip_drvs_lock); 14static DEFINE_SPINLOCK(chip_drvs_lock);
16static LIST_HEAD(chip_drvs_list); 15static LIST_HEAD(chip_drvs_list);
diff --git a/drivers/mtd/chips/map_absent.c b/drivers/mtd/chips/map_absent.c
index 494d30d0631a..f2b872946871 100644
--- a/drivers/mtd/chips/map_absent.c
+++ b/drivers/mtd/chips/map_absent.c
@@ -25,7 +25,6 @@
25#include <linux/init.h> 25#include <linux/init.h>
26#include <linux/mtd/mtd.h> 26#include <linux/mtd/mtd.h>
27#include <linux/mtd/map.h> 27#include <linux/mtd/map.h>
28#include <linux/mtd/compatmac.h>
29 28
30static int map_absent_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *); 29static int map_absent_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
31static int map_absent_write (struct mtd_info *, loff_t, size_t, size_t *, const u_char *); 30static int map_absent_write (struct mtd_info *, loff_t, size_t, size_t *, const u_char *);
diff --git a/drivers/mtd/chips/map_ram.c b/drivers/mtd/chips/map_ram.c
index 6bdc50c727e7..67640ccb2d41 100644
--- a/drivers/mtd/chips/map_ram.c
+++ b/drivers/mtd/chips/map_ram.c
@@ -13,7 +13,6 @@
13#include <linux/init.h> 13#include <linux/init.h>
14#include <linux/mtd/mtd.h> 14#include <linux/mtd/mtd.h>
15#include <linux/mtd/map.h> 15#include <linux/mtd/map.h>
16#include <linux/mtd/compatmac.h>
17 16
18 17
19static int mapram_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *); 18static int mapram_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
diff --git a/drivers/mtd/chips/map_rom.c b/drivers/mtd/chips/map_rom.c
index 076090a67b90..593f73d480d2 100644
--- a/drivers/mtd/chips/map_rom.c
+++ b/drivers/mtd/chips/map_rom.c
@@ -13,7 +13,6 @@
13#include <linux/init.h> 13#include <linux/init.h>
14#include <linux/mtd/mtd.h> 14#include <linux/mtd/mtd.h>
15#include <linux/mtd/map.h> 15#include <linux/mtd/map.h>
16#include <linux/mtd/compatmac.h>
17 16
18static int maprom_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *); 17static int maprom_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
19static int maprom_write (struct mtd_info *, loff_t, size_t, size_t *, const u_char *); 18static int maprom_write (struct mtd_info *, loff_t, size_t, size_t *, const u_char *);
diff --git a/drivers/mtd/cmdlinepart.c b/drivers/mtd/cmdlinepart.c
index 1479da6d3aa6..e790f38893b0 100644
--- a/drivers/mtd/cmdlinepart.c
+++ b/drivers/mtd/cmdlinepart.c
@@ -1,7 +1,22 @@
1/* 1/*
2 * Read flash partition table from command line 2 * Read flash partition table from command line
3 * 3 *
4 * Copyright 2002 SYSGO Real-Time Solutions GmbH 4 * Copyright © 2002 SYSGO Real-Time Solutions GmbH
5 * Copyright © 2002-2010 David Woodhouse <dwmw2@infradead.org>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
5 * 20 *
6 * The format for the command line is as follows: 21 * The format for the command line is as follows:
7 * 22 *
diff --git a/drivers/mtd/devices/docecc.c b/drivers/mtd/devices/docecc.c
index a19cda52da5c..a99838bb2dc0 100644
--- a/drivers/mtd/devices/docecc.c
+++ b/drivers/mtd/devices/docecc.c
@@ -31,7 +31,6 @@
31#include <linux/init.h> 31#include <linux/init.h>
32#include <linux/types.h> 32#include <linux/types.h>
33 33
34#include <linux/mtd/compatmac.h> /* for min() in older kernels */
35#include <linux/mtd/mtd.h> 34#include <linux/mtd/mtd.h>
36#include <linux/mtd/doc2000.h> 35#include <linux/mtd/doc2000.h>
37 36
diff --git a/drivers/mtd/devices/docprobe.c b/drivers/mtd/devices/docprobe.c
index 6e62922942b1..d374603493a7 100644
--- a/drivers/mtd/devices/docprobe.c
+++ b/drivers/mtd/devices/docprobe.c
@@ -49,7 +49,6 @@
49#include <linux/mtd/mtd.h> 49#include <linux/mtd/mtd.h>
50#include <linux/mtd/nand.h> 50#include <linux/mtd/nand.h>
51#include <linux/mtd/doc2000.h> 51#include <linux/mtd/doc2000.h>
52#include <linux/mtd/compatmac.h>
53 52
54/* Where to look for the devices? */ 53/* Where to look for the devices? */
55#ifndef CONFIG_MTD_DOCPROBE_ADDRESS 54#ifndef CONFIG_MTD_DOCPROBE_ADDRESS
diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c
index 81e49a9b017e..6f512b5c117b 100644
--- a/drivers/mtd/devices/m25p80.c
+++ b/drivers/mtd/devices/m25p80.c
@@ -16,6 +16,8 @@
16 */ 16 */
17 17
18#include <linux/init.h> 18#include <linux/init.h>
19#include <linux/err.h>
20#include <linux/errno.h>
19#include <linux/module.h> 21#include <linux/module.h>
20#include <linux/device.h> 22#include <linux/device.h>
21#include <linux/interrupt.h> 23#include <linux/interrupt.h>
@@ -345,8 +347,7 @@ static int m25p80_read(struct mtd_info *mtd, loff_t from, size_t len,
345 spi_message_add_tail(&t[1], &m); 347 spi_message_add_tail(&t[1], &m);
346 348
347 /* Byte count starts at zero. */ 349 /* Byte count starts at zero. */
348 if (retlen) 350 *retlen = 0;
349 *retlen = 0;
350 351
351 mutex_lock(&flash->lock); 352 mutex_lock(&flash->lock);
352 353
@@ -392,8 +393,7 @@ static int m25p80_write(struct mtd_info *mtd, loff_t to, size_t len,
392 dev_name(&flash->spi->dev), __func__, "to", 393 dev_name(&flash->spi->dev), __func__, "to",
393 (u32)to, len); 394 (u32)to, len);
394 395
395 if (retlen) 396 *retlen = 0;
396 *retlen = 0;
397 397
398 /* sanity checks */ 398 /* sanity checks */
399 if (!len) 399 if (!len)
@@ -464,8 +464,7 @@ static int m25p80_write(struct mtd_info *mtd, loff_t to, size_t len,
464 464
465 spi_sync(flash->spi, &m); 465 spi_sync(flash->spi, &m);
466 466
467 if (retlen) 467 *retlen += m.actual_length - m25p_cmdsz(flash);
468 *retlen += m.actual_length - m25p_cmdsz(flash);
469 } 468 }
470 } 469 }
471 470
@@ -483,8 +482,7 @@ static int sst_write(struct mtd_info *mtd, loff_t to, size_t len,
483 size_t actual; 482 size_t actual;
484 int cmd_sz, ret; 483 int cmd_sz, ret;
485 484
486 if (retlen) 485 *retlen = 0;
487 *retlen = 0;
488 486
489 /* sanity checks */ 487 /* sanity checks */
490 if (!len) 488 if (!len)
@@ -639,8 +637,18 @@ static const struct spi_device_id m25p_ids[] = {
639 { "at26df161a", INFO(0x1f4601, 0, 64 * 1024, 32, SECT_4K) }, 637 { "at26df161a", INFO(0x1f4601, 0, 64 * 1024, 32, SECT_4K) },
640 { "at26df321", INFO(0x1f4701, 0, 64 * 1024, 64, SECT_4K) }, 638 { "at26df321", INFO(0x1f4701, 0, 64 * 1024, 64, SECT_4K) },
641 639
640 /* EON -- en25pxx */
641 { "en25p32", INFO(0x1c2016, 0, 64 * 1024, 64, 0) },
642 { "en25p64", INFO(0x1c2017, 0, 64 * 1024, 128, 0) },
643
644 /* Intel/Numonyx -- xxxs33b */
645 { "160s33b", INFO(0x898911, 0, 64 * 1024, 32, 0) },
646 { "320s33b", INFO(0x898912, 0, 64 * 1024, 64, 0) },
647 { "640s33b", INFO(0x898913, 0, 64 * 1024, 128, 0) },
648
642 /* Macronix */ 649 /* Macronix */
643 { "mx25l4005a", INFO(0xc22013, 0, 64 * 1024, 8, SECT_4K) }, 650 { "mx25l4005a", INFO(0xc22013, 0, 64 * 1024, 8, SECT_4K) },
651 { "mx25l8005", INFO(0xc22014, 0, 64 * 1024, 16, 0) },
644 { "mx25l3205d", INFO(0xc22016, 0, 64 * 1024, 64, 0) }, 652 { "mx25l3205d", INFO(0xc22016, 0, 64 * 1024, 64, 0) },
645 { "mx25l6405d", INFO(0xc22017, 0, 64 * 1024, 128, 0) }, 653 { "mx25l6405d", INFO(0xc22017, 0, 64 * 1024, 128, 0) },
646 { "mx25l12805d", INFO(0xc22018, 0, 64 * 1024, 256, 0) }, 654 { "mx25l12805d", INFO(0xc22018, 0, 64 * 1024, 256, 0) },
@@ -680,6 +688,16 @@ static const struct spi_device_id m25p_ids[] = {
680 { "m25p64", INFO(0x202017, 0, 64 * 1024, 128, 0) }, 688 { "m25p64", INFO(0x202017, 0, 64 * 1024, 128, 0) },
681 { "m25p128", INFO(0x202018, 0, 256 * 1024, 64, 0) }, 689 { "m25p128", INFO(0x202018, 0, 256 * 1024, 64, 0) },
682 690
691 { "m25p05-nonjedec", INFO(0, 0, 32 * 1024, 2, 0) },
692 { "m25p10-nonjedec", INFO(0, 0, 32 * 1024, 4, 0) },
693 { "m25p20-nonjedec", INFO(0, 0, 64 * 1024, 4, 0) },
694 { "m25p40-nonjedec", INFO(0, 0, 64 * 1024, 8, 0) },
695 { "m25p80-nonjedec", INFO(0, 0, 64 * 1024, 16, 0) },
696 { "m25p16-nonjedec", INFO(0, 0, 64 * 1024, 32, 0) },
697 { "m25p32-nonjedec", INFO(0, 0, 64 * 1024, 64, 0) },
698 { "m25p64-nonjedec", INFO(0, 0, 64 * 1024, 128, 0) },
699 { "m25p128-nonjedec", INFO(0, 0, 256 * 1024, 64, 0) },
700
683 { "m45pe10", INFO(0x204011, 0, 64 * 1024, 2, 0) }, 701 { "m45pe10", INFO(0x204011, 0, 64 * 1024, 2, 0) },
684 { "m45pe80", INFO(0x204014, 0, 64 * 1024, 16, 0) }, 702 { "m45pe80", INFO(0x204014, 0, 64 * 1024, 16, 0) },
685 { "m45pe16", INFO(0x204015, 0, 64 * 1024, 32, 0) }, 703 { "m45pe16", INFO(0x204015, 0, 64 * 1024, 32, 0) },
@@ -694,6 +712,7 @@ static const struct spi_device_id m25p_ids[] = {
694 { "w25x80", INFO(0xef3014, 0, 64 * 1024, 16, SECT_4K) }, 712 { "w25x80", INFO(0xef3014, 0, 64 * 1024, 16, SECT_4K) },
695 { "w25x16", INFO(0xef3015, 0, 64 * 1024, 32, SECT_4K) }, 713 { "w25x16", INFO(0xef3015, 0, 64 * 1024, 32, SECT_4K) },
696 { "w25x32", INFO(0xef3016, 0, 64 * 1024, 64, SECT_4K) }, 714 { "w25x32", INFO(0xef3016, 0, 64 * 1024, 64, SECT_4K) },
715 { "w25q32", INFO(0xef4016, 0, 64 * 1024, 64, SECT_4K) },
697 { "w25x64", INFO(0xef3017, 0, 64 * 1024, 128, SECT_4K) }, 716 { "w25x64", INFO(0xef3017, 0, 64 * 1024, 128, SECT_4K) },
698 717
699 /* Catalyst / On Semiconductor -- non-JEDEC */ 718 /* Catalyst / On Semiconductor -- non-JEDEC */
@@ -723,7 +742,7 @@ static const struct spi_device_id *__devinit jedec_probe(struct spi_device *spi)
723 if (tmp < 0) { 742 if (tmp < 0) {
724 DEBUG(MTD_DEBUG_LEVEL0, "%s: error %d reading JEDEC ID\n", 743 DEBUG(MTD_DEBUG_LEVEL0, "%s: error %d reading JEDEC ID\n",
725 dev_name(&spi->dev), tmp); 744 dev_name(&spi->dev), tmp);
726 return NULL; 745 return ERR_PTR(tmp);
727 } 746 }
728 jedec = id[0]; 747 jedec = id[0];
729 jedec = jedec << 8; 748 jedec = jedec << 8;
@@ -731,14 +750,6 @@ static const struct spi_device_id *__devinit jedec_probe(struct spi_device *spi)
731 jedec = jedec << 8; 750 jedec = jedec << 8;
732 jedec |= id[2]; 751 jedec |= id[2];
733 752
734 /*
735 * Some chips (like Numonyx M25P80) have JEDEC and non-JEDEC variants,
736 * which depend on technology process. Officially RDID command doesn't
737 * exist for non-JEDEC chips, but for compatibility they return ID 0.
738 */
739 if (jedec == 0)
740 return NULL;
741
742 ext_jedec = id[3] << 8 | id[4]; 753 ext_jedec = id[3] << 8 | id[4];
743 754
744 for (tmp = 0; tmp < ARRAY_SIZE(m25p_ids) - 1; tmp++) { 755 for (tmp = 0; tmp < ARRAY_SIZE(m25p_ids) - 1; tmp++) {
@@ -749,7 +760,7 @@ static const struct spi_device_id *__devinit jedec_probe(struct spi_device *spi)
749 return &m25p_ids[tmp]; 760 return &m25p_ids[tmp];
750 } 761 }
751 } 762 }
752 return NULL; 763 return ERR_PTR(-ENODEV);
753} 764}
754 765
755 766
@@ -782,7 +793,7 @@ static int __devinit m25p_probe(struct spi_device *spi)
782 break; 793 break;
783 } 794 }
784 795
785 if (plat_id) 796 if (i < ARRAY_SIZE(m25p_ids) - 1)
786 id = plat_id; 797 id = plat_id;
787 else 798 else
788 dev_warn(&spi->dev, "unrecognized id %s\n", data->type); 799 dev_warn(&spi->dev, "unrecognized id %s\n", data->type);
@@ -794,9 +805,8 @@ static int __devinit m25p_probe(struct spi_device *spi)
794 const struct spi_device_id *jid; 805 const struct spi_device_id *jid;
795 806
796 jid = jedec_probe(spi); 807 jid = jedec_probe(spi);
797 if (!jid) { 808 if (IS_ERR(jid)) {
798 dev_info(&spi->dev, "non-JEDEC variant of %s\n", 809 return PTR_ERR(jid);
799 id->name);
800 } else if (jid != id) { 810 } else if (jid != id) {
801 /* 811 /*
802 * JEDEC knows better, so overwrite platform ID. We 812 * JEDEC knows better, so overwrite platform ID. We
@@ -826,11 +836,12 @@ static int __devinit m25p_probe(struct spi_device *spi)
826 dev_set_drvdata(&spi->dev, flash); 836 dev_set_drvdata(&spi->dev, flash);
827 837
828 /* 838 /*
829 * Atmel and SST serial flash tend to power 839 * Atmel, SST and Intel/Numonyx serial flash tend to power
830 * up with the software protection bits set 840 * up with the software protection bits set
831 */ 841 */
832 842
833 if (info->jedec_id >> 16 == 0x1f || 843 if (info->jedec_id >> 16 == 0x1f ||
844 info->jedec_id >> 16 == 0x89 ||
834 info->jedec_id >> 16 == 0xbf) { 845 info->jedec_id >> 16 == 0xbf) {
835 write_enable(flash); 846 write_enable(flash);
836 write_sr(flash, 0); 847 write_sr(flash, 0);
diff --git a/drivers/mtd/devices/mtd_dataflash.c b/drivers/mtd/devices/mtd_dataflash.c
index 19817404ce7d..c5015cc721d5 100644
--- a/drivers/mtd/devices/mtd_dataflash.c
+++ b/drivers/mtd/devices/mtd_dataflash.c
@@ -141,7 +141,7 @@ static int dataflash_waitready(struct spi_device *spi)
141 */ 141 */
142static int dataflash_erase(struct mtd_info *mtd, struct erase_info *instr) 142static int dataflash_erase(struct mtd_info *mtd, struct erase_info *instr)
143{ 143{
144 struct dataflash *priv = (struct dataflash *)mtd->priv; 144 struct dataflash *priv = mtd->priv;
145 struct spi_device *spi = priv->spi; 145 struct spi_device *spi = priv->spi;
146 struct spi_transfer x = { .tx_dma = 0, }; 146 struct spi_transfer x = { .tx_dma = 0, };
147 struct spi_message msg; 147 struct spi_message msg;
@@ -231,7 +231,7 @@ static int dataflash_erase(struct mtd_info *mtd, struct erase_info *instr)
231static int dataflash_read(struct mtd_info *mtd, loff_t from, size_t len, 231static int dataflash_read(struct mtd_info *mtd, loff_t from, size_t len,
232 size_t *retlen, u_char *buf) 232 size_t *retlen, u_char *buf)
233{ 233{
234 struct dataflash *priv = (struct dataflash *)mtd->priv; 234 struct dataflash *priv = mtd->priv;
235 struct spi_transfer x[2] = { { .tx_dma = 0, }, }; 235 struct spi_transfer x[2] = { { .tx_dma = 0, }, };
236 struct spi_message msg; 236 struct spi_message msg;
237 unsigned int addr; 237 unsigned int addr;
@@ -304,7 +304,7 @@ static int dataflash_read(struct mtd_info *mtd, loff_t from, size_t len,
304static int dataflash_write(struct mtd_info *mtd, loff_t to, size_t len, 304static int dataflash_write(struct mtd_info *mtd, loff_t to, size_t len,
305 size_t * retlen, const u_char * buf) 305 size_t * retlen, const u_char * buf)
306{ 306{
307 struct dataflash *priv = (struct dataflash *)mtd->priv; 307 struct dataflash *priv = mtd->priv;
308 struct spi_device *spi = priv->spi; 308 struct spi_device *spi = priv->spi;
309 struct spi_transfer x[2] = { { .tx_dma = 0, }, }; 309 struct spi_transfer x[2] = { { .tx_dma = 0, }, };
310 struct spi_message msg; 310 struct spi_message msg;
@@ -515,7 +515,7 @@ static ssize_t otp_read(struct spi_device *spi, unsigned base,
515static int dataflash_read_fact_otp(struct mtd_info *mtd, 515static int dataflash_read_fact_otp(struct mtd_info *mtd,
516 loff_t from, size_t len, size_t *retlen, u_char *buf) 516 loff_t from, size_t len, size_t *retlen, u_char *buf)
517{ 517{
518 struct dataflash *priv = (struct dataflash *)mtd->priv; 518 struct dataflash *priv = mtd->priv;
519 int status; 519 int status;
520 520
521 /* 64 bytes, from 0..63 ... start at 64 on-chip */ 521 /* 64 bytes, from 0..63 ... start at 64 on-chip */
@@ -532,7 +532,7 @@ static int dataflash_read_fact_otp(struct mtd_info *mtd,
532static int dataflash_read_user_otp(struct mtd_info *mtd, 532static int dataflash_read_user_otp(struct mtd_info *mtd,
533 loff_t from, size_t len, size_t *retlen, u_char *buf) 533 loff_t from, size_t len, size_t *retlen, u_char *buf)
534{ 534{
535 struct dataflash *priv = (struct dataflash *)mtd->priv; 535 struct dataflash *priv = mtd->priv;
536 int status; 536 int status;
537 537
538 /* 64 bytes, from 0..63 ... start at 0 on-chip */ 538 /* 64 bytes, from 0..63 ... start at 0 on-chip */
@@ -553,7 +553,7 @@ static int dataflash_write_user_otp(struct mtd_info *mtd,
553 const size_t l = 4 + 64; 553 const size_t l = 4 + 64;
554 uint8_t *scratch; 554 uint8_t *scratch;
555 struct spi_transfer t; 555 struct spi_transfer t;
556 struct dataflash *priv = (struct dataflash *)mtd->priv; 556 struct dataflash *priv = mtd->priv;
557 int status; 557 int status;
558 558
559 if (len > 64) 559 if (len > 64)
diff --git a/drivers/mtd/devices/mtdram.c b/drivers/mtd/devices/mtdram.c
index fce5ff7589aa..26a6e809013d 100644
--- a/drivers/mtd/devices/mtdram.c
+++ b/drivers/mtd/devices/mtdram.c
@@ -14,7 +14,6 @@
14#include <linux/ioport.h> 14#include <linux/ioport.h>
15#include <linux/vmalloc.h> 15#include <linux/vmalloc.h>
16#include <linux/init.h> 16#include <linux/init.h>
17#include <linux/mtd/compatmac.h>
18#include <linux/mtd/mtd.h> 17#include <linux/mtd/mtd.h>
19#include <linux/mtd/mtdram.h> 18#include <linux/mtd/mtdram.h>
20 19
diff --git a/drivers/mtd/devices/pmc551.c b/drivers/mtd/devices/pmc551.c
index fc8ea0a57ac2..ef0aba0ce58f 100644
--- a/drivers/mtd/devices/pmc551.c
+++ b/drivers/mtd/devices/pmc551.c
@@ -98,7 +98,6 @@
98 98
99#include <linux/mtd/mtd.h> 99#include <linux/mtd/mtd.h>
100#include <linux/mtd/pmc551.h> 100#include <linux/mtd/pmc551.h>
101#include <linux/mtd/compatmac.h>
102 101
103static struct mtd_info *pmc551list; 102static struct mtd_info *pmc551list;
104 103
diff --git a/drivers/mtd/devices/sst25l.c b/drivers/mtd/devices/sst25l.c
index ab5d8cd02a15..684247a8a5ed 100644
--- a/drivers/mtd/devices/sst25l.c
+++ b/drivers/mtd/devices/sst25l.c
@@ -454,7 +454,7 @@ static int __init sst25l_probe(struct spi_device *spi)
454 parts, nr_parts); 454 parts, nr_parts);
455 } 455 }
456 456
457 } else if (data->nr_parts) { 457 } else if (data && data->nr_parts) {
458 dev_warn(&spi->dev, "ignoring %d default partitions on %s\n", 458 dev_warn(&spi->dev, "ignoring %d default partitions on %s\n",
459 data->nr_parts, data->name); 459 data->nr_parts, data->name);
460 } 460 }
diff --git a/drivers/mtd/ftl.c b/drivers/mtd/ftl.c
index 62da9eb7032b..4d6a64c387ec 100644
--- a/drivers/mtd/ftl.c
+++ b/drivers/mtd/ftl.c
@@ -26,7 +26,7 @@
26 26
27 The initial developer of the original code is David A. Hinds 27 The initial developer of the original code is David A. Hinds
28 <dahinds@users.sourceforge.net>. Portions created by David A. Hinds 28 <dahinds@users.sourceforge.net>. Portions created by David A. Hinds
29 are Copyright (C) 1999 David A. Hinds. All Rights Reserved. 29 are Copyright © 1999 David A. Hinds. All Rights Reserved.
30 30
31 Alternatively, the contents of this file may be used under the 31 Alternatively, the contents of this file may be used under the
32 terms of the GNU General Public License version 2 (the "GPL"), in 32 terms of the GNU General Public License version 2 (the "GPL"), in
diff --git a/drivers/mtd/inftlcore.c b/drivers/mtd/inftlcore.c
index 015a7fe1b6ee..d7592e67d048 100644
--- a/drivers/mtd/inftlcore.c
+++ b/drivers/mtd/inftlcore.c
@@ -1,11 +1,11 @@
1/* 1/*
2 * inftlcore.c -- Linux driver for Inverse Flash Translation Layer (INFTL) 2 * inftlcore.c -- Linux driver for Inverse Flash Translation Layer (INFTL)
3 * 3 *
4 * (C) Copyright 2002, Greg Ungerer (gerg@snapgear.com) 4 * Copyright © 2002, Greg Ungerer (gerg@snapgear.com)
5 * 5 *
6 * Based heavily on the nftlcore.c code which is: 6 * Based heavily on the nftlcore.c code which is:
7 * (c) 1999 Machine Vision Holdings, Inc. 7 * Copyright © 1999 Machine Vision Holdings, Inc.
8 * Author: David Woodhouse <dwmw2@infradead.org> 8 * Copyright © 1999 David Woodhouse <dwmw2@infradead.org>
9 * 9 *
10 * This program is free software; you can redistribute it and/or modify 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 11 * it under the terms of the GNU General Public License as published by
diff --git a/drivers/mtd/inftlmount.c b/drivers/mtd/inftlmount.c
index 8f988d7d3c5c..104052e774b0 100644
--- a/drivers/mtd/inftlmount.c
+++ b/drivers/mtd/inftlmount.c
@@ -2,11 +2,11 @@
2 * inftlmount.c -- INFTL mount code with extensive checks. 2 * inftlmount.c -- INFTL mount code with extensive checks.
3 * 3 *
4 * Author: Greg Ungerer (gerg@snapgear.com) 4 * Author: Greg Ungerer (gerg@snapgear.com)
5 * (C) Copyright 2002-2003, Greg Ungerer (gerg@snapgear.com) 5 * Copyright © 2002-2003, Greg Ungerer (gerg@snapgear.com)
6 * 6 *
7 * Based heavily on the nftlmount.c code which is: 7 * Based heavily on the nftlmount.c code which is:
8 * Author: Fabrice Bellard (fabrice.bellard@netgem.com) 8 * Author: Fabrice Bellard (fabrice.bellard@netgem.com)
9 * Copyright (C) 2000 Netgem S.A. 9 * Copyright © 2000 Netgem S.A.
10 * 10 *
11 * This program is free software; you can redistribute it and/or modify 11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by 12 * it under the terms of the GNU General Public License as published by
@@ -34,7 +34,6 @@
34#include <linux/mtd/mtd.h> 34#include <linux/mtd/mtd.h>
35#include <linux/mtd/nftl.h> 35#include <linux/mtd/nftl.h>
36#include <linux/mtd/inftl.h> 36#include <linux/mtd/inftl.h>
37#include <linux/mtd/compatmac.h>
38 37
39/* 38/*
40 * find_boot_record: Find the INFTL Media Header and its Spare copy which 39 * find_boot_record: Find the INFTL Media Header and its Spare copy which
diff --git a/drivers/mtd/lpddr/lpddr_cmds.c b/drivers/mtd/lpddr/lpddr_cmds.c
index fece5be58715..04fdfcca93f7 100644
--- a/drivers/mtd/lpddr/lpddr_cmds.c
+++ b/drivers/mtd/lpddr/lpddr_cmds.c
@@ -98,7 +98,7 @@ struct mtd_info *lpddr_cmdset(struct map_info *map)
98 numchips = lpddr->numchips / lpddr->qinfo->HWPartsNum; 98 numchips = lpddr->numchips / lpddr->qinfo->HWPartsNum;
99 for (i = 0; i < numchips; i++) { 99 for (i = 0; i < numchips; i++) {
100 shared[i].writing = shared[i].erasing = NULL; 100 shared[i].writing = shared[i].erasing = NULL;
101 spin_lock_init(&shared[i].lock); 101 mutex_init(&shared[i].lock);
102 for (j = 0; j < lpddr->qinfo->HWPartsNum; j++) { 102 for (j = 0; j < lpddr->qinfo->HWPartsNum; j++) {
103 *chip = lpddr->chips[i]; 103 *chip = lpddr->chips[i];
104 chip->start += j << lpddr->chipshift; 104 chip->start += j << lpddr->chipshift;
@@ -217,7 +217,7 @@ static int get_chip(struct map_info *map, struct flchip *chip, int mode)
217 */ 217 */
218 struct flchip_shared *shared = chip->priv; 218 struct flchip_shared *shared = chip->priv;
219 struct flchip *contender; 219 struct flchip *contender;
220 spin_lock(&shared->lock); 220 mutex_lock(&shared->lock);
221 contender = shared->writing; 221 contender = shared->writing;
222 if (contender && contender != chip) { 222 if (contender && contender != chip) {
223 /* 223 /*
@@ -230,7 +230,7 @@ static int get_chip(struct map_info *map, struct flchip *chip, int mode)
230 * get_chip returns success we're clear to go ahead. 230 * get_chip returns success we're clear to go ahead.
231 */ 231 */
232 ret = mutex_trylock(&contender->mutex); 232 ret = mutex_trylock(&contender->mutex);
233 spin_unlock(&shared->lock); 233 mutex_unlock(&shared->lock);
234 if (!ret) 234 if (!ret)
235 goto retry; 235 goto retry;
236 mutex_unlock(&chip->mutex); 236 mutex_unlock(&chip->mutex);
@@ -245,7 +245,7 @@ static int get_chip(struct map_info *map, struct flchip *chip, int mode)
245 mutex_unlock(&contender->mutex); 245 mutex_unlock(&contender->mutex);
246 return ret; 246 return ret;
247 } 247 }
248 spin_lock(&shared->lock); 248 mutex_lock(&shared->lock);
249 249
250 /* We should not own chip if it is already in FL_SYNCING 250 /* We should not own chip if it is already in FL_SYNCING
251 * state. Put contender and retry. */ 251 * state. Put contender and retry. */
@@ -261,7 +261,7 @@ static int get_chip(struct map_info *map, struct flchip *chip, int mode)
261 Must sleep in such a case. */ 261 Must sleep in such a case. */
262 if (mode == FL_ERASING && shared->erasing 262 if (mode == FL_ERASING && shared->erasing
263 && shared->erasing->oldstate == FL_ERASING) { 263 && shared->erasing->oldstate == FL_ERASING) {
264 spin_unlock(&shared->lock); 264 mutex_unlock(&shared->lock);
265 set_current_state(TASK_UNINTERRUPTIBLE); 265 set_current_state(TASK_UNINTERRUPTIBLE);
266 add_wait_queue(&chip->wq, &wait); 266 add_wait_queue(&chip->wq, &wait);
267 mutex_unlock(&chip->mutex); 267 mutex_unlock(&chip->mutex);
@@ -275,7 +275,7 @@ static int get_chip(struct map_info *map, struct flchip *chip, int mode)
275 shared->writing = chip; 275 shared->writing = chip;
276 if (mode == FL_ERASING) 276 if (mode == FL_ERASING)
277 shared->erasing = chip; 277 shared->erasing = chip;
278 spin_unlock(&shared->lock); 278 mutex_unlock(&shared->lock);
279 } 279 }
280 280
281 ret = chip_ready(map, chip, mode); 281 ret = chip_ready(map, chip, mode);
@@ -348,7 +348,7 @@ static void put_chip(struct map_info *map, struct flchip *chip)
348{ 348{
349 if (chip->priv) { 349 if (chip->priv) {
350 struct flchip_shared *shared = chip->priv; 350 struct flchip_shared *shared = chip->priv;
351 spin_lock(&shared->lock); 351 mutex_lock(&shared->lock);
352 if (shared->writing == chip && chip->oldstate == FL_READY) { 352 if (shared->writing == chip && chip->oldstate == FL_READY) {
353 /* We own the ability to write, but we're done */ 353 /* We own the ability to write, but we're done */
354 shared->writing = shared->erasing; 354 shared->writing = shared->erasing;
@@ -356,7 +356,7 @@ static void put_chip(struct map_info *map, struct flchip *chip)
356 /* give back the ownership */ 356 /* give back the ownership */
357 struct flchip *loaner = shared->writing; 357 struct flchip *loaner = shared->writing;
358 mutex_lock(&loaner->mutex); 358 mutex_lock(&loaner->mutex);
359 spin_unlock(&shared->lock); 359 mutex_unlock(&shared->lock);
360 mutex_unlock(&chip->mutex); 360 mutex_unlock(&chip->mutex);
361 put_chip(map, loaner); 361 put_chip(map, loaner);
362 mutex_lock(&chip->mutex); 362 mutex_lock(&chip->mutex);
@@ -374,11 +374,11 @@ static void put_chip(struct map_info *map, struct flchip *chip)
374 * Don't let the switch below mess things up since 374 * Don't let the switch below mess things up since
375 * we don't have ownership to resume anything. 375 * we don't have ownership to resume anything.
376 */ 376 */
377 spin_unlock(&shared->lock); 377 mutex_unlock(&shared->lock);
378 wake_up(&chip->wq); 378 wake_up(&chip->wq);
379 return; 379 return;
380 } 380 }
381 spin_unlock(&shared->lock); 381 mutex_unlock(&shared->lock);
382 } 382 }
383 383
384 switch (chip->oldstate) { 384 switch (chip->oldstate) {
diff --git a/drivers/mtd/maps/Kconfig b/drivers/mtd/maps/Kconfig
index 6629d09f3b38..701d942c6795 100644
--- a/drivers/mtd/maps/Kconfig
+++ b/drivers/mtd/maps/Kconfig
@@ -319,14 +319,6 @@ config MTD_CFI_FLAGADM
319 Mapping for the Flaga digital module. If you don't have one, ignore 319 Mapping for the Flaga digital module. If you don't have one, ignore
320 this setting. 320 this setting.
321 321
322config MTD_REDWOOD
323 tristate "CFI Flash devices mapped on IBM Redwood"
324 depends on MTD_CFI
325 help
326 This enables access routines for the flash chips on the IBM
327 Redwood board. If you have one of these boards and would like to
328 use the flash chips on it, say 'Y'.
329
330config MTD_SOLUTIONENGINE 322config MTD_SOLUTIONENGINE
331 tristate "CFI Flash device mapped on Hitachi SolutionEngine" 323 tristate "CFI Flash device mapped on Hitachi SolutionEngine"
332 depends on SUPERH && SOLUTION_ENGINE && MTD_CFI && MTD_REDBOOT_PARTS 324 depends on SUPERH && SOLUTION_ENGINE && MTD_CFI && MTD_REDBOOT_PARTS
diff --git a/drivers/mtd/maps/Makefile b/drivers/mtd/maps/Makefile
index bb035cd54c72..f216bb573713 100644
--- a/drivers/mtd/maps/Makefile
+++ b/drivers/mtd/maps/Makefile
@@ -44,7 +44,6 @@ obj-$(CONFIG_MTD_AUTCPU12) += autcpu12-nvram.o
44obj-$(CONFIG_MTD_EDB7312) += edb7312.o 44obj-$(CONFIG_MTD_EDB7312) += edb7312.o
45obj-$(CONFIG_MTD_IMPA7) += impa7.o 45obj-$(CONFIG_MTD_IMPA7) += impa7.o
46obj-$(CONFIG_MTD_FORTUNET) += fortunet.o 46obj-$(CONFIG_MTD_FORTUNET) += fortunet.o
47obj-$(CONFIG_MTD_REDWOOD) += redwood.o
48obj-$(CONFIG_MTD_UCLINUX) += uclinux.o 47obj-$(CONFIG_MTD_UCLINUX) += uclinux.o
49obj-$(CONFIG_MTD_NETtel) += nettel.o 48obj-$(CONFIG_MTD_NETtel) += nettel.o
50obj-$(CONFIG_MTD_SCB2_FLASH) += scb2_flash.o 49obj-$(CONFIG_MTD_SCB2_FLASH) += scb2_flash.o
diff --git a/drivers/mtd/maps/ixp4xx.c b/drivers/mtd/maps/ixp4xx.c
index e0a5e0426ead..1f9fde0dad35 100644
--- a/drivers/mtd/maps/ixp4xx.c
+++ b/drivers/mtd/maps/ixp4xx.c
@@ -118,7 +118,7 @@ static void ixp4xx_copy_from(struct map_info *map, void *to,
118 *dest++ = BYTE1(data); 118 *dest++ = BYTE1(data);
119 src += 2; 119 src += 2;
120 len -= 2; 120 len -= 2;
121 } 121 }
122 122
123 if (len > 0) 123 if (len > 0)
124 *dest++ = BYTE0(flash_read16(src)); 124 *dest++ = BYTE0(flash_read16(src));
@@ -185,6 +185,8 @@ static int ixp4xx_flash_probe(struct platform_device *dev)
185{ 185{
186 struct flash_platform_data *plat = dev->dev.platform_data; 186 struct flash_platform_data *plat = dev->dev.platform_data;
187 struct ixp4xx_flash_info *info; 187 struct ixp4xx_flash_info *info;
188 const char *part_type = NULL;
189 int nr_parts = 0;
188 int err = -1; 190 int err = -1;
189 191
190 if (!plat) 192 if (!plat)
@@ -218,9 +220,9 @@ static int ixp4xx_flash_probe(struct platform_device *dev)
218 */ 220 */
219 info->map.bankwidth = 2; 221 info->map.bankwidth = 2;
220 info->map.name = dev_name(&dev->dev); 222 info->map.name = dev_name(&dev->dev);
221 info->map.read = ixp4xx_read16, 223 info->map.read = ixp4xx_read16;
222 info->map.write = ixp4xx_probe_write16, 224 info->map.write = ixp4xx_probe_write16;
223 info->map.copy_from = ixp4xx_copy_from, 225 info->map.copy_from = ixp4xx_copy_from;
224 226
225 info->res = request_mem_region(dev->resource->start, 227 info->res = request_mem_region(dev->resource->start,
226 resource_size(dev->resource), 228 resource_size(dev->resource),
@@ -248,11 +250,28 @@ static int ixp4xx_flash_probe(struct platform_device *dev)
248 info->mtd->owner = THIS_MODULE; 250 info->mtd->owner = THIS_MODULE;
249 251
250 /* Use the fast version */ 252 /* Use the fast version */
251 info->map.write = ixp4xx_write16, 253 info->map.write = ixp4xx_write16;
254
255#ifdef CONFIG_MTD_PARTITIONS
256 nr_parts = parse_mtd_partitions(info->mtd, probes, &info->partitions,
257 dev->resource->start);
258#endif
259 if (nr_parts > 0) {
260 part_type = "dynamic";
261 } else {
262 info->partitions = plat->parts;
263 nr_parts = plat->nr_parts;
264 part_type = "static";
265 }
266 if (nr_parts == 0) {
267 printk(KERN_NOTICE "IXP4xx flash: no partition info "
268 "available, registering whole flash\n");
269 err = add_mtd_device(info->mtd);
270 } else {
271 printk(KERN_NOTICE "IXP4xx flash: using %s partition "
272 "definition\n", part_type);
273 err = add_mtd_partitions(info->mtd, info->partitions, nr_parts);
252 274
253 err = parse_mtd_partitions(info->mtd, probes, &info->partitions, dev->resource->start);
254 if (err > 0) {
255 err = add_mtd_partitions(info->mtd, info->partitions, err);
256 if(err) 275 if(err)
257 printk(KERN_ERR "Could not parse partitions\n"); 276 printk(KERN_ERR "Could not parse partitions\n");
258 } 277 }
diff --git a/drivers/mtd/maps/physmap.c b/drivers/mtd/maps/physmap.c
index 426461a5f0d4..4c18b98a3110 100644
--- a/drivers/mtd/maps/physmap.c
+++ b/drivers/mtd/maps/physmap.c
@@ -106,12 +106,12 @@ static int physmap_flash_probe(struct platform_device *dev)
106 106
107 for (i = 0; i < dev->num_resources; i++) { 107 for (i = 0; i < dev->num_resources; i++) {
108 printk(KERN_NOTICE "physmap platform flash device: %.8llx at %.8llx\n", 108 printk(KERN_NOTICE "physmap platform flash device: %.8llx at %.8llx\n",
109 (unsigned long long)(dev->resource[i].end - dev->resource[i].start + 1), 109 (unsigned long long)resource_size(&dev->resource[i]),
110 (unsigned long long)dev->resource[i].start); 110 (unsigned long long)dev->resource[i].start);
111 111
112 if (!devm_request_mem_region(&dev->dev, 112 if (!devm_request_mem_region(&dev->dev,
113 dev->resource[i].start, 113 dev->resource[i].start,
114 dev->resource[i].end - dev->resource[i].start + 1, 114 resource_size(&dev->resource[i]),
115 dev_name(&dev->dev))) { 115 dev_name(&dev->dev))) {
116 dev_err(&dev->dev, "Could not reserve memory region\n"); 116 dev_err(&dev->dev, "Could not reserve memory region\n");
117 err = -ENOMEM; 117 err = -ENOMEM;
@@ -120,7 +120,7 @@ static int physmap_flash_probe(struct platform_device *dev)
120 120
121 info->map[i].name = dev_name(&dev->dev); 121 info->map[i].name = dev_name(&dev->dev);
122 info->map[i].phys = dev->resource[i].start; 122 info->map[i].phys = dev->resource[i].start;
123 info->map[i].size = dev->resource[i].end - dev->resource[i].start + 1; 123 info->map[i].size = resource_size(&dev->resource[i]);
124 info->map[i].bankwidth = physmap_data->width; 124 info->map[i].bankwidth = physmap_data->width;
125 info->map[i].set_vpp = physmap_data->set_vpp; 125 info->map[i].set_vpp = physmap_data->set_vpp;
126 info->map[i].pfow_base = physmap_data->pfow_base; 126 info->map[i].pfow_base = physmap_data->pfow_base;
@@ -136,8 +136,12 @@ static int physmap_flash_probe(struct platform_device *dev)
136 simple_map_init(&info->map[i]); 136 simple_map_init(&info->map[i]);
137 137
138 probe_type = rom_probe_types; 138 probe_type = rom_probe_types;
139 for (; info->mtd[i] == NULL && *probe_type != NULL; probe_type++) 139 if (physmap_data->probe_type == NULL) {
140 info->mtd[i] = do_map_probe(*probe_type, &info->map[i]); 140 for (; info->mtd[i] == NULL && *probe_type != NULL; probe_type++)
141 info->mtd[i] = do_map_probe(*probe_type, &info->map[i]);
142 } else
143 info->mtd[i] = do_map_probe(physmap_data->probe_type, &info->map[i]);
144
141 if (info->mtd[i] == NULL) { 145 if (info->mtd[i] == NULL) {
142 dev_err(&dev->dev, "map_probe failed\n"); 146 dev_err(&dev->dev, "map_probe failed\n");
143 err = -ENXIO; 147 err = -ENXIO;
diff --git a/drivers/mtd/maps/physmap_of.c b/drivers/mtd/maps/physmap_of.c
index ba124baa646d..00af55d7afba 100644
--- a/drivers/mtd/maps/physmap_of.c
+++ b/drivers/mtd/maps/physmap_of.c
@@ -43,7 +43,7 @@ struct of_flash {
43#ifdef CONFIG_MTD_PARTITIONS 43#ifdef CONFIG_MTD_PARTITIONS
44#define OF_FLASH_PARTS(info) ((info)->parts) 44#define OF_FLASH_PARTS(info) ((info)->parts)
45 45
46static int parse_obsolete_partitions(struct of_device *dev, 46static int parse_obsolete_partitions(struct platform_device *dev,
47 struct of_flash *info, 47 struct of_flash *info,
48 struct device_node *dp) 48 struct device_node *dp)
49{ 49{
@@ -93,7 +93,7 @@ static int parse_obsolete_partitions(struct of_device *dev,
93#define parse_partitions(info, dev) (0) 93#define parse_partitions(info, dev) (0)
94#endif /* MTD_PARTITIONS */ 94#endif /* MTD_PARTITIONS */
95 95
96static int of_flash_remove(struct of_device *dev) 96static int of_flash_remove(struct platform_device *dev)
97{ 97{
98 struct of_flash *info; 98 struct of_flash *info;
99 int i; 99 int i;
@@ -140,7 +140,7 @@ static int of_flash_remove(struct of_device *dev)
140/* Helper function to handle probing of the obsolete "direct-mapped" 140/* Helper function to handle probing of the obsolete "direct-mapped"
141 * compatible binding, which has an extra "probe-type" property 141 * compatible binding, which has an extra "probe-type" property
142 * describing the type of flash probe necessary. */ 142 * describing the type of flash probe necessary. */
143static struct mtd_info * __devinit obsolete_probe(struct of_device *dev, 143static struct mtd_info * __devinit obsolete_probe(struct platform_device *dev,
144 struct map_info *map) 144 struct map_info *map)
145{ 145{
146 struct device_node *dp = dev->dev.of_node; 146 struct device_node *dp = dev->dev.of_node;
@@ -215,7 +215,7 @@ static void __devinit of_free_probes(const char **probes)
215} 215}
216#endif 216#endif
217 217
218static int __devinit of_flash_probe(struct of_device *dev, 218static int __devinit of_flash_probe(struct platform_device *dev,
219 const struct of_device_id *match) 219 const struct of_device_id *match)
220{ 220{
221#ifdef CONFIG_MTD_PARTITIONS 221#ifdef CONFIG_MTD_PARTITIONS
@@ -353,7 +353,7 @@ static int __devinit of_flash_probe(struct of_device *dev,
353 &info->parts, 0); 353 &info->parts, 0);
354 if (err < 0) { 354 if (err < 0) {
355 of_free_probes(part_probe_types); 355 of_free_probes(part_probe_types);
356 return err; 356 goto err_out;
357 } 357 }
358 of_free_probes(part_probe_types); 358 of_free_probes(part_probe_types);
359 359
@@ -361,14 +361,14 @@ static int __devinit of_flash_probe(struct of_device *dev,
361 if (err == 0) { 361 if (err == 0) {
362 err = of_mtd_parse_partitions(&dev->dev, dp, &info->parts); 362 err = of_mtd_parse_partitions(&dev->dev, dp, &info->parts);
363 if (err < 0) 363 if (err < 0)
364 return err; 364 goto err_out;
365 } 365 }
366#endif 366#endif
367 367
368 if (err == 0) { 368 if (err == 0) {
369 err = parse_obsolete_partitions(dev, info, dp); 369 err = parse_obsolete_partitions(dev, info, dp);
370 if (err < 0) 370 if (err < 0)
371 return err; 371 goto err_out;
372 } 372 }
373 373
374 if (err > 0) 374 if (err > 0)
diff --git a/drivers/mtd/maps/redwood.c b/drivers/mtd/maps/redwood.c
deleted file mode 100644
index d2c9db00db0c..000000000000
--- a/drivers/mtd/maps/redwood.c
+++ /dev/null
@@ -1,131 +0,0 @@
1/*
2 * drivers/mtd/maps/redwood.c
3 *
4 * FLASH map for the IBM Redwood 4/5/6 boards.
5 *
6 * Author: MontaVista Software, Inc. <source@mvista.com>
7 *
8 * 2001-2003 (c) MontaVista, Software, Inc. This file is licensed under
9 * the terms of the GNU General Public License version 2. This program
10 * is licensed "as is" without any warranty of any kind, whether express
11 * or implied.
12 */
13
14#include <linux/module.h>
15#include <linux/types.h>
16#include <linux/kernel.h>
17#include <linux/init.h>
18
19#include <linux/mtd/mtd.h>
20#include <linux/mtd/map.h>
21#include <linux/mtd/partitions.h>
22
23#include <asm/io.h>
24
25#define WINDOW_ADDR 0xffc00000
26#define WINDOW_SIZE 0x00400000
27
28#define RW_PART0_OF 0
29#define RW_PART0_SZ 0x10000
30#define RW_PART1_OF RW_PART0_SZ
31#define RW_PART1_SZ 0x200000 - 0x10000
32#define RW_PART2_OF 0x200000
33#define RW_PART2_SZ 0x10000
34#define RW_PART3_OF 0x210000
35#define RW_PART3_SZ 0x200000 - (0x10000 + 0x20000)
36#define RW_PART4_OF 0x3e0000
37#define RW_PART4_SZ 0x20000
38
39static struct mtd_partition redwood_flash_partitions[] = {
40 {
41 .name = "Redwood OpenBIOS Vital Product Data",
42 .offset = RW_PART0_OF,
43 .size = RW_PART0_SZ,
44 .mask_flags = MTD_WRITEABLE /* force read-only */
45 },
46 {
47 .name = "Redwood kernel",
48 .offset = RW_PART1_OF,
49 .size = RW_PART1_SZ
50 },
51 {
52 .name = "Redwood OpenBIOS non-volatile storage",
53 .offset = RW_PART2_OF,
54 .size = RW_PART2_SZ,
55 .mask_flags = MTD_WRITEABLE /* force read-only */
56 },
57 {
58 .name = "Redwood filesystem",
59 .offset = RW_PART3_OF,
60 .size = RW_PART3_SZ
61 },
62 {
63 .name = "Redwood OpenBIOS",
64 .offset = RW_PART4_OF,
65 .size = RW_PART4_SZ,
66 .mask_flags = MTD_WRITEABLE /* force read-only */
67 }
68};
69
70struct map_info redwood_flash_map = {
71 .name = "IBM Redwood",
72 .size = WINDOW_SIZE,
73 .bankwidth = 2,
74 .phys = WINDOW_ADDR,
75};
76
77
78#define NUM_REDWOOD_FLASH_PARTITIONS ARRAY_SIZE(redwood_flash_partitions)
79
80static struct mtd_info *redwood_mtd;
81
82static int __init init_redwood_flash(void)
83{
84 int err;
85
86 printk(KERN_NOTICE "redwood: flash mapping: %x at %x\n",
87 WINDOW_SIZE, WINDOW_ADDR);
88
89 redwood_flash_map.virt = ioremap(WINDOW_ADDR, WINDOW_SIZE);
90
91 if (!redwood_flash_map.virt) {
92 printk("init_redwood_flash: failed to ioremap\n");
93 return -EIO;
94 }
95 simple_map_init(&redwood_flash_map);
96
97 redwood_mtd = do_map_probe("cfi_probe",&redwood_flash_map);
98
99 if (redwood_mtd) {
100 redwood_mtd->owner = THIS_MODULE;
101 err = add_mtd_partitions(redwood_mtd,
102 redwood_flash_partitions,
103 NUM_REDWOOD_FLASH_PARTITIONS);
104 if (err) {
105 printk("init_redwood_flash: add_mtd_partitions failed\n");
106 iounmap(redwood_flash_map.virt);
107 }
108 return err;
109
110 }
111
112 iounmap(redwood_flash_map.virt);
113 return -ENXIO;
114}
115
116static void __exit cleanup_redwood_flash(void)
117{
118 if (redwood_mtd) {
119 del_mtd_partitions(redwood_mtd);
120 /* moved iounmap after map_destroy - armin */
121 map_destroy(redwood_mtd);
122 iounmap((void *)redwood_flash_map.virt);
123 }
124}
125
126module_init(init_redwood_flash);
127module_exit(cleanup_redwood_flash);
128
129MODULE_LICENSE("GPL");
130MODULE_AUTHOR("MontaVista Software <source@mvista.com>");
131MODULE_DESCRIPTION("MTD map driver for the IBM Redwood reference boards");
diff --git a/drivers/mtd/maps/sun_uflash.c b/drivers/mtd/maps/sun_uflash.c
index 8984236a8d0a..3582ba1f9b09 100644
--- a/drivers/mtd/maps/sun_uflash.c
+++ b/drivers/mtd/maps/sun_uflash.c
@@ -48,7 +48,7 @@ struct map_info uflash_map_templ = {
48 .bankwidth = UFLASH_BUSWIDTH, 48 .bankwidth = UFLASH_BUSWIDTH,
49}; 49};
50 50
51int uflash_devinit(struct of_device *op, struct device_node *dp) 51int uflash_devinit(struct platform_device *op, struct device_node *dp)
52{ 52{
53 struct uflash_dev *up; 53 struct uflash_dev *up;
54 54
@@ -108,7 +108,7 @@ int uflash_devinit(struct of_device *op, struct device_node *dp)
108 return 0; 108 return 0;
109} 109}
110 110
111static int __devinit uflash_probe(struct of_device *op, const struct of_device_id *match) 111static int __devinit uflash_probe(struct platform_device *op, const struct of_device_id *match)
112{ 112{
113 struct device_node *dp = op->dev.of_node; 113 struct device_node *dp = op->dev.of_node;
114 114
@@ -121,7 +121,7 @@ static int __devinit uflash_probe(struct of_device *op, const struct of_device_i
121 return uflash_devinit(op, dp); 121 return uflash_devinit(op, dp);
122} 122}
123 123
124static int __devexit uflash_remove(struct of_device *op) 124static int __devexit uflash_remove(struct platform_device *op)
125{ 125{
126 struct uflash_dev *up = dev_get_drvdata(&op->dev); 126 struct uflash_dev *up = dev_get_drvdata(&op->dev);
127 127
diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c
index 03e19c1965cc..62e68707b07f 100644
--- a/drivers/mtd/mtd_blkdevs.c
+++ b/drivers/mtd/mtd_blkdevs.c
@@ -1,7 +1,21 @@
1/* 1/*
2 * (C) 2003 David Woodhouse <dwmw2@infradead.org> 2 * Interface to Linux block layer for MTD 'translation layers'.
3 * 3 *
4 * Interface to Linux 2.5 block layer for MTD 'translation layers'. 4 * Copyright © 2003-2010 David Woodhouse <dwmw2@infradead.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
5 * 19 *
6 */ 20 */
7 21
@@ -15,6 +29,7 @@
15#include <linux/blkdev.h> 29#include <linux/blkdev.h>
16#include <linux/blkpg.h> 30#include <linux/blkpg.h>
17#include <linux/spinlock.h> 31#include <linux/spinlock.h>
32#include <linux/smp_lock.h>
18#include <linux/hdreg.h> 33#include <linux/hdreg.h>
19#include <linux/init.h> 34#include <linux/init.h>
20#include <linux/mutex.h> 35#include <linux/mutex.h>
@@ -73,14 +88,14 @@ static int do_blktrans_request(struct mtd_blktrans_ops *tr,
73 88
74 buf = req->buffer; 89 buf = req->buffer;
75 90
76 if (!blk_fs_request(req)) 91 if (req->cmd_type != REQ_TYPE_FS)
77 return -EIO; 92 return -EIO;
78 93
79 if (blk_rq_pos(req) + blk_rq_cur_sectors(req) > 94 if (blk_rq_pos(req) + blk_rq_cur_sectors(req) >
80 get_capacity(req->rq_disk)) 95 get_capacity(req->rq_disk))
81 return -EIO; 96 return -EIO;
82 97
83 if (blk_discard_rq(req)) 98 if (req->cmd_flags & REQ_DISCARD)
84 return tr->discard(dev, block, nsect); 99 return tr->discard(dev, block, nsect);
85 100
86 switch(rq_data_dir(req)) { 101 switch(rq_data_dir(req)) {
@@ -164,8 +179,9 @@ static int blktrans_open(struct block_device *bdev, fmode_t mode)
164 int ret; 179 int ret;
165 180
166 if (!dev) 181 if (!dev)
167 return -ERESTARTSYS; 182 return -ERESTARTSYS; /* FIXME: busy loop! -arnd*/
168 183
184 lock_kernel();
169 mutex_lock(&dev->lock); 185 mutex_lock(&dev->lock);
170 186
171 if (!dev->mtd) { 187 if (!dev->mtd) {
@@ -182,6 +198,7 @@ static int blktrans_open(struct block_device *bdev, fmode_t mode)
182unlock: 198unlock:
183 mutex_unlock(&dev->lock); 199 mutex_unlock(&dev->lock);
184 blktrans_dev_put(dev); 200 blktrans_dev_put(dev);
201 unlock_kernel();
185 return ret; 202 return ret;
186} 203}
187 204
@@ -193,6 +210,7 @@ static int blktrans_release(struct gendisk *disk, fmode_t mode)
193 if (!dev) 210 if (!dev)
194 return ret; 211 return ret;
195 212
213 lock_kernel();
196 mutex_lock(&dev->lock); 214 mutex_lock(&dev->lock);
197 215
198 /* Release one reference, we sure its not the last one here*/ 216 /* Release one reference, we sure its not the last one here*/
@@ -205,6 +223,7 @@ static int blktrans_release(struct gendisk *disk, fmode_t mode)
205unlock: 223unlock:
206 mutex_unlock(&dev->lock); 224 mutex_unlock(&dev->lock);
207 blktrans_dev_put(dev); 225 blktrans_dev_put(dev);
226 unlock_kernel();
208 return ret; 227 return ret;
209} 228}
210 229
@@ -237,6 +256,7 @@ static int blktrans_ioctl(struct block_device *bdev, fmode_t mode,
237 if (!dev) 256 if (!dev)
238 return ret; 257 return ret;
239 258
259 lock_kernel();
240 mutex_lock(&dev->lock); 260 mutex_lock(&dev->lock);
241 261
242 if (!dev->mtd) 262 if (!dev->mtd)
@@ -245,11 +265,13 @@ static int blktrans_ioctl(struct block_device *bdev, fmode_t mode,
245 switch (cmd) { 265 switch (cmd) {
246 case BLKFLSBUF: 266 case BLKFLSBUF:
247 ret = dev->tr->flush ? dev->tr->flush(dev) : 0; 267 ret = dev->tr->flush ? dev->tr->flush(dev) : 0;
268 break;
248 default: 269 default:
249 ret = -ENOTTY; 270 ret = -ENOTTY;
250 } 271 }
251unlock: 272unlock:
252 mutex_unlock(&dev->lock); 273 mutex_unlock(&dev->lock);
274 unlock_kernel();
253 blktrans_dev_put(dev); 275 blktrans_dev_put(dev);
254 return ret; 276 return ret;
255} 277}
@@ -258,7 +280,7 @@ static const struct block_device_operations mtd_blktrans_ops = {
258 .owner = THIS_MODULE, 280 .owner = THIS_MODULE,
259 .open = blktrans_open, 281 .open = blktrans_open,
260 .release = blktrans_release, 282 .release = blktrans_release,
261 .locked_ioctl = blktrans_ioctl, 283 .ioctl = blktrans_ioctl,
262 .getgeo = blktrans_getgeo, 284 .getgeo = blktrans_getgeo,
263}; 285};
264 286
@@ -409,13 +431,14 @@ int del_mtd_blktrans_dev(struct mtd_blktrans_dev *old)
409 BUG(); 431 BUG();
410 } 432 }
411 433
412 /* Stop new requests to arrive */
413 del_gendisk(old->disk);
414
415 if (old->disk_attributes) 434 if (old->disk_attributes)
416 sysfs_remove_group(&disk_to_dev(old->disk)->kobj, 435 sysfs_remove_group(&disk_to_dev(old->disk)->kobj,
417 old->disk_attributes); 436 old->disk_attributes);
418 437
438 /* Stop new requests to arrive */
439 del_gendisk(old->disk);
440
441
419 /* Stop the thread */ 442 /* Stop the thread */
420 kthread_stop(old->thread); 443 kthread_stop(old->thread);
421 444
diff --git a/drivers/mtd/mtdblock.c b/drivers/mtd/mtdblock.c
index e6edbec609fd..1e74ad961040 100644
--- a/drivers/mtd/mtdblock.c
+++ b/drivers/mtd/mtdblock.c
@@ -1,8 +1,23 @@
1/* 1/*
2 * Direct MTD block device access 2 * Direct MTD block device access
3 * 3 *
4 * (C) 2000-2003 Nicolas Pitre <nico@fluxnic.net> 4 * Copyright © 1999-2010 David Woodhouse <dwmw2@infradead.org>
5 * (C) 1999-2003 David Woodhouse <dwmw2@infradead.org> 5 * Copyright © 2000-2003 Nicolas Pitre <nico@fluxnic.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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 *
6 */ 21 */
7 22
8#include <linux/fs.h> 23#include <linux/fs.h>
diff --git a/drivers/mtd/mtdblock_ro.c b/drivers/mtd/mtdblock_ro.c
index d0d3f79f9d03..795a8c0a05b8 100644
--- a/drivers/mtd/mtdblock_ro.c
+++ b/drivers/mtd/mtdblock_ro.c
@@ -1,7 +1,22 @@
1/* 1/*
2 * (C) 2003 David Woodhouse <dwmw2@infradead.org>
3 *
4 * Simple read-only (writable only for RAM) mtdblock driver 2 * Simple read-only (writable only for RAM) mtdblock driver
3 *
4 * Copyright © 2001-2010 David Woodhouse <dwmw2@infradead.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 *
5 */ 20 */
6 21
7#include <linux/init.h> 22#include <linux/init.h>
diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index 91c8013cf0d9..a825002123c8 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -1,5 +1,19 @@
1/* 1/*
2 * Character-device access to raw MTD devices. 2 * Copyright © 1999-2010 David Woodhouse <dwmw2@infradead.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
3 * 17 *
4 */ 18 */
5 19
@@ -18,7 +32,7 @@
18#include <linux/mount.h> 32#include <linux/mount.h>
19 33
20#include <linux/mtd/mtd.h> 34#include <linux/mtd/mtd.h>
21#include <linux/mtd/compatmac.h> 35#include <linux/mtd/map.h>
22 36
23#include <asm/uaccess.h> 37#include <asm/uaccess.h>
24 38
@@ -675,6 +689,20 @@ static int mtd_ioctl(struct file *file, u_int cmd, u_long arg)
675 break; 689 break;
676 } 690 }
677 691
692 case MEMISLOCKED:
693 {
694 struct erase_info_user einfo;
695
696 if (copy_from_user(&einfo, argp, sizeof(einfo)))
697 return -EFAULT;
698
699 if (!mtd->is_locked)
700 ret = -EOPNOTSUPP;
701 else
702 ret = mtd->is_locked(mtd, einfo.start, einfo.length);
703 break;
704 }
705
678 /* Legacy interface */ 706 /* Legacy interface */
679 case MEMGETOOBSEL: 707 case MEMGETOOBSEL:
680 { 708 {
@@ -950,9 +978,34 @@ static int mtd_mmap(struct file *file, struct vm_area_struct *vma)
950#ifdef CONFIG_MMU 978#ifdef CONFIG_MMU
951 struct mtd_file_info *mfi = file->private_data; 979 struct mtd_file_info *mfi = file->private_data;
952 struct mtd_info *mtd = mfi->mtd; 980 struct mtd_info *mtd = mfi->mtd;
981 struct map_info *map = mtd->priv;
982 unsigned long start;
983 unsigned long off;
984 u32 len;
985
986 if (mtd->type == MTD_RAM || mtd->type == MTD_ROM) {
987 off = vma->vm_pgoff << PAGE_SHIFT;
988 start = map->phys;
989 len = PAGE_ALIGN((start & ~PAGE_MASK) + map->size);
990 start &= PAGE_MASK;
991 if ((vma->vm_end - vma->vm_start + off) > len)
992 return -EINVAL;
993
994 off += start;
995 vma->vm_pgoff = off >> PAGE_SHIFT;
996 vma->vm_flags |= VM_IO | VM_RESERVED;
997
998#ifdef pgprot_noncached
999 if (file->f_flags & O_DSYNC || off >= __pa(high_memory))
1000 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
1001#endif
1002 if (io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT,
1003 vma->vm_end - vma->vm_start,
1004 vma->vm_page_prot))
1005 return -EAGAIN;
953 1006
954 if (mtd->type == MTD_RAM || mtd->type == MTD_ROM)
955 return 0; 1007 return 0;
1008 }
956 return -ENOSYS; 1009 return -ENOSYS;
957#else 1010#else
958 return vma->vm_flags & VM_SHARED ? 0 : -ENOSYS; 1011 return vma->vm_flags & VM_SHARED ? 0 : -ENOSYS;
diff --git a/drivers/mtd/mtdconcat.c b/drivers/mtd/mtdconcat.c
index 7e075621bbf4..bf8de0943103 100644
--- a/drivers/mtd/mtdconcat.c
+++ b/drivers/mtd/mtdconcat.c
@@ -1,11 +1,25 @@
1/* 1/*
2 * MTD device concatenation layer 2 * MTD device concatenation layer
3 * 3 *
4 * (C) 2002 Robert Kaiser <rkaiser@sysgo.de> 4 * Copyright © 2002 Robert Kaiser <rkaiser@sysgo.de>
5 * Copyright © 2002-2010 David Woodhouse <dwmw2@infradead.org>
5 * 6 *
6 * NAND support by Christian Gan <cgan@iders.ca> 7 * NAND support by Christian Gan <cgan@iders.ca>
7 * 8 *
8 * This code is GPL 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 *
9 */ 23 */
10 24
11#include <linux/kernel.h> 25#include <linux/kernel.h>
@@ -540,10 +554,12 @@ static int concat_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
540 else 554 else
541 size = len; 555 size = len;
542 556
543 err = subdev->lock(subdev, ofs, size); 557 if (subdev->lock) {
544 558 err = subdev->lock(subdev, ofs, size);
545 if (err) 559 if (err)
546 break; 560 break;
561 } else
562 err = -EOPNOTSUPP;
547 563
548 len -= size; 564 len -= size;
549 if (len == 0) 565 if (len == 0)
@@ -578,10 +594,12 @@ static int concat_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
578 else 594 else
579 size = len; 595 size = len;
580 596
581 err = subdev->unlock(subdev, ofs, size); 597 if (subdev->unlock) {
582 598 err = subdev->unlock(subdev, ofs, size);
583 if (err) 599 if (err)
584 break; 600 break;
601 } else
602 err = -EOPNOTSUPP;
585 603
586 len -= size; 604 len -= size;
587 if (len == 0) 605 if (len == 0)
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index a1b8b70d2d0a..527cebf58da4 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -2,9 +2,23 @@
2 * Core registration and callback routines for MTD 2 * Core registration and callback routines for MTD
3 * drivers and users. 3 * drivers and users.
4 * 4 *
5 * bdi bits are: 5 * Copyright © 1999-2010 David Woodhouse <dwmw2@infradead.org>
6 * Copyright © 2006 Red Hat, Inc. All Rights Reserved. 6 * Copyright © 2006 Red Hat UK Limited
7 * Written by David Howells (dhowells@redhat.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 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 *
8 */ 22 */
9 23
10#include <linux/module.h> 24#include <linux/module.h>
@@ -17,7 +31,6 @@
17#include <linux/err.h> 31#include <linux/err.h>
18#include <linux/ioctl.h> 32#include <linux/ioctl.h>
19#include <linux/init.h> 33#include <linux/init.h>
20#include <linux/mtd/compatmac.h>
21#include <linux/proc_fs.h> 34#include <linux/proc_fs.h>
22#include <linux/idr.h> 35#include <linux/idr.h>
23#include <linux/backing-dev.h> 36#include <linux/backing-dev.h>
diff --git a/drivers/mtd/mtdoops.c b/drivers/mtd/mtdoops.c
index 328313c3dccb..1ee72f3f0512 100644
--- a/drivers/mtd/mtdoops.c
+++ b/drivers/mtd/mtdoops.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * MTD Oops/Panic logger 2 * MTD Oops/Panic logger
3 * 3 *
4 * Copyright (C) 2007 Nokia Corporation. All rights reserved. 4 * Copyright © 2007 Nokia Corporation. All rights reserved.
5 * 5 *
6 * Author: Richard Purdie <rpurdie@openedhand.com> 6 * Author: Richard Purdie <rpurdie@openedhand.com>
7 * 7 *
diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index b8043a9ba32d..dc6558568876 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -1,12 +1,24 @@
1/* 1/*
2 * Simple MTD partitioning layer 2 * Simple MTD partitioning layer
3 * 3 *
4 * (C) 2000 Nicolas Pitre <nico@fluxnic.net> 4 * Copyright © 2000 Nicolas Pitre <nico@fluxnic.net>
5 * Copyright © 2002 Thomas Gleixner <gleixner@linutronix.de>
6 * Copyright © 2000-2010 David Woodhouse <dwmw2@infradead.org>
5 * 7 *
6 * This code is GPL 8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
7 * 21 *
8 * 02-21-2002 Thomas Gleixner <gleixner@autronix.de>
9 * added support for read_oob, write_oob
10 */ 22 */
11 23
12#include <linux/module.h> 24#include <linux/module.h>
@@ -17,7 +29,6 @@
17#include <linux/kmod.h> 29#include <linux/kmod.h>
18#include <linux/mtd/mtd.h> 30#include <linux/mtd/mtd.h>
19#include <linux/mtd/partitions.h> 31#include <linux/mtd/partitions.h>
20#include <linux/mtd/compatmac.h>
21 32
22/* Our partition linked list */ 33/* Our partition linked list */
23static LIST_HEAD(mtd_partitions); 34static LIST_HEAD(mtd_partitions);
@@ -264,6 +275,14 @@ static int part_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
264 return part->master->unlock(part->master, ofs + part->offset, len); 275 return part->master->unlock(part->master, ofs + part->offset, len);
265} 276}
266 277
278static int part_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len)
279{
280 struct mtd_part *part = PART(mtd);
281 if ((len + ofs) > mtd->size)
282 return -EINVAL;
283 return part->master->is_locked(part->master, ofs + part->offset, len);
284}
285
267static void part_sync(struct mtd_info *mtd) 286static void part_sync(struct mtd_info *mtd)
268{ 287{
269 struct mtd_part *part = PART(mtd); 288 struct mtd_part *part = PART(mtd);
@@ -402,6 +421,8 @@ static struct mtd_part *add_one_partition(struct mtd_info *master,
402 slave->mtd.lock = part_lock; 421 slave->mtd.lock = part_lock;
403 if (master->unlock) 422 if (master->unlock)
404 slave->mtd.unlock = part_unlock; 423 slave->mtd.unlock = part_unlock;
424 if (master->is_locked)
425 slave->mtd.is_locked = part_is_locked;
405 if (master->block_isbad) 426 if (master->block_isbad)
406 slave->mtd.block_isbad = part_block_isbad; 427 slave->mtd.block_isbad = part_block_isbad;
407 if (master->block_markbad) 428 if (master->block_markbad)
diff --git a/drivers/mtd/mtdsuper.c b/drivers/mtd/mtdsuper.c
index bd9a443ccf69..38e2ab07e7a3 100644
--- a/drivers/mtd/mtdsuper.c
+++ b/drivers/mtd/mtdsuper.c
@@ -1,6 +1,8 @@
1/* MTD-based superblock management 1/* MTD-based superblock management
2 * 2 *
3 * Copyright © 2001-2007 Red Hat, Inc. All Rights Reserved. 3 * Copyright © 2001-2007 Red Hat, Inc. All Rights Reserved.
4 * Copyright © 2001-2010 David Woodhouse <dwmw2@infradead.org>
5 *
4 * Written by: David Howells <dhowells@redhat.com> 6 * Written by: David Howells <dhowells@redhat.com>
5 * David Woodhouse <dwmw2@infradead.org> 7 * David Woodhouse <dwmw2@infradead.org>
6 * 8 *
diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig
index 362d177efe1b..8b4b67c8a391 100644
--- a/drivers/mtd/nand/Kconfig
+++ b/drivers/mtd/nand/Kconfig
@@ -37,7 +37,6 @@ config MTD_SM_COMMON
37 37
38config MTD_NAND_MUSEUM_IDS 38config MTD_NAND_MUSEUM_IDS
39 bool "Enable chip ids for obsolete ancient NAND devices" 39 bool "Enable chip ids for obsolete ancient NAND devices"
40 depends on MTD_NAND
41 default n 40 default n
42 help 41 help
43 Enable this option only when your board has first generation 42 Enable this option only when your board has first generation
@@ -61,6 +60,7 @@ config MTD_NAND_DENALI
61config MTD_NAND_DENALI_SCRATCH_REG_ADDR 60config MTD_NAND_DENALI_SCRATCH_REG_ADDR
62 hex "Denali NAND size scratch register address" 61 hex "Denali NAND size scratch register address"
63 default "0xFF108018" 62 default "0xFF108018"
63 depends on MTD_NAND_DENALI
64 help 64 help
65 Some platforms place the NAND chip size in a scratch register 65 Some platforms place the NAND chip size in a scratch register
66 because (some versions of) the driver aren't able to automatically 66 because (some versions of) the driver aren't able to automatically
@@ -101,13 +101,13 @@ config MTD_NAND_AMS_DELTA
101 101
102config MTD_NAND_OMAP2 102config MTD_NAND_OMAP2
103 tristate "NAND Flash device on OMAP2 and OMAP3" 103 tristate "NAND Flash device on OMAP2 and OMAP3"
104 depends on ARM && MTD_NAND && (ARCH_OMAP2 || ARCH_OMAP3) 104 depends on ARM && (ARCH_OMAP2 || ARCH_OMAP3)
105 help 105 help
106 Support for NAND flash on Texas Instruments OMAP2 and OMAP3 platforms. 106 Support for NAND flash on Texas Instruments OMAP2 and OMAP3 platforms.
107 107
108config MTD_NAND_OMAP_PREFETCH 108config MTD_NAND_OMAP_PREFETCH
109 bool "GPMC prefetch support for NAND Flash device" 109 bool "GPMC prefetch support for NAND Flash device"
110 depends on MTD_NAND && MTD_NAND_OMAP2 110 depends on MTD_NAND_OMAP2
111 default y 111 default y
112 help 112 help
113 The NAND device can be accessed for Read/Write using GPMC PREFETCH engine 113 The NAND device can be accessed for Read/Write using GPMC PREFETCH engine
@@ -146,7 +146,7 @@ config MTD_NAND_AU1550
146 146
147config MTD_NAND_BF5XX 147config MTD_NAND_BF5XX
148 tristate "Blackfin on-chip NAND Flash Controller driver" 148 tristate "Blackfin on-chip NAND Flash Controller driver"
149 depends on (BF54x || BF52x) && MTD_NAND 149 depends on BF54x || BF52x
150 help 150 help
151 This enables the Blackfin on-chip NAND flash controller 151 This enables the Blackfin on-chip NAND flash controller
152 152
@@ -236,7 +236,7 @@ config MTD_NAND_S3C2410_CLKSTOP
236 236
237config MTD_NAND_BCM_UMI 237config MTD_NAND_BCM_UMI
238 tristate "NAND Flash support for BCM Reference Boards" 238 tristate "NAND Flash support for BCM Reference Boards"
239 depends on ARCH_BCMRING && MTD_NAND 239 depends on ARCH_BCMRING
240 help 240 help
241 This enables the NAND flash controller on the BCM UMI block. 241 This enables the NAND flash controller on the BCM UMI block.
242 242
@@ -395,7 +395,7 @@ endchoice
395 395
396config MTD_NAND_PXA3xx 396config MTD_NAND_PXA3xx
397 tristate "Support for NAND flash devices on PXA3xx" 397 tristate "Support for NAND flash devices on PXA3xx"
398 depends on MTD_NAND && (PXA3xx || ARCH_MMP) 398 depends on PXA3xx || ARCH_MMP
399 help 399 help
400 This enables the driver for the NAND flash device found on 400 This enables the driver for the NAND flash device found on
401 PXA3xx processors 401 PXA3xx processors
@@ -409,18 +409,18 @@ config MTD_NAND_PXA3xx_BUILTIN
409 409
410config MTD_NAND_CM_X270 410config MTD_NAND_CM_X270
411 tristate "Support for NAND Flash on CM-X270 modules" 411 tristate "Support for NAND Flash on CM-X270 modules"
412 depends on MTD_NAND && MACH_ARMCORE 412 depends on MACH_ARMCORE
413 413
414config MTD_NAND_PASEMI 414config MTD_NAND_PASEMI
415 tristate "NAND support for PA Semi PWRficient" 415 tristate "NAND support for PA Semi PWRficient"
416 depends on MTD_NAND && PPC_PASEMI 416 depends on PPC_PASEMI
417 help 417 help
418 Enables support for NAND Flash interface on PA Semi PWRficient 418 Enables support for NAND Flash interface on PA Semi PWRficient
419 based boards 419 based boards
420 420
421config MTD_NAND_TMIO 421config MTD_NAND_TMIO
422 tristate "NAND Flash device on Toshiba Mobile IO Controller" 422 tristate "NAND Flash device on Toshiba Mobile IO Controller"
423 depends on MTD_NAND && MFD_TMIO 423 depends on MFD_TMIO
424 help 424 help
425 Support for NAND flash connected to a Toshiba Mobile IO 425 Support for NAND flash connected to a Toshiba Mobile IO
426 Controller in some PDAs, including the Sharp SL6000x. 426 Controller in some PDAs, including the Sharp SL6000x.
@@ -434,7 +434,6 @@ config MTD_NAND_NANDSIM
434 434
435config MTD_NAND_PLATFORM 435config MTD_NAND_PLATFORM
436 tristate "Support for generic platform NAND driver" 436 tristate "Support for generic platform NAND driver"
437 depends on MTD_NAND
438 help 437 help
439 This implements a generic NAND driver for on-SOC platform 438 This implements a generic NAND driver for on-SOC platform
440 devices. You will need to provide platform-specific functions 439 devices. You will need to provide platform-specific functions
@@ -442,14 +441,14 @@ config MTD_NAND_PLATFORM
442 441
443config MTD_ALAUDA 442config MTD_ALAUDA
444 tristate "MTD driver for Olympus MAUSB-10 and Fujifilm DPC-R1" 443 tristate "MTD driver for Olympus MAUSB-10 and Fujifilm DPC-R1"
445 depends on MTD_NAND && USB 444 depends on USB
446 help 445 help
447 These two (and possibly other) Alauda-based cardreaders for 446 These two (and possibly other) Alauda-based cardreaders for
448 SmartMedia and xD allow raw flash access. 447 SmartMedia and xD allow raw flash access.
449 448
450config MTD_NAND_ORION 449config MTD_NAND_ORION
451 tristate "NAND Flash support for Marvell Orion SoC" 450 tristate "NAND Flash support for Marvell Orion SoC"
452 depends on PLAT_ORION && MTD_NAND 451 depends on PLAT_ORION
453 help 452 help
454 This enables the NAND flash controller on Orion machines. 453 This enables the NAND flash controller on Orion machines.
455 454
@@ -458,7 +457,7 @@ config MTD_NAND_ORION
458 457
459config MTD_NAND_FSL_ELBC 458config MTD_NAND_FSL_ELBC
460 tristate "NAND support for Freescale eLBC controllers" 459 tristate "NAND support for Freescale eLBC controllers"
461 depends on MTD_NAND && PPC_OF 460 depends on PPC_OF
462 help 461 help
463 Various Freescale chips, including the 8313, include a NAND Flash 462 Various Freescale chips, including the 8313, include a NAND Flash
464 Controller Module with built-in hardware ECC capabilities. 463 Controller Module with built-in hardware ECC capabilities.
@@ -467,7 +466,7 @@ config MTD_NAND_FSL_ELBC
467 466
468config MTD_NAND_FSL_UPM 467config MTD_NAND_FSL_UPM
469 tristate "Support for NAND on Freescale UPM" 468 tristate "Support for NAND on Freescale UPM"
470 depends on MTD_NAND && (PPC_83xx || PPC_85xx) 469 depends on PPC_83xx || PPC_85xx
471 select FSL_LBC 470 select FSL_LBC
472 help 471 help
473 Enables support for NAND Flash chips wired onto Freescale PowerPC 472 Enables support for NAND Flash chips wired onto Freescale PowerPC
@@ -482,7 +481,7 @@ config MTD_NAND_MPC5121_NFC
482 481
483config MTD_NAND_MXC 482config MTD_NAND_MXC
484 tristate "MXC NAND support" 483 tristate "MXC NAND support"
485 depends on ARCH_MX2 || ARCH_MX25 || ARCH_MX3 484 depends on ARCH_MX2 || ARCH_MX25 || ARCH_MX3 || ARCH_MX51
486 help 485 help
487 This enables the driver for the NAND flash controller on the 486 This enables the driver for the NAND flash controller on the
488 MXC processors. 487 MXC processors.
@@ -495,7 +494,7 @@ config MTD_NAND_NOMADIK
495 494
496config MTD_NAND_SH_FLCTL 495config MTD_NAND_SH_FLCTL
497 tristate "Support for NAND on Renesas SuperH FLCTL" 496 tristate "Support for NAND on Renesas SuperH FLCTL"
498 depends on MTD_NAND && (SUPERH || ARCH_SHMOBILE) 497 depends on SUPERH || ARCH_SHMOBILE
499 help 498 help
500 Several Renesas SuperH CPU has FLCTL. This option enables support 499 Several Renesas SuperH CPU has FLCTL. This option enables support
501 for NAND Flash using FLCTL. 500 for NAND Flash using FLCTL.
@@ -515,7 +514,7 @@ config MTD_NAND_TXX9NDFMC
515 514
516config MTD_NAND_SOCRATES 515config MTD_NAND_SOCRATES
517 tristate "Support for NAND on Socrates board" 516 tristate "Support for NAND on Socrates board"
518 depends on MTD_NAND && SOCRATES 517 depends on SOCRATES
519 help 518 help
520 Enables support for NAND Flash chips wired onto Socrates board. 519 Enables support for NAND Flash chips wired onto Socrates board.
521 520
diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
index 04d30887ca7f..ccce0f03b5dc 100644
--- a/drivers/mtd/nand/atmel_nand.c
+++ b/drivers/mtd/nand/atmel_nand.c
@@ -364,7 +364,7 @@ static void atmel_nand_hwctl(struct mtd_info *mtd, int mode)
364 } 364 }
365} 365}
366 366
367#ifdef CONFIG_MTD_PARTITIONS 367#ifdef CONFIG_MTD_CMDLINE_PARTS
368static const char *part_probes[] = { "cmdlinepart", NULL }; 368static const char *part_probes[] = { "cmdlinepart", NULL };
369#endif 369#endif
370 370
diff --git a/drivers/mtd/nand/bf5xx_nand.c b/drivers/mtd/nand/bf5xx_nand.c
index 2974995e194d..a382e3dd0a5d 100644
--- a/drivers/mtd/nand/bf5xx_nand.c
+++ b/drivers/mtd/nand/bf5xx_nand.c
@@ -20,9 +20,6 @@
20 * - DMA supported in ECC_HW 20 * - DMA supported in ECC_HW
21 * - YAFFS tested as rootfs in both ECC_HW and ECC_SW 21 * - YAFFS tested as rootfs in both ECC_HW and ECC_SW
22 * 22 *
23 * TODO:
24 * Enable JFFS2 over NAND as rootfs
25 *
26 * This program is free software; you can redistribute it and/or modify 23 * This program is free software; you can redistribute it and/or modify
27 * it under the terms of the GNU General Public License as published by 24 * it under the terms of the GNU General Public License as published by
28 * the Free Software Foundation; either version 2 of the License, or 25 * the Free Software Foundation; either version 2 of the License, or
@@ -206,7 +203,7 @@ static void bf5xx_nand_hwcontrol(struct mtd_info *mtd, int cmd,
206 203
207 if (ctrl & NAND_CLE) 204 if (ctrl & NAND_CLE)
208 bfin_write_NFC_CMD(cmd); 205 bfin_write_NFC_CMD(cmd);
209 else 206 else if (ctrl & NAND_ALE)
210 bfin_write_NFC_ADDR(cmd); 207 bfin_write_NFC_ADDR(cmd);
211 SSYNC(); 208 SSYNC();
212} 209}
@@ -218,9 +215,9 @@ static void bf5xx_nand_hwcontrol(struct mtd_info *mtd, int cmd,
218 */ 215 */
219static int bf5xx_nand_devready(struct mtd_info *mtd) 216static int bf5xx_nand_devready(struct mtd_info *mtd)
220{ 217{
221 unsigned short val = bfin_read_NFC_IRQSTAT(); 218 unsigned short val = bfin_read_NFC_STAT();
222 219
223 if ((val & NBUSYIRQ) == NBUSYIRQ) 220 if ((val & NBUSY) == NBUSY)
224 return 1; 221 return 1;
225 else 222 else
226 return 0; 223 return 0;
@@ -317,18 +314,16 @@ static int bf5xx_nand_correct_data_256(struct mtd_info *mtd, u_char *dat,
317static int bf5xx_nand_correct_data(struct mtd_info *mtd, u_char *dat, 314static int bf5xx_nand_correct_data(struct mtd_info *mtd, u_char *dat,
318 u_char *read_ecc, u_char *calc_ecc) 315 u_char *read_ecc, u_char *calc_ecc)
319{ 316{
320 struct bf5xx_nand_info *info = mtd_to_nand_info(mtd); 317 struct nand_chip *chip = mtd->priv;
321 struct bf5xx_nand_platform *plat = info->platform;
322 unsigned short page_size = (plat->page_size ? 512 : 256);
323 int ret; 318 int ret;
324 319
325 ret = bf5xx_nand_correct_data_256(mtd, dat, read_ecc, calc_ecc); 320 ret = bf5xx_nand_correct_data_256(mtd, dat, read_ecc, calc_ecc);
326 321
327 /* If page size is 512, correct second 256 bytes */ 322 /* If ecc size is 512, correct second 256 bytes */
328 if (page_size == 512) { 323 if (chip->ecc.size == 512) {
329 dat += 256; 324 dat += 256;
330 read_ecc += 8; 325 read_ecc += 3;
331 calc_ecc += 8; 326 calc_ecc += 3;
332 ret |= bf5xx_nand_correct_data_256(mtd, dat, read_ecc, calc_ecc); 327 ret |= bf5xx_nand_correct_data_256(mtd, dat, read_ecc, calc_ecc);
333 } 328 }
334 329
@@ -344,13 +339,12 @@ static int bf5xx_nand_calculate_ecc(struct mtd_info *mtd,
344 const u_char *dat, u_char *ecc_code) 339 const u_char *dat, u_char *ecc_code)
345{ 340{
346 struct bf5xx_nand_info *info = mtd_to_nand_info(mtd); 341 struct bf5xx_nand_info *info = mtd_to_nand_info(mtd);
347 struct bf5xx_nand_platform *plat = info->platform; 342 struct nand_chip *chip = mtd->priv;
348 u16 page_size = (plat->page_size ? 512 : 256);
349 u16 ecc0, ecc1; 343 u16 ecc0, ecc1;
350 u32 code[2]; 344 u32 code[2];
351 u8 *p; 345 u8 *p;
352 346
353 /* first 4 bytes ECC code for 256 page size */ 347 /* first 3 bytes ECC code for 256 page size */
354 ecc0 = bfin_read_NFC_ECC0(); 348 ecc0 = bfin_read_NFC_ECC0();
355 ecc1 = bfin_read_NFC_ECC1(); 349 ecc1 = bfin_read_NFC_ECC1();
356 350
@@ -358,12 +352,11 @@ static int bf5xx_nand_calculate_ecc(struct mtd_info *mtd,
358 352
359 dev_dbg(info->device, "returning ecc 0x%08x\n", code[0]); 353 dev_dbg(info->device, "returning ecc 0x%08x\n", code[0]);
360 354
361 /* first 3 bytes in ecc_code for 256 page size */
362 p = (u8 *) code; 355 p = (u8 *) code;
363 memcpy(ecc_code, p, 3); 356 memcpy(ecc_code, p, 3);
364 357
365 /* second 4 bytes ECC code for 512 page size */ 358 /* second 3 bytes ECC code for 512 ecc size */
366 if (page_size == 512) { 359 if (chip->ecc.size == 512) {
367 ecc0 = bfin_read_NFC_ECC2(); 360 ecc0 = bfin_read_NFC_ECC2();
368 ecc1 = bfin_read_NFC_ECC3(); 361 ecc1 = bfin_read_NFC_ECC3();
369 code[1] = (ecc0 & 0x7ff) | ((ecc1 & 0x7ff) << 11); 362 code[1] = (ecc0 & 0x7ff) | ((ecc1 & 0x7ff) << 11);
@@ -483,8 +476,7 @@ static void bf5xx_nand_dma_rw(struct mtd_info *mtd,
483 uint8_t *buf, int is_read) 476 uint8_t *buf, int is_read)
484{ 477{
485 struct bf5xx_nand_info *info = mtd_to_nand_info(mtd); 478 struct bf5xx_nand_info *info = mtd_to_nand_info(mtd);
486 struct bf5xx_nand_platform *plat = info->platform; 479 struct nand_chip *chip = mtd->priv;
487 unsigned short page_size = (plat->page_size ? 512 : 256);
488 unsigned short val; 480 unsigned short val;
489 481
490 dev_dbg(info->device, " mtd->%p, buf->%p, is_read %d\n", 482 dev_dbg(info->device, " mtd->%p, buf->%p, is_read %d\n",
@@ -498,10 +490,10 @@ static void bf5xx_nand_dma_rw(struct mtd_info *mtd,
498 */ 490 */
499 if (is_read) 491 if (is_read)
500 invalidate_dcache_range((unsigned int)buf, 492 invalidate_dcache_range((unsigned int)buf,
501 (unsigned int)(buf + page_size)); 493 (unsigned int)(buf + chip->ecc.size));
502 else 494 else
503 flush_dcache_range((unsigned int)buf, 495 flush_dcache_range((unsigned int)buf,
504 (unsigned int)(buf + page_size)); 496 (unsigned int)(buf + chip->ecc.size));
505 497
506 /* 498 /*
507 * This register must be written before each page is 499 * This register must be written before each page is
@@ -510,6 +502,8 @@ static void bf5xx_nand_dma_rw(struct mtd_info *mtd,
510 */ 502 */
511 bfin_write_NFC_RST(ECC_RST); 503 bfin_write_NFC_RST(ECC_RST);
512 SSYNC(); 504 SSYNC();
505 while (bfin_read_NFC_RST() & ECC_RST)
506 cpu_relax();
513 507
514 disable_dma(CH_NFC); 508 disable_dma(CH_NFC);
515 clear_dma_irqstat(CH_NFC); 509 clear_dma_irqstat(CH_NFC);
@@ -520,13 +514,13 @@ static void bf5xx_nand_dma_rw(struct mtd_info *mtd,
520 514
521 /* The DMAs have different size on BF52x and BF54x */ 515 /* The DMAs have different size on BF52x and BF54x */
522#ifdef CONFIG_BF52x 516#ifdef CONFIG_BF52x
523 set_dma_x_count(CH_NFC, (page_size >> 1)); 517 set_dma_x_count(CH_NFC, (chip->ecc.size >> 1));
524 set_dma_x_modify(CH_NFC, 2); 518 set_dma_x_modify(CH_NFC, 2);
525 val = DI_EN | WDSIZE_16; 519 val = DI_EN | WDSIZE_16;
526#endif 520#endif
527 521
528#ifdef CONFIG_BF54x 522#ifdef CONFIG_BF54x
529 set_dma_x_count(CH_NFC, (page_size >> 2)); 523 set_dma_x_count(CH_NFC, (chip->ecc.size >> 2));
530 set_dma_x_modify(CH_NFC, 4); 524 set_dma_x_modify(CH_NFC, 4);
531 val = DI_EN | WDSIZE_32; 525 val = DI_EN | WDSIZE_32;
532#endif 526#endif
@@ -548,12 +542,11 @@ static void bf5xx_nand_dma_read_buf(struct mtd_info *mtd,
548 uint8_t *buf, int len) 542 uint8_t *buf, int len)
549{ 543{
550 struct bf5xx_nand_info *info = mtd_to_nand_info(mtd); 544 struct bf5xx_nand_info *info = mtd_to_nand_info(mtd);
551 struct bf5xx_nand_platform *plat = info->platform; 545 struct nand_chip *chip = mtd->priv;
552 unsigned short page_size = (plat->page_size ? 512 : 256);
553 546
554 dev_dbg(info->device, "mtd->%p, buf->%p, int %d\n", mtd, buf, len); 547 dev_dbg(info->device, "mtd->%p, buf->%p, int %d\n", mtd, buf, len);
555 548
556 if (len == page_size) 549 if (len == chip->ecc.size)
557 bf5xx_nand_dma_rw(mtd, buf, 1); 550 bf5xx_nand_dma_rw(mtd, buf, 1);
558 else 551 else
559 bf5xx_nand_read_buf(mtd, buf, len); 552 bf5xx_nand_read_buf(mtd, buf, len);
@@ -563,17 +556,32 @@ static void bf5xx_nand_dma_write_buf(struct mtd_info *mtd,
563 const uint8_t *buf, int len) 556 const uint8_t *buf, int len)
564{ 557{
565 struct bf5xx_nand_info *info = mtd_to_nand_info(mtd); 558 struct bf5xx_nand_info *info = mtd_to_nand_info(mtd);
566 struct bf5xx_nand_platform *plat = info->platform; 559 struct nand_chip *chip = mtd->priv;
567 unsigned short page_size = (plat->page_size ? 512 : 256);
568 560
569 dev_dbg(info->device, "mtd->%p, buf->%p, len %d\n", mtd, buf, len); 561 dev_dbg(info->device, "mtd->%p, buf->%p, len %d\n", mtd, buf, len);
570 562
571 if (len == page_size) 563 if (len == chip->ecc.size)
572 bf5xx_nand_dma_rw(mtd, (uint8_t *)buf, 0); 564 bf5xx_nand_dma_rw(mtd, (uint8_t *)buf, 0);
573 else 565 else
574 bf5xx_nand_write_buf(mtd, buf, len); 566 bf5xx_nand_write_buf(mtd, buf, len);
575} 567}
576 568
569static int bf5xx_nand_read_page_raw(struct mtd_info *mtd, struct nand_chip *chip,
570 uint8_t *buf, int page)
571{
572 bf5xx_nand_read_buf(mtd, buf, mtd->writesize);
573 bf5xx_nand_read_buf(mtd, chip->oob_poi, mtd->oobsize);
574
575 return 0;
576}
577
578static void bf5xx_nand_write_page_raw(struct mtd_info *mtd, struct nand_chip *chip,
579 const uint8_t *buf)
580{
581 bf5xx_nand_write_buf(mtd, buf, mtd->writesize);
582 bf5xx_nand_write_buf(mtd, chip->oob_poi, mtd->oobsize);
583}
584
577/* 585/*
578 * System initialization functions 586 * System initialization functions
579 */ 587 */
@@ -627,15 +635,14 @@ static int bf5xx_nand_hw_init(struct bf5xx_nand_info *info)
627 635
628 /* setup NFC_CTL register */ 636 /* setup NFC_CTL register */
629 dev_info(info->device, 637 dev_info(info->device,
630 "page_size=%d, data_width=%d, wr_dly=%d, rd_dly=%d\n", 638 "data_width=%d, wr_dly=%d, rd_dly=%d\n",
631 (plat->page_size ? 512 : 256),
632 (plat->data_width ? 16 : 8), 639 (plat->data_width ? 16 : 8),
633 plat->wr_dly, plat->rd_dly); 640 plat->wr_dly, plat->rd_dly);
634 641
635 val = (plat->page_size << NFC_PG_SIZE_OFFSET) | 642 val = (1 << NFC_PG_SIZE_OFFSET) |
636 (plat->data_width << NFC_NWIDTH_OFFSET) | 643 (plat->data_width << NFC_NWIDTH_OFFSET) |
637 (plat->rd_dly << NFC_RDDLY_OFFSET) | 644 (plat->rd_dly << NFC_RDDLY_OFFSET) |
638 (plat->rd_dly << NFC_WRDLY_OFFSET); 645 (plat->wr_dly << NFC_WRDLY_OFFSET);
639 dev_dbg(info->device, "NFC_CTL is 0x%04x\n", val); 646 dev_dbg(info->device, "NFC_CTL is 0x%04x\n", val);
640 647
641 bfin_write_NFC_CTL(val); 648 bfin_write_NFC_CTL(val);
@@ -698,6 +705,33 @@ static int __devexit bf5xx_nand_remove(struct platform_device *pdev)
698 return 0; 705 return 0;
699} 706}
700 707
708static int bf5xx_nand_scan(struct mtd_info *mtd)
709{
710 struct nand_chip *chip = mtd->priv;
711 int ret;
712
713 ret = nand_scan_ident(mtd, 1);
714 if (ret)
715 return ret;
716
717 if (hardware_ecc) {
718 /*
719 * for nand with page size > 512B, think it as several sections with 512B
720 */
721 if (likely(mtd->writesize >= 512)) {
722 chip->ecc.size = 512;
723 chip->ecc.bytes = 6;
724 } else {
725 chip->ecc.size = 256;
726 chip->ecc.bytes = 3;
727 bfin_write_NFC_CTL(bfin_read_NFC_CTL() & ~(1 << NFC_PG_SIZE_OFFSET));
728 SSYNC();
729 }
730 }
731
732 return nand_scan_tail(mtd);
733}
734
701/* 735/*
702 * bf5xx_nand_probe 736 * bf5xx_nand_probe
703 * 737 *
@@ -783,27 +817,20 @@ static int __devinit bf5xx_nand_probe(struct platform_device *pdev)
783 chip->badblock_pattern = &bootrom_bbt; 817 chip->badblock_pattern = &bootrom_bbt;
784 chip->ecc.layout = &bootrom_ecclayout; 818 chip->ecc.layout = &bootrom_ecclayout;
785#endif 819#endif
786
787 if (plat->page_size == NFC_PG_SIZE_256) {
788 chip->ecc.bytes = 3;
789 chip->ecc.size = 256;
790 } else if (plat->page_size == NFC_PG_SIZE_512) {
791 chip->ecc.bytes = 6;
792 chip->ecc.size = 512;
793 }
794
795 chip->read_buf = bf5xx_nand_dma_read_buf; 820 chip->read_buf = bf5xx_nand_dma_read_buf;
796 chip->write_buf = bf5xx_nand_dma_write_buf; 821 chip->write_buf = bf5xx_nand_dma_write_buf;
797 chip->ecc.calculate = bf5xx_nand_calculate_ecc; 822 chip->ecc.calculate = bf5xx_nand_calculate_ecc;
798 chip->ecc.correct = bf5xx_nand_correct_data; 823 chip->ecc.correct = bf5xx_nand_correct_data;
799 chip->ecc.mode = NAND_ECC_HW; 824 chip->ecc.mode = NAND_ECC_HW;
800 chip->ecc.hwctl = bf5xx_nand_enable_hwecc; 825 chip->ecc.hwctl = bf5xx_nand_enable_hwecc;
826 chip->ecc.read_page_raw = bf5xx_nand_read_page_raw;
827 chip->ecc.write_page_raw = bf5xx_nand_write_page_raw;
801 } else { 828 } else {
802 chip->ecc.mode = NAND_ECC_SOFT; 829 chip->ecc.mode = NAND_ECC_SOFT;
803 } 830 }
804 831
805 /* scan hardware nand chip and setup mtd info data struct */ 832 /* scan hardware nand chip and setup mtd info data struct */
806 if (nand_scan(mtd, 1)) { 833 if (bf5xx_nand_scan(mtd)) {
807 err = -ENXIO; 834 err = -ENXIO;
808 goto out_err_nand_scan; 835 goto out_err_nand_scan;
809 } 836 }
diff --git a/drivers/mtd/nand/davinci_nand.c b/drivers/mtd/nand/davinci_nand.c
index 9c9d893affeb..2ac7367afe77 100644
--- a/drivers/mtd/nand/davinci_nand.c
+++ b/drivers/mtd/nand/davinci_nand.c
@@ -311,7 +311,9 @@ static int nand_davinci_correct_4bit(struct mtd_info *mtd,
311 unsigned short ecc10[8]; 311 unsigned short ecc10[8];
312 unsigned short *ecc16; 312 unsigned short *ecc16;
313 u32 syndrome[4]; 313 u32 syndrome[4];
314 u32 ecc_state;
314 unsigned num_errors, corrected; 315 unsigned num_errors, corrected;
316 unsigned long timeo = jiffies + msecs_to_jiffies(100);
315 317
316 /* All bytes 0xff? It's an erased page; ignore its ECC. */ 318 /* All bytes 0xff? It's an erased page; ignore its ECC. */
317 for (i = 0; i < 10; i++) { 319 for (i = 0; i < 10; i++) {
@@ -361,6 +363,21 @@ compare:
361 */ 363 */
362 davinci_nand_writel(info, NANDFCR_OFFSET, 364 davinci_nand_writel(info, NANDFCR_OFFSET,
363 davinci_nand_readl(info, NANDFCR_OFFSET) | BIT(13)); 365 davinci_nand_readl(info, NANDFCR_OFFSET) | BIT(13));
366
367 /*
368 * ECC_STATE field reads 0x3 (Error correction complete) immediately
369 * after setting the 4BITECC_ADD_CALC_START bit. So if you immediately
370 * begin trying to poll for the state, you may fall right out of your
371 * loop without any of the correction calculations having taken place.
372 * The recommendation from the hardware team is to wait till ECC_STATE
373 * reads less than 4, which means ECC HW has entered correction state.
374 */
375 do {
376 ecc_state = (davinci_nand_readl(info,
377 NANDFSR_OFFSET) >> 8) & 0x0f;
378 cpu_relax();
379 } while ((ecc_state < 4) && time_before(jiffies, timeo));
380
364 for (;;) { 381 for (;;) {
365 u32 fsr = davinci_nand_readl(info, NANDFSR_OFFSET); 382 u32 fsr = davinci_nand_readl(info, NANDFSR_OFFSET);
366 383
diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
index 3dfda9cc677d..532fe07cf886 100644
--- a/drivers/mtd/nand/denali.c
+++ b/drivers/mtd/nand/denali.c
@@ -21,6 +21,7 @@
21#include <linux/delay.h> 21#include <linux/delay.h>
22#include <linux/wait.h> 22#include <linux/wait.h>
23#include <linux/mutex.h> 23#include <linux/mutex.h>
24#include <linux/slab.h>
24#include <linux/pci.h> 25#include <linux/pci.h>
25#include <linux/mtd/mtd.h> 26#include <linux/mtd/mtd.h>
26#include <linux/module.h> 27#include <linux/module.h>
@@ -29,15 +30,15 @@
29 30
30MODULE_LICENSE("GPL"); 31MODULE_LICENSE("GPL");
31 32
32/* We define a module parameter that allows the user to override 33/* We define a module parameter that allows the user to override
33 * the hardware and decide what timing mode should be used. 34 * the hardware and decide what timing mode should be used.
34 */ 35 */
35#define NAND_DEFAULT_TIMINGS -1 36#define NAND_DEFAULT_TIMINGS -1
36 37
37static int onfi_timing_mode = NAND_DEFAULT_TIMINGS; 38static int onfi_timing_mode = NAND_DEFAULT_TIMINGS;
38module_param(onfi_timing_mode, int, S_IRUGO); 39module_param(onfi_timing_mode, int, S_IRUGO);
39MODULE_PARM_DESC(onfi_timing_mode, "Overrides default ONFI setting. -1 indicates" 40MODULE_PARM_DESC(onfi_timing_mode, "Overrides default ONFI setting."
40 " use default timings"); 41 " -1 indicates use default timings");
41 42
42#define DENALI_NAND_NAME "denali-nand" 43#define DENALI_NAND_NAME "denali-nand"
43 44
@@ -54,13 +55,13 @@ MODULE_PARM_DESC(onfi_timing_mode, "Overrides default ONFI setting. -1 indicates
54 INTR_STATUS0__RST_COMP | \ 55 INTR_STATUS0__RST_COMP | \
55 INTR_STATUS0__ERASE_COMP) 56 INTR_STATUS0__ERASE_COMP)
56 57
57/* indicates whether or not the internal value for the flash bank is 58/* indicates whether or not the internal value for the flash bank is
58 valid or not */ 59 * valid or not */
59#define CHIP_SELECT_INVALID -1 60#define CHIP_SELECT_INVALID -1
60 61
61#define SUPPORT_8BITECC 1 62#define SUPPORT_8BITECC 1
62 63
63/* This macro divides two integers and rounds fractional values up 64/* This macro divides two integers and rounds fractional values up
64 * to the nearest integer value. */ 65 * to the nearest integer value. */
65#define CEIL_DIV(X, Y) (((X)%(Y)) ? ((X)/(Y)+1) : ((X)/(Y))) 66#define CEIL_DIV(X, Y) (((X)%(Y)) ? ((X)/(Y)+1) : ((X)/(Y)))
66 67
@@ -70,7 +71,7 @@ MODULE_PARM_DESC(onfi_timing_mode, "Overrides default ONFI setting. -1 indicates
70#define mtd_to_denali(m) container_of(m, struct denali_nand_info, mtd) 71#define mtd_to_denali(m) container_of(m, struct denali_nand_info, mtd)
71 72
72/* These constants are defined by the driver to enable common driver 73/* These constants are defined by the driver to enable common driver
73 configuration options. */ 74 * configuration options. */
74#define SPARE_ACCESS 0x41 75#define SPARE_ACCESS 0x41
75#define MAIN_ACCESS 0x42 76#define MAIN_ACCESS 0x42
76#define MAIN_SPARE_ACCESS 0x43 77#define MAIN_SPARE_ACCESS 0x43
@@ -83,7 +84,7 @@ MODULE_PARM_DESC(onfi_timing_mode, "Overrides default ONFI setting. -1 indicates
83#define ADDR_CYCLE 1 84#define ADDR_CYCLE 1
84#define STATUS_CYCLE 2 85#define STATUS_CYCLE 2
85 86
86/* this is a helper macro that allows us to 87/* this is a helper macro that allows us to
87 * format the bank into the proper bits for the controller */ 88 * format the bank into the proper bits for the controller */
88#define BANK(x) ((x) << 24) 89#define BANK(x) ((x) << 24)
89 90
@@ -95,73 +96,59 @@ static const struct pci_device_id denali_pci_ids[] = {
95}; 96};
96 97
97 98
98/* these are static lookup tables that give us easy access to 99/* these are static lookup tables that give us easy access to
99 registers in the NAND controller. 100 * registers in the NAND controller.
100 */ 101 */
101static const uint32_t intr_status_addresses[4] = {INTR_STATUS0, 102static const uint32_t intr_status_addresses[4] = {INTR_STATUS0,
102 INTR_STATUS1, 103 INTR_STATUS1,
103 INTR_STATUS2, 104 INTR_STATUS2,
104 INTR_STATUS3}; 105 INTR_STATUS3};
105 106
106static const uint32_t device_reset_banks[4] = {DEVICE_RESET__BANK0, 107static const uint32_t device_reset_banks[4] = {DEVICE_RESET__BANK0,
107 DEVICE_RESET__BANK1, 108 DEVICE_RESET__BANK1,
108 DEVICE_RESET__BANK2, 109 DEVICE_RESET__BANK2,
109 DEVICE_RESET__BANK3}; 110 DEVICE_RESET__BANK3};
110 111
111static const uint32_t operation_timeout[4] = {INTR_STATUS0__TIME_OUT, 112static const uint32_t operation_timeout[4] = {INTR_STATUS0__TIME_OUT,
112 INTR_STATUS1__TIME_OUT, 113 INTR_STATUS1__TIME_OUT,
113 INTR_STATUS2__TIME_OUT, 114 INTR_STATUS2__TIME_OUT,
114 INTR_STATUS3__TIME_OUT}; 115 INTR_STATUS3__TIME_OUT};
115 116
116static const uint32_t reset_complete[4] = {INTR_STATUS0__RST_COMP, 117static const uint32_t reset_complete[4] = {INTR_STATUS0__RST_COMP,
117 INTR_STATUS1__RST_COMP, 118 INTR_STATUS1__RST_COMP,
118 INTR_STATUS2__RST_COMP, 119 INTR_STATUS2__RST_COMP,
119 INTR_STATUS3__RST_COMP}; 120 INTR_STATUS3__RST_COMP};
120
121/* specifies the debug level of the driver */
122static int nand_debug_level = 0;
123 121
124/* forward declarations */ 122/* forward declarations */
125static void clear_interrupts(struct denali_nand_info *denali); 123static void clear_interrupts(struct denali_nand_info *denali);
126static uint32_t wait_for_irq(struct denali_nand_info *denali, uint32_t irq_mask); 124static uint32_t wait_for_irq(struct denali_nand_info *denali,
127static void denali_irq_enable(struct denali_nand_info *denali, uint32_t int_mask); 125 uint32_t irq_mask);
126static void denali_irq_enable(struct denali_nand_info *denali,
127 uint32_t int_mask);
128static uint32_t read_interrupt_status(struct denali_nand_info *denali); 128static uint32_t read_interrupt_status(struct denali_nand_info *denali);
129 129
130#define DEBUG_DENALI 0 130/* Certain operations for the denali NAND controller use
131 131 * an indexed mode to read/write data. The operation is
132/* This is a wrapper for writing to the denali registers. 132 * performed by writing the address value of the command
133 * this allows us to create debug information so we can 133 * to the device memory followed by the data. This function
134 * observe how the driver is programming the device. 134 * abstracts this common operation.
135 * it uses standard linux convention for (val, addr) */
136static void denali_write32(uint32_t value, void *addr)
137{
138 iowrite32(value, addr);
139
140#if DEBUG_DENALI
141 printk(KERN_ERR "wrote: 0x%x -> 0x%x\n", value, (uint32_t)((uint32_t)addr & 0x1fff));
142#endif
143}
144
145/* Certain operations for the denali NAND controller use an indexed mode to read/write
146 data. The operation is performed by writing the address value of the command to
147 the device memory followed by the data. This function abstracts this common
148 operation.
149*/ 135*/
150static void index_addr(struct denali_nand_info *denali, uint32_t address, uint32_t data) 136static void index_addr(struct denali_nand_info *denali,
137 uint32_t address, uint32_t data)
151{ 138{
152 denali_write32(address, denali->flash_mem); 139 iowrite32(address, denali->flash_mem);
153 denali_write32(data, denali->flash_mem + 0x10); 140 iowrite32(data, denali->flash_mem + 0x10);
154} 141}
155 142
156/* Perform an indexed read of the device */ 143/* Perform an indexed read of the device */
157static void index_addr_read_data(struct denali_nand_info *denali, 144static void index_addr_read_data(struct denali_nand_info *denali,
158 uint32_t address, uint32_t *pdata) 145 uint32_t address, uint32_t *pdata)
159{ 146{
160 denali_write32(address, denali->flash_mem); 147 iowrite32(address, denali->flash_mem);
161 *pdata = ioread32(denali->flash_mem + 0x10); 148 *pdata = ioread32(denali->flash_mem + 0x10);
162} 149}
163 150
164/* We need to buffer some data for some of the NAND core routines. 151/* We need to buffer some data for some of the NAND core routines.
165 * The operations manage buffering that data. */ 152 * The operations manage buffering that data. */
166static void reset_buf(struct denali_nand_info *denali) 153static void reset_buf(struct denali_nand_info *denali)
167{ 154{
@@ -182,75 +169,70 @@ static void read_status(struct denali_nand_info *denali)
182 /* initialize the data buffer to store status */ 169 /* initialize the data buffer to store status */
183 reset_buf(denali); 170 reset_buf(denali);
184 171
185 /* initiate a device status read */ 172 cmd = ioread32(denali->flash_reg + WRITE_PROTECT);
186 cmd = MODE_11 | BANK(denali->flash_bank); 173 if (cmd)
187 index_addr(denali, cmd | COMMAND_CYCLE, 0x70); 174 write_byte_to_buf(denali, NAND_STATUS_WP);
188 denali_write32(cmd | STATUS_CYCLE, denali->flash_mem); 175 else
189 176 write_byte_to_buf(denali, 0);
190 /* update buffer with status value */
191 write_byte_to_buf(denali, ioread32(denali->flash_mem + 0x10));
192
193#if DEBUG_DENALI
194 printk("device reporting status value of 0x%2x\n", denali->buf.buf[0]);
195#endif
196} 177}
197 178
198/* resets a specific device connected to the core */ 179/* resets a specific device connected to the core */
199static void reset_bank(struct denali_nand_info *denali) 180static void reset_bank(struct denali_nand_info *denali)
200{ 181{
201 uint32_t irq_status = 0; 182 uint32_t irq_status = 0;
202 uint32_t irq_mask = reset_complete[denali->flash_bank] | 183 uint32_t irq_mask = reset_complete[denali->flash_bank] |
203 operation_timeout[denali->flash_bank]; 184 operation_timeout[denali->flash_bank];
204 int bank = 0; 185 int bank = 0;
205 186
206 clear_interrupts(denali); 187 clear_interrupts(denali);
207 188
208 bank = device_reset_banks[denali->flash_bank]; 189 bank = device_reset_banks[denali->flash_bank];
209 denali_write32(bank, denali->flash_reg + DEVICE_RESET); 190 iowrite32(bank, denali->flash_reg + DEVICE_RESET);
210 191
211 irq_status = wait_for_irq(denali, irq_mask); 192 irq_status = wait_for_irq(denali, irq_mask);
212 193
213 if (irq_status & operation_timeout[denali->flash_bank]) 194 if (irq_status & operation_timeout[denali->flash_bank])
214 { 195 dev_err(&denali->dev->dev, "reset bank failed.\n");
215 printk(KERN_ERR "reset bank failed.\n");
216 }
217} 196}
218 197
219/* Reset the flash controller */ 198/* Reset the flash controller */
220static uint16_t NAND_Flash_Reset(struct denali_nand_info *denali) 199static uint16_t denali_nand_reset(struct denali_nand_info *denali)
221{ 200{
222 uint32_t i; 201 uint32_t i;
223 202
224 nand_dbg_print(NAND_DBG_TRACE, "%s, Line %d, Function: %s\n", 203 dev_dbg(&denali->dev->dev, "%s, Line %d, Function: %s\n",
225 __FILE__, __LINE__, __func__); 204 __FILE__, __LINE__, __func__);
226 205
227 for (i = 0 ; i < LLD_MAX_FLASH_BANKS; i++) 206 for (i = 0 ; i < LLD_MAX_FLASH_BANKS; i++)
228 denali_write32(reset_complete[i] | operation_timeout[i], 207 iowrite32(reset_complete[i] | operation_timeout[i],
229 denali->flash_reg + intr_status_addresses[i]); 208 denali->flash_reg + intr_status_addresses[i]);
230 209
231 for (i = 0 ; i < LLD_MAX_FLASH_BANKS; i++) { 210 for (i = 0 ; i < LLD_MAX_FLASH_BANKS; i++) {
232 denali_write32(device_reset_banks[i], denali->flash_reg + DEVICE_RESET); 211 iowrite32(device_reset_banks[i],
233 while (!(ioread32(denali->flash_reg + intr_status_addresses[i]) & 212 denali->flash_reg + DEVICE_RESET);
213 while (!(ioread32(denali->flash_reg +
214 intr_status_addresses[i]) &
234 (reset_complete[i] | operation_timeout[i]))) 215 (reset_complete[i] | operation_timeout[i])))
235 ; 216 cpu_relax();
236 if (ioread32(denali->flash_reg + intr_status_addresses[i]) & 217 if (ioread32(denali->flash_reg + intr_status_addresses[i]) &
237 operation_timeout[i]) 218 operation_timeout[i])
238 nand_dbg_print(NAND_DBG_WARN, 219 dev_dbg(&denali->dev->dev,
239 "NAND Reset operation timed out on bank %d\n", i); 220 "NAND Reset operation timed out on bank %d\n", i);
240 } 221 }
241 222
242 for (i = 0; i < LLD_MAX_FLASH_BANKS; i++) 223 for (i = 0; i < LLD_MAX_FLASH_BANKS; i++)
243 denali_write32(reset_complete[i] | operation_timeout[i], 224 iowrite32(reset_complete[i] | operation_timeout[i],
244 denali->flash_reg + intr_status_addresses[i]); 225 denali->flash_reg + intr_status_addresses[i]);
245 226
246 return PASS; 227 return PASS;
247} 228}
248 229
249/* this routine calculates the ONFI timing values for a given mode and programs 230/* this routine calculates the ONFI timing values for a given mode and
250 * the clocking register accordingly. The mode is determined by the get_onfi_nand_para 231 * programs the clocking register accordingly. The mode is determined by
251 routine. 232 * the get_onfi_nand_para routine.
252 */ 233 */
253static void NAND_ONFi_Timing_Mode(struct denali_nand_info *denali, uint16_t mode) 234static void nand_onfi_timing_set(struct denali_nand_info *denali,
235 uint16_t mode)
254{ 236{
255 uint16_t Trea[6] = {40, 30, 25, 20, 20, 16}; 237 uint16_t Trea[6] = {40, 30, 25, 20, 20, 16};
256 uint16_t Trp[6] = {50, 25, 17, 15, 12, 10}; 238 uint16_t Trp[6] = {50, 25, 17, 15, 12, 10};
@@ -272,7 +254,7 @@ static void NAND_ONFi_Timing_Mode(struct denali_nand_info *denali, uint16_t mode
272 uint16_t acc_clks; 254 uint16_t acc_clks;
273 uint16_t addr_2_data, re_2_we, re_2_re, we_2_re, cs_cnt; 255 uint16_t addr_2_data, re_2_we, re_2_re, we_2_re, cs_cnt;
274 256
275 nand_dbg_print(NAND_DBG_TRACE, "%s, Line %d, Function: %s\n", 257 dev_dbg(&denali->dev->dev, "%s, Line %d, Function: %s\n",
276 __FILE__, __LINE__, __func__); 258 __FILE__, __LINE__, __func__);
277 259
278 en_lo = CEIL_DIV(Trp[mode], CLK_X); 260 en_lo = CEIL_DIV(Trp[mode], CLK_X);
@@ -309,7 +291,7 @@ static void NAND_ONFi_Timing_Mode(struct denali_nand_info *denali, uint16_t mode
309 acc_clks++; 291 acc_clks++;
310 292
311 if ((data_invalid - acc_clks * CLK_X) < 2) 293 if ((data_invalid - acc_clks * CLK_X) < 2)
312 nand_dbg_print(NAND_DBG_WARN, "%s, Line %d: Warning!\n", 294 dev_warn(&denali->dev->dev, "%s, Line %d: Warning!\n",
313 __FILE__, __LINE__); 295 __FILE__, __LINE__);
314 296
315 addr_2_data = CEIL_DIV(Tadl[mode], CLK_X); 297 addr_2_data = CEIL_DIV(Tadl[mode], CLK_X);
@@ -337,146 +319,34 @@ static void NAND_ONFi_Timing_Mode(struct denali_nand_info *denali, uint16_t mode
337 (ioread32(denali->flash_reg + DEVICE_ID) == 0x88)) 319 (ioread32(denali->flash_reg + DEVICE_ID) == 0x88))
338 acc_clks = 6; 320 acc_clks = 6;
339 321
340 denali_write32(acc_clks, denali->flash_reg + ACC_CLKS); 322 iowrite32(acc_clks, denali->flash_reg + ACC_CLKS);
341 denali_write32(re_2_we, denali->flash_reg + RE_2_WE); 323 iowrite32(re_2_we, denali->flash_reg + RE_2_WE);
342 denali_write32(re_2_re, denali->flash_reg + RE_2_RE); 324 iowrite32(re_2_re, denali->flash_reg + RE_2_RE);
343 denali_write32(we_2_re, denali->flash_reg + WE_2_RE); 325 iowrite32(we_2_re, denali->flash_reg + WE_2_RE);
344 denali_write32(addr_2_data, denali->flash_reg + ADDR_2_DATA); 326 iowrite32(addr_2_data, denali->flash_reg + ADDR_2_DATA);
345 denali_write32(en_lo, denali->flash_reg + RDWR_EN_LO_CNT); 327 iowrite32(en_lo, denali->flash_reg + RDWR_EN_LO_CNT);
346 denali_write32(en_hi, denali->flash_reg + RDWR_EN_HI_CNT); 328 iowrite32(en_hi, denali->flash_reg + RDWR_EN_HI_CNT);
347 denali_write32(cs_cnt, denali->flash_reg + CS_SETUP_CNT); 329 iowrite32(cs_cnt, denali->flash_reg + CS_SETUP_CNT);
348}
349
350/* configures the initial ECC settings for the controller */
351static void set_ecc_config(struct denali_nand_info *denali)
352{
353#if SUPPORT_8BITECC
354 if ((ioread32(denali->flash_reg + DEVICE_MAIN_AREA_SIZE) < 4096) ||
355 (ioread32(denali->flash_reg + DEVICE_SPARE_AREA_SIZE) <= 128))
356 denali_write32(8, denali->flash_reg + ECC_CORRECTION);
357#endif
358
359 if ((ioread32(denali->flash_reg + ECC_CORRECTION) & ECC_CORRECTION__VALUE)
360 == 1) {
361 denali->dev_info.wECCBytesPerSector = 4;
362 denali->dev_info.wECCBytesPerSector *= denali->dev_info.wDevicesConnected;
363 denali->dev_info.wNumPageSpareFlag =
364 denali->dev_info.wPageSpareSize -
365 denali->dev_info.wPageDataSize /
366 (ECC_SECTOR_SIZE * denali->dev_info.wDevicesConnected) *
367 denali->dev_info.wECCBytesPerSector
368 - denali->dev_info.wSpareSkipBytes;
369 } else {
370 denali->dev_info.wECCBytesPerSector =
371 (ioread32(denali->flash_reg + ECC_CORRECTION) &
372 ECC_CORRECTION__VALUE) * 13 / 8;
373 if ((denali->dev_info.wECCBytesPerSector) % 2 == 0)
374 denali->dev_info.wECCBytesPerSector += 2;
375 else
376 denali->dev_info.wECCBytesPerSector += 1;
377
378 denali->dev_info.wECCBytesPerSector *= denali->dev_info.wDevicesConnected;
379 denali->dev_info.wNumPageSpareFlag = denali->dev_info.wPageSpareSize -
380 denali->dev_info.wPageDataSize /
381 (ECC_SECTOR_SIZE * denali->dev_info.wDevicesConnected) *
382 denali->dev_info.wECCBytesPerSector
383 - denali->dev_info.wSpareSkipBytes;
384 }
385} 330}
386 331
387/* queries the NAND device to see what ONFI modes it supports. */ 332/* queries the NAND device to see what ONFI modes it supports. */
388static uint16_t get_onfi_nand_para(struct denali_nand_info *denali) 333static uint16_t get_onfi_nand_para(struct denali_nand_info *denali)
389{ 334{
390 int i; 335 int i;
391 uint16_t blks_lun_l, blks_lun_h, n_of_luns; 336 /* we needn't to do a reset here because driver has already
392 uint32_t blockperlun, id; 337 * reset all the banks before
393 338 * */
394 denali_write32(DEVICE_RESET__BANK0, denali->flash_reg + DEVICE_RESET);
395
396 while (!((ioread32(denali->flash_reg + INTR_STATUS0) &
397 INTR_STATUS0__RST_COMP) |
398 (ioread32(denali->flash_reg + INTR_STATUS0) &
399 INTR_STATUS0__TIME_OUT)))
400 ;
401
402 if (ioread32(denali->flash_reg + INTR_STATUS0) & INTR_STATUS0__RST_COMP) {
403 denali_write32(DEVICE_RESET__BANK1, denali->flash_reg + DEVICE_RESET);
404 while (!((ioread32(denali->flash_reg + INTR_STATUS1) &
405 INTR_STATUS1__RST_COMP) |
406 (ioread32(denali->flash_reg + INTR_STATUS1) &
407 INTR_STATUS1__TIME_OUT)))
408 ;
409
410 if (ioread32(denali->flash_reg + INTR_STATUS1) &
411 INTR_STATUS1__RST_COMP) {
412 denali_write32(DEVICE_RESET__BANK2,
413 denali->flash_reg + DEVICE_RESET);
414 while (!((ioread32(denali->flash_reg + INTR_STATUS2) &
415 INTR_STATUS2__RST_COMP) |
416 (ioread32(denali->flash_reg + INTR_STATUS2) &
417 INTR_STATUS2__TIME_OUT)))
418 ;
419
420 if (ioread32(denali->flash_reg + INTR_STATUS2) &
421 INTR_STATUS2__RST_COMP) {
422 denali_write32(DEVICE_RESET__BANK3,
423 denali->flash_reg + DEVICE_RESET);
424 while (!((ioread32(denali->flash_reg + INTR_STATUS3) &
425 INTR_STATUS3__RST_COMP) |
426 (ioread32(denali->flash_reg + INTR_STATUS3) &
427 INTR_STATUS3__TIME_OUT)))
428 ;
429 } else {
430 printk(KERN_ERR "Getting a time out for bank 2!\n");
431 }
432 } else {
433 printk(KERN_ERR "Getting a time out for bank 1!\n");
434 }
435 }
436
437 denali_write32(INTR_STATUS0__TIME_OUT, denali->flash_reg + INTR_STATUS0);
438 denali_write32(INTR_STATUS1__TIME_OUT, denali->flash_reg + INTR_STATUS1);
439 denali_write32(INTR_STATUS2__TIME_OUT, denali->flash_reg + INTR_STATUS2);
440 denali_write32(INTR_STATUS3__TIME_OUT, denali->flash_reg + INTR_STATUS3);
441
442 denali->dev_info.wONFIDevFeatures =
443 ioread32(denali->flash_reg + ONFI_DEVICE_FEATURES);
444 denali->dev_info.wONFIOptCommands =
445 ioread32(denali->flash_reg + ONFI_OPTIONAL_COMMANDS);
446 denali->dev_info.wONFITimingMode =
447 ioread32(denali->flash_reg + ONFI_TIMING_MODE);
448 denali->dev_info.wONFIPgmCacheTimingMode =
449 ioread32(denali->flash_reg + ONFI_PGM_CACHE_TIMING_MODE);
450
451 n_of_luns = ioread32(denali->flash_reg + ONFI_DEVICE_NO_OF_LUNS) &
452 ONFI_DEVICE_NO_OF_LUNS__NO_OF_LUNS;
453 blks_lun_l = ioread32(denali->flash_reg + ONFI_DEVICE_NO_OF_BLOCKS_PER_LUN_L);
454 blks_lun_h = ioread32(denali->flash_reg + ONFI_DEVICE_NO_OF_BLOCKS_PER_LUN_U);
455
456 blockperlun = (blks_lun_h << 16) | blks_lun_l;
457
458 denali->dev_info.wTotalBlocks = n_of_luns * blockperlun;
459
460 if (!(ioread32(denali->flash_reg + ONFI_TIMING_MODE) & 339 if (!(ioread32(denali->flash_reg + ONFI_TIMING_MODE) &
461 ONFI_TIMING_MODE__VALUE)) 340 ONFI_TIMING_MODE__VALUE))
462 return FAIL; 341 return FAIL;
463 342
464 for (i = 5; i > 0; i--) { 343 for (i = 5; i > 0; i--) {
465 if (ioread32(denali->flash_reg + ONFI_TIMING_MODE) & (0x01 << i)) 344 if (ioread32(denali->flash_reg + ONFI_TIMING_MODE) &
345 (0x01 << i))
466 break; 346 break;
467 } 347 }
468 348
469 NAND_ONFi_Timing_Mode(denali, i); 349 nand_onfi_timing_set(denali, i);
470
471 index_addr(denali, MODE_11 | 0, 0x90);
472 index_addr(denali, MODE_11 | 1, 0);
473
474 for (i = 0; i < 3; i++)
475 index_addr_read_data(denali, MODE_11 | 2, &id);
476
477 nand_dbg_print(NAND_DBG_DEBUG, "3rd ID: 0x%x\n", id);
478
479 denali->dev_info.MLCDevice = id & 0x0C;
480 350
481 /* By now, all the ONFI devices we know support the page cache */ 351 /* By now, all the ONFI devices we know support the page cache */
482 /* rw feature. So here we enable the pipeline_rw_ahead feature */ 352 /* rw feature. So here we enable the pipeline_rw_ahead feature */
@@ -486,131 +356,78 @@ static uint16_t get_onfi_nand_para(struct denali_nand_info *denali)
486 return PASS; 356 return PASS;
487} 357}
488 358
489static void get_samsung_nand_para(struct denali_nand_info *denali) 359static void get_samsung_nand_para(struct denali_nand_info *denali,
360 uint8_t device_id)
490{ 361{
491 uint8_t no_of_planes; 362 if (device_id == 0xd3) { /* Samsung K9WAG08U1A */
492 uint32_t blk_size;
493 uint64_t plane_size, capacity;
494 uint32_t id_bytes[5];
495 int i;
496
497 index_addr(denali, (uint32_t)(MODE_11 | 0), 0x90);
498 index_addr(denali, (uint32_t)(MODE_11 | 1), 0);
499 for (i = 0; i < 5; i++)
500 index_addr_read_data(denali, (uint32_t)(MODE_11 | 2), &id_bytes[i]);
501
502 nand_dbg_print(NAND_DBG_DEBUG,
503 "ID bytes: 0x%x, 0x%x, 0x%x, 0x%x, 0x%x\n",
504 id_bytes[0], id_bytes[1], id_bytes[2],
505 id_bytes[3], id_bytes[4]);
506
507 if ((id_bytes[1] & 0xff) == 0xd3) { /* Samsung K9WAG08U1A */
508 /* Set timing register values according to datasheet */ 363 /* Set timing register values according to datasheet */
509 denali_write32(5, denali->flash_reg + ACC_CLKS); 364 iowrite32(5, denali->flash_reg + ACC_CLKS);
510 denali_write32(20, denali->flash_reg + RE_2_WE); 365 iowrite32(20, denali->flash_reg + RE_2_WE);
511 denali_write32(12, denali->flash_reg + WE_2_RE); 366 iowrite32(12, denali->flash_reg + WE_2_RE);
512 denali_write32(14, denali->flash_reg + ADDR_2_DATA); 367 iowrite32(14, denali->flash_reg + ADDR_2_DATA);
513 denali_write32(3, denali->flash_reg + RDWR_EN_LO_CNT); 368 iowrite32(3, denali->flash_reg + RDWR_EN_LO_CNT);
514 denali_write32(2, denali->flash_reg + RDWR_EN_HI_CNT); 369 iowrite32(2, denali->flash_reg + RDWR_EN_HI_CNT);
515 denali_write32(2, denali->flash_reg + CS_SETUP_CNT); 370 iowrite32(2, denali->flash_reg + CS_SETUP_CNT);
516 } 371 }
517
518 no_of_planes = 1 << ((id_bytes[4] & 0x0c) >> 2);
519 plane_size = (uint64_t)64 << ((id_bytes[4] & 0x70) >> 4);
520 blk_size = 64 << ((ioread32(denali->flash_reg + DEVICE_PARAM_1) & 0x30) >> 4);
521 capacity = (uint64_t)128 * plane_size * no_of_planes;
522
523 do_div(capacity, blk_size);
524 denali->dev_info.wTotalBlocks = capacity;
525} 372}
526 373
527static void get_toshiba_nand_para(struct denali_nand_info *denali) 374static void get_toshiba_nand_para(struct denali_nand_info *denali)
528{ 375{
529 void __iomem *scratch_reg;
530 uint32_t tmp; 376 uint32_t tmp;
531 377
532 /* Workaround to fix a controller bug which reports a wrong */ 378 /* Workaround to fix a controller bug which reports a wrong */
533 /* spare area size for some kind of Toshiba NAND device */ 379 /* spare area size for some kind of Toshiba NAND device */
534 if ((ioread32(denali->flash_reg + DEVICE_MAIN_AREA_SIZE) == 4096) && 380 if ((ioread32(denali->flash_reg + DEVICE_MAIN_AREA_SIZE) == 4096) &&
535 (ioread32(denali->flash_reg + DEVICE_SPARE_AREA_SIZE) == 64)) { 381 (ioread32(denali->flash_reg + DEVICE_SPARE_AREA_SIZE) == 64)) {
536 denali_write32(216, denali->flash_reg + DEVICE_SPARE_AREA_SIZE); 382 iowrite32(216, denali->flash_reg + DEVICE_SPARE_AREA_SIZE);
537 tmp = ioread32(denali->flash_reg + DEVICES_CONNECTED) * 383 tmp = ioread32(denali->flash_reg + DEVICES_CONNECTED) *
538 ioread32(denali->flash_reg + DEVICE_SPARE_AREA_SIZE); 384 ioread32(denali->flash_reg + DEVICE_SPARE_AREA_SIZE);
539 denali_write32(tmp, denali->flash_reg + LOGICAL_PAGE_SPARE_SIZE); 385 iowrite32(tmp,
386 denali->flash_reg + LOGICAL_PAGE_SPARE_SIZE);
540#if SUPPORT_15BITECC 387#if SUPPORT_15BITECC
541 denali_write32(15, denali->flash_reg + ECC_CORRECTION); 388 iowrite32(15, denali->flash_reg + ECC_CORRECTION);
542#elif SUPPORT_8BITECC 389#elif SUPPORT_8BITECC
543 denali_write32(8, denali->flash_reg + ECC_CORRECTION); 390 iowrite32(8, denali->flash_reg + ECC_CORRECTION);
544#endif 391#endif
545 } 392 }
546
547 /* As Toshiba NAND can not provide it's block number, */
548 /* so here we need user to provide the correct block */
549 /* number in a scratch register before the Linux NAND */
550 /* driver is loaded. If no valid value found in the scratch */
551 /* register, then we use default block number value */
552 scratch_reg = ioremap_nocache(SCRATCH_REG_ADDR, SCRATCH_REG_SIZE);
553 if (!scratch_reg) {
554 printk(KERN_ERR "Spectra: ioremap failed in %s, Line %d",
555 __FILE__, __LINE__);
556 denali->dev_info.wTotalBlocks = GLOB_HWCTL_DEFAULT_BLKS;
557 } else {
558 nand_dbg_print(NAND_DBG_WARN,
559 "Spectra: ioremap reg address: 0x%p\n", scratch_reg);
560 denali->dev_info.wTotalBlocks = 1 << ioread8(scratch_reg);
561 if (denali->dev_info.wTotalBlocks < 512)
562 denali->dev_info.wTotalBlocks = GLOB_HWCTL_DEFAULT_BLKS;
563 iounmap(scratch_reg);
564 }
565} 393}
566 394
567static void get_hynix_nand_para(struct denali_nand_info *denali) 395static void get_hynix_nand_para(struct denali_nand_info *denali,
396 uint8_t device_id)
568{ 397{
569 void __iomem *scratch_reg;
570 uint32_t main_size, spare_size; 398 uint32_t main_size, spare_size;
571 399
572 switch (denali->dev_info.wDeviceID) { 400 switch (device_id) {
573 case 0xD5: /* Hynix H27UAG8T2A, H27UBG8U5A or H27UCG8VFA */ 401 case 0xD5: /* Hynix H27UAG8T2A, H27UBG8U5A or H27UCG8VFA */
574 case 0xD7: /* Hynix H27UDG8VEM, H27UCG8UDM or H27UCG8V5A */ 402 case 0xD7: /* Hynix H27UDG8VEM, H27UCG8UDM or H27UCG8V5A */
575 denali_write32(128, denali->flash_reg + PAGES_PER_BLOCK); 403 iowrite32(128, denali->flash_reg + PAGES_PER_BLOCK);
576 denali_write32(4096, denali->flash_reg + DEVICE_MAIN_AREA_SIZE); 404 iowrite32(4096, denali->flash_reg + DEVICE_MAIN_AREA_SIZE);
577 denali_write32(224, denali->flash_reg + DEVICE_SPARE_AREA_SIZE); 405 iowrite32(224, denali->flash_reg + DEVICE_SPARE_AREA_SIZE);
578 main_size = 4096 * ioread32(denali->flash_reg + DEVICES_CONNECTED); 406 main_size = 4096 *
579 spare_size = 224 * ioread32(denali->flash_reg + DEVICES_CONNECTED); 407 ioread32(denali->flash_reg + DEVICES_CONNECTED);
580 denali_write32(main_size, denali->flash_reg + LOGICAL_PAGE_DATA_SIZE); 408 spare_size = 224 *
581 denali_write32(spare_size, denali->flash_reg + LOGICAL_PAGE_SPARE_SIZE); 409 ioread32(denali->flash_reg + DEVICES_CONNECTED);
582 denali_write32(0, denali->flash_reg + DEVICE_WIDTH); 410 iowrite32(main_size,
411 denali->flash_reg + LOGICAL_PAGE_DATA_SIZE);
412 iowrite32(spare_size,
413 denali->flash_reg + LOGICAL_PAGE_SPARE_SIZE);
414 iowrite32(0, denali->flash_reg + DEVICE_WIDTH);
583#if SUPPORT_15BITECC 415#if SUPPORT_15BITECC
584 denali_write32(15, denali->flash_reg + ECC_CORRECTION); 416 iowrite32(15, denali->flash_reg + ECC_CORRECTION);
585#elif SUPPORT_8BITECC 417#elif SUPPORT_8BITECC
586 denali_write32(8, denali->flash_reg + ECC_CORRECTION); 418 iowrite32(8, denali->flash_reg + ECC_CORRECTION);
587#endif 419#endif
588 denali->dev_info.MLCDevice = 1;
589 break; 420 break;
590 default: 421 default:
591 nand_dbg_print(NAND_DBG_WARN, 422 dev_warn(&denali->dev->dev,
592 "Spectra: Unknown Hynix NAND (Device ID: 0x%x)." 423 "Spectra: Unknown Hynix NAND (Device ID: 0x%x)."
593 "Will use default parameter values instead.\n", 424 "Will use default parameter values instead.\n",
594 denali->dev_info.wDeviceID); 425 device_id);
595 }
596
597 scratch_reg = ioremap_nocache(SCRATCH_REG_ADDR, SCRATCH_REG_SIZE);
598 if (!scratch_reg) {
599 printk(KERN_ERR "Spectra: ioremap failed in %s, Line %d",
600 __FILE__, __LINE__);
601 denali->dev_info.wTotalBlocks = GLOB_HWCTL_DEFAULT_BLKS;
602 } else {
603 nand_dbg_print(NAND_DBG_WARN,
604 "Spectra: ioremap reg address: 0x%p\n", scratch_reg);
605 denali->dev_info.wTotalBlocks = 1 << ioread8(scratch_reg);
606 if (denali->dev_info.wTotalBlocks < 512)
607 denali->dev_info.wTotalBlocks = GLOB_HWCTL_DEFAULT_BLKS;
608 iounmap(scratch_reg);
609 } 426 }
610} 427}
611 428
612/* determines how many NAND chips are connected to the controller. Note for 429/* determines how many NAND chips are connected to the controller. Note for
613 Intel CE4100 devices we don't support more than one device. 430 * Intel CE4100 devices we don't support more than one device.
614 */ 431 */
615static void find_valid_banks(struct denali_nand_info *denali) 432static void find_valid_banks(struct denali_nand_info *denali)
616{ 433{
@@ -621,9 +438,10 @@ static void find_valid_banks(struct denali_nand_info *denali)
621 for (i = 0; i < LLD_MAX_FLASH_BANKS; i++) { 438 for (i = 0; i < LLD_MAX_FLASH_BANKS; i++) {
622 index_addr(denali, (uint32_t)(MODE_11 | (i << 24) | 0), 0x90); 439 index_addr(denali, (uint32_t)(MODE_11 | (i << 24) | 0), 0x90);
623 index_addr(denali, (uint32_t)(MODE_11 | (i << 24) | 1), 0); 440 index_addr(denali, (uint32_t)(MODE_11 | (i << 24) | 1), 0);
624 index_addr_read_data(denali, (uint32_t)(MODE_11 | (i << 24) | 2), &id[i]); 441 index_addr_read_data(denali,
442 (uint32_t)(MODE_11 | (i << 24) | 2), &id[i]);
625 443
626 nand_dbg_print(NAND_DBG_DEBUG, 444 dev_dbg(&denali->dev->dev,
627 "Return 1st ID for bank[%d]: %x\n", i, id[i]); 445 "Return 1st ID for bank[%d]: %x\n", i, id[i]);
628 446
629 if (i == 0) { 447 if (i == 0) {
@@ -637,282 +455,126 @@ static void find_valid_banks(struct denali_nand_info *denali)
637 } 455 }
638 } 456 }
639 457
640 if (denali->platform == INTEL_CE4100) 458 if (denali->platform == INTEL_CE4100) {
641 {
642 /* Platform limitations of the CE4100 device limit 459 /* Platform limitations of the CE4100 device limit
643 * users to a single chip solution for NAND. 460 * users to a single chip solution for NAND.
644 * Multichip support is not enabled. 461 * Multichip support is not enabled.
645 */ 462 */
646 if (denali->total_used_banks != 1) 463 if (denali->total_used_banks != 1) {
647 { 464 dev_err(&denali->dev->dev,
648 printk(KERN_ERR "Sorry, Intel CE4100 only supports " 465 "Sorry, Intel CE4100 only supports "
649 "a single NAND device.\n"); 466 "a single NAND device.\n");
650 BUG(); 467 BUG();
651 } 468 }
652 } 469 }
653 nand_dbg_print(NAND_DBG_DEBUG, 470 dev_dbg(&denali->dev->dev,
654 "denali->total_used_banks: %d\n", denali->total_used_banks); 471 "denali->total_used_banks: %d\n", denali->total_used_banks);
655} 472}
656 473
657static void detect_partition_feature(struct denali_nand_info *denali) 474static void detect_partition_feature(struct denali_nand_info *denali)
658{ 475{
476 /* For MRST platform, denali->fwblks represent the
477 * number of blocks firmware is taken,
478 * FW is in protect partition and MTD driver has no
479 * permission to access it. So let driver know how many
480 * blocks it can't touch.
481 * */
659 if (ioread32(denali->flash_reg + FEATURES) & FEATURES__PARTITION) { 482 if (ioread32(denali->flash_reg + FEATURES) & FEATURES__PARTITION) {
660 if ((ioread32(denali->flash_reg + PERM_SRC_ID_1) & 483 if ((ioread32(denali->flash_reg + PERM_SRC_ID_1) &
661 PERM_SRC_ID_1__SRCID) == SPECTRA_PARTITION_ID) { 484 PERM_SRC_ID_1__SRCID) == SPECTRA_PARTITION_ID) {
662 denali->dev_info.wSpectraStartBlock = 485 denali->fwblks =
663 ((ioread32(denali->flash_reg + MIN_MAX_BANK_1) & 486 ((ioread32(denali->flash_reg + MIN_MAX_BANK_1) &
664 MIN_MAX_BANK_1__MIN_VALUE) * 487 MIN_MAX_BANK_1__MIN_VALUE) *
665 denali->dev_info.wTotalBlocks) 488 denali->blksperchip)
666 + 489 +
667 (ioread32(denali->flash_reg + MIN_BLK_ADDR_1) & 490 (ioread32(denali->flash_reg + MIN_BLK_ADDR_1) &
668 MIN_BLK_ADDR_1__VALUE); 491 MIN_BLK_ADDR_1__VALUE);
669 492 } else
670 denali->dev_info.wSpectraEndBlock = 493 denali->fwblks = SPECTRA_START_BLOCK;
671 (((ioread32(denali->flash_reg + MIN_MAX_BANK_1) & 494 } else
672 MIN_MAX_BANK_1__MAX_VALUE) >> 2) * 495 denali->fwblks = SPECTRA_START_BLOCK;
673 denali->dev_info.wTotalBlocks)
674 +
675 (ioread32(denali->flash_reg + MAX_BLK_ADDR_1) &
676 MAX_BLK_ADDR_1__VALUE);
677
678 denali->dev_info.wTotalBlocks *= denali->total_used_banks;
679
680 if (denali->dev_info.wSpectraEndBlock >=
681 denali->dev_info.wTotalBlocks) {
682 denali->dev_info.wSpectraEndBlock =
683 denali->dev_info.wTotalBlocks - 1;
684 }
685
686 denali->dev_info.wDataBlockNum =
687 denali->dev_info.wSpectraEndBlock -
688 denali->dev_info.wSpectraStartBlock + 1;
689 } else {
690 denali->dev_info.wTotalBlocks *= denali->total_used_banks;
691 denali->dev_info.wSpectraStartBlock = SPECTRA_START_BLOCK;
692 denali->dev_info.wSpectraEndBlock =
693 denali->dev_info.wTotalBlocks - 1;
694 denali->dev_info.wDataBlockNum =
695 denali->dev_info.wSpectraEndBlock -
696 denali->dev_info.wSpectraStartBlock + 1;
697 }
698 } else {
699 denali->dev_info.wTotalBlocks *= denali->total_used_banks;
700 denali->dev_info.wSpectraStartBlock = SPECTRA_START_BLOCK;
701 denali->dev_info.wSpectraEndBlock = denali->dev_info.wTotalBlocks - 1;
702 denali->dev_info.wDataBlockNum =
703 denali->dev_info.wSpectraEndBlock -
704 denali->dev_info.wSpectraStartBlock + 1;
705 }
706} 496}
707 497
708static void dump_device_info(struct denali_nand_info *denali) 498static uint16_t denali_nand_timing_set(struct denali_nand_info *denali)
709{
710 nand_dbg_print(NAND_DBG_DEBUG, "denali->dev_info:\n");
711 nand_dbg_print(NAND_DBG_DEBUG, "DeviceMaker: 0x%x\n",
712 denali->dev_info.wDeviceMaker);
713 nand_dbg_print(NAND_DBG_DEBUG, "DeviceID: 0x%x\n",
714 denali->dev_info.wDeviceID);
715 nand_dbg_print(NAND_DBG_DEBUG, "DeviceType: 0x%x\n",
716 denali->dev_info.wDeviceType);
717 nand_dbg_print(NAND_DBG_DEBUG, "SpectraStartBlock: %d\n",
718 denali->dev_info.wSpectraStartBlock);
719 nand_dbg_print(NAND_DBG_DEBUG, "SpectraEndBlock: %d\n",
720 denali->dev_info.wSpectraEndBlock);
721 nand_dbg_print(NAND_DBG_DEBUG, "TotalBlocks: %d\n",
722 denali->dev_info.wTotalBlocks);
723 nand_dbg_print(NAND_DBG_DEBUG, "PagesPerBlock: %d\n",
724 denali->dev_info.wPagesPerBlock);
725 nand_dbg_print(NAND_DBG_DEBUG, "PageSize: %d\n",
726 denali->dev_info.wPageSize);
727 nand_dbg_print(NAND_DBG_DEBUG, "PageDataSize: %d\n",
728 denali->dev_info.wPageDataSize);
729 nand_dbg_print(NAND_DBG_DEBUG, "PageSpareSize: %d\n",
730 denali->dev_info.wPageSpareSize);
731 nand_dbg_print(NAND_DBG_DEBUG, "NumPageSpareFlag: %d\n",
732 denali->dev_info.wNumPageSpareFlag);
733 nand_dbg_print(NAND_DBG_DEBUG, "ECCBytesPerSector: %d\n",
734 denali->dev_info.wECCBytesPerSector);
735 nand_dbg_print(NAND_DBG_DEBUG, "BlockSize: %d\n",
736 denali->dev_info.wBlockSize);
737 nand_dbg_print(NAND_DBG_DEBUG, "BlockDataSize: %d\n",
738 denali->dev_info.wBlockDataSize);
739 nand_dbg_print(NAND_DBG_DEBUG, "DataBlockNum: %d\n",
740 denali->dev_info.wDataBlockNum);
741 nand_dbg_print(NAND_DBG_DEBUG, "PlaneNum: %d\n",
742 denali->dev_info.bPlaneNum);
743 nand_dbg_print(NAND_DBG_DEBUG, "DeviceMainAreaSize: %d\n",
744 denali->dev_info.wDeviceMainAreaSize);
745 nand_dbg_print(NAND_DBG_DEBUG, "DeviceSpareAreaSize: %d\n",
746 denali->dev_info.wDeviceSpareAreaSize);
747 nand_dbg_print(NAND_DBG_DEBUG, "DevicesConnected: %d\n",
748 denali->dev_info.wDevicesConnected);
749 nand_dbg_print(NAND_DBG_DEBUG, "DeviceWidth: %d\n",
750 denali->dev_info.wDeviceWidth);
751 nand_dbg_print(NAND_DBG_DEBUG, "HWRevision: 0x%x\n",
752 denali->dev_info.wHWRevision);
753 nand_dbg_print(NAND_DBG_DEBUG, "HWFeatures: 0x%x\n",
754 denali->dev_info.wHWFeatures);
755 nand_dbg_print(NAND_DBG_DEBUG, "ONFIDevFeatures: 0x%x\n",
756 denali->dev_info.wONFIDevFeatures);
757 nand_dbg_print(NAND_DBG_DEBUG, "ONFIOptCommands: 0x%x\n",
758 denali->dev_info.wONFIOptCommands);
759 nand_dbg_print(NAND_DBG_DEBUG, "ONFITimingMode: 0x%x\n",
760 denali->dev_info.wONFITimingMode);
761 nand_dbg_print(NAND_DBG_DEBUG, "ONFIPgmCacheTimingMode: 0x%x\n",
762 denali->dev_info.wONFIPgmCacheTimingMode);
763 nand_dbg_print(NAND_DBG_DEBUG, "MLCDevice: %s\n",
764 denali->dev_info.MLCDevice ? "Yes" : "No");
765 nand_dbg_print(NAND_DBG_DEBUG, "SpareSkipBytes: %d\n",
766 denali->dev_info.wSpareSkipBytes);
767 nand_dbg_print(NAND_DBG_DEBUG, "BitsInPageNumber: %d\n",
768 denali->dev_info.nBitsInPageNumber);
769 nand_dbg_print(NAND_DBG_DEBUG, "BitsInPageDataSize: %d\n",
770 denali->dev_info.nBitsInPageDataSize);
771 nand_dbg_print(NAND_DBG_DEBUG, "BitsInBlockDataSize: %d\n",
772 denali->dev_info.nBitsInBlockDataSize);
773}
774
775static uint16_t NAND_Read_Device_ID(struct denali_nand_info *denali)
776{ 499{
777 uint16_t status = PASS; 500 uint16_t status = PASS;
778 uint8_t no_of_planes; 501 uint32_t id_bytes[5], addr;
779 502 uint8_t i, maf_id, device_id;
780 nand_dbg_print(NAND_DBG_TRACE, "%s, Line %d, Function: %s\n", 503
781 __FILE__, __LINE__, __func__); 504 dev_dbg(&denali->dev->dev,
782 505 "%s, Line %d, Function: %s\n",
783 denali->dev_info.wDeviceMaker = ioread32(denali->flash_reg + MANUFACTURER_ID); 506 __FILE__, __LINE__, __func__);
784 denali->dev_info.wDeviceID = ioread32(denali->flash_reg + DEVICE_ID); 507
785 denali->dev_info.bDeviceParam0 = ioread32(denali->flash_reg + DEVICE_PARAM_0); 508 /* Use read id method to get device ID and other
786 denali->dev_info.bDeviceParam1 = ioread32(denali->flash_reg + DEVICE_PARAM_1); 509 * params. For some NAND chips, controller can't
787 denali->dev_info.bDeviceParam2 = ioread32(denali->flash_reg + DEVICE_PARAM_2); 510 * report the correct device ID by reading from
788 511 * DEVICE_ID register
789 denali->dev_info.MLCDevice = ioread32(denali->flash_reg + DEVICE_PARAM_0) & 0x0c; 512 * */
513 addr = (uint32_t)MODE_11 | BANK(denali->flash_bank);
514 index_addr(denali, (uint32_t)addr | 0, 0x90);
515 index_addr(denali, (uint32_t)addr | 1, 0);
516 for (i = 0; i < 5; i++)
517 index_addr_read_data(denali, addr | 2, &id_bytes[i]);
518 maf_id = id_bytes[0];
519 device_id = id_bytes[1];
790 520
791 if (ioread32(denali->flash_reg + ONFI_DEVICE_NO_OF_LUNS) & 521 if (ioread32(denali->flash_reg + ONFI_DEVICE_NO_OF_LUNS) &
792 ONFI_DEVICE_NO_OF_LUNS__ONFI_DEVICE) { /* ONFI 1.0 NAND */ 522 ONFI_DEVICE_NO_OF_LUNS__ONFI_DEVICE) { /* ONFI 1.0 NAND */
793 if (FAIL == get_onfi_nand_para(denali)) 523 if (FAIL == get_onfi_nand_para(denali))
794 return FAIL; 524 return FAIL;
795 } else if (denali->dev_info.wDeviceMaker == 0xEC) { /* Samsung NAND */ 525 } else if (maf_id == 0xEC) { /* Samsung NAND */
796 get_samsung_nand_para(denali); 526 get_samsung_nand_para(denali, device_id);
797 } else if (denali->dev_info.wDeviceMaker == 0x98) { /* Toshiba NAND */ 527 } else if (maf_id == 0x98) { /* Toshiba NAND */
798 get_toshiba_nand_para(denali); 528 get_toshiba_nand_para(denali);
799 } else if (denali->dev_info.wDeviceMaker == 0xAD) { /* Hynix NAND */ 529 } else if (maf_id == 0xAD) { /* Hynix NAND */
800 get_hynix_nand_para(denali); 530 get_hynix_nand_para(denali, device_id);
801 } else {
802 denali->dev_info.wTotalBlocks = GLOB_HWCTL_DEFAULT_BLKS;
803 } 531 }
804 532
805 nand_dbg_print(NAND_DBG_DEBUG, "Dump timing register values:" 533 dev_info(&denali->dev->dev,
806 "acc_clks: %d, re_2_we: %d, we_2_re: %d," 534 "Dump timing register values:"
807 "addr_2_data: %d, rdwr_en_lo_cnt: %d, " 535 "acc_clks: %d, re_2_we: %d, re_2_re: %d\n"
536 "we_2_re: %d, addr_2_data: %d, rdwr_en_lo_cnt: %d\n"
808 "rdwr_en_hi_cnt: %d, cs_setup_cnt: %d\n", 537 "rdwr_en_hi_cnt: %d, cs_setup_cnt: %d\n",
809 ioread32(denali->flash_reg + ACC_CLKS), 538 ioread32(denali->flash_reg + ACC_CLKS),
810 ioread32(denali->flash_reg + RE_2_WE), 539 ioread32(denali->flash_reg + RE_2_WE),
540 ioread32(denali->flash_reg + RE_2_RE),
811 ioread32(denali->flash_reg + WE_2_RE), 541 ioread32(denali->flash_reg + WE_2_RE),
812 ioread32(denali->flash_reg + ADDR_2_DATA), 542 ioread32(denali->flash_reg + ADDR_2_DATA),
813 ioread32(denali->flash_reg + RDWR_EN_LO_CNT), 543 ioread32(denali->flash_reg + RDWR_EN_LO_CNT),
814 ioread32(denali->flash_reg + RDWR_EN_HI_CNT), 544 ioread32(denali->flash_reg + RDWR_EN_HI_CNT),
815 ioread32(denali->flash_reg + CS_SETUP_CNT)); 545 ioread32(denali->flash_reg + CS_SETUP_CNT));
816 546
817 denali->dev_info.wHWRevision = ioread32(denali->flash_reg + REVISION);
818 denali->dev_info.wHWFeatures = ioread32(denali->flash_reg + FEATURES);
819
820 denali->dev_info.wDeviceMainAreaSize =
821 ioread32(denali->flash_reg + DEVICE_MAIN_AREA_SIZE);
822 denali->dev_info.wDeviceSpareAreaSize =
823 ioread32(denali->flash_reg + DEVICE_SPARE_AREA_SIZE);
824
825 denali->dev_info.wPageDataSize =
826 ioread32(denali->flash_reg + LOGICAL_PAGE_DATA_SIZE);
827
828 /* Note: When using the Micon 4K NAND device, the controller will report
829 * Page Spare Size as 216 bytes. But Micron's Spec say it's 218 bytes.
830 * And if force set it to 218 bytes, the controller can not work
831 * correctly. So just let it be. But keep in mind that this bug may
832 * cause
833 * other problems in future. - Yunpeng 2008-10-10
834 */
835 denali->dev_info.wPageSpareSize =
836 ioread32(denali->flash_reg + LOGICAL_PAGE_SPARE_SIZE);
837
838 denali->dev_info.wPagesPerBlock = ioread32(denali->flash_reg + PAGES_PER_BLOCK);
839
840 denali->dev_info.wPageSize =
841 denali->dev_info.wPageDataSize + denali->dev_info.wPageSpareSize;
842 denali->dev_info.wBlockSize =
843 denali->dev_info.wPageSize * denali->dev_info.wPagesPerBlock;
844 denali->dev_info.wBlockDataSize =
845 denali->dev_info.wPagesPerBlock * denali->dev_info.wPageDataSize;
846
847 denali->dev_info.wDeviceWidth = ioread32(denali->flash_reg + DEVICE_WIDTH);
848 denali->dev_info.wDeviceType =
849 ((ioread32(denali->flash_reg + DEVICE_WIDTH) > 0) ? 16 : 8);
850
851 denali->dev_info.wDevicesConnected = ioread32(denali->flash_reg + DEVICES_CONNECTED);
852
853 denali->dev_info.wSpareSkipBytes =
854 ioread32(denali->flash_reg + SPARE_AREA_SKIP_BYTES) *
855 denali->dev_info.wDevicesConnected;
856
857 denali->dev_info.nBitsInPageNumber =
858 ilog2(denali->dev_info.wPagesPerBlock);
859 denali->dev_info.nBitsInPageDataSize =
860 ilog2(denali->dev_info.wPageDataSize);
861 denali->dev_info.nBitsInBlockDataSize =
862 ilog2(denali->dev_info.wBlockDataSize);
863
864 set_ecc_config(denali);
865
866 no_of_planes = ioread32(denali->flash_reg + NUMBER_OF_PLANES) &
867 NUMBER_OF_PLANES__VALUE;
868
869 switch (no_of_planes) {
870 case 0:
871 case 1:
872 case 3:
873 case 7:
874 denali->dev_info.bPlaneNum = no_of_planes + 1;
875 break;
876 default:
877 status = FAIL;
878 break;
879 }
880
881 find_valid_banks(denali); 547 find_valid_banks(denali);
882 548
883 detect_partition_feature(denali); 549 detect_partition_feature(denali);
884 550
885 dump_device_info(denali);
886
887 /* If the user specified to override the default timings 551 /* If the user specified to override the default timings
888 * with a specific ONFI mode, we apply those changes here. 552 * with a specific ONFI mode, we apply those changes here.
889 */ 553 */
890 if (onfi_timing_mode != NAND_DEFAULT_TIMINGS) 554 if (onfi_timing_mode != NAND_DEFAULT_TIMINGS)
891 { 555 nand_onfi_timing_set(denali, onfi_timing_mode);
892 NAND_ONFi_Timing_Mode(denali, onfi_timing_mode);
893 }
894 556
895 return status; 557 return status;
896} 558}
897 559
898static void NAND_LLD_Enable_Disable_Interrupts(struct denali_nand_info *denali, 560static void denali_set_intr_modes(struct denali_nand_info *denali,
899 uint16_t INT_ENABLE) 561 uint16_t INT_ENABLE)
900{ 562{
901 nand_dbg_print(NAND_DBG_TRACE, "%s, Line %d, Function: %s\n", 563 dev_dbg(&denali->dev->dev, "%s, Line %d, Function: %s\n",
902 __FILE__, __LINE__, __func__); 564 __FILE__, __LINE__, __func__);
903 565
904 if (INT_ENABLE) 566 if (INT_ENABLE)
905 denali_write32(1, denali->flash_reg + GLOBAL_INT_ENABLE); 567 iowrite32(1, denali->flash_reg + GLOBAL_INT_ENABLE);
906 else 568 else
907 denali_write32(0, denali->flash_reg + GLOBAL_INT_ENABLE); 569 iowrite32(0, denali->flash_reg + GLOBAL_INT_ENABLE);
908} 570}
909 571
910/* validation function to verify that the controlling software is making 572/* validation function to verify that the controlling software is making
911 a valid request 573 * a valid request
912 */ 574 */
913static inline bool is_flash_bank_valid(int flash_bank) 575static inline bool is_flash_bank_valid(int flash_bank)
914{ 576{
915 return (flash_bank >= 0 && flash_bank < 4); 577 return (flash_bank >= 0 && flash_bank < 4);
916} 578}
917 579
918static void denali_irq_init(struct denali_nand_info *denali) 580static void denali_irq_init(struct denali_nand_info *denali)
@@ -920,49 +582,51 @@ static void denali_irq_init(struct denali_nand_info *denali)
920 uint32_t int_mask = 0; 582 uint32_t int_mask = 0;
921 583
922 /* Disable global interrupts */ 584 /* Disable global interrupts */
923 NAND_LLD_Enable_Disable_Interrupts(denali, false); 585 denali_set_intr_modes(denali, false);
924 586
925 int_mask = DENALI_IRQ_ALL; 587 int_mask = DENALI_IRQ_ALL;
926 588
927 /* Clear all status bits */ 589 /* Clear all status bits */
928 denali_write32(0xFFFF, denali->flash_reg + INTR_STATUS0); 590 iowrite32(0xFFFF, denali->flash_reg + INTR_STATUS0);
929 denali_write32(0xFFFF, denali->flash_reg + INTR_STATUS1); 591 iowrite32(0xFFFF, denali->flash_reg + INTR_STATUS1);
930 denali_write32(0xFFFF, denali->flash_reg + INTR_STATUS2); 592 iowrite32(0xFFFF, denali->flash_reg + INTR_STATUS2);
931 denali_write32(0xFFFF, denali->flash_reg + INTR_STATUS3); 593 iowrite32(0xFFFF, denali->flash_reg + INTR_STATUS3);
932 594
933 denali_irq_enable(denali, int_mask); 595 denali_irq_enable(denali, int_mask);
934} 596}
935 597
936static void denali_irq_cleanup(int irqnum, struct denali_nand_info *denali) 598static void denali_irq_cleanup(int irqnum, struct denali_nand_info *denali)
937{ 599{
938 NAND_LLD_Enable_Disable_Interrupts(denali, false); 600 denali_set_intr_modes(denali, false);
939 free_irq(irqnum, denali); 601 free_irq(irqnum, denali);
940} 602}
941 603
942static void denali_irq_enable(struct denali_nand_info *denali, uint32_t int_mask) 604static void denali_irq_enable(struct denali_nand_info *denali,
605 uint32_t int_mask)
943{ 606{
944 denali_write32(int_mask, denali->flash_reg + INTR_EN0); 607 iowrite32(int_mask, denali->flash_reg + INTR_EN0);
945 denali_write32(int_mask, denali->flash_reg + INTR_EN1); 608 iowrite32(int_mask, denali->flash_reg + INTR_EN1);
946 denali_write32(int_mask, denali->flash_reg + INTR_EN2); 609 iowrite32(int_mask, denali->flash_reg + INTR_EN2);
947 denali_write32(int_mask, denali->flash_reg + INTR_EN3); 610 iowrite32(int_mask, denali->flash_reg + INTR_EN3);
948} 611}
949 612
950/* This function only returns when an interrupt that this driver cares about 613/* This function only returns when an interrupt that this driver cares about
951 * occurs. This is to reduce the overhead of servicing interrupts 614 * occurs. This is to reduce the overhead of servicing interrupts
952 */ 615 */
953static inline uint32_t denali_irq_detected(struct denali_nand_info *denali) 616static inline uint32_t denali_irq_detected(struct denali_nand_info *denali)
954{ 617{
955 return (read_interrupt_status(denali) & DENALI_IRQ_ALL); 618 return read_interrupt_status(denali) & DENALI_IRQ_ALL;
956} 619}
957 620
958/* Interrupts are cleared by writing a 1 to the appropriate status bit */ 621/* Interrupts are cleared by writing a 1 to the appropriate status bit */
959static inline void clear_interrupt(struct denali_nand_info *denali, uint32_t irq_mask) 622static inline void clear_interrupt(struct denali_nand_info *denali,
623 uint32_t irq_mask)
960{ 624{
961 uint32_t intr_status_reg = 0; 625 uint32_t intr_status_reg = 0;
962 626
963 intr_status_reg = intr_status_addresses[denali->flash_bank]; 627 intr_status_reg = intr_status_addresses[denali->flash_bank];
964 628
965 denali_write32(irq_mask, denali->flash_reg + intr_status_reg); 629 iowrite32(irq_mask, denali->flash_reg + intr_status_reg);
966} 630}
967 631
968static void clear_interrupts(struct denali_nand_info *denali) 632static void clear_interrupts(struct denali_nand_info *denali)
@@ -971,11 +635,7 @@ static void clear_interrupts(struct denali_nand_info *denali)
971 spin_lock_irq(&denali->irq_lock); 635 spin_lock_irq(&denali->irq_lock);
972 636
973 status = read_interrupt_status(denali); 637 status = read_interrupt_status(denali);
974 638 clear_interrupt(denali, status);
975#if DEBUG_DENALI
976 denali->irq_debug_array[denali->idx++] = 0x30000000 | status;
977 denali->idx %= 32;
978#endif
979 639
980 denali->irq_status = 0x0; 640 denali->irq_status = 0x0;
981 spin_unlock_irq(&denali->irq_lock); 641 spin_unlock_irq(&denali->irq_lock);
@@ -990,22 +650,9 @@ static uint32_t read_interrupt_status(struct denali_nand_info *denali)
990 return ioread32(denali->flash_reg + intr_status_reg); 650 return ioread32(denali->flash_reg + intr_status_reg);
991} 651}
992 652
993#if DEBUG_DENALI 653/* This is the interrupt service routine. It handles all interrupts
994static void print_irq_log(struct denali_nand_info *denali) 654 * sent to this device. Note that on CE4100, this is a shared
995{ 655 * interrupt.
996 int i = 0;
997
998 printk("ISR debug log index = %X\n", denali->idx);
999 for (i = 0; i < 32; i++)
1000 {
1001 printk("%08X: %08X\n", i, denali->irq_debug_array[i]);
1002 }
1003}
1004#endif
1005
1006/* This is the interrupt service routine. It handles all interrupts
1007 * sent to this device. Note that on CE4100, this is a shared
1008 * interrupt.
1009 */ 656 */
1010static irqreturn_t denali_isr(int irq, void *dev_id) 657static irqreturn_t denali_isr(int irq, void *dev_id)
1011{ 658{
@@ -1015,21 +662,14 @@ static irqreturn_t denali_isr(int irq, void *dev_id)
1015 662
1016 spin_lock(&denali->irq_lock); 663 spin_lock(&denali->irq_lock);
1017 664
1018 /* check to see if a valid NAND chip has 665 /* check to see if a valid NAND chip has
1019 * been selected. 666 * been selected.
1020 */ 667 */
1021 if (is_flash_bank_valid(denali->flash_bank)) 668 if (is_flash_bank_valid(denali->flash_bank)) {
1022 { 669 /* check to see if controller generated
1023 /* check to see if controller generated
1024 * the interrupt, since this is a shared interrupt */ 670 * the interrupt, since this is a shared interrupt */
1025 if ((irq_status = denali_irq_detected(denali)) != 0) 671 irq_status = denali_irq_detected(denali);
1026 { 672 if (irq_status != 0) {
1027#if DEBUG_DENALI
1028 denali->irq_debug_array[denali->idx++] = 0x10000000 | irq_status;
1029 denali->idx %= 32;
1030
1031 printk("IRQ status = 0x%04x\n", irq_status);
1032#endif
1033 /* handle interrupt */ 673 /* handle interrupt */
1034 /* first acknowledge it */ 674 /* first acknowledge it */
1035 clear_interrupt(denali, irq_status); 675 clear_interrupt(denali, irq_status);
@@ -1054,149 +694,120 @@ static uint32_t wait_for_irq(struct denali_nand_info *denali, uint32_t irq_mask)
1054 bool retry = false; 694 bool retry = false;
1055 unsigned long timeout = msecs_to_jiffies(1000); 695 unsigned long timeout = msecs_to_jiffies(1000);
1056 696
1057 do 697 do {
1058 { 698 comp_res =
1059#if DEBUG_DENALI 699 wait_for_completion_timeout(&denali->complete, timeout);
1060 printk("waiting for 0x%x\n", irq_mask);
1061#endif
1062 comp_res = wait_for_completion_timeout(&denali->complete, timeout);
1063 spin_lock_irq(&denali->irq_lock); 700 spin_lock_irq(&denali->irq_lock);
1064 intr_status = denali->irq_status; 701 intr_status = denali->irq_status;
1065 702
1066#if DEBUG_DENALI 703 if (intr_status & irq_mask) {
1067 denali->irq_debug_array[denali->idx++] = 0x20000000 | (irq_mask << 16) | intr_status;
1068 denali->idx %= 32;
1069#endif
1070
1071 if (intr_status & irq_mask)
1072 {
1073 denali->irq_status &= ~irq_mask; 704 denali->irq_status &= ~irq_mask;
1074 spin_unlock_irq(&denali->irq_lock); 705 spin_unlock_irq(&denali->irq_lock);
1075#if DEBUG_DENALI
1076 if (retry) printk("status on retry = 0x%x\n", intr_status);
1077#endif
1078 /* our interrupt was detected */ 706 /* our interrupt was detected */
1079 break; 707 break;
1080 } 708 } else {
1081 else 709 /* these are not the interrupts you are looking for -
1082 { 710 * need to wait again */
1083 /* these are not the interrupts you are looking for -
1084 need to wait again */
1085 spin_unlock_irq(&denali->irq_lock); 711 spin_unlock_irq(&denali->irq_lock);
1086#if DEBUG_DENALI
1087 print_irq_log(denali);
1088 printk("received irq nobody cared: irq_status = 0x%x,"
1089 " irq_mask = 0x%x, timeout = %ld\n", intr_status, irq_mask, comp_res);
1090#endif
1091 retry = true; 712 retry = true;
1092 } 713 }
1093 } while (comp_res != 0); 714 } while (comp_res != 0);
1094 715
1095 if (comp_res == 0) 716 if (comp_res == 0) {
1096 {
1097 /* timeout */ 717 /* timeout */
1098 printk(KERN_ERR "timeout occurred, status = 0x%x, mask = 0x%x\n", 718 printk(KERN_ERR "timeout occurred, status = 0x%x, mask = 0x%x\n",
1099 intr_status, irq_mask); 719 intr_status, irq_mask);
1100 720
1101 intr_status = 0; 721 intr_status = 0;
1102 } 722 }
1103 return intr_status; 723 return intr_status;
1104} 724}
1105 725
1106/* This helper function setups the registers for ECC and whether or not 726/* This helper function setups the registers for ECC and whether or not
1107 the spare area will be transfered. */ 727 * the spare area will be transfered. */
1108static void setup_ecc_for_xfer(struct denali_nand_info *denali, bool ecc_en, 728static void setup_ecc_for_xfer(struct denali_nand_info *denali, bool ecc_en,
1109 bool transfer_spare) 729 bool transfer_spare)
1110{ 730{
1111 int ecc_en_flag = 0, transfer_spare_flag = 0; 731 int ecc_en_flag = 0, transfer_spare_flag = 0;
1112 732
1113 /* set ECC, transfer spare bits if needed */ 733 /* set ECC, transfer spare bits if needed */
1114 ecc_en_flag = ecc_en ? ECC_ENABLE__FLAG : 0; 734 ecc_en_flag = ecc_en ? ECC_ENABLE__FLAG : 0;
1115 transfer_spare_flag = transfer_spare ? TRANSFER_SPARE_REG__FLAG : 0; 735 transfer_spare_flag = transfer_spare ? TRANSFER_SPARE_REG__FLAG : 0;
1116 736
1117 /* Enable spare area/ECC per user's request. */ 737 /* Enable spare area/ECC per user's request. */
1118 denali_write32(ecc_en_flag, denali->flash_reg + ECC_ENABLE); 738 iowrite32(ecc_en_flag, denali->flash_reg + ECC_ENABLE);
1119 denali_write32(transfer_spare_flag, denali->flash_reg + TRANSFER_SPARE_REG); 739 iowrite32(transfer_spare_flag,
740 denali->flash_reg + TRANSFER_SPARE_REG);
1120} 741}
1121 742
1122/* sends a pipeline command operation to the controller. See the Denali NAND 743/* sends a pipeline command operation to the controller. See the Denali NAND
1123 controller's user guide for more information (section 4.2.3.6). 744 * controller's user guide for more information (section 4.2.3.6).
1124 */ 745 */
1125static int denali_send_pipeline_cmd(struct denali_nand_info *denali, bool ecc_en, 746static int denali_send_pipeline_cmd(struct denali_nand_info *denali,
1126 bool transfer_spare, int access_type, 747 bool ecc_en,
1127 int op) 748 bool transfer_spare,
749 int access_type,
750 int op)
1128{ 751{
1129 int status = PASS; 752 int status = PASS;
1130 uint32_t addr = 0x0, cmd = 0x0, page_count = 1, irq_status = 0, 753 uint32_t addr = 0x0, cmd = 0x0, page_count = 1, irq_status = 0,
1131 irq_mask = 0; 754 irq_mask = 0;
1132 755
1133 if (op == DENALI_READ) irq_mask = INTR_STATUS0__LOAD_COMP; 756 if (op == DENALI_READ)
1134 else if (op == DENALI_WRITE) irq_mask = 0; 757 irq_mask = INTR_STATUS0__LOAD_COMP;
1135 else BUG(); 758 else if (op == DENALI_WRITE)
759 irq_mask = 0;
760 else
761 BUG();
1136 762
1137 setup_ecc_for_xfer(denali, ecc_en, transfer_spare); 763 setup_ecc_for_xfer(denali, ecc_en, transfer_spare);
1138 764
1139#if DEBUG_DENALI
1140 spin_lock_irq(&denali->irq_lock);
1141 denali->irq_debug_array[denali->idx++] = 0x40000000 | ioread32(denali->flash_reg + ECC_ENABLE) | (access_type << 4);
1142 denali->idx %= 32;
1143 spin_unlock_irq(&denali->irq_lock);
1144#endif
1145
1146
1147 /* clear interrupts */ 765 /* clear interrupts */
1148 clear_interrupts(denali); 766 clear_interrupts(denali);
1149 767
1150 addr = BANK(denali->flash_bank) | denali->page; 768 addr = BANK(denali->flash_bank) | denali->page;
1151 769
1152 if (op == DENALI_WRITE && access_type != SPARE_ACCESS) 770 if (op == DENALI_WRITE && access_type != SPARE_ACCESS) {
1153 { 771 cmd = MODE_01 | addr;
1154 cmd = MODE_01 | addr; 772 iowrite32(cmd, denali->flash_mem);
1155 denali_write32(cmd, denali->flash_mem); 773 } else if (op == DENALI_WRITE && access_type == SPARE_ACCESS) {
1156 }
1157 else if (op == DENALI_WRITE && access_type == SPARE_ACCESS)
1158 {
1159 /* read spare area */ 774 /* read spare area */
1160 cmd = MODE_10 | addr; 775 cmd = MODE_10 | addr;
1161 index_addr(denali, (uint32_t)cmd, access_type); 776 index_addr(denali, (uint32_t)cmd, access_type);
1162 777
1163 cmd = MODE_01 | addr; 778 cmd = MODE_01 | addr;
1164 denali_write32(cmd, denali->flash_mem); 779 iowrite32(cmd, denali->flash_mem);
1165 } 780 } else if (op == DENALI_READ) {
1166 else if (op == DENALI_READ)
1167 {
1168 /* setup page read request for access type */ 781 /* setup page read request for access type */
1169 cmd = MODE_10 | addr; 782 cmd = MODE_10 | addr;
1170 index_addr(denali, (uint32_t)cmd, access_type); 783 index_addr(denali, (uint32_t)cmd, access_type);
1171 784
1172 /* page 33 of the NAND controller spec indicates we should not 785 /* page 33 of the NAND controller spec indicates we should not
1173 use the pipeline commands in Spare area only mode. So we 786 use the pipeline commands in Spare area only mode. So we
1174 don't. 787 don't.
1175 */ 788 */
1176 if (access_type == SPARE_ACCESS) 789 if (access_type == SPARE_ACCESS) {
1177 {
1178 cmd = MODE_01 | addr; 790 cmd = MODE_01 | addr;
1179 denali_write32(cmd, denali->flash_mem); 791 iowrite32(cmd, denali->flash_mem);
1180 } 792 } else {
1181 else 793 index_addr(denali, (uint32_t)cmd,
1182 { 794 0x2000 | op | page_count);
1183 index_addr(denali, (uint32_t)cmd, 0x2000 | op | page_count); 795
1184 796 /* wait for command to be accepted
1185 /* wait for command to be accepted 797 * can always use status0 bit as the
1186 * can always use status0 bit as the mask is identical for each 798 * mask is identical for each
1187 * bank. */ 799 * bank. */
1188 irq_status = wait_for_irq(denali, irq_mask); 800 irq_status = wait_for_irq(denali, irq_mask);
1189 801
1190 if (irq_status == 0) 802 if (irq_status == 0) {
1191 { 803 dev_err(&denali->dev->dev,
1192 printk(KERN_ERR "cmd, page, addr on timeout " 804 "cmd, page, addr on timeout "
1193 "(0x%x, 0x%x, 0x%x)\n", cmd, denali->page, addr); 805 "(0x%x, 0x%x, 0x%x)\n",
806 cmd, denali->page, addr);
1194 status = FAIL; 807 status = FAIL;
1195 } 808 } else {
1196 else
1197 {
1198 cmd = MODE_01 | addr; 809 cmd = MODE_01 | addr;
1199 denali_write32(cmd, denali->flash_mem); 810 iowrite32(cmd, denali->flash_mem);
1200 } 811 }
1201 } 812 }
1202 } 813 }
@@ -1204,36 +815,35 @@ static int denali_send_pipeline_cmd(struct denali_nand_info *denali, bool ecc_en
1204} 815}
1205 816
1206/* helper function that simply writes a buffer to the flash */ 817/* helper function that simply writes a buffer to the flash */
1207static int write_data_to_flash_mem(struct denali_nand_info *denali, const uint8_t *buf, 818static int write_data_to_flash_mem(struct denali_nand_info *denali,
1208 int len) 819 const uint8_t *buf,
820 int len)
1209{ 821{
1210 uint32_t i = 0, *buf32; 822 uint32_t i = 0, *buf32;
1211 823
1212 /* verify that the len is a multiple of 4. see comment in 824 /* verify that the len is a multiple of 4. see comment in
1213 * read_data_from_flash_mem() */ 825 * read_data_from_flash_mem() */
1214 BUG_ON((len % 4) != 0); 826 BUG_ON((len % 4) != 0);
1215 827
1216 /* write the data to the flash memory */ 828 /* write the data to the flash memory */
1217 buf32 = (uint32_t *)buf; 829 buf32 = (uint32_t *)buf;
1218 for (i = 0; i < len / 4; i++) 830 for (i = 0; i < len / 4; i++)
1219 { 831 iowrite32(*buf32++, denali->flash_mem + 0x10);
1220 denali_write32(*buf32++, denali->flash_mem + 0x10); 832 return i*4; /* intent is to return the number of bytes read */
1221 }
1222 return i*4; /* intent is to return the number of bytes read */
1223} 833}
1224 834
1225/* helper function that simply reads a buffer from the flash */ 835/* helper function that simply reads a buffer from the flash */
1226static int read_data_from_flash_mem(struct denali_nand_info *denali, uint8_t *buf, 836static int read_data_from_flash_mem(struct denali_nand_info *denali,
1227 int len) 837 uint8_t *buf,
838 int len)
1228{ 839{
1229 uint32_t i = 0, *buf32; 840 uint32_t i = 0, *buf32;
1230 841
1231 /* we assume that len will be a multiple of 4, if not 842 /* we assume that len will be a multiple of 4, if not
1232 * it would be nice to know about it ASAP rather than 843 * it would be nice to know about it ASAP rather than
1233 * have random failures... 844 * have random failures...
1234 * 845 * This assumption is based on the fact that this
1235 * This assumption is based on the fact that this 846 * function is designed to be used to read flash pages,
1236 * function is designed to be used to read flash pages,
1237 * which are typically multiples of 4... 847 * which are typically multiples of 4...
1238 */ 848 */
1239 849
@@ -1242,10 +852,8 @@ static int read_data_from_flash_mem(struct denali_nand_info *denali, uint8_t *bu
1242 /* transfer the data from the flash */ 852 /* transfer the data from the flash */
1243 buf32 = (uint32_t *)buf; 853 buf32 = (uint32_t *)buf;
1244 for (i = 0; i < len / 4; i++) 854 for (i = 0; i < len / 4; i++)
1245 {
1246 *buf32++ = ioread32(denali->flash_mem + 0x10); 855 *buf32++ = ioread32(denali->flash_mem + 0x10);
1247 } 856 return i*4; /* intent is to return the number of bytes read */
1248 return i*4; /* intent is to return the number of bytes read */
1249} 857}
1250 858
1251/* writes OOB data to the device */ 859/* writes OOB data to the device */
@@ -1253,38 +861,26 @@ static int write_oob_data(struct mtd_info *mtd, uint8_t *buf, int page)
1253{ 861{
1254 struct denali_nand_info *denali = mtd_to_denali(mtd); 862 struct denali_nand_info *denali = mtd_to_denali(mtd);
1255 uint32_t irq_status = 0; 863 uint32_t irq_status = 0;
1256 uint32_t irq_mask = INTR_STATUS0__PROGRAM_COMP | 864 uint32_t irq_mask = INTR_STATUS0__PROGRAM_COMP |
1257 INTR_STATUS0__PROGRAM_FAIL; 865 INTR_STATUS0__PROGRAM_FAIL;
1258 int status = 0; 866 int status = 0;
1259 867
1260 denali->page = page; 868 denali->page = page;
1261 869
1262 if (denali_send_pipeline_cmd(denali, false, false, SPARE_ACCESS, 870 if (denali_send_pipeline_cmd(denali, false, false, SPARE_ACCESS,
1263 DENALI_WRITE) == PASS) 871 DENALI_WRITE) == PASS) {
1264 {
1265 write_data_to_flash_mem(denali, buf, mtd->oobsize); 872 write_data_to_flash_mem(denali, buf, mtd->oobsize);
1266 873
1267#if DEBUG_DENALI
1268 spin_lock_irq(&denali->irq_lock);
1269 denali->irq_debug_array[denali->idx++] = 0x80000000 | mtd->oobsize;
1270 denali->idx %= 32;
1271 spin_unlock_irq(&denali->irq_lock);
1272#endif
1273
1274
1275 /* wait for operation to complete */ 874 /* wait for operation to complete */
1276 irq_status = wait_for_irq(denali, irq_mask); 875 irq_status = wait_for_irq(denali, irq_mask);
1277 876
1278 if (irq_status == 0) 877 if (irq_status == 0) {
1279 { 878 dev_err(&denali->dev->dev, "OOB write failed\n");
1280 printk(KERN_ERR "OOB write failed\n");
1281 status = -EIO; 879 status = -EIO;
1282 } 880 }
1283 } 881 } else {
1284 else 882 dev_err(&denali->dev->dev, "unable to send pipeline command\n");
1285 { 883 status = -EIO;
1286 printk(KERN_ERR "unable to send pipeline command\n");
1287 status = -EIO;
1288 } 884 }
1289 return status; 885 return status;
1290} 886}
@@ -1293,60 +889,45 @@ static int write_oob_data(struct mtd_info *mtd, uint8_t *buf, int page)
1293static void read_oob_data(struct mtd_info *mtd, uint8_t *buf, int page) 889static void read_oob_data(struct mtd_info *mtd, uint8_t *buf, int page)
1294{ 890{
1295 struct denali_nand_info *denali = mtd_to_denali(mtd); 891 struct denali_nand_info *denali = mtd_to_denali(mtd);
1296 uint32_t irq_mask = INTR_STATUS0__LOAD_COMP, irq_status = 0, addr = 0x0, cmd = 0x0; 892 uint32_t irq_mask = INTR_STATUS0__LOAD_COMP,
893 irq_status = 0, addr = 0x0, cmd = 0x0;
1297 894
1298 denali->page = page; 895 denali->page = page;
1299 896
1300#if DEBUG_DENALI 897 if (denali_send_pipeline_cmd(denali, false, true, SPARE_ACCESS,
1301 printk("read_oob %d\n", page); 898 DENALI_READ) == PASS) {
1302#endif 899 read_data_from_flash_mem(denali, buf, mtd->oobsize);
1303 if (denali_send_pipeline_cmd(denali, false, true, SPARE_ACCESS,
1304 DENALI_READ) == PASS)
1305 {
1306 read_data_from_flash_mem(denali, buf, mtd->oobsize);
1307 900
1308 /* wait for command to be accepted 901 /* wait for command to be accepted
1309 * can always use status0 bit as the mask is identical for each 902 * can always use status0 bit as the mask is identical for each
1310 * bank. */ 903 * bank. */
1311 irq_status = wait_for_irq(denali, irq_mask); 904 irq_status = wait_for_irq(denali, irq_mask);
1312 905
1313 if (irq_status == 0) 906 if (irq_status == 0)
1314 { 907 dev_err(&denali->dev->dev, "page on OOB timeout %d\n",
1315 printk(KERN_ERR "page on OOB timeout %d\n", denali->page); 908 denali->page);
1316 }
1317 909
1318 /* We set the device back to MAIN_ACCESS here as I observed 910 /* We set the device back to MAIN_ACCESS here as I observed
1319 * instability with the controller if you do a block erase 911 * instability with the controller if you do a block erase
1320 * and the last transaction was a SPARE_ACCESS. Block erase 912 * and the last transaction was a SPARE_ACCESS. Block erase
1321 * is reliable (according to the MTD test infrastructure) 913 * is reliable (according to the MTD test infrastructure)
1322 * if you are in MAIN_ACCESS. 914 * if you are in MAIN_ACCESS.
1323 */ 915 */
1324 addr = BANK(denali->flash_bank) | denali->page; 916 addr = BANK(denali->flash_bank) | denali->page;
1325 cmd = MODE_10 | addr; 917 cmd = MODE_10 | addr;
1326 index_addr(denali, (uint32_t)cmd, MAIN_ACCESS); 918 index_addr(denali, (uint32_t)cmd, MAIN_ACCESS);
1327
1328#if DEBUG_DENALI
1329 spin_lock_irq(&denali->irq_lock);
1330 denali->irq_debug_array[denali->idx++] = 0x60000000 | mtd->oobsize;
1331 denali->idx %= 32;
1332 spin_unlock_irq(&denali->irq_lock);
1333#endif
1334 } 919 }
1335} 920}
1336 921
1337/* this function examines buffers to see if they contain data that 922/* this function examines buffers to see if they contain data that
1338 * indicate that the buffer is part of an erased region of flash. 923 * indicate that the buffer is part of an erased region of flash.
1339 */ 924 */
1340bool is_erased(uint8_t *buf, int len) 925bool is_erased(uint8_t *buf, int len)
1341{ 926{
1342 int i = 0; 927 int i = 0;
1343 for (i = 0; i < len; i++) 928 for (i = 0; i < len; i++)
1344 {
1345 if (buf[i] != 0xFF) 929 if (buf[i] != 0xFF)
1346 {
1347 return false; 930 return false;
1348 }
1349 }
1350 return true; 931 return true;
1351} 932}
1352#define ECC_SECTOR_SIZE 512 933#define ECC_SECTOR_SIZE 512
@@ -1354,71 +935,70 @@ bool is_erased(uint8_t *buf, int len)
1354#define ECC_SECTOR(x) (((x) & ECC_ERROR_ADDRESS__SECTOR_NR) >> 12) 935#define ECC_SECTOR(x) (((x) & ECC_ERROR_ADDRESS__SECTOR_NR) >> 12)
1355#define ECC_BYTE(x) (((x) & ECC_ERROR_ADDRESS__OFFSET)) 936#define ECC_BYTE(x) (((x) & ECC_ERROR_ADDRESS__OFFSET))
1356#define ECC_CORRECTION_VALUE(x) ((x) & ERR_CORRECTION_INFO__BYTEMASK) 937#define ECC_CORRECTION_VALUE(x) ((x) & ERR_CORRECTION_INFO__BYTEMASK)
1357#define ECC_ERROR_CORRECTABLE(x) (!((x) & ERR_CORRECTION_INFO)) 938#define ECC_ERROR_CORRECTABLE(x) (!((x) & ERR_CORRECTION_INFO__ERROR_TYPE))
1358#define ECC_ERR_DEVICE(x) ((x) & ERR_CORRECTION_INFO__DEVICE_NR >> 8) 939#define ECC_ERR_DEVICE(x) (((x) & ERR_CORRECTION_INFO__DEVICE_NR) >> 8)
1359#define ECC_LAST_ERR(x) ((x) & ERR_CORRECTION_INFO__LAST_ERR_INFO) 940#define ECC_LAST_ERR(x) ((x) & ERR_CORRECTION_INFO__LAST_ERR_INFO)
1360 941
1361static bool handle_ecc(struct denali_nand_info *denali, uint8_t *buf, 942static bool handle_ecc(struct denali_nand_info *denali, uint8_t *buf,
1362 uint8_t *oobbuf, uint32_t irq_status) 943 uint32_t irq_status)
1363{ 944{
1364 bool check_erased_page = false; 945 bool check_erased_page = false;
1365 946
1366 if (irq_status & INTR_STATUS0__ECC_ERR) 947 if (irq_status & INTR_STATUS0__ECC_ERR) {
1367 {
1368 /* read the ECC errors. we'll ignore them for now */ 948 /* read the ECC errors. we'll ignore them for now */
1369 uint32_t err_address = 0, err_correction_info = 0; 949 uint32_t err_address = 0, err_correction_info = 0;
1370 uint32_t err_byte = 0, err_sector = 0, err_device = 0; 950 uint32_t err_byte = 0, err_sector = 0, err_device = 0;
1371 uint32_t err_correction_value = 0; 951 uint32_t err_correction_value = 0;
952 denali_set_intr_modes(denali, false);
1372 953
1373 do 954 do {
1374 { 955 err_address = ioread32(denali->flash_reg +
1375 err_address = ioread32(denali->flash_reg +
1376 ECC_ERROR_ADDRESS); 956 ECC_ERROR_ADDRESS);
1377 err_sector = ECC_SECTOR(err_address); 957 err_sector = ECC_SECTOR(err_address);
1378 err_byte = ECC_BYTE(err_address); 958 err_byte = ECC_BYTE(err_address);
1379 959
1380 960 err_correction_info = ioread32(denali->flash_reg +
1381 err_correction_info = ioread32(denali->flash_reg +
1382 ERR_CORRECTION_INFO); 961 ERR_CORRECTION_INFO);
1383 err_correction_value = 962 err_correction_value =
1384 ECC_CORRECTION_VALUE(err_correction_info); 963 ECC_CORRECTION_VALUE(err_correction_info);
1385 err_device = ECC_ERR_DEVICE(err_correction_info); 964 err_device = ECC_ERR_DEVICE(err_correction_info);
1386 965
1387 if (ECC_ERROR_CORRECTABLE(err_correction_info)) 966 if (ECC_ERROR_CORRECTABLE(err_correction_info)) {
1388 { 967 /* If err_byte is larger than ECC_SECTOR_SIZE,
1389 /* offset in our buffer is computed as: 968 * means error happend in OOB, so we ignore
1390 sector number * sector size + offset in 969 * it. It's no need for us to correct it
1391 sector 970 * err_device is represented the NAND error
1392 */ 971 * bits are happened in if there are more
1393 int offset = err_sector * ECC_SECTOR_SIZE + 972 * than one NAND connected.
1394 err_byte; 973 * */
1395 if (offset < denali->mtd.writesize) 974 if (err_byte < ECC_SECTOR_SIZE) {
1396 { 975 int offset;
976 offset = (err_sector *
977 ECC_SECTOR_SIZE +
978 err_byte) *
979 denali->devnum +
980 err_device;
1397 /* correct the ECC error */ 981 /* correct the ECC error */
1398 buf[offset] ^= err_correction_value; 982 buf[offset] ^= err_correction_value;
1399 denali->mtd.ecc_stats.corrected++; 983 denali->mtd.ecc_stats.corrected++;
1400 } 984 }
1401 else 985 } else {
1402 { 986 /* if the error is not correctable, need to
1403 /* bummer, couldn't correct the error */ 987 * look at the page to see if it is an erased
1404 printk(KERN_ERR "ECC offset invalid\n"); 988 * page. if so, then it's not a real ECC error
1405 denali->mtd.ecc_stats.failed++; 989 * */
1406 }
1407 }
1408 else
1409 {
1410 /* if the error is not correctable, need to
1411 * look at the page to see if it is an erased page.
1412 * if so, then it's not a real ECC error */
1413 check_erased_page = true; 990 check_erased_page = true;
1414 } 991 }
1415
1416#if DEBUG_DENALI
1417 printk("Detected ECC error in page %d: err_addr = 0x%08x,"
1418 " info to fix is 0x%08x\n", denali->page, err_address,
1419 err_correction_info);
1420#endif
1421 } while (!ECC_LAST_ERR(err_correction_info)); 992 } while (!ECC_LAST_ERR(err_correction_info));
993 /* Once handle all ecc errors, controller will triger
994 * a ECC_TRANSACTION_DONE interrupt, so here just wait
995 * for a while for this interrupt
996 * */
997 while (!(read_interrupt_status(denali) &
998 INTR_STATUS0__ECC_TRANSACTION_DONE))
999 cpu_relax();
1000 clear_interrupts(denali);
1001 denali_set_intr_modes(denali, true);
1422 } 1002 }
1423 return check_erased_page; 1003 return check_erased_page;
1424} 1004}
@@ -1428,9 +1008,10 @@ static void denali_enable_dma(struct denali_nand_info *denali, bool en)
1428{ 1008{
1429 uint32_t reg_val = 0x0; 1009 uint32_t reg_val = 0x0;
1430 1010
1431 if (en) reg_val = DMA_ENABLE__FLAG; 1011 if (en)
1012 reg_val = DMA_ENABLE__FLAG;
1432 1013
1433 denali_write32(reg_val, denali->flash_reg + DMA_ENABLE); 1014 iowrite32(reg_val, denali->flash_reg + DMA_ENABLE);
1434 ioread32(denali->flash_reg + DMA_ENABLE); 1015 ioread32(denali->flash_reg + DMA_ENABLE);
1435} 1016}
1436 1017
@@ -1458,9 +1039,9 @@ static void denali_setup_dma(struct denali_nand_info *denali, int op)
1458 index_addr(denali, mode | 0x14000, 0x2400); 1039 index_addr(denali, mode | 0x14000, 0x2400);
1459} 1040}
1460 1041
1461/* writes a page. user specifies type, and this function handles the 1042/* writes a page. user specifies type, and this function handles the
1462 configuration details. */ 1043 * configuration details. */
1463static void write_page(struct mtd_info *mtd, struct nand_chip *chip, 1044static void write_page(struct mtd_info *mtd, struct nand_chip *chip,
1464 const uint8_t *buf, bool raw_xfer) 1045 const uint8_t *buf, bool raw_xfer)
1465{ 1046{
1466 struct denali_nand_info *denali = mtd_to_denali(mtd); 1047 struct denali_nand_info *denali = mtd_to_denali(mtd);
@@ -1470,7 +1051,7 @@ static void write_page(struct mtd_info *mtd, struct nand_chip *chip,
1470 size_t size = denali->mtd.writesize + denali->mtd.oobsize; 1051 size_t size = denali->mtd.writesize + denali->mtd.oobsize;
1471 1052
1472 uint32_t irq_status = 0; 1053 uint32_t irq_status = 0;
1473 uint32_t irq_mask = INTR_STATUS0__DMA_CMD_COMP | 1054 uint32_t irq_mask = INTR_STATUS0__DMA_CMD_COMP |
1474 INTR_STATUS0__PROGRAM_FAIL; 1055 INTR_STATUS0__PROGRAM_FAIL;
1475 1056
1476 /* if it is a raw xfer, we want to disable ecc, and send 1057 /* if it is a raw xfer, we want to disable ecc, and send
@@ -1483,74 +1064,75 @@ static void write_page(struct mtd_info *mtd, struct nand_chip *chip,
1483 /* copy buffer into DMA buffer */ 1064 /* copy buffer into DMA buffer */
1484 memcpy(denali->buf.buf, buf, mtd->writesize); 1065 memcpy(denali->buf.buf, buf, mtd->writesize);
1485 1066
1486 if (raw_xfer) 1067 if (raw_xfer) {
1487 {
1488 /* transfer the data to the spare area */ 1068 /* transfer the data to the spare area */
1489 memcpy(denali->buf.buf + mtd->writesize, 1069 memcpy(denali->buf.buf + mtd->writesize,
1490 chip->oob_poi, 1070 chip->oob_poi,
1491 mtd->oobsize); 1071 mtd->oobsize);
1492 } 1072 }
1493 1073
1494 pci_dma_sync_single_for_device(pci_dev, addr, size, PCI_DMA_TODEVICE); 1074 pci_dma_sync_single_for_device(pci_dev, addr, size, PCI_DMA_TODEVICE);
1495 1075
1496 clear_interrupts(denali); 1076 clear_interrupts(denali);
1497 denali_enable_dma(denali, true); 1077 denali_enable_dma(denali, true);
1498 1078
1499 denali_setup_dma(denali, DENALI_WRITE); 1079 denali_setup_dma(denali, DENALI_WRITE);
1500 1080
1501 /* wait for operation to complete */ 1081 /* wait for operation to complete */
1502 irq_status = wait_for_irq(denali, irq_mask); 1082 irq_status = wait_for_irq(denali, irq_mask);
1503 1083
1504 if (irq_status == 0) 1084 if (irq_status == 0) {
1505 { 1085 dev_err(&denali->dev->dev,
1506 printk(KERN_ERR "timeout on write_page (type = %d)\n", raw_xfer); 1086 "timeout on write_page (type = %d)\n",
1507 denali->status = 1087 raw_xfer);
1508 (irq_status & INTR_STATUS0__PROGRAM_FAIL) ? NAND_STATUS_FAIL : 1088 denali->status =
1509 PASS; 1089 (irq_status & INTR_STATUS0__PROGRAM_FAIL) ?
1090 NAND_STATUS_FAIL : PASS;
1510 } 1091 }
1511 1092
1512 denali_enable_dma(denali, false); 1093 denali_enable_dma(denali, false);
1513 pci_dma_sync_single_for_cpu(pci_dev, addr, size, PCI_DMA_TODEVICE); 1094 pci_dma_sync_single_for_cpu(pci_dev, addr, size, PCI_DMA_TODEVICE);
1514} 1095}
1515 1096
1516/* NAND core entry points */ 1097/* NAND core entry points */
1517 1098
1518/* this is the callback that the NAND core calls to write a page. Since 1099/* this is the callback that the NAND core calls to write a page. Since
1519 writing a page with ECC or without is similar, all the work is done 1100 * writing a page with ECC or without is similar, all the work is done
1520 by write_page above. */ 1101 * by write_page above.
1521static void denali_write_page(struct mtd_info *mtd, struct nand_chip *chip, 1102 * */
1103static void denali_write_page(struct mtd_info *mtd, struct nand_chip *chip,
1522 const uint8_t *buf) 1104 const uint8_t *buf)
1523{ 1105{
1524 /* for regular page writes, we let HW handle all the ECC 1106 /* for regular page writes, we let HW handle all the ECC
1525 * data written to the device. */ 1107 * data written to the device. */
1526 write_page(mtd, chip, buf, false); 1108 write_page(mtd, chip, buf, false);
1527} 1109}
1528 1110
1529/* This is the callback that the NAND core calls to write a page without ECC. 1111/* This is the callback that the NAND core calls to write a page without ECC.
1530 raw access is similiar to ECC page writes, so all the work is done in the 1112 * raw access is similiar to ECC page writes, so all the work is done in the
1531 write_page() function above. 1113 * write_page() function above.
1532 */ 1114 */
1533static void denali_write_page_raw(struct mtd_info *mtd, struct nand_chip *chip, 1115static void denali_write_page_raw(struct mtd_info *mtd, struct nand_chip *chip,
1534 const uint8_t *buf) 1116 const uint8_t *buf)
1535{ 1117{
1536 /* for raw page writes, we want to disable ECC and simply write 1118 /* for raw page writes, we want to disable ECC and simply write
1537 whatever data is in the buffer. */ 1119 whatever data is in the buffer. */
1538 write_page(mtd, chip, buf, true); 1120 write_page(mtd, chip, buf, true);
1539} 1121}
1540 1122
1541static int denali_write_oob(struct mtd_info *mtd, struct nand_chip *chip, 1123static int denali_write_oob(struct mtd_info *mtd, struct nand_chip *chip,
1542 int page) 1124 int page)
1543{ 1125{
1544 return write_oob_data(mtd, chip->oob_poi, page); 1126 return write_oob_data(mtd, chip->oob_poi, page);
1545} 1127}
1546 1128
1547static int denali_read_oob(struct mtd_info *mtd, struct nand_chip *chip, 1129static int denali_read_oob(struct mtd_info *mtd, struct nand_chip *chip,
1548 int page, int sndcmd) 1130 int page, int sndcmd)
1549{ 1131{
1550 read_oob_data(mtd, chip->oob_poi, page); 1132 read_oob_data(mtd, chip->oob_poi, page);
1551 1133
1552 return 0; /* notify NAND core to send command to 1134 return 0; /* notify NAND core to send command to
1553 * NAND device. */ 1135 NAND device. */
1554} 1136}
1555 1137
1556static int denali_read_page(struct mtd_info *mtd, struct nand_chip *chip, 1138static int denali_read_page(struct mtd_info *mtd, struct nand_chip *chip,
@@ -1563,10 +1145,17 @@ static int denali_read_page(struct mtd_info *mtd, struct nand_chip *chip,
1563 size_t size = denali->mtd.writesize + denali->mtd.oobsize; 1145 size_t size = denali->mtd.writesize + denali->mtd.oobsize;
1564 1146
1565 uint32_t irq_status = 0; 1147 uint32_t irq_status = 0;
1566 uint32_t irq_mask = INTR_STATUS0__ECC_TRANSACTION_DONE | 1148 uint32_t irq_mask = INTR_STATUS0__ECC_TRANSACTION_DONE |
1567 INTR_STATUS0__ECC_ERR; 1149 INTR_STATUS0__ECC_ERR;
1568 bool check_erased_page = false; 1150 bool check_erased_page = false;
1569 1151
1152 if (page != denali->page) {
1153 dev_err(&denali->dev->dev, "IN %s: page %d is not"
1154 " equal to denali->page %d, investigate!!",
1155 __func__, page, denali->page);
1156 BUG();
1157 }
1158
1570 setup_ecc_for_xfer(denali, true, false); 1159 setup_ecc_for_xfer(denali, true, false);
1571 1160
1572 denali_enable_dma(denali, true); 1161 denali_enable_dma(denali, true);
@@ -1581,26 +1170,20 @@ static int denali_read_page(struct mtd_info *mtd, struct nand_chip *chip,
1581 pci_dma_sync_single_for_cpu(pci_dev, addr, size, PCI_DMA_FROMDEVICE); 1170 pci_dma_sync_single_for_cpu(pci_dev, addr, size, PCI_DMA_FROMDEVICE);
1582 1171
1583 memcpy(buf, denali->buf.buf, mtd->writesize); 1172 memcpy(buf, denali->buf.buf, mtd->writesize);
1584 1173
1585 check_erased_page = handle_ecc(denali, buf, chip->oob_poi, irq_status); 1174 check_erased_page = handle_ecc(denali, buf, irq_status);
1586 denali_enable_dma(denali, false); 1175 denali_enable_dma(denali, false);
1587 1176
1588 if (check_erased_page) 1177 if (check_erased_page) {
1589 {
1590 read_oob_data(&denali->mtd, chip->oob_poi, denali->page); 1178 read_oob_data(&denali->mtd, chip->oob_poi, denali->page);
1591 1179
1592 /* check ECC failures that may have occurred on erased pages */ 1180 /* check ECC failures that may have occurred on erased pages */
1593 if (check_erased_page) 1181 if (check_erased_page) {
1594 {
1595 if (!is_erased(buf, denali->mtd.writesize)) 1182 if (!is_erased(buf, denali->mtd.writesize))
1596 {
1597 denali->mtd.ecc_stats.failed++; 1183 denali->mtd.ecc_stats.failed++;
1598 }
1599 if (!is_erased(buf, denali->mtd.oobsize)) 1184 if (!is_erased(buf, denali->mtd.oobsize))
1600 {
1601 denali->mtd.ecc_stats.failed++; 1185 denali->mtd.ecc_stats.failed++;
1602 } 1186 }
1603 }
1604 } 1187 }
1605 return 0; 1188 return 0;
1606} 1189}
@@ -1616,7 +1199,14 @@ static int denali_read_page_raw(struct mtd_info *mtd, struct nand_chip *chip,
1616 1199
1617 uint32_t irq_status = 0; 1200 uint32_t irq_status = 0;
1618 uint32_t irq_mask = INTR_STATUS0__DMA_CMD_COMP; 1201 uint32_t irq_mask = INTR_STATUS0__DMA_CMD_COMP;
1619 1202
1203 if (page != denali->page) {
1204 dev_err(&denali->dev->dev, "IN %s: page %d is not"
1205 " equal to denali->page %d, investigate!!",
1206 __func__, page, denali->page);
1207 BUG();
1208 }
1209
1620 setup_ecc_for_xfer(denali, false, true); 1210 setup_ecc_for_xfer(denali, false, true);
1621 denali_enable_dma(denali, true); 1211 denali_enable_dma(denali, true);
1622 1212
@@ -1644,22 +1234,15 @@ static uint8_t denali_read_byte(struct mtd_info *mtd)
1644 uint8_t result = 0xff; 1234 uint8_t result = 0xff;
1645 1235
1646 if (denali->buf.head < denali->buf.tail) 1236 if (denali->buf.head < denali->buf.tail)
1647 {
1648 result = denali->buf.buf[denali->buf.head++]; 1237 result = denali->buf.buf[denali->buf.head++];
1649 }
1650 1238
1651#if DEBUG_DENALI
1652 printk("read byte -> 0x%02x\n", result);
1653#endif
1654 return result; 1239 return result;
1655} 1240}
1656 1241
1657static void denali_select_chip(struct mtd_info *mtd, int chip) 1242static void denali_select_chip(struct mtd_info *mtd, int chip)
1658{ 1243{
1659 struct denali_nand_info *denali = mtd_to_denali(mtd); 1244 struct denali_nand_info *denali = mtd_to_denali(mtd);
1660#if DEBUG_DENALI 1245
1661 printk("denali select chip %d\n", chip);
1662#endif
1663 spin_lock_irq(&denali->irq_lock); 1246 spin_lock_irq(&denali->irq_lock);
1664 denali->flash_bank = chip; 1247 denali->flash_bank = chip;
1665 spin_unlock_irq(&denali->irq_lock); 1248 spin_unlock_irq(&denali->irq_lock);
@@ -1671,9 +1254,6 @@ static int denali_waitfunc(struct mtd_info *mtd, struct nand_chip *chip)
1671 int status = denali->status; 1254 int status = denali->status;
1672 denali->status = 0; 1255 denali->status = 0;
1673 1256
1674#if DEBUG_DENALI
1675 printk("waitfunc %d\n", status);
1676#endif
1677 return status; 1257 return status;
1678} 1258}
1679 1259
@@ -1683,95 +1263,93 @@ static void denali_erase(struct mtd_info *mtd, int page)
1683 1263
1684 uint32_t cmd = 0x0, irq_status = 0; 1264 uint32_t cmd = 0x0, irq_status = 0;
1685 1265
1686#if DEBUG_DENALI
1687 printk("erase page: %d\n", page);
1688#endif
1689 /* clear interrupts */ 1266 /* clear interrupts */
1690 clear_interrupts(denali); 1267 clear_interrupts(denali);
1691 1268
1692 /* setup page read request for access type */ 1269 /* setup page read request for access type */
1693 cmd = MODE_10 | BANK(denali->flash_bank) | page; 1270 cmd = MODE_10 | BANK(denali->flash_bank) | page;
1694 index_addr(denali, (uint32_t)cmd, 0x1); 1271 index_addr(denali, (uint32_t)cmd, 0x1);
1695 1272
1696 /* wait for erase to complete or failure to occur */ 1273 /* wait for erase to complete or failure to occur */
1697 irq_status = wait_for_irq(denali, INTR_STATUS0__ERASE_COMP | 1274 irq_status = wait_for_irq(denali, INTR_STATUS0__ERASE_COMP |
1698 INTR_STATUS0__ERASE_FAIL); 1275 INTR_STATUS0__ERASE_FAIL);
1699 1276
1700 denali->status = (irq_status & INTR_STATUS0__ERASE_FAIL) ? NAND_STATUS_FAIL : 1277 denali->status = (irq_status & INTR_STATUS0__ERASE_FAIL) ?
1701 PASS; 1278 NAND_STATUS_FAIL : PASS;
1702} 1279}
1703 1280
1704static void denali_cmdfunc(struct mtd_info *mtd, unsigned int cmd, int col, 1281static void denali_cmdfunc(struct mtd_info *mtd, unsigned int cmd, int col,
1705 int page) 1282 int page)
1706{ 1283{
1707 struct denali_nand_info *denali = mtd_to_denali(mtd); 1284 struct denali_nand_info *denali = mtd_to_denali(mtd);
1285 uint32_t addr, id;
1286 int i;
1708 1287
1709#if DEBUG_DENALI 1288 switch (cmd) {
1710 printk("cmdfunc: 0x%x %d %d\n", cmd, col, page); 1289 case NAND_CMD_PAGEPROG:
1711#endif 1290 break;
1712 switch (cmd) 1291 case NAND_CMD_STATUS:
1713 { 1292 read_status(denali);
1714 case NAND_CMD_PAGEPROG: 1293 break;
1715 break; 1294 case NAND_CMD_READID:
1716 case NAND_CMD_STATUS: 1295 reset_buf(denali);
1717 read_status(denali); 1296 /*sometimes ManufactureId read from register is not right
1718 break; 1297 * e.g. some of Micron MT29F32G08QAA MLC NAND chips
1719 case NAND_CMD_READID: 1298 * So here we send READID cmd to NAND insteand
1720 reset_buf(denali); 1299 * */
1721 if (denali->flash_bank < denali->total_used_banks) 1300 addr = (uint32_t)MODE_11 | BANK(denali->flash_bank);
1722 { 1301 index_addr(denali, (uint32_t)addr | 0, 0x90);
1723 /* write manufacturer information into nand 1302 index_addr(denali, (uint32_t)addr | 1, 0);
1724 buffer for NAND subsystem to fetch. 1303 for (i = 0; i < 5; i++) {
1725 */ 1304 index_addr_read_data(denali,
1726 write_byte_to_buf(denali, denali->dev_info.wDeviceMaker); 1305 (uint32_t)addr | 2,
1727 write_byte_to_buf(denali, denali->dev_info.wDeviceID); 1306 &id);
1728 write_byte_to_buf(denali, denali->dev_info.bDeviceParam0); 1307 write_byte_to_buf(denali, id);
1729 write_byte_to_buf(denali, denali->dev_info.bDeviceParam1); 1308 }
1730 write_byte_to_buf(denali, denali->dev_info.bDeviceParam2); 1309 break;
1731 } 1310 case NAND_CMD_READ0:
1732 else 1311 case NAND_CMD_SEQIN:
1733 { 1312 denali->page = page;
1734 int i; 1313 break;
1735 for (i = 0; i < 5; i++) 1314 case NAND_CMD_RESET:
1736 write_byte_to_buf(denali, 0xff); 1315 reset_bank(denali);
1737 } 1316 break;
1738 break; 1317 case NAND_CMD_READOOB:
1739 case NAND_CMD_READ0: 1318 /* TODO: Read OOB data */
1740 case NAND_CMD_SEQIN: 1319 break;
1741 denali->page = page; 1320 default:
1742 break; 1321 printk(KERN_ERR ": unsupported command"
1743 case NAND_CMD_RESET: 1322 " received 0x%x\n", cmd);
1744 reset_bank(denali); 1323 break;
1745 break;
1746 case NAND_CMD_READOOB:
1747 /* TODO: Read OOB data */
1748 break;
1749 default:
1750 printk(KERN_ERR ": unsupported command received 0x%x\n", cmd);
1751 break;
1752 } 1324 }
1753} 1325}
1754 1326
1755/* stubs for ECC functions not used by the NAND core */ 1327/* stubs for ECC functions not used by the NAND core */
1756static int denali_ecc_calculate(struct mtd_info *mtd, const uint8_t *data, 1328static int denali_ecc_calculate(struct mtd_info *mtd, const uint8_t *data,
1757 uint8_t *ecc_code) 1329 uint8_t *ecc_code)
1758{ 1330{
1759 printk(KERN_ERR "denali_ecc_calculate called unexpectedly\n"); 1331 struct denali_nand_info *denali = mtd_to_denali(mtd);
1332 dev_err(&denali->dev->dev,
1333 "denali_ecc_calculate called unexpectedly\n");
1760 BUG(); 1334 BUG();
1761 return -EIO; 1335 return -EIO;
1762} 1336}
1763 1337
1764static int denali_ecc_correct(struct mtd_info *mtd, uint8_t *data, 1338static int denali_ecc_correct(struct mtd_info *mtd, uint8_t *data,
1765 uint8_t *read_ecc, uint8_t *calc_ecc) 1339 uint8_t *read_ecc, uint8_t *calc_ecc)
1766{ 1340{
1767 printk(KERN_ERR "denali_ecc_correct called unexpectedly\n"); 1341 struct denali_nand_info *denali = mtd_to_denali(mtd);
1342 dev_err(&denali->dev->dev,
1343 "denali_ecc_correct called unexpectedly\n");
1768 BUG(); 1344 BUG();
1769 return -EIO; 1345 return -EIO;
1770} 1346}
1771 1347
1772static void denali_ecc_hwctl(struct mtd_info *mtd, int mode) 1348static void denali_ecc_hwctl(struct mtd_info *mtd, int mode)
1773{ 1349{
1774 printk(KERN_ERR "denali_ecc_hwctl called unexpectedly\n"); 1350 struct denali_nand_info *denali = mtd_to_denali(mtd);
1351 dev_err(&denali->dev->dev,
1352 "denali_ecc_hwctl called unexpectedly\n");
1775 BUG(); 1353 BUG();
1776} 1354}
1777/* end NAND core entry points */ 1355/* end NAND core entry points */
@@ -1779,38 +1357,39 @@ static void denali_ecc_hwctl(struct mtd_info *mtd, int mode)
1779/* Initialization code to bring the device up to a known good state */ 1357/* Initialization code to bring the device up to a known good state */
1780static void denali_hw_init(struct denali_nand_info *denali) 1358static void denali_hw_init(struct denali_nand_info *denali)
1781{ 1359{
1782 denali_irq_init(denali); 1360 /* tell driver how many bit controller will skip before
1783 NAND_Flash_Reset(denali); 1361 * writing ECC code in OOB, this register may be already
1784 denali_write32(0x0F, denali->flash_reg + RB_PIN_ENABLED); 1362 * set by firmware. So we read this value out.
1785 denali_write32(CHIP_EN_DONT_CARE__FLAG, denali->flash_reg + CHIP_ENABLE_DONT_CARE); 1363 * if this value is 0, just let it be.
1786 1364 * */
1787 denali_write32(0x0, denali->flash_reg + SPARE_AREA_SKIP_BYTES); 1365 denali->bbtskipbytes = ioread32(denali->flash_reg +
1788 denali_write32(0xffff, denali->flash_reg + SPARE_AREA_MARKER); 1366 SPARE_AREA_SKIP_BYTES);
1367 denali_nand_reset(denali);
1368 iowrite32(0x0F, denali->flash_reg + RB_PIN_ENABLED);
1369 iowrite32(CHIP_EN_DONT_CARE__FLAG,
1370 denali->flash_reg + CHIP_ENABLE_DONT_CARE);
1371
1372 iowrite32(0xffff, denali->flash_reg + SPARE_AREA_MARKER);
1789 1373
1790 /* Should set value for these registers when init */ 1374 /* Should set value for these registers when init */
1791 denali_write32(0, denali->flash_reg + TWO_ROW_ADDR_CYCLES); 1375 iowrite32(0, denali->flash_reg + TWO_ROW_ADDR_CYCLES);
1792 denali_write32(1, denali->flash_reg + ECC_ENABLE); 1376 iowrite32(1, denali->flash_reg + ECC_ENABLE);
1377 denali_nand_timing_set(denali);
1378 denali_irq_init(denali);
1793} 1379}
1794 1380
1795/* ECC layout for SLC devices. Denali spec indicates SLC fixed at 4 bytes */ 1381/* Althogh controller spec said SLC ECC is forceb to be 4bit,
1796#define ECC_BYTES_SLC 4 * (2048 / ECC_SECTOR_SIZE) 1382 * but denali controller in MRST only support 15bit and 8bit ECC
1797static struct nand_ecclayout nand_oob_slc = { 1383 * correction
1798 .eccbytes = 4, 1384 * */
1799 .eccpos = { 0, 1, 2, 3 }, /* not used */ 1385#define ECC_8BITS 14
1800 .oobfree = {{ 1386static struct nand_ecclayout nand_8bit_oob = {
1801 .offset = ECC_BYTES_SLC, 1387 .eccbytes = 14,
1802 .length = 64 - ECC_BYTES_SLC
1803 }}
1804}; 1388};
1805 1389
1806#define ECC_BYTES_MLC 14 * (2048 / ECC_SECTOR_SIZE) 1390#define ECC_15BITS 26
1807static struct nand_ecclayout nand_oob_mlc_14bit = { 1391static struct nand_ecclayout nand_15bit_oob = {
1808 .eccbytes = 14, 1392 .eccbytes = 26,
1809 .eccpos = { 0, 1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13 }, /* not used */
1810 .oobfree = {{
1811 .offset = ECC_BYTES_MLC,
1812 .length = 64 - ECC_BYTES_MLC
1813 }}
1814}; 1393};
1815 1394
1816static uint8_t bbt_pattern[] = {'B', 'b', 't', '0' }; 1395static uint8_t bbt_pattern[] = {'B', 'b', 't', '0' };
@@ -1842,12 +1421,12 @@ void denali_drv_init(struct denali_nand_info *denali)
1842 denali->idx = 0; 1421 denali->idx = 0;
1843 1422
1844 /* setup interrupt handler */ 1423 /* setup interrupt handler */
1845 /* the completion object will be used to notify 1424 /* the completion object will be used to notify
1846 * the callee that the interrupt is done */ 1425 * the callee that the interrupt is done */
1847 init_completion(&denali->complete); 1426 init_completion(&denali->complete);
1848 1427
1849 /* the spinlock will be used to synchronize the ISR 1428 /* the spinlock will be used to synchronize the ISR
1850 * with any element that might be access shared 1429 * with any element that might be access shared
1851 * data (interrupt status) */ 1430 * data (interrupt status) */
1852 spin_lock_init(&denali->irq_lock); 1431 spin_lock_init(&denali->irq_lock);
1853 1432
@@ -1866,9 +1445,6 @@ static int denali_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
1866 unsigned long csr_len, mem_len; 1445 unsigned long csr_len, mem_len;
1867 struct denali_nand_info *denali; 1446 struct denali_nand_info *denali;
1868 1447
1869 nand_dbg_print(NAND_DBG_TRACE, "%s, Line %d, Function: %s\n",
1870 __FILE__, __LINE__, __func__);
1871
1872 denali = kzalloc(sizeof(*denali), GFP_KERNEL); 1448 denali = kzalloc(sizeof(*denali), GFP_KERNEL);
1873 if (!denali) 1449 if (!denali)
1874 return -ENOMEM; 1450 return -ENOMEM;
@@ -1876,19 +1452,18 @@ static int denali_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
1876 ret = pci_enable_device(dev); 1452 ret = pci_enable_device(dev);
1877 if (ret) { 1453 if (ret) {
1878 printk(KERN_ERR "Spectra: pci_enable_device failed.\n"); 1454 printk(KERN_ERR "Spectra: pci_enable_device failed.\n");
1879 goto failed_enable; 1455 goto failed_alloc_memery;
1880 } 1456 }
1881 1457
1882 if (id->driver_data == INTEL_CE4100) { 1458 if (id->driver_data == INTEL_CE4100) {
1883 /* Due to a silicon limitation, we can only support 1459 /* Due to a silicon limitation, we can only support
1884 * ONFI timing mode 1 and below. 1460 * ONFI timing mode 1 and below.
1885 */ 1461 */
1886 if (onfi_timing_mode < -1 || onfi_timing_mode > 1) 1462 if (onfi_timing_mode < -1 || onfi_timing_mode > 1) {
1887 { 1463 printk(KERN_ERR "Intel CE4100 only supports"
1888 printk("Intel CE4100 only supports ONFI timing mode 1 " 1464 " ONFI timing mode 1 or below\n");
1889 "or below\n");
1890 ret = -EINVAL; 1465 ret = -EINVAL;
1891 goto failed_enable; 1466 goto failed_enable_dev;
1892 } 1467 }
1893 denali->platform = INTEL_CE4100; 1468 denali->platform = INTEL_CE4100;
1894 mem_base = pci_resource_start(dev, 0); 1469 mem_base = pci_resource_start(dev, 0);
@@ -1898,108 +1473,74 @@ static int denali_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
1898 } else { 1473 } else {
1899 denali->platform = INTEL_MRST; 1474 denali->platform = INTEL_MRST;
1900 csr_base = pci_resource_start(dev, 0); 1475 csr_base = pci_resource_start(dev, 0);
1901 csr_len = pci_resource_start(dev, 0); 1476 csr_len = pci_resource_len(dev, 0);
1902 mem_base = pci_resource_start(dev, 1); 1477 mem_base = pci_resource_start(dev, 1);
1903 mem_len = pci_resource_len(dev, 1); 1478 mem_len = pci_resource_len(dev, 1);
1904 if (!mem_len) { 1479 if (!mem_len) {
1905 mem_base = csr_base + csr_len; 1480 mem_base = csr_base + csr_len;
1906 mem_len = csr_len; 1481 mem_len = csr_len;
1907 nand_dbg_print(NAND_DBG_WARN,
1908 "Spectra: No second BAR for PCI device; assuming %08Lx\n",
1909 (uint64_t)csr_base);
1910 } 1482 }
1911 } 1483 }
1912 1484
1913 /* Is 32-bit DMA supported? */ 1485 /* Is 32-bit DMA supported? */
1914 ret = pci_set_dma_mask(dev, DMA_BIT_MASK(32)); 1486 ret = pci_set_dma_mask(dev, DMA_BIT_MASK(32));
1915 1487
1916 if (ret) 1488 if (ret) {
1917 {
1918 printk(KERN_ERR "Spectra: no usable DMA configuration\n"); 1489 printk(KERN_ERR "Spectra: no usable DMA configuration\n");
1919 goto failed_enable; 1490 goto failed_enable_dev;
1920 } 1491 }
1921 denali->buf.dma_buf = pci_map_single(dev, denali->buf.buf, DENALI_BUF_SIZE, 1492 denali->buf.dma_buf =
1922 PCI_DMA_BIDIRECTIONAL); 1493 pci_map_single(dev, denali->buf.buf,
1923 1494 DENALI_BUF_SIZE,
1924 if (pci_dma_mapping_error(dev, denali->buf.dma_buf)) 1495 PCI_DMA_BIDIRECTIONAL);
1925 { 1496
1926 printk(KERN_ERR "Spectra: failed to map DMA buffer\n"); 1497 if (pci_dma_mapping_error(dev, denali->buf.dma_buf)) {
1927 goto failed_enable; 1498 dev_err(&dev->dev, "Spectra: failed to map DMA buffer\n");
1499 goto failed_enable_dev;
1928 } 1500 }
1929 1501
1930 pci_set_master(dev); 1502 pci_set_master(dev);
1931 denali->dev = dev; 1503 denali->dev = dev;
1504 denali->mtd.dev.parent = &dev->dev;
1932 1505
1933 ret = pci_request_regions(dev, DENALI_NAND_NAME); 1506 ret = pci_request_regions(dev, DENALI_NAND_NAME);
1934 if (ret) { 1507 if (ret) {
1935 printk(KERN_ERR "Spectra: Unable to request memory regions\n"); 1508 printk(KERN_ERR "Spectra: Unable to request memory regions\n");
1936 goto failed_req_csr; 1509 goto failed_dma_map;
1937 } 1510 }
1938 1511
1939 denali->flash_reg = ioremap_nocache(csr_base, csr_len); 1512 denali->flash_reg = ioremap_nocache(csr_base, csr_len);
1940 if (!denali->flash_reg) { 1513 if (!denali->flash_reg) {
1941 printk(KERN_ERR "Spectra: Unable to remap memory region\n"); 1514 printk(KERN_ERR "Spectra: Unable to remap memory region\n");
1942 ret = -ENOMEM; 1515 ret = -ENOMEM;
1943 goto failed_remap_csr; 1516 goto failed_req_regions;
1944 } 1517 }
1945 nand_dbg_print(NAND_DBG_DEBUG, "Spectra: CSR 0x%08Lx -> 0x%p (0x%lx)\n",
1946 (uint64_t)csr_base, denali->flash_reg, csr_len);
1947 1518
1948 denali->flash_mem = ioremap_nocache(mem_base, mem_len); 1519 denali->flash_mem = ioremap_nocache(mem_base, mem_len);
1949 if (!denali->flash_mem) { 1520 if (!denali->flash_mem) {
1950 printk(KERN_ERR "Spectra: ioremap_nocache failed!"); 1521 printk(KERN_ERR "Spectra: ioremap_nocache failed!");
1951 iounmap(denali->flash_reg);
1952 ret = -ENOMEM; 1522 ret = -ENOMEM;
1953 goto failed_remap_csr; 1523 goto failed_remap_reg;
1954 } 1524 }
1955 1525
1956 nand_dbg_print(NAND_DBG_WARN,
1957 "Spectra: Remapped flash base address: "
1958 "0x%p, len: %ld\n",
1959 denali->flash_mem, csr_len);
1960
1961 denali_hw_init(denali); 1526 denali_hw_init(denali);
1962 denali_drv_init(denali); 1527 denali_drv_init(denali);
1963 1528
1964 nand_dbg_print(NAND_DBG_DEBUG, "Spectra: IRQ %d\n", dev->irq); 1529 /* denali_isr register is done after all the hardware
1530 * initilization is finished*/
1965 if (request_irq(dev->irq, denali_isr, IRQF_SHARED, 1531 if (request_irq(dev->irq, denali_isr, IRQF_SHARED,
1966 DENALI_NAND_NAME, denali)) { 1532 DENALI_NAND_NAME, denali)) {
1967 printk(KERN_ERR "Spectra: Unable to allocate IRQ\n"); 1533 printk(KERN_ERR "Spectra: Unable to allocate IRQ\n");
1968 ret = -ENODEV; 1534 ret = -ENODEV;
1969 goto failed_request_irq; 1535 goto failed_remap_mem;
1970 } 1536 }
1971 1537
1972 /* now that our ISR is registered, we can enable interrupts */ 1538 /* now that our ISR is registered, we can enable interrupts */
1973 NAND_LLD_Enable_Disable_Interrupts(denali, true); 1539 denali_set_intr_modes(denali, true);
1974 1540
1975 pci_set_drvdata(dev, denali); 1541 pci_set_drvdata(dev, denali);
1976 1542
1977 NAND_Read_Device_ID(denali); 1543 denali->mtd.name = "denali-nand";
1978
1979 /* MTD supported page sizes vary by kernel. We validate our
1980 kernel supports the device here.
1981 */
1982 if (denali->dev_info.wPageSize > NAND_MAX_PAGESIZE + NAND_MAX_OOBSIZE)
1983 {
1984 ret = -ENODEV;
1985 printk(KERN_ERR "Spectra: device size not supported by this "
1986 "version of MTD.");
1987 goto failed_nand;
1988 }
1989
1990 nand_dbg_print(NAND_DBG_DEBUG, "Dump timing register values:"
1991 "acc_clks: %d, re_2_we: %d, we_2_re: %d,"
1992 "addr_2_data: %d, rdwr_en_lo_cnt: %d, "
1993 "rdwr_en_hi_cnt: %d, cs_setup_cnt: %d\n",
1994 ioread32(denali->flash_reg + ACC_CLKS),
1995 ioread32(denali->flash_reg + RE_2_WE),
1996 ioread32(denali->flash_reg + WE_2_RE),
1997 ioread32(denali->flash_reg + ADDR_2_DATA),
1998 ioread32(denali->flash_reg + RDWR_EN_LO_CNT),
1999 ioread32(denali->flash_reg + RDWR_EN_HI_CNT),
2000 ioread32(denali->flash_reg + CS_SETUP_CNT));
2001
2002 denali->mtd.name = "Denali NAND";
2003 denali->mtd.owner = THIS_MODULE; 1544 denali->mtd.owner = THIS_MODULE;
2004 denali->mtd.priv = &denali->nand; 1545 denali->mtd.priv = &denali->nand;
2005 1546
@@ -2009,18 +1550,46 @@ static int denali_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
2009 denali->nand.read_byte = denali_read_byte; 1550 denali->nand.read_byte = denali_read_byte;
2010 denali->nand.waitfunc = denali_waitfunc; 1551 denali->nand.waitfunc = denali_waitfunc;
2011 1552
2012 /* scan for NAND devices attached to the controller 1553 /* scan for NAND devices attached to the controller
2013 * this is the first stage in a two step process to register 1554 * this is the first stage in a two step process to register
2014 * with the nand subsystem */ 1555 * with the nand subsystem */
2015 if (nand_scan_ident(&denali->mtd, LLD_MAX_FLASH_BANKS, NULL)) 1556 if (nand_scan_ident(&denali->mtd, LLD_MAX_FLASH_BANKS, NULL)) {
2016 {
2017 ret = -ENXIO; 1557 ret = -ENXIO;
2018 goto failed_nand; 1558 goto failed_req_irq;
2019 } 1559 }
2020 1560
2021 /* second stage of the NAND scan 1561 /* MTD supported page sizes vary by kernel. We validate our
2022 * this stage requires information regarding ECC and 1562 * kernel supports the device here.
2023 * bad block management. */ 1563 */
1564 if (denali->mtd.writesize > NAND_MAX_PAGESIZE + NAND_MAX_OOBSIZE) {
1565 ret = -ENODEV;
1566 printk(KERN_ERR "Spectra: device size not supported by this "
1567 "version of MTD.");
1568 goto failed_req_irq;
1569 }
1570
1571 /* support for multi nand
1572 * MTD known nothing about multi nand,
1573 * so we should tell it the real pagesize
1574 * and anything necessery
1575 */
1576 denali->devnum = ioread32(denali->flash_reg + DEVICES_CONNECTED);
1577 denali->nand.chipsize <<= (denali->devnum - 1);
1578 denali->nand.page_shift += (denali->devnum - 1);
1579 denali->nand.pagemask = (denali->nand.chipsize >>
1580 denali->nand.page_shift) - 1;
1581 denali->nand.bbt_erase_shift += (denali->devnum - 1);
1582 denali->nand.phys_erase_shift = denali->nand.bbt_erase_shift;
1583 denali->nand.chip_shift += (denali->devnum - 1);
1584 denali->mtd.writesize <<= (denali->devnum - 1);
1585 denali->mtd.oobsize <<= (denali->devnum - 1);
1586 denali->mtd.erasesize <<= (denali->devnum - 1);
1587 denali->mtd.size = denali->nand.numchips * denali->nand.chipsize;
1588 denali->bbtskipbytes *= denali->devnum;
1589
1590 /* second stage of the NAND scan
1591 * this stage requires information regarding ECC and
1592 * bad block management. */
2024 1593
2025 /* Bad block management */ 1594 /* Bad block management */
2026 denali->nand.bbt_td = &bbt_main_descr; 1595 denali->nand.bbt_td = &bbt_main_descr;
@@ -2030,26 +1599,57 @@ static int denali_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
2030 denali->nand.options |= NAND_USE_FLASH_BBT | NAND_SKIP_BBTSCAN; 1599 denali->nand.options |= NAND_USE_FLASH_BBT | NAND_SKIP_BBTSCAN;
2031 denali->nand.ecc.mode = NAND_ECC_HW_SYNDROME; 1600 denali->nand.ecc.mode = NAND_ECC_HW_SYNDROME;
2032 1601
2033 if (denali->dev_info.MLCDevice) 1602 /* Denali Controller only support 15bit and 8bit ECC in MRST,
2034 { 1603 * so just let controller do 15bit ECC for MLC and 8bit ECC for
2035 denali->nand.ecc.layout = &nand_oob_mlc_14bit; 1604 * SLC if possible.
2036 denali->nand.ecc.bytes = ECC_BYTES_MLC; 1605 * */
2037 } 1606 if (denali->nand.cellinfo & 0xc &&
2038 else /* SLC */ 1607 (denali->mtd.oobsize > (denali->bbtskipbytes +
2039 { 1608 ECC_15BITS * (denali->mtd.writesize /
2040 denali->nand.ecc.layout = &nand_oob_slc; 1609 ECC_SECTOR_SIZE)))) {
2041 denali->nand.ecc.bytes = ECC_BYTES_SLC; 1610 /* if MLC OOB size is large enough, use 15bit ECC*/
1611 denali->nand.ecc.layout = &nand_15bit_oob;
1612 denali->nand.ecc.bytes = ECC_15BITS;
1613 iowrite32(15, denali->flash_reg + ECC_CORRECTION);
1614 } else if (denali->mtd.oobsize < (denali->bbtskipbytes +
1615 ECC_8BITS * (denali->mtd.writesize /
1616 ECC_SECTOR_SIZE))) {
1617 printk(KERN_ERR "Your NAND chip OOB is not large enough to"
1618 " contain 8bit ECC correction codes");
1619 goto failed_req_irq;
1620 } else {
1621 denali->nand.ecc.layout = &nand_8bit_oob;
1622 denali->nand.ecc.bytes = ECC_8BITS;
1623 iowrite32(8, denali->flash_reg + ECC_CORRECTION);
2042 } 1624 }
2043 1625
2044 /* These functions are required by the NAND core framework, otherwise, 1626 denali->nand.ecc.bytes *= denali->devnum;
2045 the NAND core will assert. However, we don't need them, so we'll stub 1627 denali->nand.ecc.layout->eccbytes *=
2046 them out. */ 1628 denali->mtd.writesize / ECC_SECTOR_SIZE;
1629 denali->nand.ecc.layout->oobfree[0].offset =
1630 denali->bbtskipbytes + denali->nand.ecc.layout->eccbytes;
1631 denali->nand.ecc.layout->oobfree[0].length =
1632 denali->mtd.oobsize - denali->nand.ecc.layout->eccbytes -
1633 denali->bbtskipbytes;
1634
1635 /* Let driver know the total blocks number and
1636 * how many blocks contained by each nand chip.
1637 * blksperchip will help driver to know how many
1638 * blocks is taken by FW.
1639 * */
1640 denali->totalblks = denali->mtd.size >>
1641 denali->nand.phys_erase_shift;
1642 denali->blksperchip = denali->totalblks / denali->nand.numchips;
1643
1644 /* These functions are required by the NAND core framework, otherwise,
1645 * the NAND core will assert. However, we don't need them, so we'll stub
1646 * them out. */
2047 denali->nand.ecc.calculate = denali_ecc_calculate; 1647 denali->nand.ecc.calculate = denali_ecc_calculate;
2048 denali->nand.ecc.correct = denali_ecc_correct; 1648 denali->nand.ecc.correct = denali_ecc_correct;
2049 denali->nand.ecc.hwctl = denali_ecc_hwctl; 1649 denali->nand.ecc.hwctl = denali_ecc_hwctl;
2050 1650
2051 /* override the default read operations */ 1651 /* override the default read operations */
2052 denali->nand.ecc.size = denali->mtd.writesize; 1652 denali->nand.ecc.size = ECC_SECTOR_SIZE * denali->devnum;
2053 denali->nand.ecc.read_page = denali_read_page; 1653 denali->nand.ecc.read_page = denali_read_page;
2054 denali->nand.ecc.read_page_raw = denali_read_page_raw; 1654 denali->nand.ecc.read_page_raw = denali_read_page_raw;
2055 denali->nand.ecc.write_page = denali_write_page; 1655 denali->nand.ecc.write_page = denali_write_page;
@@ -2058,30 +1658,33 @@ static int denali_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
2058 denali->nand.ecc.write_oob = denali_write_oob; 1658 denali->nand.ecc.write_oob = denali_write_oob;
2059 denali->nand.erase_cmd = denali_erase; 1659 denali->nand.erase_cmd = denali_erase;
2060 1660
2061 if (nand_scan_tail(&denali->mtd)) 1661 if (nand_scan_tail(&denali->mtd)) {
2062 {
2063 ret = -ENXIO; 1662 ret = -ENXIO;
2064 goto failed_nand; 1663 goto failed_req_irq;
2065 } 1664 }
2066 1665
2067 ret = add_mtd_device(&denali->mtd); 1666 ret = add_mtd_device(&denali->mtd);
2068 if (ret) { 1667 if (ret) {
2069 printk(KERN_ERR "Spectra: Failed to register MTD device: %d\n", ret); 1668 dev_err(&dev->dev, "Spectra: Failed to register MTD: %d\n",
2070 goto failed_nand; 1669 ret);
1670 goto failed_req_irq;
2071 } 1671 }
2072 return 0; 1672 return 0;
2073 1673
2074 failed_nand: 1674failed_req_irq:
2075 denali_irq_cleanup(dev->irq, denali); 1675 denali_irq_cleanup(dev->irq, denali);
2076 failed_request_irq: 1676failed_remap_mem:
2077 iounmap(denali->flash_reg);
2078 iounmap(denali->flash_mem); 1677 iounmap(denali->flash_mem);
2079 failed_remap_csr: 1678failed_remap_reg:
1679 iounmap(denali->flash_reg);
1680failed_req_regions:
2080 pci_release_regions(dev); 1681 pci_release_regions(dev);
2081 failed_req_csr: 1682failed_dma_map:
2082 pci_unmap_single(dev, denali->buf.dma_buf, DENALI_BUF_SIZE, 1683 pci_unmap_single(dev, denali->buf.dma_buf, DENALI_BUF_SIZE,
2083 PCI_DMA_BIDIRECTIONAL); 1684 PCI_DMA_BIDIRECTIONAL);
2084 failed_enable: 1685failed_enable_dev:
1686 pci_disable_device(dev);
1687failed_alloc_memery:
2085 kfree(denali); 1688 kfree(denali);
2086 return ret; 1689 return ret;
2087} 1690}
@@ -2091,9 +1694,6 @@ static void denali_pci_remove(struct pci_dev *dev)
2091{ 1694{
2092 struct denali_nand_info *denali = pci_get_drvdata(dev); 1695 struct denali_nand_info *denali = pci_get_drvdata(dev);
2093 1696
2094 nand_dbg_print(NAND_DBG_WARN, "%s, Line %d, Function: %s\n",
2095 __FILE__, __LINE__, __func__);
2096
2097 nand_release(&denali->mtd); 1697 nand_release(&denali->mtd);
2098 del_mtd_device(&denali->mtd); 1698 del_mtd_device(&denali->mtd);
2099 1699
@@ -2103,7 +1703,7 @@ static void denali_pci_remove(struct pci_dev *dev)
2103 iounmap(denali->flash_mem); 1703 iounmap(denali->flash_mem);
2104 pci_release_regions(dev); 1704 pci_release_regions(dev);
2105 pci_disable_device(dev); 1705 pci_disable_device(dev);
2106 pci_unmap_single(dev, denali->buf.dma_buf, DENALI_BUF_SIZE, 1706 pci_unmap_single(dev, denali->buf.dma_buf, DENALI_BUF_SIZE,
2107 PCI_DMA_BIDIRECTIONAL); 1707 PCI_DMA_BIDIRECTIONAL);
2108 pci_set_drvdata(dev, NULL); 1708 pci_set_drvdata(dev, NULL);
2109 kfree(denali); 1709 kfree(denali);
@@ -2120,7 +1720,8 @@ static struct pci_driver denali_pci_driver = {
2120 1720
2121static int __devinit denali_init(void) 1721static int __devinit denali_init(void)
2122{ 1722{
2123 printk(KERN_INFO "Spectra MTD driver built on %s @ %s\n", __DATE__, __TIME__); 1723 printk(KERN_INFO "Spectra MTD driver built on %s @ %s\n",
1724 __DATE__, __TIME__);
2124 return pci_register_driver(&denali_pci_driver); 1725 return pci_register_driver(&denali_pci_driver);
2125} 1726}
2126 1727
diff --git a/drivers/mtd/nand/denali.h b/drivers/mtd/nand/denali.h
index 422a29ab2f60..3918bcb1561e 100644
--- a/drivers/mtd/nand/denali.h
+++ b/drivers/mtd/nand/denali.h
@@ -17,7 +17,7 @@
17 * 17 *
18 */ 18 */
19 19
20#include <linux/mtd/nand.h> 20#include <linux/mtd/nand.h>
21 21
22#define DEVICE_RESET 0x0 22#define DEVICE_RESET 0x0
23#define DEVICE_RESET__BANK0 0x0001 23#define DEVICE_RESET__BANK0 0x0001
@@ -29,7 +29,7 @@
29#define TRANSFER_SPARE_REG__FLAG 0x0001 29#define TRANSFER_SPARE_REG__FLAG 0x0001
30 30
31#define LOAD_WAIT_CNT 0x20 31#define LOAD_WAIT_CNT 0x20
32#define LOAD_WAIT_CNT__VALUE 0xffff 32#define LOAD_WAIT_CNT__VALUE 0xffff
33 33
34#define PROGRAM_WAIT_CNT 0x30 34#define PROGRAM_WAIT_CNT 0x30
35#define PROGRAM_WAIT_CNT__VALUE 0xffff 35#define PROGRAM_WAIT_CNT__VALUE 0xffff
@@ -83,7 +83,7 @@
83#define RE_2_WE 0x120 83#define RE_2_WE 0x120
84#define RE_2_WE__VALUE 0x003f 84#define RE_2_WE__VALUE 0x003f
85 85
86#define ACC_CLKS 0x130 86#define ACC_CLKS 0x130
87#define ACC_CLKS__VALUE 0x000f 87#define ACC_CLKS__VALUE 0x000f
88 88
89#define NUMBER_OF_PLANES 0x140 89#define NUMBER_OF_PLANES 0x140
@@ -140,7 +140,7 @@
140#define DEVICES_CONNECTED 0x250 140#define DEVICES_CONNECTED 0x250
141#define DEVICES_CONNECTED__VALUE 0x0007 141#define DEVICES_CONNECTED__VALUE 0x0007
142 142
143#define DIE_MASK 0x260 143#define DIE_MASK 0x260
144#define DIE_MASK__VALUE 0x00ff 144#define DIE_MASK__VALUE 0x00ff
145 145
146#define FIRST_BLOCK_OF_NEXT_PLANE 0x270 146#define FIRST_BLOCK_OF_NEXT_PLANE 0x270
@@ -152,7 +152,7 @@
152#define RE_2_RE 0x290 152#define RE_2_RE 0x290
153#define RE_2_RE__VALUE 0x003f 153#define RE_2_RE__VALUE 0x003f
154 154
155#define MANUFACTURER_ID 0x300 155#define MANUFACTURER_ID 0x300
156#define MANUFACTURER_ID__VALUE 0x00ff 156#define MANUFACTURER_ID__VALUE 0x00ff
157 157
158#define DEVICE_ID 0x310 158#define DEVICE_ID 0x310
@@ -173,13 +173,13 @@
173#define LOGICAL_PAGE_SPARE_SIZE 0x360 173#define LOGICAL_PAGE_SPARE_SIZE 0x360
174#define LOGICAL_PAGE_SPARE_SIZE__VALUE 0xffff 174#define LOGICAL_PAGE_SPARE_SIZE__VALUE 0xffff
175 175
176#define REVISION 0x370 176#define REVISION 0x370
177#define REVISION__VALUE 0xffff 177#define REVISION__VALUE 0xffff
178 178
179#define ONFI_DEVICE_FEATURES 0x380 179#define ONFI_DEVICE_FEATURES 0x380
180#define ONFI_DEVICE_FEATURES__VALUE 0x003f 180#define ONFI_DEVICE_FEATURES__VALUE 0x003f
181 181
182#define ONFI_OPTIONAL_COMMANDS 0x390 182#define ONFI_OPTIONAL_COMMANDS 0x390
183#define ONFI_OPTIONAL_COMMANDS__VALUE 0x003f 183#define ONFI_OPTIONAL_COMMANDS__VALUE 0x003f
184 184
185#define ONFI_TIMING_MODE 0x3a0 185#define ONFI_TIMING_MODE 0x3a0
@@ -201,12 +201,12 @@
201#define FEATURES 0x3f0 201#define FEATURES 0x3f0
202#define FEATURES__N_BANKS 0x0003 202#define FEATURES__N_BANKS 0x0003
203#define FEATURES__ECC_MAX_ERR 0x003c 203#define FEATURES__ECC_MAX_ERR 0x003c
204#define FEATURES__DMA 0x0040 204#define FEATURES__DMA 0x0040
205#define FEATURES__CMD_DMA 0x0080 205#define FEATURES__CMD_DMA 0x0080
206#define FEATURES__PARTITION 0x0100 206#define FEATURES__PARTITION 0x0100
207#define FEATURES__XDMA_SIDEBAND 0x0200 207#define FEATURES__XDMA_SIDEBAND 0x0200
208#define FEATURES__GPREG 0x0400 208#define FEATURES__GPREG 0x0400
209#define FEATURES__INDEX_ADDR 0x0800 209#define FEATURES__INDEX_ADDR 0x0800
210 210
211#define TRANSFER_MODE 0x400 211#define TRANSFER_MODE 0x400
212#define TRANSFER_MODE__VALUE 0x0003 212#define TRANSFER_MODE__VALUE 0x0003
@@ -235,12 +235,12 @@
235#define INTR_EN0__DMA_CMD_COMP 0x0004 235#define INTR_EN0__DMA_CMD_COMP 0x0004
236#define INTR_EN0__TIME_OUT 0x0008 236#define INTR_EN0__TIME_OUT 0x0008
237#define INTR_EN0__PROGRAM_FAIL 0x0010 237#define INTR_EN0__PROGRAM_FAIL 0x0010
238#define INTR_EN0__ERASE_FAIL 0x0020 238#define INTR_EN0__ERASE_FAIL 0x0020
239#define INTR_EN0__LOAD_COMP 0x0040 239#define INTR_EN0__LOAD_COMP 0x0040
240#define INTR_EN0__PROGRAM_COMP 0x0080 240#define INTR_EN0__PROGRAM_COMP 0x0080
241#define INTR_EN0__ERASE_COMP 0x0100 241#define INTR_EN0__ERASE_COMP 0x0100
242#define INTR_EN0__PIPE_CPYBCK_CMD_COMP 0x0200 242#define INTR_EN0__PIPE_CPYBCK_CMD_COMP 0x0200
243#define INTR_EN0__LOCKED_BLK 0x0400 243#define INTR_EN0__LOCKED_BLK 0x0400
244#define INTR_EN0__UNSUP_CMD 0x0800 244#define INTR_EN0__UNSUP_CMD 0x0800
245#define INTR_EN0__INT_ACT 0x1000 245#define INTR_EN0__INT_ACT 0x1000
246#define INTR_EN0__RST_COMP 0x2000 246#define INTR_EN0__RST_COMP 0x2000
@@ -253,7 +253,7 @@
253#define ERR_PAGE_ADDR0 0x440 253#define ERR_PAGE_ADDR0 0x440
254#define ERR_PAGE_ADDR0__VALUE 0xffff 254#define ERR_PAGE_ADDR0__VALUE 0xffff
255 255
256#define ERR_BLOCK_ADDR0 0x450 256#define ERR_BLOCK_ADDR0 0x450
257#define ERR_BLOCK_ADDR0__VALUE 0xffff 257#define ERR_BLOCK_ADDR0__VALUE 0xffff
258 258
259#define INTR_STATUS1 0x460 259#define INTR_STATUS1 0x460
@@ -280,12 +280,12 @@
280#define INTR_EN1__DMA_CMD_COMP 0x0004 280#define INTR_EN1__DMA_CMD_COMP 0x0004
281#define INTR_EN1__TIME_OUT 0x0008 281#define INTR_EN1__TIME_OUT 0x0008
282#define INTR_EN1__PROGRAM_FAIL 0x0010 282#define INTR_EN1__PROGRAM_FAIL 0x0010
283#define INTR_EN1__ERASE_FAIL 0x0020 283#define INTR_EN1__ERASE_FAIL 0x0020
284#define INTR_EN1__LOAD_COMP 0x0040 284#define INTR_EN1__LOAD_COMP 0x0040
285#define INTR_EN1__PROGRAM_COMP 0x0080 285#define INTR_EN1__PROGRAM_COMP 0x0080
286#define INTR_EN1__ERASE_COMP 0x0100 286#define INTR_EN1__ERASE_COMP 0x0100
287#define INTR_EN1__PIPE_CPYBCK_CMD_COMP 0x0200 287#define INTR_EN1__PIPE_CPYBCK_CMD_COMP 0x0200
288#define INTR_EN1__LOCKED_BLK 0x0400 288#define INTR_EN1__LOCKED_BLK 0x0400
289#define INTR_EN1__UNSUP_CMD 0x0800 289#define INTR_EN1__UNSUP_CMD 0x0800
290#define INTR_EN1__INT_ACT 0x1000 290#define INTR_EN1__INT_ACT 0x1000
291#define INTR_EN1__RST_COMP 0x2000 291#define INTR_EN1__RST_COMP 0x2000
@@ -298,7 +298,7 @@
298#define ERR_PAGE_ADDR1 0x490 298#define ERR_PAGE_ADDR1 0x490
299#define ERR_PAGE_ADDR1__VALUE 0xffff 299#define ERR_PAGE_ADDR1__VALUE 0xffff
300 300
301#define ERR_BLOCK_ADDR1 0x4a0 301#define ERR_BLOCK_ADDR1 0x4a0
302#define ERR_BLOCK_ADDR1__VALUE 0xffff 302#define ERR_BLOCK_ADDR1__VALUE 0xffff
303 303
304#define INTR_STATUS2 0x4b0 304#define INTR_STATUS2 0x4b0
@@ -325,12 +325,12 @@
325#define INTR_EN2__DMA_CMD_COMP 0x0004 325#define INTR_EN2__DMA_CMD_COMP 0x0004
326#define INTR_EN2__TIME_OUT 0x0008 326#define INTR_EN2__TIME_OUT 0x0008
327#define INTR_EN2__PROGRAM_FAIL 0x0010 327#define INTR_EN2__PROGRAM_FAIL 0x0010
328#define INTR_EN2__ERASE_FAIL 0x0020 328#define INTR_EN2__ERASE_FAIL 0x0020
329#define INTR_EN2__LOAD_COMP 0x0040 329#define INTR_EN2__LOAD_COMP 0x0040
330#define INTR_EN2__PROGRAM_COMP 0x0080 330#define INTR_EN2__PROGRAM_COMP 0x0080
331#define INTR_EN2__ERASE_COMP 0x0100 331#define INTR_EN2__ERASE_COMP 0x0100
332#define INTR_EN2__PIPE_CPYBCK_CMD_COMP 0x0200 332#define INTR_EN2__PIPE_CPYBCK_CMD_COMP 0x0200
333#define INTR_EN2__LOCKED_BLK 0x0400 333#define INTR_EN2__LOCKED_BLK 0x0400
334#define INTR_EN2__UNSUP_CMD 0x0800 334#define INTR_EN2__UNSUP_CMD 0x0800
335#define INTR_EN2__INT_ACT 0x1000 335#define INTR_EN2__INT_ACT 0x1000
336#define INTR_EN2__RST_COMP 0x2000 336#define INTR_EN2__RST_COMP 0x2000
@@ -343,7 +343,7 @@
343#define ERR_PAGE_ADDR2 0x4e0 343#define ERR_PAGE_ADDR2 0x4e0
344#define ERR_PAGE_ADDR2__VALUE 0xffff 344#define ERR_PAGE_ADDR2__VALUE 0xffff
345 345
346#define ERR_BLOCK_ADDR2 0x4f0 346#define ERR_BLOCK_ADDR2 0x4f0
347#define ERR_BLOCK_ADDR2__VALUE 0xffff 347#define ERR_BLOCK_ADDR2__VALUE 0xffff
348 348
349#define INTR_STATUS3 0x500 349#define INTR_STATUS3 0x500
@@ -370,12 +370,12 @@
370#define INTR_EN3__DMA_CMD_COMP 0x0004 370#define INTR_EN3__DMA_CMD_COMP 0x0004
371#define INTR_EN3__TIME_OUT 0x0008 371#define INTR_EN3__TIME_OUT 0x0008
372#define INTR_EN3__PROGRAM_FAIL 0x0010 372#define INTR_EN3__PROGRAM_FAIL 0x0010
373#define INTR_EN3__ERASE_FAIL 0x0020 373#define INTR_EN3__ERASE_FAIL 0x0020
374#define INTR_EN3__LOAD_COMP 0x0040 374#define INTR_EN3__LOAD_COMP 0x0040
375#define INTR_EN3__PROGRAM_COMP 0x0080 375#define INTR_EN3__PROGRAM_COMP 0x0080
376#define INTR_EN3__ERASE_COMP 0x0100 376#define INTR_EN3__ERASE_COMP 0x0100
377#define INTR_EN3__PIPE_CPYBCK_CMD_COMP 0x0200 377#define INTR_EN3__PIPE_CPYBCK_CMD_COMP 0x0200
378#define INTR_EN3__LOCKED_BLK 0x0400 378#define INTR_EN3__LOCKED_BLK 0x0400
379#define INTR_EN3__UNSUP_CMD 0x0800 379#define INTR_EN3__UNSUP_CMD 0x0800
380#define INTR_EN3__INT_ACT 0x1000 380#define INTR_EN3__INT_ACT 0x1000
381#define INTR_EN3__RST_COMP 0x2000 381#define INTR_EN3__RST_COMP 0x2000
@@ -388,7 +388,7 @@
388#define ERR_PAGE_ADDR3 0x530 388#define ERR_PAGE_ADDR3 0x530
389#define ERR_PAGE_ADDR3__VALUE 0xffff 389#define ERR_PAGE_ADDR3__VALUE 0xffff
390 390
391#define ERR_BLOCK_ADDR3 0x540 391#define ERR_BLOCK_ADDR3 0x540
392#define ERR_BLOCK_ADDR3__VALUE 0xffff 392#define ERR_BLOCK_ADDR3__VALUE 0xffff
393 393
394#define DATA_INTR 0x550 394#define DATA_INTR 0x550
@@ -412,9 +412,9 @@
412#define GPREG_3__VALUE 0xffff 412#define GPREG_3__VALUE 0xffff
413 413
414#define ECC_THRESHOLD 0x600 414#define ECC_THRESHOLD 0x600
415#define ECC_THRESHOLD__VALUE 0x03ff 415#define ECC_THRESHOLD__VALUE 0x03ff
416 416
417#define ECC_ERROR_BLOCK_ADDRESS 0x610 417#define ECC_ERROR_BLOCK_ADDRESS 0x610
418#define ECC_ERROR_BLOCK_ADDRESS__VALUE 0xffff 418#define ECC_ERROR_BLOCK_ADDRESS__VALUE 0xffff
419 419
420#define ECC_ERROR_PAGE_ADDRESS 0x620 420#define ECC_ERROR_PAGE_ADDRESS 0x620
@@ -466,7 +466,7 @@
466#define CHNL_ACTIVE__CHANNEL3 0x0008 466#define CHNL_ACTIVE__CHANNEL3 0x0008
467 467
468#define ACTIVE_SRC_ID 0x800 468#define ACTIVE_SRC_ID 0x800
469#define ACTIVE_SRC_ID__VALUE 0x00ff 469#define ACTIVE_SRC_ID__VALUE 0x00ff
470 470
471#define PTN_INTR 0x810 471#define PTN_INTR 0x810
472#define PTN_INTR__CONFIG_ERROR 0x0001 472#define PTN_INTR__CONFIG_ERROR 0x0001
@@ -485,7 +485,7 @@
485#define PTN_INTR_EN__REG_ACCESS_ERROR 0x0020 485#define PTN_INTR_EN__REG_ACCESS_ERROR 0x0020
486 486
487#define PERM_SRC_ID_0 0x830 487#define PERM_SRC_ID_0 0x830
488#define PERM_SRC_ID_0__SRCID 0x00ff 488#define PERM_SRC_ID_0__SRCID 0x00ff
489#define PERM_SRC_ID_0__DIRECT_ACCESS_ACTIVE 0x0800 489#define PERM_SRC_ID_0__DIRECT_ACCESS_ACTIVE 0x0800
490#define PERM_SRC_ID_0__WRITE_ACTIVE 0x2000 490#define PERM_SRC_ID_0__WRITE_ACTIVE 0x2000
491#define PERM_SRC_ID_0__READ_ACTIVE 0x4000 491#define PERM_SRC_ID_0__READ_ACTIVE 0x4000
@@ -502,7 +502,7 @@
502#define MIN_MAX_BANK_0__MAX_VALUE 0x000c 502#define MIN_MAX_BANK_0__MAX_VALUE 0x000c
503 503
504#define PERM_SRC_ID_1 0x870 504#define PERM_SRC_ID_1 0x870
505#define PERM_SRC_ID_1__SRCID 0x00ff 505#define PERM_SRC_ID_1__SRCID 0x00ff
506#define PERM_SRC_ID_1__DIRECT_ACCESS_ACTIVE 0x0800 506#define PERM_SRC_ID_1__DIRECT_ACCESS_ACTIVE 0x0800
507#define PERM_SRC_ID_1__WRITE_ACTIVE 0x2000 507#define PERM_SRC_ID_1__WRITE_ACTIVE 0x2000
508#define PERM_SRC_ID_1__READ_ACTIVE 0x4000 508#define PERM_SRC_ID_1__READ_ACTIVE 0x4000
@@ -519,7 +519,7 @@
519#define MIN_MAX_BANK_1__MAX_VALUE 0x000c 519#define MIN_MAX_BANK_1__MAX_VALUE 0x000c
520 520
521#define PERM_SRC_ID_2 0x8b0 521#define PERM_SRC_ID_2 0x8b0
522#define PERM_SRC_ID_2__SRCID 0x00ff 522#define PERM_SRC_ID_2__SRCID 0x00ff
523#define PERM_SRC_ID_2__DIRECT_ACCESS_ACTIVE 0x0800 523#define PERM_SRC_ID_2__DIRECT_ACCESS_ACTIVE 0x0800
524#define PERM_SRC_ID_2__WRITE_ACTIVE 0x2000 524#define PERM_SRC_ID_2__WRITE_ACTIVE 0x2000
525#define PERM_SRC_ID_2__READ_ACTIVE 0x4000 525#define PERM_SRC_ID_2__READ_ACTIVE 0x4000
@@ -536,7 +536,7 @@
536#define MIN_MAX_BANK_2__MAX_VALUE 0x000c 536#define MIN_MAX_BANK_2__MAX_VALUE 0x000c
537 537
538#define PERM_SRC_ID_3 0x8f0 538#define PERM_SRC_ID_3 0x8f0
539#define PERM_SRC_ID_3__SRCID 0x00ff 539#define PERM_SRC_ID_3__SRCID 0x00ff
540#define PERM_SRC_ID_3__DIRECT_ACCESS_ACTIVE 0x0800 540#define PERM_SRC_ID_3__DIRECT_ACCESS_ACTIVE 0x0800
541#define PERM_SRC_ID_3__WRITE_ACTIVE 0x2000 541#define PERM_SRC_ID_3__WRITE_ACTIVE 0x2000
542#define PERM_SRC_ID_3__READ_ACTIVE 0x4000 542#define PERM_SRC_ID_3__READ_ACTIVE 0x4000
@@ -553,7 +553,7 @@
553#define MIN_MAX_BANK_3__MAX_VALUE 0x000c 553#define MIN_MAX_BANK_3__MAX_VALUE 0x000c
554 554
555#define PERM_SRC_ID_4 0x930 555#define PERM_SRC_ID_4 0x930
556#define PERM_SRC_ID_4__SRCID 0x00ff 556#define PERM_SRC_ID_4__SRCID 0x00ff
557#define PERM_SRC_ID_4__DIRECT_ACCESS_ACTIVE 0x0800 557#define PERM_SRC_ID_4__DIRECT_ACCESS_ACTIVE 0x0800
558#define PERM_SRC_ID_4__WRITE_ACTIVE 0x2000 558#define PERM_SRC_ID_4__WRITE_ACTIVE 0x2000
559#define PERM_SRC_ID_4__READ_ACTIVE 0x4000 559#define PERM_SRC_ID_4__READ_ACTIVE 0x4000
@@ -570,7 +570,7 @@
570#define MIN_MAX_BANK_4__MAX_VALUE 0x000c 570#define MIN_MAX_BANK_4__MAX_VALUE 0x000c
571 571
572#define PERM_SRC_ID_5 0x970 572#define PERM_SRC_ID_5 0x970
573#define PERM_SRC_ID_5__SRCID 0x00ff 573#define PERM_SRC_ID_5__SRCID 0x00ff
574#define PERM_SRC_ID_5__DIRECT_ACCESS_ACTIVE 0x0800 574#define PERM_SRC_ID_5__DIRECT_ACCESS_ACTIVE 0x0800
575#define PERM_SRC_ID_5__WRITE_ACTIVE 0x2000 575#define PERM_SRC_ID_5__WRITE_ACTIVE 0x2000
576#define PERM_SRC_ID_5__READ_ACTIVE 0x4000 576#define PERM_SRC_ID_5__READ_ACTIVE 0x4000
@@ -587,7 +587,7 @@
587#define MIN_MAX_BANK_5__MAX_VALUE 0x000c 587#define MIN_MAX_BANK_5__MAX_VALUE 0x000c
588 588
589#define PERM_SRC_ID_6 0x9b0 589#define PERM_SRC_ID_6 0x9b0
590#define PERM_SRC_ID_6__SRCID 0x00ff 590#define PERM_SRC_ID_6__SRCID 0x00ff
591#define PERM_SRC_ID_6__DIRECT_ACCESS_ACTIVE 0x0800 591#define PERM_SRC_ID_6__DIRECT_ACCESS_ACTIVE 0x0800
592#define PERM_SRC_ID_6__WRITE_ACTIVE 0x2000 592#define PERM_SRC_ID_6__WRITE_ACTIVE 0x2000
593#define PERM_SRC_ID_6__READ_ACTIVE 0x4000 593#define PERM_SRC_ID_6__READ_ACTIVE 0x4000
@@ -604,7 +604,7 @@
604#define MIN_MAX_BANK_6__MAX_VALUE 0x000c 604#define MIN_MAX_BANK_6__MAX_VALUE 0x000c
605 605
606#define PERM_SRC_ID_7 0x9f0 606#define PERM_SRC_ID_7 0x9f0
607#define PERM_SRC_ID_7__SRCID 0x00ff 607#define PERM_SRC_ID_7__SRCID 0x00ff
608#define PERM_SRC_ID_7__DIRECT_ACCESS_ACTIVE 0x0800 608#define PERM_SRC_ID_7__DIRECT_ACCESS_ACTIVE 0x0800
609#define PERM_SRC_ID_7__WRITE_ACTIVE 0x2000 609#define PERM_SRC_ID_7__WRITE_ACTIVE 0x2000
610#define PERM_SRC_ID_7__READ_ACTIVE 0x4000 610#define PERM_SRC_ID_7__READ_ACTIVE 0x4000
@@ -620,47 +620,6 @@
620#define MIN_MAX_BANK_7__MIN_VALUE 0x0003 620#define MIN_MAX_BANK_7__MIN_VALUE 0x0003
621#define MIN_MAX_BANK_7__MAX_VALUE 0x000c 621#define MIN_MAX_BANK_7__MAX_VALUE 0x000c
622 622
623/* flash.h */
624struct device_info_tag {
625 uint16_t wDeviceMaker;
626 uint16_t wDeviceID;
627 uint8_t bDeviceParam0;
628 uint8_t bDeviceParam1;
629 uint8_t bDeviceParam2;
630 uint32_t wDeviceType;
631 uint32_t wSpectraStartBlock;
632 uint32_t wSpectraEndBlock;
633 uint32_t wTotalBlocks;
634 uint16_t wPagesPerBlock;
635 uint16_t wPageSize;
636 uint16_t wPageDataSize;
637 uint16_t wPageSpareSize;
638 uint16_t wNumPageSpareFlag;
639 uint16_t wECCBytesPerSector;
640 uint32_t wBlockSize;
641 uint32_t wBlockDataSize;
642 uint32_t wDataBlockNum;
643 uint8_t bPlaneNum;
644 uint16_t wDeviceMainAreaSize;
645 uint16_t wDeviceSpareAreaSize;
646 uint16_t wDevicesConnected;
647 uint16_t wDeviceWidth;
648 uint16_t wHWRevision;
649 uint16_t wHWFeatures;
650
651 uint16_t wONFIDevFeatures;
652 uint16_t wONFIOptCommands;
653 uint16_t wONFITimingMode;
654 uint16_t wONFIPgmCacheTimingMode;
655
656 uint16_t MLCDevice;
657 uint16_t wSpareSkipBytes;
658
659 uint8_t nBitsInPageNumber;
660 uint8_t nBitsInPageDataSize;
661 uint8_t nBitsInBlockDataSize;
662};
663
664/* ffsdefs.h */ 623/* ffsdefs.h */
665#define CLEAR 0 /*use this to clear a field instead of "fail"*/ 624#define CLEAR 0 /*use this to clear a field instead of "fail"*/
666#define SET 1 /*use this to set a field instead of "pass"*/ 625#define SET 1 /*use this to set a field instead of "pass"*/
@@ -676,24 +635,6 @@ struct device_info_tag {
676#define CLK_X 5 635#define CLK_X 5
677#define CLK_MULTI 4 636#define CLK_MULTI 4
678 637
679/* ffsport.h */
680#define VERBOSE 1
681
682#define NAND_DBG_WARN 1
683#define NAND_DBG_DEBUG 2
684#define NAND_DBG_TRACE 3
685
686#ifdef VERBOSE
687#define nand_dbg_print(level, args...) \
688 do { \
689 if (level <= nand_debug_level) \
690 printk(KERN_ALERT args); \
691 } while (0)
692#else
693#define nand_dbg_print(level, args...)
694#endif
695
696
697/* spectraswconfig.h */ 638/* spectraswconfig.h */
698#define CMD_DMA 0 639#define CMD_DMA 0
699 640
@@ -772,10 +713,9 @@ struct device_info_tag {
772#define ECC_SECTOR_SIZE 512 713#define ECC_SECTOR_SIZE 512
773#define LLD_MAX_FLASH_BANKS 4 714#define LLD_MAX_FLASH_BANKS 4
774 715
775#define DENALI_BUF_SIZE NAND_MAX_PAGESIZE + NAND_MAX_OOBSIZE 716#define DENALI_BUF_SIZE (NAND_MAX_PAGESIZE + NAND_MAX_OOBSIZE)
776 717
777struct nand_buf 718struct nand_buf {
778{
779 int head; 719 int head;
780 int tail; 720 int tail;
781 uint8_t buf[DENALI_BUF_SIZE]; 721 uint8_t buf[DENALI_BUF_SIZE];
@@ -788,7 +728,6 @@ struct nand_buf
788struct denali_nand_info { 728struct denali_nand_info {
789 struct mtd_info mtd; 729 struct mtd_info mtd;
790 struct nand_chip nand; 730 struct nand_chip nand;
791 struct device_info_tag dev_info;
792 int flash_bank; /* currently selected chip */ 731 int flash_bank; /* currently selected chip */
793 int status; 732 int status;
794 int platform; 733 int platform;
@@ -806,11 +745,12 @@ struct denali_nand_info {
806 uint32_t irq_status; 745 uint32_t irq_status;
807 int irq_debug_array[32]; 746 int irq_debug_array[32];
808 int idx; 747 int idx;
809};
810 748
811static uint16_t NAND_Flash_Reset(struct denali_nand_info *denali); 749 uint32_t devnum; /* represent how many nands connected */
812static uint16_t NAND_Read_Device_ID(struct denali_nand_info *denali); 750 uint32_t fwblks; /* represent how many blocks FW used */
813static void NAND_LLD_Enable_Disable_Interrupts(struct denali_nand_info *denali, uint16_t INT_ENABLE); 751 uint32_t totalblks;
752 uint32_t blksperchip;
753 uint32_t bbtskipbytes;
754};
814 755
815#endif /*_LLD_NAND_*/ 756#endif /*_LLD_NAND_*/
816
diff --git a/drivers/mtd/nand/diskonchip.c b/drivers/mtd/nand/diskonchip.c
index 47067bc98248..b7f8de7b2780 100644
--- a/drivers/mtd/nand/diskonchip.c
+++ b/drivers/mtd/nand/diskonchip.c
@@ -29,7 +29,6 @@
29#include <linux/mtd/mtd.h> 29#include <linux/mtd/mtd.h>
30#include <linux/mtd/nand.h> 30#include <linux/mtd/nand.h>
31#include <linux/mtd/doc2000.h> 31#include <linux/mtd/doc2000.h>
32#include <linux/mtd/compatmac.h>
33#include <linux/mtd/partitions.h> 32#include <linux/mtd/partitions.h>
34#include <linux/mtd/inftl.h> 33#include <linux/mtd/inftl.h>
35 34
@@ -146,6 +145,7 @@ static int doc_ecc_decode(struct rs_control *rs, uint8_t *data, uint8_t *ecc)
146 uint8_t parity; 145 uint8_t parity;
147 uint16_t ds[4], s[5], tmp, errval[8], syn[4]; 146 uint16_t ds[4], s[5], tmp, errval[8], syn[4];
148 147
148 memset(syn, 0, sizeof(syn));
149 /* Convert the ecc bytes into words */ 149 /* Convert the ecc bytes into words */
150 ds[0] = ((ecc[4] & 0xff) >> 0) | ((ecc[5] & 0x03) << 8); 150 ds[0] = ((ecc[4] & 0xff) >> 0) | ((ecc[5] & 0x03) << 8);
151 ds[1] = ((ecc[5] & 0xfc) >> 2) | ((ecc[2] & 0x0f) << 6); 151 ds[1] = ((ecc[5] & 0xfc) >> 2) | ((ecc[2] & 0x0f) << 6);
@@ -169,9 +169,9 @@ static int doc_ecc_decode(struct rs_control *rs, uint8_t *data, uint8_t *ecc)
169 s[i] ^= rs->alpha_to[rs_modnn(rs, tmp + (FCR + i) * j)]; 169 s[i] ^= rs->alpha_to[rs_modnn(rs, tmp + (FCR + i) * j)];
170 } 170 }
171 171
172 /* Calc s[i] = s[i] / alpha^(v + i) */ 172 /* Calc syn[i] = s[i] / alpha^(v + i) */
173 for (i = 0; i < NROOTS; i++) { 173 for (i = 0; i < NROOTS; i++) {
174 if (syn[i]) 174 if (s[i])
175 syn[i] = rs_modnn(rs, rs->index_of[s[i]] + (NN - FCR - i)); 175 syn[i] = rs_modnn(rs, rs->index_of[s[i]] + (NN - FCR - i));
176 } 176 }
177 /* Call the decoder library */ 177 /* Call the decoder library */
diff --git a/drivers/mtd/nand/fsl_elbc_nand.c b/drivers/mtd/nand/fsl_elbc_nand.c
index 5084cc517944..80de0bff6c3a 100644
--- a/drivers/mtd/nand/fsl_elbc_nand.c
+++ b/drivers/mtd/nand/fsl_elbc_nand.c
@@ -958,7 +958,7 @@ static int __devinit fsl_elbc_ctrl_init(struct fsl_elbc_ctrl *ctrl)
958 return 0; 958 return 0;
959} 959}
960 960
961static int fsl_elbc_ctrl_remove(struct of_device *ofdev) 961static int fsl_elbc_ctrl_remove(struct platform_device *ofdev)
962{ 962{
963 struct fsl_elbc_ctrl *ctrl = dev_get_drvdata(&ofdev->dev); 963 struct fsl_elbc_ctrl *ctrl = dev_get_drvdata(&ofdev->dev);
964 int i; 964 int i;
@@ -1013,7 +1013,7 @@ static irqreturn_t fsl_elbc_ctrl_irq(int irqno, void *data)
1013 * in the chip probe function. 1013 * in the chip probe function.
1014*/ 1014*/
1015 1015
1016static int __devinit fsl_elbc_ctrl_probe(struct of_device *ofdev, 1016static int __devinit fsl_elbc_ctrl_probe(struct platform_device *ofdev,
1017 const struct of_device_id *match) 1017 const struct of_device_id *match)
1018{ 1018{
1019 struct device_node *child; 1019 struct device_node *child;
diff --git a/drivers/mtd/nand/fsl_upm.c b/drivers/mtd/nand/fsl_upm.c
index 1312eda57ba6..4eff8b25e5af 100644
--- a/drivers/mtd/nand/fsl_upm.c
+++ b/drivers/mtd/nand/fsl_upm.c
@@ -217,7 +217,7 @@ err:
217 return ret; 217 return ret;
218} 218}
219 219
220static int __devinit fun_probe(struct of_device *ofdev, 220static int __devinit fun_probe(struct platform_device *ofdev,
221 const struct of_device_id *ofid) 221 const struct of_device_id *ofid)
222{ 222{
223 struct fsl_upm_nand *fun; 223 struct fsl_upm_nand *fun;
@@ -335,7 +335,7 @@ err1:
335 return ret; 335 return ret;
336} 336}
337 337
338static int __devexit fun_remove(struct of_device *ofdev) 338static int __devexit fun_remove(struct platform_device *ofdev)
339{ 339{
340 struct fsl_upm_nand *fun = dev_get_drvdata(&ofdev->dev); 340 struct fsl_upm_nand *fun = dev_get_drvdata(&ofdev->dev);
341 int i; 341 int i;
diff --git a/drivers/mtd/nand/mpc5121_nfc.c b/drivers/mtd/nand/mpc5121_nfc.c
index 0a130dcaa129..df0c1da4ff49 100644
--- a/drivers/mtd/nand/mpc5121_nfc.c
+++ b/drivers/mtd/nand/mpc5121_nfc.c
@@ -647,7 +647,7 @@ static void mpc5121_nfc_free(struct device *dev, struct mtd_info *mtd)
647 iounmap(prv->csreg); 647 iounmap(prv->csreg);
648} 648}
649 649
650static int __devinit mpc5121_nfc_probe(struct of_device *op, 650static int __devinit mpc5121_nfc_probe(struct platform_device *op,
651 const struct of_device_id *match) 651 const struct of_device_id *match)
652{ 652{
653 struct device_node *rootnode, *dn = op->dev.of_node; 653 struct device_node *rootnode, *dn = op->dev.of_node;
@@ -869,7 +869,7 @@ error:
869 return retval; 869 return retval;
870} 870}
871 871
872static int __devexit mpc5121_nfc_remove(struct of_device *op) 872static int __devexit mpc5121_nfc_remove(struct platform_device *op)
873{ 873{
874 struct device *dev = &op->dev; 874 struct device *dev = &op->dev;
875 struct mtd_info *mtd = dev_get_drvdata(dev); 875 struct mtd_info *mtd = dev_get_drvdata(dev);
diff --git a/drivers/mtd/nand/mxc_nand.c b/drivers/mtd/nand/mxc_nand.c
index 0d76b169482f..fcf8ceb277d4 100644
--- a/drivers/mtd/nand/mxc_nand.c
+++ b/drivers/mtd/nand/mxc_nand.c
@@ -39,60 +39,96 @@
39 39
40#define nfc_is_v21() (cpu_is_mx25() || cpu_is_mx35()) 40#define nfc_is_v21() (cpu_is_mx25() || cpu_is_mx35())
41#define nfc_is_v1() (cpu_is_mx31() || cpu_is_mx27() || cpu_is_mx21()) 41#define nfc_is_v1() (cpu_is_mx31() || cpu_is_mx27() || cpu_is_mx21())
42#define nfc_is_v3_2() cpu_is_mx51()
43#define nfc_is_v3() nfc_is_v3_2()
42 44
43/* Addresses for NFC registers */ 45/* Addresses for NFC registers */
44#define NFC_BUF_SIZE 0xE00 46#define NFC_V1_V2_BUF_SIZE (host->regs + 0x00)
45#define NFC_BUF_ADDR 0xE04 47#define NFC_V1_V2_BUF_ADDR (host->regs + 0x04)
46#define NFC_FLASH_ADDR 0xE06 48#define NFC_V1_V2_FLASH_ADDR (host->regs + 0x06)
47#define NFC_FLASH_CMD 0xE08 49#define NFC_V1_V2_FLASH_CMD (host->regs + 0x08)
48#define NFC_CONFIG 0xE0A 50#define NFC_V1_V2_CONFIG (host->regs + 0x0a)
49#define NFC_ECC_STATUS_RESULT 0xE0C 51#define NFC_V1_V2_ECC_STATUS_RESULT (host->regs + 0x0c)
50#define NFC_RSLTMAIN_AREA 0xE0E 52#define NFC_V1_V2_RSLTMAIN_AREA (host->regs + 0x0e)
51#define NFC_RSLTSPARE_AREA 0xE10 53#define NFC_V1_V2_RSLTSPARE_AREA (host->regs + 0x10)
52#define NFC_WRPROT 0xE12 54#define NFC_V1_V2_WRPROT (host->regs + 0x12)
53#define NFC_V1_UNLOCKSTART_BLKADDR 0xe14 55#define NFC_V1_UNLOCKSTART_BLKADDR (host->regs + 0x14)
54#define NFC_V1_UNLOCKEND_BLKADDR 0xe16 56#define NFC_V1_UNLOCKEND_BLKADDR (host->regs + 0x16)
55#define NFC_V21_UNLOCKSTART_BLKADDR 0xe20 57#define NFC_V21_UNLOCKSTART_BLKADDR (host->regs + 0x20)
56#define NFC_V21_UNLOCKEND_BLKADDR 0xe22 58#define NFC_V21_UNLOCKEND_BLKADDR (host->regs + 0x22)
57#define NFC_NF_WRPRST 0xE18 59#define NFC_V1_V2_NF_WRPRST (host->regs + 0x18)
58#define NFC_CONFIG1 0xE1A 60#define NFC_V1_V2_CONFIG1 (host->regs + 0x1a)
59#define NFC_CONFIG2 0xE1C 61#define NFC_V1_V2_CONFIG2 (host->regs + 0x1c)
60 62
61/* Set INT to 0, FCMD to 1, rest to 0 in NFC_CONFIG2 Register 63#define NFC_V2_CONFIG1_ECC_MODE_4 (1 << 0)
62 * for Command operation */ 64#define NFC_V1_V2_CONFIG1_SP_EN (1 << 2)
63#define NFC_CMD 0x1 65#define NFC_V1_V2_CONFIG1_ECC_EN (1 << 3)
64 66#define NFC_V1_V2_CONFIG1_INT_MSK (1 << 4)
65/* Set INT to 0, FADD to 1, rest to 0 in NFC_CONFIG2 Register 67#define NFC_V1_V2_CONFIG1_BIG (1 << 5)
66 * for Address operation */ 68#define NFC_V1_V2_CONFIG1_RST (1 << 6)
67#define NFC_ADDR 0x2 69#define NFC_V1_V2_CONFIG1_CE (1 << 7)
68 70#define NFC_V1_V2_CONFIG1_ONE_CYCLE (1 << 8)
69/* Set INT to 0, FDI to 1, rest to 0 in NFC_CONFIG2 Register 71
70 * for Input operation */ 72#define NFC_V1_V2_CONFIG2_INT (1 << 15)
71#define NFC_INPUT 0x4 73
72 74/*
73/* Set INT to 0, FDO to 001, rest to 0 in NFC_CONFIG2 Register 75 * Operation modes for the NFC. Valid for v1, v2 and v3
74 * for Data Output operation */ 76 * type controllers.
75#define NFC_OUTPUT 0x8 77 */
76 78#define NFC_CMD (1 << 0)
77/* Set INT to 0, FD0 to 010, rest to 0 in NFC_CONFIG2 Register 79#define NFC_ADDR (1 << 1)
78 * for Read ID operation */ 80#define NFC_INPUT (1 << 2)
79#define NFC_ID 0x10 81#define NFC_OUTPUT (1 << 3)
80 82#define NFC_ID (1 << 4)
81/* Set INT to 0, FDO to 100, rest to 0 in NFC_CONFIG2 Register 83#define NFC_STATUS (1 << 5)
82 * for Read Status operation */ 84
83#define NFC_STATUS 0x20 85#define NFC_V3_FLASH_CMD (host->regs_axi + 0x00)
84 86#define NFC_V3_FLASH_ADDR0 (host->regs_axi + 0x04)
85/* Set INT to 1, rest to 0 in NFC_CONFIG2 Register for Read 87
86 * Status operation */ 88#define NFC_V3_CONFIG1 (host->regs_axi + 0x34)
87#define NFC_INT 0x8000 89#define NFC_V3_CONFIG1_SP_EN (1 << 0)
88 90#define NFC_V3_CONFIG1_RBA(x) (((x) & 0x7 ) << 4)
89#define NFC_SP_EN (1 << 2) 91
90#define NFC_ECC_EN (1 << 3) 92#define NFC_V3_ECC_STATUS_RESULT (host->regs_axi + 0x38)
91#define NFC_INT_MSK (1 << 4) 93
92#define NFC_BIG (1 << 5) 94#define NFC_V3_LAUNCH (host->regs_axi + 0x40)
93#define NFC_RST (1 << 6) 95
94#define NFC_CE (1 << 7) 96#define NFC_V3_WRPROT (host->regs_ip + 0x0)
95#define NFC_ONE_CYCLE (1 << 8) 97#define NFC_V3_WRPROT_LOCK_TIGHT (1 << 0)
98#define NFC_V3_WRPROT_LOCK (1 << 1)
99#define NFC_V3_WRPROT_UNLOCK (1 << 2)
100#define NFC_V3_WRPROT_BLS_UNLOCK (2 << 6)
101
102#define NFC_V3_WRPROT_UNLOCK_BLK_ADD0 (host->regs_ip + 0x04)
103
104#define NFC_V3_CONFIG2 (host->regs_ip + 0x24)
105#define NFC_V3_CONFIG2_PS_512 (0 << 0)
106#define NFC_V3_CONFIG2_PS_2048 (1 << 0)
107#define NFC_V3_CONFIG2_PS_4096 (2 << 0)
108#define NFC_V3_CONFIG2_ONE_CYCLE (1 << 2)
109#define NFC_V3_CONFIG2_ECC_EN (1 << 3)
110#define NFC_V3_CONFIG2_2CMD_PHASES (1 << 4)
111#define NFC_V3_CONFIG2_NUM_ADDR_PHASE0 (1 << 5)
112#define NFC_V3_CONFIG2_ECC_MODE_8 (1 << 6)
113#define NFC_V3_CONFIG2_PPB(x) (((x) & 0x3) << 7)
114#define NFC_V3_CONFIG2_NUM_ADDR_PHASE1(x) (((x) & 0x3) << 12)
115#define NFC_V3_CONFIG2_INT_MSK (1 << 15)
116#define NFC_V3_CONFIG2_ST_CMD(x) (((x) & 0xff) << 24)
117#define NFC_V3_CONFIG2_SPAS(x) (((x) & 0xff) << 16)
118
119#define NFC_V3_CONFIG3 (host->regs_ip + 0x28)
120#define NFC_V3_CONFIG3_ADD_OP(x) (((x) & 0x3) << 0)
121#define NFC_V3_CONFIG3_FW8 (1 << 3)
122#define NFC_V3_CONFIG3_SBB(x) (((x) & 0x7) << 8)
123#define NFC_V3_CONFIG3_NUM_OF_DEVICES(x) (((x) & 0x7) << 12)
124#define NFC_V3_CONFIG3_RBB_MODE (1 << 15)
125#define NFC_V3_CONFIG3_NO_SDMA (1 << 20)
126
127#define NFC_V3_IPC (host->regs_ip + 0x2C)
128#define NFC_V3_IPC_CREQ (1 << 0)
129#define NFC_V3_IPC_INT (1 << 31)
130
131#define NFC_V3_DELAY_LINE (host->regs_ip + 0x34)
96 132
97struct mxc_nand_host { 133struct mxc_nand_host {
98 struct mtd_info mtd; 134 struct mtd_info mtd;
@@ -102,20 +138,30 @@ struct mxc_nand_host {
102 138
103 void *spare0; 139 void *spare0;
104 void *main_area0; 140 void *main_area0;
105 void *main_area1;
106 141
107 void __iomem *base; 142 void __iomem *base;
108 void __iomem *regs; 143 void __iomem *regs;
144 void __iomem *regs_axi;
145 void __iomem *regs_ip;
109 int status_request; 146 int status_request;
110 struct clk *clk; 147 struct clk *clk;
111 int clk_act; 148 int clk_act;
112 int irq; 149 int irq;
150 int eccsize;
113 151
114 wait_queue_head_t irq_waitq; 152 wait_queue_head_t irq_waitq;
115 153
116 uint8_t *data_buf; 154 uint8_t *data_buf;
117 unsigned int buf_start; 155 unsigned int buf_start;
118 int spare_len; 156 int spare_len;
157
158 void (*preset)(struct mtd_info *);
159 void (*send_cmd)(struct mxc_nand_host *, uint16_t, int);
160 void (*send_addr)(struct mxc_nand_host *, uint16_t, int);
161 void (*send_page)(struct mtd_info *, unsigned int);
162 void (*send_read_id)(struct mxc_nand_host *);
163 uint16_t (*get_dev_status)(struct mxc_nand_host *);
164 int (*check_int)(struct mxc_nand_host *);
119}; 165};
120 166
121/* OOB placement block for use with hardware ecc generation */ 167/* OOB placement block for use with hardware ecc generation */
@@ -175,34 +221,52 @@ static irqreturn_t mxc_nfc_irq(int irq, void *dev_id)
175 return IRQ_HANDLED; 221 return IRQ_HANDLED;
176} 222}
177 223
224static int check_int_v3(struct mxc_nand_host *host)
225{
226 uint32_t tmp;
227
228 tmp = readl(NFC_V3_IPC);
229 if (!(tmp & NFC_V3_IPC_INT))
230 return 0;
231
232 tmp &= ~NFC_V3_IPC_INT;
233 writel(tmp, NFC_V3_IPC);
234
235 return 1;
236}
237
238static int check_int_v1_v2(struct mxc_nand_host *host)
239{
240 uint32_t tmp;
241
242 tmp = readw(NFC_V1_V2_CONFIG2);
243 if (!(tmp & NFC_V1_V2_CONFIG2_INT))
244 return 0;
245
246 writew(tmp & ~NFC_V1_V2_CONFIG2_INT, NFC_V1_V2_CONFIG2);
247
248 return 1;
249}
250
178/* This function polls the NANDFC to wait for the basic operation to 251/* This function polls the NANDFC to wait for the basic operation to
179 * complete by checking the INT bit of config2 register. 252 * complete by checking the INT bit of config2 register.
180 */ 253 */
181static void wait_op_done(struct mxc_nand_host *host, int useirq) 254static void wait_op_done(struct mxc_nand_host *host, int useirq)
182{ 255{
183 uint16_t tmp;
184 int max_retries = 8000; 256 int max_retries = 8000;
185 257
186 if (useirq) { 258 if (useirq) {
187 if ((readw(host->regs + NFC_CONFIG2) & NFC_INT) == 0) { 259 if (!host->check_int(host)) {
188 260
189 enable_irq(host->irq); 261 enable_irq(host->irq);
190 262
191 wait_event(host->irq_waitq, 263 wait_event(host->irq_waitq, host->check_int(host));
192 readw(host->regs + NFC_CONFIG2) & NFC_INT);
193
194 tmp = readw(host->regs + NFC_CONFIG2);
195 tmp &= ~NFC_INT;
196 writew(tmp, host->regs + NFC_CONFIG2);
197 } 264 }
198 } else { 265 } else {
199 while (max_retries-- > 0) { 266 while (max_retries-- > 0) {
200 if (readw(host->regs + NFC_CONFIG2) & NFC_INT) { 267 if (host->check_int(host))
201 tmp = readw(host->regs + NFC_CONFIG2);
202 tmp &= ~NFC_INT;
203 writew(tmp, host->regs + NFC_CONFIG2);
204 break; 268 break;
205 } 269
206 udelay(1); 270 udelay(1);
207 } 271 }
208 if (max_retries < 0) 272 if (max_retries < 0)
@@ -211,21 +275,33 @@ static void wait_op_done(struct mxc_nand_host *host, int useirq)
211 } 275 }
212} 276}
213 277
278static void send_cmd_v3(struct mxc_nand_host *host, uint16_t cmd, int useirq)
279{
280 /* fill command */
281 writel(cmd, NFC_V3_FLASH_CMD);
282
283 /* send out command */
284 writel(NFC_CMD, NFC_V3_LAUNCH);
285
286 /* Wait for operation to complete */
287 wait_op_done(host, useirq);
288}
289
214/* This function issues the specified command to the NAND device and 290/* This function issues the specified command to the NAND device and
215 * waits for completion. */ 291 * waits for completion. */
216static void send_cmd(struct mxc_nand_host *host, uint16_t cmd, int useirq) 292static void send_cmd_v1_v2(struct mxc_nand_host *host, uint16_t cmd, int useirq)
217{ 293{
218 DEBUG(MTD_DEBUG_LEVEL3, "send_cmd(host, 0x%x, %d)\n", cmd, useirq); 294 DEBUG(MTD_DEBUG_LEVEL3, "send_cmd(host, 0x%x, %d)\n", cmd, useirq);
219 295
220 writew(cmd, host->regs + NFC_FLASH_CMD); 296 writew(cmd, NFC_V1_V2_FLASH_CMD);
221 writew(NFC_CMD, host->regs + NFC_CONFIG2); 297 writew(NFC_CMD, NFC_V1_V2_CONFIG2);
222 298
223 if (cpu_is_mx21() && (cmd == NAND_CMD_RESET)) { 299 if (cpu_is_mx21() && (cmd == NAND_CMD_RESET)) {
224 int max_retries = 100; 300 int max_retries = 100;
225 /* Reset completion is indicated by NFC_CONFIG2 */ 301 /* Reset completion is indicated by NFC_CONFIG2 */
226 /* being set to 0 */ 302 /* being set to 0 */
227 while (max_retries-- > 0) { 303 while (max_retries-- > 0) {
228 if (readw(host->regs + NFC_CONFIG2) == 0) { 304 if (readw(NFC_V1_V2_CONFIG2) == 0) {
229 break; 305 break;
230 } 306 }
231 udelay(1); 307 udelay(1);
@@ -239,21 +315,48 @@ static void send_cmd(struct mxc_nand_host *host, uint16_t cmd, int useirq)
239 } 315 }
240} 316}
241 317
318static void send_addr_v3(struct mxc_nand_host *host, uint16_t addr, int islast)
319{
320 /* fill address */
321 writel(addr, NFC_V3_FLASH_ADDR0);
322
323 /* send out address */
324 writel(NFC_ADDR, NFC_V3_LAUNCH);
325
326 wait_op_done(host, 0);
327}
328
242/* This function sends an address (or partial address) to the 329/* This function sends an address (or partial address) to the
243 * NAND device. The address is used to select the source/destination for 330 * NAND device. The address is used to select the source/destination for
244 * a NAND command. */ 331 * a NAND command. */
245static void send_addr(struct mxc_nand_host *host, uint16_t addr, int islast) 332static void send_addr_v1_v2(struct mxc_nand_host *host, uint16_t addr, int islast)
246{ 333{
247 DEBUG(MTD_DEBUG_LEVEL3, "send_addr(host, 0x%x %d)\n", addr, islast); 334 DEBUG(MTD_DEBUG_LEVEL3, "send_addr(host, 0x%x %d)\n", addr, islast);
248 335
249 writew(addr, host->regs + NFC_FLASH_ADDR); 336 writew(addr, NFC_V1_V2_FLASH_ADDR);
250 writew(NFC_ADDR, host->regs + NFC_CONFIG2); 337 writew(NFC_ADDR, NFC_V1_V2_CONFIG2);
251 338
252 /* Wait for operation to complete */ 339 /* Wait for operation to complete */
253 wait_op_done(host, islast); 340 wait_op_done(host, islast);
254} 341}
255 342
256static void send_page(struct mtd_info *mtd, unsigned int ops) 343static void send_page_v3(struct mtd_info *mtd, unsigned int ops)
344{
345 struct nand_chip *nand_chip = mtd->priv;
346 struct mxc_nand_host *host = nand_chip->priv;
347 uint32_t tmp;
348
349 tmp = readl(NFC_V3_CONFIG1);
350 tmp &= ~(7 << 4);
351 writel(tmp, NFC_V3_CONFIG1);
352
353 /* transfer data from NFC ram to nand */
354 writel(ops, NFC_V3_LAUNCH);
355
356 wait_op_done(host, false);
357}
358
359static void send_page_v1_v2(struct mtd_info *mtd, unsigned int ops)
257{ 360{
258 struct nand_chip *nand_chip = mtd->priv; 361 struct nand_chip *nand_chip = mtd->priv;
259 struct mxc_nand_host *host = nand_chip->priv; 362 struct mxc_nand_host *host = nand_chip->priv;
@@ -267,24 +370,34 @@ static void send_page(struct mtd_info *mtd, unsigned int ops)
267 for (i = 0; i < bufs; i++) { 370 for (i = 0; i < bufs; i++) {
268 371
269 /* NANDFC buffer 0 is used for page read/write */ 372 /* NANDFC buffer 0 is used for page read/write */
270 writew(i, host->regs + NFC_BUF_ADDR); 373 writew(i, NFC_V1_V2_BUF_ADDR);
271 374
272 writew(ops, host->regs + NFC_CONFIG2); 375 writew(ops, NFC_V1_V2_CONFIG2);
273 376
274 /* Wait for operation to complete */ 377 /* Wait for operation to complete */
275 wait_op_done(host, true); 378 wait_op_done(host, true);
276 } 379 }
277} 380}
278 381
382static void send_read_id_v3(struct mxc_nand_host *host)
383{
384 /* Read ID into main buffer */
385 writel(NFC_ID, NFC_V3_LAUNCH);
386
387 wait_op_done(host, true);
388
389 memcpy(host->data_buf, host->main_area0, 16);
390}
391
279/* Request the NANDFC to perform a read of the NAND device ID. */ 392/* Request the NANDFC to perform a read of the NAND device ID. */
280static void send_read_id(struct mxc_nand_host *host) 393static void send_read_id_v1_v2(struct mxc_nand_host *host)
281{ 394{
282 struct nand_chip *this = &host->nand; 395 struct nand_chip *this = &host->nand;
283 396
284 /* NANDFC buffer 0 is used for device ID output */ 397 /* NANDFC buffer 0 is used for device ID output */
285 writew(0x0, host->regs + NFC_BUF_ADDR); 398 writew(0x0, NFC_V1_V2_BUF_ADDR);
286 399
287 writew(NFC_ID, host->regs + NFC_CONFIG2); 400 writew(NFC_ID, NFC_V1_V2_CONFIG2);
288 401
289 /* Wait for operation to complete */ 402 /* Wait for operation to complete */
290 wait_op_done(host, true); 403 wait_op_done(host, true);
@@ -301,29 +414,36 @@ static void send_read_id(struct mxc_nand_host *host)
301 memcpy(host->data_buf, host->main_area0, 16); 414 memcpy(host->data_buf, host->main_area0, 16);
302} 415}
303 416
417static uint16_t get_dev_status_v3(struct mxc_nand_host *host)
418{
419 writew(NFC_STATUS, NFC_V3_LAUNCH);
420 wait_op_done(host, true);
421
422 return readl(NFC_V3_CONFIG1) >> 16;
423}
424
304/* This function requests the NANDFC to perform a read of the 425/* This function requests the NANDFC to perform a read of the
305 * NAND device status and returns the current status. */ 426 * NAND device status and returns the current status. */
306static uint16_t get_dev_status(struct mxc_nand_host *host) 427static uint16_t get_dev_status_v1_v2(struct mxc_nand_host *host)
307{ 428{
308 void __iomem *main_buf = host->main_area1; 429 void __iomem *main_buf = host->main_area0;
309 uint32_t store; 430 uint32_t store;
310 uint16_t ret; 431 uint16_t ret;
311 /* Issue status request to NAND device */
312 432
313 /* store the main area1 first word, later do recovery */ 433 writew(0x0, NFC_V1_V2_BUF_ADDR);
314 store = readl(main_buf);
315 /* NANDFC buffer 1 is used for device status to prevent
316 * corruption of read/write buffer on status requests. */
317 writew(1, host->regs + NFC_BUF_ADDR);
318 434
319 writew(NFC_STATUS, host->regs + NFC_CONFIG2); 435 /*
436 * The device status is stored in main_area0. To
437 * prevent corruption of the buffer save the value
438 * and restore it afterwards.
439 */
440 store = readl(main_buf);
320 441
321 /* Wait for operation to complete */ 442 writew(NFC_STATUS, NFC_V1_V2_CONFIG2);
322 wait_op_done(host, true); 443 wait_op_done(host, true);
323 444
324 /* Status is placed in first word of main buffer */
325 /* get status, then recovery area 1 data */
326 ret = readw(main_buf); 445 ret = readw(main_buf);
446
327 writel(store, main_buf); 447 writel(store, main_buf);
328 448
329 return ret; 449 return ret;
@@ -347,7 +467,7 @@ static void mxc_nand_enable_hwecc(struct mtd_info *mtd, int mode)
347 */ 467 */
348} 468}
349 469
350static int mxc_nand_correct_data(struct mtd_info *mtd, u_char *dat, 470static int mxc_nand_correct_data_v1(struct mtd_info *mtd, u_char *dat,
351 u_char *read_ecc, u_char *calc_ecc) 471 u_char *read_ecc, u_char *calc_ecc)
352{ 472{
353 struct nand_chip *nand_chip = mtd->priv; 473 struct nand_chip *nand_chip = mtd->priv;
@@ -358,7 +478,7 @@ static int mxc_nand_correct_data(struct mtd_info *mtd, u_char *dat,
358 * additional correction. 2-Bit errors cannot be corrected by 478 * additional correction. 2-Bit errors cannot be corrected by
359 * HW ECC, so we need to return failure 479 * HW ECC, so we need to return failure
360 */ 480 */
361 uint16_t ecc_status = readw(host->regs + NFC_ECC_STATUS_RESULT); 481 uint16_t ecc_status = readw(NFC_V1_V2_ECC_STATUS_RESULT);
362 482
363 if (((ecc_status & 0x3) == 2) || ((ecc_status >> 2) == 2)) { 483 if (((ecc_status & 0x3) == 2) || ((ecc_status >> 2) == 2)) {
364 DEBUG(MTD_DEBUG_LEVEL0, 484 DEBUG(MTD_DEBUG_LEVEL0,
@@ -369,6 +489,43 @@ static int mxc_nand_correct_data(struct mtd_info *mtd, u_char *dat,
369 return 0; 489 return 0;
370} 490}
371 491
492static int mxc_nand_correct_data_v2_v3(struct mtd_info *mtd, u_char *dat,
493 u_char *read_ecc, u_char *calc_ecc)
494{
495 struct nand_chip *nand_chip = mtd->priv;
496 struct mxc_nand_host *host = nand_chip->priv;
497 u32 ecc_stat, err;
498 int no_subpages = 1;
499 int ret = 0;
500 u8 ecc_bit_mask, err_limit;
501
502 ecc_bit_mask = (host->eccsize == 4) ? 0x7 : 0xf;
503 err_limit = (host->eccsize == 4) ? 0x4 : 0x8;
504
505 no_subpages = mtd->writesize >> 9;
506
507 if (nfc_is_v21())
508 ecc_stat = readl(NFC_V1_V2_ECC_STATUS_RESULT);
509 else
510 ecc_stat = readl(NFC_V3_ECC_STATUS_RESULT);
511
512 do {
513 err = ecc_stat & ecc_bit_mask;
514 if (err > err_limit) {
515 printk(KERN_WARNING "UnCorrectable RS-ECC Error\n");
516 return -1;
517 } else {
518 ret += err;
519 }
520 ecc_stat >>= 4;
521 } while (--no_subpages);
522
523 mtd->ecc_stats.corrected += ret;
524 pr_debug("%d Symbol Correctable RS-ECC Error\n", ret);
525
526 return ret;
527}
528
372static int mxc_nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat, 529static int mxc_nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat,
373 u_char *ecc_code) 530 u_char *ecc_code)
374{ 531{
@@ -383,7 +540,7 @@ static u_char mxc_nand_read_byte(struct mtd_info *mtd)
383 540
384 /* Check for status request */ 541 /* Check for status request */
385 if (host->status_request) 542 if (host->status_request)
386 return get_dev_status(host) & 0xFF; 543 return host->get_dev_status(host) & 0xFF;
387 544
388 ret = *(uint8_t *)(host->data_buf + host->buf_start); 545 ret = *(uint8_t *)(host->data_buf + host->buf_start);
389 host->buf_start++; 546 host->buf_start++;
@@ -519,71 +676,163 @@ static void mxc_do_addr_cycle(struct mtd_info *mtd, int column, int page_addr)
519 * we will used the saved column address to index into 676 * we will used the saved column address to index into
520 * the full page. 677 * the full page.
521 */ 678 */
522 send_addr(host, 0, page_addr == -1); 679 host->send_addr(host, 0, page_addr == -1);
523 if (mtd->writesize > 512) 680 if (mtd->writesize > 512)
524 /* another col addr cycle for 2k page */ 681 /* another col addr cycle for 2k page */
525 send_addr(host, 0, false); 682 host->send_addr(host, 0, false);
526 } 683 }
527 684
528 /* Write out page address, if necessary */ 685 /* Write out page address, if necessary */
529 if (page_addr != -1) { 686 if (page_addr != -1) {
530 /* paddr_0 - p_addr_7 */ 687 /* paddr_0 - p_addr_7 */
531 send_addr(host, (page_addr & 0xff), false); 688 host->send_addr(host, (page_addr & 0xff), false);
532 689
533 if (mtd->writesize > 512) { 690 if (mtd->writesize > 512) {
534 if (mtd->size >= 0x10000000) { 691 if (mtd->size >= 0x10000000) {
535 /* paddr_8 - paddr_15 */ 692 /* paddr_8 - paddr_15 */
536 send_addr(host, (page_addr >> 8) & 0xff, false); 693 host->send_addr(host, (page_addr >> 8) & 0xff, false);
537 send_addr(host, (page_addr >> 16) & 0xff, true); 694 host->send_addr(host, (page_addr >> 16) & 0xff, true);
538 } else 695 } else
539 /* paddr_8 - paddr_15 */ 696 /* paddr_8 - paddr_15 */
540 send_addr(host, (page_addr >> 8) & 0xff, true); 697 host->send_addr(host, (page_addr >> 8) & 0xff, true);
541 } else { 698 } else {
542 /* One more address cycle for higher density devices */ 699 /* One more address cycle for higher density devices */
543 if (mtd->size >= 0x4000000) { 700 if (mtd->size >= 0x4000000) {
544 /* paddr_8 - paddr_15 */ 701 /* paddr_8 - paddr_15 */
545 send_addr(host, (page_addr >> 8) & 0xff, false); 702 host->send_addr(host, (page_addr >> 8) & 0xff, false);
546 send_addr(host, (page_addr >> 16) & 0xff, true); 703 host->send_addr(host, (page_addr >> 16) & 0xff, true);
547 } else 704 } else
548 /* paddr_8 - paddr_15 */ 705 /* paddr_8 - paddr_15 */
549 send_addr(host, (page_addr >> 8) & 0xff, true); 706 host->send_addr(host, (page_addr >> 8) & 0xff, true);
550 } 707 }
551 } 708 }
552} 709}
553 710
554static void preset(struct mtd_info *mtd) 711/*
712 * v2 and v3 type controllers can do 4bit or 8bit ecc depending
713 * on how much oob the nand chip has. For 8bit ecc we need at least
714 * 26 bytes of oob data per 512 byte block.
715 */
716static int get_eccsize(struct mtd_info *mtd)
717{
718 int oobbytes_per_512 = 0;
719
720 oobbytes_per_512 = mtd->oobsize * 512 / mtd->writesize;
721
722 if (oobbytes_per_512 < 26)
723 return 4;
724 else
725 return 8;
726}
727
728static void preset_v1_v2(struct mtd_info *mtd)
555{ 729{
556 struct nand_chip *nand_chip = mtd->priv; 730 struct nand_chip *nand_chip = mtd->priv;
557 struct mxc_nand_host *host = nand_chip->priv; 731 struct mxc_nand_host *host = nand_chip->priv;
558 uint16_t tmp; 732 uint16_t tmp;
559 733
560 /* enable interrupt, disable spare enable */ 734 /* enable interrupt, disable spare enable */
561 tmp = readw(host->regs + NFC_CONFIG1); 735 tmp = readw(NFC_V1_V2_CONFIG1);
562 tmp &= ~NFC_INT_MSK; 736 tmp &= ~NFC_V1_V2_CONFIG1_INT_MSK;
563 tmp &= ~NFC_SP_EN; 737 tmp &= ~NFC_V1_V2_CONFIG1_SP_EN;
564 if (nand_chip->ecc.mode == NAND_ECC_HW) { 738 if (nand_chip->ecc.mode == NAND_ECC_HW) {
565 tmp |= NFC_ECC_EN; 739 tmp |= NFC_V1_V2_CONFIG1_ECC_EN;
740 } else {
741 tmp &= ~NFC_V1_V2_CONFIG1_ECC_EN;
742 }
743
744 if (nfc_is_v21() && mtd->writesize) {
745 host->eccsize = get_eccsize(mtd);
746 if (host->eccsize == 4)
747 tmp |= NFC_V2_CONFIG1_ECC_MODE_4;
566 } else { 748 } else {
567 tmp &= ~NFC_ECC_EN; 749 host->eccsize = 1;
568 } 750 }
569 writew(tmp, host->regs + NFC_CONFIG1); 751
752 writew(tmp, NFC_V1_V2_CONFIG1);
570 /* preset operation */ 753 /* preset operation */
571 754
572 /* Unlock the internal RAM Buffer */ 755 /* Unlock the internal RAM Buffer */
573 writew(0x2, host->regs + NFC_CONFIG); 756 writew(0x2, NFC_V1_V2_CONFIG);
574 757
575 /* Blocks to be unlocked */ 758 /* Blocks to be unlocked */
576 if (nfc_is_v21()) { 759 if (nfc_is_v21()) {
577 writew(0x0, host->regs + NFC_V21_UNLOCKSTART_BLKADDR); 760 writew(0x0, NFC_V21_UNLOCKSTART_BLKADDR);
578 writew(0xffff, host->regs + NFC_V21_UNLOCKEND_BLKADDR); 761 writew(0xffff, NFC_V21_UNLOCKEND_BLKADDR);
579 } else if (nfc_is_v1()) { 762 } else if (nfc_is_v1()) {
580 writew(0x0, host->regs + NFC_V1_UNLOCKSTART_BLKADDR); 763 writew(0x0, NFC_V1_UNLOCKSTART_BLKADDR);
581 writew(0x4000, host->regs + NFC_V1_UNLOCKEND_BLKADDR); 764 writew(0x4000, NFC_V1_UNLOCKEND_BLKADDR);
582 } else 765 } else
583 BUG(); 766 BUG();
584 767
585 /* Unlock Block Command for given address range */ 768 /* Unlock Block Command for given address range */
586 writew(0x4, host->regs + NFC_WRPROT); 769 writew(0x4, NFC_V1_V2_WRPROT);
770}
771
772static void preset_v3(struct mtd_info *mtd)
773{
774 struct nand_chip *chip = mtd->priv;
775 struct mxc_nand_host *host = chip->priv;
776 uint32_t config2, config3;
777 int i, addr_phases;
778
779 writel(NFC_V3_CONFIG1_RBA(0), NFC_V3_CONFIG1);
780 writel(NFC_V3_IPC_CREQ, NFC_V3_IPC);
781
782 /* Unlock the internal RAM Buffer */
783 writel(NFC_V3_WRPROT_BLS_UNLOCK | NFC_V3_WRPROT_UNLOCK,
784 NFC_V3_WRPROT);
785
786 /* Blocks to be unlocked */
787 for (i = 0; i < NAND_MAX_CHIPS; i++)
788 writel(0x0 | (0xffff << 16),
789 NFC_V3_WRPROT_UNLOCK_BLK_ADD0 + (i << 2));
790
791 writel(0, NFC_V3_IPC);
792
793 config2 = NFC_V3_CONFIG2_ONE_CYCLE |
794 NFC_V3_CONFIG2_2CMD_PHASES |
795 NFC_V3_CONFIG2_SPAS(mtd->oobsize >> 1) |
796 NFC_V3_CONFIG2_ST_CMD(0x70) |
797 NFC_V3_CONFIG2_NUM_ADDR_PHASE0;
798
799 if (chip->ecc.mode == NAND_ECC_HW)
800 config2 |= NFC_V3_CONFIG2_ECC_EN;
801
802 addr_phases = fls(chip->pagemask) >> 3;
803
804 if (mtd->writesize == 2048) {
805 config2 |= NFC_V3_CONFIG2_PS_2048;
806 config2 |= NFC_V3_CONFIG2_NUM_ADDR_PHASE1(addr_phases);
807 } else if (mtd->writesize == 4096) {
808 config2 |= NFC_V3_CONFIG2_PS_4096;
809 config2 |= NFC_V3_CONFIG2_NUM_ADDR_PHASE1(addr_phases);
810 } else {
811 config2 |= NFC_V3_CONFIG2_PS_512;
812 config2 |= NFC_V3_CONFIG2_NUM_ADDR_PHASE1(addr_phases - 1);
813 }
814
815 if (mtd->writesize) {
816 config2 |= NFC_V3_CONFIG2_PPB(ffs(mtd->erasesize / mtd->writesize) - 6);
817 host->eccsize = get_eccsize(mtd);
818 if (host->eccsize == 8)
819 config2 |= NFC_V3_CONFIG2_ECC_MODE_8;
820 }
821
822 writel(config2, NFC_V3_CONFIG2);
823
824 config3 = NFC_V3_CONFIG3_NUM_OF_DEVICES(0) |
825 NFC_V3_CONFIG3_NO_SDMA |
826 NFC_V3_CONFIG3_RBB_MODE |
827 NFC_V3_CONFIG3_SBB(6) | /* Reset default */
828 NFC_V3_CONFIG3_ADD_OP(0);
829
830 if (!(chip->options & NAND_BUSWIDTH_16))
831 config3 |= NFC_V3_CONFIG3_FW8;
832
833 writel(config3, NFC_V3_CONFIG3);
834
835 writel(0, NFC_V3_DELAY_LINE);
587} 836}
588 837
589/* Used by the upper layer to write command to NAND Flash for 838/* Used by the upper layer to write command to NAND Flash for
@@ -604,15 +853,15 @@ static void mxc_nand_command(struct mtd_info *mtd, unsigned command,
604 /* Command pre-processing step */ 853 /* Command pre-processing step */
605 switch (command) { 854 switch (command) {
606 case NAND_CMD_RESET: 855 case NAND_CMD_RESET:
607 send_cmd(host, command, false); 856 host->preset(mtd);
608 preset(mtd); 857 host->send_cmd(host, command, false);
609 break; 858 break;
610 859
611 case NAND_CMD_STATUS: 860 case NAND_CMD_STATUS:
612 host->buf_start = 0; 861 host->buf_start = 0;
613 host->status_request = true; 862 host->status_request = true;
614 863
615 send_cmd(host, command, true); 864 host->send_cmd(host, command, true);
616 mxc_do_addr_cycle(mtd, column, page_addr); 865 mxc_do_addr_cycle(mtd, column, page_addr);
617 break; 866 break;
618 867
@@ -625,13 +874,13 @@ static void mxc_nand_command(struct mtd_info *mtd, unsigned command,
625 874
626 command = NAND_CMD_READ0; /* only READ0 is valid */ 875 command = NAND_CMD_READ0; /* only READ0 is valid */
627 876
628 send_cmd(host, command, false); 877 host->send_cmd(host, command, false);
629 mxc_do_addr_cycle(mtd, column, page_addr); 878 mxc_do_addr_cycle(mtd, column, page_addr);
630 879
631 if (mtd->writesize > 512) 880 if (mtd->writesize > 512)
632 send_cmd(host, NAND_CMD_READSTART, true); 881 host->send_cmd(host, NAND_CMD_READSTART, true);
633 882
634 send_page(mtd, NFC_OUTPUT); 883 host->send_page(mtd, NFC_OUTPUT);
635 884
636 memcpy(host->data_buf, host->main_area0, mtd->writesize); 885 memcpy(host->data_buf, host->main_area0, mtd->writesize);
637 copy_spare(mtd, true); 886 copy_spare(mtd, true);
@@ -644,28 +893,28 @@ static void mxc_nand_command(struct mtd_info *mtd, unsigned command,
644 893
645 host->buf_start = column; 894 host->buf_start = column;
646 895
647 send_cmd(host, command, false); 896 host->send_cmd(host, command, false);
648 mxc_do_addr_cycle(mtd, column, page_addr); 897 mxc_do_addr_cycle(mtd, column, page_addr);
649 break; 898 break;
650 899
651 case NAND_CMD_PAGEPROG: 900 case NAND_CMD_PAGEPROG:
652 memcpy(host->main_area0, host->data_buf, mtd->writesize); 901 memcpy(host->main_area0, host->data_buf, mtd->writesize);
653 copy_spare(mtd, false); 902 copy_spare(mtd, false);
654 send_page(mtd, NFC_INPUT); 903 host->send_page(mtd, NFC_INPUT);
655 send_cmd(host, command, true); 904 host->send_cmd(host, command, true);
656 mxc_do_addr_cycle(mtd, column, page_addr); 905 mxc_do_addr_cycle(mtd, column, page_addr);
657 break; 906 break;
658 907
659 case NAND_CMD_READID: 908 case NAND_CMD_READID:
660 send_cmd(host, command, true); 909 host->send_cmd(host, command, true);
661 mxc_do_addr_cycle(mtd, column, page_addr); 910 mxc_do_addr_cycle(mtd, column, page_addr);
662 send_read_id(host); 911 host->send_read_id(host);
663 host->buf_start = column; 912 host->buf_start = column;
664 break; 913 break;
665 914
666 case NAND_CMD_ERASE1: 915 case NAND_CMD_ERASE1:
667 case NAND_CMD_ERASE2: 916 case NAND_CMD_ERASE2:
668 send_cmd(host, command, false); 917 host->send_cmd(host, command, false);
669 mxc_do_addr_cycle(mtd, column, page_addr); 918 mxc_do_addr_cycle(mtd, column, page_addr);
670 919
671 break; 920 break;
@@ -761,22 +1010,55 @@ static int __init mxcnd_probe(struct platform_device *pdev)
761 } 1010 }
762 1011
763 host->main_area0 = host->base; 1012 host->main_area0 = host->base;
764 host->main_area1 = host->base + 0x200; 1013
1014 if (nfc_is_v1() || nfc_is_v21()) {
1015 host->preset = preset_v1_v2;
1016 host->send_cmd = send_cmd_v1_v2;
1017 host->send_addr = send_addr_v1_v2;
1018 host->send_page = send_page_v1_v2;
1019 host->send_read_id = send_read_id_v1_v2;
1020 host->get_dev_status = get_dev_status_v1_v2;
1021 host->check_int = check_int_v1_v2;
1022 }
765 1023
766 if (nfc_is_v21()) { 1024 if (nfc_is_v21()) {
767 host->regs = host->base + 0x1000; 1025 host->regs = host->base + 0x1e00;
768 host->spare0 = host->base + 0x1000; 1026 host->spare0 = host->base + 0x1000;
769 host->spare_len = 64; 1027 host->spare_len = 64;
770 oob_smallpage = &nandv2_hw_eccoob_smallpage; 1028 oob_smallpage = &nandv2_hw_eccoob_smallpage;
771 oob_largepage = &nandv2_hw_eccoob_largepage; 1029 oob_largepage = &nandv2_hw_eccoob_largepage;
772 this->ecc.bytes = 9; 1030 this->ecc.bytes = 9;
773 } else if (nfc_is_v1()) { 1031 } else if (nfc_is_v1()) {
774 host->regs = host->base; 1032 host->regs = host->base + 0xe00;
775 host->spare0 = host->base + 0x800; 1033 host->spare0 = host->base + 0x800;
776 host->spare_len = 16; 1034 host->spare_len = 16;
777 oob_smallpage = &nandv1_hw_eccoob_smallpage; 1035 oob_smallpage = &nandv1_hw_eccoob_smallpage;
778 oob_largepage = &nandv1_hw_eccoob_largepage; 1036 oob_largepage = &nandv1_hw_eccoob_largepage;
779 this->ecc.bytes = 3; 1037 this->ecc.bytes = 3;
1038 host->eccsize = 1;
1039 } else if (nfc_is_v3_2()) {
1040 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
1041 if (!res) {
1042 err = -ENODEV;
1043 goto eirq;
1044 }
1045 host->regs_ip = ioremap(res->start, resource_size(res));
1046 if (!host->regs_ip) {
1047 err = -ENOMEM;
1048 goto eirq;
1049 }
1050 host->regs_axi = host->base + 0x1e00;
1051 host->spare0 = host->base + 0x1000;
1052 host->spare_len = 64;
1053 host->preset = preset_v3;
1054 host->send_cmd = send_cmd_v3;
1055 host->send_addr = send_addr_v3;
1056 host->send_page = send_page_v3;
1057 host->send_read_id = send_read_id_v3;
1058 host->check_int = check_int_v3;
1059 host->get_dev_status = get_dev_status_v3;
1060 oob_smallpage = &nandv2_hw_eccoob_smallpage;
1061 oob_largepage = &nandv2_hw_eccoob_largepage;
780 } else 1062 } else
781 BUG(); 1063 BUG();
782 1064
@@ -786,7 +1068,10 @@ static int __init mxcnd_probe(struct platform_device *pdev)
786 if (pdata->hw_ecc) { 1068 if (pdata->hw_ecc) {
787 this->ecc.calculate = mxc_nand_calculate_ecc; 1069 this->ecc.calculate = mxc_nand_calculate_ecc;
788 this->ecc.hwctl = mxc_nand_enable_hwecc; 1070 this->ecc.hwctl = mxc_nand_enable_hwecc;
789 this->ecc.correct = mxc_nand_correct_data; 1071 if (nfc_is_v1())
1072 this->ecc.correct = mxc_nand_correct_data_v1;
1073 else
1074 this->ecc.correct = mxc_nand_correct_data_v2_v3;
790 this->ecc.mode = NAND_ECC_HW; 1075 this->ecc.mode = NAND_ECC_HW;
791 } else { 1076 } else {
792 this->ecc.mode = NAND_ECC_SOFT; 1077 this->ecc.mode = NAND_ECC_SOFT;
@@ -817,6 +1102,9 @@ static int __init mxcnd_probe(struct platform_device *pdev)
817 goto escan; 1102 goto escan;
818 } 1103 }
819 1104
1105 /* Call preset again, with correct writesize this time */
1106 host->preset(mtd);
1107
820 if (mtd->writesize == 2048) 1108 if (mtd->writesize == 2048)
821 this->ecc.layout = oob_largepage; 1109 this->ecc.layout = oob_largepage;
822 1110
@@ -848,6 +1136,8 @@ static int __init mxcnd_probe(struct platform_device *pdev)
848escan: 1136escan:
849 free_irq(host->irq, host); 1137 free_irq(host->irq, host);
850eirq: 1138eirq:
1139 if (host->regs_ip)
1140 iounmap(host->regs_ip);
851 iounmap(host->base); 1141 iounmap(host->base);
852eres: 1142eres:
853 clk_put(host->clk); 1143 clk_put(host->clk);
@@ -867,59 +1157,19 @@ static int __devexit mxcnd_remove(struct platform_device *pdev)
867 1157
868 nand_release(&host->mtd); 1158 nand_release(&host->mtd);
869 free_irq(host->irq, host); 1159 free_irq(host->irq, host);
1160 if (host->regs_ip)
1161 iounmap(host->regs_ip);
870 iounmap(host->base); 1162 iounmap(host->base);
871 kfree(host); 1163 kfree(host);
872 1164
873 return 0; 1165 return 0;
874} 1166}
875 1167
876#ifdef CONFIG_PM
877static int mxcnd_suspend(struct platform_device *pdev, pm_message_t state)
878{
879 struct mtd_info *mtd = platform_get_drvdata(pdev);
880 struct nand_chip *nand_chip = mtd->priv;
881 struct mxc_nand_host *host = nand_chip->priv;
882 int ret = 0;
883
884 DEBUG(MTD_DEBUG_LEVEL0, "MXC_ND : NAND suspend\n");
885
886 ret = mtd->suspend(mtd);
887
888 /*
889 * nand_suspend locks the device for exclusive access, so
890 * the clock must already be off.
891 */
892 BUG_ON(!ret && host->clk_act);
893
894 return ret;
895}
896
897static int mxcnd_resume(struct platform_device *pdev)
898{
899 struct mtd_info *mtd = platform_get_drvdata(pdev);
900 struct nand_chip *nand_chip = mtd->priv;
901 struct mxc_nand_host *host = nand_chip->priv;
902 int ret = 0;
903
904 DEBUG(MTD_DEBUG_LEVEL0, "MXC_ND : NAND resume\n");
905
906 mtd->resume(mtd);
907
908 return ret;
909}
910
911#else
912# define mxcnd_suspend NULL
913# define mxcnd_resume NULL
914#endif /* CONFIG_PM */
915
916static struct platform_driver mxcnd_driver = { 1168static struct platform_driver mxcnd_driver = {
917 .driver = { 1169 .driver = {
918 .name = DRIVER_NAME, 1170 .name = DRIVER_NAME,
919 }, 1171 },
920 .remove = __devexit_p(mxcnd_remove), 1172 .remove = __devexit_p(mxcnd_remove),
921 .suspend = mxcnd_suspend,
922 .resume = mxcnd_resume,
923}; 1173};
924 1174
925static int __init mxc_nd_init(void) 1175static int __init mxc_nd_init(void)
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 4a7b86423ee9..a3c7473dd409 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -42,7 +42,6 @@
42#include <linux/mtd/mtd.h> 42#include <linux/mtd/mtd.h>
43#include <linux/mtd/nand.h> 43#include <linux/mtd/nand.h>
44#include <linux/mtd/nand_ecc.h> 44#include <linux/mtd/nand_ecc.h>
45#include <linux/mtd/compatmac.h>
46#include <linux/interrupt.h> 45#include <linux/interrupt.h>
47#include <linux/bitops.h> 46#include <linux/bitops.h>
48#include <linux/leds.h> 47#include <linux/leds.h>
@@ -347,7 +346,7 @@ static int nand_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip)
347 struct nand_chip *chip = mtd->priv; 346 struct nand_chip *chip = mtd->priv;
348 u16 bad; 347 u16 bad;
349 348
350 if (chip->options & NAND_BB_LAST_PAGE) 349 if (chip->options & NAND_BBT_SCANLASTPAGE)
351 ofs += mtd->erasesize - mtd->writesize; 350 ofs += mtd->erasesize - mtd->writesize;
352 351
353 page = (int)(ofs >> chip->page_shift) & chip->pagemask; 352 page = (int)(ofs >> chip->page_shift) & chip->pagemask;
@@ -397,9 +396,9 @@ static int nand_default_block_markbad(struct mtd_info *mtd, loff_t ofs)
397{ 396{
398 struct nand_chip *chip = mtd->priv; 397 struct nand_chip *chip = mtd->priv;
399 uint8_t buf[2] = { 0, 0 }; 398 uint8_t buf[2] = { 0, 0 };
400 int block, ret; 399 int block, ret, i = 0;
401 400
402 if (chip->options & NAND_BB_LAST_PAGE) 401 if (chip->options & NAND_BBT_SCANLASTPAGE)
403 ofs += mtd->erasesize - mtd->writesize; 402 ofs += mtd->erasesize - mtd->writesize;
404 403
405 /* Get block number */ 404 /* Get block number */
@@ -411,17 +410,31 @@ static int nand_default_block_markbad(struct mtd_info *mtd, loff_t ofs)
411 if (chip->options & NAND_USE_FLASH_BBT) 410 if (chip->options & NAND_USE_FLASH_BBT)
412 ret = nand_update_bbt(mtd, ofs); 411 ret = nand_update_bbt(mtd, ofs);
413 else { 412 else {
414 /* We write two bytes, so we dont have to mess with 16 bit
415 * access
416 */
417 nand_get_device(chip, mtd, FL_WRITING); 413 nand_get_device(chip, mtd, FL_WRITING);
418 ofs += mtd->oobsize;
419 chip->ops.len = chip->ops.ooblen = 2;
420 chip->ops.datbuf = NULL;
421 chip->ops.oobbuf = buf;
422 chip->ops.ooboffs = chip->badblockpos & ~0x01;
423 414
424 ret = nand_do_write_oob(mtd, ofs, &chip->ops); 415 /* Write to first two pages and to byte 1 and 6 if necessary.
416 * If we write to more than one location, the first error
417 * encountered quits the procedure. We write two bytes per
418 * location, so we dont have to mess with 16 bit access.
419 */
420 do {
421 chip->ops.len = chip->ops.ooblen = 2;
422 chip->ops.datbuf = NULL;
423 chip->ops.oobbuf = buf;
424 chip->ops.ooboffs = chip->badblockpos & ~0x01;
425
426 ret = nand_do_write_oob(mtd, ofs, &chip->ops);
427
428 if (!ret && (chip->options & NAND_BBT_SCANBYTE1AND6)) {
429 chip->ops.ooboffs = NAND_SMALL_BADBLOCK_POS
430 & ~0x01;
431 ret = nand_do_write_oob(mtd, ofs, &chip->ops);
432 }
433 i++;
434 ofs += mtd->writesize;
435 } while (!ret && (chip->options & NAND_BBT_SCAN2NDPAGE) &&
436 i < 2);
437
425 nand_release_device(mtd); 438 nand_release_device(mtd);
426 } 439 }
427 if (!ret) 440 if (!ret)
@@ -876,17 +889,17 @@ static int nand_wait(struct mtd_info *mtd, struct nand_chip *chip)
876} 889}
877 890
878/** 891/**
879 * __nand_unlock - [REPLACABLE] unlocks specified locked blockes 892 * __nand_unlock - [REPLACEABLE] unlocks specified locked blocks
880 * 893 *
881 * @param mtd - mtd info 894 * @mtd: mtd info
882 * @param ofs - offset to start unlock from 895 * @ofs: offset to start unlock from
883 * @param len - length to unlock 896 * @len: length to unlock
884 * @invert - when = 0, unlock the range of blocks within the lower and 897 * @invert: when = 0, unlock the range of blocks within the lower and
885 * upper boundary address 898 * upper boundary address
886 * whne = 1, unlock the range of blocks outside the boundaries 899 * when = 1, unlock the range of blocks outside the boundaries
887 * of the lower and upper boundary address 900 * of the lower and upper boundary address
888 * 901 *
889 * @return - unlock status 902 * return - unlock status
890 */ 903 */
891static int __nand_unlock(struct mtd_info *mtd, loff_t ofs, 904static int __nand_unlock(struct mtd_info *mtd, loff_t ofs,
892 uint64_t len, int invert) 905 uint64_t len, int invert)
@@ -918,13 +931,13 @@ static int __nand_unlock(struct mtd_info *mtd, loff_t ofs,
918} 931}
919 932
920/** 933/**
921 * nand_unlock - [REPLACABLE] unlocks specified locked blockes 934 * nand_unlock - [REPLACEABLE] unlocks specified locked blocks
922 * 935 *
923 * @param mtd - mtd info 936 * @mtd: mtd info
924 * @param ofs - offset to start unlock from 937 * @ofs: offset to start unlock from
925 * @param len - length to unlock 938 * @len: length to unlock
926 * 939 *
927 * @return - unlock status 940 * return - unlock status
928 */ 941 */
929int nand_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len) 942int nand_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
930{ 943{
@@ -969,16 +982,16 @@ out:
969} 982}
970 983
971/** 984/**
972 * nand_lock - [REPLACABLE] locks all blockes present in the device 985 * nand_lock - [REPLACEABLE] locks all blocks present in the device
973 * 986 *
974 * @param mtd - mtd info 987 * @mtd: mtd info
975 * @param ofs - offset to start unlock from 988 * @ofs: offset to start unlock from
976 * @param len - length to unlock 989 * @len: length to unlock
977 * 990 *
978 * @return - lock status 991 * return - lock status
979 * 992 *
980 * This feature is not support in many NAND parts. 'Micron' NAND parts 993 * This feature is not supported in many NAND parts. 'Micron' NAND parts
981 * do have this feature, but it allows only to lock all blocks not for 994 * do have this feature, but it allows only to lock all blocks, not for
982 * specified range for block. 995 * specified range for block.
983 * 996 *
984 * Implementing 'lock' feature by making use of 'unlock', for now. 997 * Implementing 'lock' feature by making use of 'unlock', for now.
@@ -2080,6 +2093,7 @@ static int nand_write_page(struct mtd_info *mtd, struct nand_chip *chip,
2080 * nand_fill_oob - [Internal] Transfer client buffer to oob 2093 * nand_fill_oob - [Internal] Transfer client buffer to oob
2081 * @chip: nand chip structure 2094 * @chip: nand chip structure
2082 * @oob: oob data buffer 2095 * @oob: oob data buffer
2096 * @len: oob data write length
2083 * @ops: oob ops structure 2097 * @ops: oob ops structure
2084 */ 2098 */
2085static uint8_t *nand_fill_oob(struct nand_chip *chip, uint8_t *oob, size_t len, 2099static uint8_t *nand_fill_oob(struct nand_chip *chip, uint8_t *oob, size_t len,
@@ -2920,9 +2934,14 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
2920 chip->chip_shift = ffs((unsigned)(chip->chipsize >> 32)) + 32 - 1; 2934 chip->chip_shift = ffs((unsigned)(chip->chipsize >> 32)) + 32 - 1;
2921 2935
2922 /* Set the bad block position */ 2936 /* Set the bad block position */
2923 chip->badblockpos = mtd->writesize > 512 ? 2937 if (!(busw & NAND_BUSWIDTH_16) && (*maf_id == NAND_MFR_STMICRO ||
2924 NAND_LARGE_BADBLOCK_POS : NAND_SMALL_BADBLOCK_POS; 2938 (*maf_id == NAND_MFR_SAMSUNG &&
2925 chip->badblockbits = 8; 2939 mtd->writesize == 512) ||
2940 *maf_id == NAND_MFR_AMD))
2941 chip->badblockpos = NAND_SMALL_BADBLOCK_POS;
2942 else
2943 chip->badblockpos = NAND_LARGE_BADBLOCK_POS;
2944
2926 2945
2927 /* Get chip options, preserve non chip based options */ 2946 /* Get chip options, preserve non chip based options */
2928 chip->options &= ~NAND_CHIPOPTIONS_MSK; 2947 chip->options &= ~NAND_CHIPOPTIONS_MSK;
@@ -2941,12 +2960,32 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
2941 2960
2942 /* 2961 /*
2943 * Bad block marker is stored in the last page of each block 2962 * Bad block marker is stored in the last page of each block
2944 * on Samsung and Hynix MLC devices 2963 * on Samsung and Hynix MLC devices; stored in first two pages
2964 * of each block on Micron devices with 2KiB pages and on
2965 * SLC Samsung, Hynix, and AMD/Spansion. All others scan only
2966 * the first page.
2945 */ 2967 */
2946 if ((chip->cellinfo & NAND_CI_CELLTYPE_MSK) && 2968 if ((chip->cellinfo & NAND_CI_CELLTYPE_MSK) &&
2947 (*maf_id == NAND_MFR_SAMSUNG || 2969 (*maf_id == NAND_MFR_SAMSUNG ||
2948 *maf_id == NAND_MFR_HYNIX)) 2970 *maf_id == NAND_MFR_HYNIX))
2949 chip->options |= NAND_BB_LAST_PAGE; 2971 chip->options |= NAND_BBT_SCANLASTPAGE;
2972 else if ((!(chip->cellinfo & NAND_CI_CELLTYPE_MSK) &&
2973 (*maf_id == NAND_MFR_SAMSUNG ||
2974 *maf_id == NAND_MFR_HYNIX ||
2975 *maf_id == NAND_MFR_AMD)) ||
2976 (mtd->writesize == 2048 &&
2977 *maf_id == NAND_MFR_MICRON))
2978 chip->options |= NAND_BBT_SCAN2NDPAGE;
2979
2980 /*
2981 * Numonyx/ST 2K pages, x8 bus use BOTH byte 1 and 6
2982 */
2983 if (!(busw & NAND_BUSWIDTH_16) &&
2984 *maf_id == NAND_MFR_STMICRO &&
2985 mtd->writesize == 2048) {
2986 chip->options |= NAND_BBT_SCANBYTE1AND6;
2987 chip->badblockpos = 0;
2988 }
2950 2989
2951 /* Check for AND chips with 4 page planes */ 2990 /* Check for AND chips with 4 page planes */
2952 if (chip->options & NAND_4PAGE_ARRAY) 2991 if (chip->options & NAND_4PAGE_ARRAY)
@@ -3306,6 +3345,11 @@ void nand_release(struct mtd_info *mtd)
3306 kfree(chip->bbt); 3345 kfree(chip->bbt);
3307 if (!(chip->options & NAND_OWN_BUFFERS)) 3346 if (!(chip->options & NAND_OWN_BUFFERS))
3308 kfree(chip->buffers); 3347 kfree(chip->buffers);
3348
3349 /* Free bad block descriptor memory */
3350 if (chip->badblock_pattern && chip->badblock_pattern->options
3351 & NAND_BBT_DYNAMICSTRUCT)
3352 kfree(chip->badblock_pattern);
3309} 3353}
3310 3354
3311EXPORT_SYMBOL_GPL(nand_lock); 3355EXPORT_SYMBOL_GPL(nand_lock);
diff --git a/drivers/mtd/nand/nand_bbt.c b/drivers/mtd/nand/nand_bbt.c
index ad97c0ce73b2..5fedf4a74f16 100644
--- a/drivers/mtd/nand/nand_bbt.c
+++ b/drivers/mtd/nand/nand_bbt.c
@@ -55,7 +55,6 @@
55#include <linux/mtd/mtd.h> 55#include <linux/mtd/mtd.h>
56#include <linux/mtd/nand.h> 56#include <linux/mtd/nand.h>
57#include <linux/mtd/nand_ecc.h> 57#include <linux/mtd/nand_ecc.h>
58#include <linux/mtd/compatmac.h>
59#include <linux/bitops.h> 58#include <linux/bitops.h>
60#include <linux/delay.h> 59#include <linux/delay.h>
61#include <linux/vmalloc.h> 60#include <linux/vmalloc.h>
@@ -93,6 +92,28 @@ static int check_pattern(uint8_t *buf, int len, int paglen, struct nand_bbt_desc
93 return -1; 92 return -1;
94 } 93 }
95 94
95 /* Check both positions 1 and 6 for pattern? */
96 if (td->options & NAND_BBT_SCANBYTE1AND6) {
97 if (td->options & NAND_BBT_SCANEMPTY) {
98 p += td->len;
99 end += NAND_SMALL_BADBLOCK_POS - td->offs;
100 /* Check region between positions 1 and 6 */
101 for (i = 0; i < NAND_SMALL_BADBLOCK_POS - td->offs - td->len;
102 i++) {
103 if (*p++ != 0xff)
104 return -1;
105 }
106 }
107 else {
108 p += NAND_SMALL_BADBLOCK_POS - td->offs;
109 }
110 /* Compare the pattern */
111 for (i = 0; i < td->len; i++) {
112 if (p[i] != td->pattern[i])
113 return -1;
114 }
115 }
116
96 if (td->options & NAND_BBT_SCANEMPTY) { 117 if (td->options & NAND_BBT_SCANEMPTY) {
97 p += td->len; 118 p += td->len;
98 end += td->len; 119 end += td->len;
@@ -124,6 +145,13 @@ static int check_short_pattern(uint8_t *buf, struct nand_bbt_descr *td)
124 if (p[td->offs + i] != td->pattern[i]) 145 if (p[td->offs + i] != td->pattern[i])
125 return -1; 146 return -1;
126 } 147 }
148 /* Need to check location 1 AND 6? */
149 if (td->options & NAND_BBT_SCANBYTE1AND6) {
150 for (i = 0; i < td->len; i++) {
151 if (p[NAND_SMALL_BADBLOCK_POS + i] != td->pattern[i])
152 return -1;
153 }
154 }
127 return 0; 155 return 0;
128} 156}
129 157
@@ -397,12 +425,10 @@ static int create_bbt(struct mtd_info *mtd, uint8_t *buf,
397 425
398 if (bd->options & NAND_BBT_SCANALLPAGES) 426 if (bd->options & NAND_BBT_SCANALLPAGES)
399 len = 1 << (this->bbt_erase_shift - this->page_shift); 427 len = 1 << (this->bbt_erase_shift - this->page_shift);
400 else { 428 else if (bd->options & NAND_BBT_SCAN2NDPAGE)
401 if (bd->options & NAND_BBT_SCAN2NDPAGE) 429 len = 2;
402 len = 2; 430 else
403 else 431 len = 1;
404 len = 1;
405 }
406 432
407 if (!(bd->options & NAND_BBT_SCANEMPTY)) { 433 if (!(bd->options & NAND_BBT_SCANEMPTY)) {
408 /* We need only read few bytes from the OOB area */ 434 /* We need only read few bytes from the OOB area */
@@ -432,7 +458,7 @@ static int create_bbt(struct mtd_info *mtd, uint8_t *buf,
432 from = (loff_t)startblock << (this->bbt_erase_shift - 1); 458 from = (loff_t)startblock << (this->bbt_erase_shift - 1);
433 } 459 }
434 460
435 if (this->options & NAND_BB_LAST_PAGE) 461 if (this->options & NAND_BBT_SCANLASTPAGE)
436 from += mtd->erasesize - (mtd->writesize * len); 462 from += mtd->erasesize - (mtd->writesize * len);
437 463
438 for (i = startblock; i < numblocks;) { 464 for (i = startblock; i < numblocks;) {
@@ -1092,30 +1118,16 @@ int nand_update_bbt(struct mtd_info *mtd, loff_t offs)
1092 * while scanning a device for factory marked good / bad blocks. */ 1118 * while scanning a device for factory marked good / bad blocks. */
1093static uint8_t scan_ff_pattern[] = { 0xff, 0xff }; 1119static uint8_t scan_ff_pattern[] = { 0xff, 0xff };
1094 1120
1095static struct nand_bbt_descr smallpage_memorybased = {
1096 .options = NAND_BBT_SCAN2NDPAGE,
1097 .offs = 5,
1098 .len = 1,
1099 .pattern = scan_ff_pattern
1100};
1101
1102static struct nand_bbt_descr largepage_memorybased = {
1103 .options = 0,
1104 .offs = 0,
1105 .len = 2,
1106 .pattern = scan_ff_pattern
1107};
1108
1109static struct nand_bbt_descr smallpage_flashbased = { 1121static struct nand_bbt_descr smallpage_flashbased = {
1110 .options = NAND_BBT_SCAN2NDPAGE, 1122 .options = NAND_BBT_SCAN2NDPAGE,
1111 .offs = 5, 1123 .offs = NAND_SMALL_BADBLOCK_POS,
1112 .len = 1, 1124 .len = 1,
1113 .pattern = scan_ff_pattern 1125 .pattern = scan_ff_pattern
1114}; 1126};
1115 1127
1116static struct nand_bbt_descr largepage_flashbased = { 1128static struct nand_bbt_descr largepage_flashbased = {
1117 .options = NAND_BBT_SCAN2NDPAGE, 1129 .options = NAND_BBT_SCAN2NDPAGE,
1118 .offs = 0, 1130 .offs = NAND_LARGE_BADBLOCK_POS,
1119 .len = 2, 1131 .len = 2,
1120 .pattern = scan_ff_pattern 1132 .pattern = scan_ff_pattern
1121}; 1133};
@@ -1154,6 +1166,43 @@ static struct nand_bbt_descr bbt_mirror_descr = {
1154 .pattern = mirror_pattern 1166 .pattern = mirror_pattern
1155}; 1167};
1156 1168
1169#define BBT_SCAN_OPTIONS (NAND_BBT_SCANLASTPAGE | NAND_BBT_SCAN2NDPAGE | \
1170 NAND_BBT_SCANBYTE1AND6)
1171/**
1172 * nand_create_default_bbt_descr - [Internal] Creates a BBT descriptor structure
1173 * @this: NAND chip to create descriptor for
1174 *
1175 * This function allocates and initializes a nand_bbt_descr for BBM detection
1176 * based on the properties of "this". The new descriptor is stored in
1177 * this->badblock_pattern. Thus, this->badblock_pattern should be NULL when
1178 * passed to this function.
1179 *
1180 * TODO: Handle other flags, replace other static structs
1181 * (e.g. handle NAND_BBT_FLASH for flash-based BBT,
1182 * replace smallpage_flashbased)
1183 *
1184 */
1185static int nand_create_default_bbt_descr(struct nand_chip *this)
1186{
1187 struct nand_bbt_descr *bd;
1188 if (this->badblock_pattern) {
1189 printk(KERN_WARNING "BBT descr already allocated; not replacing.\n");
1190 return -EINVAL;
1191 }
1192 bd = kzalloc(sizeof(*bd), GFP_KERNEL);
1193 if (!bd) {
1194 printk(KERN_ERR "nand_create_default_bbt_descr: Out of memory\n");
1195 return -ENOMEM;
1196 }
1197 bd->options = this->options & BBT_SCAN_OPTIONS;
1198 bd->offs = this->badblockpos;
1199 bd->len = (this->options & NAND_BUSWIDTH_16) ? 2 : 1;
1200 bd->pattern = scan_ff_pattern;
1201 bd->options |= NAND_BBT_DYNAMICSTRUCT;
1202 this->badblock_pattern = bd;
1203 return 0;
1204}
1205
1157/** 1206/**
1158 * nand_default_bbt - [NAND Interface] Select a default bad block table for the device 1207 * nand_default_bbt - [NAND Interface] Select a default bad block table for the device
1159 * @mtd: MTD device structure 1208 * @mtd: MTD device structure
@@ -1196,10 +1245,8 @@ int nand_default_bbt(struct mtd_info *mtd)
1196 } else { 1245 } else {
1197 this->bbt_td = NULL; 1246 this->bbt_td = NULL;
1198 this->bbt_md = NULL; 1247 this->bbt_md = NULL;
1199 if (!this->badblock_pattern) { 1248 if (!this->badblock_pattern)
1200 this->badblock_pattern = (mtd->writesize > 512) ? 1249 nand_create_default_bbt_descr(this);
1201 &largepage_memorybased : &smallpage_memorybased;
1202 }
1203 } 1250 }
1204 return nand_scan_bbt(mtd, this->badblock_pattern); 1251 return nand_scan_bbt(mtd, this->badblock_pattern);
1205} 1252}
diff --git a/drivers/mtd/nand/nand_ids.c b/drivers/mtd/nand/nand_ids.c
index 89907ed99009..c65f19074bc8 100644
--- a/drivers/mtd/nand/nand_ids.c
+++ b/drivers/mtd/nand/nand_ids.c
@@ -85,6 +85,7 @@ struct nand_flash_dev nand_flash_ids[] = {
85 {"NAND 128MiB 3,3V 8-bit", 0xD1, 0, 128, 0, LP_OPTIONS}, 85 {"NAND 128MiB 3,3V 8-bit", 0xD1, 0, 128, 0, LP_OPTIONS},
86 {"NAND 128MiB 1,8V 16-bit", 0xB1, 0, 128, 0, LP_OPTIONS16}, 86 {"NAND 128MiB 1,8V 16-bit", 0xB1, 0, 128, 0, LP_OPTIONS16},
87 {"NAND 128MiB 3,3V 16-bit", 0xC1, 0, 128, 0, LP_OPTIONS16}, 87 {"NAND 128MiB 3,3V 16-bit", 0xC1, 0, 128, 0, LP_OPTIONS16},
88 {"NAND 128MiB 1,8V 16-bit", 0xAD, 0, 128, 0, LP_OPTIONS16},
88 89
89 /* 2 Gigabit */ 90 /* 2 Gigabit */
90 {"NAND 256MiB 1,8V 8-bit", 0xAA, 0, 256, 0, LP_OPTIONS}, 91 {"NAND 256MiB 1,8V 8-bit", 0xAA, 0, 256, 0, LP_OPTIONS},
@@ -110,6 +111,9 @@ struct nand_flash_dev nand_flash_ids[] = {
110 {"NAND 2GiB 1,8V 16-bit", 0xB5, 0, 2048, 0, LP_OPTIONS16}, 111 {"NAND 2GiB 1,8V 16-bit", 0xB5, 0, 2048, 0, LP_OPTIONS16},
111 {"NAND 2GiB 3,3V 16-bit", 0xC5, 0, 2048, 0, LP_OPTIONS16}, 112 {"NAND 2GiB 3,3V 16-bit", 0xC5, 0, 2048, 0, LP_OPTIONS16},
112 113
114 /* 32 Gigabit */
115 {"NAND 4GiB 3,3V 8-bit", 0xD7, 0, 4096, 0, LP_OPTIONS},
116
113 /* 117 /*
114 * Renesas AND 1 Gigabit. Those chips do not support extended id and 118 * Renesas AND 1 Gigabit. Those chips do not support extended id and
115 * have a strange page/block layout ! The chosen minimum erasesize is 119 * have a strange page/block layout ! The chosen minimum erasesize is
diff --git a/drivers/mtd/nand/nandsim.c b/drivers/mtd/nand/nandsim.c
index 261337efe0ee..c25648bb5793 100644
--- a/drivers/mtd/nand/nandsim.c
+++ b/drivers/mtd/nand/nandsim.c
@@ -553,8 +553,8 @@ static uint64_t divide(uint64_t n, uint32_t d)
553 */ 553 */
554static int init_nandsim(struct mtd_info *mtd) 554static int init_nandsim(struct mtd_info *mtd)
555{ 555{
556 struct nand_chip *chip = (struct nand_chip *)mtd->priv; 556 struct nand_chip *chip = mtd->priv;
557 struct nandsim *ns = (struct nandsim *)(chip->priv); 557 struct nandsim *ns = chip->priv;
558 int i, ret = 0; 558 int i, ret = 0;
559 uint64_t remains; 559 uint64_t remains;
560 uint64_t next_offset; 560 uint64_t next_offset;
@@ -1877,7 +1877,7 @@ static void switch_state(struct nandsim *ns)
1877 1877
1878static u_char ns_nand_read_byte(struct mtd_info *mtd) 1878static u_char ns_nand_read_byte(struct mtd_info *mtd)
1879{ 1879{
1880 struct nandsim *ns = (struct nandsim *)((struct nand_chip *)mtd->priv)->priv; 1880 struct nandsim *ns = ((struct nand_chip *)mtd->priv)->priv;
1881 u_char outb = 0x00; 1881 u_char outb = 0x00;
1882 1882
1883 /* Sanity and correctness checks */ 1883 /* Sanity and correctness checks */
@@ -1950,7 +1950,7 @@ static u_char ns_nand_read_byte(struct mtd_info *mtd)
1950 1950
1951static void ns_nand_write_byte(struct mtd_info *mtd, u_char byte) 1951static void ns_nand_write_byte(struct mtd_info *mtd, u_char byte)
1952{ 1952{
1953 struct nandsim *ns = (struct nandsim *)((struct nand_chip *)mtd->priv)->priv; 1953 struct nandsim *ns = ((struct nand_chip *)mtd->priv)->priv;
1954 1954
1955 /* Sanity and correctness checks */ 1955 /* Sanity and correctness checks */
1956 if (!ns->lines.ce) { 1956 if (!ns->lines.ce) {
@@ -2132,7 +2132,7 @@ static uint16_t ns_nand_read_word(struct mtd_info *mtd)
2132 2132
2133static void ns_nand_write_buf(struct mtd_info *mtd, const u_char *buf, int len) 2133static void ns_nand_write_buf(struct mtd_info *mtd, const u_char *buf, int len)
2134{ 2134{
2135 struct nandsim *ns = (struct nandsim *)((struct nand_chip *)mtd->priv)->priv; 2135 struct nandsim *ns = ((struct nand_chip *)mtd->priv)->priv;
2136 2136
2137 /* Check that chip is expecting data input */ 2137 /* Check that chip is expecting data input */
2138 if (!(ns->state & STATE_DATAIN_MASK)) { 2138 if (!(ns->state & STATE_DATAIN_MASK)) {
@@ -2159,7 +2159,7 @@ static void ns_nand_write_buf(struct mtd_info *mtd, const u_char *buf, int len)
2159 2159
2160static void ns_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len) 2160static void ns_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len)
2161{ 2161{
2162 struct nandsim *ns = (struct nandsim *)((struct nand_chip *)mtd->priv)->priv; 2162 struct nandsim *ns = ((struct nand_chip *)mtd->priv)->priv;
2163 2163
2164 /* Sanity and correctness checks */ 2164 /* Sanity and correctness checks */
2165 if (!ns->lines.ce) { 2165 if (!ns->lines.ce) {
@@ -2352,7 +2352,7 @@ module_init(ns_init_module);
2352 */ 2352 */
2353static void __exit ns_cleanup_module(void) 2353static void __exit ns_cleanup_module(void)
2354{ 2354{
2355 struct nandsim *ns = (struct nandsim *)(((struct nand_chip *)nsmtd->priv)->priv); 2355 struct nandsim *ns = ((struct nand_chip *)nsmtd->priv)->priv;
2356 int i; 2356 int i;
2357 2357
2358 free_nandsim(ns); /* Free nandsim private resources */ 2358 free_nandsim(ns); /* Free nandsim private resources */
diff --git a/drivers/mtd/nand/ndfc.c b/drivers/mtd/nand/ndfc.c
index 98fd2bdf8be1..510554e6c115 100644
--- a/drivers/mtd/nand/ndfc.c
+++ b/drivers/mtd/nand/ndfc.c
@@ -35,7 +35,7 @@
35 35
36 36
37struct ndfc_controller { 37struct ndfc_controller {
38 struct of_device *ofdev; 38 struct platform_device *ofdev;
39 void __iomem *ndfcbase; 39 void __iomem *ndfcbase;
40 struct mtd_info mtd; 40 struct mtd_info mtd;
41 struct nand_chip chip; 41 struct nand_chip chip;
@@ -225,7 +225,7 @@ err:
225 return ret; 225 return ret;
226} 226}
227 227
228static int __devinit ndfc_probe(struct of_device *ofdev, 228static int __devinit ndfc_probe(struct platform_device *ofdev,
229 const struct of_device_id *match) 229 const struct of_device_id *match)
230{ 230{
231 struct ndfc_controller *ndfc = &ndfc_ctrl; 231 struct ndfc_controller *ndfc = &ndfc_ctrl;
@@ -277,7 +277,7 @@ static int __devinit ndfc_probe(struct of_device *ofdev,
277 return 0; 277 return 0;
278} 278}
279 279
280static int __devexit ndfc_remove(struct of_device *ofdev) 280static int __devexit ndfc_remove(struct platform_device *ofdev)
281{ 281{
282 struct ndfc_controller *ndfc = dev_get_drvdata(&ofdev->dev); 282 struct ndfc_controller *ndfc = dev_get_drvdata(&ofdev->dev);
283 283
diff --git a/drivers/mtd/nand/omap2.c b/drivers/mtd/nand/omap2.c
index ee87325c7712..133d51528f8d 100644
--- a/drivers/mtd/nand/omap2.c
+++ b/drivers/mtd/nand/omap2.c
@@ -7,6 +7,7 @@
7 * it under the terms of the GNU General Public License version 2 as 7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation. 8 * published by the Free Software Foundation.
9 */ 9 */
10#define CONFIG_MTD_NAND_OMAP_HWECC
10 11
11#include <linux/platform_device.h> 12#include <linux/platform_device.h>
12#include <linux/dma-mapping.h> 13#include <linux/dma-mapping.h>
@@ -23,20 +24,8 @@
23#include <plat/gpmc.h> 24#include <plat/gpmc.h>
24#include <plat/nand.h> 25#include <plat/nand.h>
25 26
26#define GPMC_IRQ_STATUS 0x18
27#define GPMC_ECC_CONFIG 0x1F4
28#define GPMC_ECC_CONTROL 0x1F8
29#define GPMC_ECC_SIZE_CONFIG 0x1FC
30#define GPMC_ECC1_RESULT 0x200
31
32#define DRIVER_NAME "omap2-nand" 27#define DRIVER_NAME "omap2-nand"
33 28
34#define NAND_WP_OFF 0
35#define NAND_WP_BIT 0x00000010
36
37#define GPMC_BUF_FULL 0x00000001
38#define GPMC_BUF_EMPTY 0x00000000
39
40#define NAND_Ecc_P1e (1 << 0) 29#define NAND_Ecc_P1e (1 << 0)
41#define NAND_Ecc_P2e (1 << 1) 30#define NAND_Ecc_P2e (1 << 1)
42#define NAND_Ecc_P4e (1 << 2) 31#define NAND_Ecc_P4e (1 << 2)
@@ -139,34 +128,11 @@ struct omap_nand_info {
139 128
140 int gpmc_cs; 129 int gpmc_cs;
141 unsigned long phys_base; 130 unsigned long phys_base;
142 void __iomem *gpmc_cs_baseaddr;
143 void __iomem *gpmc_baseaddr;
144 void __iomem *nand_pref_fifo_add;
145 struct completion comp; 131 struct completion comp;
146 int dma_ch; 132 int dma_ch;
147}; 133};
148 134
149/** 135/**
150 * omap_nand_wp - This function enable or disable the Write Protect feature
151 * @mtd: MTD device structure
152 * @mode: WP ON/OFF
153 */
154static void omap_nand_wp(struct mtd_info *mtd, int mode)
155{
156 struct omap_nand_info *info = container_of(mtd,
157 struct omap_nand_info, mtd);
158
159 unsigned long config = __raw_readl(info->gpmc_baseaddr + GPMC_CONFIG);
160
161 if (mode)
162 config &= ~(NAND_WP_BIT); /* WP is ON */
163 else
164 config |= (NAND_WP_BIT); /* WP is OFF */
165
166 __raw_writel(config, (info->gpmc_baseaddr + GPMC_CONFIG));
167}
168
169/**
170 * omap_hwcontrol - hardware specific access to control-lines 136 * omap_hwcontrol - hardware specific access to control-lines
171 * @mtd: MTD device structure 137 * @mtd: MTD device structure
172 * @cmd: command to device 138 * @cmd: command to device
@@ -181,31 +147,17 @@ static void omap_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl)
181{ 147{
182 struct omap_nand_info *info = container_of(mtd, 148 struct omap_nand_info *info = container_of(mtd,
183 struct omap_nand_info, mtd); 149 struct omap_nand_info, mtd);
184 switch (ctrl) {
185 case NAND_CTRL_CHANGE | NAND_CTRL_CLE:
186 info->nand.IO_ADDR_W = info->gpmc_cs_baseaddr +
187 GPMC_CS_NAND_COMMAND;
188 info->nand.IO_ADDR_R = info->gpmc_cs_baseaddr +
189 GPMC_CS_NAND_DATA;
190 break;
191
192 case NAND_CTRL_CHANGE | NAND_CTRL_ALE:
193 info->nand.IO_ADDR_W = info->gpmc_cs_baseaddr +
194 GPMC_CS_NAND_ADDRESS;
195 info->nand.IO_ADDR_R = info->gpmc_cs_baseaddr +
196 GPMC_CS_NAND_DATA;
197 break;
198
199 case NAND_CTRL_CHANGE | NAND_NCE:
200 info->nand.IO_ADDR_W = info->gpmc_cs_baseaddr +
201 GPMC_CS_NAND_DATA;
202 info->nand.IO_ADDR_R = info->gpmc_cs_baseaddr +
203 GPMC_CS_NAND_DATA;
204 break;
205 }
206 150
207 if (cmd != NAND_CMD_NONE) 151 if (cmd != NAND_CMD_NONE) {
208 __raw_writeb(cmd, info->nand.IO_ADDR_W); 152 if (ctrl & NAND_CLE)
153 gpmc_nand_write(info->gpmc_cs, GPMC_NAND_COMMAND, cmd);
154
155 else if (ctrl & NAND_ALE)
156 gpmc_nand_write(info->gpmc_cs, GPMC_NAND_ADDRESS, cmd);
157
158 else /* NAND_NCE */
159 gpmc_nand_write(info->gpmc_cs, GPMC_NAND_DATA, cmd);
160 }
209} 161}
210 162
211/** 163/**
@@ -232,11 +184,14 @@ static void omap_write_buf8(struct mtd_info *mtd, const u_char *buf, int len)
232 struct omap_nand_info *info = container_of(mtd, 184 struct omap_nand_info *info = container_of(mtd,
233 struct omap_nand_info, mtd); 185 struct omap_nand_info, mtd);
234 u_char *p = (u_char *)buf; 186 u_char *p = (u_char *)buf;
187 u32 status = 0;
235 188
236 while (len--) { 189 while (len--) {
237 iowrite8(*p++, info->nand.IO_ADDR_W); 190 iowrite8(*p++, info->nand.IO_ADDR_W);
238 while (GPMC_BUF_EMPTY == (readl(info->gpmc_baseaddr + 191 /* wait until buffer is available for write */
239 GPMC_STATUS) & GPMC_BUF_FULL)); 192 do {
193 status = gpmc_read_status(GPMC_STATUS_BUFFER);
194 } while (!status);
240 } 195 }
241} 196}
242 197
@@ -264,16 +219,16 @@ static void omap_write_buf16(struct mtd_info *mtd, const u_char * buf, int len)
264 struct omap_nand_info *info = container_of(mtd, 219 struct omap_nand_info *info = container_of(mtd,
265 struct omap_nand_info, mtd); 220 struct omap_nand_info, mtd);
266 u16 *p = (u16 *) buf; 221 u16 *p = (u16 *) buf;
267 222 u32 status = 0;
268 /* FIXME try bursts of writesw() or DMA ... */ 223 /* FIXME try bursts of writesw() or DMA ... */
269 len >>= 1; 224 len >>= 1;
270 225
271 while (len--) { 226 while (len--) {
272 iowrite16(*p++, info->nand.IO_ADDR_W); 227 iowrite16(*p++, info->nand.IO_ADDR_W);
273 228 /* wait until buffer is available for write */
274 while (GPMC_BUF_EMPTY == (readl(info->gpmc_baseaddr + 229 do {
275 GPMC_STATUS) & GPMC_BUF_FULL)) 230 status = gpmc_read_status(GPMC_STATUS_BUFFER);
276 ; 231 } while (!status);
277 } 232 }
278} 233}
279 234
@@ -287,7 +242,7 @@ static void omap_read_buf_pref(struct mtd_info *mtd, u_char *buf, int len)
287{ 242{
288 struct omap_nand_info *info = container_of(mtd, 243 struct omap_nand_info *info = container_of(mtd,
289 struct omap_nand_info, mtd); 244 struct omap_nand_info, mtd);
290 uint32_t pfpw_status = 0, r_count = 0; 245 uint32_t r_count = 0;
291 int ret = 0; 246 int ret = 0;
292 u32 *p = (u32 *)buf; 247 u32 *p = (u32 *)buf;
293 248
@@ -310,16 +265,16 @@ static void omap_read_buf_pref(struct mtd_info *mtd, u_char *buf, int len)
310 else 265 else
311 omap_read_buf8(mtd, buf, len); 266 omap_read_buf8(mtd, buf, len);
312 } else { 267 } else {
268 p = (u32 *) buf;
313 do { 269 do {
314 pfpw_status = gpmc_prefetch_status(); 270 r_count = gpmc_read_status(GPMC_PREFETCH_FIFO_CNT);
315 r_count = ((pfpw_status >> 24) & 0x7F) >> 2; 271 r_count = r_count >> 2;
316 ioread32_rep(info->nand_pref_fifo_add, p, r_count); 272 ioread32_rep(info->nand.IO_ADDR_R, p, r_count);
317 p += r_count; 273 p += r_count;
318 len -= r_count << 2; 274 len -= r_count << 2;
319 } while (len); 275 } while (len);
320
321 /* disable and stop the PFPW engine */ 276 /* disable and stop the PFPW engine */
322 gpmc_prefetch_reset(); 277 gpmc_prefetch_reset(info->gpmc_cs);
323 } 278 }
324} 279}
325 280
@@ -334,13 +289,13 @@ static void omap_write_buf_pref(struct mtd_info *mtd,
334{ 289{
335 struct omap_nand_info *info = container_of(mtd, 290 struct omap_nand_info *info = container_of(mtd,
336 struct omap_nand_info, mtd); 291 struct omap_nand_info, mtd);
337 uint32_t pfpw_status = 0, w_count = 0; 292 uint32_t pref_count = 0, w_count = 0;
338 int i = 0, ret = 0; 293 int i = 0, ret = 0;
339 u16 *p = (u16 *) buf; 294 u16 *p;
340 295
341 /* take care of subpage writes */ 296 /* take care of subpage writes */
342 if (len % 2 != 0) { 297 if (len % 2 != 0) {
343 writeb(*buf, info->nand.IO_ADDR_R); 298 writeb(*buf, info->nand.IO_ADDR_W);
344 p = (u16 *)(buf + 1); 299 p = (u16 *)(buf + 1);
345 len--; 300 len--;
346 } 301 }
@@ -354,16 +309,19 @@ static void omap_write_buf_pref(struct mtd_info *mtd,
354 else 309 else
355 omap_write_buf8(mtd, buf, len); 310 omap_write_buf8(mtd, buf, len);
356 } else { 311 } else {
357 pfpw_status = gpmc_prefetch_status(); 312 p = (u16 *) buf;
358 while (pfpw_status & 0x3FFF) { 313 while (len) {
359 w_count = ((pfpw_status >> 24) & 0x7F) >> 1; 314 w_count = gpmc_read_status(GPMC_PREFETCH_FIFO_CNT);
315 w_count = w_count >> 1;
360 for (i = 0; (i < w_count) && len; i++, len -= 2) 316 for (i = 0; (i < w_count) && len; i++, len -= 2)
361 iowrite16(*p++, info->nand_pref_fifo_add); 317 iowrite16(*p++, info->nand.IO_ADDR_W);
362 pfpw_status = gpmc_prefetch_status();
363 } 318 }
364 319 /* wait for data to flushed-out before reset the prefetch */
320 do {
321 pref_count = gpmc_read_status(GPMC_PREFETCH_COUNT);
322 } while (pref_count);
365 /* disable and stop the PFPW engine */ 323 /* disable and stop the PFPW engine */
366 gpmc_prefetch_reset(); 324 gpmc_prefetch_reset(info->gpmc_cs);
367 } 325 }
368} 326}
369 327
@@ -451,8 +409,9 @@ static inline int omap_nand_dma_transfer(struct mtd_info *mtd, void *addr,
451 /* setup and start DMA using dma_addr */ 409 /* setup and start DMA using dma_addr */
452 wait_for_completion(&info->comp); 410 wait_for_completion(&info->comp);
453 411
454 while (0x3fff & (prefetch_status = gpmc_prefetch_status())) 412 do {
455 ; 413 prefetch_status = gpmc_read_status(GPMC_PREFETCH_COUNT);
414 } while (prefetch_status);
456 /* disable and stop the PFPW engine */ 415 /* disable and stop the PFPW engine */
457 gpmc_prefetch_reset(); 416 gpmc_prefetch_reset();
458 417
@@ -530,29 +489,6 @@ static int omap_verify_buf(struct mtd_info *mtd, const u_char * buf, int len)
530} 489}
531 490
532#ifdef CONFIG_MTD_NAND_OMAP_HWECC 491#ifdef CONFIG_MTD_NAND_OMAP_HWECC
533/**
534 * omap_hwecc_init - Initialize the HW ECC for NAND flash in GPMC controller
535 * @mtd: MTD device structure
536 */
537static void omap_hwecc_init(struct mtd_info *mtd)
538{
539 struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
540 mtd);
541 struct nand_chip *chip = mtd->priv;
542 unsigned long val = 0x0;
543
544 /* Read from ECC Control Register */
545 val = __raw_readl(info->gpmc_baseaddr + GPMC_ECC_CONTROL);
546 /* Clear all ECC | Enable Reg1 */
547 val = ((0x00000001<<8) | 0x00000001);
548 __raw_writel(val, info->gpmc_baseaddr + GPMC_ECC_CONTROL);
549
550 /* Read from ECC Size Config Register */
551 val = __raw_readl(info->gpmc_baseaddr + GPMC_ECC_SIZE_CONFIG);
552 /* ECCSIZE1=512 | Select eccResultsize[0-3] */
553 val = ((((chip->ecc.size >> 1) - 1) << 22) | (0x0000000F));
554 __raw_writel(val, info->gpmc_baseaddr + GPMC_ECC_SIZE_CONFIG);
555}
556 492
557/** 493/**
558 * gen_true_ecc - This function will generate true ECC value 494 * gen_true_ecc - This function will generate true ECC value
@@ -755,19 +691,7 @@ static int omap_calculate_ecc(struct mtd_info *mtd, const u_char *dat,
755{ 691{
756 struct omap_nand_info *info = container_of(mtd, struct omap_nand_info, 692 struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
757 mtd); 693 mtd);
758 unsigned long val = 0x0; 694 return gpmc_calculate_ecc(info->gpmc_cs, dat, ecc_code);
759 unsigned long reg;
760
761 /* Start Reading from HW ECC1_Result = 0x200 */
762 reg = (unsigned long)(info->gpmc_baseaddr + GPMC_ECC1_RESULT);
763 val = __raw_readl(reg);
764 *ecc_code++ = val; /* P128e, ..., P1e */
765 *ecc_code++ = val >> 16; /* P128o, ..., P1o */
766 /* P2048o, P1024o, P512o, P256o, P2048e, P1024e, P512e, P256e */
767 *ecc_code++ = ((val >> 8) & 0x0f) | ((val >> 20) & 0xf0);
768 reg += 4;
769
770 return 0;
771} 695}
772 696
773/** 697/**
@@ -781,32 +705,10 @@ static void omap_enable_hwecc(struct mtd_info *mtd, int mode)
781 mtd); 705 mtd);
782 struct nand_chip *chip = mtd->priv; 706 struct nand_chip *chip = mtd->priv;
783 unsigned int dev_width = (chip->options & NAND_BUSWIDTH_16) ? 1 : 0; 707 unsigned int dev_width = (chip->options & NAND_BUSWIDTH_16) ? 1 : 0;
784 unsigned long val = __raw_readl(info->gpmc_baseaddr + GPMC_ECC_CONFIG);
785
786 switch (mode) {
787 case NAND_ECC_READ:
788 __raw_writel(0x101, info->gpmc_baseaddr + GPMC_ECC_CONTROL);
789 /* (ECC 16 or 8 bit col) | ( CS ) | ECC Enable */
790 val = (dev_width << 7) | (info->gpmc_cs << 1) | (0x1);
791 break;
792 case NAND_ECC_READSYN:
793 __raw_writel(0x100, info->gpmc_baseaddr + GPMC_ECC_CONTROL);
794 /* (ECC 16 or 8 bit col) | ( CS ) | ECC Enable */
795 val = (dev_width << 7) | (info->gpmc_cs << 1) | (0x1);
796 break;
797 case NAND_ECC_WRITE:
798 __raw_writel(0x101, info->gpmc_baseaddr + GPMC_ECC_CONTROL);
799 /* (ECC 16 or 8 bit col) | ( CS ) | ECC Enable */
800 val = (dev_width << 7) | (info->gpmc_cs << 1) | (0x1);
801 break;
802 default:
803 DEBUG(MTD_DEBUG_LEVEL0, "Error: Unrecognized Mode[%d]!\n",
804 mode);
805 break;
806 }
807 708
808 __raw_writel(val, info->gpmc_baseaddr + GPMC_ECC_CONFIG); 709 gpmc_enable_hwecc(info->gpmc_cs, mode, dev_width, info->nand.ecc.size);
809} 710}
711
810#endif 712#endif
811 713
812/** 714/**
@@ -834,14 +736,10 @@ static int omap_wait(struct mtd_info *mtd, struct nand_chip *chip)
834 else 736 else
835 timeo += (HZ * 20) / 1000; 737 timeo += (HZ * 20) / 1000;
836 738
837 this->IO_ADDR_W = (void *) info->gpmc_cs_baseaddr + 739 gpmc_nand_write(info->gpmc_cs,
838 GPMC_CS_NAND_COMMAND; 740 GPMC_NAND_COMMAND, (NAND_CMD_STATUS & 0xFF));
839 this->IO_ADDR_R = (void *) info->gpmc_cs_baseaddr + GPMC_CS_NAND_DATA;
840
841 __raw_writeb(NAND_CMD_STATUS & 0xFF, this->IO_ADDR_W);
842
843 while (time_before(jiffies, timeo)) { 741 while (time_before(jiffies, timeo)) {
844 status = __raw_readb(this->IO_ADDR_R); 742 status = gpmc_nand_read(info->gpmc_cs, GPMC_NAND_DATA);
845 if (status & NAND_STATUS_READY) 743 if (status & NAND_STATUS_READY)
846 break; 744 break;
847 cond_resched(); 745 cond_resched();
@@ -855,22 +753,22 @@ static int omap_wait(struct mtd_info *mtd, struct nand_chip *chip)
855 */ 753 */
856static int omap_dev_ready(struct mtd_info *mtd) 754static int omap_dev_ready(struct mtd_info *mtd)
857{ 755{
756 unsigned int val = 0;
858 struct omap_nand_info *info = container_of(mtd, struct omap_nand_info, 757 struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
859 mtd); 758 mtd);
860 unsigned int val = __raw_readl(info->gpmc_baseaddr + GPMC_IRQ_STATUS);
861 759
760 val = gpmc_read_status(GPMC_GET_IRQ_STATUS);
862 if ((val & 0x100) == 0x100) { 761 if ((val & 0x100) == 0x100) {
863 /* Clear IRQ Interrupt */ 762 /* Clear IRQ Interrupt */
864 val |= 0x100; 763 val |= 0x100;
865 val &= ~(0x0); 764 val &= ~(0x0);
866 __raw_writel(val, info->gpmc_baseaddr + GPMC_IRQ_STATUS); 765 gpmc_cs_configure(info->gpmc_cs, GPMC_SET_IRQ_STATUS, val);
867 } else { 766 } else {
868 unsigned int cnt = 0; 767 unsigned int cnt = 0;
869 while (cnt++ < 0x1FF) { 768 while (cnt++ < 0x1FF) {
870 if ((val & 0x100) == 0x100) 769 if ((val & 0x100) == 0x100)
871 return 0; 770 return 0;
872 val = __raw_readl(info->gpmc_baseaddr + 771 val = gpmc_read_status(GPMC_GET_IRQ_STATUS);
873 GPMC_IRQ_STATUS);
874 } 772 }
875 } 773 }
876 774
@@ -901,8 +799,6 @@ static int __devinit omap_nand_probe(struct platform_device *pdev)
901 info->pdev = pdev; 799 info->pdev = pdev;
902 800
903 info->gpmc_cs = pdata->cs; 801 info->gpmc_cs = pdata->cs;
904 info->gpmc_baseaddr = pdata->gpmc_baseaddr;
905 info->gpmc_cs_baseaddr = pdata->gpmc_cs_baseaddr;
906 info->phys_base = pdata->phys_base; 802 info->phys_base = pdata->phys_base;
907 803
908 info->mtd.priv = &info->nand; 804 info->mtd.priv = &info->nand;
@@ -913,7 +809,7 @@ static int __devinit omap_nand_probe(struct platform_device *pdev)
913 info->nand.options |= NAND_SKIP_BBTSCAN; 809 info->nand.options |= NAND_SKIP_BBTSCAN;
914 810
915 /* NAND write protect off */ 811 /* NAND write protect off */
916 omap_nand_wp(&info->mtd, NAND_WP_OFF); 812 gpmc_cs_configure(info->gpmc_cs, GPMC_CONFIG_WP, 0);
917 813
918 if (!request_mem_region(info->phys_base, NAND_IO_SIZE, 814 if (!request_mem_region(info->phys_base, NAND_IO_SIZE,
919 pdev->dev.driver->name)) { 815 pdev->dev.driver->name)) {
@@ -948,8 +844,6 @@ static int __devinit omap_nand_probe(struct platform_device *pdev)
948 } 844 }
949 845
950 if (use_prefetch) { 846 if (use_prefetch) {
951 /* copy the virtual address of nand base for fifo access */
952 info->nand_pref_fifo_add = info->nand.IO_ADDR_R;
953 847
954 info->nand.read_buf = omap_read_buf_pref; 848 info->nand.read_buf = omap_read_buf_pref;
955 info->nand.write_buf = omap_write_buf_pref; 849 info->nand.write_buf = omap_write_buf_pref;
@@ -989,8 +883,6 @@ static int __devinit omap_nand_probe(struct platform_device *pdev)
989 info->nand.ecc.correct = omap_correct_data; 883 info->nand.ecc.correct = omap_correct_data;
990 info->nand.ecc.mode = NAND_ECC_HW; 884 info->nand.ecc.mode = NAND_ECC_HW;
991 885
992 /* init HW ECC */
993 omap_hwecc_init(&info->mtd);
994#else 886#else
995 info->nand.ecc.mode = NAND_ECC_SOFT; 887 info->nand.ecc.mode = NAND_ECC_SOFT;
996#endif 888#endif
@@ -1040,7 +932,7 @@ static int omap_nand_remove(struct platform_device *pdev)
1040 932
1041 /* Release NAND device, its internal structures and partitions */ 933 /* Release NAND device, its internal structures and partitions */
1042 nand_release(&info->mtd); 934 nand_release(&info->mtd);
1043 iounmap(info->nand_pref_fifo_add); 935 iounmap(info->nand.IO_ADDR_R);
1044 kfree(&info->mtd); 936 kfree(&info->mtd);
1045 return 0; 937 return 0;
1046} 938}
diff --git a/drivers/mtd/nand/pasemi_nand.c b/drivers/mtd/nand/pasemi_nand.c
index f02af24d033a..6ddb2461d740 100644
--- a/drivers/mtd/nand/pasemi_nand.c
+++ b/drivers/mtd/nand/pasemi_nand.c
@@ -89,7 +89,7 @@ int pasemi_device_ready(struct mtd_info *mtd)
89 return !!(inl(lpcctl) & LBICTRL_LPCCTL_NR); 89 return !!(inl(lpcctl) & LBICTRL_LPCCTL_NR);
90} 90}
91 91
92static int __devinit pasemi_nand_probe(struct of_device *ofdev, 92static int __devinit pasemi_nand_probe(struct platform_device *ofdev,
93 const struct of_device_id *match) 93 const struct of_device_id *match)
94{ 94{
95 struct pci_dev *pdev; 95 struct pci_dev *pdev;
@@ -185,7 +185,7 @@ static int __devinit pasemi_nand_probe(struct of_device *ofdev,
185 return err; 185 return err;
186} 186}
187 187
188static int __devexit pasemi_nand_remove(struct of_device *ofdev) 188static int __devexit pasemi_nand_remove(struct platform_device *ofdev)
189{ 189{
190 struct nand_chip *chip; 190 struct nand_chip *chip;
191 191
diff --git a/drivers/mtd/nand/plat_nand.c b/drivers/mtd/nand/plat_nand.c
index 8d467315f02b..317aff428e42 100644
--- a/drivers/mtd/nand/plat_nand.c
+++ b/drivers/mtd/nand/plat_nand.c
@@ -37,6 +37,11 @@ static int __devinit plat_nand_probe(struct platform_device *pdev)
37 struct resource *res; 37 struct resource *res;
38 int err = 0; 38 int err = 0;
39 39
40 if (pdata->chip.nr_chips < 1) {
41 dev_err(&pdev->dev, "invalid number of chips specified\n");
42 return -EINVAL;
43 }
44
40 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 45 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
41 if (!res) 46 if (!res)
42 return -ENXIO; 47 return -ENXIO;
@@ -91,7 +96,7 @@ static int __devinit plat_nand_probe(struct platform_device *pdev)
91 } 96 }
92 97
93 /* Scan to find existance of the device */ 98 /* Scan to find existance of the device */
94 if (nand_scan(&data->mtd, 1)) { 99 if (nand_scan(&data->mtd, pdata->chip.nr_chips)) {
95 err = -ENXIO; 100 err = -ENXIO;
96 goto out; 101 goto out;
97 } 102 }
diff --git a/drivers/mtd/nand/r852.c b/drivers/mtd/nand/r852.c
index bcfc851fe550..5169ca6a66bc 100644
--- a/drivers/mtd/nand/r852.c
+++ b/drivers/mtd/nand/r852.c
@@ -64,8 +64,8 @@ static inline void r852_write_reg_dword(struct r852_device *dev,
64/* returns pointer to our private structure */ 64/* returns pointer to our private structure */
65static inline struct r852_device *r852_get_dev(struct mtd_info *mtd) 65static inline struct r852_device *r852_get_dev(struct mtd_info *mtd)
66{ 66{
67 struct nand_chip *chip = (struct nand_chip *)mtd->priv; 67 struct nand_chip *chip = mtd->priv;
68 return (struct r852_device *)chip->priv; 68 return chip->priv;
69} 69}
70 70
71 71
@@ -380,7 +380,7 @@ void r852_cmdctl(struct mtd_info *mtd, int dat, unsigned int ctrl)
380 */ 380 */
381int r852_wait(struct mtd_info *mtd, struct nand_chip *chip) 381int r852_wait(struct mtd_info *mtd, struct nand_chip *chip)
382{ 382{
383 struct r852_device *dev = (struct r852_device *)chip->priv; 383 struct r852_device *dev = chip->priv;
384 384
385 unsigned long timeout; 385 unsigned long timeout;
386 int status; 386 int status;
diff --git a/drivers/mtd/nand/rtc_from4.c b/drivers/mtd/nand/rtc_from4.c
index a033c4cd8e16..67440b5beef8 100644
--- a/drivers/mtd/nand/rtc_from4.c
+++ b/drivers/mtd/nand/rtc_from4.c
@@ -24,7 +24,6 @@
24#include <linux/rslib.h> 24#include <linux/rslib.h>
25#include <linux/bitrev.h> 25#include <linux/bitrev.h>
26#include <linux/module.h> 26#include <linux/module.h>
27#include <linux/mtd/compatmac.h>
28#include <linux/mtd/mtd.h> 27#include <linux/mtd/mtd.h>
29#include <linux/mtd/nand.h> 28#include <linux/mtd/nand.h>
30#include <linux/mtd/partitions.h> 29#include <linux/mtd/partitions.h>
diff --git a/drivers/mtd/nand/s3c2410.c b/drivers/mtd/nand/s3c2410.c
index 239aadfd01b0..33d832dddfdd 100644
--- a/drivers/mtd/nand/s3c2410.c
+++ b/drivers/mtd/nand/s3c2410.c
@@ -727,15 +727,12 @@ static int s3c2410_nand_add_partition(struct s3c2410_nand_info *info,
727 if (set == NULL) 727 if (set == NULL)
728 return add_mtd_device(&mtd->mtd); 728 return add_mtd_device(&mtd->mtd);
729 729
730 if (set->nr_partitions == 0) { 730 mtd->mtd.name = set->name;
731 mtd->mtd.name = set->name; 731 nr_part = parse_mtd_partitions(&mtd->mtd, part_probes, &part_info, 0);
732 nr_part = parse_mtd_partitions(&mtd->mtd, part_probes, 732
733 &part_info, 0); 733 if (nr_part <= 0 && set->nr_partitions > 0) {
734 } else { 734 nr_part = set->nr_partitions;
735 if (set->nr_partitions > 0 && set->partitions != NULL) { 735 part_info = set->partitions;
736 nr_part = set->nr_partitions;
737 part_info = set->partitions;
738 }
739 } 736 }
740 737
741 if (nr_part > 0 && part_info) 738 if (nr_part > 0 && part_info)
diff --git a/drivers/mtd/nand/sm_common.c b/drivers/mtd/nand/sm_common.c
index ac80fb362e63..4a8f367c295c 100644
--- a/drivers/mtd/nand/sm_common.c
+++ b/drivers/mtd/nand/sm_common.c
@@ -109,7 +109,7 @@ static struct nand_flash_dev nand_xd_flash_ids[] = {
109 109
110int sm_register_device(struct mtd_info *mtd, int smartmedia) 110int sm_register_device(struct mtd_info *mtd, int smartmedia)
111{ 111{
112 struct nand_chip *chip = (struct nand_chip *)mtd->priv; 112 struct nand_chip *chip = mtd->priv;
113 int ret; 113 int ret;
114 114
115 chip->options |= NAND_SKIP_BBTSCAN; 115 chip->options |= NAND_SKIP_BBTSCAN;
diff --git a/drivers/mtd/nand/socrates_nand.c b/drivers/mtd/nand/socrates_nand.c
index cc728b12de82..a8e403eebedb 100644
--- a/drivers/mtd/nand/socrates_nand.c
+++ b/drivers/mtd/nand/socrates_nand.c
@@ -162,7 +162,7 @@ static const char *part_probes[] = { "cmdlinepart", NULL };
162/* 162/*
163 * Probe for the NAND device. 163 * Probe for the NAND device.
164 */ 164 */
165static int __devinit socrates_nand_probe(struct of_device *ofdev, 165static int __devinit socrates_nand_probe(struct platform_device *ofdev,
166 const struct of_device_id *ofid) 166 const struct of_device_id *ofid)
167{ 167{
168 struct socrates_nand_host *host; 168 struct socrates_nand_host *host;
@@ -276,7 +276,7 @@ out:
276/* 276/*
277 * Remove a NAND device. 277 * Remove a NAND device.
278 */ 278 */
279static int __devexit socrates_nand_remove(struct of_device *ofdev) 279static int __devexit socrates_nand_remove(struct platform_device *ofdev)
280{ 280{
281 struct socrates_nand_host *host = dev_get_drvdata(&ofdev->dev); 281 struct socrates_nand_host *host = dev_get_drvdata(&ofdev->dev);
282 struct mtd_info *mtd = &host->mtd; 282 struct mtd_info *mtd = &host->mtd;
diff --git a/drivers/mtd/nftlcore.c b/drivers/mtd/nftlcore.c
index a4578bf903aa..b155666acfbe 100644
--- a/drivers/mtd/nftlcore.c
+++ b/drivers/mtd/nftlcore.c
@@ -1,11 +1,22 @@
1/* Linux driver for NAND Flash Translation Layer */
2/* (c) 1999 Machine Vision Holdings, Inc. */
3/* Author: David Woodhouse <dwmw2@infradead.org> */
4
5/* 1/*
6 The contents of this file are distributed under the GNU General 2 * Linux driver for NAND Flash Translation Layer
7 Public License version 2. The author places no additional 3 *
8 restrictions of any kind on it. 4 * Copyright © 1999 Machine Vision Holdings, Inc.
5 * Copyright © 1999-2010 David Woodhouse <dwmw2@infradead.org>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
9 */ 20 */
10 21
11#define PRERELEASE 22#define PRERELEASE
diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
index 8b22b1836e9f..e3cd1ffad2f6 100644
--- a/drivers/mtd/nftlmount.c
+++ b/drivers/mtd/nftlmount.c
@@ -2,7 +2,8 @@
2 * NFTL mount code with extensive checks 2 * NFTL mount code with extensive checks
3 * 3 *
4 * Author: Fabrice Bellard (fabrice.bellard@netgem.com) 4 * Author: Fabrice Bellard (fabrice.bellard@netgem.com)
5 * Copyright (C) 2000 Netgem S.A. 5 * Copyright © 2000 Netgem S.A.
6 * Copyright © 1999-2010 David Woodhouse <dwmw2@infradead.org>
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 as published by 9 * it under the terms of the GNU General Public License as published by
diff --git a/drivers/mtd/ofpart.c b/drivers/mtd/ofpart.c
index 4f0d635674f3..8bf7dc6d1ce6 100644
--- a/drivers/mtd/ofpart.c
+++ b/drivers/mtd/ofpart.c
@@ -1,11 +1,11 @@
1/* 1/*
2 * Flash partitions described by the OF (or flattened) device tree 2 * Flash partitions described by the OF (or flattened) device tree
3 * 3 *
4 * Copyright (C) 2006 MontaVista Software Inc. 4 * Copyright © 2006 MontaVista Software Inc.
5 * Author: Vitaly Wool <vwool@ru.mvista.com> 5 * Author: Vitaly Wool <vwool@ru.mvista.com>
6 * 6 *
7 * Revised to handle newer style flash binding by: 7 * Revised to handle newer style flash binding by:
8 * Copyright (C) 2007 David Gibson, IBM Corporation. 8 * Copyright © 2007 David Gibson, IBM Corporation.
9 * 9 *
10 * This program is free software; you can redistribute it and/or modify it 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 11 * under the terms of the GNU General Public License as published by the
diff --git a/drivers/mtd/onenand/Kconfig b/drivers/mtd/onenand/Kconfig
index 9a49d68ba5f9..3f32289fdbb5 100644
--- a/drivers/mtd/onenand/Kconfig
+++ b/drivers/mtd/onenand/Kconfig
@@ -25,14 +25,14 @@ config MTD_ONENAND_GENERIC
25 25
26config MTD_ONENAND_OMAP2 26config MTD_ONENAND_OMAP2
27 tristate "OneNAND on OMAP2/OMAP3 support" 27 tristate "OneNAND on OMAP2/OMAP3 support"
28 depends on MTD_ONENAND && (ARCH_OMAP2 || ARCH_OMAP3) 28 depends on ARCH_OMAP2 || ARCH_OMAP3
29 help 29 help
30 Support for a OneNAND flash device connected to an OMAP2/OMAP3 CPU 30 Support for a OneNAND flash device connected to an OMAP2/OMAP3 CPU
31 via the GPMC memory controller. 31 via the GPMC memory controller.
32 32
33config MTD_ONENAND_SAMSUNG 33config MTD_ONENAND_SAMSUNG
34 tristate "OneNAND on Samsung SOC controller support" 34 tristate "OneNAND on Samsung SOC controller support"
35 depends on MTD_ONENAND && (ARCH_S3C64XX || ARCH_S5PC100 || ARCH_S5PV210) 35 depends on ARCH_S3C64XX || ARCH_S5PC100 || ARCH_S5PV210
36 help 36 help
37 Support for a OneNAND flash device connected to an Samsung SOC 37 Support for a OneNAND flash device connected to an Samsung SOC
38 S3C64XX/S5PC1XX controller. 38 S3C64XX/S5PC1XX controller.
diff --git a/drivers/mtd/onenand/onenand_base.c b/drivers/mtd/onenand/onenand_base.c
index 26caf2590dae..a2bb520286f8 100644
--- a/drivers/mtd/onenand/onenand_base.c
+++ b/drivers/mtd/onenand/onenand_base.c
@@ -377,8 +377,11 @@ static int onenand_command(struct mtd_info *mtd, int cmd, loff_t addr, size_t le
377 377
378 default: 378 default:
379 block = onenand_block(this, addr); 379 block = onenand_block(this, addr);
380 page = (int) (addr - onenand_addr(this, block)) >> this->page_shift; 380 if (FLEXONENAND(this))
381 381 page = (int) (addr - onenand_addr(this, block))>>\
382 this->page_shift;
383 else
384 page = (int) (addr >> this->page_shift);
382 if (ONENAND_IS_2PLANE(this)) { 385 if (ONENAND_IS_2PLANE(this)) {
383 /* Make the even block number */ 386 /* Make the even block number */
384 block &= ~1; 387 block &= ~1;
@@ -3730,17 +3733,16 @@ out:
3730} 3733}
3731 3734
3732/** 3735/**
3733 * onenand_probe - [OneNAND Interface] Probe the OneNAND device 3736 * onenand_chip_probe - [OneNAND Interface] The generic chip probe
3734 * @param mtd MTD device structure 3737 * @param mtd MTD device structure
3735 * 3738 *
3736 * OneNAND detection method: 3739 * OneNAND detection method:
3737 * Compare the values from command with ones from register 3740 * Compare the values from command with ones from register
3738 */ 3741 */
3739static int onenand_probe(struct mtd_info *mtd) 3742static int onenand_chip_probe(struct mtd_info *mtd)
3740{ 3743{
3741 struct onenand_chip *this = mtd->priv; 3744 struct onenand_chip *this = mtd->priv;
3742 int bram_maf_id, bram_dev_id, maf_id, dev_id, ver_id; 3745 int bram_maf_id, bram_dev_id, maf_id, dev_id;
3743 int density;
3744 int syscfg; 3746 int syscfg;
3745 3747
3746 /* Save system configuration 1 */ 3748 /* Save system configuration 1 */
@@ -3763,12 +3765,6 @@ static int onenand_probe(struct mtd_info *mtd)
3763 /* Restore system configuration 1 */ 3765 /* Restore system configuration 1 */
3764 this->write_word(syscfg, this->base + ONENAND_REG_SYS_CFG1); 3766 this->write_word(syscfg, this->base + ONENAND_REG_SYS_CFG1);
3765 3767
3766 /* Workaround */
3767 if (syscfg & ONENAND_SYS_CFG1_SYNC_WRITE) {
3768 bram_maf_id = this->read_word(this->base + ONENAND_REG_MANUFACTURER_ID);
3769 bram_dev_id = this->read_word(this->base + ONENAND_REG_DEVICE_ID);
3770 }
3771
3772 /* Check manufacturer ID */ 3768 /* Check manufacturer ID */
3773 if (onenand_check_maf(bram_maf_id)) 3769 if (onenand_check_maf(bram_maf_id))
3774 return -ENXIO; 3770 return -ENXIO;
@@ -3776,13 +3772,35 @@ static int onenand_probe(struct mtd_info *mtd)
3776 /* Read manufacturer and device IDs from Register */ 3772 /* Read manufacturer and device IDs from Register */
3777 maf_id = this->read_word(this->base + ONENAND_REG_MANUFACTURER_ID); 3773 maf_id = this->read_word(this->base + ONENAND_REG_MANUFACTURER_ID);
3778 dev_id = this->read_word(this->base + ONENAND_REG_DEVICE_ID); 3774 dev_id = this->read_word(this->base + ONENAND_REG_DEVICE_ID);
3779 ver_id = this->read_word(this->base + ONENAND_REG_VERSION_ID);
3780 this->technology = this->read_word(this->base + ONENAND_REG_TECHNOLOGY);
3781 3775
3782 /* Check OneNAND device */ 3776 /* Check OneNAND device */
3783 if (maf_id != bram_maf_id || dev_id != bram_dev_id) 3777 if (maf_id != bram_maf_id || dev_id != bram_dev_id)
3784 return -ENXIO; 3778 return -ENXIO;
3785 3779
3780 return 0;
3781}
3782
3783/**
3784 * onenand_probe - [OneNAND Interface] Probe the OneNAND device
3785 * @param mtd MTD device structure
3786 */
3787static int onenand_probe(struct mtd_info *mtd)
3788{
3789 struct onenand_chip *this = mtd->priv;
3790 int maf_id, dev_id, ver_id;
3791 int density;
3792 int ret;
3793
3794 ret = this->chip_probe(mtd);
3795 if (ret)
3796 return ret;
3797
3798 /* Read manufacturer and device IDs from Register */
3799 maf_id = this->read_word(this->base + ONENAND_REG_MANUFACTURER_ID);
3800 dev_id = this->read_word(this->base + ONENAND_REG_DEVICE_ID);
3801 ver_id = this->read_word(this->base + ONENAND_REG_VERSION_ID);
3802 this->technology = this->read_word(this->base + ONENAND_REG_TECHNOLOGY);
3803
3786 /* Flash device information */ 3804 /* Flash device information */
3787 onenand_print_device_info(dev_id, ver_id); 3805 onenand_print_device_info(dev_id, ver_id);
3788 this->device_id = dev_id; 3806 this->device_id = dev_id;
@@ -3909,6 +3927,9 @@ int onenand_scan(struct mtd_info *mtd, int maxchips)
3909 if (!this->unlock_all) 3927 if (!this->unlock_all)
3910 this->unlock_all = onenand_unlock_all; 3928 this->unlock_all = onenand_unlock_all;
3911 3929
3930 if (!this->chip_probe)
3931 this->chip_probe = onenand_chip_probe;
3932
3912 if (!this->read_bufferram) 3933 if (!this->read_bufferram)
3913 this->read_bufferram = onenand_read_bufferram; 3934 this->read_bufferram = onenand_read_bufferram;
3914 if (!this->write_bufferram) 3935 if (!this->write_bufferram)
diff --git a/drivers/mtd/onenand/onenand_bbt.c b/drivers/mtd/onenand/onenand_bbt.c
index a91fcac1af01..01ab5b3c453b 100644
--- a/drivers/mtd/onenand/onenand_bbt.c
+++ b/drivers/mtd/onenand/onenand_bbt.c
@@ -15,7 +15,6 @@
15#include <linux/slab.h> 15#include <linux/slab.h>
16#include <linux/mtd/mtd.h> 16#include <linux/mtd/mtd.h>
17#include <linux/mtd/onenand.h> 17#include <linux/mtd/onenand.h>
18#include <linux/mtd/compatmac.h>
19 18
20/** 19/**
21 * check_short_pattern - [GENERIC] check if a pattern is in the buffer 20 * check_short_pattern - [GENERIC] check if a pattern is in the buffer
diff --git a/drivers/mtd/onenand/samsung.c b/drivers/mtd/onenand/samsung.c
index 2750317cb58f..cb443af3d45f 100644
--- a/drivers/mtd/onenand/samsung.c
+++ b/drivers/mtd/onenand/samsung.c
@@ -630,6 +630,12 @@ normal:
630 return 0; 630 return 0;
631} 631}
632 632
633static int s5pc110_chip_probe(struct mtd_info *mtd)
634{
635 /* Now just return 0 */
636 return 0;
637}
638
633static int s3c_onenand_bbt_wait(struct mtd_info *mtd, int state) 639static int s3c_onenand_bbt_wait(struct mtd_info *mtd, int state)
634{ 640{
635 unsigned int flags = INT_ACT | LOAD_CMP; 641 unsigned int flags = INT_ACT | LOAD_CMP;
@@ -757,6 +763,7 @@ static void s3c_onenand_setup(struct mtd_info *mtd)
757 /* Use generic onenand functions */ 763 /* Use generic onenand functions */
758 onenand->cmd_map = s5pc1xx_cmd_map; 764 onenand->cmd_map = s5pc1xx_cmd_map;
759 this->read_bufferram = s5pc110_read_bufferram; 765 this->read_bufferram = s5pc110_read_bufferram;
766 this->chip_probe = s5pc110_chip_probe;
760 return; 767 return;
761 } else { 768 } else {
762 BUG(); 769 BUG();
@@ -781,7 +788,6 @@ static int s3c_onenand_probe(struct platform_device *pdev)
781 struct mtd_info *mtd; 788 struct mtd_info *mtd;
782 struct resource *r; 789 struct resource *r;
783 int size, err; 790 int size, err;
784 unsigned long onenand_ctrl_cfg = 0;
785 791
786 pdata = pdev->dev.platform_data; 792 pdata = pdev->dev.platform_data;
787 /* No need to check pdata. the platform data is optional */ 793 /* No need to check pdata. the platform data is optional */
@@ -900,14 +906,6 @@ static int s3c_onenand_probe(struct platform_device *pdev)
900 } 906 }
901 907
902 onenand->phys_base = onenand->base_res->start; 908 onenand->phys_base = onenand->base_res->start;
903
904 onenand_ctrl_cfg = readl(onenand->dma_addr + 0x100);
905 if ((onenand_ctrl_cfg & ONENAND_SYS_CFG1_SYNC_WRITE) &&
906 onenand->dma_addr)
907 writel(onenand_ctrl_cfg & ~ONENAND_SYS_CFG1_SYNC_WRITE,
908 onenand->dma_addr + 0x100);
909 else
910 onenand_ctrl_cfg = 0;
911 } 909 }
912 910
913 if (onenand_scan(mtd, 1)) { 911 if (onenand_scan(mtd, 1)) {
@@ -915,10 +913,7 @@ static int s3c_onenand_probe(struct platform_device *pdev)
915 goto scan_failed; 913 goto scan_failed;
916 } 914 }
917 915
918 if (onenand->type == TYPE_S5PC110) { 916 if (onenand->type != TYPE_S5PC110) {
919 if (onenand_ctrl_cfg && onenand->dma_addr)
920 writel(onenand_ctrl_cfg, onenand->dma_addr + 0x100);
921 } else {
922 /* S3C doesn't handle subpage write */ 917 /* S3C doesn't handle subpage write */
923 mtd->subpage_sft = 0; 918 mtd->subpage_sft = 0;
924 this->subpagesize = mtd->writesize; 919 this->subpagesize = mtd->writesize;
diff --git a/drivers/mtd/redboot.c b/drivers/mtd/redboot.c
index 2d600a1bf2aa..7a87d07cd79f 100644
--- a/drivers/mtd/redboot.c
+++ b/drivers/mtd/redboot.c
@@ -1,6 +1,24 @@
1/* 1/*
2 * Parse RedBoot-style Flash Image System (FIS) tables and 2 * Parse RedBoot-style Flash Image System (FIS) tables and
3 * produce a Linux partition array to match. 3 * produce a Linux partition array to match.
4 *
5 * Copyright © 2001 Red Hat UK Limited
6 * Copyright © 2001-2010 David Woodhouse <dwmw2@infradead.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 *
4 */ 22 */
5 23
6#include <linux/kernel.h> 24#include <linux/kernel.h>
diff --git a/drivers/mtd/rfd_ftl.c b/drivers/mtd/rfd_ftl.c
index 63b83c0d9a13..cc4d1805b864 100644
--- a/drivers/mtd/rfd_ftl.c
+++ b/drivers/mtd/rfd_ftl.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * rfd_ftl.c -- resident flash disk (flash translation layer) 2 * rfd_ftl.c -- resident flash disk (flash translation layer)
3 * 3 *
4 * Copyright (C) 2005 Sean Young <sean@mess.org> 4 * Copyright © 2005 Sean Young <sean@mess.org>
5 * 5 *
6 * This type of flash translation layer (FTL) is used by the Embedded BIOS 6 * This type of flash translation layer (FTL) is used by the Embedded BIOS
7 * by General Software. It is known as the Resident Flash Disk (RFD), see: 7 * by General Software. It is known as the Resident Flash Disk (RFD), see:
diff --git a/drivers/mtd/ssfdc.c b/drivers/mtd/ssfdc.c
index 81c4ecdc11f5..5cd189793332 100644
--- a/drivers/mtd/ssfdc.c
+++ b/drivers/mtd/ssfdc.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * Linux driver for SSFDC Flash Translation Layer (Read only) 2 * Linux driver for SSFDC Flash Translation Layer (Read only)
3 * (c) 2005 Eptar srl 3 * © 2005 Eptar srl
4 * Author: Claudio Lanconelli <lanconelli.claudio@eptar.com> 4 * Author: Claudio Lanconelli <lanconelli.claudio@eptar.com>
5 * 5 *
6 * Based on NTFL and MTDBLOCK_RO drivers 6 * Based on NTFL and MTDBLOCK_RO drivers
diff --git a/drivers/mtd/tests/mtd_pagetest.c b/drivers/mtd/tests/mtd_pagetest.c
index 6bc1b8276c62..00b937e38c1d 100644
--- a/drivers/mtd/tests/mtd_pagetest.c
+++ b/drivers/mtd/tests/mtd_pagetest.c
@@ -310,7 +310,7 @@ static int crosstest(void)
310static int erasecrosstest(void) 310static int erasecrosstest(void)
311{ 311{
312 size_t read = 0, written = 0; 312 size_t read = 0, written = 0;
313 int err = 0, i, ebnum, ok = 1, ebnum2; 313 int err = 0, i, ebnum, ebnum2;
314 loff_t addr0; 314 loff_t addr0;
315 char *readbuf = twopages; 315 char *readbuf = twopages;
316 316
@@ -357,8 +357,7 @@ static int erasecrosstest(void)
357 if (memcmp(writebuf, readbuf, pgsize)) { 357 if (memcmp(writebuf, readbuf, pgsize)) {
358 printk(PRINT_PREF "verify failed!\n"); 358 printk(PRINT_PREF "verify failed!\n");
359 errcnt += 1; 359 errcnt += 1;
360 ok = 0; 360 return -1;
361 return err;
362 } 361 }
363 362
364 printk(PRINT_PREF "erasing block %d\n", ebnum); 363 printk(PRINT_PREF "erasing block %d\n", ebnum);
@@ -396,10 +395,10 @@ static int erasecrosstest(void)
396 if (memcmp(writebuf, readbuf, pgsize)) { 395 if (memcmp(writebuf, readbuf, pgsize)) {
397 printk(PRINT_PREF "verify failed!\n"); 396 printk(PRINT_PREF "verify failed!\n");
398 errcnt += 1; 397 errcnt += 1;
399 ok = 0; 398 return -1;
400 } 399 }
401 400
402 if (ok && !err) 401 if (!err)
403 printk(PRINT_PREF "erasecrosstest ok\n"); 402 printk(PRINT_PREF "erasecrosstest ok\n");
404 return err; 403 return err;
405} 404}
diff --git a/drivers/net/arm/ixp4xx_eth.c b/drivers/net/arm/ixp4xx_eth.c
index 4f1cc7164ad9..6028226a7270 100644
--- a/drivers/net/arm/ixp4xx_eth.c
+++ b/drivers/net/arm/ixp4xx_eth.c
@@ -241,7 +241,7 @@ static inline void memcpy_swab32(u32 *dest, u32 *src, int cnt)
241 241
242static spinlock_t mdio_lock; 242static spinlock_t mdio_lock;
243static struct eth_regs __iomem *mdio_regs; /* mdio command and status only */ 243static struct eth_regs __iomem *mdio_regs; /* mdio command and status only */
244struct mii_bus *mdio_bus; 244static struct mii_bus *mdio_bus;
245static int ports_open; 245static int ports_open;
246static struct port *npe_port_tab[MAX_NPES]; 246static struct port *npe_port_tab[MAX_NPES];
247static struct dma_pool *dma_pool; 247static struct dma_pool *dma_pool;
diff --git a/drivers/net/caif/caif_spi_slave.c b/drivers/net/caif/caif_spi_slave.c
index 077ccf840edf..2111dbfea6fe 100644
--- a/drivers/net/caif/caif_spi_slave.c
+++ b/drivers/net/caif/caif_spi_slave.c
@@ -22,13 +22,13 @@
22#include <net/caif/caif_spi.h> 22#include <net/caif/caif_spi.h>
23 23
24#ifndef CONFIG_CAIF_SPI_SYNC 24#ifndef CONFIG_CAIF_SPI_SYNC
25#define SPI_DATA_POS SPI_CMD_SZ 25#define SPI_DATA_POS 0
26static inline int forward_to_spi_cmd(struct cfspi *cfspi) 26static inline int forward_to_spi_cmd(struct cfspi *cfspi)
27{ 27{
28 return cfspi->rx_cpck_len; 28 return cfspi->rx_cpck_len;
29} 29}
30#else 30#else
31#define SPI_DATA_POS 0 31#define SPI_DATA_POS SPI_CMD_SZ
32static inline int forward_to_spi_cmd(struct cfspi *cfspi) 32static inline int forward_to_spi_cmd(struct cfspi *cfspi)
33{ 33{
34 return 0; 34 return 0;
diff --git a/drivers/net/can/mscan/mpc5xxx_can.c b/drivers/net/can/mscan/mpc5xxx_can.c
index af753936e835..b1bdc909090f 100644
--- a/drivers/net/can/mscan/mpc5xxx_can.c
+++ b/drivers/net/can/mscan/mpc5xxx_can.c
@@ -38,7 +38,7 @@
38 38
39struct mpc5xxx_can_data { 39struct mpc5xxx_can_data {
40 unsigned int type; 40 unsigned int type;
41 u32 (*get_clock)(struct of_device *ofdev, const char *clock_name, 41 u32 (*get_clock)(struct platform_device *ofdev, const char *clock_name,
42 int *mscan_clksrc); 42 int *mscan_clksrc);
43}; 43};
44 44
@@ -48,7 +48,7 @@ static struct of_device_id __devinitdata mpc52xx_cdm_ids[] = {
48 {} 48 {}
49}; 49};
50 50
51static u32 __devinit mpc52xx_can_get_clock(struct of_device *ofdev, 51static u32 __devinit mpc52xx_can_get_clock(struct platform_device *ofdev,
52 const char *clock_name, 52 const char *clock_name,
53 int *mscan_clksrc) 53 int *mscan_clksrc)
54{ 54{
@@ -101,7 +101,7 @@ static u32 __devinit mpc52xx_can_get_clock(struct of_device *ofdev,
101 return freq; 101 return freq;
102} 102}
103#else /* !CONFIG_PPC_MPC52xx */ 103#else /* !CONFIG_PPC_MPC52xx */
104static u32 __devinit mpc52xx_can_get_clock(struct of_device *ofdev, 104static u32 __devinit mpc52xx_can_get_clock(struct platform_device *ofdev,
105 const char *clock_name, 105 const char *clock_name,
106 int *mscan_clksrc) 106 int *mscan_clksrc)
107{ 107{
@@ -129,7 +129,7 @@ static struct of_device_id __devinitdata mpc512x_clock_ids[] = {
129 {} 129 {}
130}; 130};
131 131
132static u32 __devinit mpc512x_can_get_clock(struct of_device *ofdev, 132static u32 __devinit mpc512x_can_get_clock(struct platform_device *ofdev,
133 const char *clock_name, 133 const char *clock_name,
134 int *mscan_clksrc) 134 int *mscan_clksrc)
135{ 135{
@@ -239,7 +239,7 @@ exit_unmap:
239 return freq; 239 return freq;
240} 240}
241#else /* !CONFIG_PPC_MPC512x */ 241#else /* !CONFIG_PPC_MPC512x */
242static u32 __devinit mpc512x_can_get_clock(struct of_device *ofdev, 242static u32 __devinit mpc512x_can_get_clock(struct platform_device *ofdev,
243 const char *clock_name, 243 const char *clock_name,
244 int *mscan_clksrc) 244 int *mscan_clksrc)
245{ 245{
@@ -247,7 +247,7 @@ static u32 __devinit mpc512x_can_get_clock(struct of_device *ofdev,
247} 247}
248#endif /* CONFIG_PPC_MPC512x */ 248#endif /* CONFIG_PPC_MPC512x */
249 249
250static int __devinit mpc5xxx_can_probe(struct of_device *ofdev, 250static int __devinit mpc5xxx_can_probe(struct platform_device *ofdev,
251 const struct of_device_id *id) 251 const struct of_device_id *id)
252{ 252{
253 struct mpc5xxx_can_data *data = (struct mpc5xxx_can_data *)id->data; 253 struct mpc5xxx_can_data *data = (struct mpc5xxx_can_data *)id->data;
@@ -317,7 +317,7 @@ exit_unmap_mem:
317 return err; 317 return err;
318} 318}
319 319
320static int __devexit mpc5xxx_can_remove(struct of_device *ofdev) 320static int __devexit mpc5xxx_can_remove(struct platform_device *ofdev)
321{ 321{
322 struct net_device *dev = dev_get_drvdata(&ofdev->dev); 322 struct net_device *dev = dev_get_drvdata(&ofdev->dev);
323 struct mscan_priv *priv = netdev_priv(dev); 323 struct mscan_priv *priv = netdev_priv(dev);
@@ -334,7 +334,7 @@ static int __devexit mpc5xxx_can_remove(struct of_device *ofdev)
334 334
335#ifdef CONFIG_PM 335#ifdef CONFIG_PM
336static struct mscan_regs saved_regs; 336static struct mscan_regs saved_regs;
337static int mpc5xxx_can_suspend(struct of_device *ofdev, pm_message_t state) 337static int mpc5xxx_can_suspend(struct platform_device *ofdev, pm_message_t state)
338{ 338{
339 struct net_device *dev = dev_get_drvdata(&ofdev->dev); 339 struct net_device *dev = dev_get_drvdata(&ofdev->dev);
340 struct mscan_priv *priv = netdev_priv(dev); 340 struct mscan_priv *priv = netdev_priv(dev);
@@ -345,7 +345,7 @@ static int mpc5xxx_can_suspend(struct of_device *ofdev, pm_message_t state)
345 return 0; 345 return 0;
346} 346}
347 347
348static int mpc5xxx_can_resume(struct of_device *ofdev) 348static int mpc5xxx_can_resume(struct platform_device *ofdev)
349{ 349{
350 struct net_device *dev = dev_get_drvdata(&ofdev->dev); 350 struct net_device *dev = dev_get_drvdata(&ofdev->dev);
351 struct mscan_priv *priv = netdev_priv(dev); 351 struct mscan_priv *priv = netdev_priv(dev);
diff --git a/drivers/net/can/sja1000/sja1000_of_platform.c b/drivers/net/can/sja1000/sja1000_of_platform.c
index ac1a83d7c204..5bfccfdf3bbb 100644
--- a/drivers/net/can/sja1000/sja1000_of_platform.c
+++ b/drivers/net/can/sja1000/sja1000_of_platform.c
@@ -67,7 +67,7 @@ static void sja1000_ofp_write_reg(const struct sja1000_priv *priv,
67 out_8(priv->reg_base + reg, val); 67 out_8(priv->reg_base + reg, val);
68} 68}
69 69
70static int __devexit sja1000_ofp_remove(struct of_device *ofdev) 70static int __devexit sja1000_ofp_remove(struct platform_device *ofdev)
71{ 71{
72 struct net_device *dev = dev_get_drvdata(&ofdev->dev); 72 struct net_device *dev = dev_get_drvdata(&ofdev->dev);
73 struct sja1000_priv *priv = netdev_priv(dev); 73 struct sja1000_priv *priv = netdev_priv(dev);
@@ -87,7 +87,7 @@ static int __devexit sja1000_ofp_remove(struct of_device *ofdev)
87 return 0; 87 return 0;
88} 88}
89 89
90static int __devinit sja1000_ofp_probe(struct of_device *ofdev, 90static int __devinit sja1000_ofp_probe(struct platform_device *ofdev,
91 const struct of_device_id *id) 91 const struct of_device_id *id)
92{ 92{
93 struct device_node *np = ofdev->dev.of_node; 93 struct device_node *np = ofdev->dev.of_node;
diff --git a/drivers/net/cxgb3/cxgb3_main.c b/drivers/net/cxgb3/cxgb3_main.c
index 066fd5b09fda..ad19585d960b 100644
--- a/drivers/net/cxgb3/cxgb3_main.c
+++ b/drivers/net/cxgb3/cxgb3_main.c
@@ -3198,17 +3198,17 @@ static int __devinit init_one(struct pci_dev *pdev,
3198 } 3198 }
3199 } 3199 }
3200 3200
3201 err = pci_request_regions(pdev, DRV_NAME); 3201 err = pci_enable_device(pdev);
3202 if (err) { 3202 if (err) {
3203 /* Just info, some other driver may have claimed the device. */ 3203 dev_err(&pdev->dev, "cannot enable PCI device\n");
3204 dev_info(&pdev->dev, "cannot obtain PCI resources\n"); 3204 goto out;
3205 return err;
3206 } 3205 }
3207 3206
3208 err = pci_enable_device(pdev); 3207 err = pci_request_regions(pdev, DRV_NAME);
3209 if (err) { 3208 if (err) {
3210 dev_err(&pdev->dev, "cannot enable PCI device\n"); 3209 /* Just info, some other driver may have claimed the device. */
3211 goto out_release_regions; 3210 dev_info(&pdev->dev, "cannot obtain PCI resources\n");
3211 goto out_disable_device;
3212 } 3212 }
3213 3213
3214 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) { 3214 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
@@ -3217,11 +3217,11 @@ static int __devinit init_one(struct pci_dev *pdev,
3217 if (err) { 3217 if (err) {
3218 dev_err(&pdev->dev, "unable to obtain 64-bit DMA for " 3218 dev_err(&pdev->dev, "unable to obtain 64-bit DMA for "
3219 "coherent allocations\n"); 3219 "coherent allocations\n");
3220 goto out_disable_device; 3220 goto out_release_regions;
3221 } 3221 }
3222 } else if ((err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) != 0) { 3222 } else if ((err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) != 0) {
3223 dev_err(&pdev->dev, "no usable DMA configuration\n"); 3223 dev_err(&pdev->dev, "no usable DMA configuration\n");
3224 goto out_disable_device; 3224 goto out_release_regions;
3225 } 3225 }
3226 3226
3227 pci_set_master(pdev); 3227 pci_set_master(pdev);
@@ -3234,7 +3234,7 @@ static int __devinit init_one(struct pci_dev *pdev,
3234 adapter = kzalloc(sizeof(*adapter), GFP_KERNEL); 3234 adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
3235 if (!adapter) { 3235 if (!adapter) {
3236 err = -ENOMEM; 3236 err = -ENOMEM;
3237 goto out_disable_device; 3237 goto out_release_regions;
3238 } 3238 }
3239 3239
3240 adapter->nofail_skb = 3240 adapter->nofail_skb =
@@ -3370,11 +3370,12 @@ out_free_dev:
3370out_free_adapter: 3370out_free_adapter:
3371 kfree(adapter); 3371 kfree(adapter);
3372 3372
3373out_disable_device:
3374 pci_disable_device(pdev);
3375out_release_regions: 3373out_release_regions:
3376 pci_release_regions(pdev); 3374 pci_release_regions(pdev);
3375out_disable_device:
3376 pci_disable_device(pdev);
3377 pci_set_drvdata(pdev, NULL); 3377 pci_set_drvdata(pdev, NULL);
3378out:
3378 return err; 3379 return err;
3379} 3380}
3380 3381
diff --git a/drivers/net/cxgb4vf/cxgb4vf_main.c b/drivers/net/cxgb4vf/cxgb4vf_main.c
index a16563219ac9..7b6d07f50c71 100644
--- a/drivers/net/cxgb4vf/cxgb4vf_main.c
+++ b/drivers/net/cxgb4vf/cxgb4vf_main.c
@@ -2462,23 +2462,24 @@ static int __devinit cxgb4vf_pci_probe(struct pci_dev *pdev,
2462 version_printed = 1; 2462 version_printed = 1;
2463 } 2463 }
2464 2464
2465
2465 /* 2466 /*
2466 * Reserve PCI resources for the device. If we can't get them some 2467 * Initialize generic PCI device state.
2467 * other driver may have already claimed the device ...
2468 */ 2468 */
2469 err = pci_request_regions(pdev, KBUILD_MODNAME); 2469 err = pci_enable_device(pdev);
2470 if (err) { 2470 if (err) {
2471 dev_err(&pdev->dev, "cannot obtain PCI resources\n"); 2471 dev_err(&pdev->dev, "cannot enable PCI device\n");
2472 return err; 2472 return err;
2473 } 2473 }
2474 2474
2475 /* 2475 /*
2476 * Initialize generic PCI device state. 2476 * Reserve PCI resources for the device. If we can't get them some
2477 * other driver may have already claimed the device ...
2477 */ 2478 */
2478 err = pci_enable_device(pdev); 2479 err = pci_request_regions(pdev, KBUILD_MODNAME);
2479 if (err) { 2480 if (err) {
2480 dev_err(&pdev->dev, "cannot enable PCI device\n"); 2481 dev_err(&pdev->dev, "cannot obtain PCI resources\n");
2481 goto err_release_regions; 2482 goto err_disable_device;
2482 } 2483 }
2483 2484
2484 /* 2485 /*
@@ -2491,14 +2492,14 @@ static int __devinit cxgb4vf_pci_probe(struct pci_dev *pdev,
2491 if (err) { 2492 if (err) {
2492 dev_err(&pdev->dev, "unable to obtain 64-bit DMA for" 2493 dev_err(&pdev->dev, "unable to obtain 64-bit DMA for"
2493 " coherent allocations\n"); 2494 " coherent allocations\n");
2494 goto err_disable_device; 2495 goto err_release_regions;
2495 } 2496 }
2496 pci_using_dac = 1; 2497 pci_using_dac = 1;
2497 } else { 2498 } else {
2498 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); 2499 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
2499 if (err != 0) { 2500 if (err != 0) {
2500 dev_err(&pdev->dev, "no usable DMA configuration\n"); 2501 dev_err(&pdev->dev, "no usable DMA configuration\n");
2501 goto err_disable_device; 2502 goto err_release_regions;
2502 } 2503 }
2503 pci_using_dac = 0; 2504 pci_using_dac = 0;
2504 } 2505 }
@@ -2514,7 +2515,7 @@ static int __devinit cxgb4vf_pci_probe(struct pci_dev *pdev,
2514 adapter = kzalloc(sizeof(*adapter), GFP_KERNEL); 2515 adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
2515 if (!adapter) { 2516 if (!adapter) {
2516 err = -ENOMEM; 2517 err = -ENOMEM;
2517 goto err_disable_device; 2518 goto err_release_regions;
2518 } 2519 }
2519 pci_set_drvdata(pdev, adapter); 2520 pci_set_drvdata(pdev, adapter);
2520 adapter->pdev = pdev; 2521 adapter->pdev = pdev;
@@ -2750,13 +2751,13 @@ err_free_adapter:
2750 kfree(adapter); 2751 kfree(adapter);
2751 pci_set_drvdata(pdev, NULL); 2752 pci_set_drvdata(pdev, NULL);
2752 2753
2753err_disable_device:
2754 pci_disable_device(pdev);
2755 pci_clear_master(pdev);
2756
2757err_release_regions: 2754err_release_regions:
2758 pci_release_regions(pdev); 2755 pci_release_regions(pdev);
2759 pci_set_drvdata(pdev, NULL); 2756 pci_set_drvdata(pdev, NULL);
2757 pci_clear_master(pdev);
2758
2759err_disable_device:
2760 pci_disable_device(pdev);
2760 2761
2761err_out: 2762err_out:
2762 return err; 2763 return err;
diff --git a/drivers/net/davinci_emac.c b/drivers/net/davinci_emac.c
index d0824e322068..7fbd052ddb0a 100644
--- a/drivers/net/davinci_emac.c
+++ b/drivers/net/davinci_emac.c
@@ -2944,8 +2944,8 @@ static int __devexit davinci_emac_remove(struct platform_device *pdev)
2944 release_mem_region(res->start, res->end - res->start + 1); 2944 release_mem_region(res->start, res->end - res->start + 1);
2945 2945
2946 unregister_netdev(ndev); 2946 unregister_netdev(ndev);
2947 free_netdev(ndev);
2948 iounmap(priv->remap_addr); 2947 iounmap(priv->remap_addr);
2948 free_netdev(ndev);
2949 2949
2950 clk_disable(emac_clk); 2950 clk_disable(emac_clk);
2951 clk_put(emac_clk); 2951 clk_put(emac_clk);
diff --git a/drivers/net/e100.c b/drivers/net/e100.c
index b194bad29ace..8e2eab4e7c75 100644
--- a/drivers/net/e100.c
+++ b/drivers/net/e100.c
@@ -1779,6 +1779,7 @@ static int e100_tx_clean(struct nic *nic)
1779 for (cb = nic->cb_to_clean; 1779 for (cb = nic->cb_to_clean;
1780 cb->status & cpu_to_le16(cb_complete); 1780 cb->status & cpu_to_le16(cb_complete);
1781 cb = nic->cb_to_clean = cb->next) { 1781 cb = nic->cb_to_clean = cb->next) {
1782 rmb(); /* read skb after status */
1782 netif_printk(nic, tx_done, KERN_DEBUG, nic->netdev, 1783 netif_printk(nic, tx_done, KERN_DEBUG, nic->netdev,
1783 "cb[%d]->status = 0x%04X\n", 1784 "cb[%d]->status = 0x%04X\n",
1784 (int)(((void*)cb - (void*)nic->cbs)/sizeof(struct cb)), 1785 (int)(((void*)cb - (void*)nic->cbs)/sizeof(struct cb)),
@@ -1927,6 +1928,7 @@ static int e100_rx_indicate(struct nic *nic, struct rx *rx,
1927 1928
1928 netif_printk(nic, rx_status, KERN_DEBUG, nic->netdev, 1929 netif_printk(nic, rx_status, KERN_DEBUG, nic->netdev,
1929 "status=0x%04X\n", rfd_status); 1930 "status=0x%04X\n", rfd_status);
1931 rmb(); /* read size after status bit */
1930 1932
1931 /* If data isn't ready, nothing to indicate */ 1933 /* If data isn't ready, nothing to indicate */
1932 if (unlikely(!(rfd_status & cb_complete))) { 1934 if (unlikely(!(rfd_status & cb_complete))) {
diff --git a/drivers/net/e1000/e1000_main.c b/drivers/net/e1000/e1000_main.c
index 02833af8a0b1..5cc39ed289c6 100644
--- a/drivers/net/e1000/e1000_main.c
+++ b/drivers/net/e1000/e1000_main.c
@@ -3454,6 +3454,7 @@ static bool e1000_clean_tx_irq(struct e1000_adapter *adapter,
3454 while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) && 3454 while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
3455 (count < tx_ring->count)) { 3455 (count < tx_ring->count)) {
3456 bool cleaned = false; 3456 bool cleaned = false;
3457 rmb(); /* read buffer_info after eop_desc */
3457 for ( ; !cleaned; count++) { 3458 for ( ; !cleaned; count++) {
3458 tx_desc = E1000_TX_DESC(*tx_ring, i); 3459 tx_desc = E1000_TX_DESC(*tx_ring, i);
3459 buffer_info = &tx_ring->buffer_info[i]; 3460 buffer_info = &tx_ring->buffer_info[i];
@@ -3643,6 +3644,7 @@ static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter,
3643 if (*work_done >= work_to_do) 3644 if (*work_done >= work_to_do)
3644 break; 3645 break;
3645 (*work_done)++; 3646 (*work_done)++;
3647 rmb(); /* read descriptor and rx_buffer_info after status DD */
3646 3648
3647 status = rx_desc->status; 3649 status = rx_desc->status;
3648 skb = buffer_info->skb; 3650 skb = buffer_info->skb;
@@ -3849,6 +3851,7 @@ static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
3849 if (*work_done >= work_to_do) 3851 if (*work_done >= work_to_do)
3850 break; 3852 break;
3851 (*work_done)++; 3853 (*work_done)++;
3854 rmb(); /* read descriptor and rx_buffer_info after status DD */
3852 3855
3853 status = rx_desc->status; 3856 status = rx_desc->status;
3854 skb = buffer_info->skb; 3857 skb = buffer_info->skb;
diff --git a/drivers/net/e1000e/netdev.c b/drivers/net/e1000e/netdev.c
index 521c6ee1f32a..2b8ef44bd2b1 100644
--- a/drivers/net/e1000e/netdev.c
+++ b/drivers/net/e1000e/netdev.c
@@ -781,6 +781,7 @@ static bool e1000_clean_rx_irq(struct e1000_adapter *adapter,
781 if (*work_done >= work_to_do) 781 if (*work_done >= work_to_do)
782 break; 782 break;
783 (*work_done)++; 783 (*work_done)++;
784 rmb(); /* read descriptor and rx_buffer_info after status DD */
784 785
785 status = rx_desc->status; 786 status = rx_desc->status;
786 skb = buffer_info->skb; 787 skb = buffer_info->skb;
@@ -991,6 +992,7 @@ static bool e1000_clean_tx_irq(struct e1000_adapter *adapter)
991 while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) && 992 while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
992 (count < tx_ring->count)) { 993 (count < tx_ring->count)) {
993 bool cleaned = false; 994 bool cleaned = false;
995 rmb(); /* read buffer_info after eop_desc */
994 for (; !cleaned; count++) { 996 for (; !cleaned; count++) {
995 tx_desc = E1000_TX_DESC(*tx_ring, i); 997 tx_desc = E1000_TX_DESC(*tx_ring, i);
996 buffer_info = &tx_ring->buffer_info[i]; 998 buffer_info = &tx_ring->buffer_info[i];
@@ -1087,6 +1089,7 @@ static bool e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
1087 break; 1089 break;
1088 (*work_done)++; 1090 (*work_done)++;
1089 skb = buffer_info->skb; 1091 skb = buffer_info->skb;
1092 rmb(); /* read descriptor and rx_buffer_info after status DD */
1090 1093
1091 /* in the packet split case this is header only */ 1094 /* in the packet split case this is header only */
1092 prefetch(skb->data - NET_IP_ALIGN); 1095 prefetch(skb->data - NET_IP_ALIGN);
@@ -1286,6 +1289,7 @@ static bool e1000_clean_jumbo_rx_irq(struct e1000_adapter *adapter,
1286 if (*work_done >= work_to_do) 1289 if (*work_done >= work_to_do)
1287 break; 1290 break;
1288 (*work_done)++; 1291 (*work_done)++;
1292 rmb(); /* read descriptor and rx_buffer_info after status DD */
1289 1293
1290 status = rx_desc->status; 1294 status = rx_desc->status;
1291 skb = buffer_info->skb; 1295 skb = buffer_info->skb;
diff --git a/drivers/net/ehea/ehea.h b/drivers/net/ehea/ehea.h
index 0060e422f171..99a929964e3c 100644
--- a/drivers/net/ehea/ehea.h
+++ b/drivers/net/ehea/ehea.h
@@ -413,7 +413,7 @@ struct ehea_port_res {
413 413
414struct ehea_adapter { 414struct ehea_adapter {
415 u64 handle; 415 u64 handle;
416 struct of_device *ofdev; 416 struct platform_device *ofdev;
417 struct ehea_port *port[EHEA_MAX_PORTS]; 417 struct ehea_port *port[EHEA_MAX_PORTS];
418 struct ehea_eq *neq; /* notification event queue */ 418 struct ehea_eq *neq; /* notification event queue */
419 struct tasklet_struct neq_tasklet; 419 struct tasklet_struct neq_tasklet;
@@ -465,7 +465,7 @@ struct ehea_port {
465 struct net_device *netdev; 465 struct net_device *netdev;
466 struct net_device_stats stats; 466 struct net_device_stats stats;
467 struct ehea_port_res port_res[EHEA_MAX_PORT_RES]; 467 struct ehea_port_res port_res[EHEA_MAX_PORT_RES];
468 struct of_device ofdev; /* Open Firmware Device */ 468 struct platform_device ofdev; /* Open Firmware Device */
469 struct ehea_mc_list *mc_list; /* Multicast MAC addresses */ 469 struct ehea_mc_list *mc_list; /* Multicast MAC addresses */
470 struct vlan_group *vgrp; 470 struct vlan_group *vgrp;
471 struct ehea_eq *qp_eq; 471 struct ehea_eq *qp_eq;
diff --git a/drivers/net/ehea/ehea_main.c b/drivers/net/ehea/ehea_main.c
index 3beba70b7dea..897719b49f96 100644
--- a/drivers/net/ehea/ehea_main.c
+++ b/drivers/net/ehea/ehea_main.c
@@ -107,10 +107,10 @@ struct ehea_fw_handle_array ehea_fw_handles;
107struct ehea_bcmc_reg_array ehea_bcmc_regs; 107struct ehea_bcmc_reg_array ehea_bcmc_regs;
108 108
109 109
110static int __devinit ehea_probe_adapter(struct of_device *dev, 110static int __devinit ehea_probe_adapter(struct platform_device *dev,
111 const struct of_device_id *id); 111 const struct of_device_id *id);
112 112
113static int __devexit ehea_remove(struct of_device *dev); 113static int __devexit ehea_remove(struct platform_device *dev);
114 114
115static struct of_device_id ehea_device_table[] = { 115static struct of_device_id ehea_device_table[] = {
116 { 116 {
@@ -3376,7 +3376,7 @@ static ssize_t ehea_remove_port(struct device *dev,
3376static DEVICE_ATTR(probe_port, S_IWUSR, NULL, ehea_probe_port); 3376static DEVICE_ATTR(probe_port, S_IWUSR, NULL, ehea_probe_port);
3377static DEVICE_ATTR(remove_port, S_IWUSR, NULL, ehea_remove_port); 3377static DEVICE_ATTR(remove_port, S_IWUSR, NULL, ehea_remove_port);
3378 3378
3379int ehea_create_device_sysfs(struct of_device *dev) 3379int ehea_create_device_sysfs(struct platform_device *dev)
3380{ 3380{
3381 int ret = device_create_file(&dev->dev, &dev_attr_probe_port); 3381 int ret = device_create_file(&dev->dev, &dev_attr_probe_port);
3382 if (ret) 3382 if (ret)
@@ -3387,13 +3387,13 @@ out:
3387 return ret; 3387 return ret;
3388} 3388}
3389 3389
3390void ehea_remove_device_sysfs(struct of_device *dev) 3390void ehea_remove_device_sysfs(struct platform_device *dev)
3391{ 3391{
3392 device_remove_file(&dev->dev, &dev_attr_probe_port); 3392 device_remove_file(&dev->dev, &dev_attr_probe_port);
3393 device_remove_file(&dev->dev, &dev_attr_remove_port); 3393 device_remove_file(&dev->dev, &dev_attr_remove_port);
3394} 3394}
3395 3395
3396static int __devinit ehea_probe_adapter(struct of_device *dev, 3396static int __devinit ehea_probe_adapter(struct platform_device *dev,
3397 const struct of_device_id *id) 3397 const struct of_device_id *id)
3398{ 3398{
3399 struct ehea_adapter *adapter; 3399 struct ehea_adapter *adapter;
@@ -3492,7 +3492,7 @@ out:
3492 return ret; 3492 return ret;
3493} 3493}
3494 3494
3495static int __devexit ehea_remove(struct of_device *dev) 3495static int __devexit ehea_remove(struct platform_device *dev)
3496{ 3496{
3497 struct ehea_adapter *adapter = dev_get_drvdata(&dev->dev); 3497 struct ehea_adapter *adapter = dev_get_drvdata(&dev->dev);
3498 int i; 3498 int i;
diff --git a/drivers/net/enic/enic_main.c b/drivers/net/enic/enic_main.c
index 77a7f87d498e..9aab85366d21 100644
--- a/drivers/net/enic/enic_main.c
+++ b/drivers/net/enic/enic_main.c
@@ -1087,10 +1087,7 @@ static int enic_set_port_profile(struct enic *enic, u8 *mac)
1087{ 1087{
1088 struct vic_provinfo *vp; 1088 struct vic_provinfo *vp;
1089 u8 oui[3] = VIC_PROVINFO_CISCO_OUI; 1089 u8 oui[3] = VIC_PROVINFO_CISCO_OUI;
1090 u8 *uuid;
1091 char uuid_str[38]; 1090 char uuid_str[38];
1092 static char *uuid_fmt = "%02X%02X%02X%02X-%02X%02X-%02X%02X-"
1093 "%02X%02X-%02X%02X%02X%02X%0X%02X";
1094 int err; 1091 int err;
1095 1092
1096 err = enic_vnic_dev_deinit(enic); 1093 err = enic_vnic_dev_deinit(enic);
@@ -1121,24 +1118,14 @@ static int enic_set_port_profile(struct enic *enic, u8 *mac)
1121 ETH_ALEN, mac); 1118 ETH_ALEN, mac);
1122 1119
1123 if (enic->pp.set & ENIC_SET_INSTANCE) { 1120 if (enic->pp.set & ENIC_SET_INSTANCE) {
1124 uuid = enic->pp.instance_uuid; 1121 sprintf(uuid_str, "%pUB", enic->pp.instance_uuid);
1125 sprintf(uuid_str, uuid_fmt,
1126 uuid[0], uuid[1], uuid[2], uuid[3],
1127 uuid[4], uuid[5], uuid[6], uuid[7],
1128 uuid[8], uuid[9], uuid[10], uuid[11],
1129 uuid[12], uuid[13], uuid[14], uuid[15]);
1130 vic_provinfo_add_tlv(vp, 1122 vic_provinfo_add_tlv(vp,
1131 VIC_LINUX_PROV_TLV_CLIENT_UUID_STR, 1123 VIC_LINUX_PROV_TLV_CLIENT_UUID_STR,
1132 sizeof(uuid_str), uuid_str); 1124 sizeof(uuid_str), uuid_str);
1133 } 1125 }
1134 1126
1135 if (enic->pp.set & ENIC_SET_HOST) { 1127 if (enic->pp.set & ENIC_SET_HOST) {
1136 uuid = enic->pp.host_uuid; 1128 sprintf(uuid_str, "%pUB", enic->pp.host_uuid);
1137 sprintf(uuid_str, uuid_fmt,
1138 uuid[0], uuid[1], uuid[2], uuid[3],
1139 uuid[4], uuid[5], uuid[6], uuid[7],
1140 uuid[8], uuid[9], uuid[10], uuid[11],
1141 uuid[12], uuid[13], uuid[14], uuid[15]);
1142 vic_provinfo_add_tlv(vp, 1129 vic_provinfo_add_tlv(vp,
1143 VIC_LINUX_PROV_TLV_HOST_UUID_STR, 1130 VIC_LINUX_PROV_TLV_HOST_UUID_STR,
1144 sizeof(uuid_str), uuid_str); 1131 sizeof(uuid_str), uuid_str);
diff --git a/drivers/net/fec_mpc52xx.c b/drivers/net/fec_mpc52xx.c
index d1a5b17b2a95..e3e10b4add9c 100644
--- a/drivers/net/fec_mpc52xx.c
+++ b/drivers/net/fec_mpc52xx.c
@@ -850,7 +850,7 @@ static const struct net_device_ops mpc52xx_fec_netdev_ops = {
850/* ======================================================================== */ 850/* ======================================================================== */
851 851
852static int __devinit 852static int __devinit
853mpc52xx_fec_probe(struct of_device *op, const struct of_device_id *match) 853mpc52xx_fec_probe(struct platform_device *op, const struct of_device_id *match)
854{ 854{
855 int rv; 855 int rv;
856 struct net_device *ndev; 856 struct net_device *ndev;
@@ -995,7 +995,7 @@ err_netdev:
995} 995}
996 996
997static int 997static int
998mpc52xx_fec_remove(struct of_device *op) 998mpc52xx_fec_remove(struct platform_device *op)
999{ 999{
1000 struct net_device *ndev; 1000 struct net_device *ndev;
1001 struct mpc52xx_fec_priv *priv; 1001 struct mpc52xx_fec_priv *priv;
@@ -1025,7 +1025,7 @@ mpc52xx_fec_remove(struct of_device *op)
1025} 1025}
1026 1026
1027#ifdef CONFIG_PM 1027#ifdef CONFIG_PM
1028static int mpc52xx_fec_of_suspend(struct of_device *op, pm_message_t state) 1028static int mpc52xx_fec_of_suspend(struct platform_device *op, pm_message_t state)
1029{ 1029{
1030 struct net_device *dev = dev_get_drvdata(&op->dev); 1030 struct net_device *dev = dev_get_drvdata(&op->dev);
1031 1031
@@ -1035,7 +1035,7 @@ static int mpc52xx_fec_of_suspend(struct of_device *op, pm_message_t state)
1035 return 0; 1035 return 0;
1036} 1036}
1037 1037
1038static int mpc52xx_fec_of_resume(struct of_device *op) 1038static int mpc52xx_fec_of_resume(struct platform_device *op)
1039{ 1039{
1040 struct net_device *dev = dev_get_drvdata(&op->dev); 1040 struct net_device *dev = dev_get_drvdata(&op->dev);
1041 1041
diff --git a/drivers/net/fec_mpc52xx_phy.c b/drivers/net/fec_mpc52xx_phy.c
index dbaf72cbb233..0b4cb6f15984 100644
--- a/drivers/net/fec_mpc52xx_phy.c
+++ b/drivers/net/fec_mpc52xx_phy.c
@@ -61,7 +61,7 @@ static int mpc52xx_fec_mdio_write(struct mii_bus *bus, int phy_id, int reg,
61 data | FEC_MII_WRITE_FRAME); 61 data | FEC_MII_WRITE_FRAME);
62} 62}
63 63
64static int mpc52xx_fec_mdio_probe(struct of_device *of, 64static int mpc52xx_fec_mdio_probe(struct platform_device *of,
65 const struct of_device_id *match) 65 const struct of_device_id *match)
66{ 66{
67 struct device *dev = &of->dev; 67 struct device *dev = &of->dev;
@@ -122,7 +122,7 @@ static int mpc52xx_fec_mdio_probe(struct of_device *of,
122 return err; 122 return err;
123} 123}
124 124
125static int mpc52xx_fec_mdio_remove(struct of_device *of) 125static int mpc52xx_fec_mdio_remove(struct platform_device *of)
126{ 126{
127 struct device *dev = &of->dev; 127 struct device *dev = &of->dev;
128 struct mii_bus *bus = dev_get_drvdata(dev); 128 struct mii_bus *bus = dev_get_drvdata(dev);
diff --git a/drivers/net/fs_enet/fs_enet-main.c b/drivers/net/fs_enet/fs_enet-main.c
index f08cff9020bd..d6e3111959ab 100644
--- a/drivers/net/fs_enet/fs_enet-main.c
+++ b/drivers/net/fs_enet/fs_enet-main.c
@@ -997,7 +997,7 @@ static const struct net_device_ops fs_enet_netdev_ops = {
997#endif 997#endif
998}; 998};
999 999
1000static int __devinit fs_enet_probe(struct of_device *ofdev, 1000static int __devinit fs_enet_probe(struct platform_device *ofdev,
1001 const struct of_device_id *match) 1001 const struct of_device_id *match)
1002{ 1002{
1003 struct net_device *ndev; 1003 struct net_device *ndev;
@@ -1105,7 +1105,7 @@ out_free_fpi:
1105 return ret; 1105 return ret;
1106} 1106}
1107 1107
1108static int fs_enet_remove(struct of_device *ofdev) 1108static int fs_enet_remove(struct platform_device *ofdev)
1109{ 1109{
1110 struct net_device *ndev = dev_get_drvdata(&ofdev->dev); 1110 struct net_device *ndev = dev_get_drvdata(&ofdev->dev);
1111 struct fs_enet_private *fep = netdev_priv(ndev); 1111 struct fs_enet_private *fep = netdev_priv(ndev);
diff --git a/drivers/net/fs_enet/mac-fcc.c b/drivers/net/fs_enet/mac-fcc.c
index 48e91b6242ce..7a84e45487e8 100644
--- a/drivers/net/fs_enet/mac-fcc.c
+++ b/drivers/net/fs_enet/mac-fcc.c
@@ -84,7 +84,7 @@ static inline int fcc_cr_cmd(struct fs_enet_private *fep, u32 op)
84 84
85static int do_pd_setup(struct fs_enet_private *fep) 85static int do_pd_setup(struct fs_enet_private *fep)
86{ 86{
87 struct of_device *ofdev = to_of_device(fep->dev); 87 struct platform_device *ofdev = to_platform_device(fep->dev);
88 struct fs_platform_info *fpi = fep->fpi; 88 struct fs_platform_info *fpi = fep->fpi;
89 int ret = -EINVAL; 89 int ret = -EINVAL;
90 90
diff --git a/drivers/net/fs_enet/mac-fec.c b/drivers/net/fs_enet/mac-fec.c
index 7ca1642276d0..61035fc5599b 100644
--- a/drivers/net/fs_enet/mac-fec.c
+++ b/drivers/net/fs_enet/mac-fec.c
@@ -96,7 +96,7 @@ static int whack_reset(struct fec __iomem *fecp)
96 96
97static int do_pd_setup(struct fs_enet_private *fep) 97static int do_pd_setup(struct fs_enet_private *fep)
98{ 98{
99 struct of_device *ofdev = to_of_device(fep->dev); 99 struct platform_device *ofdev = to_platform_device(fep->dev);
100 100
101 fep->interrupt = of_irq_to_resource(ofdev->dev.of_node, 0, NULL); 101 fep->interrupt = of_irq_to_resource(ofdev->dev.of_node, 0, NULL);
102 if (fep->interrupt == NO_IRQ) 102 if (fep->interrupt == NO_IRQ)
diff --git a/drivers/net/fs_enet/mac-scc.c b/drivers/net/fs_enet/mac-scc.c
index a3c44544846d..22a02a767069 100644
--- a/drivers/net/fs_enet/mac-scc.c
+++ b/drivers/net/fs_enet/mac-scc.c
@@ -96,7 +96,7 @@ static inline int scc_cr_cmd(struct fs_enet_private *fep, u32 op)
96 96
97static int do_pd_setup(struct fs_enet_private *fep) 97static int do_pd_setup(struct fs_enet_private *fep)
98{ 98{
99 struct of_device *ofdev = to_of_device(fep->dev); 99 struct platform_device *ofdev = to_platform_device(fep->dev);
100 100
101 fep->interrupt = of_irq_to_resource(ofdev->dev.of_node, 0, NULL); 101 fep->interrupt = of_irq_to_resource(ofdev->dev.of_node, 0, NULL);
102 if (fep->interrupt == NO_IRQ) 102 if (fep->interrupt == NO_IRQ)
diff --git a/drivers/net/fs_enet/mii-bitbang.c b/drivers/net/fs_enet/mii-bitbang.c
index 3607340f3da7..3cda2b515471 100644
--- a/drivers/net/fs_enet/mii-bitbang.c
+++ b/drivers/net/fs_enet/mii-bitbang.c
@@ -150,7 +150,7 @@ static int __devinit fs_mii_bitbang_init(struct mii_bus *bus,
150 return 0; 150 return 0;
151} 151}
152 152
153static int __devinit fs_enet_mdio_probe(struct of_device *ofdev, 153static int __devinit fs_enet_mdio_probe(struct platform_device *ofdev,
154 const struct of_device_id *match) 154 const struct of_device_id *match)
155{ 155{
156 struct mii_bus *new_bus; 156 struct mii_bus *new_bus;
@@ -200,7 +200,7 @@ out:
200 return ret; 200 return ret;
201} 201}
202 202
203static int fs_enet_mdio_remove(struct of_device *ofdev) 203static int fs_enet_mdio_remove(struct platform_device *ofdev)
204{ 204{
205 struct mii_bus *bus = dev_get_drvdata(&ofdev->dev); 205 struct mii_bus *bus = dev_get_drvdata(&ofdev->dev);
206 struct bb_info *bitbang = bus->priv; 206 struct bb_info *bitbang = bus->priv;
diff --git a/drivers/net/fs_enet/mii-fec.c b/drivers/net/fs_enet/mii-fec.c
index bddffd169b93..dbb9c48623df 100644
--- a/drivers/net/fs_enet/mii-fec.c
+++ b/drivers/net/fs_enet/mii-fec.c
@@ -101,7 +101,7 @@ static int fs_enet_fec_mii_reset(struct mii_bus *bus)
101 return 0; 101 return 0;
102} 102}
103 103
104static int __devinit fs_enet_mdio_probe(struct of_device *ofdev, 104static int __devinit fs_enet_mdio_probe(struct platform_device *ofdev,
105 const struct of_device_id *match) 105 const struct of_device_id *match)
106{ 106{
107 struct resource res; 107 struct resource res;
@@ -192,7 +192,7 @@ out:
192 return ret; 192 return ret;
193} 193}
194 194
195static int fs_enet_mdio_remove(struct of_device *ofdev) 195static int fs_enet_mdio_remove(struct platform_device *ofdev)
196{ 196{
197 struct mii_bus *bus = dev_get_drvdata(&ofdev->dev); 197 struct mii_bus *bus = dev_get_drvdata(&ofdev->dev);
198 struct fec_info *fec = bus->priv; 198 struct fec_info *fec = bus->priv;
diff --git a/drivers/net/fsl_pq_mdio.c b/drivers/net/fsl_pq_mdio.c
index f53f850b6418..d4bf91aac25f 100644
--- a/drivers/net/fsl_pq_mdio.c
+++ b/drivers/net/fsl_pq_mdio.c
@@ -265,7 +265,7 @@ static int get_ucc_id_for_range(u64 start, u64 end, u32 *ucc_id)
265#endif 265#endif
266 266
267 267
268static int fsl_pq_mdio_probe(struct of_device *ofdev, 268static int fsl_pq_mdio_probe(struct platform_device *ofdev,
269 const struct of_device_id *match) 269 const struct of_device_id *match)
270{ 270{
271 struct device_node *np = ofdev->dev.of_node; 271 struct device_node *np = ofdev->dev.of_node;
@@ -425,7 +425,7 @@ err_free_priv:
425} 425}
426 426
427 427
428static int fsl_pq_mdio_remove(struct of_device *ofdev) 428static int fsl_pq_mdio_remove(struct platform_device *ofdev)
429{ 429{
430 struct device *device = &ofdev->dev; 430 struct device *device = &ofdev->dev;
431 struct mii_bus *bus = dev_get_drvdata(device); 431 struct mii_bus *bus = dev_get_drvdata(device);
diff --git a/drivers/net/gianfar.c b/drivers/net/gianfar.c
index a1b6301bc674..4f7c3f3ca234 100644
--- a/drivers/net/gianfar.c
+++ b/drivers/net/gianfar.c
@@ -122,9 +122,9 @@ static irqreturn_t gfar_interrupt(int irq, void *dev_id);
122static void adjust_link(struct net_device *dev); 122static void adjust_link(struct net_device *dev);
123static void init_registers(struct net_device *dev); 123static void init_registers(struct net_device *dev);
124static int init_phy(struct net_device *dev); 124static int init_phy(struct net_device *dev);
125static int gfar_probe(struct of_device *ofdev, 125static int gfar_probe(struct platform_device *ofdev,
126 const struct of_device_id *match); 126 const struct of_device_id *match);
127static int gfar_remove(struct of_device *ofdev); 127static int gfar_remove(struct platform_device *ofdev);
128static void free_skb_resources(struct gfar_private *priv); 128static void free_skb_resources(struct gfar_private *priv);
129static void gfar_set_multi(struct net_device *dev); 129static void gfar_set_multi(struct net_device *dev);
130static void gfar_set_hash_for_addr(struct net_device *dev, u8 *addr); 130static void gfar_set_hash_for_addr(struct net_device *dev, u8 *addr);
@@ -605,7 +605,7 @@ static int gfar_parse_group(struct device_node *np,
605 return 0; 605 return 0;
606} 606}
607 607
608static int gfar_of_init(struct of_device *ofdev, struct net_device **pdev) 608static int gfar_of_init(struct platform_device *ofdev, struct net_device **pdev)
609{ 609{
610 const char *model; 610 const char *model;
611 const char *ctype; 611 const char *ctype;
@@ -959,7 +959,7 @@ static void gfar_detect_errata(struct gfar_private *priv)
959 959
960/* Set up the ethernet device structure, private data, 960/* Set up the ethernet device structure, private data,
961 * and anything else we need before we start */ 961 * and anything else we need before we start */
962static int gfar_probe(struct of_device *ofdev, 962static int gfar_probe(struct platform_device *ofdev,
963 const struct of_device_id *match) 963 const struct of_device_id *match)
964{ 964{
965 u32 tempval; 965 u32 tempval;
@@ -1238,7 +1238,7 @@ register_fail:
1238 return err; 1238 return err;
1239} 1239}
1240 1240
1241static int gfar_remove(struct of_device *ofdev) 1241static int gfar_remove(struct platform_device *ofdev)
1242{ 1242{
1243 struct gfar_private *priv = dev_get_drvdata(&ofdev->dev); 1243 struct gfar_private *priv = dev_get_drvdata(&ofdev->dev);
1244 1244
diff --git a/drivers/net/gianfar.h b/drivers/net/gianfar.h
index 710810e2adb4..68984eb88ae0 100644
--- a/drivers/net/gianfar.h
+++ b/drivers/net/gianfar.h
@@ -1054,7 +1054,7 @@ struct gfar_private {
1054 1054
1055 struct device_node *node; 1055 struct device_node *node;
1056 struct net_device *ndev; 1056 struct net_device *ndev;
1057 struct of_device *ofdev; 1057 struct platform_device *ofdev;
1058 enum gfar_errata errata; 1058 enum gfar_errata errata;
1059 1059
1060 struct gfar_priv_grp gfargrp[MAXGROUPS]; 1060 struct gfar_priv_grp gfargrp[MAXGROUPS];
diff --git a/drivers/net/greth.c b/drivers/net/greth.c
index 4d09eab3548e..f15c64f1cd38 100644
--- a/drivers/net/greth.c
+++ b/drivers/net/greth.c
@@ -1373,7 +1373,7 @@ error:
1373} 1373}
1374 1374
1375/* Initialize the GRETH MAC */ 1375/* Initialize the GRETH MAC */
1376static int __devinit greth_of_probe(struct of_device *ofdev, const struct of_device_id *match) 1376static int __devinit greth_of_probe(struct platform_device *ofdev, const struct of_device_id *match)
1377{ 1377{
1378 struct net_device *dev; 1378 struct net_device *dev;
1379 struct greth_private *greth; 1379 struct greth_private *greth;
@@ -1412,7 +1412,7 @@ static int __devinit greth_of_probe(struct of_device *ofdev, const struct of_dev
1412 } 1412 }
1413 1413
1414 regs = (struct greth_regs *) greth->regs; 1414 regs = (struct greth_regs *) greth->regs;
1415 greth->irq = ofdev->irqs[0]; 1415 greth->irq = ofdev->archdata.irqs[0];
1416 1416
1417 dev_set_drvdata(greth->dev, dev); 1417 dev_set_drvdata(greth->dev, dev);
1418 SET_NETDEV_DEV(dev, greth->dev); 1418 SET_NETDEV_DEV(dev, greth->dev);
@@ -1572,7 +1572,7 @@ error1:
1572 return err; 1572 return err;
1573} 1573}
1574 1574
1575static int __devexit greth_of_remove(struct of_device *of_dev) 1575static int __devexit greth_of_remove(struct platform_device *of_dev)
1576{ 1576{
1577 struct net_device *ndev = dev_get_drvdata(&of_dev->dev); 1577 struct net_device *ndev = dev_get_drvdata(&of_dev->dev);
1578 struct greth_private *greth = netdev_priv(ndev); 1578 struct greth_private *greth = netdev_priv(ndev);
diff --git a/drivers/net/greth.h b/drivers/net/greth.h
index 973388d6abca..03ad903cd676 100644
--- a/drivers/net/greth.h
+++ b/drivers/net/greth.h
@@ -118,7 +118,7 @@ struct greth_private {
118 118
119 int irq; 119 int irq;
120 120
121 struct device *dev; /* Pointer to of_device->dev */ 121 struct device *dev; /* Pointer to platform_device->dev */
122 struct net_device *netdev; 122 struct net_device *netdev;
123 struct napi_struct napi; 123 struct napi_struct napi;
124 spinlock_t devlock; 124 spinlock_t devlock;
diff --git a/drivers/net/ibm_newemac/core.c b/drivers/net/ibm_newemac/core.c
index eeec7bc2ce74..3506fd6ad726 100644
--- a/drivers/net/ibm_newemac/core.c
+++ b/drivers/net/ibm_newemac/core.c
@@ -2245,7 +2245,7 @@ static int emac_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd)
2245struct emac_depentry { 2245struct emac_depentry {
2246 u32 phandle; 2246 u32 phandle;
2247 struct device_node *node; 2247 struct device_node *node;
2248 struct of_device *ofdev; 2248 struct platform_device *ofdev;
2249 void *drvdata; 2249 void *drvdata;
2250}; 2250};
2251 2251
@@ -2719,7 +2719,7 @@ static const struct net_device_ops emac_gige_netdev_ops = {
2719 .ndo_change_mtu = emac_change_mtu, 2719 .ndo_change_mtu = emac_change_mtu,
2720}; 2720};
2721 2721
2722static int __devinit emac_probe(struct of_device *ofdev, 2722static int __devinit emac_probe(struct platform_device *ofdev,
2723 const struct of_device_id *match) 2723 const struct of_device_id *match)
2724{ 2724{
2725 struct net_device *ndev; 2725 struct net_device *ndev;
@@ -2941,7 +2941,7 @@ static int __devinit emac_probe(struct of_device *ofdev,
2941 return err; 2941 return err;
2942} 2942}
2943 2943
2944static int __devexit emac_remove(struct of_device *ofdev) 2944static int __devexit emac_remove(struct platform_device *ofdev)
2945{ 2945{
2946 struct emac_instance *dev = dev_get_drvdata(&ofdev->dev); 2946 struct emac_instance *dev = dev_get_drvdata(&ofdev->dev);
2947 2947
diff --git a/drivers/net/ibm_newemac/core.h b/drivers/net/ibm_newemac/core.h
index b1cbe6fdfc7a..9e37e3d9c51d 100644
--- a/drivers/net/ibm_newemac/core.h
+++ b/drivers/net/ibm_newemac/core.h
@@ -170,12 +170,12 @@ struct emac_instance {
170 struct net_device *ndev; 170 struct net_device *ndev;
171 struct resource rsrc_regs; 171 struct resource rsrc_regs;
172 struct emac_regs __iomem *emacp; 172 struct emac_regs __iomem *emacp;
173 struct of_device *ofdev; 173 struct platform_device *ofdev;
174 struct device_node **blist; /* bootlist entry */ 174 struct device_node **blist; /* bootlist entry */
175 175
176 /* MAL linkage */ 176 /* MAL linkage */
177 u32 mal_ph; 177 u32 mal_ph;
178 struct of_device *mal_dev; 178 struct platform_device *mal_dev;
179 u32 mal_rx_chan; 179 u32 mal_rx_chan;
180 u32 mal_tx_chan; 180 u32 mal_tx_chan;
181 struct mal_instance *mal; 181 struct mal_instance *mal;
@@ -196,24 +196,24 @@ struct emac_instance {
196 196
197 /* Shared MDIO if any */ 197 /* Shared MDIO if any */
198 u32 mdio_ph; 198 u32 mdio_ph;
199 struct of_device *mdio_dev; 199 struct platform_device *mdio_dev;
200 struct emac_instance *mdio_instance; 200 struct emac_instance *mdio_instance;
201 struct mutex mdio_lock; 201 struct mutex mdio_lock;
202 202
203 /* ZMII infos if any */ 203 /* ZMII infos if any */
204 u32 zmii_ph; 204 u32 zmii_ph;
205 u32 zmii_port; 205 u32 zmii_port;
206 struct of_device *zmii_dev; 206 struct platform_device *zmii_dev;
207 207
208 /* RGMII infos if any */ 208 /* RGMII infos if any */
209 u32 rgmii_ph; 209 u32 rgmii_ph;
210 u32 rgmii_port; 210 u32 rgmii_port;
211 struct of_device *rgmii_dev; 211 struct platform_device *rgmii_dev;
212 212
213 /* TAH infos if any */ 213 /* TAH infos if any */
214 u32 tah_ph; 214 u32 tah_ph;
215 u32 tah_port; 215 u32 tah_port;
216 struct of_device *tah_dev; 216 struct platform_device *tah_dev;
217 217
218 /* IRQs */ 218 /* IRQs */
219 int wol_irq; 219 int wol_irq;
diff --git a/drivers/net/ibm_newemac/mal.c b/drivers/net/ibm_newemac/mal.c
index fcff9e0bd382..d5717e2123e1 100644
--- a/drivers/net/ibm_newemac/mal.c
+++ b/drivers/net/ibm_newemac/mal.c
@@ -517,7 +517,7 @@ void *mal_dump_regs(struct mal_instance *mal, void *buf)
517 return regs + 1; 517 return regs + 1;
518} 518}
519 519
520static int __devinit mal_probe(struct of_device *ofdev, 520static int __devinit mal_probe(struct platform_device *ofdev,
521 const struct of_device_id *match) 521 const struct of_device_id *match)
522{ 522{
523 struct mal_instance *mal; 523 struct mal_instance *mal;
@@ -730,7 +730,7 @@ static int __devinit mal_probe(struct of_device *ofdev,
730 return err; 730 return err;
731} 731}
732 732
733static int __devexit mal_remove(struct of_device *ofdev) 733static int __devexit mal_remove(struct platform_device *ofdev)
734{ 734{
735 struct mal_instance *mal = dev_get_drvdata(&ofdev->dev); 735 struct mal_instance *mal = dev_get_drvdata(&ofdev->dev);
736 736
diff --git a/drivers/net/ibm_newemac/mal.h b/drivers/net/ibm_newemac/mal.h
index 9ededfbf0726..66084214bf45 100644
--- a/drivers/net/ibm_newemac/mal.h
+++ b/drivers/net/ibm_newemac/mal.h
@@ -210,7 +210,7 @@ struct mal_instance {
210 dma_addr_t bd_dma; 210 dma_addr_t bd_dma;
211 struct mal_descriptor *bd_virt; 211 struct mal_descriptor *bd_virt;
212 212
213 struct of_device *ofdev; 213 struct platform_device *ofdev;
214 int index; 214 int index;
215 spinlock_t lock; 215 spinlock_t lock;
216 216
diff --git a/drivers/net/ibm_newemac/rgmii.c b/drivers/net/ibm_newemac/rgmii.c
index 108919bcdf13..dd61798897ac 100644
--- a/drivers/net/ibm_newemac/rgmii.c
+++ b/drivers/net/ibm_newemac/rgmii.c
@@ -93,7 +93,7 @@ static inline u32 rgmii_mode_mask(int mode, int input)
93 } 93 }
94} 94}
95 95
96int __devinit rgmii_attach(struct of_device *ofdev, int input, int mode) 96int __devinit rgmii_attach(struct platform_device *ofdev, int input, int mode)
97{ 97{
98 struct rgmii_instance *dev = dev_get_drvdata(&ofdev->dev); 98 struct rgmii_instance *dev = dev_get_drvdata(&ofdev->dev);
99 struct rgmii_regs __iomem *p = dev->base; 99 struct rgmii_regs __iomem *p = dev->base;
@@ -122,7 +122,7 @@ int __devinit rgmii_attach(struct of_device *ofdev, int input, int mode)
122 return 0; 122 return 0;
123} 123}
124 124
125void rgmii_set_speed(struct of_device *ofdev, int input, int speed) 125void rgmii_set_speed(struct platform_device *ofdev, int input, int speed)
126{ 126{
127 struct rgmii_instance *dev = dev_get_drvdata(&ofdev->dev); 127 struct rgmii_instance *dev = dev_get_drvdata(&ofdev->dev);
128 struct rgmii_regs __iomem *p = dev->base; 128 struct rgmii_regs __iomem *p = dev->base;
@@ -144,7 +144,7 @@ void rgmii_set_speed(struct of_device *ofdev, int input, int speed)
144 mutex_unlock(&dev->lock); 144 mutex_unlock(&dev->lock);
145} 145}
146 146
147void rgmii_get_mdio(struct of_device *ofdev, int input) 147void rgmii_get_mdio(struct platform_device *ofdev, int input)
148{ 148{
149 struct rgmii_instance *dev = dev_get_drvdata(&ofdev->dev); 149 struct rgmii_instance *dev = dev_get_drvdata(&ofdev->dev);
150 struct rgmii_regs __iomem *p = dev->base; 150 struct rgmii_regs __iomem *p = dev->base;
@@ -165,7 +165,7 @@ void rgmii_get_mdio(struct of_device *ofdev, int input)
165 DBG2(dev, " fer = 0x%08x\n", fer); 165 DBG2(dev, " fer = 0x%08x\n", fer);
166} 166}
167 167
168void rgmii_put_mdio(struct of_device *ofdev, int input) 168void rgmii_put_mdio(struct platform_device *ofdev, int input)
169{ 169{
170 struct rgmii_instance *dev = dev_get_drvdata(&ofdev->dev); 170 struct rgmii_instance *dev = dev_get_drvdata(&ofdev->dev);
171 struct rgmii_regs __iomem *p = dev->base; 171 struct rgmii_regs __iomem *p = dev->base;
@@ -186,7 +186,7 @@ void rgmii_put_mdio(struct of_device *ofdev, int input)
186 mutex_unlock(&dev->lock); 186 mutex_unlock(&dev->lock);
187} 187}
188 188
189void rgmii_detach(struct of_device *ofdev, int input) 189void rgmii_detach(struct platform_device *ofdev, int input)
190{ 190{
191 struct rgmii_instance *dev = dev_get_drvdata(&ofdev->dev); 191 struct rgmii_instance *dev = dev_get_drvdata(&ofdev->dev);
192 struct rgmii_regs __iomem *p; 192 struct rgmii_regs __iomem *p;
@@ -206,13 +206,13 @@ void rgmii_detach(struct of_device *ofdev, int input)
206 mutex_unlock(&dev->lock); 206 mutex_unlock(&dev->lock);
207} 207}
208 208
209int rgmii_get_regs_len(struct of_device *ofdev) 209int rgmii_get_regs_len(struct platform_device *ofdev)
210{ 210{
211 return sizeof(struct emac_ethtool_regs_subhdr) + 211 return sizeof(struct emac_ethtool_regs_subhdr) +
212 sizeof(struct rgmii_regs); 212 sizeof(struct rgmii_regs);
213} 213}
214 214
215void *rgmii_dump_regs(struct of_device *ofdev, void *buf) 215void *rgmii_dump_regs(struct platform_device *ofdev, void *buf)
216{ 216{
217 struct rgmii_instance *dev = dev_get_drvdata(&ofdev->dev); 217 struct rgmii_instance *dev = dev_get_drvdata(&ofdev->dev);
218 struct emac_ethtool_regs_subhdr *hdr = buf; 218 struct emac_ethtool_regs_subhdr *hdr = buf;
@@ -228,7 +228,7 @@ void *rgmii_dump_regs(struct of_device *ofdev, void *buf)
228} 228}
229 229
230 230
231static int __devinit rgmii_probe(struct of_device *ofdev, 231static int __devinit rgmii_probe(struct platform_device *ofdev,
232 const struct of_device_id *match) 232 const struct of_device_id *match)
233{ 233{
234 struct device_node *np = ofdev->dev.of_node; 234 struct device_node *np = ofdev->dev.of_node;
@@ -293,7 +293,7 @@ static int __devinit rgmii_probe(struct of_device *ofdev,
293 return rc; 293 return rc;
294} 294}
295 295
296static int __devexit rgmii_remove(struct of_device *ofdev) 296static int __devexit rgmii_remove(struct platform_device *ofdev)
297{ 297{
298 struct rgmii_instance *dev = dev_get_drvdata(&ofdev->dev); 298 struct rgmii_instance *dev = dev_get_drvdata(&ofdev->dev);
299 299
diff --git a/drivers/net/ibm_newemac/rgmii.h b/drivers/net/ibm_newemac/rgmii.h
index c4a4b358a270..d69799049865 100644
--- a/drivers/net/ibm_newemac/rgmii.h
+++ b/drivers/net/ibm_newemac/rgmii.h
@@ -51,20 +51,20 @@ struct rgmii_instance {
51 int users; 51 int users;
52 52
53 /* OF device instance */ 53 /* OF device instance */
54 struct of_device *ofdev; 54 struct platform_device *ofdev;
55}; 55};
56 56
57#ifdef CONFIG_IBM_NEW_EMAC_RGMII 57#ifdef CONFIG_IBM_NEW_EMAC_RGMII
58 58
59extern int rgmii_init(void); 59extern int rgmii_init(void);
60extern void rgmii_exit(void); 60extern void rgmii_exit(void);
61extern int rgmii_attach(struct of_device *ofdev, int input, int mode); 61extern int rgmii_attach(struct platform_device *ofdev, int input, int mode);
62extern void rgmii_detach(struct of_device *ofdev, int input); 62extern void rgmii_detach(struct platform_device *ofdev, int input);
63extern void rgmii_get_mdio(struct of_device *ofdev, int input); 63extern void rgmii_get_mdio(struct platform_device *ofdev, int input);
64extern void rgmii_put_mdio(struct of_device *ofdev, int input); 64extern void rgmii_put_mdio(struct platform_device *ofdev, int input);
65extern void rgmii_set_speed(struct of_device *ofdev, int input, int speed); 65extern void rgmii_set_speed(struct platform_device *ofdev, int input, int speed);
66extern int rgmii_get_regs_len(struct of_device *ofdev); 66extern int rgmii_get_regs_len(struct platform_device *ofdev);
67extern void *rgmii_dump_regs(struct of_device *ofdev, void *buf); 67extern void *rgmii_dump_regs(struct platform_device *ofdev, void *buf);
68 68
69#else 69#else
70 70
diff --git a/drivers/net/ibm_newemac/tah.c b/drivers/net/ibm_newemac/tah.c
index 044637144c43..299aa49490c0 100644
--- a/drivers/net/ibm_newemac/tah.c
+++ b/drivers/net/ibm_newemac/tah.c
@@ -23,7 +23,7 @@
23#include "emac.h" 23#include "emac.h"
24#include "core.h" 24#include "core.h"
25 25
26int __devinit tah_attach(struct of_device *ofdev, int channel) 26int __devinit tah_attach(struct platform_device *ofdev, int channel)
27{ 27{
28 struct tah_instance *dev = dev_get_drvdata(&ofdev->dev); 28 struct tah_instance *dev = dev_get_drvdata(&ofdev->dev);
29 29
@@ -35,7 +35,7 @@ int __devinit tah_attach(struct of_device *ofdev, int channel)
35 return 0; 35 return 0;
36} 36}
37 37
38void tah_detach(struct of_device *ofdev, int channel) 38void tah_detach(struct platform_device *ofdev, int channel)
39{ 39{
40 struct tah_instance *dev = dev_get_drvdata(&ofdev->dev); 40 struct tah_instance *dev = dev_get_drvdata(&ofdev->dev);
41 41
@@ -44,7 +44,7 @@ void tah_detach(struct of_device *ofdev, int channel)
44 mutex_unlock(&dev->lock); 44 mutex_unlock(&dev->lock);
45} 45}
46 46
47void tah_reset(struct of_device *ofdev) 47void tah_reset(struct platform_device *ofdev)
48{ 48{
49 struct tah_instance *dev = dev_get_drvdata(&ofdev->dev); 49 struct tah_instance *dev = dev_get_drvdata(&ofdev->dev);
50 struct tah_regs __iomem *p = dev->base; 50 struct tah_regs __iomem *p = dev->base;
@@ -66,13 +66,13 @@ void tah_reset(struct of_device *ofdev)
66 TAH_MR_DIG); 66 TAH_MR_DIG);
67} 67}
68 68
69int tah_get_regs_len(struct of_device *ofdev) 69int tah_get_regs_len(struct platform_device *ofdev)
70{ 70{
71 return sizeof(struct emac_ethtool_regs_subhdr) + 71 return sizeof(struct emac_ethtool_regs_subhdr) +
72 sizeof(struct tah_regs); 72 sizeof(struct tah_regs);
73} 73}
74 74
75void *tah_dump_regs(struct of_device *ofdev, void *buf) 75void *tah_dump_regs(struct platform_device *ofdev, void *buf)
76{ 76{
77 struct tah_instance *dev = dev_get_drvdata(&ofdev->dev); 77 struct tah_instance *dev = dev_get_drvdata(&ofdev->dev);
78 struct emac_ethtool_regs_subhdr *hdr = buf; 78 struct emac_ethtool_regs_subhdr *hdr = buf;
@@ -87,7 +87,7 @@ void *tah_dump_regs(struct of_device *ofdev, void *buf)
87 return regs + 1; 87 return regs + 1;
88} 88}
89 89
90static int __devinit tah_probe(struct of_device *ofdev, 90static int __devinit tah_probe(struct platform_device *ofdev,
91 const struct of_device_id *match) 91 const struct of_device_id *match)
92{ 92{
93 struct device_node *np = ofdev->dev.of_node; 93 struct device_node *np = ofdev->dev.of_node;
@@ -139,7 +139,7 @@ static int __devinit tah_probe(struct of_device *ofdev,
139 return rc; 139 return rc;
140} 140}
141 141
142static int __devexit tah_remove(struct of_device *ofdev) 142static int __devexit tah_remove(struct platform_device *ofdev)
143{ 143{
144 struct tah_instance *dev = dev_get_drvdata(&ofdev->dev); 144 struct tah_instance *dev = dev_get_drvdata(&ofdev->dev);
145 145
diff --git a/drivers/net/ibm_newemac/tah.h b/drivers/net/ibm_newemac/tah.h
index a068b5658dad..61dbeca006d1 100644
--- a/drivers/net/ibm_newemac/tah.h
+++ b/drivers/net/ibm_newemac/tah.h
@@ -48,7 +48,7 @@ struct tah_instance {
48 int users; 48 int users;
49 49
50 /* OF device instance */ 50 /* OF device instance */
51 struct of_device *ofdev; 51 struct platform_device *ofdev;
52}; 52};
53 53
54 54
@@ -74,11 +74,11 @@ struct tah_instance {
74 74
75extern int tah_init(void); 75extern int tah_init(void);
76extern void tah_exit(void); 76extern void tah_exit(void);
77extern int tah_attach(struct of_device *ofdev, int channel); 77extern int tah_attach(struct platform_device *ofdev, int channel);
78extern void tah_detach(struct of_device *ofdev, int channel); 78extern void tah_detach(struct platform_device *ofdev, int channel);
79extern void tah_reset(struct of_device *ofdev); 79extern void tah_reset(struct platform_device *ofdev);
80extern int tah_get_regs_len(struct of_device *ofdev); 80extern int tah_get_regs_len(struct platform_device *ofdev);
81extern void *tah_dump_regs(struct of_device *ofdev, void *buf); 81extern void *tah_dump_regs(struct platform_device *ofdev, void *buf);
82 82
83#else 83#else
84 84
diff --git a/drivers/net/ibm_newemac/zmii.c b/drivers/net/ibm_newemac/zmii.c
index 046dcd069c45..34ed6ee8ca8a 100644
--- a/drivers/net/ibm_newemac/zmii.c
+++ b/drivers/net/ibm_newemac/zmii.c
@@ -82,7 +82,7 @@ static inline u32 zmii_mode_mask(int mode, int input)
82 } 82 }
83} 83}
84 84
85int __devinit zmii_attach(struct of_device *ofdev, int input, int *mode) 85int __devinit zmii_attach(struct platform_device *ofdev, int input, int *mode)
86{ 86{
87 struct zmii_instance *dev = dev_get_drvdata(&ofdev->dev); 87 struct zmii_instance *dev = dev_get_drvdata(&ofdev->dev);
88 struct zmii_regs __iomem *p = dev->base; 88 struct zmii_regs __iomem *p = dev->base;
@@ -148,7 +148,7 @@ int __devinit zmii_attach(struct of_device *ofdev, int input, int *mode)
148 return 0; 148 return 0;
149} 149}
150 150
151void zmii_get_mdio(struct of_device *ofdev, int input) 151void zmii_get_mdio(struct platform_device *ofdev, int input)
152{ 152{
153 struct zmii_instance *dev = dev_get_drvdata(&ofdev->dev); 153 struct zmii_instance *dev = dev_get_drvdata(&ofdev->dev);
154 u32 fer; 154 u32 fer;
@@ -161,7 +161,7 @@ void zmii_get_mdio(struct of_device *ofdev, int input)
161 out_be32(&dev->base->fer, fer | ZMII_FER_MDI(input)); 161 out_be32(&dev->base->fer, fer | ZMII_FER_MDI(input));
162} 162}
163 163
164void zmii_put_mdio(struct of_device *ofdev, int input) 164void zmii_put_mdio(struct platform_device *ofdev, int input)
165{ 165{
166 struct zmii_instance *dev = dev_get_drvdata(&ofdev->dev); 166 struct zmii_instance *dev = dev_get_drvdata(&ofdev->dev);
167 167
@@ -170,7 +170,7 @@ void zmii_put_mdio(struct of_device *ofdev, int input)
170} 170}
171 171
172 172
173void zmii_set_speed(struct of_device *ofdev, int input, int speed) 173void zmii_set_speed(struct platform_device *ofdev, int input, int speed)
174{ 174{
175 struct zmii_instance *dev = dev_get_drvdata(&ofdev->dev); 175 struct zmii_instance *dev = dev_get_drvdata(&ofdev->dev);
176 u32 ssr; 176 u32 ssr;
@@ -191,7 +191,7 @@ void zmii_set_speed(struct of_device *ofdev, int input, int speed)
191 mutex_unlock(&dev->lock); 191 mutex_unlock(&dev->lock);
192} 192}
193 193
194void zmii_detach(struct of_device *ofdev, int input) 194void zmii_detach(struct platform_device *ofdev, int input)
195{ 195{
196 struct zmii_instance *dev = dev_get_drvdata(&ofdev->dev); 196 struct zmii_instance *dev = dev_get_drvdata(&ofdev->dev);
197 197
@@ -210,13 +210,13 @@ void zmii_detach(struct of_device *ofdev, int input)
210 mutex_unlock(&dev->lock); 210 mutex_unlock(&dev->lock);
211} 211}
212 212
213int zmii_get_regs_len(struct of_device *ofdev) 213int zmii_get_regs_len(struct platform_device *ofdev)
214{ 214{
215 return sizeof(struct emac_ethtool_regs_subhdr) + 215 return sizeof(struct emac_ethtool_regs_subhdr) +
216 sizeof(struct zmii_regs); 216 sizeof(struct zmii_regs);
217} 217}
218 218
219void *zmii_dump_regs(struct of_device *ofdev, void *buf) 219void *zmii_dump_regs(struct platform_device *ofdev, void *buf)
220{ 220{
221 struct zmii_instance *dev = dev_get_drvdata(&ofdev->dev); 221 struct zmii_instance *dev = dev_get_drvdata(&ofdev->dev);
222 struct emac_ethtool_regs_subhdr *hdr = buf; 222 struct emac_ethtool_regs_subhdr *hdr = buf;
@@ -231,7 +231,7 @@ void *zmii_dump_regs(struct of_device *ofdev, void *buf)
231 return regs + 1; 231 return regs + 1;
232} 232}
233 233
234static int __devinit zmii_probe(struct of_device *ofdev, 234static int __devinit zmii_probe(struct platform_device *ofdev,
235 const struct of_device_id *match) 235 const struct of_device_id *match)
236{ 236{
237 struct device_node *np = ofdev->dev.of_node; 237 struct device_node *np = ofdev->dev.of_node;
@@ -286,7 +286,7 @@ static int __devinit zmii_probe(struct of_device *ofdev,
286 return rc; 286 return rc;
287} 287}
288 288
289static int __devexit zmii_remove(struct of_device *ofdev) 289static int __devexit zmii_remove(struct platform_device *ofdev)
290{ 290{
291 struct zmii_instance *dev = dev_get_drvdata(&ofdev->dev); 291 struct zmii_instance *dev = dev_get_drvdata(&ofdev->dev);
292 292
diff --git a/drivers/net/ibm_newemac/zmii.h b/drivers/net/ibm_newemac/zmii.h
index 6c9beba0c4b6..1333fa2b2781 100644
--- a/drivers/net/ibm_newemac/zmii.h
+++ b/drivers/net/ibm_newemac/zmii.h
@@ -48,20 +48,20 @@ struct zmii_instance {
48 u32 fer_save; 48 u32 fer_save;
49 49
50 /* OF device instance */ 50 /* OF device instance */
51 struct of_device *ofdev; 51 struct platform_device *ofdev;
52}; 52};
53 53
54#ifdef CONFIG_IBM_NEW_EMAC_ZMII 54#ifdef CONFIG_IBM_NEW_EMAC_ZMII
55 55
56extern int zmii_init(void); 56extern int zmii_init(void);
57extern void zmii_exit(void); 57extern void zmii_exit(void);
58extern int zmii_attach(struct of_device *ofdev, int input, int *mode); 58extern int zmii_attach(struct platform_device *ofdev, int input, int *mode);
59extern void zmii_detach(struct of_device *ofdev, int input); 59extern void zmii_detach(struct platform_device *ofdev, int input);
60extern void zmii_get_mdio(struct of_device *ofdev, int input); 60extern void zmii_get_mdio(struct platform_device *ofdev, int input);
61extern void zmii_put_mdio(struct of_device *ofdev, int input); 61extern void zmii_put_mdio(struct platform_device *ofdev, int input);
62extern void zmii_set_speed(struct of_device *ofdev, int input, int speed); 62extern void zmii_set_speed(struct platform_device *ofdev, int input, int speed);
63extern int zmii_get_regs_len(struct of_device *ocpdev); 63extern int zmii_get_regs_len(struct platform_device *ocpdev);
64extern void *zmii_dump_regs(struct of_device *ofdev, void *buf); 64extern void *zmii_dump_regs(struct platform_device *ofdev, void *buf);
65 65
66#else 66#else
67# define zmii_init() 0 67# define zmii_init() 0
diff --git a/drivers/net/igb/igb_main.c b/drivers/net/igb/igb_main.c
index df5dcd23e4fc..9b4e5895f5f9 100644
--- a/drivers/net/igb/igb_main.c
+++ b/drivers/net/igb/igb_main.c
@@ -5353,6 +5353,7 @@ static bool igb_clean_tx_irq(struct igb_q_vector *q_vector)
5353 5353
5354 while ((eop_desc->wb.status & cpu_to_le32(E1000_TXD_STAT_DD)) && 5354 while ((eop_desc->wb.status & cpu_to_le32(E1000_TXD_STAT_DD)) &&
5355 (count < tx_ring->count)) { 5355 (count < tx_ring->count)) {
5356 rmb(); /* read buffer_info after eop_desc status */
5356 for (cleaned = false; !cleaned; count++) { 5357 for (cleaned = false; !cleaned; count++) {
5357 tx_desc = E1000_TX_DESC_ADV(*tx_ring, i); 5358 tx_desc = E1000_TX_DESC_ADV(*tx_ring, i);
5358 buffer_info = &tx_ring->buffer_info[i]; 5359 buffer_info = &tx_ring->buffer_info[i];
@@ -5558,6 +5559,7 @@ static bool igb_clean_rx_irq_adv(struct igb_q_vector *q_vector,
5558 if (*work_done >= budget) 5559 if (*work_done >= budget)
5559 break; 5560 break;
5560 (*work_done)++; 5561 (*work_done)++;
5562 rmb(); /* read descriptor and rx_buffer_info after status DD */
5561 5563
5562 skb = buffer_info->skb; 5564 skb = buffer_info->skb;
5563 prefetch(skb->data - NET_IP_ALIGN); 5565 prefetch(skb->data - NET_IP_ALIGN);
diff --git a/drivers/net/igbvf/netdev.c b/drivers/net/igbvf/netdev.c
index ec808fa8dc21..c539f7c9c3e0 100644
--- a/drivers/net/igbvf/netdev.c
+++ b/drivers/net/igbvf/netdev.c
@@ -248,6 +248,7 @@ static bool igbvf_clean_rx_irq(struct igbvf_adapter *adapter,
248 if (*work_done >= work_to_do) 248 if (*work_done >= work_to_do)
249 break; 249 break;
250 (*work_done)++; 250 (*work_done)++;
251 rmb(); /* read descriptor and rx_buffer_info after status DD */
251 252
252 buffer_info = &rx_ring->buffer_info[i]; 253 buffer_info = &rx_ring->buffer_info[i];
253 254
@@ -780,6 +781,7 @@ static bool igbvf_clean_tx_irq(struct igbvf_ring *tx_ring)
780 781
781 while ((eop_desc->wb.status & cpu_to_le32(E1000_TXD_STAT_DD)) && 782 while ((eop_desc->wb.status & cpu_to_le32(E1000_TXD_STAT_DD)) &&
782 (count < tx_ring->count)) { 783 (count < tx_ring->count)) {
784 rmb(); /* read buffer_info after eop_desc status */
783 for (cleaned = false; !cleaned; count++) { 785 for (cleaned = false; !cleaned; count++) {
784 tx_desc = IGBVF_TX_DESC_ADV(*tx_ring, i); 786 tx_desc = IGBVF_TX_DESC_ADV(*tx_ring, i);
785 buffer_info = &tx_ring->buffer_info[i]; 787 buffer_info = &tx_ring->buffer_info[i];
diff --git a/drivers/net/irda/sh_irda.c b/drivers/net/irda/sh_irda.c
index edd5666f0ffb..9e3f4f54281d 100644
--- a/drivers/net/irda/sh_irda.c
+++ b/drivers/net/irda/sh_irda.c
@@ -748,7 +748,6 @@ static int __devinit sh_irda_probe(struct platform_device *pdev)
748 struct net_device *ndev; 748 struct net_device *ndev;
749 struct sh_irda_self *self; 749 struct sh_irda_self *self;
750 struct resource *res; 750 struct resource *res;
751 char clk_name[8];
752 int irq; 751 int irq;
753 int err = -ENOMEM; 752 int err = -ENOMEM;
754 753
@@ -775,10 +774,9 @@ static int __devinit sh_irda_probe(struct platform_device *pdev)
775 if (err) 774 if (err)
776 goto err_mem_2; 775 goto err_mem_2;
777 776
778 snprintf(clk_name, sizeof(clk_name), "irda%d", pdev->id); 777 self->clk = clk_get(&pdev->dev, NULL);
779 self->clk = clk_get(&pdev->dev, clk_name);
780 if (IS_ERR(self->clk)) { 778 if (IS_ERR(self->clk)) {
781 dev_err(&pdev->dev, "cannot get clock \"%s\"\n", clk_name); 779 dev_err(&pdev->dev, "cannot get irda clock\n");
782 goto err_mem_3; 780 goto err_mem_3;
783 } 781 }
784 782
diff --git a/drivers/net/ixgb/ixgb_main.c b/drivers/net/ixgb/ixgb_main.c
index c6b75c83100c..45fc89b9ba64 100644
--- a/drivers/net/ixgb/ixgb_main.c
+++ b/drivers/net/ixgb/ixgb_main.c
@@ -1816,6 +1816,7 @@ ixgb_clean_tx_irq(struct ixgb_adapter *adapter)
1816 1816
1817 while (eop_desc->status & IXGB_TX_DESC_STATUS_DD) { 1817 while (eop_desc->status & IXGB_TX_DESC_STATUS_DD) {
1818 1818
1819 rmb(); /* read buffer_info after eop_desc */
1819 for (cleaned = false; !cleaned; ) { 1820 for (cleaned = false; !cleaned; ) {
1820 tx_desc = IXGB_TX_DESC(*tx_ring, i); 1821 tx_desc = IXGB_TX_DESC(*tx_ring, i);
1821 buffer_info = &tx_ring->buffer_info[i]; 1822 buffer_info = &tx_ring->buffer_info[i];
@@ -1976,6 +1977,7 @@ ixgb_clean_rx_irq(struct ixgb_adapter *adapter, int *work_done, int work_to_do)
1976 break; 1977 break;
1977 1978
1978 (*work_done)++; 1979 (*work_done)++;
1980 rmb(); /* read descriptor and rx_buffer_info after status DD */
1979 status = rx_desc->status; 1981 status = rx_desc->status;
1980 skb = buffer_info->skb; 1982 skb = buffer_info->skb;
1981 buffer_info->skb = NULL; 1983 buffer_info->skb = NULL;
diff --git a/drivers/net/ixgbe/ixgbe_main.c b/drivers/net/ixgbe/ixgbe_main.c
index 7d6a415bcf88..e32af434cc9d 100644
--- a/drivers/net/ixgbe/ixgbe_main.c
+++ b/drivers/net/ixgbe/ixgbe_main.c
@@ -748,6 +748,7 @@ static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
748 while ((eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)) && 748 while ((eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)) &&
749 (count < tx_ring->work_limit)) { 749 (count < tx_ring->work_limit)) {
750 bool cleaned = false; 750 bool cleaned = false;
751 rmb(); /* read buffer_info after eop_desc */
751 for ( ; !cleaned; count++) { 752 for ( ; !cleaned; count++) {
752 struct sk_buff *skb; 753 struct sk_buff *skb;
753 tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i); 754 tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i);
@@ -6155,9 +6156,11 @@ static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
6155 txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1); 6156 txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1);
6156 txq += adapter->ring_feature[RING_F_FCOE].mask; 6157 txq += adapter->ring_feature[RING_F_FCOE].mask;
6157 return txq; 6158 return txq;
6159#ifdef CONFIG_IXGBE_DCB
6158 } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { 6160 } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
6159 txq = adapter->fcoe.up; 6161 txq = adapter->fcoe.up;
6160 return txq; 6162 return txq;
6163#endif
6161 } 6164 }
6162 } 6165 }
6163#endif 6166#endif
@@ -6216,10 +6219,14 @@ static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb,
6216 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED && 6219 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED &&
6217 (skb->protocol == htons(ETH_P_FCOE) || 6220 (skb->protocol == htons(ETH_P_FCOE) ||
6218 skb->protocol == htons(ETH_P_FIP))) { 6221 skb->protocol == htons(ETH_P_FIP))) {
6219 tx_flags &= ~(IXGBE_TX_FLAGS_VLAN_PRIO_MASK 6222#ifdef CONFIG_IXGBE_DCB
6220 << IXGBE_TX_FLAGS_VLAN_SHIFT); 6223 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
6221 tx_flags |= ((adapter->fcoe.up << 13) 6224 tx_flags &= ~(IXGBE_TX_FLAGS_VLAN_PRIO_MASK
6222 << IXGBE_TX_FLAGS_VLAN_SHIFT); 6225 << IXGBE_TX_FLAGS_VLAN_SHIFT);
6226 tx_flags |= ((adapter->fcoe.up << 13)
6227 << IXGBE_TX_FLAGS_VLAN_SHIFT);
6228 }
6229#endif
6223 /* flag for FCoE offloads */ 6230 /* flag for FCoE offloads */
6224 if (skb->protocol == htons(ETH_P_FCOE)) 6231 if (skb->protocol == htons(ETH_P_FCOE))
6225 tx_flags |= IXGBE_TX_FLAGS_FCOE; 6232 tx_flags |= IXGBE_TX_FLAGS_FCOE;
diff --git a/drivers/net/ixgbevf/ixgbevf_main.c b/drivers/net/ixgbevf/ixgbevf_main.c
index 3e291ccc629d..918c00359b0a 100644
--- a/drivers/net/ixgbevf/ixgbevf_main.c
+++ b/drivers/net/ixgbevf/ixgbevf_main.c
@@ -231,6 +231,7 @@ static bool ixgbevf_clean_tx_irq(struct ixgbevf_adapter *adapter,
231 while ((eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)) && 231 while ((eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)) &&
232 (count < tx_ring->work_limit)) { 232 (count < tx_ring->work_limit)) {
233 bool cleaned = false; 233 bool cleaned = false;
234 rmb(); /* read buffer_info after eop_desc */
234 for ( ; !cleaned; count++) { 235 for ( ; !cleaned; count++) {
235 struct sk_buff *skb; 236 struct sk_buff *skb;
236 tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i); 237 tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i);
@@ -518,6 +519,7 @@ static bool ixgbevf_clean_rx_irq(struct ixgbevf_q_vector *q_vector,
518 break; 519 break;
519 (*work_done)++; 520 (*work_done)++;
520 521
522 rmb(); /* read descriptor and rx_buffer_info after status DD */
521 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) { 523 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
522 hdr_info = le16_to_cpu(ixgbevf_get_hdr_info(rx_desc)); 524 hdr_info = le16_to_cpu(ixgbevf_get_hdr_info(rx_desc));
523 len = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >> 525 len = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >>
diff --git a/drivers/net/ll_temac_main.c b/drivers/net/ll_temac_main.c
index 4eea3f70c5cf..c7b624711f5e 100644
--- a/drivers/net/ll_temac_main.c
+++ b/drivers/net/ll_temac_main.c
@@ -159,7 +159,7 @@ static void temac_dma_dcr_out(struct temac_local *lp, int reg, u32 value)
159 * temac_dcr_setup - If the DMA is DCR based, then setup the address and 159 * temac_dcr_setup - If the DMA is DCR based, then setup the address and
160 * I/O functions 160 * I/O functions
161 */ 161 */
162static int temac_dcr_setup(struct temac_local *lp, struct of_device *op, 162static int temac_dcr_setup(struct temac_local *lp, struct platform_device *op,
163 struct device_node *np) 163 struct device_node *np)
164{ 164{
165 unsigned int dcrs; 165 unsigned int dcrs;
@@ -184,7 +184,7 @@ static int temac_dcr_setup(struct temac_local *lp, struct of_device *op,
184 * temac_dcr_setup - This is a stub for when DCR is not supported, 184 * temac_dcr_setup - This is a stub for when DCR is not supported,
185 * such as with MicroBlaze 185 * such as with MicroBlaze
186 */ 186 */
187static int temac_dcr_setup(struct temac_local *lp, struct of_device *op, 187static int temac_dcr_setup(struct temac_local *lp, struct platform_device *op,
188 struct device_node *np) 188 struct device_node *np)
189{ 189{
190 return -1; 190 return -1;
@@ -952,7 +952,7 @@ static const struct attribute_group temac_attr_group = {
952}; 952};
953 953
954static int __init 954static int __init
955temac_of_probe(struct of_device *op, const struct of_device_id *match) 955temac_of_probe(struct platform_device *op, const struct of_device_id *match)
956{ 956{
957 struct device_node *np; 957 struct device_node *np;
958 struct temac_local *lp; 958 struct temac_local *lp;
@@ -1094,7 +1094,7 @@ temac_of_probe(struct of_device *op, const struct of_device_id *match)
1094 return rc; 1094 return rc;
1095} 1095}
1096 1096
1097static int __devexit temac_of_remove(struct of_device *op) 1097static int __devexit temac_of_remove(struct platform_device *op)
1098{ 1098{
1099 struct net_device *ndev = dev_get_drvdata(&op->dev); 1099 struct net_device *ndev = dev_get_drvdata(&op->dev);
1100 struct temac_local *lp = netdev_priv(ndev); 1100 struct temac_local *lp = netdev_priv(ndev);
diff --git a/drivers/net/myri10ge/myri10ge.c b/drivers/net/myri10ge/myri10ge.c
index d771d1650d60..fb2c0927d3cc 100644
--- a/drivers/net/myri10ge/myri10ge.c
+++ b/drivers/net/myri10ge/myri10ge.c
@@ -239,6 +239,7 @@ struct myri10ge_priv {
239 int watchdog_resets; 239 int watchdog_resets;
240 int watchdog_pause; 240 int watchdog_pause;
241 int pause; 241 int pause;
242 bool fw_name_allocated;
242 char *fw_name; 243 char *fw_name;
243 char eeprom_strings[MYRI10GE_EEPROM_STRINGS_SIZE]; 244 char eeprom_strings[MYRI10GE_EEPROM_STRINGS_SIZE];
244 char *product_code_string; 245 char *product_code_string;
@@ -271,6 +272,7 @@ MODULE_FIRMWARE("myri10ge_eth_z8e.dat");
271MODULE_FIRMWARE("myri10ge_rss_ethp_z8e.dat"); 272MODULE_FIRMWARE("myri10ge_rss_ethp_z8e.dat");
272MODULE_FIRMWARE("myri10ge_rss_eth_z8e.dat"); 273MODULE_FIRMWARE("myri10ge_rss_eth_z8e.dat");
273 274
275/* Careful: must be accessed under kparam_block_sysfs_write */
274static char *myri10ge_fw_name = NULL; 276static char *myri10ge_fw_name = NULL;
275module_param(myri10ge_fw_name, charp, S_IRUGO | S_IWUSR); 277module_param(myri10ge_fw_name, charp, S_IRUGO | S_IWUSR);
276MODULE_PARM_DESC(myri10ge_fw_name, "Firmware image name"); 278MODULE_PARM_DESC(myri10ge_fw_name, "Firmware image name");
@@ -376,6 +378,14 @@ static inline void put_be32(__be32 val, __be32 __iomem * p)
376 378
377static struct net_device_stats *myri10ge_get_stats(struct net_device *dev); 379static struct net_device_stats *myri10ge_get_stats(struct net_device *dev);
378 380
381static void set_fw_name(struct myri10ge_priv *mgp, char *name, bool allocated)
382{
383 if (mgp->fw_name_allocated)
384 kfree(mgp->fw_name);
385 mgp->fw_name = name;
386 mgp->fw_name_allocated = allocated;
387}
388
379static int 389static int
380myri10ge_send_cmd(struct myri10ge_priv *mgp, u32 cmd, 390myri10ge_send_cmd(struct myri10ge_priv *mgp, u32 cmd,
381 struct myri10ge_cmd *data, int atomic) 391 struct myri10ge_cmd *data, int atomic)
@@ -747,7 +757,7 @@ static int myri10ge_load_firmware(struct myri10ge_priv *mgp, int adopt)
747 dev_warn(&mgp->pdev->dev, "via hotplug\n"); 757 dev_warn(&mgp->pdev->dev, "via hotplug\n");
748 } 758 }
749 759
750 mgp->fw_name = "adopted"; 760 set_fw_name(mgp, "adopted", false);
751 mgp->tx_boundary = 2048; 761 mgp->tx_boundary = 2048;
752 myri10ge_dummy_rdma(mgp, 1); 762 myri10ge_dummy_rdma(mgp, 1);
753 status = myri10ge_get_firmware_capabilities(mgp); 763 status = myri10ge_get_firmware_capabilities(mgp);
@@ -3233,7 +3243,7 @@ static void myri10ge_firmware_probe(struct myri10ge_priv *mgp)
3233 * load the optimized firmware (which assumes aligned PCIe 3243 * load the optimized firmware (which assumes aligned PCIe
3234 * completions) in order to see if it works on this host. 3244 * completions) in order to see if it works on this host.
3235 */ 3245 */
3236 mgp->fw_name = myri10ge_fw_aligned; 3246 set_fw_name(mgp, myri10ge_fw_aligned, false);
3237 status = myri10ge_load_firmware(mgp, 1); 3247 status = myri10ge_load_firmware(mgp, 1);
3238 if (status != 0) { 3248 if (status != 0) {
3239 goto abort; 3249 goto abort;
@@ -3261,7 +3271,7 @@ static void myri10ge_firmware_probe(struct myri10ge_priv *mgp)
3261abort: 3271abort:
3262 /* fall back to using the unaligned firmware */ 3272 /* fall back to using the unaligned firmware */
3263 mgp->tx_boundary = 2048; 3273 mgp->tx_boundary = 2048;
3264 mgp->fw_name = myri10ge_fw_unaligned; 3274 set_fw_name(mgp, myri10ge_fw_unaligned, false);
3265 3275
3266} 3276}
3267 3277
@@ -3284,7 +3294,7 @@ static void myri10ge_select_firmware(struct myri10ge_priv *mgp)
3284 dev_info(&mgp->pdev->dev, "PCIE x%d Link\n", 3294 dev_info(&mgp->pdev->dev, "PCIE x%d Link\n",
3285 link_width); 3295 link_width);
3286 mgp->tx_boundary = 4096; 3296 mgp->tx_boundary = 4096;
3287 mgp->fw_name = myri10ge_fw_aligned; 3297 set_fw_name(mgp, myri10ge_fw_aligned, false);
3288 } else { 3298 } else {
3289 myri10ge_firmware_probe(mgp); 3299 myri10ge_firmware_probe(mgp);
3290 } 3300 }
@@ -3293,22 +3303,29 @@ static void myri10ge_select_firmware(struct myri10ge_priv *mgp)
3293 dev_info(&mgp->pdev->dev, 3303 dev_info(&mgp->pdev->dev,
3294 "Assuming aligned completions (forced)\n"); 3304 "Assuming aligned completions (forced)\n");
3295 mgp->tx_boundary = 4096; 3305 mgp->tx_boundary = 4096;
3296 mgp->fw_name = myri10ge_fw_aligned; 3306 set_fw_name(mgp, myri10ge_fw_aligned, false);
3297 } else { 3307 } else {
3298 dev_info(&mgp->pdev->dev, 3308 dev_info(&mgp->pdev->dev,
3299 "Assuming unaligned completions (forced)\n"); 3309 "Assuming unaligned completions (forced)\n");
3300 mgp->tx_boundary = 2048; 3310 mgp->tx_boundary = 2048;
3301 mgp->fw_name = myri10ge_fw_unaligned; 3311 set_fw_name(mgp, myri10ge_fw_unaligned, false);
3302 } 3312 }
3303 } 3313 }
3314
3315 kparam_block_sysfs_write(myri10ge_fw_name);
3304 if (myri10ge_fw_name != NULL) { 3316 if (myri10ge_fw_name != NULL) {
3305 overridden = 1; 3317 char *fw_name = kstrdup(myri10ge_fw_name, GFP_KERNEL);
3306 mgp->fw_name = myri10ge_fw_name; 3318 if (fw_name) {
3319 overridden = 1;
3320 set_fw_name(mgp, fw_name, true);
3321 }
3307 } 3322 }
3323 kparam_unblock_sysfs_write(myri10ge_fw_name);
3324
3308 if (mgp->board_number < MYRI10GE_MAX_BOARDS && 3325 if (mgp->board_number < MYRI10GE_MAX_BOARDS &&
3309 myri10ge_fw_names[mgp->board_number] != NULL && 3326 myri10ge_fw_names[mgp->board_number] != NULL &&
3310 strlen(myri10ge_fw_names[mgp->board_number])) { 3327 strlen(myri10ge_fw_names[mgp->board_number])) {
3311 mgp->fw_name = myri10ge_fw_names[mgp->board_number]; 3328 set_fw_name(mgp, myri10ge_fw_names[mgp->board_number], false);
3312 overridden = 1; 3329 overridden = 1;
3313 } 3330 }
3314 if (overridden) 3331 if (overridden)
@@ -3660,6 +3677,7 @@ static void myri10ge_probe_slices(struct myri10ge_priv *mgp)
3660 struct myri10ge_cmd cmd; 3677 struct myri10ge_cmd cmd;
3661 struct pci_dev *pdev = mgp->pdev; 3678 struct pci_dev *pdev = mgp->pdev;
3662 char *old_fw; 3679 char *old_fw;
3680 bool old_allocated;
3663 int i, status, ncpus, msix_cap; 3681 int i, status, ncpus, msix_cap;
3664 3682
3665 mgp->num_slices = 1; 3683 mgp->num_slices = 1;
@@ -3672,17 +3690,23 @@ static void myri10ge_probe_slices(struct myri10ge_priv *mgp)
3672 3690
3673 /* try to load the slice aware rss firmware */ 3691 /* try to load the slice aware rss firmware */
3674 old_fw = mgp->fw_name; 3692 old_fw = mgp->fw_name;
3693 old_allocated = mgp->fw_name_allocated;
3694 /* don't free old_fw if we override it. */
3695 mgp->fw_name_allocated = false;
3696
3675 if (myri10ge_fw_name != NULL) { 3697 if (myri10ge_fw_name != NULL) {
3676 dev_info(&mgp->pdev->dev, "overriding rss firmware to %s\n", 3698 dev_info(&mgp->pdev->dev, "overriding rss firmware to %s\n",
3677 myri10ge_fw_name); 3699 myri10ge_fw_name);
3678 mgp->fw_name = myri10ge_fw_name; 3700 set_fw_name(mgp, myri10ge_fw_name, false);
3679 } else if (old_fw == myri10ge_fw_aligned) 3701 } else if (old_fw == myri10ge_fw_aligned)
3680 mgp->fw_name = myri10ge_fw_rss_aligned; 3702 set_fw_name(mgp, myri10ge_fw_rss_aligned, false);
3681 else 3703 else
3682 mgp->fw_name = myri10ge_fw_rss_unaligned; 3704 set_fw_name(mgp, myri10ge_fw_rss_unaligned, false);
3683 status = myri10ge_load_firmware(mgp, 0); 3705 status = myri10ge_load_firmware(mgp, 0);
3684 if (status != 0) { 3706 if (status != 0) {
3685 dev_info(&pdev->dev, "Rss firmware not found\n"); 3707 dev_info(&pdev->dev, "Rss firmware not found\n");
3708 if (old_allocated)
3709 kfree(old_fw);
3686 return; 3710 return;
3687 } 3711 }
3688 3712
@@ -3747,6 +3771,8 @@ static void myri10ge_probe_slices(struct myri10ge_priv *mgp)
3747 mgp->num_slices); 3771 mgp->num_slices);
3748 if (status == 0) { 3772 if (status == 0) {
3749 pci_disable_msix(pdev); 3773 pci_disable_msix(pdev);
3774 if (old_allocated)
3775 kfree(old_fw);
3750 return; 3776 return;
3751 } 3777 }
3752 if (status > 0) 3778 if (status > 0)
@@ -3763,7 +3789,7 @@ disable_msix:
3763 3789
3764abort_with_fw: 3790abort_with_fw:
3765 mgp->num_slices = 1; 3791 mgp->num_slices = 1;
3766 mgp->fw_name = old_fw; 3792 set_fw_name(mgp, old_fw, old_allocated);
3767 myri10ge_load_firmware(mgp, 0); 3793 myri10ge_load_firmware(mgp, 0);
3768} 3794}
3769 3795
@@ -3993,6 +4019,7 @@ abort_with_enabled:
3993 pci_disable_device(pdev); 4019 pci_disable_device(pdev);
3994 4020
3995abort_with_netdev: 4021abort_with_netdev:
4022 set_fw_name(mgp, NULL, false);
3996 free_netdev(netdev); 4023 free_netdev(netdev);
3997 return status; 4024 return status;
3998} 4025}
@@ -4037,6 +4064,7 @@ static void myri10ge_remove(struct pci_dev *pdev)
4037 dma_free_coherent(&pdev->dev, sizeof(*mgp->cmd), 4064 dma_free_coherent(&pdev->dev, sizeof(*mgp->cmd),
4038 mgp->cmd, mgp->cmd_bus); 4065 mgp->cmd, mgp->cmd_bus);
4039 4066
4067 set_fw_name(mgp, NULL, false);
4040 free_netdev(netdev); 4068 free_netdev(netdev);
4041 pci_disable_device(pdev); 4069 pci_disable_device(pdev);
4042 pci_set_drvdata(pdev, NULL); 4070 pci_set_drvdata(pdev, NULL);
diff --git a/drivers/net/myri_sbus.c b/drivers/net/myri_sbus.c
index 04e552aa14ec..617f898ba5f0 100644
--- a/drivers/net/myri_sbus.c
+++ b/drivers/net/myri_sbus.c
@@ -926,7 +926,7 @@ static const struct net_device_ops myri_ops = {
926 .ndo_validate_addr = eth_validate_addr, 926 .ndo_validate_addr = eth_validate_addr,
927}; 927};
928 928
929static int __devinit myri_sbus_probe(struct of_device *op, const struct of_device_id *match) 929static int __devinit myri_sbus_probe(struct platform_device *op, const struct of_device_id *match)
930{ 930{
931 struct device_node *dp = op->dev.of_node; 931 struct device_node *dp = op->dev.of_node;
932 static unsigned version_printed; 932 static unsigned version_printed;
@@ -1124,7 +1124,7 @@ err:
1124 return -ENODEV; 1124 return -ENODEV;
1125} 1125}
1126 1126
1127static int __devexit myri_sbus_remove(struct of_device *op) 1127static int __devexit myri_sbus_remove(struct platform_device *op)
1128{ 1128{
1129 struct myri_eth *mp = dev_get_drvdata(&op->dev); 1129 struct myri_eth *mp = dev_get_drvdata(&op->dev);
1130 struct net_device *net_dev = mp->dev; 1130 struct net_device *net_dev = mp->dev;
diff --git a/drivers/net/myri_sbus.h b/drivers/net/myri_sbus.h
index ff363e95d9cf..80a2fa5cf757 100644
--- a/drivers/net/myri_sbus.h
+++ b/drivers/net/myri_sbus.h
@@ -288,7 +288,7 @@ struct myri_eth {
288 struct myri_eeprom eeprom; /* Local copy of EEPROM. */ 288 struct myri_eeprom eeprom; /* Local copy of EEPROM. */
289 unsigned int reg_size; /* Size of register space. */ 289 unsigned int reg_size; /* Size of register space. */
290 unsigned int shmem_base; /* Offset to shared ram. */ 290 unsigned int shmem_base; /* Offset to shared ram. */
291 struct of_device *myri_op; /* Our OF device struct. */ 291 struct platform_device *myri_op; /* Our OF device struct. */
292}; 292};
293 293
294/* We use this to acquire receive skb's that we can DMA directly into. */ 294/* We use this to acquire receive skb's that we can DMA directly into. */
diff --git a/drivers/net/netxen/netxen_nic_main.c b/drivers/net/netxen/netxen_nic_main.c
index 6ce6ce1df6d2..fd86e18604e6 100644
--- a/drivers/net/netxen/netxen_nic_main.c
+++ b/drivers/net/netxen/netxen_nic_main.c
@@ -2001,27 +2001,26 @@ static void netxen_tx_timeout_task(struct work_struct *work)
2001 if (++adapter->tx_timeo_cnt >= NX_MAX_TX_TIMEOUTS) 2001 if (++adapter->tx_timeo_cnt >= NX_MAX_TX_TIMEOUTS)
2002 goto request_reset; 2002 goto request_reset;
2003 2003
2004 rtnl_lock();
2004 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { 2005 if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) {
2005 /* try to scrub interrupt */ 2006 /* try to scrub interrupt */
2006 netxen_napi_disable(adapter); 2007 netxen_napi_disable(adapter);
2007 2008
2008 adapter->netdev->trans_start = jiffies;
2009
2010 netxen_napi_enable(adapter); 2009 netxen_napi_enable(adapter);
2011 2010
2012 netif_wake_queue(adapter->netdev); 2011 netif_wake_queue(adapter->netdev);
2013 2012
2014 clear_bit(__NX_RESETTING, &adapter->state); 2013 clear_bit(__NX_RESETTING, &adapter->state);
2015 return;
2016 } else { 2014 } else {
2017 clear_bit(__NX_RESETTING, &adapter->state); 2015 clear_bit(__NX_RESETTING, &adapter->state);
2018 if (!netxen_nic_reset_context(adapter)) { 2016 if (netxen_nic_reset_context(adapter)) {
2019 adapter->netdev->trans_start = jiffies; 2017 rtnl_unlock();
2020 return; 2018 goto request_reset;
2021 } 2019 }
2022
2023 /* context reset failed, fall through for fw reset */
2024 } 2020 }
2021 adapter->netdev->trans_start = jiffies;
2022 rtnl_unlock();
2023 return;
2025 2024
2026request_reset: 2025request_reset:
2027 adapter->need_fw_reset = 1; 2026 adapter->need_fw_reset = 1;
diff --git a/drivers/net/niu.c b/drivers/net/niu.c
index 404f2d552888..bc695d53cdcc 100644
--- a/drivers/net/niu.c
+++ b/drivers/net/niu.c
@@ -9103,7 +9103,7 @@ retry:
9103static int __devinit niu_n2_irq_init(struct niu *np, u8 *ldg_num_map) 9103static int __devinit niu_n2_irq_init(struct niu *np, u8 *ldg_num_map)
9104{ 9104{
9105#ifdef CONFIG_SPARC64 9105#ifdef CONFIG_SPARC64
9106 struct of_device *op = np->op; 9106 struct platform_device *op = np->op;
9107 const u32 *int_prop; 9107 const u32 *int_prop;
9108 int i; 9108 int i;
9109 9109
@@ -9688,7 +9688,7 @@ static void __devinit niu_driver_version(void)
9688 9688
9689static struct net_device * __devinit niu_alloc_and_init( 9689static struct net_device * __devinit niu_alloc_and_init(
9690 struct device *gen_dev, struct pci_dev *pdev, 9690 struct device *gen_dev, struct pci_dev *pdev,
9691 struct of_device *op, const struct niu_ops *ops, 9691 struct platform_device *op, const struct niu_ops *ops,
9692 u8 port) 9692 u8 port)
9693{ 9693{
9694 struct net_device *dev; 9694 struct net_device *dev;
@@ -10064,7 +10064,7 @@ static const struct niu_ops niu_phys_ops = {
10064 .unmap_single = niu_phys_unmap_single, 10064 .unmap_single = niu_phys_unmap_single,
10065}; 10065};
10066 10066
10067static int __devinit niu_of_probe(struct of_device *op, 10067static int __devinit niu_of_probe(struct platform_device *op,
10068 const struct of_device_id *match) 10068 const struct of_device_id *match)
10069{ 10069{
10070 union niu_parent_id parent_id; 10070 union niu_parent_id parent_id;
@@ -10179,7 +10179,7 @@ err_out:
10179 return err; 10179 return err;
10180} 10180}
10181 10181
10182static int __devexit niu_of_remove(struct of_device *op) 10182static int __devexit niu_of_remove(struct platform_device *op)
10183{ 10183{
10184 struct net_device *dev = dev_get_drvdata(&op->dev); 10184 struct net_device *dev = dev_get_drvdata(&op->dev);
10185 10185
diff --git a/drivers/net/pcmcia/xirc2ps_cs.c b/drivers/net/pcmcia/xirc2ps_cs.c
index 4eb6f986703b..f5819526b5ee 100644
--- a/drivers/net/pcmcia/xirc2ps_cs.c
+++ b/drivers/net/pcmcia/xirc2ps_cs.c
@@ -808,6 +808,7 @@ xirc2ps_config(struct pcmcia_device * link)
808 } 808 }
809 809
810 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_16; 810 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_16;
811 link->io_lines = 10;
811 if (local->modem) { 812 if (local->modem) {
812 int pass; 813 int pass;
813 814
@@ -839,7 +840,6 @@ xirc2ps_config(struct pcmcia_device * link)
839 } 840 }
840 printk(KNOT_XIRC "no ports available\n"); 841 printk(KNOT_XIRC "no ports available\n");
841 } else { 842 } else {
842 link->io_lines = 10;
843 link->resource[0]->end = 16; 843 link->resource[0]->end = 16;
844 for (ioaddr = 0x300; ioaddr < 0x400; ioaddr += 0x10) { 844 for (ioaddr = 0x300; ioaddr < 0x400; ioaddr += 0x10) {
845 link->resource[0]->start = ioaddr; 845 link->resource[0]->start = ioaddr;
diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig
index a527e37728cd..eb799b36c86a 100644
--- a/drivers/net/phy/Kconfig
+++ b/drivers/net/phy/Kconfig
@@ -5,7 +5,7 @@
5menuconfig PHYLIB 5menuconfig PHYLIB
6 tristate "PHY Device support and infrastructure" 6 tristate "PHY Device support and infrastructure"
7 depends on !S390 7 depends on !S390
8 depends on NET_ETHERNET 8 depends on NETDEVICES
9 help 9 help
10 Ethernet controllers are usually attached to PHY 10 Ethernet controllers are usually attached to PHY
11 devices. This option provides infrastructure for 11 devices. This option provides infrastructure for
diff --git a/drivers/net/phy/mdio-gpio.c b/drivers/net/phy/mdio-gpio.c
index fc5fef2a8175..f62c7b717bc8 100644
--- a/drivers/net/phy/mdio-gpio.c
+++ b/drivers/net/phy/mdio-gpio.c
@@ -188,7 +188,7 @@ static int __devexit mdio_gpio_remove(struct platform_device *pdev)
188 188
189#ifdef CONFIG_OF_GPIO 189#ifdef CONFIG_OF_GPIO
190 190
191static int __devinit mdio_ofgpio_probe(struct of_device *ofdev, 191static int __devinit mdio_ofgpio_probe(struct platform_device *ofdev,
192 const struct of_device_id *match) 192 const struct of_device_id *match)
193{ 193{
194 struct mdio_gpio_platform_data *pdata; 194 struct mdio_gpio_platform_data *pdata;
@@ -224,7 +224,7 @@ out_free:
224 return -ENODEV; 224 return -ENODEV;
225} 225}
226 226
227static int __devexit mdio_ofgpio_remove(struct of_device *ofdev) 227static int __devexit mdio_ofgpio_remove(struct platform_device *ofdev)
228{ 228{
229 mdio_gpio_bus_destroy(&ofdev->dev); 229 mdio_gpio_bus_destroy(&ofdev->dev);
230 kfree(ofdev->dev.platform_data); 230 kfree(ofdev->dev.platform_data);
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 5130db8f5c4e..1bb16cb79433 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -301,7 +301,7 @@ EXPORT_SYMBOL(phy_ethtool_gset);
301/** 301/**
302 * phy_mii_ioctl - generic PHY MII ioctl interface 302 * phy_mii_ioctl - generic PHY MII ioctl interface
303 * @phydev: the phy_device struct 303 * @phydev: the phy_device struct
304 * @mii_data: MII ioctl data 304 * @ifr: &struct ifreq for socket ioctl's
305 * @cmd: ioctl cmd to execute 305 * @cmd: ioctl cmd to execute
306 * 306 *
307 * Note that this function is currently incompatible with the 307 * Note that this function is currently incompatible with the
diff --git a/drivers/net/ppp_async.c b/drivers/net/ppp_async.c
index 6c2e8fa0ca31..af50a530daee 100644
--- a/drivers/net/ppp_async.c
+++ b/drivers/net/ppp_async.c
@@ -108,9 +108,9 @@ static void ppp_async_process(unsigned long arg);
108static void async_lcp_peek(struct asyncppp *ap, unsigned char *data, 108static void async_lcp_peek(struct asyncppp *ap, unsigned char *data,
109 int len, int inbound); 109 int len, int inbound);
110 110
111static struct ppp_channel_ops async_ops = { 111static const struct ppp_channel_ops async_ops = {
112 ppp_async_send, 112 .start_xmit = ppp_async_send,
113 ppp_async_ioctl 113 .ioctl = ppp_async_ioctl,
114}; 114};
115 115
116/* 116/*
diff --git a/drivers/net/ppp_synctty.c b/drivers/net/ppp_synctty.c
index 52938da1e542..4c95ec3fb8d4 100644
--- a/drivers/net/ppp_synctty.c
+++ b/drivers/net/ppp_synctty.c
@@ -97,9 +97,9 @@ static void ppp_sync_flush_output(struct syncppp *ap);
97static void ppp_sync_input(struct syncppp *ap, const unsigned char *buf, 97static void ppp_sync_input(struct syncppp *ap, const unsigned char *buf,
98 char *flags, int count); 98 char *flags, int count);
99 99
100static struct ppp_channel_ops sync_ops = { 100static const struct ppp_channel_ops sync_ops = {
101 ppp_sync_send, 101 .start_xmit = ppp_sync_send,
102 ppp_sync_ioctl 102 .ioctl = ppp_sync_ioctl,
103}; 103};
104 104
105/* 105/*
diff --git a/drivers/net/pppoe.c b/drivers/net/pppoe.c
index 344ef330e123..c07de359dc07 100644
--- a/drivers/net/pppoe.c
+++ b/drivers/net/pppoe.c
@@ -92,7 +92,7 @@
92static int __pppoe_xmit(struct sock *sk, struct sk_buff *skb); 92static int __pppoe_xmit(struct sock *sk, struct sk_buff *skb);
93 93
94static const struct proto_ops pppoe_ops; 94static const struct proto_ops pppoe_ops;
95static struct ppp_channel_ops pppoe_chan_ops; 95static const struct ppp_channel_ops pppoe_chan_ops;
96 96
97/* per-net private data for this module */ 97/* per-net private data for this module */
98static int pppoe_net_id __read_mostly; 98static int pppoe_net_id __read_mostly;
@@ -963,7 +963,7 @@ static int pppoe_xmit(struct ppp_channel *chan, struct sk_buff *skb)
963 return __pppoe_xmit(sk, skb); 963 return __pppoe_xmit(sk, skb);
964} 964}
965 965
966static struct ppp_channel_ops pppoe_chan_ops = { 966static const struct ppp_channel_ops pppoe_chan_ops = {
967 .start_xmit = pppoe_xmit, 967 .start_xmit = pppoe_xmit,
968}; 968};
969 969
diff --git a/drivers/net/qlcnic/qlcnic_main.c b/drivers/net/qlcnic/qlcnic_main.c
index b9615bd745ea..bf6d87adda4f 100644
--- a/drivers/net/qlcnic/qlcnic_main.c
+++ b/drivers/net/qlcnic/qlcnic_main.c
@@ -473,48 +473,58 @@ qlcnic_cleanup_pci_map(struct qlcnic_adapter *adapter)
473static int 473static int
474qlcnic_init_pci_info(struct qlcnic_adapter *adapter) 474qlcnic_init_pci_info(struct qlcnic_adapter *adapter)
475{ 475{
476 struct qlcnic_pci_info pci_info[QLCNIC_MAX_PCI_FUNC]; 476 struct qlcnic_pci_info *pci_info;
477 int i, ret = 0, err; 477 int i, ret = 0, err;
478 u8 pfn; 478 u8 pfn;
479 479
480 if (!adapter->npars) 480 pci_info = kcalloc(QLCNIC_MAX_PCI_FUNC, sizeof(*pci_info), GFP_KERNEL);
481 adapter->npars = kzalloc(sizeof(struct qlcnic_npar_info) * 481 if (!pci_info)
482 QLCNIC_MAX_PCI_FUNC, GFP_KERNEL);
483 if (!adapter->npars)
484 return -ENOMEM; 482 return -ENOMEM;
485 483
486 if (!adapter->eswitch) 484 adapter->npars = kzalloc(sizeof(struct qlcnic_npar_info) *
487 adapter->eswitch = kzalloc(sizeof(struct qlcnic_eswitch) * 485 QLCNIC_MAX_PCI_FUNC, GFP_KERNEL);
486 if (!adapter->npars) {
487 err = -ENOMEM;
488 goto err_pci_info;
489 }
490
491 adapter->eswitch = kzalloc(sizeof(struct qlcnic_eswitch) *
488 QLCNIC_NIU_MAX_XG_PORTS, GFP_KERNEL); 492 QLCNIC_NIU_MAX_XG_PORTS, GFP_KERNEL);
489 if (!adapter->eswitch) { 493 if (!adapter->eswitch) {
490 err = -ENOMEM; 494 err = -ENOMEM;
491 goto err_eswitch; 495 goto err_npars;
492 } 496 }
493 497
494 ret = qlcnic_get_pci_info(adapter, pci_info); 498 ret = qlcnic_get_pci_info(adapter, pci_info);
495 if (!ret) { 499 if (ret)
496 for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) { 500 goto err_eswitch;
497 pfn = pci_info[i].id;
498 if (pfn > QLCNIC_MAX_PCI_FUNC)
499 return QL_STATUS_INVALID_PARAM;
500 adapter->npars[pfn].active = pci_info[i].active;
501 adapter->npars[pfn].type = pci_info[i].type;
502 adapter->npars[pfn].phy_port = pci_info[i].default_port;
503 adapter->npars[pfn].mac_learning = DEFAULT_MAC_LEARN;
504 adapter->npars[pfn].min_bw = pci_info[i].tx_min_bw;
505 adapter->npars[pfn].max_bw = pci_info[i].tx_max_bw;
506 }
507
508 for (i = 0; i < QLCNIC_NIU_MAX_XG_PORTS; i++)
509 adapter->eswitch[i].flags |= QLCNIC_SWITCH_ENABLE;
510 501
511 return ret; 502 for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) {
503 pfn = pci_info[i].id;
504 if (pfn > QLCNIC_MAX_PCI_FUNC)
505 return QL_STATUS_INVALID_PARAM;
506 adapter->npars[pfn].active = pci_info[i].active;
507 adapter->npars[pfn].type = pci_info[i].type;
508 adapter->npars[pfn].phy_port = pci_info[i].default_port;
509 adapter->npars[pfn].mac_learning = DEFAULT_MAC_LEARN;
510 adapter->npars[pfn].min_bw = pci_info[i].tx_min_bw;
511 adapter->npars[pfn].max_bw = pci_info[i].tx_max_bw;
512 } 512 }
513 513
514 for (i = 0; i < QLCNIC_NIU_MAX_XG_PORTS; i++)
515 adapter->eswitch[i].flags |= QLCNIC_SWITCH_ENABLE;
516
517 kfree(pci_info);
518 return 0;
519
520err_eswitch:
514 kfree(adapter->eswitch); 521 kfree(adapter->eswitch);
515 adapter->eswitch = NULL; 522 adapter->eswitch = NULL;
516err_eswitch: 523err_npars:
517 kfree(adapter->npars); 524 kfree(adapter->npars);
525 adapter->npars = NULL;
526err_pci_info:
527 kfree(pci_info);
518 528
519 return ret; 529 return ret;
520} 530}
@@ -3361,15 +3371,21 @@ qlcnic_sysfs_read_pci_config(struct file *file, struct kobject *kobj,
3361 struct device *dev = container_of(kobj, struct device, kobj); 3371 struct device *dev = container_of(kobj, struct device, kobj);
3362 struct qlcnic_adapter *adapter = dev_get_drvdata(dev); 3372 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3363 struct qlcnic_pci_func_cfg pci_cfg[QLCNIC_MAX_PCI_FUNC]; 3373 struct qlcnic_pci_func_cfg pci_cfg[QLCNIC_MAX_PCI_FUNC];
3364 struct qlcnic_pci_info pci_info[QLCNIC_MAX_PCI_FUNC]; 3374 struct qlcnic_pci_info *pci_info;
3365 int i, ret; 3375 int i, ret;
3366 3376
3367 if (size != sizeof(pci_cfg)) 3377 if (size != sizeof(pci_cfg))
3368 return QL_STATUS_INVALID_PARAM; 3378 return QL_STATUS_INVALID_PARAM;
3369 3379
3380 pci_info = kcalloc(QLCNIC_MAX_PCI_FUNC, sizeof(*pci_info), GFP_KERNEL);
3381 if (!pci_info)
3382 return -ENOMEM;
3383
3370 ret = qlcnic_get_pci_info(adapter, pci_info); 3384 ret = qlcnic_get_pci_info(adapter, pci_info);
3371 if (ret) 3385 if (ret) {
3386 kfree(pci_info);
3372 return ret; 3387 return ret;
3388 }
3373 3389
3374 for (i = 0; i < QLCNIC_MAX_PCI_FUNC ; i++) { 3390 for (i = 0; i < QLCNIC_MAX_PCI_FUNC ; i++) {
3375 pci_cfg[i].pci_func = pci_info[i].id; 3391 pci_cfg[i].pci_func = pci_info[i].id;
@@ -3380,8 +3396,8 @@ qlcnic_sysfs_read_pci_config(struct file *file, struct kobject *kobj,
3380 memcpy(&pci_cfg[i].def_mac_addr, &pci_info[i].mac, ETH_ALEN); 3396 memcpy(&pci_cfg[i].def_mac_addr, &pci_info[i].mac, ETH_ALEN);
3381 } 3397 }
3382 memcpy(buf, &pci_cfg, size); 3398 memcpy(buf, &pci_cfg, size);
3399 kfree(pci_info);
3383 return size; 3400 return size;
3384
3385} 3401}
3386static struct bin_attribute bin_attr_npar_config = { 3402static struct bin_attribute bin_attr_npar_config = {
3387 .attr = {.name = "npar_config", .mode = (S_IRUGO | S_IWUSR)}, 3403 .attr = {.name = "npar_config", .mode = (S_IRUGO | S_IWUSR)},
diff --git a/drivers/net/sunbmac.c b/drivers/net/sunbmac.c
index 09c071bd6ad4..618643e3ca3e 100644
--- a/drivers/net/sunbmac.c
+++ b/drivers/net/sunbmac.c
@@ -97,7 +97,7 @@ static int qec_global_reset(void __iomem *gregs)
97 97
98static void qec_init(struct bigmac *bp) 98static void qec_init(struct bigmac *bp)
99{ 99{
100 struct of_device *qec_op = bp->qec_op; 100 struct platform_device *qec_op = bp->qec_op;
101 void __iomem *gregs = bp->gregs; 101 void __iomem *gregs = bp->gregs;
102 u8 bsizes = bp->bigmac_bursts; 102 u8 bsizes = bp->bigmac_bursts;
103 u32 regval; 103 u32 regval;
@@ -1083,8 +1083,8 @@ static const struct net_device_ops bigmac_ops = {
1083 .ndo_validate_addr = eth_validate_addr, 1083 .ndo_validate_addr = eth_validate_addr,
1084}; 1084};
1085 1085
1086static int __devinit bigmac_ether_init(struct of_device *op, 1086static int __devinit bigmac_ether_init(struct platform_device *op,
1087 struct of_device *qec_op) 1087 struct platform_device *qec_op)
1088{ 1088{
1089 static int version_printed; 1089 static int version_printed;
1090 struct net_device *dev; 1090 struct net_device *dev;
@@ -1242,25 +1242,25 @@ fail_and_cleanup:
1242/* QEC can be the parent of either QuadEthernet or a BigMAC. We want 1242/* QEC can be the parent of either QuadEthernet or a BigMAC. We want
1243 * the latter. 1243 * the latter.
1244 */ 1244 */
1245static int __devinit bigmac_sbus_probe(struct of_device *op, 1245static int __devinit bigmac_sbus_probe(struct platform_device *op,
1246 const struct of_device_id *match) 1246 const struct of_device_id *match)
1247{ 1247{
1248 struct device *parent = op->dev.parent; 1248 struct device *parent = op->dev.parent;
1249 struct of_device *qec_op; 1249 struct platform_device *qec_op;
1250 1250
1251 qec_op = to_of_device(parent); 1251 qec_op = to_platform_device(parent);
1252 1252
1253 return bigmac_ether_init(op, qec_op); 1253 return bigmac_ether_init(op, qec_op);
1254} 1254}
1255 1255
1256static int __devexit bigmac_sbus_remove(struct of_device *op) 1256static int __devexit bigmac_sbus_remove(struct platform_device *op)
1257{ 1257{
1258 struct bigmac *bp = dev_get_drvdata(&op->dev); 1258 struct bigmac *bp = dev_get_drvdata(&op->dev);
1259 struct device *parent = op->dev.parent; 1259 struct device *parent = op->dev.parent;
1260 struct net_device *net_dev = bp->dev; 1260 struct net_device *net_dev = bp->dev;
1261 struct of_device *qec_op; 1261 struct platform_device *qec_op;
1262 1262
1263 qec_op = to_of_device(parent); 1263 qec_op = to_platform_device(parent);
1264 1264
1265 unregister_netdev(net_dev); 1265 unregister_netdev(net_dev);
1266 1266
diff --git a/drivers/net/sunbmac.h b/drivers/net/sunbmac.h
index 8840bc0b840b..8db88945b889 100644
--- a/drivers/net/sunbmac.h
+++ b/drivers/net/sunbmac.h
@@ -329,8 +329,8 @@ struct bigmac {
329 unsigned int timer_ticks; 329 unsigned int timer_ticks;
330 330
331 struct net_device_stats enet_stats; 331 struct net_device_stats enet_stats;
332 struct of_device *qec_op; 332 struct platform_device *qec_op;
333 struct of_device *bigmac_op; 333 struct platform_device *bigmac_op;
334 struct net_device *dev; 334 struct net_device *dev;
335}; 335};
336 336
diff --git a/drivers/net/sunhme.c b/drivers/net/sunhme.c
index eec443f64079..bd0df1c14955 100644
--- a/drivers/net/sunhme.c
+++ b/drivers/net/sunhme.c
@@ -1591,7 +1591,7 @@ static int happy_meal_init(struct happy_meal *hp)
1591 */ 1591 */
1592#ifdef CONFIG_SBUS 1592#ifdef CONFIG_SBUS
1593 if ((hp->happy_flags & HFLAG_PCI) == 0) { 1593 if ((hp->happy_flags & HFLAG_PCI) == 0) {
1594 struct of_device *op = hp->happy_dev; 1594 struct platform_device *op = hp->happy_dev;
1595 if (sbus_can_dma_64bit()) { 1595 if (sbus_can_dma_64bit()) {
1596 sbus_set_sbus64(&op->dev, 1596 sbus_set_sbus64(&op->dev,
1597 hp->happy_bursts); 1597 hp->happy_bursts);
@@ -2480,7 +2480,7 @@ static void hme_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info
2480#ifdef CONFIG_SBUS 2480#ifdef CONFIG_SBUS
2481 else { 2481 else {
2482 const struct linux_prom_registers *regs; 2482 const struct linux_prom_registers *regs;
2483 struct of_device *op = hp->happy_dev; 2483 struct platform_device *op = hp->happy_dev;
2484 regs = of_get_property(op->dev.of_node, "regs", NULL); 2484 regs = of_get_property(op->dev.of_node, "regs", NULL);
2485 if (regs) 2485 if (regs)
2486 sprintf(info->bus_info, "SBUS:%d", 2486 sprintf(info->bus_info, "SBUS:%d",
@@ -2515,13 +2515,13 @@ static int hme_version_printed;
2515 * 2515 *
2516 * Return NULL on failure. 2516 * Return NULL on failure.
2517 */ 2517 */
2518static struct quattro * __devinit quattro_sbus_find(struct of_device *child) 2518static struct quattro * __devinit quattro_sbus_find(struct platform_device *child)
2519{ 2519{
2520 struct device *parent = child->dev.parent; 2520 struct device *parent = child->dev.parent;
2521 struct of_device *op; 2521 struct platform_device *op;
2522 struct quattro *qp; 2522 struct quattro *qp;
2523 2523
2524 op = to_of_device(parent); 2524 op = to_platform_device(parent);
2525 qp = dev_get_drvdata(&op->dev); 2525 qp = dev_get_drvdata(&op->dev);
2526 if (qp) 2526 if (qp)
2527 return qp; 2527 return qp;
@@ -2551,7 +2551,7 @@ static int __init quattro_sbus_register_irqs(void)
2551 struct quattro *qp; 2551 struct quattro *qp;
2552 2552
2553 for (qp = qfe_sbus_list; qp != NULL; qp = qp->next) { 2553 for (qp = qfe_sbus_list; qp != NULL; qp = qp->next) {
2554 struct of_device *op = qp->quattro_dev; 2554 struct platform_device *op = qp->quattro_dev;
2555 int err, qfe_slot, skip = 0; 2555 int err, qfe_slot, skip = 0;
2556 2556
2557 for (qfe_slot = 0; qfe_slot < 4; qfe_slot++) { 2557 for (qfe_slot = 0; qfe_slot < 4; qfe_slot++) {
@@ -2580,7 +2580,7 @@ static void quattro_sbus_free_irqs(void)
2580 struct quattro *qp; 2580 struct quattro *qp;
2581 2581
2582 for (qp = qfe_sbus_list; qp != NULL; qp = qp->next) { 2582 for (qp = qfe_sbus_list; qp != NULL; qp = qp->next) {
2583 struct of_device *op = qp->quattro_dev; 2583 struct platform_device *op = qp->quattro_dev;
2584 int qfe_slot, skip = 0; 2584 int qfe_slot, skip = 0;
2585 2585
2586 for (qfe_slot = 0; qfe_slot < 4; qfe_slot++) { 2586 for (qfe_slot = 0; qfe_slot < 4; qfe_slot++) {
@@ -2639,7 +2639,7 @@ static const struct net_device_ops hme_netdev_ops = {
2639}; 2639};
2640 2640
2641#ifdef CONFIG_SBUS 2641#ifdef CONFIG_SBUS
2642static int __devinit happy_meal_sbus_probe_one(struct of_device *op, int is_qfe) 2642static int __devinit happy_meal_sbus_probe_one(struct platform_device *op, int is_qfe)
2643{ 2643{
2644 struct device_node *dp = op->dev.of_node, *sbus_dp; 2644 struct device_node *dp = op->dev.of_node, *sbus_dp;
2645 struct quattro *qp = NULL; 2645 struct quattro *qp = NULL;
@@ -2648,7 +2648,7 @@ static int __devinit happy_meal_sbus_probe_one(struct of_device *op, int is_qfe)
2648 int i, qfe_slot = -1; 2648 int i, qfe_slot = -1;
2649 int err = -ENODEV; 2649 int err = -ENODEV;
2650 2650
2651 sbus_dp = to_of_device(op->dev.parent)->dev.of_node; 2651 sbus_dp = op->dev.parent->of_node;
2652 2652
2653 /* We can match PCI devices too, do not accept those here. */ 2653 /* We can match PCI devices too, do not accept those here. */
2654 if (strcmp(sbus_dp->name, "sbus")) 2654 if (strcmp(sbus_dp->name, "sbus"))
@@ -3235,7 +3235,7 @@ static void happy_meal_pci_exit(void)
3235#endif 3235#endif
3236 3236
3237#ifdef CONFIG_SBUS 3237#ifdef CONFIG_SBUS
3238static int __devinit hme_sbus_probe(struct of_device *op, const struct of_device_id *match) 3238static int __devinit hme_sbus_probe(struct platform_device *op, const struct of_device_id *match)
3239{ 3239{
3240 struct device_node *dp = op->dev.of_node; 3240 struct device_node *dp = op->dev.of_node;
3241 const char *model = of_get_property(dp, "model", NULL); 3241 const char *model = of_get_property(dp, "model", NULL);
@@ -3247,7 +3247,7 @@ static int __devinit hme_sbus_probe(struct of_device *op, const struct of_device
3247 return happy_meal_sbus_probe_one(op, is_qfe); 3247 return happy_meal_sbus_probe_one(op, is_qfe);
3248} 3248}
3249 3249
3250static int __devexit hme_sbus_remove(struct of_device *op) 3250static int __devexit hme_sbus_remove(struct platform_device *op)
3251{ 3251{
3252 struct happy_meal *hp = dev_get_drvdata(&op->dev); 3252 struct happy_meal *hp = dev_get_drvdata(&op->dev);
3253 struct net_device *net_dev = hp->dev; 3253 struct net_device *net_dev = hp->dev;
diff --git a/drivers/net/sunhme.h b/drivers/net/sunhme.h
index efd2ca0fcad3..756b5bf3aa89 100644
--- a/drivers/net/sunhme.h
+++ b/drivers/net/sunhme.h
@@ -407,7 +407,7 @@ struct happy_meal {
407 void (*write_rxd)(struct happy_meal_rxd *, u32, u32); 407 void (*write_rxd)(struct happy_meal_rxd *, u32, u32);
408#endif 408#endif
409 409
410 /* This is either an of_device or a pci_dev. */ 410 /* This is either an platform_device or a pci_dev. */
411 void *happy_dev; 411 void *happy_dev;
412 struct device *dma_dev; 412 struct device *dma_dev;
413 413
diff --git a/drivers/net/sunlance.c b/drivers/net/sunlance.c
index ee364fa75634..8dcb858f2168 100644
--- a/drivers/net/sunlance.c
+++ b/drivers/net/sunlance.c
@@ -250,7 +250,7 @@ struct lance_private {
250 int rx_new, tx_new; 250 int rx_new, tx_new;
251 int rx_old, tx_old; 251 int rx_old, tx_old;
252 252
253 struct of_device *ledma; /* If set this points to ledma */ 253 struct platform_device *ledma; /* If set this points to ledma */
254 char tpe; /* cable-selection is TPE */ 254 char tpe; /* cable-selection is TPE */
255 char auto_select; /* cable-selection by carrier */ 255 char auto_select; /* cable-selection by carrier */
256 char burst_sizes; /* ledma SBus burst sizes */ 256 char burst_sizes; /* ledma SBus burst sizes */
@@ -265,8 +265,8 @@ struct lance_private {
265 char *name; 265 char *name;
266 dma_addr_t init_block_dvma; 266 dma_addr_t init_block_dvma;
267 struct net_device *dev; /* Backpointer */ 267 struct net_device *dev; /* Backpointer */
268 struct of_device *op; 268 struct platform_device *op;
269 struct of_device *lebuffer; 269 struct platform_device *lebuffer;
270 struct timer_list multicast_timer; 270 struct timer_list multicast_timer;
271}; 271};
272 272
@@ -1272,7 +1272,7 @@ static void lance_free_hwresources(struct lance_private *lp)
1272 if (lp->lregs) 1272 if (lp->lregs)
1273 of_iounmap(&lp->op->resource[0], lp->lregs, LANCE_REG_SIZE); 1273 of_iounmap(&lp->op->resource[0], lp->lregs, LANCE_REG_SIZE);
1274 if (lp->dregs) { 1274 if (lp->dregs) {
1275 struct of_device *ledma = lp->ledma; 1275 struct platform_device *ledma = lp->ledma;
1276 1276
1277 of_iounmap(&ledma->resource[0], lp->dregs, 1277 of_iounmap(&ledma->resource[0], lp->dregs,
1278 resource_size(&ledma->resource[0])); 1278 resource_size(&ledma->resource[0]));
@@ -1319,9 +1319,9 @@ static const struct net_device_ops sparc_lance_ops = {
1319 .ndo_validate_addr = eth_validate_addr, 1319 .ndo_validate_addr = eth_validate_addr,
1320}; 1320};
1321 1321
1322static int __devinit sparc_lance_probe_one(struct of_device *op, 1322static int __devinit sparc_lance_probe_one(struct platform_device *op,
1323 struct of_device *ledma, 1323 struct platform_device *ledma,
1324 struct of_device *lebuffer) 1324 struct platform_device *lebuffer)
1325{ 1325{
1326 struct device_node *dp = op->dev.of_node; 1326 struct device_node *dp = op->dev.of_node;
1327 static unsigned version_printed; 1327 static unsigned version_printed;
@@ -1503,9 +1503,9 @@ fail:
1503 return -ENODEV; 1503 return -ENODEV;
1504} 1504}
1505 1505
1506static int __devinit sunlance_sbus_probe(struct of_device *op, const struct of_device_id *match) 1506static int __devinit sunlance_sbus_probe(struct platform_device *op, const struct of_device_id *match)
1507{ 1507{
1508 struct of_device *parent = to_of_device(op->dev.parent); 1508 struct platform_device *parent = to_platform_device(op->dev.parent);
1509 struct device_node *parent_dp = parent->dev.of_node; 1509 struct device_node *parent_dp = parent->dev.of_node;
1510 int err; 1510 int err;
1511 1511
@@ -1519,7 +1519,7 @@ static int __devinit sunlance_sbus_probe(struct of_device *op, const struct of_d
1519 return err; 1519 return err;
1520} 1520}
1521 1521
1522static int __devexit sunlance_sbus_remove(struct of_device *op) 1522static int __devexit sunlance_sbus_remove(struct platform_device *op)
1523{ 1523{
1524 struct lance_private *lp = dev_get_drvdata(&op->dev); 1524 struct lance_private *lp = dev_get_drvdata(&op->dev);
1525 struct net_device *net_dev = lp->dev; 1525 struct net_device *net_dev = lp->dev;
diff --git a/drivers/net/sunqe.c b/drivers/net/sunqe.c
index 5f84a5dadedd..72e65d4666ef 100644
--- a/drivers/net/sunqe.c
+++ b/drivers/net/sunqe.c
@@ -689,7 +689,7 @@ static void qe_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
689{ 689{
690 const struct linux_prom_registers *regs; 690 const struct linux_prom_registers *regs;
691 struct sunqe *qep = netdev_priv(dev); 691 struct sunqe *qep = netdev_priv(dev);
692 struct of_device *op; 692 struct platform_device *op;
693 693
694 strcpy(info->driver, "sunqe"); 694 strcpy(info->driver, "sunqe");
695 strcpy(info->version, "3.0"); 695 strcpy(info->version, "3.0");
@@ -720,7 +720,7 @@ static const struct ethtool_ops qe_ethtool_ops = {
720}; 720};
721 721
722/* This is only called once at boot time for each card probed. */ 722/* This is only called once at boot time for each card probed. */
723static void qec_init_once(struct sunqec *qecp, struct of_device *op) 723static void qec_init_once(struct sunqec *qecp, struct platform_device *op)
724{ 724{
725 u8 bsizes = qecp->qec_bursts; 725 u8 bsizes = qecp->qec_bursts;
726 726
@@ -770,9 +770,9 @@ static u8 __devinit qec_get_burst(struct device_node *dp)
770 return bsizes; 770 return bsizes;
771} 771}
772 772
773static struct sunqec * __devinit get_qec(struct of_device *child) 773static struct sunqec * __devinit get_qec(struct platform_device *child)
774{ 774{
775 struct of_device *op = to_of_device(child->dev.parent); 775 struct platform_device *op = to_platform_device(child->dev.parent);
776 struct sunqec *qecp; 776 struct sunqec *qecp;
777 777
778 qecp = dev_get_drvdata(&op->dev); 778 qecp = dev_get_drvdata(&op->dev);
@@ -836,7 +836,7 @@ static const struct net_device_ops qec_ops = {
836 .ndo_validate_addr = eth_validate_addr, 836 .ndo_validate_addr = eth_validate_addr,
837}; 837};
838 838
839static int __devinit qec_ether_init(struct of_device *op) 839static int __devinit qec_ether_init(struct platform_device *op)
840{ 840{
841 static unsigned version_printed; 841 static unsigned version_printed;
842 struct net_device *dev; 842 struct net_device *dev;
@@ -941,12 +941,12 @@ fail:
941 return res; 941 return res;
942} 942}
943 943
944static int __devinit qec_sbus_probe(struct of_device *op, const struct of_device_id *match) 944static int __devinit qec_sbus_probe(struct platform_device *op, const struct of_device_id *match)
945{ 945{
946 return qec_ether_init(op); 946 return qec_ether_init(op);
947} 947}
948 948
949static int __devexit qec_sbus_remove(struct of_device *op) 949static int __devexit qec_sbus_remove(struct platform_device *op)
950{ 950{
951 struct sunqe *qp = dev_get_drvdata(&op->dev); 951 struct sunqe *qp = dev_get_drvdata(&op->dev);
952 struct net_device *net_dev = qp->dev; 952 struct net_device *net_dev = qp->dev;
@@ -997,7 +997,7 @@ static void __exit qec_exit(void)
997 997
998 while (root_qec_dev) { 998 while (root_qec_dev) {
999 struct sunqec *next = root_qec_dev->next_module; 999 struct sunqec *next = root_qec_dev->next_module;
1000 struct of_device *op = root_qec_dev->op; 1000 struct platform_device *op = root_qec_dev->op;
1001 1001
1002 free_irq(op->archdata.irqs[0], (void *) root_qec_dev); 1002 free_irq(op->archdata.irqs[0], (void *) root_qec_dev);
1003 of_iounmap(&op->resource[0], root_qec_dev->gregs, 1003 of_iounmap(&op->resource[0], root_qec_dev->gregs,
diff --git a/drivers/net/sunqe.h b/drivers/net/sunqe.h
index 5813a7b2faa5..581781b6b2fa 100644
--- a/drivers/net/sunqe.h
+++ b/drivers/net/sunqe.h
@@ -314,7 +314,7 @@ struct sunqec {
314 void __iomem *gregs; /* QEC Global Registers */ 314 void __iomem *gregs; /* QEC Global Registers */
315 struct sunqe *qes[4]; /* Each child MACE */ 315 struct sunqe *qes[4]; /* Each child MACE */
316 unsigned int qec_bursts; /* Support burst sizes */ 316 unsigned int qec_bursts; /* Support burst sizes */
317 struct of_device *op; /* QEC's OF device */ 317 struct platform_device *op; /* QEC's OF device */
318 struct sunqec *next_module; /* List of all QECs in system */ 318 struct sunqec *next_module; /* List of all QECs in system */
319}; 319};
320 320
@@ -342,7 +342,7 @@ struct sunqe {
342 __u32 buffers_dvma; /* DVMA visible address. */ 342 __u32 buffers_dvma; /* DVMA visible address. */
343 struct sunqec *parent; 343 struct sunqec *parent;
344 u8 mconfig; /* Base MACE mconfig value */ 344 u8 mconfig; /* Base MACE mconfig value */
345 struct of_device *op; /* QE's OF device struct */ 345 struct platform_device *op; /* QE's OF device struct */
346 struct net_device *dev; /* QE's netdevice struct */ 346 struct net_device *dev; /* QE's netdevice struct */
347 int channel; /* Who am I? */ 347 int channel; /* Who am I? */
348}; 348};
diff --git a/drivers/net/ucc_geth.c b/drivers/net/ucc_geth.c
index 8d532f9b50d0..a4c3f5708246 100644
--- a/drivers/net/ucc_geth.c
+++ b/drivers/net/ucc_geth.c
@@ -3601,7 +3601,7 @@ static void ucc_geth_timeout(struct net_device *dev)
3601 3601
3602#ifdef CONFIG_PM 3602#ifdef CONFIG_PM
3603 3603
3604static int ucc_geth_suspend(struct of_device *ofdev, pm_message_t state) 3604static int ucc_geth_suspend(struct platform_device *ofdev, pm_message_t state)
3605{ 3605{
3606 struct net_device *ndev = dev_get_drvdata(&ofdev->dev); 3606 struct net_device *ndev = dev_get_drvdata(&ofdev->dev);
3607 struct ucc_geth_private *ugeth = netdev_priv(ndev); 3607 struct ucc_geth_private *ugeth = netdev_priv(ndev);
@@ -3629,7 +3629,7 @@ static int ucc_geth_suspend(struct of_device *ofdev, pm_message_t state)
3629 return 0; 3629 return 0;
3630} 3630}
3631 3631
3632static int ucc_geth_resume(struct of_device *ofdev) 3632static int ucc_geth_resume(struct platform_device *ofdev)
3633{ 3633{
3634 struct net_device *ndev = dev_get_drvdata(&ofdev->dev); 3634 struct net_device *ndev = dev_get_drvdata(&ofdev->dev);
3635 struct ucc_geth_private *ugeth = netdev_priv(ndev); 3635 struct ucc_geth_private *ugeth = netdev_priv(ndev);
@@ -3732,7 +3732,7 @@ static const struct net_device_ops ucc_geth_netdev_ops = {
3732#endif 3732#endif
3733}; 3733};
3734 3734
3735static int ucc_geth_probe(struct of_device* ofdev, const struct of_device_id *match) 3735static int ucc_geth_probe(struct platform_device* ofdev, const struct of_device_id *match)
3736{ 3736{
3737 struct device *device = &ofdev->dev; 3737 struct device *device = &ofdev->dev;
3738 struct device_node *np = ofdev->dev.of_node; 3738 struct device_node *np = ofdev->dev.of_node;
@@ -3954,7 +3954,7 @@ static int ucc_geth_probe(struct of_device* ofdev, const struct of_device_id *ma
3954 return 0; 3954 return 0;
3955} 3955}
3956 3956
3957static int ucc_geth_remove(struct of_device* ofdev) 3957static int ucc_geth_remove(struct platform_device* ofdev)
3958{ 3958{
3959 struct device *device = &ofdev->dev; 3959 struct device *device = &ofdev->dev;
3960 struct net_device *dev = dev_get_drvdata(device); 3960 struct net_device *dev = dev_get_drvdata(device);
diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
index 3b03794ac3f5..ca7fc9df1ccf 100644
--- a/drivers/net/usb/usbnet.c
+++ b/drivers/net/usb/usbnet.c
@@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(usbnet_defer_kevent);
315 315
316static void rx_complete (struct urb *urb); 316static void rx_complete (struct urb *urb);
317 317
318static void rx_submit (struct usbnet *dev, struct urb *urb, gfp_t flags) 318static int rx_submit (struct usbnet *dev, struct urb *urb, gfp_t flags)
319{ 319{
320 struct sk_buff *skb; 320 struct sk_buff *skb;
321 struct skb_data *entry; 321 struct skb_data *entry;
@@ -327,7 +327,7 @@ static void rx_submit (struct usbnet *dev, struct urb *urb, gfp_t flags)
327 netif_dbg(dev, rx_err, dev->net, "no rx skb\n"); 327 netif_dbg(dev, rx_err, dev->net, "no rx skb\n");
328 usbnet_defer_kevent (dev, EVENT_RX_MEMORY); 328 usbnet_defer_kevent (dev, EVENT_RX_MEMORY);
329 usb_free_urb (urb); 329 usb_free_urb (urb);
330 return; 330 return -ENOMEM;
331 } 331 }
332 skb_reserve (skb, NET_IP_ALIGN); 332 skb_reserve (skb, NET_IP_ALIGN);
333 333
@@ -357,6 +357,9 @@ static void rx_submit (struct usbnet *dev, struct urb *urb, gfp_t flags)
357 netif_dbg(dev, ifdown, dev->net, "device gone\n"); 357 netif_dbg(dev, ifdown, dev->net, "device gone\n");
358 netif_device_detach (dev->net); 358 netif_device_detach (dev->net);
359 break; 359 break;
360 case -EHOSTUNREACH:
361 retval = -ENOLINK;
362 break;
360 default: 363 default:
361 netif_dbg(dev, rx_err, dev->net, 364 netif_dbg(dev, rx_err, dev->net,
362 "rx submit, %d\n", retval); 365 "rx submit, %d\n", retval);
@@ -374,6 +377,7 @@ static void rx_submit (struct usbnet *dev, struct urb *urb, gfp_t flags)
374 dev_kfree_skb_any (skb); 377 dev_kfree_skb_any (skb);
375 usb_free_urb (urb); 378 usb_free_urb (urb);
376 } 379 }
380 return retval;
377} 381}
378 382
379 383
@@ -912,6 +916,7 @@ fail_halt:
912 /* tasklet could resubmit itself forever if memory is tight */ 916 /* tasklet could resubmit itself forever if memory is tight */
913 if (test_bit (EVENT_RX_MEMORY, &dev->flags)) { 917 if (test_bit (EVENT_RX_MEMORY, &dev->flags)) {
914 struct urb *urb = NULL; 918 struct urb *urb = NULL;
919 int resched = 1;
915 920
916 if (netif_running (dev->net)) 921 if (netif_running (dev->net))
917 urb = usb_alloc_urb (0, GFP_KERNEL); 922 urb = usb_alloc_urb (0, GFP_KERNEL);
@@ -922,10 +927,12 @@ fail_halt:
922 status = usb_autopm_get_interface(dev->intf); 927 status = usb_autopm_get_interface(dev->intf);
923 if (status < 0) 928 if (status < 0)
924 goto fail_lowmem; 929 goto fail_lowmem;
925 rx_submit (dev, urb, GFP_KERNEL); 930 if (rx_submit (dev, urb, GFP_KERNEL) == -ENOLINK)
931 resched = 0;
926 usb_autopm_put_interface(dev->intf); 932 usb_autopm_put_interface(dev->intf);
927fail_lowmem: 933fail_lowmem:
928 tasklet_schedule (&dev->bh); 934 if (resched)
935 tasklet_schedule (&dev->bh);
929 } 936 }
930 } 937 }
931 938
@@ -1175,8 +1182,11 @@ static void usbnet_bh (unsigned long param)
1175 // don't refill the queue all at once 1182 // don't refill the queue all at once
1176 for (i = 0; i < 10 && dev->rxq.qlen < qlen; i++) { 1183 for (i = 0; i < 10 && dev->rxq.qlen < qlen; i++) {
1177 urb = usb_alloc_urb (0, GFP_ATOMIC); 1184 urb = usb_alloc_urb (0, GFP_ATOMIC);
1178 if (urb != NULL) 1185 if (urb != NULL) {
1179 rx_submit (dev, urb, GFP_ATOMIC); 1186 if (rx_submit (dev, urb, GFP_ATOMIC) ==
1187 -ENOLINK)
1188 return;
1189 }
1180 } 1190 }
1181 if (temp != dev->rxq.qlen) 1191 if (temp != dev->rxq.qlen)
1182 netif_dbg(dev, link, dev->net, 1192 netif_dbg(dev, link, dev->net,
@@ -1457,7 +1467,6 @@ int usbnet_resume (struct usb_interface *intf)
1457 spin_lock_irq(&dev->txq.lock); 1467 spin_lock_irq(&dev->txq.lock);
1458 while ((res = usb_get_from_anchor(&dev->deferred))) { 1468 while ((res = usb_get_from_anchor(&dev->deferred))) {
1459 1469
1460 printk(KERN_INFO"%s has delayed data\n", __func__);
1461 skb = (struct sk_buff *)res->context; 1470 skb = (struct sk_buff *)res->context;
1462 retval = usb_submit_urb(res, GFP_ATOMIC); 1471 retval = usb_submit_urb(res, GFP_ATOMIC);
1463 if (retval < 0) { 1472 if (retval < 0) {
diff --git a/drivers/net/via-velocity.c b/drivers/net/via-velocity.c
index 42dffd3e5795..fd69095ef6e3 100644
--- a/drivers/net/via-velocity.c
+++ b/drivers/net/via-velocity.c
@@ -2763,12 +2763,12 @@ static int __devinit velocity_found1(struct pci_dev *pdev, const struct pci_devi
2763 2763
2764 vptr->dev = dev; 2764 vptr->dev = dev;
2765 2765
2766 dev->irq = pdev->irq;
2767
2768 ret = pci_enable_device(pdev); 2766 ret = pci_enable_device(pdev);
2769 if (ret < 0) 2767 if (ret < 0)
2770 goto err_free_dev; 2768 goto err_free_dev;
2771 2769
2770 dev->irq = pdev->irq;
2771
2772 ret = velocity_get_pci_info(vptr, pdev); 2772 ret = velocity_get_pci_info(vptr, pdev);
2773 if (ret < 0) { 2773 if (ret < 0) {
2774 /* error message already printed */ 2774 /* error message already printed */
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index bb6b67f6b0cc..4598e9d2608f 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -705,6 +705,19 @@ static int virtnet_close(struct net_device *dev)
705 return 0; 705 return 0;
706} 706}
707 707
708static void virtnet_get_drvinfo(struct net_device *dev,
709 struct ethtool_drvinfo *drvinfo)
710{
711 struct virtnet_info *vi = netdev_priv(dev);
712 struct virtio_device *vdev = vi->vdev;
713
714 strncpy(drvinfo->driver, KBUILD_MODNAME, ARRAY_SIZE(drvinfo->driver));
715 strncpy(drvinfo->version, "N/A", ARRAY_SIZE(drvinfo->version));
716 strncpy(drvinfo->fw_version, "N/A", ARRAY_SIZE(drvinfo->fw_version));
717 strncpy(drvinfo->bus_info, dev_name(&vdev->dev),
718 ARRAY_SIZE(drvinfo->bus_info));
719}
720
708static int virtnet_set_tx_csum(struct net_device *dev, u32 data) 721static int virtnet_set_tx_csum(struct net_device *dev, u32 data)
709{ 722{
710 struct virtnet_info *vi = netdev_priv(dev); 723 struct virtnet_info *vi = netdev_priv(dev);
@@ -817,6 +830,7 @@ static void virtnet_vlan_rx_kill_vid(struct net_device *dev, u16 vid)
817} 830}
818 831
819static const struct ethtool_ops virtnet_ethtool_ops = { 832static const struct ethtool_ops virtnet_ethtool_ops = {
833 .get_drvinfo = virtnet_get_drvinfo,
820 .set_tx_csum = virtnet_set_tx_csum, 834 .set_tx_csum = virtnet_set_tx_csum,
821 .set_sg = ethtool_op_set_sg, 835 .set_sg = ethtool_op_set_sg,
822 .set_tso = ethtool_op_set_tso, 836 .set_tso = ethtool_op_set_tso,
diff --git a/drivers/net/wan/farsync.c b/drivers/net/wan/farsync.c
index ad7719fe6d0a..e050bd65e037 100644
--- a/drivers/net/wan/farsync.c
+++ b/drivers/net/wan/farsync.c
@@ -885,20 +885,21 @@ fst_rx_dma_complete(struct fst_card_info *card, struct fst_port_info *port,
885 * Receive a frame through the DMA 885 * Receive a frame through the DMA
886 */ 886 */
887static inline void 887static inline void
888fst_rx_dma(struct fst_card_info *card, unsigned char *skb, 888fst_rx_dma(struct fst_card_info *card, dma_addr_t skb,
889 unsigned char *mem, int len) 889 dma_addr_t mem, int len)
890{ 890{
891 /* 891 /*
892 * This routine will setup the DMA and start it 892 * This routine will setup the DMA and start it
893 */ 893 */
894 894
895 dbg(DBG_RX, "In fst_rx_dma %p %p %d\n", skb, mem, len); 895 dbg(DBG_RX, "In fst_rx_dma %lx %lx %d\n",
896 (unsigned long) skb, (unsigned long) mem, len);
896 if (card->dmarx_in_progress) { 897 if (card->dmarx_in_progress) {
897 dbg(DBG_ASS, "In fst_rx_dma while dma in progress\n"); 898 dbg(DBG_ASS, "In fst_rx_dma while dma in progress\n");
898 } 899 }
899 900
900 outl((unsigned long) skb, card->pci_conf + DMAPADR0); /* Copy to here */ 901 outl(skb, card->pci_conf + DMAPADR0); /* Copy to here */
901 outl((unsigned long) mem, card->pci_conf + DMALADR0); /* from here */ 902 outl(mem, card->pci_conf + DMALADR0); /* from here */
902 outl(len, card->pci_conf + DMASIZ0); /* for this length */ 903 outl(len, card->pci_conf + DMASIZ0); /* for this length */
903 outl(0x00000000c, card->pci_conf + DMADPR0); /* In this direction */ 904 outl(0x00000000c, card->pci_conf + DMADPR0); /* In this direction */
904 905
@@ -1309,8 +1310,8 @@ fst_intr_rx(struct fst_card_info *card, struct fst_port_info *port)
1309 card->dma_port_rx = port; 1310 card->dma_port_rx = port;
1310 card->dma_len_rx = len; 1311 card->dma_len_rx = len;
1311 card->dma_rxpos = rxp; 1312 card->dma_rxpos = rxp;
1312 fst_rx_dma(card, (char *) card->rx_dma_handle_card, 1313 fst_rx_dma(card, card->rx_dma_handle_card,
1313 (char *) BUF_OFFSET(rxBuffer[pi][rxp][0]), len); 1314 BUF_OFFSET(rxBuffer[pi][rxp][0]), len);
1314 } 1315 }
1315 if (rxp != port->rxpos) { 1316 if (rxp != port->rxpos) {
1316 dbg(DBG_ASS, "About to increment rxpos by more than 1\n"); 1317 dbg(DBG_ASS, "About to increment rxpos by more than 1\n");
diff --git a/drivers/net/wan/ixp4xx_hss.c b/drivers/net/wan/ixp4xx_hss.c
index 88e363033e23..6c571e198835 100644
--- a/drivers/net/wan/ixp4xx_hss.c
+++ b/drivers/net/wan/ixp4xx_hss.c
@@ -396,7 +396,7 @@ static void hss_config(struct port *port)
396 msg.cmd = PORT_CONFIG_WRITE; 396 msg.cmd = PORT_CONFIG_WRITE;
397 msg.hss_port = port->id; 397 msg.hss_port = port->id;
398 msg.index = HSS_CONFIG_TX_PCR; 398 msg.index = HSS_CONFIG_TX_PCR;
399 msg.data32 = PCR_FRM_SYNC_OUTPUT_RISING | PCR_MSB_ENDIAN | 399 msg.data32 = PCR_FRM_PULSE_DISABLED | PCR_MSB_ENDIAN |
400 PCR_TX_DATA_ENABLE | PCR_SOF_NO_FBIT; 400 PCR_TX_DATA_ENABLE | PCR_SOF_NO_FBIT;
401 if (port->clock_type == CLOCK_INT) 401 if (port->clock_type == CLOCK_INT)
402 msg.data32 |= PCR_SYNC_CLK_DIR_OUTPUT; 402 msg.data32 |= PCR_SYNC_CLK_DIR_OUTPUT;
diff --git a/drivers/net/wireless/ath/ath9k/ar9002_calib.c b/drivers/net/wireless/ath/ath9k/ar9002_calib.c
index dabafb874c36..fe7418aefc4a 100644
--- a/drivers/net/wireless/ath/ath9k/ar9002_calib.c
+++ b/drivers/net/wireless/ath/ath9k/ar9002_calib.c
@@ -63,6 +63,7 @@ static bool ar9002_hw_per_calibration(struct ath_hw *ah,
63 u8 rxchainmask, 63 u8 rxchainmask,
64 struct ath9k_cal_list *currCal) 64 struct ath9k_cal_list *currCal)
65{ 65{
66 struct ath9k_hw_cal_data *caldata = ah->caldata;
66 bool iscaldone = false; 67 bool iscaldone = false;
67 68
68 if (currCal->calState == CAL_RUNNING) { 69 if (currCal->calState == CAL_RUNNING) {
@@ -81,14 +82,14 @@ static bool ar9002_hw_per_calibration(struct ath_hw *ah,
81 } 82 }
82 83
83 currCal->calData->calPostProc(ah, numChains); 84 currCal->calData->calPostProc(ah, numChains);
84 ichan->CalValid |= currCal->calData->calType; 85 caldata->CalValid |= currCal->calData->calType;
85 currCal->calState = CAL_DONE; 86 currCal->calState = CAL_DONE;
86 iscaldone = true; 87 iscaldone = true;
87 } else { 88 } else {
88 ar9002_hw_setup_calibration(ah, currCal); 89 ar9002_hw_setup_calibration(ah, currCal);
89 } 90 }
90 } 91 }
91 } else if (!(ichan->CalValid & currCal->calData->calType)) { 92 } else if (!(caldata->CalValid & currCal->calData->calType)) {
92 ath9k_hw_reset_calibration(ah, currCal); 93 ath9k_hw_reset_calibration(ah, currCal);
93 } 94 }
94 95
@@ -686,8 +687,13 @@ static bool ar9002_hw_calibrate(struct ath_hw *ah,
686{ 687{
687 bool iscaldone = true; 688 bool iscaldone = true;
688 struct ath9k_cal_list *currCal = ah->cal_list_curr; 689 struct ath9k_cal_list *currCal = ah->cal_list_curr;
690 bool nfcal, nfcal_pending = false;
689 691
690 if (currCal && 692 nfcal = !!(REG_READ(ah, AR_PHY_AGC_CONTROL) & AR_PHY_AGC_CONTROL_NF);
693 if (ah->caldata)
694 nfcal_pending = ah->caldata->nfcal_pending;
695
696 if (currCal && !nfcal &&
691 (currCal->calState == CAL_RUNNING || 697 (currCal->calState == CAL_RUNNING ||
692 currCal->calState == CAL_WAITING)) { 698 currCal->calState == CAL_WAITING)) {
693 iscaldone = ar9002_hw_per_calibration(ah, chan, 699 iscaldone = ar9002_hw_per_calibration(ah, chan,
@@ -703,7 +709,7 @@ static bool ar9002_hw_calibrate(struct ath_hw *ah,
703 } 709 }
704 710
705 /* Do NF cal only at longer intervals */ 711 /* Do NF cal only at longer intervals */
706 if (longcal) { 712 if (longcal || nfcal_pending) {
707 /* Do periodic PAOffset Cal */ 713 /* Do periodic PAOffset Cal */
708 ar9002_hw_pa_cal(ah, false); 714 ar9002_hw_pa_cal(ah, false);
709 ar9002_hw_olc_temp_compensation(ah); 715 ar9002_hw_olc_temp_compensation(ah);
@@ -712,16 +718,18 @@ static bool ar9002_hw_calibrate(struct ath_hw *ah,
712 * Get the value from the previous NF cal and update 718 * Get the value from the previous NF cal and update
713 * history buffer. 719 * history buffer.
714 */ 720 */
715 ath9k_hw_getnf(ah, chan); 721 if (ath9k_hw_getnf(ah, chan)) {
716 722 /*
717 /* 723 * Load the NF from history buffer of the current
718 * Load the NF from history buffer of the current channel. 724 * channel.
719 * NF is slow time-variant, so it is OK to use a historical 725 * NF is slow time-variant, so it is OK to use a
720 * value. 726 * historical value.
721 */ 727 */
722 ath9k_hw_loadnf(ah, ah->curchan); 728 ath9k_hw_loadnf(ah, ah->curchan);
729 }
723 730
724 ath9k_hw_start_nfcal(ah); 731 if (longcal)
732 ath9k_hw_start_nfcal(ah, false);
725 } 733 }
726 734
727 return iscaldone; 735 return iscaldone;
@@ -869,8 +877,10 @@ static bool ar9002_hw_init_cal(struct ath_hw *ah, struct ath9k_channel *chan)
869 ar9002_hw_pa_cal(ah, true); 877 ar9002_hw_pa_cal(ah, true);
870 878
871 /* Do NF Calibration after DC offset and other calibrations */ 879 /* Do NF Calibration after DC offset and other calibrations */
872 REG_WRITE(ah, AR_PHY_AGC_CONTROL, 880 ath9k_hw_start_nfcal(ah, true);
873 REG_READ(ah, AR_PHY_AGC_CONTROL) | AR_PHY_AGC_CONTROL_NF); 881
882 if (ah->caldata)
883 ah->caldata->nfcal_pending = true;
874 884
875 ah->cal_list = ah->cal_list_last = ah->cal_list_curr = NULL; 885 ah->cal_list = ah->cal_list_last = ah->cal_list_curr = NULL;
876 886
@@ -901,7 +911,8 @@ static bool ar9002_hw_init_cal(struct ath_hw *ah, struct ath9k_channel *chan)
901 ath9k_hw_reset_calibration(ah, ah->cal_list_curr); 911 ath9k_hw_reset_calibration(ah, ah->cal_list_curr);
902 } 912 }
903 913
904 chan->CalValid = 0; 914 if (ah->caldata)
915 ah->caldata->CalValid = 0;
905 916
906 return true; 917 return true;
907} 918}
diff --git a/drivers/net/wireless/ath/ath9k/ar9003_calib.c b/drivers/net/wireless/ath/ath9k/ar9003_calib.c
index 5a0650399136..4674ea8c9c99 100644
--- a/drivers/net/wireless/ath/ath9k/ar9003_calib.c
+++ b/drivers/net/wireless/ath/ath9k/ar9003_calib.c
@@ -68,6 +68,7 @@ static bool ar9003_hw_per_calibration(struct ath_hw *ah,
68 u8 rxchainmask, 68 u8 rxchainmask,
69 struct ath9k_cal_list *currCal) 69 struct ath9k_cal_list *currCal)
70{ 70{
71 struct ath9k_hw_cal_data *caldata = ah->caldata;
71 /* Cal is assumed not done until explicitly set below */ 72 /* Cal is assumed not done until explicitly set below */
72 bool iscaldone = false; 73 bool iscaldone = false;
73 74
@@ -95,7 +96,7 @@ static bool ar9003_hw_per_calibration(struct ath_hw *ah,
95 currCal->calData->calPostProc(ah, numChains); 96 currCal->calData->calPostProc(ah, numChains);
96 97
97 /* Calibration has finished. */ 98 /* Calibration has finished. */
98 ichan->CalValid |= currCal->calData->calType; 99 caldata->CalValid |= currCal->calData->calType;
99 currCal->calState = CAL_DONE; 100 currCal->calState = CAL_DONE;
100 iscaldone = true; 101 iscaldone = true;
101 } else { 102 } else {
@@ -106,7 +107,7 @@ static bool ar9003_hw_per_calibration(struct ath_hw *ah,
106 ar9003_hw_setup_calibration(ah, currCal); 107 ar9003_hw_setup_calibration(ah, currCal);
107 } 108 }
108 } 109 }
109 } else if (!(ichan->CalValid & currCal->calData->calType)) { 110 } else if (!(caldata->CalValid & currCal->calData->calType)) {
110 /* If current cal is marked invalid in channel, kick it off */ 111 /* If current cal is marked invalid in channel, kick it off */
111 ath9k_hw_reset_calibration(ah, currCal); 112 ath9k_hw_reset_calibration(ah, currCal);
112 } 113 }
@@ -149,6 +150,12 @@ static bool ar9003_hw_calibrate(struct ath_hw *ah,
149 /* Do NF cal only at longer intervals */ 150 /* Do NF cal only at longer intervals */
150 if (longcal) { 151 if (longcal) {
151 /* 152 /*
153 * Get the value from the previous NF cal and update
154 * history buffer.
155 */
156 ath9k_hw_getnf(ah, chan);
157
158 /*
152 * Load the NF from history buffer of the current channel. 159 * Load the NF from history buffer of the current channel.
153 * NF is slow time-variant, so it is OK to use a historical 160 * NF is slow time-variant, so it is OK to use a historical
154 * value. 161 * value.
@@ -156,7 +163,7 @@ static bool ar9003_hw_calibrate(struct ath_hw *ah,
156 ath9k_hw_loadnf(ah, ah->curchan); 163 ath9k_hw_loadnf(ah, ah->curchan);
157 164
158 /* start NF calibration, without updating BB NF register */ 165 /* start NF calibration, without updating BB NF register */
159 ath9k_hw_start_nfcal(ah); 166 ath9k_hw_start_nfcal(ah, false);
160 } 167 }
161 168
162 return iscaldone; 169 return iscaldone;
@@ -762,6 +769,8 @@ static bool ar9003_hw_init_cal(struct ath_hw *ah,
762 /* Revert chainmasks to their original values before NF cal */ 769 /* Revert chainmasks to their original values before NF cal */
763 ar9003_hw_set_chain_masks(ah, ah->rxchainmask, ah->txchainmask); 770 ar9003_hw_set_chain_masks(ah, ah->rxchainmask, ah->txchainmask);
764 771
772 ath9k_hw_start_nfcal(ah, true);
773
765 /* Initialize list pointers */ 774 /* Initialize list pointers */
766 ah->cal_list = ah->cal_list_last = ah->cal_list_curr = NULL; 775 ah->cal_list = ah->cal_list_last = ah->cal_list_curr = NULL;
767 776
@@ -785,7 +794,8 @@ static bool ar9003_hw_init_cal(struct ath_hw *ah,
785 if (ah->cal_list_curr) 794 if (ah->cal_list_curr)
786 ath9k_hw_reset_calibration(ah, ah->cal_list_curr); 795 ath9k_hw_reset_calibration(ah, ah->cal_list_curr);
787 796
788 chan->CalValid = 0; 797 if (ah->caldata)
798 ah->caldata->CalValid = 0;
789 799
790 return true; 800 return true;
791} 801}
diff --git a/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c b/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c
index ace8d2678b18..b883b174385b 100644
--- a/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c
+++ b/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c
@@ -41,6 +41,20 @@
41#define LE16(x) __constant_cpu_to_le16(x) 41#define LE16(x) __constant_cpu_to_le16(x)
42#define LE32(x) __constant_cpu_to_le32(x) 42#define LE32(x) __constant_cpu_to_le32(x)
43 43
44/* Local defines to distinguish between extension and control CTL's */
45#define EXT_ADDITIVE (0x8000)
46#define CTL_11A_EXT (CTL_11A | EXT_ADDITIVE)
47#define CTL_11G_EXT (CTL_11G | EXT_ADDITIVE)
48#define CTL_11B_EXT (CTL_11B | EXT_ADDITIVE)
49#define REDUCE_SCALED_POWER_BY_TWO_CHAIN 6 /* 10*log10(2)*2 */
50#define REDUCE_SCALED_POWER_BY_THREE_CHAIN 9 /* 10*log10(3)*2 */
51#define PWRINCR_3_TO_1_CHAIN 9 /* 10*log(3)*2 */
52#define PWRINCR_3_TO_2_CHAIN 3 /* floor(10*log(3/2)*2) */
53#define PWRINCR_2_TO_1_CHAIN 6 /* 10*log(2)*2 */
54
55#define SUB_NUM_CTL_MODES_AT_5G_40 2 /* excluding HT40, EXT-OFDM */
56#define SUB_NUM_CTL_MODES_AT_2G_40 3 /* excluding HT40, EXT-OFDM, EXT-CCK */
57
44static const struct ar9300_eeprom ar9300_default = { 58static const struct ar9300_eeprom ar9300_default = {
45 .eepromVersion = 2, 59 .eepromVersion = 2,
46 .templateVersion = 2, 60 .templateVersion = 2,
@@ -609,6 +623,14 @@ static const struct ar9300_eeprom ar9300_default = {
609 } 623 }
610}; 624};
611 625
626static u16 ath9k_hw_fbin2freq(u8 fbin, bool is2GHz)
627{
628 if (fbin == AR9300_BCHAN_UNUSED)
629 return fbin;
630
631 return (u16) ((is2GHz) ? (2300 + fbin) : (4800 + 5 * fbin));
632}
633
612static int ath9k_hw_ar9300_check_eeprom(struct ath_hw *ah) 634static int ath9k_hw_ar9300_check_eeprom(struct ath_hw *ah)
613{ 635{
614 return 0; 636 return 0;
@@ -1417,9 +1439,9 @@ static int ar9003_hw_tx_power_regwrite(struct ath_hw *ah, u8 * pPwrArray)
1417#undef POW_SM 1439#undef POW_SM
1418} 1440}
1419 1441
1420static void ar9003_hw_set_target_power_eeprom(struct ath_hw *ah, u16 freq) 1442static void ar9003_hw_set_target_power_eeprom(struct ath_hw *ah, u16 freq,
1443 u8 *targetPowerValT2)
1421{ 1444{
1422 u8 targetPowerValT2[ar9300RateSize];
1423 /* XXX: hard code for now, need to get from eeprom struct */ 1445 /* XXX: hard code for now, need to get from eeprom struct */
1424 u8 ht40PowerIncForPdadc = 0; 1446 u8 ht40PowerIncForPdadc = 0;
1425 bool is2GHz = false; 1447 bool is2GHz = false;
@@ -1553,9 +1575,6 @@ static void ar9003_hw_set_target_power_eeprom(struct ath_hw *ah, u16 freq)
1553 "TPC[%02d] 0x%08x\n", i, targetPowerValT2[i]); 1575 "TPC[%02d] 0x%08x\n", i, targetPowerValT2[i]);
1554 i++; 1576 i++;
1555 } 1577 }
1556
1557 /* Write target power array to registers */
1558 ar9003_hw_tx_power_regwrite(ah, targetPowerValT2);
1559} 1578}
1560 1579
1561static int ar9003_hw_cal_pier_get(struct ath_hw *ah, 1580static int ar9003_hw_cal_pier_get(struct ath_hw *ah,
@@ -1799,14 +1818,369 @@ static int ar9003_hw_calibration_apply(struct ath_hw *ah, int frequency)
1799 return 0; 1818 return 0;
1800} 1819}
1801 1820
1821static u16 ar9003_hw_get_direct_edge_power(struct ar9300_eeprom *eep,
1822 int idx,
1823 int edge,
1824 bool is2GHz)
1825{
1826 struct cal_ctl_data_2g *ctl_2g = eep->ctlPowerData_2G;
1827 struct cal_ctl_data_5g *ctl_5g = eep->ctlPowerData_5G;
1828
1829 if (is2GHz)
1830 return ctl_2g[idx].ctlEdges[edge].tPower;
1831 else
1832 return ctl_5g[idx].ctlEdges[edge].tPower;
1833}
1834
1835static u16 ar9003_hw_get_indirect_edge_power(struct ar9300_eeprom *eep,
1836 int idx,
1837 unsigned int edge,
1838 u16 freq,
1839 bool is2GHz)
1840{
1841 struct cal_ctl_data_2g *ctl_2g = eep->ctlPowerData_2G;
1842 struct cal_ctl_data_5g *ctl_5g = eep->ctlPowerData_5G;
1843
1844 u8 *ctl_freqbin = is2GHz ?
1845 &eep->ctl_freqbin_2G[idx][0] :
1846 &eep->ctl_freqbin_5G[idx][0];
1847
1848 if (is2GHz) {
1849 if (ath9k_hw_fbin2freq(ctl_freqbin[edge - 1], 1) < freq &&
1850 ctl_2g[idx].ctlEdges[edge - 1].flag)
1851 return ctl_2g[idx].ctlEdges[edge - 1].tPower;
1852 } else {
1853 if (ath9k_hw_fbin2freq(ctl_freqbin[edge - 1], 0) < freq &&
1854 ctl_5g[idx].ctlEdges[edge - 1].flag)
1855 return ctl_5g[idx].ctlEdges[edge - 1].tPower;
1856 }
1857
1858 return AR9300_MAX_RATE_POWER;
1859}
1860
1861/*
1862 * Find the maximum conformance test limit for the given channel and CTL info
1863 */
1864static u16 ar9003_hw_get_max_edge_power(struct ar9300_eeprom *eep,
1865 u16 freq, int idx, bool is2GHz)
1866{
1867 u16 twiceMaxEdgePower = AR9300_MAX_RATE_POWER;
1868 u8 *ctl_freqbin = is2GHz ?
1869 &eep->ctl_freqbin_2G[idx][0] :
1870 &eep->ctl_freqbin_5G[idx][0];
1871 u16 num_edges = is2GHz ?
1872 AR9300_NUM_BAND_EDGES_2G : AR9300_NUM_BAND_EDGES_5G;
1873 unsigned int edge;
1874
1875 /* Get the edge power */
1876 for (edge = 0;
1877 (edge < num_edges) && (ctl_freqbin[edge] != AR9300_BCHAN_UNUSED);
1878 edge++) {
1879 /*
1880 * If there's an exact channel match or an inband flag set
1881 * on the lower channel use the given rdEdgePower
1882 */
1883 if (freq == ath9k_hw_fbin2freq(ctl_freqbin[edge], is2GHz)) {
1884 twiceMaxEdgePower =
1885 ar9003_hw_get_direct_edge_power(eep, idx,
1886 edge, is2GHz);
1887 break;
1888 } else if ((edge > 0) &&
1889 (freq < ath9k_hw_fbin2freq(ctl_freqbin[edge],
1890 is2GHz))) {
1891 twiceMaxEdgePower =
1892 ar9003_hw_get_indirect_edge_power(eep, idx,
1893 edge, freq,
1894 is2GHz);
1895 /*
1896 * Leave loop - no more affecting edges possible in
1897 * this monotonic increasing list
1898 */
1899 break;
1900 }
1901 }
1902 return twiceMaxEdgePower;
1903}
1904
1905static void ar9003_hw_set_power_per_rate_table(struct ath_hw *ah,
1906 struct ath9k_channel *chan,
1907 u8 *pPwrArray, u16 cfgCtl,
1908 u8 twiceAntennaReduction,
1909 u8 twiceMaxRegulatoryPower,
1910 u16 powerLimit)
1911{
1912 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
1913 struct ath_common *common = ath9k_hw_common(ah);
1914 struct ar9300_eeprom *pEepData = &ah->eeprom.ar9300_eep;
1915 u16 twiceMaxEdgePower = AR9300_MAX_RATE_POWER;
1916 static const u16 tpScaleReductionTable[5] = {
1917 0, 3, 6, 9, AR9300_MAX_RATE_POWER
1918 };
1919 int i;
1920 int16_t twiceLargestAntenna;
1921 u16 scaledPower = 0, minCtlPower, maxRegAllowedPower;
1922 u16 ctlModesFor11a[] = {
1923 CTL_11A, CTL_5GHT20, CTL_11A_EXT, CTL_5GHT40
1924 };
1925 u16 ctlModesFor11g[] = {
1926 CTL_11B, CTL_11G, CTL_2GHT20, CTL_11B_EXT,
1927 CTL_11G_EXT, CTL_2GHT40
1928 };
1929 u16 numCtlModes, *pCtlMode, ctlMode, freq;
1930 struct chan_centers centers;
1931 u8 *ctlIndex;
1932 u8 ctlNum;
1933 u16 twiceMinEdgePower;
1934 bool is2ghz = IS_CHAN_2GHZ(chan);
1935
1936 ath9k_hw_get_channel_centers(ah, chan, &centers);
1937
1938 /* Compute TxPower reduction due to Antenna Gain */
1939 if (is2ghz)
1940 twiceLargestAntenna = pEepData->modalHeader2G.antennaGain;
1941 else
1942 twiceLargestAntenna = pEepData->modalHeader5G.antennaGain;
1943
1944 twiceLargestAntenna = (int16_t)min((twiceAntennaReduction) -
1945 twiceLargestAntenna, 0);
1946
1947 /*
1948 * scaledPower is the minimum of the user input power level
1949 * and the regulatory allowed power level
1950 */
1951 maxRegAllowedPower = twiceMaxRegulatoryPower + twiceLargestAntenna;
1952
1953 if (regulatory->tp_scale != ATH9K_TP_SCALE_MAX) {
1954 maxRegAllowedPower -=
1955 (tpScaleReductionTable[(regulatory->tp_scale)] * 2);
1956 }
1957
1958 scaledPower = min(powerLimit, maxRegAllowedPower);
1959
1960 /*
1961 * Reduce scaled Power by number of chains active to get
1962 * to per chain tx power level
1963 */
1964 switch (ar5416_get_ntxchains(ah->txchainmask)) {
1965 case 1:
1966 break;
1967 case 2:
1968 scaledPower -= REDUCE_SCALED_POWER_BY_TWO_CHAIN;
1969 break;
1970 case 3:
1971 scaledPower -= REDUCE_SCALED_POWER_BY_THREE_CHAIN;
1972 break;
1973 }
1974
1975 scaledPower = max((u16)0, scaledPower);
1976
1977 /*
1978 * Get target powers from EEPROM - our baseline for TX Power
1979 */
1980 if (is2ghz) {
1981 /* Setup for CTL modes */
1982 /* CTL_11B, CTL_11G, CTL_2GHT20 */
1983 numCtlModes =
1984 ARRAY_SIZE(ctlModesFor11g) -
1985 SUB_NUM_CTL_MODES_AT_2G_40;
1986 pCtlMode = ctlModesFor11g;
1987 if (IS_CHAN_HT40(chan))
1988 /* All 2G CTL's */
1989 numCtlModes = ARRAY_SIZE(ctlModesFor11g);
1990 } else {
1991 /* Setup for CTL modes */
1992 /* CTL_11A, CTL_5GHT20 */
1993 numCtlModes = ARRAY_SIZE(ctlModesFor11a) -
1994 SUB_NUM_CTL_MODES_AT_5G_40;
1995 pCtlMode = ctlModesFor11a;
1996 if (IS_CHAN_HT40(chan))
1997 /* All 5G CTL's */
1998 numCtlModes = ARRAY_SIZE(ctlModesFor11a);
1999 }
2000
2001 /*
2002 * For MIMO, need to apply regulatory caps individually across
2003 * dynamically running modes: CCK, OFDM, HT20, HT40
2004 *
2005 * The outer loop walks through each possible applicable runtime mode.
2006 * The inner loop walks through each ctlIndex entry in EEPROM.
2007 * The ctl value is encoded as [7:4] == test group, [3:0] == test mode.
2008 */
2009 for (ctlMode = 0; ctlMode < numCtlModes; ctlMode++) {
2010 bool isHt40CtlMode = (pCtlMode[ctlMode] == CTL_5GHT40) ||
2011 (pCtlMode[ctlMode] == CTL_2GHT40);
2012 if (isHt40CtlMode)
2013 freq = centers.synth_center;
2014 else if (pCtlMode[ctlMode] & EXT_ADDITIVE)
2015 freq = centers.ext_center;
2016 else
2017 freq = centers.ctl_center;
2018
2019 ath_print(common, ATH_DBG_REGULATORY,
2020 "LOOP-Mode ctlMode %d < %d, isHt40CtlMode %d, "
2021 "EXT_ADDITIVE %d\n",
2022 ctlMode, numCtlModes, isHt40CtlMode,
2023 (pCtlMode[ctlMode] & EXT_ADDITIVE));
2024
2025 /* walk through each CTL index stored in EEPROM */
2026 if (is2ghz) {
2027 ctlIndex = pEepData->ctlIndex_2G;
2028 ctlNum = AR9300_NUM_CTLS_2G;
2029 } else {
2030 ctlIndex = pEepData->ctlIndex_5G;
2031 ctlNum = AR9300_NUM_CTLS_5G;
2032 }
2033
2034 for (i = 0; (i < ctlNum) && ctlIndex[i]; i++) {
2035 ath_print(common, ATH_DBG_REGULATORY,
2036 "LOOP-Ctlidx %d: cfgCtl 0x%2.2x "
2037 "pCtlMode 0x%2.2x ctlIndex 0x%2.2x "
2038 "chan %dn",
2039 i, cfgCtl, pCtlMode[ctlMode], ctlIndex[i],
2040 chan->channel);
2041
2042 /*
2043 * compare test group from regulatory
2044 * channel list with test mode from pCtlMode
2045 * list
2046 */
2047 if ((((cfgCtl & ~CTL_MODE_M) |
2048 (pCtlMode[ctlMode] & CTL_MODE_M)) ==
2049 ctlIndex[i]) ||
2050 (((cfgCtl & ~CTL_MODE_M) |
2051 (pCtlMode[ctlMode] & CTL_MODE_M)) ==
2052 ((ctlIndex[i] & CTL_MODE_M) |
2053 SD_NO_CTL))) {
2054 twiceMinEdgePower =
2055 ar9003_hw_get_max_edge_power(pEepData,
2056 freq, i,
2057 is2ghz);
2058
2059 if ((cfgCtl & ~CTL_MODE_M) == SD_NO_CTL)
2060 /*
2061 * Find the minimum of all CTL
2062 * edge powers that apply to
2063 * this channel
2064 */
2065 twiceMaxEdgePower =
2066 min(twiceMaxEdgePower,
2067 twiceMinEdgePower);
2068 else {
2069 /* specific */
2070 twiceMaxEdgePower =
2071 twiceMinEdgePower;
2072 break;
2073 }
2074 }
2075 }
2076
2077 minCtlPower = (u8)min(twiceMaxEdgePower, scaledPower);
2078
2079 ath_print(common, ATH_DBG_REGULATORY,
2080 "SEL-Min ctlMode %d pCtlMode %d 2xMaxEdge %d "
2081 "sP %d minCtlPwr %d\n",
2082 ctlMode, pCtlMode[ctlMode], twiceMaxEdgePower,
2083 scaledPower, minCtlPower);
2084
2085 /* Apply ctl mode to correct target power set */
2086 switch (pCtlMode[ctlMode]) {
2087 case CTL_11B:
2088 for (i = ALL_TARGET_LEGACY_1L_5L;
2089 i <= ALL_TARGET_LEGACY_11S; i++)
2090 pPwrArray[i] =
2091 (u8)min((u16)pPwrArray[i],
2092 minCtlPower);
2093 break;
2094 case CTL_11A:
2095 case CTL_11G:
2096 for (i = ALL_TARGET_LEGACY_6_24;
2097 i <= ALL_TARGET_LEGACY_54; i++)
2098 pPwrArray[i] =
2099 (u8)min((u16)pPwrArray[i],
2100 minCtlPower);
2101 break;
2102 case CTL_5GHT20:
2103 case CTL_2GHT20:
2104 for (i = ALL_TARGET_HT20_0_8_16;
2105 i <= ALL_TARGET_HT20_21; i++)
2106 pPwrArray[i] =
2107 (u8)min((u16)pPwrArray[i],
2108 minCtlPower);
2109 pPwrArray[ALL_TARGET_HT20_22] =
2110 (u8)min((u16)pPwrArray[ALL_TARGET_HT20_22],
2111 minCtlPower);
2112 pPwrArray[ALL_TARGET_HT20_23] =
2113 (u8)min((u16)pPwrArray[ALL_TARGET_HT20_23],
2114 minCtlPower);
2115 break;
2116 case CTL_5GHT40:
2117 case CTL_2GHT40:
2118 for (i = ALL_TARGET_HT40_0_8_16;
2119 i <= ALL_TARGET_HT40_23; i++)
2120 pPwrArray[i] =
2121 (u8)min((u16)pPwrArray[i],
2122 minCtlPower);
2123 break;
2124 default:
2125 break;
2126 }
2127 } /* end ctl mode checking */
2128}
2129
1802static void ath9k_hw_ar9300_set_txpower(struct ath_hw *ah, 2130static void ath9k_hw_ar9300_set_txpower(struct ath_hw *ah,
1803 struct ath9k_channel *chan, u16 cfgCtl, 2131 struct ath9k_channel *chan, u16 cfgCtl,
1804 u8 twiceAntennaReduction, 2132 u8 twiceAntennaReduction,
1805 u8 twiceMaxRegulatoryPower, 2133 u8 twiceMaxRegulatoryPower,
1806 u8 powerLimit) 2134 u8 powerLimit)
1807{ 2135{
1808 ah->txpower_limit = powerLimit; 2136 struct ath_common *common = ath9k_hw_common(ah);
1809 ar9003_hw_set_target_power_eeprom(ah, chan->channel); 2137 u8 targetPowerValT2[ar9300RateSize];
2138 unsigned int i = 0;
2139
2140 ar9003_hw_set_target_power_eeprom(ah, chan->channel, targetPowerValT2);
2141 ar9003_hw_set_power_per_rate_table(ah, chan,
2142 targetPowerValT2, cfgCtl,
2143 twiceAntennaReduction,
2144 twiceMaxRegulatoryPower,
2145 powerLimit);
2146
2147 while (i < ar9300RateSize) {
2148 ath_print(common, ATH_DBG_EEPROM,
2149 "TPC[%02d] 0x%08x ", i, targetPowerValT2[i]);
2150 i++;
2151 ath_print(common, ATH_DBG_EEPROM,
2152 "TPC[%02d] 0x%08x ", i, targetPowerValT2[i]);
2153 i++;
2154 ath_print(common, ATH_DBG_EEPROM,
2155 "TPC[%02d] 0x%08x ", i, targetPowerValT2[i]);
2156 i++;
2157 ath_print(common, ATH_DBG_EEPROM,
2158 "TPC[%02d] 0x%08x\n\n", i, targetPowerValT2[i]);
2159 i++;
2160 }
2161
2162 /* Write target power array to registers */
2163 ar9003_hw_tx_power_regwrite(ah, targetPowerValT2);
2164
2165 /*
2166 * This is the TX power we send back to driver core,
2167 * and it can use to pass to userspace to display our
2168 * currently configured TX power setting.
2169 *
2170 * Since power is rate dependent, use one of the indices
2171 * from the AR9300_Rates enum to select an entry from
2172 * targetPowerValT2[] to report. Currently returns the
2173 * power for HT40 MCS 0, HT20 MCS 0, or OFDM 6 Mbps
2174 * as CCK power is less interesting (?).
2175 */
2176 i = ALL_TARGET_LEGACY_6_24; /* legacy */
2177 if (IS_CHAN_HT40(chan))
2178 i = ALL_TARGET_HT40_0_8_16; /* ht40 */
2179 else if (IS_CHAN_HT20(chan))
2180 i = ALL_TARGET_HT20_0_8_16; /* ht20 */
2181
2182 ah->txpower_limit = targetPowerValT2[i];
2183
1810 ar9003_hw_calibration_apply(ah, chan->channel); 2184 ar9003_hw_calibration_apply(ah, chan->channel);
1811} 2185}
1812 2186
diff --git a/drivers/net/wireless/ath/ath9k/ar9003_paprd.c b/drivers/net/wireless/ath/ath9k/ar9003_paprd.c
index 49e0c865ce5c..7c38229ba670 100644
--- a/drivers/net/wireless/ath/ath9k/ar9003_paprd.c
+++ b/drivers/net/wireless/ath/ath9k/ar9003_paprd.c
@@ -577,10 +577,11 @@ static bool create_pa_curve(u32 *data_L, u32 *data_U, u32 *pa_table, u16 *gain)
577} 577}
578 578
579void ar9003_paprd_populate_single_table(struct ath_hw *ah, 579void ar9003_paprd_populate_single_table(struct ath_hw *ah,
580 struct ath9k_channel *chan, int chain) 580 struct ath9k_hw_cal_data *caldata,
581 int chain)
581{ 582{
582 u32 *paprd_table_val = chan->pa_table[chain]; 583 u32 *paprd_table_val = caldata->pa_table[chain];
583 u32 small_signal_gain = chan->small_signal_gain[chain]; 584 u32 small_signal_gain = caldata->small_signal_gain[chain];
584 u32 training_power; 585 u32 training_power;
585 u32 reg = 0; 586 u32 reg = 0;
586 int i; 587 int i;
@@ -654,17 +655,17 @@ int ar9003_paprd_setup_gain_table(struct ath_hw *ah, int chain)
654} 655}
655EXPORT_SYMBOL(ar9003_paprd_setup_gain_table); 656EXPORT_SYMBOL(ar9003_paprd_setup_gain_table);
656 657
657int ar9003_paprd_create_curve(struct ath_hw *ah, struct ath9k_channel *chan, 658int ar9003_paprd_create_curve(struct ath_hw *ah,
658 int chain) 659 struct ath9k_hw_cal_data *caldata, int chain)
659{ 660{
660 u16 *small_signal_gain = &chan->small_signal_gain[chain]; 661 u16 *small_signal_gain = &caldata->small_signal_gain[chain];
661 u32 *pa_table = chan->pa_table[chain]; 662 u32 *pa_table = caldata->pa_table[chain];
662 u32 *data_L, *data_U; 663 u32 *data_L, *data_U;
663 int i, status = 0; 664 int i, status = 0;
664 u32 *buf; 665 u32 *buf;
665 u32 reg; 666 u32 reg;
666 667
667 memset(chan->pa_table[chain], 0, sizeof(chan->pa_table[chain])); 668 memset(caldata->pa_table[chain], 0, sizeof(caldata->pa_table[chain]));
668 669
669 buf = kmalloc(2 * 48 * sizeof(u32), GFP_ATOMIC); 670 buf = kmalloc(2 * 48 * sizeof(u32), GFP_ATOMIC);
670 if (!buf) 671 if (!buf)
diff --git a/drivers/net/wireless/ath/ath9k/ar9003_phy.c b/drivers/net/wireless/ath/ath9k/ar9003_phy.c
index a753a431bb13..a491854fa38a 100644
--- a/drivers/net/wireless/ath/ath9k/ar9003_phy.c
+++ b/drivers/net/wireless/ath/ath9k/ar9003_phy.c
@@ -542,7 +542,11 @@ static void ar9003_hw_prog_ini(struct ath_hw *ah,
542 u32 reg = INI_RA(iniArr, i, 0); 542 u32 reg = INI_RA(iniArr, i, 0);
543 u32 val = INI_RA(iniArr, i, column); 543 u32 val = INI_RA(iniArr, i, column);
544 544
545 REG_WRITE(ah, reg, val); 545 if (reg >= 0x16000 && reg < 0x17000)
546 ath9k_hw_analog_shift_regwrite(ah, reg, val);
547 else
548 REG_WRITE(ah, reg, val);
549
546 DO_DELAY(regWrites); 550 DO_DELAY(regWrites);
547 } 551 }
548} 552}
diff --git a/drivers/net/wireless/ath/ath9k/ath9k.h b/drivers/net/wireless/ath/ath9k/ath9k.h
index 998ae2c49ed2..07f26ee7a723 100644
--- a/drivers/net/wireless/ath/ath9k/ath9k.h
+++ b/drivers/net/wireless/ath/ath9k/ath9k.h
@@ -510,7 +510,7 @@ void ath_deinit_leds(struct ath_softc *sc);
510#define SC_OP_BEACONS BIT(1) 510#define SC_OP_BEACONS BIT(1)
511#define SC_OP_RXAGGR BIT(2) 511#define SC_OP_RXAGGR BIT(2)
512#define SC_OP_TXAGGR BIT(3) 512#define SC_OP_TXAGGR BIT(3)
513#define SC_OP_FULL_RESET BIT(4) 513#define SC_OP_OFFCHANNEL BIT(4)
514#define SC_OP_PREAMBLE_SHORT BIT(5) 514#define SC_OP_PREAMBLE_SHORT BIT(5)
515#define SC_OP_PROTECT_ENABLE BIT(6) 515#define SC_OP_PROTECT_ENABLE BIT(6)
516#define SC_OP_RXFLUSH BIT(7) 516#define SC_OP_RXFLUSH BIT(7)
@@ -609,6 +609,7 @@ struct ath_softc {
609struct ath_wiphy { 609struct ath_wiphy {
610 struct ath_softc *sc; /* shared for all virtual wiphys */ 610 struct ath_softc *sc; /* shared for all virtual wiphys */
611 struct ieee80211_hw *hw; 611 struct ieee80211_hw *hw;
612 struct ath9k_hw_cal_data caldata;
612 enum ath_wiphy_state { 613 enum ath_wiphy_state {
613 ATH_WIPHY_INACTIVE, 614 ATH_WIPHY_INACTIVE,
614 ATH_WIPHY_ACTIVE, 615 ATH_WIPHY_ACTIVE,
diff --git a/drivers/net/wireless/ath/ath9k/calib.c b/drivers/net/wireless/ath/ath9k/calib.c
index 139289e4e933..45208690c0ec 100644
--- a/drivers/net/wireless/ath/ath9k/calib.c
+++ b/drivers/net/wireless/ath/ath9k/calib.c
@@ -22,23 +22,6 @@
22/* We can tune this as we go by monitoring really low values */ 22/* We can tune this as we go by monitoring really low values */
23#define ATH9K_NF_TOO_LOW -60 23#define ATH9K_NF_TOO_LOW -60
24 24
25/* AR5416 may return very high value (like -31 dBm), in those cases the nf
26 * is incorrect and we should use the static NF value. Later we can try to
27 * find out why they are reporting these values */
28
29static bool ath9k_hw_nf_in_range(struct ath_hw *ah, s16 nf)
30{
31 if (nf > ATH9K_NF_TOO_LOW) {
32 ath_print(ath9k_hw_common(ah), ATH_DBG_CALIBRATE,
33 "noise floor value detected (%d) is "
34 "lower than what we think is a "
35 "reasonable value (%d)\n",
36 nf, ATH9K_NF_TOO_LOW);
37 return false;
38 }
39 return true;
40}
41
42static int16_t ath9k_hw_get_nf_hist_mid(int16_t *nfCalBuffer) 25static int16_t ath9k_hw_get_nf_hist_mid(int16_t *nfCalBuffer)
43{ 26{
44 int16_t nfval; 27 int16_t nfval;
@@ -121,6 +104,19 @@ void ath9k_hw_reset_calibration(struct ath_hw *ah,
121 ah->cal_samples = 0; 104 ah->cal_samples = 0;
122} 105}
123 106
107static s16 ath9k_hw_get_default_nf(struct ath_hw *ah,
108 struct ath9k_channel *chan)
109{
110 struct ath_nf_limits *limit;
111
112 if (!chan || IS_CHAN_2GHZ(chan))
113 limit = &ah->nf_2g;
114 else
115 limit = &ah->nf_5g;
116
117 return limit->nominal;
118}
119
124/* This is done for the currently configured channel */ 120/* This is done for the currently configured channel */
125bool ath9k_hw_reset_calvalid(struct ath_hw *ah) 121bool ath9k_hw_reset_calvalid(struct ath_hw *ah)
126{ 122{
@@ -128,7 +124,7 @@ bool ath9k_hw_reset_calvalid(struct ath_hw *ah)
128 struct ieee80211_conf *conf = &common->hw->conf; 124 struct ieee80211_conf *conf = &common->hw->conf;
129 struct ath9k_cal_list *currCal = ah->cal_list_curr; 125 struct ath9k_cal_list *currCal = ah->cal_list_curr;
130 126
131 if (!ah->curchan) 127 if (!ah->caldata)
132 return true; 128 return true;
133 129
134 if (!AR_SREV_9100(ah) && !AR_SREV_9160_10_OR_LATER(ah)) 130 if (!AR_SREV_9100(ah) && !AR_SREV_9160_10_OR_LATER(ah))
@@ -151,37 +147,55 @@ bool ath9k_hw_reset_calvalid(struct ath_hw *ah)
151 "Resetting Cal %d state for channel %u\n", 147 "Resetting Cal %d state for channel %u\n",
152 currCal->calData->calType, conf->channel->center_freq); 148 currCal->calData->calType, conf->channel->center_freq);
153 149
154 ah->curchan->CalValid &= ~currCal->calData->calType; 150 ah->caldata->CalValid &= ~currCal->calData->calType;
155 currCal->calState = CAL_WAITING; 151 currCal->calState = CAL_WAITING;
156 152
157 return false; 153 return false;
158} 154}
159EXPORT_SYMBOL(ath9k_hw_reset_calvalid); 155EXPORT_SYMBOL(ath9k_hw_reset_calvalid);
160 156
161void ath9k_hw_start_nfcal(struct ath_hw *ah) 157void ath9k_hw_start_nfcal(struct ath_hw *ah, bool update)
162{ 158{
159 if (ah->caldata)
160 ah->caldata->nfcal_pending = true;
161
163 REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, 162 REG_SET_BIT(ah, AR_PHY_AGC_CONTROL,
164 AR_PHY_AGC_CONTROL_ENABLE_NF); 163 AR_PHY_AGC_CONTROL_ENABLE_NF);
165 REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, 164
165 if (update)
166 REG_CLR_BIT(ah, AR_PHY_AGC_CONTROL,
167 AR_PHY_AGC_CONTROL_NO_UPDATE_NF);
168 else
169 REG_SET_BIT(ah, AR_PHY_AGC_CONTROL,
166 AR_PHY_AGC_CONTROL_NO_UPDATE_NF); 170 AR_PHY_AGC_CONTROL_NO_UPDATE_NF);
171
167 REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_NF); 172 REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_NF);
168} 173}
169 174
170void ath9k_hw_loadnf(struct ath_hw *ah, struct ath9k_channel *chan) 175void ath9k_hw_loadnf(struct ath_hw *ah, struct ath9k_channel *chan)
171{ 176{
172 struct ath9k_nfcal_hist *h; 177 struct ath9k_nfcal_hist *h = NULL;
173 unsigned i, j; 178 unsigned i, j;
174 int32_t val; 179 int32_t val;
175 u8 chainmask = (ah->rxchainmask << 3) | ah->rxchainmask; 180 u8 chainmask = (ah->rxchainmask << 3) | ah->rxchainmask;
176 struct ath_common *common = ath9k_hw_common(ah); 181 struct ath_common *common = ath9k_hw_common(ah);
182 s16 default_nf = ath9k_hw_get_default_nf(ah, chan);
177 183
178 h = ah->nfCalHist; 184 if (ah->caldata)
185 h = ah->caldata->nfCalHist;
179 186
180 for (i = 0; i < NUM_NF_READINGS; i++) { 187 for (i = 0; i < NUM_NF_READINGS; i++) {
181 if (chainmask & (1 << i)) { 188 if (chainmask & (1 << i)) {
189 s16 nfval;
190
191 if (h)
192 nfval = h[i].privNF;
193 else
194 nfval = default_nf;
195
182 val = REG_READ(ah, ah->nf_regs[i]); 196 val = REG_READ(ah, ah->nf_regs[i]);
183 val &= 0xFFFFFE00; 197 val &= 0xFFFFFE00;
184 val |= (((u32) (h[i].privNF) << 1) & 0x1ff); 198 val |= (((u32) nfval << 1) & 0x1ff);
185 REG_WRITE(ah, ah->nf_regs[i], val); 199 REG_WRITE(ah, ah->nf_regs[i], val);
186 } 200 }
187 } 201 }
@@ -277,22 +291,25 @@ static void ath9k_hw_nf_sanitize(struct ath_hw *ah, s16 *nf)
277 } 291 }
278} 292}
279 293
280int16_t ath9k_hw_getnf(struct ath_hw *ah, 294bool ath9k_hw_getnf(struct ath_hw *ah, struct ath9k_channel *chan)
281 struct ath9k_channel *chan)
282{ 295{
283 struct ath_common *common = ath9k_hw_common(ah); 296 struct ath_common *common = ath9k_hw_common(ah);
284 int16_t nf, nfThresh; 297 int16_t nf, nfThresh;
285 int16_t nfarray[NUM_NF_READINGS] = { 0 }; 298 int16_t nfarray[NUM_NF_READINGS] = { 0 };
286 struct ath9k_nfcal_hist *h; 299 struct ath9k_nfcal_hist *h;
287 struct ieee80211_channel *c = chan->chan; 300 struct ieee80211_channel *c = chan->chan;
301 struct ath9k_hw_cal_data *caldata = ah->caldata;
302
303 if (!caldata)
304 return false;
288 305
289 chan->channelFlags &= (~CHANNEL_CW_INT); 306 chan->channelFlags &= (~CHANNEL_CW_INT);
290 if (REG_READ(ah, AR_PHY_AGC_CONTROL) & AR_PHY_AGC_CONTROL_NF) { 307 if (REG_READ(ah, AR_PHY_AGC_CONTROL) & AR_PHY_AGC_CONTROL_NF) {
291 ath_print(common, ATH_DBG_CALIBRATE, 308 ath_print(common, ATH_DBG_CALIBRATE,
292 "NF did not complete in calibration window\n"); 309 "NF did not complete in calibration window\n");
293 nf = 0; 310 nf = 0;
294 chan->rawNoiseFloor = nf; 311 caldata->rawNoiseFloor = nf;
295 return chan->rawNoiseFloor; 312 return false;
296 } else { 313 } else {
297 ath9k_hw_do_getnf(ah, nfarray); 314 ath9k_hw_do_getnf(ah, nfarray);
298 ath9k_hw_nf_sanitize(ah, nfarray); 315 ath9k_hw_nf_sanitize(ah, nfarray);
@@ -307,47 +324,40 @@ int16_t ath9k_hw_getnf(struct ath_hw *ah,
307 } 324 }
308 } 325 }
309 326
310 h = ah->nfCalHist; 327 h = caldata->nfCalHist;
311 328 caldata->nfcal_pending = false;
312 ath9k_hw_update_nfcal_hist_buffer(h, nfarray); 329 ath9k_hw_update_nfcal_hist_buffer(h, nfarray);
313 chan->rawNoiseFloor = h[0].privNF; 330 caldata->rawNoiseFloor = h[0].privNF;
314 331 return true;
315 return chan->rawNoiseFloor;
316} 332}
317 333
318void ath9k_init_nfcal_hist_buffer(struct ath_hw *ah) 334void ath9k_init_nfcal_hist_buffer(struct ath_hw *ah,
335 struct ath9k_channel *chan)
319{ 336{
320 struct ath_nf_limits *limit; 337 struct ath9k_nfcal_hist *h;
338 s16 default_nf;
321 int i, j; 339 int i, j;
322 340
323 if (!ah->curchan || IS_CHAN_2GHZ(ah->curchan)) 341 if (!ah->caldata)
324 limit = &ah->nf_2g; 342 return;
325 else
326 limit = &ah->nf_5g;
327 343
344 h = ah->caldata->nfCalHist;
345 default_nf = ath9k_hw_get_default_nf(ah, chan);
328 for (i = 0; i < NUM_NF_READINGS; i++) { 346 for (i = 0; i < NUM_NF_READINGS; i++) {
329 ah->nfCalHist[i].currIndex = 0; 347 h[i].currIndex = 0;
330 ah->nfCalHist[i].privNF = limit->nominal; 348 h[i].privNF = default_nf;
331 ah->nfCalHist[i].invalidNFcount = 349 h[i].invalidNFcount = AR_PHY_CCA_FILTERWINDOW_LENGTH;
332 AR_PHY_CCA_FILTERWINDOW_LENGTH;
333 for (j = 0; j < ATH9K_NF_CAL_HIST_MAX; j++) { 350 for (j = 0; j < ATH9K_NF_CAL_HIST_MAX; j++) {
334 ah->nfCalHist[i].nfCalBuffer[j] = limit->nominal; 351 h[i].nfCalBuffer[j] = default_nf;
335 } 352 }
336 } 353 }
337} 354}
338 355
339s16 ath9k_hw_getchan_noise(struct ath_hw *ah, struct ath9k_channel *chan) 356s16 ath9k_hw_getchan_noise(struct ath_hw *ah, struct ath9k_channel *chan)
340{ 357{
341 s16 nf; 358 if (!ah->caldata || !ah->caldata->rawNoiseFloor)
342 359 return ath9k_hw_get_default_nf(ah, chan);
343 if (chan->rawNoiseFloor == 0)
344 nf = -96;
345 else
346 nf = chan->rawNoiseFloor;
347
348 if (!ath9k_hw_nf_in_range(ah, nf))
349 nf = ATH_DEFAULT_NOISE_FLOOR;
350 360
351 return nf; 361 return ah->caldata->rawNoiseFloor;
352} 362}
353EXPORT_SYMBOL(ath9k_hw_getchan_noise); 363EXPORT_SYMBOL(ath9k_hw_getchan_noise);
diff --git a/drivers/net/wireless/ath/ath9k/calib.h b/drivers/net/wireless/ath/ath9k/calib.h
index cd60d09cdda7..0a304b3eeeb6 100644
--- a/drivers/net/wireless/ath/ath9k/calib.h
+++ b/drivers/net/wireless/ath/ath9k/calib.h
@@ -108,11 +108,11 @@ struct ath9k_pacal_info{
108}; 108};
109 109
110bool ath9k_hw_reset_calvalid(struct ath_hw *ah); 110bool ath9k_hw_reset_calvalid(struct ath_hw *ah);
111void ath9k_hw_start_nfcal(struct ath_hw *ah); 111void ath9k_hw_start_nfcal(struct ath_hw *ah, bool update);
112void ath9k_hw_loadnf(struct ath_hw *ah, struct ath9k_channel *chan); 112void ath9k_hw_loadnf(struct ath_hw *ah, struct ath9k_channel *chan);
113int16_t ath9k_hw_getnf(struct ath_hw *ah, 113bool ath9k_hw_getnf(struct ath_hw *ah, struct ath9k_channel *chan);
114 struct ath9k_channel *chan); 114void ath9k_init_nfcal_hist_buffer(struct ath_hw *ah,
115void ath9k_init_nfcal_hist_buffer(struct ath_hw *ah); 115 struct ath9k_channel *chan);
116s16 ath9k_hw_getchan_noise(struct ath_hw *ah, struct ath9k_channel *chan); 116s16 ath9k_hw_getchan_noise(struct ath_hw *ah, struct ath9k_channel *chan);
117void ath9k_hw_reset_calibration(struct ath_hw *ah, 117void ath9k_hw_reset_calibration(struct ath_hw *ah,
118 struct ath9k_cal_list *currCal); 118 struct ath9k_cal_list *currCal);
diff --git a/drivers/net/wireless/ath/ath9k/htc.h b/drivers/net/wireless/ath/ath9k/htc.h
index 3756400e6bf9..43b9e21bc562 100644
--- a/drivers/net/wireless/ath/ath9k/htc.h
+++ b/drivers/net/wireless/ath/ath9k/htc.h
@@ -353,6 +353,8 @@ struct ath9k_htc_priv {
353 u16 seq_no; 353 u16 seq_no;
354 u32 bmiss_cnt; 354 u32 bmiss_cnt;
355 355
356 struct ath9k_hw_cal_data caldata[38];
357
356 spinlock_t beacon_lock; 358 spinlock_t beacon_lock;
357 359
358 bool tx_queues_stop; 360 bool tx_queues_stop;
diff --git a/drivers/net/wireless/ath/ath9k/htc_drv_main.c b/drivers/net/wireless/ath/ath9k/htc_drv_main.c
index cf9bcc67ade2..ebed9d1691a5 100644
--- a/drivers/net/wireless/ath/ath9k/htc_drv_main.c
+++ b/drivers/net/wireless/ath/ath9k/htc_drv_main.c
@@ -125,6 +125,7 @@ static int ath9k_htc_set_channel(struct ath9k_htc_priv *priv,
125 struct ieee80211_conf *conf = &common->hw->conf; 125 struct ieee80211_conf *conf = &common->hw->conf;
126 bool fastcc = true; 126 bool fastcc = true;
127 struct ieee80211_channel *channel = hw->conf.channel; 127 struct ieee80211_channel *channel = hw->conf.channel;
128 struct ath9k_hw_cal_data *caldata;
128 enum htc_phymode mode; 129 enum htc_phymode mode;
129 __be16 htc_mode; 130 __be16 htc_mode;
130 u8 cmd_rsp; 131 u8 cmd_rsp;
@@ -149,7 +150,8 @@ static int ath9k_htc_set_channel(struct ath9k_htc_priv *priv,
149 priv->ah->curchan->channel, 150 priv->ah->curchan->channel,
150 channel->center_freq, conf_is_ht(conf), conf_is_ht40(conf)); 151 channel->center_freq, conf_is_ht(conf), conf_is_ht40(conf));
151 152
152 ret = ath9k_hw_reset(ah, hchan, fastcc); 153 caldata = &priv->caldata[channel->hw_value];
154 ret = ath9k_hw_reset(ah, hchan, caldata, fastcc);
153 if (ret) { 155 if (ret) {
154 ath_print(common, ATH_DBG_FATAL, 156 ath_print(common, ATH_DBG_FATAL,
155 "Unable to reset channel (%u Mhz) " 157 "Unable to reset channel (%u Mhz) "
@@ -1028,7 +1030,7 @@ static void ath9k_htc_radio_enable(struct ieee80211_hw *hw)
1028 ah->curchan = ath9k_cmn_get_curchannel(hw, ah); 1030 ah->curchan = ath9k_cmn_get_curchannel(hw, ah);
1029 1031
1030 /* Reset the HW */ 1032 /* Reset the HW */
1031 ret = ath9k_hw_reset(ah, ah->curchan, false); 1033 ret = ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
1032 if (ret) { 1034 if (ret) {
1033 ath_print(common, ATH_DBG_FATAL, 1035 ath_print(common, ATH_DBG_FATAL,
1034 "Unable to reset hardware; reset status %d " 1036 "Unable to reset hardware; reset status %d "
@@ -1091,7 +1093,7 @@ static void ath9k_htc_radio_disable(struct ieee80211_hw *hw)
1091 ah->curchan = ath9k_cmn_get_curchannel(hw, ah); 1093 ah->curchan = ath9k_cmn_get_curchannel(hw, ah);
1092 1094
1093 /* Reset the HW */ 1095 /* Reset the HW */
1094 ret = ath9k_hw_reset(ah, ah->curchan, false); 1096 ret = ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
1095 if (ret) { 1097 if (ret) {
1096 ath_print(common, ATH_DBG_FATAL, 1098 ath_print(common, ATH_DBG_FATAL,
1097 "Unable to reset hardware; reset status %d " 1099 "Unable to reset hardware; reset status %d "
@@ -1179,7 +1181,7 @@ static int ath9k_htc_start(struct ieee80211_hw *hw)
1179 ath9k_hw_configpcipowersave(ah, 0, 0); 1181 ath9k_hw_configpcipowersave(ah, 0, 0);
1180 1182
1181 ath9k_hw_htc_resetinit(ah); 1183 ath9k_hw_htc_resetinit(ah);
1182 ret = ath9k_hw_reset(ah, init_channel, false); 1184 ret = ath9k_hw_reset(ah, init_channel, ah->caldata, false);
1183 if (ret) { 1185 if (ret) {
1184 ath_print(common, ATH_DBG_FATAL, 1186 ath_print(common, ATH_DBG_FATAL,
1185 "Unable to reset hardware; reset status %d " 1187 "Unable to reset hardware; reset status %d "
diff --git a/drivers/net/wireless/ath/ath9k/hw.c b/drivers/net/wireless/ath/ath9k/hw.c
index 8d291ccf5c88..3384ca164562 100644
--- a/drivers/net/wireless/ath/ath9k/hw.c
+++ b/drivers/net/wireless/ath/ath9k/hw.c
@@ -610,7 +610,6 @@ static int __ath9k_hw_init(struct ath_hw *ah)
610 else 610 else
611 ah->tx_trig_level = (AR_FTRIG_512B >> AR_FTRIG_S); 611 ah->tx_trig_level = (AR_FTRIG_512B >> AR_FTRIG_S);
612 612
613 ath9k_init_nfcal_hist_buffer(ah);
614 ah->bb_watchdog_timeout_ms = 25; 613 ah->bb_watchdog_timeout_ms = 25;
615 614
616 common->state = ATH_HW_INITIALIZED; 615 common->state = ATH_HW_INITIALIZED;
@@ -1183,9 +1182,6 @@ static bool ath9k_hw_channel_change(struct ath_hw *ah,
1183 1182
1184 ath9k_hw_spur_mitigate_freq(ah, chan); 1183 ath9k_hw_spur_mitigate_freq(ah, chan);
1185 1184
1186 if (!chan->oneTimeCalsDone)
1187 chan->oneTimeCalsDone = true;
1188
1189 return true; 1185 return true;
1190} 1186}
1191 1187
@@ -1218,7 +1214,7 @@ bool ath9k_hw_check_alive(struct ath_hw *ah)
1218EXPORT_SYMBOL(ath9k_hw_check_alive); 1214EXPORT_SYMBOL(ath9k_hw_check_alive);
1219 1215
1220int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan, 1216int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
1221 bool bChannelChange) 1217 struct ath9k_hw_cal_data *caldata, bool bChannelChange)
1222{ 1218{
1223 struct ath_common *common = ath9k_hw_common(ah); 1219 struct ath_common *common = ath9k_hw_common(ah);
1224 u32 saveLedState; 1220 u32 saveLedState;
@@ -1243,9 +1239,19 @@ int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
1243 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) 1239 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
1244 return -EIO; 1240 return -EIO;
1245 1241
1246 if (curchan && !ah->chip_fullsleep) 1242 if (curchan && !ah->chip_fullsleep && ah->caldata)
1247 ath9k_hw_getnf(ah, curchan); 1243 ath9k_hw_getnf(ah, curchan);
1248 1244
1245 ah->caldata = caldata;
1246 if (caldata &&
1247 (chan->channel != caldata->channel ||
1248 (chan->channelFlags & ~CHANNEL_CW_INT) !=
1249 (caldata->channelFlags & ~CHANNEL_CW_INT))) {
1250 /* Operating channel changed, reset channel calibration data */
1251 memset(caldata, 0, sizeof(*caldata));
1252 ath9k_init_nfcal_hist_buffer(ah, chan);
1253 }
1254
1249 if (bChannelChange && 1255 if (bChannelChange &&
1250 (ah->chip_fullsleep != true) && 1256 (ah->chip_fullsleep != true) &&
1251 (ah->curchan != NULL) && 1257 (ah->curchan != NULL) &&
@@ -1256,7 +1262,7 @@ int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
1256 1262
1257 if (ath9k_hw_channel_change(ah, chan)) { 1263 if (ath9k_hw_channel_change(ah, chan)) {
1258 ath9k_hw_loadnf(ah, ah->curchan); 1264 ath9k_hw_loadnf(ah, ah->curchan);
1259 ath9k_hw_start_nfcal(ah); 1265 ath9k_hw_start_nfcal(ah, true);
1260 return 0; 1266 return 0;
1261 } 1267 }
1262 } 1268 }
@@ -1461,11 +1467,8 @@ int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
1461 if (ah->btcoex_hw.enabled) 1467 if (ah->btcoex_hw.enabled)
1462 ath9k_hw_btcoex_enable(ah); 1468 ath9k_hw_btcoex_enable(ah);
1463 1469
1464 if (AR_SREV_9300_20_OR_LATER(ah)) { 1470 if (AR_SREV_9300_20_OR_LATER(ah))
1465 ath9k_hw_loadnf(ah, curchan);
1466 ath9k_hw_start_nfcal(ah);
1467 ar9003_hw_bb_watchdog_config(ah); 1471 ar9003_hw_bb_watchdog_config(ah);
1468 }
1469 1472
1470 return 0; 1473 return 0;
1471} 1474}
diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
index 2d30efc0b94f..399f7c1283cd 100644
--- a/drivers/net/wireless/ath/ath9k/hw.h
+++ b/drivers/net/wireless/ath/ath9k/hw.h
@@ -346,19 +346,25 @@ enum ath9k_int {
346 CHANNEL_HT40PLUS | \ 346 CHANNEL_HT40PLUS | \
347 CHANNEL_HT40MINUS) 347 CHANNEL_HT40MINUS)
348 348
349struct ath9k_channel { 349struct ath9k_hw_cal_data {
350 struct ieee80211_channel *chan;
351 u16 channel; 350 u16 channel;
352 u32 channelFlags; 351 u32 channelFlags;
353 u32 chanmode;
354 int32_t CalValid; 352 int32_t CalValid;
355 bool oneTimeCalsDone;
356 int8_t iCoff; 353 int8_t iCoff;
357 int8_t qCoff; 354 int8_t qCoff;
358 int16_t rawNoiseFloor; 355 int16_t rawNoiseFloor;
359 bool paprd_done; 356 bool paprd_done;
357 bool nfcal_pending;
360 u16 small_signal_gain[AR9300_MAX_CHAINS]; 358 u16 small_signal_gain[AR9300_MAX_CHAINS];
361 u32 pa_table[AR9300_MAX_CHAINS][PAPRD_TABLE_SZ]; 359 u32 pa_table[AR9300_MAX_CHAINS][PAPRD_TABLE_SZ];
360 struct ath9k_nfcal_hist nfCalHist[NUM_NF_READINGS];
361};
362
363struct ath9k_channel {
364 struct ieee80211_channel *chan;
365 u16 channel;
366 u32 channelFlags;
367 u32 chanmode;
362}; 368};
363 369
364#define IS_CHAN_G(_c) ((((_c)->channelFlags & (CHANNEL_G)) == CHANNEL_G) || \ 370#define IS_CHAN_G(_c) ((((_c)->channelFlags & (CHANNEL_G)) == CHANNEL_G) || \
@@ -669,7 +675,7 @@ struct ath_hw {
669 enum nl80211_iftype opmode; 675 enum nl80211_iftype opmode;
670 enum ath9k_power_mode power_mode; 676 enum ath9k_power_mode power_mode;
671 677
672 struct ath9k_nfcal_hist nfCalHist[NUM_NF_READINGS]; 678 struct ath9k_hw_cal_data *caldata;
673 struct ath9k_pacal_info pacal_info; 679 struct ath9k_pacal_info pacal_info;
674 struct ar5416Stats stats; 680 struct ar5416Stats stats;
675 struct ath9k_tx_queue_info txq[ATH9K_NUM_TX_QUEUES]; 681 struct ath9k_tx_queue_info txq[ATH9K_NUM_TX_QUEUES];
@@ -863,7 +869,7 @@ const char *ath9k_hw_probe(u16 vendorid, u16 devid);
863void ath9k_hw_deinit(struct ath_hw *ah); 869void ath9k_hw_deinit(struct ath_hw *ah);
864int ath9k_hw_init(struct ath_hw *ah); 870int ath9k_hw_init(struct ath_hw *ah);
865int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan, 871int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
866 bool bChannelChange); 872 struct ath9k_hw_cal_data *caldata, bool bChannelChange);
867int ath9k_hw_fill_cap_info(struct ath_hw *ah); 873int ath9k_hw_fill_cap_info(struct ath_hw *ah);
868u32 ath9k_regd_get_ctl(struct ath_regulatory *reg, struct ath9k_channel *chan); 874u32 ath9k_regd_get_ctl(struct ath_regulatory *reg, struct ath9k_channel *chan);
869 875
@@ -958,9 +964,10 @@ void ar9003_hw_bb_watchdog_read(struct ath_hw *ah);
958void ar9003_hw_bb_watchdog_dbg_info(struct ath_hw *ah); 964void ar9003_hw_bb_watchdog_dbg_info(struct ath_hw *ah);
959void ar9003_paprd_enable(struct ath_hw *ah, bool val); 965void ar9003_paprd_enable(struct ath_hw *ah, bool val);
960void ar9003_paprd_populate_single_table(struct ath_hw *ah, 966void ar9003_paprd_populate_single_table(struct ath_hw *ah,
961 struct ath9k_channel *chan, int chain); 967 struct ath9k_hw_cal_data *caldata,
962int ar9003_paprd_create_curve(struct ath_hw *ah, struct ath9k_channel *chan, 968 int chain);
963 int chain); 969int ar9003_paprd_create_curve(struct ath_hw *ah,
970 struct ath9k_hw_cal_data *caldata, int chain);
964int ar9003_paprd_setup_gain_table(struct ath_hw *ah, int chain); 971int ar9003_paprd_setup_gain_table(struct ath_hw *ah, int chain);
965int ar9003_paprd_init_table(struct ath_hw *ah); 972int ar9003_paprd_init_table(struct ath_hw *ah);
966bool ar9003_paprd_is_done(struct ath_hw *ah); 973bool ar9003_paprd_is_done(struct ath_hw *ah);
diff --git a/drivers/net/wireless/ath/ath9k/main.c b/drivers/net/wireless/ath/ath9k/main.c
index 0429dda0961f..3caa32316e7b 100644
--- a/drivers/net/wireless/ath/ath9k/main.c
+++ b/drivers/net/wireless/ath/ath9k/main.c
@@ -154,6 +154,27 @@ void ath9k_ps_restore(struct ath_softc *sc)
154 spin_unlock_irqrestore(&sc->sc_pm_lock, flags); 154 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
155} 155}
156 156
157static void ath_start_ani(struct ath_common *common)
158{
159 struct ath_hw *ah = common->ah;
160 unsigned long timestamp = jiffies_to_msecs(jiffies);
161 struct ath_softc *sc = (struct ath_softc *) common->priv;
162
163 if (!(sc->sc_flags & SC_OP_ANI_RUN))
164 return;
165
166 if (sc->sc_flags & SC_OP_OFFCHANNEL)
167 return;
168
169 common->ani.longcal_timer = timestamp;
170 common->ani.shortcal_timer = timestamp;
171 common->ani.checkani_timer = timestamp;
172
173 mod_timer(&common->ani.timer,
174 jiffies +
175 msecs_to_jiffies((u32)ah->config.ani_poll_interval));
176}
177
157/* 178/*
158 * Set/change channels. If the channel is really being changed, it's done 179 * Set/change channels. If the channel is really being changed, it's done
159 * by reseting the chip. To accomplish this we must first cleanup any pending 180 * by reseting the chip. To accomplish this we must first cleanup any pending
@@ -162,16 +183,23 @@ void ath9k_ps_restore(struct ath_softc *sc)
162int ath_set_channel(struct ath_softc *sc, struct ieee80211_hw *hw, 183int ath_set_channel(struct ath_softc *sc, struct ieee80211_hw *hw,
163 struct ath9k_channel *hchan) 184 struct ath9k_channel *hchan)
164{ 185{
186 struct ath_wiphy *aphy = hw->priv;
165 struct ath_hw *ah = sc->sc_ah; 187 struct ath_hw *ah = sc->sc_ah;
166 struct ath_common *common = ath9k_hw_common(ah); 188 struct ath_common *common = ath9k_hw_common(ah);
167 struct ieee80211_conf *conf = &common->hw->conf; 189 struct ieee80211_conf *conf = &common->hw->conf;
168 bool fastcc = true, stopped; 190 bool fastcc = true, stopped;
169 struct ieee80211_channel *channel = hw->conf.channel; 191 struct ieee80211_channel *channel = hw->conf.channel;
192 struct ath9k_hw_cal_data *caldata = NULL;
170 int r; 193 int r;
171 194
172 if (sc->sc_flags & SC_OP_INVALID) 195 if (sc->sc_flags & SC_OP_INVALID)
173 return -EIO; 196 return -EIO;
174 197
198 del_timer_sync(&common->ani.timer);
199 cancel_work_sync(&sc->paprd_work);
200 cancel_work_sync(&sc->hw_check_work);
201 cancel_delayed_work_sync(&sc->tx_complete_work);
202
175 ath9k_ps_wakeup(sc); 203 ath9k_ps_wakeup(sc);
176 204
177 /* 205 /*
@@ -191,9 +219,12 @@ int ath_set_channel(struct ath_softc *sc, struct ieee80211_hw *hw,
191 * to flush data frames already in queue because of 219 * to flush data frames already in queue because of
192 * changing channel. */ 220 * changing channel. */
193 221
194 if (!stopped || (sc->sc_flags & SC_OP_FULL_RESET)) 222 if (!stopped || !(sc->sc_flags & SC_OP_OFFCHANNEL))
195 fastcc = false; 223 fastcc = false;
196 224
225 if (!(sc->sc_flags & SC_OP_OFFCHANNEL))
226 caldata = &aphy->caldata;
227
197 ath_print(common, ATH_DBG_CONFIG, 228 ath_print(common, ATH_DBG_CONFIG,
198 "(%u MHz) -> (%u MHz), conf_is_ht40: %d\n", 229 "(%u MHz) -> (%u MHz), conf_is_ht40: %d\n",
199 sc->sc_ah->curchan->channel, 230 sc->sc_ah->curchan->channel,
@@ -201,7 +232,7 @@ int ath_set_channel(struct ath_softc *sc, struct ieee80211_hw *hw,
201 232
202 spin_lock_bh(&sc->sc_resetlock); 233 spin_lock_bh(&sc->sc_resetlock);
203 234
204 r = ath9k_hw_reset(ah, hchan, fastcc); 235 r = ath9k_hw_reset(ah, hchan, caldata, fastcc);
205 if (r) { 236 if (r) {
206 ath_print(common, ATH_DBG_FATAL, 237 ath_print(common, ATH_DBG_FATAL,
207 "Unable to reset channel (%u MHz), " 238 "Unable to reset channel (%u MHz), "
@@ -212,8 +243,6 @@ int ath_set_channel(struct ath_softc *sc, struct ieee80211_hw *hw,
212 } 243 }
213 spin_unlock_bh(&sc->sc_resetlock); 244 spin_unlock_bh(&sc->sc_resetlock);
214 245
215 sc->sc_flags &= ~SC_OP_FULL_RESET;
216
217 if (ath_startrecv(sc) != 0) { 246 if (ath_startrecv(sc) != 0) {
218 ath_print(common, ATH_DBG_FATAL, 247 ath_print(common, ATH_DBG_FATAL,
219 "Unable to restart recv logic\n"); 248 "Unable to restart recv logic\n");
@@ -225,6 +254,12 @@ int ath_set_channel(struct ath_softc *sc, struct ieee80211_hw *hw,
225 ath_update_txpow(sc); 254 ath_update_txpow(sc);
226 ath9k_hw_set_interrupts(ah, ah->imask); 255 ath9k_hw_set_interrupts(ah, ah->imask);
227 256
257 if (!(sc->sc_flags & (SC_OP_OFFCHANNEL | SC_OP_SCANNING))) {
258 ath_start_ani(common);
259 ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0);
260 ath_beacon_config(sc, NULL);
261 }
262
228 ps_restore: 263 ps_restore:
229 ath9k_ps_restore(sc); 264 ath9k_ps_restore(sc);
230 return r; 265 return r;
@@ -233,17 +268,19 @@ int ath_set_channel(struct ath_softc *sc, struct ieee80211_hw *hw,
233static void ath_paprd_activate(struct ath_softc *sc) 268static void ath_paprd_activate(struct ath_softc *sc)
234{ 269{
235 struct ath_hw *ah = sc->sc_ah; 270 struct ath_hw *ah = sc->sc_ah;
271 struct ath9k_hw_cal_data *caldata = ah->caldata;
236 int chain; 272 int chain;
237 273
238 if (!ah->curchan->paprd_done) 274 if (!caldata || !caldata->paprd_done)
239 return; 275 return;
240 276
241 ath9k_ps_wakeup(sc); 277 ath9k_ps_wakeup(sc);
278 ar9003_paprd_enable(ah, false);
242 for (chain = 0; chain < AR9300_MAX_CHAINS; chain++) { 279 for (chain = 0; chain < AR9300_MAX_CHAINS; chain++) {
243 if (!(ah->caps.tx_chainmask & BIT(chain))) 280 if (!(ah->caps.tx_chainmask & BIT(chain)))
244 continue; 281 continue;
245 282
246 ar9003_paprd_populate_single_table(ah, ah->curchan, chain); 283 ar9003_paprd_populate_single_table(ah, caldata, chain);
247 } 284 }
248 285
249 ar9003_paprd_enable(ah, true); 286 ar9003_paprd_enable(ah, true);
@@ -261,6 +298,7 @@ void ath_paprd_calibrate(struct work_struct *work)
261 int band = hw->conf.channel->band; 298 int band = hw->conf.channel->band;
262 struct ieee80211_supported_band *sband = &sc->sbands[band]; 299 struct ieee80211_supported_band *sband = &sc->sbands[band];
263 struct ath_tx_control txctl; 300 struct ath_tx_control txctl;
301 struct ath9k_hw_cal_data *caldata = ah->caldata;
264 int qnum, ftype; 302 int qnum, ftype;
265 int chain_ok = 0; 303 int chain_ok = 0;
266 int chain; 304 int chain;
@@ -268,6 +306,9 @@ void ath_paprd_calibrate(struct work_struct *work)
268 int time_left; 306 int time_left;
269 int i; 307 int i;
270 308
309 if (!caldata)
310 return;
311
271 skb = alloc_skb(len, GFP_KERNEL); 312 skb = alloc_skb(len, GFP_KERNEL);
272 if (!skb) 313 if (!skb)
273 return; 314 return;
@@ -322,7 +363,7 @@ void ath_paprd_calibrate(struct work_struct *work)
322 if (!ar9003_paprd_is_done(ah)) 363 if (!ar9003_paprd_is_done(ah))
323 break; 364 break;
324 365
325 if (ar9003_paprd_create_curve(ah, ah->curchan, chain) != 0) 366 if (ar9003_paprd_create_curve(ah, caldata, chain) != 0)
326 break; 367 break;
327 368
328 chain_ok = 1; 369 chain_ok = 1;
@@ -330,7 +371,7 @@ void ath_paprd_calibrate(struct work_struct *work)
330 kfree_skb(skb); 371 kfree_skb(skb);
331 372
332 if (chain_ok) { 373 if (chain_ok) {
333 ah->curchan->paprd_done = true; 374 caldata->paprd_done = true;
334 ath_paprd_activate(sc); 375 ath_paprd_activate(sc);
335 } 376 }
336 377
@@ -439,33 +480,14 @@ set_timer:
439 cal_interval = min(cal_interval, (u32)short_cal_interval); 480 cal_interval = min(cal_interval, (u32)short_cal_interval);
440 481
441 mod_timer(&common->ani.timer, jiffies + msecs_to_jiffies(cal_interval)); 482 mod_timer(&common->ani.timer, jiffies + msecs_to_jiffies(cal_interval));
442 if ((sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_PAPRD) && 483 if ((sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_PAPRD) && ah->caldata) {
443 !(sc->sc_flags & SC_OP_SCANNING)) { 484 if (!ah->caldata->paprd_done)
444 if (!sc->sc_ah->curchan->paprd_done)
445 ieee80211_queue_work(sc->hw, &sc->paprd_work); 485 ieee80211_queue_work(sc->hw, &sc->paprd_work);
446 else 486 else
447 ath_paprd_activate(sc); 487 ath_paprd_activate(sc);
448 } 488 }
449} 489}
450 490
451static void ath_start_ani(struct ath_common *common)
452{
453 struct ath_hw *ah = common->ah;
454 unsigned long timestamp = jiffies_to_msecs(jiffies);
455 struct ath_softc *sc = (struct ath_softc *) common->priv;
456
457 if (!(sc->sc_flags & SC_OP_ANI_RUN))
458 return;
459
460 common->ani.longcal_timer = timestamp;
461 common->ani.shortcal_timer = timestamp;
462 common->ani.checkani_timer = timestamp;
463
464 mod_timer(&common->ani.timer,
465 jiffies +
466 msecs_to_jiffies((u32)ah->config.ani_poll_interval));
467}
468
469/* 491/*
470 * Update tx/rx chainmask. For legacy association, 492 * Update tx/rx chainmask. For legacy association,
471 * hard code chainmask to 1x1, for 11n association, use 493 * hard code chainmask to 1x1, for 11n association, use
@@ -477,7 +499,7 @@ void ath_update_chainmask(struct ath_softc *sc, int is_ht)
477 struct ath_hw *ah = sc->sc_ah; 499 struct ath_hw *ah = sc->sc_ah;
478 struct ath_common *common = ath9k_hw_common(ah); 500 struct ath_common *common = ath9k_hw_common(ah);
479 501
480 if ((sc->sc_flags & SC_OP_SCANNING) || is_ht || 502 if ((sc->sc_flags & SC_OP_OFFCHANNEL) || is_ht ||
481 (ah->btcoex_hw.scheme != ATH_BTCOEX_CFG_NONE)) { 503 (ah->btcoex_hw.scheme != ATH_BTCOEX_CFG_NONE)) {
482 common->tx_chainmask = ah->caps.tx_chainmask; 504 common->tx_chainmask = ah->caps.tx_chainmask;
483 common->rx_chainmask = ah->caps.rx_chainmask; 505 common->rx_chainmask = ah->caps.rx_chainmask;
@@ -817,7 +839,7 @@ void ath_radio_enable(struct ath_softc *sc, struct ieee80211_hw *hw)
817 ah->curchan = ath_get_curchannel(sc, sc->hw); 839 ah->curchan = ath_get_curchannel(sc, sc->hw);
818 840
819 spin_lock_bh(&sc->sc_resetlock); 841 spin_lock_bh(&sc->sc_resetlock);
820 r = ath9k_hw_reset(ah, ah->curchan, false); 842 r = ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
821 if (r) { 843 if (r) {
822 ath_print(common, ATH_DBG_FATAL, 844 ath_print(common, ATH_DBG_FATAL,
823 "Unable to reset channel (%u MHz), " 845 "Unable to reset channel (%u MHz), "
@@ -877,7 +899,7 @@ void ath_radio_disable(struct ath_softc *sc, struct ieee80211_hw *hw)
877 ah->curchan = ath_get_curchannel(sc, hw); 899 ah->curchan = ath_get_curchannel(sc, hw);
878 900
879 spin_lock_bh(&sc->sc_resetlock); 901 spin_lock_bh(&sc->sc_resetlock);
880 r = ath9k_hw_reset(ah, ah->curchan, false); 902 r = ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
881 if (r) { 903 if (r) {
882 ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_FATAL, 904 ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_FATAL,
883 "Unable to reset channel (%u MHz), " 905 "Unable to reset channel (%u MHz), "
@@ -910,7 +932,7 @@ int ath_reset(struct ath_softc *sc, bool retry_tx)
910 ath_flushrecv(sc); 932 ath_flushrecv(sc);
911 933
912 spin_lock_bh(&sc->sc_resetlock); 934 spin_lock_bh(&sc->sc_resetlock);
913 r = ath9k_hw_reset(ah, sc->sc_ah->curchan, false); 935 r = ath9k_hw_reset(ah, sc->sc_ah->curchan, ah->caldata, false);
914 if (r) 936 if (r)
915 ath_print(common, ATH_DBG_FATAL, 937 ath_print(common, ATH_DBG_FATAL,
916 "Unable to reset hardware; reset status %d\n", r); 938 "Unable to reset hardware; reset status %d\n", r);
@@ -1085,7 +1107,7 @@ static int ath9k_start(struct ieee80211_hw *hw)
1085 * and then setup of the interrupt mask. 1107 * and then setup of the interrupt mask.
1086 */ 1108 */
1087 spin_lock_bh(&sc->sc_resetlock); 1109 spin_lock_bh(&sc->sc_resetlock);
1088 r = ath9k_hw_reset(ah, init_channel, false); 1110 r = ath9k_hw_reset(ah, init_channel, ah->caldata, false);
1089 if (r) { 1111 if (r) {
1090 ath_print(common, ATH_DBG_FATAL, 1112 ath_print(common, ATH_DBG_FATAL,
1091 "Unable to reset hardware; reset status %d " 1113 "Unable to reset hardware; reset status %d "
@@ -1579,6 +1601,10 @@ static int ath9k_config(struct ieee80211_hw *hw, u32 changed)
1579 1601
1580 aphy->chan_idx = pos; 1602 aphy->chan_idx = pos;
1581 aphy->chan_is_ht = conf_is_ht(conf); 1603 aphy->chan_is_ht = conf_is_ht(conf);
1604 if (hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)
1605 sc->sc_flags |= SC_OP_OFFCHANNEL;
1606 else
1607 sc->sc_flags &= ~SC_OP_OFFCHANNEL;
1582 1608
1583 if (aphy->state == ATH_WIPHY_SCAN || 1609 if (aphy->state == ATH_WIPHY_SCAN ||
1584 aphy->state == ATH_WIPHY_ACTIVE) 1610 aphy->state == ATH_WIPHY_ACTIVE)
@@ -1990,7 +2016,6 @@ static void ath9k_sw_scan_start(struct ieee80211_hw *hw)
1990{ 2016{
1991 struct ath_wiphy *aphy = hw->priv; 2017 struct ath_wiphy *aphy = hw->priv;
1992 struct ath_softc *sc = aphy->sc; 2018 struct ath_softc *sc = aphy->sc;
1993 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1994 2019
1995 mutex_lock(&sc->mutex); 2020 mutex_lock(&sc->mutex);
1996 if (ath9k_wiphy_scanning(sc)) { 2021 if (ath9k_wiphy_scanning(sc)) {
@@ -2008,10 +2033,6 @@ static void ath9k_sw_scan_start(struct ieee80211_hw *hw)
2008 aphy->state = ATH_WIPHY_SCAN; 2033 aphy->state = ATH_WIPHY_SCAN;
2009 ath9k_wiphy_pause_all_forced(sc, aphy); 2034 ath9k_wiphy_pause_all_forced(sc, aphy);
2010 sc->sc_flags |= SC_OP_SCANNING; 2035 sc->sc_flags |= SC_OP_SCANNING;
2011 del_timer_sync(&common->ani.timer);
2012 cancel_work_sync(&sc->paprd_work);
2013 cancel_work_sync(&sc->hw_check_work);
2014 cancel_delayed_work_sync(&sc->tx_complete_work);
2015 mutex_unlock(&sc->mutex); 2036 mutex_unlock(&sc->mutex);
2016} 2037}
2017 2038
@@ -2023,15 +2044,10 @@ static void ath9k_sw_scan_complete(struct ieee80211_hw *hw)
2023{ 2044{
2024 struct ath_wiphy *aphy = hw->priv; 2045 struct ath_wiphy *aphy = hw->priv;
2025 struct ath_softc *sc = aphy->sc; 2046 struct ath_softc *sc = aphy->sc;
2026 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
2027 2047
2028 mutex_lock(&sc->mutex); 2048 mutex_lock(&sc->mutex);
2029 aphy->state = ATH_WIPHY_ACTIVE; 2049 aphy->state = ATH_WIPHY_ACTIVE;
2030 sc->sc_flags &= ~SC_OP_SCANNING; 2050 sc->sc_flags &= ~SC_OP_SCANNING;
2031 sc->sc_flags |= SC_OP_FULL_RESET;
2032 ath_start_ani(common);
2033 ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0);
2034 ath_beacon_config(sc, NULL);
2035 mutex_unlock(&sc->mutex); 2051 mutex_unlock(&sc->mutex);
2036} 2052}
2037 2053
diff --git a/drivers/net/wireless/ath/ath9k/recv.c b/drivers/net/wireless/ath/ath9k/recv.c
index da0cfe90c38a..a3fc987ebab0 100644
--- a/drivers/net/wireless/ath/ath9k/recv.c
+++ b/drivers/net/wireless/ath/ath9k/recv.c
@@ -1140,6 +1140,11 @@ int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp)
1140 if (flush) 1140 if (flush)
1141 goto requeue; 1141 goto requeue;
1142 1142
1143 retval = ath9k_rx_skb_preprocess(common, hw, hdr, &rs,
1144 rxs, &decrypt_error);
1145 if (retval)
1146 goto requeue;
1147
1143 rxs->mactime = (tsf & ~0xffffffffULL) | rs.rs_tstamp; 1148 rxs->mactime = (tsf & ~0xffffffffULL) | rs.rs_tstamp;
1144 if (rs.rs_tstamp > tsf_lower && 1149 if (rs.rs_tstamp > tsf_lower &&
1145 unlikely(rs.rs_tstamp - tsf_lower > 0x10000000)) 1150 unlikely(rs.rs_tstamp - tsf_lower > 0x10000000))
@@ -1149,11 +1154,6 @@ int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp)
1149 unlikely(tsf_lower - rs.rs_tstamp > 0x10000000)) 1154 unlikely(tsf_lower - rs.rs_tstamp > 0x10000000))
1150 rxs->mactime += 0x100000000ULL; 1155 rxs->mactime += 0x100000000ULL;
1151 1156
1152 retval = ath9k_rx_skb_preprocess(common, hw, hdr, &rs,
1153 rxs, &decrypt_error);
1154 if (retval)
1155 goto requeue;
1156
1157 /* Ensure we always have an skb to requeue once we are done 1157 /* Ensure we always have an skb to requeue once we are done
1158 * processing the current buffer's skb */ 1158 * processing the current buffer's skb */
1159 requeue_skb = ath_rxbuf_alloc(common, common->rx_bufsize, GFP_ATOMIC); 1159 requeue_skb = ath_rxbuf_alloc(common, common->rx_bufsize, GFP_ATOMIC);
diff --git a/drivers/net/wireless/ath/ath9k/xmit.c b/drivers/net/wireless/ath/ath9k/xmit.c
index 501b72821b4d..4dda14e36227 100644
--- a/drivers/net/wireless/ath/ath9k/xmit.c
+++ b/drivers/net/wireless/ath/ath9k/xmit.c
@@ -120,26 +120,14 @@ static void ath_tx_queue_tid(struct ath_txq *txq, struct ath_atx_tid *tid)
120 list_add_tail(&ac->list, &txq->axq_acq); 120 list_add_tail(&ac->list, &txq->axq_acq);
121} 121}
122 122
123static void ath_tx_pause_tid(struct ath_softc *sc, struct ath_atx_tid *tid)
124{
125 struct ath_txq *txq = &sc->tx.txq[tid->ac->qnum];
126
127 spin_lock_bh(&txq->axq_lock);
128 tid->paused++;
129 spin_unlock_bh(&txq->axq_lock);
130}
131
132static void ath_tx_resume_tid(struct ath_softc *sc, struct ath_atx_tid *tid) 123static void ath_tx_resume_tid(struct ath_softc *sc, struct ath_atx_tid *tid)
133{ 124{
134 struct ath_txq *txq = &sc->tx.txq[tid->ac->qnum]; 125 struct ath_txq *txq = &sc->tx.txq[tid->ac->qnum];
135 126
136 BUG_ON(tid->paused <= 0); 127 WARN_ON(!tid->paused);
137 spin_lock_bh(&txq->axq_lock);
138
139 tid->paused--;
140 128
141 if (tid->paused > 0) 129 spin_lock_bh(&txq->axq_lock);
142 goto unlock; 130 tid->paused = false;
143 131
144 if (list_empty(&tid->buf_q)) 132 if (list_empty(&tid->buf_q))
145 goto unlock; 133 goto unlock;
@@ -157,15 +145,10 @@ static void ath_tx_flush_tid(struct ath_softc *sc, struct ath_atx_tid *tid)
157 struct list_head bf_head; 145 struct list_head bf_head;
158 INIT_LIST_HEAD(&bf_head); 146 INIT_LIST_HEAD(&bf_head);
159 147
160 BUG_ON(tid->paused <= 0); 148 WARN_ON(!tid->paused);
161 spin_lock_bh(&txq->axq_lock);
162 149
163 tid->paused--; 150 spin_lock_bh(&txq->axq_lock);
164 151 tid->paused = false;
165 if (tid->paused > 0) {
166 spin_unlock_bh(&txq->axq_lock);
167 return;
168 }
169 152
170 while (!list_empty(&tid->buf_q)) { 153 while (!list_empty(&tid->buf_q)) {
171 bf = list_first_entry(&tid->buf_q, struct ath_buf, list); 154 bf = list_first_entry(&tid->buf_q, struct ath_buf, list);
@@ -811,7 +794,7 @@ void ath_tx_aggr_start(struct ath_softc *sc, struct ieee80211_sta *sta,
811 an = (struct ath_node *)sta->drv_priv; 794 an = (struct ath_node *)sta->drv_priv;
812 txtid = ATH_AN_2_TID(an, tid); 795 txtid = ATH_AN_2_TID(an, tid);
813 txtid->state |= AGGR_ADDBA_PROGRESS; 796 txtid->state |= AGGR_ADDBA_PROGRESS;
814 ath_tx_pause_tid(sc, txtid); 797 txtid->paused = true;
815 *ssn = txtid->seq_start; 798 *ssn = txtid->seq_start;
816} 799}
817 800
@@ -835,10 +818,9 @@ void ath_tx_aggr_stop(struct ath_softc *sc, struct ieee80211_sta *sta, u16 tid)
835 return; 818 return;
836 } 819 }
837 820
838 ath_tx_pause_tid(sc, txtid);
839
840 /* drop all software retried frames and mark this TID */ 821 /* drop all software retried frames and mark this TID */
841 spin_lock_bh(&txq->axq_lock); 822 spin_lock_bh(&txq->axq_lock);
823 txtid->paused = true;
842 while (!list_empty(&txtid->buf_q)) { 824 while (!list_empty(&txtid->buf_q)) {
843 bf = list_first_entry(&txtid->buf_q, struct ath_buf, list); 825 bf = list_first_entry(&txtid->buf_q, struct ath_buf, list);
844 if (!bf_isretried(bf)) { 826 if (!bf_isretried(bf)) {
@@ -1181,7 +1163,7 @@ void ath_drain_all_txq(struct ath_softc *sc, bool retry_tx)
1181 "Failed to stop TX DMA. Resetting hardware!\n"); 1163 "Failed to stop TX DMA. Resetting hardware!\n");
1182 1164
1183 spin_lock_bh(&sc->sc_resetlock); 1165 spin_lock_bh(&sc->sc_resetlock);
1184 r = ath9k_hw_reset(ah, sc->sc_ah->curchan, false); 1166 r = ath9k_hw_reset(ah, sc->sc_ah->curchan, ah->caldata, false);
1185 if (r) 1167 if (r)
1186 ath_print(common, ATH_DBG_FATAL, 1168 ath_print(common, ATH_DBG_FATAL,
1187 "Unable to reset hardware; reset status %d\n", 1169 "Unable to reset hardware; reset status %d\n",
diff --git a/drivers/net/wireless/ipw2x00/ipw2100.c b/drivers/net/wireless/ipw2x00/ipw2100.c
index c24c5efeae1f..16bbfa3189a5 100644
--- a/drivers/net/wireless/ipw2x00/ipw2100.c
+++ b/drivers/net/wireless/ipw2x00/ipw2100.c
@@ -1924,6 +1924,10 @@ static int ipw2100_net_init(struct net_device *dev)
1924 bg_band->channels = 1924 bg_band->channels =
1925 kzalloc(geo->bg_channels * 1925 kzalloc(geo->bg_channels *
1926 sizeof(struct ieee80211_channel), GFP_KERNEL); 1926 sizeof(struct ieee80211_channel), GFP_KERNEL);
1927 if (!bg_band->channels) {
1928 ipw2100_down(priv);
1929 return -ENOMEM;
1930 }
1927 /* translate geo->bg to bg_band.channels */ 1931 /* translate geo->bg to bg_band.channels */
1928 for (i = 0; i < geo->bg_channels; i++) { 1932 for (i = 0; i < geo->bg_channels; i++) {
1929 bg_band->channels[i].band = IEEE80211_BAND_2GHZ; 1933 bg_band->channels[i].band = IEEE80211_BAND_2GHZ;
diff --git a/drivers/net/wireless/iwlwifi/iwl-1000.c b/drivers/net/wireless/iwlwifi/iwl-1000.c
index 8848333bc3a9..fec026212326 100644
--- a/drivers/net/wireless/iwlwifi/iwl-1000.c
+++ b/drivers/net/wireless/iwlwifi/iwl-1000.c
@@ -260,7 +260,7 @@ struct iwl_cfg iwl1000_bgn_cfg = {
260 .shadow_ram_support = false, 260 .shadow_ram_support = false,
261 .ht_greenfield_support = true, 261 .ht_greenfield_support = true,
262 .led_compensation = 51, 262 .led_compensation = 51,
263 .use_rts_for_ht = true, /* use rts/cts protection */ 263 .use_rts_for_aggregation = true, /* use rts/cts protection */
264 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, 264 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
265 .support_ct_kill_exit = true, 265 .support_ct_kill_exit = true,
266 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_EXT_LONG_THRESHOLD_DEF, 266 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_EXT_LONG_THRESHOLD_DEF,
diff --git a/drivers/net/wireless/iwlwifi/iwl-3945.c b/drivers/net/wireless/iwlwifi/iwl-3945.c
index a07310fefcf2..6950a783913b 100644
--- a/drivers/net/wireless/iwlwifi/iwl-3945.c
+++ b/drivers/net/wireless/iwlwifi/iwl-3945.c
@@ -769,22 +769,6 @@ void iwl3945_hw_build_tx_cmd_rate(struct iwl_priv *priv,
769 rts_retry_limit = data_retry_limit; 769 rts_retry_limit = data_retry_limit;
770 tx_cmd->rts_retry_limit = rts_retry_limit; 770 tx_cmd->rts_retry_limit = rts_retry_limit;
771 771
772 if (ieee80211_is_mgmt(fc)) {
773 switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
774 case cpu_to_le16(IEEE80211_STYPE_AUTH):
775 case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
776 case cpu_to_le16(IEEE80211_STYPE_ASSOC_REQ):
777 case cpu_to_le16(IEEE80211_STYPE_REASSOC_REQ):
778 if (tx_flags & TX_CMD_FLG_RTS_MSK) {
779 tx_flags &= ~TX_CMD_FLG_RTS_MSK;
780 tx_flags |= TX_CMD_FLG_CTS_MSK;
781 }
782 break;
783 default:
784 break;
785 }
786 }
787
788 tx_cmd->rate = rate; 772 tx_cmd->rate = rate;
789 tx_cmd->tx_flags = tx_flags; 773 tx_cmd->tx_flags = tx_flags;
790 774
@@ -2717,7 +2701,7 @@ static struct iwl_lib_ops iwl3945_lib = {
2717static struct iwl_hcmd_utils_ops iwl3945_hcmd_utils = { 2701static struct iwl_hcmd_utils_ops iwl3945_hcmd_utils = {
2718 .get_hcmd_size = iwl3945_get_hcmd_size, 2702 .get_hcmd_size = iwl3945_get_hcmd_size,
2719 .build_addsta_hcmd = iwl3945_build_addsta_hcmd, 2703 .build_addsta_hcmd = iwl3945_build_addsta_hcmd,
2720 .rts_tx_cmd_flag = iwlcore_rts_tx_cmd_flag, 2704 .tx_cmd_protection = iwlcore_tx_cmd_protection,
2721 .request_scan = iwl3945_request_scan, 2705 .request_scan = iwl3945_request_scan,
2722}; 2706};
2723 2707
diff --git a/drivers/net/wireless/iwlwifi/iwl-4965.c b/drivers/net/wireless/iwlwifi/iwl-4965.c
index d6531ad3906a..d6da356608fa 100644
--- a/drivers/net/wireless/iwlwifi/iwl-4965.c
+++ b/drivers/net/wireless/iwlwifi/iwl-4965.c
@@ -2223,7 +2223,7 @@ static struct iwl_hcmd_utils_ops iwl4965_hcmd_utils = {
2223 .build_addsta_hcmd = iwl4965_build_addsta_hcmd, 2223 .build_addsta_hcmd = iwl4965_build_addsta_hcmd,
2224 .chain_noise_reset = iwl4965_chain_noise_reset, 2224 .chain_noise_reset = iwl4965_chain_noise_reset,
2225 .gain_computation = iwl4965_gain_computation, 2225 .gain_computation = iwl4965_gain_computation,
2226 .rts_tx_cmd_flag = iwlcore_rts_tx_cmd_flag, 2226 .tx_cmd_protection = iwlcore_tx_cmd_protection,
2227 .calc_rssi = iwl4965_calc_rssi, 2227 .calc_rssi = iwl4965_calc_rssi,
2228 .request_scan = iwlagn_request_scan, 2228 .request_scan = iwlagn_request_scan,
2229}; 2229};
diff --git a/drivers/net/wireless/iwlwifi/iwl-5000.c b/drivers/net/wireless/iwlwifi/iwl-5000.c
index 8093ce2804fb..aacf3770f075 100644
--- a/drivers/net/wireless/iwlwifi/iwl-5000.c
+++ b/drivers/net/wireless/iwlwifi/iwl-5000.c
@@ -506,7 +506,7 @@ struct iwl_cfg iwl5300_agn_cfg = {
506 .use_bsm = false, 506 .use_bsm = false,
507 .ht_greenfield_support = true, 507 .ht_greenfield_support = true,
508 .led_compensation = 51, 508 .led_compensation = 51,
509 .use_rts_for_ht = true, /* use rts/cts protection */ 509 .use_rts_for_aggregation = true, /* use rts/cts protection */
510 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, 510 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
511 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF, 511 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF,
512 .chain_noise_scale = 1000, 512 .chain_noise_scale = 1000,
@@ -537,7 +537,7 @@ struct iwl_cfg iwl5100_bgn_cfg = {
537 .use_bsm = false, 537 .use_bsm = false,
538 .ht_greenfield_support = true, 538 .ht_greenfield_support = true,
539 .led_compensation = 51, 539 .led_compensation = 51,
540 .use_rts_for_ht = true, /* use rts/cts protection */ 540 .use_rts_for_aggregation = true, /* use rts/cts protection */
541 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, 541 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
542 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF, 542 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF,
543 .chain_noise_scale = 1000, 543 .chain_noise_scale = 1000,
@@ -597,7 +597,7 @@ struct iwl_cfg iwl5100_agn_cfg = {
597 .use_bsm = false, 597 .use_bsm = false,
598 .ht_greenfield_support = true, 598 .ht_greenfield_support = true,
599 .led_compensation = 51, 599 .led_compensation = 51,
600 .use_rts_for_ht = true, /* use rts/cts protection */ 600 .use_rts_for_aggregation = true, /* use rts/cts protection */
601 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, 601 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
602 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF, 602 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF,
603 .chain_noise_scale = 1000, 603 .chain_noise_scale = 1000,
@@ -628,7 +628,7 @@ struct iwl_cfg iwl5350_agn_cfg = {
628 .use_bsm = false, 628 .use_bsm = false,
629 .ht_greenfield_support = true, 629 .ht_greenfield_support = true,
630 .led_compensation = 51, 630 .led_compensation = 51,
631 .use_rts_for_ht = true, /* use rts/cts protection */ 631 .use_rts_for_aggregation = true, /* use rts/cts protection */
632 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, 632 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
633 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF, 633 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF,
634 .chain_noise_scale = 1000, 634 .chain_noise_scale = 1000,
@@ -659,7 +659,7 @@ struct iwl_cfg iwl5150_agn_cfg = {
659 .use_bsm = false, 659 .use_bsm = false,
660 .ht_greenfield_support = true, 660 .ht_greenfield_support = true,
661 .led_compensation = 51, 661 .led_compensation = 51,
662 .use_rts_for_ht = true, /* use rts/cts protection */ 662 .use_rts_for_aggregation = true, /* use rts/cts protection */
663 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, 663 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
664 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF, 664 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF,
665 .chain_noise_scale = 1000, 665 .chain_noise_scale = 1000,
diff --git a/drivers/net/wireless/iwlwifi/iwl-6000.c b/drivers/net/wireless/iwlwifi/iwl-6000.c
index 58270529a0e4..af4fd50f3405 100644
--- a/drivers/net/wireless/iwlwifi/iwl-6000.c
+++ b/drivers/net/wireless/iwlwifi/iwl-6000.c
@@ -381,7 +381,7 @@ struct iwl_cfg iwl6000g2a_2agn_cfg = {
381 .shadow_ram_support = true, 381 .shadow_ram_support = true,
382 .ht_greenfield_support = true, 382 .ht_greenfield_support = true,
383 .led_compensation = 51, 383 .led_compensation = 51,
384 .use_rts_for_ht = true, /* use rts/cts protection */ 384 .use_rts_for_aggregation = true, /* use rts/cts protection */
385 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, 385 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
386 .supports_idle = true, 386 .supports_idle = true,
387 .adv_thermal_throttle = true, 387 .adv_thermal_throttle = true,
@@ -489,7 +489,7 @@ struct iwl_cfg iwl6000g2b_2agn_cfg = {
489 .shadow_ram_support = true, 489 .shadow_ram_support = true,
490 .ht_greenfield_support = true, 490 .ht_greenfield_support = true,
491 .led_compensation = 51, 491 .led_compensation = 51,
492 .use_rts_for_ht = true, /* use rts/cts protection */ 492 .use_rts_for_aggregation = true, /* use rts/cts protection */
493 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, 493 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
494 .supports_idle = true, 494 .supports_idle = true,
495 .adv_thermal_throttle = true, 495 .adv_thermal_throttle = true,
@@ -563,7 +563,7 @@ struct iwl_cfg iwl6000g2b_2bgn_cfg = {
563 .shadow_ram_support = true, 563 .shadow_ram_support = true,
564 .ht_greenfield_support = true, 564 .ht_greenfield_support = true,
565 .led_compensation = 51, 565 .led_compensation = 51,
566 .use_rts_for_ht = true, /* use rts/cts protection */ 566 .use_rts_for_aggregation = true, /* use rts/cts protection */
567 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, 567 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
568 .supports_idle = true, 568 .supports_idle = true,
569 .adv_thermal_throttle = true, 569 .adv_thermal_throttle = true,
@@ -637,7 +637,7 @@ struct iwl_cfg iwl6000g2b_bgn_cfg = {
637 .shadow_ram_support = true, 637 .shadow_ram_support = true,
638 .ht_greenfield_support = true, 638 .ht_greenfield_support = true,
639 .led_compensation = 51, 639 .led_compensation = 51,
640 .use_rts_for_ht = true, /* use rts/cts protection */ 640 .use_rts_for_aggregation = true, /* use rts/cts protection */
641 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, 641 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
642 .supports_idle = true, 642 .supports_idle = true,
643 .adv_thermal_throttle = true, 643 .adv_thermal_throttle = true,
@@ -714,7 +714,7 @@ struct iwl_cfg iwl6000i_2agn_cfg = {
714 .shadow_ram_support = true, 714 .shadow_ram_support = true,
715 .ht_greenfield_support = true, 715 .ht_greenfield_support = true,
716 .led_compensation = 51, 716 .led_compensation = 51,
717 .use_rts_for_ht = true, /* use rts/cts protection */ 717 .use_rts_for_aggregation = true, /* use rts/cts protection */
718 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, 718 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
719 .supports_idle = true, 719 .supports_idle = true,
720 .adv_thermal_throttle = true, 720 .adv_thermal_throttle = true,
@@ -821,7 +821,7 @@ struct iwl_cfg iwl6050_2agn_cfg = {
821 .shadow_ram_support = true, 821 .shadow_ram_support = true,
822 .ht_greenfield_support = true, 822 .ht_greenfield_support = true,
823 .led_compensation = 51, 823 .led_compensation = 51,
824 .use_rts_for_ht = true, /* use rts/cts protection */ 824 .use_rts_for_aggregation = true, /* use rts/cts protection */
825 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, 825 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
826 .supports_idle = true, 826 .supports_idle = true,
827 .adv_thermal_throttle = true, 827 .adv_thermal_throttle = true,
@@ -859,7 +859,7 @@ struct iwl_cfg iwl6050g2_bgn_cfg = {
859 .shadow_ram_support = true, 859 .shadow_ram_support = true,
860 .ht_greenfield_support = true, 860 .ht_greenfield_support = true,
861 .led_compensation = 51, 861 .led_compensation = 51,
862 .use_rts_for_ht = true, /* use rts/cts protection */ 862 .use_rts_for_aggregation = true, /* use rts/cts protection */
863 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, 863 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
864 .supports_idle = true, 864 .supports_idle = true,
865 .adv_thermal_throttle = true, 865 .adv_thermal_throttle = true,
@@ -933,7 +933,7 @@ struct iwl_cfg iwl6000_3agn_cfg = {
933 .shadow_ram_support = true, 933 .shadow_ram_support = true,
934 .ht_greenfield_support = true, 934 .ht_greenfield_support = true,
935 .led_compensation = 51, 935 .led_compensation = 51,
936 .use_rts_for_ht = true, /* use rts/cts protection */ 936 .use_rts_for_aggregation = true, /* use rts/cts protection */
937 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, 937 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
938 .supports_idle = true, 938 .supports_idle = true,
939 .adv_thermal_throttle = true, 939 .adv_thermal_throttle = true,
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-debugfs.c b/drivers/net/wireless/iwlwifi/iwl-agn-debugfs.c
index f052c6d09b37..d706b8afbe5a 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-debugfs.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn-debugfs.c
@@ -980,7 +980,7 @@ ssize_t iwl_ucode_bt_stats_read(struct file *file,
980 le32_to_cpu(bt->lo_priority_tx_req_cnt), 980 le32_to_cpu(bt->lo_priority_tx_req_cnt),
981 accum_bt->lo_priority_tx_req_cnt); 981 accum_bt->lo_priority_tx_req_cnt);
982 pos += scnprintf(buf + pos, bufsz - pos, 982 pos += scnprintf(buf + pos, bufsz - pos,
983 "lo_priority_rx_denied_cnt:\t%u\t\t\t%u\n", 983 "lo_priority_tx_denied_cnt:\t%u\t\t\t%u\n",
984 le32_to_cpu(bt->lo_priority_tx_denied_cnt), 984 le32_to_cpu(bt->lo_priority_tx_denied_cnt),
985 accum_bt->lo_priority_tx_denied_cnt); 985 accum_bt->lo_priority_tx_denied_cnt);
986 pos += scnprintf(buf + pos, bufsz - pos, 986 pos += scnprintf(buf + pos, bufsz - pos,
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-hcmd.c b/drivers/net/wireless/iwlwifi/iwl-agn-hcmd.c
index a7216dda9786..75b901b3eb1e 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-hcmd.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn-hcmd.c
@@ -211,10 +211,21 @@ static void iwlagn_chain_noise_reset(struct iwl_priv *priv)
211 } 211 }
212} 212}
213 213
214static void iwlagn_rts_tx_cmd_flag(struct ieee80211_tx_info *info, 214static void iwlagn_tx_cmd_protection(struct iwl_priv *priv,
215 __le32 *tx_flags) 215 struct ieee80211_tx_info *info,
216 __le16 fc, __le32 *tx_flags)
216{ 217{
217 *tx_flags |= TX_CMD_FLG_PROT_REQUIRE_MSK; 218 if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS ||
219 info->control.rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
220 *tx_flags |= TX_CMD_FLG_PROT_REQUIRE_MSK;
221 return;
222 }
223
224 if (priv->cfg->use_rts_for_aggregation &&
225 info->flags & IEEE80211_TX_CTL_AMPDU) {
226 *tx_flags |= TX_CMD_FLG_PROT_REQUIRE_MSK;
227 return;
228 }
218} 229}
219 230
220/* Calc max signal level (dBm) among 3 possible receivers */ 231/* Calc max signal level (dBm) among 3 possible receivers */
@@ -268,7 +279,7 @@ struct iwl_hcmd_utils_ops iwlagn_hcmd_utils = {
268 .build_addsta_hcmd = iwlagn_build_addsta_hcmd, 279 .build_addsta_hcmd = iwlagn_build_addsta_hcmd,
269 .gain_computation = iwlagn_gain_computation, 280 .gain_computation = iwlagn_gain_computation,
270 .chain_noise_reset = iwlagn_chain_noise_reset, 281 .chain_noise_reset = iwlagn_chain_noise_reset,
271 .rts_tx_cmd_flag = iwlagn_rts_tx_cmd_flag, 282 .tx_cmd_protection = iwlagn_tx_cmd_protection,
272 .calc_rssi = iwlagn_calc_rssi, 283 .calc_rssi = iwlagn_calc_rssi,
273 .request_scan = iwlagn_request_scan, 284 .request_scan = iwlagn_request_scan,
274}; 285};
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-lib.c b/drivers/net/wireless/iwlwifi/iwl-agn-lib.c
index a1b6d202d57c..9dd9e64c2b0b 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-lib.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn-lib.c
@@ -1429,7 +1429,7 @@ int iwlagn_manage_ibss_station(struct iwl_priv *priv,
1429void iwl_free_tfds_in_queue(struct iwl_priv *priv, 1429void iwl_free_tfds_in_queue(struct iwl_priv *priv,
1430 int sta_id, int tid, int freed) 1430 int sta_id, int tid, int freed)
1431{ 1431{
1432 WARN_ON(!spin_is_locked(&priv->sta_lock)); 1432 lockdep_assert_held(&priv->sta_lock);
1433 1433
1434 if (priv->stations[sta_id].tid[tid].tfds_in_queue >= freed) 1434 if (priv->stations[sta_id].tid[tid].tfds_in_queue >= freed)
1435 priv->stations[sta_id].tid[tid].tfds_in_queue -= freed; 1435 priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-rs.c b/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
index 35c86d22b14b..23e5c42e7d7e 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
@@ -300,8 +300,9 @@ static int rs_tl_turn_on_agg_for_tid(struct iwl_priv *priv,
300 struct ieee80211_sta *sta) 300 struct ieee80211_sta *sta)
301{ 301{
302 int ret = -EAGAIN; 302 int ret = -EAGAIN;
303 u32 load = rs_tl_get_load(lq_data, tid);
303 304
304 if (rs_tl_get_load(lq_data, tid) > IWL_AGG_LOAD_THRESHOLD) { 305 if (load > IWL_AGG_LOAD_THRESHOLD) {
305 IWL_DEBUG_HT(priv, "Starting Tx agg: STA: %pM tid: %d\n", 306 IWL_DEBUG_HT(priv, "Starting Tx agg: STA: %pM tid: %d\n",
306 sta->addr, tid); 307 sta->addr, tid);
307 ret = ieee80211_start_tx_ba_session(sta, tid); 308 ret = ieee80211_start_tx_ba_session(sta, tid);
@@ -311,12 +312,14 @@ static int rs_tl_turn_on_agg_for_tid(struct iwl_priv *priv,
311 * this might be cause by reloading firmware 312 * this might be cause by reloading firmware
312 * stop the tx ba session here 313 * stop the tx ba session here
313 */ 314 */
314 IWL_DEBUG_HT(priv, "Fail start Tx agg on tid: %d\n", 315 IWL_ERR(priv, "Fail start Tx agg on tid: %d\n",
315 tid); 316 tid);
316 ieee80211_stop_tx_ba_session(sta, tid); 317 ieee80211_stop_tx_ba_session(sta, tid);
317 } 318 }
318 } else 319 } else {
319 IWL_ERR(priv, "Fail finding valid aggregation tid: %d\n", tid); 320 IWL_ERR(priv, "Aggregation not enabled for tid %d "
321 "because load = %u\n", tid, load);
322 }
320 return ret; 323 return ret;
321} 324}
322 325
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-tx.c b/drivers/net/wireless/iwlwifi/iwl-agn-tx.c
index 55a1b31fd09a..69155aa448fb 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-tx.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn-tx.c
@@ -379,10 +379,7 @@ static void iwlagn_tx_cmd_build_basic(struct iwl_priv *priv,
379 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; 379 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
380 } 380 }
381 381
382 priv->cfg->ops->utils->rts_tx_cmd_flag(info, &tx_flags); 382 priv->cfg->ops->utils->tx_cmd_protection(priv, info, fc, &tx_flags);
383
384 if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK))
385 tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
386 383
387 tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK); 384 tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK);
388 if (ieee80211_is_mgmt(fc)) { 385 if (ieee80211_is_mgmt(fc)) {
@@ -456,21 +453,6 @@ static void iwlagn_tx_cmd_build_rate(struct iwl_priv *priv,
456 if ((rate_idx >= IWL_FIRST_CCK_RATE) && (rate_idx <= IWL_LAST_CCK_RATE)) 453 if ((rate_idx >= IWL_FIRST_CCK_RATE) && (rate_idx <= IWL_LAST_CCK_RATE))
457 rate_flags |= RATE_MCS_CCK_MSK; 454 rate_flags |= RATE_MCS_CCK_MSK;
458 455
459 /* Set up RTS and CTS flags for certain packets */
460 switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
461 case cpu_to_le16(IEEE80211_STYPE_AUTH):
462 case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
463 case cpu_to_le16(IEEE80211_STYPE_ASSOC_REQ):
464 case cpu_to_le16(IEEE80211_STYPE_REASSOC_REQ):
465 if (tx_cmd->tx_flags & TX_CMD_FLG_RTS_MSK) {
466 tx_cmd->tx_flags &= ~TX_CMD_FLG_RTS_MSK;
467 tx_cmd->tx_flags |= TX_CMD_FLG_CTS_MSK;
468 }
469 break;
470 default:
471 break;
472 }
473
474 /* Set up antennas */ 456 /* Set up antennas */
475 priv->mgmt_tx_ant = iwl_toggle_tx_ant(priv, priv->mgmt_tx_ant, 457 priv->mgmt_tx_ant = iwl_toggle_tx_ant(priv, priv->mgmt_tx_ant,
476 priv->hw_params.valid_tx_ant); 458 priv->hw_params.valid_tx_ant);
@@ -1117,7 +1099,7 @@ int iwlagn_txq_check_empty(struct iwl_priv *priv,
1117 u8 *addr = priv->stations[sta_id].sta.sta.addr; 1099 u8 *addr = priv->stations[sta_id].sta.sta.addr;
1118 struct iwl_tid_data *tid_data = &priv->stations[sta_id].tid[tid]; 1100 struct iwl_tid_data *tid_data = &priv->stations[sta_id].tid[tid];
1119 1101
1120 WARN_ON(!spin_is_locked(&priv->sta_lock)); 1102 lockdep_assert_held(&priv->sta_lock);
1121 1103
1122 switch (priv->stations[sta_id].tid[tid].agg.state) { 1104 switch (priv->stations[sta_id].tid[tid].agg.state) {
1123 case IWL_EMPTYING_HW_QUEUE_DELBA: 1105 case IWL_EMPTYING_HW_QUEUE_DELBA:
@@ -1331,7 +1313,14 @@ void iwlagn_rx_reply_compressed_ba(struct iwl_priv *priv,
1331 tid = ba_resp->tid; 1313 tid = ba_resp->tid;
1332 agg = &priv->stations[sta_id].tid[tid].agg; 1314 agg = &priv->stations[sta_id].tid[tid].agg;
1333 if (unlikely(agg->txq_id != scd_flow)) { 1315 if (unlikely(agg->txq_id != scd_flow)) {
1334 IWL_ERR(priv, "BA scd_flow %d does not match txq_id %d\n", 1316 /*
1317 * FIXME: this is a uCode bug which need to be addressed,
1318 * log the information and return for now!
1319 * since it is possible happen very often and in order
1320 * not to fill the syslog, don't enable the logging by default
1321 */
1322 IWL_DEBUG_TX_REPLY(priv,
1323 "BA scd_flow %d does not match txq_id %d\n",
1335 scd_flow, agg->txq_id); 1324 scd_flow, agg->txq_id);
1336 return; 1325 return;
1337 } 1326 }
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn.c b/drivers/net/wireless/iwlwifi/iwl-agn.c
index 35337b1e7cac..c1882fd8345d 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn.c
@@ -202,13 +202,6 @@ int iwl_commit_rxon(struct iwl_priv *priv)
202 202
203 priv->start_calib = 0; 203 priv->start_calib = 0;
204 if (new_assoc) { 204 if (new_assoc) {
205 /*
206 * allow CTS-to-self if possible for new association.
207 * this is relevant only for 5000 series and up,
208 * but will not damage 4965
209 */
210 priv->staging_rxon.flags |= RXON_FLG_SELF_CTS_EN;
211
212 /* Apply the new configuration 205 /* Apply the new configuration
213 * RXON assoc doesn't clear the station table in uCode, 206 * RXON assoc doesn't clear the station table in uCode,
214 */ 207 */
@@ -1618,45 +1611,9 @@ static ssize_t store_tx_power(struct device *d,
1618 1611
1619static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power); 1612static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
1620 1613
1621static ssize_t show_rts_ht_protection(struct device *d,
1622 struct device_attribute *attr, char *buf)
1623{
1624 struct iwl_priv *priv = dev_get_drvdata(d);
1625
1626 return sprintf(buf, "%s\n",
1627 priv->cfg->use_rts_for_ht ? "RTS/CTS" : "CTS-to-self");
1628}
1629
1630static ssize_t store_rts_ht_protection(struct device *d,
1631 struct device_attribute *attr,
1632 const char *buf, size_t count)
1633{
1634 struct iwl_priv *priv = dev_get_drvdata(d);
1635 unsigned long val;
1636 int ret;
1637
1638 ret = strict_strtoul(buf, 10, &val);
1639 if (ret)
1640 IWL_INFO(priv, "Input is not in decimal form.\n");
1641 else {
1642 if (!iwl_is_associated(priv))
1643 priv->cfg->use_rts_for_ht = val ? true : false;
1644 else
1645 IWL_ERR(priv, "Sta associated with AP - "
1646 "Change protection mechanism is not allowed\n");
1647 ret = count;
1648 }
1649 return ret;
1650}
1651
1652static DEVICE_ATTR(rts_ht_protection, S_IWUSR | S_IRUGO,
1653 show_rts_ht_protection, store_rts_ht_protection);
1654
1655
1656static struct attribute *iwl_sysfs_entries[] = { 1614static struct attribute *iwl_sysfs_entries[] = {
1657 &dev_attr_temperature.attr, 1615 &dev_attr_temperature.attr,
1658 &dev_attr_tx_power.attr, 1616 &dev_attr_tx_power.attr,
1659 &dev_attr_rts_ht_protection.attr,
1660#ifdef CONFIG_IWLWIFI_DEBUG 1617#ifdef CONFIG_IWLWIFI_DEBUG
1661 &dev_attr_debug_level.attr, 1618 &dev_attr_debug_level.attr,
1662#endif 1619#endif
@@ -3464,25 +3421,6 @@ static int iwl_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3464 return ret; 3421 return ret;
3465} 3422}
3466 3423
3467/*
3468 * switch to RTS/CTS for TX
3469 */
3470static void iwl_enable_rts_cts(struct iwl_priv *priv)
3471{
3472
3473 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3474 return;
3475
3476 priv->staging_rxon.flags &= ~RXON_FLG_SELF_CTS_EN;
3477 if (!test_bit(STATUS_SCANNING, &priv->status)) {
3478 IWL_DEBUG_INFO(priv, "use RTS/CTS protection\n");
3479 iwlcore_commit_rxon(priv);
3480 } else {
3481 /* scanning, defer the request until scan completed */
3482 IWL_DEBUG_INFO(priv, "defer setting RTS/CTS protection\n");
3483 }
3484}
3485
3486static int iwl_mac_ampdu_action(struct ieee80211_hw *hw, 3424static int iwl_mac_ampdu_action(struct ieee80211_hw *hw,
3487 struct ieee80211_vif *vif, 3425 struct ieee80211_vif *vif,
3488 enum ieee80211_ampdu_mlme_action action, 3426 enum ieee80211_ampdu_mlme_action action,
@@ -3529,14 +3467,33 @@ static int iwl_mac_ampdu_action(struct ieee80211_hw *hw,
3529 } 3467 }
3530 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) 3468 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3531 ret = 0; 3469 ret = 0;
3470 if (priv->cfg->use_rts_for_aggregation) {
3471 struct iwl_station_priv *sta_priv =
3472 (void *) sta->drv_priv;
3473 /*
3474 * switch off RTS/CTS if it was previously enabled
3475 */
3476
3477 sta_priv->lq_sta.lq.general_params.flags &=
3478 ~LINK_QUAL_FLAGS_SET_STA_TLC_RTS_MSK;
3479 iwl_send_lq_cmd(priv, &sta_priv->lq_sta.lq,
3480 CMD_ASYNC, false);
3481 }
3532 break; 3482 break;
3533 case IEEE80211_AMPDU_TX_OPERATIONAL: 3483 case IEEE80211_AMPDU_TX_OPERATIONAL:
3534 if (priv->cfg->use_rts_for_ht) { 3484 if (priv->cfg->use_rts_for_aggregation) {
3485 struct iwl_station_priv *sta_priv =
3486 (void *) sta->drv_priv;
3487
3535 /* 3488 /*
3536 * switch to RTS/CTS if it is the prefer protection 3489 * switch to RTS/CTS if it is the prefer protection
3537 * method for HT traffic 3490 * method for HT traffic
3538 */ 3491 */
3539 iwl_enable_rts_cts(priv); 3492
3493 sta_priv->lq_sta.lq.general_params.flags |=
3494 LINK_QUAL_FLAGS_SET_STA_TLC_RTS_MSK;
3495 iwl_send_lq_cmd(priv, &sta_priv->lq_sta.lq,
3496 CMD_ASYNC, false);
3540 } 3497 }
3541 ret = 0; 3498 ret = 0;
3542 break; 3499 break;
diff --git a/drivers/net/wireless/iwlwifi/iwl-core.c b/drivers/net/wireless/iwlwifi/iwl-core.c
index 8024d44ce4bb..2c03c6e20a72 100644
--- a/drivers/net/wireless/iwlwifi/iwl-core.c
+++ b/drivers/net/wireless/iwlwifi/iwl-core.c
@@ -401,21 +401,38 @@ void iwlcore_free_geos(struct iwl_priv *priv)
401EXPORT_SYMBOL(iwlcore_free_geos); 401EXPORT_SYMBOL(iwlcore_free_geos);
402 402
403/* 403/*
404 * iwlcore_rts_tx_cmd_flag: Set rts/cts. 3945 and 4965 only share this 404 * iwlcore_tx_cmd_protection: Set rts/cts. 3945 and 4965 only share this
405 * function. 405 * function.
406 */ 406 */
407void iwlcore_rts_tx_cmd_flag(struct ieee80211_tx_info *info, 407void iwlcore_tx_cmd_protection(struct iwl_priv *priv,
408 __le32 *tx_flags) 408 struct ieee80211_tx_info *info,
409 __le16 fc, __le32 *tx_flags)
409{ 410{
410 if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS) { 411 if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS) {
411 *tx_flags |= TX_CMD_FLG_RTS_MSK; 412 *tx_flags |= TX_CMD_FLG_RTS_MSK;
412 *tx_flags &= ~TX_CMD_FLG_CTS_MSK; 413 *tx_flags &= ~TX_CMD_FLG_CTS_MSK;
414 *tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
415
416 if (!ieee80211_is_mgmt(fc))
417 return;
418
419 switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
420 case cpu_to_le16(IEEE80211_STYPE_AUTH):
421 case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
422 case cpu_to_le16(IEEE80211_STYPE_ASSOC_REQ):
423 case cpu_to_le16(IEEE80211_STYPE_REASSOC_REQ):
424 *tx_flags &= ~TX_CMD_FLG_RTS_MSK;
425 *tx_flags |= TX_CMD_FLG_CTS_MSK;
426 break;
427 }
413 } else if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT) { 428 } else if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
414 *tx_flags &= ~TX_CMD_FLG_RTS_MSK; 429 *tx_flags &= ~TX_CMD_FLG_RTS_MSK;
415 *tx_flags |= TX_CMD_FLG_CTS_MSK; 430 *tx_flags |= TX_CMD_FLG_CTS_MSK;
431 *tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
416 } 432 }
417} 433}
418EXPORT_SYMBOL(iwlcore_rts_tx_cmd_flag); 434EXPORT_SYMBOL(iwlcore_tx_cmd_protection);
435
419 436
420static bool is_single_rx_stream(struct iwl_priv *priv) 437static bool is_single_rx_stream(struct iwl_priv *priv)
421{ 438{
@@ -1869,6 +1886,10 @@ void iwl_bss_info_changed(struct ieee80211_hw *hw,
1869 priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK; 1886 priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
1870 else 1887 else
1871 priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK; 1888 priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
1889 if (bss_conf->use_cts_prot)
1890 priv->staging_rxon.flags |= RXON_FLG_SELF_CTS_EN;
1891 else
1892 priv->staging_rxon.flags &= ~RXON_FLG_SELF_CTS_EN;
1872 } 1893 }
1873 1894
1874 if (changes & BSS_CHANGED_BASIC_RATES) { 1895 if (changes & BSS_CHANGED_BASIC_RATES) {
@@ -2000,6 +2021,7 @@ void iwl_mac_remove_interface(struct ieee80211_hw *hw,
2000 struct ieee80211_vif *vif) 2021 struct ieee80211_vif *vif)
2001{ 2022{
2002 struct iwl_priv *priv = hw->priv; 2023 struct iwl_priv *priv = hw->priv;
2024 bool scan_completed = false;
2003 2025
2004 IWL_DEBUG_MAC80211(priv, "enter\n"); 2026 IWL_DEBUG_MAC80211(priv, "enter\n");
2005 2027
@@ -2013,7 +2035,7 @@ void iwl_mac_remove_interface(struct ieee80211_hw *hw,
2013 if (priv->vif == vif) { 2035 if (priv->vif == vif) {
2014 priv->vif = NULL; 2036 priv->vif = NULL;
2015 if (priv->scan_vif == vif) { 2037 if (priv->scan_vif == vif) {
2016 ieee80211_scan_completed(priv->hw, true); 2038 scan_completed = true;
2017 priv->scan_vif = NULL; 2039 priv->scan_vif = NULL;
2018 priv->scan_request = NULL; 2040 priv->scan_request = NULL;
2019 } 2041 }
@@ -2021,6 +2043,9 @@ void iwl_mac_remove_interface(struct ieee80211_hw *hw,
2021 } 2043 }
2022 mutex_unlock(&priv->mutex); 2044 mutex_unlock(&priv->mutex);
2023 2045
2046 if (scan_completed)
2047 ieee80211_scan_completed(priv->hw, true);
2048
2024 IWL_DEBUG_MAC80211(priv, "leave\n"); 2049 IWL_DEBUG_MAC80211(priv, "leave\n");
2025 2050
2026} 2051}
diff --git a/drivers/net/wireless/iwlwifi/iwl-core.h b/drivers/net/wireless/iwlwifi/iwl-core.h
index e9d23f2f869d..4a71dfb10a15 100644
--- a/drivers/net/wireless/iwlwifi/iwl-core.h
+++ b/drivers/net/wireless/iwlwifi/iwl-core.h
@@ -104,8 +104,9 @@ struct iwl_hcmd_utils_ops {
104 u32 min_average_noise, 104 u32 min_average_noise,
105 u8 default_chain); 105 u8 default_chain);
106 void (*chain_noise_reset)(struct iwl_priv *priv); 106 void (*chain_noise_reset)(struct iwl_priv *priv);
107 void (*rts_tx_cmd_flag)(struct ieee80211_tx_info *info, 107 void (*tx_cmd_protection)(struct iwl_priv *priv,
108 __le32 *tx_flags); 108 struct ieee80211_tx_info *info,
109 __le16 fc, __le32 *tx_flags);
109 int (*calc_rssi)(struct iwl_priv *priv, 110 int (*calc_rssi)(struct iwl_priv *priv,
110 struct iwl_rx_phy_res *rx_resp); 111 struct iwl_rx_phy_res *rx_resp);
111 void (*request_scan)(struct iwl_priv *priv, struct ieee80211_vif *vif); 112 void (*request_scan)(struct iwl_priv *priv, struct ieee80211_vif *vif);
@@ -249,7 +250,7 @@ struct iwl_mod_params {
249 * @led_compensation: compensate on the led on/off time per HW according 250 * @led_compensation: compensate on the led on/off time per HW according
250 * to the deviation to achieve the desired led frequency. 251 * to the deviation to achieve the desired led frequency.
251 * The detail algorithm is described in iwl-led.c 252 * The detail algorithm is described in iwl-led.c
252 * @use_rts_for_ht: use rts/cts protection for HT traffic 253 * @use_rts_for_aggregation: use rts/cts protection for HT traffic
253 * @chain_noise_num_beacons: number of beacons used to compute chain noise 254 * @chain_noise_num_beacons: number of beacons used to compute chain noise
254 * @adv_thermal_throttle: support advance thermal throttle 255 * @adv_thermal_throttle: support advance thermal throttle
255 * @support_ct_kill_exit: support ct kill exit condition 256 * @support_ct_kill_exit: support ct kill exit condition
@@ -318,7 +319,7 @@ struct iwl_cfg {
318 const bool ht_greenfield_support; 319 const bool ht_greenfield_support;
319 u16 led_compensation; 320 u16 led_compensation;
320 const bool broken_powersave; 321 const bool broken_powersave;
321 bool use_rts_for_ht; 322 bool use_rts_for_aggregation;
322 int chain_noise_num_beacons; 323 int chain_noise_num_beacons;
323 const bool supports_idle; 324 const bool supports_idle;
324 bool adv_thermal_throttle; 325 bool adv_thermal_throttle;
@@ -390,8 +391,9 @@ void iwl_config_ap(struct iwl_priv *priv, struct ieee80211_vif *vif);
390void iwl_mac_reset_tsf(struct ieee80211_hw *hw); 391void iwl_mac_reset_tsf(struct ieee80211_hw *hw);
391int iwl_alloc_txq_mem(struct iwl_priv *priv); 392int iwl_alloc_txq_mem(struct iwl_priv *priv);
392void iwl_free_txq_mem(struct iwl_priv *priv); 393void iwl_free_txq_mem(struct iwl_priv *priv);
393void iwlcore_rts_tx_cmd_flag(struct ieee80211_tx_info *info, 394void iwlcore_tx_cmd_protection(struct iwl_priv *priv,
394 __le32 *tx_flags); 395 struct ieee80211_tx_info *info,
396 __le16 fc, __le32 *tx_flags);
395#ifdef CONFIG_IWLWIFI_DEBUGFS 397#ifdef CONFIG_IWLWIFI_DEBUGFS
396int iwl_alloc_traffic_mem(struct iwl_priv *priv); 398int iwl_alloc_traffic_mem(struct iwl_priv *priv);
397void iwl_free_traffic_mem(struct iwl_priv *priv); 399void iwl_free_traffic_mem(struct iwl_priv *priv);
diff --git a/drivers/net/wireless/iwlwifi/iwl-debug.h b/drivers/net/wireless/iwlwifi/iwl-debug.h
index 5c2bcef5df0c..0b961a353ff6 100644
--- a/drivers/net/wireless/iwlwifi/iwl-debug.h
+++ b/drivers/net/wireless/iwlwifi/iwl-debug.h
@@ -71,7 +71,7 @@ do { \
71#define IWL_DEBUG(__priv, level, fmt, args...) 71#define IWL_DEBUG(__priv, level, fmt, args...)
72#define IWL_DEBUG_LIMIT(__priv, level, fmt, args...) 72#define IWL_DEBUG_LIMIT(__priv, level, fmt, args...)
73static inline void iwl_print_hex_dump(struct iwl_priv *priv, int level, 73static inline void iwl_print_hex_dump(struct iwl_priv *priv, int level,
74 void *p, u32 len) 74 const void *p, u32 len)
75{} 75{}
76#endif /* CONFIG_IWLWIFI_DEBUG */ 76#endif /* CONFIG_IWLWIFI_DEBUG */
77 77
diff --git a/drivers/net/wireless/iwlwifi/iwl-devtrace.h b/drivers/net/wireless/iwlwifi/iwl-devtrace.h
index ae7319bb3a99..4cf864c664ee 100644
--- a/drivers/net/wireless/iwlwifi/iwl-devtrace.h
+++ b/drivers/net/wireless/iwlwifi/iwl-devtrace.h
@@ -193,7 +193,7 @@ TRACE_EVENT(iwlwifi_dev_tx,
193 __entry->framelen = buf0_len + buf1_len; 193 __entry->framelen = buf0_len + buf1_len;
194 memcpy(__get_dynamic_array(tfd), tfd, tfdlen); 194 memcpy(__get_dynamic_array(tfd), tfd, tfdlen);
195 memcpy(__get_dynamic_array(buf0), buf0, buf0_len); 195 memcpy(__get_dynamic_array(buf0), buf0, buf0_len);
196 memcpy(__get_dynamic_array(buf1), buf1, buf0_len); 196 memcpy(__get_dynamic_array(buf1), buf1, buf1_len);
197 ), 197 ),
198 TP_printk("[%p] TX %.2x (%zu bytes)", 198 TP_printk("[%p] TX %.2x (%zu bytes)",
199 __entry->priv, 199 __entry->priv,
diff --git a/drivers/net/wireless/iwlwifi/iwl-scan.c b/drivers/net/wireless/iwlwifi/iwl-scan.c
index b0c6b0473901..a4b3663a262f 100644
--- a/drivers/net/wireless/iwlwifi/iwl-scan.c
+++ b/drivers/net/wireless/iwlwifi/iwl-scan.c
@@ -298,7 +298,7 @@ EXPORT_SYMBOL(iwl_init_scan_params);
298 298
299static int iwl_scan_initiate(struct iwl_priv *priv, struct ieee80211_vif *vif) 299static int iwl_scan_initiate(struct iwl_priv *priv, struct ieee80211_vif *vif)
300{ 300{
301 WARN_ON(!mutex_is_locked(&priv->mutex)); 301 lockdep_assert_held(&priv->mutex);
302 302
303 IWL_DEBUG_INFO(priv, "Starting scan...\n"); 303 IWL_DEBUG_INFO(priv, "Starting scan...\n");
304 set_bit(STATUS_SCANNING, &priv->status); 304 set_bit(STATUS_SCANNING, &priv->status);
diff --git a/drivers/net/wireless/iwlwifi/iwl-sta.c b/drivers/net/wireless/iwlwifi/iwl-sta.c
index 9511f03f07e0..7e0829be5e78 100644
--- a/drivers/net/wireless/iwlwifi/iwl-sta.c
+++ b/drivers/net/wireless/iwlwifi/iwl-sta.c
@@ -773,7 +773,7 @@ static int iwl_send_static_wepkey_cmd(struct iwl_priv *priv, u8 send_if_empty)
773 773
774int iwl_restore_default_wep_keys(struct iwl_priv *priv) 774int iwl_restore_default_wep_keys(struct iwl_priv *priv)
775{ 775{
776 WARN_ON(!mutex_is_locked(&priv->mutex)); 776 lockdep_assert_held(&priv->mutex);
777 777
778 return iwl_send_static_wepkey_cmd(priv, 0); 778 return iwl_send_static_wepkey_cmd(priv, 0);
779} 779}
@@ -784,7 +784,7 @@ int iwl_remove_default_wep_key(struct iwl_priv *priv,
784{ 784{
785 int ret; 785 int ret;
786 786
787 WARN_ON(!mutex_is_locked(&priv->mutex)); 787 lockdep_assert_held(&priv->mutex);
788 788
789 IWL_DEBUG_WEP(priv, "Removing default WEP key: idx=%d\n", 789 IWL_DEBUG_WEP(priv, "Removing default WEP key: idx=%d\n",
790 keyconf->keyidx); 790 keyconf->keyidx);
@@ -808,7 +808,7 @@ int iwl_set_default_wep_key(struct iwl_priv *priv,
808{ 808{
809 int ret; 809 int ret;
810 810
811 WARN_ON(!mutex_is_locked(&priv->mutex)); 811 lockdep_assert_held(&priv->mutex);
812 812
813 if (keyconf->keylen != WEP_KEY_LEN_128 && 813 if (keyconf->keylen != WEP_KEY_LEN_128 &&
814 keyconf->keylen != WEP_KEY_LEN_64) { 814 keyconf->keylen != WEP_KEY_LEN_64) {
diff --git a/drivers/net/wireless/iwlwifi/iwl3945-base.c b/drivers/net/wireless/iwlwifi/iwl3945-base.c
index d24eb47d3705..70c4b8fba0ee 100644
--- a/drivers/net/wireless/iwlwifi/iwl3945-base.c
+++ b/drivers/net/wireless/iwlwifi/iwl3945-base.c
@@ -435,10 +435,7 @@ static void iwl3945_build_tx_cmd_basic(struct iwl_priv *priv,
435 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; 435 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
436 } 436 }
437 437
438 priv->cfg->ops->utils->rts_tx_cmd_flag(info, &tx_flags); 438 priv->cfg->ops->utils->tx_cmd_protection(priv, info, fc, &tx_flags);
439
440 if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK))
441 tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
442 439
443 tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK); 440 tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK);
444 if (ieee80211_is_mgmt(fc)) { 441 if (ieee80211_is_mgmt(fc)) {
diff --git a/drivers/net/wireless/libertas/cfg.c b/drivers/net/wireless/libertas/cfg.c
index 25f902760980..3e82f1627209 100644
--- a/drivers/net/wireless/libertas/cfg.c
+++ b/drivers/net/wireless/libertas/cfg.c
@@ -6,7 +6,10 @@
6 * 6 *
7 */ 7 */
8 8
9#include <linux/sched.h>
10#include <linux/wait.h>
9#include <linux/slab.h> 11#include <linux/slab.h>
12#include <linux/sched.h>
10#include <linux/ieee80211.h> 13#include <linux/ieee80211.h>
11#include <net/cfg80211.h> 14#include <net/cfg80211.h>
12#include <asm/unaligned.h> 15#include <asm/unaligned.h>
@@ -257,6 +260,29 @@ static int lbs_add_supported_rates_tlv(u8 *tlv)
257 return sizeof(rate_tlv->header) + i; 260 return sizeof(rate_tlv->header) + i;
258} 261}
259 262
263/* Add common rates from a TLV and return the new end of the TLV */
264static u8 *
265add_ie_rates(u8 *tlv, const u8 *ie, int *nrates)
266{
267 int hw, ap, ap_max = ie[1];
268 u8 hw_rate;
269
270 /* Advance past IE header */
271 ie += 2;
272
273 lbs_deb_hex(LBS_DEB_ASSOC, "AP IE Rates", (u8 *) ie, ap_max);
274
275 for (hw = 0; hw < ARRAY_SIZE(lbs_rates); hw++) {
276 hw_rate = lbs_rates[hw].bitrate / 5;
277 for (ap = 0; ap < ap_max; ap++) {
278 if (hw_rate == (ie[ap] & 0x7f)) {
279 *tlv++ = ie[ap];
280 *nrates = *nrates + 1;
281 }
282 }
283 }
284 return tlv;
285}
260 286
261/* 287/*
262 * Adds a TLV with all rates the hardware *and* BSS supports. 288 * Adds a TLV with all rates the hardware *and* BSS supports.
@@ -264,8 +290,11 @@ static int lbs_add_supported_rates_tlv(u8 *tlv)
264static int lbs_add_common_rates_tlv(u8 *tlv, struct cfg80211_bss *bss) 290static int lbs_add_common_rates_tlv(u8 *tlv, struct cfg80211_bss *bss)
265{ 291{
266 struct mrvl_ie_rates_param_set *rate_tlv = (void *)tlv; 292 struct mrvl_ie_rates_param_set *rate_tlv = (void *)tlv;
267 const u8 *rates_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SUPP_RATES); 293 const u8 *rates_eid, *ext_rates_eid;
268 int n; 294 int n = 0;
295
296 rates_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SUPP_RATES);
297 ext_rates_eid = ieee80211_bss_get_ie(bss, WLAN_EID_EXT_SUPP_RATES);
269 298
270 /* 299 /*
271 * 01 00 TLV_TYPE_RATES 300 * 01 00 TLV_TYPE_RATES
@@ -275,26 +304,21 @@ static int lbs_add_common_rates_tlv(u8 *tlv, struct cfg80211_bss *bss)
275 rate_tlv->header.type = cpu_to_le16(TLV_TYPE_RATES); 304 rate_tlv->header.type = cpu_to_le16(TLV_TYPE_RATES);
276 tlv += sizeof(rate_tlv->header); 305 tlv += sizeof(rate_tlv->header);
277 306
278 if (!rates_eid) { 307 /* Add basic rates */
308 if (rates_eid) {
309 tlv = add_ie_rates(tlv, rates_eid, &n);
310
311 /* Add extended rates, if any */
312 if (ext_rates_eid)
313 tlv = add_ie_rates(tlv, ext_rates_eid, &n);
314 } else {
315 lbs_deb_assoc("assoc: bss had no basic rate IE\n");
279 /* Fallback: add basic 802.11b rates */ 316 /* Fallback: add basic 802.11b rates */
280 *tlv++ = 0x82; 317 *tlv++ = 0x82;
281 *tlv++ = 0x84; 318 *tlv++ = 0x84;
282 *tlv++ = 0x8b; 319 *tlv++ = 0x8b;
283 *tlv++ = 0x96; 320 *tlv++ = 0x96;
284 n = 4; 321 n = 4;
285 } else {
286 int hw, ap;
287 u8 ap_max = rates_eid[1];
288 n = 0;
289 for (hw = 0; hw < ARRAY_SIZE(lbs_rates); hw++) {
290 u8 hw_rate = lbs_rates[hw].bitrate / 5;
291 for (ap = 0; ap < ap_max; ap++) {
292 if (hw_rate == (rates_eid[ap+2] & 0x7f)) {
293 *tlv++ = rates_eid[ap+2];
294 n++;
295 }
296 }
297 }
298 } 322 }
299 323
300 rate_tlv->header.len = cpu_to_le16(n); 324 rate_tlv->header.len = cpu_to_le16(n);
@@ -465,7 +489,15 @@ static int lbs_ret_scan(struct lbs_private *priv, unsigned long dummy,
465 lbs_deb_enter(LBS_DEB_CFG80211); 489 lbs_deb_enter(LBS_DEB_CFG80211);
466 490
467 bsssize = get_unaligned_le16(&scanresp->bssdescriptsize); 491 bsssize = get_unaligned_le16(&scanresp->bssdescriptsize);
468 nr_sets = le16_to_cpu(resp->size); 492 nr_sets = le16_to_cpu(scanresp->nr_sets);
493
494 lbs_deb_scan("scan response: %d BSSs (%d bytes); resp size %d bytes\n",
495 nr_sets, bsssize, le16_to_cpu(resp->size));
496
497 if (nr_sets == 0) {
498 ret = 0;
499 goto done;
500 }
469 501
470 /* 502 /*
471 * The general layout of the scan response is described in chapter 503 * The general layout of the scan response is described in chapter
@@ -670,8 +702,13 @@ static void lbs_scan_worker(struct work_struct *work)
670 702
671 if (priv->scan_channel >= priv->scan_req->n_channels) { 703 if (priv->scan_channel >= priv->scan_req->n_channels) {
672 /* Mark scan done */ 704 /* Mark scan done */
673 cfg80211_scan_done(priv->scan_req, false); 705 if (priv->internal_scan)
706 kfree(priv->scan_req);
707 else
708 cfg80211_scan_done(priv->scan_req, false);
709
674 priv->scan_req = NULL; 710 priv->scan_req = NULL;
711 priv->last_scan = jiffies;
675 } 712 }
676 713
677 /* Restart network */ 714 /* Restart network */
@@ -682,10 +719,33 @@ static void lbs_scan_worker(struct work_struct *work)
682 719
683 kfree(scan_cmd); 720 kfree(scan_cmd);
684 721
722 /* Wake up anything waiting on scan completion */
723 if (priv->scan_req == NULL) {
724 lbs_deb_scan("scan: waking up waiters\n");
725 wake_up_all(&priv->scan_q);
726 }
727
685 out_no_scan_cmd: 728 out_no_scan_cmd:
686 lbs_deb_leave(LBS_DEB_SCAN); 729 lbs_deb_leave(LBS_DEB_SCAN);
687} 730}
688 731
732static void _internal_start_scan(struct lbs_private *priv, bool internal,
733 struct cfg80211_scan_request *request)
734{
735 lbs_deb_enter(LBS_DEB_CFG80211);
736
737 lbs_deb_scan("scan: ssids %d, channels %d, ie_len %zd\n",
738 request->n_ssids, request->n_channels, request->ie_len);
739
740 priv->scan_channel = 0;
741 queue_delayed_work(priv->work_thread, &priv->scan_work,
742 msecs_to_jiffies(50));
743
744 priv->scan_req = request;
745 priv->internal_scan = internal;
746
747 lbs_deb_leave(LBS_DEB_CFG80211);
748}
689 749
690static int lbs_cfg_scan(struct wiphy *wiphy, 750static int lbs_cfg_scan(struct wiphy *wiphy,
691 struct net_device *dev, 751 struct net_device *dev,
@@ -702,18 +762,11 @@ static int lbs_cfg_scan(struct wiphy *wiphy,
702 goto out; 762 goto out;
703 } 763 }
704 764
705 lbs_deb_scan("scan: ssids %d, channels %d, ie_len %zd\n", 765 _internal_start_scan(priv, false, request);
706 request->n_ssids, request->n_channels, request->ie_len);
707
708 priv->scan_channel = 0;
709 queue_delayed_work(priv->work_thread, &priv->scan_work,
710 msecs_to_jiffies(50));
711 766
712 if (priv->surpriseremoved) 767 if (priv->surpriseremoved)
713 ret = -EIO; 768 ret = -EIO;
714 769
715 priv->scan_req = request;
716
717 out: 770 out:
718 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret); 771 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
719 return ret; 772 return ret;
@@ -1000,6 +1053,7 @@ static int lbs_associate(struct lbs_private *priv,
1000 int status; 1053 int status;
1001 int ret; 1054 int ret;
1002 u8 *pos = &(cmd->iebuf[0]); 1055 u8 *pos = &(cmd->iebuf[0]);
1056 u8 *tmp;
1003 1057
1004 lbs_deb_enter(LBS_DEB_CFG80211); 1058 lbs_deb_enter(LBS_DEB_CFG80211);
1005 1059
@@ -1044,7 +1098,9 @@ static int lbs_associate(struct lbs_private *priv,
1044 pos += lbs_add_cf_param_tlv(pos); 1098 pos += lbs_add_cf_param_tlv(pos);
1045 1099
1046 /* add rates TLV */ 1100 /* add rates TLV */
1101 tmp = pos + 4; /* skip Marvell IE header */
1047 pos += lbs_add_common_rates_tlv(pos, bss); 1102 pos += lbs_add_common_rates_tlv(pos, bss);
1103 lbs_deb_hex(LBS_DEB_ASSOC, "Common Rates", tmp, pos - tmp);
1048 1104
1049 /* add auth type TLV */ 1105 /* add auth type TLV */
1050 if (priv->fwrelease >= 0x09000000) 1106 if (priv->fwrelease >= 0x09000000)
@@ -1124,7 +1180,62 @@ done:
1124 return ret; 1180 return ret;
1125} 1181}
1126 1182
1183static struct cfg80211_scan_request *
1184_new_connect_scan_req(struct wiphy *wiphy, struct cfg80211_connect_params *sme)
1185{
1186 struct cfg80211_scan_request *creq = NULL;
1187 int i, n_channels = 0;
1188 enum ieee80211_band band;
1189
1190 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1191 if (wiphy->bands[band])
1192 n_channels += wiphy->bands[band]->n_channels;
1193 }
1194
1195 creq = kzalloc(sizeof(*creq) + sizeof(struct cfg80211_ssid) +
1196 n_channels * sizeof(void *),
1197 GFP_ATOMIC);
1198 if (!creq)
1199 return NULL;
1200
1201 /* SSIDs come after channels */
1202 creq->ssids = (void *)&creq->channels[n_channels];
1203 creq->n_channels = n_channels;
1204 creq->n_ssids = 1;
1205
1206 /* Scan all available channels */
1207 i = 0;
1208 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1209 int j;
1210
1211 if (!wiphy->bands[band])
1212 continue;
1213
1214 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
1215 /* ignore disabled channels */
1216 if (wiphy->bands[band]->channels[j].flags &
1217 IEEE80211_CHAN_DISABLED)
1218 continue;
1219
1220 creq->channels[i] = &wiphy->bands[band]->channels[j];
1221 i++;
1222 }
1223 }
1224 if (i) {
1225 /* Set real number of channels specified in creq->channels[] */
1226 creq->n_channels = i;
1227
1228 /* Scan for the SSID we're going to connect to */
1229 memcpy(creq->ssids[0].ssid, sme->ssid, sme->ssid_len);
1230 creq->ssids[0].ssid_len = sme->ssid_len;
1231 } else {
1232 /* No channels found... */
1233 kfree(creq);
1234 creq = NULL;
1235 }
1127 1236
1237 return creq;
1238}
1128 1239
1129static int lbs_cfg_connect(struct wiphy *wiphy, struct net_device *dev, 1240static int lbs_cfg_connect(struct wiphy *wiphy, struct net_device *dev,
1130 struct cfg80211_connect_params *sme) 1241 struct cfg80211_connect_params *sme)
@@ -1136,37 +1247,43 @@ static int lbs_cfg_connect(struct wiphy *wiphy, struct net_device *dev,
1136 1247
1137 lbs_deb_enter(LBS_DEB_CFG80211); 1248 lbs_deb_enter(LBS_DEB_CFG80211);
1138 1249
1139 if (sme->bssid) { 1250 if (!sme->bssid) {
1140 bss = cfg80211_get_bss(wiphy, sme->channel, sme->bssid, 1251 /* Run a scan if one isn't in-progress already and if the last
1141 sme->ssid, sme->ssid_len, 1252 * scan was done more than 2 seconds ago.
1142 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
1143 } else {
1144 /*
1145 * Here we have an impedance mismatch. The firmware command
1146 * CMD_802_11_ASSOCIATE always needs a BSSID, it cannot
1147 * connect otherwise. However, for the connect-API of
1148 * cfg80211 the bssid is purely optional. We don't get one,
1149 * except the user specifies one on the "iw" command line.
1150 *
1151 * If we don't got one, we could initiate a scan and look
1152 * for the best matching cfg80211_bss entry.
1153 *
1154 * Or, better yet, net/wireless/sme.c get's rewritten into
1155 * something more generally useful.
1156 */ 1253 */
1157 lbs_pr_err("TODO: no BSS specified\n"); 1254 if (priv->scan_req == NULL &&
1158 ret = -ENOTSUPP; 1255 time_after(jiffies, priv->last_scan + (2 * HZ))) {
1159 goto done; 1256 struct cfg80211_scan_request *creq;
1160 }
1161 1257
1258 creq = _new_connect_scan_req(wiphy, sme);
1259 if (!creq) {
1260 ret = -EINVAL;
1261 goto done;
1262 }
1263
1264 lbs_deb_assoc("assoc: scanning for compatible AP\n");
1265 _internal_start_scan(priv, true, creq);
1266 }
1267
1268 /* Wait for any in-progress scan to complete */
1269 lbs_deb_assoc("assoc: waiting for scan to complete\n");
1270 wait_event_interruptible_timeout(priv->scan_q,
1271 (priv->scan_req == NULL),
1272 (15 * HZ));
1273 lbs_deb_assoc("assoc: scanning competed\n");
1274 }
1162 1275
1276 /* Find the BSS we want using available scan results */
1277 bss = cfg80211_get_bss(wiphy, sme->channel, sme->bssid,
1278 sme->ssid, sme->ssid_len,
1279 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
1163 if (!bss) { 1280 if (!bss) {
1164 lbs_pr_err("assicate: bss %pM not in scan results\n", 1281 lbs_pr_err("assoc: bss %pM not in scan results\n",
1165 sme->bssid); 1282 sme->bssid);
1166 ret = -ENOENT; 1283 ret = -ENOENT;
1167 goto done; 1284 goto done;
1168 } 1285 }
1169 lbs_deb_assoc("trying %pM", sme->bssid); 1286 lbs_deb_assoc("trying %pM\n", bss->bssid);
1170 lbs_deb_assoc("cipher 0x%x, key index %d, key len %d\n", 1287 lbs_deb_assoc("cipher 0x%x, key index %d, key len %d\n",
1171 sme->crypto.cipher_group, 1288 sme->crypto.cipher_group,
1172 sme->key_idx, sme->key_len); 1289 sme->key_idx, sme->key_len);
@@ -1229,7 +1346,7 @@ static int lbs_cfg_connect(struct wiphy *wiphy, struct net_device *dev,
1229 lbs_set_radio(priv, preamble, 1); 1346 lbs_set_radio(priv, preamble, 1);
1230 1347
1231 /* Do the actual association */ 1348 /* Do the actual association */
1232 lbs_associate(priv, bss, sme); 1349 ret = lbs_associate(priv, bss, sme);
1233 1350
1234 done: 1351 done:
1235 if (bss) 1352 if (bss)
diff --git a/drivers/net/wireless/libertas/dev.h b/drivers/net/wireless/libertas/dev.h
index 3c7e255e18c7..f062ed583901 100644
--- a/drivers/net/wireless/libertas/dev.h
+++ b/drivers/net/wireless/libertas/dev.h
@@ -161,6 +161,11 @@ struct lbs_private {
161 /** Scanning */ 161 /** Scanning */
162 struct delayed_work scan_work; 162 struct delayed_work scan_work;
163 int scan_channel; 163 int scan_channel;
164 /* Queue of things waiting for scan completion */
165 wait_queue_head_t scan_q;
166 /* Whether the scan was initiated internally and not by cfg80211 */
167 bool internal_scan;
168 unsigned long last_scan;
164}; 169};
165 170
166extern struct cmd_confirm_sleep confirm_sleep; 171extern struct cmd_confirm_sleep confirm_sleep;
diff --git a/drivers/net/wireless/libertas/if_sdio.c b/drivers/net/wireless/libertas/if_sdio.c
index 6e71346a7550..ba854c70ab94 100644
--- a/drivers/net/wireless/libertas/if_sdio.c
+++ b/drivers/net/wireless/libertas/if_sdio.c
@@ -125,6 +125,8 @@ struct if_sdio_card {
125 125
126 const char *helper; 126 const char *helper;
127 const char *firmware; 127 const char *firmware;
128 bool helper_allocated;
129 bool firmware_allocated;
128 130
129 u8 buffer[65536]; 131 u8 buffer[65536];
130 132
@@ -984,16 +986,34 @@ static int if_sdio_probe(struct sdio_func *func,
984 card->helper = if_sdio_models[i].helper; 986 card->helper = if_sdio_models[i].helper;
985 card->firmware = if_sdio_models[i].firmware; 987 card->firmware = if_sdio_models[i].firmware;
986 988
989 kparam_block_sysfs_write(helper_name);
987 if (lbs_helper_name) { 990 if (lbs_helper_name) {
991 char *helper = kstrdup(lbs_helper_name, GFP_KERNEL);
992 if (!helper) {
993 kparam_unblock_sysfs_write(helper_name);
994 ret = -ENOMEM;
995 goto free;
996 }
988 lbs_deb_sdio("overriding helper firmware: %s\n", 997 lbs_deb_sdio("overriding helper firmware: %s\n",
989 lbs_helper_name); 998 lbs_helper_name);
990 card->helper = lbs_helper_name; 999 card->helper = helper;
1000 card->helper_allocated = true;
991 } 1001 }
1002 kparam_unblock_sysfs_write(helper_name);
992 1003
1004 kparam_block_sysfs_write(fw_name);
993 if (lbs_fw_name) { 1005 if (lbs_fw_name) {
1006 char *fw_name = kstrdup(lbs_fw_name, GFP_KERNEL);
1007 if (!fw_name) {
1008 kparam_unblock_sysfs_write(fw_name);
1009 ret = -ENOMEM;
1010 goto free;
1011 }
994 lbs_deb_sdio("overriding firmware: %s\n", lbs_fw_name); 1012 lbs_deb_sdio("overriding firmware: %s\n", lbs_fw_name);
995 card->firmware = lbs_fw_name; 1013 card->firmware = fw_name;
1014 card->firmware_allocated = true;
996 } 1015 }
1016 kparam_unblock_sysfs_write(fw_name);
997 1017
998 sdio_claim_host(func); 1018 sdio_claim_host(func);
999 1019
@@ -1127,6 +1147,10 @@ free:
1127 kfree(packet); 1147 kfree(packet);
1128 } 1148 }
1129 1149
1150 if (card->helper_allocated)
1151 kfree(card->helper);
1152 if (card->firmware_allocated)
1153 kfree(card->firmware);
1130 kfree(card); 1154 kfree(card);
1131 1155
1132 goto out; 1156 goto out;
@@ -1177,6 +1201,10 @@ static void if_sdio_remove(struct sdio_func *func)
1177 kfree(packet); 1201 kfree(packet);
1178 } 1202 }
1179 1203
1204 if (card->helper_allocated)
1205 kfree(card->helper);
1206 if (card->firmware_allocated)
1207 kfree(card->firmware);
1180 kfree(card); 1208 kfree(card);
1181 1209
1182 lbs_deb_leave(LBS_DEB_SDIO); 1210 lbs_deb_leave(LBS_DEB_SDIO);
diff --git a/drivers/net/wireless/libertas/if_usb.c b/drivers/net/wireless/libertas/if_usb.c
index 07ece9d26c63..3ff61063671a 100644
--- a/drivers/net/wireless/libertas/if_usb.c
+++ b/drivers/net/wireless/libertas/if_usb.c
@@ -289,10 +289,13 @@ static int if_usb_probe(struct usb_interface *intf,
289 } 289 }
290 290
291 /* Upload firmware */ 291 /* Upload firmware */
292 kparam_block_sysfs_write(fw_name);
292 if (__if_usb_prog_firmware(cardp, lbs_fw_name, BOOT_CMD_FW_BY_USB)) { 293 if (__if_usb_prog_firmware(cardp, lbs_fw_name, BOOT_CMD_FW_BY_USB)) {
294 kparam_unblock_sysfs_write(fw_name);
293 lbs_deb_usbd(&udev->dev, "FW upload failed\n"); 295 lbs_deb_usbd(&udev->dev, "FW upload failed\n");
294 goto err_prog_firmware; 296 goto err_prog_firmware;
295 } 297 }
298 kparam_unblock_sysfs_write(fw_name);
296 299
297 if (!(priv = lbs_add_card(cardp, &udev->dev))) 300 if (!(priv = lbs_add_card(cardp, &udev->dev)))
298 goto err_prog_firmware; 301 goto err_prog_firmware;
diff --git a/drivers/net/wireless/libertas/main.c b/drivers/net/wireless/libertas/main.c
index 258967144b96..24958a86747b 100644
--- a/drivers/net/wireless/libertas/main.c
+++ b/drivers/net/wireless/libertas/main.c
@@ -719,6 +719,7 @@ static int lbs_init_adapter(struct lbs_private *priv)
719 priv->deep_sleep_required = 0; 719 priv->deep_sleep_required = 0;
720 priv->wakeup_dev_required = 0; 720 priv->wakeup_dev_required = 0;
721 init_waitqueue_head(&priv->ds_awake_q); 721 init_waitqueue_head(&priv->ds_awake_q);
722 init_waitqueue_head(&priv->scan_q);
722 priv->authtype_auto = 1; 723 priv->authtype_auto = 1;
723 priv->is_host_sleep_configured = 0; 724 priv->is_host_sleep_configured = 0;
724 priv->is_host_sleep_activated = 0; 725 priv->is_host_sleep_activated = 0;
diff --git a/drivers/net/wireless/libertas_tf/if_usb.c b/drivers/net/wireless/libertas_tf/if_usb.c
index b172f5d87a3b..41a4f214ade1 100644
--- a/drivers/net/wireless/libertas_tf/if_usb.c
+++ b/drivers/net/wireless/libertas_tf/if_usb.c
@@ -811,12 +811,15 @@ static int if_usb_prog_firmware(struct if_usb_card *cardp)
811 811
812 lbtf_deb_enter(LBTF_DEB_USB); 812 lbtf_deb_enter(LBTF_DEB_USB);
813 813
814 kparam_block_sysfs_write(fw_name);
814 ret = request_firmware(&cardp->fw, lbtf_fw_name, &cardp->udev->dev); 815 ret = request_firmware(&cardp->fw, lbtf_fw_name, &cardp->udev->dev);
815 if (ret < 0) { 816 if (ret < 0) {
816 pr_err("request_firmware() failed with %#x\n", ret); 817 pr_err("request_firmware() failed with %#x\n", ret);
817 pr_err("firmware %s not found\n", lbtf_fw_name); 818 pr_err("firmware %s not found\n", lbtf_fw_name);
819 kparam_unblock_sysfs_write(fw_name);
818 goto done; 820 goto done;
819 } 821 }
822 kparam_unblock_sysfs_write(fw_name);
820 823
821 if (check_fwfile_format(cardp->fw->data, cardp->fw->size)) 824 if (check_fwfile_format(cardp->fw->data, cardp->fw->size))
822 goto release_fw; 825 goto release_fw;
diff --git a/drivers/net/wireless/rt2x00/rt2x00pci.c b/drivers/net/wireless/rt2x00/rt2x00pci.c
index 19b262e1ddbe..63c2cc408e15 100644
--- a/drivers/net/wireless/rt2x00/rt2x00pci.c
+++ b/drivers/net/wireless/rt2x00/rt2x00pci.c
@@ -240,16 +240,16 @@ int rt2x00pci_probe(struct pci_dev *pci_dev, const struct pci_device_id *id)
240 struct rt2x00_dev *rt2x00dev; 240 struct rt2x00_dev *rt2x00dev;
241 int retval; 241 int retval;
242 242
243 retval = pci_request_regions(pci_dev, pci_name(pci_dev)); 243 retval = pci_enable_device(pci_dev);
244 if (retval) { 244 if (retval) {
245 ERROR_PROBE("PCI request regions failed.\n"); 245 ERROR_PROBE("Enable device failed.\n");
246 return retval; 246 return retval;
247 } 247 }
248 248
249 retval = pci_enable_device(pci_dev); 249 retval = pci_request_regions(pci_dev, pci_name(pci_dev));
250 if (retval) { 250 if (retval) {
251 ERROR_PROBE("Enable device failed.\n"); 251 ERROR_PROBE("PCI request regions failed.\n");
252 goto exit_release_regions; 252 goto exit_disable_device;
253 } 253 }
254 254
255 pci_set_master(pci_dev); 255 pci_set_master(pci_dev);
@@ -260,14 +260,14 @@ int rt2x00pci_probe(struct pci_dev *pci_dev, const struct pci_device_id *id)
260 if (dma_set_mask(&pci_dev->dev, DMA_BIT_MASK(32))) { 260 if (dma_set_mask(&pci_dev->dev, DMA_BIT_MASK(32))) {
261 ERROR_PROBE("PCI DMA not supported.\n"); 261 ERROR_PROBE("PCI DMA not supported.\n");
262 retval = -EIO; 262 retval = -EIO;
263 goto exit_disable_device; 263 goto exit_release_regions;
264 } 264 }
265 265
266 hw = ieee80211_alloc_hw(sizeof(struct rt2x00_dev), ops->hw); 266 hw = ieee80211_alloc_hw(sizeof(struct rt2x00_dev), ops->hw);
267 if (!hw) { 267 if (!hw) {
268 ERROR_PROBE("Failed to allocate hardware.\n"); 268 ERROR_PROBE("Failed to allocate hardware.\n");
269 retval = -ENOMEM; 269 retval = -ENOMEM;
270 goto exit_disable_device; 270 goto exit_release_regions;
271 } 271 }
272 272
273 pci_set_drvdata(pci_dev, hw); 273 pci_set_drvdata(pci_dev, hw);
@@ -300,13 +300,12 @@ exit_free_reg:
300exit_free_device: 300exit_free_device:
301 ieee80211_free_hw(hw); 301 ieee80211_free_hw(hw);
302 302
303exit_disable_device:
304 if (retval != -EBUSY)
305 pci_disable_device(pci_dev);
306
307exit_release_regions: 303exit_release_regions:
308 pci_release_regions(pci_dev); 304 pci_release_regions(pci_dev);
309 305
306exit_disable_device:
307 pci_disable_device(pci_dev);
308
310 pci_set_drvdata(pci_dev, NULL); 309 pci_set_drvdata(pci_dev, NULL);
311 310
312 return retval; 311 return retval;
diff --git a/drivers/net/wireless/rtl818x/rtl8180_dev.c b/drivers/net/wireless/rtl818x/rtl8180_dev.c
index 1d8178563d76..b50c39aaec05 100644
--- a/drivers/net/wireless/rtl818x/rtl8180_dev.c
+++ b/drivers/net/wireless/rtl818x/rtl8180_dev.c
@@ -695,6 +695,8 @@ static void rtl8180_beacon_work(struct work_struct *work)
695 695
696 /* grab a fresh beacon */ 696 /* grab a fresh beacon */
697 skb = ieee80211_beacon_get(dev, vif); 697 skb = ieee80211_beacon_get(dev, vif);
698 if (!skb)
699 goto resched;
698 700
699 /* 701 /*
700 * update beacon timestamp w/ TSF value 702 * update beacon timestamp w/ TSF value
diff --git a/drivers/net/wireless/wl12xx/wl1271_spi.c b/drivers/net/wireless/wl12xx/wl1271_spi.c
index 96d25fb50495..4cb99c541e2a 100644
--- a/drivers/net/wireless/wl12xx/wl1271_spi.c
+++ b/drivers/net/wireless/wl12xx/wl1271_spi.c
@@ -160,9 +160,8 @@ static void wl1271_spi_init(struct wl1271 *wl)
160 spi_message_add_tail(&t, &m); 160 spi_message_add_tail(&t, &m);
161 161
162 spi_sync(wl_to_spi(wl), &m); 162 spi_sync(wl_to_spi(wl), &m);
163 kfree(cmd);
164
165 wl1271_dump(DEBUG_SPI, "spi init -> ", cmd, WSPI_INIT_CMD_LEN); 163 wl1271_dump(DEBUG_SPI, "spi init -> ", cmd, WSPI_INIT_CMD_LEN);
164 kfree(cmd);
166} 165}
167 166
168#define WL1271_BUSY_WORD_TIMEOUT 1000 167#define WL1271_BUSY_WORD_TIMEOUT 1000
diff --git a/drivers/net/xilinx_emaclite.c b/drivers/net/xilinx_emaclite.c
index b2c2f391b29d..ecbbb688eba0 100644
--- a/drivers/net/xilinx_emaclite.c
+++ b/drivers/net/xilinx_emaclite.c
@@ -1086,7 +1086,7 @@ static void xemaclite_remove_ndev(struct net_device *ndev)
1086 * 1086 *
1087 * Return: Value of the parameter if the parameter is found, or 0 otherwise 1087 * Return: Value of the parameter if the parameter is found, or 0 otherwise
1088 */ 1088 */
1089static bool get_bool(struct of_device *ofdev, const char *s) 1089static bool get_bool(struct platform_device *ofdev, const char *s)
1090{ 1090{
1091 u32 *p = (u32 *)of_get_property(ofdev->dev.of_node, s, NULL); 1091 u32 *p = (u32 *)of_get_property(ofdev->dev.of_node, s, NULL);
1092 1092
@@ -1115,7 +1115,7 @@ static struct net_device_ops xemaclite_netdev_ops;
1115 * Return: 0, if the driver is bound to the Emaclite device, or 1115 * Return: 0, if the driver is bound to the Emaclite device, or
1116 * a negative error if there is failure. 1116 * a negative error if there is failure.
1117 */ 1117 */
1118static int __devinit xemaclite_of_probe(struct of_device *ofdev, 1118static int __devinit xemaclite_of_probe(struct platform_device *ofdev,
1119 const struct of_device_id *match) 1119 const struct of_device_id *match)
1120{ 1120{
1121 struct resource r_irq; /* Interrupt resources */ 1121 struct resource r_irq; /* Interrupt resources */
@@ -1240,7 +1240,7 @@ error2:
1240 * 1240 *
1241 * Return: 0, always. 1241 * Return: 0, always.
1242 */ 1242 */
1243static int __devexit xemaclite_of_remove(struct of_device *of_dev) 1243static int __devexit xemaclite_of_remove(struct platform_device *of_dev)
1244{ 1244{
1245 struct device *dev = &of_dev->dev; 1245 struct device *dev = &of_dev->dev;
1246 struct net_device *ndev = dev_get_drvdata(dev); 1246 struct net_device *ndev = dev_get_drvdata(dev);
diff --git a/drivers/of/device.c b/drivers/of/device.c
index 0d8a0644f540..92de0eb74aea 100644
--- a/drivers/of/device.c
+++ b/drivers/of/device.c
@@ -14,7 +14,7 @@
14 * @ids: array of of device match structures to search in 14 * @ids: array of of device match structures to search in
15 * @dev: the of device structure to match against 15 * @dev: the of device structure to match against
16 * 16 *
17 * Used by a driver to check whether an of_device present in the 17 * Used by a driver to check whether an platform_device present in the
18 * system is in its list of supported devices. 18 * system is in its list of supported devices.
19 */ 19 */
20const struct of_device_id *of_match_device(const struct of_device_id *matches, 20const struct of_device_id *of_match_device(const struct of_device_id *matches,
diff --git a/drivers/parport/parport_serial.c b/drivers/parport/parport_serial.c
index 40e208d130f5..f01e26440f11 100644
--- a/drivers/parport/parport_serial.c
+++ b/drivers/parport/parport_serial.c
@@ -342,7 +342,6 @@ static int __devinit parport_register (struct pci_dev *dev,
342 dev_dbg(&dev->dev, 342 dev_dbg(&dev->dev,
343 "PCI parallel port detected: I/O at %#lx(%#lx), IRQ %d\n", 343 "PCI parallel port detected: I/O at %#lx(%#lx), IRQ %d\n",
344 io_lo, io_hi, irq); 344 io_lo, io_hi, irq);
345 irq = PARPORT_IRQ_NONE;
346 } 345 }
347 port = parport_pc_probe_port (io_lo, io_hi, irq, 346 port = parport_pc_probe_port (io_lo, io_hi, irq,
348 PARPORT_DMA_NONE, &dev->dev, IRQF_SHARED); 347 PARPORT_DMA_NONE, &dev->dev, IRQF_SHARED);
diff --git a/drivers/parport/parport_sunbpp.c b/drivers/parport/parport_sunbpp.c
index 210a6441a066..55ba118f1cf1 100644
--- a/drivers/parport/parport_sunbpp.c
+++ b/drivers/parport/parport_sunbpp.c
@@ -286,7 +286,7 @@ static struct parport_operations parport_sunbpp_ops =
286 .owner = THIS_MODULE, 286 .owner = THIS_MODULE,
287}; 287};
288 288
289static int __devinit bpp_probe(struct of_device *op, const struct of_device_id *match) 289static int __devinit bpp_probe(struct platform_device *op, const struct of_device_id *match)
290{ 290{
291 struct parport_operations *ops; 291 struct parport_operations *ops;
292 struct bpp_regs __iomem *regs; 292 struct bpp_regs __iomem *regs;
@@ -351,7 +351,7 @@ out_unmap:
351 return err; 351 return err;
352} 352}
353 353
354static int __devexit bpp_remove(struct of_device *op) 354static int __devexit bpp_remove(struct platform_device *op)
355{ 355{
356 struct parport *p = dev_get_drvdata(&op->dev); 356 struct parport *p = dev_get_drvdata(&op->dev);
357 struct parport_operations *ops = p->ops; 357 struct parport_operations *ops = p->ops;
diff --git a/drivers/pci/intel-iommu.c b/drivers/pci/intel-iommu.c
index 6a5af18faf68..c3ceebb5be84 100644
--- a/drivers/pci/intel-iommu.c
+++ b/drivers/pci/intel-iommu.c
@@ -236,7 +236,7 @@ static inline u64 dma_pte_addr(struct dma_pte *pte)
236 return pte->val & VTD_PAGE_MASK; 236 return pte->val & VTD_PAGE_MASK;
237#else 237#else
238 /* Must have a full atomic 64-bit read */ 238 /* Must have a full atomic 64-bit read */
239 return __cmpxchg64(pte, 0ULL, 0ULL) & VTD_PAGE_MASK; 239 return __cmpxchg64(&pte->val, 0ULL, 0ULL) & VTD_PAGE_MASK;
240#endif 240#endif
241} 241}
242 242
@@ -3030,6 +3030,34 @@ static void __init iommu_exit_mempool(void)
3030 3030
3031} 3031}
3032 3032
3033static void quirk_ioat_snb_local_iommu(struct pci_dev *pdev)
3034{
3035 struct dmar_drhd_unit *drhd;
3036 u32 vtbar;
3037 int rc;
3038
3039 /* We know that this device on this chipset has its own IOMMU.
3040 * If we find it under a different IOMMU, then the BIOS is lying
3041 * to us. Hope that the IOMMU for this device is actually
3042 * disabled, and it needs no translation...
3043 */
3044 rc = pci_bus_read_config_dword(pdev->bus, PCI_DEVFN(0, 0), 0xb0, &vtbar);
3045 if (rc) {
3046 /* "can't" happen */
3047 dev_info(&pdev->dev, "failed to run vt-d quirk\n");
3048 return;
3049 }
3050 vtbar &= 0xffff0000;
3051
3052 /* we know that the this iommu should be at offset 0xa000 from vtbar */
3053 drhd = dmar_find_matched_drhd_unit(pdev);
3054 if (WARN_TAINT_ONCE(!drhd || drhd->reg_base_addr - vtbar != 0xa000,
3055 TAINT_FIRMWARE_WORKAROUND,
3056 "BIOS assigned incorrect VT-d unit for Intel(R) QuickData Technology device\n"))
3057 pdev->dev.archdata.iommu = DUMMY_DEVICE_DOMAIN_INFO;
3058}
3059DECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_SNB, quirk_ioat_snb_local_iommu);
3060
3033static void __init init_no_remapping_devices(void) 3061static void __init init_no_remapping_devices(void)
3034{ 3062{
3035 struct dmar_drhd_unit *drhd; 3063 struct dmar_drhd_unit *drhd;
diff --git a/drivers/pci/intr_remapping.c b/drivers/pci/intr_remapping.c
index 1694a0e2845b..fd1d2867cdcc 100644
--- a/drivers/pci/intr_remapping.c
+++ b/drivers/pci/intr_remapping.c
@@ -21,6 +21,8 @@ static int ir_ioapic_num, ir_hpet_num;
21int intr_remapping_enabled; 21int intr_remapping_enabled;
22 22
23static int disable_intremap; 23static int disable_intremap;
24static int disable_sourceid_checking;
25
24static __init int setup_nointremap(char *str) 26static __init int setup_nointremap(char *str)
25{ 27{
26 disable_intremap = 1; 28 disable_intremap = 1;
@@ -28,6 +30,22 @@ static __init int setup_nointremap(char *str)
28} 30}
29early_param("nointremap", setup_nointremap); 31early_param("nointremap", setup_nointremap);
30 32
33static __init int setup_intremap(char *str)
34{
35 if (!str)
36 return -EINVAL;
37
38 if (!strncmp(str, "on", 2))
39 disable_intremap = 0;
40 else if (!strncmp(str, "off", 3))
41 disable_intremap = 1;
42 else if (!strncmp(str, "nosid", 5))
43 disable_sourceid_checking = 1;
44
45 return 0;
46}
47early_param("intremap", setup_intremap);
48
31struct irq_2_iommu { 49struct irq_2_iommu {
32 struct intel_iommu *iommu; 50 struct intel_iommu *iommu;
33 u16 irte_index; 51 u16 irte_index;
@@ -453,6 +471,8 @@ int free_irte(int irq)
453static void set_irte_sid(struct irte *irte, unsigned int svt, 471static void set_irte_sid(struct irte *irte, unsigned int svt,
454 unsigned int sq, unsigned int sid) 472 unsigned int sq, unsigned int sid)
455{ 473{
474 if (disable_sourceid_checking)
475 svt = SVT_NO_VERIFY;
456 irte->svt = svt; 476 irte->svt = svt;
457 irte->sq = sq; 477 irte->sq = sq;
458 irte->sid = sid; 478 irte->sid = sid;
diff --git a/drivers/pcmcia/Kconfig b/drivers/pcmcia/Kconfig
index c988514eb551..c80a7a6e7698 100644
--- a/drivers/pcmcia/Kconfig
+++ b/drivers/pcmcia/Kconfig
@@ -215,7 +215,7 @@ config PCMCIA_PXA2XX
215 depends on (ARCH_LUBBOCK || MACH_MAINSTONE || PXA_SHARPSL \ 215 depends on (ARCH_LUBBOCK || MACH_MAINSTONE || PXA_SHARPSL \
216 || MACH_ARMCORE || ARCH_PXA_PALM || TRIZEPS_PCMCIA \ 216 || MACH_ARMCORE || ARCH_PXA_PALM || TRIZEPS_PCMCIA \
217 || ARCOM_PCMCIA || ARCH_PXA_ESERIES || MACH_STARGATE2 \ 217 || ARCOM_PCMCIA || ARCH_PXA_ESERIES || MACH_STARGATE2 \
218 || MACH_VPAC270) 218 || MACH_VPAC270 || MACH_BALLOON3)
219 select PCMCIA_SOC_COMMON 219 select PCMCIA_SOC_COMMON
220 help 220 help
221 Say Y here to include support for the PXA2xx PCMCIA controller 221 Say Y here to include support for the PXA2xx PCMCIA controller
diff --git a/drivers/pcmcia/Makefile b/drivers/pcmcia/Makefile
index 7a2b1604bf1c..8d9386a22eb3 100644
--- a/drivers/pcmcia/Makefile
+++ b/drivers/pcmcia/Makefile
@@ -69,6 +69,7 @@ pxa2xx-obj-$(CONFIG_MACH_PALMLD) += pxa2xx_palmld.o
69pxa2xx-obj-$(CONFIG_MACH_E740) += pxa2xx_e740.o 69pxa2xx-obj-$(CONFIG_MACH_E740) += pxa2xx_e740.o
70pxa2xx-obj-$(CONFIG_MACH_STARGATE2) += pxa2xx_stargate2.o 70pxa2xx-obj-$(CONFIG_MACH_STARGATE2) += pxa2xx_stargate2.o
71pxa2xx-obj-$(CONFIG_MACH_VPAC270) += pxa2xx_vpac270.o 71pxa2xx-obj-$(CONFIG_MACH_VPAC270) += pxa2xx_vpac270.o
72pxa2xx-obj-$(CONFIG_MACH_BALLOON3) += pxa2xx_balloon3.o
72 73
73obj-$(CONFIG_PCMCIA_PXA2XX) += pxa2xx_base.o $(pxa2xx-obj-y) 74obj-$(CONFIG_PCMCIA_PXA2XX) += pxa2xx_base.o $(pxa2xx-obj-y)
74 75
diff --git a/drivers/pcmcia/electra_cf.c b/drivers/pcmcia/electra_cf.c
index f94d8281cfb0..546d3024b6f0 100644
--- a/drivers/pcmcia/electra_cf.c
+++ b/drivers/pcmcia/electra_cf.c
@@ -44,7 +44,7 @@ struct electra_cf_socket {
44 unsigned present:1; 44 unsigned present:1;
45 unsigned active:1; 45 unsigned active:1;
46 46
47 struct of_device *ofdev; 47 struct platform_device *ofdev;
48 unsigned long mem_phys; 48 unsigned long mem_phys;
49 void __iomem * mem_base; 49 void __iomem * mem_base;
50 unsigned long mem_size; 50 unsigned long mem_size;
@@ -181,7 +181,7 @@ static struct pccard_operations electra_cf_ops = {
181 .set_mem_map = electra_cf_set_mem_map, 181 .set_mem_map = electra_cf_set_mem_map,
182}; 182};
183 183
184static int __devinit electra_cf_probe(struct of_device *ofdev, 184static int __devinit electra_cf_probe(struct platform_device *ofdev,
185 const struct of_device_id *match) 185 const struct of_device_id *match)
186{ 186{
187 struct device *device = &ofdev->dev; 187 struct device *device = &ofdev->dev;
@@ -325,7 +325,7 @@ fail1:
325 325
326} 326}
327 327
328static int __devexit electra_cf_remove(struct of_device *ofdev) 328static int __devexit electra_cf_remove(struct platform_device *ofdev)
329{ 329{
330 struct device *device = &ofdev->dev; 330 struct device *device = &ofdev->dev;
331 struct electra_cf_socket *cf; 331 struct electra_cf_socket *cf;
diff --git a/drivers/pcmcia/m8xx_pcmcia.c b/drivers/pcmcia/m8xx_pcmcia.c
index f2f90a7d3e12..f0ecad99ce81 100644
--- a/drivers/pcmcia/m8xx_pcmcia.c
+++ b/drivers/pcmcia/m8xx_pcmcia.c
@@ -1149,7 +1149,7 @@ static struct pccard_operations m8xx_services = {
1149 .set_mem_map = m8xx_set_mem_map, 1149 .set_mem_map = m8xx_set_mem_map,
1150}; 1150};
1151 1151
1152static int __init m8xx_probe(struct of_device *ofdev, 1152static int __init m8xx_probe(struct platform_device *ofdev,
1153 const struct of_device_id *match) 1153 const struct of_device_id *match)
1154{ 1154{
1155 struct pcmcia_win *w; 1155 struct pcmcia_win *w;
@@ -1249,7 +1249,7 @@ static int __init m8xx_probe(struct of_device *ofdev,
1249 return 0; 1249 return 0;
1250} 1250}
1251 1251
1252static int m8xx_remove(struct of_device *ofdev) 1252static int m8xx_remove(struct platform_device *ofdev)
1253{ 1253{
1254 u32 m, i; 1254 u32 m, i;
1255 struct pcmcia_win *w; 1255 struct pcmcia_win *w;
diff --git a/drivers/pcmcia/pxa2xx_balloon3.c b/drivers/pcmcia/pxa2xx_balloon3.c
new file mode 100644
index 000000000000..dbbdd0063202
--- /dev/null
+++ b/drivers/pcmcia/pxa2xx_balloon3.c
@@ -0,0 +1,158 @@
1/*
2 * linux/drivers/pcmcia/pxa2xx_balloon3.c
3 *
4 * Balloon3 PCMCIA specific routines.
5 *
6 * Author: Nick Bane
7 * Created: June, 2006
8 * Copyright: Toby Churchill Ltd
9 * Derived from pxa2xx_mainstone.c, by Nico Pitre
10 *
11 * Various modification by Marek Vasut <marek.vasut@gmail.com>
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License version 2 as
15 * published by the Free Software Foundation.
16 */
17
18#include <linux/module.h>
19#include <linux/gpio.h>
20#include <linux/errno.h>
21#include <linux/interrupt.h>
22#include <linux/platform_device.h>
23#include <linux/irq.h>
24#include <linux/io.h>
25
26#include <mach/balloon3.h>
27
28#include "soc_common.h"
29
30/*
31 * These are a list of interrupt sources that provokes a polled
32 * check of status
33 */
34static struct pcmcia_irqs irqs[] = {
35 { 0, BALLOON3_S0_CD_IRQ, "PCMCIA0 CD" },
36 { 0, BALLOON3_BP_NSTSCHG_IRQ, "PCMCIA0 STSCHG" },
37};
38
39static int balloon3_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
40{
41 uint16_t ver;
42 int ret;
43 static void __iomem *fpga_ver;
44
45 ver = __raw_readw(BALLOON3_FPGA_VER);
46 if (ver > 0x0201)
47 pr_warn("The FPGA code, version 0x%04x, is newer than rel-0.3. "
48 "PCMCIA/CF support might be broken in this version!",
49 ver);
50
51 skt->socket.pci_irq = BALLOON3_BP_CF_NRDY_IRQ;
52 return soc_pcmcia_request_irqs(skt, irqs, ARRAY_SIZE(irqs));
53}
54
55static void balloon3_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
56{
57 soc_pcmcia_free_irqs(skt, irqs, ARRAY_SIZE(irqs));
58}
59
60static unsigned long balloon3_pcmcia_status[2] = {
61 BALLOON3_CF_nSTSCHG_BVD1,
62 BALLOON3_CF_nSTSCHG_BVD1
63};
64
65static void balloon3_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
66 struct pcmcia_state *state)
67{
68 uint16_t status;
69 int flip;
70
71 /* This actually reads the STATUS register */
72 status = __raw_readw(BALLOON3_CF_STATUS_REG);
73 flip = (status ^ balloon3_pcmcia_status[skt->nr])
74 & BALLOON3_CF_nSTSCHG_BVD1;
75 /*
76 * Workaround for STSCHG which can't be deasserted:
77 * We therefore disable/enable corresponding IRQs
78 * as needed to avoid IRQ locks.
79 */
80 if (flip) {
81 balloon3_pcmcia_status[skt->nr] = status;
82 if (status & BALLOON3_CF_nSTSCHG_BVD1)
83 enable_irq(BALLOON3_BP_NSTSCHG_IRQ);
84 else
85 disable_irq(BALLOON3_BP_NSTSCHG_IRQ);
86 }
87
88 state->detect = !gpio_get_value(BALLOON3_GPIO_S0_CD);
89 state->ready = !!(status & BALLOON3_CF_nIRQ);
90 state->bvd1 = !!(status & BALLOON3_CF_nSTSCHG_BVD1);
91 state->bvd2 = 0; /* not available */
92 state->vs_3v = 1; /* Always true its a CF card */
93 state->vs_Xv = 0; /* not available */
94 state->wrprot = 0; /* not available */
95}
96
97static int balloon3_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
98 const socket_state_t *state)
99{
100 __raw_writew((state->flags & SS_RESET) ? BALLOON3_CF_RESET : 0,
101 BALLOON3_CF_CONTROL_REG);
102 return 0;
103}
104
105static void balloon3_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
106{
107}
108
109static void balloon3_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
110{
111}
112
113static struct pcmcia_low_level balloon3_pcmcia_ops = {
114 .owner = THIS_MODULE,
115 .hw_init = balloon3_pcmcia_hw_init,
116 .hw_shutdown = balloon3_pcmcia_hw_shutdown,
117 .socket_state = balloon3_pcmcia_socket_state,
118 .configure_socket = balloon3_pcmcia_configure_socket,
119 .socket_init = balloon3_pcmcia_socket_init,
120 .socket_suspend = balloon3_pcmcia_socket_suspend,
121 .first = 0,
122 .nr = 1,
123};
124
125static struct platform_device *balloon3_pcmcia_device;
126
127static int __init balloon3_pcmcia_init(void)
128{
129 int ret;
130
131 balloon3_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
132 if (!balloon3_pcmcia_device)
133 return -ENOMEM;
134
135 ret = platform_device_add_data(balloon3_pcmcia_device,
136 &balloon3_pcmcia_ops, sizeof(balloon3_pcmcia_ops));
137
138 if (!ret)
139 ret = platform_device_add(balloon3_pcmcia_device);
140
141 if (ret)
142 platform_device_put(balloon3_pcmcia_device);
143
144 return ret;
145}
146
147static void __exit balloon3_pcmcia_exit(void)
148{
149 platform_device_unregister(balloon3_pcmcia_device);
150}
151
152module_init(balloon3_pcmcia_init);
153module_exit(balloon3_pcmcia_exit);
154
155MODULE_LICENSE("GPL");
156MODULE_AUTHOR("Nick Bane <nick@cecomputing.co.uk>");
157MODULE_ALIAS("platform:pxa2xx-pcmcia");
158MODULE_DESCRIPTION("Balloon3 board CF/PCMCIA driver");
diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
index 79baa6368f79..044f430f3b43 100644
--- a/drivers/platform/x86/Kconfig
+++ b/drivers/platform/x86/Kconfig
@@ -219,6 +219,13 @@ config SONYPI_COMPAT
219 ---help--- 219 ---help---
220 Build the sonypi driver compatibility code into the sony-laptop driver. 220 Build the sonypi driver compatibility code into the sony-laptop driver.
221 221
222config IDEAPAD_ACPI
223 tristate "Lenovo IdeaPad ACPI Laptop Extras"
224 depends on ACPI
225 depends on RFKILL
226 help
227 This is a driver for the rfkill switches on Lenovo IdeaPad netbooks.
228
222config THINKPAD_ACPI 229config THINKPAD_ACPI
223 tristate "ThinkPad ACPI Laptop Extras" 230 tristate "ThinkPad ACPI Laptop Extras"
224 depends on ACPI 231 depends on ACPI
diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile
index 4744c7744ffa..85fb2b84f57e 100644
--- a/drivers/platform/x86/Makefile
+++ b/drivers/platform/x86/Makefile
@@ -15,6 +15,7 @@ obj-$(CONFIG_ACERHDF) += acerhdf.o
15obj-$(CONFIG_HP_WMI) += hp-wmi.o 15obj-$(CONFIG_HP_WMI) += hp-wmi.o
16obj-$(CONFIG_TC1100_WMI) += tc1100-wmi.o 16obj-$(CONFIG_TC1100_WMI) += tc1100-wmi.o
17obj-$(CONFIG_SONY_LAPTOP) += sony-laptop.o 17obj-$(CONFIG_SONY_LAPTOP) += sony-laptop.o
18obj-$(CONFIG_IDEAPAD_ACPI) += ideapad_acpi.o
18obj-$(CONFIG_THINKPAD_ACPI) += thinkpad_acpi.o 19obj-$(CONFIG_THINKPAD_ACPI) += thinkpad_acpi.o
19obj-$(CONFIG_FUJITSU_LAPTOP) += fujitsu-laptop.o 20obj-$(CONFIG_FUJITSU_LAPTOP) += fujitsu-laptop.o
20obj-$(CONFIG_PANASONIC_LAPTOP) += panasonic-laptop.o 21obj-$(CONFIG_PANASONIC_LAPTOP) += panasonic-laptop.o
diff --git a/drivers/platform/x86/ideapad_acpi.c b/drivers/platform/x86/ideapad_acpi.c
new file mode 100644
index 000000000000..798496353e8c
--- /dev/null
+++ b/drivers/platform/x86/ideapad_acpi.c
@@ -0,0 +1,306 @@
1/*
2 * ideapad_acpi.c - Lenovo IdeaPad ACPI Extras
3 *
4 * Copyright © 2010 Intel Corporation
5 * Copyright © 2010 David Woodhouse <dwmw2@infradead.org>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 * 02110-1301, USA.
21 */
22
23#include <linux/kernel.h>
24#include <linux/module.h>
25#include <linux/init.h>
26#include <linux/types.h>
27#include <acpi/acpi_bus.h>
28#include <acpi/acpi_drivers.h>
29#include <linux/rfkill.h>
30
31#define IDEAPAD_DEV_CAMERA 0
32#define IDEAPAD_DEV_WLAN 1
33#define IDEAPAD_DEV_BLUETOOTH 2
34#define IDEAPAD_DEV_3G 3
35#define IDEAPAD_DEV_KILLSW 4
36
37struct ideapad_private {
38 struct rfkill *rfk[5];
39};
40
41static struct {
42 char *name;
43 int type;
44} ideapad_rfk_data[] = {
45 /* camera has no rfkill */
46 { "ideapad_wlan", RFKILL_TYPE_WLAN },
47 { "ideapad_bluetooth", RFKILL_TYPE_BLUETOOTH },
48 { "ideapad_3g", RFKILL_TYPE_WWAN },
49 { "ideapad_killsw", RFKILL_TYPE_WLAN }
50};
51
52static int ideapad_dev_exists(int device)
53{
54 acpi_status status;
55 union acpi_object in_param;
56 struct acpi_object_list input = { 1, &in_param };
57 struct acpi_buffer output;
58 union acpi_object out_obj;
59
60 output.length = sizeof(out_obj);
61 output.pointer = &out_obj;
62
63 in_param.type = ACPI_TYPE_INTEGER;
64 in_param.integer.value = device + 1;
65
66 status = acpi_evaluate_object(NULL, "\\_SB_.DECN", &input, &output);
67 if (ACPI_FAILURE(status)) {
68 printk(KERN_WARNING "IdeaPAD \\_SB_.DECN method failed %d. Is this an IdeaPAD?\n", status);
69 return -ENODEV;
70 }
71 if (out_obj.type != ACPI_TYPE_INTEGER) {
72 printk(KERN_WARNING "IdeaPAD \\_SB_.DECN method returned unexpected type\n");
73 return -ENODEV;
74 }
75 return out_obj.integer.value;
76}
77
78static int ideapad_dev_get_state(int device)
79{
80 acpi_status status;
81 union acpi_object in_param;
82 struct acpi_object_list input = { 1, &in_param };
83 struct acpi_buffer output;
84 union acpi_object out_obj;
85
86 output.length = sizeof(out_obj);
87 output.pointer = &out_obj;
88
89 in_param.type = ACPI_TYPE_INTEGER;
90 in_param.integer.value = device + 1;
91
92 status = acpi_evaluate_object(NULL, "\\_SB_.GECN", &input, &output);
93 if (ACPI_FAILURE(status)) {
94 printk(KERN_WARNING "IdeaPAD \\_SB_.GECN method failed %d\n", status);
95 return -ENODEV;
96 }
97 if (out_obj.type != ACPI_TYPE_INTEGER) {
98 printk(KERN_WARNING "IdeaPAD \\_SB_.GECN method returned unexpected type\n");
99 return -ENODEV;
100 }
101 return out_obj.integer.value;
102}
103
104static int ideapad_dev_set_state(int device, int state)
105{
106 acpi_status status;
107 union acpi_object in_params[2];
108 struct acpi_object_list input = { 2, in_params };
109
110 in_params[0].type = ACPI_TYPE_INTEGER;
111 in_params[0].integer.value = device + 1;
112 in_params[1].type = ACPI_TYPE_INTEGER;
113 in_params[1].integer.value = state;
114
115 status = acpi_evaluate_object(NULL, "\\_SB_.SECN", &input, NULL);
116 if (ACPI_FAILURE(status)) {
117 printk(KERN_WARNING "IdeaPAD \\_SB_.SECN method failed %d\n", status);
118 return -ENODEV;
119 }
120 return 0;
121}
122static ssize_t show_ideapad_cam(struct device *dev,
123 struct device_attribute *attr,
124 char *buf)
125{
126 int state = ideapad_dev_get_state(IDEAPAD_DEV_CAMERA);
127 if (state < 0)
128 return state;
129
130 return sprintf(buf, "%d\n", state);
131}
132
133static ssize_t store_ideapad_cam(struct device *dev,
134 struct device_attribute *attr,
135 const char *buf, size_t count)
136{
137 int ret, state;
138
139 if (!count)
140 return 0;
141 if (sscanf(buf, "%i", &state) != 1)
142 return -EINVAL;
143 ret = ideapad_dev_set_state(IDEAPAD_DEV_CAMERA, !!state);
144 if (ret < 0)
145 return ret;
146 return count;
147}
148
149static DEVICE_ATTR(camera_power, 0644, show_ideapad_cam, store_ideapad_cam);
150
151static int ideapad_rfk_set(void *data, bool blocked)
152{
153 int device = (unsigned long)data;
154
155 if (device == IDEAPAD_DEV_KILLSW)
156 return -EINVAL;
157 return ideapad_dev_set_state(device, !blocked);
158}
159
160static struct rfkill_ops ideapad_rfk_ops = {
161 .set_block = ideapad_rfk_set,
162};
163
164static void ideapad_sync_rfk_state(struct acpi_device *adevice)
165{
166 struct ideapad_private *priv = dev_get_drvdata(&adevice->dev);
167 int hw_blocked = !ideapad_dev_get_state(IDEAPAD_DEV_KILLSW);
168 int i;
169
170 rfkill_set_hw_state(priv->rfk[IDEAPAD_DEV_KILLSW], hw_blocked);
171 for (i = IDEAPAD_DEV_WLAN; i < IDEAPAD_DEV_KILLSW; i++)
172 if (priv->rfk[i])
173 rfkill_set_hw_state(priv->rfk[i], hw_blocked);
174 if (hw_blocked)
175 return;
176
177 for (i = IDEAPAD_DEV_WLAN; i < IDEAPAD_DEV_KILLSW; i++)
178 if (priv->rfk[i])
179 rfkill_set_sw_state(priv->rfk[i], !ideapad_dev_get_state(i));
180}
181
182static int ideapad_register_rfkill(struct acpi_device *adevice, int dev)
183{
184 struct ideapad_private *priv = dev_get_drvdata(&adevice->dev);
185 int ret;
186
187 priv->rfk[dev] = rfkill_alloc(ideapad_rfk_data[dev-1].name, &adevice->dev,
188 ideapad_rfk_data[dev-1].type, &ideapad_rfk_ops,
189 (void *)(long)dev);
190 if (!priv->rfk[dev])
191 return -ENOMEM;
192
193 ret = rfkill_register(priv->rfk[dev]);
194 if (ret) {
195 rfkill_destroy(priv->rfk[dev]);
196 return ret;
197 }
198 return 0;
199}
200
201static void ideapad_unregister_rfkill(struct acpi_device *adevice, int dev)
202{
203 struct ideapad_private *priv = dev_get_drvdata(&adevice->dev);
204
205 if (!priv->rfk[dev])
206 return;
207
208 rfkill_unregister(priv->rfk[dev]);
209 rfkill_destroy(priv->rfk[dev]);
210}
211
212static const struct acpi_device_id ideapad_device_ids[] = {
213 { "VPC2004", 0},
214 { "", 0},
215};
216MODULE_DEVICE_TABLE(acpi, ideapad_device_ids);
217
218static int ideapad_acpi_add(struct acpi_device *adevice)
219{
220 int i;
221 int devs_present[5];
222 struct ideapad_private *priv;
223
224 for (i = IDEAPAD_DEV_CAMERA; i < IDEAPAD_DEV_KILLSW; i++) {
225 devs_present[i] = ideapad_dev_exists(i);
226 if (devs_present[i] < 0)
227 return devs_present[i];
228 }
229
230 /* The hardware switch is always present */
231 devs_present[IDEAPAD_DEV_KILLSW] = 1;
232
233 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
234 if (!priv)
235 return -ENOMEM;
236
237 if (devs_present[IDEAPAD_DEV_CAMERA]) {
238 int ret = device_create_file(&adevice->dev, &dev_attr_camera_power);
239 if (ret) {
240 kfree(priv);
241 return ret;
242 }
243 }
244
245 dev_set_drvdata(&adevice->dev, priv);
246 for (i = IDEAPAD_DEV_WLAN; i <= IDEAPAD_DEV_KILLSW; i++) {
247 if (!devs_present[i])
248 continue;
249
250 ideapad_register_rfkill(adevice, i);
251 }
252 ideapad_sync_rfk_state(adevice);
253 return 0;
254}
255
256static int ideapad_acpi_remove(struct acpi_device *adevice, int type)
257{
258 struct ideapad_private *priv = dev_get_drvdata(&adevice->dev);
259 int i;
260
261 device_remove_file(&adevice->dev, &dev_attr_camera_power);
262
263 for (i = IDEAPAD_DEV_WLAN; i <= IDEAPAD_DEV_KILLSW; i++)
264 ideapad_unregister_rfkill(adevice, i);
265
266 dev_set_drvdata(&adevice->dev, NULL);
267 kfree(priv);
268 return 0;
269}
270
271static void ideapad_acpi_notify(struct acpi_device *adevice, u32 event)
272{
273 ideapad_sync_rfk_state(adevice);
274}
275
276static struct acpi_driver ideapad_acpi_driver = {
277 .name = "ideapad_acpi",
278 .class = "IdeaPad",
279 .ids = ideapad_device_ids,
280 .ops.add = ideapad_acpi_add,
281 .ops.remove = ideapad_acpi_remove,
282 .ops.notify = ideapad_acpi_notify,
283 .owner = THIS_MODULE,
284};
285
286
287static int __init ideapad_acpi_module_init(void)
288{
289 acpi_bus_register_driver(&ideapad_acpi_driver);
290
291 return 0;
292}
293
294
295static void __exit ideapad_acpi_module_exit(void)
296{
297 acpi_bus_unregister_driver(&ideapad_acpi_driver);
298
299}
300
301MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
302MODULE_DESCRIPTION("IdeaPad ACPI Extras");
303MODULE_LICENSE("GPL");
304
305module_init(ideapad_acpi_module_init);
306module_exit(ideapad_acpi_module_exit);
diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index 1e5506be39b4..07343568a12e 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -136,6 +136,12 @@ config BATTERY_Z2
136 help 136 help
137 Say Y to include support for the battery on the Zipit Z2. 137 Say Y to include support for the battery on the Zipit Z2.
138 138
139config BATTERY_S3C_ADC
140 tristate "Battery driver for Samsung ADC based monitoring"
141 depends on S3C_ADC
142 help
143 Say Y here to enable support for iPAQ h1930/h1940/rx1950 battery
144
139config CHARGER_PCF50633 145config CHARGER_PCF50633
140 tristate "NXP PCF50633 MBC" 146 tristate "NXP PCF50633 MBC"
141 depends on MFD_PCF50633 147 depends on MFD_PCF50633
@@ -153,4 +159,11 @@ config BATTERY_JZ4740
153 This driver can be build as a module. If so, the module will be 159 This driver can be build as a module. If so, the module will be
154 called jz4740-battery. 160 called jz4740-battery.
155 161
162config BATTERY_INTEL_MID
163 tristate "Battery driver for Intel MID platforms"
164 depends on INTEL_SCU_IPC && SPI
165 help
166 Say Y here to enable the battery driver on Intel MID
167 platforms.
168
156endif # POWER_SUPPLY 169endif # POWER_SUPPLY
diff --git a/drivers/power/Makefile b/drivers/power/Makefile
index cf95009d9bcd..10143aaf4ee3 100644
--- a/drivers/power/Makefile
+++ b/drivers/power/Makefile
@@ -33,5 +33,7 @@ obj-$(CONFIG_BATTERY_BQ27x00) += bq27x00_battery.o
33obj-$(CONFIG_BATTERY_DA9030) += da9030_battery.o 33obj-$(CONFIG_BATTERY_DA9030) += da9030_battery.o
34obj-$(CONFIG_BATTERY_MAX17040) += max17040_battery.o 34obj-$(CONFIG_BATTERY_MAX17040) += max17040_battery.o
35obj-$(CONFIG_BATTERY_Z2) += z2_battery.o 35obj-$(CONFIG_BATTERY_Z2) += z2_battery.o
36obj-$(CONFIG_BATTERY_S3C_ADC) += s3c_adc_battery.o
36obj-$(CONFIG_CHARGER_PCF50633) += pcf50633-charger.o 37obj-$(CONFIG_CHARGER_PCF50633) += pcf50633-charger.o
37obj-$(CONFIG_BATTERY_JZ4740) += jz4740-battery.o 38obj-$(CONFIG_BATTERY_JZ4740) += jz4740-battery.o
39obj-$(CONFIG_BATTERY_INTEL_MID) += intel_mid_battery.o
diff --git a/drivers/power/intel_mid_battery.c b/drivers/power/intel_mid_battery.c
new file mode 100644
index 000000000000..c61ffec2ff10
--- /dev/null
+++ b/drivers/power/intel_mid_battery.c
@@ -0,0 +1,799 @@
1/*
2 * intel_mid_battery.c - Intel MID PMIC Battery Driver
3 *
4 * Copyright (C) 2009 Intel Corporation
5 *
6 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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; version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20 *
21 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
22 * Author: Nithish Mahalingam <nithish.mahalingam@intel.com>
23 */
24
25#include <linux/module.h>
26#include <linux/init.h>
27#include <linux/err.h>
28#include <linux/interrupt.h>
29#include <linux/workqueue.h>
30#include <linux/jiffies.h>
31#include <linux/param.h>
32#include <linux/device.h>
33#include <linux/spi/spi.h>
34#include <linux/platform_device.h>
35#include <linux/power_supply.h>
36
37#include <asm/intel_scu_ipc.h>
38
39#define DRIVER_NAME "pmic_battery"
40
41/*********************************************************************
42 * Generic defines
43 *********************************************************************/
44
45static int debug;
46module_param(debug, int, 0444);
47MODULE_PARM_DESC(debug, "Flag to enable PMIC Battery debug messages.");
48
49#define PMIC_BATT_DRV_INFO_UPDATED 1
50#define PMIC_BATT_PRESENT 1
51#define PMIC_BATT_NOT_PRESENT 0
52#define PMIC_USB_PRESENT PMIC_BATT_PRESENT
53#define PMIC_USB_NOT_PRESENT PMIC_BATT_NOT_PRESENT
54
55/* pmic battery register related */
56#define PMIC_BATT_CHR_SCHRGINT_ADDR 0xD2
57#define PMIC_BATT_CHR_SBATOVP_MASK (1 << 1)
58#define PMIC_BATT_CHR_STEMP_MASK (1 << 2)
59#define PMIC_BATT_CHR_SCOMP_MASK (1 << 3)
60#define PMIC_BATT_CHR_SUSBDET_MASK (1 << 4)
61#define PMIC_BATT_CHR_SBATDET_MASK (1 << 5)
62#define PMIC_BATT_CHR_SDCLMT_MASK (1 << 6)
63#define PMIC_BATT_CHR_SUSBOVP_MASK (1 << 7)
64#define PMIC_BATT_CHR_EXCPT_MASK 0xC6
65#define PMIC_BATT_ADC_ACCCHRG_MASK (1 << 31)
66#define PMIC_BATT_ADC_ACCCHRGVAL_MASK 0x7FFFFFFF
67
68/* pmic ipc related */
69#define PMIC_BATT_CHR_IPC_FCHRG_SUBID 0x4
70#define PMIC_BATT_CHR_IPC_TCHRG_SUBID 0x6
71
72/* types of battery charging */
73enum batt_charge_type {
74 BATT_USBOTG_500MA_CHARGE,
75 BATT_USBOTG_TRICKLE_CHARGE,
76};
77
78/* valid battery events */
79enum batt_event {
80 BATT_EVENT_BATOVP_EXCPT,
81 BATT_EVENT_USBOVP_EXCPT,
82 BATT_EVENT_TEMP_EXCPT,
83 BATT_EVENT_DCLMT_EXCPT,
84 BATT_EVENT_EXCPT
85};
86
87
88/*********************************************************************
89 * Battery properties
90 *********************************************************************/
91
92/*
93 * pmic battery info
94 */
95struct pmic_power_module_info {
96 bool is_dev_info_updated;
97 struct device *dev;
98 /* pmic battery data */
99 unsigned long update_time; /* jiffies when data read */
100 unsigned int usb_is_present;
101 unsigned int batt_is_present;
102 unsigned int batt_health;
103 unsigned int usb_health;
104 unsigned int batt_status;
105 unsigned int batt_charge_now; /* in mAS */
106 unsigned int batt_prev_charge_full; /* in mAS */
107 unsigned int batt_charge_rate; /* in units per second */
108
109 struct power_supply usb;
110 struct power_supply batt;
111 int irq; /* GPE_ID or IRQ# */
112 struct workqueue_struct *monitor_wqueue;
113 struct delayed_work monitor_battery;
114 struct work_struct handler;
115};
116
117static unsigned int delay_time = 2000; /* in ms */
118
119/*
120 * pmic ac properties
121 */
122static enum power_supply_property pmic_usb_props[] = {
123 POWER_SUPPLY_PROP_PRESENT,
124 POWER_SUPPLY_PROP_HEALTH,
125};
126
127/*
128 * pmic battery properties
129 */
130static enum power_supply_property pmic_battery_props[] = {
131 POWER_SUPPLY_PROP_STATUS,
132 POWER_SUPPLY_PROP_HEALTH,
133 POWER_SUPPLY_PROP_PRESENT,
134 POWER_SUPPLY_PROP_CHARGE_NOW,
135 POWER_SUPPLY_PROP_CHARGE_FULL,
136};
137
138
139/*
140 * Glue functions for talking to the IPC
141 */
142
143struct battery_property {
144 u32 capacity; /* Charger capacity */
145 u8 crnt; /* Quick charge current value*/
146 u8 volt; /* Fine adjustment of constant charge voltage */
147 u8 prot; /* CHRGPROT register value */
148 u8 prot2; /* CHRGPROT1 register value */
149 u8 timer; /* Charging timer */
150};
151
152#define IPCMSG_BATTERY 0xEF
153
154/* Battery coulomb counter accumulator commands */
155#define IPC_CMD_CC_WR 0 /* Update coulomb counter value */
156#define IPC_CMD_CC_RD 1 /* Read coulomb counter value */
157#define IPC_CMD_BATTERY_PROPERTY 2 /* Read Battery property */
158
159/**
160 * pmic_scu_ipc_battery_cc_read - read battery cc
161 * @value: battery coulomb counter read
162 *
163 * Reads the battery couloumb counter value, returns 0 on success, or
164 * an error code
165 *
166 * This function may sleep. Locking for SCU accesses is handled for
167 * the caller.
168 */
169static int pmic_scu_ipc_battery_cc_read(u32 *value)
170{
171 return intel_scu_ipc_command(IPCMSG_BATTERY, IPC_CMD_CC_RD,
172 NULL, 0, value, 1);
173}
174
175/**
176 * pmic_scu_ipc_battery_property_get - fetch properties
177 * @prop: battery properties
178 *
179 * Retrieve the battery properties from the power management
180 *
181 * This function may sleep. Locking for SCU accesses is handled for
182 * the caller.
183 */
184static int pmic_scu_ipc_battery_property_get(struct battery_property *prop)
185{
186 u32 data[3];
187 u8 *p = (u8 *)&data[1];
188 int err = intel_scu_ipc_command(IPC_CMD_BATTERY_PROPERTY,
189 IPCMSG_BATTERY, NULL, 0, data, 3);
190
191 prop->capacity = data[0];
192 prop->crnt = *p++;
193 prop->volt = *p++;
194 prop->prot = *p++;
195 prop->prot2 = *p++;
196 prop->timer = *p++;
197
198 return err;
199}
200
201/**
202 * pmic_scu_ipc_set_charger - set charger
203 * @charger: charger to select
204 *
205 * Switch the charging mode for the SCU
206 */
207
208static int pmic_scu_ipc_set_charger(int charger)
209{
210 return intel_scu_ipc_simple_command(charger, IPCMSG_BATTERY);
211}
212
213/**
214 * pmic_battery_log_event - log battery events
215 * @event: battery event to be logged
216 * Context: can sleep
217 *
218 * There are multiple battery events which may be of interest to users;
219 * this battery function logs the different battery events onto the
220 * kernel log messages.
221 */
222static void pmic_battery_log_event(enum batt_event event)
223{
224 printk(KERN_WARNING "pmic-battery: ");
225 switch (event) {
226 case BATT_EVENT_BATOVP_EXCPT:
227 printk(KERN_CONT "battery overvoltage condition\n");
228 break;
229 case BATT_EVENT_USBOVP_EXCPT:
230 printk(KERN_CONT "usb charger overvoltage condition\n");
231 break;
232 case BATT_EVENT_TEMP_EXCPT:
233 printk(KERN_CONT "high battery temperature condition\n");
234 break;
235 case BATT_EVENT_DCLMT_EXCPT:
236 printk(KERN_CONT "over battery charge current condition\n");
237 break;
238 default:
239 printk(KERN_CONT "charger/battery exception %d\n", event);
240 break;
241 }
242}
243
244/**
245 * pmic_battery_read_status - read battery status information
246 * @pbi: device info structure to update the read information
247 * Context: can sleep
248 *
249 * PMIC power source information need to be updated based on the data read
250 * from the PMIC battery registers.
251 *
252 */
253static void pmic_battery_read_status(struct pmic_power_module_info *pbi)
254{
255 unsigned int update_time_intrvl;
256 unsigned int chrg_val;
257 u32 ccval;
258 u8 r8;
259 struct battery_property batt_prop;
260 int batt_present = 0;
261 int usb_present = 0;
262 int batt_exception = 0;
263
264 /* make sure the last batt_status read happened delay_time before */
265 if (pbi->update_time && time_before(jiffies, pbi->update_time +
266 msecs_to_jiffies(delay_time)))
267 return;
268
269 update_time_intrvl = jiffies_to_msecs(jiffies - pbi->update_time);
270 pbi->update_time = jiffies;
271
272 /* read coulomb counter registers and schrgint register */
273 if (pmic_scu_ipc_battery_cc_read(&ccval)) {
274 dev_warn(pbi->dev, "%s(): ipc config cmd failed\n",
275 __func__);
276 return;
277 }
278
279 if (intel_scu_ipc_ioread8(PMIC_BATT_CHR_SCHRGINT_ADDR, &r8)) {
280 dev_warn(pbi->dev, "%s(): ipc pmic read failed\n",
281 __func__);
282 return;
283 }
284
285 /*
286 * set pmic_power_module_info members based on pmic register values
287 * read.
288 */
289
290 /* set batt_is_present */
291 if (r8 & PMIC_BATT_CHR_SBATDET_MASK) {
292 pbi->batt_is_present = PMIC_BATT_PRESENT;
293 batt_present = 1;
294 } else {
295 pbi->batt_is_present = PMIC_BATT_NOT_PRESENT;
296 pbi->batt_health = POWER_SUPPLY_HEALTH_UNKNOWN;
297 pbi->batt_status = POWER_SUPPLY_STATUS_UNKNOWN;
298 }
299
300 /* set batt_health */
301 if (batt_present) {
302 if (r8 & PMIC_BATT_CHR_SBATOVP_MASK) {
303 pbi->batt_health = POWER_SUPPLY_HEALTH_OVERVOLTAGE;
304 pbi->batt_status = POWER_SUPPLY_STATUS_NOT_CHARGING;
305 pmic_battery_log_event(BATT_EVENT_BATOVP_EXCPT);
306 batt_exception = 1;
307 } else if (r8 & PMIC_BATT_CHR_SDCLMT_MASK) {
308 pbi->batt_health = POWER_SUPPLY_HEALTH_OVERVOLTAGE;
309 pbi->batt_status = POWER_SUPPLY_STATUS_NOT_CHARGING;
310 pmic_battery_log_event(BATT_EVENT_DCLMT_EXCPT);
311 batt_exception = 1;
312 } else if (r8 & PMIC_BATT_CHR_STEMP_MASK) {
313 pbi->batt_health = POWER_SUPPLY_HEALTH_OVERHEAT;
314 pbi->batt_status = POWER_SUPPLY_STATUS_NOT_CHARGING;
315 pmic_battery_log_event(BATT_EVENT_TEMP_EXCPT);
316 batt_exception = 1;
317 } else {
318 pbi->batt_health = POWER_SUPPLY_HEALTH_GOOD;
319 }
320 }
321
322 /* set usb_is_present */
323 if (r8 & PMIC_BATT_CHR_SUSBDET_MASK) {
324 pbi->usb_is_present = PMIC_USB_PRESENT;
325 usb_present = 1;
326 } else {
327 pbi->usb_is_present = PMIC_USB_NOT_PRESENT;
328 pbi->usb_health = POWER_SUPPLY_HEALTH_UNKNOWN;
329 }
330
331 if (usb_present) {
332 if (r8 & PMIC_BATT_CHR_SUSBOVP_MASK) {
333 pbi->usb_health = POWER_SUPPLY_HEALTH_OVERVOLTAGE;
334 pmic_battery_log_event(BATT_EVENT_USBOVP_EXCPT);
335 } else {
336 pbi->usb_health = POWER_SUPPLY_HEALTH_GOOD;
337 }
338 }
339
340 chrg_val = ccval & PMIC_BATT_ADC_ACCCHRGVAL_MASK;
341
342 /* set batt_prev_charge_full to battery capacity the first time */
343 if (!pbi->is_dev_info_updated) {
344 if (pmic_scu_ipc_battery_property_get(&batt_prop)) {
345 dev_warn(pbi->dev, "%s(): ipc config cmd failed\n",
346 __func__);
347 return;
348 }
349 pbi->batt_prev_charge_full = batt_prop.capacity;
350 }
351
352 /* set batt_status */
353 if (batt_present && !batt_exception) {
354 if (r8 & PMIC_BATT_CHR_SCOMP_MASK) {
355 pbi->batt_status = POWER_SUPPLY_STATUS_FULL;
356 pbi->batt_prev_charge_full = chrg_val;
357 } else if (ccval & PMIC_BATT_ADC_ACCCHRG_MASK) {
358 pbi->batt_status = POWER_SUPPLY_STATUS_DISCHARGING;
359 } else {
360 pbi->batt_status = POWER_SUPPLY_STATUS_CHARGING;
361 }
362 }
363
364 /* set batt_charge_rate */
365 if (pbi->is_dev_info_updated && batt_present && !batt_exception) {
366 if (pbi->batt_status == POWER_SUPPLY_STATUS_DISCHARGING) {
367 if (pbi->batt_charge_now - chrg_val) {
368 pbi->batt_charge_rate = ((pbi->batt_charge_now -
369 chrg_val) * 1000 * 60) /
370 update_time_intrvl;
371 }
372 } else if (pbi->batt_status == POWER_SUPPLY_STATUS_CHARGING) {
373 if (chrg_val - pbi->batt_charge_now) {
374 pbi->batt_charge_rate = ((chrg_val -
375 pbi->batt_charge_now) * 1000 * 60) /
376 update_time_intrvl;
377 }
378 } else
379 pbi->batt_charge_rate = 0;
380 } else {
381 pbi->batt_charge_rate = -1;
382 }
383
384 /* batt_charge_now */
385 if (batt_present && !batt_exception)
386 pbi->batt_charge_now = chrg_val;
387 else
388 pbi->batt_charge_now = -1;
389
390 pbi->is_dev_info_updated = PMIC_BATT_DRV_INFO_UPDATED;
391}
392
393/**
394 * pmic_usb_get_property - usb power source get property
395 * @psy: usb power supply context
396 * @psp: usb power source property
397 * @val: usb power source property value
398 * Context: can sleep
399 *
400 * PMIC usb power source property needs to be provided to power_supply
401 * subsytem for it to provide the information to users.
402 */
403static int pmic_usb_get_property(struct power_supply *psy,
404 enum power_supply_property psp,
405 union power_supply_propval *val)
406{
407 struct pmic_power_module_info *pbi = container_of(psy,
408 struct pmic_power_module_info, usb);
409
410 /* update pmic_power_module_info members */
411 pmic_battery_read_status(pbi);
412
413 switch (psp) {
414 case POWER_SUPPLY_PROP_PRESENT:
415 val->intval = pbi->usb_is_present;
416 break;
417 case POWER_SUPPLY_PROP_HEALTH:
418 val->intval = pbi->usb_health;
419 break;
420 default:
421 return -EINVAL;
422 }
423
424 return 0;
425}
426
427static inline unsigned long mAStouAh(unsigned long v)
428{
429 /* seconds to hours, mA to µA */
430 return (v * 1000) / 3600;
431}
432
433/**
434 * pmic_battery_get_property - battery power source get property
435 * @psy: battery power supply context
436 * @psp: battery power source property
437 * @val: battery power source property value
438 * Context: can sleep
439 *
440 * PMIC battery power source property needs to be provided to power_supply
441 * subsytem for it to provide the information to users.
442 */
443static int pmic_battery_get_property(struct power_supply *psy,
444 enum power_supply_property psp,
445 union power_supply_propval *val)
446{
447 struct pmic_power_module_info *pbi = container_of(psy,
448 struct pmic_power_module_info, batt);
449
450 /* update pmic_power_module_info members */
451 pmic_battery_read_status(pbi);
452
453 switch (psp) {
454 case POWER_SUPPLY_PROP_STATUS:
455 val->intval = pbi->batt_status;
456 break;
457 case POWER_SUPPLY_PROP_HEALTH:
458 val->intval = pbi->batt_health;
459 break;
460 case POWER_SUPPLY_PROP_PRESENT:
461 val->intval = pbi->batt_is_present;
462 break;
463 case POWER_SUPPLY_PROP_CHARGE_NOW:
464 val->intval = mAStouAh(pbi->batt_charge_now);
465 break;
466 case POWER_SUPPLY_PROP_CHARGE_FULL:
467 val->intval = mAStouAh(pbi->batt_prev_charge_full);
468 break;
469 default:
470 return -EINVAL;
471 }
472
473 return 0;
474}
475
476/**
477 * pmic_battery_monitor - monitor battery status
478 * @work: work structure
479 * Context: can sleep
480 *
481 * PMIC battery status needs to be monitored for any change
482 * and information needs to be frequently updated.
483 */
484static void pmic_battery_monitor(struct work_struct *work)
485{
486 struct pmic_power_module_info *pbi = container_of(work,
487 struct pmic_power_module_info, monitor_battery.work);
488
489 /* update pmic_power_module_info members */
490 pmic_battery_read_status(pbi);
491 queue_delayed_work(pbi->monitor_wqueue, &pbi->monitor_battery, HZ * 10);
492}
493
494/**
495 * pmic_battery_set_charger - set battery charger
496 * @pbi: device info structure
497 * @chrg: charge mode to set battery charger in
498 * Context: can sleep
499 *
500 * PMIC battery charger needs to be enabled based on the usb charge
501 * capabilities connected to the platform.
502 */
503static int pmic_battery_set_charger(struct pmic_power_module_info *pbi,
504 enum batt_charge_type chrg)
505{
506 int retval;
507
508 /* set usblmt bits and chrgcntl register bits appropriately */
509 switch (chrg) {
510 case BATT_USBOTG_500MA_CHARGE:
511 retval = pmic_scu_ipc_set_charger(PMIC_BATT_CHR_IPC_FCHRG_SUBID);
512 break;
513 case BATT_USBOTG_TRICKLE_CHARGE:
514 retval = pmic_scu_ipc_set_charger(PMIC_BATT_CHR_IPC_TCHRG_SUBID);
515 break;
516 default:
517 dev_warn(pbi->dev, "%s(): out of range usb charger "
518 "charge detected\n", __func__);
519 return -EINVAL;
520 }
521
522 if (retval) {
523 dev_warn(pbi->dev, "%s(): ipc pmic read failed\n",
524 __func__);
525 return retval;;
526 }
527
528 return 0;
529}
530
531/**
532 * pmic_battery_interrupt_handler - pmic battery interrupt handler
533 * Context: interrupt context
534 *
535 * PMIC battery interrupt handler which will be called with either
536 * battery full condition occurs or usb otg & battery connect
537 * condition occurs.
538 */
539static irqreturn_t pmic_battery_interrupt_handler(int id, void *dev)
540{
541 struct pmic_power_module_info *pbi = dev;
542
543 schedule_work(&pbi->handler);
544
545 return IRQ_HANDLED;
546}
547
548/**
549 * pmic_battery_handle_intrpt - pmic battery service interrupt
550 * @work: work structure
551 * Context: can sleep
552 *
553 * PMIC battery needs to either update the battery status as full
554 * if it detects battery full condition caused the interrupt or needs
555 * to enable battery charger if it detects usb and battery detect
556 * caused the source of interrupt.
557 */
558static void pmic_battery_handle_intrpt(struct work_struct *work)
559{
560 struct pmic_power_module_info *pbi = container_of(work,
561 struct pmic_power_module_info, handler);
562 enum batt_charge_type chrg;
563 u8 r8;
564
565 if (intel_scu_ipc_ioread8(PMIC_BATT_CHR_SCHRGINT_ADDR, &r8)) {
566 dev_warn(pbi->dev, "%s(): ipc pmic read failed\n",
567 __func__);
568 return;
569 }
570 /* find the cause of the interrupt */
571 if (r8 & PMIC_BATT_CHR_SBATDET_MASK) {
572 pbi->batt_is_present = PMIC_BATT_PRESENT;
573 } else {
574 pbi->batt_is_present = PMIC_BATT_NOT_PRESENT;
575 pbi->batt_health = POWER_SUPPLY_HEALTH_UNKNOWN;
576 pbi->batt_status = POWER_SUPPLY_STATUS_UNKNOWN;
577 return;
578 }
579
580 if (r8 & PMIC_BATT_CHR_EXCPT_MASK) {
581 pbi->batt_health = POWER_SUPPLY_HEALTH_UNKNOWN;
582 pbi->batt_status = POWER_SUPPLY_STATUS_NOT_CHARGING;
583 pbi->usb_health = POWER_SUPPLY_HEALTH_UNKNOWN;
584 pmic_battery_log_event(BATT_EVENT_EXCPT);
585 return;
586 } else {
587 pbi->batt_health = POWER_SUPPLY_HEALTH_GOOD;
588 pbi->usb_health = POWER_SUPPLY_HEALTH_GOOD;
589 }
590
591 if (r8 & PMIC_BATT_CHR_SCOMP_MASK) {
592 u32 ccval;
593 pbi->batt_status = POWER_SUPPLY_STATUS_FULL;
594
595 if (pmic_scu_ipc_battery_cc_read(&ccval)) {
596 dev_warn(pbi->dev, "%s(): ipc config cmd "
597 "failed\n", __func__);
598 return;
599 }
600 pbi->batt_prev_charge_full = ccval &
601 PMIC_BATT_ADC_ACCCHRGVAL_MASK;
602 return;
603 }
604
605 if (r8 & PMIC_BATT_CHR_SUSBDET_MASK) {
606 pbi->usb_is_present = PMIC_USB_PRESENT;
607 } else {
608 pbi->usb_is_present = PMIC_USB_NOT_PRESENT;
609 pbi->usb_health = POWER_SUPPLY_HEALTH_UNKNOWN;
610 return;
611 }
612
613 /* setup battery charging */
614
615#if 0
616 /* check usb otg power capability and set charger accordingly */
617 retval = langwell_udc_maxpower(&power);
618 if (retval) {
619 dev_warn(pbi->dev,
620 "%s(): usb otg power query failed with error code %d\n",
621 __func__, retval);
622 return;
623 }
624
625 if (power >= 500)
626 chrg = BATT_USBOTG_500MA_CHARGE;
627 else
628#endif
629 chrg = BATT_USBOTG_TRICKLE_CHARGE;
630
631 /* enable battery charging */
632 if (pmic_battery_set_charger(pbi, chrg)) {
633 dev_warn(pbi->dev,
634 "%s(): failed to set up battery charging\n", __func__);
635 return;
636 }
637
638 dev_dbg(pbi->dev,
639 "pmic-battery: %s() - setting up battery charger successful\n",
640 __func__);
641}
642
643/**
644 * pmic_battery_probe - pmic battery initialize
645 * @irq: pmic battery device irq
646 * @dev: pmic battery device structure
647 * Context: can sleep
648 *
649 * PMIC battery initializes its internal data structue and other
650 * infrastructure components for it to work as expected.
651 */
652static __devinit int probe(int irq, struct device *dev)
653{
654 int retval = 0;
655 struct pmic_power_module_info *pbi;
656
657 dev_dbg(dev, "pmic-battery: found pmic battery device\n");
658
659 pbi = kzalloc(sizeof(*pbi), GFP_KERNEL);
660 if (!pbi) {
661 dev_err(dev, "%s(): memory allocation failed\n",
662 __func__);
663 return -ENOMEM;
664 }
665
666 pbi->dev = dev;
667 pbi->irq = irq;
668 dev_set_drvdata(dev, pbi);
669
670 /* initialize all required framework before enabling interrupts */
671 INIT_WORK(&pbi->handler, pmic_battery_handle_intrpt);
672 INIT_DELAYED_WORK(&pbi->monitor_battery, pmic_battery_monitor);
673 pbi->monitor_wqueue =
674 create_singlethread_workqueue(dev_name(dev));
675 if (!pbi->monitor_wqueue) {
676 dev_err(dev, "%s(): wqueue init failed\n", __func__);
677 retval = -ESRCH;
678 goto wqueue_failed;
679 }
680
681 /* register interrupt */
682 retval = request_irq(pbi->irq, pmic_battery_interrupt_handler,
683 0, DRIVER_NAME, pbi);
684 if (retval) {
685 dev_err(dev, "%s(): cannot get IRQ\n", __func__);
686 goto requestirq_failed;
687 }
688
689 /* register pmic-batt with power supply subsystem */
690 pbi->batt.name = "pmic-batt";
691 pbi->batt.type = POWER_SUPPLY_TYPE_BATTERY;
692 pbi->batt.properties = pmic_battery_props;
693 pbi->batt.num_properties = ARRAY_SIZE(pmic_battery_props);
694 pbi->batt.get_property = pmic_battery_get_property;
695 retval = power_supply_register(dev, &pbi->batt);
696 if (retval) {
697 dev_err(dev,
698 "%s(): failed to register pmic battery device with power supply subsystem\n",
699 __func__);
700 goto power_reg_failed;
701 }
702
703 dev_dbg(dev, "pmic-battery: %s() - pmic battery device "
704 "registration with power supply subsystem successful\n",
705 __func__);
706
707 queue_delayed_work(pbi->monitor_wqueue, &pbi->monitor_battery, HZ * 1);
708
709 /* register pmic-usb with power supply subsystem */
710 pbi->usb.name = "pmic-usb";
711 pbi->usb.type = POWER_SUPPLY_TYPE_USB;
712 pbi->usb.properties = pmic_usb_props;
713 pbi->usb.num_properties = ARRAY_SIZE(pmic_usb_props);
714 pbi->usb.get_property = pmic_usb_get_property;
715 retval = power_supply_register(dev, &pbi->usb);
716 if (retval) {
717 dev_err(dev,
718 "%s(): failed to register pmic usb device with power supply subsystem\n",
719 __func__);
720 goto power_reg_failed_1;
721 }
722
723 if (debug)
724 printk(KERN_INFO "pmic-battery: %s() - pmic usb device "
725 "registration with power supply subsystem successful\n",
726 __func__);
727
728 return retval;
729
730power_reg_failed_1:
731 power_supply_unregister(&pbi->batt);
732power_reg_failed:
733 cancel_rearming_delayed_workqueue(pbi->monitor_wqueue,
734 &pbi->monitor_battery);
735requestirq_failed:
736 destroy_workqueue(pbi->monitor_wqueue);
737wqueue_failed:
738 kfree(pbi);
739
740 return retval;
741}
742
743static int __devinit platform_pmic_battery_probe(struct platform_device *pdev)
744{
745 return probe(pdev->id, &pdev->dev);
746}
747
748/**
749 * pmic_battery_remove - pmic battery finalize
750 * @dev: pmic battery device structure
751 * Context: can sleep
752 *
753 * PMIC battery finalizes its internal data structue and other
754 * infrastructure components that it initialized in
755 * pmic_battery_probe.
756 */
757
758static int __devexit platform_pmic_battery_remove(struct platform_device *pdev)
759{
760 struct pmic_power_module_info *pbi = dev_get_drvdata(&pdev->dev);
761
762 free_irq(pbi->irq, pbi);
763 cancel_rearming_delayed_workqueue(pbi->monitor_wqueue,
764 &pbi->monitor_battery);
765 destroy_workqueue(pbi->monitor_wqueue);
766
767 power_supply_unregister(&pbi->usb);
768 power_supply_unregister(&pbi->batt);
769
770 flush_scheduled_work();
771 kfree(pbi);
772 return 0;
773}
774
775static struct platform_driver platform_pmic_battery_driver = {
776 .driver = {
777 .name = DRIVER_NAME,
778 .owner = THIS_MODULE,
779 },
780 .probe = platform_pmic_battery_probe,
781 .remove = __devexit_p(platform_pmic_battery_remove),
782};
783
784static int __init platform_pmic_battery_module_init(void)
785{
786 return platform_driver_register(&platform_pmic_battery_driver);
787}
788
789static void __exit platform_pmic_battery_module_exit(void)
790{
791 platform_driver_unregister(&platform_pmic_battery_driver);
792}
793
794module_init(platform_pmic_battery_module_init);
795module_exit(platform_pmic_battery_module_exit);
796
797MODULE_AUTHOR("Nithish Mahalingam <nithish.mahalingam@intel.com>");
798MODULE_DESCRIPTION("Intel Moorestown PMIC Battery Driver");
799MODULE_LICENSE("GPL");
diff --git a/drivers/power/olpc_battery.c b/drivers/power/olpc_battery.c
index baefcf1cffc9..aafc1c506eda 100644
--- a/drivers/power/olpc_battery.c
+++ b/drivers/power/olpc_battery.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Battery driver for One Laptop Per Child board. 2 * Battery driver for One Laptop Per Child board.
3 * 3 *
4 * Copyright © 2006 David Woodhouse <dwmw2@infradead.org> 4 * Copyright © 2006-2010 David Woodhouse <dwmw2@infradead.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as 7 * it under the terms of the GNU General Public License version 2 as
@@ -384,7 +384,6 @@ static struct bin_attribute olpc_bat_eeprom = {
384 .attr = { 384 .attr = {
385 .name = "eeprom", 385 .name = "eeprom",
386 .mode = S_IRUGO, 386 .mode = S_IRUGO,
387 .owner = THIS_MODULE,
388 }, 387 },
389 .size = 0, 388 .size = 0,
390 .read = olpc_bat_eeprom_read, 389 .read = olpc_bat_eeprom_read,
diff --git a/drivers/power/s3c_adc_battery.c b/drivers/power/s3c_adc_battery.c
new file mode 100644
index 000000000000..fe16b482e912
--- /dev/null
+++ b/drivers/power/s3c_adc_battery.c
@@ -0,0 +1,431 @@
1/*
2 * iPAQ h1930/h1940/rx1950 battery controler driver
3 * Copyright (c) Vasily Khoruzhick
4 * Based on h1940_battery.c by Arnaud Patard
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 for
8 * more details.
9 *
10 */
11
12#include <linux/interrupt.h>
13#include <linux/platform_device.h>
14#include <linux/power_supply.h>
15#include <linux/leds.h>
16#include <linux/gpio.h>
17#include <linux/err.h>
18#include <linux/timer.h>
19#include <linux/jiffies.h>
20#include <linux/s3c_adc_battery.h>
21#include <linux/errno.h>
22#include <linux/init.h>
23
24#include <plat/adc.h>
25
26#define BAT_POLL_INTERVAL 10000 /* ms */
27#define JITTER_DELAY 500 /* ms */
28
29struct s3c_adc_bat {
30 struct power_supply psy;
31 struct s3c_adc_client *client;
32 struct s3c_adc_bat_pdata *pdata;
33 int volt_value;
34 int cur_value;
35 unsigned int timestamp;
36 int level;
37 int status;
38 int cable_plugged:1;
39};
40
41static struct delayed_work bat_work;
42
43static void s3c_adc_bat_ext_power_changed(struct power_supply *psy)
44{
45 schedule_delayed_work(&bat_work,
46 msecs_to_jiffies(JITTER_DELAY));
47}
48
49static enum power_supply_property s3c_adc_backup_bat_props[] = {
50 POWER_SUPPLY_PROP_VOLTAGE_NOW,
51 POWER_SUPPLY_PROP_VOLTAGE_MIN,
52 POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN,
53};
54
55static int s3c_adc_backup_bat_get_property(struct power_supply *psy,
56 enum power_supply_property psp,
57 union power_supply_propval *val)
58{
59 struct s3c_adc_bat *bat = container_of(psy, struct s3c_adc_bat, psy);
60
61 if (!bat) {
62 dev_err(psy->dev, "%s: no battery infos ?!\n", __func__);
63 return -EINVAL;
64 }
65
66 if (bat->volt_value < 0 ||
67 jiffies_to_msecs(jiffies - bat->timestamp) >
68 BAT_POLL_INTERVAL) {
69 bat->volt_value = s3c_adc_read(bat->client,
70 bat->pdata->backup_volt_channel);
71 bat->volt_value *= bat->pdata->backup_volt_mult;
72 bat->timestamp = jiffies;
73 }
74
75 switch (psp) {
76 case POWER_SUPPLY_PROP_VOLTAGE_NOW:
77 val->intval = bat->volt_value;
78 return 0;
79 case POWER_SUPPLY_PROP_VOLTAGE_MIN:
80 val->intval = bat->pdata->backup_volt_min;
81 return 0;
82 case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN:
83 val->intval = bat->pdata->backup_volt_max;
84 return 0;
85 default:
86 return -EINVAL;
87 }
88}
89
90static struct s3c_adc_bat backup_bat = {
91 .psy = {
92 .name = "backup-battery",
93 .type = POWER_SUPPLY_TYPE_BATTERY,
94 .properties = s3c_adc_backup_bat_props,
95 .num_properties = ARRAY_SIZE(s3c_adc_backup_bat_props),
96 .get_property = s3c_adc_backup_bat_get_property,
97 .use_for_apm = 1,
98 },
99};
100
101static enum power_supply_property s3c_adc_main_bat_props[] = {
102 POWER_SUPPLY_PROP_STATUS,
103 POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
104 POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN,
105 POWER_SUPPLY_PROP_CHARGE_NOW,
106 POWER_SUPPLY_PROP_VOLTAGE_NOW,
107 POWER_SUPPLY_PROP_CURRENT_NOW,
108};
109
110static int calc_full_volt(int volt_val, int cur_val, int impedance)
111{
112 return volt_val + cur_val * impedance / 1000;
113}
114
115static int s3c_adc_bat_get_property(struct power_supply *psy,
116 enum power_supply_property psp,
117 union power_supply_propval *val)
118{
119 struct s3c_adc_bat *bat = container_of(psy, struct s3c_adc_bat, psy);
120
121 int new_level;
122 int full_volt;
123 const struct s3c_adc_bat_thresh *lut = bat->pdata->lut_noac;
124 unsigned int lut_size = bat->pdata->lut_noac_cnt;
125
126 if (!bat) {
127 dev_err(psy->dev, "no battery infos ?!\n");
128 return -EINVAL;
129 }
130
131 if (bat->volt_value < 0 || bat->cur_value < 0 ||
132 jiffies_to_msecs(jiffies - bat->timestamp) >
133 BAT_POLL_INTERVAL) {
134 bat->volt_value = s3c_adc_read(bat->client,
135 bat->pdata->volt_channel) * bat->pdata->volt_mult;
136 bat->cur_value = s3c_adc_read(bat->client,
137 bat->pdata->current_channel) * bat->pdata->current_mult;
138 bat->timestamp = jiffies;
139 }
140
141 if (bat->cable_plugged &&
142 ((bat->pdata->gpio_charge_finished < 0) ||
143 !gpio_get_value(bat->pdata->gpio_charge_finished))) {
144 lut = bat->pdata->lut_acin;
145 lut_size = bat->pdata->lut_acin_cnt;
146 }
147
148 new_level = 100000;
149 full_volt = calc_full_volt((bat->volt_value / 1000),
150 (bat->cur_value / 1000), bat->pdata->internal_impedance);
151
152 if (full_volt < calc_full_volt(lut->volt, lut->cur,
153 bat->pdata->internal_impedance)) {
154 lut_size--;
155 while (lut_size--) {
156 int lut_volt1;
157 int lut_volt2;
158
159 lut_volt1 = calc_full_volt(lut[0].volt, lut[0].cur,
160 bat->pdata->internal_impedance);
161 lut_volt2 = calc_full_volt(lut[1].volt, lut[1].cur,
162 bat->pdata->internal_impedance);
163 if (full_volt < lut_volt1 && full_volt >= lut_volt2) {
164 new_level = (lut[1].level +
165 (lut[0].level - lut[1].level) *
166 (full_volt - lut_volt2) /
167 (lut_volt1 - lut_volt2)) * 1000;
168 break;
169 }
170 new_level = lut[1].level * 1000;
171 lut++;
172 }
173 }
174
175 bat->level = new_level;
176
177 switch (psp) {
178 case POWER_SUPPLY_PROP_STATUS:
179 if (bat->pdata->gpio_charge_finished < 0)
180 val->intval = bat->level == 100000 ?
181 POWER_SUPPLY_STATUS_FULL : bat->status;
182 else
183 val->intval = bat->status;
184 return 0;
185 case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
186 val->intval = 100000;
187 return 0;
188 case POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN:
189 val->intval = 0;
190 return 0;
191 case POWER_SUPPLY_PROP_CHARGE_NOW:
192 val->intval = bat->level;
193 return 0;
194 case POWER_SUPPLY_PROP_VOLTAGE_NOW:
195 val->intval = bat->volt_value;
196 return 0;
197 case POWER_SUPPLY_PROP_CURRENT_NOW:
198 val->intval = bat->cur_value;
199 return 0;
200 default:
201 return -EINVAL;
202 }
203}
204
205static struct s3c_adc_bat main_bat = {
206 .psy = {
207 .name = "main-battery",
208 .type = POWER_SUPPLY_TYPE_BATTERY,
209 .properties = s3c_adc_main_bat_props,
210 .num_properties = ARRAY_SIZE(s3c_adc_main_bat_props),
211 .get_property = s3c_adc_bat_get_property,
212 .external_power_changed = s3c_adc_bat_ext_power_changed,
213 .use_for_apm = 1,
214 },
215};
216
217static void s3c_adc_bat_work(struct work_struct *work)
218{
219 struct s3c_adc_bat *bat = &main_bat;
220 int is_charged;
221 int is_plugged;
222 static int was_plugged;
223
224 is_plugged = power_supply_am_i_supplied(&bat->psy);
225 bat->cable_plugged = is_plugged;
226 if (is_plugged != was_plugged) {
227 was_plugged = is_plugged;
228 if (is_plugged) {
229 if (bat->pdata->enable_charger)
230 bat->pdata->enable_charger();
231 bat->status = POWER_SUPPLY_STATUS_CHARGING;
232 } else {
233 if (bat->pdata->disable_charger)
234 bat->pdata->disable_charger();
235 bat->status = POWER_SUPPLY_STATUS_DISCHARGING;
236 }
237 } else {
238 if ((bat->pdata->gpio_charge_finished >= 0) && is_plugged) {
239 is_charged = gpio_get_value(
240 main_bat.pdata->gpio_charge_finished);
241 if (is_charged) {
242 if (bat->pdata->disable_charger)
243 bat->pdata->disable_charger();
244 bat->status = POWER_SUPPLY_STATUS_FULL;
245 } else {
246 if (bat->pdata->enable_charger)
247 bat->pdata->enable_charger();
248 bat->status = POWER_SUPPLY_STATUS_CHARGING;
249 }
250 }
251 }
252
253 power_supply_changed(&bat->psy);
254}
255
256static irqreturn_t s3c_adc_bat_charged(int irq, void *dev_id)
257{
258 schedule_delayed_work(&bat_work,
259 msecs_to_jiffies(JITTER_DELAY));
260 return IRQ_HANDLED;
261}
262
263static int __init s3c_adc_bat_probe(struct platform_device *pdev)
264{
265 struct s3c_adc_client *client;
266 struct s3c_adc_bat_pdata *pdata = pdev->dev.platform_data;
267 int ret;
268
269 client = s3c_adc_register(pdev, NULL, NULL, 0);
270 if (IS_ERR(client)) {
271 dev_err(&pdev->dev, "cannot register adc\n");
272 return PTR_ERR(client);
273 }
274
275 platform_set_drvdata(pdev, client);
276
277 main_bat.client = client;
278 main_bat.pdata = pdata;
279 main_bat.volt_value = -1;
280 main_bat.cur_value = -1;
281 main_bat.cable_plugged = 0;
282 main_bat.status = POWER_SUPPLY_STATUS_DISCHARGING;
283
284 ret = power_supply_register(&pdev->dev, &main_bat.psy);
285 if (ret)
286 goto err_reg_main;
287 if (pdata->backup_volt_mult) {
288 backup_bat.client = client;
289 backup_bat.pdata = pdev->dev.platform_data;
290 backup_bat.volt_value = -1;
291 ret = power_supply_register(&pdev->dev, &backup_bat.psy);
292 if (ret)
293 goto err_reg_backup;
294 }
295
296 INIT_DELAYED_WORK(&bat_work, s3c_adc_bat_work);
297
298 if (pdata->gpio_charge_finished >= 0) {
299 ret = gpio_request(pdata->gpio_charge_finished, "charged");
300 if (ret)
301 goto err_gpio;
302
303 ret = request_irq(gpio_to_irq(pdata->gpio_charge_finished),
304 s3c_adc_bat_charged,
305 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
306 "battery charged", NULL);
307 if (ret)
308 goto err_irq;
309 }
310
311 if (pdata->init) {
312 ret = pdata->init();
313 if (ret)
314 goto err_platform;
315 }
316
317 dev_info(&pdev->dev, "successfully loaded\n");
318 device_init_wakeup(&pdev->dev, 1);
319
320 /* Schedule timer to check current status */
321 schedule_delayed_work(&bat_work,
322 msecs_to_jiffies(JITTER_DELAY));
323
324 return 0;
325
326err_platform:
327 if (pdata->gpio_charge_finished >= 0)
328 free_irq(gpio_to_irq(pdata->gpio_charge_finished), NULL);
329err_irq:
330 if (pdata->gpio_charge_finished >= 0)
331 gpio_free(pdata->gpio_charge_finished);
332err_gpio:
333 if (pdata->backup_volt_mult)
334 power_supply_unregister(&backup_bat.psy);
335err_reg_backup:
336 power_supply_unregister(&main_bat.psy);
337err_reg_main:
338 return ret;
339}
340
341static int s3c_adc_bat_remove(struct platform_device *pdev)
342{
343 struct s3c_adc_client *client = platform_get_drvdata(pdev);
344 struct s3c_adc_bat_pdata *pdata = pdev->dev.platform_data;
345
346 power_supply_unregister(&main_bat.psy);
347 if (pdata->backup_volt_mult)
348 power_supply_unregister(&backup_bat.psy);
349
350 s3c_adc_release(client);
351
352 if (pdata->gpio_charge_finished >= 0) {
353 free_irq(gpio_to_irq(pdata->gpio_charge_finished), NULL);
354 gpio_free(pdata->gpio_charge_finished);
355 }
356
357 cancel_delayed_work(&bat_work);
358
359 if (pdata->exit)
360 pdata->exit();
361
362 return 0;
363}
364
365#ifdef CONFIG_PM
366static int s3c_adc_bat_suspend(struct platform_device *pdev,
367 pm_message_t state)
368{
369 struct s3c_adc_bat_pdata *pdata = pdev->dev.platform_data;
370
371 if (pdata->gpio_charge_finished >= 0) {
372 if (device_may_wakeup(&pdev->dev))
373 enable_irq_wake(
374 gpio_to_irq(pdata->gpio_charge_finished));
375 else {
376 disable_irq(gpio_to_irq(pdata->gpio_charge_finished));
377 main_bat.pdata->disable_charger();
378 }
379 }
380
381 return 0;
382}
383
384static int s3c_adc_bat_resume(struct platform_device *pdev)
385{
386 struct s3c_adc_bat_pdata *pdata = pdev->dev.platform_data;
387
388 if (pdata->gpio_charge_finished >= 0) {
389 if (device_may_wakeup(&pdev->dev))
390 disable_irq_wake(
391 gpio_to_irq(pdata->gpio_charge_finished));
392 else
393 enable_irq(gpio_to_irq(pdata->gpio_charge_finished));
394 }
395
396 /* Schedule timer to check current status */
397 schedule_delayed_work(&bat_work,
398 msecs_to_jiffies(JITTER_DELAY));
399
400 return 0;
401}
402#else
403#define s3c_adc_battery_suspend NULL
404#define s3c_adc_battery_resume NULL
405#endif
406
407static struct platform_driver s3c_adc_bat_driver = {
408 .driver = {
409 .name = "s3c-adc-battery",
410 },
411 .probe = s3c_adc_bat_probe,
412 .remove = s3c_adc_bat_remove,
413 .suspend = s3c_adc_bat_suspend,
414 .resume = s3c_adc_bat_resume,
415};
416
417static int __init s3c_adc_bat_init(void)
418{
419 return platform_driver_register(&s3c_adc_bat_driver);
420}
421module_init(s3c_adc_bat_init);
422
423static void __exit s3c_adc_bat_exit(void)
424{
425 platform_driver_unregister(&s3c_adc_bat_driver);
426}
427module_exit(s3c_adc_bat_exit);
428
429MODULE_AUTHOR("Vasily Khoruzhick <anarsoul@gmail.com>");
430MODULE_DESCRIPTION("iPAQ H1930/H1940/RX1950 battery controler driver");
431MODULE_LICENSE("GPL");
diff --git a/drivers/power/wm97xx_battery.c b/drivers/power/wm97xx_battery.c
index 4e8afce0c818..5071d85ec12d 100644
--- a/drivers/power/wm97xx_battery.c
+++ b/drivers/power/wm97xx_battery.c
@@ -29,7 +29,6 @@ static DEFINE_MUTEX(bat_lock);
29static struct work_struct bat_work; 29static struct work_struct bat_work;
30static struct mutex work_lock; 30static struct mutex work_lock;
31static int bat_status = POWER_SUPPLY_STATUS_UNKNOWN; 31static int bat_status = POWER_SUPPLY_STATUS_UNKNOWN;
32static struct wm97xx_batt_info *gpdata;
33static enum power_supply_property *prop; 32static enum power_supply_property *prop;
34 33
35static unsigned long wm97xx_read_bat(struct power_supply *bat_ps) 34static unsigned long wm97xx_read_bat(struct power_supply *bat_ps)
@@ -172,12 +171,6 @@ static int __devinit wm97xx_bat_probe(struct platform_device *dev)
172 struct wm97xx_pdata *wmdata = dev->dev.platform_data; 171 struct wm97xx_pdata *wmdata = dev->dev.platform_data;
173 struct wm97xx_batt_pdata *pdata; 172 struct wm97xx_batt_pdata *pdata;
174 173
175 if (gpdata) {
176 dev_err(&dev->dev, "Do not pass platform_data through "
177 "wm97xx_bat_set_pdata!\n");
178 return -EINVAL;
179 }
180
181 if (!wmdata) { 174 if (!wmdata) {
182 dev_err(&dev->dev, "No platform data supplied\n"); 175 dev_err(&dev->dev, "No platform data supplied\n");
183 return -EINVAL; 176 return -EINVAL;
@@ -308,15 +301,6 @@ static void __exit wm97xx_bat_exit(void)
308 platform_driver_unregister(&wm97xx_bat_driver); 301 platform_driver_unregister(&wm97xx_bat_driver);
309} 302}
310 303
311/* The interface is deprecated, as well as linux/wm97xx_batt.h */
312void wm97xx_bat_set_pdata(struct wm97xx_batt_info *data);
313
314void wm97xx_bat_set_pdata(struct wm97xx_batt_info *data)
315{
316 gpdata = data;
317}
318EXPORT_SYMBOL_GPL(wm97xx_bat_set_pdata);
319
320module_init(wm97xx_bat_init); 304module_init(wm97xx_bat_init);
321module_exit(wm97xx_bat_exit); 305module_exit(wm97xx_bat_exit);
322 306
diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index 04f2e085116a..172951bf23a4 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -100,6 +100,14 @@ config REGULATOR_MAX8925
100 help 100 help
101 Say y here to support the voltage regulaltor of Maxim MAX8925 PMIC. 101 Say y here to support the voltage regulaltor of Maxim MAX8925 PMIC.
102 102
103config REGULATOR_MAX8998
104 tristate "Maxim 8998 voltage regulator"
105 depends on MFD_MAX8998
106 help
107 This driver controls a Maxim 8998 voltage output regulator
108 via I2C bus. The provided regulator is suitable for S3C6410
109 and S5PC1XX chips to control VCC_CORE and VCC_USIM voltages.
110
103config REGULATOR_TWL4030 111config REGULATOR_TWL4030
104 bool "TI TWL4030/TWL5030/TWL6030/TPS695x0 PMIC" 112 bool "TI TWL4030/TWL5030/TWL6030/TPS695x0 PMIC"
105 depends on TWL4030_CORE 113 depends on TWL4030_CORE
@@ -201,5 +209,31 @@ config REGULATOR_88PM8607
201 help 209 help
202 This driver supports 88PM8607 voltage regulator chips. 210 This driver supports 88PM8607 voltage regulator chips.
203 211
212config REGULATOR_ISL6271A
213 tristate "Intersil ISL6271A Power regulator"
214 depends on I2C
215 help
216 This driver supports ISL6271A voltage regulator chip.
217
218config REGULATOR_AD5398
219 tristate "Analog Devices AD5398/AD5821 regulators"
220 depends on I2C
221 help
222 This driver supports AD5398 and AD5821 current regulator chips.
223 If building into module, its name is ad5398.ko.
224
225config REGULATOR_AB8500
226 bool "ST-Ericsson AB8500 Power Regulators"
227 depends on AB8500_CORE
228 help
229 This driver supports the regulators found on the ST-Ericsson mixed
230 signal AB8500 PMIC
231
232config REGULATOR_TPS6586X
233 tristate "TI TPS6586X Power regulators"
234 depends on MFD_TPS6586X
235 help
236 This driver supports TPS6586X voltage regulator chips.
237
204endif 238endif
205 239
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index 4e7feece22d5..8285fd832e16 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -8,6 +8,7 @@ obj-$(CONFIG_REGULATOR_FIXED_VOLTAGE) += fixed.o
8obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o 8obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o
9obj-$(CONFIG_REGULATOR_USERSPACE_CONSUMER) += userspace-consumer.o 9obj-$(CONFIG_REGULATOR_USERSPACE_CONSUMER) += userspace-consumer.o
10 10
11obj-$(CONFIG_REGULATOR_AD5398) += ad5398.o
11obj-$(CONFIG_REGULATOR_BQ24022) += bq24022.o 12obj-$(CONFIG_REGULATOR_BQ24022) += bq24022.o
12obj-$(CONFIG_REGULATOR_DUMMY) += dummy.o 13obj-$(CONFIG_REGULATOR_DUMMY) += dummy.o
13obj-$(CONFIG_REGULATOR_LP3971) += lp3971.o 14obj-$(CONFIG_REGULATOR_LP3971) += lp3971.o
@@ -16,12 +17,14 @@ obj-$(CONFIG_REGULATOR_TWL4030) += twl-regulator.o
16obj-$(CONFIG_REGULATOR_MAX8649) += max8649.o 17obj-$(CONFIG_REGULATOR_MAX8649) += max8649.o
17obj-$(CONFIG_REGULATOR_MAX8660) += max8660.o 18obj-$(CONFIG_REGULATOR_MAX8660) += max8660.o
18obj-$(CONFIG_REGULATOR_MAX8925) += max8925-regulator.o 19obj-$(CONFIG_REGULATOR_MAX8925) += max8925-regulator.o
20obj-$(CONFIG_REGULATOR_MAX8998) += max8998.o
19obj-$(CONFIG_REGULATOR_WM831X) += wm831x-dcdc.o 21obj-$(CONFIG_REGULATOR_WM831X) += wm831x-dcdc.o
20obj-$(CONFIG_REGULATOR_WM831X) += wm831x-isink.o 22obj-$(CONFIG_REGULATOR_WM831X) += wm831x-isink.o
21obj-$(CONFIG_REGULATOR_WM831X) += wm831x-ldo.o 23obj-$(CONFIG_REGULATOR_WM831X) += wm831x-ldo.o
22obj-$(CONFIG_REGULATOR_WM8350) += wm8350-regulator.o 24obj-$(CONFIG_REGULATOR_WM8350) += wm8350-regulator.o
23obj-$(CONFIG_REGULATOR_WM8400) += wm8400-regulator.o 25obj-$(CONFIG_REGULATOR_WM8400) += wm8400-regulator.o
24obj-$(CONFIG_REGULATOR_WM8994) += wm8994-regulator.o 26obj-$(CONFIG_REGULATOR_WM8994) += wm8994-regulator.o
27obj-$(CONFIG_REGULATOR_TPS6586X) += tps6586x-regulator.o
25obj-$(CONFIG_REGULATOR_DA903X) += da903x.o 28obj-$(CONFIG_REGULATOR_DA903X) += da903x.o
26obj-$(CONFIG_REGULATOR_PCF50633) += pcf50633-regulator.o 29obj-$(CONFIG_REGULATOR_PCF50633) += pcf50633-regulator.o
27obj-$(CONFIG_REGULATOR_PCAP) += pcap-regulator.o 30obj-$(CONFIG_REGULATOR_PCAP) += pcap-regulator.o
@@ -31,5 +34,7 @@ obj-$(CONFIG_REGULATOR_AB3100) += ab3100.o
31obj-$(CONFIG_REGULATOR_TPS65023) += tps65023-regulator.o 34obj-$(CONFIG_REGULATOR_TPS65023) += tps65023-regulator.o
32obj-$(CONFIG_REGULATOR_TPS6507X) += tps6507x-regulator.o 35obj-$(CONFIG_REGULATOR_TPS6507X) += tps6507x-regulator.o
33obj-$(CONFIG_REGULATOR_88PM8607) += 88pm8607.o 36obj-$(CONFIG_REGULATOR_88PM8607) += 88pm8607.o
37obj-$(CONFIG_REGULATOR_ISL6271A) += isl6271a-regulator.o
38obj-$(CONFIG_REGULATOR_AB8500) += ab8500.o
34 39
35ccflags-$(CONFIG_REGULATOR_DEBUG) += -DDEBUG 40ccflags-$(CONFIG_REGULATOR_DEBUG) += -DDEBUG
diff --git a/drivers/regulator/ab8500.c b/drivers/regulator/ab8500.c
new file mode 100644
index 000000000000..dc3f1a491675
--- /dev/null
+++ b/drivers/regulator/ab8500.c
@@ -0,0 +1,427 @@
1/*
2 * Copyright (C) ST-Ericsson SA 2010
3 *
4 * License Terms: GNU General Public License v2
5 *
6 * Author: Sundar Iyer <sundar.iyer@stericsson.com> for ST-Ericsson
7 *
8 * AB8500 peripheral regulators
9 *
10 * AB8500 supports the following regulators,
11 * LDOs - VAUDIO, VANAMIC2/2, VDIGMIC, VINTCORE12, VTVOUT,
12 * VAUX1/2/3, VANA
13 *
14 * for DB8500 cut 1.0 and previous versions of the silicon, all accesses
15 * to registers are through the DB8500 SPI. In cut 1.1 onwards, these
16 * accesses are through the DB8500 PRCMU I2C
17 *
18 */
19#include <linux/init.h>
20#include <linux/kernel.h>
21#include <linux/err.h>
22#include <linux/platform_device.h>
23#include <linux/mfd/ab8500.h>
24#include <linux/regulator/driver.h>
25#include <linux/regulator/machine.h>
26#include <linux/regulator/ab8500.h>
27
28/**
29 * struct ab8500_regulator_info - ab8500 regulator information
30 * @desc: regulator description
31 * @ab8500: ab8500 parent
32 * @regulator_dev: regulator device
33 * @max_uV: maximum voltage (for variable voltage supplies)
34 * @min_uV: minimum voltage (for variable voltage supplies)
35 * @fixed_uV: typical voltage (for fixed voltage supplies)
36 * @update_reg: register to control on/off
37 * @mask: mask to enable/disable regulator
38 * @enable: bits to enable the regulator in normal(high power) mode
39 * @voltage_reg: register to control regulator voltage
40 * @voltage_mask: mask to control regulator voltage
41 * @supported_voltages: supported voltage table
42 * @voltages_len: number of supported voltages for the regulator
43 */
44struct ab8500_regulator_info {
45 struct device *dev;
46 struct regulator_desc desc;
47 struct ab8500 *ab8500;
48 struct regulator_dev *regulator;
49 int max_uV;
50 int min_uV;
51 int fixed_uV;
52 int update_reg;
53 int mask;
54 int enable;
55 int voltage_reg;
56 int voltage_mask;
57 int const *supported_voltages;
58 int voltages_len;
59};
60
61/* voltage tables for the vauxn/vintcore supplies */
62static const int ldo_vauxn_voltages[] = {
63 1100000,
64 1200000,
65 1300000,
66 1400000,
67 1500000,
68 1800000,
69 1850000,
70 1900000,
71 2500000,
72 2650000,
73 2700000,
74 2750000,
75 2800000,
76 2900000,
77 3000000,
78 3300000,
79};
80
81static const int ldo_vintcore_voltages[] = {
82 1200000,
83 1225000,
84 1250000,
85 1275000,
86 1300000,
87 1325000,
88 1350000,
89};
90
91static int ab8500_regulator_enable(struct regulator_dev *rdev)
92{
93 int regulator_id, ret;
94 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
95
96 regulator_id = rdev_get_id(rdev);
97 if (regulator_id >= AB8500_NUM_REGULATORS)
98 return -EINVAL;
99
100 ret = ab8500_set_bits(info->ab8500, info->update_reg,
101 info->mask, info->enable);
102 if (ret < 0)
103 dev_err(rdev_get_dev(rdev),
104 "couldn't set enable bits for regulator\n");
105 return ret;
106}
107
108static int ab8500_regulator_disable(struct regulator_dev *rdev)
109{
110 int regulator_id, ret;
111 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
112
113 regulator_id = rdev_get_id(rdev);
114 if (regulator_id >= AB8500_NUM_REGULATORS)
115 return -EINVAL;
116
117 ret = ab8500_set_bits(info->ab8500, info->update_reg,
118 info->mask, 0x0);
119 if (ret < 0)
120 dev_err(rdev_get_dev(rdev),
121 "couldn't set disable bits for regulator\n");
122 return ret;
123}
124
125static int ab8500_regulator_is_enabled(struct regulator_dev *rdev)
126{
127 int regulator_id, ret;
128 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
129
130 regulator_id = rdev_get_id(rdev);
131 if (regulator_id >= AB8500_NUM_REGULATORS)
132 return -EINVAL;
133
134 ret = ab8500_read(info->ab8500, info->update_reg);
135 if (ret < 0) {
136 dev_err(rdev_get_dev(rdev),
137 "couldn't read 0x%x register\n", info->update_reg);
138 return ret;
139 }
140
141 if (ret & info->mask)
142 return true;
143 else
144 return false;
145}
146
147static int ab8500_list_voltage(struct regulator_dev *rdev, unsigned selector)
148{
149 int regulator_id;
150 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
151
152 regulator_id = rdev_get_id(rdev);
153 if (regulator_id >= AB8500_NUM_REGULATORS)
154 return -EINVAL;
155
156 /* return the uV for the fixed regulators */
157 if (info->fixed_uV)
158 return info->fixed_uV;
159
160 if (selector > info->voltages_len)
161 return -EINVAL;
162
163 return info->supported_voltages[selector];
164}
165
166static int ab8500_regulator_get_voltage(struct regulator_dev *rdev)
167{
168 int regulator_id, ret, val;
169 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
170
171 regulator_id = rdev_get_id(rdev);
172 if (regulator_id >= AB8500_NUM_REGULATORS)
173 return -EINVAL;
174
175 ret = ab8500_read(info->ab8500, info->voltage_reg);
176 if (ret < 0) {
177 dev_err(rdev_get_dev(rdev),
178 "couldn't read voltage reg for regulator\n");
179 return ret;
180 }
181
182 /* vintcore has a different layout */
183 val = ret & info->voltage_mask;
184 if (regulator_id == AB8500_LDO_INTCORE)
185 ret = info->supported_voltages[val >> 0x3];
186 else
187 ret = info->supported_voltages[val];
188
189 return ret;
190}
191
192static int ab8500_get_best_voltage_index(struct regulator_dev *rdev,
193 int min_uV, int max_uV)
194{
195 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
196 int i;
197
198 /* check the supported voltage */
199 for (i = 0; i < info->voltages_len; i++) {
200 if ((info->supported_voltages[i] >= min_uV) &&
201 (info->supported_voltages[i] <= max_uV))
202 return i;
203 }
204
205 return -EINVAL;
206}
207
208static int ab8500_regulator_set_voltage(struct regulator_dev *rdev,
209 int min_uV, int max_uV)
210{
211 int regulator_id, ret;
212 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
213
214 regulator_id = rdev_get_id(rdev);
215 if (regulator_id >= AB8500_NUM_REGULATORS)
216 return -EINVAL;
217
218 /* get the appropriate voltages within the range */
219 ret = ab8500_get_best_voltage_index(rdev, min_uV, max_uV);
220 if (ret < 0) {
221 dev_err(rdev_get_dev(rdev),
222 "couldn't get best voltage for regulator\n");
223 return ret;
224 }
225
226 /* set the registers for the request */
227 ret = ab8500_set_bits(info->ab8500, info->voltage_reg,
228 info->voltage_mask, ret);
229 if (ret < 0)
230 dev_err(rdev_get_dev(rdev),
231 "couldn't set voltage reg for regulator\n");
232
233 return ret;
234}
235
236static struct regulator_ops ab8500_regulator_ops = {
237 .enable = ab8500_regulator_enable,
238 .disable = ab8500_regulator_disable,
239 .is_enabled = ab8500_regulator_is_enabled,
240 .get_voltage = ab8500_regulator_get_voltage,
241 .set_voltage = ab8500_regulator_set_voltage,
242 .list_voltage = ab8500_list_voltage,
243};
244
245static int ab8500_fixed_get_voltage(struct regulator_dev *rdev)
246{
247 int regulator_id;
248 struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
249
250 regulator_id = rdev_get_id(rdev);
251 if (regulator_id >= AB8500_NUM_REGULATORS)
252 return -EINVAL;
253
254 return info->fixed_uV;
255}
256
257static struct regulator_ops ab8500_ldo_fixed_ops = {
258 .enable = ab8500_regulator_enable,
259 .disable = ab8500_regulator_disable,
260 .is_enabled = ab8500_regulator_is_enabled,
261 .get_voltage = ab8500_fixed_get_voltage,
262 .list_voltage = ab8500_list_voltage,
263};
264
265#define AB8500_LDO(_id, min, max, reg, reg_mask, reg_enable, \
266 volt_reg, volt_mask, voltages, \
267 len_volts) \
268{ \
269 .desc = { \
270 .name = "LDO-" #_id, \
271 .ops = &ab8500_regulator_ops, \
272 .type = REGULATOR_VOLTAGE, \
273 .id = AB8500_LDO_##_id, \
274 .owner = THIS_MODULE, \
275 }, \
276 .min_uV = (min) * 1000, \
277 .max_uV = (max) * 1000, \
278 .update_reg = reg, \
279 .mask = reg_mask, \
280 .enable = reg_enable, \
281 .voltage_reg = volt_reg, \
282 .voltage_mask = volt_mask, \
283 .supported_voltages = voltages, \
284 .voltages_len = len_volts, \
285 .fixed_uV = 0, \
286}
287
288#define AB8500_FIXED_LDO(_id, fixed, reg, reg_mask, \
289 reg_enable) \
290{ \
291 .desc = { \
292 .name = "LDO-" #_id, \
293 .ops = &ab8500_ldo_fixed_ops, \
294 .type = REGULATOR_VOLTAGE, \
295 .id = AB8500_LDO_##_id, \
296 .owner = THIS_MODULE, \
297 }, \
298 .fixed_uV = fixed * 1000, \
299 .update_reg = reg, \
300 .mask = reg_mask, \
301 .enable = reg_enable, \
302}
303
304static struct ab8500_regulator_info ab8500_regulator_info[] = {
305 /*
306 * Variable Voltage LDOs
307 * name, min uV, max uV, ctrl reg, reg mask, enable mask,
308 * volt ctrl reg, volt ctrl mask, volt table, num supported volts
309 */
310 AB8500_LDO(AUX1, 1100, 3300, 0x0409, 0x3, 0x1, 0x041f, 0xf,
311 ldo_vauxn_voltages, ARRAY_SIZE(ldo_vauxn_voltages)),
312 AB8500_LDO(AUX2, 1100, 3300, 0x0409, 0xc, 0x4, 0x0420, 0xf,
313 ldo_vauxn_voltages, ARRAY_SIZE(ldo_vauxn_voltages)),
314 AB8500_LDO(AUX3, 1100, 3300, 0x040a, 0x3, 0x1, 0x0421, 0xf,
315 ldo_vauxn_voltages, ARRAY_SIZE(ldo_vauxn_voltages)),
316 AB8500_LDO(INTCORE, 1100, 3300, 0x0380, 0x4, 0x4, 0x0380, 0x38,
317 ldo_vintcore_voltages, ARRAY_SIZE(ldo_vintcore_voltages)),
318
319 /*
320 * Fixed Voltage LDOs
321 * name, o/p uV, ctrl reg, enable, disable
322 */
323 AB8500_FIXED_LDO(TVOUT, 2000, 0x0380, 0x2, 0x2),
324 AB8500_FIXED_LDO(AUDIO, 2000, 0x0383, 0x2, 0x2),
325 AB8500_FIXED_LDO(ANAMIC1, 2050, 0x0383, 0x4, 0x4),
326 AB8500_FIXED_LDO(ANAMIC2, 2050, 0x0383, 0x8, 0x8),
327 AB8500_FIXED_LDO(DMIC, 1800, 0x0383, 0x10, 0x10),
328 AB8500_FIXED_LDO(ANA, 1200, 0x0383, 0xc, 0x4),
329};
330
331static inline struct ab8500_regulator_info *find_regulator_info(int id)
332{
333 struct ab8500_regulator_info *info;
334 int i;
335
336 for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) {
337 info = &ab8500_regulator_info[i];
338 if (info->desc.id == id)
339 return info;
340 }
341 return NULL;
342}
343
344static __devinit int ab8500_regulator_probe(struct platform_device *pdev)
345{
346 struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent);
347 struct ab8500_platform_data *pdata = dev_get_platdata(ab8500->dev);
348 int i, err;
349
350 if (!ab8500) {
351 dev_err(&pdev->dev, "null mfd parent\n");
352 return -EINVAL;
353 }
354
355 /* register all regulators */
356 for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) {
357 struct ab8500_regulator_info *info = NULL;
358
359 /* assign per-regulator data */
360 info = &ab8500_regulator_info[i];
361 info->dev = &pdev->dev;
362 info->ab8500 = ab8500;
363
364 info->regulator = regulator_register(&info->desc, &pdev->dev,
365 pdata->regulator[i], info);
366 if (IS_ERR(info->regulator)) {
367 err = PTR_ERR(info->regulator);
368 dev_err(&pdev->dev, "failed to register regulator %s\n",
369 info->desc.name);
370 /* when we fail, un-register all earlier regulators */
371 i--;
372 while (i > 0) {
373 info = &ab8500_regulator_info[i];
374 regulator_unregister(info->regulator);
375 i--;
376 }
377 return err;
378 }
379 }
380
381 return 0;
382}
383
384static __devexit int ab8500_regulator_remove(struct platform_device *pdev)
385{
386 int i;
387
388 for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) {
389 struct ab8500_regulator_info *info = NULL;
390 info = &ab8500_regulator_info[i];
391 regulator_unregister(info->regulator);
392 }
393
394 return 0;
395}
396
397static struct platform_driver ab8500_regulator_driver = {
398 .probe = ab8500_regulator_probe,
399 .remove = __devexit_p(ab8500_regulator_remove),
400 .driver = {
401 .name = "ab8500-regulator",
402 .owner = THIS_MODULE,
403 },
404};
405
406static int __init ab8500_regulator_init(void)
407{
408 int ret;
409
410 ret = platform_driver_register(&ab8500_regulator_driver);
411 if (ret != 0)
412 pr_err("Failed to register ab8500 regulator: %d\n", ret);
413
414 return ret;
415}
416subsys_initcall(ab8500_regulator_init);
417
418static void __exit ab8500_regulator_exit(void)
419{
420 platform_driver_unregister(&ab8500_regulator_driver);
421}
422module_exit(ab8500_regulator_exit);
423
424MODULE_LICENSE("GPL v2");
425MODULE_AUTHOR("Sundar Iyer <sundar.iyer@stericsson.com>");
426MODULE_DESCRIPTION("Regulator Driver for ST-Ericsson AB8500 Mixed-Sig PMIC");
427MODULE_ALIAS("platform:ab8500-regulator");
diff --git a/drivers/regulator/ad5398.c b/drivers/regulator/ad5398.c
new file mode 100644
index 000000000000..d59d2f2314af
--- /dev/null
+++ b/drivers/regulator/ad5398.c
@@ -0,0 +1,288 @@
1/*
2 * Voltage and current regulation for AD5398 and AD5821
3 *
4 * Copyright 2010 Analog Devices Inc.
5 *
6 * Enter bugs at http://blackfin.uclinux.org/
7 *
8 * Licensed under the GPL-2 or later.
9 */
10
11#include <linux/module.h>
12#include <linux/err.h>
13#include <linux/i2c.h>
14#include <linux/slab.h>
15#include <linux/platform_device.h>
16#include <linux/regulator/driver.h>
17#include <linux/regulator/machine.h>
18
19#define AD5398_CURRENT_EN_MASK 0x8000
20
21struct ad5398_chip_info {
22 struct i2c_client *client;
23 int min_uA;
24 int max_uA;
25 unsigned int current_level;
26 unsigned int current_mask;
27 unsigned int current_offset;
28 struct regulator_dev rdev;
29};
30
31static int ad5398_calc_current(struct ad5398_chip_info *chip,
32 unsigned selector)
33{
34 unsigned range_uA = chip->max_uA - chip->min_uA;
35
36 return chip->min_uA + (selector * range_uA / chip->current_level);
37}
38
39static int ad5398_read_reg(struct i2c_client *client, unsigned short *data)
40{
41 unsigned short val;
42 int ret;
43
44 ret = i2c_master_recv(client, (char *)&val, 2);
45 if (ret < 0) {
46 dev_err(&client->dev, "I2C read error\n");
47 return ret;
48 }
49 *data = be16_to_cpu(val);
50
51 return ret;
52}
53
54static int ad5398_write_reg(struct i2c_client *client, const unsigned short data)
55{
56 unsigned short val;
57 int ret;
58
59 val = cpu_to_be16(data);
60 ret = i2c_master_send(client, (char *)&val, 2);
61 if (ret < 0)
62 dev_err(&client->dev, "I2C write error\n");
63
64 return ret;
65}
66
67static int ad5398_get_current_limit(struct regulator_dev *rdev)
68{
69 struct ad5398_chip_info *chip = rdev_get_drvdata(rdev);
70 struct i2c_client *client = chip->client;
71 unsigned short data;
72 int ret;
73
74 ret = ad5398_read_reg(client, &data);
75 if (ret < 0)
76 return ret;
77
78 ret = (data & chip->current_mask) >> chip->current_offset;
79
80 return ad5398_calc_current(chip, ret);
81}
82
83static int ad5398_set_current_limit(struct regulator_dev *rdev, int min_uA, int max_uA)
84{
85 struct ad5398_chip_info *chip = rdev_get_drvdata(rdev);
86 struct i2c_client *client = chip->client;
87 unsigned range_uA = chip->max_uA - chip->min_uA;
88 unsigned selector;
89 unsigned short data;
90 int ret;
91
92 if (min_uA > chip->max_uA || min_uA < chip->min_uA)
93 return -EINVAL;
94 if (max_uA > chip->max_uA || max_uA < chip->min_uA)
95 return -EINVAL;
96
97 selector = ((min_uA - chip->min_uA) * chip->current_level +
98 range_uA - 1) / range_uA;
99 if (ad5398_calc_current(chip, selector) > max_uA)
100 return -EINVAL;
101
102 dev_dbg(&client->dev, "changing current %dmA\n",
103 ad5398_calc_current(chip, selector) / 1000);
104
105 /* read chip enable bit */
106 ret = ad5398_read_reg(client, &data);
107 if (ret < 0)
108 return ret;
109
110 /* prepare register data */
111 selector = (selector << chip->current_offset) & chip->current_mask;
112 data = (unsigned short)selector | (data & AD5398_CURRENT_EN_MASK);
113
114 /* write the new current value back as well as enable bit */
115 ret = ad5398_write_reg(client, data);
116
117 return ret;
118}
119
120static int ad5398_is_enabled(struct regulator_dev *rdev)
121{
122 struct ad5398_chip_info *chip = rdev_get_drvdata(rdev);
123 struct i2c_client *client = chip->client;
124 unsigned short data;
125 int ret;
126
127 ret = ad5398_read_reg(client, &data);
128 if (ret < 0)
129 return ret;
130
131 if (data & AD5398_CURRENT_EN_MASK)
132 return 1;
133 else
134 return 0;
135}
136
137static int ad5398_enable(struct regulator_dev *rdev)
138{
139 struct ad5398_chip_info *chip = rdev_get_drvdata(rdev);
140 struct i2c_client *client = chip->client;
141 unsigned short data;
142 int ret;
143
144 ret = ad5398_read_reg(client, &data);
145 if (ret < 0)
146 return ret;
147
148 if (data & AD5398_CURRENT_EN_MASK)
149 return 0;
150
151 data |= AD5398_CURRENT_EN_MASK;
152
153 ret = ad5398_write_reg(client, data);
154
155 return ret;
156}
157
158static int ad5398_disable(struct regulator_dev *rdev)
159{
160 struct ad5398_chip_info *chip = rdev_get_drvdata(rdev);
161 struct i2c_client *client = chip->client;
162 unsigned short data;
163 int ret;
164
165 ret = ad5398_read_reg(client, &data);
166 if (ret < 0)
167 return ret;
168
169 if (!(data & AD5398_CURRENT_EN_MASK))
170 return 0;
171
172 data &= ~AD5398_CURRENT_EN_MASK;
173
174 ret = ad5398_write_reg(client, data);
175
176 return ret;
177}
178
179static struct regulator_ops ad5398_ops = {
180 .get_current_limit = ad5398_get_current_limit,
181 .set_current_limit = ad5398_set_current_limit,
182 .enable = ad5398_enable,
183 .disable = ad5398_disable,
184 .is_enabled = ad5398_is_enabled,
185};
186
187static struct regulator_desc ad5398_reg = {
188 .name = "isink",
189 .id = 0,
190 .ops = &ad5398_ops,
191 .type = REGULATOR_CURRENT,
192 .owner = THIS_MODULE,
193};
194
195struct ad5398_current_data_format {
196 int current_bits;
197 int current_offset;
198 int min_uA;
199 int max_uA;
200};
201
202static const struct ad5398_current_data_format df_10_4_120 = {10, 4, 0, 120000};
203
204static const struct i2c_device_id ad5398_id[] = {
205 { "ad5398", (kernel_ulong_t)&df_10_4_120 },
206 { "ad5821", (kernel_ulong_t)&df_10_4_120 },
207 { }
208};
209MODULE_DEVICE_TABLE(i2c, ad5398_id);
210
211static int __devinit ad5398_probe(struct i2c_client *client,
212 const struct i2c_device_id *id)
213{
214 struct regulator_dev *rdev;
215 struct regulator_init_data *init_data = client->dev.platform_data;
216 struct ad5398_chip_info *chip;
217 const struct ad5398_current_data_format *df =
218 (struct ad5398_current_data_format *)id->driver_data;
219 int ret;
220
221 if (!init_data)
222 return -EINVAL;
223
224 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
225 if (!chip)
226 return -ENOMEM;
227
228 chip->client = client;
229
230 chip->min_uA = df->min_uA;
231 chip->max_uA = df->max_uA;
232 chip->current_level = 1 << df->current_bits;
233 chip->current_offset = df->current_offset;
234 chip->current_mask = (chip->current_level - 1) << chip->current_offset;
235
236 rdev = regulator_register(&ad5398_reg, &client->dev, init_data, chip);
237 if (IS_ERR(rdev)) {
238 ret = PTR_ERR(rdev);
239 dev_err(&client->dev, "failed to register %s %s\n",
240 id->name, ad5398_reg.name);
241 goto err;
242 }
243
244 i2c_set_clientdata(client, chip);
245 dev_dbg(&client->dev, "%s regulator driver is registered.\n", id->name);
246 return 0;
247
248err:
249 kfree(chip);
250 return ret;
251}
252
253static int __devexit ad5398_remove(struct i2c_client *client)
254{
255 struct ad5398_chip_info *chip = i2c_get_clientdata(client);
256
257 regulator_unregister(&chip->rdev);
258 kfree(chip);
259 i2c_set_clientdata(client, NULL);
260
261 return 0;
262}
263
264static struct i2c_driver ad5398_driver = {
265 .probe = ad5398_probe,
266 .remove = __devexit_p(ad5398_remove),
267 .driver = {
268 .name = "ad5398",
269 },
270 .id_table = ad5398_id,
271};
272
273static int __init ad5398_init(void)
274{
275 return i2c_add_driver(&ad5398_driver);
276}
277subsys_initcall(ad5398_init);
278
279static void __exit ad5398_exit(void)
280{
281 i2c_del_driver(&ad5398_driver);
282}
283module_exit(ad5398_exit);
284
285MODULE_DESCRIPTION("AD5398 and AD5821 current regulator driver");
286MODULE_AUTHOR("Sonic Zhang");
287MODULE_LICENSE("GPL");
288MODULE_ALIAS("i2c:ad5398-regulator");
diff --git a/drivers/regulator/isl6271a-regulator.c b/drivers/regulator/isl6271a-regulator.c
new file mode 100644
index 000000000000..e49d2bd393f2
--- /dev/null
+++ b/drivers/regulator/isl6271a-regulator.c
@@ -0,0 +1,236 @@
1/*
2 * isl6271a-regulator.c
3 *
4 * Support for Intersil ISL6271A voltage regulator
5 *
6 * Copyright (C) 2010 Marek Vasut <marek.vasut@gmail.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 version 2.
11 *
12 * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind,
13 * whether express or implied; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 */
17
18#include <linux/kernel.h>
19#include <linux/module.h>
20#include <linux/init.h>
21#include <linux/err.h>
22#include <linux/platform_device.h>
23#include <linux/regulator/driver.h>
24#include <linux/i2c.h>
25#include <linux/delay.h>
26#include <linux/slab.h>
27
28#define ISL6271A_VOLTAGE_MIN 850000
29#define ISL6271A_VOLTAGE_MAX 1600000
30#define ISL6271A_VOLTAGE_STEP 50000
31
32/* PMIC details */
33struct isl_pmic {
34 struct i2c_client *client;
35 struct regulator_dev *rdev[3];
36 struct mutex mtx;
37};
38
39static int isl6271a_get_voltage(struct regulator_dev *dev)
40{
41 struct isl_pmic *pmic = rdev_get_drvdata(dev);
42 int idx, data;
43
44 mutex_lock(&pmic->mtx);
45
46 idx = i2c_smbus_read_byte(pmic->client);
47 if (idx < 0) {
48 dev_err(&pmic->client->dev, "Error getting voltage\n");
49 data = idx;
50 goto out;
51 }
52
53 /* Convert the data from chip to microvolts */
54 data = ISL6271A_VOLTAGE_MIN + (ISL6271A_VOLTAGE_STEP * (idx & 0xf));
55
56out:
57 mutex_unlock(&pmic->mtx);
58 return data;
59}
60
61static int isl6271a_set_voltage(struct regulator_dev *dev, int minuV, int maxuV)
62{
63 struct isl_pmic *pmic = rdev_get_drvdata(dev);
64 int vsel, err, data;
65
66 if (minuV < ISL6271A_VOLTAGE_MIN || minuV > ISL6271A_VOLTAGE_MAX)
67 return -EINVAL;
68 if (maxuV < ISL6271A_VOLTAGE_MIN || maxuV > ISL6271A_VOLTAGE_MAX)
69 return -EINVAL;
70
71 /* Align to 50000 mV */
72 vsel = minuV - (minuV % ISL6271A_VOLTAGE_STEP);
73
74 /* If the result fell out of [minuV,maxuV] range, put it back */
75 if (vsel < minuV)
76 vsel += ISL6271A_VOLTAGE_STEP;
77
78 /* Convert the microvolts to data for the chip */
79 data = (vsel - ISL6271A_VOLTAGE_MIN) / ISL6271A_VOLTAGE_STEP;
80
81 mutex_lock(&pmic->mtx);
82
83 err = i2c_smbus_write_byte(pmic->client, data);
84 if (err < 0)
85 dev_err(&pmic->client->dev, "Error setting voltage\n");
86
87 mutex_unlock(&pmic->mtx);
88 return err;
89}
90
91static int isl6271a_list_voltage(struct regulator_dev *dev, unsigned selector)
92{
93 return ISL6271A_VOLTAGE_MIN + (ISL6271A_VOLTAGE_STEP * selector);
94}
95
96static struct regulator_ops isl_core_ops = {
97 .get_voltage = isl6271a_get_voltage,
98 .set_voltage = isl6271a_set_voltage,
99 .list_voltage = isl6271a_list_voltage,
100};
101
102static int isl6271a_get_fixed_voltage(struct regulator_dev *dev)
103{
104 int id = rdev_get_id(dev);
105 return (id == 1) ? 1100000 : 1300000;
106}
107
108static int isl6271a_list_fixed_voltage(struct regulator_dev *dev, unsigned selector)
109{
110 int id = rdev_get_id(dev);
111 return (id == 1) ? 1100000 : 1300000;
112}
113
114static struct regulator_ops isl_fixed_ops = {
115 .get_voltage = isl6271a_get_fixed_voltage,
116 .list_voltage = isl6271a_list_fixed_voltage,
117};
118
119static struct regulator_desc isl_rd[] = {
120 {
121 .name = "Core Buck",
122 .id = 0,
123 .n_voltages = 16,
124 .ops = &isl_core_ops,
125 .type = REGULATOR_VOLTAGE,
126 .owner = THIS_MODULE,
127 }, {
128 .name = "LDO1",
129 .id = 1,
130 .n_voltages = 1,
131 .ops = &isl_fixed_ops,
132 .type = REGULATOR_VOLTAGE,
133 .owner = THIS_MODULE,
134 }, {
135 .name = "LDO2",
136 .id = 2,
137 .n_voltages = 1,
138 .ops = &isl_fixed_ops,
139 .type = REGULATOR_VOLTAGE,
140 .owner = THIS_MODULE,
141 },
142};
143
144static int __devinit isl6271a_probe(struct i2c_client *i2c,
145 const struct i2c_device_id *id)
146{
147 struct regulator_init_data *init_data = i2c->dev.platform_data;
148 struct isl_pmic *pmic;
149 int err, i;
150
151 if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
152 return -EIO;
153
154 if (!init_data) {
155 dev_err(&i2c->dev, "no platform data supplied\n");
156 return -EIO;
157 }
158
159 pmic = kzalloc(sizeof(struct isl_pmic), GFP_KERNEL);
160 if (!pmic)
161 return -ENOMEM;
162
163 pmic->client = i2c;
164
165 mutex_init(&pmic->mtx);
166
167 for (i = 0; i < 3; i++) {
168 pmic->rdev[i] = regulator_register(&isl_rd[0], &i2c->dev,
169 init_data, pmic);
170 if (IS_ERR(pmic->rdev[i])) {
171 dev_err(&i2c->dev, "failed to register %s\n", id->name);
172 err = PTR_ERR(pmic->rdev);
173 goto error;
174 }
175 }
176
177 i2c_set_clientdata(i2c, pmic);
178
179 return 0;
180
181error:
182 while (--i >= 0)
183 regulator_unregister(pmic->rdev[i]);
184
185 kfree(pmic);
186 return err;
187}
188
189static int __devexit isl6271a_remove(struct i2c_client *i2c)
190{
191 struct isl_pmic *pmic = i2c_get_clientdata(i2c);
192 int i;
193
194 i2c_set_clientdata(i2c, NULL);
195
196 for (i = 0; i < 3; i++)
197 regulator_unregister(pmic->rdev[i]);
198
199 kfree(pmic);
200
201 return 0;
202}
203
204static const struct i2c_device_id isl6271a_id[] = {
205 {.name = "isl6271a", 0 },
206 { },
207};
208
209MODULE_DEVICE_TABLE(i2c, isl6271a_id);
210
211static struct i2c_driver isl6271a_i2c_driver = {
212 .driver = {
213 .name = "isl6271a",
214 .owner = THIS_MODULE,
215 },
216 .probe = isl6271a_probe,
217 .remove = __devexit_p(isl6271a_remove),
218 .id_table = isl6271a_id,
219};
220
221static int __init isl6271a_init(void)
222{
223 return i2c_add_driver(&isl6271a_i2c_driver);
224}
225
226static void __exit isl6271a_cleanup(void)
227{
228 i2c_del_driver(&isl6271a_i2c_driver);
229}
230
231subsys_initcall(isl6271a_init);
232module_exit(isl6271a_cleanup);
233
234MODULE_AUTHOR("Marek Vasut <marek.vasut@gmail.com>");
235MODULE_DESCRIPTION("Intersil ISL6271A voltage regulator driver");
236MODULE_LICENSE("GPL v2");
diff --git a/drivers/regulator/lp3971.c b/drivers/regulator/lp3971.c
index 8ae3732eb24b..3bb82b624e19 100644
--- a/drivers/regulator/lp3971.c
+++ b/drivers/regulator/lp3971.c
@@ -377,7 +377,7 @@ static int lp3971_i2c_read(struct i2c_client *i2c, char reg, int count,
377 if (count != 1) 377 if (count != 1)
378 return -EIO; 378 return -EIO;
379 ret = i2c_smbus_read_byte_data(i2c, reg); 379 ret = i2c_smbus_read_byte_data(i2c, reg);
380 if (ret < 0 || count != 1) 380 if (ret < 0)
381 return -EIO; 381 return -EIO;
382 382
383 *dest = ret; 383 *dest = ret;
@@ -387,15 +387,9 @@ static int lp3971_i2c_read(struct i2c_client *i2c, char reg, int count,
387static int lp3971_i2c_write(struct i2c_client *i2c, char reg, int count, 387static int lp3971_i2c_write(struct i2c_client *i2c, char reg, int count,
388 const u16 *src) 388 const u16 *src)
389{ 389{
390 int ret;
391
392 if (count != 1) 390 if (count != 1)
393 return -EIO; 391 return -EIO;
394 ret = i2c_smbus_write_byte_data(i2c, reg, *src); 392 return i2c_smbus_write_byte_data(i2c, reg, *src);
395 if (ret >= 0)
396 return 0;
397
398 return ret;
399} 393}
400 394
401static u8 lp3971_reg_read(struct lp3971 *lp3971, u8 reg) 395static u8 lp3971_reg_read(struct lp3971 *lp3971, u8 reg)
diff --git a/drivers/regulator/max1586.c b/drivers/regulator/max1586.c
index 2b54d9d75f11..8867c2710a6d 100644
--- a/drivers/regulator/max1586.c
+++ b/drivers/regulator/max1586.c
@@ -223,7 +223,7 @@ static int __devinit max1586_pmic_probe(struct i2c_client *client,
223 } 223 }
224 } 224 }
225 225
226 i2c_set_clientdata(client, rdev); 226 i2c_set_clientdata(client, max1586);
227 dev_info(&client->dev, "Maxim 1586 regulator driver loaded\n"); 227 dev_info(&client->dev, "Maxim 1586 regulator driver loaded\n");
228 return 0; 228 return 0;
229 229
@@ -238,13 +238,13 @@ out:
238 238
239static int __devexit max1586_pmic_remove(struct i2c_client *client) 239static int __devexit max1586_pmic_remove(struct i2c_client *client)
240{ 240{
241 struct regulator_dev **rdev = i2c_get_clientdata(client); 241 struct max1586_data *max1586 = i2c_get_clientdata(client);
242 int i; 242 int i;
243 243
244 for (i = 0; i <= MAX1586_V6; i++) 244 for (i = 0; i <= MAX1586_V6; i++)
245 if (rdev[i]) 245 if (max1586->rdev[i])
246 regulator_unregister(rdev[i]); 246 regulator_unregister(max1586->rdev[i]);
247 kfree(rdev); 247 kfree(max1586);
248 248
249 return 0; 249 return 0;
250} 250}
diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
index d97220efae5a..c570e6eb0db2 100644
--- a/drivers/regulator/max8660.c
+++ b/drivers/regulator/max8660.c
@@ -450,7 +450,7 @@ static int __devinit max8660_probe(struct i2c_client *client,
450 } 450 }
451 } 451 }
452 452
453 i2c_set_clientdata(client, rdev); 453 i2c_set_clientdata(client, max8660);
454 dev_info(&client->dev, "Maxim 8660/8661 regulator driver loaded\n"); 454 dev_info(&client->dev, "Maxim 8660/8661 regulator driver loaded\n");
455 return 0; 455 return 0;
456 456
@@ -465,13 +465,13 @@ out:
465 465
466static int __devexit max8660_remove(struct i2c_client *client) 466static int __devexit max8660_remove(struct i2c_client *client)
467{ 467{
468 struct regulator_dev **rdev = i2c_get_clientdata(client); 468 struct max8660 *max8660 = i2c_get_clientdata(client);
469 int i; 469 int i;
470 470
471 for (i = 0; i < MAX8660_V_END; i++) 471 for (i = 0; i < MAX8660_V_END; i++)
472 if (rdev[i]) 472 if (max8660->rdev[i])
473 regulator_unregister(rdev[i]); 473 regulator_unregister(max8660->rdev[i]);
474 kfree(rdev); 474 kfree(max8660);
475 475
476 return 0; 476 return 0;
477} 477}
diff --git a/drivers/regulator/max8998.c b/drivers/regulator/max8998.c
new file mode 100644
index 000000000000..ab67298799f9
--- /dev/null
+++ b/drivers/regulator/max8998.c
@@ -0,0 +1,635 @@
1/*
2 * max8998.c - Voltage regulator driver for the Maxim 8998
3 *
4 * Copyright (C) 2009-2010 Samsung Electronics
5 * Kyungmin Park <kyungmin.park@samsung.com>
6 * Marek Szyprowski <m.szyprowski@samsung.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 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23#include <linux/module.h>
24#include <linux/init.h>
25#include <linux/i2c.h>
26#include <linux/err.h>
27#include <linux/gpio.h>
28#include <linux/slab.h>
29#include <linux/interrupt.h>
30#include <linux/mutex.h>
31#include <linux/delay.h>
32#include <linux/platform_device.h>
33#include <linux/regulator/driver.h>
34#include <linux/mfd/max8998.h>
35#include <linux/mfd/max8998-private.h>
36
37struct max8998_data {
38 struct device *dev;
39 struct max8998_dev *iodev;
40 int num_regulators;
41 struct regulator_dev **rdev;
42};
43
44struct voltage_map_desc {
45 int min;
46 int max;
47 int step;
48};
49
50/* Voltage maps */
51static const struct voltage_map_desc ldo23_voltage_map_desc = {
52 .min = 800, .step = 50, .max = 1300,
53};
54static const struct voltage_map_desc ldo456711_voltage_map_desc = {
55 .min = 1600, .step = 100, .max = 3600,
56};
57static const struct voltage_map_desc ldo8_voltage_map_desc = {
58 .min = 3000, .step = 100, .max = 3600,
59};
60static const struct voltage_map_desc ldo9_voltage_map_desc = {
61 .min = 2800, .step = 100, .max = 3100,
62};
63static const struct voltage_map_desc ldo10_voltage_map_desc = {
64 .min = 950, .step = 50, .max = 1300,
65};
66static const struct voltage_map_desc ldo1213_voltage_map_desc = {
67 .min = 800, .step = 100, .max = 3300,
68};
69static const struct voltage_map_desc ldo1415_voltage_map_desc = {
70 .min = 1200, .step = 100, .max = 3300,
71};
72static const struct voltage_map_desc ldo1617_voltage_map_desc = {
73 .min = 1600, .step = 100, .max = 3600,
74};
75static const struct voltage_map_desc buck12_voltage_map_desc = {
76 .min = 750, .step = 25, .max = 1525,
77};
78static const struct voltage_map_desc buck3_voltage_map_desc = {
79 .min = 1600, .step = 100, .max = 3600,
80};
81static const struct voltage_map_desc buck4_voltage_map_desc = {
82 .min = 800, .step = 100, .max = 2300,
83};
84
85static const struct voltage_map_desc *ldo_voltage_map[] = {
86 NULL,
87 NULL,
88 &ldo23_voltage_map_desc, /* LDO2 */
89 &ldo23_voltage_map_desc, /* LDO3 */
90 &ldo456711_voltage_map_desc, /* LDO4 */
91 &ldo456711_voltage_map_desc, /* LDO5 */
92 &ldo456711_voltage_map_desc, /* LDO6 */
93 &ldo456711_voltage_map_desc, /* LDO7 */
94 &ldo8_voltage_map_desc, /* LDO8 */
95 &ldo9_voltage_map_desc, /* LDO9 */
96 &ldo10_voltage_map_desc, /* LDO10 */
97 &ldo456711_voltage_map_desc, /* LDO11 */
98 &ldo1213_voltage_map_desc, /* LDO12 */
99 &ldo1213_voltage_map_desc, /* LDO13 */
100 &ldo1415_voltage_map_desc, /* LDO14 */
101 &ldo1415_voltage_map_desc, /* LDO15 */
102 &ldo1617_voltage_map_desc, /* LDO16 */
103 &ldo1617_voltage_map_desc, /* LDO17 */
104 &buck12_voltage_map_desc, /* BUCK1 */
105 &buck12_voltage_map_desc, /* BUCK2 */
106 &buck3_voltage_map_desc, /* BUCK3 */
107 &buck4_voltage_map_desc, /* BUCK4 */
108};
109
110static inline int max8998_get_ldo(struct regulator_dev *rdev)
111{
112 return rdev_get_id(rdev);
113}
114
115static int max8998_list_voltage(struct regulator_dev *rdev,
116 unsigned int selector)
117{
118 const struct voltage_map_desc *desc;
119 int ldo = max8998_get_ldo(rdev);
120 int val;
121
122 if (ldo >= ARRAY_SIZE(ldo_voltage_map))
123 return -EINVAL;
124
125 desc = ldo_voltage_map[ldo];
126 if (desc == NULL)
127 return -EINVAL;
128
129 val = desc->min + desc->step * selector;
130 if (val > desc->max)
131 return -EINVAL;
132
133 return val * 1000;
134}
135
136static int max8998_get_enable_register(struct regulator_dev *rdev,
137 int *reg, int *shift)
138{
139 int ldo = max8998_get_ldo(rdev);
140
141 switch (ldo) {
142 case MAX8998_LDO2 ... MAX8998_LDO5:
143 *reg = MAX8998_REG_ONOFF1;
144 *shift = 3 - (ldo - MAX8998_LDO2);
145 break;
146 case MAX8998_LDO6 ... MAX8998_LDO13:
147 *reg = MAX8998_REG_ONOFF2;
148 *shift = 7 - (ldo - MAX8998_LDO6);
149 break;
150 case MAX8998_LDO14 ... MAX8998_LDO17:
151 *reg = MAX8998_REG_ONOFF3;
152 *shift = 7 - (ldo - MAX8998_LDO14);
153 break;
154 case MAX8998_BUCK1 ... MAX8998_BUCK4:
155 *reg = MAX8998_REG_ONOFF1;
156 *shift = 7 - (ldo - MAX8998_BUCK1);
157 break;
158 case MAX8998_EN32KHZ_AP ... MAX8998_ENVICHG:
159 *reg = MAX8998_REG_ONOFF4;
160 *shift = 7 - (ldo - MAX8998_EN32KHZ_AP);
161 break;
162 case MAX8998_ESAFEOUT1 ... MAX8998_ESAFEOUT2:
163 *reg = MAX8998_REG_CHGR2;
164 *shift = 7 - (ldo - MAX8998_ESAFEOUT1);
165 break;
166 default:
167 return -EINVAL;
168 }
169
170 return 0;
171}
172
173static int max8998_ldo_is_enabled(struct regulator_dev *rdev)
174{
175 struct max8998_data *max8998 = rdev_get_drvdata(rdev);
176 int ret, reg, shift = 8;
177 u8 val;
178
179 ret = max8998_get_enable_register(rdev, &reg, &shift);
180 if (ret)
181 return ret;
182
183 ret = max8998_read_reg(max8998->iodev, reg, &val);
184 if (ret)
185 return ret;
186
187 return val & (1 << shift);
188}
189
190static int max8998_ldo_enable(struct regulator_dev *rdev)
191{
192 struct max8998_data *max8998 = rdev_get_drvdata(rdev);
193 int reg, shift = 8, ret;
194
195 ret = max8998_get_enable_register(rdev, &reg, &shift);
196 if (ret)
197 return ret;
198
199 return max8998_update_reg(max8998->iodev, reg, 1<<shift, 1<<shift);
200}
201
202static int max8998_ldo_disable(struct regulator_dev *rdev)
203{
204 struct max8998_data *max8998 = rdev_get_drvdata(rdev);
205 int reg, shift = 8, ret;
206
207 ret = max8998_get_enable_register(rdev, &reg, &shift);
208 if (ret)
209 return ret;
210
211 return max8998_update_reg(max8998->iodev, reg, 0, 1<<shift);
212}
213
214static int max8998_get_voltage_register(struct regulator_dev *rdev,
215 int *_reg, int *_shift, int *_mask)
216{
217 int ldo = max8998_get_ldo(rdev);
218 int reg, shift = 0, mask = 0xff;
219
220 switch (ldo) {
221 case MAX8998_LDO2 ... MAX8998_LDO3:
222 reg = MAX8998_REG_LDO2_LDO3;
223 mask = 0xf;
224 if (ldo == MAX8998_LDO2)
225 shift = 4;
226 else
227 shift = 0;
228 break;
229 case MAX8998_LDO4 ... MAX8998_LDO7:
230 reg = MAX8998_REG_LDO4 + (ldo - MAX8998_LDO4);
231 break;
232 case MAX8998_LDO8 ... MAX8998_LDO9:
233 reg = MAX8998_REG_LDO8_LDO9;
234 mask = 0xf;
235 if (ldo == MAX8998_LDO8)
236 shift = 4;
237 else
238 shift = 0;
239 break;
240 case MAX8998_LDO10 ... MAX8998_LDO11:
241 reg = MAX8998_REG_LDO10_LDO11;
242 if (ldo == MAX8998_LDO10) {
243 shift = 5;
244 mask = 0x7;
245 } else {
246 shift = 0;
247 mask = 0x1f;
248 }
249 break;
250 case MAX8998_LDO12 ... MAX8998_LDO17:
251 reg = MAX8998_REG_LDO12 + (ldo - MAX8998_LDO12);
252 break;
253 case MAX8998_BUCK1:
254 reg = MAX8998_REG_BUCK1_DVSARM1;
255 break;
256 case MAX8998_BUCK2:
257 reg = MAX8998_REG_BUCK2_DVSINT1;
258 break;
259 case MAX8998_BUCK3:
260 reg = MAX8998_REG_BUCK3;
261 break;
262 case MAX8998_BUCK4:
263 reg = MAX8998_REG_BUCK4;
264 break;
265 default:
266 return -EINVAL;
267 }
268
269 *_reg = reg;
270 *_shift = shift;
271 *_mask = mask;
272
273 return 0;
274}
275
276static int max8998_get_voltage(struct regulator_dev *rdev)
277{
278 struct max8998_data *max8998 = rdev_get_drvdata(rdev);
279 int reg, shift = 0, mask, ret;
280 u8 val;
281
282 ret = max8998_get_voltage_register(rdev, &reg, &shift, &mask);
283 if (ret)
284 return ret;
285
286 ret = max8998_read_reg(max8998->iodev, reg, &val);
287 if (ret)
288 return ret;
289
290 val >>= shift;
291 val &= mask;
292
293 return max8998_list_voltage(rdev, val);
294}
295
296static int max8998_set_voltage(struct regulator_dev *rdev,
297 int min_uV, int max_uV)
298{
299 struct max8998_data *max8998 = rdev_get_drvdata(rdev);
300 int min_vol = min_uV / 1000, max_vol = max_uV / 1000;
301 int previous_vol = 0;
302 const struct voltage_map_desc *desc;
303 int ldo = max8998_get_ldo(rdev);
304 int reg, shift = 0, mask, ret;
305 int i = 0;
306 u8 val;
307 bool en_ramp = false;
308
309 if (ldo >= ARRAY_SIZE(ldo_voltage_map))
310 return -EINVAL;
311
312 desc = ldo_voltage_map[ldo];
313 if (desc == NULL)
314 return -EINVAL;
315
316 if (max_vol < desc->min || min_vol > desc->max)
317 return -EINVAL;
318
319 while (desc->min + desc->step*i < min_vol &&
320 desc->min + desc->step*i < desc->max)
321 i++;
322
323 if (desc->min + desc->step*i > max_vol)
324 return -EINVAL;
325
326 ret = max8998_get_voltage_register(rdev, &reg, &shift, &mask);
327 if (ret)
328 return ret;
329
330 /* wait for RAMP_UP_DELAY if rdev is BUCK1/2 and
331 * ENRAMP is ON */
332 if (ldo == MAX8998_BUCK1 || ldo == MAX8998_BUCK2) {
333 max8998_read_reg(max8998->iodev, MAX8998_REG_ONOFF4, &val);
334 if (val & (1 << 4)) {
335 en_ramp = true;
336 previous_vol = max8998_get_voltage(rdev);
337 }
338 }
339
340 ret = max8998_update_reg(max8998->iodev, reg, i<<shift, mask<<shift);
341
342 if (en_ramp == true) {
343 int difference = desc->min + desc->step*i - previous_vol/1000;
344 if (difference > 0)
345 udelay(difference / ((val & 0x0f) + 1));
346 }
347
348 return ret;
349}
350
351static struct regulator_ops max8998_ldo_ops = {
352 .list_voltage = max8998_list_voltage,
353 .is_enabled = max8998_ldo_is_enabled,
354 .enable = max8998_ldo_enable,
355 .disable = max8998_ldo_disable,
356 .get_voltage = max8998_get_voltage,
357 .set_voltage = max8998_set_voltage,
358 .set_suspend_enable = max8998_ldo_enable,
359 .set_suspend_disable = max8998_ldo_disable,
360};
361
362static struct regulator_ops max8998_buck_ops = {
363 .list_voltage = max8998_list_voltage,
364 .is_enabled = max8998_ldo_is_enabled,
365 .enable = max8998_ldo_enable,
366 .disable = max8998_ldo_disable,
367 .get_voltage = max8998_get_voltage,
368 .set_voltage = max8998_set_voltage,
369 .set_suspend_enable = max8998_ldo_enable,
370 .set_suspend_disable = max8998_ldo_disable,
371};
372
373static struct regulator_ops max8998_others_ops = {
374 .is_enabled = max8998_ldo_is_enabled,
375 .enable = max8998_ldo_enable,
376 .disable = max8998_ldo_disable,
377 .set_suspend_enable = max8998_ldo_enable,
378 .set_suspend_disable = max8998_ldo_disable,
379};
380
381static struct regulator_desc regulators[] = {
382 {
383 .name = "LDO2",
384 .id = MAX8998_LDO2,
385 .ops = &max8998_ldo_ops,
386 .type = REGULATOR_VOLTAGE,
387 .owner = THIS_MODULE,
388 }, {
389 .name = "LDO3",
390 .id = MAX8998_LDO3,
391 .ops = &max8998_ldo_ops,
392 .type = REGULATOR_VOLTAGE,
393 .owner = THIS_MODULE,
394 }, {
395 .name = "LDO4",
396 .id = MAX8998_LDO4,
397 .ops = &max8998_ldo_ops,
398 .type = REGULATOR_VOLTAGE,
399 .owner = THIS_MODULE,
400 }, {
401 .name = "LDO5",
402 .id = MAX8998_LDO5,
403 .ops = &max8998_ldo_ops,
404 .type = REGULATOR_VOLTAGE,
405 .owner = THIS_MODULE,
406 }, {
407 .name = "LDO6",
408 .id = MAX8998_LDO6,
409 .ops = &max8998_ldo_ops,
410 .type = REGULATOR_VOLTAGE,
411 .owner = THIS_MODULE,
412 }, {
413 .name = "LDO7",
414 .id = MAX8998_LDO7,
415 .ops = &max8998_ldo_ops,
416 .type = REGULATOR_VOLTAGE,
417 .owner = THIS_MODULE,
418 }, {
419 .name = "LDO8",
420 .id = MAX8998_LDO8,
421 .ops = &max8998_ldo_ops,
422 .type = REGULATOR_VOLTAGE,
423 .owner = THIS_MODULE,
424 }, {
425 .name = "LDO9",
426 .id = MAX8998_LDO9,
427 .ops = &max8998_ldo_ops,
428 .type = REGULATOR_VOLTAGE,
429 .owner = THIS_MODULE,
430 }, {
431 .name = "LDO10",
432 .id = MAX8998_LDO10,
433 .ops = &max8998_ldo_ops,
434 .type = REGULATOR_VOLTAGE,
435 .owner = THIS_MODULE,
436 }, {
437 .name = "LDO11",
438 .id = MAX8998_LDO11,
439 .ops = &max8998_ldo_ops,
440 .type = REGULATOR_VOLTAGE,
441 .owner = THIS_MODULE,
442 }, {
443 .name = "LDO12",
444 .id = MAX8998_LDO12,
445 .ops = &max8998_ldo_ops,
446 .type = REGULATOR_VOLTAGE,
447 .owner = THIS_MODULE,
448 }, {
449 .name = "LDO13",
450 .id = MAX8998_LDO13,
451 .ops = &max8998_ldo_ops,
452 .type = REGULATOR_VOLTAGE,
453 .owner = THIS_MODULE,
454 }, {
455 .name = "LDO14",
456 .id = MAX8998_LDO14,
457 .ops = &max8998_ldo_ops,
458 .type = REGULATOR_VOLTAGE,
459 .owner = THIS_MODULE,
460 }, {
461 .name = "LDO15",
462 .id = MAX8998_LDO15,
463 .ops = &max8998_ldo_ops,
464 .type = REGULATOR_VOLTAGE,
465 .owner = THIS_MODULE,
466 }, {
467 .name = "LDO16",
468 .id = MAX8998_LDO16,
469 .ops = &max8998_ldo_ops,
470 .type = REGULATOR_VOLTAGE,
471 .owner = THIS_MODULE,
472 }, {
473 .name = "LDO17",
474 .id = MAX8998_LDO17,
475 .ops = &max8998_ldo_ops,
476 .type = REGULATOR_VOLTAGE,
477 .owner = THIS_MODULE,
478 }, {
479 .name = "BUCK1",
480 .id = MAX8998_BUCK1,
481 .ops = &max8998_buck_ops,
482 .type = REGULATOR_VOLTAGE,
483 .owner = THIS_MODULE,
484 }, {
485 .name = "BUCK2",
486 .id = MAX8998_BUCK2,
487 .ops = &max8998_buck_ops,
488 .type = REGULATOR_VOLTAGE,
489 .owner = THIS_MODULE,
490 }, {
491 .name = "BUCK3",
492 .id = MAX8998_BUCK3,
493 .ops = &max8998_buck_ops,
494 .type = REGULATOR_VOLTAGE,
495 .owner = THIS_MODULE,
496 }, {
497 .name = "BUCK4",
498 .id = MAX8998_BUCK4,
499 .ops = &max8998_buck_ops,
500 .type = REGULATOR_VOLTAGE,
501 .owner = THIS_MODULE,
502 }, {
503 .name = "EN32KHz AP",
504 .id = MAX8998_EN32KHZ_AP,
505 .ops = &max8998_others_ops,
506 .type = REGULATOR_VOLTAGE,
507 .owner = THIS_MODULE,
508 }, {
509 .name = "EN32KHz CP",
510 .id = MAX8998_EN32KHZ_CP,
511 .ops = &max8998_others_ops,
512 .type = REGULATOR_VOLTAGE,
513 .owner = THIS_MODULE,
514 }, {
515 .name = "ENVICHG",
516 .id = MAX8998_ENVICHG,
517 .ops = &max8998_others_ops,
518 .type = REGULATOR_VOLTAGE,
519 .owner = THIS_MODULE,
520 }, {
521 .name = "ESAFEOUT1",
522 .id = MAX8998_ESAFEOUT1,
523 .ops = &max8998_others_ops,
524 .type = REGULATOR_VOLTAGE,
525 .owner = THIS_MODULE,
526 }, {
527 .name = "ESAFEOUT2",
528 .id = MAX8998_ESAFEOUT2,
529 .ops = &max8998_others_ops,
530 .type = REGULATOR_VOLTAGE,
531 .owner = THIS_MODULE,
532 }
533};
534
535static __devinit int max8998_pmic_probe(struct platform_device *pdev)
536{
537 struct max8998_dev *iodev = dev_get_drvdata(pdev->dev.parent);
538 struct max8998_platform_data *pdata = dev_get_platdata(iodev->dev);
539 struct regulator_dev **rdev;
540 struct max8998_data *max8998;
541 int i, ret, size;
542
543 if (!pdata) {
544 dev_err(pdev->dev.parent, "No platform init data supplied\n");
545 return -ENODEV;
546 }
547
548 max8998 = kzalloc(sizeof(struct max8998_data), GFP_KERNEL);
549 if (!max8998)
550 return -ENOMEM;
551
552 size = sizeof(struct regulator_dev *) * (pdata->num_regulators + 1);
553 max8998->rdev = kzalloc(size, GFP_KERNEL);
554 if (!max8998->rdev) {
555 kfree(max8998);
556 return -ENOMEM;
557 }
558
559 rdev = max8998->rdev;
560 max8998->iodev = iodev;
561 platform_set_drvdata(pdev, max8998);
562
563 for (i = 0; i < pdata->num_regulators; i++) {
564 const struct voltage_map_desc *desc;
565 int id = pdata->regulators[i].id;
566 int index = id - MAX8998_LDO2;
567
568 desc = ldo_voltage_map[id];
569 if (desc && regulators[index].ops != &max8998_others_ops) {
570 int count = (desc->max - desc->min) / desc->step + 1;
571 regulators[index].n_voltages = count;
572 }
573 rdev[i] = regulator_register(&regulators[index], max8998->dev,
574 pdata->regulators[i].initdata, max8998);
575 if (IS_ERR(rdev[i])) {
576 ret = PTR_ERR(rdev[i]);
577 dev_err(max8998->dev, "regulator init failed\n");
578 rdev[i] = NULL;
579 goto err;
580 }
581 }
582
583
584 return 0;
585err:
586 for (i = 0; i <= max8998->num_regulators; i++)
587 if (rdev[i])
588 regulator_unregister(rdev[i]);
589
590 kfree(max8998->rdev);
591 kfree(max8998);
592
593 return ret;
594}
595
596static int __devexit max8998_pmic_remove(struct platform_device *pdev)
597{
598 struct max8998_data *max8998 = platform_get_drvdata(pdev);
599 struct regulator_dev **rdev = max8998->rdev;
600 int i;
601
602 for (i = 0; i <= max8998->num_regulators; i++)
603 if (rdev[i])
604 regulator_unregister(rdev[i]);
605
606 kfree(max8998->rdev);
607 kfree(max8998);
608
609 return 0;
610}
611
612static struct platform_driver max8998_pmic_driver = {
613 .driver = {
614 .name = "max8998-pmic",
615 .owner = THIS_MODULE,
616 },
617 .probe = max8998_pmic_probe,
618 .remove = __devexit_p(max8998_pmic_remove),
619};
620
621static int __init max8998_pmic_init(void)
622{
623 return platform_driver_register(&max8998_pmic_driver);
624}
625subsys_initcall(max8998_pmic_init);
626
627static void __exit max8998_pmic_cleanup(void)
628{
629 platform_driver_unregister(&max8998_pmic_driver);
630}
631module_exit(max8998_pmic_cleanup);
632
633MODULE_DESCRIPTION("MAXIM 8998 voltage regulator driver");
634MODULE_AUTHOR("Kyungmin Park <kyungmin.park@samsung.com>");
635MODULE_LICENSE("GPL");
diff --git a/drivers/regulator/tps65023-regulator.c b/drivers/regulator/tps65023-regulator.c
index f50afc9f287a..cd6d4fc9d74f 100644
--- a/drivers/regulator/tps65023-regulator.c
+++ b/drivers/regulator/tps65023-regulator.c
@@ -585,6 +585,8 @@ static const struct tps_info tps65023_regs[] = {
585static const struct i2c_device_id tps_65023_id[] = { 585static const struct i2c_device_id tps_65023_id[] = {
586 {.name = "tps65023", 586 {.name = "tps65023",
587 .driver_data = (unsigned long) tps65023_regs,}, 587 .driver_data = (unsigned long) tps65023_regs,},
588 {.name = "tps65021",
589 .driver_data = (unsigned long) tps65023_regs,},
588 { }, 590 { },
589}; 591};
590 592
diff --git a/drivers/regulator/tps6507x-regulator.c b/drivers/regulator/tps6507x-regulator.c
index 8152d65220f5..c239f42aa4a3 100644
--- a/drivers/regulator/tps6507x-regulator.c
+++ b/drivers/regulator/tps6507x-regulator.c
@@ -614,6 +614,7 @@ int tps6507x_pmic_probe(struct platform_device *pdev)
614 } 614 }
615 615
616 tps6507x_dev->pmic = tps; 616 tps6507x_dev->pmic = tps;
617 platform_set_drvdata(pdev, tps6507x_dev);
617 618
618 return 0; 619 return 0;
619 620
diff --git a/drivers/regulator/tps6586x-regulator.c b/drivers/regulator/tps6586x-regulator.c
new file mode 100644
index 000000000000..8cff1413a147
--- /dev/null
+++ b/drivers/regulator/tps6586x-regulator.c
@@ -0,0 +1,396 @@
1/*
2 * Regulator driver for TI TPS6586x
3 *
4 * Copyright (C) 2010 Compulab Ltd.
5 * Author: Mike Rapoport <mike@compulab.co.il>
6 *
7 * Based on da903x
8 * Copyright (C) 2006-2008 Marvell International Ltd.
9 * Copyright (C) 2008 Compulab Ltd.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
14 */
15
16#include <linux/kernel.h>
17#include <linux/init.h>
18#include <linux/err.h>
19#include <linux/slab.h>
20#include <linux/platform_device.h>
21#include <linux/regulator/driver.h>
22#include <linux/regulator/machine.h>
23#include <linux/mfd/tps6586x.h>
24
25/* supply control and voltage setting */
26#define TPS6586X_SUPPLYENA 0x10
27#define TPS6586X_SUPPLYENB 0x11
28#define TPS6586X_SUPPLYENC 0x12
29#define TPS6586X_SUPPLYEND 0x13
30#define TPS6586X_SUPPLYENE 0x14
31#define TPS6586X_VCC1 0x20
32#define TPS6586X_VCC2 0x21
33#define TPS6586X_SM1V1 0x23
34#define TPS6586X_SM1V2 0x24
35#define TPS6586X_SM1SL 0x25
36#define TPS6586X_SM0V1 0x26
37#define TPS6586X_SM0V2 0x27
38#define TPS6586X_SM0SL 0x28
39#define TPS6586X_LDO2AV1 0x29
40#define TPS6586X_LDO2AV2 0x2A
41#define TPS6586X_LDO2BV1 0x2F
42#define TPS6586X_LDO2BV2 0x30
43#define TPS6586X_LDO4V1 0x32
44#define TPS6586X_LDO4V2 0x33
45
46/* converter settings */
47#define TPS6586X_SUPPLYV1 0x41
48#define TPS6586X_SUPPLYV2 0x42
49#define TPS6586X_SUPPLYV3 0x43
50#define TPS6586X_SUPPLYV4 0x44
51#define TPS6586X_SUPPLYV5 0x45
52#define TPS6586X_SUPPLYV6 0x46
53#define TPS6586X_SMODE1 0x47
54#define TPS6586X_SMODE2 0x48
55
56struct tps6586x_regulator {
57 struct regulator_desc desc;
58
59 int volt_reg;
60 int volt_shift;
61 int volt_nbits;
62 int enable_bit[2];
63 int enable_reg[2];
64
65 int *voltages;
66
67 /* for DVM regulators */
68 int go_reg;
69 int go_bit;
70};
71
72static inline struct device *to_tps6586x_dev(struct regulator_dev *rdev)
73{
74 return rdev_get_dev(rdev)->parent->parent;
75}
76
77static int tps6586x_ldo_list_voltage(struct regulator_dev *rdev,
78 unsigned selector)
79{
80 struct tps6586x_regulator *info = rdev_get_drvdata(rdev);
81
82 return info->voltages[selector] * 1000;
83}
84
85
86static int __tps6586x_ldo_set_voltage(struct device *parent,
87 struct tps6586x_regulator *ri,
88 int min_uV, int max_uV)
89{
90 int val, uV;
91 uint8_t mask;
92
93 for (val = 0; val < ri->desc.n_voltages; val++) {
94 uV = ri->voltages[val] * 1000;
95
96 /* LDO0 has minimal voltage 1.2 rather than 1.25 */
97 if (ri->desc.id == TPS6586X_ID_LDO_0 && val == 0)
98 uV -= 50 * 1000;
99
100 /* use the first in-range value */
101 if (min_uV <= uV && uV <= max_uV) {
102
103 val <<= ri->volt_shift;
104 mask = ((1 << ri->volt_nbits) - 1) << ri->volt_shift;
105
106 return tps6586x_update(parent, ri->volt_reg, val, mask);
107 }
108 }
109
110 return -EINVAL;
111}
112
113static int tps6586x_ldo_set_voltage(struct regulator_dev *rdev,
114 int min_uV, int max_uV)
115{
116 struct tps6586x_regulator *ri = rdev_get_drvdata(rdev);
117 struct device *parent = to_tps6586x_dev(rdev);
118
119 return __tps6586x_ldo_set_voltage(parent, ri, min_uV, max_uV);
120}
121
122static int tps6586x_ldo_get_voltage(struct regulator_dev *rdev)
123{
124 struct tps6586x_regulator *ri = rdev_get_drvdata(rdev);
125 struct device *parent = to_tps6586x_dev(rdev);
126 uint8_t val, mask;
127 int ret;
128
129 ret = tps6586x_read(parent, ri->volt_reg, &val);
130 if (ret)
131 return ret;
132
133 mask = ((1 << ri->volt_nbits) - 1) << ri->volt_shift;
134 val = (val & mask) >> ri->volt_shift;
135
136 if (val > ri->desc.n_voltages)
137 BUG();
138
139 return ri->voltages[val] * 1000;
140}
141
142static int tps6586x_dvm_set_voltage(struct regulator_dev *rdev,
143 int min_uV, int max_uV)
144{
145 struct tps6586x_regulator *ri = rdev_get_drvdata(rdev);
146 struct device *parent = to_tps6586x_dev(rdev);
147 int ret;
148
149 ret = __tps6586x_ldo_set_voltage(parent, ri, min_uV, max_uV);
150 if (ret)
151 return ret;
152
153 return tps6586x_set_bits(parent, ri->go_reg, ri->go_bit);
154}
155
156static int tps6586x_regulator_enable(struct regulator_dev *rdev)
157{
158 struct tps6586x_regulator *ri = rdev_get_drvdata(rdev);
159 struct device *parent = to_tps6586x_dev(rdev);
160
161 return tps6586x_set_bits(parent, ri->enable_reg[0],
162 1 << ri->enable_bit[0]);
163}
164
165static int tps6586x_regulator_disable(struct regulator_dev *rdev)
166{
167 struct tps6586x_regulator *ri = rdev_get_drvdata(rdev);
168 struct device *parent = to_tps6586x_dev(rdev);
169
170 return tps6586x_clr_bits(parent, ri->enable_reg[0],
171 1 << ri->enable_bit[0]);
172}
173
174static int tps6586x_regulator_is_enabled(struct regulator_dev *rdev)
175{
176 struct tps6586x_regulator *ri = rdev_get_drvdata(rdev);
177 struct device *parent = to_tps6586x_dev(rdev);
178 uint8_t reg_val;
179 int ret;
180
181 ret = tps6586x_read(parent, ri->enable_reg[0], &reg_val);
182 if (ret)
183 return ret;
184
185 return !!(reg_val & (1 << ri->enable_bit[0]));
186}
187
188static struct regulator_ops tps6586x_regulator_ldo_ops = {
189 .list_voltage = tps6586x_ldo_list_voltage,
190 .get_voltage = tps6586x_ldo_get_voltage,
191 .set_voltage = tps6586x_ldo_set_voltage,
192
193 .is_enabled = tps6586x_regulator_is_enabled,
194 .enable = tps6586x_regulator_enable,
195 .disable = tps6586x_regulator_disable,
196};
197
198static struct regulator_ops tps6586x_regulator_dvm_ops = {
199 .list_voltage = tps6586x_ldo_list_voltage,
200 .get_voltage = tps6586x_ldo_get_voltage,
201 .set_voltage = tps6586x_dvm_set_voltage,
202
203 .is_enabled = tps6586x_regulator_is_enabled,
204 .enable = tps6586x_regulator_enable,
205 .disable = tps6586x_regulator_disable,
206};
207
208static int tps6586x_ldo_voltages[] = {
209 1250, 1500, 1800, 2500, 2700, 2850, 3100, 3300,
210};
211
212static int tps6586x_ldo4_voltages[] = {
213 1700, 1725, 1750, 1775, 1800, 1825, 1850, 1875,
214 1900, 1925, 1950, 1975, 2000, 2025, 2050, 2075,
215 2100, 2125, 2150, 2175, 2200, 2225, 2250, 2275,
216 2300, 2325, 2350, 2375, 2400, 2425, 2450, 2475,
217};
218
219static int tps6586x_sm2_voltages[] = {
220 3000, 3050, 3100, 3150, 3200, 3250, 3300, 3350,
221 3400, 3450, 3500, 3550, 3600, 3650, 3700, 3750,
222 3800, 3850, 3900, 3950, 4000, 4050, 4100, 4150,
223 4200, 4250, 4300, 4350, 4400, 4450, 4500, 4550,
224};
225
226static int tps6586x_dvm_voltages[] = {
227 725, 750, 775, 800, 825, 850, 875, 900,
228 925, 950, 975, 1000, 1025, 1050, 1075, 1100,
229 1125, 1150, 1175, 1200, 1225, 1250, 1275, 1300,
230 1325, 1350, 1375, 1400, 1425, 1450, 1475, 1500,
231};
232
233#define TPS6586X_REGULATOR(_id, vdata, _ops, vreg, shift, nbits, \
234 ereg0, ebit0, ereg1, ebit1, goreg, gobit) \
235{ \
236 .desc = { \
237 .name = "REG-" #_id, \
238 .ops = &tps6586x_regulator_##_ops, \
239 .type = REGULATOR_VOLTAGE, \
240 .id = TPS6586X_ID_##_id, \
241 .n_voltages = ARRAY_SIZE(tps6586x_##vdata##_voltages), \
242 .owner = THIS_MODULE, \
243 }, \
244 .volt_reg = TPS6586X_##vreg, \
245 .volt_shift = (shift), \
246 .volt_nbits = (nbits), \
247 .enable_reg[0] = TPS6586X_SUPPLY##ereg0, \
248 .enable_bit[0] = (ebit0), \
249 .enable_reg[1] = TPS6586X_SUPPLY##ereg1, \
250 .enable_bit[1] = (ebit1), \
251 .voltages = tps6586x_##vdata##_voltages, \
252}
253
254#define TPS6586X_LDO(_id, vdata, vreg, shift, nbits, \
255 ereg0, ebit0, ereg1, ebit1) \
256 TPS6586X_REGULATOR(_id, vdata, ldo_ops, vreg, shift, nbits, \
257 ereg0, ebit0, ereg1, ebit1, 0, 0)
258
259#define TPS6586X_DVM(_id, vdata, vreg, shift, nbits, \
260 ereg0, ebit0, ereg1, ebit1, goreg, gobit) \
261 TPS6586X_REGULATOR(_id, vdata, dvm_ops, vreg, shift, nbits, \
262 ereg0, ebit0, ereg1, ebit1, goreg, gobit)
263
264static struct tps6586x_regulator tps6586x_regulator[] = {
265 TPS6586X_LDO(LDO_0, ldo, SUPPLYV1, 5, 3, ENC, 0, END, 0),
266 TPS6586X_LDO(LDO_3, ldo, SUPPLYV4, 0, 3, ENC, 2, END, 2),
267 TPS6586X_LDO(LDO_5, ldo, SUPPLYV6, 0, 3, ENE, 6, ENE, 6),
268 TPS6586X_LDO(LDO_6, ldo, SUPPLYV3, 0, 3, ENC, 4, END, 4),
269 TPS6586X_LDO(LDO_7, ldo, SUPPLYV3, 3, 3, ENC, 5, END, 5),
270 TPS6586X_LDO(LDO_8, ldo, SUPPLYV1, 5, 3, ENC, 6, END, 6),
271 TPS6586X_LDO(LDO_9, ldo, SUPPLYV6, 3, 3, ENE, 7, ENE, 7),
272 TPS6586X_LDO(LDO_RTC, ldo, SUPPLYV4, 3, 3, ENE, 7, ENE, 7),
273 TPS6586X_LDO(LDO_1, dvm, SUPPLYV1, 0, 5, ENC, 1, END, 1),
274 TPS6586X_LDO(SM_2, sm2, SUPPLYV2, 0, 5, ENC, 1, END, 1),
275
276 TPS6586X_DVM(LDO_2, dvm, LDO2BV1, 0, 5, ENA, 3, ENB, 3, VCC2, 6),
277 TPS6586X_DVM(LDO_4, ldo4, LDO4V1, 0, 5, ENC, 3, END, 3, VCC1, 6),
278 TPS6586X_DVM(SM_0, dvm, SM0V1, 0, 5, ENA, 1, ENB, 1, VCC1, 2),
279 TPS6586X_DVM(SM_1, dvm, SM1V1, 0, 5, ENA, 0, ENB, 0, VCC1, 0),
280};
281
282/*
283 * TPS6586X has 2 enable bits that are OR'ed to determine the actual
284 * regulator state. Clearing one of this bits allows switching
285 * regulator on and of with single register write.
286 */
287static inline int tps6586x_regulator_preinit(struct device *parent,
288 struct tps6586x_regulator *ri)
289{
290 uint8_t val1, val2;
291 int ret;
292
293 ret = tps6586x_read(parent, ri->enable_reg[0], &val1);
294 if (ret)
295 return ret;
296
297 ret = tps6586x_read(parent, ri->enable_reg[1], &val2);
298 if (ret)
299 return ret;
300
301 if (!(val2 & ri->enable_bit[1]))
302 return 0;
303
304 /*
305 * The regulator is on, but it's enabled with the bit we don't
306 * want to use, so we switch the enable bits
307 */
308 if (!(val1 & ri->enable_bit[0])) {
309 ret = tps6586x_set_bits(parent, ri->enable_reg[0],
310 1 << ri->enable_bit[0]);
311 if (ret)
312 return ret;
313 }
314
315 return tps6586x_clr_bits(parent, ri->enable_reg[1],
316 1 << ri->enable_bit[1]);
317}
318
319static inline struct tps6586x_regulator *find_regulator_info(int id)
320{
321 struct tps6586x_regulator *ri;
322 int i;
323
324 for (i = 0; i < ARRAY_SIZE(tps6586x_regulator); i++) {
325 ri = &tps6586x_regulator[i];
326 if (ri->desc.id == id)
327 return ri;
328 }
329 return NULL;
330}
331
332static int __devinit tps6586x_regulator_probe(struct platform_device *pdev)
333{
334 struct tps6586x_regulator *ri = NULL;
335 struct regulator_dev *rdev;
336 int id = pdev->id;
337 int err;
338
339 dev_dbg(&pdev->dev, "Probing reulator %d\n", id);
340
341 ri = find_regulator_info(id);
342 if (ri == NULL) {
343 dev_err(&pdev->dev, "invalid regulator ID specified\n");
344 return -EINVAL;
345 }
346
347 err = tps6586x_regulator_preinit(pdev->dev.parent, ri);
348 if (err)
349 return err;
350
351 rdev = regulator_register(&ri->desc, &pdev->dev,
352 pdev->dev.platform_data, ri);
353 if (IS_ERR(rdev)) {
354 dev_err(&pdev->dev, "failed to register regulator %s\n",
355 ri->desc.name);
356 return PTR_ERR(rdev);
357 }
358
359 platform_set_drvdata(pdev, rdev);
360
361 return 0;
362}
363
364static int __devexit tps6586x_regulator_remove(struct platform_device *pdev)
365{
366 struct regulator_dev *rdev = platform_get_drvdata(pdev);
367
368 regulator_unregister(rdev);
369 return 0;
370}
371
372static struct platform_driver tps6586x_regulator_driver = {
373 .driver = {
374 .name = "tps6586x-regulator",
375 .owner = THIS_MODULE,
376 },
377 .probe = tps6586x_regulator_probe,
378 .remove = __devexit_p(tps6586x_regulator_remove),
379};
380
381static int __init tps6586x_regulator_init(void)
382{
383 return platform_driver_register(&tps6586x_regulator_driver);
384}
385subsys_initcall(tps6586x_regulator_init);
386
387static void __exit tps6586x_regulator_exit(void)
388{
389 platform_driver_unregister(&tps6586x_regulator_driver);
390}
391module_exit(tps6586x_regulator_exit);
392
393MODULE_LICENSE("GPL");
394MODULE_AUTHOR("Mike Rapoport <mike@compulab.co.il>");
395MODULE_DESCRIPTION("Regulator Driver for TI TPS6586X PMIC");
396MODULE_ALIAS("platform:tps6586x-regulator");
diff --git a/drivers/regulator/wm8994-regulator.c b/drivers/regulator/wm8994-regulator.c
index 5a1dc8a24d35..03713bc66e4a 100644
--- a/drivers/regulator/wm8994-regulator.c
+++ b/drivers/regulator/wm8994-regulator.c
@@ -219,8 +219,6 @@ static __devinit int wm8994_ldo_probe(struct platform_device *pdev)
219 219
220 ldo->wm8994 = wm8994; 220 ldo->wm8994 = wm8994;
221 221
222 ldo->is_enabled = true;
223
224 if (pdata->ldo[id].enable && gpio_is_valid(pdata->ldo[id].enable)) { 222 if (pdata->ldo[id].enable && gpio_is_valid(pdata->ldo[id].enable)) {
225 ldo->enable = pdata->ldo[id].enable; 223 ldo->enable = pdata->ldo[id].enable;
226 224
@@ -237,7 +235,8 @@ static __devinit int wm8994_ldo_probe(struct platform_device *pdev)
237 ret); 235 ret);
238 goto err_gpio; 236 goto err_gpio;
239 } 237 }
240 } 238 } else
239 ldo->is_enabled = true;
241 240
242 ldo->regulator = regulator_register(&wm8994_ldo_desc[id], &pdev->dev, 241 ldo->regulator = regulator_register(&wm8994_ldo_desc[id], &pdev->dev,
243 pdata->ldo[id].init_data, ldo); 242 pdata->ldo[id].init_data, ldo);
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 4301a6c7ed3b..48ca7132cc05 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -166,6 +166,16 @@ config RTC_DRV_DS1672
166 This driver can also be built as a module. If so, the module 166 This driver can also be built as a module. If so, the module
167 will be called rtc-ds1672. 167 will be called rtc-ds1672.
168 168
169config RTC_DRV_DS3232
170 tristate "Dallas/Maxim DS3232"
171 depends on RTC_CLASS && I2C
172 help
173 If you say yes here you get support for Dallas Semiconductor
174 DS3232 real-time clock chips.
175
176 This driver can also be built as a module. If so, the module
177 will be called rtc-ds3232.
178
169config RTC_DRV_MAX6900 179config RTC_DRV_MAX6900
170 tristate "Maxim MAX6900" 180 tristate "Maxim MAX6900"
171 help 181 help
@@ -203,6 +213,15 @@ config RTC_DRV_ISL1208
203 This driver can also be built as a module. If so, the module 213 This driver can also be built as a module. If so, the module
204 will be called rtc-isl1208. 214 will be called rtc-isl1208.
205 215
216config RTC_DRV_ISL12022
217 tristate "Intersil ISL12022"
218 help
219 If you say yes here you get support for the
220 Intersil ISL12022 RTC chip.
221
222 This driver can also be built as a module. If so, the module
223 will be called rtc-isl12022.
224
206config RTC_DRV_X1205 225config RTC_DRV_X1205
207 tristate "Xicor/Intersil X1205" 226 tristate "Xicor/Intersil X1205"
208 help 227 help
@@ -537,6 +556,16 @@ config RTC_DRV_MSM6242
537 This driver can also be built as a module. If so, the module 556 This driver can also be built as a module. If so, the module
538 will be called rtc-msm6242. 557 will be called rtc-msm6242.
539 558
559config RTC_DRV_IMXDI
560 tristate "Freescale IMX DryIce Real Time Clock"
561 depends on ARCH_MX25
562 depends on RTC_CLASS
563 help
564 Support for Freescale IMX DryIce RTC
565
566 This driver can also be built as a module, if so, the module
567 will be called "rtc-imxdi".
568
540config RTC_MXC 569config RTC_MXC
541 tristate "Freescale MXC Real Time Clock" 570 tristate "Freescale MXC Real Time Clock"
542 depends on ARCH_MXC 571 depends on ARCH_MXC
@@ -645,9 +674,16 @@ config RTC_DRV_OMAP
645 DA8xx/OMAP-L13x chips. This driver can also be built as a 674 DA8xx/OMAP-L13x chips. This driver can also be built as a
646 module called rtc-omap. 675 module called rtc-omap.
647 676
677config HAVE_S3C_RTC
678 bool
679 help
680 This will include RTC support for Samsung SoCs. If
681 you want to include RTC support for any machine, kindly
682 select this in the respective mach-XXXX/Kconfig file.
683
648config RTC_DRV_S3C 684config RTC_DRV_S3C
649 tristate "Samsung S3C series SoC RTC" 685 tristate "Samsung S3C series SoC RTC"
650 depends on ARCH_S3C2410 || ARCH_S3C64XX 686 depends on ARCH_S3C2410 || ARCH_S3C64XX || HAVE_S3C_RTC
651 help 687 help
652 RTC (Realtime Clock) driver for the clock inbuilt into the 688 RTC (Realtime Clock) driver for the clock inbuilt into the
653 Samsung S3C24XX series of SoCs. This can provide periodic 689 Samsung S3C24XX series of SoCs. This can provide periodic
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index fedf9bb36593..0f207b3b5833 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -41,12 +41,15 @@ obj-$(CONFIG_RTC_DRV_DS1511) += rtc-ds1511.o
41obj-$(CONFIG_RTC_DRV_DS1553) += rtc-ds1553.o 41obj-$(CONFIG_RTC_DRV_DS1553) += rtc-ds1553.o
42obj-$(CONFIG_RTC_DRV_DS1672) += rtc-ds1672.o 42obj-$(CONFIG_RTC_DRV_DS1672) += rtc-ds1672.o
43obj-$(CONFIG_RTC_DRV_DS1742) += rtc-ds1742.o 43obj-$(CONFIG_RTC_DRV_DS1742) += rtc-ds1742.o
44obj-$(CONFIG_RTC_DRV_DS3232) += rtc-ds3232.o
44obj-$(CONFIG_RTC_DRV_DS3234) += rtc-ds3234.o 45obj-$(CONFIG_RTC_DRV_DS3234) += rtc-ds3234.o
45obj-$(CONFIG_RTC_DRV_EFI) += rtc-efi.o 46obj-$(CONFIG_RTC_DRV_EFI) += rtc-efi.o
46obj-$(CONFIG_RTC_DRV_EP93XX) += rtc-ep93xx.o 47obj-$(CONFIG_RTC_DRV_EP93XX) += rtc-ep93xx.o
47obj-$(CONFIG_RTC_DRV_FM3130) += rtc-fm3130.o 48obj-$(CONFIG_RTC_DRV_FM3130) += rtc-fm3130.o
48obj-$(CONFIG_RTC_DRV_GENERIC) += rtc-generic.o 49obj-$(CONFIG_RTC_DRV_GENERIC) += rtc-generic.o
50obj-$(CONFIG_RTC_DRV_IMXDI) += rtc-imxdi.o
49obj-$(CONFIG_RTC_DRV_ISL1208) += rtc-isl1208.o 51obj-$(CONFIG_RTC_DRV_ISL1208) += rtc-isl1208.o
52obj-$(CONFIG_RTC_DRV_ISL12022) += rtc-isl12022.o
50obj-$(CONFIG_RTC_DRV_JZ4740) += rtc-jz4740.o 53obj-$(CONFIG_RTC_DRV_JZ4740) += rtc-jz4740.o
51obj-$(CONFIG_RTC_DRV_M41T80) += rtc-m41t80.o 54obj-$(CONFIG_RTC_DRV_M41T80) += rtc-m41t80.o
52obj-$(CONFIG_RTC_DRV_M41T94) += rtc-m41t94.o 55obj-$(CONFIG_RTC_DRV_M41T94) += rtc-m41t94.o
diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
index 11b8ea29d2b7..5856167a0c90 100644
--- a/drivers/rtc/rtc-cmos.c
+++ b/drivers/rtc/rtc-cmos.c
@@ -970,7 +970,6 @@ static inline int cmos_poweroff(struct device *dev)
970 970
971#include <linux/acpi.h> 971#include <linux/acpi.h>
972 972
973#ifdef CONFIG_PM
974static u32 rtc_handler(void *context) 973static u32 rtc_handler(void *context)
975{ 974{
976 acpi_clear_event(ACPI_EVENT_RTC); 975 acpi_clear_event(ACPI_EVENT_RTC);
@@ -999,11 +998,6 @@ static void rtc_wake_off(struct device *dev)
999{ 998{
1000 acpi_disable_event(ACPI_EVENT_RTC, 0); 999 acpi_disable_event(ACPI_EVENT_RTC, 0);
1001} 1000}
1002#else
1003#define rtc_wake_setup() do{}while(0)
1004#define rtc_wake_on NULL
1005#define rtc_wake_off NULL
1006#endif
1007 1001
1008/* Every ACPI platform has a mc146818 compatible "cmos rtc". Here we find 1002/* Every ACPI platform has a mc146818 compatible "cmos rtc". Here we find
1009 * its device node and pass extra config data. This helps its driver use 1003 * its device node and pass extra config data. This helps its driver use
diff --git a/drivers/rtc/rtc-ds3232.c b/drivers/rtc/rtc-ds3232.c
new file mode 100644
index 000000000000..9daed8db83d3
--- /dev/null
+++ b/drivers/rtc/rtc-ds3232.c
@@ -0,0 +1,326 @@
1/*
2 * RTC client/driver for the Maxim/Dallas DS3232 Real-Time Clock over I2C
3 *
4 * Copyright (C) 2009-2010 Freescale Semiconductor.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
10 */
11/*
12 * It would be more efficient to use i2c msgs/i2c_transfer directly but, as
13 * recommened in .../Documentation/i2c/writing-clients section
14 * "Sending and receiving", using SMBus level communication is preferred.
15 */
16
17#include <linux/kernel.h>
18#include <linux/module.h>
19#include <linux/interrupt.h>
20#include <linux/i2c.h>
21#include <linux/rtc.h>
22#include <linux/bcd.h>
23#include <linux/workqueue.h>
24#include <linux/slab.h>
25
26#define DS3232_REG_SECONDS 0x00
27#define DS3232_REG_MINUTES 0x01
28#define DS3232_REG_HOURS 0x02
29#define DS3232_REG_AMPM 0x02
30#define DS3232_REG_DAY 0x03
31#define DS3232_REG_DATE 0x04
32#define DS3232_REG_MONTH 0x05
33#define DS3232_REG_CENTURY 0x05
34#define DS3232_REG_YEAR 0x06
35#define DS3232_REG_ALARM1 0x07 /* Alarm 1 BASE */
36#define DS3232_REG_ALARM2 0x0B /* Alarm 2 BASE */
37#define DS3232_REG_CR 0x0E /* Control register */
38# define DS3232_REG_CR_nEOSC 0x80
39# define DS3232_REG_CR_INTCN 0x04
40# define DS3232_REG_CR_A2IE 0x02
41# define DS3232_REG_CR_A1IE 0x01
42
43#define DS3232_REG_SR 0x0F /* control/status register */
44# define DS3232_REG_SR_OSF 0x80
45# define DS3232_REG_SR_BSY 0x04
46# define DS3232_REG_SR_A2F 0x02
47# define DS3232_REG_SR_A1F 0x01
48
49struct ds3232 {
50 struct i2c_client *client;
51 struct rtc_device *rtc;
52 struct work_struct work;
53
54 /* The mutex protects alarm operations, and prevents a race
55 * between the enable_irq() in the workqueue and the free_irq()
56 * in the remove function.
57 */
58 struct mutex mutex;
59 int exiting;
60};
61
62static struct i2c_driver ds3232_driver;
63
64static int ds3232_check_rtc_status(struct i2c_client *client)
65{
66 int ret = 0;
67 int control, stat;
68
69 stat = i2c_smbus_read_byte_data(client, DS3232_REG_SR);
70 if (stat < 0)
71 return stat;
72
73 if (stat & DS3232_REG_SR_OSF)
74 dev_warn(&client->dev,
75 "oscillator discontinuity flagged, "
76 "time unreliable\n");
77
78 stat &= ~(DS3232_REG_SR_OSF | DS3232_REG_SR_A1F | DS3232_REG_SR_A2F);
79
80 ret = i2c_smbus_write_byte_data(client, DS3232_REG_SR, stat);
81 if (ret < 0)
82 return ret;
83
84 /* If the alarm is pending, clear it before requesting
85 * the interrupt, so an interrupt event isn't reported
86 * before everything is initialized.
87 */
88
89 control = i2c_smbus_read_byte_data(client, DS3232_REG_CR);
90 if (control < 0)
91 return control;
92
93 control &= ~(DS3232_REG_CR_A1IE | DS3232_REG_CR_A2IE);
94 control |= DS3232_REG_CR_INTCN;
95
96 return i2c_smbus_write_byte_data(client, DS3232_REG_CR, control);
97}
98
99static int ds3232_read_time(struct device *dev, struct rtc_time *time)
100{
101 struct i2c_client *client = to_i2c_client(dev);
102 int ret;
103 u8 buf[7];
104 unsigned int year, month, day, hour, minute, second;
105 unsigned int week, twelve_hr, am_pm;
106 unsigned int century, add_century = 0;
107
108 ret = i2c_smbus_read_i2c_block_data(client, DS3232_REG_SECONDS, 7, buf);
109
110 if (ret < 0)
111 return ret;
112 if (ret < 7)
113 return -EIO;
114
115 second = buf[0];
116 minute = buf[1];
117 hour = buf[2];
118 week = buf[3];
119 day = buf[4];
120 month = buf[5];
121 year = buf[6];
122
123 /* Extract additional information for AM/PM and century */
124
125 twelve_hr = hour & 0x40;
126 am_pm = hour & 0x20;
127 century = month & 0x80;
128
129 /* Write to rtc_time structure */
130
131 time->tm_sec = bcd2bin(second);
132 time->tm_min = bcd2bin(minute);
133 if (twelve_hr) {
134 /* Convert to 24 hr */
135 if (am_pm)
136 time->tm_hour = bcd2bin(hour & 0x1F) + 12;
137 else
138 time->tm_hour = bcd2bin(hour & 0x1F);
139 } else {
140 time->tm_hour = bcd2bin(hour);
141 }
142
143 time->tm_wday = bcd2bin(week);
144 time->tm_mday = bcd2bin(day);
145 time->tm_mon = bcd2bin(month & 0x7F);
146 if (century)
147 add_century = 100;
148
149 time->tm_year = bcd2bin(year) + add_century;
150
151 return rtc_valid_tm(time);
152}
153
154static int ds3232_set_time(struct device *dev, struct rtc_time *time)
155{
156 struct i2c_client *client = to_i2c_client(dev);
157 u8 buf[7];
158
159 /* Extract time from rtc_time and load into ds3232*/
160
161 buf[0] = bin2bcd(time->tm_sec);
162 buf[1] = bin2bcd(time->tm_min);
163 buf[2] = bin2bcd(time->tm_hour);
164 buf[3] = bin2bcd(time->tm_wday); /* Day of the week */
165 buf[4] = bin2bcd(time->tm_mday); /* Date */
166 buf[5] = bin2bcd(time->tm_mon);
167 if (time->tm_year >= 100) {
168 buf[5] |= 0x80;
169 buf[6] = bin2bcd(time->tm_year - 100);
170 } else {
171 buf[6] = bin2bcd(time->tm_year);
172 }
173
174 return i2c_smbus_write_i2c_block_data(client,
175 DS3232_REG_SECONDS, 7, buf);
176}
177
178static irqreturn_t ds3232_irq(int irq, void *dev_id)
179{
180 struct i2c_client *client = dev_id;
181 struct ds3232 *ds3232 = i2c_get_clientdata(client);
182
183 disable_irq_nosync(irq);
184 schedule_work(&ds3232->work);
185 return IRQ_HANDLED;
186}
187
188static void ds3232_work(struct work_struct *work)
189{
190 struct ds3232 *ds3232 = container_of(work, struct ds3232, work);
191 struct i2c_client *client = ds3232->client;
192 int stat, control;
193
194 mutex_lock(&ds3232->mutex);
195
196 stat = i2c_smbus_read_byte_data(client, DS3232_REG_SR);
197 if (stat < 0)
198 goto unlock;
199
200 if (stat & DS3232_REG_SR_A1F) {
201 control = i2c_smbus_read_byte_data(client, DS3232_REG_CR);
202 if (control < 0)
203 goto out;
204 /* disable alarm1 interrupt */
205 control &= ~(DS3232_REG_CR_A1IE);
206 i2c_smbus_write_byte_data(client, DS3232_REG_CR, control);
207
208 /* clear the alarm pend flag */
209 stat &= ~DS3232_REG_SR_A1F;
210 i2c_smbus_write_byte_data(client, DS3232_REG_SR, stat);
211
212 rtc_update_irq(ds3232->rtc, 1, RTC_AF | RTC_IRQF);
213 }
214
215out:
216 if (!ds3232->exiting)
217 enable_irq(client->irq);
218unlock:
219 mutex_unlock(&ds3232->mutex);
220}
221
222static const struct rtc_class_ops ds3232_rtc_ops = {
223 .read_time = ds3232_read_time,
224 .set_time = ds3232_set_time,
225};
226
227static int __devinit ds3232_probe(struct i2c_client *client,
228 const struct i2c_device_id *id)
229{
230 struct ds3232 *ds3232;
231 int ret;
232
233 ds3232 = kzalloc(sizeof(struct ds3232), GFP_KERNEL);
234 if (!ds3232)
235 return -ENOMEM;
236
237 ds3232->client = client;
238 i2c_set_clientdata(client, ds3232);
239
240 INIT_WORK(&ds3232->work, ds3232_work);
241 mutex_init(&ds3232->mutex);
242
243 ret = ds3232_check_rtc_status(client);
244 if (ret)
245 goto out_free;
246
247 ds3232->rtc = rtc_device_register(client->name, &client->dev,
248 &ds3232_rtc_ops, THIS_MODULE);
249 if (IS_ERR(ds3232->rtc)) {
250 ret = PTR_ERR(ds3232->rtc);
251 dev_err(&client->dev, "unable to register the class device\n");
252 goto out_irq;
253 }
254
255 if (client->irq >= 0) {
256 ret = request_irq(client->irq, ds3232_irq, 0,
257 "ds3232", client);
258 if (ret) {
259 dev_err(&client->dev, "unable to request IRQ\n");
260 goto out_free;
261 }
262 }
263
264 return 0;
265
266out_irq:
267 if (client->irq >= 0)
268 free_irq(client->irq, client);
269
270out_free:
271 i2c_set_clientdata(client, NULL);
272 kfree(ds3232);
273 return ret;
274}
275
276static int __devexit ds3232_remove(struct i2c_client *client)
277{
278 struct ds3232 *ds3232 = i2c_get_clientdata(client);
279
280 if (client->irq >= 0) {
281 mutex_lock(&ds3232->mutex);
282 ds3232->exiting = 1;
283 mutex_unlock(&ds3232->mutex);
284
285 free_irq(client->irq, client);
286 flush_scheduled_work();
287 }
288
289 rtc_device_unregister(ds3232->rtc);
290 i2c_set_clientdata(client, NULL);
291 kfree(ds3232);
292 return 0;
293}
294
295static const struct i2c_device_id ds3232_id[] = {
296 { "ds3232", 0 },
297 { }
298};
299MODULE_DEVICE_TABLE(i2c, ds3232_id);
300
301static struct i2c_driver ds3232_driver = {
302 .driver = {
303 .name = "rtc-ds3232",
304 .owner = THIS_MODULE,
305 },
306 .probe = ds3232_probe,
307 .remove = __devexit_p(ds3232_remove),
308 .id_table = ds3232_id,
309};
310
311static int __init ds3232_init(void)
312{
313 return i2c_add_driver(&ds3232_driver);
314}
315
316static void __exit ds3232_exit(void)
317{
318 i2c_del_driver(&ds3232_driver);
319}
320
321module_init(ds3232_init);
322module_exit(ds3232_exit);
323
324MODULE_AUTHOR("Srikanth Srinivasan <srikanth.srinivasan@freescale.com>");
325MODULE_DESCRIPTION("Maxim/Dallas DS3232 RTC Driver");
326MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/rtc-fm3130.c b/drivers/rtc/rtc-fm3130.c
index e4de8f37ae4a..4cf2e70c5078 100644
--- a/drivers/rtc/rtc-fm3130.c
+++ b/drivers/rtc/rtc-fm3130.c
@@ -52,8 +52,8 @@ struct fm3130 {
52 struct i2c_msg msg[4]; 52 struct i2c_msg msg[4];
53 struct i2c_client *client; 53 struct i2c_client *client;
54 struct rtc_device *rtc; 54 struct rtc_device *rtc;
55 int alarm_valid;
55 int data_valid; 56 int data_valid;
56 int alarm;
57}; 57};
58static const struct i2c_device_id fm3130_id[] = { 58static const struct i2c_device_id fm3130_id[] = {
59 { "fm3130", 0 }, 59 { "fm3130", 0 },
@@ -87,11 +87,7 @@ static void fm3130_rtc_mode(struct device *dev, int mode)
87 dev_dbg(dev, "invalid mode %d\n", mode); 87 dev_dbg(dev, "invalid mode %d\n", mode);
88 break; 88 break;
89 } 89 }
90 /* Checking for alarm */ 90
91 if (fm3130->regs[FM3130_RTC_CONTROL] & FM3130_RTC_CONTROL_BIT_AF) {
92 fm3130->alarm = 1;
93 fm3130->regs[FM3130_RTC_CONTROL] &= ~FM3130_RTC_CONTROL_BIT_AF;
94 }
95 i2c_smbus_write_byte_data(fm3130->client, 91 i2c_smbus_write_byte_data(fm3130->client,
96 FM3130_RTC_CONTROL, fm3130->regs[FM3130_RTC_CONTROL]); 92 FM3130_RTC_CONTROL, fm3130->regs[FM3130_RTC_CONTROL]);
97} 93}
@@ -208,6 +204,17 @@ static int fm3130_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
208 struct fm3130 *fm3130 = dev_get_drvdata(dev); 204 struct fm3130 *fm3130 = dev_get_drvdata(dev);
209 int tmp; 205 int tmp;
210 struct rtc_time *tm = &alrm->time; 206 struct rtc_time *tm = &alrm->time;
207
208 if (!fm3130->alarm_valid) {
209 /*
210 * We have invalid alarm in RTC, probably due to battery faults
211 * or other problems. Return EIO for now, it will allow us to
212 * set alarm value later instead of error during probing which
213 * disables device
214 */
215 return -EIO;
216 }
217
211 /* read the RTC alarm registers all at once */ 218 /* read the RTC alarm registers all at once */
212 tmp = i2c_transfer(to_i2c_adapter(fm3130->client->dev.parent), 219 tmp = i2c_transfer(to_i2c_adapter(fm3130->client->dev.parent),
213 &fm3130->msg[2], 2); 220 &fm3130->msg[2], 2);
@@ -222,20 +229,31 @@ static int fm3130_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
222 fm3130->regs[FM3130_ALARM_DATE], 229 fm3130->regs[FM3130_ALARM_DATE],
223 fm3130->regs[FM3130_ALARM_MONTHS]); 230 fm3130->regs[FM3130_ALARM_MONTHS]);
224 231
225
226 tm->tm_sec = bcd2bin(fm3130->regs[FM3130_ALARM_SECONDS] & 0x7F); 232 tm->tm_sec = bcd2bin(fm3130->regs[FM3130_ALARM_SECONDS] & 0x7F);
227 tm->tm_min = bcd2bin(fm3130->regs[FM3130_ALARM_MINUTES] & 0x7F); 233 tm->tm_min = bcd2bin(fm3130->regs[FM3130_ALARM_MINUTES] & 0x7F);
228 tm->tm_hour = bcd2bin(fm3130->regs[FM3130_ALARM_HOURS] & 0x3F); 234 tm->tm_hour = bcd2bin(fm3130->regs[FM3130_ALARM_HOURS] & 0x3F);
229 tm->tm_mday = bcd2bin(fm3130->regs[FM3130_ALARM_DATE] & 0x3F); 235 tm->tm_mday = bcd2bin(fm3130->regs[FM3130_ALARM_DATE] & 0x3F);
230 tm->tm_mon = bcd2bin(fm3130->regs[FM3130_ALARM_MONTHS] & 0x1F); 236 tm->tm_mon = bcd2bin(fm3130->regs[FM3130_ALARM_MONTHS] & 0x1F);
237
231 if (tm->tm_mon > 0) 238 if (tm->tm_mon > 0)
232 tm->tm_mon -= 1; /* RTC is 1-12, tm_mon is 0-11 */ 239 tm->tm_mon -= 1; /* RTC is 1-12, tm_mon is 0-11 */
240
233 dev_dbg(dev, "%s secs=%d, mins=%d, " 241 dev_dbg(dev, "%s secs=%d, mins=%d, "
234 "hours=%d, mday=%d, mon=%d, year=%d, wday=%d\n", 242 "hours=%d, mday=%d, mon=%d, year=%d, wday=%d\n",
235 "read alarm", tm->tm_sec, tm->tm_min, 243 "read alarm", tm->tm_sec, tm->tm_min,
236 tm->tm_hour, tm->tm_mday, 244 tm->tm_hour, tm->tm_mday,
237 tm->tm_mon, tm->tm_year, tm->tm_wday); 245 tm->tm_mon, tm->tm_year, tm->tm_wday);
238 246
247 /* check if alarm enabled */
248 fm3130->regs[FM3130_RTC_CONTROL] =
249 i2c_smbus_read_byte_data(fm3130->client, FM3130_RTC_CONTROL);
250
251 if ((fm3130->regs[FM3130_RTC_CONTROL] & FM3130_RTC_CONTROL_BIT_AEN) &&
252 (~fm3130->regs[FM3130_RTC_CONTROL] &
253 FM3130_RTC_CONTROL_BIT_CAL)) {
254 alrm->enabled = 1;
255 }
256
239 return 0; 257 return 0;
240} 258}
241 259
@@ -251,25 +269,20 @@ static int fm3130_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
251 tm->tm_hour, tm->tm_mday, 269 tm->tm_hour, tm->tm_mday,
252 tm->tm_mon, tm->tm_year, tm->tm_wday); 270 tm->tm_mon, tm->tm_year, tm->tm_wday);
253 271
254 if (tm->tm_sec != -1) 272 fm3130->regs[FM3130_ALARM_SECONDS] =
255 fm3130->regs[FM3130_ALARM_SECONDS] = 273 (tm->tm_sec != -1) ? bin2bcd(tm->tm_sec) : 0x80;
256 bin2bcd(tm->tm_sec) | 0x80;
257 274
258 if (tm->tm_min != -1) 275 fm3130->regs[FM3130_ALARM_MINUTES] =
259 fm3130->regs[FM3130_ALARM_MINUTES] = 276 (tm->tm_min != -1) ? bin2bcd(tm->tm_min) : 0x80;
260 bin2bcd(tm->tm_min) | 0x80;
261 277
262 if (tm->tm_hour != -1) 278 fm3130->regs[FM3130_ALARM_HOURS] =
263 fm3130->regs[FM3130_ALARM_HOURS] = 279 (tm->tm_hour != -1) ? bin2bcd(tm->tm_hour) : 0x80;
264 bin2bcd(tm->tm_hour) | 0x80;
265 280
266 if (tm->tm_mday != -1) 281 fm3130->regs[FM3130_ALARM_DATE] =
267 fm3130->regs[FM3130_ALARM_DATE] = 282 (tm->tm_mday != -1) ? bin2bcd(tm->tm_mday) : 0x80;
268 bin2bcd(tm->tm_mday) | 0x80;
269 283
270 if (tm->tm_mon != -1) 284 fm3130->regs[FM3130_ALARM_MONTHS] =
271 fm3130->regs[FM3130_ALARM_MONTHS] = 285 (tm->tm_mon != -1) ? bin2bcd(tm->tm_mon + 1) : 0x80;
272 bin2bcd(tm->tm_mon + 1) | 0x80;
273 286
274 dev_dbg(dev, "alarm write %02x %02x %02x %02x %02x\n", 287 dev_dbg(dev, "alarm write %02x %02x %02x %02x %02x\n",
275 fm3130->regs[FM3130_ALARM_SECONDS], 288 fm3130->regs[FM3130_ALARM_SECONDS],
@@ -285,11 +298,8 @@ static int fm3130_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
285 } 298 }
286 fm3130->regs[FM3130_RTC_CONTROL] = 299 fm3130->regs[FM3130_RTC_CONTROL] =
287 i2c_smbus_read_byte_data(fm3130->client, FM3130_RTC_CONTROL); 300 i2c_smbus_read_byte_data(fm3130->client, FM3130_RTC_CONTROL);
288 /* Checking for alarm */ 301
289 if (fm3130->regs[FM3130_RTC_CONTROL] & FM3130_RTC_CONTROL_BIT_AF) { 302 /* enable or disable alarm */
290 fm3130->alarm = 1;
291 fm3130->regs[FM3130_RTC_CONTROL] &= ~FM3130_RTC_CONTROL_BIT_AF;
292 }
293 if (alrm->enabled) { 303 if (alrm->enabled) {
294 i2c_smbus_write_byte_data(fm3130->client, FM3130_RTC_CONTROL, 304 i2c_smbus_write_byte_data(fm3130->client, FM3130_RTC_CONTROL,
295 (fm3130->regs[FM3130_RTC_CONTROL] & 305 (fm3130->regs[FM3130_RTC_CONTROL] &
@@ -298,16 +308,55 @@ static int fm3130_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
298 } else { 308 } else {
299 i2c_smbus_write_byte_data(fm3130->client, FM3130_RTC_CONTROL, 309 i2c_smbus_write_byte_data(fm3130->client, FM3130_RTC_CONTROL,
300 fm3130->regs[FM3130_RTC_CONTROL] & 310 fm3130->regs[FM3130_RTC_CONTROL] &
301 ~(FM3130_RTC_CONTROL_BIT_AEN)); 311 ~(FM3130_RTC_CONTROL_BIT_CAL) &
312 ~(FM3130_RTC_CONTROL_BIT_AEN));
302 } 313 }
314
315 /* We assume here that data is valid once written */
316 if (!fm3130->alarm_valid)
317 fm3130->alarm_valid = 1;
318
303 return 0; 319 return 0;
304} 320}
305 321
322static int fm3130_alarm_irq_enable(struct device *dev, unsigned int enabled)
323{
324 struct fm3130 *fm3130 = dev_get_drvdata(dev);
325 int ret = 0;
326
327 fm3130->regs[FM3130_RTC_CONTROL] =
328 i2c_smbus_read_byte_data(fm3130->client, FM3130_RTC_CONTROL);
329
330 dev_dbg(dev, "alarm_irq_enable: enable=%d, FM3130_RTC_CONTROL=%02x\n",
331 enabled, fm3130->regs[FM3130_RTC_CONTROL]);
332
333 switch (enabled) {
334 case 0: /* alarm off */
335 ret = i2c_smbus_write_byte_data(fm3130->client,
336 FM3130_RTC_CONTROL, fm3130->regs[FM3130_RTC_CONTROL] &
337 ~(FM3130_RTC_CONTROL_BIT_CAL) &
338 ~(FM3130_RTC_CONTROL_BIT_AEN));
339 break;
340 case 1: /* alarm on */
341 ret = i2c_smbus_write_byte_data(fm3130->client,
342 FM3130_RTC_CONTROL, (fm3130->regs[FM3130_RTC_CONTROL] &
343 ~(FM3130_RTC_CONTROL_BIT_CAL)) |
344 FM3130_RTC_CONTROL_BIT_AEN);
345 break;
346 default:
347 ret = -EINVAL;
348 break;
349 }
350
351 return ret;
352}
353
306static const struct rtc_class_ops fm3130_rtc_ops = { 354static const struct rtc_class_ops fm3130_rtc_ops = {
307 .read_time = fm3130_get_time, 355 .read_time = fm3130_get_time,
308 .set_time = fm3130_set_time, 356 .set_time = fm3130_set_time,
309 .read_alarm = fm3130_read_alarm, 357 .read_alarm = fm3130_read_alarm,
310 .set_alarm = fm3130_set_alarm, 358 .set_alarm = fm3130_set_alarm,
359 .alarm_irq_enable = fm3130_alarm_irq_enable,
311}; 360};
312 361
313static struct i2c_driver fm3130_driver; 362static struct i2c_driver fm3130_driver;
@@ -356,6 +405,7 @@ static int __devinit fm3130_probe(struct i2c_client *client,
356 fm3130->msg[3].len = FM3130_ALARM_REGS; 405 fm3130->msg[3].len = FM3130_ALARM_REGS;
357 fm3130->msg[3].buf = &fm3130->regs[FM3130_ALARM_SECONDS]; 406 fm3130->msg[3].buf = &fm3130->regs[FM3130_ALARM_SECONDS];
358 407
408 fm3130->alarm_valid = 0;
359 fm3130->data_valid = 0; 409 fm3130->data_valid = 0;
360 410
361 tmp = i2c_transfer(adapter, fm3130->msg, 4); 411 tmp = i2c_transfer(adapter, fm3130->msg, 4);
@@ -370,12 +420,6 @@ static int __devinit fm3130_probe(struct i2c_client *client,
370 fm3130->regs[FM3130_CAL_CONTROL] = 420 fm3130->regs[FM3130_CAL_CONTROL] =
371 i2c_smbus_read_byte_data(client, FM3130_CAL_CONTROL); 421 i2c_smbus_read_byte_data(client, FM3130_CAL_CONTROL);
372 422
373 /* Checking for alarm */
374 if (fm3130->regs[FM3130_RTC_CONTROL] & FM3130_RTC_CONTROL_BIT_AF) {
375 fm3130->alarm = 1;
376 fm3130->regs[FM3130_RTC_CONTROL] &= ~FM3130_RTC_CONTROL_BIT_AF;
377 }
378
379 /* Disabling calibration mode */ 423 /* Disabling calibration mode */
380 if (fm3130->regs[FM3130_RTC_CONTROL] & FM3130_RTC_CONTROL_BIT_CAL) { 424 if (fm3130->regs[FM3130_RTC_CONTROL] & FM3130_RTC_CONTROL_BIT_CAL) {
381 i2c_smbus_write_byte_data(client, FM3130_RTC_CONTROL, 425 i2c_smbus_write_byte_data(client, FM3130_RTC_CONTROL,
@@ -400,44 +444,79 @@ static int __devinit fm3130_probe(struct i2c_client *client,
400 fm3130->regs[FM3130_CAL_CONTROL] & 444 fm3130->regs[FM3130_CAL_CONTROL] &
401 ~(FM3130_CAL_CONTROL_BIT_nOSCEN)); 445 ~(FM3130_CAL_CONTROL_BIT_nOSCEN));
402 446
403 /* oscillator fault? clear flag, and warn */ 447 /* low battery? clear flag, and warn */
404 if (fm3130->regs[FM3130_RTC_CONTROL] & FM3130_RTC_CONTROL_BIT_LB) 448 if (fm3130->regs[FM3130_RTC_CONTROL] & FM3130_RTC_CONTROL_BIT_LB) {
449 i2c_smbus_write_byte_data(client, FM3130_RTC_CONTROL,
450 fm3130->regs[FM3130_RTC_CONTROL] &
451 ~(FM3130_RTC_CONTROL_BIT_LB));
405 dev_warn(&client->dev, "Low battery!\n"); 452 dev_warn(&client->dev, "Low battery!\n");
453 }
406 454
407 /* oscillator fault? clear flag, and warn */ 455 /* check if Power On Reset bit is set */
408 if (fm3130->regs[FM3130_RTC_CONTROL] & FM3130_RTC_CONTROL_BIT_POR) { 456 if (fm3130->regs[FM3130_RTC_CONTROL] & FM3130_RTC_CONTROL_BIT_POR) {
409 i2c_smbus_write_byte_data(client, FM3130_RTC_CONTROL, 457 i2c_smbus_write_byte_data(client, FM3130_RTC_CONTROL,
410 fm3130->regs[FM3130_RTC_CONTROL] & 458 fm3130->regs[FM3130_RTC_CONTROL] &
411 ~FM3130_RTC_CONTROL_BIT_POR); 459 ~FM3130_RTC_CONTROL_BIT_POR);
412 dev_warn(&client->dev, "SET TIME!\n"); 460 dev_dbg(&client->dev, "POR bit is set\n");
413 } 461 }
414 /* ACS is controlled by alarm */ 462 /* ACS is controlled by alarm */
415 i2c_smbus_write_byte_data(client, FM3130_ALARM_WP_CONTROL, 0x80); 463 i2c_smbus_write_byte_data(client, FM3130_ALARM_WP_CONTROL, 0x80);
416 464
417 /* TODO */ 465 /* alarm registers sanity check */
418 /* TODO need to sanity check alarm */ 466 tmp = bcd2bin(fm3130->regs[FM3130_RTC_SECONDS] & 0x7f);
419 tmp = fm3130->regs[FM3130_RTC_SECONDS]; 467 if (tmp > 59)
420 tmp = bcd2bin(tmp & 0x7f); 468 goto bad_alarm;
421 if (tmp > 60) 469
422 goto exit_bad;
423 tmp = bcd2bin(fm3130->regs[FM3130_RTC_MINUTES] & 0x7f); 470 tmp = bcd2bin(fm3130->regs[FM3130_RTC_MINUTES] & 0x7f);
424 if (tmp > 60) 471 if (tmp > 59)
425 goto exit_bad; 472 goto bad_alarm;
473
474 tmp = bcd2bin(fm3130->regs[FM3130_RTC_HOURS] & 0x3f);
475 if (tmp > 23)
476 goto bad_alarm;
426 477
427 tmp = bcd2bin(fm3130->regs[FM3130_RTC_DATE] & 0x3f); 478 tmp = bcd2bin(fm3130->regs[FM3130_RTC_DATE] & 0x3f);
428 if (tmp == 0 || tmp > 31) 479 if (tmp == 0 || tmp > 31)
429 goto exit_bad; 480 goto bad_alarm;
430 481
431 tmp = bcd2bin(fm3130->regs[FM3130_RTC_MONTHS] & 0x1f); 482 tmp = bcd2bin(fm3130->regs[FM3130_RTC_MONTHS] & 0x1f);
432 if (tmp == 0 || tmp > 12) 483 if (tmp == 0 || tmp > 12)
433 goto exit_bad; 484 goto bad_alarm;
434 485
435 tmp = fm3130->regs[FM3130_RTC_HOURS]; 486 fm3130->alarm_valid = 1;
487
488bad_alarm:
489
490 /* clock registers sanity chek */
491 tmp = bcd2bin(fm3130->regs[FM3130_RTC_SECONDS] & 0x7f);
492 if (tmp > 59)
493 goto bad_clock;
494
495 tmp = bcd2bin(fm3130->regs[FM3130_RTC_MINUTES] & 0x7f);
496 if (tmp > 59)
497 goto bad_clock;
498
499 tmp = bcd2bin(fm3130->regs[FM3130_RTC_HOURS] & 0x3f);
500 if (tmp > 23)
501 goto bad_clock;
502
503 tmp = bcd2bin(fm3130->regs[FM3130_RTC_DAY] & 0x7);
504 if (tmp == 0 || tmp > 7)
505 goto bad_clock;
506
507 tmp = bcd2bin(fm3130->regs[FM3130_RTC_DATE] & 0x3f);
508 if (tmp == 0 || tmp > 31)
509 goto bad_clock;
510
511 tmp = bcd2bin(fm3130->regs[FM3130_RTC_MONTHS] & 0x1f);
512 if (tmp == 0 || tmp > 12)
513 goto bad_clock;
436 514
437 fm3130->data_valid = 1; 515 fm3130->data_valid = 1;
438 516
439exit_bad: 517bad_clock:
440 if (!fm3130->data_valid) 518
519 if (!fm3130->data_valid || !fm3130->alarm_valid)
441 dev_dbg(&client->dev, 520 dev_dbg(&client->dev,
442 "%s: %02x %02x %02x %02x %02x %02x %02x %02x" 521 "%s: %02x %02x %02x %02x %02x %02x %02x %02x"
443 "%02x %02x %02x %02x %02x %02x %02x\n", 522 "%02x %02x %02x %02x %02x %02x %02x\n",
diff --git a/drivers/rtc/rtc-imxdi.c b/drivers/rtc/rtc-imxdi.c
new file mode 100644
index 000000000000..2dd3c0163272
--- /dev/null
+++ b/drivers/rtc/rtc-imxdi.c
@@ -0,0 +1,519 @@
1/*
2 * Copyright 2008-2009 Freescale Semiconductor, Inc. All Rights Reserved.
3 * Copyright 2010 Orex Computed Radiography
4 */
5
6/*
7 * The code contained herein is licensed under the GNU General Public
8 * License. You may obtain a copy of the GNU General Public License
9 * Version 2 or later at the following locations:
10 *
11 * http://www.opensource.org/licenses/gpl-license.html
12 * http://www.gnu.org/copyleft/gpl.html
13 */
14
15/* based on rtc-mc13892.c */
16
17/*
18 * This driver uses the 47-bit 32 kHz counter in the Freescale DryIce block
19 * to implement a Linux RTC. Times and alarms are truncated to seconds.
20 * Since the RTC framework performs API locking via rtc->ops_lock the
21 * only simultaneous accesses we need to deal with is updating DryIce
22 * registers while servicing an alarm.
23 *
24 * Note that reading the DSR (DryIce Status Register) automatically clears
25 * the WCF (Write Complete Flag). All DryIce writes are synchronized to the
26 * LP (Low Power) domain and set the WCF upon completion. Writes to the
27 * DIER (DryIce Interrupt Enable Register) are the only exception. These
28 * occur at normal bus speeds and do not set WCF. Periodic interrupts are
29 * not supported by the hardware.
30 */
31
32#include <linux/io.h>
33#include <linux/clk.h>
34#include <linux/delay.h>
35#include <linux/module.h>
36#include <linux/platform_device.h>
37#include <linux/rtc.h>
38#include <linux/workqueue.h>
39
40/* DryIce Register Definitions */
41
42#define DTCMR 0x00 /* Time Counter MSB Reg */
43#define DTCLR 0x04 /* Time Counter LSB Reg */
44
45#define DCAMR 0x08 /* Clock Alarm MSB Reg */
46#define DCALR 0x0c /* Clock Alarm LSB Reg */
47#define DCAMR_UNSET 0xFFFFFFFF /* doomsday - 1 sec */
48
49#define DCR 0x10 /* Control Reg */
50#define DCR_TCE (1 << 3) /* Time Counter Enable */
51
52#define DSR 0x14 /* Status Reg */
53#define DSR_WBF (1 << 10) /* Write Busy Flag */
54#define DSR_WNF (1 << 9) /* Write Next Flag */
55#define DSR_WCF (1 << 8) /* Write Complete Flag */
56#define DSR_WEF (1 << 7) /* Write Error Flag */
57#define DSR_CAF (1 << 4) /* Clock Alarm Flag */
58#define DSR_NVF (1 << 1) /* Non-Valid Flag */
59#define DSR_SVF (1 << 0) /* Security Violation Flag */
60
61#define DIER 0x18 /* Interrupt Enable Reg */
62#define DIER_WNIE (1 << 9) /* Write Next Interrupt Enable */
63#define DIER_WCIE (1 << 8) /* Write Complete Interrupt Enable */
64#define DIER_WEIE (1 << 7) /* Write Error Interrupt Enable */
65#define DIER_CAIE (1 << 4) /* Clock Alarm Interrupt Enable */
66
67/**
68 * struct imxdi_dev - private imxdi rtc data
69 * @pdev: pionter to platform dev
70 * @rtc: pointer to rtc struct
71 * @ioaddr: IO registers pointer
72 * @irq: dryice normal interrupt
73 * @clk: input reference clock
74 * @dsr: copy of the DSR register
75 * @irq_lock: interrupt enable register (DIER) lock
76 * @write_wait: registers write complete queue
77 * @write_mutex: serialize registers write
78 * @work: schedule alarm work
79 */
80struct imxdi_dev {
81 struct platform_device *pdev;
82 struct rtc_device *rtc;
83 void __iomem *ioaddr;
84 int irq;
85 struct clk *clk;
86 u32 dsr;
87 spinlock_t irq_lock;
88 wait_queue_head_t write_wait;
89 struct mutex write_mutex;
90 struct work_struct work;
91};
92
93/*
94 * enable a dryice interrupt
95 */
96static void di_int_enable(struct imxdi_dev *imxdi, u32 intr)
97{
98 unsigned long flags;
99
100 spin_lock_irqsave(&imxdi->irq_lock, flags);
101 __raw_writel(__raw_readl(imxdi->ioaddr + DIER) | intr,
102 imxdi->ioaddr + DIER);
103 spin_unlock_irqrestore(&imxdi->irq_lock, flags);
104}
105
106/*
107 * disable a dryice interrupt
108 */
109static void di_int_disable(struct imxdi_dev *imxdi, u32 intr)
110{
111 unsigned long flags;
112
113 spin_lock_irqsave(&imxdi->irq_lock, flags);
114 __raw_writel(__raw_readl(imxdi->ioaddr + DIER) & ~intr,
115 imxdi->ioaddr + DIER);
116 spin_unlock_irqrestore(&imxdi->irq_lock, flags);
117}
118
119/*
120 * This function attempts to clear the dryice write-error flag.
121 *
122 * A dryice write error is similar to a bus fault and should not occur in
123 * normal operation. Clearing the flag requires another write, so the root
124 * cause of the problem may need to be fixed before the flag can be cleared.
125 */
126static void clear_write_error(struct imxdi_dev *imxdi)
127{
128 int cnt;
129
130 dev_warn(&imxdi->pdev->dev, "WARNING: Register write error!\n");
131
132 /* clear the write error flag */
133 __raw_writel(DSR_WEF, imxdi->ioaddr + DSR);
134
135 /* wait for it to take effect */
136 for (cnt = 0; cnt < 1000; cnt++) {
137 if ((__raw_readl(imxdi->ioaddr + DSR) & DSR_WEF) == 0)
138 return;
139 udelay(10);
140 }
141 dev_err(&imxdi->pdev->dev,
142 "ERROR: Cannot clear write-error flag!\n");
143}
144
145/*
146 * Write a dryice register and wait until it completes.
147 *
148 * This function uses interrupts to determine when the
149 * write has completed.
150 */
151static int di_write_wait(struct imxdi_dev *imxdi, u32 val, int reg)
152{
153 int ret;
154 int rc = 0;
155
156 /* serialize register writes */
157 mutex_lock(&imxdi->write_mutex);
158
159 /* enable the write-complete interrupt */
160 di_int_enable(imxdi, DIER_WCIE);
161
162 imxdi->dsr = 0;
163
164 /* do the register write */
165 __raw_writel(val, imxdi->ioaddr + reg);
166
167 /* wait for the write to finish */
168 ret = wait_event_interruptible_timeout(imxdi->write_wait,
169 imxdi->dsr & (DSR_WCF | DSR_WEF), msecs_to_jiffies(1));
170 if (ret < 0) {
171 rc = ret;
172 goto out;
173 } else if (ret == 0) {
174 dev_warn(&imxdi->pdev->dev,
175 "Write-wait timeout "
176 "val = 0x%08x reg = 0x%08x\n", val, reg);
177 }
178
179 /* check for write error */
180 if (imxdi->dsr & DSR_WEF) {
181 clear_write_error(imxdi);
182 rc = -EIO;
183 }
184
185out:
186 mutex_unlock(&imxdi->write_mutex);
187
188 return rc;
189}
190
191/*
192 * read the seconds portion of the current time from the dryice time counter
193 */
194static int dryice_rtc_read_time(struct device *dev, struct rtc_time *tm)
195{
196 struct imxdi_dev *imxdi = dev_get_drvdata(dev);
197 unsigned long now;
198
199 now = __raw_readl(imxdi->ioaddr + DTCMR);
200 rtc_time_to_tm(now, tm);
201
202 return 0;
203}
204
205/*
206 * set the seconds portion of dryice time counter and clear the
207 * fractional part.
208 */
209static int dryice_rtc_set_mmss(struct device *dev, unsigned long secs)
210{
211 struct imxdi_dev *imxdi = dev_get_drvdata(dev);
212 int rc;
213
214 /* zero the fractional part first */
215 rc = di_write_wait(imxdi, 0, DTCLR);
216 if (rc == 0)
217 rc = di_write_wait(imxdi, secs, DTCMR);
218
219 return rc;
220}
221
222static int dryice_rtc_alarm_irq_enable(struct device *dev,
223 unsigned int enabled)
224{
225 struct imxdi_dev *imxdi = dev_get_drvdata(dev);
226
227 if (enabled)
228 di_int_enable(imxdi, DIER_CAIE);
229 else
230 di_int_disable(imxdi, DIER_CAIE);
231
232 return 0;
233}
234
235/*
236 * read the seconds portion of the alarm register.
237 * the fractional part of the alarm register is always zero.
238 */
239static int dryice_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
240{
241 struct imxdi_dev *imxdi = dev_get_drvdata(dev);
242 u32 dcamr;
243
244 dcamr = __raw_readl(imxdi->ioaddr + DCAMR);
245 rtc_time_to_tm(dcamr, &alarm->time);
246
247 /* alarm is enabled if the interrupt is enabled */
248 alarm->enabled = (__raw_readl(imxdi->ioaddr + DIER) & DIER_CAIE) != 0;
249
250 /* don't allow the DSR read to mess up DSR_WCF */
251 mutex_lock(&imxdi->write_mutex);
252
253 /* alarm is pending if the alarm flag is set */
254 alarm->pending = (__raw_readl(imxdi->ioaddr + DSR) & DSR_CAF) != 0;
255
256 mutex_unlock(&imxdi->write_mutex);
257
258 return 0;
259}
260
261/*
262 * set the seconds portion of dryice alarm register
263 */
264static int dryice_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
265{
266 struct imxdi_dev *imxdi = dev_get_drvdata(dev);
267 unsigned long now;
268 unsigned long alarm_time;
269 int rc;
270
271 rc = rtc_tm_to_time(&alarm->time, &alarm_time);
272 if (rc)
273 return rc;
274
275 /* don't allow setting alarm in the past */
276 now = __raw_readl(imxdi->ioaddr + DTCMR);
277 if (alarm_time < now)
278 return -EINVAL;
279
280 /* write the new alarm time */
281 rc = di_write_wait(imxdi, (u32)alarm_time, DCAMR);
282 if (rc)
283 return rc;
284
285 if (alarm->enabled)
286 di_int_enable(imxdi, DIER_CAIE); /* enable alarm intr */
287 else
288 di_int_disable(imxdi, DIER_CAIE); /* disable alarm intr */
289
290 return 0;
291}
292
293static struct rtc_class_ops dryice_rtc_ops = {
294 .read_time = dryice_rtc_read_time,
295 .set_mmss = dryice_rtc_set_mmss,
296 .alarm_irq_enable = dryice_rtc_alarm_irq_enable,
297 .read_alarm = dryice_rtc_read_alarm,
298 .set_alarm = dryice_rtc_set_alarm,
299};
300
301/*
302 * dryice "normal" interrupt handler
303 */
304static irqreturn_t dryice_norm_irq(int irq, void *dev_id)
305{
306 struct imxdi_dev *imxdi = dev_id;
307 u32 dsr, dier;
308 irqreturn_t rc = IRQ_NONE;
309
310 dier = __raw_readl(imxdi->ioaddr + DIER);
311
312 /* handle write complete and write error cases */
313 if ((dier & DIER_WCIE)) {
314 /*If the write wait queue is empty then there is no pending
315 operations. It means the interrupt is for DryIce -Security.
316 IRQ must be returned as none.*/
317 if (list_empty_careful(&imxdi->write_wait.task_list))
318 return rc;
319
320 /* DSR_WCF clears itself on DSR read */
321 dsr = __raw_readl(imxdi->ioaddr + DSR);
322 if ((dsr & (DSR_WCF | DSR_WEF))) {
323 /* mask the interrupt */
324 di_int_disable(imxdi, DIER_WCIE);
325
326 /* save the dsr value for the wait queue */
327 imxdi->dsr |= dsr;
328
329 wake_up_interruptible(&imxdi->write_wait);
330 rc = IRQ_HANDLED;
331 }
332 }
333
334 /* handle the alarm case */
335 if ((dier & DIER_CAIE)) {
336 /* DSR_WCF clears itself on DSR read */
337 dsr = __raw_readl(imxdi->ioaddr + DSR);
338 if (dsr & DSR_CAF) {
339 /* mask the interrupt */
340 di_int_disable(imxdi, DIER_CAIE);
341
342 /* finish alarm in user context */
343 schedule_work(&imxdi->work);
344 rc = IRQ_HANDLED;
345 }
346 }
347 return rc;
348}
349
350/*
351 * post the alarm event from user context so it can sleep
352 * on the write completion.
353 */
354static void dryice_work(struct work_struct *work)
355{
356 struct imxdi_dev *imxdi = container_of(work,
357 struct imxdi_dev, work);
358
359 /* dismiss the interrupt (ignore error) */
360 di_write_wait(imxdi, DSR_CAF, DSR);
361
362 /* pass the alarm event to the rtc framework. */
363 rtc_update_irq(imxdi->rtc, 1, RTC_AF | RTC_IRQF);
364}
365
366/*
367 * probe for dryice rtc device
368 */
369static int dryice_rtc_probe(struct platform_device *pdev)
370{
371 struct resource *res;
372 struct imxdi_dev *imxdi;
373 int rc;
374
375 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
376 if (!res)
377 return -ENODEV;
378
379 imxdi = devm_kzalloc(&pdev->dev, sizeof(*imxdi), GFP_KERNEL);
380 if (!imxdi)
381 return -ENOMEM;
382
383 imxdi->pdev = pdev;
384
385 if (!devm_request_mem_region(&pdev->dev, res->start, resource_size(res),
386 pdev->name))
387 return -EBUSY;
388
389 imxdi->ioaddr = devm_ioremap(&pdev->dev, res->start,
390 resource_size(res));
391 if (imxdi->ioaddr == NULL)
392 return -ENOMEM;
393
394 imxdi->irq = platform_get_irq(pdev, 0);
395 if (imxdi->irq < 0)
396 return imxdi->irq;
397
398 init_waitqueue_head(&imxdi->write_wait);
399
400 INIT_WORK(&imxdi->work, dryice_work);
401
402 mutex_init(&imxdi->write_mutex);
403
404 imxdi->clk = clk_get(&pdev->dev, NULL);
405 if (IS_ERR(imxdi->clk))
406 return PTR_ERR(imxdi->clk);
407 clk_enable(imxdi->clk);
408
409 /*
410 * Initialize dryice hardware
411 */
412
413 /* mask all interrupts */
414 __raw_writel(0, imxdi->ioaddr + DIER);
415
416 rc = devm_request_irq(&pdev->dev, imxdi->irq, dryice_norm_irq,
417 IRQF_SHARED, pdev->name, imxdi);
418 if (rc) {
419 dev_warn(&pdev->dev, "interrupt not available.\n");
420 goto err;
421 }
422
423 /* put dryice into valid state */
424 if (__raw_readl(imxdi->ioaddr + DSR) & DSR_NVF) {
425 rc = di_write_wait(imxdi, DSR_NVF | DSR_SVF, DSR);
426 if (rc)
427 goto err;
428 }
429
430 /* initialize alarm */
431 rc = di_write_wait(imxdi, DCAMR_UNSET, DCAMR);
432 if (rc)
433 goto err;
434 rc = di_write_wait(imxdi, 0, DCALR);
435 if (rc)
436 goto err;
437
438 /* clear alarm flag */
439 if (__raw_readl(imxdi->ioaddr + DSR) & DSR_CAF) {
440 rc = di_write_wait(imxdi, DSR_CAF, DSR);
441 if (rc)
442 goto err;
443 }
444
445 /* the timer won't count if it has never been written to */
446 if (__raw_readl(imxdi->ioaddr + DTCMR) == 0) {
447 rc = di_write_wait(imxdi, 0, DTCMR);
448 if (rc)
449 goto err;
450 }
451
452 /* start keeping time */
453 if (!(__raw_readl(imxdi->ioaddr + DCR) & DCR_TCE)) {
454 rc = di_write_wait(imxdi,
455 __raw_readl(imxdi->ioaddr + DCR) | DCR_TCE,
456 DCR);
457 if (rc)
458 goto err;
459 }
460
461 platform_set_drvdata(pdev, imxdi);
462 imxdi->rtc = rtc_device_register(pdev->name, &pdev->dev,
463 &dryice_rtc_ops, THIS_MODULE);
464 if (IS_ERR(imxdi->rtc)) {
465 rc = PTR_ERR(imxdi->rtc);
466 goto err;
467 }
468
469 return 0;
470
471err:
472 clk_disable(imxdi->clk);
473 clk_put(imxdi->clk);
474
475 return rc;
476}
477
478static int __devexit dryice_rtc_remove(struct platform_device *pdev)
479{
480 struct imxdi_dev *imxdi = platform_get_drvdata(pdev);
481
482 flush_work(&imxdi->work);
483
484 /* mask all interrupts */
485 __raw_writel(0, imxdi->ioaddr + DIER);
486
487 rtc_device_unregister(imxdi->rtc);
488
489 clk_disable(imxdi->clk);
490 clk_put(imxdi->clk);
491
492 return 0;
493}
494
495static struct platform_driver dryice_rtc_driver = {
496 .driver = {
497 .name = "imxdi_rtc",
498 .owner = THIS_MODULE,
499 },
500 .remove = __devexit_p(dryice_rtc_remove),
501};
502
503static int __init dryice_rtc_init(void)
504{
505 return platform_driver_probe(&dryice_rtc_driver, dryice_rtc_probe);
506}
507
508static void __exit dryice_rtc_exit(void)
509{
510 platform_driver_unregister(&dryice_rtc_driver);
511}
512
513module_init(dryice_rtc_init);
514module_exit(dryice_rtc_exit);
515
516MODULE_AUTHOR("Freescale Semiconductor, Inc.");
517MODULE_AUTHOR("Baruch Siach <baruch@tkos.co.il>");
518MODULE_DESCRIPTION("IMX DryIce Realtime Clock Driver (RTC)");
519MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/rtc-isl12022.c b/drivers/rtc/rtc-isl12022.c
new file mode 100644
index 000000000000..ddbc797ea6cd
--- /dev/null
+++ b/drivers/rtc/rtc-isl12022.c
@@ -0,0 +1,327 @@
1/*
2 * An I2C driver for the Intersil ISL 12022
3 *
4 * Author: Roman Fietze <roman.fietze@telemotive.de>
5 *
6 * Based on the Philips PCF8563 RTC
7 * by Alessandro Zummo <a.zummo@towertech.it>.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License version
11 * 2 as published by the Free Software Foundation.
12 */
13
14#include <linux/i2c.h>
15#include <linux/bcd.h>
16#include <linux/rtc.h>
17#include <linux/slab.h>
18
19#define DRV_VERSION "0.1"
20
21/* ISL register offsets */
22#define ISL12022_REG_SC 0x00
23#define ISL12022_REG_MN 0x01
24#define ISL12022_REG_HR 0x02
25#define ISL12022_REG_DT 0x03
26#define ISL12022_REG_MO 0x04
27#define ISL12022_REG_YR 0x05
28#define ISL12022_REG_DW 0x06
29
30#define ISL12022_REG_SR 0x07
31#define ISL12022_REG_INT 0x08
32
33/* ISL register bits */
34#define ISL12022_HR_MIL (1 << 7) /* military or 24 hour time */
35
36#define ISL12022_SR_LBAT85 (1 << 2)
37#define ISL12022_SR_LBAT75 (1 << 1)
38
39#define ISL12022_INT_WRTC (1 << 6)
40
41
42static struct i2c_driver isl12022_driver;
43
44struct isl12022 {
45 struct rtc_device *rtc;
46
47 bool write_enabled; /* true if write enable is set */
48};
49
50
51static int isl12022_read_regs(struct i2c_client *client, uint8_t reg,
52 uint8_t *data, size_t n)
53{
54 struct i2c_msg msgs[] = {
55 {
56 .addr = client->addr,
57 .flags = 0,
58 .len = 1,
59 .buf = data
60 }, /* setup read ptr */
61 {
62 .addr = client->addr,
63 .flags = I2C_M_RD,
64 .len = n,
65 .buf = data
66 }
67 };
68
69 int ret;
70
71 data[0] = reg;
72 ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
73 if (ret != ARRAY_SIZE(msgs)) {
74 dev_err(&client->dev, "%s: read error, ret=%d\n",
75 __func__, ret);
76 return -EIO;
77 }
78
79 return 0;
80}
81
82
83static int isl12022_write_reg(struct i2c_client *client,
84 uint8_t reg, uint8_t val)
85{
86 uint8_t data[2] = { reg, val };
87 int err;
88
89 err = i2c_master_send(client, data, sizeof(data));
90 if (err != sizeof(data)) {
91 dev_err(&client->dev,
92 "%s: err=%d addr=%02x, data=%02x\n",
93 __func__, err, data[0], data[1]);
94 return -EIO;
95 }
96
97 return 0;
98}
99
100
101/*
102 * In the routines that deal directly with the isl12022 hardware, we use
103 * rtc_time -- month 0-11, hour 0-23, yr = calendar year-epoch.
104 */
105static int isl12022_get_datetime(struct i2c_client *client, struct rtc_time *tm)
106{
107 uint8_t buf[ISL12022_REG_INT + 1];
108 int ret;
109
110 ret = isl12022_read_regs(client, ISL12022_REG_SC, buf, sizeof(buf));
111 if (ret)
112 return ret;
113
114 if (buf[ISL12022_REG_SR] & (ISL12022_SR_LBAT85 | ISL12022_SR_LBAT75)) {
115 dev_warn(&client->dev,
116 "voltage dropped below %u%%, "
117 "date and time is not reliable.\n",
118 buf[ISL12022_REG_SR] & ISL12022_SR_LBAT85 ? 85 : 75);
119 }
120
121 dev_dbg(&client->dev,
122 "%s: raw data is sec=%02x, min=%02x, hr=%02x, "
123 "mday=%02x, mon=%02x, year=%02x, wday=%02x, "
124 "sr=%02x, int=%02x",
125 __func__,
126 buf[ISL12022_REG_SC],
127 buf[ISL12022_REG_MN],
128 buf[ISL12022_REG_HR],
129 buf[ISL12022_REG_DT],
130 buf[ISL12022_REG_MO],
131 buf[ISL12022_REG_YR],
132 buf[ISL12022_REG_DW],
133 buf[ISL12022_REG_SR],
134 buf[ISL12022_REG_INT]);
135
136 tm->tm_sec = bcd2bin(buf[ISL12022_REG_SC] & 0x7F);
137 tm->tm_min = bcd2bin(buf[ISL12022_REG_MN] & 0x7F);
138 tm->tm_hour = bcd2bin(buf[ISL12022_REG_HR] & 0x3F);
139 tm->tm_mday = bcd2bin(buf[ISL12022_REG_DT] & 0x3F);
140 tm->tm_wday = buf[ISL12022_REG_DW] & 0x07;
141 tm->tm_mon = bcd2bin(buf[ISL12022_REG_MO] & 0x1F) - 1;
142 tm->tm_year = bcd2bin(buf[ISL12022_REG_YR]) + 100;
143
144 dev_dbg(&client->dev, "%s: secs=%d, mins=%d, hours=%d, "
145 "mday=%d, mon=%d, year=%d, wday=%d\n",
146 __func__,
147 tm->tm_sec, tm->tm_min, tm->tm_hour,
148 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
149
150 /* The clock can give out invalid datetime, but we cannot return
151 * -EINVAL otherwise hwclock will refuse to set the time on bootup. */
152 if (rtc_valid_tm(tm) < 0)
153 dev_err(&client->dev, "retrieved date and time is invalid.\n");
154
155 return 0;
156}
157
158static int isl12022_set_datetime(struct i2c_client *client, struct rtc_time *tm)
159{
160 struct isl12022 *isl12022 = i2c_get_clientdata(client);
161 size_t i;
162 int ret;
163 uint8_t buf[ISL12022_REG_DW + 1];
164
165 dev_dbg(&client->dev, "%s: secs=%d, mins=%d, hours=%d, "
166 "mday=%d, mon=%d, year=%d, wday=%d\n",
167 __func__,
168 tm->tm_sec, tm->tm_min, tm->tm_hour,
169 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
170
171 if (!isl12022->write_enabled) {
172
173 ret = isl12022_read_regs(client, ISL12022_REG_INT, buf, 1);
174 if (ret)
175 return ret;
176
177 /* Check if WRTC (write rtc enable) is set factory default is
178 * 0 (not set) */
179 if (!(buf[0] & ISL12022_INT_WRTC)) {
180 dev_info(&client->dev,
181 "init write enable and 24 hour format\n");
182
183 /* Set the write enable bit. */
184 ret = isl12022_write_reg(client,
185 ISL12022_REG_INT,
186 buf[0] | ISL12022_INT_WRTC);
187 if (ret)
188 return ret;
189
190 /* Write to any RTC register to start RTC, we use the
191 * HR register, setting the MIL bit to use the 24 hour
192 * format. */
193 ret = isl12022_read_regs(client, ISL12022_REG_HR,
194 buf, 1);
195 if (ret)
196 return ret;
197
198 ret = isl12022_write_reg(client,
199 ISL12022_REG_HR,
200 buf[0] | ISL12022_HR_MIL);
201 if (ret)
202 return ret;
203 }
204
205 isl12022->write_enabled = 1;
206 }
207
208 /* hours, minutes and seconds */
209 buf[ISL12022_REG_SC] = bin2bcd(tm->tm_sec);
210 buf[ISL12022_REG_MN] = bin2bcd(tm->tm_min);
211 buf[ISL12022_REG_HR] = bin2bcd(tm->tm_hour) | ISL12022_HR_MIL;
212
213 buf[ISL12022_REG_DT] = bin2bcd(tm->tm_mday);
214
215 /* month, 1 - 12 */
216 buf[ISL12022_REG_MO] = bin2bcd(tm->tm_mon + 1);
217
218 /* year and century */
219 buf[ISL12022_REG_YR] = bin2bcd(tm->tm_year % 100);
220
221 buf[ISL12022_REG_DW] = tm->tm_wday & 0x07;
222
223 /* write register's data */
224 for (i = 0; i < ARRAY_SIZE(buf); i++) {
225 ret = isl12022_write_reg(client, ISL12022_REG_SC + i,
226 buf[ISL12022_REG_SC + i]);
227 if (ret)
228 return -EIO;
229 };
230
231 return 0;
232}
233
234static int isl12022_rtc_read_time(struct device *dev, struct rtc_time *tm)
235{
236 return isl12022_get_datetime(to_i2c_client(dev), tm);
237}
238
239static int isl12022_rtc_set_time(struct device *dev, struct rtc_time *tm)
240{
241 return isl12022_set_datetime(to_i2c_client(dev), tm);
242}
243
244static const struct rtc_class_ops isl12022_rtc_ops = {
245 .read_time = isl12022_rtc_read_time,
246 .set_time = isl12022_rtc_set_time,
247};
248
249static int isl12022_probe(struct i2c_client *client,
250 const struct i2c_device_id *id)
251{
252 struct isl12022 *isl12022;
253
254 int ret = 0;
255
256 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
257 return -ENODEV;
258
259 isl12022 = kzalloc(sizeof(struct isl12022), GFP_KERNEL);
260 if (!isl12022)
261 return -ENOMEM;
262
263 dev_dbg(&client->dev, "chip found, driver version " DRV_VERSION "\n");
264
265 i2c_set_clientdata(client, isl12022);
266
267 isl12022->rtc = rtc_device_register(isl12022_driver.driver.name,
268 &client->dev,
269 &isl12022_rtc_ops,
270 THIS_MODULE);
271
272 if (IS_ERR(isl12022->rtc)) {
273 ret = PTR_ERR(isl12022->rtc);
274 goto exit_kfree;
275 }
276
277 return 0;
278
279exit_kfree:
280 kfree(isl12022);
281
282 return ret;
283}
284
285static int isl12022_remove(struct i2c_client *client)
286{
287 struct isl12022 *isl12022 = i2c_get_clientdata(client);
288
289 rtc_device_unregister(isl12022->rtc);
290 kfree(isl12022);
291
292 return 0;
293}
294
295static const struct i2c_device_id isl12022_id[] = {
296 { "isl12022", 0 },
297 { "rtc8564", 0 },
298 { }
299};
300MODULE_DEVICE_TABLE(i2c, isl12022_id);
301
302static struct i2c_driver isl12022_driver = {
303 .driver = {
304 .name = "rtc-isl12022",
305 },
306 .probe = isl12022_probe,
307 .remove = isl12022_remove,
308 .id_table = isl12022_id,
309};
310
311static int __init isl12022_init(void)
312{
313 return i2c_add_driver(&isl12022_driver);
314}
315
316static void __exit isl12022_exit(void)
317{
318 i2c_del_driver(&isl12022_driver);
319}
320
321module_init(isl12022_init);
322module_exit(isl12022_exit);
323
324MODULE_AUTHOR("roman.fietze@telemotive.de");
325MODULE_DESCRIPTION("ISL 12022 RTC driver");
326MODULE_LICENSE("GPL");
327MODULE_VERSION(DRV_VERSION);
diff --git a/drivers/rtc/rtc-m41t80.c b/drivers/rtc/rtc-m41t80.c
index 6dc4e6241418..66377f3e28b8 100644
--- a/drivers/rtc/rtc-m41t80.c
+++ b/drivers/rtc/rtc-m41t80.c
@@ -121,7 +121,7 @@ static int m41t80_get_datetime(struct i2c_client *client,
121 121
122 /* assume 20YY not 19YY, and ignore the Century Bit */ 122 /* assume 20YY not 19YY, and ignore the Century Bit */
123 tm->tm_year = bcd2bin(buf[M41T80_REG_YEAR]) + 100; 123 tm->tm_year = bcd2bin(buf[M41T80_REG_YEAR]) + 100;
124 return 0; 124 return rtc_valid_tm(tm);
125} 125}
126 126
127/* Sets the given date and time to the real time clock. */ 127/* Sets the given date and time to the real time clock. */
@@ -364,7 +364,7 @@ static int m41t80_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *t)
364 t->time.tm_isdst = -1; 364 t->time.tm_isdst = -1;
365 t->enabled = !!(reg[M41T80_REG_ALARM_MON] & M41T80_ALMON_AFE); 365 t->enabled = !!(reg[M41T80_REG_ALARM_MON] & M41T80_ALMON_AFE);
366 t->pending = !!(reg[M41T80_REG_FLAGS] & M41T80_FLAGS_AF); 366 t->pending = !!(reg[M41T80_REG_FLAGS] & M41T80_FLAGS_AF);
367 return 0; 367 return rtc_valid_tm(t);
368} 368}
369 369
370static struct rtc_class_ops m41t80_rtc_ops = { 370static struct rtc_class_ops m41t80_rtc_ops = {
diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
index be8359fdb65a..a99a0b554eb8 100644
--- a/drivers/rtc/rtc-m48t59.c
+++ b/drivers/rtc/rtc-m48t59.c
@@ -105,7 +105,7 @@ static int m48t59_rtc_read_time(struct device *dev, struct rtc_time *tm)
105 dev_dbg(dev, "RTC read time %04d-%02d-%02d %02d/%02d/%02d\n", 105 dev_dbg(dev, "RTC read time %04d-%02d-%02d %02d/%02d/%02d\n",
106 tm->tm_year + 1900, tm->tm_mon, tm->tm_mday, 106 tm->tm_year + 1900, tm->tm_mon, tm->tm_mday,
107 tm->tm_hour, tm->tm_min, tm->tm_sec); 107 tm->tm_hour, tm->tm_min, tm->tm_sec);
108 return 0; 108 return rtc_valid_tm(tm);
109} 109}
110 110
111static int m48t59_rtc_set_time(struct device *dev, struct rtc_time *tm) 111static int m48t59_rtc_set_time(struct device *dev, struct rtc_time *tm)
@@ -196,7 +196,7 @@ static int m48t59_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm)
196 dev_dbg(dev, "RTC read alarm time %04d-%02d-%02d %02d/%02d/%02d\n", 196 dev_dbg(dev, "RTC read alarm time %04d-%02d-%02d %02d/%02d/%02d\n",
197 tm->tm_year + 1900, tm->tm_mon, tm->tm_mday, 197 tm->tm_year + 1900, tm->tm_mon, tm->tm_mday,
198 tm->tm_hour, tm->tm_min, tm->tm_sec); 198 tm->tm_hour, tm->tm_min, tm->tm_sec);
199 return 0; 199 return rtc_valid_tm(tm);
200} 200}
201 201
202/* 202/*
@@ -506,7 +506,6 @@ out:
506 free_irq(m48t59->irq, &pdev->dev); 506 free_irq(m48t59->irq, &pdev->dev);
507 if (m48t59->ioaddr) 507 if (m48t59->ioaddr)
508 iounmap(m48t59->ioaddr); 508 iounmap(m48t59->ioaddr);
509 if (m48t59)
510 kfree(m48t59); 509 kfree(m48t59);
511 return ret; 510 return ret;
512} 511}
diff --git a/drivers/rtc/rtc-m48t86.c b/drivers/rtc/rtc-m48t86.c
index 7c045cffa9ff..f981287d582b 100644
--- a/drivers/rtc/rtc-m48t86.c
+++ b/drivers/rtc/rtc-m48t86.c
@@ -77,7 +77,7 @@ static int m48t86_rtc_read_time(struct device *dev, struct rtc_time *tm)
77 if (ops->readbyte(M48T86_REG_HOUR) & 0x80) 77 if (ops->readbyte(M48T86_REG_HOUR) & 0x80)
78 tm->tm_hour += 12; 78 tm->tm_hour += 12;
79 79
80 return 0; 80 return rtc_valid_tm(tm);
81} 81}
82 82
83static int m48t86_rtc_set_time(struct device *dev, struct rtc_time *tm) 83static int m48t86_rtc_set_time(struct device *dev, struct rtc_time *tm)
diff --git a/drivers/rtc/rtc-max6900.c b/drivers/rtc/rtc-max6900.c
index a4f6665ab3c5..486142c2637a 100644
--- a/drivers/rtc/rtc-max6900.c
+++ b/drivers/rtc/rtc-max6900.c
@@ -159,7 +159,7 @@ static int max6900_i2c_read_time(struct i2c_client *client, struct rtc_time *tm)
159 bcd2bin(regs[MAX6900_REG_CENTURY]) * 100 - 1900; 159 bcd2bin(regs[MAX6900_REG_CENTURY]) * 100 - 1900;
160 tm->tm_wday = bcd2bin(regs[MAX6900_REG_DW]); 160 tm->tm_wday = bcd2bin(regs[MAX6900_REG_DW]);
161 161
162 return 0; 162 return rtc_valid_tm(tm);
163} 163}
164 164
165static int max6900_i2c_clear_write_protect(struct i2c_client *client) 165static int max6900_i2c_clear_write_protect(struct i2c_client *client)
diff --git a/drivers/rtc/rtc-mpc5121.c b/drivers/rtc/rtc-mpc5121.c
index db5d8c416d26..dfcdf0901d21 100644
--- a/drivers/rtc/rtc-mpc5121.c
+++ b/drivers/rtc/rtc-mpc5121.c
@@ -268,7 +268,7 @@ static const struct rtc_class_ops mpc5121_rtc_ops = {
268 .update_irq_enable = mpc5121_rtc_update_irq_enable, 268 .update_irq_enable = mpc5121_rtc_update_irq_enable,
269}; 269};
270 270
271static int __devinit mpc5121_rtc_probe(struct of_device *op, 271static int __devinit mpc5121_rtc_probe(struct platform_device *op,
272 const struct of_device_id *match) 272 const struct of_device_id *match)
273{ 273{
274 struct mpc5121_rtc_data *rtc; 274 struct mpc5121_rtc_data *rtc;
@@ -338,7 +338,7 @@ out_free:
338 return err; 338 return err;
339} 339}
340 340
341static int __devexit mpc5121_rtc_remove(struct of_device *op) 341static int __devexit mpc5121_rtc_remove(struct platform_device *op)
342{ 342{
343 struct mpc5121_rtc_data *rtc = dev_get_drvdata(&op->dev); 343 struct mpc5121_rtc_data *rtc = dev_get_drvdata(&op->dev);
344 struct mpc5121_rtc_regs __iomem *regs = rtc->regs; 344 struct mpc5121_rtc_regs __iomem *regs = rtc->regs;
diff --git a/drivers/rtc/rtc-mxc.c b/drivers/rtc/rtc-mxc.c
index 25ec921db07c..0b06c1e03fd5 100644
--- a/drivers/rtc/rtc-mxc.c
+++ b/drivers/rtc/rtc-mxc.c
@@ -83,12 +83,6 @@ struct rtc_plat_data {
83 void __iomem *ioaddr; 83 void __iomem *ioaddr;
84 int irq; 84 int irq;
85 struct clk *clk; 85 struct clk *clk;
86 unsigned int irqen;
87 int alrm_sec;
88 int alrm_min;
89 int alrm_hour;
90 int alrm_mday;
91 struct timespec mxc_rtc_delta;
92 struct rtc_time g_rtc_alarm; 86 struct rtc_time g_rtc_alarm;
93}; 87};
94 88
diff --git a/drivers/rtc/rtc-nuc900.c b/drivers/rtc/rtc-nuc900.c
index a351bd5d8176..62de66af0a68 100644
--- a/drivers/rtc/rtc-nuc900.c
+++ b/drivers/rtc/rtc-nuc900.c
@@ -85,25 +85,24 @@ static irqreturn_t nuc900_rtc_interrupt(int irq, void *_rtc)
85 85
86static int *check_rtc_access_enable(struct nuc900_rtc *nuc900_rtc) 86static int *check_rtc_access_enable(struct nuc900_rtc *nuc900_rtc)
87{ 87{
88 unsigned int i; 88 unsigned int timeout = 0x1000;
89 __raw_writel(INIRRESET, nuc900_rtc->rtc_reg + REG_RTC_INIR); 89 __raw_writel(INIRRESET, nuc900_rtc->rtc_reg + REG_RTC_INIR);
90 90
91 mdelay(10); 91 mdelay(10);
92 92
93 __raw_writel(AERPOWERON, nuc900_rtc->rtc_reg + REG_RTC_AER); 93 __raw_writel(AERPOWERON, nuc900_rtc->rtc_reg + REG_RTC_AER);
94 94
95 for (i = 0; i < 1000; i++) { 95 while (!(__raw_readl(nuc900_rtc->rtc_reg + REG_RTC_AER) & AERRWENB)
96 if (__raw_readl(nuc900_rtc->rtc_reg + REG_RTC_AER) & AERRWENB) 96 && timeout--)
97 return 0; 97 mdelay(1);
98 }
99 98
100 if ((__raw_readl(nuc900_rtc->rtc_reg + REG_RTC_AER) & AERRWENB) == 0x0) 99 if (!timeout)
101 return ERR_PTR(-ENODEV); 100 return ERR_PTR(-EPERM);
102 101
103 return ERR_PTR(-EPERM); 102 return 0;
104} 103}
105 104
106static void nuc900_rtc_bcd2bin(unsigned int timereg, 105static int nuc900_rtc_bcd2bin(unsigned int timereg,
107 unsigned int calreg, struct rtc_time *tm) 106 unsigned int calreg, struct rtc_time *tm)
108{ 107{
109 tm->tm_mday = bcd2bin(calreg >> 0); 108 tm->tm_mday = bcd2bin(calreg >> 0);
@@ -114,15 +113,21 @@ static void nuc900_rtc_bcd2bin(unsigned int timereg,
114 tm->tm_min = bcd2bin(timereg >> 8); 113 tm->tm_min = bcd2bin(timereg >> 8);
115 tm->tm_hour = bcd2bin(timereg >> 16); 114 tm->tm_hour = bcd2bin(timereg >> 16);
116 115
117 rtc_valid_tm(tm); 116 return rtc_valid_tm(tm);
118} 117}
119 118
120static void nuc900_rtc_bin2bcd(struct rtc_time *settm, 119static void nuc900_rtc_bin2bcd(struct device *dev, struct rtc_time *settm,
121 struct nuc900_bcd_time *gettm) 120 struct nuc900_bcd_time *gettm)
122{ 121{
123 gettm->bcd_mday = bin2bcd(settm->tm_mday) << 0; 122 gettm->bcd_mday = bin2bcd(settm->tm_mday) << 0;
124 gettm->bcd_mon = bin2bcd(settm->tm_mon) << 8; 123 gettm->bcd_mon = bin2bcd(settm->tm_mon) << 8;
125 gettm->bcd_year = bin2bcd(settm->tm_year - 100) << 16; 124
125 if (settm->tm_year < 100) {
126 dev_warn(dev, "The year will be between 1970-1999, right?\n");
127 gettm->bcd_year = bin2bcd(settm->tm_year) << 16;
128 } else {
129 gettm->bcd_year = bin2bcd(settm->tm_year - 100) << 16;
130 }
126 131
127 gettm->bcd_sec = bin2bcd(settm->tm_sec) << 0; 132 gettm->bcd_sec = bin2bcd(settm->tm_sec) << 0;
128 gettm->bcd_min = bin2bcd(settm->tm_min) << 8; 133 gettm->bcd_min = bin2bcd(settm->tm_min) << 8;
@@ -165,9 +170,7 @@ static int nuc900_rtc_read_time(struct device *dev, struct rtc_time *tm)
165 timeval = __raw_readl(rtc->rtc_reg + REG_RTC_TLR); 170 timeval = __raw_readl(rtc->rtc_reg + REG_RTC_TLR);
166 clrval = __raw_readl(rtc->rtc_reg + REG_RTC_CLR); 171 clrval = __raw_readl(rtc->rtc_reg + REG_RTC_CLR);
167 172
168 nuc900_rtc_bcd2bin(timeval, clrval, tm); 173 return nuc900_rtc_bcd2bin(timeval, clrval, tm);
169
170 return 0;
171} 174}
172 175
173static int nuc900_rtc_set_time(struct device *dev, struct rtc_time *tm) 176static int nuc900_rtc_set_time(struct device *dev, struct rtc_time *tm)
@@ -177,7 +180,7 @@ static int nuc900_rtc_set_time(struct device *dev, struct rtc_time *tm)
177 unsigned long val; 180 unsigned long val;
178 int *err; 181 int *err;
179 182
180 nuc900_rtc_bin2bcd(tm, &gettm); 183 nuc900_rtc_bin2bcd(dev, tm, &gettm);
181 184
182 err = check_rtc_access_enable(rtc); 185 err = check_rtc_access_enable(rtc);
183 if (IS_ERR(err)) 186 if (IS_ERR(err))
@@ -200,9 +203,7 @@ static int nuc900_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
200 timeval = __raw_readl(rtc->rtc_reg + REG_RTC_TAR); 203 timeval = __raw_readl(rtc->rtc_reg + REG_RTC_TAR);
201 carval = __raw_readl(rtc->rtc_reg + REG_RTC_CAR); 204 carval = __raw_readl(rtc->rtc_reg + REG_RTC_CAR);
202 205
203 nuc900_rtc_bcd2bin(timeval, carval, &alrm->time); 206 return nuc900_rtc_bcd2bin(timeval, carval, &alrm->time);
204
205 return 0;
206} 207}
207 208
208static int nuc900_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) 209static int nuc900_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
@@ -212,7 +213,7 @@ static int nuc900_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
212 unsigned long val; 213 unsigned long val;
213 int *err; 214 int *err;
214 215
215 nuc900_rtc_bin2bcd(&alrm->time, &tm); 216 nuc900_rtc_bin2bcd(dev, &alrm->time, &tm);
216 217
217 err = check_rtc_access_enable(rtc); 218 err = check_rtc_access_enable(rtc);
218 if (IS_ERR(err)) 219 if (IS_ERR(err))
@@ -268,29 +269,30 @@ static int __devinit nuc900_rtc_probe(struct platform_device *pdev)
268 goto fail2; 269 goto fail2;
269 } 270 }
270 271
271 nuc900_rtc->irq_num = platform_get_irq(pdev, 0); 272 platform_set_drvdata(pdev, nuc900_rtc);
272 if (request_irq(nuc900_rtc->irq_num, nuc900_rtc_interrupt,
273 IRQF_DISABLED, "nuc900rtc", nuc900_rtc)) {
274 dev_err(&pdev->dev, "NUC900 RTC request irq failed\n");
275 err = -EBUSY;
276 goto fail3;
277 }
278 273
279 nuc900_rtc->rtcdev = rtc_device_register(pdev->name, &pdev->dev, 274 nuc900_rtc->rtcdev = rtc_device_register(pdev->name, &pdev->dev,
280 &nuc900_rtc_ops, THIS_MODULE); 275 &nuc900_rtc_ops, THIS_MODULE);
281 if (IS_ERR(nuc900_rtc->rtcdev)) { 276 if (IS_ERR(nuc900_rtc->rtcdev)) {
282 dev_err(&pdev->dev, "rtc device register faild\n"); 277 dev_err(&pdev->dev, "rtc device register faild\n");
283 err = PTR_ERR(nuc900_rtc->rtcdev); 278 err = PTR_ERR(nuc900_rtc->rtcdev);
284 goto fail4; 279 goto fail3;
285 } 280 }
286 281
287 platform_set_drvdata(pdev, nuc900_rtc);
288 __raw_writel(__raw_readl(nuc900_rtc->rtc_reg + REG_RTC_TSSR) | MODE24, 282 __raw_writel(__raw_readl(nuc900_rtc->rtc_reg + REG_RTC_TSSR) | MODE24,
289 nuc900_rtc->rtc_reg + REG_RTC_TSSR); 283 nuc900_rtc->rtc_reg + REG_RTC_TSSR);
290 284
285 nuc900_rtc->irq_num = platform_get_irq(pdev, 0);
286 if (request_irq(nuc900_rtc->irq_num, nuc900_rtc_interrupt,
287 IRQF_DISABLED, "nuc900rtc", nuc900_rtc)) {
288 dev_err(&pdev->dev, "NUC900 RTC request irq failed\n");
289 err = -EBUSY;
290 goto fail4;
291 }
292
291 return 0; 293 return 0;
292 294
293fail4: free_irq(nuc900_rtc->irq_num, nuc900_rtc); 295fail4: rtc_device_unregister(nuc900_rtc->rtcdev);
294fail3: iounmap(nuc900_rtc->rtc_reg); 296fail3: iounmap(nuc900_rtc->rtc_reg);
295fail2: release_mem_region(res->start, resource_size(res)); 297fail2: release_mem_region(res->start, resource_size(res));
296fail1: kfree(nuc900_rtc); 298fail1: kfree(nuc900_rtc);
@@ -302,8 +304,8 @@ static int __devexit nuc900_rtc_remove(struct platform_device *pdev)
302 struct nuc900_rtc *nuc900_rtc = platform_get_drvdata(pdev); 304 struct nuc900_rtc *nuc900_rtc = platform_get_drvdata(pdev);
303 struct resource *res; 305 struct resource *res;
304 306
305 rtc_device_unregister(nuc900_rtc->rtcdev);
306 free_irq(nuc900_rtc->irq_num, nuc900_rtc); 307 free_irq(nuc900_rtc->irq_num, nuc900_rtc);
308 rtc_device_unregister(nuc900_rtc->rtcdev);
307 iounmap(nuc900_rtc->rtc_reg); 309 iounmap(nuc900_rtc->rtc_reg);
308 310
309 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 311 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
diff --git a/drivers/rtc/rtc-pcf8563.c b/drivers/rtc/rtc-pcf8563.c
index 1af42b4a6f59..b42c0c679266 100644
--- a/drivers/rtc/rtc-pcf8563.c
+++ b/drivers/rtc/rtc-pcf8563.c
@@ -172,14 +172,6 @@ static int pcf8563_set_datetime(struct i2c_client *client, struct rtc_time *tm)
172 return 0; 172 return 0;
173} 173}
174 174
175struct pcf8563_limit
176{
177 unsigned char reg;
178 unsigned char mask;
179 unsigned char min;
180 unsigned char max;
181};
182
183static int pcf8563_rtc_read_time(struct device *dev, struct rtc_time *tm) 175static int pcf8563_rtc_read_time(struct device *dev, struct rtc_time *tm)
184{ 176{
185 return pcf8563_get_datetime(to_i2c_client(dev), tm); 177 return pcf8563_get_datetime(to_i2c_client(dev), tm);
diff --git a/drivers/rtc/rtc-pl031.c b/drivers/rtc/rtc-pl031.c
index 71bbefc3544e..6c418fe7f288 100644
--- a/drivers/rtc/rtc-pl031.c
+++ b/drivers/rtc/rtc-pl031.c
@@ -23,7 +23,6 @@
23#include <linux/io.h> 23#include <linux/io.h>
24#include <linux/bcd.h> 24#include <linux/bcd.h>
25#include <linux/delay.h> 25#include <linux/delay.h>
26#include <linux/version.h>
27#include <linux/slab.h> 26#include <linux/slab.h>
28 27
29/* 28/*
diff --git a/drivers/rtc/rtc-pxa.c b/drivers/rtc/rtc-pxa.c
index e9c6fa035989..29e867a1aaa8 100644
--- a/drivers/rtc/rtc-pxa.c
+++ b/drivers/rtc/rtc-pxa.c
@@ -87,7 +87,6 @@ struct pxa_rtc {
87 int irq_Alrm; 87 int irq_Alrm;
88 struct rtc_device *rtc; 88 struct rtc_device *rtc;
89 spinlock_t lock; /* Protects this structure */ 89 spinlock_t lock; /* Protects this structure */
90 struct rtc_time rtc_alarm;
91}; 90};
92 91
93static u32 ryxr_calc(struct rtc_time *tm) 92static u32 ryxr_calc(struct rtc_time *tm)
@@ -236,32 +235,34 @@ static int pxa_periodic_irq_set_state(struct device *dev, int enabled)
236 return 0; 235 return 0;
237} 236}
238 237
239static int pxa_rtc_ioctl(struct device *dev, unsigned int cmd, 238static int pxa_alarm_irq_enable(struct device *dev, unsigned int enabled)
240 unsigned long arg)
241{ 239{
242 struct pxa_rtc *pxa_rtc = dev_get_drvdata(dev); 240 struct pxa_rtc *pxa_rtc = dev_get_drvdata(dev);
243 int ret = 0;
244 241
245 spin_lock_irq(&pxa_rtc->lock); 242 spin_lock_irq(&pxa_rtc->lock);
246 switch (cmd) { 243
247 case RTC_AIE_OFF: 244 if (enabled)
248 rtsr_clear_bits(pxa_rtc, RTSR_RDALE1);
249 break;
250 case RTC_AIE_ON:
251 rtsr_set_bits(pxa_rtc, RTSR_RDALE1); 245 rtsr_set_bits(pxa_rtc, RTSR_RDALE1);
252 break; 246 else
253 case RTC_UIE_OFF: 247 rtsr_clear_bits(pxa_rtc, RTSR_RDALE1);
254 rtsr_clear_bits(pxa_rtc, RTSR_HZE); 248
255 break; 249 spin_unlock_irq(&pxa_rtc->lock);
256 case RTC_UIE_ON: 250 return 0;
251}
252
253static int pxa_update_irq_enable(struct device *dev, unsigned int enabled)
254{
255 struct pxa_rtc *pxa_rtc = dev_get_drvdata(dev);
256
257 spin_lock_irq(&pxa_rtc->lock);
258
259 if (enabled)
257 rtsr_set_bits(pxa_rtc, RTSR_HZE); 260 rtsr_set_bits(pxa_rtc, RTSR_HZE);
258 break; 261 else
259 default: 262 rtsr_clear_bits(pxa_rtc, RTSR_HZE);
260 ret = -ENOIOCTLCMD;
261 }
262 263
263 spin_unlock_irq(&pxa_rtc->lock); 264 spin_unlock_irq(&pxa_rtc->lock);
264 return ret; 265 return 0;
265} 266}
266 267
267static int pxa_rtc_read_time(struct device *dev, struct rtc_time *tm) 268static int pxa_rtc_read_time(struct device *dev, struct rtc_time *tm)
@@ -340,11 +341,12 @@ static int pxa_rtc_proc(struct device *dev, struct seq_file *seq)
340static const struct rtc_class_ops pxa_rtc_ops = { 341static const struct rtc_class_ops pxa_rtc_ops = {
341 .open = pxa_rtc_open, 342 .open = pxa_rtc_open,
342 .release = pxa_rtc_release, 343 .release = pxa_rtc_release,
343 .ioctl = pxa_rtc_ioctl,
344 .read_time = pxa_rtc_read_time, 344 .read_time = pxa_rtc_read_time,
345 .set_time = pxa_rtc_set_time, 345 .set_time = pxa_rtc_set_time,
346 .read_alarm = pxa_rtc_read_alarm, 346 .read_alarm = pxa_rtc_read_alarm,
347 .set_alarm = pxa_rtc_set_alarm, 347 .set_alarm = pxa_rtc_set_alarm,
348 .alarm_irq_enable = pxa_alarm_irq_enable,
349 .update_irq_enable = pxa_update_irq_enable,
348 .proc = pxa_rtc_proc, 350 .proc = pxa_rtc_proc,
349 .irq_set_state = pxa_periodic_irq_set_state, 351 .irq_set_state = pxa_periodic_irq_set_state,
350 .irq_set_freq = pxa_periodic_irq_set_freq, 352 .irq_set_freq = pxa_periodic_irq_set_freq,
diff --git a/drivers/rtc/rtc-rp5c01.c b/drivers/rtc/rtc-rp5c01.c
index a95f733bb15a..36eb66184461 100644
--- a/drivers/rtc/rtc-rp5c01.c
+++ b/drivers/rtc/rtc-rp5c01.c
@@ -63,6 +63,8 @@ enum {
63struct rp5c01_priv { 63struct rp5c01_priv {
64 u32 __iomem *regs; 64 u32 __iomem *regs;
65 struct rtc_device *rtc; 65 struct rtc_device *rtc;
66 spinlock_t lock; /* against concurrent RTC/NVRAM access */
67 struct bin_attribute nvram_attr;
66}; 68};
67 69
68static inline unsigned int rp5c01_read(struct rp5c01_priv *priv, 70static inline unsigned int rp5c01_read(struct rp5c01_priv *priv,
@@ -92,6 +94,7 @@ static int rp5c01_read_time(struct device *dev, struct rtc_time *tm)
92{ 94{
93 struct rp5c01_priv *priv = dev_get_drvdata(dev); 95 struct rp5c01_priv *priv = dev_get_drvdata(dev);
94 96
97 spin_lock_irq(&priv->lock);
95 rp5c01_lock(priv); 98 rp5c01_lock(priv);
96 99
97 tm->tm_sec = rp5c01_read(priv, RP5C01_10_SECOND) * 10 + 100 tm->tm_sec = rp5c01_read(priv, RP5C01_10_SECOND) * 10 +
@@ -111,6 +114,7 @@ static int rp5c01_read_time(struct device *dev, struct rtc_time *tm)
111 tm->tm_year += 100; 114 tm->tm_year += 100;
112 115
113 rp5c01_unlock(priv); 116 rp5c01_unlock(priv);
117 spin_unlock_irq(&priv->lock);
114 118
115 return rtc_valid_tm(tm); 119 return rtc_valid_tm(tm);
116} 120}
@@ -119,6 +123,7 @@ static int rp5c01_set_time(struct device *dev, struct rtc_time *tm)
119{ 123{
120 struct rp5c01_priv *priv = dev_get_drvdata(dev); 124 struct rp5c01_priv *priv = dev_get_drvdata(dev);
121 125
126 spin_lock_irq(&priv->lock);
122 rp5c01_lock(priv); 127 rp5c01_lock(priv);
123 128
124 rp5c01_write(priv, tm->tm_sec / 10, RP5C01_10_SECOND); 129 rp5c01_write(priv, tm->tm_sec / 10, RP5C01_10_SECOND);
@@ -139,6 +144,7 @@ static int rp5c01_set_time(struct device *dev, struct rtc_time *tm)
139 rp5c01_write(priv, tm->tm_year % 10, RP5C01_1_YEAR); 144 rp5c01_write(priv, tm->tm_year % 10, RP5C01_1_YEAR);
140 145
141 rp5c01_unlock(priv); 146 rp5c01_unlock(priv);
147 spin_unlock_irq(&priv->lock);
142 return 0; 148 return 0;
143} 149}
144 150
@@ -147,6 +153,72 @@ static const struct rtc_class_ops rp5c01_rtc_ops = {
147 .set_time = rp5c01_set_time, 153 .set_time = rp5c01_set_time,
148}; 154};
149 155
156
157/*
158 * The NVRAM is organized as 2 blocks of 13 nibbles of 4 bits.
159 * We provide access to them like AmigaOS does: the high nibble of each 8-bit
160 * byte is stored in BLOCK10, the low nibble in BLOCK11.
161 */
162
163static ssize_t rp5c01_nvram_read(struct file *filp, struct kobject *kobj,
164 struct bin_attribute *bin_attr,
165 char *buf, loff_t pos, size_t size)
166{
167 struct device *dev = container_of(kobj, struct device, kobj);
168 struct rp5c01_priv *priv = dev_get_drvdata(dev);
169 ssize_t count;
170
171 spin_lock_irq(&priv->lock);
172
173 for (count = 0; size > 0 && pos < RP5C01_MODE; count++, size--) {
174 u8 data;
175
176 rp5c01_write(priv,
177 RP5C01_MODE_TIMER_EN | RP5C01_MODE_RAM_BLOCK10,
178 RP5C01_MODE);
179 data = rp5c01_read(priv, pos) << 4;
180 rp5c01_write(priv,
181 RP5C01_MODE_TIMER_EN | RP5C01_MODE_RAM_BLOCK11,
182 RP5C01_MODE);
183 data |= rp5c01_read(priv, pos++);
184 rp5c01_write(priv, RP5C01_MODE_TIMER_EN | RP5C01_MODE_MODE01,
185 RP5C01_MODE);
186 *buf++ = data;
187 }
188
189 spin_unlock_irq(&priv->lock);
190 return count;
191}
192
193static ssize_t rp5c01_nvram_write(struct file *filp, struct kobject *kobj,
194 struct bin_attribute *bin_attr,
195 char *buf, loff_t pos, size_t size)
196{
197 struct device *dev = container_of(kobj, struct device, kobj);
198 struct rp5c01_priv *priv = dev_get_drvdata(dev);
199 ssize_t count;
200
201 spin_lock_irq(&priv->lock);
202
203 for (count = 0; size > 0 && pos < RP5C01_MODE; count++, size--) {
204 u8 data = *buf++;
205
206 rp5c01_write(priv,
207 RP5C01_MODE_TIMER_EN | RP5C01_MODE_RAM_BLOCK10,
208 RP5C01_MODE);
209 rp5c01_write(priv, data >> 4, pos);
210 rp5c01_write(priv,
211 RP5C01_MODE_TIMER_EN | RP5C01_MODE_RAM_BLOCK11,
212 RP5C01_MODE);
213 rp5c01_write(priv, data & 0xf, pos++);
214 rp5c01_write(priv, RP5C01_MODE_TIMER_EN | RP5C01_MODE_MODE01,
215 RP5C01_MODE);
216 }
217
218 spin_unlock_irq(&priv->lock);
219 return count;
220}
221
150static int __init rp5c01_rtc_probe(struct platform_device *dev) 222static int __init rp5c01_rtc_probe(struct platform_device *dev)
151{ 223{
152 struct resource *res; 224 struct resource *res;
@@ -168,6 +240,15 @@ static int __init rp5c01_rtc_probe(struct platform_device *dev)
168 goto out_free_priv; 240 goto out_free_priv;
169 } 241 }
170 242
243 sysfs_bin_attr_init(&priv->nvram_attr);
244 priv->nvram_attr.attr.name = "nvram";
245 priv->nvram_attr.attr.mode = S_IRUGO | S_IWUSR;
246 priv->nvram_attr.read = rp5c01_nvram_read;
247 priv->nvram_attr.write = rp5c01_nvram_write;
248 priv->nvram_attr.size = RP5C01_MODE;
249
250 spin_lock_init(&priv->lock);
251
171 rtc = rtc_device_register("rtc-rp5c01", &dev->dev, &rp5c01_rtc_ops, 252 rtc = rtc_device_register("rtc-rp5c01", &dev->dev, &rp5c01_rtc_ops,
172 THIS_MODULE); 253 THIS_MODULE);
173 if (IS_ERR(rtc)) { 254 if (IS_ERR(rtc)) {
@@ -177,8 +258,15 @@ static int __init rp5c01_rtc_probe(struct platform_device *dev)
177 258
178 priv->rtc = rtc; 259 priv->rtc = rtc;
179 platform_set_drvdata(dev, priv); 260 platform_set_drvdata(dev, priv);
261
262 error = sysfs_create_bin_file(&dev->dev.kobj, &priv->nvram_attr);
263 if (error)
264 goto out_unregister;
265
180 return 0; 266 return 0;
181 267
268out_unregister:
269 rtc_device_unregister(rtc);
182out_unmap: 270out_unmap:
183 iounmap(priv->regs); 271 iounmap(priv->regs);
184out_free_priv: 272out_free_priv:
@@ -190,6 +278,7 @@ static int __exit rp5c01_rtc_remove(struct platform_device *dev)
190{ 278{
191 struct rp5c01_priv *priv = platform_get_drvdata(dev); 279 struct rp5c01_priv *priv = platform_get_drvdata(dev);
192 280
281 sysfs_remove_bin_file(&dev->dev.kobj, &priv->nvram_attr);
193 rtc_device_unregister(priv->rtc); 282 rtc_device_unregister(priv->rtc);
194 iounmap(priv->regs); 283 iounmap(priv->regs);
195 kfree(priv); 284 kfree(priv);
diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c
index 70b68d35f969..a0d3ec89d412 100644
--- a/drivers/rtc/rtc-s3c.c
+++ b/drivers/rtc/rtc-s3c.c
@@ -1,5 +1,8 @@
1/* drivers/rtc/rtc-s3c.c 1/* drivers/rtc/rtc-s3c.c
2 * 2 *
3 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com/
5 *
3 * Copyright (c) 2004,2006 Simtec Electronics 6 * Copyright (c) 2004,2006 Simtec Electronics
4 * Ben Dooks, <ben@simtec.co.uk> 7 * Ben Dooks, <ben@simtec.co.uk>
5 * http://armlinux.simtec.co.uk/ 8 * http://armlinux.simtec.co.uk/
@@ -39,6 +42,7 @@ enum s3c_cpu_type {
39 42
40static struct resource *s3c_rtc_mem; 43static struct resource *s3c_rtc_mem;
41 44
45static struct clk *rtc_clk;
42static void __iomem *s3c_rtc_base; 46static void __iomem *s3c_rtc_base;
43static int s3c_rtc_alarmno = NO_IRQ; 47static int s3c_rtc_alarmno = NO_IRQ;
44static int s3c_rtc_tickno = NO_IRQ; 48static int s3c_rtc_tickno = NO_IRQ;
@@ -53,6 +57,10 @@ static irqreturn_t s3c_rtc_alarmirq(int irq, void *id)
53 struct rtc_device *rdev = id; 57 struct rtc_device *rdev = id;
54 58
55 rtc_update_irq(rdev, 1, RTC_AF | RTC_IRQF); 59 rtc_update_irq(rdev, 1, RTC_AF | RTC_IRQF);
60
61 if (s3c_rtc_cpu_type == TYPE_S3C64XX)
62 writeb(S3C2410_INTP_ALM, s3c_rtc_base + S3C2410_INTP);
63
56 return IRQ_HANDLED; 64 return IRQ_HANDLED;
57} 65}
58 66
@@ -61,6 +69,10 @@ static irqreturn_t s3c_rtc_tickirq(int irq, void *id)
61 struct rtc_device *rdev = id; 69 struct rtc_device *rdev = id;
62 70
63 rtc_update_irq(rdev, 1, RTC_PF | RTC_IRQF); 71 rtc_update_irq(rdev, 1, RTC_PF | RTC_IRQF);
72
73 if (s3c_rtc_cpu_type == TYPE_S3C64XX)
74 writeb(S3C2410_INTP_TIC, s3c_rtc_base + S3C2410_INTP);
75
64 return IRQ_HANDLED; 76 return IRQ_HANDLED;
65} 77}
66 78
@@ -94,7 +106,7 @@ static int s3c_rtc_setpie(struct device *dev, int enabled)
94 if (enabled) 106 if (enabled)
95 tmp |= S3C64XX_RTCCON_TICEN; 107 tmp |= S3C64XX_RTCCON_TICEN;
96 108
97 writeb(tmp, s3c_rtc_base + S3C2410_RTCCON); 109 writew(tmp, s3c_rtc_base + S3C2410_RTCCON);
98 } else { 110 } else {
99 tmp = readb(s3c_rtc_base + S3C2410_TICNT); 111 tmp = readb(s3c_rtc_base + S3C2410_TICNT);
100 tmp &= ~S3C2410_TICNT_ENABLE; 112 tmp &= ~S3C2410_TICNT_ENABLE;
@@ -128,7 +140,7 @@ static int s3c_rtc_setfreq(struct device *dev, int freq)
128 140
129 tmp |= (rtc_dev->max_user_freq / freq)-1; 141 tmp |= (rtc_dev->max_user_freq / freq)-1;
130 142
131 writeb(tmp, s3c_rtc_base + S3C2410_TICNT); 143 writel(tmp, s3c_rtc_base + S3C2410_TICNT);
132 spin_unlock_irq(&s3c_rtc_pie_lock); 144 spin_unlock_irq(&s3c_rtc_pie_lock);
133 145
134 return 0; 146 return 0;
@@ -431,6 +443,10 @@ static int __devexit s3c_rtc_remove(struct platform_device *dev)
431 s3c_rtc_setpie(&dev->dev, 0); 443 s3c_rtc_setpie(&dev->dev, 0);
432 s3c_rtc_setaie(0); 444 s3c_rtc_setaie(0);
433 445
446 clk_disable(rtc_clk);
447 clk_put(rtc_clk);
448 rtc_clk = NULL;
449
434 iounmap(s3c_rtc_base); 450 iounmap(s3c_rtc_base);
435 release_resource(s3c_rtc_mem); 451 release_resource(s3c_rtc_mem);
436 kfree(s3c_rtc_mem); 452 kfree(s3c_rtc_mem);
@@ -442,6 +458,7 @@ static int __devinit s3c_rtc_probe(struct platform_device *pdev)
442{ 458{
443 struct rtc_device *rtc; 459 struct rtc_device *rtc;
444 struct resource *res; 460 struct resource *res;
461 unsigned int tmp, i;
445 int ret; 462 int ret;
446 463
447 pr_debug("%s: probe=%p\n", __func__, pdev); 464 pr_debug("%s: probe=%p\n", __func__, pdev);
@@ -488,6 +505,16 @@ static int __devinit s3c_rtc_probe(struct platform_device *pdev)
488 goto err_nomap; 505 goto err_nomap;
489 } 506 }
490 507
508 rtc_clk = clk_get(&pdev->dev, "rtc");
509 if (IS_ERR(rtc_clk)) {
510 dev_err(&pdev->dev, "failed to find rtc clock source\n");
511 ret = PTR_ERR(rtc_clk);
512 rtc_clk = NULL;
513 goto err_clk;
514 }
515
516 clk_enable(rtc_clk);
517
491 /* check to see if everything is setup correctly */ 518 /* check to see if everything is setup correctly */
492 519
493 s3c_rtc_enable(pdev, 1); 520 s3c_rtc_enable(pdev, 1);
@@ -510,6 +537,15 @@ static int __devinit s3c_rtc_probe(struct platform_device *pdev)
510 537
511 s3c_rtc_cpu_type = platform_get_device_id(pdev)->driver_data; 538 s3c_rtc_cpu_type = platform_get_device_id(pdev)->driver_data;
512 539
540 /* Check RTC Time */
541
542 for (i = S3C2410_RTCSEC; i <= S3C2410_RTCYEAR; i += 0x4) {
543 tmp = readb(s3c_rtc_base + i);
544
545 if ((tmp & 0xf) > 0x9 || ((tmp >> 4) & 0xf) > 0x9)
546 writeb(0, s3c_rtc_base + i);
547 }
548
513 if (s3c_rtc_cpu_type == TYPE_S3C64XX) 549 if (s3c_rtc_cpu_type == TYPE_S3C64XX)
514 rtc->max_user_freq = 32768; 550 rtc->max_user_freq = 32768;
515 else 551 else
@@ -523,6 +559,10 @@ static int __devinit s3c_rtc_probe(struct platform_device *pdev)
523 559
524 err_nortc: 560 err_nortc:
525 s3c_rtc_enable(pdev, 0); 561 s3c_rtc_enable(pdev, 0);
562 clk_disable(rtc_clk);
563 clk_put(rtc_clk);
564
565 err_clk:
526 iounmap(s3c_rtc_base); 566 iounmap(s3c_rtc_base);
527 567
528 err_nomap: 568 err_nomap:
diff --git a/drivers/s390/block/dasd.c b/drivers/s390/block/dasd.c
index 33975e922d65..8373ca0de8e0 100644
--- a/drivers/s390/block/dasd.c
+++ b/drivers/s390/block/dasd.c
@@ -21,6 +21,7 @@
21#include <linux/hdreg.h> 21#include <linux/hdreg.h>
22#include <linux/async.h> 22#include <linux/async.h>
23#include <linux/mutex.h> 23#include <linux/mutex.h>
24#include <linux/smp_lock.h>
24 25
25#include <asm/ccwdev.h> 26#include <asm/ccwdev.h>
26#include <asm/ebcdic.h> 27#include <asm/ebcdic.h>
@@ -1324,14 +1325,14 @@ static void __dasd_device_check_expire(struct dasd_device *device)
1324 if (device->discipline->term_IO(cqr) != 0) { 1325 if (device->discipline->term_IO(cqr) != 0) {
1325 /* Hmpf, try again in 5 sec */ 1326 /* Hmpf, try again in 5 sec */
1326 dev_err(&device->cdev->dev, 1327 dev_err(&device->cdev->dev,
1327 "cqr %p timed out (%is) but cannot be " 1328 "cqr %p timed out (%lus) but cannot be "
1328 "ended, retrying in 5 s\n", 1329 "ended, retrying in 5 s\n",
1329 cqr, (cqr->expires/HZ)); 1330 cqr, (cqr->expires/HZ));
1330 cqr->expires += 5*HZ; 1331 cqr->expires += 5*HZ;
1331 dasd_device_set_timer(device, 5*HZ); 1332 dasd_device_set_timer(device, 5*HZ);
1332 } else { 1333 } else {
1333 dev_err(&device->cdev->dev, 1334 dev_err(&device->cdev->dev,
1334 "cqr %p timed out (%is), %i retries " 1335 "cqr %p timed out (%lus), %i retries "
1335 "remaining\n", cqr, (cqr->expires/HZ), 1336 "remaining\n", cqr, (cqr->expires/HZ),
1336 cqr->retries); 1337 cqr->retries);
1337 } 1338 }
@@ -2196,7 +2197,7 @@ static void dasd_setup_queue(struct dasd_block *block)
2196 */ 2197 */
2197 blk_queue_max_segment_size(block->request_queue, PAGE_SIZE); 2198 blk_queue_max_segment_size(block->request_queue, PAGE_SIZE);
2198 blk_queue_segment_boundary(block->request_queue, PAGE_SIZE - 1); 2199 blk_queue_segment_boundary(block->request_queue, PAGE_SIZE - 1);
2199 blk_queue_ordered(block->request_queue, QUEUE_ORDERED_DRAIN, NULL); 2200 blk_queue_ordered(block->request_queue, QUEUE_ORDERED_DRAIN);
2200} 2201}
2201 2202
2202/* 2203/*
@@ -2235,6 +2236,7 @@ static int dasd_open(struct block_device *bdev, fmode_t mode)
2235 if (!block) 2236 if (!block)
2236 return -ENODEV; 2237 return -ENODEV;
2237 2238
2239 lock_kernel();
2238 base = block->base; 2240 base = block->base;
2239 atomic_inc(&block->open_count); 2241 atomic_inc(&block->open_count);
2240 if (test_bit(DASD_FLAG_OFFLINE, &base->flags)) { 2242 if (test_bit(DASD_FLAG_OFFLINE, &base->flags)) {
@@ -2269,12 +2271,14 @@ static int dasd_open(struct block_device *bdev, fmode_t mode)
2269 goto out; 2271 goto out;
2270 } 2272 }
2271 2273
2274 unlock_kernel();
2272 return 0; 2275 return 0;
2273 2276
2274out: 2277out:
2275 module_put(base->discipline->owner); 2278 module_put(base->discipline->owner);
2276unlock: 2279unlock:
2277 atomic_dec(&block->open_count); 2280 atomic_dec(&block->open_count);
2281 unlock_kernel();
2278 return rc; 2282 return rc;
2279} 2283}
2280 2284
@@ -2282,8 +2286,10 @@ static int dasd_release(struct gendisk *disk, fmode_t mode)
2282{ 2286{
2283 struct dasd_block *block = disk->private_data; 2287 struct dasd_block *block = disk->private_data;
2284 2288
2289 lock_kernel();
2285 atomic_dec(&block->open_count); 2290 atomic_dec(&block->open_count);
2286 module_put(block->base->discipline->owner); 2291 module_put(block->base->discipline->owner);
2292 unlock_kernel();
2287 return 0; 2293 return 0;
2288} 2294}
2289 2295
diff --git a/drivers/s390/block/dasd_devmap.c b/drivers/s390/block/dasd_devmap.c
index bed7b4634ccd..8d41f3ed38d7 100644
--- a/drivers/s390/block/dasd_devmap.c
+++ b/drivers/s390/block/dasd_devmap.c
@@ -1083,6 +1083,49 @@ dasd_eer_store(struct device *dev, struct device_attribute *attr,
1083 1083
1084static DEVICE_ATTR(eer_enabled, 0644, dasd_eer_show, dasd_eer_store); 1084static DEVICE_ATTR(eer_enabled, 0644, dasd_eer_show, dasd_eer_store);
1085 1085
1086/*
1087 * expiration time for default requests
1088 */
1089static ssize_t
1090dasd_expires_show(struct device *dev, struct device_attribute *attr, char *buf)
1091{
1092 struct dasd_device *device;
1093 int len;
1094
1095 device = dasd_device_from_cdev(to_ccwdev(dev));
1096 if (IS_ERR(device))
1097 return -ENODEV;
1098 len = snprintf(buf, PAGE_SIZE, "%lu\n", device->default_expires);
1099 dasd_put_device(device);
1100 return len;
1101}
1102
1103static ssize_t
1104dasd_expires_store(struct device *dev, struct device_attribute *attr,
1105 const char *buf, size_t count)
1106{
1107 struct dasd_device *device;
1108 unsigned long val;
1109
1110 device = dasd_device_from_cdev(to_ccwdev(dev));
1111 if (IS_ERR(device))
1112 return -ENODEV;
1113
1114 if ((strict_strtoul(buf, 10, &val) != 0) ||
1115 (val > DASD_EXPIRES_MAX) || val == 0) {
1116 dasd_put_device(device);
1117 return -EINVAL;
1118 }
1119
1120 if (val)
1121 device->default_expires = val;
1122
1123 dasd_put_device(device);
1124 return count;
1125}
1126
1127static DEVICE_ATTR(expires, 0644, dasd_expires_show, dasd_expires_store);
1128
1086static struct attribute * dasd_attrs[] = { 1129static struct attribute * dasd_attrs[] = {
1087 &dev_attr_readonly.attr, 1130 &dev_attr_readonly.attr,
1088 &dev_attr_discipline.attr, 1131 &dev_attr_discipline.attr,
@@ -1094,6 +1137,7 @@ static struct attribute * dasd_attrs[] = {
1094 &dev_attr_eer_enabled.attr, 1137 &dev_attr_eer_enabled.attr,
1095 &dev_attr_erplog.attr, 1138 &dev_attr_erplog.attr,
1096 &dev_attr_failfast.attr, 1139 &dev_attr_failfast.attr,
1140 &dev_attr_expires.attr,
1097 NULL, 1141 NULL,
1098}; 1142};
1099 1143
diff --git a/drivers/s390/block/dasd_diag.c b/drivers/s390/block/dasd_diag.c
index 687f323cdc38..2b3bc3ec0541 100644
--- a/drivers/s390/block/dasd_diag.c
+++ b/drivers/s390/block/dasd_diag.c
@@ -43,7 +43,7 @@ MODULE_LICENSE("GPL");
43 sizeof(struct dasd_diag_req)) / \ 43 sizeof(struct dasd_diag_req)) / \
44 sizeof(struct dasd_diag_bio)) / 2) 44 sizeof(struct dasd_diag_bio)) / 2)
45#define DIAG_MAX_RETRIES 32 45#define DIAG_MAX_RETRIES 32
46#define DIAG_TIMEOUT 50 * HZ 46#define DIAG_TIMEOUT 50
47 47
48static struct dasd_discipline dasd_diag_discipline; 48static struct dasd_discipline dasd_diag_discipline;
49 49
@@ -360,6 +360,8 @@ dasd_diag_check_device(struct dasd_device *device)
360 goto out; 360 goto out;
361 } 361 }
362 362
363 device->default_expires = DIAG_TIMEOUT;
364
363 /* Figure out position of label block */ 365 /* Figure out position of label block */
364 switch (private->rdc_data.vdev_class) { 366 switch (private->rdc_data.vdev_class) {
365 case DEV_CLASS_FBA: 367 case DEV_CLASS_FBA:
@@ -563,7 +565,7 @@ static struct dasd_ccw_req *dasd_diag_build_cp(struct dasd_device *memdev,
563 cqr->startdev = memdev; 565 cqr->startdev = memdev;
564 cqr->memdev = memdev; 566 cqr->memdev = memdev;
565 cqr->block = block; 567 cqr->block = block;
566 cqr->expires = DIAG_TIMEOUT; 568 cqr->expires = memdev->default_expires * HZ;
567 cqr->status = DASD_CQR_FILLED; 569 cqr->status = DASD_CQR_FILLED;
568 return cqr; 570 return cqr;
569} 571}
diff --git a/drivers/s390/block/dasd_eckd.c b/drivers/s390/block/dasd_eckd.c
index ab84da5592e8..66360c24bd48 100644
--- a/drivers/s390/block/dasd_eckd.c
+++ b/drivers/s390/block/dasd_eckd.c
@@ -82,6 +82,14 @@ static struct ccw_driver dasd_eckd_driver; /* see below */
82#define INIT_CQR_UNFORMATTED 1 82#define INIT_CQR_UNFORMATTED 1
83#define INIT_CQR_ERROR 2 83#define INIT_CQR_ERROR 2
84 84
85/* emergency request for reserve/release */
86static struct {
87 struct dasd_ccw_req cqr;
88 struct ccw1 ccw;
89 char data[32];
90} *dasd_reserve_req;
91static DEFINE_MUTEX(dasd_reserve_mutex);
92
85 93
86/* initial attempt at a probe function. this can be simplified once 94/* initial attempt at a probe function. this can be simplified once
87 * the other detection code is gone */ 95 * the other detection code is gone */
@@ -1107,8 +1115,9 @@ dasd_eckd_check_characteristics(struct dasd_device *device)
1107 struct dasd_eckd_private *private; 1115 struct dasd_eckd_private *private;
1108 struct dasd_block *block; 1116 struct dasd_block *block;
1109 struct dasd_uid temp_uid; 1117 struct dasd_uid temp_uid;
1110 int is_known, rc; 1118 int is_known, rc, i;
1111 int readonly; 1119 int readonly;
1120 unsigned long value;
1112 1121
1113 if (!ccw_device_is_pathgroup(device->cdev)) { 1122 if (!ccw_device_is_pathgroup(device->cdev)) {
1114 dev_warn(&device->cdev->dev, 1123 dev_warn(&device->cdev->dev,
@@ -1143,6 +1152,18 @@ dasd_eckd_check_characteristics(struct dasd_device *device)
1143 if (rc) 1152 if (rc)
1144 goto out_err1; 1153 goto out_err1;
1145 1154
1155 /* set default timeout */
1156 device->default_expires = DASD_EXPIRES;
1157 if (private->gneq) {
1158 value = 1;
1159 for (i = 0; i < private->gneq->timeout.value; i++)
1160 value = 10 * value;
1161 value = value * private->gneq->timeout.number;
1162 /* do not accept useless values */
1163 if (value != 0 && value <= DASD_EXPIRES_MAX)
1164 device->default_expires = value;
1165 }
1166
1146 /* Generate device unique id */ 1167 /* Generate device unique id */
1147 rc = dasd_eckd_generate_uid(device); 1168 rc = dasd_eckd_generate_uid(device);
1148 if (rc) 1169 if (rc)
@@ -1973,7 +1994,7 @@ static struct dasd_ccw_req *dasd_eckd_build_cp_cmd_single(
1973 cqr->startdev = startdev; 1994 cqr->startdev = startdev;
1974 cqr->memdev = startdev; 1995 cqr->memdev = startdev;
1975 cqr->block = block; 1996 cqr->block = block;
1976 cqr->expires = 5 * 60 * HZ; /* 5 minutes */ 1997 cqr->expires = startdev->default_expires * HZ; /* default 5 minutes */
1977 cqr->lpm = private->path_data.ppm; 1998 cqr->lpm = private->path_data.ppm;
1978 cqr->retries = 256; 1999 cqr->retries = 256;
1979 cqr->buildclk = get_clock(); 2000 cqr->buildclk = get_clock();
@@ -2150,7 +2171,7 @@ static struct dasd_ccw_req *dasd_eckd_build_cp_cmd_track(
2150 cqr->startdev = startdev; 2171 cqr->startdev = startdev;
2151 cqr->memdev = startdev; 2172 cqr->memdev = startdev;
2152 cqr->block = block; 2173 cqr->block = block;
2153 cqr->expires = 5 * 60 * HZ; /* 5 minutes */ 2174 cqr->expires = startdev->default_expires * HZ; /* default 5 minutes */
2154 cqr->lpm = private->path_data.ppm; 2175 cqr->lpm = private->path_data.ppm;
2155 cqr->retries = 256; 2176 cqr->retries = 256;
2156 cqr->buildclk = get_clock(); 2177 cqr->buildclk = get_clock();
@@ -2398,7 +2419,7 @@ static struct dasd_ccw_req *dasd_eckd_build_cp_tpm_track(
2398 cqr->startdev = startdev; 2419 cqr->startdev = startdev;
2399 cqr->memdev = startdev; 2420 cqr->memdev = startdev;
2400 cqr->block = block; 2421 cqr->block = block;
2401 cqr->expires = 5 * 60 * HZ; /* 5 minutes */ 2422 cqr->expires = startdev->default_expires * HZ; /* default 5 minutes */
2402 cqr->lpm = private->path_data.ppm; 2423 cqr->lpm = private->path_data.ppm;
2403 cqr->retries = 256; 2424 cqr->retries = 256;
2404 cqr->buildclk = get_clock(); 2425 cqr->buildclk = get_clock();
@@ -2645,15 +2666,23 @@ dasd_eckd_release(struct dasd_device *device)
2645 struct dasd_ccw_req *cqr; 2666 struct dasd_ccw_req *cqr;
2646 int rc; 2667 int rc;
2647 struct ccw1 *ccw; 2668 struct ccw1 *ccw;
2669 int useglobal;
2648 2670
2649 if (!capable(CAP_SYS_ADMIN)) 2671 if (!capable(CAP_SYS_ADMIN))
2650 return -EACCES; 2672 return -EACCES;
2651 2673
2674 useglobal = 0;
2652 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device); 2675 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device);
2653 if (IS_ERR(cqr)) { 2676 if (IS_ERR(cqr)) {
2654 DBF_DEV_EVENT(DBF_WARNING, device, "%s", 2677 mutex_lock(&dasd_reserve_mutex);
2655 "Could not allocate initialization request"); 2678 useglobal = 1;
2656 return PTR_ERR(cqr); 2679 cqr = &dasd_reserve_req->cqr;
2680 memset(cqr, 0, sizeof(*cqr));
2681 memset(&dasd_reserve_req->ccw, 0,
2682 sizeof(dasd_reserve_req->ccw));
2683 cqr->cpaddr = &dasd_reserve_req->ccw;
2684 cqr->data = &dasd_reserve_req->data;
2685 cqr->magic = DASD_ECKD_MAGIC;
2657 } 2686 }
2658 ccw = cqr->cpaddr; 2687 ccw = cqr->cpaddr;
2659 ccw->cmd_code = DASD_ECKD_CCW_RELEASE; 2688 ccw->cmd_code = DASD_ECKD_CCW_RELEASE;
@@ -2671,7 +2700,10 @@ dasd_eckd_release(struct dasd_device *device)
2671 2700
2672 rc = dasd_sleep_on_immediatly(cqr); 2701 rc = dasd_sleep_on_immediatly(cqr);
2673 2702
2674 dasd_sfree_request(cqr, cqr->memdev); 2703 if (useglobal)
2704 mutex_unlock(&dasd_reserve_mutex);
2705 else
2706 dasd_sfree_request(cqr, cqr->memdev);
2675 return rc; 2707 return rc;
2676} 2708}
2677 2709
@@ -2687,15 +2719,23 @@ dasd_eckd_reserve(struct dasd_device *device)
2687 struct dasd_ccw_req *cqr; 2719 struct dasd_ccw_req *cqr;
2688 int rc; 2720 int rc;
2689 struct ccw1 *ccw; 2721 struct ccw1 *ccw;
2722 int useglobal;
2690 2723
2691 if (!capable(CAP_SYS_ADMIN)) 2724 if (!capable(CAP_SYS_ADMIN))
2692 return -EACCES; 2725 return -EACCES;
2693 2726
2727 useglobal = 0;
2694 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device); 2728 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device);
2695 if (IS_ERR(cqr)) { 2729 if (IS_ERR(cqr)) {
2696 DBF_DEV_EVENT(DBF_WARNING, device, "%s", 2730 mutex_lock(&dasd_reserve_mutex);
2697 "Could not allocate initialization request"); 2731 useglobal = 1;
2698 return PTR_ERR(cqr); 2732 cqr = &dasd_reserve_req->cqr;
2733 memset(cqr, 0, sizeof(*cqr));
2734 memset(&dasd_reserve_req->ccw, 0,
2735 sizeof(dasd_reserve_req->ccw));
2736 cqr->cpaddr = &dasd_reserve_req->ccw;
2737 cqr->data = &dasd_reserve_req->data;
2738 cqr->magic = DASD_ECKD_MAGIC;
2699 } 2739 }
2700 ccw = cqr->cpaddr; 2740 ccw = cqr->cpaddr;
2701 ccw->cmd_code = DASD_ECKD_CCW_RESERVE; 2741 ccw->cmd_code = DASD_ECKD_CCW_RESERVE;
@@ -2713,7 +2753,10 @@ dasd_eckd_reserve(struct dasd_device *device)
2713 2753
2714 rc = dasd_sleep_on_immediatly(cqr); 2754 rc = dasd_sleep_on_immediatly(cqr);
2715 2755
2716 dasd_sfree_request(cqr, cqr->memdev); 2756 if (useglobal)
2757 mutex_unlock(&dasd_reserve_mutex);
2758 else
2759 dasd_sfree_request(cqr, cqr->memdev);
2717 return rc; 2760 return rc;
2718} 2761}
2719 2762
@@ -2728,15 +2771,23 @@ dasd_eckd_steal_lock(struct dasd_device *device)
2728 struct dasd_ccw_req *cqr; 2771 struct dasd_ccw_req *cqr;
2729 int rc; 2772 int rc;
2730 struct ccw1 *ccw; 2773 struct ccw1 *ccw;
2774 int useglobal;
2731 2775
2732 if (!capable(CAP_SYS_ADMIN)) 2776 if (!capable(CAP_SYS_ADMIN))
2733 return -EACCES; 2777 return -EACCES;
2734 2778
2779 useglobal = 0;
2735 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device); 2780 cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device);
2736 if (IS_ERR(cqr)) { 2781 if (IS_ERR(cqr)) {
2737 DBF_DEV_EVENT(DBF_WARNING, device, "%s", 2782 mutex_lock(&dasd_reserve_mutex);
2738 "Could not allocate initialization request"); 2783 useglobal = 1;
2739 return PTR_ERR(cqr); 2784 cqr = &dasd_reserve_req->cqr;
2785 memset(cqr, 0, sizeof(*cqr));
2786 memset(&dasd_reserve_req->ccw, 0,
2787 sizeof(dasd_reserve_req->ccw));
2788 cqr->cpaddr = &dasd_reserve_req->ccw;
2789 cqr->data = &dasd_reserve_req->data;
2790 cqr->magic = DASD_ECKD_MAGIC;
2740 } 2791 }
2741 ccw = cqr->cpaddr; 2792 ccw = cqr->cpaddr;
2742 ccw->cmd_code = DASD_ECKD_CCW_SLCK; 2793 ccw->cmd_code = DASD_ECKD_CCW_SLCK;
@@ -2754,7 +2805,10 @@ dasd_eckd_steal_lock(struct dasd_device *device)
2754 2805
2755 rc = dasd_sleep_on_immediatly(cqr); 2806 rc = dasd_sleep_on_immediatly(cqr);
2756 2807
2757 dasd_sfree_request(cqr, cqr->memdev); 2808 if (useglobal)
2809 mutex_unlock(&dasd_reserve_mutex);
2810 else
2811 dasd_sfree_request(cqr, cqr->memdev);
2758 return rc; 2812 return rc;
2759} 2813}
2760 2814
@@ -3488,10 +3542,15 @@ dasd_eckd_init(void)
3488 int ret; 3542 int ret;
3489 3543
3490 ASCEBC(dasd_eckd_discipline.ebcname, 4); 3544 ASCEBC(dasd_eckd_discipline.ebcname, 4);
3545 dasd_reserve_req = kmalloc(sizeof(*dasd_reserve_req),
3546 GFP_KERNEL | GFP_DMA);
3547 if (!dasd_reserve_req)
3548 return -ENOMEM;
3491 ret = ccw_driver_register(&dasd_eckd_driver); 3549 ret = ccw_driver_register(&dasd_eckd_driver);
3492 if (!ret) 3550 if (!ret)
3493 wait_for_device_probe(); 3551 wait_for_device_probe();
3494 3552 else
3553 kfree(dasd_reserve_req);
3495 return ret; 3554 return ret;
3496} 3555}
3497 3556
@@ -3499,6 +3558,7 @@ static void __exit
3499dasd_eckd_cleanup(void) 3558dasd_eckd_cleanup(void)
3500{ 3559{
3501 ccw_driver_unregister(&dasd_eckd_driver); 3560 ccw_driver_unregister(&dasd_eckd_driver);
3561 kfree(dasd_reserve_req);
3502} 3562}
3503 3563
3504module_init(dasd_eckd_init); 3564module_init(dasd_eckd_init);
diff --git a/drivers/s390/block/dasd_eckd.h b/drivers/s390/block/dasd_eckd.h
index dd6385a5af14..0eb49655a6cd 100644
--- a/drivers/s390/block/dasd_eckd.h
+++ b/drivers/s390/block/dasd_eckd.h
@@ -320,7 +320,12 @@ struct dasd_gneq {
320 __u8 identifier:2; 320 __u8 identifier:2;
321 __u8 reserved:6; 321 __u8 reserved:6;
322 } __attribute__ ((packed)) flags; 322 } __attribute__ ((packed)) flags;
323 __u8 reserved[7]; 323 __u8 reserved[5];
324 struct {
325 __u8 value:2;
326 __u8 number:6;
327 } __attribute__ ((packed)) timeout;
328 __u8 reserved3;
324 __u16 subsystemID; 329 __u16 subsystemID;
325 __u8 reserved2[22]; 330 __u8 reserved2[22];
326} __attribute__ ((packed)); 331} __attribute__ ((packed));
diff --git a/drivers/s390/block/dasd_eer.c b/drivers/s390/block/dasd_eer.c
index dd88803e4899..7158f9528ecc 100644
--- a/drivers/s390/block/dasd_eer.c
+++ b/drivers/s390/block/dasd_eer.c
@@ -701,7 +701,7 @@ int __init dasd_eer_init(void)
701void dasd_eer_exit(void) 701void dasd_eer_exit(void)
702{ 702{
703 if (dasd_eer_dev) { 703 if (dasd_eer_dev) {
704 WARN_ON(misc_deregister(dasd_eer_dev) != 0); 704 misc_deregister(dasd_eer_dev);
705 kfree(dasd_eer_dev); 705 kfree(dasd_eer_dev);
706 dasd_eer_dev = NULL; 706 dasd_eer_dev = NULL;
707 } 707 }
diff --git a/drivers/s390/block/dasd_fba.c b/drivers/s390/block/dasd_fba.c
index 37282b90eecc..bec5486e0e6d 100644
--- a/drivers/s390/block/dasd_fba.c
+++ b/drivers/s390/block/dasd_fba.c
@@ -163,6 +163,8 @@ dasd_fba_check_characteristics(struct dasd_device *device)
163 return rc; 163 return rc;
164 } 164 }
165 165
166 device->default_expires = DASD_EXPIRES;
167
166 readonly = dasd_device_is_ro(device); 168 readonly = dasd_device_is_ro(device);
167 if (readonly) 169 if (readonly)
168 set_bit(DASD_FLAG_DEVICE_RO, &device->flags); 170 set_bit(DASD_FLAG_DEVICE_RO, &device->flags);
@@ -370,7 +372,7 @@ static struct dasd_ccw_req *dasd_fba_build_cp(struct dasd_device * memdev,
370 cqr->startdev = memdev; 372 cqr->startdev = memdev;
371 cqr->memdev = memdev; 373 cqr->memdev = memdev;
372 cqr->block = block; 374 cqr->block = block;
373 cqr->expires = 5 * 60 * HZ; /* 5 minutes */ 375 cqr->expires = memdev->default_expires * HZ; /* default 5 minutes */
374 cqr->retries = 32; 376 cqr->retries = 32;
375 cqr->buildclk = get_clock(); 377 cqr->buildclk = get_clock();
376 cqr->status = DASD_CQR_FILLED; 378 cqr->status = DASD_CQR_FILLED;
diff --git a/drivers/s390/block/dasd_int.h b/drivers/s390/block/dasd_int.h
index 49b431d135e0..500678d7116c 100644
--- a/drivers/s390/block/dasd_int.h
+++ b/drivers/s390/block/dasd_int.h
@@ -186,7 +186,7 @@ struct dasd_ccw_req {
186 186
187 /* ... and how */ 187 /* ... and how */
188 unsigned long starttime; /* jiffies time of request start */ 188 unsigned long starttime; /* jiffies time of request start */
189 int expires; /* expiration period in jiffies */ 189 unsigned long expires; /* expiration period in jiffies */
190 char lpm; /* logical path mask */ 190 char lpm; /* logical path mask */
191 void *data; /* pointer to data area */ 191 void *data; /* pointer to data area */
192 192
@@ -224,6 +224,9 @@ struct dasd_ccw_req {
224#define DASD_CQR_CLEARED 0x84 /* request was cleared */ 224#define DASD_CQR_CLEARED 0x84 /* request was cleared */
225#define DASD_CQR_SUCCESS 0x85 /* request was successful */ 225#define DASD_CQR_SUCCESS 0x85 /* request was successful */
226 226
227/* default expiration time*/
228#define DASD_EXPIRES 300
229#define DASD_EXPIRES_MAX 40000000
227 230
228/* per dasd_ccw_req flags */ 231/* per dasd_ccw_req flags */
229#define DASD_CQR_FLAGS_USE_ERP 0 /* use ERP for this request */ 232#define DASD_CQR_FLAGS_USE_ERP 0 /* use ERP for this request */
@@ -404,6 +407,9 @@ struct dasd_device {
404 407
405 /* hook for alias management */ 408 /* hook for alias management */
406 struct list_head alias_list; 409 struct list_head alias_list;
410
411 /* default expiration time in s */
412 unsigned long default_expires;
407}; 413};
408 414
409struct dasd_block { 415struct dasd_block {
diff --git a/drivers/s390/block/dcssblk.c b/drivers/s390/block/dcssblk.c
index 9b43ae94beba..2bd72aa34c59 100644
--- a/drivers/s390/block/dcssblk.c
+++ b/drivers/s390/block/dcssblk.c
@@ -14,6 +14,7 @@
14#include <linux/init.h> 14#include <linux/init.h>
15#include <linux/slab.h> 15#include <linux/slab.h>
16#include <linux/blkdev.h> 16#include <linux/blkdev.h>
17#include <linux/smp_lock.h>
17#include <linux/completion.h> 18#include <linux/completion.h>
18#include <linux/interrupt.h> 19#include <linux/interrupt.h>
19#include <linux/platform_device.h> 20#include <linux/platform_device.h>
@@ -775,6 +776,7 @@ dcssblk_open(struct block_device *bdev, fmode_t mode)
775 struct dcssblk_dev_info *dev_info; 776 struct dcssblk_dev_info *dev_info;
776 int rc; 777 int rc;
777 778
779 lock_kernel();
778 dev_info = bdev->bd_disk->private_data; 780 dev_info = bdev->bd_disk->private_data;
779 if (NULL == dev_info) { 781 if (NULL == dev_info) {
780 rc = -ENODEV; 782 rc = -ENODEV;
@@ -784,6 +786,7 @@ dcssblk_open(struct block_device *bdev, fmode_t mode)
784 bdev->bd_block_size = 4096; 786 bdev->bd_block_size = 4096;
785 rc = 0; 787 rc = 0;
786out: 788out:
789 unlock_kernel();
787 return rc; 790 return rc;
788} 791}
789 792
@@ -794,6 +797,7 @@ dcssblk_release(struct gendisk *disk, fmode_t mode)
794 struct segment_info *entry; 797 struct segment_info *entry;
795 int rc; 798 int rc;
796 799
800 lock_kernel();
797 if (!dev_info) { 801 if (!dev_info) {
798 rc = -ENODEV; 802 rc = -ENODEV;
799 goto out; 803 goto out;
@@ -811,6 +815,7 @@ dcssblk_release(struct gendisk *disk, fmode_t mode)
811 up_write(&dcssblk_devices_sem); 815 up_write(&dcssblk_devices_sem);
812 rc = 0; 816 rc = 0;
813out: 817out:
818 unlock_kernel();
814 return rc; 819 return rc;
815} 820}
816 821
diff --git a/drivers/s390/char/monreader.c b/drivers/s390/char/monreader.c
index 2ed3f82e5c30..e021ec663ef9 100644
--- a/drivers/s390/char/monreader.c
+++ b/drivers/s390/char/monreader.c
@@ -627,7 +627,7 @@ out_iucv:
627static void __exit mon_exit(void) 627static void __exit mon_exit(void)
628{ 628{
629 segment_unload(mon_dcss_name); 629 segment_unload(mon_dcss_name);
630 WARN_ON(misc_deregister(&mon_dev) != 0); 630 misc_deregister(&mon_dev);
631 device_unregister(monreader_device); 631 device_unregister(monreader_device);
632 driver_unregister(&monreader_driver); 632 driver_unregister(&monreader_driver);
633 iucv_unregister(&monreader_iucv_handler, 1); 633 iucv_unregister(&monreader_iucv_handler, 1);
diff --git a/drivers/s390/char/monwriter.c b/drivers/s390/char/monwriter.c
index 98a49dfda1de..572a1e7fd099 100644
--- a/drivers/s390/char/monwriter.c
+++ b/drivers/s390/char/monwriter.c
@@ -380,7 +380,7 @@ out_driver:
380 380
381static void __exit mon_exit(void) 381static void __exit mon_exit(void)
382{ 382{
383 WARN_ON(misc_deregister(&mon_dev) != 0); 383 misc_deregister(&mon_dev);
384 platform_device_unregister(monwriter_pdev); 384 platform_device_unregister(monwriter_pdev);
385 platform_driver_unregister(&monwriter_pdrv); 385 platform_driver_unregister(&monwriter_pdrv);
386} 386}
diff --git a/drivers/s390/char/tape_block.c b/drivers/s390/char/tape_block.c
index 097da8ce6be6..b7de02525ec9 100644
--- a/drivers/s390/char/tape_block.c
+++ b/drivers/s390/char/tape_block.c
@@ -16,6 +16,7 @@
16#include <linux/fs.h> 16#include <linux/fs.h>
17#include <linux/module.h> 17#include <linux/module.h>
18#include <linux/blkdev.h> 18#include <linux/blkdev.h>
19#include <linux/smp_lock.h>
19#include <linux/interrupt.h> 20#include <linux/interrupt.h>
20#include <linux/buffer_head.h> 21#include <linux/buffer_head.h>
21#include <linux/kernel.h> 22#include <linux/kernel.h>
@@ -361,6 +362,7 @@ tapeblock_open(struct block_device *bdev, fmode_t mode)
361 struct tape_device * device; 362 struct tape_device * device;
362 int rc; 363 int rc;
363 364
365 lock_kernel();
364 device = tape_get_device(disk->private_data); 366 device = tape_get_device(disk->private_data);
365 367
366 if (device->required_tapemarks) { 368 if (device->required_tapemarks) {
@@ -384,12 +386,14 @@ tapeblock_open(struct block_device *bdev, fmode_t mode)
384 * is called. 386 * is called.
385 */ 387 */
386 tape_state_set(device, TS_BLKUSE); 388 tape_state_set(device, TS_BLKUSE);
389 unlock_kernel();
387 return 0; 390 return 0;
388 391
389release: 392release:
390 tape_release(device); 393 tape_release(device);
391 put_device: 394 put_device:
392 tape_put_device(device); 395 tape_put_device(device);
396 unlock_kernel();
393 return rc; 397 return rc;
394} 398}
395 399
@@ -403,10 +407,12 @@ static int
403tapeblock_release(struct gendisk *disk, fmode_t mode) 407tapeblock_release(struct gendisk *disk, fmode_t mode)
404{ 408{
405 struct tape_device *device = disk->private_data; 409 struct tape_device *device = disk->private_data;
406 410
411 lock_kernel();
407 tape_state_set(device, TS_IN_USE); 412 tape_state_set(device, TS_IN_USE);
408 tape_release(device); 413 tape_release(device);
409 tape_put_device(device); 414 tape_put_device(device);
415 unlock_kernel();
410 416
411 return 0; 417 return 0;
412} 418}
diff --git a/drivers/s390/cio/ccwreq.c b/drivers/s390/cio/ccwreq.c
index 7f206ed44fdf..d15f8b4d78bd 100644
--- a/drivers/s390/cio/ccwreq.c
+++ b/drivers/s390/cio/ccwreq.c
@@ -38,9 +38,13 @@ static u16 ccwreq_next_path(struct ccw_device *cdev)
38{ 38{
39 struct ccw_request *req = &cdev->private->req; 39 struct ccw_request *req = &cdev->private->req;
40 40
41 if (!req->singlepath) {
42 req->mask = 0;
43 goto out;
44 }
41 req->retries = req->maxretries; 45 req->retries = req->maxretries;
42 req->mask = lpm_adjust(req->mask >>= 1, req->lpm); 46 req->mask = lpm_adjust(req->mask >>= 1, req->lpm);
43 47out:
44 return req->mask; 48 return req->mask;
45} 49}
46 50
@@ -113,8 +117,12 @@ void ccw_request_start(struct ccw_device *cdev)
113{ 117{
114 struct ccw_request *req = &cdev->private->req; 118 struct ccw_request *req = &cdev->private->req;
115 119
116 /* Try all paths twice to counter link flapping. */ 120 if (req->singlepath) {
117 req->mask = 0x8080; 121 /* Try all paths twice to counter link flapping. */
122 req->mask = 0x8080;
123 } else
124 req->mask = req->lpm;
125
118 req->retries = req->maxretries; 126 req->retries = req->maxretries;
119 req->mask = lpm_adjust(req->mask, req->lpm); 127 req->mask = lpm_adjust(req->mask, req->lpm);
120 req->drc = 0; 128 req->drc = 0;
@@ -182,6 +190,8 @@ static enum io_status ccwreq_status(struct ccw_device *cdev, struct irb *lcirb)
182 /* Ask the driver what to do */ 190 /* Ask the driver what to do */
183 if (cdev->drv && cdev->drv->uc_handler) { 191 if (cdev->drv && cdev->drv->uc_handler) {
184 todo = cdev->drv->uc_handler(cdev, lcirb); 192 todo = cdev->drv->uc_handler(cdev, lcirb);
193 CIO_TRACE_EVENT(2, "uc_response");
194 CIO_HEX_EVENT(2, &todo, sizeof(todo));
185 switch (todo) { 195 switch (todo) {
186 case UC_TODO_RETRY: 196 case UC_TODO_RETRY:
187 return IO_STATUS_ERROR; 197 return IO_STATUS_ERROR;
diff --git a/drivers/s390/cio/chsc.c b/drivers/s390/cio/chsc.c
index 407d0e9adfaf..4cbb1a6ca33c 100644
--- a/drivers/s390/cio/chsc.c
+++ b/drivers/s390/cio/chsc.c
@@ -29,6 +29,7 @@
29#include "chsc.h" 29#include "chsc.h"
30 30
31static void *sei_page; 31static void *sei_page;
32static DEFINE_SPINLOCK(siosl_lock);
32static DEFINE_SPINLOCK(sda_lock); 33static DEFINE_SPINLOCK(sda_lock);
33 34
34/** 35/**
@@ -48,6 +49,7 @@ int chsc_error_from_response(int response)
48 case 0x0007: 49 case 0x0007:
49 case 0x0008: 50 case 0x0008:
50 case 0x000a: 51 case 0x000a:
52 case 0x0104:
51 return -EINVAL; 53 return -EINVAL;
52 case 0x0004: 54 case 0x0004:
53 return -EOPNOTSUPP; 55 return -EOPNOTSUPP;
@@ -974,3 +976,49 @@ int chsc_sstpi(void *page, void *result, size_t size)
974 return (rr->response.code == 0x0001) ? 0 : -EIO; 976 return (rr->response.code == 0x0001) ? 0 : -EIO;
975} 977}
976 978
979static struct {
980 struct chsc_header request;
981 u32 word1;
982 struct subchannel_id sid;
983 u32 word3;
984 struct chsc_header response;
985 u32 word[11];
986} __attribute__ ((packed)) siosl_area __attribute__ ((__aligned__(PAGE_SIZE)));
987
988int chsc_siosl(struct subchannel_id schid)
989{
990 unsigned long flags;
991 int ccode;
992 int rc;
993
994 spin_lock_irqsave(&siosl_lock, flags);
995 memset(&siosl_area, 0, sizeof(siosl_area));
996 siosl_area.request.length = 0x0010;
997 siosl_area.request.code = 0x0046;
998 siosl_area.word1 = 0x80000000;
999 siosl_area.sid = schid;
1000
1001 ccode = chsc(&siosl_area);
1002 if (ccode > 0) {
1003 if (ccode == 3)
1004 rc = -ENODEV;
1005 else
1006 rc = -EBUSY;
1007 CIO_MSG_EVENT(2, "chsc: chsc failed for 0.%x.%04x (ccode=%d)\n",
1008 schid.ssid, schid.sch_no, ccode);
1009 goto out;
1010 }
1011 rc = chsc_error_from_response(siosl_area.response.code);
1012 if (rc)
1013 CIO_MSG_EVENT(2, "chsc: siosl failed for 0.%x.%04x (rc=%04x)\n",
1014 schid.ssid, schid.sch_no,
1015 siosl_area.response.code);
1016 else
1017 CIO_MSG_EVENT(4, "chsc: siosl succeeded for 0.%x.%04x\n",
1018 schid.ssid, schid.sch_no);
1019out:
1020 spin_unlock_irqrestore(&siosl_lock, flags);
1021
1022 return rc;
1023}
1024EXPORT_SYMBOL_GPL(chsc_siosl);
diff --git a/drivers/s390/cio/chsc.h b/drivers/s390/cio/chsc.h
index 37aa611d4ac5..5453013f094b 100644
--- a/drivers/s390/cio/chsc.h
+++ b/drivers/s390/cio/chsc.h
@@ -80,4 +80,6 @@ int chsc_get_channel_measurement_chars(struct channel_path *chp);
80 80
81int chsc_error_from_response(int response); 81int chsc_error_from_response(int response);
82 82
83int chsc_siosl(struct subchannel_id schid);
84
83#endif 85#endif
diff --git a/drivers/s390/cio/device.c b/drivers/s390/cio/device.c
index 6d229f3523a0..51bd3687d163 100644
--- a/drivers/s390/cio/device.c
+++ b/drivers/s390/cio/device.c
@@ -36,6 +36,7 @@
36#include "ioasm.h" 36#include "ioasm.h"
37#include "io_sch.h" 37#include "io_sch.h"
38#include "blacklist.h" 38#include "blacklist.h"
39#include "chsc.h"
39 40
40static struct timer_list recovery_timer; 41static struct timer_list recovery_timer;
41static DEFINE_SPINLOCK(recovery_lock); 42static DEFINE_SPINLOCK(recovery_lock);
@@ -486,9 +487,11 @@ static int online_store_handle_offline(struct ccw_device *cdev)
486 spin_lock_irq(cdev->ccwlock); 487 spin_lock_irq(cdev->ccwlock);
487 ccw_device_sched_todo(cdev, CDEV_TODO_UNREG_EVAL); 488 ccw_device_sched_todo(cdev, CDEV_TODO_UNREG_EVAL);
488 spin_unlock_irq(cdev->ccwlock); 489 spin_unlock_irq(cdev->ccwlock);
489 } else if (cdev->online && cdev->drv && cdev->drv->set_offline) 490 return 0;
491 }
492 if (cdev->drv && cdev->drv->set_offline)
490 return ccw_device_set_offline(cdev); 493 return ccw_device_set_offline(cdev);
491 return 0; 494 return -EINVAL;
492} 495}
493 496
494static int online_store_recog_and_online(struct ccw_device *cdev) 497static int online_store_recog_and_online(struct ccw_device *cdev)
@@ -505,8 +508,8 @@ static int online_store_recog_and_online(struct ccw_device *cdev)
505 return -EAGAIN; 508 return -EAGAIN;
506 } 509 }
507 if (cdev->drv && cdev->drv->set_online) 510 if (cdev->drv && cdev->drv->set_online)
508 ccw_device_set_online(cdev); 511 return ccw_device_set_online(cdev);
509 return 0; 512 return -EINVAL;
510} 513}
511 514
512static int online_store_handle_online(struct ccw_device *cdev, int force) 515static int online_store_handle_online(struct ccw_device *cdev, int force)
@@ -598,6 +601,25 @@ available_show (struct device *dev, struct device_attribute *attr, char *buf)
598 } 601 }
599} 602}
600 603
604static ssize_t
605initiate_logging(struct device *dev, struct device_attribute *attr,
606 const char *buf, size_t count)
607{
608 struct subchannel *sch = to_subchannel(dev);
609 int rc;
610
611 rc = chsc_siosl(sch->schid);
612 if (rc < 0) {
613 pr_warning("Logging for subchannel 0.%x.%04x failed with "
614 "errno=%d\n",
615 sch->schid.ssid, sch->schid.sch_no, rc);
616 return rc;
617 }
618 pr_notice("Logging for subchannel 0.%x.%04x was triggered\n",
619 sch->schid.ssid, sch->schid.sch_no);
620 return count;
621}
622
601static DEVICE_ATTR(chpids, 0444, chpids_show, NULL); 623static DEVICE_ATTR(chpids, 0444, chpids_show, NULL);
602static DEVICE_ATTR(pimpampom, 0444, pimpampom_show, NULL); 624static DEVICE_ATTR(pimpampom, 0444, pimpampom_show, NULL);
603static DEVICE_ATTR(devtype, 0444, devtype_show, NULL); 625static DEVICE_ATTR(devtype, 0444, devtype_show, NULL);
@@ -605,10 +627,12 @@ static DEVICE_ATTR(cutype, 0444, cutype_show, NULL);
605static DEVICE_ATTR(modalias, 0444, modalias_show, NULL); 627static DEVICE_ATTR(modalias, 0444, modalias_show, NULL);
606static DEVICE_ATTR(online, 0644, online_show, online_store); 628static DEVICE_ATTR(online, 0644, online_show, online_store);
607static DEVICE_ATTR(availability, 0444, available_show, NULL); 629static DEVICE_ATTR(availability, 0444, available_show, NULL);
630static DEVICE_ATTR(logging, 0200, NULL, initiate_logging);
608 631
609static struct attribute *io_subchannel_attrs[] = { 632static struct attribute *io_subchannel_attrs[] = {
610 &dev_attr_chpids.attr, 633 &dev_attr_chpids.attr,
611 &dev_attr_pimpampom.attr, 634 &dev_attr_pimpampom.attr,
635 &dev_attr_logging.attr,
612 NULL, 636 NULL,
613}; 637};
614 638
@@ -2036,6 +2060,21 @@ void ccw_device_sched_todo(struct ccw_device *cdev, enum cdev_todo todo)
2036 } 2060 }
2037} 2061}
2038 2062
2063/**
2064 * ccw_device_siosl() - initiate logging
2065 * @cdev: ccw device
2066 *
2067 * This function is used to invoke model-dependent logging within the channel
2068 * subsystem.
2069 */
2070int ccw_device_siosl(struct ccw_device *cdev)
2071{
2072 struct subchannel *sch = to_subchannel(cdev->dev.parent);
2073
2074 return chsc_siosl(sch->schid);
2075}
2076EXPORT_SYMBOL_GPL(ccw_device_siosl);
2077
2039MODULE_LICENSE("GPL"); 2078MODULE_LICENSE("GPL");
2040EXPORT_SYMBOL(ccw_device_set_online); 2079EXPORT_SYMBOL(ccw_device_set_online);
2041EXPORT_SYMBOL(ccw_device_set_offline); 2080EXPORT_SYMBOL(ccw_device_set_offline);
diff --git a/drivers/s390/cio/device_pgid.c b/drivers/s390/cio/device_pgid.c
index 6facb5499a65..82a5ad0d63f6 100644
--- a/drivers/s390/cio/device_pgid.c
+++ b/drivers/s390/cio/device_pgid.c
@@ -208,6 +208,7 @@ static void spid_start(struct ccw_device *cdev)
208 req->timeout = PGID_TIMEOUT; 208 req->timeout = PGID_TIMEOUT;
209 req->maxretries = PGID_RETRIES; 209 req->maxretries = PGID_RETRIES;
210 req->lpm = 0x80; 210 req->lpm = 0x80;
211 req->singlepath = 1;
211 req->callback = spid_callback; 212 req->callback = spid_callback;
212 spid_do(cdev); 213 spid_do(cdev);
213} 214}
@@ -420,6 +421,7 @@ static void verify_start(struct ccw_device *cdev)
420 req->timeout = PGID_TIMEOUT; 421 req->timeout = PGID_TIMEOUT;
421 req->maxretries = PGID_RETRIES; 422 req->maxretries = PGID_RETRIES;
422 req->lpm = 0x80; 423 req->lpm = 0x80;
424 req->singlepath = 1;
423 if (cdev->private->flags.pgroup) { 425 if (cdev->private->flags.pgroup) {
424 CIO_TRACE_EVENT(4, "snid"); 426 CIO_TRACE_EVENT(4, "snid");
425 CIO_HEX_EVENT(4, devid, sizeof(*devid)); 427 CIO_HEX_EVENT(4, devid, sizeof(*devid));
@@ -507,6 +509,7 @@ void ccw_device_disband_start(struct ccw_device *cdev)
507 req->timeout = PGID_TIMEOUT; 509 req->timeout = PGID_TIMEOUT;
508 req->maxretries = PGID_RETRIES; 510 req->maxretries = PGID_RETRIES;
509 req->lpm = sch->schib.pmcw.pam & sch->opm; 511 req->lpm = sch->schib.pmcw.pam & sch->opm;
512 req->singlepath = 1;
510 req->callback = disband_callback; 513 req->callback = disband_callback;
511 fn = SPID_FUNC_DISBAND; 514 fn = SPID_FUNC_DISBAND;
512 if (cdev->private->flags.mpath) 515 if (cdev->private->flags.mpath)
diff --git a/drivers/s390/cio/io_sch.h b/drivers/s390/cio/io_sch.h
index b9ce712a7f25..469ef93f2302 100644
--- a/drivers/s390/cio/io_sch.h
+++ b/drivers/s390/cio/io_sch.h
@@ -92,11 +92,12 @@ enum io_status {
92 * @filter: optional callback to adjust request status based on IRB data 92 * @filter: optional callback to adjust request status based on IRB data
93 * @callback: final callback 93 * @callback: final callback
94 * @data: user-defined pointer passed to all callbacks 94 * @data: user-defined pointer passed to all callbacks
95 * @singlepath: if set, use only one path from @lpm per start I/O
96 * @cancel: non-zero if request was cancelled
97 * @done: non-zero if request was finished
95 * @mask: current path mask 98 * @mask: current path mask
96 * @retries: current number of retries 99 * @retries: current number of retries
97 * @drc: delayed return code 100 * @drc: delayed return code
98 * @cancel: non-zero if request was cancelled
99 * @done: non-zero if request was finished
100 */ 101 */
101struct ccw_request { 102struct ccw_request {
102 struct ccw1 *cp; 103 struct ccw1 *cp;
@@ -108,12 +109,13 @@ struct ccw_request {
108 enum io_status); 109 enum io_status);
109 void (*callback)(struct ccw_device *, void *, int); 110 void (*callback)(struct ccw_device *, void *, int);
110 void *data; 111 void *data;
112 unsigned int singlepath:1;
111 /* These fields are used internally. */ 113 /* These fields are used internally. */
114 unsigned int cancel:1;
115 unsigned int done:1;
112 u16 mask; 116 u16 mask;
113 u16 retries; 117 u16 retries;
114 int drc; 118 int drc;
115 int cancel:1;
116 int done:1;
117} __attribute__((packed)); 119} __attribute__((packed));
118 120
119/* 121/*
diff --git a/drivers/s390/net/claw.c b/drivers/s390/net/claw.c
index a75ed3083a6a..8e4153d740f3 100644
--- a/drivers/s390/net/claw.c
+++ b/drivers/s390/net/claw.c
@@ -386,7 +386,7 @@ claw_tx(struct sk_buff *skb, struct net_device *dev)
386 struct chbk *p_ch; 386 struct chbk *p_ch;
387 387
388 CLAW_DBF_TEXT(4, trace, "claw_tx"); 388 CLAW_DBF_TEXT(4, trace, "claw_tx");
389 p_ch=&privptr->channel[WRITE]; 389 p_ch = &privptr->channel[WRITE_CHANNEL];
390 spin_lock_irqsave(get_ccwdev_lock(p_ch->cdev), saveflags); 390 spin_lock_irqsave(get_ccwdev_lock(p_ch->cdev), saveflags);
391 rc=claw_hw_tx( skb, dev, 1 ); 391 rc=claw_hw_tx( skb, dev, 1 );
392 spin_unlock_irqrestore(get_ccwdev_lock(p_ch->cdev), saveflags); 392 spin_unlock_irqrestore(get_ccwdev_lock(p_ch->cdev), saveflags);
@@ -407,7 +407,7 @@ static struct sk_buff *
407claw_pack_skb(struct claw_privbk *privptr) 407claw_pack_skb(struct claw_privbk *privptr)
408{ 408{
409 struct sk_buff *new_skb,*held_skb; 409 struct sk_buff *new_skb,*held_skb;
410 struct chbk *p_ch = &privptr->channel[WRITE]; 410 struct chbk *p_ch = &privptr->channel[WRITE_CHANNEL];
411 struct claw_env *p_env = privptr->p_env; 411 struct claw_env *p_env = privptr->p_env;
412 int pkt_cnt,pk_ind,so_far; 412 int pkt_cnt,pk_ind,so_far;
413 413
@@ -515,15 +515,15 @@ claw_open(struct net_device *dev)
515 privptr->p_env->write_size=CLAW_FRAME_SIZE; 515 privptr->p_env->write_size=CLAW_FRAME_SIZE;
516 } 516 }
517 claw_set_busy(dev); 517 claw_set_busy(dev);
518 tasklet_init(&privptr->channel[READ].tasklet, claw_irq_tasklet, 518 tasklet_init(&privptr->channel[READ_CHANNEL].tasklet, claw_irq_tasklet,
519 (unsigned long) &privptr->channel[READ]); 519 (unsigned long) &privptr->channel[READ_CHANNEL]);
520 for ( i = 0; i < 2; i++) { 520 for ( i = 0; i < 2; i++) {
521 CLAW_DBF_TEXT_(2, trace, "opn_ch%d", i); 521 CLAW_DBF_TEXT_(2, trace, "opn_ch%d", i);
522 init_waitqueue_head(&privptr->channel[i].wait); 522 init_waitqueue_head(&privptr->channel[i].wait);
523 /* skb_queue_head_init(&p_ch->io_queue); */ 523 /* skb_queue_head_init(&p_ch->io_queue); */
524 if (i == WRITE) 524 if (i == WRITE_CHANNEL)
525 skb_queue_head_init( 525 skb_queue_head_init(
526 &privptr->channel[WRITE].collect_queue); 526 &privptr->channel[WRITE_CHANNEL].collect_queue);
527 privptr->channel[i].flag_a = 0; 527 privptr->channel[i].flag_a = 0;
528 privptr->channel[i].IO_active = 0; 528 privptr->channel[i].IO_active = 0;
529 privptr->channel[i].flag &= ~CLAW_TIMER; 529 privptr->channel[i].flag &= ~CLAW_TIMER;
@@ -551,12 +551,12 @@ claw_open(struct net_device *dev)
551 if((privptr->channel[i].flag & CLAW_TIMER) == 0x00) 551 if((privptr->channel[i].flag & CLAW_TIMER) == 0x00)
552 del_timer(&timer); 552 del_timer(&timer);
553 } 553 }
554 if ((((privptr->channel[READ].last_dstat | 554 if ((((privptr->channel[READ_CHANNEL].last_dstat |
555 privptr->channel[WRITE].last_dstat) & 555 privptr->channel[WRITE_CHANNEL].last_dstat) &
556 ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) || 556 ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) ||
557 (((privptr->channel[READ].flag | 557 (((privptr->channel[READ_CHANNEL].flag |
558 privptr->channel[WRITE].flag) & CLAW_TIMER) != 0x00)) { 558 privptr->channel[WRITE_CHANNEL].flag) & CLAW_TIMER) != 0x00)) {
559 dev_info(&privptr->channel[READ].cdev->dev, 559 dev_info(&privptr->channel[READ_CHANNEL].cdev->dev,
560 "%s: remote side is not ready\n", dev->name); 560 "%s: remote side is not ready\n", dev->name);
561 CLAW_DBF_TEXT(2, trace, "notrdy"); 561 CLAW_DBF_TEXT(2, trace, "notrdy");
562 562
@@ -608,8 +608,8 @@ claw_open(struct net_device *dev)
608 } 608 }
609 } 609 }
610 privptr->buffs_alloc = 0; 610 privptr->buffs_alloc = 0;
611 privptr->channel[READ].flag= 0x00; 611 privptr->channel[READ_CHANNEL].flag = 0x00;
612 privptr->channel[WRITE].flag = 0x00; 612 privptr->channel[WRITE_CHANNEL].flag = 0x00;
613 privptr->p_buff_ccw=NULL; 613 privptr->p_buff_ccw=NULL;
614 privptr->p_buff_read=NULL; 614 privptr->p_buff_read=NULL;
615 privptr->p_buff_write=NULL; 615 privptr->p_buff_write=NULL;
@@ -652,10 +652,10 @@ claw_irq_handler(struct ccw_device *cdev,
652 } 652 }
653 653
654 /* Try to extract channel from driver data. */ 654 /* Try to extract channel from driver data. */
655 if (privptr->channel[READ].cdev == cdev) 655 if (privptr->channel[READ_CHANNEL].cdev == cdev)
656 p_ch = &privptr->channel[READ]; 656 p_ch = &privptr->channel[READ_CHANNEL];
657 else if (privptr->channel[WRITE].cdev == cdev) 657 else if (privptr->channel[WRITE_CHANNEL].cdev == cdev)
658 p_ch = &privptr->channel[WRITE]; 658 p_ch = &privptr->channel[WRITE_CHANNEL];
659 else { 659 else {
660 dev_warn(&cdev->dev, "The device is not a CLAW device\n"); 660 dev_warn(&cdev->dev, "The device is not a CLAW device\n");
661 CLAW_DBF_TEXT(2, trace, "badchan"); 661 CLAW_DBF_TEXT(2, trace, "badchan");
@@ -813,7 +813,7 @@ claw_irq_handler(struct ccw_device *cdev,
813 claw_clearbit_busy(TB_TX, dev); 813 claw_clearbit_busy(TB_TX, dev);
814 claw_clear_busy(dev); 814 claw_clear_busy(dev);
815 } 815 }
816 p_ch_r = (struct chbk *)&privptr->channel[READ]; 816 p_ch_r = (struct chbk *)&privptr->channel[READ_CHANNEL];
817 if (test_and_set_bit(CLAW_BH_ACTIVE, 817 if (test_and_set_bit(CLAW_BH_ACTIVE,
818 (void *)&p_ch_r->flag_a) == 0) 818 (void *)&p_ch_r->flag_a) == 0)
819 tasklet_schedule(&p_ch_r->tasklet); 819 tasklet_schedule(&p_ch_r->tasklet);
@@ -878,13 +878,13 @@ claw_release(struct net_device *dev)
878 for ( i = 1; i >=0 ; i--) { 878 for ( i = 1; i >=0 ; i--) {
879 spin_lock_irqsave( 879 spin_lock_irqsave(
880 get_ccwdev_lock(privptr->channel[i].cdev), saveflags); 880 get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
881 /* del_timer(&privptr->channel[READ].timer); */ 881 /* del_timer(&privptr->channel[READ_CHANNEL].timer); */
882 privptr->channel[i].claw_state = CLAW_STOP; 882 privptr->channel[i].claw_state = CLAW_STOP;
883 privptr->channel[i].IO_active = 0; 883 privptr->channel[i].IO_active = 0;
884 parm = (unsigned long) &privptr->channel[i]; 884 parm = (unsigned long) &privptr->channel[i];
885 if (i == WRITE) 885 if (i == WRITE_CHANNEL)
886 claw_purge_skb_queue( 886 claw_purge_skb_queue(
887 &privptr->channel[WRITE].collect_queue); 887 &privptr->channel[WRITE_CHANNEL].collect_queue);
888 rc = ccw_device_halt (privptr->channel[i].cdev, parm); 888 rc = ccw_device_halt (privptr->channel[i].cdev, parm);
889 if (privptr->system_validate_comp==0x00) /* never opened? */ 889 if (privptr->system_validate_comp==0x00) /* never opened? */
890 init_waitqueue_head(&privptr->channel[i].wait); 890 init_waitqueue_head(&privptr->channel[i].wait);
@@ -971,16 +971,16 @@ claw_release(struct net_device *dev)
971 privptr->mtc_skipping = 1; 971 privptr->mtc_skipping = 1;
972 privptr->mtc_offset=0; 972 privptr->mtc_offset=0;
973 973
974 if (((privptr->channel[READ].last_dstat | 974 if (((privptr->channel[READ_CHANNEL].last_dstat |
975 privptr->channel[WRITE].last_dstat) & 975 privptr->channel[WRITE_CHANNEL].last_dstat) &
976 ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) { 976 ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) {
977 dev_warn(&privptr->channel[READ].cdev->dev, 977 dev_warn(&privptr->channel[READ_CHANNEL].cdev->dev,
978 "Deactivating %s completed with incorrect" 978 "Deactivating %s completed with incorrect"
979 " subchannel status " 979 " subchannel status "
980 "(read %02x, write %02x)\n", 980 "(read %02x, write %02x)\n",
981 dev->name, 981 dev->name,
982 privptr->channel[READ].last_dstat, 982 privptr->channel[READ_CHANNEL].last_dstat,
983 privptr->channel[WRITE].last_dstat); 983 privptr->channel[WRITE_CHANNEL].last_dstat);
984 CLAW_DBF_TEXT(2, trace, "badclose"); 984 CLAW_DBF_TEXT(2, trace, "badclose");
985 } 985 }
986 CLAW_DBF_TEXT(4, trace, "rlsexit"); 986 CLAW_DBF_TEXT(4, trace, "rlsexit");
@@ -1324,7 +1324,7 @@ claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid)
1324 1324
1325 CLAW_DBF_TEXT(4, trace, "hw_tx"); 1325 CLAW_DBF_TEXT(4, trace, "hw_tx");
1326 privptr = (struct claw_privbk *)(dev->ml_priv); 1326 privptr = (struct claw_privbk *)(dev->ml_priv);
1327 p_ch=(struct chbk *)&privptr->channel[WRITE]; 1327 p_ch = (struct chbk *)&privptr->channel[WRITE_CHANNEL];
1328 p_env =privptr->p_env; 1328 p_env =privptr->p_env;
1329 claw_free_wrt_buf(dev); /* Clean up free chain if posible */ 1329 claw_free_wrt_buf(dev); /* Clean up free chain if posible */
1330 /* scan the write queue to free any completed write packets */ 1330 /* scan the write queue to free any completed write packets */
@@ -1357,7 +1357,7 @@ claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid)
1357 claw_strt_out_IO(dev ); 1357 claw_strt_out_IO(dev );
1358 claw_free_wrt_buf( dev ); 1358 claw_free_wrt_buf( dev );
1359 if (privptr->write_free_count==0) { 1359 if (privptr->write_free_count==0) {
1360 ch = &privptr->channel[WRITE]; 1360 ch = &privptr->channel[WRITE_CHANNEL];
1361 atomic_inc(&skb->users); 1361 atomic_inc(&skb->users);
1362 skb_queue_tail(&ch->collect_queue, skb); 1362 skb_queue_tail(&ch->collect_queue, skb);
1363 goto Done; 1363 goto Done;
@@ -1369,7 +1369,7 @@ claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid)
1369 } 1369 }
1370 /* tx lock */ 1370 /* tx lock */
1371 if (claw_test_and_setbit_busy(TB_TX,dev)) { /* set to busy */ 1371 if (claw_test_and_setbit_busy(TB_TX,dev)) { /* set to busy */
1372 ch = &privptr->channel[WRITE]; 1372 ch = &privptr->channel[WRITE_CHANNEL];
1373 atomic_inc(&skb->users); 1373 atomic_inc(&skb->users);
1374 skb_queue_tail(&ch->collect_queue, skb); 1374 skb_queue_tail(&ch->collect_queue, skb);
1375 claw_strt_out_IO(dev ); 1375 claw_strt_out_IO(dev );
@@ -1385,7 +1385,7 @@ claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid)
1385 privptr->p_write_free_chain == NULL ) { 1385 privptr->p_write_free_chain == NULL ) {
1386 1386
1387 claw_setbit_busy(TB_NOBUFFER,dev); 1387 claw_setbit_busy(TB_NOBUFFER,dev);
1388 ch = &privptr->channel[WRITE]; 1388 ch = &privptr->channel[WRITE_CHANNEL];
1389 atomic_inc(&skb->users); 1389 atomic_inc(&skb->users);
1390 skb_queue_tail(&ch->collect_queue, skb); 1390 skb_queue_tail(&ch->collect_queue, skb);
1391 CLAW_DBF_TEXT(2, trace, "clawbusy"); 1391 CLAW_DBF_TEXT(2, trace, "clawbusy");
@@ -1397,7 +1397,7 @@ claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid)
1397 while (len_of_data > 0) { 1397 while (len_of_data > 0) {
1398 p_this_ccw=privptr->p_write_free_chain; /* get a block */ 1398 p_this_ccw=privptr->p_write_free_chain; /* get a block */
1399 if (p_this_ccw == NULL) { /* lost the race */ 1399 if (p_this_ccw == NULL) { /* lost the race */
1400 ch = &privptr->channel[WRITE]; 1400 ch = &privptr->channel[WRITE_CHANNEL];
1401 atomic_inc(&skb->users); 1401 atomic_inc(&skb->users);
1402 skb_queue_tail(&ch->collect_queue, skb); 1402 skb_queue_tail(&ch->collect_queue, skb);
1403 goto Done2; 1403 goto Done2;
@@ -2067,7 +2067,7 @@ claw_process_control( struct net_device *dev, struct ccwbk * p_ccw)
2067 *catch up to each other */ 2067 *catch up to each other */
2068 privptr = dev->ml_priv; 2068 privptr = dev->ml_priv;
2069 p_env=privptr->p_env; 2069 p_env=privptr->p_env;
2070 tdev = &privptr->channel[READ].cdev->dev; 2070 tdev = &privptr->channel[READ_CHANNEL].cdev->dev;
2071 memcpy( &temp_host_name, p_env->host_name, 8); 2071 memcpy( &temp_host_name, p_env->host_name, 8);
2072 memcpy( &temp_ws_name, p_env->adapter_name , 8); 2072 memcpy( &temp_ws_name, p_env->adapter_name , 8);
2073 dev_info(tdev, "%s: CLAW device %.8s: " 2073 dev_info(tdev, "%s: CLAW device %.8s: "
@@ -2245,7 +2245,7 @@ claw_process_control( struct net_device *dev, struct ccwbk * p_ccw)
2245 dev->name, temp_ws_name, 2245 dev->name, temp_ws_name,
2246 p_ctlbk->linkid); 2246 p_ctlbk->linkid);
2247 privptr->active_link_ID = p_ctlbk->linkid; 2247 privptr->active_link_ID = p_ctlbk->linkid;
2248 p_ch = &privptr->channel[WRITE]; 2248 p_ch = &privptr->channel[WRITE_CHANNEL];
2249 wake_up(&p_ch->wait); /* wake up claw_open ( WRITE) */ 2249 wake_up(&p_ch->wait); /* wake up claw_open ( WRITE) */
2250 break; 2250 break;
2251 case CONNECTION_RESPONSE: 2251 case CONNECTION_RESPONSE:
@@ -2296,7 +2296,7 @@ claw_process_control( struct net_device *dev, struct ccwbk * p_ccw)
2296 "%s: Confirmed Now packing\n", dev->name); 2296 "%s: Confirmed Now packing\n", dev->name);
2297 p_env->packing = DO_PACKED; 2297 p_env->packing = DO_PACKED;
2298 } 2298 }
2299 p_ch = &privptr->channel[WRITE]; 2299 p_ch = &privptr->channel[WRITE_CHANNEL];
2300 wake_up(&p_ch->wait); 2300 wake_up(&p_ch->wait);
2301 } else { 2301 } else {
2302 dev_warn(tdev, "Activating %s failed because of" 2302 dev_warn(tdev, "Activating %s failed because of"
@@ -2556,7 +2556,7 @@ unpack_read(struct net_device *dev )
2556 p_packd=NULL; 2556 p_packd=NULL;
2557 privptr = dev->ml_priv; 2557 privptr = dev->ml_priv;
2558 2558
2559 p_dev = &privptr->channel[READ].cdev->dev; 2559 p_dev = &privptr->channel[READ_CHANNEL].cdev->dev;
2560 p_env = privptr->p_env; 2560 p_env = privptr->p_env;
2561 p_this_ccw=privptr->p_read_active_first; 2561 p_this_ccw=privptr->p_read_active_first;
2562 while (p_this_ccw!=NULL && p_this_ccw->header.flag!=CLAW_PENDING) { 2562 while (p_this_ccw!=NULL && p_this_ccw->header.flag!=CLAW_PENDING) {
@@ -2728,7 +2728,7 @@ claw_strt_read (struct net_device *dev, int lock )
2728 struct ccwbk*p_ccwbk; 2728 struct ccwbk*p_ccwbk;
2729 struct chbk *p_ch; 2729 struct chbk *p_ch;
2730 struct clawh *p_clawh; 2730 struct clawh *p_clawh;
2731 p_ch=&privptr->channel[READ]; 2731 p_ch = &privptr->channel[READ_CHANNEL];
2732 2732
2733 CLAW_DBF_TEXT(4, trace, "StRdNter"); 2733 CLAW_DBF_TEXT(4, trace, "StRdNter");
2734 p_clawh=(struct clawh *)privptr->p_claw_signal_blk; 2734 p_clawh=(struct clawh *)privptr->p_claw_signal_blk;
@@ -2782,7 +2782,7 @@ claw_strt_out_IO( struct net_device *dev )
2782 return; 2782 return;
2783 } 2783 }
2784 privptr = (struct claw_privbk *)dev->ml_priv; 2784 privptr = (struct claw_privbk *)dev->ml_priv;
2785 p_ch=&privptr->channel[WRITE]; 2785 p_ch = &privptr->channel[WRITE_CHANNEL];
2786 2786
2787 CLAW_DBF_TEXT(4, trace, "strt_io"); 2787 CLAW_DBF_TEXT(4, trace, "strt_io");
2788 p_first_ccw=privptr->p_write_active_first; 2788 p_first_ccw=privptr->p_write_active_first;
@@ -2875,7 +2875,7 @@ claw_free_netdevice(struct net_device * dev, int free_dev)
2875 if (dev->flags & IFF_RUNNING) 2875 if (dev->flags & IFF_RUNNING)
2876 claw_release(dev); 2876 claw_release(dev);
2877 if (privptr) { 2877 if (privptr) {
2878 privptr->channel[READ].ndev = NULL; /* say it's free */ 2878 privptr->channel[READ_CHANNEL].ndev = NULL; /* say it's free */
2879 } 2879 }
2880 dev->ml_priv = NULL; 2880 dev->ml_priv = NULL;
2881#ifdef MODULE 2881#ifdef MODULE
@@ -2960,18 +2960,18 @@ claw_new_device(struct ccwgroup_device *cgdev)
2960 struct ccw_dev_id dev_id; 2960 struct ccw_dev_id dev_id;
2961 2961
2962 dev_info(&cgdev->dev, "add for %s\n", 2962 dev_info(&cgdev->dev, "add for %s\n",
2963 dev_name(&cgdev->cdev[READ]->dev)); 2963 dev_name(&cgdev->cdev[READ_CHANNEL]->dev));
2964 CLAW_DBF_TEXT(2, setup, "new_dev"); 2964 CLAW_DBF_TEXT(2, setup, "new_dev");
2965 privptr = dev_get_drvdata(&cgdev->dev); 2965 privptr = dev_get_drvdata(&cgdev->dev);
2966 dev_set_drvdata(&cgdev->cdev[READ]->dev, privptr); 2966 dev_set_drvdata(&cgdev->cdev[READ_CHANNEL]->dev, privptr);
2967 dev_set_drvdata(&cgdev->cdev[WRITE]->dev, privptr); 2967 dev_set_drvdata(&cgdev->cdev[WRITE_CHANNEL]->dev, privptr);
2968 if (!privptr) 2968 if (!privptr)
2969 return -ENODEV; 2969 return -ENODEV;
2970 p_env = privptr->p_env; 2970 p_env = privptr->p_env;
2971 ccw_device_get_id(cgdev->cdev[READ], &dev_id); 2971 ccw_device_get_id(cgdev->cdev[READ_CHANNEL], &dev_id);
2972 p_env->devno[READ] = dev_id.devno; 2972 p_env->devno[READ_CHANNEL] = dev_id.devno;
2973 ccw_device_get_id(cgdev->cdev[WRITE], &dev_id); 2973 ccw_device_get_id(cgdev->cdev[WRITE_CHANNEL], &dev_id);
2974 p_env->devno[WRITE] = dev_id.devno; 2974 p_env->devno[WRITE_CHANNEL] = dev_id.devno;
2975 ret = add_channel(cgdev->cdev[0],0,privptr); 2975 ret = add_channel(cgdev->cdev[0],0,privptr);
2976 if (ret == 0) 2976 if (ret == 0)
2977 ret = add_channel(cgdev->cdev[1],1,privptr); 2977 ret = add_channel(cgdev->cdev[1],1,privptr);
@@ -2980,14 +2980,14 @@ claw_new_device(struct ccwgroup_device *cgdev)
2980 " failed with error code %d\n", ret); 2980 " failed with error code %d\n", ret);
2981 goto out; 2981 goto out;
2982 } 2982 }
2983 ret = ccw_device_set_online(cgdev->cdev[READ]); 2983 ret = ccw_device_set_online(cgdev->cdev[READ_CHANNEL]);
2984 if (ret != 0) { 2984 if (ret != 0) {
2985 dev_warn(&cgdev->dev, 2985 dev_warn(&cgdev->dev,
2986 "Setting the read subchannel online" 2986 "Setting the read subchannel online"
2987 " failed with error code %d\n", ret); 2987 " failed with error code %d\n", ret);
2988 goto out; 2988 goto out;
2989 } 2989 }
2990 ret = ccw_device_set_online(cgdev->cdev[WRITE]); 2990 ret = ccw_device_set_online(cgdev->cdev[WRITE_CHANNEL]);
2991 if (ret != 0) { 2991 if (ret != 0) {
2992 dev_warn(&cgdev->dev, 2992 dev_warn(&cgdev->dev,
2993 "Setting the write subchannel online " 2993 "Setting the write subchannel online "
@@ -3002,8 +3002,8 @@ claw_new_device(struct ccwgroup_device *cgdev)
3002 } 3002 }
3003 dev->ml_priv = privptr; 3003 dev->ml_priv = privptr;
3004 dev_set_drvdata(&cgdev->dev, privptr); 3004 dev_set_drvdata(&cgdev->dev, privptr);
3005 dev_set_drvdata(&cgdev->cdev[READ]->dev, privptr); 3005 dev_set_drvdata(&cgdev->cdev[READ_CHANNEL]->dev, privptr);
3006 dev_set_drvdata(&cgdev->cdev[WRITE]->dev, privptr); 3006 dev_set_drvdata(&cgdev->cdev[WRITE_CHANNEL]->dev, privptr);
3007 /* sysfs magic */ 3007 /* sysfs magic */
3008 SET_NETDEV_DEV(dev, &cgdev->dev); 3008 SET_NETDEV_DEV(dev, &cgdev->dev);
3009 if (register_netdev(dev) != 0) { 3009 if (register_netdev(dev) != 0) {
@@ -3021,16 +3021,16 @@ claw_new_device(struct ccwgroup_device *cgdev)
3021 goto out; 3021 goto out;
3022 } 3022 }
3023 } 3023 }
3024 privptr->channel[READ].ndev = dev; 3024 privptr->channel[READ_CHANNEL].ndev = dev;
3025 privptr->channel[WRITE].ndev = dev; 3025 privptr->channel[WRITE_CHANNEL].ndev = dev;
3026 privptr->p_env->ndev = dev; 3026 privptr->p_env->ndev = dev;
3027 3027
3028 dev_info(&cgdev->dev, "%s:readsize=%d writesize=%d " 3028 dev_info(&cgdev->dev, "%s:readsize=%d writesize=%d "
3029 "readbuffer=%d writebuffer=%d read=0x%04x write=0x%04x\n", 3029 "readbuffer=%d writebuffer=%d read=0x%04x write=0x%04x\n",
3030 dev->name, p_env->read_size, 3030 dev->name, p_env->read_size,
3031 p_env->write_size, p_env->read_buffers, 3031 p_env->write_size, p_env->read_buffers,
3032 p_env->write_buffers, p_env->devno[READ], 3032 p_env->write_buffers, p_env->devno[READ_CHANNEL],
3033 p_env->devno[WRITE]); 3033 p_env->devno[WRITE_CHANNEL]);
3034 dev_info(&cgdev->dev, "%s:host_name:%.8s, adapter_name " 3034 dev_info(&cgdev->dev, "%s:host_name:%.8s, adapter_name "
3035 ":%.8s api_type: %.8s\n", 3035 ":%.8s api_type: %.8s\n",
3036 dev->name, p_env->host_name, 3036 dev->name, p_env->host_name,
@@ -3072,10 +3072,10 @@ claw_shutdown_device(struct ccwgroup_device *cgdev)
3072 priv = dev_get_drvdata(&cgdev->dev); 3072 priv = dev_get_drvdata(&cgdev->dev);
3073 if (!priv) 3073 if (!priv)
3074 return -ENODEV; 3074 return -ENODEV;
3075 ndev = priv->channel[READ].ndev; 3075 ndev = priv->channel[READ_CHANNEL].ndev;
3076 if (ndev) { 3076 if (ndev) {
3077 /* Close the device */ 3077 /* Close the device */
3078 dev_info(&cgdev->dev, "%s: shutting down \n", 3078 dev_info(&cgdev->dev, "%s: shutting down\n",
3079 ndev->name); 3079 ndev->name);
3080 if (ndev->flags & IFF_RUNNING) 3080 if (ndev->flags & IFF_RUNNING)
3081 ret = claw_release(ndev); 3081 ret = claw_release(ndev);
@@ -3083,8 +3083,8 @@ claw_shutdown_device(struct ccwgroup_device *cgdev)
3083 unregister_netdev(ndev); 3083 unregister_netdev(ndev);
3084 ndev->ml_priv = NULL; /* cgdev data, not ndev's to free */ 3084 ndev->ml_priv = NULL; /* cgdev data, not ndev's to free */
3085 claw_free_netdevice(ndev, 1); 3085 claw_free_netdevice(ndev, 1);
3086 priv->channel[READ].ndev = NULL; 3086 priv->channel[READ_CHANNEL].ndev = NULL;
3087 priv->channel[WRITE].ndev = NULL; 3087 priv->channel[WRITE_CHANNEL].ndev = NULL;
3088 priv->p_env->ndev = NULL; 3088 priv->p_env->ndev = NULL;
3089 } 3089 }
3090 ccw_device_set_offline(cgdev->cdev[1]); 3090 ccw_device_set_offline(cgdev->cdev[1]);
@@ -3115,8 +3115,8 @@ claw_remove_device(struct ccwgroup_device *cgdev)
3115 priv->channel[1].irb=NULL; 3115 priv->channel[1].irb=NULL;
3116 kfree(priv); 3116 kfree(priv);
3117 dev_set_drvdata(&cgdev->dev, NULL); 3117 dev_set_drvdata(&cgdev->dev, NULL);
3118 dev_set_drvdata(&cgdev->cdev[READ]->dev, NULL); 3118 dev_set_drvdata(&cgdev->cdev[READ_CHANNEL]->dev, NULL);
3119 dev_set_drvdata(&cgdev->cdev[WRITE]->dev, NULL); 3119 dev_set_drvdata(&cgdev->cdev[WRITE_CHANNEL]->dev, NULL);
3120 put_device(&cgdev->dev); 3120 put_device(&cgdev->dev);
3121 3121
3122 return; 3122 return;
diff --git a/drivers/s390/net/claw.h b/drivers/s390/net/claw.h
index 46d59a13db12..1bc5904df19f 100644
--- a/drivers/s390/net/claw.h
+++ b/drivers/s390/net/claw.h
@@ -74,8 +74,8 @@
74#define MAX_ENVELOPE_SIZE 65536 74#define MAX_ENVELOPE_SIZE 65536
75#define CLAW_DEFAULT_MTU_SIZE 4096 75#define CLAW_DEFAULT_MTU_SIZE 4096
76#define DEF_PACK_BUFSIZE 32768 76#define DEF_PACK_BUFSIZE 32768
77#define READ 0 77#define READ_CHANNEL 0
78#define WRITE 1 78#define WRITE_CHANNEL 1
79 79
80#define TB_TX 0 /* sk buffer handling in process */ 80#define TB_TX 0 /* sk buffer handling in process */
81#define TB_STOP 1 /* network device stop in process */ 81#define TB_STOP 1 /* network device stop in process */
diff --git a/drivers/s390/net/ctcm_fsms.c b/drivers/s390/net/ctcm_fsms.c
index 70eb7f138414..8c921fc3511a 100644
--- a/drivers/s390/net/ctcm_fsms.c
+++ b/drivers/s390/net/ctcm_fsms.c
@@ -454,7 +454,7 @@ static void chx_firstio(fsm_instance *fi, int event, void *arg)
454 if ((fsmstate == CTC_STATE_SETUPWAIT) && 454 if ((fsmstate == CTC_STATE_SETUPWAIT) &&
455 (ch->protocol == CTCM_PROTO_OS390)) { 455 (ch->protocol == CTCM_PROTO_OS390)) {
456 /* OS/390 resp. z/OS */ 456 /* OS/390 resp. z/OS */
457 if (CHANNEL_DIRECTION(ch->flags) == READ) { 457 if (CHANNEL_DIRECTION(ch->flags) == CTCM_READ) {
458 *((__u16 *)ch->trans_skb->data) = CTCM_INITIAL_BLOCKLEN; 458 *((__u16 *)ch->trans_skb->data) = CTCM_INITIAL_BLOCKLEN;
459 fsm_addtimer(&ch->timer, CTCM_TIME_5_SEC, 459 fsm_addtimer(&ch->timer, CTCM_TIME_5_SEC,
460 CTC_EVENT_TIMER, ch); 460 CTC_EVENT_TIMER, ch);
@@ -472,14 +472,14 @@ static void chx_firstio(fsm_instance *fi, int event, void *arg)
472 * if in compatibility mode, since VM TCP delays the initial 472 * if in compatibility mode, since VM TCP delays the initial
473 * frame until it has some data to send. 473 * frame until it has some data to send.
474 */ 474 */
475 if ((CHANNEL_DIRECTION(ch->flags) == WRITE) || 475 if ((CHANNEL_DIRECTION(ch->flags) == CTCM_WRITE) ||
476 (ch->protocol != CTCM_PROTO_S390)) 476 (ch->protocol != CTCM_PROTO_S390))
477 fsm_addtimer(&ch->timer, CTCM_TIME_5_SEC, CTC_EVENT_TIMER, ch); 477 fsm_addtimer(&ch->timer, CTCM_TIME_5_SEC, CTC_EVENT_TIMER, ch);
478 478
479 *((__u16 *)ch->trans_skb->data) = CTCM_INITIAL_BLOCKLEN; 479 *((__u16 *)ch->trans_skb->data) = CTCM_INITIAL_BLOCKLEN;
480 ch->ccw[1].count = 2; /* Transfer only length */ 480 ch->ccw[1].count = 2; /* Transfer only length */
481 481
482 fsm_newstate(fi, (CHANNEL_DIRECTION(ch->flags) == READ) 482 fsm_newstate(fi, (CHANNEL_DIRECTION(ch->flags) == CTCM_READ)
483 ? CTC_STATE_RXINIT : CTC_STATE_TXINIT); 483 ? CTC_STATE_RXINIT : CTC_STATE_TXINIT);
484 rc = ccw_device_start(ch->cdev, &ch->ccw[0], 484 rc = ccw_device_start(ch->cdev, &ch->ccw[0],
485 (unsigned long)ch, 0xff, 0); 485 (unsigned long)ch, 0xff, 0);
@@ -495,7 +495,7 @@ static void chx_firstio(fsm_instance *fi, int event, void *arg)
495 * reply from VM TCP which brings up the RX channel to it's 495 * reply from VM TCP which brings up the RX channel to it's
496 * final state. 496 * final state.
497 */ 497 */
498 if ((CHANNEL_DIRECTION(ch->flags) == READ) && 498 if ((CHANNEL_DIRECTION(ch->flags) == CTCM_READ) &&
499 (ch->protocol == CTCM_PROTO_S390)) { 499 (ch->protocol == CTCM_PROTO_S390)) {
500 struct net_device *dev = ch->netdev; 500 struct net_device *dev = ch->netdev;
501 struct ctcm_priv *priv = dev->ml_priv; 501 struct ctcm_priv *priv = dev->ml_priv;
@@ -600,15 +600,15 @@ static void ctcm_chx_start(fsm_instance *fi, int event, void *arg)
600 int rc; 600 int rc;
601 601
602 CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO, "%s(%s): %s", 602 CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO, "%s(%s): %s",
603 CTCM_FUNTAIL, ch->id, 603 CTCM_FUNTAIL, ch->id,
604 (CHANNEL_DIRECTION(ch->flags) == READ) ? "RX" : "TX"); 604 (CHANNEL_DIRECTION(ch->flags) == CTCM_READ) ? "RX" : "TX");
605 605
606 if (ch->trans_skb != NULL) { 606 if (ch->trans_skb != NULL) {
607 clear_normalized_cda(&ch->ccw[1]); 607 clear_normalized_cda(&ch->ccw[1]);
608 dev_kfree_skb(ch->trans_skb); 608 dev_kfree_skb(ch->trans_skb);
609 ch->trans_skb = NULL; 609 ch->trans_skb = NULL;
610 } 610 }
611 if (CHANNEL_DIRECTION(ch->flags) == READ) { 611 if (CHANNEL_DIRECTION(ch->flags) == CTCM_READ) {
612 ch->ccw[1].cmd_code = CCW_CMD_READ; 612 ch->ccw[1].cmd_code = CCW_CMD_READ;
613 ch->ccw[1].flags = CCW_FLAG_SLI; 613 ch->ccw[1].flags = CCW_FLAG_SLI;
614 ch->ccw[1].count = 0; 614 ch->ccw[1].count = 0;
@@ -622,7 +622,8 @@ static void ctcm_chx_start(fsm_instance *fi, int event, void *arg)
622 "%s(%s): %s trans_skb alloc delayed " 622 "%s(%s): %s trans_skb alloc delayed "
623 "until first transfer", 623 "until first transfer",
624 CTCM_FUNTAIL, ch->id, 624 CTCM_FUNTAIL, ch->id,
625 (CHANNEL_DIRECTION(ch->flags) == READ) ? "RX" : "TX"); 625 (CHANNEL_DIRECTION(ch->flags) == CTCM_READ) ?
626 "RX" : "TX");
626 } 627 }
627 ch->ccw[0].cmd_code = CCW_CMD_PREPARE; 628 ch->ccw[0].cmd_code = CCW_CMD_PREPARE;
628 ch->ccw[0].flags = CCW_FLAG_SLI | CCW_FLAG_CC; 629 ch->ccw[0].flags = CCW_FLAG_SLI | CCW_FLAG_CC;
@@ -720,7 +721,7 @@ static void ctcm_chx_cleanup(fsm_instance *fi, int state,
720 721
721 ch->th_seg = 0x00; 722 ch->th_seg = 0x00;
722 ch->th_seq_num = 0x00; 723 ch->th_seq_num = 0x00;
723 if (CHANNEL_DIRECTION(ch->flags) == READ) { 724 if (CHANNEL_DIRECTION(ch->flags) == CTCM_READ) {
724 skb_queue_purge(&ch->io_queue); 725 skb_queue_purge(&ch->io_queue);
725 fsm_event(priv->fsm, DEV_EVENT_RXDOWN, dev); 726 fsm_event(priv->fsm, DEV_EVENT_RXDOWN, dev);
726 } else { 727 } else {
@@ -799,7 +800,8 @@ static void ctcm_chx_setuperr(fsm_instance *fi, int event, void *arg)
799 fsm_newstate(fi, CTC_STATE_STARTRETRY); 800 fsm_newstate(fi, CTC_STATE_STARTRETRY);
800 fsm_deltimer(&ch->timer); 801 fsm_deltimer(&ch->timer);
801 fsm_addtimer(&ch->timer, CTCM_TIME_5_SEC, CTC_EVENT_TIMER, ch); 802 fsm_addtimer(&ch->timer, CTCM_TIME_5_SEC, CTC_EVENT_TIMER, ch);
802 if (!IS_MPC(ch) && (CHANNEL_DIRECTION(ch->flags) == READ)) { 803 if (!IS_MPC(ch) &&
804 (CHANNEL_DIRECTION(ch->flags) == CTCM_READ)) {
803 int rc = ccw_device_halt(ch->cdev, (unsigned long)ch); 805 int rc = ccw_device_halt(ch->cdev, (unsigned long)ch);
804 if (rc != 0) 806 if (rc != 0)
805 ctcm_ccw_check_rc(ch, rc, 807 ctcm_ccw_check_rc(ch, rc,
@@ -811,10 +813,10 @@ static void ctcm_chx_setuperr(fsm_instance *fi, int event, void *arg)
811 CTCM_DBF_TEXT_(ERROR, CTC_DBF_CRIT, 813 CTCM_DBF_TEXT_(ERROR, CTC_DBF_CRIT,
812 "%s(%s) : %s error during %s channel setup state=%s\n", 814 "%s(%s) : %s error during %s channel setup state=%s\n",
813 CTCM_FUNTAIL, dev->name, ctc_ch_event_names[event], 815 CTCM_FUNTAIL, dev->name, ctc_ch_event_names[event],
814 (CHANNEL_DIRECTION(ch->flags) == READ) ? "RX" : "TX", 816 (CHANNEL_DIRECTION(ch->flags) == CTCM_READ) ? "RX" : "TX",
815 fsm_getstate_str(fi)); 817 fsm_getstate_str(fi));
816 818
817 if (CHANNEL_DIRECTION(ch->flags) == READ) { 819 if (CHANNEL_DIRECTION(ch->flags) == CTCM_READ) {
818 fsm_newstate(fi, CTC_STATE_RXERR); 820 fsm_newstate(fi, CTC_STATE_RXERR);
819 fsm_event(priv->fsm, DEV_EVENT_RXDOWN, dev); 821 fsm_event(priv->fsm, DEV_EVENT_RXDOWN, dev);
820 } else { 822 } else {
@@ -945,7 +947,7 @@ static void ctcm_chx_rxdisc(fsm_instance *fi, int event, void *arg)
945 fsm_event(priv->fsm, DEV_EVENT_TXDOWN, dev); 947 fsm_event(priv->fsm, DEV_EVENT_TXDOWN, dev);
946 948
947 fsm_newstate(fi, CTC_STATE_DTERM); 949 fsm_newstate(fi, CTC_STATE_DTERM);
948 ch2 = priv->channel[WRITE]; 950 ch2 = priv->channel[CTCM_WRITE];
949 fsm_newstate(ch2->fsm, CTC_STATE_DTERM); 951 fsm_newstate(ch2->fsm, CTC_STATE_DTERM);
950 952
951 ccw_device_halt(ch->cdev, (unsigned long)ch); 953 ccw_device_halt(ch->cdev, (unsigned long)ch);
@@ -1074,13 +1076,13 @@ static void ctcm_chx_iofatal(fsm_instance *fi, int event, void *arg)
1074 fsm_deltimer(&ch->timer); 1076 fsm_deltimer(&ch->timer);
1075 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR, 1077 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
1076 "%s: %s: %s unrecoverable channel error", 1078 "%s: %s: %s unrecoverable channel error",
1077 CTCM_FUNTAIL, ch->id, rd == READ ? "RX" : "TX"); 1079 CTCM_FUNTAIL, ch->id, rd == CTCM_READ ? "RX" : "TX");
1078 1080
1079 if (IS_MPC(ch)) { 1081 if (IS_MPC(ch)) {
1080 priv->stats.tx_dropped++; 1082 priv->stats.tx_dropped++;
1081 priv->stats.tx_errors++; 1083 priv->stats.tx_errors++;
1082 } 1084 }
1083 if (rd == READ) { 1085 if (rd == CTCM_READ) {
1084 fsm_newstate(fi, CTC_STATE_RXERR); 1086 fsm_newstate(fi, CTC_STATE_RXERR);
1085 fsm_event(priv->fsm, DEV_EVENT_RXDOWN, dev); 1087 fsm_event(priv->fsm, DEV_EVENT_RXDOWN, dev);
1086 } else { 1088 } else {
@@ -1503,7 +1505,7 @@ static void ctcmpc_chx_firstio(fsm_instance *fi, int event, void *arg)
1503 switch (fsm_getstate(fi)) { 1505 switch (fsm_getstate(fi)) {
1504 case CTC_STATE_STARTRETRY: 1506 case CTC_STATE_STARTRETRY:
1505 case CTC_STATE_SETUPWAIT: 1507 case CTC_STATE_SETUPWAIT:
1506 if (CHANNEL_DIRECTION(ch->flags) == READ) { 1508 if (CHANNEL_DIRECTION(ch->flags) == CTCM_READ) {
1507 ctcmpc_chx_rxidle(fi, event, arg); 1509 ctcmpc_chx_rxidle(fi, event, arg);
1508 } else { 1510 } else {
1509 fsm_newstate(fi, CTC_STATE_TXIDLE); 1511 fsm_newstate(fi, CTC_STATE_TXIDLE);
@@ -1514,7 +1516,7 @@ static void ctcmpc_chx_firstio(fsm_instance *fi, int event, void *arg)
1514 break; 1516 break;
1515 }; 1517 };
1516 1518
1517 fsm_newstate(fi, (CHANNEL_DIRECTION(ch->flags) == READ) 1519 fsm_newstate(fi, (CHANNEL_DIRECTION(ch->flags) == CTCM_READ)
1518 ? CTC_STATE_RXINIT : CTC_STATE_TXINIT); 1520 ? CTC_STATE_RXINIT : CTC_STATE_TXINIT);
1519 1521
1520done: 1522done:
@@ -1753,8 +1755,8 @@ static void ctcmpc_chx_send_sweep(fsm_instance *fsm, int event, void *arg)
1753 struct net_device *dev = ach->netdev; 1755 struct net_device *dev = ach->netdev;
1754 struct ctcm_priv *priv = dev->ml_priv; 1756 struct ctcm_priv *priv = dev->ml_priv;
1755 struct mpc_group *grp = priv->mpcg; 1757 struct mpc_group *grp = priv->mpcg;
1756 struct channel *wch = priv->channel[WRITE]; 1758 struct channel *wch = priv->channel[CTCM_WRITE];
1757 struct channel *rch = priv->channel[READ]; 1759 struct channel *rch = priv->channel[CTCM_READ];
1758 struct sk_buff *skb; 1760 struct sk_buff *skb;
1759 struct th_sweep *header; 1761 struct th_sweep *header;
1760 int rc = 0; 1762 int rc = 0;
@@ -2070,7 +2072,7 @@ static void dev_action_start(fsm_instance *fi, int event, void *arg)
2070 fsm_newstate(fi, DEV_STATE_STARTWAIT_RXTX); 2072 fsm_newstate(fi, DEV_STATE_STARTWAIT_RXTX);
2071 if (IS_MPC(priv)) 2073 if (IS_MPC(priv))
2072 priv->mpcg->channels_terminating = 0; 2074 priv->mpcg->channels_terminating = 0;
2073 for (direction = READ; direction <= WRITE; direction++) { 2075 for (direction = CTCM_READ; direction <= CTCM_WRITE; direction++) {
2074 struct channel *ch = priv->channel[direction]; 2076 struct channel *ch = priv->channel[direction];
2075 fsm_event(ch->fsm, CTC_EVENT_START, ch); 2077 fsm_event(ch->fsm, CTC_EVENT_START, ch);
2076 } 2078 }
@@ -2092,7 +2094,7 @@ static void dev_action_stop(fsm_instance *fi, int event, void *arg)
2092 CTCMY_DBF_DEV_NAME(SETUP, dev, ""); 2094 CTCMY_DBF_DEV_NAME(SETUP, dev, "");
2093 2095
2094 fsm_newstate(fi, DEV_STATE_STOPWAIT_RXTX); 2096 fsm_newstate(fi, DEV_STATE_STOPWAIT_RXTX);
2095 for (direction = READ; direction <= WRITE; direction++) { 2097 for (direction = CTCM_READ; direction <= CTCM_WRITE; direction++) {
2096 struct channel *ch = priv->channel[direction]; 2098 struct channel *ch = priv->channel[direction];
2097 fsm_event(ch->fsm, CTC_EVENT_STOP, ch); 2099 fsm_event(ch->fsm, CTC_EVENT_STOP, ch);
2098 ch->th_seq_num = 0x00; 2100 ch->th_seq_num = 0x00;
@@ -2183,11 +2185,11 @@ static void dev_action_chup(fsm_instance *fi, int event, void *arg)
2183 2185
2184 if (IS_MPC(priv)) { 2186 if (IS_MPC(priv)) {
2185 if (event == DEV_EVENT_RXUP) 2187 if (event == DEV_EVENT_RXUP)
2186 mpc_channel_action(priv->channel[READ], 2188 mpc_channel_action(priv->channel[CTCM_READ],
2187 READ, MPC_CHANNEL_ADD); 2189 CTCM_READ, MPC_CHANNEL_ADD);
2188 else 2190 else
2189 mpc_channel_action(priv->channel[WRITE], 2191 mpc_channel_action(priv->channel[CTCM_WRITE],
2190 WRITE, MPC_CHANNEL_ADD); 2192 CTCM_WRITE, MPC_CHANNEL_ADD);
2191 } 2193 }
2192} 2194}
2193 2195
@@ -2239,11 +2241,11 @@ static void dev_action_chdown(fsm_instance *fi, int event, void *arg)
2239 } 2241 }
2240 if (IS_MPC(priv)) { 2242 if (IS_MPC(priv)) {
2241 if (event == DEV_EVENT_RXDOWN) 2243 if (event == DEV_EVENT_RXDOWN)
2242 mpc_channel_action(priv->channel[READ], 2244 mpc_channel_action(priv->channel[CTCM_READ],
2243 READ, MPC_CHANNEL_REMOVE); 2245 CTCM_READ, MPC_CHANNEL_REMOVE);
2244 else 2246 else
2245 mpc_channel_action(priv->channel[WRITE], 2247 mpc_channel_action(priv->channel[CTCM_WRITE],
2246 WRITE, MPC_CHANNEL_REMOVE); 2248 CTCM_WRITE, MPC_CHANNEL_REMOVE);
2247 } 2249 }
2248} 2250}
2249 2251
diff --git a/drivers/s390/net/ctcm_main.c b/drivers/s390/net/ctcm_main.c
index 4ecafbf91211..6edf20b62de5 100644
--- a/drivers/s390/net/ctcm_main.c
+++ b/drivers/s390/net/ctcm_main.c
@@ -267,7 +267,7 @@ static struct channel *channel_get(enum ctcm_channel_types type,
267 else { 267 else {
268 ch->flags |= CHANNEL_FLAGS_INUSE; 268 ch->flags |= CHANNEL_FLAGS_INUSE;
269 ch->flags &= ~CHANNEL_FLAGS_RWMASK; 269 ch->flags &= ~CHANNEL_FLAGS_RWMASK;
270 ch->flags |= (direction == WRITE) 270 ch->flags |= (direction == CTCM_WRITE)
271 ? CHANNEL_FLAGS_WRITE : CHANNEL_FLAGS_READ; 271 ? CHANNEL_FLAGS_WRITE : CHANNEL_FLAGS_READ;
272 fsm_newstate(ch->fsm, CTC_STATE_STOPPED); 272 fsm_newstate(ch->fsm, CTC_STATE_STOPPED);
273 } 273 }
@@ -388,7 +388,8 @@ int ctcm_ch_alloc_buffer(struct channel *ch)
388 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR, 388 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
389 "%s(%s): %s trans_skb allocation error", 389 "%s(%s): %s trans_skb allocation error",
390 CTCM_FUNTAIL, ch->id, 390 CTCM_FUNTAIL, ch->id,
391 (CHANNEL_DIRECTION(ch->flags) == READ) ? "RX" : "TX"); 391 (CHANNEL_DIRECTION(ch->flags) == CTCM_READ) ?
392 "RX" : "TX");
392 return -ENOMEM; 393 return -ENOMEM;
393 } 394 }
394 395
@@ -399,7 +400,8 @@ int ctcm_ch_alloc_buffer(struct channel *ch)
399 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR, 400 CTCM_DBF_TEXT_(ERROR, CTC_DBF_ERROR,
400 "%s(%s): %s set norm_cda failed", 401 "%s(%s): %s set norm_cda failed",
401 CTCM_FUNTAIL, ch->id, 402 CTCM_FUNTAIL, ch->id,
402 (CHANNEL_DIRECTION(ch->flags) == READ) ? "RX" : "TX"); 403 (CHANNEL_DIRECTION(ch->flags) == CTCM_READ) ?
404 "RX" : "TX");
403 return -ENOMEM; 405 return -ENOMEM;
404 } 406 }
405 407
@@ -603,14 +605,14 @@ static void ctcmpc_send_sweep_req(struct channel *rch)
603 605
604 priv = dev->ml_priv; 606 priv = dev->ml_priv;
605 grp = priv->mpcg; 607 grp = priv->mpcg;
606 ch = priv->channel[WRITE]; 608 ch = priv->channel[CTCM_WRITE];
607 609
608 /* sweep processing is not complete until response and request */ 610 /* sweep processing is not complete until response and request */
609 /* has completed for all read channels in group */ 611 /* has completed for all read channels in group */
610 if (grp->in_sweep == 0) { 612 if (grp->in_sweep == 0) {
611 grp->in_sweep = 1; 613 grp->in_sweep = 1;
612 grp->sweep_rsp_pend_num = grp->active_channels[READ]; 614 grp->sweep_rsp_pend_num = grp->active_channels[CTCM_READ];
613 grp->sweep_req_pend_num = grp->active_channels[READ]; 615 grp->sweep_req_pend_num = grp->active_channels[CTCM_READ];
614 } 616 }
615 617
616 sweep_skb = __dev_alloc_skb(MPC_BUFSIZE_DEFAULT, GFP_ATOMIC|GFP_DMA); 618 sweep_skb = __dev_alloc_skb(MPC_BUFSIZE_DEFAULT, GFP_ATOMIC|GFP_DMA);
@@ -911,7 +913,7 @@ static int ctcm_tx(struct sk_buff *skb, struct net_device *dev)
911 return NETDEV_TX_BUSY; 913 return NETDEV_TX_BUSY;
912 914
913 dev->trans_start = jiffies; 915 dev->trans_start = jiffies;
914 if (ctcm_transmit_skb(priv->channel[WRITE], skb) != 0) 916 if (ctcm_transmit_skb(priv->channel[CTCM_WRITE], skb) != 0)
915 return NETDEV_TX_BUSY; 917 return NETDEV_TX_BUSY;
916 return NETDEV_TX_OK; 918 return NETDEV_TX_OK;
917} 919}
@@ -994,7 +996,7 @@ static int ctcmpc_tx(struct sk_buff *skb, struct net_device *dev)
994 } 996 }
995 997
996 dev->trans_start = jiffies; 998 dev->trans_start = jiffies;
997 if (ctcmpc_transmit_skb(priv->channel[WRITE], skb) != 0) { 999 if (ctcmpc_transmit_skb(priv->channel[CTCM_WRITE], skb) != 0) {
998 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR, 1000 CTCM_DBF_TEXT_(MPC_ERROR, CTC_DBF_ERROR,
999 "%s(%s): device error - dropped", 1001 "%s(%s): device error - dropped",
1000 CTCM_FUNTAIL, dev->name); 1002 CTCM_FUNTAIL, dev->name);
@@ -1035,7 +1037,7 @@ static int ctcm_change_mtu(struct net_device *dev, int new_mtu)
1035 return -EINVAL; 1037 return -EINVAL;
1036 1038
1037 priv = dev->ml_priv; 1039 priv = dev->ml_priv;
1038 max_bufsize = priv->channel[READ]->max_bufsize; 1040 max_bufsize = priv->channel[CTCM_READ]->max_bufsize;
1039 1041
1040 if (IS_MPC(priv)) { 1042 if (IS_MPC(priv)) {
1041 if (new_mtu > max_bufsize - TH_HEADER_LENGTH) 1043 if (new_mtu > max_bufsize - TH_HEADER_LENGTH)
@@ -1226,10 +1228,10 @@ static void ctcm_irq_handler(struct ccw_device *cdev,
1226 priv = dev_get_drvdata(&cgdev->dev); 1228 priv = dev_get_drvdata(&cgdev->dev);
1227 1229
1228 /* Try to extract channel from driver data. */ 1230 /* Try to extract channel from driver data. */
1229 if (priv->channel[READ]->cdev == cdev) 1231 if (priv->channel[CTCM_READ]->cdev == cdev)
1230 ch = priv->channel[READ]; 1232 ch = priv->channel[CTCM_READ];
1231 else if (priv->channel[WRITE]->cdev == cdev) 1233 else if (priv->channel[CTCM_WRITE]->cdev == cdev)
1232 ch = priv->channel[WRITE]; 1234 ch = priv->channel[CTCM_WRITE];
1233 else { 1235 else {
1234 dev_err(&cdev->dev, 1236 dev_err(&cdev->dev,
1235 "%s: Internal error: Can't determine channel for " 1237 "%s: Internal error: Can't determine channel for "
@@ -1587,13 +1589,13 @@ static int ctcm_new_device(struct ccwgroup_device *cgdev)
1587 goto out_ccw2; 1589 goto out_ccw2;
1588 } 1590 }
1589 1591
1590 for (direction = READ; direction <= WRITE; direction++) { 1592 for (direction = CTCM_READ; direction <= CTCM_WRITE; direction++) {
1591 priv->channel[direction] = 1593 priv->channel[direction] =
1592 channel_get(type, direction == READ ? read_id : write_id, 1594 channel_get(type, direction == CTCM_READ ?
1593 direction); 1595 read_id : write_id, direction);
1594 if (priv->channel[direction] == NULL) { 1596 if (priv->channel[direction] == NULL) {
1595 if (direction == WRITE) 1597 if (direction == CTCM_WRITE)
1596 channel_free(priv->channel[READ]); 1598 channel_free(priv->channel[CTCM_READ]);
1597 goto out_dev; 1599 goto out_dev;
1598 } 1600 }
1599 priv->channel[direction]->netdev = dev; 1601 priv->channel[direction]->netdev = dev;
@@ -1617,13 +1619,13 @@ static int ctcm_new_device(struct ccwgroup_device *cgdev)
1617 1619
1618 dev_info(&dev->dev, 1620 dev_info(&dev->dev,
1619 "setup OK : r/w = %s/%s, protocol : %d\n", 1621 "setup OK : r/w = %s/%s, protocol : %d\n",
1620 priv->channel[READ]->id, 1622 priv->channel[CTCM_READ]->id,
1621 priv->channel[WRITE]->id, priv->protocol); 1623 priv->channel[CTCM_WRITE]->id, priv->protocol);
1622 1624
1623 CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO, 1625 CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO,
1624 "setup(%s) OK : r/w = %s/%s, protocol : %d", dev->name, 1626 "setup(%s) OK : r/w = %s/%s, protocol : %d", dev->name,
1625 priv->channel[READ]->id, 1627 priv->channel[CTCM_READ]->id,
1626 priv->channel[WRITE]->id, priv->protocol); 1628 priv->channel[CTCM_WRITE]->id, priv->protocol);
1627 1629
1628 return 0; 1630 return 0;
1629out_unregister: 1631out_unregister:
@@ -1635,10 +1637,10 @@ out_ccw2:
1635out_ccw1: 1637out_ccw1:
1636 ccw_device_set_offline(cgdev->cdev[0]); 1638 ccw_device_set_offline(cgdev->cdev[0]);
1637out_remove_channel2: 1639out_remove_channel2:
1638 readc = channel_get(type, read_id, READ); 1640 readc = channel_get(type, read_id, CTCM_READ);
1639 channel_remove(readc); 1641 channel_remove(readc);
1640out_remove_channel1: 1642out_remove_channel1:
1641 writec = channel_get(type, write_id, WRITE); 1643 writec = channel_get(type, write_id, CTCM_WRITE);
1642 channel_remove(writec); 1644 channel_remove(writec);
1643out_err_result: 1645out_err_result:
1644 return result; 1646 return result;
@@ -1660,19 +1662,19 @@ static int ctcm_shutdown_device(struct ccwgroup_device *cgdev)
1660 if (!priv) 1662 if (!priv)
1661 return -ENODEV; 1663 return -ENODEV;
1662 1664
1663 if (priv->channel[READ]) { 1665 if (priv->channel[CTCM_READ]) {
1664 dev = priv->channel[READ]->netdev; 1666 dev = priv->channel[CTCM_READ]->netdev;
1665 CTCM_DBF_DEV(SETUP, dev, ""); 1667 CTCM_DBF_DEV(SETUP, dev, "");
1666 /* Close the device */ 1668 /* Close the device */
1667 ctcm_close(dev); 1669 ctcm_close(dev);
1668 dev->flags &= ~IFF_RUNNING; 1670 dev->flags &= ~IFF_RUNNING;
1669 ctcm_remove_attributes(&cgdev->dev); 1671 ctcm_remove_attributes(&cgdev->dev);
1670 channel_free(priv->channel[READ]); 1672 channel_free(priv->channel[CTCM_READ]);
1671 } else 1673 } else
1672 dev = NULL; 1674 dev = NULL;
1673 1675
1674 if (priv->channel[WRITE]) 1676 if (priv->channel[CTCM_WRITE])
1675 channel_free(priv->channel[WRITE]); 1677 channel_free(priv->channel[CTCM_WRITE]);
1676 1678
1677 if (dev) { 1679 if (dev) {
1678 unregister_netdev(dev); 1680 unregister_netdev(dev);
@@ -1685,11 +1687,11 @@ static int ctcm_shutdown_device(struct ccwgroup_device *cgdev)
1685 ccw_device_set_offline(cgdev->cdev[1]); 1687 ccw_device_set_offline(cgdev->cdev[1]);
1686 ccw_device_set_offline(cgdev->cdev[0]); 1688 ccw_device_set_offline(cgdev->cdev[0]);
1687 1689
1688 if (priv->channel[READ]) 1690 if (priv->channel[CTCM_READ])
1689 channel_remove(priv->channel[READ]); 1691 channel_remove(priv->channel[CTCM_READ]);
1690 if (priv->channel[WRITE]) 1692 if (priv->channel[CTCM_WRITE])
1691 channel_remove(priv->channel[WRITE]); 1693 channel_remove(priv->channel[CTCM_WRITE]);
1692 priv->channel[READ] = priv->channel[WRITE] = NULL; 1694 priv->channel[CTCM_READ] = priv->channel[CTCM_WRITE] = NULL;
1693 1695
1694 return 0; 1696 return 0;
1695 1697
@@ -1720,11 +1722,11 @@ static int ctcm_pm_suspend(struct ccwgroup_device *gdev)
1720 1722
1721 if (gdev->state == CCWGROUP_OFFLINE) 1723 if (gdev->state == CCWGROUP_OFFLINE)
1722 return 0; 1724 return 0;
1723 netif_device_detach(priv->channel[READ]->netdev); 1725 netif_device_detach(priv->channel[CTCM_READ]->netdev);
1724 ctcm_close(priv->channel[READ]->netdev); 1726 ctcm_close(priv->channel[CTCM_READ]->netdev);
1725 if (!wait_event_timeout(priv->fsm->wait_q, 1727 if (!wait_event_timeout(priv->fsm->wait_q,
1726 fsm_getstate(priv->fsm) == DEV_STATE_STOPPED, CTCM_TIME_5_SEC)) { 1728 fsm_getstate(priv->fsm) == DEV_STATE_STOPPED, CTCM_TIME_5_SEC)) {
1727 netif_device_attach(priv->channel[READ]->netdev); 1729 netif_device_attach(priv->channel[CTCM_READ]->netdev);
1728 return -EBUSY; 1730 return -EBUSY;
1729 } 1731 }
1730 ccw_device_set_offline(gdev->cdev[1]); 1732 ccw_device_set_offline(gdev->cdev[1]);
@@ -1745,9 +1747,9 @@ static int ctcm_pm_resume(struct ccwgroup_device *gdev)
1745 rc = ccw_device_set_online(gdev->cdev[0]); 1747 rc = ccw_device_set_online(gdev->cdev[0]);
1746 if (rc) 1748 if (rc)
1747 goto err_out; 1749 goto err_out;
1748 ctcm_open(priv->channel[READ]->netdev); 1750 ctcm_open(priv->channel[CTCM_READ]->netdev);
1749err_out: 1751err_out:
1750 netif_device_attach(priv->channel[READ]->netdev); 1752 netif_device_attach(priv->channel[CTCM_READ]->netdev);
1751 return rc; 1753 return rc;
1752} 1754}
1753 1755
diff --git a/drivers/s390/net/ctcm_main.h b/drivers/s390/net/ctcm_main.h
index d34fa14f44e7..24d5215eb0c4 100644
--- a/drivers/s390/net/ctcm_main.h
+++ b/drivers/s390/net/ctcm_main.h
@@ -111,8 +111,8 @@ enum ctcm_channel_types {
111 111
112#define CTCM_INITIAL_BLOCKLEN 2 112#define CTCM_INITIAL_BLOCKLEN 2
113 113
114#define READ 0 114#define CTCM_READ 0
115#define WRITE 1 115#define CTCM_WRITE 1
116 116
117#define CTCM_ID_SIZE 20+3 117#define CTCM_ID_SIZE 20+3
118 118
diff --git a/drivers/s390/net/ctcm_mpc.c b/drivers/s390/net/ctcm_mpc.c
index 87c24d2936d6..2861e78773cb 100644
--- a/drivers/s390/net/ctcm_mpc.c
+++ b/drivers/s390/net/ctcm_mpc.c
@@ -419,8 +419,8 @@ void ctc_mpc_establish_connectivity(int port_num,
419 return; 419 return;
420 priv = dev->ml_priv; 420 priv = dev->ml_priv;
421 grp = priv->mpcg; 421 grp = priv->mpcg;
422 rch = priv->channel[READ]; 422 rch = priv->channel[CTCM_READ];
423 wch = priv->channel[WRITE]; 423 wch = priv->channel[CTCM_WRITE];
424 424
425 CTCM_DBF_TEXT_(MPC_SETUP, CTC_DBF_INFO, 425 CTCM_DBF_TEXT_(MPC_SETUP, CTC_DBF_INFO,
426 "%s(%s): state=%s", 426 "%s(%s): state=%s",
@@ -578,7 +578,7 @@ void ctc_mpc_flow_control(int port_num, int flowc)
578 "%s: %s: flowc = %d", 578 "%s: %s: flowc = %d",
579 CTCM_FUNTAIL, dev->name, flowc); 579 CTCM_FUNTAIL, dev->name, flowc);
580 580
581 rch = priv->channel[READ]; 581 rch = priv->channel[CTCM_READ];
582 582
583 mpcg_state = fsm_getstate(grp->fsm); 583 mpcg_state = fsm_getstate(grp->fsm);
584 switch (flowc) { 584 switch (flowc) {
@@ -622,7 +622,7 @@ static void mpc_rcvd_sweep_resp(struct mpcg_info *mpcginfo)
622 struct net_device *dev = rch->netdev; 622 struct net_device *dev = rch->netdev;
623 struct ctcm_priv *priv = dev->ml_priv; 623 struct ctcm_priv *priv = dev->ml_priv;
624 struct mpc_group *grp = priv->mpcg; 624 struct mpc_group *grp = priv->mpcg;
625 struct channel *ch = priv->channel[WRITE]; 625 struct channel *ch = priv->channel[CTCM_WRITE];
626 626
627 CTCM_PR_DEBUG("%s: ch=0x%p id=%s\n", __func__, ch, ch->id); 627 CTCM_PR_DEBUG("%s: ch=0x%p id=%s\n", __func__, ch, ch->id);
628 CTCM_D3_DUMP((char *)mpcginfo->sweep, TH_SWEEP_LENGTH); 628 CTCM_D3_DUMP((char *)mpcginfo->sweep, TH_SWEEP_LENGTH);
@@ -656,7 +656,7 @@ static void ctcmpc_send_sweep_resp(struct channel *rch)
656 int rc = 0; 656 int rc = 0;
657 struct th_sweep *header; 657 struct th_sweep *header;
658 struct sk_buff *sweep_skb; 658 struct sk_buff *sweep_skb;
659 struct channel *ch = priv->channel[WRITE]; 659 struct channel *ch = priv->channel[CTCM_WRITE];
660 660
661 CTCM_PR_DEBUG("%s: ch=0x%p id=%s\n", __func__, rch, rch->id); 661 CTCM_PR_DEBUG("%s: ch=0x%p id=%s\n", __func__, rch, rch->id);
662 662
@@ -712,7 +712,7 @@ static void mpc_rcvd_sweep_req(struct mpcg_info *mpcginfo)
712 struct net_device *dev = rch->netdev; 712 struct net_device *dev = rch->netdev;
713 struct ctcm_priv *priv = dev->ml_priv; 713 struct ctcm_priv *priv = dev->ml_priv;
714 struct mpc_group *grp = priv->mpcg; 714 struct mpc_group *grp = priv->mpcg;
715 struct channel *ch = priv->channel[WRITE]; 715 struct channel *ch = priv->channel[CTCM_WRITE];
716 716
717 if (do_debug) 717 if (do_debug)
718 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_DEBUG, 718 CTCM_DBF_TEXT_(MPC_TRACE, CTC_DBF_DEBUG,
@@ -721,8 +721,8 @@ static void mpc_rcvd_sweep_req(struct mpcg_info *mpcginfo)
721 if (grp->in_sweep == 0) { 721 if (grp->in_sweep == 0) {
722 grp->in_sweep = 1; 722 grp->in_sweep = 1;
723 ctcm_test_and_set_busy(dev); 723 ctcm_test_and_set_busy(dev);
724 grp->sweep_req_pend_num = grp->active_channels[READ]; 724 grp->sweep_req_pend_num = grp->active_channels[CTCM_READ];
725 grp->sweep_rsp_pend_num = grp->active_channels[READ]; 725 grp->sweep_rsp_pend_num = grp->active_channels[CTCM_READ];
726 } 726 }
727 727
728 CTCM_D3_DUMP((char *)mpcginfo->sweep, TH_SWEEP_LENGTH); 728 CTCM_D3_DUMP((char *)mpcginfo->sweep, TH_SWEEP_LENGTH);
@@ -906,14 +906,14 @@ void mpc_group_ready(unsigned long adev)
906 fsm_newstate(grp->fsm, MPCG_STATE_READY); 906 fsm_newstate(grp->fsm, MPCG_STATE_READY);
907 907
908 /* Put up a read on the channel */ 908 /* Put up a read on the channel */
909 ch = priv->channel[READ]; 909 ch = priv->channel[CTCM_READ];
910 ch->pdu_seq = 0; 910 ch->pdu_seq = 0;
911 CTCM_PR_DBGDATA("ctcmpc: %s() ToDCM_pdu_seq= %08x\n" , 911 CTCM_PR_DBGDATA("ctcmpc: %s() ToDCM_pdu_seq= %08x\n" ,
912 __func__, ch->pdu_seq); 912 __func__, ch->pdu_seq);
913 913
914 ctcmpc_chx_rxidle(ch->fsm, CTC_EVENT_START, ch); 914 ctcmpc_chx_rxidle(ch->fsm, CTC_EVENT_START, ch);
915 /* Put the write channel in idle state */ 915 /* Put the write channel in idle state */
916 ch = priv->channel[WRITE]; 916 ch = priv->channel[CTCM_WRITE];
917 if (ch->collect_len > 0) { 917 if (ch->collect_len > 0) {
918 spin_lock(&ch->collect_lock); 918 spin_lock(&ch->collect_lock);
919 ctcm_purge_skb_queue(&ch->collect_queue); 919 ctcm_purge_skb_queue(&ch->collect_queue);
@@ -960,7 +960,8 @@ void mpc_channel_action(struct channel *ch, int direction, int action)
960 "%s: %i / Grp:%s total_channels=%i, active_channels: " 960 "%s: %i / Grp:%s total_channels=%i, active_channels: "
961 "read=%i, write=%i\n", __func__, action, 961 "read=%i, write=%i\n", __func__, action,
962 fsm_getstate_str(grp->fsm), grp->num_channel_paths, 962 fsm_getstate_str(grp->fsm), grp->num_channel_paths,
963 grp->active_channels[READ], grp->active_channels[WRITE]); 963 grp->active_channels[CTCM_READ],
964 grp->active_channels[CTCM_WRITE]);
964 965
965 if ((action == MPC_CHANNEL_ADD) && (ch->in_mpcgroup == 0)) { 966 if ((action == MPC_CHANNEL_ADD) && (ch->in_mpcgroup == 0)) {
966 grp->num_channel_paths++; 967 grp->num_channel_paths++;
@@ -994,10 +995,11 @@ void mpc_channel_action(struct channel *ch, int direction, int action)
994 grp->xid_skb->data, 995 grp->xid_skb->data,
995 grp->xid_skb->len); 996 grp->xid_skb->len);
996 997
997 ch->xid->xid2_dlc_type = ((CHANNEL_DIRECTION(ch->flags) == READ) 998 ch->xid->xid2_dlc_type =
999 ((CHANNEL_DIRECTION(ch->flags) == CTCM_READ)
998 ? XID2_READ_SIDE : XID2_WRITE_SIDE); 1000 ? XID2_READ_SIDE : XID2_WRITE_SIDE);
999 1001
1000 if (CHANNEL_DIRECTION(ch->flags) == WRITE) 1002 if (CHANNEL_DIRECTION(ch->flags) == CTCM_WRITE)
1001 ch->xid->xid2_buf_len = 0x00; 1003 ch->xid->xid2_buf_len = 0x00;
1002 1004
1003 ch->xid_skb->data = ch->xid_skb_data; 1005 ch->xid_skb->data = ch->xid_skb_data;
@@ -1006,8 +1008,8 @@ void mpc_channel_action(struct channel *ch, int direction, int action)
1006 1008
1007 fsm_newstate(ch->fsm, CH_XID0_PENDING); 1009 fsm_newstate(ch->fsm, CH_XID0_PENDING);
1008 1010
1009 if ((grp->active_channels[READ] > 0) && 1011 if ((grp->active_channels[CTCM_READ] > 0) &&
1010 (grp->active_channels[WRITE] > 0) && 1012 (grp->active_channels[CTCM_WRITE] > 0) &&
1011 (fsm_getstate(grp->fsm) < MPCG_STATE_XID2INITW)) { 1013 (fsm_getstate(grp->fsm) < MPCG_STATE_XID2INITW)) {
1012 fsm_newstate(grp->fsm, MPCG_STATE_XID2INITW); 1014 fsm_newstate(grp->fsm, MPCG_STATE_XID2INITW);
1013 CTCM_DBF_TEXT_(MPC_SETUP, CTC_DBF_NOTICE, 1015 CTCM_DBF_TEXT_(MPC_SETUP, CTC_DBF_NOTICE,
@@ -1027,10 +1029,10 @@ void mpc_channel_action(struct channel *ch, int direction, int action)
1027 if (grp->channels_terminating) 1029 if (grp->channels_terminating)
1028 goto done; 1030 goto done;
1029 1031
1030 if (((grp->active_channels[READ] == 0) && 1032 if (((grp->active_channels[CTCM_READ] == 0) &&
1031 (grp->active_channels[WRITE] > 0)) 1033 (grp->active_channels[CTCM_WRITE] > 0))
1032 || ((grp->active_channels[WRITE] == 0) && 1034 || ((grp->active_channels[CTCM_WRITE] == 0) &&
1033 (grp->active_channels[READ] > 0))) 1035 (grp->active_channels[CTCM_READ] > 0)))
1034 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev); 1036 fsm_event(grp->fsm, MPCG_EVENT_INOP, dev);
1035 } 1037 }
1036done: 1038done:
@@ -1038,7 +1040,8 @@ done:
1038 "exit %s: %i / Grp:%s total_channels=%i, active_channels: " 1040 "exit %s: %i / Grp:%s total_channels=%i, active_channels: "
1039 "read=%i, write=%i\n", __func__, action, 1041 "read=%i, write=%i\n", __func__, action,
1040 fsm_getstate_str(grp->fsm), grp->num_channel_paths, 1042 fsm_getstate_str(grp->fsm), grp->num_channel_paths,
1041 grp->active_channels[READ], grp->active_channels[WRITE]); 1043 grp->active_channels[CTCM_READ],
1044 grp->active_channels[CTCM_WRITE]);
1042 1045
1043 CTCM_PR_DEBUG("exit %s: ch=0x%p id=%s\n", __func__, ch, ch->id); 1046 CTCM_PR_DEBUG("exit %s: ch=0x%p id=%s\n", __func__, ch, ch->id);
1044} 1047}
@@ -1392,8 +1395,8 @@ static void mpc_action_go_inop(fsm_instance *fi, int event, void *arg)
1392 (grp->port_persist == 0)) 1395 (grp->port_persist == 0))
1393 fsm_deltimer(&priv->restart_timer); 1396 fsm_deltimer(&priv->restart_timer);
1394 1397
1395 wch = priv->channel[WRITE]; 1398 wch = priv->channel[CTCM_WRITE];
1396 rch = priv->channel[READ]; 1399 rch = priv->channel[CTCM_READ];
1397 1400
1398 switch (grp->saved_state) { 1401 switch (grp->saved_state) {
1399 case MPCG_STATE_RESET: 1402 case MPCG_STATE_RESET:
@@ -1480,8 +1483,8 @@ static void mpc_action_timeout(fsm_instance *fi, int event, void *arg)
1480 1483
1481 priv = dev->ml_priv; 1484 priv = dev->ml_priv;
1482 grp = priv->mpcg; 1485 grp = priv->mpcg;
1483 wch = priv->channel[WRITE]; 1486 wch = priv->channel[CTCM_WRITE];
1484 rch = priv->channel[READ]; 1487 rch = priv->channel[CTCM_READ];
1485 1488
1486 switch (fsm_getstate(grp->fsm)) { 1489 switch (fsm_getstate(grp->fsm)) {
1487 case MPCG_STATE_XID2INITW: 1490 case MPCG_STATE_XID2INITW:
@@ -1586,7 +1589,7 @@ static int mpc_validate_xid(struct mpcg_info *mpcginfo)
1586 CTCM_D3_DUMP((char *)xid, XID2_LENGTH); 1589 CTCM_D3_DUMP((char *)xid, XID2_LENGTH);
1587 1590
1588 /*the received direction should be the opposite of ours */ 1591 /*the received direction should be the opposite of ours */
1589 if (((CHANNEL_DIRECTION(ch->flags) == READ) ? XID2_WRITE_SIDE : 1592 if (((CHANNEL_DIRECTION(ch->flags) == CTCM_READ) ? XID2_WRITE_SIDE :
1590 XID2_READ_SIDE) != xid->xid2_dlc_type) { 1593 XID2_READ_SIDE) != xid->xid2_dlc_type) {
1591 rc = 2; 1594 rc = 2;
1592 /* XID REJECTED: r/w channel pairing mismatch */ 1595 /* XID REJECTED: r/w channel pairing mismatch */
@@ -1912,7 +1915,7 @@ static void mpc_action_doxid7(fsm_instance *fsm, int event, void *arg)
1912 if (grp == NULL) 1915 if (grp == NULL)
1913 return; 1916 return;
1914 1917
1915 for (direction = READ; direction <= WRITE; direction++) { 1918 for (direction = CTCM_READ; direction <= CTCM_WRITE; direction++) {
1916 struct channel *ch = priv->channel[direction]; 1919 struct channel *ch = priv->channel[direction];
1917 struct xid2 *thisxid = ch->xid; 1920 struct xid2 *thisxid = ch->xid;
1918 ch->xid_skb->data = ch->xid_skb_data; 1921 ch->xid_skb->data = ch->xid_skb_data;
@@ -2152,14 +2155,15 @@ static int mpc_send_qllc_discontact(struct net_device *dev)
2152 return -ENOMEM; 2155 return -ENOMEM;
2153 } 2156 }
2154 2157
2155 *((__u32 *)skb_push(skb, 4)) = priv->channel[READ]->pdu_seq; 2158 *((__u32 *)skb_push(skb, 4)) =
2156 priv->channel[READ]->pdu_seq++; 2159 priv->channel[CTCM_READ]->pdu_seq;
2160 priv->channel[CTCM_READ]->pdu_seq++;
2157 CTCM_PR_DBGDATA("ctcmpc: %s ToDCM_pdu_seq= %08x\n", 2161 CTCM_PR_DBGDATA("ctcmpc: %s ToDCM_pdu_seq= %08x\n",
2158 __func__, priv->channel[READ]->pdu_seq); 2162 __func__, priv->channel[CTCM_READ]->pdu_seq);
2159 2163
2160 /* receipt of CC03 resets anticipated sequence number on 2164 /* receipt of CC03 resets anticipated sequence number on
2161 receiving side */ 2165 receiving side */
2162 priv->channel[READ]->pdu_seq = 0x00; 2166 priv->channel[CTCM_READ]->pdu_seq = 0x00;
2163 skb_reset_mac_header(skb); 2167 skb_reset_mac_header(skb);
2164 skb->dev = dev; 2168 skb->dev = dev;
2165 skb->protocol = htons(ETH_P_SNAP); 2169 skb->protocol = htons(ETH_P_SNAP);
diff --git a/drivers/s390/net/ctcm_sysfs.c b/drivers/s390/net/ctcm_sysfs.c
index 2b24550e865e..8305319b2a84 100644
--- a/drivers/s390/net/ctcm_sysfs.c
+++ b/drivers/s390/net/ctcm_sysfs.c
@@ -38,8 +38,8 @@ static ssize_t ctcm_buffer_write(struct device *dev,
38 int bs1; 38 int bs1;
39 struct ctcm_priv *priv = dev_get_drvdata(dev); 39 struct ctcm_priv *priv = dev_get_drvdata(dev);
40 40
41 if (!(priv && priv->channel[READ] && 41 ndev = priv->channel[CTCM_READ]->netdev;
42 (ndev = priv->channel[READ]->netdev))) { 42 if (!(priv && priv->channel[CTCM_READ] && ndev)) {
43 CTCM_DBF_TEXT(SETUP, CTC_DBF_ERROR, "bfnondev"); 43 CTCM_DBF_TEXT(SETUP, CTC_DBF_ERROR, "bfnondev");
44 return -ENODEV; 44 return -ENODEV;
45 } 45 }
@@ -55,12 +55,12 @@ static ssize_t ctcm_buffer_write(struct device *dev,
55 (bs1 < (ndev->mtu + LL_HEADER_LENGTH + 2))) 55 (bs1 < (ndev->mtu + LL_HEADER_LENGTH + 2)))
56 goto einval; 56 goto einval;
57 57
58 priv->channel[READ]->max_bufsize = bs1; 58 priv->channel[CTCM_READ]->max_bufsize = bs1;
59 priv->channel[WRITE]->max_bufsize = bs1; 59 priv->channel[CTCM_WRITE]->max_bufsize = bs1;
60 if (!(ndev->flags & IFF_RUNNING)) 60 if (!(ndev->flags & IFF_RUNNING))
61 ndev->mtu = bs1 - LL_HEADER_LENGTH - 2; 61 ndev->mtu = bs1 - LL_HEADER_LENGTH - 2;
62 priv->channel[READ]->flags |= CHANNEL_FLAGS_BUFSIZE_CHANGED; 62 priv->channel[CTCM_READ]->flags |= CHANNEL_FLAGS_BUFSIZE_CHANGED;
63 priv->channel[WRITE]->flags |= CHANNEL_FLAGS_BUFSIZE_CHANGED; 63 priv->channel[CTCM_WRITE]->flags |= CHANNEL_FLAGS_BUFSIZE_CHANGED;
64 64
65 CTCM_DBF_DEV(SETUP, ndev, buf); 65 CTCM_DBF_DEV(SETUP, ndev, buf);
66 return count; 66 return count;
@@ -85,9 +85,9 @@ static void ctcm_print_statistics(struct ctcm_priv *priv)
85 p += sprintf(p, " Device FSM state: %s\n", 85 p += sprintf(p, " Device FSM state: %s\n",
86 fsm_getstate_str(priv->fsm)); 86 fsm_getstate_str(priv->fsm));
87 p += sprintf(p, " RX channel FSM state: %s\n", 87 p += sprintf(p, " RX channel FSM state: %s\n",
88 fsm_getstate_str(priv->channel[READ]->fsm)); 88 fsm_getstate_str(priv->channel[CTCM_READ]->fsm));
89 p += sprintf(p, " TX channel FSM state: %s\n", 89 p += sprintf(p, " TX channel FSM state: %s\n",
90 fsm_getstate_str(priv->channel[WRITE]->fsm)); 90 fsm_getstate_str(priv->channel[CTCM_WRITE]->fsm));
91 p += sprintf(p, " Max. TX buffer used: %ld\n", 91 p += sprintf(p, " Max. TX buffer used: %ld\n",
92 priv->channel[WRITE]->prof.maxmulti); 92 priv->channel[WRITE]->prof.maxmulti);
93 p += sprintf(p, " Max. chained SKBs: %ld\n", 93 p += sprintf(p, " Max. chained SKBs: %ld\n",
@@ -102,7 +102,7 @@ static void ctcm_print_statistics(struct ctcm_priv *priv)
102 priv->channel[WRITE]->prof.tx_time); 102 priv->channel[WRITE]->prof.tx_time);
103 103
104 printk(KERN_INFO "Statistics for %s:\n%s", 104 printk(KERN_INFO "Statistics for %s:\n%s",
105 priv->channel[WRITE]->netdev->name, sbuf); 105 priv->channel[CTCM_WRITE]->netdev->name, sbuf);
106 kfree(sbuf); 106 kfree(sbuf);
107 return; 107 return;
108} 108}
@@ -125,7 +125,7 @@ static ssize_t stats_write(struct device *dev, struct device_attribute *attr,
125 return -ENODEV; 125 return -ENODEV;
126 /* Reset statistics */ 126 /* Reset statistics */
127 memset(&priv->channel[WRITE]->prof, 0, 127 memset(&priv->channel[WRITE]->prof, 0,
128 sizeof(priv->channel[WRITE]->prof)); 128 sizeof(priv->channel[CTCM_WRITE]->prof));
129 return count; 129 return count;
130} 130}
131 131
diff --git a/drivers/s390/net/smsgiucv_app.c b/drivers/s390/net/smsgiucv_app.c
index 137688790207..4d2ea4000422 100644
--- a/drivers/s390/net/smsgiucv_app.c
+++ b/drivers/s390/net/smsgiucv_app.c
@@ -180,6 +180,13 @@ static int __init smsgiucv_app_init(void)
180 goto fail_put_driver; 180 goto fail_put_driver;
181 } 181 }
182 182
183 /* convert sender to uppercase characters */
184 if (sender) {
185 int len = strlen(sender);
186 while (len--)
187 sender[len] = toupper(sender[len]);
188 }
189
183 /* register with the smsgiucv device driver */ 190 /* register with the smsgiucv device driver */
184 rc = smsg_register_callback(SMSG_PREFIX, smsg_app_callback); 191 rc = smsg_register_callback(SMSG_PREFIX, smsg_app_callback);
185 if (rc) { 192 if (rc) {
diff --git a/drivers/sbus/char/bbc_envctrl.c b/drivers/sbus/char/bbc_envctrl.c
index 103fdf6b0b89..160e7510aca6 100644
--- a/drivers/sbus/char/bbc_envctrl.c
+++ b/drivers/sbus/char/bbc_envctrl.c
@@ -443,7 +443,7 @@ static int kenvctrld(void *__unused)
443 return 0; 443 return 0;
444} 444}
445 445
446static void attach_one_temp(struct bbc_i2c_bus *bp, struct of_device *op, 446static void attach_one_temp(struct bbc_i2c_bus *bp, struct platform_device *op,
447 int temp_idx) 447 int temp_idx)
448{ 448{
449 struct bbc_cpu_temperature *tp; 449 struct bbc_cpu_temperature *tp;
@@ -488,7 +488,7 @@ static void attach_one_temp(struct bbc_i2c_bus *bp, struct of_device *op,
488 tp->fan_todo[FAN_CPU] = FAN_SAME; 488 tp->fan_todo[FAN_CPU] = FAN_SAME;
489} 489}
490 490
491static void attach_one_fan(struct bbc_i2c_bus *bp, struct of_device *op, 491static void attach_one_fan(struct bbc_i2c_bus *bp, struct platform_device *op,
492 int fan_idx) 492 int fan_idx)
493{ 493{
494 struct bbc_fan_control *fp; 494 struct bbc_fan_control *fp;
@@ -559,7 +559,7 @@ static void destroy_all_fans(struct bbc_i2c_bus *bp)
559 559
560int bbc_envctrl_init(struct bbc_i2c_bus *bp) 560int bbc_envctrl_init(struct bbc_i2c_bus *bp)
561{ 561{
562 struct of_device *op; 562 struct platform_device *op;
563 int temp_index = 0; 563 int temp_index = 0;
564 int fan_index = 0; 564 int fan_index = 0;
565 int devidx = 0; 565 int devidx = 0;
diff --git a/drivers/sbus/char/bbc_i2c.c b/drivers/sbus/char/bbc_i2c.c
index 3e89c313e98d..614a5e114a19 100644
--- a/drivers/sbus/char/bbc_i2c.c
+++ b/drivers/sbus/char/bbc_i2c.c
@@ -51,7 +51,7 @@
51 * The second controller also connects to the smartcard reader, if present. 51 * The second controller also connects to the smartcard reader, if present.
52 */ 52 */
53 53
54static void set_device_claimage(struct bbc_i2c_bus *bp, struct of_device *op, int val) 54static void set_device_claimage(struct bbc_i2c_bus *bp, struct platform_device *op, int val)
55{ 55{
56 int i; 56 int i;
57 57
@@ -66,9 +66,9 @@ static void set_device_claimage(struct bbc_i2c_bus *bp, struct of_device *op, in
66#define claim_device(BP,ECHILD) set_device_claimage(BP,ECHILD,1) 66#define claim_device(BP,ECHILD) set_device_claimage(BP,ECHILD,1)
67#define release_device(BP,ECHILD) set_device_claimage(BP,ECHILD,0) 67#define release_device(BP,ECHILD) set_device_claimage(BP,ECHILD,0)
68 68
69struct of_device *bbc_i2c_getdev(struct bbc_i2c_bus *bp, int index) 69struct platform_device *bbc_i2c_getdev(struct bbc_i2c_bus *bp, int index)
70{ 70{
71 struct of_device *op = NULL; 71 struct platform_device *op = NULL;
72 int curidx = 0, i; 72 int curidx = 0, i;
73 73
74 for (i = 0; i < NUM_CHILDREN; i++) { 74 for (i = 0; i < NUM_CHILDREN; i++) {
@@ -86,7 +86,7 @@ out:
86 return NULL; 86 return NULL;
87} 87}
88 88
89struct bbc_i2c_client *bbc_i2c_attach(struct bbc_i2c_bus *bp, struct of_device *op) 89struct bbc_i2c_client *bbc_i2c_attach(struct bbc_i2c_bus *bp, struct platform_device *op)
90{ 90{
91 struct bbc_i2c_client *client; 91 struct bbc_i2c_client *client;
92 const u32 *reg; 92 const u32 *reg;
@@ -114,7 +114,7 @@ struct bbc_i2c_client *bbc_i2c_attach(struct bbc_i2c_bus *bp, struct of_device *
114void bbc_i2c_detach(struct bbc_i2c_client *client) 114void bbc_i2c_detach(struct bbc_i2c_client *client)
115{ 115{
116 struct bbc_i2c_bus *bp = client->bp; 116 struct bbc_i2c_bus *bp = client->bp;
117 struct of_device *op = client->op; 117 struct platform_device *op = client->op;
118 118
119 release_device(bp, op); 119 release_device(bp, op);
120 kfree(client); 120 kfree(client);
@@ -297,7 +297,7 @@ static void __init reset_one_i2c(struct bbc_i2c_bus *bp)
297 writeb(I2C_PCF_IDLE, bp->i2c_control_regs + 0x0); 297 writeb(I2C_PCF_IDLE, bp->i2c_control_regs + 0x0);
298} 298}
299 299
300static struct bbc_i2c_bus * __init attach_one_i2c(struct of_device *op, int index) 300static struct bbc_i2c_bus * __init attach_one_i2c(struct platform_device *op, int index)
301{ 301{
302 struct bbc_i2c_bus *bp; 302 struct bbc_i2c_bus *bp;
303 struct device_node *dp; 303 struct device_node *dp;
@@ -330,7 +330,7 @@ static struct bbc_i2c_bus * __init attach_one_i2c(struct of_device *op, int inde
330 for (dp = op->dev.of_node->child; 330 for (dp = op->dev.of_node->child;
331 dp && entry < 8; 331 dp && entry < 8;
332 dp = dp->sibling, entry++) { 332 dp = dp->sibling, entry++) {
333 struct of_device *child_op; 333 struct platform_device *child_op;
334 334
335 child_op = of_find_device_by_node(dp); 335 child_op = of_find_device_by_node(dp);
336 bp->devs[entry].device = child_op; 336 bp->devs[entry].device = child_op;
@@ -361,7 +361,7 @@ fail:
361extern int bbc_envctrl_init(struct bbc_i2c_bus *bp); 361extern int bbc_envctrl_init(struct bbc_i2c_bus *bp);
362extern void bbc_envctrl_cleanup(struct bbc_i2c_bus *bp); 362extern void bbc_envctrl_cleanup(struct bbc_i2c_bus *bp);
363 363
364static int __devinit bbc_i2c_probe(struct of_device *op, 364static int __devinit bbc_i2c_probe(struct platform_device *op,
365 const struct of_device_id *match) 365 const struct of_device_id *match)
366{ 366{
367 struct bbc_i2c_bus *bp; 367 struct bbc_i2c_bus *bp;
@@ -386,7 +386,7 @@ static int __devinit bbc_i2c_probe(struct of_device *op,
386 return err; 386 return err;
387} 387}
388 388
389static int __devexit bbc_i2c_remove(struct of_device *op) 389static int __devexit bbc_i2c_remove(struct platform_device *op)
390{ 390{
391 struct bbc_i2c_bus *bp = dev_get_drvdata(&op->dev); 391 struct bbc_i2c_bus *bp = dev_get_drvdata(&op->dev);
392 392
diff --git a/drivers/sbus/char/bbc_i2c.h b/drivers/sbus/char/bbc_i2c.h
index 83c4811b7b5e..4b4531066e75 100644
--- a/drivers/sbus/char/bbc_i2c.h
+++ b/drivers/sbus/char/bbc_i2c.h
@@ -7,7 +7,7 @@
7 7
8struct bbc_i2c_client { 8struct bbc_i2c_client {
9 struct bbc_i2c_bus *bp; 9 struct bbc_i2c_bus *bp;
10 struct of_device *op; 10 struct platform_device *op;
11 int bus; 11 int bus;
12 int address; 12 int address;
13}; 13};
@@ -64,16 +64,16 @@ struct bbc_i2c_bus {
64 struct list_head temps; 64 struct list_head temps;
65 struct list_head fans; 65 struct list_head fans;
66 66
67 struct of_device *op; 67 struct platform_device *op;
68 struct { 68 struct {
69 struct of_device *device; 69 struct platform_device *device;
70 int client_claimed; 70 int client_claimed;
71 } devs[NUM_CHILDREN]; 71 } devs[NUM_CHILDREN];
72}; 72};
73 73
74/* Probing and attachment. */ 74/* Probing and attachment. */
75extern struct of_device *bbc_i2c_getdev(struct bbc_i2c_bus *, int); 75extern struct platform_device *bbc_i2c_getdev(struct bbc_i2c_bus *, int);
76extern struct bbc_i2c_client *bbc_i2c_attach(struct bbc_i2c_bus *bp, struct of_device *); 76extern struct bbc_i2c_client *bbc_i2c_attach(struct bbc_i2c_bus *bp, struct platform_device *);
77extern void bbc_i2c_detach(struct bbc_i2c_client *); 77extern void bbc_i2c_detach(struct bbc_i2c_client *);
78 78
79/* Register read/write. NOTE: Blocking! */ 79/* Register read/write. NOTE: Blocking! */
diff --git a/drivers/sbus/char/display7seg.c b/drivers/sbus/char/display7seg.c
index 47db97583ea7..1690e53fb84a 100644
--- a/drivers/sbus/char/display7seg.c
+++ b/drivers/sbus/char/display7seg.c
@@ -170,7 +170,7 @@ static struct miscdevice d7s_miscdev = {
170 .fops = &d7s_fops 170 .fops = &d7s_fops
171}; 171};
172 172
173static int __devinit d7s_probe(struct of_device *op, 173static int __devinit d7s_probe(struct platform_device *op,
174 const struct of_device_id *match) 174 const struct of_device_id *match)
175{ 175{
176 struct device_node *opts; 176 struct device_node *opts;
@@ -236,7 +236,7 @@ out_free:
236 goto out; 236 goto out;
237} 237}
238 238
239static int __devexit d7s_remove(struct of_device *op) 239static int __devexit d7s_remove(struct platform_device *op)
240{ 240{
241 struct d7s *p = dev_get_drvdata(&op->dev); 241 struct d7s *p = dev_get_drvdata(&op->dev);
242 u8 regs = readb(p->regs); 242 u8 regs = readb(p->regs);
diff --git a/drivers/sbus/char/envctrl.c b/drivers/sbus/char/envctrl.c
index 3c27f45e2b6d..078e5f4520ef 100644
--- a/drivers/sbus/char/envctrl.c
+++ b/drivers/sbus/char/envctrl.c
@@ -1027,7 +1027,7 @@ static int kenvctrld(void *__unused)
1027 return 0; 1027 return 0;
1028} 1028}
1029 1029
1030static int __devinit envctrl_probe(struct of_device *op, 1030static int __devinit envctrl_probe(struct platform_device *op,
1031 const struct of_device_id *match) 1031 const struct of_device_id *match)
1032{ 1032{
1033 struct device_node *dp; 1033 struct device_node *dp;
@@ -1104,7 +1104,7 @@ out_iounmap:
1104 return err; 1104 return err;
1105} 1105}
1106 1106
1107static int __devexit envctrl_remove(struct of_device *op) 1107static int __devexit envctrl_remove(struct platform_device *op)
1108{ 1108{
1109 int index; 1109 int index;
1110 1110
diff --git a/drivers/sbus/char/flash.c b/drivers/sbus/char/flash.c
index 8bb31c584b64..2b4b4b613c48 100644
--- a/drivers/sbus/char/flash.c
+++ b/drivers/sbus/char/flash.c
@@ -160,7 +160,7 @@ static const struct file_operations flash_fops = {
160 160
161static struct miscdevice flash_dev = { FLASH_MINOR, "flash", &flash_fops }; 161static struct miscdevice flash_dev = { FLASH_MINOR, "flash", &flash_fops };
162 162
163static int __devinit flash_probe(struct of_device *op, 163static int __devinit flash_probe(struct platform_device *op,
164 const struct of_device_id *match) 164 const struct of_device_id *match)
165{ 165{
166 struct device_node *dp = op->dev.of_node; 166 struct device_node *dp = op->dev.of_node;
@@ -192,7 +192,7 @@ static int __devinit flash_probe(struct of_device *op,
192 return misc_register(&flash_dev); 192 return misc_register(&flash_dev);
193} 193}
194 194
195static int __devexit flash_remove(struct of_device *op) 195static int __devexit flash_remove(struct platform_device *op)
196{ 196{
197 misc_deregister(&flash_dev); 197 misc_deregister(&flash_dev);
198 198
diff --git a/drivers/sbus/char/uctrl.c b/drivers/sbus/char/uctrl.c
index 41eb6725ff5f..1b345be5cc02 100644
--- a/drivers/sbus/char/uctrl.c
+++ b/drivers/sbus/char/uctrl.c
@@ -348,7 +348,7 @@ static void uctrl_get_external_status(struct uctrl_driver *driver)
348 348
349} 349}
350 350
351static int __devinit uctrl_probe(struct of_device *op, 351static int __devinit uctrl_probe(struct platform_device *op,
352 const struct of_device_id *match) 352 const struct of_device_id *match)
353{ 353{
354 struct uctrl_driver *p; 354 struct uctrl_driver *p;
@@ -404,7 +404,7 @@ out_free:
404 goto out; 404 goto out;
405} 405}
406 406
407static int __devexit uctrl_remove(struct of_device *op) 407static int __devexit uctrl_remove(struct platform_device *op)
408{ 408{
409 struct uctrl_driver *p = dev_get_drvdata(&op->dev); 409 struct uctrl_driver *p = dev_get_drvdata(&op->dev);
410 410
diff --git a/drivers/scsi/53c700.c b/drivers/scsi/53c700.c
index 80dc3ac12cde..89fc1c8af86b 100644
--- a/drivers/scsi/53c700.c
+++ b/drivers/scsi/53c700.c
@@ -309,9 +309,6 @@ NCR_700_detect(struct scsi_host_template *tpnt,
309 hostdata->msgin = memory + MSGIN_OFFSET; 309 hostdata->msgin = memory + MSGIN_OFFSET;
310 hostdata->msgout = memory + MSGOUT_OFFSET; 310 hostdata->msgout = memory + MSGOUT_OFFSET;
311 hostdata->status = memory + STATUS_OFFSET; 311 hostdata->status = memory + STATUS_OFFSET;
312 /* all of these offsets are L1_CACHE_BYTES separated. It is fatal
313 * if this isn't sufficient separation to avoid dma flushing issues */
314 BUG_ON(!dma_is_consistent(hostdata->dev, pScript) && L1_CACHE_BYTES < dma_get_cache_alignment());
315 hostdata->slots = (struct NCR_700_command_slot *)(memory + SLOTS_OFFSET); 312 hostdata->slots = (struct NCR_700_command_slot *)(memory + SLOTS_OFFSET);
316 hostdata->dev = dev; 313 hostdata->dev = dev;
317 314
diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
index 158284f05732..bbf91aec64f5 100644
--- a/drivers/scsi/Kconfig
+++ b/drivers/scsi/Kconfig
@@ -370,6 +370,14 @@ config ISCSI_TCP
370 370
371 http://open-iscsi.org 371 http://open-iscsi.org
372 372
373config ISCSI_BOOT_SYSFS
374 tristate "iSCSI Boot Sysfs Interface"
375 default n
376 help
377 This option enables support for exposing iSCSI boot information
378 via sysfs to userspace. If you wish to export this information,
379 say Y. Otherwise, say N.
380
373source "drivers/scsi/cxgb3i/Kconfig" 381source "drivers/scsi/cxgb3i/Kconfig"
374source "drivers/scsi/bnx2i/Kconfig" 382source "drivers/scsi/bnx2i/Kconfig"
375source "drivers/scsi/be2iscsi/Kconfig" 383source "drivers/scsi/be2iscsi/Kconfig"
@@ -1853,7 +1861,7 @@ config ZFCP_DIF
1853 1861
1854config SCSI_PMCRAID 1862config SCSI_PMCRAID
1855 tristate "PMC SIERRA Linux MaxRAID adapter support" 1863 tristate "PMC SIERRA Linux MaxRAID adapter support"
1856 depends on PCI && SCSI 1864 depends on PCI && SCSI && NET
1857 ---help--- 1865 ---help---
1858 This driver supports the PMC SIERRA MaxRAID adapters. 1866 This driver supports the PMC SIERRA MaxRAID adapters.
1859 1867
diff --git a/drivers/scsi/Makefile b/drivers/scsi/Makefile
index 2a3fca2eca6a..2703c6ec5e36 100644
--- a/drivers/scsi/Makefile
+++ b/drivers/scsi/Makefile
@@ -42,6 +42,7 @@ obj-$(CONFIG_FCOE) += fcoe/
42obj-$(CONFIG_FCOE_FNIC) += fnic/ 42obj-$(CONFIG_FCOE_FNIC) += fnic/
43obj-$(CONFIG_ISCSI_TCP) += libiscsi.o libiscsi_tcp.o iscsi_tcp.o 43obj-$(CONFIG_ISCSI_TCP) += libiscsi.o libiscsi_tcp.o iscsi_tcp.o
44obj-$(CONFIG_INFINIBAND_ISER) += libiscsi.o 44obj-$(CONFIG_INFINIBAND_ISER) += libiscsi.o
45obj-$(CONFIG_ISCSI_BOOT_SYSFS) += iscsi_boot_sysfs.o
45obj-$(CONFIG_SCSI_A4000T) += 53c700.o a4000t.o 46obj-$(CONFIG_SCSI_A4000T) += 53c700.o a4000t.o
46obj-$(CONFIG_SCSI_ZORRO7XX) += 53c700.o zorro7xx.o 47obj-$(CONFIG_SCSI_ZORRO7XX) += 53c700.o zorro7xx.o
47obj-$(CONFIG_A3000_SCSI) += a3000.o wd33c93.o 48obj-$(CONFIG_A3000_SCSI) += a3000.o wd33c93.o
diff --git a/drivers/scsi/NCR5380.c b/drivers/scsi/NCR5380.c
index f92da9fd5f20..5d2f148889ad 100644
--- a/drivers/scsi/NCR5380.c
+++ b/drivers/scsi/NCR5380.c
@@ -1857,7 +1857,9 @@ static int NCR5380_transfer_dma(struct Scsi_Host *instance, unsigned char *phase
1857#endif 1857#endif
1858 /* KLL May need eop and parity in 53c400 */ 1858 /* KLL May need eop and parity in 53c400 */
1859 if (hostdata->flags & FLAG_NCR53C400) 1859 if (hostdata->flags & FLAG_NCR53C400)
1860 NCR5380_write(MODE_REG, MR_BASE | MR_DMA_MODE | MR_ENABLE_PAR_CHECK | MR_ENABLE_PAR_INTR | MR_ENABLE_EOP_INTR | MR_DMA_MODE | MR_MONITOR_BSY); 1860 NCR5380_write(MODE_REG, MR_BASE | MR_DMA_MODE |
1861 MR_ENABLE_PAR_CHECK | MR_ENABLE_PAR_INTR |
1862 MR_ENABLE_EOP_INTR | MR_MONITOR_BSY);
1861 else 1863 else
1862 NCR5380_write(MODE_REG, MR_BASE | MR_DMA_MODE); 1864 NCR5380_write(MODE_REG, MR_BASE | MR_DMA_MODE);
1863#endif /* def REAL_DMA */ 1865#endif /* def REAL_DMA */
diff --git a/drivers/scsi/aacraid/rx.c b/drivers/scsi/aacraid/rx.c
index 04057ab72a8b..84d77fd86e5b 100644
--- a/drivers/scsi/aacraid/rx.c
+++ b/drivers/scsi/aacraid/rx.c
@@ -352,9 +352,8 @@ static int aac_rx_check_health(struct aac_dev *dev)
352 pci_free_consistent(dev->pdev, sizeof(struct POSTSTATUS), 352 pci_free_consistent(dev->pdev, sizeof(struct POSTSTATUS),
353 post, paddr); 353 post, paddr);
354 if (likely((buffer[0] == '0') && ((buffer[1] == 'x') || (buffer[1] == 'X')))) { 354 if (likely((buffer[0] == '0') && ((buffer[1] == 'x') || (buffer[1] == 'X')))) {
355 ret = (buffer[2] <= '9') ? (buffer[2] - '0') : (buffer[2] - 'A' + 10); 355 ret = (hex_to_bin(buffer[2]) << 4) +
356 ret <<= 4; 356 hex_to_bin(buffer[3]);
357 ret += (buffer[3] <= '9') ? (buffer[3] - '0') : (buffer[3] - 'A' + 10);
358 } 357 }
359 pci_free_consistent(dev->pdev, 512, buffer, baddr); 358 pci_free_consistent(dev->pdev, 512, buffer, baddr);
360 return ret; 359 return ret;
diff --git a/drivers/scsi/aha1542.c b/drivers/scsi/aha1542.c
index 2a8cf137f609..4f785f254c1f 100644
--- a/drivers/scsi/aha1542.c
+++ b/drivers/scsi/aha1542.c
@@ -52,22 +52,6 @@
52#define SCSI_BUF_PA(address) isa_virt_to_bus(address) 52#define SCSI_BUF_PA(address) isa_virt_to_bus(address)
53#define SCSI_SG_PA(sgent) (isa_page_to_bus(sg_page((sgent))) + (sgent)->offset) 53#define SCSI_SG_PA(sgent) (isa_page_to_bus(sg_page((sgent))) + (sgent)->offset)
54 54
55static void BAD_SG_DMA(Scsi_Cmnd * SCpnt,
56 struct scatterlist *sgp,
57 int nseg,
58 int badseg)
59{
60 printk(KERN_CRIT "sgpnt[%d:%d] page %p/0x%llx length %u\n",
61 badseg, nseg, sg_virt(sgp),
62 (unsigned long long)SCSI_SG_PA(sgp),
63 sgp->length);
64
65 /*
66 * Not safe to continue.
67 */
68 panic("Buffer at physical address > 16Mb used for aha1542");
69}
70
71#include<linux/stat.h> 55#include<linux/stat.h>
72 56
73#ifdef DEBUG 57#ifdef DEBUG
@@ -691,8 +675,6 @@ static int aha1542_queuecommand(Scsi_Cmnd * SCpnt, void (*done) (Scsi_Cmnd *))
691 } 675 }
692 scsi_for_each_sg(SCpnt, sg, sg_count, i) { 676 scsi_for_each_sg(SCpnt, sg, sg_count, i) {
693 any2scsi(cptr[i].dataptr, SCSI_SG_PA(sg)); 677 any2scsi(cptr[i].dataptr, SCSI_SG_PA(sg));
694 if (SCSI_SG_PA(sg) + sg->length - 1 > ISA_DMA_THRESHOLD)
695 BAD_SG_DMA(SCpnt, scsi_sglist(SCpnt), sg_count, i);
696 any2scsi(cptr[i].datalen, sg->length); 678 any2scsi(cptr[i].datalen, sg->length);
697 }; 679 };
698 any2scsi(ccb[mbo].datalen, sg_count * sizeof(struct chain)); 680 any2scsi(ccb[mbo].datalen, sg_count * sizeof(struct chain));
@@ -1133,16 +1115,9 @@ static int __init aha1542_detect(struct scsi_host_template * tpnt)
1133 release_region(bases[indx], 4); 1115 release_region(bases[indx], 4);
1134 continue; 1116 continue;
1135 } 1117 }
1136 /* For now we do this - until kmalloc is more intelligent
1137 we are resigned to stupid hacks like this */
1138 if (SCSI_BUF_PA(shpnt) >= ISA_DMA_THRESHOLD) {
1139 printk(KERN_ERR "Invalid address for shpnt with 1542.\n");
1140 goto unregister;
1141 }
1142 if (!aha1542_test_port(bases[indx], shpnt)) 1118 if (!aha1542_test_port(bases[indx], shpnt))
1143 goto unregister; 1119 goto unregister;
1144 1120
1145
1146 base_io = bases[indx]; 1121 base_io = bases[indx];
1147 1122
1148 /* Set the Bus on/off-times as not to ruin floppy performance */ 1123 /* Set the Bus on/off-times as not to ruin floppy performance */
diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
index 24ac2315c5c7..3b7e83d2dab4 100644
--- a/drivers/scsi/aic94xx/aic94xx_init.c
+++ b/drivers/scsi/aic94xx/aic94xx_init.c
@@ -688,9 +688,9 @@ static int asd_register_sas_ha(struct asd_ha_struct *asd_ha)
688{ 688{
689 int i; 689 int i;
690 struct asd_sas_phy **sas_phys = 690 struct asd_sas_phy **sas_phys =
691 kmalloc(ASD_MAX_PHYS * sizeof(struct asd_sas_phy), GFP_KERNEL); 691 kcalloc(ASD_MAX_PHYS, sizeof(*sas_phys), GFP_KERNEL);
692 struct asd_sas_port **sas_ports = 692 struct asd_sas_port **sas_ports =
693 kmalloc(ASD_MAX_PHYS * sizeof(struct asd_sas_port), GFP_KERNEL); 693 kcalloc(ASD_MAX_PHYS, sizeof(*sas_ports), GFP_KERNEL);
694 694
695 if (!sas_phys || !sas_ports) { 695 if (!sas_phys || !sas_ports) {
696 kfree(sas_phys); 696 kfree(sas_phys);
diff --git a/drivers/scsi/be2iscsi/Kconfig b/drivers/scsi/be2iscsi/Kconfig
index 84c275fb9f6b..ceaca32e788d 100644
--- a/drivers/scsi/be2iscsi/Kconfig
+++ b/drivers/scsi/be2iscsi/Kconfig
@@ -2,6 +2,7 @@ config BE2ISCSI
2 tristate "ServerEngines' 10Gbps iSCSI - BladeEngine 2" 2 tristate "ServerEngines' 10Gbps iSCSI - BladeEngine 2"
3 depends on PCI && SCSI && NET 3 depends on PCI && SCSI && NET
4 select SCSI_ISCSI_ATTRS 4 select SCSI_ISCSI_ATTRS
5 select ISCSI_BOOT_SYSFS
5 6
6 help 7 help
7 This driver implements the iSCSI functionality for ServerEngines' 8 This driver implements the iSCSI functionality for ServerEngines'
diff --git a/drivers/scsi/be2iscsi/be_cmds.h b/drivers/scsi/be2iscsi/be_cmds.h
index 40641d0845f4..5218de4ab35a 100644
--- a/drivers/scsi/be2iscsi/be_cmds.h
+++ b/drivers/scsi/be2iscsi/be_cmds.h
@@ -162,6 +162,13 @@ struct be_mcc_mailbox {
162#define OPCODE_COMMON_ISCSI_CFG_POST_SGL_PAGES 2 162#define OPCODE_COMMON_ISCSI_CFG_POST_SGL_PAGES 2
163#define OPCODE_COMMON_ISCSI_CFG_REMOVE_SGL_PAGES 3 163#define OPCODE_COMMON_ISCSI_CFG_REMOVE_SGL_PAGES 3
164#define OPCODE_COMMON_ISCSI_NTWK_GET_NIC_CONFIG 7 164#define OPCODE_COMMON_ISCSI_NTWK_GET_NIC_CONFIG 7
165#define OPCODE_COMMON_ISCSI_NTWK_SET_VLAN 14
166#define OPCODE_COMMON_ISCSI_NTWK_CONFIGURE_STATELESS_IP_ADDR 17
167#define OPCODE_COMMON_ISCSI_NTWK_MODIFY_IP_ADDR 21
168#define OPCODE_COMMON_ISCSI_NTWK_GET_DEFAULT_GATEWAY 22
169#define OPCODE_COMMON_ISCSI_NTWK_MODIFY_DEFAULT_GATEWAY 23
170#define OPCODE_COMMON_ISCSI_NTWK_GET_ALL_IF_ID 24
171#define OPCODE_COMMON_ISCSI_NTWK_GET_IF_INFO 25
165#define OPCODE_COMMON_ISCSI_SET_FRAGNUM_BITS_FOR_SGL_CRA 61 172#define OPCODE_COMMON_ISCSI_SET_FRAGNUM_BITS_FOR_SGL_CRA 61
166#define OPCODE_COMMON_ISCSI_DEFQ_CREATE 64 173#define OPCODE_COMMON_ISCSI_DEFQ_CREATE 64
167#define OPCODE_COMMON_ISCSI_DEFQ_DESTROY 65 174#define OPCODE_COMMON_ISCSI_DEFQ_DESTROY 65
@@ -237,11 +244,109 @@ struct be_cmd_resp_eq_create {
237 u16 rsvd0; /* sword */ 244 u16 rsvd0; /* sword */
238} __packed; 245} __packed;
239 246
247struct mgmt_chap_format {
248 u32 flags;
249 u8 intr_chap_name[256];
250 u8 intr_secret[16];
251 u8 target_chap_name[256];
252 u8 target_secret[16];
253 u16 intr_chap_name_length;
254 u16 intr_secret_length;
255 u16 target_chap_name_length;
256 u16 target_secret_length;
257} __packed;
258
259struct mgmt_auth_method_format {
260 u8 auth_method_type;
261 u8 padding[3];
262 struct mgmt_chap_format chap;
263} __packed;
264
265struct mgmt_conn_login_options {
266 u8 flags;
267 u8 header_digest;
268 u8 data_digest;
269 u8 rsvd0;
270 u32 max_recv_datasegment_len_ini;
271 u32 max_recv_datasegment_len_tgt;
272 u32 tcp_mss;
273 u32 tcp_window_size;
274 struct mgmt_auth_method_format auth_data;
275} __packed;
276
277struct ip_address_format {
278 u16 size_of_structure;
279 u8 reserved;
280 u8 ip_type;
281 u8 ip_address[16];
282 u32 rsvd0;
283} __packed;
284
285struct mgmt_conn_info {
286 u32 connection_handle;
287 u32 connection_status;
288 u16 src_port;
289 u16 dest_port;
290 u16 dest_port_redirected;
291 u16 cid;
292 u32 estimated_throughput;
293 struct ip_address_format src_ipaddr;
294 struct ip_address_format dest_ipaddr;
295 struct ip_address_format dest_ipaddr_redirected;
296 struct mgmt_conn_login_options negotiated_login_options;
297} __packed;
298
299struct mgmt_session_login_options {
300 u8 flags;
301 u8 error_recovery_level;
302 u16 rsvd0;
303 u32 first_burst_length;
304 u32 max_burst_length;
305 u16 max_connections;
306 u16 max_outstanding_r2t;
307 u16 default_time2wait;
308 u16 default_time2retain;
309} __packed;
310
311struct mgmt_session_info {
312 u32 session_handle;
313 u32 status;
314 u8 isid[6];
315 u16 tsih;
316 u32 session_flags;
317 u16 conn_count;
318 u16 pad;
319 u8 target_name[224];
320 u8 initiator_iscsiname[224];
321 struct mgmt_session_login_options negotiated_login_options;
322 struct mgmt_conn_info conn_list[1];
323} __packed;
324
325struct be_cmd_req_get_session {
326 struct be_cmd_req_hdr hdr;
327 u32 session_handle;
328} __packed;
329
330struct be_cmd_resp_get_session {
331 struct be_cmd_resp_hdr hdr;
332 struct mgmt_session_info session_info;
333} __packed;
334
240struct mac_addr { 335struct mac_addr {
241 u16 size_of_struct; 336 u16 size_of_struct;
242 u8 addr[ETH_ALEN]; 337 u8 addr[ETH_ALEN];
243} __packed; 338} __packed;
244 339
340struct be_cmd_req_get_boot_target {
341 struct be_cmd_req_hdr hdr;
342} __packed;
343
344struct be_cmd_resp_get_boot_target {
345 struct be_cmd_resp_hdr hdr;
346 u32 boot_session_count;
347 int boot_session_handle;
348};
349
245struct be_cmd_req_mac_query { 350struct be_cmd_req_mac_query {
246 struct be_cmd_req_hdr hdr; 351 struct be_cmd_req_hdr hdr;
247 u8 type; 352 u8 type;
@@ -426,6 +531,11 @@ int be_poll_mcc(struct be_ctrl_info *ctrl);
426int mgmt_check_supported_fw(struct be_ctrl_info *ctrl, 531int mgmt_check_supported_fw(struct be_ctrl_info *ctrl,
427 struct beiscsi_hba *phba); 532 struct beiscsi_hba *phba);
428unsigned int be_cmd_get_mac_addr(struct beiscsi_hba *phba); 533unsigned int be_cmd_get_mac_addr(struct beiscsi_hba *phba);
534unsigned int beiscsi_get_boot_target(struct beiscsi_hba *phba);
535unsigned int beiscsi_get_session_info(struct beiscsi_hba *phba,
536 u32 boot_session_handle,
537 struct be_dma_mem *nonemb_cmd);
538
429void free_mcc_tag(struct be_ctrl_info *ctrl, unsigned int tag); 539void free_mcc_tag(struct be_ctrl_info *ctrl, unsigned int tag);
430/*ISCSI Functuions */ 540/*ISCSI Functuions */
431int be_cmd_fw_initialize(struct be_ctrl_info *ctrl); 541int be_cmd_fw_initialize(struct be_ctrl_info *ctrl);
@@ -601,14 +711,6 @@ struct be_eq_delay_params_in {
601 struct eq_delay delay[8]; 711 struct eq_delay delay[8];
602} __packed; 712} __packed;
603 713
604struct ip_address_format {
605 u16 size_of_structure;
606 u8 reserved;
607 u8 ip_type;
608 u8 ip_address[16];
609 u32 rsvd0;
610} __packed;
611
612struct tcp_connect_and_offload_in { 714struct tcp_connect_and_offload_in {
613 struct be_cmd_req_hdr hdr; 715 struct be_cmd_req_hdr hdr;
614 struct ip_address_format ip_address; 716 struct ip_address_format ip_address;
@@ -688,18 +790,29 @@ struct be_fw_cfg {
688 u32 function_caps; 790 u32 function_caps;
689} __packed; 791} __packed;
690 792
691#define CMD_ISCSI_COMMAND_INVALIDATE 1 793struct be_all_if_id {
692#define ISCSI_OPCODE_SCSI_DATA_OUT 5 794 struct be_cmd_req_hdr hdr;
795 u32 if_count;
796 u32 if_hndl_list[1];
797} __packed;
798
799#define ISCSI_OPCODE_SCSI_DATA_OUT 5
800#define OPCODE_COMMON_MODIFY_EQ_DELAY 41
801#define OPCODE_COMMON_ISCSI_CLEANUP 59
802#define OPCODE_COMMON_TCP_UPLOAD 56
693#define OPCODE_COMMON_ISCSI_TCP_CONNECT_AND_OFFLOAD 70 803#define OPCODE_COMMON_ISCSI_TCP_CONNECT_AND_OFFLOAD 70
694#define OPCODE_ISCSI_INI_DRIVER_OFFLOAD_SESSION 41
695#define OPCODE_COMMON_MODIFY_EQ_DELAY 41
696#define OPCODE_COMMON_ISCSI_CLEANUP 59
697#define OPCODE_COMMON_TCP_UPLOAD 56
698#define OPCODE_COMMON_ISCSI_ERROR_RECOVERY_INVALIDATE_COMMANDS 1 804#define OPCODE_COMMON_ISCSI_ERROR_RECOVERY_INVALIDATE_COMMANDS 1
699/* --- CMD_ISCSI_INVALIDATE_CONNECTION_TYPE --- */ 805#define OPCODE_ISCSI_INI_CFG_GET_HBA_NAME 6
700#define CMD_ISCSI_CONNECTION_INVALIDATE 0x8001 806#define OPCODE_ISCSI_INI_CFG_SET_HBA_NAME 7
701#define CMD_ISCSI_CONNECTION_ISSUE_TCP_RST 0x8002 807#define OPCODE_ISCSI_INI_SESSION_GET_A_SESSION 14
808#define OPCODE_ISCSI_INI_DRIVER_OFFLOAD_SESSION 41
702#define OPCODE_ISCSI_INI_DRIVER_INVALIDATE_CONNECTION 42 809#define OPCODE_ISCSI_INI_DRIVER_INVALIDATE_CONNECTION 42
810#define OPCODE_ISCSI_INI_BOOT_GET_BOOT_TARGET 52
811
812/* --- CMD_ISCSI_INVALIDATE_CONNECTION_TYPE --- */
813#define CMD_ISCSI_COMMAND_INVALIDATE 1
814#define CMD_ISCSI_CONNECTION_INVALIDATE 0x8001
815#define CMD_ISCSI_CONNECTION_ISSUE_TCP_RST 0x8002
703 816
704#define INI_WR_CMD 1 /* Initiator write command */ 817#define INI_WR_CMD 1 /* Initiator write command */
705#define INI_TMF_CMD 2 /* Initiator TMF command */ 818#define INI_TMF_CMD 2 /* Initiator TMF command */
diff --git a/drivers/scsi/be2iscsi/be_iscsi.c b/drivers/scsi/be2iscsi/be_iscsi.c
index 6d63e7b312cf..7d4d2275573c 100644
--- a/drivers/scsi/be2iscsi/be_iscsi.c
+++ b/drivers/scsi/be2iscsi/be_iscsi.c
@@ -300,40 +300,16 @@ int beiscsi_get_host_param(struct Scsi_Host *shost,
300 enum iscsi_host_param param, char *buf) 300 enum iscsi_host_param param, char *buf)
301{ 301{
302 struct beiscsi_hba *phba = (struct beiscsi_hba *)iscsi_host_priv(shost); 302 struct beiscsi_hba *phba = (struct beiscsi_hba *)iscsi_host_priv(shost);
303 struct be_cmd_resp_get_mac_addr *resp;
304 struct be_mcc_wrb *wrb;
305 unsigned int tag, wrb_num;
306 int len = 0; 303 int len = 0;
307 unsigned short status, extd_status; 304 int status;
308 struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
309 305
310 SE_DEBUG(DBG_LVL_8, "In beiscsi_get_host_param, param= %d\n", param); 306 SE_DEBUG(DBG_LVL_8, "In beiscsi_get_host_param, param= %d\n", param);
311 switch (param) { 307 switch (param) {
312 case ISCSI_HOST_PARAM_HWADDRESS: 308 case ISCSI_HOST_PARAM_HWADDRESS:
313 tag = be_cmd_get_mac_addr(phba); 309 status = beiscsi_get_macaddr(buf, phba);
314 if (!tag) { 310 if (status < 0) {
315 SE_DEBUG(DBG_LVL_1, "be_cmd_get_mac_addr Failed\n"); 311 SE_DEBUG(DBG_LVL_1, "beiscsi_get_macaddr Failed\n");
316 return -EAGAIN; 312 return status;
317 } else
318 wait_event_interruptible(phba->ctrl.mcc_wait[tag],
319 phba->ctrl.mcc_numtag[tag]);
320
321 wrb_num = (phba->ctrl.mcc_numtag[tag] & 0x00FF0000) >> 16;
322 extd_status = (phba->ctrl.mcc_numtag[tag] & 0x0000FF00) >> 8;
323 status = phba->ctrl.mcc_numtag[tag] & 0x000000FF;
324 if (status || extd_status) {
325 SE_DEBUG(DBG_LVL_1, "be_cmd_get_mac_addr Failed"
326 " status = %d extd_status = %d\n",
327 status, extd_status);
328 free_mcc_tag(&phba->ctrl, tag);
329 return -EAGAIN;
330 } else {
331 wrb = queue_get_wrb(mccq, wrb_num);
332 free_mcc_tag(&phba->ctrl, tag);
333 resp = embedded_payload(wrb);
334 memcpy(phba->mac_address, resp->mac_address, ETH_ALEN);
335 len = sysfs_format_mac(buf, phba->mac_address,
336 ETH_ALEN);
337 } 313 }
338 break; 314 break;
339 default: 315 default:
@@ -342,6 +318,48 @@ int beiscsi_get_host_param(struct Scsi_Host *shost,
342 return len; 318 return len;
343} 319}
344 320
321int beiscsi_get_macaddr(char *buf, struct beiscsi_hba *phba)
322{
323 struct be_cmd_resp_get_mac_addr *resp;
324 struct be_mcc_wrb *wrb;
325 unsigned int tag, wrb_num;
326 unsigned short status, extd_status;
327 struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
328 int rc;
329
330 if (phba->read_mac_address)
331 return sysfs_format_mac(buf, phba->mac_address,
332 ETH_ALEN);
333
334 tag = be_cmd_get_mac_addr(phba);
335 if (!tag) {
336 SE_DEBUG(DBG_LVL_1, "be_cmd_get_mac_addr Failed\n");
337 return -EBUSY;
338 } else
339 wait_event_interruptible(phba->ctrl.mcc_wait[tag],
340 phba->ctrl.mcc_numtag[tag]);
341
342 wrb_num = (phba->ctrl.mcc_numtag[tag] & 0x00FF0000) >> 16;
343 extd_status = (phba->ctrl.mcc_numtag[tag] & 0x0000FF00) >> 8;
344 status = phba->ctrl.mcc_numtag[tag] & 0x000000FF;
345 if (status || extd_status) {
346 SE_DEBUG(DBG_LVL_1, "Failed to get be_cmd_get_mac_addr"
347 " status = %d extd_status = %d\n",
348 status, extd_status);
349 free_mcc_tag(&phba->ctrl, tag);
350 return -EAGAIN;
351 }
352 wrb = queue_get_wrb(mccq, wrb_num);
353 free_mcc_tag(&phba->ctrl, tag);
354 resp = embedded_payload(wrb);
355 memcpy(phba->mac_address, resp->mac_address, ETH_ALEN);
356 rc = sysfs_format_mac(buf, phba->mac_address,
357 ETH_ALEN);
358 phba->read_mac_address = 1;
359 return rc;
360}
361
362
345/** 363/**
346 * beiscsi_conn_get_stats - get the iscsi stats 364 * beiscsi_conn_get_stats - get the iscsi stats
347 * @cls_conn: pointer to iscsi cls conn 365 * @cls_conn: pointer to iscsi cls conn
diff --git a/drivers/scsi/be2iscsi/be_iscsi.h b/drivers/scsi/be2iscsi/be_iscsi.h
index 870cdb2a73e4..8950a702b9f4 100644
--- a/drivers/scsi/be2iscsi/be_iscsi.h
+++ b/drivers/scsi/be2iscsi/be_iscsi.h
@@ -54,6 +54,8 @@ int beiscsi_conn_get_param(struct iscsi_cls_conn *cls_conn,
54int beiscsi_get_host_param(struct Scsi_Host *shost, 54int beiscsi_get_host_param(struct Scsi_Host *shost,
55 enum iscsi_host_param param, char *buf); 55 enum iscsi_host_param param, char *buf);
56 56
57int beiscsi_get_macaddr(char *buf, struct beiscsi_hba *phba);
58
57int beiscsi_set_param(struct iscsi_cls_conn *cls_conn, 59int beiscsi_set_param(struct iscsi_cls_conn *cls_conn,
58 enum iscsi_param param, char *buf, int buflen); 60 enum iscsi_param param, char *buf, int buflen);
59 61
diff --git a/drivers/scsi/be2iscsi/be_main.c b/drivers/scsi/be2iscsi/be_main.c
index 7436c5ad5697..8220bde6c04c 100644
--- a/drivers/scsi/be2iscsi/be_main.c
+++ b/drivers/scsi/be2iscsi/be_main.c
@@ -26,6 +26,7 @@
26#include <linux/string.h> 26#include <linux/string.h>
27#include <linux/kernel.h> 27#include <linux/kernel.h>
28#include <linux/semaphore.h> 28#include <linux/semaphore.h>
29#include <linux/iscsi_boot_sysfs.h>
29 30
30#include <scsi/libiscsi.h> 31#include <scsi/libiscsi.h>
31#include <scsi/scsi_transport_iscsi.h> 32#include <scsi/scsi_transport_iscsi.h>
@@ -211,6 +212,218 @@ unlock:
211 return rc; 212 return rc;
212} 213}
213 214
215static ssize_t beiscsi_show_boot_tgt_info(void *data, int type, char *buf)
216{
217 struct beiscsi_hba *phba = data;
218 char *str = buf;
219 int rc;
220
221 switch (type) {
222 case ISCSI_BOOT_TGT_NAME:
223 rc = sprintf(buf, "%.*s\n",
224 (int)strlen(phba->boot_sess.target_name),
225 (char *)&phba->boot_sess.target_name);
226 break;
227 case ISCSI_BOOT_TGT_IP_ADDR:
228 if (phba->boot_sess.conn_list[0].dest_ipaddr.ip_type == 0x1)
229 rc = sprintf(buf, "%pI4\n",
230 (char *)&phba->boot_sess.conn_list[0].
231 dest_ipaddr.ip_address);
232 else
233 rc = sprintf(str, "%pI6\n",
234 (char *)&phba->boot_sess.conn_list[0].
235 dest_ipaddr.ip_address);
236 break;
237 case ISCSI_BOOT_TGT_PORT:
238 rc = sprintf(str, "%d\n", phba->boot_sess.conn_list[0].
239 dest_port);
240 break;
241
242 case ISCSI_BOOT_TGT_CHAP_NAME:
243 rc = sprintf(str, "%.*s\n",
244 phba->boot_sess.conn_list[0].
245 negotiated_login_options.auth_data.chap.
246 target_chap_name_length,
247 (char *)&phba->boot_sess.conn_list[0].
248 negotiated_login_options.auth_data.chap.
249 target_chap_name);
250 break;
251 case ISCSI_BOOT_TGT_CHAP_SECRET:
252 rc = sprintf(str, "%.*s\n",
253 phba->boot_sess.conn_list[0].
254 negotiated_login_options.auth_data.chap.
255 target_secret_length,
256 (char *)&phba->boot_sess.conn_list[0].
257 negotiated_login_options.auth_data.chap.
258 target_secret);
259
260 break;
261 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
262 rc = sprintf(str, "%.*s\n",
263 phba->boot_sess.conn_list[0].
264 negotiated_login_options.auth_data.chap.
265 intr_chap_name_length,
266 (char *)&phba->boot_sess.conn_list[0].
267 negotiated_login_options.auth_data.chap.
268 intr_chap_name);
269
270 break;
271 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
272 rc = sprintf(str, "%.*s\n",
273 phba->boot_sess.conn_list[0].
274 negotiated_login_options.auth_data.chap.
275 intr_secret_length,
276 (char *)&phba->boot_sess.conn_list[0].
277 negotiated_login_options.auth_data.chap.
278 intr_secret);
279 break;
280 case ISCSI_BOOT_TGT_FLAGS:
281 rc = sprintf(str, "2\n");
282 break;
283 case ISCSI_BOOT_TGT_NIC_ASSOC:
284 rc = sprintf(str, "0\n");
285 break;
286 default:
287 rc = -ENOSYS;
288 break;
289 }
290 return rc;
291}
292
293static ssize_t beiscsi_show_boot_ini_info(void *data, int type, char *buf)
294{
295 struct beiscsi_hba *phba = data;
296 char *str = buf;
297 int rc;
298
299 switch (type) {
300 case ISCSI_BOOT_INI_INITIATOR_NAME:
301 rc = sprintf(str, "%s\n", phba->boot_sess.initiator_iscsiname);
302 break;
303 default:
304 rc = -ENOSYS;
305 break;
306 }
307 return rc;
308}
309
310static ssize_t beiscsi_show_boot_eth_info(void *data, int type, char *buf)
311{
312 struct beiscsi_hba *phba = data;
313 char *str = buf;
314 int rc;
315
316 switch (type) {
317 case ISCSI_BOOT_ETH_FLAGS:
318 rc = sprintf(str, "2\n");
319 break;
320 case ISCSI_BOOT_ETH_INDEX:
321 rc = sprintf(str, "0\n");
322 break;
323 case ISCSI_BOOT_ETH_MAC:
324 rc = beiscsi_get_macaddr(buf, phba);
325 if (rc < 0) {
326 SE_DEBUG(DBG_LVL_1, "beiscsi_get_macaddr Failed\n");
327 return rc;
328 }
329 break;
330 default:
331 rc = -ENOSYS;
332 break;
333 }
334 return rc;
335}
336
337
338static mode_t beiscsi_tgt_get_attr_visibility(void *data, int type)
339{
340 int rc;
341
342 switch (type) {
343 case ISCSI_BOOT_TGT_NAME:
344 case ISCSI_BOOT_TGT_IP_ADDR:
345 case ISCSI_BOOT_TGT_PORT:
346 case ISCSI_BOOT_TGT_CHAP_NAME:
347 case ISCSI_BOOT_TGT_CHAP_SECRET:
348 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
349 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
350 case ISCSI_BOOT_TGT_NIC_ASSOC:
351 case ISCSI_BOOT_TGT_FLAGS:
352 rc = S_IRUGO;
353 break;
354 default:
355 rc = 0;
356 break;
357 }
358 return rc;
359}
360
361static mode_t beiscsi_ini_get_attr_visibility(void *data, int type)
362{
363 int rc;
364
365 switch (type) {
366 case ISCSI_BOOT_INI_INITIATOR_NAME:
367 rc = S_IRUGO;
368 break;
369 default:
370 rc = 0;
371 break;
372 }
373 return rc;
374}
375
376
377static mode_t beiscsi_eth_get_attr_visibility(void *data, int type)
378{
379 int rc;
380
381 switch (type) {
382 case ISCSI_BOOT_ETH_FLAGS:
383 case ISCSI_BOOT_ETH_MAC:
384 case ISCSI_BOOT_ETH_INDEX:
385 rc = S_IRUGO;
386 break;
387 default:
388 rc = 0;
389 break;
390 }
391 return rc;
392}
393
394static int beiscsi_setup_boot_info(struct beiscsi_hba *phba)
395{
396 struct iscsi_boot_kobj *boot_kobj;
397
398 phba->boot_kset = iscsi_boot_create_host_kset(phba->shost->host_no);
399 if (!phba->boot_kset)
400 return -ENOMEM;
401
402 /* get boot info using mgmt cmd */
403 boot_kobj = iscsi_boot_create_target(phba->boot_kset, 0, phba,
404 beiscsi_show_boot_tgt_info,
405 beiscsi_tgt_get_attr_visibility);
406 if (!boot_kobj)
407 goto free_kset;
408
409 boot_kobj = iscsi_boot_create_initiator(phba->boot_kset, 0, phba,
410 beiscsi_show_boot_ini_info,
411 beiscsi_ini_get_attr_visibility);
412 if (!boot_kobj)
413 goto free_kset;
414
415 boot_kobj = iscsi_boot_create_ethernet(phba->boot_kset, 0, phba,
416 beiscsi_show_boot_eth_info,
417 beiscsi_eth_get_attr_visibility);
418 if (!boot_kobj)
419 goto free_kset;
420 return 0;
421
422free_kset:
423 iscsi_boot_destroy_kset(phba->boot_kset);
424 return -ENOMEM;
425}
426
214/*------------------- PCI Driver operations and data ----------------- */ 427/*------------------- PCI Driver operations and data ----------------- */
215static DEFINE_PCI_DEVICE_TABLE(beiscsi_pci_id_table) = { 428static DEFINE_PCI_DEVICE_TABLE(beiscsi_pci_id_table) = {
216 { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID1) }, 429 { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID1) },
@@ -268,6 +481,15 @@ static struct beiscsi_hba *beiscsi_hba_alloc(struct pci_dev *pcidev)
268 481
269 if (iscsi_host_add(shost, &phba->pcidev->dev)) 482 if (iscsi_host_add(shost, &phba->pcidev->dev))
270 goto free_devices; 483 goto free_devices;
484
485 if (beiscsi_setup_boot_info(phba))
486 /*
487 * log error but continue, because we may not be using
488 * iscsi boot.
489 */
490 shost_printk(KERN_ERR, phba->shost, "Could not set up "
491 "iSCSI boot info.");
492
271 return phba; 493 return phba;
272 494
273free_devices: 495free_devices:
@@ -3279,6 +3501,89 @@ static void hwi_disable_intr(struct beiscsi_hba *phba)
3279 "In hwi_disable_intr, Already Disabled\n"); 3501 "In hwi_disable_intr, Already Disabled\n");
3280} 3502}
3281 3503
3504static int beiscsi_get_boot_info(struct beiscsi_hba *phba)
3505{
3506 struct be_cmd_resp_get_boot_target *boot_resp;
3507 struct be_cmd_resp_get_session *session_resp;
3508 struct be_mcc_wrb *wrb;
3509 struct be_dma_mem nonemb_cmd;
3510 unsigned int tag, wrb_num;
3511 unsigned short status, extd_status;
3512 struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
3513
3514 tag = beiscsi_get_boot_target(phba);
3515 if (!tag) {
3516 SE_DEBUG(DBG_LVL_1, "be_cmd_get_mac_addr Failed\n");
3517 return -EAGAIN;
3518 } else
3519 wait_event_interruptible(phba->ctrl.mcc_wait[tag],
3520 phba->ctrl.mcc_numtag[tag]);
3521
3522 wrb_num = (phba->ctrl.mcc_numtag[tag] & 0x00FF0000) >> 16;
3523 extd_status = (phba->ctrl.mcc_numtag[tag] & 0x0000FF00) >> 8;
3524 status = phba->ctrl.mcc_numtag[tag] & 0x000000FF;
3525 if (status || extd_status) {
3526 SE_DEBUG(DBG_LVL_1, "be_cmd_get_mac_addr Failed"
3527 " status = %d extd_status = %d\n",
3528 status, extd_status);
3529 free_mcc_tag(&phba->ctrl, tag);
3530 return -EBUSY;
3531 }
3532 wrb = queue_get_wrb(mccq, wrb_num);
3533 free_mcc_tag(&phba->ctrl, tag);
3534 boot_resp = embedded_payload(wrb);
3535
3536 if (boot_resp->boot_session_handle < 0) {
3537 printk(KERN_ERR "No Boot Session for this pci_func,"
3538 "session Hndl = %d\n", boot_resp->boot_session_handle);
3539 return -ENXIO;
3540 }
3541
3542 nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
3543 sizeof(*session_resp),
3544 &nonemb_cmd.dma);
3545 if (nonemb_cmd.va == NULL) {
3546 SE_DEBUG(DBG_LVL_1,
3547 "Failed to allocate memory for"
3548 "beiscsi_get_session_info\n");
3549 return -ENOMEM;
3550 }
3551
3552 memset(nonemb_cmd.va, 0, sizeof(*session_resp));
3553 tag = beiscsi_get_session_info(phba,
3554 boot_resp->boot_session_handle, &nonemb_cmd);
3555 if (!tag) {
3556 SE_DEBUG(DBG_LVL_1, "beiscsi_get_session_info"
3557 " Failed\n");
3558 goto boot_freemem;
3559 } else
3560 wait_event_interruptible(phba->ctrl.mcc_wait[tag],
3561 phba->ctrl.mcc_numtag[tag]);
3562
3563 wrb_num = (phba->ctrl.mcc_numtag[tag] & 0x00FF0000) >> 16;
3564 extd_status = (phba->ctrl.mcc_numtag[tag] & 0x0000FF00) >> 8;
3565 status = phba->ctrl.mcc_numtag[tag] & 0x000000FF;
3566 if (status || extd_status) {
3567 SE_DEBUG(DBG_LVL_1, "beiscsi_get_session_info Failed"
3568 " status = %d extd_status = %d\n",
3569 status, extd_status);
3570 free_mcc_tag(&phba->ctrl, tag);
3571 goto boot_freemem;
3572 }
3573 wrb = queue_get_wrb(mccq, wrb_num);
3574 free_mcc_tag(&phba->ctrl, tag);
3575 session_resp = nonemb_cmd.va ;
3576 memcpy(&phba->boot_sess, &session_resp->session_info,
3577 sizeof(struct mgmt_session_info));
3578 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
3579 nonemb_cmd.va, nonemb_cmd.dma);
3580 return 0;
3581boot_freemem:
3582 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
3583 nonemb_cmd.va, nonemb_cmd.dma);
3584 return -ENOMEM;
3585}
3586
3282static int beiscsi_init_port(struct beiscsi_hba *phba) 3587static int beiscsi_init_port(struct beiscsi_hba *phba)
3283{ 3588{
3284 int ret; 3589 int ret;
@@ -3841,6 +4146,7 @@ static void beiscsi_remove(struct pci_dev *pcidev)
3841 iscsi_host_remove(phba->shost); 4146 iscsi_host_remove(phba->shost);
3842 pci_dev_put(phba->pcidev); 4147 pci_dev_put(phba->pcidev);
3843 iscsi_host_free(phba->shost); 4148 iscsi_host_free(phba->shost);
4149 iscsi_boot_destroy_kset(phba->boot_kset);
3844} 4150}
3845 4151
3846static void beiscsi_msix_enable(struct beiscsi_hba *phba) 4152static void beiscsi_msix_enable(struct beiscsi_hba *phba)
@@ -3996,6 +4302,11 @@ static int __devinit beiscsi_dev_probe(struct pci_dev *pcidev,
3996 goto free_blkenbld; 4302 goto free_blkenbld;
3997 } 4303 }
3998 hwi_enable_intr(phba); 4304 hwi_enable_intr(phba);
4305 ret = beiscsi_get_boot_info(phba);
4306 if (ret < 0) {
4307 shost_printk(KERN_ERR, phba->shost, "beiscsi_dev_probe-"
4308 "No Boot Devices !!!!!\n");
4309 }
3999 SE_DEBUG(DBG_LVL_8, "\n\n\n SUCCESS - DRIVER LOADED\n\n\n"); 4310 SE_DEBUG(DBG_LVL_8, "\n\n\n SUCCESS - DRIVER LOADED\n\n\n");
4000 return 0; 4311 return 0;
4001 4312
diff --git a/drivers/scsi/be2iscsi/be_main.h b/drivers/scsi/be2iscsi/be_main.h
index c643bb3736fc..90eb74f6bcab 100644
--- a/drivers/scsi/be2iscsi/be_main.h
+++ b/drivers/scsi/be2iscsi/be_main.h
@@ -35,7 +35,7 @@
35 35
36#include "be.h" 36#include "be.h"
37#define DRV_NAME "be2iscsi" 37#define DRV_NAME "be2iscsi"
38#define BUILD_STR "2.0.527.0" 38#define BUILD_STR "2.0.549.0"
39#define BE_NAME "ServerEngines BladeEngine2" \ 39#define BE_NAME "ServerEngines BladeEngine2" \
40 "Linux iSCSI Driver version" BUILD_STR 40 "Linux iSCSI Driver version" BUILD_STR
41#define DRV_DESC BE_NAME " " "Driver" 41#define DRV_DESC BE_NAME " " "Driver"
@@ -63,7 +63,7 @@
63#define BEISCSI_SGLIST_ELEMENTS 30 63#define BEISCSI_SGLIST_ELEMENTS 30
64 64
65#define BEISCSI_CMD_PER_LUN 128 /* scsi_host->cmd_per_lun */ 65#define BEISCSI_CMD_PER_LUN 128 /* scsi_host->cmd_per_lun */
66#define BEISCSI_MAX_SECTORS 256 /* scsi_host->max_sectors */ 66#define BEISCSI_MAX_SECTORS 2048 /* scsi_host->max_sectors */
67 67
68#define BEISCSI_MAX_CMD_LEN 16 /* scsi_host->max_cmd_len */ 68#define BEISCSI_MAX_CMD_LEN 16 /* scsi_host->max_cmd_len */
69#define BEISCSI_NUM_MAX_LUN 256 /* scsi_host->max_lun */ 69#define BEISCSI_NUM_MAX_LUN 256 /* scsi_host->max_lun */
@@ -312,6 +312,7 @@ struct beiscsi_hba {
312 struct list_head hba_queue; 312 struct list_head hba_queue;
313 unsigned short *cid_array; 313 unsigned short *cid_array;
314 struct iscsi_endpoint **ep_array; 314 struct iscsi_endpoint **ep_array;
315 struct iscsi_boot_kset *boot_kset;
315 struct Scsi_Host *shost; 316 struct Scsi_Host *shost;
316 struct { 317 struct {
317 /** 318 /**
@@ -342,6 +343,8 @@ struct beiscsi_hba {
342 struct work_struct work_cqs; /* The work being queued */ 343 struct work_struct work_cqs; /* The work being queued */
343 struct be_ctrl_info ctrl; 344 struct be_ctrl_info ctrl;
344 unsigned int generation; 345 unsigned int generation;
346 unsigned int read_mac_address;
347 struct mgmt_session_info boot_sess;
345 struct invalidate_command_table inv_tbl[128]; 348 struct invalidate_command_table inv_tbl[128];
346 349
347}; 350};
diff --git a/drivers/scsi/be2iscsi/be_mgmt.c b/drivers/scsi/be2iscsi/be_mgmt.c
index 3f3fab91a7d1..26350e470bcc 100644
--- a/drivers/scsi/be2iscsi/be_mgmt.c
+++ b/drivers/scsi/be2iscsi/be_mgmt.c
@@ -20,6 +20,77 @@
20 20
21#include "be_mgmt.h" 21#include "be_mgmt.h"
22#include "be_iscsi.h" 22#include "be_iscsi.h"
23#include <scsi/scsi_transport_iscsi.h>
24
25unsigned int beiscsi_get_boot_target(struct beiscsi_hba *phba)
26{
27 struct be_ctrl_info *ctrl = &phba->ctrl;
28 struct be_mcc_wrb *wrb;
29 struct be_cmd_req_get_mac_addr *req;
30 unsigned int tag = 0;
31
32 SE_DEBUG(DBG_LVL_8, "In bescsi_get_boot_target\n");
33 spin_lock(&ctrl->mbox_lock);
34 tag = alloc_mcc_tag(phba);
35 if (!tag) {
36 spin_unlock(&ctrl->mbox_lock);
37 return tag;
38 }
39
40 wrb = wrb_from_mccq(phba);
41 req = embedded_payload(wrb);
42 wrb->tag0 |= tag;
43 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
44 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI_INI,
45 OPCODE_ISCSI_INI_BOOT_GET_BOOT_TARGET,
46 sizeof(*req));
47
48 be_mcc_notify(phba);
49 spin_unlock(&ctrl->mbox_lock);
50 return tag;
51}
52
53unsigned int beiscsi_get_session_info(struct beiscsi_hba *phba,
54 u32 boot_session_handle,
55 struct be_dma_mem *nonemb_cmd)
56{
57 struct be_ctrl_info *ctrl = &phba->ctrl;
58 struct be_mcc_wrb *wrb;
59 unsigned int tag = 0;
60 struct be_cmd_req_get_session *req;
61 struct be_cmd_resp_get_session *resp;
62 struct be_sge *sge;
63
64 SE_DEBUG(DBG_LVL_8, "In beiscsi_get_session_info\n");
65 spin_lock(&ctrl->mbox_lock);
66 tag = alloc_mcc_tag(phba);
67 if (!tag) {
68 spin_unlock(&ctrl->mbox_lock);
69 return tag;
70 }
71
72 nonemb_cmd->size = sizeof(*resp);
73 req = nonemb_cmd->va;
74 memset(req, 0, sizeof(*req));
75 wrb = wrb_from_mccq(phba);
76 sge = nonembedded_sgl(wrb);
77 wrb->tag0 |= tag;
78
79
80 wrb->tag0 |= tag;
81 be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1);
82 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI_INI,
83 OPCODE_ISCSI_INI_SESSION_GET_A_SESSION,
84 sizeof(*resp));
85 req->session_handle = boot_session_handle;
86 sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
87 sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF);
88 sge->len = cpu_to_le32(nonemb_cmd->size);
89
90 be_mcc_notify(phba);
91 spin_unlock(&ctrl->mbox_lock);
92 return tag;
93}
23 94
24int mgmt_get_fw_config(struct be_ctrl_info *ctrl, 95int mgmt_get_fw_config(struct be_ctrl_info *ctrl,
25 struct beiscsi_hba *phba) 96 struct beiscsi_hba *phba)
diff --git a/drivers/scsi/bfa/bfa_fcport.c b/drivers/scsi/bfa/bfa_fcport.c
index f0933d8d1eda..76867b5577fa 100644
--- a/drivers/scsi/bfa/bfa_fcport.c
+++ b/drivers/scsi/bfa/bfa_fcport.c
@@ -1310,7 +1310,7 @@ bfa_fcport_isr(struct bfa_s *bfa, struct bfi_msg_s *msg)
1310 break; 1310 break;
1311 1311
1312 case BFI_FCPORT_I2H_DISABLE_RSP: 1312 case BFI_FCPORT_I2H_DISABLE_RSP:
1313 if (fcport->msgtag == i2hmsg.penable_rsp->msgtag) 1313 if (fcport->msgtag == i2hmsg.pdisable_rsp->msgtag)
1314 bfa_sm_send_event(fcport, BFA_FCPORT_SM_FWRSP); 1314 bfa_sm_send_event(fcport, BFA_FCPORT_SM_FWRSP);
1315 break; 1315 break;
1316 1316
diff --git a/drivers/scsi/bfa/bfad.c b/drivers/scsi/bfa/bfad.c
index 915a29d6c7ad..ca04cc9d332f 100644
--- a/drivers/scsi/bfa/bfad.c
+++ b/drivers/scsi/bfa/bfad.c
@@ -788,6 +788,7 @@ bfad_drv_init(struct bfad_s *bfad)
788 memset(&driver_info, 0, sizeof(driver_info)); 788 memset(&driver_info, 0, sizeof(driver_info));
789 strncpy(driver_info.version, BFAD_DRIVER_VERSION, 789 strncpy(driver_info.version, BFAD_DRIVER_VERSION,
790 sizeof(driver_info.version) - 1); 790 sizeof(driver_info.version) - 1);
791 __kernel_param_lock();
791 if (host_name) 792 if (host_name)
792 strncpy(driver_info.host_machine_name, host_name, 793 strncpy(driver_info.host_machine_name, host_name,
793 sizeof(driver_info.host_machine_name) - 1); 794 sizeof(driver_info.host_machine_name) - 1);
@@ -797,6 +798,7 @@ bfad_drv_init(struct bfad_s *bfad)
797 if (os_patch) 798 if (os_patch)
798 strncpy(driver_info.host_os_patch, os_patch, 799 strncpy(driver_info.host_os_patch, os_patch,
799 sizeof(driver_info.host_os_patch) - 1); 800 sizeof(driver_info.host_os_patch) - 1);
801 __kernel_param_unlock();
800 802
801 strncpy(driver_info.os_device_name, bfad->pci_name, 803 strncpy(driver_info.os_device_name, bfad->pci_name,
802 sizeof(driver_info.os_device_name - 1)); 804 sizeof(driver_info.os_device_name - 1));
diff --git a/drivers/scsi/bfa/bfad_im.c b/drivers/scsi/bfa/bfad_im.c
index 678120b70460..6ef87f6fcdbb 100644
--- a/drivers/scsi/bfa/bfad_im.c
+++ b/drivers/scsi/bfa/bfad_im.c
@@ -291,7 +291,7 @@ bfad_im_reset_lun_handler(struct scsi_cmnd *cmnd)
291 struct bfa_tskim_s *tskim; 291 struct bfa_tskim_s *tskim;
292 struct bfad_itnim_s *itnim; 292 struct bfad_itnim_s *itnim;
293 struct bfa_itnim_s *bfa_itnim; 293 struct bfa_itnim_s *bfa_itnim;
294 DECLARE_WAIT_QUEUE_HEAD(wq); 294 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(wq);
295 int rc = SUCCESS; 295 int rc = SUCCESS;
296 unsigned long flags; 296 unsigned long flags;
297 enum bfi_tskim_status task_status; 297 enum bfi_tskim_status task_status;
@@ -353,7 +353,7 @@ bfad_im_reset_bus_handler(struct scsi_cmnd *cmnd)
353 struct bfad_itnim_s *itnim; 353 struct bfad_itnim_s *itnim;
354 unsigned long flags; 354 unsigned long flags;
355 u32 i, rc, err_cnt = 0; 355 u32 i, rc, err_cnt = 0;
356 DECLARE_WAIT_QUEUE_HEAD(wq); 356 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(wq);
357 enum bfi_tskim_status task_status; 357 enum bfi_tskim_status task_status;
358 358
359 spin_lock_irqsave(&bfad->bfad_lock, flags); 359 spin_lock_irqsave(&bfad->bfad_lock, flags);
diff --git a/drivers/scsi/bfa/include/protocol/fcp.h b/drivers/scsi/bfa/include/protocol/fcp.h
index 9ade68ad2853..74ea63ce84b7 100644
--- a/drivers/scsi/bfa/include/protocol/fcp.h
+++ b/drivers/scsi/bfa/include/protocol/fcp.h
@@ -18,6 +18,7 @@
18#ifndef __FCPPROTO_H__ 18#ifndef __FCPPROTO_H__
19#define __FCPPROTO_H__ 19#define __FCPPROTO_H__
20 20
21#include <linux/bitops.h>
21#include <protocol/scsi.h> 22#include <protocol/scsi.h>
22 23
23#pragma pack(1) 24#pragma pack(1)
@@ -102,9 +103,6 @@ enum {
102/* 103/*
103 * Task management flags field - only one bit shall be set 104 * Task management flags field - only one bit shall be set
104 */ 105 */
105#ifndef BIT
106#define BIT(_x) (1 << (_x))
107#endif
108enum fcp_tm_cmnd{ 106enum fcp_tm_cmnd{
109 FCP_TM_ABORT_TASK_SET = BIT(1), 107 FCP_TM_ABORT_TASK_SET = BIT(1),
110 FCP_TM_CLEAR_TASK_SET = BIT(2), 108 FCP_TM_CLEAR_TASK_SET = BIT(2),
diff --git a/drivers/scsi/bnx2i/Kconfig b/drivers/scsi/bnx2i/Kconfig
index 1e9f7141102b..45a6154ce972 100644
--- a/drivers/scsi/bnx2i/Kconfig
+++ b/drivers/scsi/bnx2i/Kconfig
@@ -1,10 +1,11 @@
1config SCSI_BNX2_ISCSI 1config SCSI_BNX2_ISCSI
2 tristate "Broadcom NetXtreme II iSCSI support" 2 tristate "Broadcom NetXtreme II iSCSI support"
3 depends on NET
4 depends on PCI
3 select SCSI_ISCSI_ATTRS 5 select SCSI_ISCSI_ATTRS
4 select NETDEVICES 6 select NETDEVICES
5 select NETDEV_1000 7 select NETDEV_1000
6 select CNIC 8 select CNIC
7 depends on PCI
8 ---help--- 9 ---help---
9 This driver supports iSCSI offload for the Broadcom NetXtreme II 10 This driver supports iSCSI offload for the Broadcom NetXtreme II
10 devices. 11 devices.
diff --git a/drivers/scsi/ch.c b/drivers/scsi/ch.c
index 4799d4391203..d6532187f616 100644
--- a/drivers/scsi/ch.c
+++ b/drivers/scsi/ch.c
@@ -84,10 +84,16 @@ static const char * vendor_labels[CH_TYPES-4] = {
84}; 84};
85// module_param_string_array(vendor_labels, NULL, 0444); 85// module_param_string_array(vendor_labels, NULL, 0444);
86 86
87#define dprintk(fmt, arg...) if (debug) \ 87#define DPRINTK(fmt, arg...) \
88 printk(KERN_DEBUG "%s: " fmt, ch->name , ## arg) 88do { \
89#define vprintk(fmt, arg...) if (verbose) \ 89 if (debug) \
90 printk(KERN_INFO "%s: " fmt, ch->name , ## arg) 90 printk(KERN_DEBUG "%s: " fmt, ch->name, ##arg); \
91} while (0)
92#define VPRINTK(level, fmt, arg...) \
93do { \
94 if (verbose) \
95 printk(level "%s: " fmt, ch->name, ##arg); \
96} while (0)
91 97
92/* ------------------------------------------------------------------- */ 98/* ------------------------------------------------------------------- */
93 99
@@ -186,7 +192,7 @@ ch_do_scsi(scsi_changer *ch, unsigned char *cmd,
186 retry: 192 retry:
187 errno = 0; 193 errno = 0;
188 if (debug) { 194 if (debug) {
189 dprintk("command: "); 195 DPRINTK("command: ");
190 __scsi_print_command(cmd); 196 __scsi_print_command(cmd);
191 } 197 }
192 198
@@ -194,7 +200,7 @@ ch_do_scsi(scsi_changer *ch, unsigned char *cmd,
194 buflength, &sshdr, timeout * HZ, 200 buflength, &sshdr, timeout * HZ,
195 MAX_RETRIES, NULL); 201 MAX_RETRIES, NULL);
196 202
197 dprintk("result: 0x%x\n",result); 203 DPRINTK("result: 0x%x\n",result);
198 if (driver_byte(result) & DRIVER_SENSE) { 204 if (driver_byte(result) & DRIVER_SENSE) {
199 if (debug) 205 if (debug)
200 scsi_print_sense_hdr(ch->name, &sshdr); 206 scsi_print_sense_hdr(ch->name, &sshdr);
@@ -250,7 +256,7 @@ ch_read_element_status(scsi_changer *ch, u_int elem, char *data)
250 cmd[9] = 255; 256 cmd[9] = 255;
251 if (0 == (result = ch_do_scsi(ch, cmd, buffer, 256, DMA_FROM_DEVICE))) { 257 if (0 == (result = ch_do_scsi(ch, cmd, buffer, 256, DMA_FROM_DEVICE))) {
252 if (((buffer[16] << 8) | buffer[17]) != elem) { 258 if (((buffer[16] << 8) | buffer[17]) != elem) {
253 dprintk("asked for element 0x%02x, got 0x%02x\n", 259 DPRINTK("asked for element 0x%02x, got 0x%02x\n",
254 elem,(buffer[16] << 8) | buffer[17]); 260 elem,(buffer[16] << 8) | buffer[17]);
255 kfree(buffer); 261 kfree(buffer);
256 return -EIO; 262 return -EIO;
@@ -259,10 +265,10 @@ ch_read_element_status(scsi_changer *ch, u_int elem, char *data)
259 } else { 265 } else {
260 if (ch->voltags) { 266 if (ch->voltags) {
261 ch->voltags = 0; 267 ch->voltags = 0;
262 vprintk("device has no volume tag support\n"); 268 VPRINTK(KERN_INFO, "device has no volume tag support\n");
263 goto retry; 269 goto retry;
264 } 270 }
265 dprintk("READ ELEMENT STATUS for element 0x%x failed\n",elem); 271 DPRINTK("READ ELEMENT STATUS for element 0x%x failed\n",elem);
266 } 272 }
267 kfree(buffer); 273 kfree(buffer);
268 return result; 274 return result;
@@ -274,12 +280,12 @@ ch_init_elem(scsi_changer *ch)
274 int err; 280 int err;
275 u_char cmd[6]; 281 u_char cmd[6];
276 282
277 vprintk("INITIALIZE ELEMENT STATUS, may take some time ...\n"); 283 VPRINTK(KERN_INFO, "INITIALIZE ELEMENT STATUS, may take some time ...\n");
278 memset(cmd,0,sizeof(cmd)); 284 memset(cmd,0,sizeof(cmd));
279 cmd[0] = INITIALIZE_ELEMENT_STATUS; 285 cmd[0] = INITIALIZE_ELEMENT_STATUS;
280 cmd[1] = ch->device->lun << 5; 286 cmd[1] = ch->device->lun << 5;
281 err = ch_do_scsi(ch, cmd, NULL, 0, DMA_NONE); 287 err = ch_do_scsi(ch, cmd, NULL, 0, DMA_NONE);
282 vprintk("... finished\n"); 288 VPRINTK(KERN_INFO, "... finished\n");
283 return err; 289 return err;
284} 290}
285 291
@@ -322,20 +328,20 @@ ch_readconfig(scsi_changer *ch)
322 (buffer[buffer[3]+18] << 8) | buffer[buffer[3]+19]; 328 (buffer[buffer[3]+18] << 8) | buffer[buffer[3]+19];
323 ch->counts[CHET_DT] = 329 ch->counts[CHET_DT] =
324 (buffer[buffer[3]+20] << 8) | buffer[buffer[3]+21]; 330 (buffer[buffer[3]+20] << 8) | buffer[buffer[3]+21];
325 vprintk("type #1 (mt): 0x%x+%d [medium transport]\n", 331 VPRINTK(KERN_INFO, "type #1 (mt): 0x%x+%d [medium transport]\n",
326 ch->firsts[CHET_MT], 332 ch->firsts[CHET_MT],
327 ch->counts[CHET_MT]); 333 ch->counts[CHET_MT]);
328 vprintk("type #2 (st): 0x%x+%d [storage]\n", 334 VPRINTK(KERN_INFO, "type #2 (st): 0x%x+%d [storage]\n",
329 ch->firsts[CHET_ST], 335 ch->firsts[CHET_ST],
330 ch->counts[CHET_ST]); 336 ch->counts[CHET_ST]);
331 vprintk("type #3 (ie): 0x%x+%d [import/export]\n", 337 VPRINTK(KERN_INFO, "type #3 (ie): 0x%x+%d [import/export]\n",
332 ch->firsts[CHET_IE], 338 ch->firsts[CHET_IE],
333 ch->counts[CHET_IE]); 339 ch->counts[CHET_IE]);
334 vprintk("type #4 (dt): 0x%x+%d [data transfer]\n", 340 VPRINTK(KERN_INFO, "type #4 (dt): 0x%x+%d [data transfer]\n",
335 ch->firsts[CHET_DT], 341 ch->firsts[CHET_DT],
336 ch->counts[CHET_DT]); 342 ch->counts[CHET_DT]);
337 } else { 343 } else {
338 vprintk("reading element address assigment page failed!\n"); 344 VPRINTK(KERN_INFO, "reading element address assigment page failed!\n");
339 } 345 }
340 346
341 /* vendor specific element types */ 347 /* vendor specific element types */
@@ -346,13 +352,13 @@ ch_readconfig(scsi_changer *ch)
346 continue; 352 continue;
347 ch->firsts[CHET_V1+i] = vendor_firsts[i]; 353 ch->firsts[CHET_V1+i] = vendor_firsts[i];
348 ch->counts[CHET_V1+i] = vendor_counts[i]; 354 ch->counts[CHET_V1+i] = vendor_counts[i];
349 vprintk("type #%d (v%d): 0x%x+%d [%s, vendor specific]\n", 355 VPRINTK(KERN_INFO, "type #%d (v%d): 0x%x+%d [%s, vendor specific]\n",
350 i+5,i+1,vendor_firsts[i],vendor_counts[i], 356 i+5,i+1,vendor_firsts[i],vendor_counts[i],
351 vendor_labels[i]); 357 vendor_labels[i]);
352 } 358 }
353 359
354 /* look up the devices of the data transfer elements */ 360 /* look up the devices of the data transfer elements */
355 ch->dt = kmalloc(ch->counts[CHET_DT]*sizeof(struct scsi_device), 361 ch->dt = kcalloc(ch->counts[CHET_DT], sizeof(*ch->dt),
356 GFP_KERNEL); 362 GFP_KERNEL);
357 363
358 if (!ch->dt) { 364 if (!ch->dt) {
@@ -366,21 +372,19 @@ ch_readconfig(scsi_changer *ch)
366 if (elem < CH_DT_MAX && -1 != dt_id[elem]) { 372 if (elem < CH_DT_MAX && -1 != dt_id[elem]) {
367 id = dt_id[elem]; 373 id = dt_id[elem];
368 lun = dt_lun[elem]; 374 lun = dt_lun[elem];
369 vprintk("dt 0x%x: [insmod option] ", 375 VPRINTK(KERN_INFO, "dt 0x%x: [insmod option] ",
370 elem+ch->firsts[CHET_DT]); 376 elem+ch->firsts[CHET_DT]);
371 } else if (0 != ch_read_element_status 377 } else if (0 != ch_read_element_status
372 (ch,elem+ch->firsts[CHET_DT],data)) { 378 (ch,elem+ch->firsts[CHET_DT],data)) {
373 vprintk("dt 0x%x: READ ELEMENT STATUS failed\n", 379 VPRINTK(KERN_INFO, "dt 0x%x: READ ELEMENT STATUS failed\n",
374 elem+ch->firsts[CHET_DT]); 380 elem+ch->firsts[CHET_DT]);
375 } else { 381 } else {
376 vprintk("dt 0x%x: ",elem+ch->firsts[CHET_DT]); 382 VPRINTK(KERN_INFO, "dt 0x%x: ",elem+ch->firsts[CHET_DT]);
377 if (data[6] & 0x80) { 383 if (data[6] & 0x80) {
378 if (verbose) 384 VPRINTK(KERN_CONT, "not this SCSI bus\n");
379 printk("not this SCSI bus\n");
380 ch->dt[elem] = NULL; 385 ch->dt[elem] = NULL;
381 } else if (0 == (data[6] & 0x30)) { 386 } else if (0 == (data[6] & 0x30)) {
382 if (verbose) 387 VPRINTK(KERN_CONT, "ID/LUN unknown\n");
383 printk("ID/LUN unknown\n");
384 ch->dt[elem] = NULL; 388 ch->dt[elem] = NULL;
385 } else { 389 } else {
386 id = ch->device->id; 390 id = ch->device->id;
@@ -390,22 +394,19 @@ ch_readconfig(scsi_changer *ch)
390 } 394 }
391 } 395 }
392 if (-1 != id) { 396 if (-1 != id) {
393 if (verbose) 397 VPRINTK(KERN_CONT, "ID %i, LUN %i, ",id,lun);
394 printk("ID %i, LUN %i, ",id,lun);
395 ch->dt[elem] = 398 ch->dt[elem] =
396 scsi_device_lookup(ch->device->host, 399 scsi_device_lookup(ch->device->host,
397 ch->device->channel, 400 ch->device->channel,
398 id,lun); 401 id,lun);
399 if (!ch->dt[elem]) { 402 if (!ch->dt[elem]) {
400 /* should not happen */ 403 /* should not happen */
401 if (verbose) 404 VPRINTK(KERN_CONT, "Huh? device not found!\n");
402 printk("Huh? device not found!\n");
403 } else { 405 } else {
404 if (verbose) 406 VPRINTK(KERN_CONT, "name: %8.8s %16.16s %4.4s\n",
405 printk("name: %8.8s %16.16s %4.4s\n", 407 ch->dt[elem]->vendor,
406 ch->dt[elem]->vendor, 408 ch->dt[elem]->model,
407 ch->dt[elem]->model, 409 ch->dt[elem]->rev);
408 ch->dt[elem]->rev);
409 } 410 }
410 } 411 }
411 } 412 }
@@ -422,7 +423,7 @@ ch_position(scsi_changer *ch, u_int trans, u_int elem, int rotate)
422{ 423{
423 u_char cmd[10]; 424 u_char cmd[10];
424 425
425 dprintk("position: 0x%x\n",elem); 426 DPRINTK("position: 0x%x\n",elem);
426 if (0 == trans) 427 if (0 == trans)
427 trans = ch->firsts[CHET_MT]; 428 trans = ch->firsts[CHET_MT];
428 memset(cmd,0,sizeof(cmd)); 429 memset(cmd,0,sizeof(cmd));
@@ -441,7 +442,7 @@ ch_move(scsi_changer *ch, u_int trans, u_int src, u_int dest, int rotate)
441{ 442{
442 u_char cmd[12]; 443 u_char cmd[12];
443 444
444 dprintk("move: 0x%x => 0x%x\n",src,dest); 445 DPRINTK("move: 0x%x => 0x%x\n",src,dest);
445 if (0 == trans) 446 if (0 == trans)
446 trans = ch->firsts[CHET_MT]; 447 trans = ch->firsts[CHET_MT];
447 memset(cmd,0,sizeof(cmd)); 448 memset(cmd,0,sizeof(cmd));
@@ -463,7 +464,7 @@ ch_exchange(scsi_changer *ch, u_int trans, u_int src,
463{ 464{
464 u_char cmd[12]; 465 u_char cmd[12];
465 466
466 dprintk("exchange: 0x%x => 0x%x => 0x%x\n", 467 DPRINTK("exchange: 0x%x => 0x%x => 0x%x\n",
467 src,dest1,dest2); 468 src,dest1,dest2);
468 if (0 == trans) 469 if (0 == trans)
469 trans = ch->firsts[CHET_MT]; 470 trans = ch->firsts[CHET_MT];
@@ -511,7 +512,7 @@ ch_set_voltag(scsi_changer *ch, u_int elem,
511 if (!buffer) 512 if (!buffer)
512 return -ENOMEM; 513 return -ENOMEM;
513 514
514 dprintk("%s %s voltag: 0x%x => \"%s\"\n", 515 DPRINTK("%s %s voltag: 0x%x => \"%s\"\n",
515 clear ? "clear" : "set", 516 clear ? "clear" : "set",
516 alternate ? "alternate" : "primary", 517 alternate ? "alternate" : "primary",
517 elem, tag); 518 elem, tag);
@@ -550,7 +551,7 @@ static int ch_gstatus(scsi_changer *ch, int type, unsigned char __user *dest)
550 } 551 }
551 put_user(data[2], dest+i); 552 put_user(data[2], dest+i);
552 if (data[2] & CESTATUS_EXCEPT) 553 if (data[2] & CESTATUS_EXCEPT)
553 vprintk("element 0x%x: asc=0x%x, ascq=0x%x\n", 554 VPRINTK(KERN_INFO, "element 0x%x: asc=0x%x, ascq=0x%x\n",
554 ch->firsts[type]+i, 555 ch->firsts[type]+i,
555 (int)data[4],(int)data[5]); 556 (int)data[4],(int)data[5]);
556 retval = ch_read_element_status 557 retval = ch_read_element_status
@@ -660,7 +661,7 @@ static long ch_ioctl(struct file *file,
660 return -EFAULT; 661 return -EFAULT;
661 662
662 if (0 != ch_checkrange(ch, pos.cp_type, pos.cp_unit)) { 663 if (0 != ch_checkrange(ch, pos.cp_type, pos.cp_unit)) {
663 dprintk("CHIOPOSITION: invalid parameter\n"); 664 DPRINTK("CHIOPOSITION: invalid parameter\n");
664 return -EBADSLT; 665 return -EBADSLT;
665 } 666 }
666 mutex_lock(&ch->lock); 667 mutex_lock(&ch->lock);
@@ -680,7 +681,7 @@ static long ch_ioctl(struct file *file,
680 681
681 if (0 != ch_checkrange(ch, mv.cm_fromtype, mv.cm_fromunit) || 682 if (0 != ch_checkrange(ch, mv.cm_fromtype, mv.cm_fromunit) ||
682 0 != ch_checkrange(ch, mv.cm_totype, mv.cm_tounit )) { 683 0 != ch_checkrange(ch, mv.cm_totype, mv.cm_tounit )) {
683 dprintk("CHIOMOVE: invalid parameter\n"); 684 DPRINTK("CHIOMOVE: invalid parameter\n");
684 return -EBADSLT; 685 return -EBADSLT;
685 } 686 }
686 687
@@ -703,7 +704,7 @@ static long ch_ioctl(struct file *file,
703 if (0 != ch_checkrange(ch, mv.ce_srctype, mv.ce_srcunit ) || 704 if (0 != ch_checkrange(ch, mv.ce_srctype, mv.ce_srcunit ) ||
704 0 != ch_checkrange(ch, mv.ce_fdsttype, mv.ce_fdstunit) || 705 0 != ch_checkrange(ch, mv.ce_fdsttype, mv.ce_fdstunit) ||
705 0 != ch_checkrange(ch, mv.ce_sdsttype, mv.ce_sdstunit)) { 706 0 != ch_checkrange(ch, mv.ce_sdsttype, mv.ce_sdstunit)) {
706 dprintk("CHIOEXCHANGE: invalid parameter\n"); 707 DPRINTK("CHIOEXCHANGE: invalid parameter\n");
707 return -EBADSLT; 708 return -EBADSLT;
708 } 709 }
709 710
@@ -796,7 +797,7 @@ static long ch_ioctl(struct file *file,
796 } 797 }
797 } else if (ch->voltags) { 798 } else if (ch->voltags) {
798 ch->voltags = 0; 799 ch->voltags = 0;
799 vprintk("device has no volume tag support\n"); 800 VPRINTK(KERN_INFO, "device has no volume tag support\n");
800 goto voltag_retry; 801 goto voltag_retry;
801 } 802 }
802 kfree(buffer); 803 kfree(buffer);
@@ -824,7 +825,7 @@ static long ch_ioctl(struct file *file,
824 return -EFAULT; 825 return -EFAULT;
825 826
826 if (0 != ch_checkrange(ch, csv.csv_type, csv.csv_unit)) { 827 if (0 != ch_checkrange(ch, csv.csv_type, csv.csv_unit)) {
827 dprintk("CHIOSVOLTAG: invalid parameter\n"); 828 DPRINTK("CHIOSVOLTAG: invalid parameter\n");
828 return -EBADSLT; 829 return -EBADSLT;
829 } 830 }
830 elem = ch->firsts[csv.csv_type] + csv.csv_unit; 831 elem = ch->firsts[csv.csv_type] + csv.csv_unit;
diff --git a/drivers/scsi/dc395x.c b/drivers/scsi/dc395x.c
index bd977be7544e..54f50b07dac7 100644
--- a/drivers/scsi/dc395x.c
+++ b/drivers/scsi/dc395x.c
@@ -1597,7 +1597,7 @@ static u8 start_scsi(struct AdapterCtlBlk* acb, struct DeviceCtlBlk* dcb,
1597 u32 tag_mask = 1; 1597 u32 tag_mask = 1;
1598 u8 tag_number = 0; 1598 u8 tag_number = 0;
1599 while (tag_mask & dcb->tag_mask 1599 while (tag_mask & dcb->tag_mask
1600 && tag_number <= dcb->max_command) { 1600 && tag_number < dcb->max_command) {
1601 tag_mask = tag_mask << 1; 1601 tag_mask = tag_mask << 1;
1602 tag_number++; 1602 tag_number++;
1603 } 1603 }
diff --git a/drivers/scsi/fnic/fnic.h b/drivers/scsi/fnic/fnic.h
index 19338e0ba2c5..cbb20b13b228 100644
--- a/drivers/scsi/fnic/fnic.h
+++ b/drivers/scsi/fnic/fnic.h
@@ -21,6 +21,7 @@
21#include <linux/interrupt.h> 21#include <linux/interrupt.h>
22#include <linux/netdevice.h> 22#include <linux/netdevice.h>
23#include <linux/workqueue.h> 23#include <linux/workqueue.h>
24#include <linux/bitops.h>
24#include <scsi/libfc.h> 25#include <scsi/libfc.h>
25#include <scsi/libfcoe.h> 26#include <scsi/libfcoe.h>
26#include "fnic_io.h" 27#include "fnic_io.h"
@@ -49,7 +50,6 @@
49/* 50/*
50 * Tag bits used for special requests. 51 * Tag bits used for special requests.
51 */ 52 */
52#define BIT(nr) (1UL << (nr))
53#define FNIC_TAG_ABORT BIT(30) /* tag bit indicating abort */ 53#define FNIC_TAG_ABORT BIT(30) /* tag bit indicating abort */
54#define FNIC_TAG_DEV_RST BIT(29) /* indicates device reset */ 54#define FNIC_TAG_DEV_RST BIT(29) /* indicates device reset */
55#define FNIC_TAG_MASK (BIT(24) - 1) /* mask for lookup */ 55#define FNIC_TAG_MASK (BIT(24) - 1) /* mask for lookup */
diff --git a/drivers/scsi/g_NCR5380.c b/drivers/scsi/g_NCR5380.c
index 75585a52c88b..427a56d3117e 100644
--- a/drivers/scsi/g_NCR5380.c
+++ b/drivers/scsi/g_NCR5380.c
@@ -285,9 +285,12 @@ static int __init do_DTC3181E_setup(char *str)
285int __init generic_NCR5380_detect(struct scsi_host_template * tpnt) 285int __init generic_NCR5380_detect(struct scsi_host_template * tpnt)
286{ 286{
287 static int current_override = 0; 287 static int current_override = 0;
288 int count, i; 288 int count;
289 unsigned int *ports; 289 unsigned int *ports;
290#ifndef SCSI_G_NCR5380_MEM
291 int i;
290 unsigned long region_size = 16; 292 unsigned long region_size = 16;
293#endif
291 static unsigned int __initdata ncr_53c400a_ports[] = { 294 static unsigned int __initdata ncr_53c400a_ports[] = {
292 0x280, 0x290, 0x300, 0x310, 0x330, 0x340, 0x348, 0x350, 0 295 0x280, 0x290, 0x300, 0x310, 0x330, 0x340, 0x348, 0x350, 0
293 }; 296 };
@@ -296,7 +299,7 @@ int __init generic_NCR5380_detect(struct scsi_host_template * tpnt)
296 }; 299 };
297 int flags = 0; 300 int flags = 0;
298 struct Scsi_Host *instance; 301 struct Scsi_Host *instance;
299#ifdef CONFIG_SCSI_G_NCR5380_MEM 302#ifdef SCSI_G_NCR5380_MEM
300 unsigned long base; 303 unsigned long base;
301 void __iomem *iomem; 304 void __iomem *iomem;
302#endif 305#endif
@@ -315,17 +318,15 @@ int __init generic_NCR5380_detect(struct scsi_host_template * tpnt)
315 overrides[0].board = BOARD_NCR53C400A; 318 overrides[0].board = BOARD_NCR53C400A;
316 else if (dtc_3181e != NCR_NOT_SET) 319 else if (dtc_3181e != NCR_NOT_SET)
317 overrides[0].board = BOARD_DTC3181E; 320 overrides[0].board = BOARD_DTC3181E;
318 321#ifndef SCSI_G_NCR5380_MEM
319 if (!current_override && isapnp_present()) { 322 if (!current_override && isapnp_present()) {
320 struct pnp_dev *dev = NULL; 323 struct pnp_dev *dev = NULL;
321 count = 0; 324 count = 0;
322 while ((dev = pnp_find_dev(NULL, ISAPNP_VENDOR('D', 'T', 'C'), ISAPNP_FUNCTION(0x436e), dev))) { 325 while ((dev = pnp_find_dev(NULL, ISAPNP_VENDOR('D', 'T', 'C'), ISAPNP_FUNCTION(0x436e), dev))) {
323 if (count >= NO_OVERRIDES) 326 if (count >= NO_OVERRIDES)
324 break; 327 break;
325 if (pnp_device_attach(dev) < 0) { 328 if (pnp_device_attach(dev) < 0)
326 printk(KERN_ERR "dtc436e probe: attach failed\n");
327 continue; 329 continue;
328 }
329 if (pnp_activate_dev(dev) < 0) { 330 if (pnp_activate_dev(dev) < 0) {
330 printk(KERN_ERR "dtc436e probe: activate failed\n"); 331 printk(KERN_ERR "dtc436e probe: activate failed\n");
331 pnp_device_detach(dev); 332 pnp_device_detach(dev);
@@ -349,7 +350,7 @@ int __init generic_NCR5380_detect(struct scsi_host_template * tpnt)
349 count++; 350 count++;
350 } 351 }
351 } 352 }
352 353#endif
353 tpnt->proc_name = "g_NCR5380"; 354 tpnt->proc_name = "g_NCR5380";
354 355
355 for (count = 0; current_override < NO_OVERRIDES; ++current_override) { 356 for (count = 0; current_override < NO_OVERRIDES; ++current_override) {
@@ -374,7 +375,7 @@ int __init generic_NCR5380_detect(struct scsi_host_template * tpnt)
374 break; 375 break;
375 } 376 }
376 377
377#ifndef CONFIG_SCSI_G_NCR5380_MEM 378#ifndef SCSI_G_NCR5380_MEM
378 if (ports) { 379 if (ports) {
379 /* wakeup sequence for the NCR53C400A and DTC3181E */ 380 /* wakeup sequence for the NCR53C400A and DTC3181E */
380 381
@@ -436,7 +437,7 @@ int __init generic_NCR5380_detect(struct scsi_host_template * tpnt)
436#endif 437#endif
437 instance = scsi_register(tpnt, sizeof(struct NCR5380_hostdata)); 438 instance = scsi_register(tpnt, sizeof(struct NCR5380_hostdata));
438 if (instance == NULL) { 439 if (instance == NULL) {
439#ifndef CONFIG_SCSI_G_NCR5380_MEM 440#ifndef SCSI_G_NCR5380_MEM
440 release_region(overrides[current_override].NCR5380_map_name, region_size); 441 release_region(overrides[current_override].NCR5380_map_name, region_size);
441#else 442#else
442 iounmap(iomem); 443 iounmap(iomem);
@@ -446,10 +447,10 @@ int __init generic_NCR5380_detect(struct scsi_host_template * tpnt)
446 } 447 }
447 448
448 instance->NCR5380_instance_name = overrides[current_override].NCR5380_map_name; 449 instance->NCR5380_instance_name = overrides[current_override].NCR5380_map_name;
449#ifndef CONFIG_SCSI_G_NCR5380_MEM 450#ifndef SCSI_G_NCR5380_MEM
450 instance->n_io_port = region_size; 451 instance->n_io_port = region_size;
451#else 452#else
452 ((struct NCR5380_hostdata *)instance->hostdata).iomem = iomem; 453 ((struct NCR5380_hostdata *)instance->hostdata)->iomem = iomem;
453#endif 454#endif
454 455
455 NCR5380_init(instance, flags); 456 NCR5380_init(instance, flags);
@@ -517,10 +518,10 @@ int generic_NCR5380_release_resources(struct Scsi_Host *instance)
517 free_irq(instance->irq, instance); 518 free_irq(instance->irq, instance);
518 NCR5380_exit(instance); 519 NCR5380_exit(instance);
519 520
520#ifndef CONFIG_SCSI_G_NCR5380_MEM 521#ifndef SCSI_G_NCR5380_MEM
521 release_region(instance->NCR5380_instance_name, instance->n_io_port); 522 release_region(instance->NCR5380_instance_name, instance->n_io_port);
522#else 523#else
523 iounmap(((struct NCR5380_hostdata *)instance->hostdata).iomem); 524 iounmap(((struct NCR5380_hostdata *)instance->hostdata)->iomem);
524 release_mem_region(instance->NCR5380_instance_name, NCR5380_region_size); 525 release_mem_region(instance->NCR5380_instance_name, NCR5380_region_size);
525#endif 526#endif
526 527
@@ -590,14 +591,14 @@ static inline int NCR5380_pread(struct Scsi_Host *instance, unsigned char *dst,
590 } 591 }
591 while (NCR5380_read(C400_CONTROL_STATUS_REG) & CSR_HOST_BUF_NOT_RDY); 592 while (NCR5380_read(C400_CONTROL_STATUS_REG) & CSR_HOST_BUF_NOT_RDY);
592 593
593#ifndef CONFIG_SCSI_G_NCR5380_MEM 594#ifndef SCSI_G_NCR5380_MEM
594 { 595 {
595 int i; 596 int i;
596 for (i = 0; i < 128; i++) 597 for (i = 0; i < 128; i++)
597 dst[start + i] = NCR5380_read(C400_HOST_BUFFER); 598 dst[start + i] = NCR5380_read(C400_HOST_BUFFER);
598 } 599 }
599#else 600#else
600 /* implies CONFIG_SCSI_G_NCR5380_MEM */ 601 /* implies SCSI_G_NCR5380_MEM */
601 memcpy_fromio(dst + start, iomem + NCR53C400_host_buffer, 128); 602 memcpy_fromio(dst + start, iomem + NCR53C400_host_buffer, 128);
602#endif 603#endif
603 start += 128; 604 start += 128;
@@ -610,14 +611,14 @@ static inline int NCR5380_pread(struct Scsi_Host *instance, unsigned char *dst,
610 // FIXME - no timeout 611 // FIXME - no timeout
611 } 612 }
612 613
613#ifndef CONFIG_SCSI_G_NCR5380_MEM 614#ifndef SCSI_G_NCR5380_MEM
614 { 615 {
615 int i; 616 int i;
616 for (i = 0; i < 128; i++) 617 for (i = 0; i < 128; i++)
617 dst[start + i] = NCR5380_read(C400_HOST_BUFFER); 618 dst[start + i] = NCR5380_read(C400_HOST_BUFFER);
618 } 619 }
619#else 620#else
620 /* implies CONFIG_SCSI_G_NCR5380_MEM */ 621 /* implies SCSI_G_NCR5380_MEM */
621 memcpy_fromio(dst + start, iomem + NCR53C400_host_buffer, 128); 622 memcpy_fromio(dst + start, iomem + NCR53C400_host_buffer, 128);
622#endif 623#endif
623 start += 128; 624 start += 128;
@@ -676,13 +677,13 @@ static inline int NCR5380_pwrite(struct Scsi_Host *instance, unsigned char *src,
676 } 677 }
677 while (NCR5380_read(C400_CONTROL_STATUS_REG) & CSR_HOST_BUF_NOT_RDY) 678 while (NCR5380_read(C400_CONTROL_STATUS_REG) & CSR_HOST_BUF_NOT_RDY)
678 ; // FIXME - timeout 679 ; // FIXME - timeout
679#ifndef CONFIG_SCSI_G_NCR5380_MEM 680#ifndef SCSI_G_NCR5380_MEM
680 { 681 {
681 for (i = 0; i < 128; i++) 682 for (i = 0; i < 128; i++)
682 NCR5380_write(C400_HOST_BUFFER, src[start + i]); 683 NCR5380_write(C400_HOST_BUFFER, src[start + i]);
683 } 684 }
684#else 685#else
685 /* implies CONFIG_SCSI_G_NCR5380_MEM */ 686 /* implies SCSI_G_NCR5380_MEM */
686 memcpy_toio(iomem + NCR53C400_host_buffer, src + start, 128); 687 memcpy_toio(iomem + NCR53C400_host_buffer, src + start, 128);
687#endif 688#endif
688 start += 128; 689 start += 128;
@@ -692,13 +693,13 @@ static inline int NCR5380_pwrite(struct Scsi_Host *instance, unsigned char *src,
692 while (NCR5380_read(C400_CONTROL_STATUS_REG) & CSR_HOST_BUF_NOT_RDY) 693 while (NCR5380_read(C400_CONTROL_STATUS_REG) & CSR_HOST_BUF_NOT_RDY)
693 ; // FIXME - no timeout 694 ; // FIXME - no timeout
694 695
695#ifndef CONFIG_SCSI_G_NCR5380_MEM 696#ifndef SCSI_G_NCR5380_MEM
696 { 697 {
697 for (i = 0; i < 128; i++) 698 for (i = 0; i < 128; i++)
698 NCR5380_write(C400_HOST_BUFFER, src[start + i]); 699 NCR5380_write(C400_HOST_BUFFER, src[start + i]);
699 } 700 }
700#else 701#else
701 /* implies CONFIG_SCSI_G_NCR5380_MEM */ 702 /* implies SCSI_G_NCR5380_MEM */
702 memcpy_toio(iomem + NCR53C400_host_buffer, src + start, 128); 703 memcpy_toio(iomem + NCR53C400_host_buffer, src + start, 128);
703#endif 704#endif
704 start += 128; 705 start += 128;
@@ -938,7 +939,7 @@ module_param(ncr_53c400a, int, 0);
938module_param(dtc_3181e, int, 0); 939module_param(dtc_3181e, int, 0);
939MODULE_LICENSE("GPL"); 940MODULE_LICENSE("GPL");
940 941
941 942#ifndef SCSI_G_NCR5380_MEM
942static struct isapnp_device_id id_table[] __devinitdata = { 943static struct isapnp_device_id id_table[] __devinitdata = {
943 { 944 {
944 ISAPNP_ANY_ID, ISAPNP_ANY_ID, 945 ISAPNP_ANY_ID, ISAPNP_ANY_ID,
@@ -948,7 +949,7 @@ static struct isapnp_device_id id_table[] __devinitdata = {
948}; 949};
949 950
950MODULE_DEVICE_TABLE(isapnp, id_table); 951MODULE_DEVICE_TABLE(isapnp, id_table);
951 952#endif
952 953
953__setup("ncr5380=", do_NCR5380_setup); 954__setup("ncr5380=", do_NCR5380_setup);
954__setup("ncr53c400=", do_NCR53C400_setup); 955__setup("ncr53c400=", do_NCR53C400_setup);
diff --git a/drivers/scsi/g_NCR5380.h b/drivers/scsi/g_NCR5380.h
index df0b3f69ef63..921764c9ab24 100644
--- a/drivers/scsi/g_NCR5380.h
+++ b/drivers/scsi/g_NCR5380.h
@@ -63,7 +63,7 @@ static const char* generic_NCR5380_info(struct Scsi_Host *);
63#define __STRVAL(x) #x 63#define __STRVAL(x) #x
64#define STRVAL(x) __STRVAL(x) 64#define STRVAL(x) __STRVAL(x)
65 65
66#ifndef CONFIG_SCSI_G_NCR5380_MEM 66#ifndef SCSI_G_NCR5380_MEM
67 67
68#define NCR5380_map_config port 68#define NCR5380_map_config port
69#define NCR5380_map_type int 69#define NCR5380_map_type int
@@ -91,7 +91,7 @@ static const char* generic_NCR5380_info(struct Scsi_Host *);
91 NCR5380_map_name = (NCR5380_map_type)((instance)->NCR5380_instance_name) 91 NCR5380_map_name = (NCR5380_map_type)((instance)->NCR5380_instance_name)
92 92
93#else 93#else
94/* therefore CONFIG_SCSI_G_NCR5380_MEM */ 94/* therefore SCSI_G_NCR5380_MEM */
95 95
96#define NCR5380_map_config memory 96#define NCR5380_map_config memory
97#define NCR5380_map_type unsigned long 97#define NCR5380_map_type unsigned long
@@ -114,7 +114,7 @@ static const char* generic_NCR5380_info(struct Scsi_Host *);
114 register void __iomem *iomem 114 register void __iomem *iomem
115 115
116#define NCR5380_setup(instance) \ 116#define NCR5380_setup(instance) \
117 iomem = (((struct NCR5380_hostdata *)(instance)->hostdata).iomem) 117 iomem = (((struct NCR5380_hostdata *)(instance)->hostdata)->iomem)
118 118
119#endif 119#endif
120 120
diff --git a/drivers/scsi/gdth.c b/drivers/scsi/gdth.c
index f672d6213eea..b860d650a563 100644
--- a/drivers/scsi/gdth.c
+++ b/drivers/scsi/gdth.c
@@ -4914,7 +4914,7 @@ static int __init gdth_eisa_probe_one(u16 eisa_slot)
4914 4914
4915 error = scsi_add_host(shp, NULL); 4915 error = scsi_add_host(shp, NULL);
4916 if (error) 4916 if (error)
4917 goto out_free_coal_stat; 4917 goto out_free_ccb_phys;
4918 list_add_tail(&ha->list, &gdth_instances); 4918 list_add_tail(&ha->list, &gdth_instances);
4919 gdth_timer_init(); 4919 gdth_timer_init();
4920 4920
diff --git a/drivers/scsi/ibmvscsi/ibmvfc.c b/drivers/scsi/ibmvscsi/ibmvfc.c
index bd96cecaa619..9f75a6d519a2 100644
--- a/drivers/scsi/ibmvscsi/ibmvfc.c
+++ b/drivers/scsi/ibmvscsi/ibmvfc.c
@@ -433,6 +433,9 @@ static void ibmvfc_set_tgt_action(struct ibmvfc_target *tgt,
433{ 433{
434 switch (tgt->action) { 434 switch (tgt->action) {
435 case IBMVFC_TGT_ACTION_DEL_RPORT: 435 case IBMVFC_TGT_ACTION_DEL_RPORT:
436 if (action == IBMVFC_TGT_ACTION_DELETED_RPORT)
437 tgt->action = action;
438 case IBMVFC_TGT_ACTION_DELETED_RPORT:
436 break; 439 break;
437 default: 440 default:
438 if (action == IBMVFC_TGT_ACTION_DEL_RPORT) 441 if (action == IBMVFC_TGT_ACTION_DEL_RPORT)
@@ -2036,95 +2039,108 @@ static int ibmvfc_reset_device(struct scsi_device *sdev, int type, char *desc)
2036} 2039}
2037 2040
2038/** 2041/**
2039 * ibmvfc_abort_task_set - Abort outstanding commands to the device 2042 * ibmvfc_match_rport - Match function for specified remote port
2040 * @sdev: scsi device to abort commands 2043 * @evt: ibmvfc event struct
2041 * 2044 * @device: device to match (rport)
2042 * This sends an Abort Task Set to the VIOS for the specified device. This does
2043 * NOT send any cancel to the VIOS. That must be done separately.
2044 * 2045 *
2045 * Returns: 2046 * Returns:
2046 * 0 on success / other on failure 2047 * 1 if event matches rport / 0 if event does not match rport
2047 **/ 2048 **/
2048static int ibmvfc_abort_task_set(struct scsi_device *sdev) 2049static int ibmvfc_match_rport(struct ibmvfc_event *evt, void *rport)
2049{ 2050{
2050 struct ibmvfc_host *vhost = shost_priv(sdev->host); 2051 struct fc_rport *cmd_rport;
2051 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
2052 struct ibmvfc_cmd *tmf;
2053 struct ibmvfc_event *evt, *found_evt;
2054 union ibmvfc_iu rsp_iu;
2055 struct ibmvfc_fcp_rsp *fc_rsp = &rsp_iu.cmd.rsp;
2056 int rsp_rc = -EBUSY;
2057 unsigned long flags;
2058 int rsp_code = 0;
2059 2052
2060 spin_lock_irqsave(vhost->host->host_lock, flags); 2053 if (evt->cmnd) {
2061 found_evt = NULL; 2054 cmd_rport = starget_to_rport(scsi_target(evt->cmnd->device));
2062 list_for_each_entry(evt, &vhost->sent, queue) { 2055 if (cmd_rport == rport)
2063 if (evt->cmnd && evt->cmnd->device == sdev) { 2056 return 1;
2064 found_evt = evt;
2065 break;
2066 }
2067 }
2068
2069 if (!found_evt) {
2070 if (vhost->log_level > IBMVFC_DEFAULT_LOG_LEVEL)
2071 sdev_printk(KERN_INFO, sdev, "No events found to abort\n");
2072 spin_unlock_irqrestore(vhost->host->host_lock, flags);
2073 return 0;
2074 }
2075
2076 if (vhost->state == IBMVFC_ACTIVE) {
2077 evt = ibmvfc_get_event(vhost);
2078 ibmvfc_init_event(evt, ibmvfc_sync_completion, IBMVFC_CMD_FORMAT);
2079
2080 tmf = &evt->iu.cmd;
2081 memset(tmf, 0, sizeof(*tmf));
2082 tmf->resp.va = (u64)evt->crq.ioba + offsetof(struct ibmvfc_cmd, rsp);
2083 tmf->resp.len = sizeof(tmf->rsp);
2084 tmf->frame_type = IBMVFC_SCSI_FCP_TYPE;
2085 tmf->payload_len = sizeof(tmf->iu);
2086 tmf->resp_len = sizeof(tmf->rsp);
2087 tmf->cancel_key = (unsigned long)sdev->hostdata;
2088 tmf->tgt_scsi_id = rport->port_id;
2089 int_to_scsilun(sdev->lun, &tmf->iu.lun);
2090 tmf->flags = (IBMVFC_NO_MEM_DESC | IBMVFC_TMF);
2091 tmf->iu.tmf_flags = IBMVFC_ABORT_TASK_SET;
2092 evt->sync_iu = &rsp_iu;
2093
2094 init_completion(&evt->comp);
2095 rsp_rc = ibmvfc_send_event(evt, vhost, default_timeout);
2096 } 2057 }
2058 return 0;
2059}
2097 2060
2098 spin_unlock_irqrestore(vhost->host->host_lock, flags); 2061/**
2062 * ibmvfc_match_target - Match function for specified target
2063 * @evt: ibmvfc event struct
2064 * @device: device to match (starget)
2065 *
2066 * Returns:
2067 * 1 if event matches starget / 0 if event does not match starget
2068 **/
2069static int ibmvfc_match_target(struct ibmvfc_event *evt, void *device)
2070{
2071 if (evt->cmnd && scsi_target(evt->cmnd->device) == device)
2072 return 1;
2073 return 0;
2074}
2099 2075
2100 if (rsp_rc != 0) { 2076/**
2101 sdev_printk(KERN_ERR, sdev, "Failed to send abort. rc=%d\n", rsp_rc); 2077 * ibmvfc_match_lun - Match function for specified LUN
2102 return -EIO; 2078 * @evt: ibmvfc event struct
2103 } 2079 * @device: device to match (sdev)
2080 *
2081 * Returns:
2082 * 1 if event matches sdev / 0 if event does not match sdev
2083 **/
2084static int ibmvfc_match_lun(struct ibmvfc_event *evt, void *device)
2085{
2086 if (evt->cmnd && evt->cmnd->device == device)
2087 return 1;
2088 return 0;
2089}
2104 2090
2105 sdev_printk(KERN_INFO, sdev, "Aborting outstanding commands\n"); 2091/**
2106 wait_for_completion(&evt->comp); 2092 * ibmvfc_wait_for_ops - Wait for ops to complete
2093 * @vhost: ibmvfc host struct
2094 * @device: device to match (starget or sdev)
2095 * @match: match function
2096 *
2097 * Returns:
2098 * SUCCESS / FAILED
2099 **/
2100static int ibmvfc_wait_for_ops(struct ibmvfc_host *vhost, void *device,
2101 int (*match) (struct ibmvfc_event *, void *))
2102{
2103 struct ibmvfc_event *evt;
2104 DECLARE_COMPLETION_ONSTACK(comp);
2105 int wait;
2106 unsigned long flags;
2107 signed long timeout = IBMVFC_ABORT_WAIT_TIMEOUT * HZ;
2107 2108
2108 if (rsp_iu.cmd.status) 2109 ENTER;
2109 rsp_code = ibmvfc_get_err_result(&rsp_iu.cmd); 2110 do {
2111 wait = 0;
2112 spin_lock_irqsave(vhost->host->host_lock, flags);
2113 list_for_each_entry(evt, &vhost->sent, queue) {
2114 if (match(evt, device)) {
2115 evt->eh_comp = &comp;
2116 wait++;
2117 }
2118 }
2119 spin_unlock_irqrestore(vhost->host->host_lock, flags);
2110 2120
2111 if (rsp_code) { 2121 if (wait) {
2112 if (fc_rsp->flags & FCP_RSP_LEN_VALID) 2122 timeout = wait_for_completion_timeout(&comp, timeout);
2113 rsp_code = fc_rsp->data.info.rsp_code;
2114 2123
2115 sdev_printk(KERN_ERR, sdev, "Abort failed: %s (%x:%x) " 2124 if (!timeout) {
2116 "flags: %x fcp_rsp: %x, scsi_status: %x\n", 2125 wait = 0;
2117 ibmvfc_get_cmd_error(rsp_iu.cmd.status, rsp_iu.cmd.error), 2126 spin_lock_irqsave(vhost->host->host_lock, flags);
2118 rsp_iu.cmd.status, rsp_iu.cmd.error, fc_rsp->flags, rsp_code, 2127 list_for_each_entry(evt, &vhost->sent, queue) {
2119 fc_rsp->scsi_status); 2128 if (match(evt, device)) {
2120 rsp_rc = -EIO; 2129 evt->eh_comp = NULL;
2121 } else 2130 wait++;
2122 sdev_printk(KERN_INFO, sdev, "Abort successful\n"); 2131 }
2132 }
2133 spin_unlock_irqrestore(vhost->host->host_lock, flags);
2134 if (wait)
2135 dev_err(vhost->dev, "Timed out waiting for aborted commands\n");
2136 LEAVE;
2137 return wait ? FAILED : SUCCESS;
2138 }
2139 }
2140 } while (wait);
2123 2141
2124 spin_lock_irqsave(vhost->host->host_lock, flags); 2142 LEAVE;
2125 ibmvfc_free_event(evt); 2143 return SUCCESS;
2126 spin_unlock_irqrestore(vhost->host->host_lock, flags);
2127 return rsp_rc;
2128} 2144}
2129 2145
2130/** 2146/**
@@ -2212,88 +2228,130 @@ static int ibmvfc_cancel_all(struct scsi_device *sdev, int type)
2212} 2228}
2213 2229
2214/** 2230/**
2215 * ibmvfc_match_target - Match function for specified target 2231 * ibmvfc_match_key - Match function for specified cancel key
2216 * @evt: ibmvfc event struct 2232 * @evt: ibmvfc event struct
2217 * @device: device to match (starget) 2233 * @key: cancel key to match
2218 * 2234 *
2219 * Returns: 2235 * Returns:
2220 * 1 if event matches starget / 0 if event does not match starget 2236 * 1 if event matches key / 0 if event does not match key
2221 **/ 2237 **/
2222static int ibmvfc_match_target(struct ibmvfc_event *evt, void *device) 2238static int ibmvfc_match_key(struct ibmvfc_event *evt, void *key)
2223{ 2239{
2224 if (evt->cmnd && scsi_target(evt->cmnd->device) == device) 2240 unsigned long cancel_key = (unsigned long)key;
2225 return 1;
2226 return 0;
2227}
2228 2241
2229/** 2242 if (evt->crq.format == IBMVFC_CMD_FORMAT &&
2230 * ibmvfc_match_lun - Match function for specified LUN 2243 evt->iu.cmd.cancel_key == cancel_key)
2231 * @evt: ibmvfc event struct
2232 * @device: device to match (sdev)
2233 *
2234 * Returns:
2235 * 1 if event matches sdev / 0 if event does not match sdev
2236 **/
2237static int ibmvfc_match_lun(struct ibmvfc_event *evt, void *device)
2238{
2239 if (evt->cmnd && evt->cmnd->device == device)
2240 return 1; 2244 return 1;
2241 return 0; 2245 return 0;
2242} 2246}
2243 2247
2244/** 2248/**
2245 * ibmvfc_wait_for_ops - Wait for ops to complete 2249 * ibmvfc_abort_task_set - Abort outstanding commands to the device
2246 * @vhost: ibmvfc host struct 2250 * @sdev: scsi device to abort commands
2247 * @device: device to match (starget or sdev) 2251 *
2248 * @match: match function 2252 * This sends an Abort Task Set to the VIOS for the specified device. This does
2253 * NOT send any cancel to the VIOS. That must be done separately.
2249 * 2254 *
2250 * Returns: 2255 * Returns:
2251 * SUCCESS / FAILED 2256 * 0 on success / other on failure
2252 **/ 2257 **/
2253static int ibmvfc_wait_for_ops(struct ibmvfc_host *vhost, void *device, 2258static int ibmvfc_abort_task_set(struct scsi_device *sdev)
2254 int (*match) (struct ibmvfc_event *, void *))
2255{ 2259{
2256 struct ibmvfc_event *evt; 2260 struct ibmvfc_host *vhost = shost_priv(sdev->host);
2257 DECLARE_COMPLETION_ONSTACK(comp); 2261 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
2258 int wait; 2262 struct ibmvfc_cmd *tmf;
2259 unsigned long flags; 2263 struct ibmvfc_event *evt, *found_evt;
2260 signed long timeout = IBMVFC_ABORT_WAIT_TIMEOUT * HZ; 2264 union ibmvfc_iu rsp_iu;
2265 struct ibmvfc_fcp_rsp *fc_rsp = &rsp_iu.cmd.rsp;
2266 int rc, rsp_rc = -EBUSY;
2267 unsigned long flags, timeout = IBMVFC_ABORT_TIMEOUT;
2268 int rsp_code = 0;
2261 2269
2262 ENTER; 2270 spin_lock_irqsave(vhost->host->host_lock, flags);
2263 do { 2271 found_evt = NULL;
2264 wait = 0; 2272 list_for_each_entry(evt, &vhost->sent, queue) {
2265 spin_lock_irqsave(vhost->host->host_lock, flags); 2273 if (evt->cmnd && evt->cmnd->device == sdev) {
2266 list_for_each_entry(evt, &vhost->sent, queue) { 2274 found_evt = evt;
2267 if (match(evt, device)) { 2275 break;
2268 evt->eh_comp = &comp;
2269 wait++;
2270 }
2271 } 2276 }
2277 }
2278
2279 if (!found_evt) {
2280 if (vhost->log_level > IBMVFC_DEFAULT_LOG_LEVEL)
2281 sdev_printk(KERN_INFO, sdev, "No events found to abort\n");
2272 spin_unlock_irqrestore(vhost->host->host_lock, flags); 2282 spin_unlock_irqrestore(vhost->host->host_lock, flags);
2283 return 0;
2284 }
2273 2285
2274 if (wait) { 2286 if (vhost->state == IBMVFC_ACTIVE) {
2275 timeout = wait_for_completion_timeout(&comp, timeout); 2287 evt = ibmvfc_get_event(vhost);
2288 ibmvfc_init_event(evt, ibmvfc_sync_completion, IBMVFC_CMD_FORMAT);
2276 2289
2277 if (!timeout) { 2290 tmf = &evt->iu.cmd;
2278 wait = 0; 2291 memset(tmf, 0, sizeof(*tmf));
2279 spin_lock_irqsave(vhost->host->host_lock, flags); 2292 tmf->resp.va = (u64)evt->crq.ioba + offsetof(struct ibmvfc_cmd, rsp);
2280 list_for_each_entry(evt, &vhost->sent, queue) { 2293 tmf->resp.len = sizeof(tmf->rsp);
2281 if (match(evt, device)) { 2294 tmf->frame_type = IBMVFC_SCSI_FCP_TYPE;
2282 evt->eh_comp = NULL; 2295 tmf->payload_len = sizeof(tmf->iu);
2283 wait++; 2296 tmf->resp_len = sizeof(tmf->rsp);
2284 } 2297 tmf->cancel_key = (unsigned long)sdev->hostdata;
2285 } 2298 tmf->tgt_scsi_id = rport->port_id;
2286 spin_unlock_irqrestore(vhost->host->host_lock, flags); 2299 int_to_scsilun(sdev->lun, &tmf->iu.lun);
2287 if (wait) 2300 tmf->flags = (IBMVFC_NO_MEM_DESC | IBMVFC_TMF);
2288 dev_err(vhost->dev, "Timed out waiting for aborted commands\n"); 2301 tmf->iu.tmf_flags = IBMVFC_ABORT_TASK_SET;
2289 LEAVE; 2302 evt->sync_iu = &rsp_iu;
2290 return wait ? FAILED : SUCCESS; 2303
2291 } 2304 init_completion(&evt->comp);
2305 rsp_rc = ibmvfc_send_event(evt, vhost, default_timeout);
2306 }
2307
2308 spin_unlock_irqrestore(vhost->host->host_lock, flags);
2309
2310 if (rsp_rc != 0) {
2311 sdev_printk(KERN_ERR, sdev, "Failed to send abort. rc=%d\n", rsp_rc);
2312 return -EIO;
2313 }
2314
2315 sdev_printk(KERN_INFO, sdev, "Aborting outstanding commands\n");
2316 timeout = wait_for_completion_timeout(&evt->comp, timeout);
2317
2318 if (!timeout) {
2319 rc = ibmvfc_cancel_all(sdev, IBMVFC_TMF_ABORT_TASK_SET);
2320 if (!rc) {
2321 rc = ibmvfc_wait_for_ops(vhost, sdev->hostdata, ibmvfc_match_key);
2322 if (rc == SUCCESS)
2323 rc = 0;
2292 } 2324 }
2293 } while (wait);
2294 2325
2295 LEAVE; 2326 if (rc) {
2296 return SUCCESS; 2327 sdev_printk(KERN_INFO, sdev, "Cancel failed, resetting host\n");
2328 ibmvfc_reset_host(vhost);
2329 rsp_rc = 0;
2330 goto out;
2331 }
2332 }
2333
2334 if (rsp_iu.cmd.status)
2335 rsp_code = ibmvfc_get_err_result(&rsp_iu.cmd);
2336
2337 if (rsp_code) {
2338 if (fc_rsp->flags & FCP_RSP_LEN_VALID)
2339 rsp_code = fc_rsp->data.info.rsp_code;
2340
2341 sdev_printk(KERN_ERR, sdev, "Abort failed: %s (%x:%x) "
2342 "flags: %x fcp_rsp: %x, scsi_status: %x\n",
2343 ibmvfc_get_cmd_error(rsp_iu.cmd.status, rsp_iu.cmd.error),
2344 rsp_iu.cmd.status, rsp_iu.cmd.error, fc_rsp->flags, rsp_code,
2345 fc_rsp->scsi_status);
2346 rsp_rc = -EIO;
2347 } else
2348 sdev_printk(KERN_INFO, sdev, "Abort successful\n");
2349
2350out:
2351 spin_lock_irqsave(vhost->host->host_lock, flags);
2352 ibmvfc_free_event(evt);
2353 spin_unlock_irqrestore(vhost->host->host_lock, flags);
2354 return rsp_rc;
2297} 2355}
2298 2356
2299/** 2357/**
@@ -2351,18 +2409,6 @@ static int ibmvfc_eh_device_reset_handler(struct scsi_cmnd *cmd)
2351} 2409}
2352 2410
2353/** 2411/**
2354 * ibmvfc_dev_cancel_all_abts - Device iterated cancel all function
2355 * @sdev: scsi device struct
2356 * @data: return code
2357 *
2358 **/
2359static void ibmvfc_dev_cancel_all_abts(struct scsi_device *sdev, void *data)
2360{
2361 unsigned long *rc = data;
2362 *rc |= ibmvfc_cancel_all(sdev, IBMVFC_TMF_ABORT_TASK_SET);
2363}
2364
2365/**
2366 * ibmvfc_dev_cancel_all_reset - Device iterated cancel all function 2412 * ibmvfc_dev_cancel_all_reset - Device iterated cancel all function
2367 * @sdev: scsi device struct 2413 * @sdev: scsi device struct
2368 * @data: return code 2414 * @data: return code
@@ -2375,18 +2421,6 @@ static void ibmvfc_dev_cancel_all_reset(struct scsi_device *sdev, void *data)
2375} 2421}
2376 2422
2377/** 2423/**
2378 * ibmvfc_dev_abort_all - Device iterated abort task set function
2379 * @sdev: scsi device struct
2380 * @data: return code
2381 *
2382 **/
2383static void ibmvfc_dev_abort_all(struct scsi_device *sdev, void *data)
2384{
2385 unsigned long *rc = data;
2386 *rc |= ibmvfc_abort_task_set(sdev);
2387}
2388
2389/**
2390 * ibmvfc_eh_target_reset_handler - Reset the target 2424 * ibmvfc_eh_target_reset_handler - Reset the target
2391 * @cmd: scsi command struct 2425 * @cmd: scsi command struct
2392 * 2426 *
@@ -2440,19 +2474,22 @@ static int ibmvfc_eh_host_reset_handler(struct scsi_cmnd *cmd)
2440 **/ 2474 **/
2441static void ibmvfc_terminate_rport_io(struct fc_rport *rport) 2475static void ibmvfc_terminate_rport_io(struct fc_rport *rport)
2442{ 2476{
2443 struct scsi_target *starget = to_scsi_target(&rport->dev); 2477 struct Scsi_Host *shost = rport_to_shost(rport);
2444 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
2445 struct ibmvfc_host *vhost = shost_priv(shost); 2478 struct ibmvfc_host *vhost = shost_priv(shost);
2446 unsigned long cancel_rc = 0; 2479 struct fc_rport *dev_rport;
2447 unsigned long abort_rc = 0; 2480 struct scsi_device *sdev;
2448 int rc = FAILED; 2481 unsigned long rc;
2449 2482
2450 ENTER; 2483 ENTER;
2451 starget_for_each_device(starget, &cancel_rc, ibmvfc_dev_cancel_all_abts); 2484 shost_for_each_device(sdev, shost) {
2452 starget_for_each_device(starget, &abort_rc, ibmvfc_dev_abort_all); 2485 dev_rport = starget_to_rport(scsi_target(sdev));
2486 if (dev_rport != rport)
2487 continue;
2488 ibmvfc_cancel_all(sdev, IBMVFC_TMF_ABORT_TASK_SET);
2489 ibmvfc_abort_task_set(sdev);
2490 }
2453 2491
2454 if (!cancel_rc && !abort_rc) 2492 rc = ibmvfc_wait_for_ops(vhost, rport, ibmvfc_match_rport);
2455 rc = ibmvfc_wait_for_ops(vhost, starget, ibmvfc_match_target);
2456 2493
2457 if (rc == FAILED) 2494 if (rc == FAILED)
2458 ibmvfc_issue_fc_host_lip(shost); 2495 ibmvfc_issue_fc_host_lip(shost);
@@ -4193,11 +4230,15 @@ static void ibmvfc_tgt_add_rport(struct ibmvfc_target *tgt)
4193 if (rport && tgt->action == IBMVFC_TGT_ACTION_DEL_RPORT) { 4230 if (rport && tgt->action == IBMVFC_TGT_ACTION_DEL_RPORT) {
4194 tgt_dbg(tgt, "Deleting rport\n"); 4231 tgt_dbg(tgt, "Deleting rport\n");
4195 list_del(&tgt->queue); 4232 list_del(&tgt->queue);
4233 ibmvfc_set_tgt_action(tgt, IBMVFC_TGT_ACTION_DELETED_RPORT);
4196 spin_unlock_irqrestore(vhost->host->host_lock, flags); 4234 spin_unlock_irqrestore(vhost->host->host_lock, flags);
4197 fc_remote_port_delete(rport); 4235 fc_remote_port_delete(rport);
4198 del_timer_sync(&tgt->timer); 4236 del_timer_sync(&tgt->timer);
4199 kref_put(&tgt->kref, ibmvfc_release_tgt); 4237 kref_put(&tgt->kref, ibmvfc_release_tgt);
4200 return; 4238 return;
4239 } else if (rport && tgt->action == IBMVFC_TGT_ACTION_DELETED_RPORT) {
4240 spin_unlock_irqrestore(vhost->host->host_lock, flags);
4241 return;
4201 } 4242 }
4202 4243
4203 if (rport) { 4244 if (rport) {
@@ -4297,6 +4338,7 @@ static void ibmvfc_do_work(struct ibmvfc_host *vhost)
4297 rport = tgt->rport; 4338 rport = tgt->rport;
4298 tgt->rport = NULL; 4339 tgt->rport = NULL;
4299 list_del(&tgt->queue); 4340 list_del(&tgt->queue);
4341 ibmvfc_set_tgt_action(tgt, IBMVFC_TGT_ACTION_DELETED_RPORT);
4300 spin_unlock_irqrestore(vhost->host->host_lock, flags); 4342 spin_unlock_irqrestore(vhost->host->host_lock, flags);
4301 if (rport) 4343 if (rport)
4302 fc_remote_port_delete(rport); 4344 fc_remote_port_delete(rport);
diff --git a/drivers/scsi/ibmvscsi/ibmvfc.h b/drivers/scsi/ibmvscsi/ibmvfc.h
index d7e8dcd90650..608af394c8cf 100644
--- a/drivers/scsi/ibmvscsi/ibmvfc.h
+++ b/drivers/scsi/ibmvscsi/ibmvfc.h
@@ -29,8 +29,8 @@
29#include "viosrp.h" 29#include "viosrp.h"
30 30
31#define IBMVFC_NAME "ibmvfc" 31#define IBMVFC_NAME "ibmvfc"
32#define IBMVFC_DRIVER_VERSION "1.0.8" 32#define IBMVFC_DRIVER_VERSION "1.0.9"
33#define IBMVFC_DRIVER_DATE "(June 17, 2010)" 33#define IBMVFC_DRIVER_DATE "(August 5, 2010)"
34 34
35#define IBMVFC_DEFAULT_TIMEOUT 60 35#define IBMVFC_DEFAULT_TIMEOUT 60
36#define IBMVFC_ADISC_CANCEL_TIMEOUT 45 36#define IBMVFC_ADISC_CANCEL_TIMEOUT 45
@@ -38,6 +38,7 @@
38#define IBMVFC_ADISC_PLUS_CANCEL_TIMEOUT \ 38#define IBMVFC_ADISC_PLUS_CANCEL_TIMEOUT \
39 (IBMVFC_ADISC_TIMEOUT + IBMVFC_ADISC_CANCEL_TIMEOUT) 39 (IBMVFC_ADISC_TIMEOUT + IBMVFC_ADISC_CANCEL_TIMEOUT)
40#define IBMVFC_INIT_TIMEOUT 120 40#define IBMVFC_INIT_TIMEOUT 120
41#define IBMVFC_ABORT_TIMEOUT 8
41#define IBMVFC_ABORT_WAIT_TIMEOUT 40 42#define IBMVFC_ABORT_WAIT_TIMEOUT 40
42#define IBMVFC_MAX_REQUESTS_DEFAULT 100 43#define IBMVFC_MAX_REQUESTS_DEFAULT 100
43 44
@@ -597,6 +598,7 @@ enum ibmvfc_target_action {
597 IBMVFC_TGT_ACTION_INIT, 598 IBMVFC_TGT_ACTION_INIT,
598 IBMVFC_TGT_ACTION_INIT_WAIT, 599 IBMVFC_TGT_ACTION_INIT_WAIT,
599 IBMVFC_TGT_ACTION_DEL_RPORT, 600 IBMVFC_TGT_ACTION_DEL_RPORT,
601 IBMVFC_TGT_ACTION_DELETED_RPORT,
600}; 602};
601 603
602struct ibmvfc_target { 604struct ibmvfc_target {
diff --git a/drivers/scsi/initio.c b/drivers/scsi/initio.c
index a7714160fbc3..108797761b95 100644
--- a/drivers/scsi/initio.c
+++ b/drivers/scsi/initio.c
@@ -2817,7 +2817,6 @@ static void i91uSCBPost(u8 * host_mem, u8 * cblk_mem)
2817 } 2817 }
2818 2818
2819 cmnd->result = cblk->tastat | (cblk->hastat << 16); 2819 cmnd->result = cblk->tastat | (cblk->hastat << 16);
2820 WARN_ON(cmnd == NULL);
2821 i91u_unmap_scb(host->pci_dev, cmnd); 2820 i91u_unmap_scb(host->pci_dev, cmnd);
2822 cmnd->scsi_done(cmnd); /* Notify system DONE */ 2821 cmnd->scsi_done(cmnd); /* Notify system DONE */
2823 initio_release_scb(host, cblk); /* Release SCB for current channel */ 2822 initio_release_scb(host, cblk); /* Release SCB for current channel */
diff --git a/drivers/firmware/iscsi_boot_sysfs.c b/drivers/scsi/iscsi_boot_sysfs.c
index df6bff7366cf..df6bff7366cf 100644
--- a/drivers/firmware/iscsi_boot_sysfs.c
+++ b/drivers/scsi/iscsi_boot_sysfs.c
diff --git a/drivers/scsi/libfc/fc_fcp.c b/drivers/scsi/libfc/fc_fcp.c
index eac4d09314eb..c797f6b48f05 100644
--- a/drivers/scsi/libfc/fc_fcp.c
+++ b/drivers/scsi/libfc/fc_fcp.c
@@ -1765,14 +1765,14 @@ int fc_queuecommand(struct scsi_cmnd *sc_cmd, void (*done)(struct scsi_cmnd *))
1765 struct fcoe_dev_stats *stats; 1765 struct fcoe_dev_stats *stats;
1766 1766
1767 lport = shost_priv(sc_cmd->device->host); 1767 lport = shost_priv(sc_cmd->device->host);
1768 spin_unlock_irq(lport->host->host_lock);
1769 1768
1770 rval = fc_remote_port_chkready(rport); 1769 rval = fc_remote_port_chkready(rport);
1771 if (rval) { 1770 if (rval) {
1772 sc_cmd->result = rval; 1771 sc_cmd->result = rval;
1773 done(sc_cmd); 1772 done(sc_cmd);
1774 goto out; 1773 return 0;
1775 } 1774 }
1775 spin_unlock_irq(lport->host->host_lock);
1776 1776
1777 if (!*(struct fc_remote_port **)rport->dd_data) { 1777 if (!*(struct fc_remote_port **)rport->dd_data) {
1778 /* 1778 /*
diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
index 3482d5a5aed2..a50aa03b8ac1 100644
--- a/drivers/scsi/lpfc/lpfc.h
+++ b/drivers/scsi/lpfc/lpfc.h
@@ -775,6 +775,7 @@ struct lpfc_hba {
775 uint8_t temp_sensor_support; 775 uint8_t temp_sensor_support;
776 /* Fields used for heart beat. */ 776 /* Fields used for heart beat. */
777 unsigned long last_completion_time; 777 unsigned long last_completion_time;
778 unsigned long skipped_hb;
778 struct timer_list hb_tmofunc; 779 struct timer_list hb_tmofunc;
779 uint8_t hb_outstanding; 780 uint8_t hb_outstanding;
780 enum hba_temp_state over_temp_state; 781 enum hba_temp_state over_temp_state;
@@ -817,6 +818,8 @@ struct lpfc_hba {
817 uint32_t iocb_cnt; 818 uint32_t iocb_cnt;
818 uint32_t iocb_max; 819 uint32_t iocb_max;
819 atomic_t sdev_cnt; 820 atomic_t sdev_cnt;
821 uint8_t fips_spec_rev;
822 uint8_t fips_level;
820}; 823};
821 824
822static inline struct Scsi_Host * 825static inline struct Scsi_Host *
diff --git a/drivers/scsi/lpfc/lpfc_attr.c b/drivers/scsi/lpfc/lpfc_attr.c
index 162704cf6a96..23ce45708335 100644
--- a/drivers/scsi/lpfc/lpfc_attr.c
+++ b/drivers/scsi/lpfc/lpfc_attr.c
@@ -25,6 +25,7 @@
25#include <linux/interrupt.h> 25#include <linux/interrupt.h>
26#include <linux/aer.h> 26#include <linux/aer.h>
27#include <linux/gfp.h> 27#include <linux/gfp.h>
28#include <linux/kernel.h>
28 29
29#include <scsi/scsi.h> 30#include <scsi/scsi.h>
30#include <scsi/scsi_device.h> 31#include <scsi/scsi_device.h>
@@ -1239,6 +1240,44 @@ lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1239} 1240}
1240 1241
1241/** 1242/**
1243 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1244 * @dev: class unused variable.
1245 * @attr: device attribute, not used.
1246 * @buf: on return contains the module description text.
1247 *
1248 * Returns: size of formatted string.
1249 **/
1250static ssize_t
1251lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1252 char *buf)
1253{
1254 struct Scsi_Host *shost = class_to_shost(dev);
1255 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1256 struct lpfc_hba *phba = vport->phba;
1257
1258 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1259}
1260
1261/**
1262 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1263 * @dev: class unused variable.
1264 * @attr: device attribute, not used.
1265 * @buf: on return contains the module description text.
1266 *
1267 * Returns: size of formatted string.
1268 **/
1269static ssize_t
1270lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1271 char *buf)
1272{
1273 struct Scsi_Host *shost = class_to_shost(dev);
1274 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1275 struct lpfc_hba *phba = vport->phba;
1276
1277 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1278}
1279
1280/**
1242 * lpfc_param_show - Return a cfg attribute value in decimal 1281 * lpfc_param_show - Return a cfg attribute value in decimal
1243 * 1282 *
1244 * Description: 1283 * Description:
@@ -1676,6 +1715,8 @@ static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
1676static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL); 1715static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
1677static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL); 1716static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
1678static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL); 1717static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
1718static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
1719static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
1679 1720
1680 1721
1681static char *lpfc_soft_wwn_key = "C99G71SL8032A"; 1722static char *lpfc_soft_wwn_key = "C99G71SL8032A";
@@ -1795,12 +1836,11 @@ lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
1795 1836
1796 /* Validate and store the new name */ 1837 /* Validate and store the new name */
1797 for (i=0, j=0; i < 16; i++) { 1838 for (i=0, j=0; i < 16; i++) {
1798 if ((*buf >= 'a') && (*buf <= 'f')) 1839 int value;
1799 j = ((j << 4) | ((*buf++ -'a') + 10)); 1840
1800 else if ((*buf >= 'A') && (*buf <= 'F')) 1841 value = hex_to_bin(*buf++);
1801 j = ((j << 4) | ((*buf++ -'A') + 10)); 1842 if (value >= 0)
1802 else if ((*buf >= '0') && (*buf <= '9')) 1843 j = (j << 4) | value;
1803 j = ((j << 4) | (*buf++ -'0'));
1804 else 1844 else
1805 return -EINVAL; 1845 return -EINVAL;
1806 if (i % 2) { 1846 if (i % 2) {
@@ -1888,12 +1928,11 @@ lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
1888 1928
1889 /* Validate and store the new name */ 1929 /* Validate and store the new name */
1890 for (i=0, j=0; i < 16; i++) { 1930 for (i=0, j=0; i < 16; i++) {
1891 if ((*buf >= 'a') && (*buf <= 'f')) 1931 int value;
1892 j = ((j << 4) | ((*buf++ -'a') + 10)); 1932
1893 else if ((*buf >= 'A') && (*buf <= 'F')) 1933 value = hex_to_bin(*buf++);
1894 j = ((j << 4) | ((*buf++ -'A') + 10)); 1934 if (value >= 0)
1895 else if ((*buf >= '0') && (*buf <= '9')) 1935 j = (j << 4) | value;
1896 j = ((j << 4) | (*buf++ -'0'));
1897 else 1936 else
1898 return -EINVAL; 1937 return -EINVAL;
1899 if (i % 2) { 1938 if (i % 2) {
@@ -3279,7 +3318,7 @@ LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
3279# - Default will result in registering capabilities for all profiles. 3318# - Default will result in registering capabilities for all profiles.
3280# 3319#
3281*/ 3320*/
3282unsigned int lpfc_prot_mask = SHOST_DIX_TYPE0_PROTECTION; 3321unsigned int lpfc_prot_mask = SHOST_DIF_TYPE1_PROTECTION;
3283 3322
3284module_param(lpfc_prot_mask, uint, 0); 3323module_param(lpfc_prot_mask, uint, 0);
3285MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask"); 3324MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
@@ -3384,6 +3423,8 @@ struct device_attribute *lpfc_hba_attrs[] = {
3384 &dev_attr_iocb_hw, 3423 &dev_attr_iocb_hw,
3385 &dev_attr_txq_hw, 3424 &dev_attr_txq_hw,
3386 &dev_attr_txcmplq_hw, 3425 &dev_attr_txcmplq_hw,
3426 &dev_attr_lpfc_fips_level,
3427 &dev_attr_lpfc_fips_rev,
3387 NULL, 3428 NULL,
3388}; 3429};
3389 3430
@@ -3410,6 +3451,8 @@ struct device_attribute *lpfc_vport_attrs[] = {
3410 &dev_attr_lpfc_max_scsicmpl_time, 3451 &dev_attr_lpfc_max_scsicmpl_time,
3411 &dev_attr_lpfc_stat_data_ctrl, 3452 &dev_attr_lpfc_stat_data_ctrl,
3412 &dev_attr_lpfc_static_vport, 3453 &dev_attr_lpfc_static_vport,
3454 &dev_attr_lpfc_fips_level,
3455 &dev_attr_lpfc_fips_rev,
3413 NULL, 3456 NULL,
3414}; 3457};
3415 3458
diff --git a/drivers/scsi/lpfc/lpfc_bsg.c b/drivers/scsi/lpfc/lpfc_bsg.c
index d521569e6620..49d0cf99c24c 100644
--- a/drivers/scsi/lpfc/lpfc_bsg.c
+++ b/drivers/scsi/lpfc/lpfc_bsg.c
@@ -2724,15 +2724,6 @@ lpfc_bsg_issue_mbox(struct lpfc_hba *phba, struct fc_bsg_job *job,
2724 2724
2725 pmboxq->context2 = ext; 2725 pmboxq->context2 = ext;
2726 pmboxq->in_ext_byte_len = 2726 pmboxq->in_ext_byte_len =
2727 mbox_req->inExtWLen *
2728 sizeof(uint32_t);
2729 pmboxq->out_ext_byte_len =
2730 mbox_req->outExtWLen *
2731 sizeof(uint32_t);
2732 pmboxq->mbox_offset_word =
2733 mbox_req->mbOffset;
2734 pmboxq->context2 = ext;
2735 pmboxq->in_ext_byte_len =
2736 mbox_req->inExtWLen * sizeof(uint32_t); 2727 mbox_req->inExtWLen * sizeof(uint32_t);
2737 pmboxq->out_ext_byte_len = 2728 pmboxq->out_ext_byte_len =
2738 mbox_req->outExtWLen * sizeof(uint32_t); 2729 mbox_req->outExtWLen * sizeof(uint32_t);
diff --git a/drivers/scsi/lpfc/lpfc_compat.h b/drivers/scsi/lpfc/lpfc_compat.h
index a11f1ae7b98e..75e2e569dede 100644
--- a/drivers/scsi/lpfc/lpfc_compat.h
+++ b/drivers/scsi/lpfc/lpfc_compat.h
@@ -82,8 +82,7 @@ lpfc_memcpy_from_slim( void *dest, void __iomem *src, unsigned int bytes)
82static inline void 82static inline void
83lpfc_memcpy_to_slim( void __iomem *dest, void *src, unsigned int bytes) 83lpfc_memcpy_to_slim( void __iomem *dest, void *src, unsigned int bytes)
84{ 84{
85 /* actually returns 1 byte past dest */ 85 __iowrite32_copy(dest, src, bytes);
86 memcpy_toio( dest, src, bytes);
87} 86}
88 87
89static inline void 88static inline void
diff --git a/drivers/scsi/lpfc/lpfc_els.c b/drivers/scsi/lpfc/lpfc_els.c
index afbed6bc31f0..8d09191c327e 100644
--- a/drivers/scsi/lpfc/lpfc_els.c
+++ b/drivers/scsi/lpfc/lpfc_els.c
@@ -600,6 +600,14 @@ lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
600 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; 600 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
601 spin_unlock_irq(shost->host_lock); 601 spin_unlock_irq(shost->host_lock);
602 } 602 }
603 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
604 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
605 /*
606 * Driver needs to re-reg VPI in order for f/w
607 * to update the MAC address.
608 */
609 lpfc_register_new_vport(phba, vport, ndlp);
610 return 0;
603 } 611 }
604 612
605 if (phba->sli_rev < LPFC_SLI_REV4) { 613 if (phba->sli_rev < LPFC_SLI_REV4) {
@@ -801,9 +809,12 @@ lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
801 (irsp->un.ulpWord[4] != IOERR_SLI_ABORTED)) { 809 (irsp->un.ulpWord[4] != IOERR_SLI_ABORTED)) {
802 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS, 810 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
803 "2611 FLOGI failed on registered " 811 "2611 FLOGI failed on registered "
804 "FCF record fcf_index:%d, trying " 812 "FCF record fcf_index(%d), status: "
805 "to perform round robin failover\n", 813 "x%x/x%x, tmo:x%x, trying to perform "
806 phba->fcf.current_rec.fcf_indx); 814 "round robin failover\n",
815 phba->fcf.current_rec.fcf_indx,
816 irsp->ulpStatus, irsp->un.ulpWord[4],
817 irsp->ulpTimeout);
807 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba); 818 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
808 if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) { 819 if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) {
809 /* 820 /*
@@ -841,6 +852,12 @@ lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
841 } 852 }
842 } 853 }
843 854
855 /* FLOGI failure */
856 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
857 "2858 FLOGI failure Status:x%x/x%x TMO:x%x\n",
858 irsp->ulpStatus, irsp->un.ulpWord[4],
859 irsp->ulpTimeout);
860
844 /* Check for retry */ 861 /* Check for retry */
845 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) 862 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
846 goto out; 863 goto out;
@@ -1291,6 +1308,8 @@ lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
1291 struct serv_parm *sp; 1308 struct serv_parm *sp;
1292 uint8_t name[sizeof(struct lpfc_name)]; 1309 uint8_t name[sizeof(struct lpfc_name)];
1293 uint32_t rc, keepDID = 0; 1310 uint32_t rc, keepDID = 0;
1311 int put_node;
1312 int put_rport;
1294 1313
1295 /* Fabric nodes can have the same WWPN so we don't bother searching 1314 /* Fabric nodes can have the same WWPN so we don't bother searching
1296 * by WWPN. Just return the ndlp that was given to us. 1315 * by WWPN. Just return the ndlp that was given to us.
@@ -1379,6 +1398,28 @@ lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
1379 /* Two ndlps cannot have the same did */ 1398 /* Two ndlps cannot have the same did */
1380 ndlp->nlp_DID = keepDID; 1399 ndlp->nlp_DID = keepDID;
1381 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE); 1400 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1401 /* Since we are swapping the ndlp passed in with the new one
1402 * and the did has already been swapped, copy over the
1403 * state and names.
1404 */
1405 memcpy(&new_ndlp->nlp_portname, &ndlp->nlp_portname,
1406 sizeof(struct lpfc_name));
1407 memcpy(&new_ndlp->nlp_nodename, &ndlp->nlp_nodename,
1408 sizeof(struct lpfc_name));
1409 new_ndlp->nlp_state = ndlp->nlp_state;
1410 /* Fix up the rport accordingly */
1411 rport = ndlp->rport;
1412 if (rport) {
1413 rdata = rport->dd_data;
1414 put_node = rdata->pnode != NULL;
1415 put_rport = ndlp->rport != NULL;
1416 rdata->pnode = NULL;
1417 ndlp->rport = NULL;
1418 if (put_node)
1419 lpfc_nlp_put(ndlp);
1420 if (put_rport)
1421 put_device(&rport->dev);
1422 }
1382 } 1423 }
1383 return new_ndlp; 1424 return new_ndlp;
1384} 1425}
@@ -2880,6 +2921,17 @@ lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2880 retry = 0; 2921 retry = 0;
2881 2922
2882 if (retry) { 2923 if (retry) {
2924 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
2925 /* Stop retrying PLOGI and FDISC if in FCF discovery */
2926 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
2927 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2928 "2849 Stop retry ELS command "
2929 "x%x to remote NPORT x%x, "
2930 "Data: x%x x%x\n", cmd, did,
2931 cmdiocb->retry, delay);
2932 return 0;
2933 }
2934 }
2883 2935
2884 /* Retry ELS command <elsCmd> to remote NPORT <did> */ 2936 /* Retry ELS command <elsCmd> to remote NPORT <did> */
2885 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 2937 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
@@ -6076,8 +6128,12 @@ lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6076 6128
6077 if (mb->mbxStatus) { 6129 if (mb->mbxStatus) {
6078 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, 6130 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6079 "0915 Register VPI failed: 0x%x\n", 6131 "0915 Register VPI failed : Status: x%x"
6080 mb->mbxStatus); 6132 " upd bit: x%x \n", mb->mbxStatus,
6133 mb->un.varRegVpi.upd);
6134 if (phba->sli_rev == LPFC_SLI_REV4 &&
6135 mb->un.varRegVpi.upd)
6136 goto mbox_err_exit ;
6081 6137
6082 switch (mb->mbxStatus) { 6138 switch (mb->mbxStatus) {
6083 case 0x11: /* unsupported feature */ 6139 case 0x11: /* unsupported feature */
@@ -6142,7 +6198,7 @@ lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6142 } else 6198 } else
6143 lpfc_do_scr_ns_plogi(phba, vport); 6199 lpfc_do_scr_ns_plogi(phba, vport);
6144 } 6200 }
6145 6201mbox_err_exit:
6146 /* Now, we decrement the ndlp reference count held for this 6202 /* Now, we decrement the ndlp reference count held for this
6147 * callback function 6203 * callback function
6148 */ 6204 */
@@ -6387,6 +6443,14 @@ lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6387 else 6443 else
6388 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG; 6444 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
6389 spin_unlock_irq(shost->host_lock); 6445 spin_unlock_irq(shost->host_lock);
6446 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
6447 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
6448 /*
6449 * Driver needs to re-reg VPI in order for f/w
6450 * to update the MAC address.
6451 */
6452 lpfc_register_new_vport(phba, vport, ndlp);
6453 return ;
6390 } 6454 }
6391 6455
6392 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI) 6456 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
diff --git a/drivers/scsi/lpfc/lpfc_hbadisc.c b/drivers/scsi/lpfc/lpfc_hbadisc.c
index 0639c994349c..1f62ea8c165d 100644
--- a/drivers/scsi/lpfc/lpfc_hbadisc.c
+++ b/drivers/scsi/lpfc/lpfc_hbadisc.c
@@ -588,7 +588,7 @@ lpfc_work_done(struct lpfc_hba *phba)
588 (status & 588 (status &
589 HA_RXMASK)); 589 HA_RXMASK));
590 } 590 }
591 if (pring->txq_cnt) 591 if ((phba->sli_rev == LPFC_SLI_REV4) && pring->txq_cnt)
592 lpfc_drain_txq(phba); 592 lpfc_drain_txq(phba);
593 /* 593 /*
594 * Turn on Ring interrupts 594 * Turn on Ring interrupts
@@ -1852,8 +1852,7 @@ lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1852 __lpfc_sli4_stop_fcf_redisc_wait_timer(phba); 1852 __lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
1853 else if (phba->fcf.fcf_flag & FCF_REDISC_FOV) 1853 else if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
1854 /* If in fast failover, mark it's completed */ 1854 /* If in fast failover, mark it's completed */
1855 phba->fcf.fcf_flag &= ~(FCF_REDISC_FOV | 1855 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
1856 FCF_DISCOVERY);
1857 spin_unlock_irq(&phba->hbalock); 1856 spin_unlock_irq(&phba->hbalock);
1858 lpfc_printf_log(phba, KERN_INFO, LOG_FIP, 1857 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1859 "2836 The new FCF record (x%x) " 1858 "2836 The new FCF record (x%x) "
@@ -2651,7 +2650,6 @@ lpfc_mbx_process_link_up(struct lpfc_hba *phba, READ_LA_VAR *la)
2651 spin_unlock_irq(&phba->hbalock); 2650 spin_unlock_irq(&phba->hbalock);
2652 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, 2651 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
2653 "2778 Start FCF table scan at linkup\n"); 2652 "2778 Start FCF table scan at linkup\n");
2654
2655 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, 2653 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2656 LPFC_FCOE_FCF_GET_FIRST); 2654 LPFC_FCOE_FCF_GET_FIRST);
2657 if (rc) { 2655 if (rc) {
@@ -2660,6 +2658,9 @@ lpfc_mbx_process_link_up(struct lpfc_hba *phba, READ_LA_VAR *la)
2660 spin_unlock_irq(&phba->hbalock); 2658 spin_unlock_irq(&phba->hbalock);
2661 goto out; 2659 goto out;
2662 } 2660 }
2661 /* Reset FCF roundrobin bmask for new discovery */
2662 memset(phba->fcf.fcf_rr_bmask, 0,
2663 sizeof(*phba->fcf.fcf_rr_bmask));
2663 } 2664 }
2664 2665
2665 return; 2666 return;
@@ -5097,6 +5098,7 @@ static void
5097lpfc_unregister_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) 5098lpfc_unregister_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
5098{ 5099{
5099 struct lpfc_vport *vport = mboxq->vport; 5100 struct lpfc_vport *vport = mboxq->vport;
5101 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5100 5102
5101 if (mboxq->u.mb.mbxStatus) { 5103 if (mboxq->u.mb.mbxStatus) {
5102 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, 5104 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
@@ -5104,6 +5106,9 @@ lpfc_unregister_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
5104 "HBA state x%x\n", 5106 "HBA state x%x\n",
5105 mboxq->u.mb.mbxStatus, vport->port_state); 5107 mboxq->u.mb.mbxStatus, vport->port_state);
5106 } 5108 }
5109 spin_lock_irq(shost->host_lock);
5110 phba->pport->fc_flag &= ~FC_VFI_REGISTERED;
5111 spin_unlock_irq(shost->host_lock);
5107 mempool_free(mboxq, phba->mbox_mem_pool); 5112 mempool_free(mboxq, phba->mbox_mem_pool);
5108 return; 5113 return;
5109} 5114}
@@ -5285,6 +5290,10 @@ lpfc_unregister_fcf_rescan(struct lpfc_hba *phba)
5285 spin_lock_irq(&phba->hbalock); 5290 spin_lock_irq(&phba->hbalock);
5286 phba->fcf.fcf_flag |= FCF_INIT_DISC; 5291 phba->fcf.fcf_flag |= FCF_INIT_DISC;
5287 spin_unlock_irq(&phba->hbalock); 5292 spin_unlock_irq(&phba->hbalock);
5293
5294 /* Reset FCF roundrobin bmask for new discovery */
5295 memset(phba->fcf.fcf_rr_bmask, 0, sizeof(*phba->fcf.fcf_rr_bmask));
5296
5288 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST); 5297 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
5289 5298
5290 if (rc) { 5299 if (rc) {
diff --git a/drivers/scsi/lpfc/lpfc_hw.h b/drivers/scsi/lpfc/lpfc_hw.h
index f5dbf2be3eab..1676f61291e7 100644
--- a/drivers/scsi/lpfc/lpfc_hw.h
+++ b/drivers/scsi/lpfc/lpfc_hw.h
@@ -2291,7 +2291,8 @@ typedef struct {
2291typedef struct { 2291typedef struct {
2292#ifdef __BIG_ENDIAN_BITFIELD 2292#ifdef __BIG_ENDIAN_BITFIELD
2293 uint32_t rsvd1; 2293 uint32_t rsvd1;
2294 uint32_t rsvd2:8; 2294 uint32_t rsvd2:7;
2295 uint32_t upd:1;
2295 uint32_t sid:24; 2296 uint32_t sid:24;
2296 uint32_t wwn[2]; 2297 uint32_t wwn[2];
2297 uint32_t rsvd5; 2298 uint32_t rsvd5;
@@ -2300,7 +2301,8 @@ typedef struct {
2300#else /* __LITTLE_ENDIAN */ 2301#else /* __LITTLE_ENDIAN */
2301 uint32_t rsvd1; 2302 uint32_t rsvd1;
2302 uint32_t sid:24; 2303 uint32_t sid:24;
2303 uint32_t rsvd2:8; 2304 uint32_t upd:1;
2305 uint32_t rsvd2:7;
2304 uint32_t wwn[2]; 2306 uint32_t wwn[2];
2305 uint32_t rsvd5; 2307 uint32_t rsvd5;
2306 uint16_t vpi; 2308 uint16_t vpi;
@@ -2806,11 +2808,15 @@ typedef struct {
2806 uint32_t rsvd6; /* Reserved */ 2808 uint32_t rsvd6; /* Reserved */
2807 2809
2808#ifdef __BIG_ENDIAN_BITFIELD 2810#ifdef __BIG_ENDIAN_BITFIELD
2809 uint32_t rsvd7 : 16; /* Reserved */ 2811 uint32_t fips_rev : 3; /* FIPS Spec Revision */
2812 uint32_t fips_level : 4; /* FIPS Level */
2813 uint32_t sec_err : 9; /* security crypto error */
2810 uint32_t max_vpi : 16; /* Max number of virt N-Ports */ 2814 uint32_t max_vpi : 16; /* Max number of virt N-Ports */
2811#else /* __LITTLE_ENDIAN */ 2815#else /* __LITTLE_ENDIAN */
2812 uint32_t max_vpi : 16; /* Max number of virt N-Ports */ 2816 uint32_t max_vpi : 16; /* Max number of virt N-Ports */
2813 uint32_t rsvd7 : 16; /* Reserved */ 2817 uint32_t sec_err : 9; /* security crypto error */
2818 uint32_t fips_level : 4; /* FIPS Level */
2819 uint32_t fips_rev : 3; /* FIPS Spec Revision */
2814#endif 2820#endif
2815 2821
2816} CONFIG_PORT_VAR; 2822} CONFIG_PORT_VAR;
@@ -3441,63 +3447,63 @@ struct sli3_bg_fields {
3441static inline uint32_t 3447static inline uint32_t
3442lpfc_bgs_get_bidir_bg_prof(uint32_t bgstat) 3448lpfc_bgs_get_bidir_bg_prof(uint32_t bgstat)
3443{ 3449{
3444 return (le32_to_cpu(bgstat) & BGS_BIDIR_BG_PROF_MASK) >> 3450 return (bgstat & BGS_BIDIR_BG_PROF_MASK) >>
3445 BGS_BIDIR_BG_PROF_SHIFT; 3451 BGS_BIDIR_BG_PROF_SHIFT;
3446} 3452}
3447 3453
3448static inline uint32_t 3454static inline uint32_t
3449lpfc_bgs_get_bidir_err_cond(uint32_t bgstat) 3455lpfc_bgs_get_bidir_err_cond(uint32_t bgstat)
3450{ 3456{
3451 return (le32_to_cpu(bgstat) & BGS_BIDIR_ERR_COND_FLAGS_MASK) >> 3457 return (bgstat & BGS_BIDIR_ERR_COND_FLAGS_MASK) >>
3452 BGS_BIDIR_ERR_COND_SHIFT; 3458 BGS_BIDIR_ERR_COND_SHIFT;
3453} 3459}
3454 3460
3455static inline uint32_t 3461static inline uint32_t
3456lpfc_bgs_get_bg_prof(uint32_t bgstat) 3462lpfc_bgs_get_bg_prof(uint32_t bgstat)
3457{ 3463{
3458 return (le32_to_cpu(bgstat) & BGS_BG_PROFILE_MASK) >> 3464 return (bgstat & BGS_BG_PROFILE_MASK) >>
3459 BGS_BG_PROFILE_SHIFT; 3465 BGS_BG_PROFILE_SHIFT;
3460} 3466}
3461 3467
3462static inline uint32_t 3468static inline uint32_t
3463lpfc_bgs_get_invalid_prof(uint32_t bgstat) 3469lpfc_bgs_get_invalid_prof(uint32_t bgstat)
3464{ 3470{
3465 return (le32_to_cpu(bgstat) & BGS_INVALID_PROF_MASK) >> 3471 return (bgstat & BGS_INVALID_PROF_MASK) >>
3466 BGS_INVALID_PROF_SHIFT; 3472 BGS_INVALID_PROF_SHIFT;
3467} 3473}
3468 3474
3469static inline uint32_t 3475static inline uint32_t
3470lpfc_bgs_get_uninit_dif_block(uint32_t bgstat) 3476lpfc_bgs_get_uninit_dif_block(uint32_t bgstat)
3471{ 3477{
3472 return (le32_to_cpu(bgstat) & BGS_UNINIT_DIF_BLOCK_MASK) >> 3478 return (bgstat & BGS_UNINIT_DIF_BLOCK_MASK) >>
3473 BGS_UNINIT_DIF_BLOCK_SHIFT; 3479 BGS_UNINIT_DIF_BLOCK_SHIFT;
3474} 3480}
3475 3481
3476static inline uint32_t 3482static inline uint32_t
3477lpfc_bgs_get_hi_water_mark_present(uint32_t bgstat) 3483lpfc_bgs_get_hi_water_mark_present(uint32_t bgstat)
3478{ 3484{
3479 return (le32_to_cpu(bgstat) & BGS_HI_WATER_MARK_PRESENT_MASK) >> 3485 return (bgstat & BGS_HI_WATER_MARK_PRESENT_MASK) >>
3480 BGS_HI_WATER_MARK_PRESENT_SHIFT; 3486 BGS_HI_WATER_MARK_PRESENT_SHIFT;
3481} 3487}
3482 3488
3483static inline uint32_t 3489static inline uint32_t
3484lpfc_bgs_get_reftag_err(uint32_t bgstat) 3490lpfc_bgs_get_reftag_err(uint32_t bgstat)
3485{ 3491{
3486 return (le32_to_cpu(bgstat) & BGS_REFTAG_ERR_MASK) >> 3492 return (bgstat & BGS_REFTAG_ERR_MASK) >>
3487 BGS_REFTAG_ERR_SHIFT; 3493 BGS_REFTAG_ERR_SHIFT;
3488} 3494}
3489 3495
3490static inline uint32_t 3496static inline uint32_t
3491lpfc_bgs_get_apptag_err(uint32_t bgstat) 3497lpfc_bgs_get_apptag_err(uint32_t bgstat)
3492{ 3498{
3493 return (le32_to_cpu(bgstat) & BGS_APPTAG_ERR_MASK) >> 3499 return (bgstat & BGS_APPTAG_ERR_MASK) >>
3494 BGS_APPTAG_ERR_SHIFT; 3500 BGS_APPTAG_ERR_SHIFT;
3495} 3501}
3496 3502
3497static inline uint32_t 3503static inline uint32_t
3498lpfc_bgs_get_guard_err(uint32_t bgstat) 3504lpfc_bgs_get_guard_err(uint32_t bgstat)
3499{ 3505{
3500 return (le32_to_cpu(bgstat) & BGS_GUARD_ERR_MASK) >> 3506 return (bgstat & BGS_GUARD_ERR_MASK) >>
3501 BGS_GUARD_ERR_SHIFT; 3507 BGS_GUARD_ERR_SHIFT;
3502} 3508}
3503 3509
diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
index 2786ee3b605d..da9ba06ad583 100644
--- a/drivers/scsi/lpfc/lpfc_init.c
+++ b/drivers/scsi/lpfc/lpfc_init.c
@@ -1032,27 +1032,46 @@ lpfc_hb_timeout_handler(struct lpfc_hba *phba)
1032 /* If there is no heart beat outstanding, issue a heartbeat command */ 1032 /* If there is no heart beat outstanding, issue a heartbeat command */
1033 if (phba->cfg_enable_hba_heartbeat) { 1033 if (phba->cfg_enable_hba_heartbeat) {
1034 if (!phba->hb_outstanding) { 1034 if (!phba->hb_outstanding) {
1035 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL); 1035 if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) &&
1036 if (!pmboxq) { 1036 (list_empty(&psli->mboxq))) {
1037 mod_timer(&phba->hb_tmofunc, 1037 pmboxq = mempool_alloc(phba->mbox_mem_pool,
1038 jiffies + HZ * LPFC_HB_MBOX_INTERVAL); 1038 GFP_KERNEL);
1039 return; 1039 if (!pmboxq) {
1040 } 1040 mod_timer(&phba->hb_tmofunc,
1041 jiffies +
1042 HZ * LPFC_HB_MBOX_INTERVAL);
1043 return;
1044 }
1041 1045
1042 lpfc_heart_beat(phba, pmboxq); 1046 lpfc_heart_beat(phba, pmboxq);
1043 pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl; 1047 pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
1044 pmboxq->vport = phba->pport; 1048 pmboxq->vport = phba->pport;
1045 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); 1049 retval = lpfc_sli_issue_mbox(phba, pmboxq,
1050 MBX_NOWAIT);
1051
1052 if (retval != MBX_BUSY &&
1053 retval != MBX_SUCCESS) {
1054 mempool_free(pmboxq,
1055 phba->mbox_mem_pool);
1056 mod_timer(&phba->hb_tmofunc,
1057 jiffies +
1058 HZ * LPFC_HB_MBOX_INTERVAL);
1059 return;
1060 }
1061 phba->skipped_hb = 0;
1062 phba->hb_outstanding = 1;
1063 } else if (time_before_eq(phba->last_completion_time,
1064 phba->skipped_hb)) {
1065 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1066 "2857 Last completion time not "
1067 " updated in %d ms\n",
1068 jiffies_to_msecs(jiffies
1069 - phba->last_completion_time));
1070 } else
1071 phba->skipped_hb = jiffies;
1046 1072
1047 if (retval != MBX_BUSY && retval != MBX_SUCCESS) {
1048 mempool_free(pmboxq, phba->mbox_mem_pool);
1049 mod_timer(&phba->hb_tmofunc,
1050 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
1051 return;
1052 }
1053 mod_timer(&phba->hb_tmofunc, 1073 mod_timer(&phba->hb_tmofunc,
1054 jiffies + HZ * LPFC_HB_MBOX_TIMEOUT); 1074 jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
1055 phba->hb_outstanding = 1;
1056 return; 1075 return;
1057 } else { 1076 } else {
1058 /* 1077 /*
@@ -3281,10 +3300,10 @@ lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport)
3281 if (!ndlp) 3300 if (!ndlp)
3282 return 0; 3301 return 0;
3283 } 3302 }
3284 if (phba->pport->port_state <= LPFC_FLOGI) 3303 if (phba->pport->port_state < LPFC_FLOGI)
3285 return NULL; 3304 return NULL;
3286 /* If virtual link is not yet instantiated ignore CVL */ 3305 /* If virtual link is not yet instantiated ignore CVL */
3287 if (vport->port_state <= LPFC_FDISC) 3306 if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC))
3288 return NULL; 3307 return NULL;
3289 shost = lpfc_shost_from_vport(vport); 3308 shost = lpfc_shost_from_vport(vport);
3290 if (!shost) 3309 if (!shost)
@@ -3357,21 +3376,7 @@ lpfc_sli4_async_fcoe_evt(struct lpfc_hba *phba,
3357 "evt_tag:x%x, fcf_index:x%x\n", 3376 "evt_tag:x%x, fcf_index:x%x\n",
3358 acqe_fcoe->event_tag, 3377 acqe_fcoe->event_tag,
3359 acqe_fcoe->index); 3378 acqe_fcoe->index);
3360 /* If the FCF discovery is in progress, do nothing. */ 3379 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
3361 spin_lock_irq(&phba->hbalock);
3362 if (phba->hba_flag & FCF_DISC_INPROGRESS) {
3363 spin_unlock_irq(&phba->hbalock);
3364 break;
3365 }
3366 /* If fast FCF failover rescan event is pending, do nothing */
3367 if (phba->fcf.fcf_flag & FCF_REDISC_EVT) {
3368 spin_unlock_irq(&phba->hbalock);
3369 break;
3370 }
3371 spin_unlock_irq(&phba->hbalock);
3372
3373 if ((phba->fcf.fcf_flag & FCF_DISCOVERY) &&
3374 !(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
3375 /* 3380 /*
3376 * During period of FCF discovery, read the FCF 3381 * During period of FCF discovery, read the FCF
3377 * table record indexed by the event to update 3382 * table record indexed by the event to update
@@ -3385,13 +3390,26 @@ lpfc_sli4_async_fcoe_evt(struct lpfc_hba *phba,
3385 acqe_fcoe->index); 3390 acqe_fcoe->index);
3386 rc = lpfc_sli4_read_fcf_rec(phba, acqe_fcoe->index); 3391 rc = lpfc_sli4_read_fcf_rec(phba, acqe_fcoe->index);
3387 } 3392 }
3388 /* If the FCF has been in discovered state, do nothing. */ 3393
3394 /* If the FCF discovery is in progress, do nothing. */
3389 spin_lock_irq(&phba->hbalock); 3395 spin_lock_irq(&phba->hbalock);
3396 if (phba->hba_flag & FCF_DISC_INPROGRESS) {
3397 spin_unlock_irq(&phba->hbalock);
3398 break;
3399 }
3400 /* If fast FCF failover rescan event is pending, do nothing */
3401 if (phba->fcf.fcf_flag & FCF_REDISC_EVT) {
3402 spin_unlock_irq(&phba->hbalock);
3403 break;
3404 }
3405
3406 /* If the FCF has been in discovered state, do nothing. */
3390 if (phba->fcf.fcf_flag & FCF_SCAN_DONE) { 3407 if (phba->fcf.fcf_flag & FCF_SCAN_DONE) {
3391 spin_unlock_irq(&phba->hbalock); 3408 spin_unlock_irq(&phba->hbalock);
3392 break; 3409 break;
3393 } 3410 }
3394 spin_unlock_irq(&phba->hbalock); 3411 spin_unlock_irq(&phba->hbalock);
3412
3395 /* Otherwise, scan the entire FCF table and re-discover SAN */ 3413 /* Otherwise, scan the entire FCF table and re-discover SAN */
3396 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, 3414 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
3397 "2770 Start FCF table scan due to new FCF " 3415 "2770 Start FCF table scan due to new FCF "
@@ -3417,13 +3435,9 @@ lpfc_sli4_async_fcoe_evt(struct lpfc_hba *phba,
3417 "2549 FCF disconnected from network index 0x%x" 3435 "2549 FCF disconnected from network index 0x%x"
3418 " tag 0x%x\n", acqe_fcoe->index, 3436 " tag 0x%x\n", acqe_fcoe->index,
3419 acqe_fcoe->event_tag); 3437 acqe_fcoe->event_tag);
3420 /* If the event is not for currently used fcf do nothing */ 3438 /*
3421 if (phba->fcf.current_rec.fcf_indx != acqe_fcoe->index) 3439 * If we are in the middle of FCF failover process, clear
3422 break; 3440 * the corresponding FCF bit in the roundrobin bitmap.
3423 /* We request port to rediscover the entire FCF table for
3424 * a fast recovery from case that the current FCF record
3425 * is no longer valid if we are not in the middle of FCF
3426 * failover process already.
3427 */ 3441 */
3428 spin_lock_irq(&phba->hbalock); 3442 spin_lock_irq(&phba->hbalock);
3429 if (phba->fcf.fcf_flag & FCF_DISCOVERY) { 3443 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
@@ -3432,9 +3446,23 @@ lpfc_sli4_async_fcoe_evt(struct lpfc_hba *phba,
3432 lpfc_sli4_fcf_rr_index_clear(phba, acqe_fcoe->index); 3446 lpfc_sli4_fcf_rr_index_clear(phba, acqe_fcoe->index);
3433 break; 3447 break;
3434 } 3448 }
3449 spin_unlock_irq(&phba->hbalock);
3450
3451 /* If the event is not for currently used fcf do nothing */
3452 if (phba->fcf.current_rec.fcf_indx != acqe_fcoe->index)
3453 break;
3454
3455 /*
3456 * Otherwise, request the port to rediscover the entire FCF
3457 * table for a fast recovery from case that the current FCF
3458 * is no longer valid as we are not in the middle of FCF
3459 * failover process already.
3460 */
3461 spin_lock_irq(&phba->hbalock);
3435 /* Mark the fast failover process in progress */ 3462 /* Mark the fast failover process in progress */
3436 phba->fcf.fcf_flag |= FCF_DEAD_DISC; 3463 phba->fcf.fcf_flag |= FCF_DEAD_DISC;
3437 spin_unlock_irq(&phba->hbalock); 3464 spin_unlock_irq(&phba->hbalock);
3465
3438 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, 3466 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
3439 "2771 Start FCF fast failover process due to " 3467 "2771 Start FCF fast failover process due to "
3440 "FCF DEAD event: evt_tag:x%x, fcf_index:x%x " 3468 "FCF DEAD event: evt_tag:x%x, fcf_index:x%x "
@@ -3454,12 +3482,16 @@ lpfc_sli4_async_fcoe_evt(struct lpfc_hba *phba,
3454 * as a link down to FCF registration. 3482 * as a link down to FCF registration.
3455 */ 3483 */
3456 lpfc_sli4_fcf_dead_failthrough(phba); 3484 lpfc_sli4_fcf_dead_failthrough(phba);
3457 } else 3485 } else {
3458 /* Handling fast FCF failover to a DEAD FCF event 3486 /* Reset FCF roundrobin bmask for new discovery */
3459 * is considered equalivant to receiving CVL to all 3487 memset(phba->fcf.fcf_rr_bmask, 0,
3460 * vports. 3488 sizeof(*phba->fcf.fcf_rr_bmask));
3489 /*
3490 * Handling fast FCF failover to a DEAD FCF event is
3491 * considered equalivant to receiving CVL to all vports.
3461 */ 3492 */
3462 lpfc_sli4_perform_all_vport_cvl(phba); 3493 lpfc_sli4_perform_all_vport_cvl(phba);
3494 }
3463 break; 3495 break;
3464 case LPFC_FCOE_EVENT_TYPE_CVL: 3496 case LPFC_FCOE_EVENT_TYPE_CVL:
3465 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, 3497 lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY,
@@ -3534,7 +3566,13 @@ lpfc_sli4_async_fcoe_evt(struct lpfc_hba *phba,
3534 * the current registered FCF entry. 3566 * the current registered FCF entry.
3535 */ 3567 */
3536 lpfc_retry_pport_discovery(phba); 3568 lpfc_retry_pport_discovery(phba);
3537 } 3569 } else
3570 /*
3571 * Reset FCF roundrobin bmask for new
3572 * discovery.
3573 */
3574 memset(phba->fcf.fcf_rr_bmask, 0,
3575 sizeof(*phba->fcf.fcf_rr_bmask));
3538 } 3576 }
3539 break; 3577 break;
3540 default: 3578 default:
diff --git a/drivers/scsi/lpfc/lpfc_mbox.c b/drivers/scsi/lpfc/lpfc_mbox.c
index 9c2c7c7140c7..0dfa310cd609 100644
--- a/drivers/scsi/lpfc/lpfc_mbox.c
+++ b/drivers/scsi/lpfc/lpfc_mbox.c
@@ -815,9 +815,15 @@ void
815lpfc_reg_vpi(struct lpfc_vport *vport, LPFC_MBOXQ_t *pmb) 815lpfc_reg_vpi(struct lpfc_vport *vport, LPFC_MBOXQ_t *pmb)
816{ 816{
817 MAILBOX_t *mb = &pmb->u.mb; 817 MAILBOX_t *mb = &pmb->u.mb;
818 struct lpfc_hba *phba = vport->phba;
818 819
819 memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 820 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
820 821 /*
822 * Set the re-reg VPI bit for f/w to update the MAC address.
823 */
824 if ((phba->sli_rev == LPFC_SLI_REV4) &&
825 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI))
826 mb->un.varRegVpi.upd = 1;
821 mb->un.varRegVpi.vpi = vport->vpi + vport->phba->vpi_base; 827 mb->un.varRegVpi.vpi = vport->vpi + vport->phba->vpi_base;
822 mb->un.varRegVpi.sid = vport->fc_myDID; 828 mb->un.varRegVpi.sid = vport->fc_myDID;
823 mb->un.varRegVpi.vfi = vport->vfi + vport->phba->vfi_base; 829 mb->un.varRegVpi.vfi = vport->vfi + vport->phba->vfi_base;
diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
index c818a7255962..2e51aa6b45b3 100644
--- a/drivers/scsi/lpfc/lpfc_scsi.c
+++ b/drivers/scsi/lpfc/lpfc_scsi.c
@@ -1325,7 +1325,7 @@ lpfc_bg_setup_bpl(struct lpfc_hba *phba, struct scsi_cmnd *sc,
1325 bf_set(pde5_type, pde5, LPFC_PDE5_DESCRIPTOR); 1325 bf_set(pde5_type, pde5, LPFC_PDE5_DESCRIPTOR);
1326 pde5->reftag = reftag; 1326 pde5->reftag = reftag;
1327 1327
1328 /* Endian convertion if necessary for PDE5 */ 1328 /* Endianness conversion if necessary for PDE5 */
1329 pde5->word0 = cpu_to_le32(pde5->word0); 1329 pde5->word0 = cpu_to_le32(pde5->word0);
1330 pde5->reftag = cpu_to_le32(pde5->reftag); 1330 pde5->reftag = cpu_to_le32(pde5->reftag);
1331 1331
@@ -1347,7 +1347,7 @@ lpfc_bg_setup_bpl(struct lpfc_hba *phba, struct scsi_cmnd *sc,
1347 bf_set(pde6_ai, pde6, 1); 1347 bf_set(pde6_ai, pde6, 1);
1348 bf_set(pde6_apptagval, pde6, apptagval); 1348 bf_set(pde6_apptagval, pde6, apptagval);
1349 1349
1350 /* Endian convertion if necessary for PDE6 */ 1350 /* Endianness conversion if necessary for PDE6 */
1351 pde6->word0 = cpu_to_le32(pde6->word0); 1351 pde6->word0 = cpu_to_le32(pde6->word0);
1352 pde6->word1 = cpu_to_le32(pde6->word1); 1352 pde6->word1 = cpu_to_le32(pde6->word1);
1353 pde6->word2 = cpu_to_le32(pde6->word2); 1353 pde6->word2 = cpu_to_le32(pde6->word2);
@@ -1459,7 +1459,7 @@ lpfc_bg_setup_bpl_prot(struct lpfc_hba *phba, struct scsi_cmnd *sc,
1459 bf_set(pde5_type, pde5, LPFC_PDE5_DESCRIPTOR); 1459 bf_set(pde5_type, pde5, LPFC_PDE5_DESCRIPTOR);
1460 pde5->reftag = reftag; 1460 pde5->reftag = reftag;
1461 1461
1462 /* Endian convertion if necessary for PDE5 */ 1462 /* Endianness conversion if necessary for PDE5 */
1463 pde5->word0 = cpu_to_le32(pde5->word0); 1463 pde5->word0 = cpu_to_le32(pde5->word0);
1464 pde5->reftag = cpu_to_le32(pde5->reftag); 1464 pde5->reftag = cpu_to_le32(pde5->reftag);
1465 1465
@@ -1479,7 +1479,7 @@ lpfc_bg_setup_bpl_prot(struct lpfc_hba *phba, struct scsi_cmnd *sc,
1479 bf_set(pde6_ai, pde6, 1); 1479 bf_set(pde6_ai, pde6, 1);
1480 bf_set(pde6_apptagval, pde6, apptagval); 1480 bf_set(pde6_apptagval, pde6, apptagval);
1481 1481
1482 /* Endian convertion if necessary for PDE6 */ 1482 /* Endianness conversion if necessary for PDE6 */
1483 pde6->word0 = cpu_to_le32(pde6->word0); 1483 pde6->word0 = cpu_to_le32(pde6->word0);
1484 pde6->word1 = cpu_to_le32(pde6->word1); 1484 pde6->word1 = cpu_to_le32(pde6->word1);
1485 pde6->word2 = cpu_to_le32(pde6->word2); 1485 pde6->word2 = cpu_to_le32(pde6->word2);
diff --git a/drivers/scsi/lpfc/lpfc_sli.c b/drivers/scsi/lpfc/lpfc_sli.c
index e758eae0d0fd..fb8905f893f5 100644
--- a/drivers/scsi/lpfc/lpfc_sli.c
+++ b/drivers/scsi/lpfc/lpfc_sli.c
@@ -1046,7 +1046,7 @@ lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
1046 } else 1046 } else
1047 spin_unlock_irq(&phba->hbalock); 1047 spin_unlock_irq(&phba->hbalock);
1048 1048
1049 lpfc_printf_log(phba, KERN_ERR,LOG_SLI, 1049 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
1050 "0318 Failed to allocate IOTAG.last IOTAG is %d\n", 1050 "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
1051 psli->last_iotag); 1051 psli->last_iotag);
1052 1052
@@ -3914,7 +3914,8 @@ lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
3914 phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED | 3914 phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
3915 LPFC_SLI3_HBQ_ENABLED | 3915 LPFC_SLI3_HBQ_ENABLED |
3916 LPFC_SLI3_CRP_ENABLED | 3916 LPFC_SLI3_CRP_ENABLED |
3917 LPFC_SLI3_BG_ENABLED); 3917 LPFC_SLI3_BG_ENABLED |
3918 LPFC_SLI3_DSS_ENABLED);
3918 if (rc != MBX_SUCCESS) { 3919 if (rc != MBX_SUCCESS) {
3919 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, 3920 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3920 "0442 Adapter failed to init, mbxCmd x%x " 3921 "0442 Adapter failed to init, mbxCmd x%x "
@@ -3949,8 +3950,23 @@ lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
3949 3950
3950 } else 3951 } else
3951 phba->max_vpi = 0; 3952 phba->max_vpi = 0;
3952 if (pmb->u.mb.un.varCfgPort.gdss) 3953 phba->fips_level = 0;
3954 phba->fips_spec_rev = 0;
3955 if (pmb->u.mb.un.varCfgPort.gdss) {
3953 phba->sli3_options |= LPFC_SLI3_DSS_ENABLED; 3956 phba->sli3_options |= LPFC_SLI3_DSS_ENABLED;
3957 phba->fips_level = pmb->u.mb.un.varCfgPort.fips_level;
3958 phba->fips_spec_rev = pmb->u.mb.un.varCfgPort.fips_rev;
3959 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3960 "2850 Security Crypto Active. FIPS x%d "
3961 "(Spec Rev: x%d)",
3962 phba->fips_level, phba->fips_spec_rev);
3963 }
3964 if (pmb->u.mb.un.varCfgPort.sec_err) {
3965 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3966 "2856 Config Port Security Crypto "
3967 "Error: x%x ",
3968 pmb->u.mb.un.varCfgPort.sec_err);
3969 }
3954 if (pmb->u.mb.un.varCfgPort.gerbm) 3970 if (pmb->u.mb.un.varCfgPort.gerbm)
3955 phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED; 3971 phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
3956 if (pmb->u.mb.un.varCfgPort.gcrp) 3972 if (pmb->u.mb.un.varCfgPort.gcrp)
@@ -9040,6 +9056,7 @@ lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
9040 switch (bf_get(lpfc_cqe_code, &cqevt)) { 9056 switch (bf_get(lpfc_cqe_code, &cqevt)) {
9041 case CQE_CODE_COMPL_WQE: 9057 case CQE_CODE_COMPL_WQE:
9042 /* Process the WQ/RQ complete event */ 9058 /* Process the WQ/RQ complete event */
9059 phba->last_completion_time = jiffies;
9043 workposted = lpfc_sli4_sp_handle_els_wcqe(phba, 9060 workposted = lpfc_sli4_sp_handle_els_wcqe(phba,
9044 (struct lpfc_wcqe_complete *)&cqevt); 9061 (struct lpfc_wcqe_complete *)&cqevt);
9045 break; 9062 break;
@@ -9050,11 +9067,13 @@ lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
9050 break; 9067 break;
9051 case CQE_CODE_XRI_ABORTED: 9068 case CQE_CODE_XRI_ABORTED:
9052 /* Process the WQ XRI abort event */ 9069 /* Process the WQ XRI abort event */
9070 phba->last_completion_time = jiffies;
9053 workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, 9071 workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
9054 (struct sli4_wcqe_xri_aborted *)&cqevt); 9072 (struct sli4_wcqe_xri_aborted *)&cqevt);
9055 break; 9073 break;
9056 case CQE_CODE_RECEIVE: 9074 case CQE_CODE_RECEIVE:
9057 /* Process the RQ event */ 9075 /* Process the RQ event */
9076 phba->last_completion_time = jiffies;
9058 workposted = lpfc_sli4_sp_handle_rcqe(phba, 9077 workposted = lpfc_sli4_sp_handle_rcqe(phba,
9059 (struct lpfc_rcqe *)&cqevt); 9078 (struct lpfc_rcqe *)&cqevt);
9060 break; 9079 break;
@@ -9276,7 +9295,6 @@ lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
9276{ 9295{
9277 struct lpfc_wcqe_release wcqe; 9296 struct lpfc_wcqe_release wcqe;
9278 bool workposted = false; 9297 bool workposted = false;
9279 unsigned long iflag;
9280 9298
9281 /* Copy the work queue CQE and convert endian order if needed */ 9299 /* Copy the work queue CQE and convert endian order if needed */
9282 lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe)); 9300 lpfc_sli_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
@@ -9285,9 +9303,7 @@ lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
9285 switch (bf_get(lpfc_wcqe_c_code, &wcqe)) { 9303 switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
9286 case CQE_CODE_COMPL_WQE: 9304 case CQE_CODE_COMPL_WQE:
9287 /* Process the WQ complete event */ 9305 /* Process the WQ complete event */
9288 spin_lock_irqsave(&phba->hbalock, iflag);
9289 phba->last_completion_time = jiffies; 9306 phba->last_completion_time = jiffies;
9290 spin_unlock_irqrestore(&phba->hbalock, iflag);
9291 lpfc_sli4_fp_handle_fcp_wcqe(phba, 9307 lpfc_sli4_fp_handle_fcp_wcqe(phba,
9292 (struct lpfc_wcqe_complete *)&wcqe); 9308 (struct lpfc_wcqe_complete *)&wcqe);
9293 break; 9309 break;
@@ -9298,6 +9314,7 @@ lpfc_sli4_fp_handle_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
9298 break; 9314 break;
9299 case CQE_CODE_XRI_ABORTED: 9315 case CQE_CODE_XRI_ABORTED:
9300 /* Process the WQ XRI abort event */ 9316 /* Process the WQ XRI abort event */
9317 phba->last_completion_time = jiffies;
9301 workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq, 9318 workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
9302 (struct sli4_wcqe_xri_aborted *)&wcqe); 9319 (struct sli4_wcqe_xri_aborted *)&wcqe);
9303 break; 9320 break;
@@ -12278,12 +12295,9 @@ lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
12278 spin_lock_irq(&phba->hbalock); 12295 spin_lock_irq(&phba->hbalock);
12279 phba->hba_flag |= FCF_DISC_INPROGRESS; 12296 phba->hba_flag |= FCF_DISC_INPROGRESS;
12280 spin_unlock_irq(&phba->hbalock); 12297 spin_unlock_irq(&phba->hbalock);
12281 /* Reset FCF round robin index bmask for new scan */ 12298 /* Reset eligible FCF count for new scan */
12282 if (fcf_index == LPFC_FCOE_FCF_GET_FIRST) { 12299 if (fcf_index == LPFC_FCOE_FCF_GET_FIRST)
12283 memset(phba->fcf.fcf_rr_bmask, 0,
12284 sizeof(*phba->fcf.fcf_rr_bmask));
12285 phba->fcf.eligible_fcf_cnt = 0; 12300 phba->fcf.eligible_fcf_cnt = 0;
12286 }
12287 error = 0; 12301 error = 0;
12288 } 12302 }
12289fail_fcf_scan: 12303fail_fcf_scan:
diff --git a/drivers/scsi/lpfc/lpfc_version.h b/drivers/scsi/lpfc/lpfc_version.h
index d28830af71d8..61afb3420a96 100644
--- a/drivers/scsi/lpfc/lpfc_version.h
+++ b/drivers/scsi/lpfc/lpfc_version.h
@@ -18,7 +18,7 @@
18 * included with this package. * 18 * included with this package. *
19 *******************************************************************/ 19 *******************************************************************/
20 20
21#define LPFC_DRIVER_VERSION "8.3.15" 21#define LPFC_DRIVER_VERSION "8.3.16"
22#define LPFC_DRIVER_NAME "lpfc" 22#define LPFC_DRIVER_NAME "lpfc"
23#define LPFC_SP_DRIVER_HANDLER_NAME "lpfc:sp" 23#define LPFC_SP_DRIVER_HANDLER_NAME "lpfc:sp"
24#define LPFC_FP_DRIVER_HANDLER_NAME "lpfc:fp" 24#define LPFC_FP_DRIVER_HANDLER_NAME "lpfc:fp"
diff --git a/drivers/scsi/osd/osd_initiator.c b/drivers/scsi/osd/osd_initiator.c
index ee4b6914667f..fda4de3440c4 100644
--- a/drivers/scsi/osd/osd_initiator.c
+++ b/drivers/scsi/osd/osd_initiator.c
@@ -716,7 +716,7 @@ static int _osd_req_list_objects(struct osd_request *or,
716 return PTR_ERR(bio); 716 return PTR_ERR(bio);
717 } 717 }
718 718
719 bio->bi_rw &= ~(1 << BIO_RW); 719 bio->bi_rw &= ~REQ_WRITE;
720 or->in.bio = bio; 720 or->in.bio = bio;
721 or->in.total_bytes = bio->bi_size; 721 or->in.total_bytes = bio->bi_size;
722 return 0; 722 return 0;
@@ -814,7 +814,7 @@ void osd_req_write(struct osd_request *or,
814{ 814{
815 _osd_req_encode_common(or, OSD_ACT_WRITE, obj, offset, len); 815 _osd_req_encode_common(or, OSD_ACT_WRITE, obj, offset, len);
816 WARN_ON(or->out.bio || or->out.total_bytes); 816 WARN_ON(or->out.bio || or->out.total_bytes);
817 WARN_ON(0 == bio_rw_flagged(bio, BIO_RW)); 817 WARN_ON(0 == (bio->bi_rw & REQ_WRITE));
818 or->out.bio = bio; 818 or->out.bio = bio;
819 or->out.total_bytes = len; 819 or->out.total_bytes = len;
820} 820}
@@ -829,7 +829,7 @@ int osd_req_write_kern(struct osd_request *or,
829 if (IS_ERR(bio)) 829 if (IS_ERR(bio))
830 return PTR_ERR(bio); 830 return PTR_ERR(bio);
831 831
832 bio->bi_rw |= (1 << BIO_RW); /* FIXME: bio_set_dir() */ 832 bio->bi_rw |= REQ_WRITE; /* FIXME: bio_set_dir() */
833 osd_req_write(or, obj, offset, bio, len); 833 osd_req_write(or, obj, offset, bio, len);
834 return 0; 834 return 0;
835} 835}
@@ -865,7 +865,7 @@ void osd_req_read(struct osd_request *or,
865{ 865{
866 _osd_req_encode_common(or, OSD_ACT_READ, obj, offset, len); 866 _osd_req_encode_common(or, OSD_ACT_READ, obj, offset, len);
867 WARN_ON(or->in.bio || or->in.total_bytes); 867 WARN_ON(or->in.bio || or->in.total_bytes);
868 WARN_ON(1 == bio_rw_flagged(bio, BIO_RW)); 868 WARN_ON(1 == (bio->bi_rw & REQ_WRITE));
869 or->in.bio = bio; 869 or->in.bio = bio;
870 or->in.total_bytes = len; 870 or->in.total_bytes = len;
871} 871}
diff --git a/drivers/scsi/osst.c b/drivers/scsi/osst.c
index d64b7178fa08..278b352ae78d 100644
--- a/drivers/scsi/osst.c
+++ b/drivers/scsi/osst.c
@@ -5868,7 +5868,8 @@ static int osst_probe(struct device *dev)
5868 } 5868 }
5869 5869
5870 /* find a free minor number */ 5870 /* find a free minor number */
5871 for (i=0; os_scsi_tapes[i] && i<osst_max_dev; i++); 5871 for (i = 0; i < osst_max_dev && os_scsi_tapes[i]; i++)
5872 ;
5872 if(i >= osst_max_dev) panic ("Scsi_devices corrupt (osst)"); 5873 if(i >= osst_max_dev) panic ("Scsi_devices corrupt (osst)");
5873 dev_num = i; 5874 dev_num = i;
5874 5875
diff --git a/drivers/scsi/pm8001/pm8001_hwi.c b/drivers/scsi/pm8001/pm8001_hwi.c
index 58d1134935ef..9793aa6afb10 100644
--- a/drivers/scsi/pm8001/pm8001_hwi.c
+++ b/drivers/scsi/pm8001/pm8001_hwi.c
@@ -4199,8 +4199,10 @@ static int pm8001_chip_get_nvmd_req(struct pm8001_hba_info *pm8001_ha,
4199 circularQ = &pm8001_ha->inbnd_q_tbl[0]; 4199 circularQ = &pm8001_ha->inbnd_q_tbl[0];
4200 memset(&nvmd_req, 0, sizeof(nvmd_req)); 4200 memset(&nvmd_req, 0, sizeof(nvmd_req));
4201 rc = pm8001_tag_alloc(pm8001_ha, &tag); 4201 rc = pm8001_tag_alloc(pm8001_ha, &tag);
4202 if (rc) 4202 if (rc) {
4203 kfree(fw_control_context);
4203 return rc; 4204 return rc;
4205 }
4204 ccb = &pm8001_ha->ccb_info[tag]; 4206 ccb = &pm8001_ha->ccb_info[tag];
4205 ccb->ccb_tag = tag; 4207 ccb->ccb_tag = tag;
4206 ccb->fw_control_context = fw_control_context; 4208 ccb->fw_control_context = fw_control_context;
@@ -4276,8 +4278,10 @@ static int pm8001_chip_set_nvmd_req(struct pm8001_hba_info *pm8001_ha,
4276 ioctl_payload->length); 4278 ioctl_payload->length);
4277 memset(&nvmd_req, 0, sizeof(nvmd_req)); 4279 memset(&nvmd_req, 0, sizeof(nvmd_req));
4278 rc = pm8001_tag_alloc(pm8001_ha, &tag); 4280 rc = pm8001_tag_alloc(pm8001_ha, &tag);
4279 if (rc) 4281 if (rc) {
4282 kfree(fw_control_context);
4280 return rc; 4283 return rc;
4284 }
4281 ccb = &pm8001_ha->ccb_info[tag]; 4285 ccb = &pm8001_ha->ccb_info[tag];
4282 ccb->fw_control_context = fw_control_context; 4286 ccb->fw_control_context = fw_control_context;
4283 ccb->ccb_tag = tag; 4287 ccb->ccb_tag = tag;
@@ -4387,6 +4391,7 @@ pm8001_chip_fw_flash_update_req(struct pm8001_hba_info *pm8001_ha,
4387 fw_control->len, 0) != 0) { 4391 fw_control->len, 0) != 0) {
4388 PM8001_FAIL_DBG(pm8001_ha, 4392 PM8001_FAIL_DBG(pm8001_ha,
4389 pm8001_printk("Mem alloc failure\n")); 4393 pm8001_printk("Mem alloc failure\n"));
4394 kfree(fw_control_context);
4390 return -ENOMEM; 4395 return -ENOMEM;
4391 } 4396 }
4392 } 4397 }
@@ -4401,8 +4406,10 @@ pm8001_chip_fw_flash_update_req(struct pm8001_hba_info *pm8001_ha,
4401 fw_control_context->virtAddr = buffer; 4406 fw_control_context->virtAddr = buffer;
4402 fw_control_context->len = fw_control->len; 4407 fw_control_context->len = fw_control->len;
4403 rc = pm8001_tag_alloc(pm8001_ha, &tag); 4408 rc = pm8001_tag_alloc(pm8001_ha, &tag);
4404 if (rc) 4409 if (rc) {
4410 kfree(fw_control_context);
4405 return rc; 4411 return rc;
4412 }
4406 ccb = &pm8001_ha->ccb_info[tag]; 4413 ccb = &pm8001_ha->ccb_info[tag];
4407 ccb->fw_control_context = fw_control_context; 4414 ccb->fw_control_context = fw_control_context;
4408 ccb->ccb_tag = tag; 4415 ccb->ccb_tag = tag;
diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index ff2172da7c19..8c80b49ac1c4 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -115,8 +115,8 @@ int ql2xmaxqueues = 1;
115module_param(ql2xmaxqueues, int, S_IRUGO|S_IRUSR); 115module_param(ql2xmaxqueues, int, S_IRUGO|S_IRUSR);
116MODULE_PARM_DESC(ql2xmaxqueues, 116MODULE_PARM_DESC(ql2xmaxqueues,
117 "Enables MQ settings " 117 "Enables MQ settings "
118 "Default is 1 for single queue. Set it to number \ 118 "Default is 1 for single queue. Set it to number "
119 of queues in MQ mode."); 119 "of queues in MQ mode.");
120 120
121int ql2xmultique_tag; 121int ql2xmultique_tag;
122module_param(ql2xmultique_tag, int, S_IRUGO|S_IRUSR); 122module_param(ql2xmultique_tag, int, S_IRUGO|S_IRUSR);
diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
index a79da8dd2064..9dc0a6616edd 100644
--- a/drivers/scsi/qla4xxx/ql4_def.h
+++ b/drivers/scsi/qla4xxx/ql4_def.h
@@ -36,6 +36,24 @@
36#include "ql4_dbg.h" 36#include "ql4_dbg.h"
37#include "ql4_nx.h" 37#include "ql4_nx.h"
38 38
39#if defined(CONFIG_PCIEAER)
40#include <linux/aer.h>
41#else
42/* AER releated */
43static inline int pci_enable_pcie_error_reporting(struct pci_dev *dev)
44{
45 return -EINVAL;
46}
47static inline int pci_disable_pcie_error_reporting(struct pci_dev *dev)
48{
49 return -EINVAL;
50}
51static inline int pci_cleanup_aer_uncorrect_error_status(struct pci_dev *dev)
52{
53 return -EINVAL;
54}
55#endif
56
39#ifndef PCI_DEVICE_ID_QLOGIC_ISP4010 57#ifndef PCI_DEVICE_ID_QLOGIC_ISP4010
40#define PCI_DEVICE_ID_QLOGIC_ISP4010 0x4010 58#define PCI_DEVICE_ID_QLOGIC_ISP4010 0x4010
41#endif 59#endif
@@ -137,6 +155,9 @@
137#define ISCSI_ALIAS_SIZE 32 /* ISCSI Alias name size */ 155#define ISCSI_ALIAS_SIZE 32 /* ISCSI Alias name size */
138#define ISCSI_NAME_SIZE 0xE0 /* ISCSI Name size */ 156#define ISCSI_NAME_SIZE 0xE0 /* ISCSI Name size */
139 157
158#define QL4_SESS_RECOVERY_TMO 30 /* iSCSI session */
159 /* recovery timeout */
160
140#define LSDW(x) ((u32)((u64)(x))) 161#define LSDW(x) ((u32)((u64)(x)))
141#define MSDW(x) ((u32)((((u64)(x)) >> 16) >> 16)) 162#define MSDW(x) ((u32)((((u64)(x)) >> 16) >> 16))
142 163
@@ -249,7 +270,6 @@ struct ddb_entry {
249 uint32_t default_time2wait; /* Default Min time between 270 uint32_t default_time2wait; /* Default Min time between
250 * relogins (+aens) */ 271 * relogins (+aens) */
251 272
252 atomic_t port_down_timer; /* Device connection timer */
253 atomic_t retry_relogin_timer; /* Min Time between relogins 273 atomic_t retry_relogin_timer; /* Min Time between relogins
254 * (4000 only) */ 274 * (4000 only) */
255 atomic_t relogin_timer; /* Max Time to wait for relogin to complete */ 275 atomic_t relogin_timer; /* Max Time to wait for relogin to complete */
@@ -378,7 +398,9 @@ struct scsi_qla_host {
378#define AF_MSI_ENABLED 16 /* 0x00010000 */ 398#define AF_MSI_ENABLED 16 /* 0x00010000 */
379#define AF_MSIX_ENABLED 17 /* 0x00020000 */ 399#define AF_MSIX_ENABLED 17 /* 0x00020000 */
380#define AF_MBOX_COMMAND_NOPOLL 18 /* 0x00040000 */ 400#define AF_MBOX_COMMAND_NOPOLL 18 /* 0x00040000 */
381 401#define AF_FW_RECOVERY 19 /* 0x00080000 */
402#define AF_EEH_BUSY 20 /* 0x00100000 */
403#define AF_PCI_CHANNEL_IO_PERM_FAILURE 21 /* 0x00200000 */
382 404
383 unsigned long dpc_flags; 405 unsigned long dpc_flags;
384 406
@@ -474,7 +496,6 @@ struct scsi_qla_host {
474 uint32_t timer_active; 496 uint32_t timer_active;
475 497
476 /* Recovery Timers */ 498 /* Recovery Timers */
477 uint32_t port_down_retry_count;
478 uint32_t discovery_wait; 499 uint32_t discovery_wait;
479 atomic_t check_relogin_timeouts; 500 atomic_t check_relogin_timeouts;
480 uint32_t retry_reset_ha_cnt; 501 uint32_t retry_reset_ha_cnt;
@@ -615,6 +636,15 @@ static inline int is_qla8022(struct scsi_qla_host *ha)
615 return ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8022; 636 return ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8022;
616} 637}
617 638
639/* Note: Currently AER/EEH is now supported only for 8022 cards
640 * This function needs to be updated when AER/EEH is enabled
641 * for other cards.
642 */
643static inline int is_aer_supported(struct scsi_qla_host *ha)
644{
645 return ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8022;
646}
647
618static inline int adapter_up(struct scsi_qla_host *ha) 648static inline int adapter_up(struct scsi_qla_host *ha)
619{ 649{
620 return (test_bit(AF_ONLINE, &ha->flags) != 0) && 650 return (test_bit(AF_ONLINE, &ha->flags) != 0) &&
diff --git a/drivers/scsi/qla4xxx/ql4_fw.h b/drivers/scsi/qla4xxx/ql4_fw.h
index c94c9ddfb3a6..0336c6db8cb3 100644
--- a/drivers/scsi/qla4xxx/ql4_fw.h
+++ b/drivers/scsi/qla4xxx/ql4_fw.h
@@ -673,17 +673,17 @@ struct flash_sys_info {
673}; /* 200 */ 673}; /* 200 */
674 674
675struct mbx_sys_info { 675struct mbx_sys_info {
676 uint8_t board_id_str[16]; /* Keep board ID string first */ 676 uint8_t board_id_str[16]; /* 0-f Keep board ID string first */
677 /* in this structure for GUI. */ 677 /* in this structure for GUI. */
678 uint16_t board_id; /* board ID code */ 678 uint16_t board_id; /* 10-11 board ID code */
679 uint16_t phys_port_cnt; /* number of physical network ports */ 679 uint16_t phys_port_cnt; /* 12-13 number of physical network ports */
680 uint16_t port_num; /* network port for this PCI function */ 680 uint16_t port_num; /* 14-15 network port for this PCI function */
681 /* (port 0 is first port) */ 681 /* (port 0 is first port) */
682 uint8_t mac_addr[6]; /* MAC address for this PCI function */ 682 uint8_t mac_addr[6]; /* 16-1b MAC address for this PCI function */
683 uint32_t iscsi_pci_func_cnt; /* number of iSCSI PCI functions */ 683 uint32_t iscsi_pci_func_cnt; /* 1c-1f number of iSCSI PCI functions */
684 uint32_t pci_func; /* this PCI function */ 684 uint32_t pci_func; /* 20-23 this PCI function */
685 unsigned char serial_number[16]; /* serial number string */ 685 unsigned char serial_number[16]; /* 24-33 serial number string */
686 uint8_t reserved[16]; 686 uint8_t reserved[12]; /* 34-3f */
687}; 687};
688 688
689struct crash_record { 689struct crash_record {
diff --git a/drivers/scsi/qla4xxx/ql4_glbl.h b/drivers/scsi/qla4xxx/ql4_glbl.h
index c9cd5d6db982..f065204e401b 100644
--- a/drivers/scsi/qla4xxx/ql4_glbl.h
+++ b/drivers/scsi/qla4xxx/ql4_glbl.h
@@ -93,6 +93,7 @@ void qla4xxx_free_irqs(struct scsi_qla_host *ha);
93void qla4xxx_process_response_queue(struct scsi_qla_host *ha); 93void qla4xxx_process_response_queue(struct scsi_qla_host *ha);
94void qla4xxx_wake_dpc(struct scsi_qla_host *ha); 94void qla4xxx_wake_dpc(struct scsi_qla_host *ha);
95void qla4xxx_get_conn_event_log(struct scsi_qla_host *ha); 95void qla4xxx_get_conn_event_log(struct scsi_qla_host *ha);
96void qla4xxx_mailbox_premature_completion(struct scsi_qla_host *ha);
96 97
97void qla4_8xxx_pci_config(struct scsi_qla_host *); 98void qla4_8xxx_pci_config(struct scsi_qla_host *);
98int qla4_8xxx_iospace_config(struct scsi_qla_host *ha); 99int qla4_8xxx_iospace_config(struct scsi_qla_host *ha);
@@ -131,6 +132,7 @@ void qla4_8xxx_idc_unlock(struct scsi_qla_host *ha);
131int qla4_8xxx_device_state_handler(struct scsi_qla_host *ha); 132int qla4_8xxx_device_state_handler(struct scsi_qla_host *ha);
132void qla4_8xxx_need_qsnt_handler(struct scsi_qla_host *ha); 133void qla4_8xxx_need_qsnt_handler(struct scsi_qla_host *ha);
133void qla4_8xxx_clear_drv_active(struct scsi_qla_host *ha); 134void qla4_8xxx_clear_drv_active(struct scsi_qla_host *ha);
135inline void qla4_8xxx_set_drv_active(struct scsi_qla_host *ha);
134 136
135extern int ql4xextended_error_logging; 137extern int ql4xextended_error_logging;
136extern int ql4xdiscoverywait; 138extern int ql4xdiscoverywait;
diff --git a/drivers/scsi/qla4xxx/ql4_init.c b/drivers/scsi/qla4xxx/ql4_init.c
index 30073577c3a4..4c9be77ee70b 100644
--- a/drivers/scsi/qla4xxx/ql4_init.c
+++ b/drivers/scsi/qla4xxx/ql4_init.c
@@ -308,7 +308,6 @@ static int qla4xxx_fw_ready(struct scsi_qla_host *ha)
308 DEBUG2(printk("scsi%ld: %s: unable to get firmware " 308 DEBUG2(printk("scsi%ld: %s: unable to get firmware "
309 "state\n", ha->host_no, __func__)); 309 "state\n", ha->host_no, __func__));
310 break; 310 break;
311
312 } 311 }
313 312
314 if (ha->firmware_state & FW_STATE_ERROR) { 313 if (ha->firmware_state & FW_STATE_ERROR) {
@@ -445,6 +444,16 @@ static int qla4xxx_init_firmware(struct scsi_qla_host *ha)
445{ 444{
446 int status = QLA_ERROR; 445 int status = QLA_ERROR;
447 446
447 if (is_aer_supported(ha) &&
448 test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))
449 return status;
450
451 /* For 82xx, stop firmware before initializing because if BIOS
452 * has previously initialized firmware, then driver's initialize
453 * firmware will fail. */
454 if (is_qla8022(ha))
455 qla4_8xxx_stop_firmware(ha);
456
448 ql4_printk(KERN_INFO, ha, "Initializing firmware..\n"); 457 ql4_printk(KERN_INFO, ha, "Initializing firmware..\n");
449 if (qla4xxx_initialize_fw_cb(ha) == QLA_ERROR) { 458 if (qla4xxx_initialize_fw_cb(ha) == QLA_ERROR) {
450 DEBUG2(printk("scsi%ld: %s: Failed to initialize firmware " 459 DEBUG2(printk("scsi%ld: %s: Failed to initialize firmware "
@@ -669,7 +678,6 @@ static struct ddb_entry * qla4xxx_alloc_ddb(struct scsi_qla_host *ha,
669 } 678 }
670 679
671 ddb_entry->fw_ddb_index = fw_ddb_index; 680 ddb_entry->fw_ddb_index = fw_ddb_index;
672 atomic_set(&ddb_entry->port_down_timer, ha->port_down_retry_count);
673 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY); 681 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
674 atomic_set(&ddb_entry->relogin_timer, 0); 682 atomic_set(&ddb_entry->relogin_timer, 0);
675 atomic_set(&ddb_entry->relogin_retry_count, 0); 683 atomic_set(&ddb_entry->relogin_retry_count, 0);
@@ -1556,8 +1564,6 @@ int qla4xxx_process_ddb_changed(struct scsi_qla_host *ha, uint32_t fw_ddb_index,
1556 /* Device is back online. */ 1564 /* Device is back online. */
1557 if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) { 1565 if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) {
1558 atomic_set(&ddb_entry->state, DDB_STATE_ONLINE); 1566 atomic_set(&ddb_entry->state, DDB_STATE_ONLINE);
1559 atomic_set(&ddb_entry->port_down_timer,
1560 ha->port_down_retry_count);
1561 atomic_set(&ddb_entry->relogin_retry_count, 0); 1567 atomic_set(&ddb_entry->relogin_retry_count, 0);
1562 atomic_set(&ddb_entry->relogin_timer, 0); 1568 atomic_set(&ddb_entry->relogin_timer, 0);
1563 clear_bit(DF_RELOGIN, &ddb_entry->flags); 1569 clear_bit(DF_RELOGIN, &ddb_entry->flags);
diff --git a/drivers/scsi/qla4xxx/ql4_iocb.c b/drivers/scsi/qla4xxx/ql4_iocb.c
index f89973deac5b..4ef9ba112ee8 100644
--- a/drivers/scsi/qla4xxx/ql4_iocb.c
+++ b/drivers/scsi/qla4xxx/ql4_iocb.c
@@ -19,7 +19,7 @@ qla4xxx_space_in_req_ring(struct scsi_qla_host *ha, uint16_t req_cnt)
19 19
20 /* Calculate number of free request entries. */ 20 /* Calculate number of free request entries. */
21 if ((req_cnt + 2) >= ha->req_q_count) { 21 if ((req_cnt + 2) >= ha->req_q_count) {
22 cnt = (uint16_t) le32_to_cpu(ha->shadow_regs->req_q_out); 22 cnt = (uint16_t) ha->isp_ops->rd_shdw_req_q_out(ha);
23 if (ha->request_in < cnt) 23 if (ha->request_in < cnt)
24 ha->req_q_count = cnt - ha->request_in; 24 ha->req_q_count = cnt - ha->request_in;
25 else 25 else
diff --git a/drivers/scsi/qla4xxx/ql4_isr.c b/drivers/scsi/qla4xxx/ql4_isr.c
index aa65697a86b4..2a1ab63f3eb0 100644
--- a/drivers/scsi/qla4xxx/ql4_isr.c
+++ b/drivers/scsi/qla4xxx/ql4_isr.c
@@ -816,6 +816,9 @@ irqreturn_t qla4_8xxx_intr_handler(int irq, void *dev_id)
816 unsigned long flags = 0; 816 unsigned long flags = 0;
817 uint8_t reqs_count = 0; 817 uint8_t reqs_count = 0;
818 818
819 if (unlikely(pci_channel_offline(ha->pdev)))
820 return IRQ_HANDLED;
821
819 ha->isr_count++; 822 ha->isr_count++;
820 status = qla4_8xxx_rd_32(ha, ISR_INT_VECTOR); 823 status = qla4_8xxx_rd_32(ha, ISR_INT_VECTOR);
821 if (!(status & ha->nx_legacy_intr.int_vec_bit)) 824 if (!(status & ha->nx_legacy_intr.int_vec_bit))
diff --git a/drivers/scsi/qla4xxx/ql4_mbx.c b/drivers/scsi/qla4xxx/ql4_mbx.c
index 940ee561ee0a..90021704d8ca 100644
--- a/drivers/scsi/qla4xxx/ql4_mbx.c
+++ b/drivers/scsi/qla4xxx/ql4_mbx.c
@@ -39,6 +39,22 @@ int qla4xxx_mailbox_command(struct scsi_qla_host *ha, uint8_t inCount,
39 "pointer\n", ha->host_no, __func__)); 39 "pointer\n", ha->host_no, __func__));
40 return status; 40 return status;
41 } 41 }
42
43 if (is_qla8022(ha) &&
44 test_bit(AF_FW_RECOVERY, &ha->flags)) {
45 DEBUG2(ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: prematurely "
46 "completing mbx cmd as firmware recovery detected\n",
47 ha->host_no, __func__));
48 return status;
49 }
50
51 if ((is_aer_supported(ha)) &&
52 (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))) {
53 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Perm failure on EEH, "
54 "timeout MBX Exiting.\n", ha->host_no, __func__));
55 return status;
56 }
57
42 /* Mailbox code active */ 58 /* Mailbox code active */
43 wait_count = MBOX_TOV * 100; 59 wait_count = MBOX_TOV * 100;
44 60
@@ -150,6 +166,7 @@ int qla4xxx_mailbox_command(struct scsi_qla_host *ha, uint8_t inCount,
150 while (test_bit(AF_MBOX_COMMAND_DONE, &ha->flags) == 0) { 166 while (test_bit(AF_MBOX_COMMAND_DONE, &ha->flags) == 0) {
151 if (time_after_eq(jiffies, wait_count)) 167 if (time_after_eq(jiffies, wait_count))
152 break; 168 break;
169
153 /* 170 /*
154 * Service the interrupt. 171 * Service the interrupt.
155 * The ISR will save the mailbox status registers 172 * The ISR will save the mailbox status registers
@@ -196,6 +213,14 @@ int qla4xxx_mailbox_command(struct scsi_qla_host *ha, uint8_t inCount,
196 213
197 /* Check for mailbox timeout. */ 214 /* Check for mailbox timeout. */
198 if (!test_bit(AF_MBOX_COMMAND_DONE, &ha->flags)) { 215 if (!test_bit(AF_MBOX_COMMAND_DONE, &ha->flags)) {
216 if (is_qla8022(ha) &&
217 test_bit(AF_FW_RECOVERY, &ha->flags)) {
218 DEBUG2(ql4_printk(KERN_INFO, ha,
219 "scsi%ld: %s: prematurely completing mbx cmd as "
220 "firmware recovery detected\n",
221 ha->host_no, __func__));
222 goto mbox_exit;
223 }
199 DEBUG2(printk("scsi%ld: Mailbox Cmd 0x%08X timed out ...," 224 DEBUG2(printk("scsi%ld: Mailbox Cmd 0x%08X timed out ...,"
200 " Scheduling Adapter Reset\n", ha->host_no, 225 " Scheduling Adapter Reset\n", ha->host_no,
201 mbx_cmd[0])); 226 mbx_cmd[0]));
@@ -246,6 +271,28 @@ mbox_exit:
246 return status; 271 return status;
247} 272}
248 273
274void qla4xxx_mailbox_premature_completion(struct scsi_qla_host *ha)
275{
276 set_bit(AF_FW_RECOVERY, &ha->flags);
277 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: set FW RECOVERY!\n",
278 ha->host_no, __func__);
279
280 if (test_bit(AF_MBOX_COMMAND, &ha->flags)) {
281 if (test_bit(AF_MBOX_COMMAND_NOPOLL, &ha->flags)) {
282 complete(&ha->mbx_intr_comp);
283 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Due to fw "
284 "recovery, doing premature completion of "
285 "mbx cmd\n", ha->host_no, __func__);
286
287 } else {
288 set_bit(AF_MBOX_COMMAND_DONE, &ha->flags);
289 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Due to fw "
290 "recovery, doing premature completion of "
291 "polling mbx cmd\n", ha->host_no, __func__);
292 }
293 }
294}
295
249static uint8_t 296static uint8_t
250qla4xxx_set_ifcb(struct scsi_qla_host *ha, uint32_t *mbox_cmd, 297qla4xxx_set_ifcb(struct scsi_qla_host *ha, uint32_t *mbox_cmd,
251 uint32_t *mbox_sts, dma_addr_t init_fw_cb_dma) 298 uint32_t *mbox_sts, dma_addr_t init_fw_cb_dma)
@@ -361,7 +408,6 @@ qla4xxx_update_local_ifcb(struct scsi_qla_host *ha,
361 min(sizeof(ha->alias), sizeof(init_fw_cb->Alias)));*/ 408 min(sizeof(ha->alias), sizeof(init_fw_cb->Alias)));*/
362 409
363 /* Save Command Line Paramater info */ 410 /* Save Command Line Paramater info */
364 ha->port_down_retry_count = le16_to_cpu(init_fw_cb->conn_ka_timeout);
365 ha->discovery_wait = ql4xdiscoverywait; 411 ha->discovery_wait = ql4xdiscoverywait;
366 412
367 if (ha->acb_version == ACB_SUPPORTED) { 413 if (ha->acb_version == ACB_SUPPORTED) {
diff --git a/drivers/scsi/qla4xxx/ql4_nx.c b/drivers/scsi/qla4xxx/ql4_nx.c
index 3e119ae78397..e031a734836e 100644
--- a/drivers/scsi/qla4xxx/ql4_nx.c
+++ b/drivers/scsi/qla4xxx/ql4_nx.c
@@ -1418,7 +1418,7 @@ static int qla4_8xxx_rcvpeg_ready(struct scsi_qla_host *ha)
1418 return QLA_SUCCESS; 1418 return QLA_SUCCESS;
1419} 1419}
1420 1420
1421static inline void 1421inline void
1422qla4_8xxx_set_drv_active(struct scsi_qla_host *ha) 1422qla4_8xxx_set_drv_active(struct scsi_qla_host *ha)
1423{ 1423{
1424 uint32_t drv_active; 1424 uint32_t drv_active;
@@ -1441,11 +1441,15 @@ qla4_8xxx_clear_drv_active(struct scsi_qla_host *ha)
1441static inline int 1441static inline int
1442qla4_8xxx_need_reset(struct scsi_qla_host *ha) 1442qla4_8xxx_need_reset(struct scsi_qla_host *ha)
1443{ 1443{
1444 uint32_t drv_state; 1444 uint32_t drv_state, drv_active;
1445 int rval; 1445 int rval;
1446 1446
1447 drv_active = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
1447 drv_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DRV_STATE); 1448 drv_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DRV_STATE);
1448 rval = drv_state & (1 << (ha->func_num * 4)); 1449 rval = drv_state & (1 << (ha->func_num * 4));
1450 if ((test_bit(AF_EEH_BUSY, &ha->flags)) && drv_active)
1451 rval = 1;
1452
1449 return rval; 1453 return rval;
1450} 1454}
1451 1455
@@ -1949,7 +1953,8 @@ qla4_8xxx_get_fdt_info(struct scsi_qla_host *ha)
1949 uint16_t cnt, chksum; 1953 uint16_t cnt, chksum;
1950 uint16_t *wptr; 1954 uint16_t *wptr;
1951 struct qla_fdt_layout *fdt; 1955 struct qla_fdt_layout *fdt;
1952 uint16_t mid, fid; 1956 uint16_t mid = 0;
1957 uint16_t fid = 0;
1953 struct ql82xx_hw_data *hw = &ha->hw; 1958 struct ql82xx_hw_data *hw = &ha->hw;
1954 1959
1955 hw->flash_conf_off = FARX_ACCESS_FLASH_CONF; 1960 hw->flash_conf_off = FARX_ACCESS_FLASH_CONF;
@@ -2105,6 +2110,9 @@ qla4_8xxx_isp_reset(struct scsi_qla_host *ha)
2105 qla4_8xxx_clear_rst_ready(ha); 2110 qla4_8xxx_clear_rst_ready(ha);
2106 qla4_8xxx_idc_unlock(ha); 2111 qla4_8xxx_idc_unlock(ha);
2107 2112
2113 if (rval == QLA_SUCCESS)
2114 clear_bit(AF_FW_RECOVERY, &ha->flags);
2115
2108 return rval; 2116 return rval;
2109} 2117}
2110 2118
@@ -2145,7 +2153,8 @@ int qla4_8xxx_get_sys_info(struct scsi_qla_host *ha)
2145 goto exit_validate_mac82; 2153 goto exit_validate_mac82;
2146 } 2154 }
2147 2155
2148 if (mbox_sts[4] < sizeof(*sys_info)) { 2156 /* Make sure we receive the minimum required data to cache internally */
2157 if (mbox_sts[4] < offsetof(struct mbx_sys_info, reserved)) {
2149 DEBUG2(printk("scsi%ld: %s: GET_SYS_INFO data receive" 2158 DEBUG2(printk("scsi%ld: %s: GET_SYS_INFO data receive"
2150 " error (%x)\n", ha->host_no, __func__, mbox_sts[4])); 2159 " error (%x)\n", ha->host_no, __func__, mbox_sts[4]));
2151 goto exit_validate_mac82; 2160 goto exit_validate_mac82;
diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
index 5529b2a39741..370d40ff1529 100644
--- a/drivers/scsi/qla4xxx/ql4_os.c
+++ b/drivers/scsi/qla4xxx/ql4_os.c
@@ -163,10 +163,10 @@ static void qla4xxx_recovery_timedout(struct iscsi_cls_session *session)
163 if (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) { 163 if (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) {
164 atomic_set(&ddb_entry->state, DDB_STATE_DEAD); 164 atomic_set(&ddb_entry->state, DDB_STATE_DEAD);
165 165
166 DEBUG2(printk("scsi%ld: %s: ddb [%d] port down retry count " 166 DEBUG2(printk("scsi%ld: %s: ddb [%d] session recovery timeout "
167 "of (%d) secs exhausted, marking device DEAD.\n", 167 "of (%d) secs exhausted, marking device DEAD.\n",
168 ha->host_no, __func__, ddb_entry->fw_ddb_index, 168 ha->host_no, __func__, ddb_entry->fw_ddb_index,
169 ha->port_down_retry_count)); 169 QL4_SESS_RECOVERY_TMO));
170 170
171 qla4xxx_wake_dpc(ha); 171 qla4xxx_wake_dpc(ha);
172 } 172 }
@@ -298,7 +298,8 @@ int qla4xxx_add_sess(struct ddb_entry *ddb_entry)
298{ 298{
299 int err; 299 int err;
300 300
301 ddb_entry->sess->recovery_tmo = ddb_entry->ha->port_down_retry_count; 301 ddb_entry->sess->recovery_tmo = QL4_SESS_RECOVERY_TMO;
302
302 err = iscsi_add_session(ddb_entry->sess, ddb_entry->fw_ddb_index); 303 err = iscsi_add_session(ddb_entry->sess, ddb_entry->fw_ddb_index);
303 if (err) { 304 if (err) {
304 DEBUG2(printk(KERN_ERR "Could not add session.\n")); 305 DEBUG2(printk(KERN_ERR "Could not add session.\n"));
@@ -474,6 +475,14 @@ static int qla4xxx_queuecommand(struct scsi_cmnd *cmd,
474 struct srb *srb; 475 struct srb *srb;
475 int rval; 476 int rval;
476 477
478 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
479 if (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))
480 cmd->result = DID_NO_CONNECT << 16;
481 else
482 cmd->result = DID_REQUEUE << 16;
483 goto qc_fail_command;
484 }
485
477 if (!sess) { 486 if (!sess) {
478 cmd->result = DID_IMM_RETRY << 16; 487 cmd->result = DID_IMM_RETRY << 16;
479 goto qc_fail_command; 488 goto qc_fail_command;
@@ -654,6 +663,13 @@ static void qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha)
654 uint32_t fw_heartbeat_counter, halt_status; 663 uint32_t fw_heartbeat_counter, halt_status;
655 664
656 fw_heartbeat_counter = qla4_8xxx_rd_32(ha, QLA82XX_PEG_ALIVE_COUNTER); 665 fw_heartbeat_counter = qla4_8xxx_rd_32(ha, QLA82XX_PEG_ALIVE_COUNTER);
666 /* If PEG_ALIVE_COUNTER is 0xffffffff, AER/EEH is in progress, ignore */
667 if (fw_heartbeat_counter == 0xffffffff) {
668 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Device in frozen "
669 "state, QLA82XX_PEG_ALIVE_COUNTER is 0xffffffff\n",
670 ha->host_no, __func__));
671 return;
672 }
657 673
658 if (ha->fw_heartbeat_counter == fw_heartbeat_counter) { 674 if (ha->fw_heartbeat_counter == fw_heartbeat_counter) {
659 ha->seconds_since_last_heartbeat++; 675 ha->seconds_since_last_heartbeat++;
@@ -662,6 +678,7 @@ static void qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha)
662 ha->seconds_since_last_heartbeat = 0; 678 ha->seconds_since_last_heartbeat = 0;
663 halt_status = qla4_8xxx_rd_32(ha, 679 halt_status = qla4_8xxx_rd_32(ha,
664 QLA82XX_PEG_HALT_STATUS1); 680 QLA82XX_PEG_HALT_STATUS1);
681
665 /* Since we cannot change dev_state in interrupt 682 /* Since we cannot change dev_state in interrupt
666 * context, set appropriate DPC flag then wakeup 683 * context, set appropriate DPC flag then wakeup
667 * DPC */ 684 * DPC */
@@ -673,6 +690,7 @@ static void qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha)
673 set_bit(DPC_RESET_HA, &ha->dpc_flags); 690 set_bit(DPC_RESET_HA, &ha->dpc_flags);
674 } 691 }
675 qla4xxx_wake_dpc(ha); 692 qla4xxx_wake_dpc(ha);
693 qla4xxx_mailbox_premature_completion(ha);
676 } 694 }
677 } 695 }
678 ha->fw_heartbeat_counter = fw_heartbeat_counter; 696 ha->fw_heartbeat_counter = fw_heartbeat_counter;
@@ -698,6 +716,7 @@ void qla4_8xxx_watchdog(struct scsi_qla_host *ha)
698 ha->host_no, __func__); 716 ha->host_no, __func__);
699 set_bit(DPC_RESET_HA, &ha->dpc_flags); 717 set_bit(DPC_RESET_HA, &ha->dpc_flags);
700 qla4xxx_wake_dpc(ha); 718 qla4xxx_wake_dpc(ha);
719 qla4xxx_mailbox_premature_completion(ha);
701 } else if (dev_state == QLA82XX_DEV_NEED_QUIESCENT && 720 } else if (dev_state == QLA82XX_DEV_NEED_QUIESCENT &&
702 !test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) { 721 !test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
703 printk("scsi%ld: %s: HW State: NEED QUIES!\n", 722 printk("scsi%ld: %s: HW State: NEED QUIES!\n",
@@ -719,6 +738,19 @@ static void qla4xxx_timer(struct scsi_qla_host *ha)
719{ 738{
720 struct ddb_entry *ddb_entry, *dtemp; 739 struct ddb_entry *ddb_entry, *dtemp;
721 int start_dpc = 0; 740 int start_dpc = 0;
741 uint16_t w;
742
743 /* If we are in the middle of AER/EEH processing
744 * skip any processing and reschedule the timer
745 */
746 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
747 mod_timer(&ha->timer, jiffies + HZ);
748 return;
749 }
750
751 /* Hardware read to trigger an EEH error during mailbox waits. */
752 if (!pci_channel_offline(ha->pdev))
753 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
722 754
723 if (test_bit(AF_HBA_GOING_AWAY, &ha->flags)) { 755 if (test_bit(AF_HBA_GOING_AWAY, &ha->flags)) {
724 DEBUG2(ql4_printk(KERN_INFO, ha, "%s exited. HBA GOING AWAY\n", 756 DEBUG2(ql4_printk(KERN_INFO, ha, "%s exited. HBA GOING AWAY\n",
@@ -1207,7 +1239,13 @@ static void qla4xxx_do_dpc(struct work_struct *work)
1207 1239
1208 /* Initialization not yet finished. Don't do anything yet. */ 1240 /* Initialization not yet finished. Don't do anything yet. */
1209 if (!test_bit(AF_INIT_DONE, &ha->flags)) 1241 if (!test_bit(AF_INIT_DONE, &ha->flags))
1210 return; 1242 goto do_dpc_exit;
1243
1244 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
1245 DEBUG2(printk(KERN_INFO "scsi%ld: %s: flags = %lx\n",
1246 ha->host_no, __func__, ha->flags));
1247 goto do_dpc_exit;
1248 }
1211 1249
1212 /* HBA is in the process of being permanently disabled. 1250 /* HBA is in the process of being permanently disabled.
1213 * Don't process anything */ 1251 * Don't process anything */
@@ -1346,6 +1384,8 @@ dpc_post_reset_ha:
1346 } 1384 }
1347 } 1385 }
1348 } 1386 }
1387
1388do_dpc_exit:
1349 clear_bit(AF_DPC_SCHEDULED, &ha->flags); 1389 clear_bit(AF_DPC_SCHEDULED, &ha->flags);
1350} 1390}
1351 1391
@@ -1612,6 +1652,8 @@ static int __devinit qla4xxx_probe_adapter(struct pci_dev *pdev,
1612 ha->host = host; 1652 ha->host = host;
1613 ha->host_no = host->host_no; 1653 ha->host_no = host->host_no;
1614 1654
1655 pci_enable_pcie_error_reporting(pdev);
1656
1615 /* Setup Runtime configurable options */ 1657 /* Setup Runtime configurable options */
1616 if (is_qla8022(ha)) { 1658 if (is_qla8022(ha)) {
1617 ha->isp_ops = &qla4_8xxx_isp_ops; 1659 ha->isp_ops = &qla4_8xxx_isp_ops;
@@ -1630,6 +1672,10 @@ static int __devinit qla4xxx_probe_adapter(struct pci_dev *pdev,
1630 ha->isp_ops = &qla4xxx_isp_ops; 1672 ha->isp_ops = &qla4xxx_isp_ops;
1631 } 1673 }
1632 1674
1675 /* Set EEH reset type to fundamental if required by hba */
1676 if (is_qla8022(ha))
1677 pdev->needs_freset = 1;
1678
1633 /* Configure PCI I/O space. */ 1679 /* Configure PCI I/O space. */
1634 ret = ha->isp_ops->iospace_config(ha); 1680 ret = ha->isp_ops->iospace_config(ha);
1635 if (ret) 1681 if (ret)
@@ -1726,6 +1772,7 @@ static int __devinit qla4xxx_probe_adapter(struct pci_dev *pdev,
1726 } 1772 }
1727 } 1773 }
1728 1774
1775 pci_save_state(ha->pdev);
1729 ha->isp_ops->enable_intrs(ha); 1776 ha->isp_ops->enable_intrs(ha);
1730 1777
1731 /* Start timer thread. */ 1778 /* Start timer thread. */
@@ -1752,6 +1799,7 @@ probe_failed:
1752 qla4xxx_free_adapter(ha); 1799 qla4xxx_free_adapter(ha);
1753 1800
1754probe_failed_ioconfig: 1801probe_failed_ioconfig:
1802 pci_disable_pcie_error_reporting(pdev);
1755 scsi_host_put(ha->host); 1803 scsi_host_put(ha->host);
1756 1804
1757probe_disable_device: 1805probe_disable_device:
@@ -1781,6 +1829,7 @@ static void __devexit qla4xxx_remove_adapter(struct pci_dev *pdev)
1781 1829
1782 scsi_host_put(ha->host); 1830 scsi_host_put(ha->host);
1783 1831
1832 pci_disable_pcie_error_reporting(pdev);
1784 pci_disable_device(pdev); 1833 pci_disable_device(pdev);
1785 pci_set_drvdata(pdev, NULL); 1834 pci_set_drvdata(pdev, NULL);
1786} 1835}
@@ -1877,6 +1926,17 @@ static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha,
1877 int done = 0; 1926 int done = 0;
1878 struct srb *rp; 1927 struct srb *rp;
1879 uint32_t max_wait_time = EH_WAIT_CMD_TOV; 1928 uint32_t max_wait_time = EH_WAIT_CMD_TOV;
1929 int ret = SUCCESS;
1930
1931 /* Dont wait on command if PCI error is being handled
1932 * by PCI AER driver
1933 */
1934 if (unlikely(pci_channel_offline(ha->pdev)) ||
1935 (test_bit(AF_EEH_BUSY, &ha->flags))) {
1936 ql4_printk(KERN_WARNING, ha, "scsi%ld: Return from %s\n",
1937 ha->host_no, __func__);
1938 return ret;
1939 }
1880 1940
1881 do { 1941 do {
1882 /* Checking to see if its returned to OS */ 1942 /* Checking to see if its returned to OS */
@@ -2172,6 +2232,252 @@ static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd)
2172 return return_status; 2232 return return_status;
2173} 2233}
2174 2234
2235/* PCI AER driver recovers from all correctable errors w/o
2236 * driver intervention. For uncorrectable errors PCI AER
2237 * driver calls the following device driver's callbacks
2238 *
2239 * - Fatal Errors - link_reset
2240 * - Non-Fatal Errors - driver's pci_error_detected() which
2241 * returns CAN_RECOVER, NEED_RESET or DISCONNECT.
2242 *
2243 * PCI AER driver calls
2244 * CAN_RECOVER - driver's pci_mmio_enabled(), mmio_enabled
2245 * returns RECOVERED or NEED_RESET if fw_hung
2246 * NEED_RESET - driver's slot_reset()
2247 * DISCONNECT - device is dead & cannot recover
2248 * RECOVERED - driver's pci_resume()
2249 */
2250static pci_ers_result_t
2251qla4xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
2252{
2253 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
2254
2255 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: error detected:state %x\n",
2256 ha->host_no, __func__, state);
2257
2258 if (!is_aer_supported(ha))
2259 return PCI_ERS_RESULT_NONE;
2260
2261 switch (state) {
2262 case pci_channel_io_normal:
2263 clear_bit(AF_EEH_BUSY, &ha->flags);
2264 return PCI_ERS_RESULT_CAN_RECOVER;
2265 case pci_channel_io_frozen:
2266 set_bit(AF_EEH_BUSY, &ha->flags);
2267 qla4xxx_mailbox_premature_completion(ha);
2268 qla4xxx_free_irqs(ha);
2269 pci_disable_device(pdev);
2270 return PCI_ERS_RESULT_NEED_RESET;
2271 case pci_channel_io_perm_failure:
2272 set_bit(AF_EEH_BUSY, &ha->flags);
2273 set_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags);
2274 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
2275 return PCI_ERS_RESULT_DISCONNECT;
2276 }
2277 return PCI_ERS_RESULT_NEED_RESET;
2278}
2279
2280/**
2281 * qla4xxx_pci_mmio_enabled() gets called if
2282 * qla4xxx_pci_error_detected() returns PCI_ERS_RESULT_CAN_RECOVER
2283 * and read/write to the device still works.
2284 **/
2285static pci_ers_result_t
2286qla4xxx_pci_mmio_enabled(struct pci_dev *pdev)
2287{
2288 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
2289
2290 if (!is_aer_supported(ha))
2291 return PCI_ERS_RESULT_NONE;
2292
2293 if (test_bit(AF_FW_RECOVERY, &ha->flags)) {
2294 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: firmware hang -- "
2295 "mmio_enabled\n", ha->host_no, __func__);
2296 return PCI_ERS_RESULT_NEED_RESET;
2297 } else
2298 return PCI_ERS_RESULT_RECOVERED;
2299}
2300
2301uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha)
2302{
2303 uint32_t rval = QLA_ERROR;
2304 int fn;
2305 struct pci_dev *other_pdev = NULL;
2306
2307 ql4_printk(KERN_WARNING, ha, "scsi%ld: In %s\n", ha->host_no, __func__);
2308
2309 set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
2310
2311 if (test_bit(AF_ONLINE, &ha->flags)) {
2312 clear_bit(AF_ONLINE, &ha->flags);
2313 qla4xxx_mark_all_devices_missing(ha);
2314 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
2315 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
2316 }
2317
2318 fn = PCI_FUNC(ha->pdev->devfn);
2319 while (fn > 0) {
2320 fn--;
2321 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Finding PCI device at "
2322 "func %x\n", ha->host_no, __func__, fn);
2323 /* Get the pci device given the domain, bus,
2324 * slot/function number */
2325 other_pdev =
2326 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
2327 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
2328 fn));
2329
2330 if (!other_pdev)
2331 continue;
2332
2333 if (atomic_read(&other_pdev->enable_cnt)) {
2334 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Found PCI "
2335 "func in enabled state%x\n", ha->host_no,
2336 __func__, fn);
2337 pci_dev_put(other_pdev);
2338 break;
2339 }
2340 pci_dev_put(other_pdev);
2341 }
2342
2343 /* The first function on the card, the reset owner will
2344 * start & initialize the firmware. The other functions
2345 * on the card will reset the firmware context
2346 */
2347 if (!fn) {
2348 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn being reset "
2349 "0x%x is the owner\n", ha->host_no, __func__,
2350 ha->pdev->devfn);
2351
2352 qla4_8xxx_idc_lock(ha);
2353 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
2354 QLA82XX_DEV_COLD);
2355
2356 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
2357 QLA82XX_IDC_VERSION);
2358
2359 qla4_8xxx_idc_unlock(ha);
2360 clear_bit(AF_FW_RECOVERY, &ha->flags);
2361 rval = qla4xxx_initialize_adapter(ha, PRESERVE_DDB_LIST);
2362 qla4_8xxx_idc_lock(ha);
2363
2364 if (rval != QLA_SUCCESS) {
2365 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
2366 "FAILED\n", ha->host_no, __func__);
2367 qla4_8xxx_clear_drv_active(ha);
2368 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
2369 QLA82XX_DEV_FAILED);
2370 } else {
2371 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
2372 "READY\n", ha->host_no, __func__);
2373 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
2374 QLA82XX_DEV_READY);
2375 /* Clear driver state register */
2376 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
2377 qla4_8xxx_set_drv_active(ha);
2378 ha->isp_ops->enable_intrs(ha);
2379 }
2380 qla4_8xxx_idc_unlock(ha);
2381 } else {
2382 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn 0x%x is not "
2383 "the reset owner\n", ha->host_no, __func__,
2384 ha->pdev->devfn);
2385 if ((qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
2386 QLA82XX_DEV_READY)) {
2387 clear_bit(AF_FW_RECOVERY, &ha->flags);
2388 rval = qla4xxx_initialize_adapter(ha,
2389 PRESERVE_DDB_LIST);
2390 if (rval == QLA_SUCCESS)
2391 ha->isp_ops->enable_intrs(ha);
2392 qla4_8xxx_idc_lock(ha);
2393 qla4_8xxx_set_drv_active(ha);
2394 qla4_8xxx_idc_unlock(ha);
2395 }
2396 }
2397 clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
2398 return rval;
2399}
2400
2401static pci_ers_result_t
2402qla4xxx_pci_slot_reset(struct pci_dev *pdev)
2403{
2404 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
2405 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
2406 int rc;
2407
2408 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: slot_reset\n",
2409 ha->host_no, __func__);
2410
2411 if (!is_aer_supported(ha))
2412 return PCI_ERS_RESULT_NONE;
2413
2414 /* Restore the saved state of PCIe device -
2415 * BAR registers, PCI Config space, PCIX, MSI,
2416 * IOV states
2417 */
2418 pci_restore_state(pdev);
2419
2420 /* pci_restore_state() clears the saved_state flag of the device
2421 * save restored state which resets saved_state flag
2422 */
2423 pci_save_state(pdev);
2424
2425 /* Initialize device or resume if in suspended state */
2426 rc = pci_enable_device(pdev);
2427 if (rc) {
2428 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Cant re-enable "
2429 "device after reset\n", ha->host_no, __func__);
2430 goto exit_slot_reset;
2431 }
2432
2433 ret = qla4xxx_request_irqs(ha);
2434 if (ret) {
2435 ql4_printk(KERN_WARNING, ha, "Failed to reserve interrupt %d"
2436 " already in use.\n", pdev->irq);
2437 goto exit_slot_reset;
2438 }
2439
2440 if (is_qla8022(ha)) {
2441 if (qla4_8xxx_error_recovery(ha) == QLA_SUCCESS) {
2442 ret = PCI_ERS_RESULT_RECOVERED;
2443 goto exit_slot_reset;
2444 } else
2445 goto exit_slot_reset;
2446 }
2447
2448exit_slot_reset:
2449 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Return=%x\n"
2450 "device after reset\n", ha->host_no, __func__, ret);
2451 return ret;
2452}
2453
2454static void
2455qla4xxx_pci_resume(struct pci_dev *pdev)
2456{
2457 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
2458 int ret;
2459
2460 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: pci_resume\n",
2461 ha->host_no, __func__);
2462
2463 ret = qla4xxx_wait_for_hba_online(ha);
2464 if (ret != QLA_SUCCESS) {
2465 ql4_printk(KERN_ERR, ha, "scsi%ld: %s: the device failed to "
2466 "resume I/O from slot/link_reset\n", ha->host_no,
2467 __func__);
2468 }
2469
2470 pci_cleanup_aer_uncorrect_error_status(pdev);
2471 clear_bit(AF_EEH_BUSY, &ha->flags);
2472}
2473
2474static struct pci_error_handlers qla4xxx_err_handler = {
2475 .error_detected = qla4xxx_pci_error_detected,
2476 .mmio_enabled = qla4xxx_pci_mmio_enabled,
2477 .slot_reset = qla4xxx_pci_slot_reset,
2478 .resume = qla4xxx_pci_resume,
2479};
2480
2175static struct pci_device_id qla4xxx_pci_tbl[] = { 2481static struct pci_device_id qla4xxx_pci_tbl[] = {
2176 { 2482 {
2177 .vendor = PCI_VENDOR_ID_QLOGIC, 2483 .vendor = PCI_VENDOR_ID_QLOGIC,
@@ -2206,6 +2512,7 @@ static struct pci_driver qla4xxx_pci_driver = {
2206 .id_table = qla4xxx_pci_tbl, 2512 .id_table = qla4xxx_pci_tbl,
2207 .probe = qla4xxx_probe_adapter, 2513 .probe = qla4xxx_probe_adapter,
2208 .remove = qla4xxx_remove_adapter, 2514 .remove = qla4xxx_remove_adapter,
2515 .err_handler = &qla4xxx_err_handler,
2209}; 2516};
2210 2517
2211static int __init qla4xxx_module_init(void) 2518static int __init qla4xxx_module_init(void)
diff --git a/drivers/scsi/qla4xxx/ql4_version.h b/drivers/scsi/qla4xxx/ql4_version.h
index c905dbd75331..a77b973f2cbc 100644
--- a/drivers/scsi/qla4xxx/ql4_version.h
+++ b/drivers/scsi/qla4xxx/ql4_version.h
@@ -5,4 +5,4 @@
5 * See LICENSE.qla4xxx for copyright and licensing details. 5 * See LICENSE.qla4xxx for copyright and licensing details.
6 */ 6 */
7 7
8#define QLA4XXX_DRIVER_VERSION "5.02.00-k2" 8#define QLA4XXX_DRIVER_VERSION "5.02.00-k3"
diff --git a/drivers/scsi/qlogicpti.c b/drivers/scsi/qlogicpti.c
index 53d7ed0dc169..f8c561cf751e 100644
--- a/drivers/scsi/qlogicpti.c
+++ b/drivers/scsi/qlogicpti.c
@@ -704,7 +704,7 @@ static void __devexit qpti_chain_del(struct qlogicpti *qpti)
704 704
705static int __devinit qpti_map_regs(struct qlogicpti *qpti) 705static int __devinit qpti_map_regs(struct qlogicpti *qpti)
706{ 706{
707 struct of_device *op = qpti->op; 707 struct platform_device *op = qpti->op;
708 708
709 qpti->qregs = of_ioremap(&op->resource[0], 0, 709 qpti->qregs = of_ioremap(&op->resource[0], 0,
710 resource_size(&op->resource[0]), 710 resource_size(&op->resource[0]),
@@ -727,7 +727,7 @@ static int __devinit qpti_map_regs(struct qlogicpti *qpti)
727 727
728static int __devinit qpti_register_irq(struct qlogicpti *qpti) 728static int __devinit qpti_register_irq(struct qlogicpti *qpti)
729{ 729{
730 struct of_device *op = qpti->op; 730 struct platform_device *op = qpti->op;
731 731
732 qpti->qhost->irq = qpti->irq = op->archdata.irqs[0]; 732 qpti->qhost->irq = qpti->irq = op->archdata.irqs[0];
733 733
@@ -752,7 +752,7 @@ fail:
752 752
753static void __devinit qpti_get_scsi_id(struct qlogicpti *qpti) 753static void __devinit qpti_get_scsi_id(struct qlogicpti *qpti)
754{ 754{
755 struct of_device *op = qpti->op; 755 struct platform_device *op = qpti->op;
756 struct device_node *dp; 756 struct device_node *dp;
757 757
758 dp = op->dev.of_node; 758 dp = op->dev.of_node;
@@ -773,7 +773,7 @@ static void __devinit qpti_get_scsi_id(struct qlogicpti *qpti)
773 773
774static void qpti_get_bursts(struct qlogicpti *qpti) 774static void qpti_get_bursts(struct qlogicpti *qpti)
775{ 775{
776 struct of_device *op = qpti->op; 776 struct platform_device *op = qpti->op;
777 u8 bursts, bmask; 777 u8 bursts, bmask;
778 778
779 bursts = of_getintprop_default(op->dev.of_node, "burst-sizes", 0xff); 779 bursts = of_getintprop_default(op->dev.of_node, "burst-sizes", 0xff);
@@ -806,7 +806,7 @@ static void qpti_get_clock(struct qlogicpti *qpti)
806 */ 806 */
807static int __devinit qpti_map_queues(struct qlogicpti *qpti) 807static int __devinit qpti_map_queues(struct qlogicpti *qpti)
808{ 808{
809 struct of_device *op = qpti->op; 809 struct platform_device *op = qpti->op;
810 810
811#define QSIZE(entries) (((entries) + 1) * QUEUE_ENTRY_LEN) 811#define QSIZE(entries) (((entries) + 1) * QUEUE_ENTRY_LEN)
812 qpti->res_cpu = dma_alloc_coherent(&op->dev, 812 qpti->res_cpu = dma_alloc_coherent(&op->dev,
@@ -1290,7 +1290,7 @@ static struct scsi_host_template qpti_template = {
1290 .use_clustering = ENABLE_CLUSTERING, 1290 .use_clustering = ENABLE_CLUSTERING,
1291}; 1291};
1292 1292
1293static int __devinit qpti_sbus_probe(struct of_device *op, const struct of_device_id *match) 1293static int __devinit qpti_sbus_probe(struct platform_device *op, const struct of_device_id *match)
1294{ 1294{
1295 struct scsi_host_template *tpnt = match->data; 1295 struct scsi_host_template *tpnt = match->data;
1296 struct device_node *dp = op->dev.of_node; 1296 struct device_node *dp = op->dev.of_node;
@@ -1401,7 +1401,7 @@ fail_unlink:
1401 return -ENODEV; 1401 return -ENODEV;
1402} 1402}
1403 1403
1404static int __devexit qpti_sbus_remove(struct of_device *op) 1404static int __devexit qpti_sbus_remove(struct platform_device *op)
1405{ 1405{
1406 struct qlogicpti *qpti = dev_get_drvdata(&op->dev); 1406 struct qlogicpti *qpti = dev_get_drvdata(&op->dev);
1407 1407
diff --git a/drivers/scsi/qlogicpti.h b/drivers/scsi/qlogicpti.h
index e3c74d1ee2db..4377e87ee79c 100644
--- a/drivers/scsi/qlogicpti.h
+++ b/drivers/scsi/qlogicpti.h
@@ -342,7 +342,7 @@ struct qlogicpti {
342 u_int req_in_ptr; /* index of next request slot */ 342 u_int req_in_ptr; /* index of next request slot */
343 u_int res_out_ptr; /* index of next result slot */ 343 u_int res_out_ptr; /* index of next result slot */
344 long send_marker; /* must we send a marker? */ 344 long send_marker; /* must we send a marker? */
345 struct of_device *op; 345 struct platform_device *op;
346 unsigned long __pad; 346 unsigned long __pad;
347 347
348 int cmd_count[MAX_TARGETS]; 348 int cmd_count[MAX_TARGETS];
diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c
index 2bf98469dc4c..1de30eb83bb0 100644
--- a/drivers/scsi/scsi_error.c
+++ b/drivers/scsi/scsi_error.c
@@ -320,7 +320,7 @@ static int scsi_check_sense(struct scsi_cmnd *scmd)
320 "changed. The Linux SCSI layer does not " 320 "changed. The Linux SCSI layer does not "
321 "automatically adjust these parameters.\n"); 321 "automatically adjust these parameters.\n");
322 322
323 if (blk_barrier_rq(scmd->request)) 323 if (scmd->request->cmd_flags & REQ_HARDBARRIER)
324 /* 324 /*
325 * barrier requests should always retry on UA 325 * barrier requests should always retry on UA
326 * otherwise block will get a spurious error 326 * otherwise block will get a spurious error
@@ -473,14 +473,17 @@ static int scsi_eh_completed_normally(struct scsi_cmnd *scmd)
473 */ 473 */
474 return SUCCESS; 474 return SUCCESS;
475 case RESERVATION_CONFLICT: 475 case RESERVATION_CONFLICT:
476 /* 476 if (scmd->cmnd[0] == TEST_UNIT_READY)
477 * let issuer deal with this, it could be just fine 477 /* it is a success, we probed the device and
478 */ 478 * found it */
479 return SUCCESS; 479 return SUCCESS;
480 /* otherwise, we failed to send the command */
481 return FAILED;
480 case QUEUE_FULL: 482 case QUEUE_FULL:
481 scsi_handle_queue_full(scmd->device); 483 scsi_handle_queue_full(scmd->device);
482 /* fall through */ 484 /* fall through */
483 case BUSY: 485 case BUSY:
486 return NEEDS_RETRY;
484 default: 487 default:
485 return FAILED; 488 return FAILED;
486 } 489 }
@@ -1331,16 +1334,16 @@ int scsi_noretry_cmd(struct scsi_cmnd *scmd)
1331 case DID_OK: 1334 case DID_OK:
1332 break; 1335 break;
1333 case DID_BUS_BUSY: 1336 case DID_BUS_BUSY:
1334 return blk_failfast_transport(scmd->request); 1337 return (scmd->request->cmd_flags & REQ_FAILFAST_TRANSPORT);
1335 case DID_PARITY: 1338 case DID_PARITY:
1336 return blk_failfast_dev(scmd->request); 1339 return (scmd->request->cmd_flags & REQ_FAILFAST_DEV);
1337 case DID_ERROR: 1340 case DID_ERROR:
1338 if (msg_byte(scmd->result) == COMMAND_COMPLETE && 1341 if (msg_byte(scmd->result) == COMMAND_COMPLETE &&
1339 status_byte(scmd->result) == RESERVATION_CONFLICT) 1342 status_byte(scmd->result) == RESERVATION_CONFLICT)
1340 return 0; 1343 return 0;
1341 /* fall through */ 1344 /* fall through */
1342 case DID_SOFT_ERROR: 1345 case DID_SOFT_ERROR:
1343 return blk_failfast_driver(scmd->request); 1346 return (scmd->request->cmd_flags & REQ_FAILFAST_DRIVER);
1344 } 1347 }
1345 1348
1346 switch (status_byte(scmd->result)) { 1349 switch (status_byte(scmd->result)) {
@@ -1349,7 +1352,9 @@ int scsi_noretry_cmd(struct scsi_cmnd *scmd)
1349 * assume caller has checked sense and determinted 1352 * assume caller has checked sense and determinted
1350 * the check condition was retryable. 1353 * the check condition was retryable.
1351 */ 1354 */
1352 return blk_failfast_dev(scmd->request); 1355 if (scmd->request->cmd_flags & REQ_FAILFAST_DEV ||
1356 scmd->request->cmd_type == REQ_TYPE_BLOCK_PC)
1357 return 1;
1353 } 1358 }
1354 1359
1355 return 0; 1360 return 0;
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 1646fe7cbd4b..9ade720422c6 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -85,7 +85,7 @@ static void scsi_unprep_request(struct request *req)
85{ 85{
86 struct scsi_cmnd *cmd = req->special; 86 struct scsi_cmnd *cmd = req->special;
87 87
88 req->cmd_flags &= ~REQ_DONTPREP; 88 blk_unprep_request(req);
89 req->special = NULL; 89 req->special = NULL;
90 90
91 scsi_put_command(cmd); 91 scsi_put_command(cmd);
@@ -722,7 +722,7 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
722 sense_deferred = scsi_sense_is_deferred(&sshdr); 722 sense_deferred = scsi_sense_is_deferred(&sshdr);
723 } 723 }
724 724
725 if (blk_pc_request(req)) { /* SG_IO ioctl from block level */ 725 if (req->cmd_type == REQ_TYPE_BLOCK_PC) { /* SG_IO ioctl from block level */
726 req->errors = result; 726 req->errors = result;
727 if (result) { 727 if (result) {
728 if (sense_valid && req->sense) { 728 if (sense_valid && req->sense) {
@@ -757,7 +757,8 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
757 } 757 }
758 } 758 }
759 759
760 BUG_ON(blk_bidi_rq(req)); /* bidi not support for !blk_pc_request yet */ 760 /* no bidi support for !REQ_TYPE_BLOCK_PC yet */
761 BUG_ON(blk_bidi_rq(req));
761 762
762 /* 763 /*
763 * Next deal with any sectors which we were able to correctly 764 * Next deal with any sectors which we were able to correctly
@@ -1010,11 +1011,8 @@ int scsi_init_io(struct scsi_cmnd *cmd, gfp_t gfp_mask)
1010 1011
1011err_exit: 1012err_exit:
1012 scsi_release_buffers(cmd); 1013 scsi_release_buffers(cmd);
1013 if (error == BLKPREP_KILL) 1014 scsi_put_command(cmd);
1014 scsi_put_command(cmd); 1015 cmd->request->special = NULL;
1015 else /* BLKPREP_DEFER */
1016 scsi_unprep_request(cmd->request);
1017
1018 return error; 1016 return error;
1019} 1017}
1020EXPORT_SYMBOL(scsi_init_io); 1018EXPORT_SYMBOL(scsi_init_io);
@@ -1372,12 +1370,6 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
1372 1370
1373 blk_start_request(req); 1371 blk_start_request(req);
1374 1372
1375 if (unlikely(cmd == NULL)) {
1376 printk(KERN_CRIT "impossible request in %s.\n",
1377 __func__);
1378 BUG();
1379 }
1380
1381 sdev = cmd->device; 1373 sdev = cmd->device;
1382 starget = scsi_target(sdev); 1374 starget = scsi_target(sdev);
1383 shost = sdev->host; 1375 shost = sdev->host;
diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
index 66241dd525ae..c399be979921 100644
--- a/drivers/scsi/scsi_tgt_lib.c
+++ b/drivers/scsi/scsi_tgt_lib.c
@@ -185,6 +185,7 @@ static void scsi_tgt_cmd_destroy(struct work_struct *work)
185 dprintk("cmd %p %d %u\n", cmd, cmd->sc_data_direction, 185 dprintk("cmd %p %d %u\n", cmd, cmd->sc_data_direction,
186 rq_data_dir(cmd->request)); 186 rq_data_dir(cmd->request));
187 scsi_unmap_user_pages(tcmd); 187 scsi_unmap_user_pages(tcmd);
188 tcmd->rq->bio = NULL;
188 scsi_host_put_command(scsi_tgt_cmd_to_host(cmd), cmd); 189 scsi_host_put_command(scsi_tgt_cmd_to_host(cmd), cmd);
189} 190}
190 191
diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
index edb6b362a8fa..d7e470a06180 100644
--- a/drivers/scsi/scsi_transport_fc.c
+++ b/drivers/scsi/scsi_transport_fc.c
@@ -29,6 +29,7 @@
29#include <linux/init.h> 29#include <linux/init.h>
30#include <linux/slab.h> 30#include <linux/slab.h>
31#include <linux/delay.h> 31#include <linux/delay.h>
32#include <linux/kernel.h>
32#include <scsi/scsi_device.h> 33#include <scsi/scsi_device.h>
33#include <scsi/scsi_host.h> 34#include <scsi/scsi_host.h>
34#include <scsi/scsi_transport.h> 35#include <scsi/scsi_transport.h>
@@ -1730,12 +1731,11 @@ fc_parse_wwn(const char *ns, u64 *nm)
1730 1731
1731 /* Validate and store the new name */ 1732 /* Validate and store the new name */
1732 for (i=0, j=0; i < 16; i++) { 1733 for (i=0, j=0; i < 16; i++) {
1733 if ((*ns >= 'a') && (*ns <= 'f')) 1734 int value;
1734 j = ((j << 4) | ((*ns++ -'a') + 10)); 1735
1735 else if ((*ns >= 'A') && (*ns <= 'F')) 1736 value = hex_to_bin(*ns++);
1736 j = ((j << 4) | ((*ns++ -'A') + 10)); 1737 if (value >= 0)
1737 else if ((*ns >= '0') && (*ns <= '9')) 1738 j = (j << 4) | value;
1738 j = ((j << 4) | (*ns++ -'0'));
1739 else 1739 else
1740 return -EINVAL; 1740 return -EINVAL;
1741 if (i % 2) { 1741 if (i % 2) {
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index cc8a1d1d915a..2714becc2eaf 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -46,6 +46,7 @@
46#include <linux/blkdev.h> 46#include <linux/blkdev.h>
47#include <linux/blkpg.h> 47#include <linux/blkpg.h>
48#include <linux/delay.h> 48#include <linux/delay.h>
49#include <linux/smp_lock.h>
49#include <linux/mutex.h> 50#include <linux/mutex.h>
50#include <linux/string_helpers.h> 51#include <linux/string_helpers.h>
51#include <linux/async.h> 52#include <linux/async.h>
@@ -118,8 +119,8 @@ static DEFINE_IDA(sd_index_ida);
118 * object after last put) */ 119 * object after last put) */
119static DEFINE_MUTEX(sd_ref_mutex); 120static DEFINE_MUTEX(sd_ref_mutex);
120 121
121struct kmem_cache *sd_cdb_cache; 122static struct kmem_cache *sd_cdb_cache;
122mempool_t *sd_cdb_pool; 123static mempool_t *sd_cdb_pool;
123 124
124static const char *sd_cache_types[] = { 125static const char *sd_cache_types[] = {
125 "write through", "none", "write back", 126 "write through", "none", "write back",
@@ -146,7 +147,7 @@ sd_store_cache_type(struct device *dev, struct device_attribute *attr,
146 return -EINVAL; 147 return -EINVAL;
147 148
148 for (i = 0; i < ARRAY_SIZE(sd_cache_types); i++) { 149 for (i = 0; i < ARRAY_SIZE(sd_cache_types); i++) {
149 const int len = strlen(sd_cache_types[i]); 150 len = strlen(sd_cache_types[i]);
150 if (strncmp(sd_cache_types[i], buf, len) == 0 && 151 if (strncmp(sd_cache_types[i], buf, len) == 0 &&
151 buf[len] == '\n') { 152 buf[len] == '\n') {
152 ct = i; 153 ct = i;
@@ -411,54 +412,85 @@ static void sd_prot_op(struct scsi_cmnd *scmd, unsigned int dif)
411} 412}
412 413
413/** 414/**
414 * sd_prepare_discard - unmap blocks on thinly provisioned device 415 * scsi_setup_discard_cmnd - unmap blocks on thinly provisioned device
416 * @sdp: scsi device to operate one
415 * @rq: Request to prepare 417 * @rq: Request to prepare
416 * 418 *
417 * Will issue either UNMAP or WRITE SAME(16) depending on preference 419 * Will issue either UNMAP or WRITE SAME(16) depending on preference
418 * indicated by target device. 420 * indicated by target device.
419 **/ 421 **/
420static int sd_prepare_discard(struct request *rq) 422static int scsi_setup_discard_cmnd(struct scsi_device *sdp, struct request *rq)
421{ 423{
422 struct scsi_disk *sdkp = scsi_disk(rq->rq_disk); 424 struct scsi_disk *sdkp = scsi_disk(rq->rq_disk);
423 struct bio *bio = rq->bio; 425 struct bio *bio = rq->bio;
424 sector_t sector = bio->bi_sector; 426 sector_t sector = bio->bi_sector;
425 unsigned int num = bio_sectors(bio); 427 unsigned int nr_sectors = bio_sectors(bio);
428 unsigned int len;
429 int ret;
430 struct page *page;
426 431
427 if (sdkp->device->sector_size == 4096) { 432 if (sdkp->device->sector_size == 4096) {
428 sector >>= 3; 433 sector >>= 3;
429 num >>= 3; 434 nr_sectors >>= 3;
430 } 435 }
431 436
432 rq->cmd_type = REQ_TYPE_BLOCK_PC;
433 rq->timeout = SD_TIMEOUT; 437 rq->timeout = SD_TIMEOUT;
434 438
435 memset(rq->cmd, 0, rq->cmd_len); 439 memset(rq->cmd, 0, rq->cmd_len);
436 440
441 page = alloc_page(GFP_ATOMIC | __GFP_ZERO);
442 if (!page)
443 return BLKPREP_DEFER;
444
437 if (sdkp->unmap) { 445 if (sdkp->unmap) {
438 char *buf = kmap_atomic(bio_page(bio), KM_USER0); 446 char *buf = page_address(page);
439 447
448 rq->cmd_len = 10;
440 rq->cmd[0] = UNMAP; 449 rq->cmd[0] = UNMAP;
441 rq->cmd[8] = 24; 450 rq->cmd[8] = 24;
442 rq->cmd_len = 10;
443
444 /* Ensure that data length matches payload */
445 rq->__data_len = bio->bi_size = bio->bi_io_vec->bv_len = 24;
446 451
447 put_unaligned_be16(6 + 16, &buf[0]); 452 put_unaligned_be16(6 + 16, &buf[0]);
448 put_unaligned_be16(16, &buf[2]); 453 put_unaligned_be16(16, &buf[2]);
449 put_unaligned_be64(sector, &buf[8]); 454 put_unaligned_be64(sector, &buf[8]);
450 put_unaligned_be32(num, &buf[16]); 455 put_unaligned_be32(nr_sectors, &buf[16]);
451 456
452 kunmap_atomic(buf, KM_USER0); 457 len = 24;
453 } else { 458 } else {
459 rq->cmd_len = 16;
454 rq->cmd[0] = WRITE_SAME_16; 460 rq->cmd[0] = WRITE_SAME_16;
455 rq->cmd[1] = 0x8; /* UNMAP */ 461 rq->cmd[1] = 0x8; /* UNMAP */
456 put_unaligned_be64(sector, &rq->cmd[2]); 462 put_unaligned_be64(sector, &rq->cmd[2]);
457 put_unaligned_be32(num, &rq->cmd[10]); 463 put_unaligned_be32(nr_sectors, &rq->cmd[10]);
458 rq->cmd_len = 16; 464
465 len = sdkp->device->sector_size;
466 }
467
468 blk_add_request_payload(rq, page, len);
469 ret = scsi_setup_blk_pc_cmnd(sdp, rq);
470 rq->buffer = page_address(page);
471 if (ret != BLKPREP_OK) {
472 __free_page(page);
473 rq->buffer = NULL;
459 } 474 }
475 return ret;
476}
460 477
461 return BLKPREP_OK; 478static int scsi_setup_flush_cmnd(struct scsi_device *sdp, struct request *rq)
479{
480 rq->timeout = SD_TIMEOUT;
481 rq->retries = SD_MAX_RETRIES;
482 rq->cmd[0] = SYNCHRONIZE_CACHE;
483 rq->cmd_len = 10;
484
485 return scsi_setup_blk_pc_cmnd(sdp, rq);
486}
487
488static void sd_unprep_fn(struct request_queue *q, struct request *rq)
489{
490 if (rq->cmd_flags & REQ_DISCARD) {
491 free_page((unsigned long)rq->buffer);
492 rq->buffer = NULL;
493 }
462} 494}
463 495
464/** 496/**
@@ -485,10 +517,13 @@ static int sd_prep_fn(struct request_queue *q, struct request *rq)
485 * Discard request come in as REQ_TYPE_FS but we turn them into 517 * Discard request come in as REQ_TYPE_FS but we turn them into
486 * block PC requests to make life easier. 518 * block PC requests to make life easier.
487 */ 519 */
488 if (blk_discard_rq(rq)) 520 if (rq->cmd_flags & REQ_DISCARD) {
489 ret = sd_prepare_discard(rq); 521 ret = scsi_setup_discard_cmnd(sdp, rq);
490 522 goto out;
491 if (rq->cmd_type == REQ_TYPE_BLOCK_PC) { 523 } else if (rq->cmd_flags & REQ_FLUSH) {
524 ret = scsi_setup_flush_cmnd(sdp, rq);
525 goto out;
526 } else if (rq->cmd_type == REQ_TYPE_BLOCK_PC) {
492 ret = scsi_setup_blk_pc_cmnd(sdp, rq); 527 ret = scsi_setup_blk_pc_cmnd(sdp, rq);
493 goto out; 528 goto out;
494 } else if (rq->cmd_type != REQ_TYPE_FS) { 529 } else if (rq->cmd_type != REQ_TYPE_FS) {
@@ -636,7 +671,7 @@ static int sd_prep_fn(struct request_queue *q, struct request *rq)
636 SCpnt->cmnd[0] = VARIABLE_LENGTH_CMD; 671 SCpnt->cmnd[0] = VARIABLE_LENGTH_CMD;
637 SCpnt->cmnd[7] = 0x18; 672 SCpnt->cmnd[7] = 0x18;
638 SCpnt->cmnd[9] = (rq_data_dir(rq) == READ) ? READ_32 : WRITE_32; 673 SCpnt->cmnd[9] = (rq_data_dir(rq) == READ) ? READ_32 : WRITE_32;
639 SCpnt->cmnd[10] = protect | (blk_fua_rq(rq) ? 0x8 : 0); 674 SCpnt->cmnd[10] = protect | ((rq->cmd_flags & REQ_FUA) ? 0x8 : 0);
640 675
641 /* LBA */ 676 /* LBA */
642 SCpnt->cmnd[12] = sizeof(block) > 4 ? (unsigned char) (block >> 56) & 0xff : 0; 677 SCpnt->cmnd[12] = sizeof(block) > 4 ? (unsigned char) (block >> 56) & 0xff : 0;
@@ -661,7 +696,7 @@ static int sd_prep_fn(struct request_queue *q, struct request *rq)
661 SCpnt->cmnd[31] = (unsigned char) this_count & 0xff; 696 SCpnt->cmnd[31] = (unsigned char) this_count & 0xff;
662 } else if (block > 0xffffffff) { 697 } else if (block > 0xffffffff) {
663 SCpnt->cmnd[0] += READ_16 - READ_6; 698 SCpnt->cmnd[0] += READ_16 - READ_6;
664 SCpnt->cmnd[1] = protect | (blk_fua_rq(rq) ? 0x8 : 0); 699 SCpnt->cmnd[1] = protect | ((rq->cmd_flags & REQ_FUA) ? 0x8 : 0);
665 SCpnt->cmnd[2] = sizeof(block) > 4 ? (unsigned char) (block >> 56) & 0xff : 0; 700 SCpnt->cmnd[2] = sizeof(block) > 4 ? (unsigned char) (block >> 56) & 0xff : 0;
666 SCpnt->cmnd[3] = sizeof(block) > 4 ? (unsigned char) (block >> 48) & 0xff : 0; 701 SCpnt->cmnd[3] = sizeof(block) > 4 ? (unsigned char) (block >> 48) & 0xff : 0;
667 SCpnt->cmnd[4] = sizeof(block) > 4 ? (unsigned char) (block >> 40) & 0xff : 0; 702 SCpnt->cmnd[4] = sizeof(block) > 4 ? (unsigned char) (block >> 40) & 0xff : 0;
@@ -682,7 +717,7 @@ static int sd_prep_fn(struct request_queue *q, struct request *rq)
682 this_count = 0xffff; 717 this_count = 0xffff;
683 718
684 SCpnt->cmnd[0] += READ_10 - READ_6; 719 SCpnt->cmnd[0] += READ_10 - READ_6;
685 SCpnt->cmnd[1] = protect | (blk_fua_rq(rq) ? 0x8 : 0); 720 SCpnt->cmnd[1] = protect | ((rq->cmd_flags & REQ_FUA) ? 0x8 : 0);
686 SCpnt->cmnd[2] = (unsigned char) (block >> 24) & 0xff; 721 SCpnt->cmnd[2] = (unsigned char) (block >> 24) & 0xff;
687 SCpnt->cmnd[3] = (unsigned char) (block >> 16) & 0xff; 722 SCpnt->cmnd[3] = (unsigned char) (block >> 16) & 0xff;
688 SCpnt->cmnd[4] = (unsigned char) (block >> 8) & 0xff; 723 SCpnt->cmnd[4] = (unsigned char) (block >> 8) & 0xff;
@@ -691,7 +726,7 @@ static int sd_prep_fn(struct request_queue *q, struct request *rq)
691 SCpnt->cmnd[7] = (unsigned char) (this_count >> 8) & 0xff; 726 SCpnt->cmnd[7] = (unsigned char) (this_count >> 8) & 0xff;
692 SCpnt->cmnd[8] = (unsigned char) this_count & 0xff; 727 SCpnt->cmnd[8] = (unsigned char) this_count & 0xff;
693 } else { 728 } else {
694 if (unlikely(blk_fua_rq(rq))) { 729 if (unlikely(rq->cmd_flags & REQ_FUA)) {
695 /* 730 /*
696 * This happens only if this drive failed 731 * This happens only if this drive failed
697 * 10byte rw command with ILLEGAL_REQUEST 732 * 10byte rw command with ILLEGAL_REQUEST
@@ -745,6 +780,8 @@ static int sd_prep_fn(struct request_queue *q, struct request *rq)
745 * or from within the kernel (e.g. as a result of a mount(1) ). 780 * or from within the kernel (e.g. as a result of a mount(1) ).
746 * In the latter case @inode and @filp carry an abridged amount 781 * In the latter case @inode and @filp carry an abridged amount
747 * of information as noted above. 782 * of information as noted above.
783 *
784 * Locking: called with bdev->bd_mutex held.
748 **/ 785 **/
749static int sd_open(struct block_device *bdev, fmode_t mode) 786static int sd_open(struct block_device *bdev, fmode_t mode)
750{ 787{
@@ -799,7 +836,7 @@ static int sd_open(struct block_device *bdev, fmode_t mode)
799 if (!scsi_device_online(sdev)) 836 if (!scsi_device_online(sdev))
800 goto error_out; 837 goto error_out;
801 838
802 if (!sdkp->openers++ && sdev->removable) { 839 if ((atomic_inc_return(&sdkp->openers) == 1) && sdev->removable) {
803 if (scsi_block_when_processing_errors(sdev)) 840 if (scsi_block_when_processing_errors(sdev))
804 scsi_set_medium_removal(sdev, SCSI_REMOVAL_PREVENT); 841 scsi_set_medium_removal(sdev, SCSI_REMOVAL_PREVENT);
805 } 842 }
@@ -823,6 +860,8 @@ error_autopm:
823 * 860 *
824 * Note: may block (uninterruptible) if error recovery is underway 861 * Note: may block (uninterruptible) if error recovery is underway
825 * on this disk. 862 * on this disk.
863 *
864 * Locking: called with bdev->bd_mutex held.
826 **/ 865 **/
827static int sd_release(struct gendisk *disk, fmode_t mode) 866static int sd_release(struct gendisk *disk, fmode_t mode)
828{ 867{
@@ -831,7 +870,7 @@ static int sd_release(struct gendisk *disk, fmode_t mode)
831 870
832 SCSI_LOG_HLQUEUE(3, sd_printk(KERN_INFO, sdkp, "sd_release\n")); 871 SCSI_LOG_HLQUEUE(3, sd_printk(KERN_INFO, sdkp, "sd_release\n"));
833 872
834 if (!--sdkp->openers && sdev->removable) { 873 if (atomic_dec_return(&sdkp->openers) && sdev->removable) {
835 if (scsi_block_when_processing_errors(sdev)) 874 if (scsi_block_when_processing_errors(sdev))
836 scsi_set_medium_removal(sdev, SCSI_REMOVAL_ALLOW); 875 scsi_set_medium_removal(sdev, SCSI_REMOVAL_ALLOW);
837 } 876 }
@@ -904,7 +943,7 @@ static int sd_ioctl(struct block_device *bdev, fmode_t mode,
904 error = scsi_nonblockable_ioctl(sdp, cmd, p, 943 error = scsi_nonblockable_ioctl(sdp, cmd, p,
905 (mode & FMODE_NDELAY) != 0); 944 (mode & FMODE_NDELAY) != 0);
906 if (!scsi_block_when_processing_errors(sdp) || !error) 945 if (!scsi_block_when_processing_errors(sdp) || !error)
907 return error; 946 goto out;
908 947
909 /* 948 /*
910 * Send SCSI addressing ioctls directly to mid level, send other 949 * Send SCSI addressing ioctls directly to mid level, send other
@@ -914,13 +953,17 @@ static int sd_ioctl(struct block_device *bdev, fmode_t mode,
914 switch (cmd) { 953 switch (cmd) {
915 case SCSI_IOCTL_GET_IDLUN: 954 case SCSI_IOCTL_GET_IDLUN:
916 case SCSI_IOCTL_GET_BUS_NUMBER: 955 case SCSI_IOCTL_GET_BUS_NUMBER:
917 return scsi_ioctl(sdp, cmd, p); 956 error = scsi_ioctl(sdp, cmd, p);
957 break;
918 default: 958 default:
919 error = scsi_cmd_ioctl(disk->queue, disk, mode, cmd, p); 959 error = scsi_cmd_ioctl(disk->queue, disk, mode, cmd, p);
920 if (error != -ENOTTY) 960 if (error != -ENOTTY)
921 return error; 961 break;
962 error = scsi_ioctl(sdp, cmd, p);
963 break;
922 } 964 }
923 return scsi_ioctl(sdp, cmd, p); 965out:
966 return error;
924} 967}
925 968
926static void set_media_not_present(struct scsi_disk *sdkp) 969static void set_media_not_present(struct scsi_disk *sdkp)
@@ -1045,15 +1088,6 @@ static int sd_sync_cache(struct scsi_disk *sdkp)
1045 return 0; 1088 return 0;
1046} 1089}
1047 1090
1048static void sd_prepare_flush(struct request_queue *q, struct request *rq)
1049{
1050 rq->cmd_type = REQ_TYPE_BLOCK_PC;
1051 rq->timeout = SD_TIMEOUT;
1052 rq->retries = SD_MAX_RETRIES;
1053 rq->cmd[0] = SYNCHRONIZE_CACHE;
1054 rq->cmd_len = 10;
1055}
1056
1057static void sd_rescan(struct device *dev) 1091static void sd_rescan(struct device *dev)
1058{ 1092{
1059 struct scsi_disk *sdkp = scsi_disk_get_from_dev(dev); 1093 struct scsi_disk *sdkp = scsi_disk_get_from_dev(dev);
@@ -1103,7 +1137,7 @@ static const struct block_device_operations sd_fops = {
1103 .owner = THIS_MODULE, 1137 .owner = THIS_MODULE,
1104 .open = sd_open, 1138 .open = sd_open,
1105 .release = sd_release, 1139 .release = sd_release,
1106 .locked_ioctl = sd_ioctl, 1140 .ioctl = sd_ioctl,
1107 .getgeo = sd_getgeo, 1141 .getgeo = sd_getgeo,
1108#ifdef CONFIG_COMPAT 1142#ifdef CONFIG_COMPAT
1109 .compat_ioctl = sd_compat_ioctl, 1143 .compat_ioctl = sd_compat_ioctl,
@@ -1120,7 +1154,7 @@ static unsigned int sd_completed_bytes(struct scsi_cmnd *scmd)
1120 u64 bad_lba; 1154 u64 bad_lba;
1121 int info_valid; 1155 int info_valid;
1122 1156
1123 if (!blk_fs_request(scmd->request)) 1157 if (scmd->request->cmd_type != REQ_TYPE_FS)
1124 return 0; 1158 return 0;
1125 1159
1126 info_valid = scsi_get_sense_info_fld(scmd->sense_buffer, 1160 info_valid = scsi_get_sense_info_fld(scmd->sense_buffer,
@@ -1171,6 +1205,12 @@ static int sd_done(struct scsi_cmnd *SCpnt)
1171 int sense_valid = 0; 1205 int sense_valid = 0;
1172 int sense_deferred = 0; 1206 int sense_deferred = 0;
1173 1207
1208 if (SCpnt->request->cmd_flags & REQ_DISCARD) {
1209 if (!result)
1210 scsi_set_resid(SCpnt, 0);
1211 return good_bytes;
1212 }
1213
1174 if (result) { 1214 if (result) {
1175 sense_valid = scsi_command_normalize_sense(SCpnt, &sshdr); 1215 sense_valid = scsi_command_normalize_sense(SCpnt, &sshdr);
1176 if (sense_valid) 1216 if (sense_valid)
@@ -1383,7 +1423,7 @@ sd_spinup_disk(struct scsi_disk *sdkp)
1383/* 1423/*
1384 * Determine whether disk supports Data Integrity Field. 1424 * Determine whether disk supports Data Integrity Field.
1385 */ 1425 */
1386void sd_read_protection_type(struct scsi_disk *sdkp, unsigned char *buffer) 1426static void sd_read_protection_type(struct scsi_disk *sdkp, unsigned char *buffer)
1387{ 1427{
1388 struct scsi_device *sdp = sdkp->device; 1428 struct scsi_device *sdp = sdkp->device;
1389 u8 type; 1429 u8 type;
@@ -1929,7 +1969,7 @@ defaults:
1929 * The ATO bit indicates whether the DIF application tag is available 1969 * The ATO bit indicates whether the DIF application tag is available
1930 * for use by the operating system. 1970 * for use by the operating system.
1931 */ 1971 */
1932void sd_read_app_tag_own(struct scsi_disk *sdkp, unsigned char *buffer) 1972static void sd_read_app_tag_own(struct scsi_disk *sdkp, unsigned char *buffer)
1933{ 1973{
1934 int res, offset; 1974 int res, offset;
1935 struct scsi_device *sdp = sdkp->device; 1975 struct scsi_device *sdp = sdkp->device;
@@ -2121,7 +2161,7 @@ static int sd_revalidate_disk(struct gendisk *disk)
2121 else 2161 else
2122 ordered = QUEUE_ORDERED_DRAIN; 2162 ordered = QUEUE_ORDERED_DRAIN;
2123 2163
2124 blk_queue_ordered(sdkp->disk->queue, ordered, sd_prepare_flush); 2164 blk_queue_ordered(sdkp->disk->queue, ordered);
2125 2165
2126 set_capacity(disk, sdkp->capacity); 2166 set_capacity(disk, sdkp->capacity);
2127 kfree(buffer); 2167 kfree(buffer);
@@ -2234,6 +2274,7 @@ static void sd_probe_async(void *data, async_cookie_t cookie)
2234 sd_revalidate_disk(gd); 2274 sd_revalidate_disk(gd);
2235 2275
2236 blk_queue_prep_rq(sdp->request_queue, sd_prep_fn); 2276 blk_queue_prep_rq(sdp->request_queue, sd_prep_fn);
2277 blk_queue_unprep_rq(sdp->request_queue, sd_unprep_fn);
2237 2278
2238 gd->driverfs_dev = &sdp->sdev_gendev; 2279 gd->driverfs_dev = &sdp->sdev_gendev;
2239 gd->flags = GENHD_FL_EXT_DEVT; 2280 gd->flags = GENHD_FL_EXT_DEVT;
@@ -2274,7 +2315,7 @@ static int sd_probe(struct device *dev)
2274 struct scsi_device *sdp = to_scsi_device(dev); 2315 struct scsi_device *sdp = to_scsi_device(dev);
2275 struct scsi_disk *sdkp; 2316 struct scsi_disk *sdkp;
2276 struct gendisk *gd; 2317 struct gendisk *gd;
2277 u32 index; 2318 int index;
2278 int error; 2319 int error;
2279 2320
2280 error = -ENODEV; 2321 error = -ENODEV;
@@ -2313,7 +2354,7 @@ static int sd_probe(struct device *dev)
2313 sdkp->driver = &sd_template; 2354 sdkp->driver = &sd_template;
2314 sdkp->disk = gd; 2355 sdkp->disk = gd;
2315 sdkp->index = index; 2356 sdkp->index = index;
2316 sdkp->openers = 0; 2357 atomic_set(&sdkp->openers, 0);
2317 sdkp->previous_state = 1; 2358 sdkp->previous_state = 1;
2318 2359
2319 if (!sdp->request_queue->rq_timeout) { 2360 if (!sdp->request_queue->rq_timeout) {
@@ -2372,6 +2413,7 @@ static int sd_remove(struct device *dev)
2372 2413
2373 async_synchronize_full(); 2414 async_synchronize_full();
2374 blk_queue_prep_rq(sdkp->device->request_queue, scsi_prep_fn); 2415 blk_queue_prep_rq(sdkp->device->request_queue, scsi_prep_fn);
2416 blk_queue_unprep_rq(sdkp->device->request_queue, NULL);
2375 device_del(&sdkp->dev); 2417 device_del(&sdkp->dev);
2376 del_gendisk(sdkp->disk); 2418 del_gendisk(sdkp->disk);
2377 sd_shutdown(dev); 2419 sd_shutdown(dev);
diff --git a/drivers/scsi/sd.h b/drivers/scsi/sd.h
index 43d3caf268ef..f81a9309e6de 100644
--- a/drivers/scsi/sd.h
+++ b/drivers/scsi/sd.h
@@ -47,7 +47,7 @@ struct scsi_disk {
47 struct scsi_device *device; 47 struct scsi_device *device;
48 struct device dev; 48 struct device dev;
49 struct gendisk *disk; 49 struct gendisk *disk;
50 unsigned int openers; /* protected by BKL for now, yuck */ 50 atomic_t openers;
51 sector_t capacity; /* size in 512-byte sectors */ 51 sector_t capacity; /* size in 512-byte sectors */
52 u32 index; 52 u32 index;
53 unsigned short hw_sector_size; 53 unsigned short hw_sector_size;
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 2968c6b83ddb..78d616315d8e 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -1686,14 +1686,9 @@ static int sg_start_req(Sg_request *srp, unsigned char *cmd)
1686 int len, size = sizeof(struct sg_iovec) * iov_count; 1686 int len, size = sizeof(struct sg_iovec) * iov_count;
1687 struct iovec *iov; 1687 struct iovec *iov;
1688 1688
1689 iov = kmalloc(size, GFP_ATOMIC); 1689 iov = memdup_user(hp->dxferp, size);
1690 if (!iov) 1690 if (IS_ERR(iov))
1691 return -ENOMEM; 1691 return PTR_ERR(iov);
1692
1693 if (copy_from_user(iov, hp->dxferp, size)) {
1694 kfree(iov);
1695 return -EFAULT;
1696 }
1697 1692
1698 len = iov_length(iov, iov_count); 1693 len = iov_length(iov, iov_count);
1699 if (hp->dxfer_len < len) { 1694 if (hp->dxfer_len < len) {
diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c
index 0a90abc7f140..ba9c3e0387ce 100644
--- a/drivers/scsi/sr.c
+++ b/drivers/scsi/sr.c
@@ -44,6 +44,7 @@
44#include <linux/init.h> 44#include <linux/init.h>
45#include <linux/blkdev.h> 45#include <linux/blkdev.h>
46#include <linux/mutex.h> 46#include <linux/mutex.h>
47#include <linux/smp_lock.h>
47#include <linux/slab.h> 48#include <linux/slab.h>
48#include <asm/uaccess.h> 49#include <asm/uaccess.h>
49 50
@@ -466,22 +467,27 @@ static int sr_prep_fn(struct request_queue *q, struct request *rq)
466 467
467static int sr_block_open(struct block_device *bdev, fmode_t mode) 468static int sr_block_open(struct block_device *bdev, fmode_t mode)
468{ 469{
469 struct scsi_cd *cd = scsi_cd_get(bdev->bd_disk); 470 struct scsi_cd *cd;
470 int ret = -ENXIO; 471 int ret = -ENXIO;
471 472
473 lock_kernel();
474 cd = scsi_cd_get(bdev->bd_disk);
472 if (cd) { 475 if (cd) {
473 ret = cdrom_open(&cd->cdi, bdev, mode); 476 ret = cdrom_open(&cd->cdi, bdev, mode);
474 if (ret) 477 if (ret)
475 scsi_cd_put(cd); 478 scsi_cd_put(cd);
476 } 479 }
480 unlock_kernel();
477 return ret; 481 return ret;
478} 482}
479 483
480static int sr_block_release(struct gendisk *disk, fmode_t mode) 484static int sr_block_release(struct gendisk *disk, fmode_t mode)
481{ 485{
482 struct scsi_cd *cd = scsi_cd(disk); 486 struct scsi_cd *cd = scsi_cd(disk);
487 lock_kernel();
483 cdrom_release(&cd->cdi, mode); 488 cdrom_release(&cd->cdi, mode);
484 scsi_cd_put(cd); 489 scsi_cd_put(cd);
490 unlock_kernel();
485 return 0; 491 return 0;
486} 492}
487 493
@@ -493,6 +499,8 @@ static int sr_block_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
493 void __user *argp = (void __user *)arg; 499 void __user *argp = (void __user *)arg;
494 int ret; 500 int ret;
495 501
502 lock_kernel();
503
496 /* 504 /*
497 * Send SCSI addressing ioctls directly to mid level, send other 505 * Send SCSI addressing ioctls directly to mid level, send other
498 * ioctls to cdrom/block level. 506 * ioctls to cdrom/block level.
@@ -500,12 +508,13 @@ static int sr_block_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
500 switch (cmd) { 508 switch (cmd) {
501 case SCSI_IOCTL_GET_IDLUN: 509 case SCSI_IOCTL_GET_IDLUN:
502 case SCSI_IOCTL_GET_BUS_NUMBER: 510 case SCSI_IOCTL_GET_BUS_NUMBER:
503 return scsi_ioctl(sdev, cmd, argp); 511 ret = scsi_ioctl(sdev, cmd, argp);
512 goto out;
504 } 513 }
505 514
506 ret = cdrom_ioctl(&cd->cdi, bdev, mode, cmd, arg); 515 ret = cdrom_ioctl(&cd->cdi, bdev, mode, cmd, arg);
507 if (ret != -ENOSYS) 516 if (ret != -ENOSYS)
508 return ret; 517 goto out;
509 518
510 /* 519 /*
511 * ENODEV means that we didn't recognise the ioctl, or that we 520 * ENODEV means that we didn't recognise the ioctl, or that we
@@ -516,8 +525,12 @@ static int sr_block_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
516 ret = scsi_nonblockable_ioctl(sdev, cmd, argp, 525 ret = scsi_nonblockable_ioctl(sdev, cmd, argp,
517 (mode & FMODE_NDELAY) != 0); 526 (mode & FMODE_NDELAY) != 0);
518 if (ret != -ENODEV) 527 if (ret != -ENODEV)
519 return ret; 528 goto out;
520 return scsi_ioctl(sdev, cmd, argp); 529 ret = scsi_ioctl(sdev, cmd, argp);
530
531out:
532 unlock_kernel();
533 return ret;
521} 534}
522 535
523static int sr_block_media_changed(struct gendisk *disk) 536static int sr_block_media_changed(struct gendisk *disk)
@@ -531,7 +544,7 @@ static const struct block_device_operations sr_bdops =
531 .owner = THIS_MODULE, 544 .owner = THIS_MODULE,
532 .open = sr_block_open, 545 .open = sr_block_open,
533 .release = sr_block_release, 546 .release = sr_block_release,
534 .locked_ioctl = sr_block_ioctl, 547 .ioctl = sr_block_ioctl,
535 .media_changed = sr_block_media_changed, 548 .media_changed = sr_block_media_changed,
536 /* 549 /*
537 * No compat_ioctl for now because sr_block_ioctl never 550 * No compat_ioctl for now because sr_block_ioctl never
diff --git a/drivers/scsi/sun3_NCR5380.c b/drivers/scsi/sun3_NCR5380.c
index b5838d547c68..713620ed70d9 100644
--- a/drivers/scsi/sun3_NCR5380.c
+++ b/drivers/scsi/sun3_NCR5380.c
@@ -2022,7 +2022,7 @@ static void NCR5380_information_transfer (struct Scsi_Host *instance)
2022 if((count > SUN3_DMA_MINSIZE) && (sun3_dma_setup_done 2022 if((count > SUN3_DMA_MINSIZE) && (sun3_dma_setup_done
2023 != cmd)) 2023 != cmd))
2024 { 2024 {
2025 if(blk_fs_request(cmd->request)) { 2025 if (cmd->request->cmd_type == REQ_TYPE_FS) {
2026 sun3scsi_dma_setup(d, count, 2026 sun3scsi_dma_setup(d, count,
2027 rq_data_dir(cmd->request)); 2027 rq_data_dir(cmd->request));
2028 sun3_dma_setup_done = cmd; 2028 sun3_dma_setup_done = cmd;
diff --git a/drivers/scsi/sun3_scsi.c b/drivers/scsi/sun3_scsi.c
index e606cf0a2eb7..613f5880d135 100644
--- a/drivers/scsi/sun3_scsi.c
+++ b/drivers/scsi/sun3_scsi.c
@@ -524,7 +524,7 @@ static inline unsigned long sun3scsi_dma_xfer_len(unsigned long wanted,
524 struct scsi_cmnd *cmd, 524 struct scsi_cmnd *cmd,
525 int write_flag) 525 int write_flag)
526{ 526{
527 if(blk_fs_request(cmd->request)) 527 if (cmd->request->cmd_type == REQ_TYPE_FS)
528 return wanted; 528 return wanted;
529 else 529 else
530 return 0; 530 return 0;
diff --git a/drivers/scsi/sun3_scsi_vme.c b/drivers/scsi/sun3_scsi_vme.c
index aaa4fd0dd1b9..7c526b8e30ac 100644
--- a/drivers/scsi/sun3_scsi_vme.c
+++ b/drivers/scsi/sun3_scsi_vme.c
@@ -458,7 +458,7 @@ static inline unsigned long sun3scsi_dma_xfer_len(unsigned long wanted,
458 struct scsi_cmnd *cmd, 458 struct scsi_cmnd *cmd,
459 int write_flag) 459 int write_flag)
460{ 460{
461 if(blk_fs_request(cmd->request)) 461 if (cmd->request->cmd_type == REQ_TYPE_FS)
462 return wanted; 462 return wanted;
463 else 463 else
464 return 0; 464 return 0;
diff --git a/drivers/scsi/sun_esp.c b/drivers/scsi/sun_esp.c
index 89ba6fe02f80..193b37ba1834 100644
--- a/drivers/scsi/sun_esp.c
+++ b/drivers/scsi/sun_esp.c
@@ -44,7 +44,7 @@ enum dvma_rev {
44}; 44};
45 45
46static int __devinit esp_sbus_setup_dma(struct esp *esp, 46static int __devinit esp_sbus_setup_dma(struct esp *esp,
47 struct of_device *dma_of) 47 struct platform_device *dma_of)
48{ 48{
49 esp->dma = dma_of; 49 esp->dma = dma_of;
50 50
@@ -81,7 +81,7 @@ static int __devinit esp_sbus_setup_dma(struct esp *esp,
81 81
82static int __devinit esp_sbus_map_regs(struct esp *esp, int hme) 82static int __devinit esp_sbus_map_regs(struct esp *esp, int hme)
83{ 83{
84 struct of_device *op = esp->dev; 84 struct platform_device *op = esp->dev;
85 struct resource *res; 85 struct resource *res;
86 86
87 /* On HME, two reg sets exist, first is DVMA, 87 /* On HME, two reg sets exist, first is DVMA,
@@ -101,7 +101,7 @@ static int __devinit esp_sbus_map_regs(struct esp *esp, int hme)
101 101
102static int __devinit esp_sbus_map_command_block(struct esp *esp) 102static int __devinit esp_sbus_map_command_block(struct esp *esp)
103{ 103{
104 struct of_device *op = esp->dev; 104 struct platform_device *op = esp->dev;
105 105
106 esp->command_block = dma_alloc_coherent(&op->dev, 16, 106 esp->command_block = dma_alloc_coherent(&op->dev, 16,
107 &esp->command_block_dma, 107 &esp->command_block_dma,
@@ -114,15 +114,15 @@ static int __devinit esp_sbus_map_command_block(struct esp *esp)
114static int __devinit esp_sbus_register_irq(struct esp *esp) 114static int __devinit esp_sbus_register_irq(struct esp *esp)
115{ 115{
116 struct Scsi_Host *host = esp->host; 116 struct Scsi_Host *host = esp->host;
117 struct of_device *op = esp->dev; 117 struct platform_device *op = esp->dev;
118 118
119 host->irq = op->archdata.irqs[0]; 119 host->irq = op->archdata.irqs[0];
120 return request_irq(host->irq, scsi_esp_intr, IRQF_SHARED, "ESP", esp); 120 return request_irq(host->irq, scsi_esp_intr, IRQF_SHARED, "ESP", esp);
121} 121}
122 122
123static void __devinit esp_get_scsi_id(struct esp *esp, struct of_device *espdma) 123static void __devinit esp_get_scsi_id(struct esp *esp, struct platform_device *espdma)
124{ 124{
125 struct of_device *op = esp->dev; 125 struct platform_device *op = esp->dev;
126 struct device_node *dp; 126 struct device_node *dp;
127 127
128 dp = op->dev.of_node; 128 dp = op->dev.of_node;
@@ -144,7 +144,7 @@ done:
144 144
145static void __devinit esp_get_differential(struct esp *esp) 145static void __devinit esp_get_differential(struct esp *esp)
146{ 146{
147 struct of_device *op = esp->dev; 147 struct platform_device *op = esp->dev;
148 struct device_node *dp; 148 struct device_node *dp;
149 149
150 dp = op->dev.of_node; 150 dp = op->dev.of_node;
@@ -156,7 +156,7 @@ static void __devinit esp_get_differential(struct esp *esp)
156 156
157static void __devinit esp_get_clock_params(struct esp *esp) 157static void __devinit esp_get_clock_params(struct esp *esp)
158{ 158{
159 struct of_device *op = esp->dev; 159 struct platform_device *op = esp->dev;
160 struct device_node *bus_dp, *dp; 160 struct device_node *bus_dp, *dp;
161 int fmhz; 161 int fmhz;
162 162
@@ -170,10 +170,10 @@ static void __devinit esp_get_clock_params(struct esp *esp)
170 esp->cfreq = fmhz; 170 esp->cfreq = fmhz;
171} 171}
172 172
173static void __devinit esp_get_bursts(struct esp *esp, struct of_device *dma_of) 173static void __devinit esp_get_bursts(struct esp *esp, struct platform_device *dma_of)
174{ 174{
175 struct device_node *dma_dp = dma_of->dev.of_node; 175 struct device_node *dma_dp = dma_of->dev.of_node;
176 struct of_device *op = esp->dev; 176 struct platform_device *op = esp->dev;
177 struct device_node *dp; 177 struct device_node *dp;
178 u8 bursts, val; 178 u8 bursts, val;
179 179
@@ -195,7 +195,7 @@ static void __devinit esp_get_bursts(struct esp *esp, struct of_device *dma_of)
195 esp->bursts = bursts; 195 esp->bursts = bursts;
196} 196}
197 197
198static void __devinit esp_sbus_get_props(struct esp *esp, struct of_device *espdma) 198static void __devinit esp_sbus_get_props(struct esp *esp, struct platform_device *espdma)
199{ 199{
200 esp_get_scsi_id(esp, espdma); 200 esp_get_scsi_id(esp, espdma);
201 esp_get_differential(esp); 201 esp_get_differential(esp);
@@ -216,7 +216,7 @@ static u8 sbus_esp_read8(struct esp *esp, unsigned long reg)
216static dma_addr_t sbus_esp_map_single(struct esp *esp, void *buf, 216static dma_addr_t sbus_esp_map_single(struct esp *esp, void *buf,
217 size_t sz, int dir) 217 size_t sz, int dir)
218{ 218{
219 struct of_device *op = esp->dev; 219 struct platform_device *op = esp->dev;
220 220
221 return dma_map_single(&op->dev, buf, sz, dir); 221 return dma_map_single(&op->dev, buf, sz, dir);
222} 222}
@@ -224,7 +224,7 @@ static dma_addr_t sbus_esp_map_single(struct esp *esp, void *buf,
224static int sbus_esp_map_sg(struct esp *esp, struct scatterlist *sg, 224static int sbus_esp_map_sg(struct esp *esp, struct scatterlist *sg,
225 int num_sg, int dir) 225 int num_sg, int dir)
226{ 226{
227 struct of_device *op = esp->dev; 227 struct platform_device *op = esp->dev;
228 228
229 return dma_map_sg(&op->dev, sg, num_sg, dir); 229 return dma_map_sg(&op->dev, sg, num_sg, dir);
230} 230}
@@ -232,7 +232,7 @@ static int sbus_esp_map_sg(struct esp *esp, struct scatterlist *sg,
232static void sbus_esp_unmap_single(struct esp *esp, dma_addr_t addr, 232static void sbus_esp_unmap_single(struct esp *esp, dma_addr_t addr,
233 size_t sz, int dir) 233 size_t sz, int dir)
234{ 234{
235 struct of_device *op = esp->dev; 235 struct platform_device *op = esp->dev;
236 236
237 dma_unmap_single(&op->dev, addr, sz, dir); 237 dma_unmap_single(&op->dev, addr, sz, dir);
238} 238}
@@ -240,7 +240,7 @@ static void sbus_esp_unmap_single(struct esp *esp, dma_addr_t addr,
240static void sbus_esp_unmap_sg(struct esp *esp, struct scatterlist *sg, 240static void sbus_esp_unmap_sg(struct esp *esp, struct scatterlist *sg,
241 int num_sg, int dir) 241 int num_sg, int dir)
242{ 242{
243 struct of_device *op = esp->dev; 243 struct platform_device *op = esp->dev;
244 244
245 dma_unmap_sg(&op->dev, sg, num_sg, dir); 245 dma_unmap_sg(&op->dev, sg, num_sg, dir);
246} 246}
@@ -256,7 +256,7 @@ static void sbus_esp_reset_dma(struct esp *esp)
256{ 256{
257 int can_do_burst16, can_do_burst32, can_do_burst64; 257 int can_do_burst16, can_do_burst32, can_do_burst64;
258 int can_do_sbus64, lim; 258 int can_do_sbus64, lim;
259 struct of_device *op; 259 struct platform_device *op;
260 u32 val; 260 u32 val;
261 261
262 can_do_burst16 = (esp->bursts & DMA_BURST16) != 0; 262 can_do_burst16 = (esp->bursts & DMA_BURST16) != 0;
@@ -487,8 +487,8 @@ static const struct esp_driver_ops sbus_esp_ops = {
487 .dma_error = sbus_esp_dma_error, 487 .dma_error = sbus_esp_dma_error,
488}; 488};
489 489
490static int __devinit esp_sbus_probe_one(struct of_device *op, 490static int __devinit esp_sbus_probe_one(struct platform_device *op,
491 struct of_device *espdma, 491 struct platform_device *espdma,
492 int hme) 492 int hme)
493{ 493{
494 struct scsi_host_template *tpnt = &scsi_esp_template; 494 struct scsi_host_template *tpnt = &scsi_esp_template;
@@ -562,11 +562,11 @@ fail:
562 return err; 562 return err;
563} 563}
564 564
565static int __devinit esp_sbus_probe(struct of_device *op, const struct of_device_id *match) 565static int __devinit esp_sbus_probe(struct platform_device *op, const struct of_device_id *match)
566{ 566{
567 struct device_node *dma_node = NULL; 567 struct device_node *dma_node = NULL;
568 struct device_node *dp = op->dev.of_node; 568 struct device_node *dp = op->dev.of_node;
569 struct of_device *dma_of = NULL; 569 struct platform_device *dma_of = NULL;
570 int hme = 0; 570 int hme = 0;
571 571
572 if (dp->parent && 572 if (dp->parent &&
@@ -585,10 +585,10 @@ static int __devinit esp_sbus_probe(struct of_device *op, const struct of_device
585 return esp_sbus_probe_one(op, dma_of, hme); 585 return esp_sbus_probe_one(op, dma_of, hme);
586} 586}
587 587
588static int __devexit esp_sbus_remove(struct of_device *op) 588static int __devexit esp_sbus_remove(struct platform_device *op)
589{ 589{
590 struct esp *esp = dev_get_drvdata(&op->dev); 590 struct esp *esp = dev_get_drvdata(&op->dev);
591 struct of_device *dma_of = esp->dma; 591 struct platform_device *dma_of = esp->dma;
592 unsigned int irq = esp->host->irq; 592 unsigned int irq = esp->host->irq;
593 bool is_hme; 593 bool is_hme;
594 u32 val; 594 u32 val;
diff --git a/drivers/serial/21285.c b/drivers/serial/21285.c
index 8681f1345056..d89aa38c5cf0 100644
--- a/drivers/serial/21285.c
+++ b/drivers/serial/21285.c
@@ -216,7 +216,7 @@ serial21285_set_termios(struct uart_port *port, struct ktermios *termios,
216 struct ktermios *old) 216 struct ktermios *old)
217{ 217{
218 unsigned long flags; 218 unsigned long flags;
219 unsigned int baud, quot, h_lcr; 219 unsigned int baud, quot, h_lcr, b;
220 220
221 /* 221 /*
222 * We don't support modem control lines. 222 * We don't support modem control lines.
@@ -234,12 +234,8 @@ serial21285_set_termios(struct uart_port *port, struct ktermios *termios,
234 */ 234 */
235 baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16); 235 baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16);
236 quot = uart_get_divisor(port, baud); 236 quot = uart_get_divisor(port, baud);
237 237 b = port->uartclk / (16 * quot);
238 if (port->state && port->state->port.tty) { 238 tty_termios_encode_baud_rate(termios, b, b);
239 struct tty_struct *tty = port->state->port.tty;
240 unsigned int b = port->uartclk / (16 * quot);
241 tty_encode_baud_rate(tty, b, b);
242 }
243 239
244 switch (termios->c_cflag & CSIZE) { 240 switch (termios->c_cflag & CSIZE) {
245 case CS5: 241 case CS5:
diff --git a/drivers/serial/68328serial.c b/drivers/serial/68328serial.c
index 30463862603b..7356a56ac458 100644
--- a/drivers/serial/68328serial.c
+++ b/drivers/serial/68328serial.c
@@ -78,10 +78,6 @@ struct m68k_serial *m68k_consinfo = 0;
78 78
79#define M68K_CLOCK (16667000) /* FIXME: 16MHz is likely wrong */ 79#define M68K_CLOCK (16667000) /* FIXME: 16MHz is likely wrong */
80 80
81#ifdef CONFIG_CONSOLE
82extern wait_queue_head_t keypress_wait;
83#endif
84
85struct tty_driver *serial_driver; 81struct tty_driver *serial_driver;
86 82
87/* number of characters left in xmit buffer before we ask for more */ 83/* number of characters left in xmit buffer before we ask for more */
@@ -102,19 +98,13 @@ static void change_speed(struct m68k_serial *info);
102 * Setup for console. Argument comes from the boot command line. 98 * Setup for console. Argument comes from the boot command line.
103 */ 99 */
104 100
105#if defined(CONFIG_M68EZ328ADS) || defined(CONFIG_ALMA_ANS) || defined(CONFIG_DRAGONIXVZ) 101/* note: this is messy, but it works, again, perhaps defined somewhere else?*/
106#define CONSOLE_BAUD_RATE 115200 102#ifdef CONFIG_M68VZ328
107#define DEFAULT_CBAUD B115200 103#define CONSOLE_BAUD_RATE 19200
108#else 104#define DEFAULT_CBAUD B19200
109 /* (es) */
110 /* note: this is messy, but it works, again, perhaps defined somewhere else?*/
111 #ifdef CONFIG_M68VZ328
112 #define CONSOLE_BAUD_RATE 19200
113 #define DEFAULT_CBAUD B19200
114 #endif
115 /* (/es) */
116#endif 105#endif
117 106
107
118#ifndef CONSOLE_BAUD_RATE 108#ifndef CONSOLE_BAUD_RATE
119#define CONSOLE_BAUD_RATE 9600 109#define CONSOLE_BAUD_RATE 9600
120#define DEFAULT_CBAUD B9600 110#define DEFAULT_CBAUD B9600
@@ -300,10 +290,6 @@ static void receive_chars(struct m68k_serial *info, unsigned short rx)
300 return; 290 return;
301#endif /* CONFIG_MAGIC_SYSRQ */ 291#endif /* CONFIG_MAGIC_SYSRQ */
302 } 292 }
303 /* It is a 'keyboard interrupt' ;-) */
304#ifdef CONFIG_CONSOLE
305 wake_up(&keypress_wait);
306#endif
307 } 293 }
308 294
309 if(!tty) 295 if(!tty)
@@ -1243,7 +1229,9 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
1243 retval = -ERESTARTSYS; 1229 retval = -ERESTARTSYS;
1244 break; 1230 break;
1245 } 1231 }
1232 tty_unlock();
1246 schedule(); 1233 schedule();
1234 tty_lock();
1247 } 1235 }
1248 current->state = TASK_RUNNING; 1236 current->state = TASK_RUNNING;
1249 remove_wait_queue(&info->open_wait, &wait); 1237 remove_wait_queue(&info->open_wait, &wait);
diff --git a/drivers/serial/68360serial.c b/drivers/serial/68360serial.c
index 768612f8e41e..0dff3bbddc8b 100644
--- a/drivers/serial/68360serial.c
+++ b/drivers/serial/68360serial.c
@@ -1705,7 +1705,6 @@ static void rs_360_wait_until_sent(struct tty_struct *tty, int timeout)
1705 printk("jiff=%lu...", jiffies); 1705 printk("jiff=%lu...", jiffies);
1706#endif 1706#endif
1707 1707
1708 lock_kernel();
1709 /* We go through the loop at least once because we can't tell 1708 /* We go through the loop at least once because we can't tell
1710 * exactly when the last character exits the shifter. There can 1709 * exactly when the last character exits the shifter. There can
1711 * be at least two characters waiting to be sent after the buffers 1710 * be at least two characters waiting to be sent after the buffers
@@ -1734,7 +1733,6 @@ static void rs_360_wait_until_sent(struct tty_struct *tty, int timeout)
1734 bdp--; 1733 bdp--;
1735 } while (bdp->status & BD_SC_READY); 1734 } while (bdp->status & BD_SC_READY);
1736 current->state = TASK_RUNNING; 1735 current->state = TASK_RUNNING;
1737 unlock_kernel();
1738#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT 1736#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1739 printk("lsr = %d (jiff=%lu)...done\n", lsr, jiffies); 1737 printk("lsr = %d (jiff=%lu)...done\n", lsr, jiffies);
1740#endif 1738#endif
@@ -1862,7 +1860,9 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
1862 printk("block_til_ready blocking: ttys%d, count = %d\n", 1860 printk("block_til_ready blocking: ttys%d, count = %d\n",
1863 info->line, state->count); 1861 info->line, state->count);
1864#endif 1862#endif
1863 tty_unlock();
1865 schedule(); 1864 schedule();
1865 tty_lock();
1866 } 1866 }
1867 current->state = TASK_RUNNING; 1867 current->state = TASK_RUNNING;
1868 remove_wait_queue(&info->open_wait, &wait); 1868 remove_wait_queue(&info->open_wait, &wait);
diff --git a/drivers/serial/8250.c b/drivers/serial/8250.c
index 09ef57034c9c..24110f6f61e0 100644
--- a/drivers/serial/8250.c
+++ b/drivers/serial/8250.c
@@ -241,7 +241,7 @@ static const struct serial8250_config uart_config[] = {
241 .fifo_size = 128, 241 .fifo_size = 128,
242 .tx_loadsz = 128, 242 .tx_loadsz = 128,
243 .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, 243 .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
244 .flags = UART_CAP_FIFO, 244 .flags = UART_CAP_FIFO | UART_CAP_EFR | UART_CAP_SLEEP,
245 }, 245 },
246 [PORT_16654] = { 246 [PORT_16654] = {
247 .name = "ST16654", 247 .name = "ST16654",
@@ -300,6 +300,13 @@ static const struct serial8250_config uart_config[] = {
300 .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_00, 300 .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_00,
301 .flags = UART_CAP_FIFO | UART_CAP_AFE, 301 .flags = UART_CAP_FIFO | UART_CAP_AFE,
302 }, 302 },
303 [PORT_U6_16550A] = {
304 .name = "U6_16550A",
305 .fifo_size = 64,
306 .tx_loadsz = 64,
307 .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
308 .flags = UART_CAP_FIFO | UART_CAP_AFE,
309 },
303}; 310};
304 311
305#if defined(CONFIG_MIPS_ALCHEMY) 312#if defined(CONFIG_MIPS_ALCHEMY)
@@ -1070,6 +1077,15 @@ static void autoconfig_16550a(struct uart_8250_port *up)
1070 DEBUG_AUTOCONF("Couldn't force IER_UUE to 0 "); 1077 DEBUG_AUTOCONF("Couldn't force IER_UUE to 0 ");
1071 } 1078 }
1072 serial_outp(up, UART_IER, iersave); 1079 serial_outp(up, UART_IER, iersave);
1080
1081 /*
1082 * We distinguish between 16550A and U6 16550A by counting
1083 * how many bytes are in the FIFO.
1084 */
1085 if (up->port.type == PORT_16550A && size_fifo(up) == 64) {
1086 up->port.type = PORT_U6_16550A;
1087 up->capabilities |= UART_CAP_AFE;
1088 }
1073} 1089}
1074 1090
1075/* 1091/*
@@ -2224,9 +2240,9 @@ static unsigned int serial8250_get_divisor(struct uart_port *port, unsigned int
2224 return quot; 2240 return quot;
2225} 2241}
2226 2242
2227static void 2243void
2228serial8250_set_termios(struct uart_port *port, struct ktermios *termios, 2244serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
2229 struct ktermios *old) 2245 struct ktermios *old)
2230{ 2246{
2231 struct uart_8250_port *up = (struct uart_8250_port *)port; 2247 struct uart_8250_port *up = (struct uart_8250_port *)port;
2232 unsigned char cval, fcr = 0; 2248 unsigned char cval, fcr = 0;
@@ -2402,16 +2418,22 @@ serial8250_set_termios(struct uart_port *port, struct ktermios *termios,
2402 if (tty_termios_baud_rate(termios)) 2418 if (tty_termios_baud_rate(termios))
2403 tty_termios_encode_baud_rate(termios, baud, baud); 2419 tty_termios_encode_baud_rate(termios, baud, baud);
2404} 2420}
2421EXPORT_SYMBOL(serial8250_do_set_termios);
2405 2422
2406static void 2423static void
2407serial8250_set_ldisc(struct uart_port *port) 2424serial8250_set_termios(struct uart_port *port, struct ktermios *termios,
2425 struct ktermios *old)
2408{ 2426{
2409 int line = port->line; 2427 if (port->set_termios)
2410 2428 port->set_termios(port, termios, old);
2411 if (line >= port->state->port.tty->driver->num) 2429 else
2412 return; 2430 serial8250_do_set_termios(port, termios, old);
2431}
2413 2432
2414 if (port->state->port.tty->ldisc->ops->num == N_PPS) { 2433static void
2434serial8250_set_ldisc(struct uart_port *port, int new)
2435{
2436 if (new == N_PPS) {
2415 port->flags |= UPF_HARDPPS_CD; 2437 port->flags |= UPF_HARDPPS_CD;
2416 serial8250_enable_ms(port); 2438 serial8250_enable_ms(port);
2417 } else 2439 } else
@@ -2987,6 +3009,7 @@ static int __devinit serial8250_probe(struct platform_device *dev)
2987 port.type = p->type; 3009 port.type = p->type;
2988 port.serial_in = p->serial_in; 3010 port.serial_in = p->serial_in;
2989 port.serial_out = p->serial_out; 3011 port.serial_out = p->serial_out;
3012 port.set_termios = p->set_termios;
2990 port.dev = &dev->dev; 3013 port.dev = &dev->dev;
2991 port.irqflags |= irqflag; 3014 port.irqflags |= irqflag;
2992 ret = serial8250_register_port(&port); 3015 ret = serial8250_register_port(&port);
@@ -3150,6 +3173,9 @@ int serial8250_register_port(struct uart_port *port)
3150 uart->port.serial_in = port->serial_in; 3173 uart->port.serial_in = port->serial_in;
3151 if (port->serial_out) 3174 if (port->serial_out)
3152 uart->port.serial_out = port->serial_out; 3175 uart->port.serial_out = port->serial_out;
3176 /* Possibly override set_termios call */
3177 if (port->set_termios)
3178 uart->port.set_termios = port->set_termios;
3153 3179
3154 ret = uart_add_one_port(&serial8250_reg, &uart->port); 3180 ret = uart_add_one_port(&serial8250_reg, &uart->port);
3155 if (ret == 0) 3181 if (ret == 0)
diff --git a/drivers/serial/8250_early.c b/drivers/serial/8250_early.c
index f279745e9fef..b745792ec25a 100644
--- a/drivers/serial/8250_early.c
+++ b/drivers/serial/8250_early.c
@@ -19,9 +19,11 @@
19 * The user can specify the device directly, e.g., 19 * The user can specify the device directly, e.g.,
20 * earlycon=uart8250,io,0x3f8,9600n8 20 * earlycon=uart8250,io,0x3f8,9600n8
21 * earlycon=uart8250,mmio,0xff5e0000,115200n8 21 * earlycon=uart8250,mmio,0xff5e0000,115200n8
22 * earlycon=uart8250,mmio32,0xff5e0000,115200n8
22 * or 23 * or
23 * console=uart8250,io,0x3f8,9600n8 24 * console=uart8250,io,0x3f8,9600n8
24 * console=uart8250,mmio,0xff5e0000,115200n8 25 * console=uart8250,mmio,0xff5e0000,115200n8
26 * console=uart8250,mmio32,0xff5e0000,115200n8
25 */ 27 */
26 28
27#include <linux/tty.h> 29#include <linux/tty.h>
@@ -48,18 +50,31 @@ static struct early_serial8250_device early_device;
48 50
49static unsigned int __init serial_in(struct uart_port *port, int offset) 51static unsigned int __init serial_in(struct uart_port *port, int offset)
50{ 52{
51 if (port->iotype == UPIO_MEM) 53 switch (port->iotype) {
54 case UPIO_MEM:
52 return readb(port->membase + offset); 55 return readb(port->membase + offset);
53 else 56 case UPIO_MEM32:
57 return readl(port->membase + (offset << 2));
58 case UPIO_PORT:
54 return inb(port->iobase + offset); 59 return inb(port->iobase + offset);
60 default:
61 return 0;
62 }
55} 63}
56 64
57static void __init serial_out(struct uart_port *port, int offset, int value) 65static void __init serial_out(struct uart_port *port, int offset, int value)
58{ 66{
59 if (port->iotype == UPIO_MEM) 67 switch (port->iotype) {
68 case UPIO_MEM:
60 writeb(value, port->membase + offset); 69 writeb(value, port->membase + offset);
61 else 70 break;
71 case UPIO_MEM32:
72 writel(value, port->membase + (offset << 2));
73 break;
74 case UPIO_PORT:
62 outb(value, port->iobase + offset); 75 outb(value, port->iobase + offset);
76 break;
77 }
63} 78}
64 79
65#define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE) 80#define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
@@ -137,15 +152,21 @@ static int __init parse_options(struct early_serial8250_device *device,
137 char *options) 152 char *options)
138{ 153{
139 struct uart_port *port = &device->port; 154 struct uart_port *port = &device->port;
140 int mmio, length; 155 int mmio, mmio32, length;
141 156
142 if (!options) 157 if (!options)
143 return -ENODEV; 158 return -ENODEV;
144 159
145 port->uartclk = BASE_BAUD * 16; 160 port->uartclk = BASE_BAUD * 16;
146 if (!strncmp(options, "mmio,", 5)) { 161
147 port->iotype = UPIO_MEM; 162 mmio = !strncmp(options, "mmio,", 5);
148 port->mapbase = simple_strtoul(options + 5, &options, 0); 163 mmio32 = !strncmp(options, "mmio32,", 7);
164 if (mmio || mmio32) {
165 port->iotype = (mmio ? UPIO_MEM : UPIO_MEM32);
166 port->mapbase = simple_strtoul(options + (mmio ? 5 : 7),
167 &options, 0);
168 if (mmio32)
169 port->regshift = 2;
149#ifdef CONFIG_FIX_EARLYCON_MEM 170#ifdef CONFIG_FIX_EARLYCON_MEM
150 set_fixmap_nocache(FIX_EARLYCON_MEM_BASE, 171 set_fixmap_nocache(FIX_EARLYCON_MEM_BASE,
151 port->mapbase & PAGE_MASK); 172 port->mapbase & PAGE_MASK);
@@ -157,11 +178,10 @@ static int __init parse_options(struct early_serial8250_device *device,
157 if (!port->membase) { 178 if (!port->membase) {
158 printk(KERN_ERR "%s: Couldn't ioremap 0x%llx\n", 179 printk(KERN_ERR "%s: Couldn't ioremap 0x%llx\n",
159 __func__, 180 __func__,
160 (unsigned long long)port->mapbase); 181 (unsigned long long) port->mapbase);
161 return -ENOMEM; 182 return -ENOMEM;
162 } 183 }
163#endif 184#endif
164 mmio = 1;
165 } else if (!strncmp(options, "io,", 3)) { 185 } else if (!strncmp(options, "io,", 3)) {
166 port->iotype = UPIO_PORT; 186 port->iotype = UPIO_PORT;
167 port->iobase = simple_strtoul(options + 3, &options, 0); 187 port->iobase = simple_strtoul(options + 3, &options, 0);
@@ -181,11 +201,18 @@ static int __init parse_options(struct early_serial8250_device *device,
181 device->baud); 201 device->baud);
182 } 202 }
183 203
184 printk(KERN_INFO "Early serial console at %s 0x%llx (options '%s')\n", 204 if (mmio || mmio32)
185 mmio ? "MMIO" : "I/O port", 205 printk(KERN_INFO
186 mmio ? (unsigned long long) port->mapbase 206 "Early serial console at MMIO%s 0x%llu (options '%s')\n",
187 : (unsigned long long) port->iobase, 207 mmio32 ? "32" : "",
188 device->options); 208 (unsigned long long)port->mapbase,
209 device->options);
210 else
211 printk(KERN_INFO
212 "Early serial console at I/O port 0x%lu (options '%s')\n",
213 port->iobase,
214 device->options);
215
189 return 0; 216 return 0;
190} 217}
191 218
diff --git a/drivers/serial/8250_pci.c b/drivers/serial/8250_pci.c
index 746a44621d91..53be4d35a0aa 100644
--- a/drivers/serial/8250_pci.c
+++ b/drivers/serial/8250_pci.c
@@ -994,6 +994,7 @@ static int skip_tx_en_setup(struct serial_private *priv,
994#define PCI_DEVICE_ID_TITAN_800E 0xA014 994#define PCI_DEVICE_ID_TITAN_800E 0xA014
995#define PCI_DEVICE_ID_TITAN_200EI 0xA016 995#define PCI_DEVICE_ID_TITAN_200EI 0xA016
996#define PCI_DEVICE_ID_TITAN_200EISI 0xA017 996#define PCI_DEVICE_ID_TITAN_200EISI 0xA017
997#define PCI_DEVICE_ID_OXSEMI_16PCI958 0x9538
997 998
998/* Unknown vendors/cards - this should not be in linux/pci_ids.h */ 999/* Unknown vendors/cards - this should not be in linux/pci_ids.h */
999#define PCI_SUBDEVICE_ID_UNKNOWN_0x1584 0x1584 1000#define PCI_SUBDEVICE_ID_UNKNOWN_0x1584 0x1584
@@ -1542,6 +1543,8 @@ enum pci_board_num_t {
1542 pbn_b2_4_921600, 1543 pbn_b2_4_921600,
1543 pbn_b2_8_921600, 1544 pbn_b2_8_921600,
1544 1545
1546 pbn_b2_8_1152000,
1547
1545 pbn_b2_bt_1_115200, 1548 pbn_b2_bt_1_115200,
1546 pbn_b2_bt_2_115200, 1549 pbn_b2_bt_2_115200,
1547 pbn_b2_bt_4_115200, 1550 pbn_b2_bt_4_115200,
@@ -1960,6 +1963,13 @@ static struct pciserial_board pci_boards[] __devinitdata = {
1960 .uart_offset = 8, 1963 .uart_offset = 8,
1961 }, 1964 },
1962 1965
1966 [pbn_b2_8_1152000] = {
1967 .flags = FL_BASE2,
1968 .num_ports = 8,
1969 .base_baud = 1152000,
1970 .uart_offset = 8,
1971 },
1972
1963 [pbn_b2_bt_1_115200] = { 1973 [pbn_b2_bt_1_115200] = {
1964 .flags = FL_BASE2|FL_BASE_BARS, 1974 .flags = FL_BASE2|FL_BASE_BARS,
1965 .num_ports = 1, 1975 .num_ports = 1,
@@ -2875,6 +2885,9 @@ static struct pci_device_id serial_pci_tbl[] = {
2875 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI952, 2885 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI952,
2876 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2886 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
2877 pbn_b0_bt_2_921600 }, 2887 pbn_b0_bt_2_921600 },
2888 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI958,
2889 PCI_ANY_ID , PCI_ANY_ID, 0, 0,
2890 pbn_b2_8_1152000 },
2878 2891
2879 /* 2892 /*
2880 * Oxford Semiconductor Inc. Tornado PCI express device range. 2893 * Oxford Semiconductor Inc. Tornado PCI express device range.
diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index e437ce8c1748..12900f7083b0 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -536,12 +536,13 @@ config SERIAL_S3C6400
536 536
537config SERIAL_S5PV210 537config SERIAL_S5PV210
538 tristate "Samsung S5PV210 Serial port support" 538 tristate "Samsung S5PV210 Serial port support"
539 depends on SERIAL_SAMSUNG && (CPU_S5PV210 || CPU_S5P6442) 539 depends on SERIAL_SAMSUNG && (CPU_S5PV210 || CPU_S5P6442 || CPU_S5PV310)
540 select SERIAL_SAMSUNG_UARTS_4 if CPU_S5PV210 540 select SERIAL_SAMSUNG_UARTS_4 if (CPU_S5PV210 || CPU_S5PV310)
541 default y 541 default y
542 help 542 help
543 Serial port support for Samsung's S5P Family of SoC's 543 Serial port support for Samsung's S5P Family of SoC's
544 544
545
545config SERIAL_MAX3100 546config SERIAL_MAX3100
546 tristate "MAX3100 support" 547 tristate "MAX3100 support"
547 depends on SPI 548 depends on SPI
@@ -549,6 +550,22 @@ config SERIAL_MAX3100
549 help 550 help
550 MAX3100 chip support 551 MAX3100 chip support
551 552
553config SERIAL_MAX3107
554 tristate "MAX3107 support"
555 depends on SPI
556 select SERIAL_CORE
557 help
558 MAX3107 chip support
559
560config SERIAL_MAX3107_AAVA
561 tristate "MAX3107 AAVA platform support"
562 depends on X86_MRST && SERIAL_MAX3107 && GPIOLIB
563 select SERIAL_CORE
564 help
565 Support for the MAX3107 chip configuration found on the AAVA
566 platform. Includes the extra initialisation and GPIO support
567 neded for this device.
568
552config SERIAL_DZ 569config SERIAL_DZ
553 bool "DECstation DZ serial driver" 570 bool "DECstation DZ serial driver"
554 depends on MACH_DECSTATION && 32BIT 571 depends on MACH_DECSTATION && 32BIT
@@ -690,6 +707,33 @@ config SERIAL_SA1100_CONSOLE
690 your boot loader (lilo or loadlin) about how to pass options to the 707 your boot loader (lilo or loadlin) about how to pass options to the
691 kernel at boot time.) 708 kernel at boot time.)
692 709
710config SERIAL_MRST_MAX3110
711 tristate "SPI UART driver for Max3110"
712 depends on SPI_DW_PCI
713 select SERIAL_CORE
714 select SERIAL_CORE_CONSOLE
715 help
716 This is the UART protocol driver for the MAX3110 device on
717 the Intel Moorestown platform. On other systems use the max3100
718 driver.
719
720config MRST_MAX3110_IRQ
721 boolean "Enable GPIO IRQ for Max3110 over Moorestown"
722 default n
723 depends on SERIAL_MRST_MAX3110 && GPIO_LANGWELL
724 help
725 This has to be enabled after Moorestown GPIO driver is loaded
726
727config SERIAL_MFD_HSU
728 tristate "Medfield High Speed UART support"
729 depends on PCI
730 select SERIAL_CORE
731
732config SERIAL_MFD_HSU_CONSOLE
733 boolean "Medfile HSU serial console support"
734 depends on SERIAL_MFD_HSU=y
735 select SERIAL_CORE_CONSOLE
736
693config SERIAL_BFIN 737config SERIAL_BFIN
694 tristate "Blackfin serial port support" 738 tristate "Blackfin serial port support"
695 depends on BLACKFIN 739 depends on BLACKFIN
diff --git a/drivers/serial/Makefile b/drivers/serial/Makefile
index 208a85572c32..1ca4fd599ffe 100644
--- a/drivers/serial/Makefile
+++ b/drivers/serial/Makefile
@@ -46,6 +46,8 @@ obj-$(CONFIG_SERIAL_S3C24A0) += s3c24a0.o
46obj-$(CONFIG_SERIAL_S3C6400) += s3c6400.o 46obj-$(CONFIG_SERIAL_S3C6400) += s3c6400.o
47obj-$(CONFIG_SERIAL_S5PV210) += s5pv210.o 47obj-$(CONFIG_SERIAL_S5PV210) += s5pv210.o
48obj-$(CONFIG_SERIAL_MAX3100) += max3100.o 48obj-$(CONFIG_SERIAL_MAX3100) += max3100.o
49obj-$(CONFIG_SERIAL_MAX3107) += max3107.o
50obj-$(CONFIG_SERIAL_MAX3107_AAVA) += max3107-aava.o
49obj-$(CONFIG_SERIAL_IP22_ZILOG) += ip22zilog.o 51obj-$(CONFIG_SERIAL_IP22_ZILOG) += ip22zilog.o
50obj-$(CONFIG_SERIAL_MUX) += mux.o 52obj-$(CONFIG_SERIAL_MUX) += mux.o
51obj-$(CONFIG_SERIAL_68328) += 68328serial.o 53obj-$(CONFIG_SERIAL_68328) += 68328serial.o
@@ -84,3 +86,5 @@ obj-$(CONFIG_SERIAL_TIMBERDALE) += timbuart.o
84obj-$(CONFIG_SERIAL_GRLIB_GAISLER_APBUART) += apbuart.o 86obj-$(CONFIG_SERIAL_GRLIB_GAISLER_APBUART) += apbuart.o
85obj-$(CONFIG_SERIAL_ALTERA_JTAGUART) += altera_jtaguart.o 87obj-$(CONFIG_SERIAL_ALTERA_JTAGUART) += altera_jtaguart.o
86obj-$(CONFIG_SERIAL_ALTERA_UART) += altera_uart.o 88obj-$(CONFIG_SERIAL_ALTERA_UART) += altera_uart.o
89obj-$(CONFIG_SERIAL_MRST_MAX3110) += mrst_max3110.o
90obj-$(CONFIG_SERIAL_MFD_HSU) += mfd.o
diff --git a/drivers/serial/altera_uart.c b/drivers/serial/altera_uart.c
index 0f1189605d21..f8d8a00554da 100644
--- a/drivers/serial/altera_uart.c
+++ b/drivers/serial/altera_uart.c
@@ -394,7 +394,7 @@ int __init early_altera_uart_setup(struct altera_uart_platform_uart *platp)
394static void altera_uart_console_putc(struct uart_port *port, const char c) 394static void altera_uart_console_putc(struct uart_port *port, const char c)
395{ 395{
396 while (!(readl(port->membase + ALTERA_UART_STATUS_REG) & 396 while (!(readl(port->membase + ALTERA_UART_STATUS_REG) &
397 ALTERA_UART_STATUS_TRDY_MSK)) 397 ALTERA_UART_STATUS_TRDY_MSK))
398 cpu_relax(); 398 cpu_relax();
399 399
400 writel(c, port->membase + ALTERA_UART_TXDATA_REG); 400 writel(c, port->membase + ALTERA_UART_TXDATA_REG);
diff --git a/drivers/serial/apbuart.c b/drivers/serial/apbuart.c
index 0099b8692b60..cc01c650a144 100644
--- a/drivers/serial/apbuart.c
+++ b/drivers/serial/apbuart.c
@@ -551,7 +551,7 @@ static struct uart_driver grlib_apbuart_driver = {
551/* OF Platform Driver */ 551/* OF Platform Driver */
552/* ======================================================================== */ 552/* ======================================================================== */
553 553
554static int __devinit apbuart_probe(struct of_device *op, 554static int __devinit apbuart_probe(struct platform_device *op,
555 const struct of_device_id *match) 555 const struct of_device_id *match)
556{ 556{
557 int i = -1; 557 int i = -1;
diff --git a/drivers/serial/atmel_serial.c b/drivers/serial/atmel_serial.c
index a182def7007d..3892666b5fbd 100644
--- a/drivers/serial/atmel_serial.c
+++ b/drivers/serial/atmel_serial.c
@@ -217,7 +217,8 @@ void atmel_config_rs485(struct uart_port *port, struct serial_rs485 *rs485conf)
217 if (rs485conf->flags & SER_RS485_ENABLED) { 217 if (rs485conf->flags & SER_RS485_ENABLED) {
218 dev_dbg(port->dev, "Setting UART to RS485\n"); 218 dev_dbg(port->dev, "Setting UART to RS485\n");
219 atmel_port->tx_done_mask = ATMEL_US_TXEMPTY; 219 atmel_port->tx_done_mask = ATMEL_US_TXEMPTY;
220 UART_PUT_TTGR(port, rs485conf->delay_rts_before_send); 220 if (rs485conf->flags & SER_RS485_RTS_AFTER_SEND)
221 UART_PUT_TTGR(port, rs485conf->delay_rts_after_send);
221 mode |= ATMEL_US_USMODE_RS485; 222 mode |= ATMEL_US_USMODE_RS485;
222 } else { 223 } else {
223 dev_dbg(port->dev, "Setting UART to RS232\n"); 224 dev_dbg(port->dev, "Setting UART to RS232\n");
@@ -292,7 +293,9 @@ static void atmel_set_mctrl(struct uart_port *port, u_int mctrl)
292 293
293 if (atmel_port->rs485.flags & SER_RS485_ENABLED) { 294 if (atmel_port->rs485.flags & SER_RS485_ENABLED) {
294 dev_dbg(port->dev, "Setting UART to RS485\n"); 295 dev_dbg(port->dev, "Setting UART to RS485\n");
295 UART_PUT_TTGR(port, atmel_port->rs485.delay_rts_before_send); 296 if (atmel_port->rs485.flags & SER_RS485_RTS_AFTER_SEND)
297 UART_PUT_TTGR(port,
298 atmel_port->rs485.delay_rts_after_send);
296 mode |= ATMEL_US_USMODE_RS485; 299 mode |= ATMEL_US_USMODE_RS485;
297 } else { 300 } else {
298 dev_dbg(port->dev, "Setting UART to RS232\n"); 301 dev_dbg(port->dev, "Setting UART to RS232\n");
@@ -1211,7 +1214,9 @@ static void atmel_set_termios(struct uart_port *port, struct ktermios *termios,
1211 1214
1212 if (atmel_port->rs485.flags & SER_RS485_ENABLED) { 1215 if (atmel_port->rs485.flags & SER_RS485_ENABLED) {
1213 dev_dbg(port->dev, "Setting UART to RS485\n"); 1216 dev_dbg(port->dev, "Setting UART to RS485\n");
1214 UART_PUT_TTGR(port, atmel_port->rs485.delay_rts_before_send); 1217 if (atmel_port->rs485.flags & SER_RS485_RTS_AFTER_SEND)
1218 UART_PUT_TTGR(port,
1219 atmel_port->rs485.delay_rts_after_send);
1215 mode |= ATMEL_US_USMODE_RS485; 1220 mode |= ATMEL_US_USMODE_RS485;
1216 } else { 1221 } else {
1217 dev_dbg(port->dev, "Setting UART to RS232\n"); 1222 dev_dbg(port->dev, "Setting UART to RS232\n");
diff --git a/drivers/serial/bfin_5xx.c b/drivers/serial/bfin_5xx.c
index 511cbf687877..a9eff2b18eab 100644
--- a/drivers/serial/bfin_5xx.c
+++ b/drivers/serial/bfin_5xx.c
@@ -957,15 +957,12 @@ bfin_serial_verify_port(struct uart_port *port, struct serial_struct *ser)
957 * Enable the IrDA function if tty->ldisc.num is N_IRDA. 957 * Enable the IrDA function if tty->ldisc.num is N_IRDA.
958 * In other cases, disable IrDA function. 958 * In other cases, disable IrDA function.
959 */ 959 */
960static void bfin_serial_set_ldisc(struct uart_port *port) 960static void bfin_serial_set_ldisc(struct uart_port *port, int ld)
961{ 961{
962 int line = port->line; 962 int line = port->line;
963 unsigned short val; 963 unsigned short val;
964 964
965 if (line >= port->state->port.tty->driver->num) 965 switch (ld) {
966 return;
967
968 switch (port->state->port.tty->termios->c_line) {
969 case N_IRDA: 966 case N_IRDA:
970 val = UART_GET_GCTL(&bfin_serial_ports[line]); 967 val = UART_GET_GCTL(&bfin_serial_ports[line]);
971 val |= (IREN | RPOLC); 968 val |= (IREN | RPOLC);
diff --git a/drivers/serial/cpm_uart/cpm_uart_core.c b/drivers/serial/cpm_uart/cpm_uart_core.c
index 6016179db533..f2b8adcc6c92 100644
--- a/drivers/serial/cpm_uart/cpm_uart_core.c
+++ b/drivers/serial/cpm_uart/cpm_uart_core.c
@@ -1340,7 +1340,7 @@ static struct uart_driver cpm_reg = {
1340 1340
1341static int probe_index; 1341static int probe_index;
1342 1342
1343static int __devinit cpm_uart_probe(struct of_device *ofdev, 1343static int __devinit cpm_uart_probe(struct platform_device *ofdev,
1344 const struct of_device_id *match) 1344 const struct of_device_id *match)
1345{ 1345{
1346 int index = probe_index++; 1346 int index = probe_index++;
@@ -1364,7 +1364,7 @@ static int __devinit cpm_uart_probe(struct of_device *ofdev,
1364 return uart_add_one_port(&cpm_reg, &pinfo->port); 1364 return uart_add_one_port(&cpm_reg, &pinfo->port);
1365} 1365}
1366 1366
1367static int __devexit cpm_uart_remove(struct of_device *ofdev) 1367static int __devexit cpm_uart_remove(struct platform_device *ofdev)
1368{ 1368{
1369 struct uart_cpm_port *pinfo = dev_get_drvdata(&ofdev->dev); 1369 struct uart_cpm_port *pinfo = dev_get_drvdata(&ofdev->dev);
1370 return uart_remove_one_port(&cpm_reg, &pinfo->port); 1370 return uart_remove_one_port(&cpm_reg, &pinfo->port);
diff --git a/drivers/serial/crisv10.c b/drivers/serial/crisv10.c
index 31f172397af3..c856905bb3bd 100644
--- a/drivers/serial/crisv10.c
+++ b/drivers/serial/crisv10.c
@@ -3724,6 +3724,17 @@ rs_ioctl(struct tty_struct *tty, struct file * file,
3724 return e100_enable_rs485(tty, &rs485data); 3724 return e100_enable_rs485(tty, &rs485data);
3725 } 3725 }
3726 3726
3727 case TIOCGRS485:
3728 {
3729 struct serial_rs485 *rs485data =
3730 &(((struct e100_serial *)tty->driver_data)->rs485);
3731 /* This is the ioctl to get RS485 data from user-space */
3732 if (copy_to_user((struct serial_rs485 *) arg,
3733 rs485data,
3734 sizeof(serial_rs485)))
3735 return -EFAULT;
3736 break;
3737 }
3727 3738
3728 case TIOCSERWRRS485: 3739 case TIOCSERWRRS485:
3729 { 3740 {
@@ -3924,7 +3935,6 @@ static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
3924 * Check R_DMA_CHx_STATUS bit 0-6=number of available bytes in FIFO 3935 * Check R_DMA_CHx_STATUS bit 0-6=number of available bytes in FIFO
3925 * R_DMA_CHx_HWSW bit 31-16=nbr of bytes left in DMA buffer (0=64k) 3936 * R_DMA_CHx_HWSW bit 31-16=nbr of bytes left in DMA buffer (0=64k)
3926 */ 3937 */
3927 lock_kernel();
3928 orig_jiffies = jiffies; 3938 orig_jiffies = jiffies;
3929 while (info->xmit.head != info->xmit.tail || /* More in send queue */ 3939 while (info->xmit.head != info->xmit.tail || /* More in send queue */
3930 (*info->ostatusadr & 0x007f) || /* more in FIFO */ 3940 (*info->ostatusadr & 0x007f) || /* more in FIFO */
@@ -3941,7 +3951,6 @@ static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
3941 curr_time_usec - info->last_tx_active_usec; 3951 curr_time_usec - info->last_tx_active_usec;
3942 } 3952 }
3943 set_current_state(TASK_RUNNING); 3953 set_current_state(TASK_RUNNING);
3944 unlock_kernel();
3945} 3954}
3946 3955
3947/* 3956/*
@@ -3981,7 +3990,7 @@ block_til_ready(struct tty_struct *tty, struct file * filp,
3981 */ 3990 */
3982 if (tty_hung_up_p(filp) || 3991 if (tty_hung_up_p(filp) ||
3983 (info->flags & ASYNC_CLOSING)) { 3992 (info->flags & ASYNC_CLOSING)) {
3984 wait_event_interruptible(info->close_wait, 3993 wait_event_interruptible_tty(info->close_wait,
3985 !(info->flags & ASYNC_CLOSING)); 3994 !(info->flags & ASYNC_CLOSING));
3986#ifdef SERIAL_DO_RESTART 3995#ifdef SERIAL_DO_RESTART
3987 if (info->flags & ASYNC_HUP_NOTIFY) 3996 if (info->flags & ASYNC_HUP_NOTIFY)
@@ -4057,7 +4066,9 @@ block_til_ready(struct tty_struct *tty, struct file * filp,
4057 printk("block_til_ready blocking: ttyS%d, count = %d\n", 4066 printk("block_til_ready blocking: ttyS%d, count = %d\n",
4058 info->line, info->count); 4067 info->line, info->count);
4059#endif 4068#endif
4069 tty_unlock();
4060 schedule(); 4070 schedule();
4071 tty_lock();
4061 } 4072 }
4062 set_current_state(TASK_RUNNING); 4073 set_current_state(TASK_RUNNING);
4063 remove_wait_queue(&info->open_wait, &wait); 4074 remove_wait_queue(&info->open_wait, &wait);
@@ -4139,7 +4150,7 @@ rs_open(struct tty_struct *tty, struct file * filp)
4139 */ 4150 */
4140 if (tty_hung_up_p(filp) || 4151 if (tty_hung_up_p(filp) ||
4141 (info->flags & ASYNC_CLOSING)) { 4152 (info->flags & ASYNC_CLOSING)) {
4142 wait_event_interruptible(info->close_wait, 4153 wait_event_interruptible_tty(info->close_wait,
4143 !(info->flags & ASYNC_CLOSING)); 4154 !(info->flags & ASYNC_CLOSING));
4144#ifdef SERIAL_DO_RESTART 4155#ifdef SERIAL_DO_RESTART
4145 return ((info->flags & ASYNC_HUP_NOTIFY) ? 4156 return ((info->flags & ASYNC_HUP_NOTIFY) ?
@@ -4522,8 +4533,8 @@ static int __init rs_init(void)
4522 INIT_WORK(&info->work, do_softint); 4533 INIT_WORK(&info->work, do_softint);
4523 4534
4524 if (info->enabled) { 4535 if (info->enabled) {
4525 printk(KERN_INFO "%s%d at 0x%x is a builtin UART with DMA\n", 4536 printk(KERN_INFO "%s%d at %p is a builtin UART with DMA\n",
4526 serial_driver->name, info->line, (unsigned int)info->ioport); 4537 serial_driver->name, info->line, info->ioport);
4527 } 4538 }
4528 } 4539 }
4529#ifdef CONFIG_ETRAX_FAST_TIMER 4540#ifdef CONFIG_ETRAX_FAST_TIMER
diff --git a/drivers/serial/imx.c b/drivers/serial/imx.c
index eacb588a9345..66ecc7ab6dab 100644
--- a/drivers/serial/imx.c
+++ b/drivers/serial/imx.c
@@ -909,13 +909,11 @@ imx_set_termios(struct uart_port *port, struct ktermios *termios,
909 rational_best_approximation(16 * div * baud, sport->port.uartclk, 909 rational_best_approximation(16 * div * baud, sport->port.uartclk,
910 1 << 16, 1 << 16, &num, &denom); 910 1 << 16, 1 << 16, &num, &denom);
911 911
912 if (port->state && port->state->port.tty) { 912 tdiv64 = sport->port.uartclk;
913 tdiv64 = sport->port.uartclk; 913 tdiv64 *= num;
914 tdiv64 *= num; 914 do_div(tdiv64, denom * 16 * div);
915 do_div(tdiv64, denom * 16 * div); 915 tty_termios_encode_baud_rate(termios,
916 tty_encode_baud_rate(sport->port.state->port.tty,
917 (speed_t)tdiv64, (speed_t)tdiv64); 916 (speed_t)tdiv64, (speed_t)tdiv64);
918 }
919 917
920 num -= 1; 918 num -= 1;
921 denom -= 1; 919 denom -= 1;
diff --git a/drivers/serial/ioc3_serial.c b/drivers/serial/ioc3_serial.c
index f164ba4eba02..93de907b1208 100644
--- a/drivers/serial/ioc3_serial.c
+++ b/drivers/serial/ioc3_serial.c
@@ -954,12 +954,13 @@ ioc3_change_speed(struct uart_port *the_port,
954 struct ktermios *new_termios, struct ktermios *old_termios) 954 struct ktermios *new_termios, struct ktermios *old_termios)
955{ 955{
956 struct ioc3_port *port = get_ioc3_port(the_port); 956 struct ioc3_port *port = get_ioc3_port(the_port);
957 unsigned int cflag; 957 unsigned int cflag, iflag;
958 int baud; 958 int baud;
959 int new_parity = 0, new_parity_enable = 0, new_stop = 0, new_data = 8; 959 int new_parity = 0, new_parity_enable = 0, new_stop = 0, new_data = 8;
960 struct uart_state *state = the_port->state; 960 struct uart_state *state = the_port->state;
961 961
962 cflag = new_termios->c_cflag; 962 cflag = new_termios->c_cflag;
963 iflag = new_termios->c_iflag;
963 964
964 switch (cflag & CSIZE) { 965 switch (cflag & CSIZE) {
965 case CS5: 966 case CS5:
@@ -1000,12 +1001,12 @@ ioc3_change_speed(struct uart_port *the_port,
1000 1001
1001 state->port.tty->low_latency = 1; 1002 state->port.tty->low_latency = 1;
1002 1003
1003 if (I_IGNPAR(state->port.tty)) 1004 if (iflag & IGNPAR)
1004 the_port->ignore_status_mask &= ~(N_PARITY_ERROR 1005 the_port->ignore_status_mask &= ~(N_PARITY_ERROR
1005 | N_FRAMING_ERROR); 1006 | N_FRAMING_ERROR);
1006 if (I_IGNBRK(state->port.tty)) { 1007 if (iflag & IGNBRK) {
1007 the_port->ignore_status_mask &= ~N_BREAK; 1008 the_port->ignore_status_mask &= ~N_BREAK;
1008 if (I_IGNPAR(state->port.tty)) 1009 if (iflag & IGNPAR)
1009 the_port->ignore_status_mask &= ~N_OVERRUN_ERROR; 1010 the_port->ignore_status_mask &= ~N_OVERRUN_ERROR;
1010 } 1011 }
1011 if (!(cflag & CREAD)) { 1012 if (!(cflag & CREAD)) {
diff --git a/drivers/serial/ioc4_serial.c b/drivers/serial/ioc4_serial.c
index 8ad28fc64926..fcfe82653ac8 100644
--- a/drivers/serial/ioc4_serial.c
+++ b/drivers/serial/ioc4_serial.c
@@ -1685,11 +1685,12 @@ ioc4_change_speed(struct uart_port *the_port,
1685{ 1685{
1686 struct ioc4_port *port = get_ioc4_port(the_port, 0); 1686 struct ioc4_port *port = get_ioc4_port(the_port, 0);
1687 int baud, bits; 1687 int baud, bits;
1688 unsigned cflag; 1688 unsigned cflag, iflag;
1689 int new_parity = 0, new_parity_enable = 0, new_stop = 0, new_data = 8; 1689 int new_parity = 0, new_parity_enable = 0, new_stop = 0, new_data = 8;
1690 struct uart_state *state = the_port->state; 1690 struct uart_state *state = the_port->state;
1691 1691
1692 cflag = new_termios->c_cflag; 1692 cflag = new_termios->c_cflag;
1693 iflag = new_termios->c_iflag;
1693 1694
1694 switch (cflag & CSIZE) { 1695 switch (cflag & CSIZE) {
1695 case CS5: 1696 case CS5:
@@ -1741,12 +1742,12 @@ ioc4_change_speed(struct uart_port *the_port,
1741 1742
1742 state->port.tty->low_latency = 1; 1743 state->port.tty->low_latency = 1;
1743 1744
1744 if (I_IGNPAR(state->port.tty)) 1745 if (iflag & IGNPAR)
1745 the_port->ignore_status_mask &= ~(N_PARITY_ERROR 1746 the_port->ignore_status_mask &= ~(N_PARITY_ERROR
1746 | N_FRAMING_ERROR); 1747 | N_FRAMING_ERROR);
1747 if (I_IGNBRK(state->port.tty)) { 1748 if (iflag & IGNBRK) {
1748 the_port->ignore_status_mask &= ~N_BREAK; 1749 the_port->ignore_status_mask &= ~N_BREAK;
1749 if (I_IGNPAR(state->port.tty)) 1750 if (iflag & IGNPAR)
1750 the_port->ignore_status_mask &= ~N_OVERRUN_ERROR; 1751 the_port->ignore_status_mask &= ~N_OVERRUN_ERROR;
1751 } 1752 }
1752 if (!(cflag & CREAD)) { 1753 if (!(cflag & CREAD)) {
diff --git a/drivers/serial/max3100.c b/drivers/serial/max3100.c
index 3351c3bd59e4..beb1afa27d8d 100644
--- a/drivers/serial/max3100.c
+++ b/drivers/serial/max3100.c
@@ -430,17 +430,14 @@ max3100_set_termios(struct uart_port *port, struct ktermios *termios,
430 int baud = 0; 430 int baud = 0;
431 unsigned cflag; 431 unsigned cflag;
432 u32 param_new, param_mask, parity = 0; 432 u32 param_new, param_mask, parity = 0;
433 struct tty_struct *tty = s->port.state->port.tty;
434 433
435 dev_dbg(&s->spi->dev, "%s\n", __func__); 434 dev_dbg(&s->spi->dev, "%s\n", __func__);
436 if (!tty)
437 return;
438 435
439 cflag = termios->c_cflag; 436 cflag = termios->c_cflag;
440 param_new = 0; 437 param_new = 0;
441 param_mask = 0; 438 param_mask = 0;
442 439
443 baud = tty_get_baud_rate(tty); 440 baud = tty_termios_baud_rate(termios);
444 param_new = s->conf & MAX3100_BAUD; 441 param_new = s->conf & MAX3100_BAUD;
445 switch (baud) { 442 switch (baud) {
446 case 300: 443 case 300:
@@ -485,7 +482,7 @@ max3100_set_termios(struct uart_port *port, struct ktermios *termios,
485 default: 482 default:
486 baud = s->baud; 483 baud = s->baud;
487 } 484 }
488 tty_encode_baud_rate(tty, baud, baud); 485 tty_termios_encode_baud_rate(termios, baud, baud);
489 s->baud = baud; 486 s->baud = baud;
490 param_mask |= MAX3100_BAUD; 487 param_mask |= MAX3100_BAUD;
491 488
diff --git a/drivers/serial/max3107-aava.c b/drivers/serial/max3107-aava.c
new file mode 100644
index 000000000000..a1fe304f2f52
--- /dev/null
+++ b/drivers/serial/max3107-aava.c
@@ -0,0 +1,344 @@
1/*
2 * max3107.c - spi uart protocol driver for Maxim 3107
3 * Based on max3100.c
4 * by Christian Pellegrin <chripell@evolware.org>
5 * and max3110.c
6 * by Feng Tang <feng.tang@intel.com>
7 *
8 * Copyright (C) Aavamobile 2009
9 *
10 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
27 *
28 */
29
30#include <linux/delay.h>
31#include <linux/device.h>
32#include <linux/serial_core.h>
33#include <linux/serial.h>
34#include <linux/spi/spi.h>
35#include <linux/freezer.h>
36#include <linux/platform_device.h>
37#include <linux/gpio.h>
38#include <linux/sfi.h>
39#include <asm/mrst.h>
40#include "max3107.h"
41
42/* GPIO direction to input function */
43static int max3107_gpio_direction_in(struct gpio_chip *chip, unsigned offset)
44{
45 struct max3107_port *s = container_of(chip, struct max3107_port, chip);
46 u16 buf[1]; /* Buffer for SPI transfer */
47
48 if (offset >= MAX3107_GPIO_COUNT) {
49 dev_err(&s->spi->dev, "Invalid GPIO\n");
50 return -EINVAL;
51 }
52
53 /* Read current GPIO configuration register */
54 buf[0] = MAX3107_GPIOCFG_REG;
55 /* Perform SPI transfer */
56 if (max3107_rw(s, (u8 *)buf, (u8 *)buf, 2)) {
57 dev_err(&s->spi->dev, "SPI transfer GPIO read failed\n");
58 return -EIO;
59 }
60 buf[0] &= MAX3107_SPI_RX_DATA_MASK;
61
62 /* Set GPIO to input */
63 buf[0] &= ~(0x0001 << offset);
64
65 /* Write new GPIO configuration register value */
66 buf[0] |= (MAX3107_WRITE_BIT | MAX3107_GPIOCFG_REG);
67 /* Perform SPI transfer */
68 if (max3107_rw(s, (u8 *)buf, NULL, 2)) {
69 dev_err(&s->spi->dev, "SPI transfer GPIO write failed\n");
70 return -EIO;
71 }
72 return 0;
73}
74
75/* GPIO direction to output function */
76static int max3107_gpio_direction_out(struct gpio_chip *chip, unsigned offset,
77 int value)
78{
79 struct max3107_port *s = container_of(chip, struct max3107_port, chip);
80 u16 buf[2]; /* Buffer for SPI transfers */
81
82 if (offset >= MAX3107_GPIO_COUNT) {
83 dev_err(&s->spi->dev, "Invalid GPIO\n");
84 return -EINVAL;
85 }
86
87 /* Read current GPIO configuration and data registers */
88 buf[0] = MAX3107_GPIOCFG_REG;
89 buf[1] = MAX3107_GPIODATA_REG;
90 /* Perform SPI transfer */
91 if (max3107_rw(s, (u8 *)buf, (u8 *)buf, 4)) {
92 dev_err(&s->spi->dev, "SPI transfer gpio failed\n");
93 return -EIO;
94 }
95 buf[0] &= MAX3107_SPI_RX_DATA_MASK;
96 buf[1] &= MAX3107_SPI_RX_DATA_MASK;
97
98 /* Set GPIO to output */
99 buf[0] |= (0x0001 << offset);
100 /* Set value */
101 if (value)
102 buf[1] |= (0x0001 << offset);
103 else
104 buf[1] &= ~(0x0001 << offset);
105
106 /* Write new GPIO configuration and data register values */
107 buf[0] |= (MAX3107_WRITE_BIT | MAX3107_GPIOCFG_REG);
108 buf[1] |= (MAX3107_WRITE_BIT | MAX3107_GPIODATA_REG);
109 /* Perform SPI transfer */
110 if (max3107_rw(s, (u8 *)buf, NULL, 4)) {
111 dev_err(&s->spi->dev,
112 "SPI transfer for GPIO conf data w failed\n");
113 return -EIO;
114 }
115 return 0;
116}
117
118/* GPIO value query function */
119static int max3107_gpio_get(struct gpio_chip *chip, unsigned offset)
120{
121 struct max3107_port *s = container_of(chip, struct max3107_port, chip);
122 u16 buf[1]; /* Buffer for SPI transfer */
123
124 if (offset >= MAX3107_GPIO_COUNT) {
125 dev_err(&s->spi->dev, "Invalid GPIO\n");
126 return -EINVAL;
127 }
128
129 /* Read current GPIO data register */
130 buf[0] = MAX3107_GPIODATA_REG;
131 /* Perform SPI transfer */
132 if (max3107_rw(s, (u8 *)buf, (u8 *)buf, 2)) {
133 dev_err(&s->spi->dev, "SPI transfer GPIO data r failed\n");
134 return -EIO;
135 }
136 buf[0] &= MAX3107_SPI_RX_DATA_MASK;
137
138 /* Return value */
139 return buf[0] & (0x0001 << offset);
140}
141
142/* GPIO value set function */
143static void max3107_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
144{
145 struct max3107_port *s = container_of(chip, struct max3107_port, chip);
146 u16 buf[2]; /* Buffer for SPI transfers */
147
148 if (offset >= MAX3107_GPIO_COUNT) {
149 dev_err(&s->spi->dev, "Invalid GPIO\n");
150 return;
151 }
152
153 /* Read current GPIO configuration registers*/
154 buf[0] = MAX3107_GPIODATA_REG;
155 buf[1] = MAX3107_GPIOCFG_REG;
156 /* Perform SPI transfer */
157 if (max3107_rw(s, (u8 *)buf, (u8 *)buf, 4)) {
158 dev_err(&s->spi->dev,
159 "SPI transfer for GPIO data and config read failed\n");
160 return;
161 }
162 buf[0] &= MAX3107_SPI_RX_DATA_MASK;
163 buf[1] &= MAX3107_SPI_RX_DATA_MASK;
164
165 if (!(buf[1] & (0x0001 << offset))) {
166 /* Configured as input, can't set value */
167 dev_warn(&s->spi->dev,
168 "Trying to set value for input GPIO\n");
169 return;
170 }
171
172 /* Set value */
173 if (value)
174 buf[0] |= (0x0001 << offset);
175 else
176 buf[0] &= ~(0x0001 << offset);
177
178 /* Write new GPIO data register value */
179 buf[0] |= (MAX3107_WRITE_BIT | MAX3107_GPIODATA_REG);
180 /* Perform SPI transfer */
181 if (max3107_rw(s, (u8 *)buf, NULL, 2))
182 dev_err(&s->spi->dev, "SPI transfer GPIO data w failed\n");
183}
184
185/* GPIO chip data */
186static struct gpio_chip max3107_gpio_chip = {
187 .owner = THIS_MODULE,
188 .direction_input = max3107_gpio_direction_in,
189 .direction_output = max3107_gpio_direction_out,
190 .get = max3107_gpio_get,
191 .set = max3107_gpio_set,
192 .can_sleep = 1,
193 .base = MAX3107_GPIO_BASE,
194 .ngpio = MAX3107_GPIO_COUNT,
195};
196
197/**
198 * max3107_aava_reset - reset on AAVA systems
199 * @spi: The SPI device we are probing
200 *
201 * Reset the device ready for probing.
202 */
203
204static int max3107_aava_reset(struct spi_device *spi)
205{
206 /* Reset the chip */
207 if (gpio_request(MAX3107_RESET_GPIO, "max3107")) {
208 pr_err("Requesting RESET GPIO failed\n");
209 return -EIO;
210 }
211 if (gpio_direction_output(MAX3107_RESET_GPIO, 0)) {
212 pr_err("Setting RESET GPIO to 0 failed\n");
213 gpio_free(MAX3107_RESET_GPIO);
214 return -EIO;
215 }
216 msleep(MAX3107_RESET_DELAY);
217 if (gpio_direction_output(MAX3107_RESET_GPIO, 1)) {
218 pr_err("Setting RESET GPIO to 1 failed\n");
219 gpio_free(MAX3107_RESET_GPIO);
220 return -EIO;
221 }
222 gpio_free(MAX3107_RESET_GPIO);
223 msleep(MAX3107_WAKEUP_DELAY);
224 return 0;
225}
226
227static int max3107_aava_configure(struct max3107_port *s)
228{
229 int retval;
230
231 /* Initialize GPIO chip data */
232 s->chip = max3107_gpio_chip;
233 s->chip.label = s->spi->modalias;
234 s->chip.dev = &s->spi->dev;
235
236 /* Add GPIO chip */
237 retval = gpiochip_add(&s->chip);
238 if (retval) {
239 dev_err(&s->spi->dev, "Adding GPIO chip failed\n");
240 return retval;
241 }
242
243 /* Temporary fix for EV2 boot problems, set modem reset to 0 */
244 max3107_gpio_direction_out(&s->chip, 3, 0);
245 return 0;
246}
247
248#if 0
249/* This will get enabled once we have the board stuff merged for this
250 specific case */
251
252static const struct baud_table brg13_ext[] = {
253 { 300, MAX3107_BRG13_B300 },
254 { 600, MAX3107_BRG13_B600 },
255 { 1200, MAX3107_BRG13_B1200 },
256 { 2400, MAX3107_BRG13_B2400 },
257 { 4800, MAX3107_BRG13_B4800 },
258 { 9600, MAX3107_BRG13_B9600 },
259 { 19200, MAX3107_BRG13_B19200 },
260 { 57600, MAX3107_BRG13_B57600 },
261 { 115200, MAX3107_BRG13_B115200 },
262 { 230400, MAX3107_BRG13_B230400 },
263 { 460800, MAX3107_BRG13_B460800 },
264 { 921600, MAX3107_BRG13_B921600 },
265 { 0, 0 }
266};
267
268static void max3107_aava_init(struct max3107_port *s)
269{
270 /*override for AAVA SC specific*/
271 if (mrst_platform_id() == MRST_PLATFORM_AAVA_SC) {
272 if (get_koski_build_id() <= KOSKI_EV2)
273 if (s->ext_clk) {
274 s->brg_cfg = MAX3107_BRG13_B9600;
275 s->baud_tbl = (struct baud_table *)brg13_ext;
276 }
277 }
278}
279#endif
280
281static int __devexit max3107_aava_remove(struct spi_device *spi)
282{
283 struct max3107_port *s = dev_get_drvdata(&spi->dev);
284
285 /* Remove GPIO chip */
286 if (gpiochip_remove(&s->chip))
287 dev_warn(&spi->dev, "Removing GPIO chip failed\n");
288
289 /* Then do the default remove */
290 return max3107_remove(spi);
291}
292
293/* Platform data */
294static struct max3107_plat aava_plat_data = {
295 .loopback = 0,
296 .ext_clk = 1,
297/* .init = max3107_aava_init, */
298 .configure = max3107_aava_configure,
299 .hw_suspend = max3107_hw_susp,
300 .polled_mode = 0,
301 .poll_time = 0,
302};
303
304
305static int __devinit max3107_probe_aava(struct spi_device *spi)
306{
307 int err = max3107_aava_reset(spi);
308 if (err < 0)
309 return err;
310 return max3107_probe(spi, &aava_plat_data);
311}
312
313/* Spi driver data */
314static struct spi_driver max3107_driver = {
315 .driver = {
316 .name = "aava-max3107",
317 .bus = &spi_bus_type,
318 .owner = THIS_MODULE,
319 },
320 .probe = max3107_probe_aava,
321 .remove = __devexit_p(max3107_aava_remove),
322 .suspend = max3107_suspend,
323 .resume = max3107_resume,
324};
325
326/* Driver init function */
327static int __init max3107_init(void)
328{
329 return spi_register_driver(&max3107_driver);
330}
331
332/* Driver exit function */
333static void __exit max3107_exit(void)
334{
335 spi_unregister_driver(&max3107_driver);
336}
337
338module_init(max3107_init);
339module_exit(max3107_exit);
340
341MODULE_DESCRIPTION("MAX3107 driver");
342MODULE_AUTHOR("Aavamobile");
343MODULE_ALIAS("aava-max3107-spi");
344MODULE_LICENSE("GPL v2");
diff --git a/drivers/serial/max3107.c b/drivers/serial/max3107.c
new file mode 100644
index 000000000000..67283c1a57ff
--- /dev/null
+++ b/drivers/serial/max3107.c
@@ -0,0 +1,1197 @@
1/*
2 * max3107.c - spi uart protocol driver for Maxim 3107
3 * Based on max3100.c
4 * by Christian Pellegrin <chripell@evolware.org>
5 * and max3110.c
6 * by Feng Tang <feng.tang@intel.com>
7 *
8 * Copyright (C) Aavamobile 2009
9 *
10 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
27 *
28 */
29
30#include <linux/delay.h>
31#include <linux/device.h>
32#include <linux/serial_core.h>
33#include <linux/serial.h>
34#include <linux/gpio.h>
35#include <linux/spi/spi.h>
36#include <linux/freezer.h>
37#include "max3107.h"
38
39static const struct baud_table brg26_ext[] = {
40 { 300, MAX3107_BRG26_B300 },
41 { 600, MAX3107_BRG26_B600 },
42 { 1200, MAX3107_BRG26_B1200 },
43 { 2400, MAX3107_BRG26_B2400 },
44 { 4800, MAX3107_BRG26_B4800 },
45 { 9600, MAX3107_BRG26_B9600 },
46 { 19200, MAX3107_BRG26_B19200 },
47 { 57600, MAX3107_BRG26_B57600 },
48 { 115200, MAX3107_BRG26_B115200 },
49 { 230400, MAX3107_BRG26_B230400 },
50 { 460800, MAX3107_BRG26_B460800 },
51 { 921600, MAX3107_BRG26_B921600 },
52 { 0, 0 }
53};
54
55static const struct baud_table brg13_int[] = {
56 { 300, MAX3107_BRG13_IB300 },
57 { 600, MAX3107_BRG13_IB600 },
58 { 1200, MAX3107_BRG13_IB1200 },
59 { 2400, MAX3107_BRG13_IB2400 },
60 { 4800, MAX3107_BRG13_IB4800 },
61 { 9600, MAX3107_BRG13_IB9600 },
62 { 19200, MAX3107_BRG13_IB19200 },
63 { 57600, MAX3107_BRG13_IB57600 },
64 { 115200, MAX3107_BRG13_IB115200 },
65 { 230400, MAX3107_BRG13_IB230400 },
66 { 460800, MAX3107_BRG13_IB460800 },
67 { 921600, MAX3107_BRG13_IB921600 },
68 { 0, 0 }
69};
70
71static u32 get_new_brg(int baud, struct max3107_port *s)
72{
73 int i;
74 const struct baud_table *baud_tbl = s->baud_tbl;
75
76 for (i = 0; i < 13; i++) {
77 if (baud == baud_tbl[i].baud)
78 return baud_tbl[i].new_brg;
79 }
80
81 return 0;
82}
83
84/* Perform SPI transfer for write/read of device register(s) */
85int max3107_rw(struct max3107_port *s, u8 *tx, u8 *rx, int len)
86{
87 struct spi_message spi_msg;
88 struct spi_transfer spi_xfer;
89
90 /* Initialize SPI ,message */
91 spi_message_init(&spi_msg);
92
93 /* Initialize SPI transfer */
94 memset(&spi_xfer, 0, sizeof spi_xfer);
95 spi_xfer.len = len;
96 spi_xfer.tx_buf = tx;
97 spi_xfer.rx_buf = rx;
98 spi_xfer.speed_hz = MAX3107_SPI_SPEED;
99
100 /* Add SPI transfer to SPI message */
101 spi_message_add_tail(&spi_xfer, &spi_msg);
102
103#ifdef DBG_TRACE_SPI_DATA
104 {
105 int i;
106 pr_info("tx len %d:\n", spi_xfer.len);
107 for (i = 0 ; i < spi_xfer.len && i < 32 ; i++)
108 pr_info(" %x", ((u8 *)spi_xfer.tx_buf)[i]);
109 pr_info("\n");
110 }
111#endif
112
113 /* Perform synchronous SPI transfer */
114 if (spi_sync(s->spi, &spi_msg)) {
115 dev_err(&s->spi->dev, "spi_sync failure\n");
116 return -EIO;
117 }
118
119#ifdef DBG_TRACE_SPI_DATA
120 if (spi_xfer.rx_buf) {
121 int i;
122 pr_info("rx len %d:\n", spi_xfer.len);
123 for (i = 0 ; i < spi_xfer.len && i < 32 ; i++)
124 pr_info(" %x", ((u8 *)spi_xfer.rx_buf)[i]);
125 pr_info("\n");
126 }
127#endif
128 return 0;
129}
130EXPORT_SYMBOL_GPL(max3107_rw);
131
132/* Puts received data to circular buffer */
133static void put_data_to_circ_buf(struct max3107_port *s, unsigned char *data,
134 int len)
135{
136 struct uart_port *port = &s->port;
137 struct tty_struct *tty;
138
139 if (!port->state)
140 return;
141
142 tty = port->state->port.tty;
143 if (!tty)
144 return;
145
146 /* Insert received data */
147 tty_insert_flip_string(tty, data, len);
148 /* Update RX counter */
149 port->icount.rx += len;
150}
151
152/* Handle data receiving */
153static void max3107_handlerx(struct max3107_port *s, u16 rxlvl)
154{
155 int i;
156 int j;
157 int len; /* SPI transfer buffer length */
158 u16 *buf;
159 u8 *valid_str;
160
161 if (!s->rx_enabled)
162 /* RX is disabled */
163 return;
164
165 if (rxlvl == 0) {
166 /* RX fifo is empty */
167 return;
168 } else if (rxlvl >= MAX3107_RX_FIFO_SIZE) {
169 dev_warn(&s->spi->dev, "Possible RX FIFO overrun %d\n", rxlvl);
170 /* Ensure sanity of RX level */
171 rxlvl = MAX3107_RX_FIFO_SIZE;
172 }
173 if ((s->rxbuf == 0) || (s->rxstr == 0)) {
174 dev_warn(&s->spi->dev, "Rx buffer/str isn't ready\n");
175 return;
176 }
177 buf = s->rxbuf;
178 valid_str = s->rxstr;
179 while (rxlvl) {
180 pr_debug("rxlvl %d\n", rxlvl);
181 /* Clear buffer */
182 memset(buf, 0, sizeof(u16) * (MAX3107_RX_FIFO_SIZE + 2));
183 len = 0;
184 if (s->irqen_reg & MAX3107_IRQ_RXFIFO_BIT) {
185 /* First disable RX FIFO interrupt */
186 pr_debug("Disabling RX INT\n");
187 buf[0] = (MAX3107_WRITE_BIT | MAX3107_IRQEN_REG);
188 s->irqen_reg &= ~MAX3107_IRQ_RXFIFO_BIT;
189 buf[0] |= s->irqen_reg;
190 len++;
191 }
192 /* Just increase the length by amount of words in FIFO since
193 * buffer was zeroed and SPI transfer of 0x0000 means reading
194 * from RX FIFO
195 */
196 len += rxlvl;
197 /* Append RX level query */
198 buf[len] = MAX3107_RXFIFOLVL_REG;
199 len++;
200
201 /* Perform the SPI transfer */
202 if (max3107_rw(s, (u8 *)buf, (u8 *)buf, len * 2)) {
203 dev_err(&s->spi->dev, "SPI transfer for RX h failed\n");
204 return;
205 }
206
207 /* Skip RX FIFO interrupt disabling word if it was added */
208 j = ((len - 1) - rxlvl);
209 /* Read received words */
210 for (i = 0; i < rxlvl; i++, j++)
211 valid_str[i] = (u8)buf[j];
212 put_data_to_circ_buf(s, valid_str, rxlvl);
213 /* Get new RX level */
214 rxlvl = (buf[len - 1] & MAX3107_SPI_RX_DATA_MASK);
215 }
216
217 if (s->rx_enabled) {
218 /* RX still enabled, re-enable RX FIFO interrupt */
219 pr_debug("Enabling RX INT\n");
220 buf[0] = (MAX3107_WRITE_BIT | MAX3107_IRQEN_REG);
221 s->irqen_reg |= MAX3107_IRQ_RXFIFO_BIT;
222 buf[0] |= s->irqen_reg;
223 if (max3107_rw(s, (u8 *)buf, NULL, 2))
224 dev_err(&s->spi->dev, "RX FIFO INT enabling failed\n");
225 }
226
227 /* Push the received data to receivers */
228 if (s->port.state->port.tty)
229 tty_flip_buffer_push(s->port.state->port.tty);
230}
231
232
233/* Handle data sending */
234static void max3107_handletx(struct max3107_port *s)
235{
236 struct circ_buf *xmit = &s->port.state->xmit;
237 int i;
238 unsigned long flags;
239 int len; /* SPI transfer buffer length */
240 u16 *buf;
241
242 if (!s->tx_fifo_empty)
243 /* Don't send more data before previous data is sent */
244 return;
245
246 if (uart_circ_empty(xmit) || uart_tx_stopped(&s->port))
247 /* No data to send or TX is stopped */
248 return;
249
250 if (!s->txbuf) {
251 dev_warn(&s->spi->dev, "Txbuf isn't ready\n");
252 return;
253 }
254 buf = s->txbuf;
255 /* Get length of data pending in circular buffer */
256 len = uart_circ_chars_pending(xmit);
257 if (len) {
258 /* Limit to size of TX FIFO */
259 if (len > MAX3107_TX_FIFO_SIZE)
260 len = MAX3107_TX_FIFO_SIZE;
261
262 pr_debug("txlen %d\n", len);
263
264 /* Update TX counter */
265 s->port.icount.tx += len;
266
267 /* TX FIFO will no longer be empty */
268 s->tx_fifo_empty = 0;
269
270 i = 0;
271 if (s->irqen_reg & MAX3107_IRQ_TXEMPTY_BIT) {
272 /* First disable TX empty interrupt */
273 pr_debug("Disabling TE INT\n");
274 buf[i] = (MAX3107_WRITE_BIT | MAX3107_IRQEN_REG);
275 s->irqen_reg &= ~MAX3107_IRQ_TXEMPTY_BIT;
276 buf[i] |= s->irqen_reg;
277 i++;
278 len++;
279 }
280 /* Add data to send */
281 spin_lock_irqsave(&s->port.lock, flags);
282 for ( ; i < len ; i++) {
283 buf[i] = (MAX3107_WRITE_BIT | MAX3107_THR_REG);
284 buf[i] |= ((u16)xmit->buf[xmit->tail] &
285 MAX3107_SPI_TX_DATA_MASK);
286 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
287 }
288 spin_unlock_irqrestore(&s->port.lock, flags);
289 if (!(s->irqen_reg & MAX3107_IRQ_TXEMPTY_BIT)) {
290 /* Enable TX empty interrupt */
291 pr_debug("Enabling TE INT\n");
292 buf[i] = (MAX3107_WRITE_BIT | MAX3107_IRQEN_REG);
293 s->irqen_reg |= MAX3107_IRQ_TXEMPTY_BIT;
294 buf[i] |= s->irqen_reg;
295 i++;
296 len++;
297 }
298 if (!s->tx_enabled) {
299 /* Enable TX */
300 pr_debug("Enable TX\n");
301 buf[i] = (MAX3107_WRITE_BIT | MAX3107_MODE1_REG);
302 spin_lock_irqsave(&s->data_lock, flags);
303 s->mode1_reg &= ~MAX3107_MODE1_TXDIS_BIT;
304 buf[i] |= s->mode1_reg;
305 spin_unlock_irqrestore(&s->data_lock, flags);
306 s->tx_enabled = 1;
307 i++;
308 len++;
309 }
310
311 /* Perform the SPI transfer */
312 if (max3107_rw(s, (u8 *)buf, NULL, len*2)) {
313 dev_err(&s->spi->dev,
314 "SPI transfer TX handling failed\n");
315 return;
316 }
317 }
318
319 /* Indicate wake up if circular buffer is getting low on data */
320 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
321 uart_write_wakeup(&s->port);
322
323}
324
325/* Handle interrupts
326 * Also reads and returns current RX FIFO level
327 */
328static u16 handle_interrupt(struct max3107_port *s)
329{
330 u16 buf[4]; /* Buffer for SPI transfers */
331 u8 irq_status;
332 u16 rx_level;
333 unsigned long flags;
334
335 /* Read IRQ status register */
336 buf[0] = MAX3107_IRQSTS_REG;
337 /* Read status IRQ status register */
338 buf[1] = MAX3107_STS_IRQSTS_REG;
339 /* Read LSR IRQ status register */
340 buf[2] = MAX3107_LSR_IRQSTS_REG;
341 /* Query RX level */
342 buf[3] = MAX3107_RXFIFOLVL_REG;
343
344 if (max3107_rw(s, (u8 *)buf, (u8 *)buf, 8)) {
345 dev_err(&s->spi->dev,
346 "SPI transfer for INTR handling failed\n");
347 return 0;
348 }
349
350 irq_status = (u8)buf[0];
351 pr_debug("IRQSTS %x\n", irq_status);
352 rx_level = (buf[3] & MAX3107_SPI_RX_DATA_MASK);
353
354 if (irq_status & MAX3107_IRQ_LSR_BIT) {
355 /* LSR interrupt */
356 if (buf[2] & MAX3107_LSR_RXTO_BIT)
357 /* RX timeout interrupt,
358 * handled by normal RX handling
359 */
360 pr_debug("RX TO INT\n");
361 }
362
363 if (irq_status & MAX3107_IRQ_TXEMPTY_BIT) {
364 /* Tx empty interrupt,
365 * disable TX and set tx_fifo_empty flag
366 */
367 pr_debug("TE INT, disabling TX\n");
368 buf[0] = (MAX3107_WRITE_BIT | MAX3107_MODE1_REG);
369 spin_lock_irqsave(&s->data_lock, flags);
370 s->mode1_reg |= MAX3107_MODE1_TXDIS_BIT;
371 buf[0] |= s->mode1_reg;
372 spin_unlock_irqrestore(&s->data_lock, flags);
373 if (max3107_rw(s, (u8 *)buf, NULL, 2))
374 dev_err(&s->spi->dev, "SPI transfer TX dis failed\n");
375 s->tx_enabled = 0;
376 s->tx_fifo_empty = 1;
377 }
378
379 if (irq_status & MAX3107_IRQ_RXFIFO_BIT)
380 /* RX FIFO interrupt,
381 * handled by normal RX handling
382 */
383 pr_debug("RFIFO INT\n");
384
385 /* Return RX level */
386 return rx_level;
387}
388
389/* Trigger work thread*/
390static void max3107_dowork(struct max3107_port *s)
391{
392 if (!work_pending(&s->work) && !freezing(current) && !s->suspended)
393 queue_work(s->workqueue, &s->work);
394 else
395 dev_warn(&s->spi->dev, "interrup isn't serviced normally!\n");
396}
397
398/* Work thread */
399static void max3107_work(struct work_struct *w)
400{
401 struct max3107_port *s = container_of(w, struct max3107_port, work);
402 u16 rxlvl = 0;
403 int len; /* SPI transfer buffer length */
404 u16 buf[5]; /* Buffer for SPI transfers */
405 unsigned long flags;
406
407 /* Start by reading current RX FIFO level */
408 buf[0] = MAX3107_RXFIFOLVL_REG;
409 if (max3107_rw(s, (u8 *)buf, (u8 *)buf, 2)) {
410 dev_err(&s->spi->dev, "SPI transfer RX lev failed\n");
411 rxlvl = 0;
412 } else {
413 rxlvl = (buf[0] & MAX3107_SPI_RX_DATA_MASK);
414 }
415
416 do {
417 pr_debug("rxlvl %d\n", rxlvl);
418
419 /* Handle RX */
420 max3107_handlerx(s, rxlvl);
421 rxlvl = 0;
422
423 if (s->handle_irq) {
424 /* Handle pending interrupts
425 * We also get new RX FIFO level since new data may
426 * have been received while pushing received data to
427 * receivers
428 */
429 s->handle_irq = 0;
430 rxlvl = handle_interrupt(s);
431 }
432
433 /* Handle TX */
434 max3107_handletx(s);
435
436 /* Handle configuration changes */
437 len = 0;
438 spin_lock_irqsave(&s->data_lock, flags);
439 if (s->mode1_commit) {
440 pr_debug("mode1_commit\n");
441 buf[len] = (MAX3107_WRITE_BIT | MAX3107_MODE1_REG);
442 buf[len++] |= s->mode1_reg;
443 s->mode1_commit = 0;
444 }
445 if (s->lcr_commit) {
446 pr_debug("lcr_commit\n");
447 buf[len] = (MAX3107_WRITE_BIT | MAX3107_LCR_REG);
448 buf[len++] |= s->lcr_reg;
449 s->lcr_commit = 0;
450 }
451 if (s->brg_commit) {
452 pr_debug("brg_commit\n");
453 buf[len] = (MAX3107_WRITE_BIT | MAX3107_BRGDIVMSB_REG);
454 buf[len++] |= ((s->brg_cfg >> 16) &
455 MAX3107_SPI_TX_DATA_MASK);
456 buf[len] = (MAX3107_WRITE_BIT | MAX3107_BRGDIVLSB_REG);
457 buf[len++] |= ((s->brg_cfg >> 8) &
458 MAX3107_SPI_TX_DATA_MASK);
459 buf[len] = (MAX3107_WRITE_BIT | MAX3107_BRGCFG_REG);
460 buf[len++] |= ((s->brg_cfg) & 0xff);
461 s->brg_commit = 0;
462 }
463 spin_unlock_irqrestore(&s->data_lock, flags);
464
465 if (len > 0) {
466 if (max3107_rw(s, (u8 *)buf, NULL, len * 2))
467 dev_err(&s->spi->dev,
468 "SPI transfer config failed\n");
469 }
470
471 /* Reloop if interrupt handling indicated data in RX FIFO */
472 } while (rxlvl);
473
474}
475
476/* Set sleep mode */
477static void max3107_set_sleep(struct max3107_port *s, int mode)
478{
479 u16 buf[1]; /* Buffer for SPI transfer */
480 unsigned long flags;
481 pr_debug("enter, mode %d\n", mode);
482
483 buf[0] = (MAX3107_WRITE_BIT | MAX3107_MODE1_REG);
484 spin_lock_irqsave(&s->data_lock, flags);
485 switch (mode) {
486 case MAX3107_DISABLE_FORCED_SLEEP:
487 s->mode1_reg &= ~MAX3107_MODE1_FORCESLEEP_BIT;
488 break;
489 case MAX3107_ENABLE_FORCED_SLEEP:
490 s->mode1_reg |= MAX3107_MODE1_FORCESLEEP_BIT;
491 break;
492 case MAX3107_DISABLE_AUTOSLEEP:
493 s->mode1_reg &= ~MAX3107_MODE1_AUTOSLEEP_BIT;
494 break;
495 case MAX3107_ENABLE_AUTOSLEEP:
496 s->mode1_reg |= MAX3107_MODE1_AUTOSLEEP_BIT;
497 break;
498 default:
499 spin_unlock_irqrestore(&s->data_lock, flags);
500 dev_warn(&s->spi->dev, "invalid sleep mode\n");
501 return;
502 }
503 buf[0] |= s->mode1_reg;
504 spin_unlock_irqrestore(&s->data_lock, flags);
505
506 if (max3107_rw(s, (u8 *)buf, NULL, 2))
507 dev_err(&s->spi->dev, "SPI transfer sleep mode failed\n");
508
509 if (mode == MAX3107_DISABLE_AUTOSLEEP ||
510 mode == MAX3107_DISABLE_FORCED_SLEEP)
511 msleep(MAX3107_WAKEUP_DELAY);
512}
513
514/* Perform full register initialization */
515static void max3107_register_init(struct max3107_port *s)
516{
517 u16 buf[11]; /* Buffer for SPI transfers */
518
519 /* 1. Configure baud rate, 9600 as default */
520 s->baud = 9600;
521 /* the below is default*/
522 if (s->ext_clk) {
523 s->brg_cfg = MAX3107_BRG26_B9600;
524 s->baud_tbl = (struct baud_table *)brg26_ext;
525 } else {
526 s->brg_cfg = MAX3107_BRG13_IB9600;
527 s->baud_tbl = (struct baud_table *)brg13_int;
528 }
529
530 if (s->pdata->init)
531 s->pdata->init(s);
532
533 buf[0] = (MAX3107_WRITE_BIT | MAX3107_BRGDIVMSB_REG)
534 | ((s->brg_cfg >> 16) & MAX3107_SPI_TX_DATA_MASK);
535 buf[1] = (MAX3107_WRITE_BIT | MAX3107_BRGDIVLSB_REG)
536 | ((s->brg_cfg >> 8) & MAX3107_SPI_TX_DATA_MASK);
537 buf[2] = (MAX3107_WRITE_BIT | MAX3107_BRGCFG_REG)
538 | ((s->brg_cfg) & 0xff);
539
540 /* 2. Configure LCR register, 8N1 mode by default */
541 s->lcr_reg = MAX3107_LCR_WORD_LEN_8;
542 buf[3] = (MAX3107_WRITE_BIT | MAX3107_LCR_REG)
543 | s->lcr_reg;
544
545 /* 3. Configure MODE 1 register */
546 s->mode1_reg = 0;
547 /* Enable IRQ pin */
548 s->mode1_reg |= MAX3107_MODE1_IRQSEL_BIT;
549 /* Disable TX */
550 s->mode1_reg |= MAX3107_MODE1_TXDIS_BIT;
551 s->tx_enabled = 0;
552 /* RX is enabled */
553 s->rx_enabled = 1;
554 buf[4] = (MAX3107_WRITE_BIT | MAX3107_MODE1_REG)
555 | s->mode1_reg;
556
557 /* 4. Configure MODE 2 register */
558 buf[5] = (MAX3107_WRITE_BIT | MAX3107_MODE2_REG);
559 if (s->loopback) {
560 /* Enable loopback */
561 buf[5] |= MAX3107_MODE2_LOOPBACK_BIT;
562 }
563 /* Reset FIFOs */
564 buf[5] |= MAX3107_MODE2_FIFORST_BIT;
565 s->tx_fifo_empty = 1;
566
567 /* 5. Configure FIFO trigger level register */
568 buf[6] = (MAX3107_WRITE_BIT | MAX3107_FIFOTRIGLVL_REG);
569 /* RX FIFO trigger for 16 words, TX FIFO trigger not used */
570 buf[6] |= (MAX3107_FIFOTRIGLVL_RX(16) | MAX3107_FIFOTRIGLVL_TX(0));
571
572 /* 6. Configure flow control levels */
573 buf[7] = (MAX3107_WRITE_BIT | MAX3107_FLOWLVL_REG);
574 /* Flow control halt level 96, resume level 48 */
575 buf[7] |= (MAX3107_FLOWLVL_RES(48) | MAX3107_FLOWLVL_HALT(96));
576
577 /* 7. Configure flow control */
578 buf[8] = (MAX3107_WRITE_BIT | MAX3107_FLOWCTRL_REG);
579 /* Enable auto CTS and auto RTS flow control */
580 buf[8] |= (MAX3107_FLOWCTRL_AUTOCTS_BIT | MAX3107_FLOWCTRL_AUTORTS_BIT);
581
582 /* 8. Configure RX timeout register */
583 buf[9] = (MAX3107_WRITE_BIT | MAX3107_RXTO_REG);
584 /* Timeout after 48 character intervals */
585 buf[9] |= 0x0030;
586
587 /* 9. Configure LSR interrupt enable register */
588 buf[10] = (MAX3107_WRITE_BIT | MAX3107_LSR_IRQEN_REG);
589 /* Enable RX timeout interrupt */
590 buf[10] |= MAX3107_LSR_RXTO_BIT;
591
592 /* Perform SPI transfer */
593 if (max3107_rw(s, (u8 *)buf, NULL, 22))
594 dev_err(&s->spi->dev, "SPI transfer for init failed\n");
595
596 /* 10. Clear IRQ status register by reading it */
597 buf[0] = MAX3107_IRQSTS_REG;
598
599 /* 11. Configure interrupt enable register */
600 /* Enable LSR interrupt */
601 s->irqen_reg = MAX3107_IRQ_LSR_BIT;
602 /* Enable RX FIFO interrupt */
603 s->irqen_reg |= MAX3107_IRQ_RXFIFO_BIT;
604 buf[1] = (MAX3107_WRITE_BIT | MAX3107_IRQEN_REG)
605 | s->irqen_reg;
606
607 /* 12. Clear FIFO reset that was set in step 6 */
608 buf[2] = (MAX3107_WRITE_BIT | MAX3107_MODE2_REG);
609 if (s->loopback) {
610 /* Keep loopback enabled */
611 buf[2] |= MAX3107_MODE2_LOOPBACK_BIT;
612 }
613
614 /* Perform SPI transfer */
615 if (max3107_rw(s, (u8 *)buf, (u8 *)buf, 6))
616 dev_err(&s->spi->dev, "SPI transfer for init failed\n");
617
618}
619
620/* IRQ handler */
621static irqreturn_t max3107_irq(int irqno, void *dev_id)
622{
623 struct max3107_port *s = dev_id;
624
625 if (irqno != s->spi->irq) {
626 /* Unexpected IRQ */
627 return IRQ_NONE;
628 }
629
630 /* Indicate irq */
631 s->handle_irq = 1;
632
633 /* Trigger work thread */
634 max3107_dowork(s);
635
636 return IRQ_HANDLED;
637}
638
639/* HW suspension function
640 *
641 * Currently autosleep is used to decrease current consumption, alternative
642 * approach would be to set the chip to reset mode if UART is not being
643 * used but that would mess the GPIOs
644 *
645 */
646void max3107_hw_susp(struct max3107_port *s, int suspend)
647{
648 pr_debug("enter, suspend %d\n", suspend);
649
650 if (suspend) {
651 /* Suspend requested,
652 * enable autosleep to decrease current consumption
653 */
654 s->suspended = 1;
655 max3107_set_sleep(s, MAX3107_ENABLE_AUTOSLEEP);
656 } else {
657 /* Resume requested,
658 * disable autosleep
659 */
660 s->suspended = 0;
661 max3107_set_sleep(s, MAX3107_DISABLE_AUTOSLEEP);
662 }
663}
664EXPORT_SYMBOL_GPL(max3107_hw_susp);
665
666/* Modem status IRQ enabling */
667static void max3107_enable_ms(struct uart_port *port)
668{
669 /* Modem status not supported */
670}
671
672/* Data send function */
673static void max3107_start_tx(struct uart_port *port)
674{
675 struct max3107_port *s = container_of(port, struct max3107_port, port);
676
677 /* Trigger work thread for sending data */
678 max3107_dowork(s);
679}
680
681/* Function for checking that there is no pending transfers */
682static unsigned int max3107_tx_empty(struct uart_port *port)
683{
684 struct max3107_port *s = container_of(port, struct max3107_port, port);
685
686 pr_debug("returning %d\n",
687 (s->tx_fifo_empty && uart_circ_empty(&s->port.state->xmit)));
688 return s->tx_fifo_empty && uart_circ_empty(&s->port.state->xmit);
689}
690
691/* Function for stopping RX */
692static void max3107_stop_rx(struct uart_port *port)
693{
694 struct max3107_port *s = container_of(port, struct max3107_port, port);
695 unsigned long flags;
696
697 /* Set RX disabled in MODE 1 register */
698 spin_lock_irqsave(&s->data_lock, flags);
699 s->mode1_reg |= MAX3107_MODE1_RXDIS_BIT;
700 s->mode1_commit = 1;
701 spin_unlock_irqrestore(&s->data_lock, flags);
702 /* Set RX disabled */
703 s->rx_enabled = 0;
704 /* Trigger work thread for doing the actual configuration change */
705 max3107_dowork(s);
706}
707
708/* Function for returning control pin states */
709static unsigned int max3107_get_mctrl(struct uart_port *port)
710{
711 /* DCD and DSR are not wired and CTS/RTS is handled automatically
712 * so just indicate DSR and CAR asserted
713 */
714 return TIOCM_DSR | TIOCM_CAR;
715}
716
717/* Function for setting control pin states */
718static void max3107_set_mctrl(struct uart_port *port, unsigned int mctrl)
719{
720 /* DCD and DSR are not wired and CTS/RTS is hadnled automatically
721 * so do nothing
722 */
723}
724
725/* Function for configuring UART parameters */
726static void max3107_set_termios(struct uart_port *port,
727 struct ktermios *termios,
728 struct ktermios *old)
729{
730 struct max3107_port *s = container_of(port, struct max3107_port, port);
731 struct tty_struct *tty;
732 int baud;
733 u16 new_lcr = 0;
734 u32 new_brg = 0;
735 unsigned long flags;
736
737 if (!port->state)
738 return;
739
740 tty = port->state->port.tty;
741 if (!tty)
742 return;
743
744 /* Get new LCR register values */
745 /* Word size */
746 if ((termios->c_cflag & CSIZE) == CS7)
747 new_lcr |= MAX3107_LCR_WORD_LEN_7;
748 else
749 new_lcr |= MAX3107_LCR_WORD_LEN_8;
750
751 /* Parity */
752 if (termios->c_cflag & PARENB) {
753 new_lcr |= MAX3107_LCR_PARITY_BIT;
754 if (!(termios->c_cflag & PARODD))
755 new_lcr |= MAX3107_LCR_EVENPARITY_BIT;
756 }
757
758 /* Stop bits */
759 if (termios->c_cflag & CSTOPB) {
760 /* 2 stop bits */
761 new_lcr |= MAX3107_LCR_STOPLEN_BIT;
762 }
763
764 /* Mask termios capabilities we don't support */
765 termios->c_cflag &= ~CMSPAR;
766
767 /* Set status ignore mask */
768 s->port.ignore_status_mask = 0;
769 if (termios->c_iflag & IGNPAR)
770 s->port.ignore_status_mask |= MAX3107_ALL_ERRORS;
771
772 /* Set low latency to immediately handle pushed data */
773 s->port.state->port.tty->low_latency = 1;
774
775 /* Get new baud rate generator configuration */
776 baud = tty_get_baud_rate(tty);
777
778 spin_lock_irqsave(&s->data_lock, flags);
779 new_brg = get_new_brg(baud, s);
780 /* if can't find the corrent config, use previous */
781 if (!new_brg) {
782 baud = s->baud;
783 new_brg = s->brg_cfg;
784 }
785 spin_unlock_irqrestore(&s->data_lock, flags);
786 tty_termios_encode_baud_rate(termios, baud, baud);
787 s->baud = baud;
788
789 /* Update timeout according to new baud rate */
790 uart_update_timeout(port, termios->c_cflag, baud);
791
792 spin_lock_irqsave(&s->data_lock, flags);
793 if (s->lcr_reg != new_lcr) {
794 s->lcr_reg = new_lcr;
795 s->lcr_commit = 1;
796 }
797 if (s->brg_cfg != new_brg) {
798 s->brg_cfg = new_brg;
799 s->brg_commit = 1;
800 }
801 spin_unlock_irqrestore(&s->data_lock, flags);
802
803 /* Trigger work thread for doing the actual configuration change */
804 max3107_dowork(s);
805}
806
807/* Port shutdown function */
808static void max3107_shutdown(struct uart_port *port)
809{
810 struct max3107_port *s = container_of(port, struct max3107_port, port);
811
812 if (s->suspended && s->pdata->hw_suspend)
813 s->pdata->hw_suspend(s, 0);
814
815 /* Free the interrupt */
816 free_irq(s->spi->irq, s);
817
818 if (s->workqueue) {
819 /* Flush and destroy work queue */
820 flush_workqueue(s->workqueue);
821 destroy_workqueue(s->workqueue);
822 s->workqueue = NULL;
823 }
824
825 /* Suspend HW */
826 if (s->pdata->hw_suspend)
827 s->pdata->hw_suspend(s, 1);
828}
829
830/* Port startup function */
831static int max3107_startup(struct uart_port *port)
832{
833 struct max3107_port *s = container_of(port, struct max3107_port, port);
834
835 /* Initialize work queue */
836 s->workqueue = create_freezeable_workqueue("max3107");
837 if (!s->workqueue) {
838 dev_err(&s->spi->dev, "Workqueue creation failed\n");
839 return -EBUSY;
840 }
841 INIT_WORK(&s->work, max3107_work);
842
843 /* Setup IRQ */
844 if (request_irq(s->spi->irq, max3107_irq, IRQF_TRIGGER_FALLING,
845 "max3107", s)) {
846 dev_err(&s->spi->dev, "IRQ reguest failed\n");
847 destroy_workqueue(s->workqueue);
848 s->workqueue = NULL;
849 return -EBUSY;
850 }
851
852 /* Resume HW */
853 if (s->pdata->hw_suspend)
854 s->pdata->hw_suspend(s, 0);
855
856 /* Init registers */
857 max3107_register_init(s);
858
859 return 0;
860}
861
862/* Port type function */
863static const char *max3107_type(struct uart_port *port)
864{
865 struct max3107_port *s = container_of(port, struct max3107_port, port);
866 return s->spi->modalias;
867}
868
869/* Port release function */
870static void max3107_release_port(struct uart_port *port)
871{
872 /* Do nothing */
873}
874
875/* Port request function */
876static int max3107_request_port(struct uart_port *port)
877{
878 /* Do nothing */
879 return 0;
880}
881
882/* Port config function */
883static void max3107_config_port(struct uart_port *port, int flags)
884{
885 struct max3107_port *s = container_of(port, struct max3107_port, port);
886 s->port.type = PORT_MAX3107;
887}
888
889/* Port verify function */
890static int max3107_verify_port(struct uart_port *port,
891 struct serial_struct *ser)
892{
893 if (ser->type == PORT_UNKNOWN || ser->type == PORT_MAX3107)
894 return 0;
895
896 return -EINVAL;
897}
898
899/* Port stop TX function */
900static void max3107_stop_tx(struct uart_port *port)
901{
902 /* Do nothing */
903}
904
905/* Port break control function */
906static void max3107_break_ctl(struct uart_port *port, int break_state)
907{
908 /* We don't support break control, do nothing */
909}
910
911
912/* Port functions */
913static struct uart_ops max3107_ops = {
914 .tx_empty = max3107_tx_empty,
915 .set_mctrl = max3107_set_mctrl,
916 .get_mctrl = max3107_get_mctrl,
917 .stop_tx = max3107_stop_tx,
918 .start_tx = max3107_start_tx,
919 .stop_rx = max3107_stop_rx,
920 .enable_ms = max3107_enable_ms,
921 .break_ctl = max3107_break_ctl,
922 .startup = max3107_startup,
923 .shutdown = max3107_shutdown,
924 .set_termios = max3107_set_termios,
925 .type = max3107_type,
926 .release_port = max3107_release_port,
927 .request_port = max3107_request_port,
928 .config_port = max3107_config_port,
929 .verify_port = max3107_verify_port,
930};
931
932/* UART driver data */
933static struct uart_driver max3107_uart_driver = {
934 .owner = THIS_MODULE,
935 .driver_name = "ttyMAX",
936 .dev_name = "ttyMAX",
937 .nr = 1,
938};
939
940static int driver_registered = 0;
941
942
943
944/* 'Generic' platform data */
945static struct max3107_plat generic_plat_data = {
946 .loopback = 0,
947 .ext_clk = 1,
948 .hw_suspend = max3107_hw_susp,
949 .polled_mode = 0,
950 .poll_time = 0,
951};
952
953
954/*******************************************************************/
955
956/**
957 * max3107_probe - SPI bus probe entry point
958 * @spi: the spi device
959 *
960 * SPI wants us to probe this device and if appropriate claim it.
961 * Perform any platform specific requirements and then initialise
962 * the device.
963 */
964
965int max3107_probe(struct spi_device *spi, struct max3107_plat *pdata)
966{
967 struct max3107_port *s;
968 u16 buf[2]; /* Buffer for SPI transfers */
969 int retval;
970
971 pr_info("enter max3107 probe\n");
972
973 /* Allocate port structure */
974 s = kzalloc(sizeof(*s), GFP_KERNEL);
975 if (!s) {
976 pr_err("Allocating port structure failed\n");
977 return -ENOMEM;
978 }
979
980 s->pdata = pdata;
981
982 /* SPI Rx buffer
983 * +2 for RX FIFO interrupt
984 * disabling and RX level query
985 */
986 s->rxbuf = kzalloc(sizeof(u16) * (MAX3107_RX_FIFO_SIZE+2), GFP_KERNEL);
987 if (!s->rxbuf) {
988 pr_err("Allocating RX buffer failed\n");
989 return -ENOMEM;
990 }
991 s->rxstr = kzalloc(sizeof(u8) * MAX3107_RX_FIFO_SIZE, GFP_KERNEL);
992 if (!s->rxstr) {
993 pr_err("Allocating RX buffer failed\n");
994 return -ENOMEM;
995 }
996 /* SPI Tx buffer
997 * SPI transfer buffer
998 * +3 for TX FIFO empty
999 * interrupt disabling and
1000 * enabling and TX enabling
1001 */
1002 s->txbuf = kzalloc(sizeof(u16) * MAX3107_TX_FIFO_SIZE + 3, GFP_KERNEL);
1003 if (!s->txbuf) {
1004 pr_err("Allocating TX buffer failed\n");
1005 return -ENOMEM;
1006 }
1007 /* Initialize shared data lock */
1008 spin_lock_init(&s->data_lock);
1009
1010 /* SPI intializations */
1011 dev_set_drvdata(&spi->dev, s);
1012 spi->mode = SPI_MODE_0;
1013 spi->dev.platform_data = pdata;
1014 spi->bits_per_word = 16;
1015 s->ext_clk = pdata->ext_clk;
1016 s->loopback = pdata->loopback;
1017 spi_setup(spi);
1018 s->spi = spi;
1019
1020 /* Check REV ID to ensure we are talking to what we expect */
1021 buf[0] = MAX3107_REVID_REG;
1022 if (max3107_rw(s, (u8 *)buf, (u8 *)buf, 2)) {
1023 dev_err(&s->spi->dev, "SPI transfer for REVID read failed\n");
1024 return -EIO;
1025 }
1026 if ((buf[0] & MAX3107_SPI_RX_DATA_MASK) != MAX3107_REVID1 &&
1027 (buf[0] & MAX3107_SPI_RX_DATA_MASK) != MAX3107_REVID2) {
1028 dev_err(&s->spi->dev, "REVID %x does not match\n",
1029 (buf[0] & MAX3107_SPI_RX_DATA_MASK));
1030 return -ENODEV;
1031 }
1032
1033 /* Disable all interrupts */
1034 buf[0] = (MAX3107_WRITE_BIT | MAX3107_IRQEN_REG | 0x0000);
1035 buf[0] |= 0x0000;
1036
1037 /* Configure clock source */
1038 buf[1] = (MAX3107_WRITE_BIT | MAX3107_CLKSRC_REG);
1039 if (s->ext_clk) {
1040 /* External clock */
1041 buf[1] |= MAX3107_CLKSRC_EXTCLK_BIT;
1042 }
1043
1044 /* PLL bypass ON */
1045 buf[1] |= MAX3107_CLKSRC_PLLBYP_BIT;
1046
1047 /* Perform SPI transfer */
1048 if (max3107_rw(s, (u8 *)buf, NULL, 4)) {
1049 dev_err(&s->spi->dev, "SPI transfer for init failed\n");
1050 return -EIO;
1051 }
1052
1053 /* Register UART driver */
1054 if (!driver_registered) {
1055 retval = uart_register_driver(&max3107_uart_driver);
1056 if (retval) {
1057 dev_err(&s->spi->dev, "Registering UART driver failed\n");
1058 return retval;
1059 }
1060 driver_registered = 1;
1061 }
1062
1063 /* Initialize UART port data */
1064 s->port.fifosize = 128;
1065 s->port.ops = &max3107_ops;
1066 s->port.line = 0;
1067 s->port.dev = &spi->dev;
1068 s->port.uartclk = 9600;
1069 s->port.flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF;
1070 s->port.irq = s->spi->irq;
1071 s->port.type = PORT_MAX3107;
1072
1073 /* Add UART port */
1074 retval = uart_add_one_port(&max3107_uart_driver, &s->port);
1075 if (retval < 0) {
1076 dev_err(&s->spi->dev, "Adding UART port failed\n");
1077 return retval;
1078 }
1079
1080 if (pdata->configure) {
1081 retval = pdata->configure(s);
1082 if (retval < 0)
1083 return retval;
1084 }
1085
1086 /* Go to suspend mode */
1087 if (pdata->hw_suspend)
1088 pdata->hw_suspend(s, 1);
1089
1090 return 0;
1091}
1092EXPORT_SYMBOL_GPL(max3107_probe);
1093
1094/* Driver remove function */
1095int max3107_remove(struct spi_device *spi)
1096{
1097 struct max3107_port *s = dev_get_drvdata(&spi->dev);
1098
1099 pr_info("enter max3107 remove\n");
1100
1101 /* Remove port */
1102 if (uart_remove_one_port(&max3107_uart_driver, &s->port))
1103 dev_warn(&s->spi->dev, "Removing UART port failed\n");
1104
1105
1106 /* Free TxRx buffer */
1107 kfree(s->rxbuf);
1108 kfree(s->rxstr);
1109 kfree(s->txbuf);
1110
1111 /* Free port structure */
1112 kfree(s);
1113
1114 return 0;
1115}
1116EXPORT_SYMBOL_GPL(max3107_remove);
1117
1118/* Driver suspend function */
1119int max3107_suspend(struct spi_device *spi, pm_message_t state)
1120{
1121#ifdef CONFIG_PM
1122 struct max3107_port *s = dev_get_drvdata(&spi->dev);
1123
1124 pr_debug("enter suspend\n");
1125
1126 /* Suspend UART port */
1127 uart_suspend_port(&max3107_uart_driver, &s->port);
1128
1129 /* Go to suspend mode */
1130 if (s->pdata->hw_suspend)
1131 s->pdata->hw_suspend(s, 1);
1132#endif /* CONFIG_PM */
1133 return 0;
1134}
1135EXPORT_SYMBOL_GPL(max3107_suspend);
1136
1137/* Driver resume function */
1138int max3107_resume(struct spi_device *spi)
1139{
1140#ifdef CONFIG_PM
1141 struct max3107_port *s = dev_get_drvdata(&spi->dev);
1142
1143 pr_debug("enter resume\n");
1144
1145 /* Resume from suspend */
1146 if (s->pdata->hw_suspend)
1147 s->pdata->hw_suspend(s, 0);
1148
1149 /* Resume UART port */
1150 uart_resume_port(&max3107_uart_driver, &s->port);
1151#endif /* CONFIG_PM */
1152 return 0;
1153}
1154EXPORT_SYMBOL_GPL(max3107_resume);
1155
1156static int max3107_probe_generic(struct spi_device *spi)
1157{
1158 return max3107_probe(spi, &generic_plat_data);
1159}
1160
1161/* Spi driver data */
1162static struct spi_driver max3107_driver = {
1163 .driver = {
1164 .name = "max3107",
1165 .bus = &spi_bus_type,
1166 .owner = THIS_MODULE,
1167 },
1168 .probe = max3107_probe_generic,
1169 .remove = __devexit_p(max3107_remove),
1170 .suspend = max3107_suspend,
1171 .resume = max3107_resume,
1172};
1173
1174/* Driver init function */
1175static int __init max3107_init(void)
1176{
1177 pr_info("enter max3107 init\n");
1178 return spi_register_driver(&max3107_driver);
1179}
1180
1181/* Driver exit function */
1182static void __exit max3107_exit(void)
1183{
1184 pr_info("enter max3107 exit\n");
1185 /* Unregister UART driver */
1186 if (driver_registered)
1187 uart_unregister_driver(&max3107_uart_driver);
1188 spi_unregister_driver(&max3107_driver);
1189}
1190
1191module_init(max3107_init);
1192module_exit(max3107_exit);
1193
1194MODULE_DESCRIPTION("MAX3107 driver");
1195MODULE_AUTHOR("Aavamobile");
1196MODULE_ALIAS("max3107-spi");
1197MODULE_LICENSE("GPL v2");
diff --git a/drivers/serial/max3107.h b/drivers/serial/max3107.h
new file mode 100644
index 000000000000..7ab632392502
--- /dev/null
+++ b/drivers/serial/max3107.h
@@ -0,0 +1,441 @@
1/*
2 * max3107.h - spi uart protocol driver header for Maxim 3107
3 *
4 * Copyright (C) Aavamobile 2009
5 * Based on serial_max3100.h by Christian Pellegrin
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 */
12
13#ifndef _MAX3107_H
14#define _MAX3107_H
15
16/* Serial error status definitions */
17#define MAX3107_PARITY_ERROR 1
18#define MAX3107_FRAME_ERROR 2
19#define MAX3107_OVERRUN_ERROR 4
20#define MAX3107_ALL_ERRORS (MAX3107_PARITY_ERROR | \
21 MAX3107_FRAME_ERROR | \
22 MAX3107_OVERRUN_ERROR)
23
24/* GPIO definitions */
25#define MAX3107_GPIO_BASE 88
26#define MAX3107_GPIO_COUNT 4
27
28
29/* GPIO connected to chip's reset pin */
30#define MAX3107_RESET_GPIO 87
31
32
33/* Chip reset delay */
34#define MAX3107_RESET_DELAY 10
35
36/* Chip wakeup delay */
37#define MAX3107_WAKEUP_DELAY 50
38
39
40/* Sleep mode definitions */
41#define MAX3107_DISABLE_FORCED_SLEEP 0
42#define MAX3107_ENABLE_FORCED_SLEEP 1
43#define MAX3107_DISABLE_AUTOSLEEP 2
44#define MAX3107_ENABLE_AUTOSLEEP 3
45
46
47/* Definitions for register access with SPI transfers
48 *
49 * SPI transfer format:
50 *
51 * Master to slave bits xzzzzzzzyyyyyyyy
52 * Slave to master bits aaaaaaaabbbbbbbb
53 *
54 * where:
55 * x = 0 for reads, 1 for writes
56 * z = register address
57 * y = new register value if write, 0 if read
58 * a = unspecified
59 * b = register value if read, unspecified if write
60 */
61
62/* SPI speed */
63#define MAX3107_SPI_SPEED (3125000 * 2)
64
65/* Write bit */
66#define MAX3107_WRITE_BIT (1 << 15)
67
68/* SPI TX data mask */
69#define MAX3107_SPI_RX_DATA_MASK (0x00ff)
70
71/* SPI RX data mask */
72#define MAX3107_SPI_TX_DATA_MASK (0x00ff)
73
74/* Register access masks */
75#define MAX3107_RHR_REG (0x0000) /* RX FIFO */
76#define MAX3107_THR_REG (0x0000) /* TX FIFO */
77#define MAX3107_IRQEN_REG (0x0100) /* IRQ enable */
78#define MAX3107_IRQSTS_REG (0x0200) /* IRQ status */
79#define MAX3107_LSR_IRQEN_REG (0x0300) /* LSR IRQ enable */
80#define MAX3107_LSR_IRQSTS_REG (0x0400) /* LSR IRQ status */
81#define MAX3107_SPCHR_IRQEN_REG (0x0500) /* Special char IRQ enable */
82#define MAX3107_SPCHR_IRQSTS_REG (0x0600) /* Special char IRQ status */
83#define MAX3107_STS_IRQEN_REG (0x0700) /* Status IRQ enable */
84#define MAX3107_STS_IRQSTS_REG (0x0800) /* Status IRQ status */
85#define MAX3107_MODE1_REG (0x0900) /* MODE1 */
86#define MAX3107_MODE2_REG (0x0a00) /* MODE2 */
87#define MAX3107_LCR_REG (0x0b00) /* LCR */
88#define MAX3107_RXTO_REG (0x0c00) /* RX timeout */
89#define MAX3107_HDPIXDELAY_REG (0x0d00) /* Auto transceiver delays */
90#define MAX3107_IRDA_REG (0x0e00) /* IRDA settings */
91#define MAX3107_FLOWLVL_REG (0x0f00) /* Flow control levels */
92#define MAX3107_FIFOTRIGLVL_REG (0x1000) /* FIFO IRQ trigger levels */
93#define MAX3107_TXFIFOLVL_REG (0x1100) /* TX FIFO level */
94#define MAX3107_RXFIFOLVL_REG (0x1200) /* RX FIFO level */
95#define MAX3107_FLOWCTRL_REG (0x1300) /* Flow control */
96#define MAX3107_XON1_REG (0x1400) /* XON1 character */
97#define MAX3107_XON2_REG (0x1500) /* XON2 character */
98#define MAX3107_XOFF1_REG (0x1600) /* XOFF1 character */
99#define MAX3107_XOFF2_REG (0x1700) /* XOFF2 character */
100#define MAX3107_GPIOCFG_REG (0x1800) /* GPIO config */
101#define MAX3107_GPIODATA_REG (0x1900) /* GPIO data */
102#define MAX3107_PLLCFG_REG (0x1a00) /* PLL config */
103#define MAX3107_BRGCFG_REG (0x1b00) /* Baud rate generator conf */
104#define MAX3107_BRGDIVLSB_REG (0x1c00) /* Baud rate divisor LSB */
105#define MAX3107_BRGDIVMSB_REG (0x1d00) /* Baud rate divisor MSB */
106#define MAX3107_CLKSRC_REG (0x1e00) /* Clock source */
107#define MAX3107_REVID_REG (0x1f00) /* Revision identification */
108
109/* IRQ register bits */
110#define MAX3107_IRQ_LSR_BIT (1 << 0) /* LSR interrupt */
111#define MAX3107_IRQ_SPCHR_BIT (1 << 1) /* Special char interrupt */
112#define MAX3107_IRQ_STS_BIT (1 << 2) /* Status interrupt */
113#define MAX3107_IRQ_RXFIFO_BIT (1 << 3) /* RX FIFO interrupt */
114#define MAX3107_IRQ_TXFIFO_BIT (1 << 4) /* TX FIFO interrupt */
115#define MAX3107_IRQ_TXEMPTY_BIT (1 << 5) /* TX FIFO empty interrupt */
116#define MAX3107_IRQ_RXEMPTY_BIT (1 << 6) /* RX FIFO empty interrupt */
117#define MAX3107_IRQ_CTS_BIT (1 << 7) /* CTS interrupt */
118
119/* LSR register bits */
120#define MAX3107_LSR_RXTO_BIT (1 << 0) /* RX timeout */
121#define MAX3107_LSR_RXOVR_BIT (1 << 1) /* RX overrun */
122#define MAX3107_LSR_RXPAR_BIT (1 << 2) /* RX parity error */
123#define MAX3107_LSR_FRERR_BIT (1 << 3) /* Frame error */
124#define MAX3107_LSR_RXBRK_BIT (1 << 4) /* RX break */
125#define MAX3107_LSR_RXNOISE_BIT (1 << 5) /* RX noise */
126#define MAX3107_LSR_UNDEF6_BIT (1 << 6) /* Undefined/not used */
127#define MAX3107_LSR_CTS_BIT (1 << 7) /* CTS pin state */
128
129/* Special character register bits */
130#define MAX3107_SPCHR_XON1_BIT (1 << 0) /* XON1 character */
131#define MAX3107_SPCHR_XON2_BIT (1 << 1) /* XON2 character */
132#define MAX3107_SPCHR_XOFF1_BIT (1 << 2) /* XOFF1 character */
133#define MAX3107_SPCHR_XOFF2_BIT (1 << 3) /* XOFF2 character */
134#define MAX3107_SPCHR_BREAK_BIT (1 << 4) /* RX break */
135#define MAX3107_SPCHR_MULTIDROP_BIT (1 << 5) /* 9-bit multidrop addr char */
136#define MAX3107_SPCHR_UNDEF6_BIT (1 << 6) /* Undefined/not used */
137#define MAX3107_SPCHR_UNDEF7_BIT (1 << 7) /* Undefined/not used */
138
139/* Status register bits */
140#define MAX3107_STS_GPIO0_BIT (1 << 0) /* GPIO 0 interrupt */
141#define MAX3107_STS_GPIO1_BIT (1 << 1) /* GPIO 1 interrupt */
142#define MAX3107_STS_GPIO2_BIT (1 << 2) /* GPIO 2 interrupt */
143#define MAX3107_STS_GPIO3_BIT (1 << 3) /* GPIO 3 interrupt */
144#define MAX3107_STS_UNDEF4_BIT (1 << 4) /* Undefined/not used */
145#define MAX3107_STS_CLKREADY_BIT (1 << 5) /* Clock ready */
146#define MAX3107_STS_SLEEP_BIT (1 << 6) /* Sleep interrupt */
147#define MAX3107_STS_UNDEF7_BIT (1 << 7) /* Undefined/not used */
148
149/* MODE1 register bits */
150#define MAX3107_MODE1_RXDIS_BIT (1 << 0) /* RX disable */
151#define MAX3107_MODE1_TXDIS_BIT (1 << 1) /* TX disable */
152#define MAX3107_MODE1_TXHIZ_BIT (1 << 2) /* TX pin three-state */
153#define MAX3107_MODE1_RTSHIZ_BIT (1 << 3) /* RTS pin three-state */
154#define MAX3107_MODE1_TRNSCVCTRL_BIT (1 << 4) /* Transceiver ctrl enable */
155#define MAX3107_MODE1_FORCESLEEP_BIT (1 << 5) /* Force sleep mode */
156#define MAX3107_MODE1_AUTOSLEEP_BIT (1 << 6) /* Auto sleep enable */
157#define MAX3107_MODE1_IRQSEL_BIT (1 << 7) /* IRQ pin enable */
158
159/* MODE2 register bits */
160#define MAX3107_MODE2_RST_BIT (1 << 0) /* Chip reset */
161#define MAX3107_MODE2_FIFORST_BIT (1 << 1) /* FIFO reset */
162#define MAX3107_MODE2_RXTRIGINV_BIT (1 << 2) /* RX FIFO INT invert */
163#define MAX3107_MODE2_RXEMPTINV_BIT (1 << 3) /* RX FIFO empty INT invert */
164#define MAX3107_MODE2_SPCHR_BIT (1 << 4) /* Special chr detect enable */
165#define MAX3107_MODE2_LOOPBACK_BIT (1 << 5) /* Internal loopback enable */
166#define MAX3107_MODE2_MULTIDROP_BIT (1 << 6) /* 9-bit multidrop enable */
167#define MAX3107_MODE2_ECHOSUPR_BIT (1 << 7) /* ECHO suppression enable */
168
169/* LCR register bits */
170#define MAX3107_LCR_LENGTH0_BIT (1 << 0) /* Word length bit 0 */
171#define MAX3107_LCR_LENGTH1_BIT (1 << 1) /* Word length bit 1
172 *
173 * Word length bits table:
174 * 00 -> 5 bit words
175 * 01 -> 6 bit words
176 * 10 -> 7 bit words
177 * 11 -> 8 bit words
178 */
179#define MAX3107_LCR_STOPLEN_BIT (1 << 2) /* STOP length bit
180 *
181 * STOP length bit table:
182 * 0 -> 1 stop bit
183 * 1 -> 1-1.5 stop bits if
184 * word length is 5,
185 * 2 stop bits otherwise
186 */
187#define MAX3107_LCR_PARITY_BIT (1 << 3) /* Parity bit enable */
188#define MAX3107_LCR_EVENPARITY_BIT (1 << 4) /* Even parity bit enable */
189#define MAX3107_LCR_FORCEPARITY_BIT (1 << 5) /* 9-bit multidrop parity */
190#define MAX3107_LCR_TXBREAK_BIT (1 << 6) /* TX break enable */
191#define MAX3107_LCR_RTS_BIT (1 << 7) /* RTS pin control */
192#define MAX3107_LCR_WORD_LEN_5 (0x0000)
193#define MAX3107_LCR_WORD_LEN_6 (0x0001)
194#define MAX3107_LCR_WORD_LEN_7 (0x0002)
195#define MAX3107_LCR_WORD_LEN_8 (0x0003)
196
197
198/* IRDA register bits */
199#define MAX3107_IRDA_IRDAEN_BIT (1 << 0) /* IRDA mode enable */
200#define MAX3107_IRDA_SIR_BIT (1 << 1) /* SIR mode enable */
201#define MAX3107_IRDA_SHORTIR_BIT (1 << 2) /* Short SIR mode enable */
202#define MAX3107_IRDA_MIR_BIT (1 << 3) /* MIR mode enable */
203#define MAX3107_IRDA_RXINV_BIT (1 << 4) /* RX logic inversion enable */
204#define MAX3107_IRDA_TXINV_BIT (1 << 5) /* TX logic inversion enable */
205#define MAX3107_IRDA_UNDEF6_BIT (1 << 6) /* Undefined/not used */
206#define MAX3107_IRDA_UNDEF7_BIT (1 << 7) /* Undefined/not used */
207
208/* Flow control trigger level register masks */
209#define MAX3107_FLOWLVL_HALT_MASK (0x000f) /* Flow control halt level */
210#define MAX3107_FLOWLVL_RES_MASK (0x00f0) /* Flow control resume level */
211#define MAX3107_FLOWLVL_HALT(words) ((words/8) & 0x000f)
212#define MAX3107_FLOWLVL_RES(words) (((words/8) & 0x000f) << 4)
213
214/* FIFO interrupt trigger level register masks */
215#define MAX3107_FIFOTRIGLVL_TX_MASK (0x000f) /* TX FIFO trigger level */
216#define MAX3107_FIFOTRIGLVL_RX_MASK (0x00f0) /* RX FIFO trigger level */
217#define MAX3107_FIFOTRIGLVL_TX(words) ((words/8) & 0x000f)
218#define MAX3107_FIFOTRIGLVL_RX(words) (((words/8) & 0x000f) << 4)
219
220/* Flow control register bits */
221#define MAX3107_FLOWCTRL_AUTORTS_BIT (1 << 0) /* Auto RTS flow ctrl enable */
222#define MAX3107_FLOWCTRL_AUTOCTS_BIT (1 << 1) /* Auto CTS flow ctrl enable */
223#define MAX3107_FLOWCTRL_GPIADDR_BIT (1 << 2) /* Enables that GPIO inputs
224 * are used in conjunction with
225 * XOFF2 for definition of
226 * special character */
227#define MAX3107_FLOWCTRL_SWFLOWEN_BIT (1 << 3) /* Auto SW flow ctrl enable */
228#define MAX3107_FLOWCTRL_SWFLOW0_BIT (1 << 4) /* SWFLOW bit 0 */
229#define MAX3107_FLOWCTRL_SWFLOW1_BIT (1 << 5) /* SWFLOW bit 1
230 *
231 * SWFLOW bits 1 & 0 table:
232 * 00 -> no transmitter flow
233 * control
234 * 01 -> receiver compares
235 * XON2 and XOFF2
236 * and controls
237 * transmitter
238 * 10 -> receiver compares
239 * XON1 and XOFF1
240 * and controls
241 * transmitter
242 * 11 -> receiver compares
243 * XON1, XON2, XOFF1 and
244 * XOFF2 and controls
245 * transmitter
246 */
247#define MAX3107_FLOWCTRL_SWFLOW2_BIT (1 << 6) /* SWFLOW bit 2 */
248#define MAX3107_FLOWCTRL_SWFLOW3_BIT (1 << 7) /* SWFLOW bit 3
249 *
250 * SWFLOW bits 3 & 2 table:
251 * 00 -> no received flow
252 * control
253 * 01 -> transmitter generates
254 * XON2 and XOFF2
255 * 10 -> transmitter generates
256 * XON1 and XOFF1
257 * 11 -> transmitter generates
258 * XON1, XON2, XOFF1 and
259 * XOFF2
260 */
261
262/* GPIO configuration register bits */
263#define MAX3107_GPIOCFG_GP0OUT_BIT (1 << 0) /* GPIO 0 output enable */
264#define MAX3107_GPIOCFG_GP1OUT_BIT (1 << 1) /* GPIO 1 output enable */
265#define MAX3107_GPIOCFG_GP2OUT_BIT (1 << 2) /* GPIO 2 output enable */
266#define MAX3107_GPIOCFG_GP3OUT_BIT (1 << 3) /* GPIO 3 output enable */
267#define MAX3107_GPIOCFG_GP0OD_BIT (1 << 4) /* GPIO 0 open-drain enable */
268#define MAX3107_GPIOCFG_GP1OD_BIT (1 << 5) /* GPIO 1 open-drain enable */
269#define MAX3107_GPIOCFG_GP2OD_BIT (1 << 6) /* GPIO 2 open-drain enable */
270#define MAX3107_GPIOCFG_GP3OD_BIT (1 << 7) /* GPIO 3 open-drain enable */
271
272/* GPIO DATA register bits */
273#define MAX3107_GPIODATA_GP0OUT_BIT (1 << 0) /* GPIO 0 output value */
274#define MAX3107_GPIODATA_GP1OUT_BIT (1 << 1) /* GPIO 1 output value */
275#define MAX3107_GPIODATA_GP2OUT_BIT (1 << 2) /* GPIO 2 output value */
276#define MAX3107_GPIODATA_GP3OUT_BIT (1 << 3) /* GPIO 3 output value */
277#define MAX3107_GPIODATA_GP0IN_BIT (1 << 4) /* GPIO 0 input value */
278#define MAX3107_GPIODATA_GP1IN_BIT (1 << 5) /* GPIO 1 input value */
279#define MAX3107_GPIODATA_GP2IN_BIT (1 << 6) /* GPIO 2 input value */
280#define MAX3107_GPIODATA_GP3IN_BIT (1 << 7) /* GPIO 3 input value */
281
282/* PLL configuration register masks */
283#define MAX3107_PLLCFG_PREDIV_MASK (0x003f) /* PLL predivision value */
284#define MAX3107_PLLCFG_PLLFACTOR_MASK (0x00c0) /* PLL multiplication factor */
285
286/* Baud rate generator configuration register masks and bits */
287#define MAX3107_BRGCFG_FRACT_MASK (0x000f) /* Fractional portion of
288 * Baud rate generator divisor
289 */
290#define MAX3107_BRGCFG_2XMODE_BIT (1 << 4) /* Double baud rate */
291#define MAX3107_BRGCFG_4XMODE_BIT (1 << 5) /* Quadruple baud rate */
292#define MAX3107_BRGCFG_UNDEF6_BIT (1 << 6) /* Undefined/not used */
293#define MAX3107_BRGCFG_UNDEF7_BIT (1 << 7) /* Undefined/not used */
294
295/* Clock source register bits */
296#define MAX3107_CLKSRC_INTOSC_BIT (1 << 0) /* Internal osc enable */
297#define MAX3107_CLKSRC_CRYST_BIT (1 << 1) /* Crystal osc enable */
298#define MAX3107_CLKSRC_PLL_BIT (1 << 2) /* PLL enable */
299#define MAX3107_CLKSRC_PLLBYP_BIT (1 << 3) /* PLL bypass */
300#define MAX3107_CLKSRC_EXTCLK_BIT (1 << 4) /* External clock enable */
301#define MAX3107_CLKSRC_UNDEF5_BIT (1 << 5) /* Undefined/not used */
302#define MAX3107_CLKSRC_UNDEF6_BIT (1 << 6) /* Undefined/not used */
303#define MAX3107_CLKSRC_CLK2RTS_BIT (1 << 7) /* Baud clk to RTS pin */
304
305
306/* HW definitions */
307#define MAX3107_RX_FIFO_SIZE 128
308#define MAX3107_TX_FIFO_SIZE 128
309#define MAX3107_REVID1 0x00a0
310#define MAX3107_REVID2 0x00a1
311
312
313/* Baud rate generator configuration values for external clock 13MHz */
314#define MAX3107_BRG13_B300 (0x0A9400 | 0x05)
315#define MAX3107_BRG13_B600 (0x054A00 | 0x03)
316#define MAX3107_BRG13_B1200 (0x02A500 | 0x01)
317#define MAX3107_BRG13_B2400 (0x015200 | 0x09)
318#define MAX3107_BRG13_B4800 (0x00A900 | 0x04)
319#define MAX3107_BRG13_B9600 (0x005400 | 0x0A)
320#define MAX3107_BRG13_B19200 (0x002A00 | 0x05)
321#define MAX3107_BRG13_B38400 (0x001500 | 0x03)
322#define MAX3107_BRG13_B57600 (0x000E00 | 0x02)
323#define MAX3107_BRG13_B115200 (0x000700 | 0x01)
324#define MAX3107_BRG13_B230400 (0x000300 | 0x08)
325#define MAX3107_BRG13_B460800 (0x000100 | 0x0c)
326#define MAX3107_BRG13_B921600 (0x000100 | 0x1c)
327
328/* Baud rate generator configuration values for external clock 26MHz */
329#define MAX3107_BRG26_B300 (0x152800 | 0x0A)
330#define MAX3107_BRG26_B600 (0x0A9400 | 0x05)
331#define MAX3107_BRG26_B1200 (0x054A00 | 0x03)
332#define MAX3107_BRG26_B2400 (0x02A500 | 0x01)
333#define MAX3107_BRG26_B4800 (0x015200 | 0x09)
334#define MAX3107_BRG26_B9600 (0x00A900 | 0x04)
335#define MAX3107_BRG26_B19200 (0x005400 | 0x0A)
336#define MAX3107_BRG26_B38400 (0x002A00 | 0x05)
337#define MAX3107_BRG26_B57600 (0x001C00 | 0x03)
338#define MAX3107_BRG26_B115200 (0x000E00 | 0x02)
339#define MAX3107_BRG26_B230400 (0x000700 | 0x01)
340#define MAX3107_BRG26_B460800 (0x000300 | 0x08)
341#define MAX3107_BRG26_B921600 (0x000100 | 0x0C)
342
343/* Baud rate generator configuration values for internal clock */
344#define MAX3107_BRG13_IB300 (0x008000 | 0x00)
345#define MAX3107_BRG13_IB600 (0x004000 | 0x00)
346#define MAX3107_BRG13_IB1200 (0x002000 | 0x00)
347#define MAX3107_BRG13_IB2400 (0x001000 | 0x00)
348#define MAX3107_BRG13_IB4800 (0x000800 | 0x00)
349#define MAX3107_BRG13_IB9600 (0x000400 | 0x00)
350#define MAX3107_BRG13_IB19200 (0x000200 | 0x00)
351#define MAX3107_BRG13_IB38400 (0x000100 | 0x00)
352#define MAX3107_BRG13_IB57600 (0x000000 | 0x0B)
353#define MAX3107_BRG13_IB115200 (0x000000 | 0x05)
354#define MAX3107_BRG13_IB230400 (0x000000 | 0x03)
355#define MAX3107_BRG13_IB460800 (0x000000 | 0x00)
356#define MAX3107_BRG13_IB921600 (0x000000 | 0x00)
357
358
359struct baud_table {
360 int baud;
361 u32 new_brg;
362};
363
364struct max3107_port {
365 /* UART port structure */
366 struct uart_port port;
367
368 /* SPI device structure */
369 struct spi_device *spi;
370
371#if defined(CONFIG_GPIOLIB)
372 /* GPIO chip stucture */
373 struct gpio_chip chip;
374#endif
375
376 /* Workqueue that does all the magic */
377 struct workqueue_struct *workqueue;
378 struct work_struct work;
379
380 /* Lock for shared data */
381 spinlock_t data_lock;
382
383 /* Device configuration */
384 int ext_clk; /* 1 if external clock used */
385 int loopback; /* Current loopback mode state */
386 int baud; /* Current baud rate */
387
388 /* State flags */
389 int suspended; /* Indicates suspend mode */
390 int tx_fifo_empty; /* Flag for TX FIFO state */
391 int rx_enabled; /* Flag for receiver state */
392 int tx_enabled; /* Flag for transmitter state */
393
394 u16 irqen_reg; /* Current IRQ enable register value */
395 /* Shared data */
396 u16 mode1_reg; /* Current mode1 register value*/
397 int mode1_commit; /* Flag for setting new mode1 register value */
398 u16 lcr_reg; /* Current LCR register value */
399 int lcr_commit; /* Flag for setting new LCR register value */
400 u32 brg_cfg; /* Current Baud rate generator config */
401 int brg_commit; /* Flag for setting new baud rate generator
402 * config
403 */
404 struct baud_table *baud_tbl;
405 int handle_irq; /* Indicates that IRQ should be handled */
406
407 /* Rx buffer and str*/
408 u16 *rxbuf;
409 u8 *rxstr;
410 /* Tx buffer*/
411 u16 *txbuf;
412
413 struct max3107_plat *pdata; /* Platform data */
414};
415
416/* Platform data structure */
417struct max3107_plat {
418 /* Loopback mode enable */
419 int loopback;
420 /* External clock enable */
421 int ext_clk;
422 /* Called during the register initialisation */
423 void (*init)(struct max3107_port *s);
424 /* Called when the port is found and configured */
425 int (*configure)(struct max3107_port *s);
426 /* HW suspend function */
427 void (*hw_suspend) (struct max3107_port *s, int suspend);
428 /* Polling mode enable */
429 int polled_mode;
430 /* Polling period if polling mode enabled */
431 int poll_time;
432};
433
434extern int max3107_rw(struct max3107_port *s, u8 *tx, u8 *rx, int len);
435extern void max3107_hw_susp(struct max3107_port *s, int suspend);
436extern int max3107_probe(struct spi_device *spi, struct max3107_plat *pdata);
437extern int max3107_remove(struct spi_device *spi);
438extern int max3107_suspend(struct spi_device *spi, pm_message_t state);
439extern int max3107_resume(struct spi_device *spi);
440
441#endif /* _LINUX_SERIAL_MAX3107_H */
diff --git a/drivers/serial/mcf.c b/drivers/serial/mcf.c
index b5aaef965f24..3394b7cc1722 100644
--- a/drivers/serial/mcf.c
+++ b/drivers/serial/mcf.c
@@ -70,16 +70,14 @@ static unsigned int mcf_tx_empty(struct uart_port *port)
70static unsigned int mcf_get_mctrl(struct uart_port *port) 70static unsigned int mcf_get_mctrl(struct uart_port *port)
71{ 71{
72 struct mcf_uart *pp = container_of(port, struct mcf_uart, port); 72 struct mcf_uart *pp = container_of(port, struct mcf_uart, port);
73 unsigned long flags;
74 unsigned int sigs; 73 unsigned int sigs;
75 74
76 spin_lock_irqsave(&port->lock, flags);
77 sigs = (readb(port->membase + MCFUART_UIPR) & MCFUART_UIPR_CTS) ? 75 sigs = (readb(port->membase + MCFUART_UIPR) & MCFUART_UIPR_CTS) ?
78 0 : TIOCM_CTS; 76 0 : TIOCM_CTS;
79 sigs |= (pp->sigs & TIOCM_RTS); 77 sigs |= (pp->sigs & TIOCM_RTS);
80 sigs |= (mcf_getppdcd(port->line) ? TIOCM_CD : 0); 78 sigs |= (mcf_getppdcd(port->line) ? TIOCM_CD : 0);
81 sigs |= (mcf_getppdtr(port->line) ? TIOCM_DTR : 0); 79 sigs |= (mcf_getppdtr(port->line) ? TIOCM_DTR : 0);
82 spin_unlock_irqrestore(&port->lock, flags); 80
83 return sigs; 81 return sigs;
84} 82}
85 83
@@ -88,16 +86,13 @@ static unsigned int mcf_get_mctrl(struct uart_port *port)
88static void mcf_set_mctrl(struct uart_port *port, unsigned int sigs) 86static void mcf_set_mctrl(struct uart_port *port, unsigned int sigs)
89{ 87{
90 struct mcf_uart *pp = container_of(port, struct mcf_uart, port); 88 struct mcf_uart *pp = container_of(port, struct mcf_uart, port);
91 unsigned long flags;
92 89
93 spin_lock_irqsave(&port->lock, flags);
94 pp->sigs = sigs; 90 pp->sigs = sigs;
95 mcf_setppdtr(port->line, (sigs & TIOCM_DTR)); 91 mcf_setppdtr(port->line, (sigs & TIOCM_DTR));
96 if (sigs & TIOCM_RTS) 92 if (sigs & TIOCM_RTS)
97 writeb(MCFUART_UOP_RTS, port->membase + MCFUART_UOP1); 93 writeb(MCFUART_UOP_RTS, port->membase + MCFUART_UOP1);
98 else 94 else
99 writeb(MCFUART_UOP_RTS, port->membase + MCFUART_UOP0); 95 writeb(MCFUART_UOP_RTS, port->membase + MCFUART_UOP0);
100 spin_unlock_irqrestore(&port->lock, flags);
101} 96}
102 97
103/****************************************************************************/ 98/****************************************************************************/
@@ -105,12 +100,9 @@ static void mcf_set_mctrl(struct uart_port *port, unsigned int sigs)
105static void mcf_start_tx(struct uart_port *port) 100static void mcf_start_tx(struct uart_port *port)
106{ 101{
107 struct mcf_uart *pp = container_of(port, struct mcf_uart, port); 102 struct mcf_uart *pp = container_of(port, struct mcf_uart, port);
108 unsigned long flags;
109 103
110 spin_lock_irqsave(&port->lock, flags);
111 pp->imr |= MCFUART_UIR_TXREADY; 104 pp->imr |= MCFUART_UIR_TXREADY;
112 writeb(pp->imr, port->membase + MCFUART_UIMR); 105 writeb(pp->imr, port->membase + MCFUART_UIMR);
113 spin_unlock_irqrestore(&port->lock, flags);
114} 106}
115 107
116/****************************************************************************/ 108/****************************************************************************/
@@ -118,12 +110,9 @@ static void mcf_start_tx(struct uart_port *port)
118static void mcf_stop_tx(struct uart_port *port) 110static void mcf_stop_tx(struct uart_port *port)
119{ 111{
120 struct mcf_uart *pp = container_of(port, struct mcf_uart, port); 112 struct mcf_uart *pp = container_of(port, struct mcf_uart, port);
121 unsigned long flags;
122 113
123 spin_lock_irqsave(&port->lock, flags);
124 pp->imr &= ~MCFUART_UIR_TXREADY; 114 pp->imr &= ~MCFUART_UIR_TXREADY;
125 writeb(pp->imr, port->membase + MCFUART_UIMR); 115 writeb(pp->imr, port->membase + MCFUART_UIMR);
126 spin_unlock_irqrestore(&port->lock, flags);
127} 116}
128 117
129/****************************************************************************/ 118/****************************************************************************/
@@ -131,12 +120,9 @@ static void mcf_stop_tx(struct uart_port *port)
131static void mcf_stop_rx(struct uart_port *port) 120static void mcf_stop_rx(struct uart_port *port)
132{ 121{
133 struct mcf_uart *pp = container_of(port, struct mcf_uart, port); 122 struct mcf_uart *pp = container_of(port, struct mcf_uart, port);
134 unsigned long flags;
135 123
136 spin_lock_irqsave(&port->lock, flags);
137 pp->imr &= ~MCFUART_UIR_RXREADY; 124 pp->imr &= ~MCFUART_UIR_RXREADY;
138 writeb(pp->imr, port->membase + MCFUART_UIMR); 125 writeb(pp->imr, port->membase + MCFUART_UIMR);
139 spin_unlock_irqrestore(&port->lock, flags);
140} 126}
141 127
142/****************************************************************************/ 128/****************************************************************************/
@@ -366,13 +352,22 @@ static irqreturn_t mcf_interrupt(int irq, void *data)
366 struct uart_port *port = data; 352 struct uart_port *port = data;
367 struct mcf_uart *pp = container_of(port, struct mcf_uart, port); 353 struct mcf_uart *pp = container_of(port, struct mcf_uart, port);
368 unsigned int isr; 354 unsigned int isr;
355 irqreturn_t ret = IRQ_NONE;
369 356
370 isr = readb(port->membase + MCFUART_UISR) & pp->imr; 357 isr = readb(port->membase + MCFUART_UISR) & pp->imr;
371 if (isr & MCFUART_UIR_RXREADY) 358
359 spin_lock(&port->lock);
360 if (isr & MCFUART_UIR_RXREADY) {
372 mcf_rx_chars(pp); 361 mcf_rx_chars(pp);
373 if (isr & MCFUART_UIR_TXREADY) 362 ret = IRQ_HANDLED;
363 }
364 if (isr & MCFUART_UIR_TXREADY) {
374 mcf_tx_chars(pp); 365 mcf_tx_chars(pp);
375 return IRQ_HANDLED; 366 ret = IRQ_HANDLED;
367 }
368 spin_unlock(&port->lock);
369
370 return ret;
376} 371}
377 372
378/****************************************************************************/ 373/****************************************************************************/
diff --git a/drivers/serial/mfd.c b/drivers/serial/mfd.c
new file mode 100644
index 000000000000..bc9af503907f
--- /dev/null
+++ b/drivers/serial/mfd.c
@@ -0,0 +1,1498 @@
1/*
2 * mfd.c: driver for High Speed UART device of Intel Medfield platform
3 *
4 * Refer pxa.c, 8250.c and some other drivers in drivers/serial/
5 *
6 * (C) Copyright 2010 Intel Corporation
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
10 * as published by the Free Software Foundation; version 2
11 * of the License.
12 */
13
14/* Notes:
15 * 1. DMA channel allocation: 0/1 channel are assigned to port 0,
16 * 2/3 chan to port 1, 4/5 chan to port 3. Even number chans
17 * are used for RX, odd chans for TX
18 *
19 * 2. In A0 stepping, UART will not support TX half empty flag
20 *
21 * 3. The RI/DSR/DCD/DTR are not pinned out, DCD & DSR are always
22 * asserted, only when the HW is reset the DDCD and DDSR will
23 * be triggered
24 */
25
26#include <linux/module.h>
27#include <linux/init.h>
28#include <linux/console.h>
29#include <linux/sysrq.h>
30#include <linux/serial_reg.h>
31#include <linux/circ_buf.h>
32#include <linux/delay.h>
33#include <linux/interrupt.h>
34#include <linux/tty.h>
35#include <linux/tty_flip.h>
36#include <linux/serial_core.h>
37#include <linux/serial_mfd.h>
38#include <linux/dma-mapping.h>
39#include <linux/pci.h>
40#include <linux/io.h>
41#include <linux/debugfs.h>
42
43#define MFD_HSU_A0_STEPPING 1
44
45#define HSU_DMA_BUF_SIZE 2048
46
47#define chan_readl(chan, offset) readl(chan->reg + offset)
48#define chan_writel(chan, offset, val) writel(val, chan->reg + offset)
49
50#define mfd_readl(obj, offset) readl(obj->reg + offset)
51#define mfd_writel(obj, offset, val) writel(val, obj->reg + offset)
52
53#define HSU_DMA_TIMEOUT_CHECK_FREQ (HZ/10)
54
55struct hsu_dma_buffer {
56 u8 *buf;
57 dma_addr_t dma_addr;
58 u32 dma_size;
59 u32 ofs;
60};
61
62struct hsu_dma_chan {
63 u32 id;
64 enum dma_data_direction dirt;
65 struct uart_hsu_port *uport;
66 void __iomem *reg;
67 struct timer_list rx_timer; /* only needed by RX channel */
68};
69
70struct uart_hsu_port {
71 struct uart_port port;
72 unsigned char ier;
73 unsigned char lcr;
74 unsigned char mcr;
75 unsigned int lsr_break_flag;
76 char name[12];
77 int index;
78 struct device *dev;
79
80 struct hsu_dma_chan *txc;
81 struct hsu_dma_chan *rxc;
82 struct hsu_dma_buffer txbuf;
83 struct hsu_dma_buffer rxbuf;
84 int use_dma; /* flag for DMA/PIO */
85 int running;
86 int dma_tx_on;
87};
88
89/* Top level data structure of HSU */
90struct hsu_port {
91 void __iomem *reg;
92 unsigned long paddr;
93 unsigned long iolen;
94 u32 irq;
95
96 struct uart_hsu_port port[3];
97 struct hsu_dma_chan chans[10];
98
99 struct dentry *debugfs;
100};
101
102static inline unsigned int serial_in(struct uart_hsu_port *up, int offset)
103{
104 unsigned int val;
105
106 if (offset > UART_MSR) {
107 offset <<= 2;
108 val = readl(up->port.membase + offset);
109 } else
110 val = (unsigned int)readb(up->port.membase + offset);
111
112 return val;
113}
114
115static inline void serial_out(struct uart_hsu_port *up, int offset, int value)
116{
117 if (offset > UART_MSR) {
118 offset <<= 2;
119 writel(value, up->port.membase + offset);
120 } else {
121 unsigned char val = value & 0xff;
122 writeb(val, up->port.membase + offset);
123 }
124}
125
126#ifdef CONFIG_DEBUG_FS
127
128#define HSU_REGS_BUFSIZE 1024
129
130static int hsu_show_regs_open(struct inode *inode, struct file *file)
131{
132 file->private_data = inode->i_private;
133 return 0;
134}
135
136static ssize_t port_show_regs(struct file *file, char __user *user_buf,
137 size_t count, loff_t *ppos)
138{
139 struct uart_hsu_port *up = file->private_data;
140 char *buf;
141 u32 len = 0;
142 ssize_t ret;
143
144 buf = kzalloc(HSU_REGS_BUFSIZE, GFP_KERNEL);
145 if (!buf)
146 return 0;
147
148 len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,
149 "MFD HSU port[%d] regs:\n", up->index);
150
151 len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,
152 "=================================\n");
153 len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,
154 "IER: \t\t0x%08x\n", serial_in(up, UART_IER));
155 len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,
156 "IIR: \t\t0x%08x\n", serial_in(up, UART_IIR));
157 len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,
158 "LCR: \t\t0x%08x\n", serial_in(up, UART_LCR));
159 len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,
160 "MCR: \t\t0x%08x\n", serial_in(up, UART_MCR));
161 len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,
162 "LSR: \t\t0x%08x\n", serial_in(up, UART_LSR));
163 len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,
164 "MSR: \t\t0x%08x\n", serial_in(up, UART_MSR));
165 len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,
166 "FOR: \t\t0x%08x\n", serial_in(up, UART_FOR));
167 len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,
168 "PS: \t\t0x%08x\n", serial_in(up, UART_PS));
169 len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,
170 "MUL: \t\t0x%08x\n", serial_in(up, UART_MUL));
171 len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,
172 "DIV: \t\t0x%08x\n", serial_in(up, UART_DIV));
173
174 ret = simple_read_from_buffer(user_buf, count, ppos, buf, len);
175 kfree(buf);
176 return ret;
177}
178
179static ssize_t dma_show_regs(struct file *file, char __user *user_buf,
180 size_t count, loff_t *ppos)
181{
182 struct hsu_dma_chan *chan = file->private_data;
183 char *buf;
184 u32 len = 0;
185 ssize_t ret;
186
187 buf = kzalloc(HSU_REGS_BUFSIZE, GFP_KERNEL);
188 if (!buf)
189 return 0;
190
191 len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,
192 "MFD HSU DMA channel [%d] regs:\n", chan->id);
193
194 len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,
195 "=================================\n");
196 len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,
197 "CR: \t\t0x%08x\n", chan_readl(chan, HSU_CH_CR));
198 len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,
199 "DCR: \t\t0x%08x\n", chan_readl(chan, HSU_CH_DCR));
200 len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,
201 "BSR: \t\t0x%08x\n", chan_readl(chan, HSU_CH_BSR));
202 len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,
203 "MOTSR: \t\t0x%08x\n", chan_readl(chan, HSU_CH_MOTSR));
204 len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,
205 "D0SAR: \t\t0x%08x\n", chan_readl(chan, HSU_CH_D0SAR));
206 len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,
207 "D0TSR: \t\t0x%08x\n", chan_readl(chan, HSU_CH_D0TSR));
208 len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,
209 "D0SAR: \t\t0x%08x\n", chan_readl(chan, HSU_CH_D1SAR));
210 len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,
211 "D0TSR: \t\t0x%08x\n", chan_readl(chan, HSU_CH_D1TSR));
212 len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,
213 "D0SAR: \t\t0x%08x\n", chan_readl(chan, HSU_CH_D2SAR));
214 len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,
215 "D0TSR: \t\t0x%08x\n", chan_readl(chan, HSU_CH_D2TSR));
216 len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,
217 "D0SAR: \t\t0x%08x\n", chan_readl(chan, HSU_CH_D3SAR));
218 len += snprintf(buf + len, HSU_REGS_BUFSIZE - len,
219 "D0TSR: \t\t0x%08x\n", chan_readl(chan, HSU_CH_D3TSR));
220
221 ret = simple_read_from_buffer(user_buf, count, ppos, buf, len);
222 kfree(buf);
223 return ret;
224}
225
226static const struct file_operations port_regs_ops = {
227 .owner = THIS_MODULE,
228 .open = hsu_show_regs_open,
229 .read = port_show_regs,
230};
231
232static const struct file_operations dma_regs_ops = {
233 .owner = THIS_MODULE,
234 .open = hsu_show_regs_open,
235 .read = dma_show_regs,
236};
237
238static int hsu_debugfs_init(struct hsu_port *hsu)
239{
240 int i;
241 char name[32];
242
243 hsu->debugfs = debugfs_create_dir("hsu", NULL);
244 if (!hsu->debugfs)
245 return -ENOMEM;
246
247 for (i = 0; i < 3; i++) {
248 snprintf(name, sizeof(name), "port_%d_regs", i);
249 debugfs_create_file(name, S_IFREG | S_IRUGO,
250 hsu->debugfs, (void *)(&hsu->port[i]), &port_regs_ops);
251 }
252
253 for (i = 0; i < 6; i++) {
254 snprintf(name, sizeof(name), "dma_chan_%d_regs", i);
255 debugfs_create_file(name, S_IFREG | S_IRUGO,
256 hsu->debugfs, (void *)&hsu->chans[i], &dma_regs_ops);
257 }
258
259 return 0;
260}
261
262static void hsu_debugfs_remove(struct hsu_port *hsu)
263{
264 if (hsu->debugfs)
265 debugfs_remove_recursive(hsu->debugfs);
266}
267
268#else
269static inline int hsu_debugfs_init(struct hsu_port *hsu)
270{
271 return 0;
272}
273
274static inline void hsu_debugfs_remove(struct hsu_port *hsu)
275{
276}
277#endif /* CONFIG_DEBUG_FS */
278
279static void serial_hsu_enable_ms(struct uart_port *port)
280{
281 struct uart_hsu_port *up =
282 container_of(port, struct uart_hsu_port, port);
283
284 up->ier |= UART_IER_MSI;
285 serial_out(up, UART_IER, up->ier);
286}
287
288void hsu_dma_tx(struct uart_hsu_port *up)
289{
290 struct circ_buf *xmit = &up->port.state->xmit;
291 struct hsu_dma_buffer *dbuf = &up->txbuf;
292 int count;
293
294 /* test_and_set_bit may be better, but anyway it's in lock protected mode */
295 if (up->dma_tx_on)
296 return;
297
298 /* Update the circ buf info */
299 xmit->tail += dbuf->ofs;
300 xmit->tail &= UART_XMIT_SIZE - 1;
301
302 up->port.icount.tx += dbuf->ofs;
303 dbuf->ofs = 0;
304
305 /* Disable the channel */
306 chan_writel(up->txc, HSU_CH_CR, 0x0);
307
308 if (!uart_circ_empty(xmit) && !uart_tx_stopped(&up->port)) {
309 dma_sync_single_for_device(up->port.dev,
310 dbuf->dma_addr,
311 dbuf->dma_size,
312 DMA_TO_DEVICE);
313
314 count = CIRC_CNT_TO_END(xmit->head, xmit->tail, UART_XMIT_SIZE);
315 dbuf->ofs = count;
316
317 /* Reprogram the channel */
318 chan_writel(up->txc, HSU_CH_D0SAR, dbuf->dma_addr + xmit->tail);
319 chan_writel(up->txc, HSU_CH_D0TSR, count);
320
321 /* Reenable the channel */
322 chan_writel(up->txc, HSU_CH_DCR, 0x1
323 | (0x1 << 8)
324 | (0x1 << 16)
325 | (0x1 << 24));
326 up->dma_tx_on = 1;
327 chan_writel(up->txc, HSU_CH_CR, 0x1);
328 }
329
330 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
331 uart_write_wakeup(&up->port);
332}
333
334/* The buffer is already cache coherent */
335void hsu_dma_start_rx_chan(struct hsu_dma_chan *rxc, struct hsu_dma_buffer *dbuf)
336{
337 dbuf->ofs = 0;
338
339 chan_writel(rxc, HSU_CH_BSR, 32);
340 chan_writel(rxc, HSU_CH_MOTSR, 4);
341
342 chan_writel(rxc, HSU_CH_D0SAR, dbuf->dma_addr);
343 chan_writel(rxc, HSU_CH_D0TSR, dbuf->dma_size);
344 chan_writel(rxc, HSU_CH_DCR, 0x1 | (0x1 << 8)
345 | (0x1 << 16)
346 | (0x1 << 24) /* timeout bit, see HSU Errata 1 */
347 );
348 chan_writel(rxc, HSU_CH_CR, 0x3);
349
350 mod_timer(&rxc->rx_timer, jiffies + HSU_DMA_TIMEOUT_CHECK_FREQ);
351}
352
353/* Protected by spin_lock_irqsave(port->lock) */
354static void serial_hsu_start_tx(struct uart_port *port)
355{
356 struct uart_hsu_port *up =
357 container_of(port, struct uart_hsu_port, port);
358
359 if (up->use_dma) {
360 hsu_dma_tx(up);
361 } else if (!(up->ier & UART_IER_THRI)) {
362 up->ier |= UART_IER_THRI;
363 serial_out(up, UART_IER, up->ier);
364 }
365}
366
367static void serial_hsu_stop_tx(struct uart_port *port)
368{
369 struct uart_hsu_port *up =
370 container_of(port, struct uart_hsu_port, port);
371 struct hsu_dma_chan *txc = up->txc;
372
373 if (up->use_dma)
374 chan_writel(txc, HSU_CH_CR, 0x0);
375 else if (up->ier & UART_IER_THRI) {
376 up->ier &= ~UART_IER_THRI;
377 serial_out(up, UART_IER, up->ier);
378 }
379}
380
381/* This is always called in spinlock protected mode, so
382 * modify timeout timer is safe here */
383void hsu_dma_rx(struct uart_hsu_port *up, u32 int_sts)
384{
385 struct hsu_dma_buffer *dbuf = &up->rxbuf;
386 struct hsu_dma_chan *chan = up->rxc;
387 struct uart_port *port = &up->port;
388 struct tty_struct *tty = port->state->port.tty;
389 int count;
390
391 if (!tty)
392 return;
393
394 /*
395 * First need to know how many is already transferred,
396 * then check if its a timeout DMA irq, and return
397 * the trail bytes out, push them up and reenable the
398 * channel
399 */
400
401 /* Timeout IRQ, need wait some time, see Errata 2 */
402 if (int_sts & 0xf00)
403 udelay(2);
404
405 /* Stop the channel */
406 chan_writel(chan, HSU_CH_CR, 0x0);
407
408 count = chan_readl(chan, HSU_CH_D0SAR) - dbuf->dma_addr;
409 if (!count) {
410 /* Restart the channel before we leave */
411 chan_writel(chan, HSU_CH_CR, 0x3);
412 return;
413 }
414 del_timer(&chan->rx_timer);
415
416 dma_sync_single_for_cpu(port->dev, dbuf->dma_addr,
417 dbuf->dma_size, DMA_FROM_DEVICE);
418
419 /*
420 * Head will only wrap around when we recycle
421 * the DMA buffer, and when that happens, we
422 * explicitly set tail to 0. So head will
423 * always be greater than tail.
424 */
425 tty_insert_flip_string(tty, dbuf->buf, count);
426 port->icount.rx += count;
427
428 dma_sync_single_for_device(up->port.dev, dbuf->dma_addr,
429 dbuf->dma_size, DMA_FROM_DEVICE);
430
431 /* Reprogram the channel */
432 chan_writel(chan, HSU_CH_D0SAR, dbuf->dma_addr);
433 chan_writel(chan, HSU_CH_D0TSR, dbuf->dma_size);
434 chan_writel(chan, HSU_CH_DCR, 0x1
435 | (0x1 << 8)
436 | (0x1 << 16)
437 | (0x1 << 24) /* timeout bit, see HSU Errata 1 */
438 );
439 tty_flip_buffer_push(tty);
440
441 chan_writel(chan, HSU_CH_CR, 0x3);
442 chan->rx_timer.expires = jiffies + HSU_DMA_TIMEOUT_CHECK_FREQ;
443 add_timer(&chan->rx_timer);
444
445}
446
447static void serial_hsu_stop_rx(struct uart_port *port)
448{
449 struct uart_hsu_port *up =
450 container_of(port, struct uart_hsu_port, port);
451 struct hsu_dma_chan *chan = up->rxc;
452
453 if (up->use_dma)
454 chan_writel(chan, HSU_CH_CR, 0x2);
455 else {
456 up->ier &= ~UART_IER_RLSI;
457 up->port.read_status_mask &= ~UART_LSR_DR;
458 serial_out(up, UART_IER, up->ier);
459 }
460}
461
462static inline void receive_chars(struct uart_hsu_port *up, int *status)
463{
464 struct tty_struct *tty = up->port.state->port.tty;
465 unsigned int ch, flag;
466 unsigned int max_count = 256;
467
468 if (!tty)
469 return;
470
471 do {
472 ch = serial_in(up, UART_RX);
473 flag = TTY_NORMAL;
474 up->port.icount.rx++;
475
476 if (unlikely(*status & (UART_LSR_BI | UART_LSR_PE |
477 UART_LSR_FE | UART_LSR_OE))) {
478
479 dev_warn(up->dev, "We really rush into ERR/BI case"
480 "status = 0x%02x", *status);
481 /* For statistics only */
482 if (*status & UART_LSR_BI) {
483 *status &= ~(UART_LSR_FE | UART_LSR_PE);
484 up->port.icount.brk++;
485 /*
486 * We do the SysRQ and SAK checking
487 * here because otherwise the break
488 * may get masked by ignore_status_mask
489 * or read_status_mask.
490 */
491 if (uart_handle_break(&up->port))
492 goto ignore_char;
493 } else if (*status & UART_LSR_PE)
494 up->port.icount.parity++;
495 else if (*status & UART_LSR_FE)
496 up->port.icount.frame++;
497 if (*status & UART_LSR_OE)
498 up->port.icount.overrun++;
499
500 /* Mask off conditions which should be ignored. */
501 *status &= up->port.read_status_mask;
502
503#ifdef CONFIG_SERIAL_MFD_HSU_CONSOLE
504 if (up->port.cons &&
505 up->port.cons->index == up->port.line) {
506 /* Recover the break flag from console xmit */
507 *status |= up->lsr_break_flag;
508 up->lsr_break_flag = 0;
509 }
510#endif
511 if (*status & UART_LSR_BI) {
512 flag = TTY_BREAK;
513 } else if (*status & UART_LSR_PE)
514 flag = TTY_PARITY;
515 else if (*status & UART_LSR_FE)
516 flag = TTY_FRAME;
517 }
518
519 if (uart_handle_sysrq_char(&up->port, ch))
520 goto ignore_char;
521
522 uart_insert_char(&up->port, *status, UART_LSR_OE, ch, flag);
523 ignore_char:
524 *status = serial_in(up, UART_LSR);
525 } while ((*status & UART_LSR_DR) && max_count--);
526 tty_flip_buffer_push(tty);
527}
528
529static void transmit_chars(struct uart_hsu_port *up)
530{
531 struct circ_buf *xmit = &up->port.state->xmit;
532 int count;
533
534 if (up->port.x_char) {
535 serial_out(up, UART_TX, up->port.x_char);
536 up->port.icount.tx++;
537 up->port.x_char = 0;
538 return;
539 }
540 if (uart_circ_empty(xmit) || uart_tx_stopped(&up->port)) {
541 serial_hsu_stop_tx(&up->port);
542 return;
543 }
544
545#ifndef MFD_HSU_A0_STEPPING
546 count = up->port.fifosize / 2;
547#else
548 /*
549 * A0 only supports fully empty IRQ, and the first char written
550 * into it won't clear the EMPT bit, so we may need be cautious
551 * by useing a shorter buffer
552 */
553 count = up->port.fifosize - 4;
554#endif
555 do {
556 serial_out(up, UART_TX, xmit->buf[xmit->tail]);
557 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
558
559 up->port.icount.tx++;
560 if (uart_circ_empty(xmit))
561 break;
562 } while (--count > 0);
563
564 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
565 uart_write_wakeup(&up->port);
566
567 if (uart_circ_empty(xmit))
568 serial_hsu_stop_tx(&up->port);
569}
570
571static inline void check_modem_status(struct uart_hsu_port *up)
572{
573 int status;
574
575 status = serial_in(up, UART_MSR);
576
577 if ((status & UART_MSR_ANY_DELTA) == 0)
578 return;
579
580 if (status & UART_MSR_TERI)
581 up->port.icount.rng++;
582 if (status & UART_MSR_DDSR)
583 up->port.icount.dsr++;
584 /* We may only get DDCD when HW init and reset */
585 if (status & UART_MSR_DDCD)
586 uart_handle_dcd_change(&up->port, status & UART_MSR_DCD);
587 /* Will start/stop_tx accordingly */
588 if (status & UART_MSR_DCTS)
589 uart_handle_cts_change(&up->port, status & UART_MSR_CTS);
590
591 wake_up_interruptible(&up->port.state->port.delta_msr_wait);
592}
593
594/*
595 * This handles the interrupt from one port.
596 */
597static irqreturn_t port_irq(int irq, void *dev_id)
598{
599 struct uart_hsu_port *up = dev_id;
600 unsigned int iir, lsr;
601 unsigned long flags;
602
603 if (unlikely(!up->running))
604 return IRQ_NONE;
605
606 spin_lock_irqsave(&up->port.lock, flags);
607 if (up->use_dma) {
608 lsr = serial_in(up, UART_LSR);
609 if (unlikely(lsr & (UART_LSR_BI | UART_LSR_PE |
610 UART_LSR_FE | UART_LSR_OE)))
611 dev_warn(up->dev,
612 "Got lsr irq while using DMA, lsr = 0x%2x\n",
613 lsr);
614 check_modem_status(up);
615 spin_unlock_irqrestore(&up->port.lock, flags);
616 return IRQ_HANDLED;
617 }
618
619 iir = serial_in(up, UART_IIR);
620 if (iir & UART_IIR_NO_INT) {
621 spin_unlock_irqrestore(&up->port.lock, flags);
622 return IRQ_NONE;
623 }
624
625 lsr = serial_in(up, UART_LSR);
626 if (lsr & UART_LSR_DR)
627 receive_chars(up, &lsr);
628 check_modem_status(up);
629
630 /* lsr will be renewed during the receive_chars */
631 if (lsr & UART_LSR_THRE)
632 transmit_chars(up);
633
634 spin_unlock_irqrestore(&up->port.lock, flags);
635 return IRQ_HANDLED;
636}
637
638static inline void dma_chan_irq(struct hsu_dma_chan *chan)
639{
640 struct uart_hsu_port *up = chan->uport;
641 unsigned long flags;
642 u32 int_sts;
643
644 spin_lock_irqsave(&up->port.lock, flags);
645
646 if (!up->use_dma || !up->running)
647 goto exit;
648
649 /*
650 * No matter what situation, need read clear the IRQ status
651 * There is a bug, see Errata 5, HSD 2900918
652 */
653 int_sts = chan_readl(chan, HSU_CH_SR);
654
655 /* Rx channel */
656 if (chan->dirt == DMA_FROM_DEVICE)
657 hsu_dma_rx(up, int_sts);
658
659 /* Tx channel */
660 if (chan->dirt == DMA_TO_DEVICE) {
661 chan_writel(chan, HSU_CH_CR, 0x0);
662 up->dma_tx_on = 0;
663 hsu_dma_tx(up);
664 }
665
666exit:
667 spin_unlock_irqrestore(&up->port.lock, flags);
668 return;
669}
670
671static irqreturn_t dma_irq(int irq, void *dev_id)
672{
673 struct hsu_port *hsu = dev_id;
674 u32 int_sts, i;
675
676 int_sts = mfd_readl(hsu, HSU_GBL_DMAISR);
677
678 /* Currently we only have 6 channels may be used */
679 for (i = 0; i < 6; i++) {
680 if (int_sts & 0x1)
681 dma_chan_irq(&hsu->chans[i]);
682 int_sts >>= 1;
683 }
684
685 return IRQ_HANDLED;
686}
687
688static unsigned int serial_hsu_tx_empty(struct uart_port *port)
689{
690 struct uart_hsu_port *up =
691 container_of(port, struct uart_hsu_port, port);
692 unsigned long flags;
693 unsigned int ret;
694
695 spin_lock_irqsave(&up->port.lock, flags);
696 ret = serial_in(up, UART_LSR) & UART_LSR_TEMT ? TIOCSER_TEMT : 0;
697 spin_unlock_irqrestore(&up->port.lock, flags);
698
699 return ret;
700}
701
702static unsigned int serial_hsu_get_mctrl(struct uart_port *port)
703{
704 struct uart_hsu_port *up =
705 container_of(port, struct uart_hsu_port, port);
706 unsigned char status;
707 unsigned int ret;
708
709 status = serial_in(up, UART_MSR);
710
711 ret = 0;
712 if (status & UART_MSR_DCD)
713 ret |= TIOCM_CAR;
714 if (status & UART_MSR_RI)
715 ret |= TIOCM_RNG;
716 if (status & UART_MSR_DSR)
717 ret |= TIOCM_DSR;
718 if (status & UART_MSR_CTS)
719 ret |= TIOCM_CTS;
720 return ret;
721}
722
723static void serial_hsu_set_mctrl(struct uart_port *port, unsigned int mctrl)
724{
725 struct uart_hsu_port *up =
726 container_of(port, struct uart_hsu_port, port);
727 unsigned char mcr = 0;
728
729 if (mctrl & TIOCM_RTS)
730 mcr |= UART_MCR_RTS;
731 if (mctrl & TIOCM_DTR)
732 mcr |= UART_MCR_DTR;
733 if (mctrl & TIOCM_OUT1)
734 mcr |= UART_MCR_OUT1;
735 if (mctrl & TIOCM_OUT2)
736 mcr |= UART_MCR_OUT2;
737 if (mctrl & TIOCM_LOOP)
738 mcr |= UART_MCR_LOOP;
739
740 mcr |= up->mcr;
741
742 serial_out(up, UART_MCR, mcr);
743}
744
745static void serial_hsu_break_ctl(struct uart_port *port, int break_state)
746{
747 struct uart_hsu_port *up =
748 container_of(port, struct uart_hsu_port, port);
749 unsigned long flags;
750
751 spin_lock_irqsave(&up->port.lock, flags);
752 if (break_state == -1)
753 up->lcr |= UART_LCR_SBC;
754 else
755 up->lcr &= ~UART_LCR_SBC;
756 serial_out(up, UART_LCR, up->lcr);
757 spin_unlock_irqrestore(&up->port.lock, flags);
758}
759
760/*
761 * What special to do:
762 * 1. chose the 64B fifo mode
763 * 2. make sure not to select half empty mode for A0 stepping
764 * 3. start dma or pio depends on configuration
765 * 4. we only allocate dma memory when needed
766 */
767static int serial_hsu_startup(struct uart_port *port)
768{
769 struct uart_hsu_port *up =
770 container_of(port, struct uart_hsu_port, port);
771 unsigned long flags;
772
773 /*
774 * Clear the FIFO buffers and disable them.
775 * (they will be reenabled in set_termios())
776 */
777 serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO);
778 serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO |
779 UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT);
780 serial_out(up, UART_FCR, 0);
781
782 /* Clear the interrupt registers. */
783 (void) serial_in(up, UART_LSR);
784 (void) serial_in(up, UART_RX);
785 (void) serial_in(up, UART_IIR);
786 (void) serial_in(up, UART_MSR);
787
788 /* Now, initialize the UART, default is 8n1 */
789 serial_out(up, UART_LCR, UART_LCR_WLEN8);
790
791 spin_lock_irqsave(&up->port.lock, flags);
792
793 up->port.mctrl |= TIOCM_OUT2;
794 serial_hsu_set_mctrl(&up->port, up->port.mctrl);
795
796 /*
797 * Finally, enable interrupts. Note: Modem status interrupts
798 * are set via set_termios(), which will be occurring imminently
799 * anyway, so we don't enable them here.
800 */
801 if (!up->use_dma)
802 up->ier = UART_IER_RLSI | UART_IER_RDI | UART_IER_RTOIE;
803 else
804 up->ier = 0;
805 serial_out(up, UART_IER, up->ier);
806
807 spin_unlock_irqrestore(&up->port.lock, flags);
808
809 /* DMA init */
810 if (up->use_dma) {
811 struct hsu_dma_buffer *dbuf;
812 struct circ_buf *xmit = &port->state->xmit;
813
814 up->dma_tx_on = 0;
815
816 /* First allocate the RX buffer */
817 dbuf = &up->rxbuf;
818 dbuf->buf = kzalloc(HSU_DMA_BUF_SIZE, GFP_KERNEL);
819 if (!dbuf->buf) {
820 up->use_dma = 0;
821 goto exit;
822 }
823 dbuf->dma_addr = dma_map_single(port->dev,
824 dbuf->buf,
825 HSU_DMA_BUF_SIZE,
826 DMA_FROM_DEVICE);
827 dbuf->dma_size = HSU_DMA_BUF_SIZE;
828
829 /* Start the RX channel right now */
830 hsu_dma_start_rx_chan(up->rxc, dbuf);
831
832 /* Next init the TX DMA */
833 dbuf = &up->txbuf;
834 dbuf->buf = xmit->buf;
835 dbuf->dma_addr = dma_map_single(port->dev,
836 dbuf->buf,
837 UART_XMIT_SIZE,
838 DMA_TO_DEVICE);
839 dbuf->dma_size = UART_XMIT_SIZE;
840
841 /* This should not be changed all around */
842 chan_writel(up->txc, HSU_CH_BSR, 32);
843 chan_writel(up->txc, HSU_CH_MOTSR, 4);
844 dbuf->ofs = 0;
845 }
846
847exit:
848 /* And clear the interrupt registers again for luck. */
849 (void) serial_in(up, UART_LSR);
850 (void) serial_in(up, UART_RX);
851 (void) serial_in(up, UART_IIR);
852 (void) serial_in(up, UART_MSR);
853
854 up->running = 1;
855 return 0;
856}
857
858static void serial_hsu_shutdown(struct uart_port *port)
859{
860 struct uart_hsu_port *up =
861 container_of(port, struct uart_hsu_port, port);
862 unsigned long flags;
863
864 del_timer_sync(&up->rxc->rx_timer);
865
866 /* Disable interrupts from this port */
867 up->ier = 0;
868 serial_out(up, UART_IER, 0);
869 up->running = 0;
870
871 spin_lock_irqsave(&up->port.lock, flags);
872 up->port.mctrl &= ~TIOCM_OUT2;
873 serial_hsu_set_mctrl(&up->port, up->port.mctrl);
874 spin_unlock_irqrestore(&up->port.lock, flags);
875
876 /* Disable break condition and FIFOs */
877 serial_out(up, UART_LCR, serial_in(up, UART_LCR) & ~UART_LCR_SBC);
878 serial_out(up, UART_FCR, UART_FCR_ENABLE_FIFO |
879 UART_FCR_CLEAR_RCVR |
880 UART_FCR_CLEAR_XMIT);
881 serial_out(up, UART_FCR, 0);
882}
883
884static void
885serial_hsu_set_termios(struct uart_port *port, struct ktermios *termios,
886 struct ktermios *old)
887{
888 struct uart_hsu_port *up =
889 container_of(port, struct uart_hsu_port, port);
890 struct tty_struct *tty = port->state->port.tty;
891 unsigned char cval, fcr = 0;
892 unsigned long flags;
893 unsigned int baud, quot;
894 u32 mul = 0x3600;
895 u32 ps = 0x10;
896
897 switch (termios->c_cflag & CSIZE) {
898 case CS5:
899 cval = UART_LCR_WLEN5;
900 break;
901 case CS6:
902 cval = UART_LCR_WLEN6;
903 break;
904 case CS7:
905 cval = UART_LCR_WLEN7;
906 break;
907 default:
908 case CS8:
909 cval = UART_LCR_WLEN8;
910 break;
911 }
912
913 /* CMSPAR isn't supported by this driver */
914 if (tty)
915 tty->termios->c_cflag &= ~CMSPAR;
916
917 if (termios->c_cflag & CSTOPB)
918 cval |= UART_LCR_STOP;
919 if (termios->c_cflag & PARENB)
920 cval |= UART_LCR_PARITY;
921 if (!(termios->c_cflag & PARODD))
922 cval |= UART_LCR_EPAR;
923
924 /*
925 * For those basic low baud rate we can get the direct
926 * scalar from 2746800, like 115200 = 2746800/24, for those
927 * higher baud rate, we have to handle them case by case,
928 * but DIV reg is never touched as its default value 0x3d09
929 */
930 baud = uart_get_baud_rate(port, termios, old, 0, 4000000);
931 quot = uart_get_divisor(port, baud);
932
933 switch (baud) {
934 case 3500000:
935 mul = 0x3345;
936 ps = 0xC;
937 quot = 1;
938 break;
939 case 2500000:
940 mul = 0x2710;
941 ps = 0x10;
942 quot = 1;
943 break;
944 case 18432000:
945 mul = 0x2400;
946 ps = 0x10;
947 quot = 1;
948 break;
949 case 1500000:
950 mul = 0x1D4C;
951 ps = 0xc;
952 quot = 1;
953 break;
954 default:
955 ;
956 }
957
958 if ((up->port.uartclk / quot) < (2400 * 16))
959 fcr = UART_FCR_ENABLE_FIFO | UART_FCR_HSU_64_1B;
960 else if ((up->port.uartclk / quot) < (230400 * 16))
961 fcr = UART_FCR_ENABLE_FIFO | UART_FCR_HSU_64_16B;
962 else
963 fcr = UART_FCR_ENABLE_FIFO | UART_FCR_HSU_64_32B;
964
965 fcr |= UART_FCR_HSU_64B_FIFO;
966#ifdef MFD_HSU_A0_STEPPING
967 /* A0 doesn't support half empty IRQ */
968 fcr |= UART_FCR_FULL_EMPT_TXI;
969#endif
970
971 /*
972 * Ok, we're now changing the port state. Do it with
973 * interrupts disabled.
974 */
975 spin_lock_irqsave(&up->port.lock, flags);
976
977 /* Update the per-port timeout */
978 uart_update_timeout(port, termios->c_cflag, baud);
979
980 up->port.read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR;
981 if (termios->c_iflag & INPCK)
982 up->port.read_status_mask |= UART_LSR_FE | UART_LSR_PE;
983 if (termios->c_iflag & (BRKINT | PARMRK))
984 up->port.read_status_mask |= UART_LSR_BI;
985
986 /* Characters to ignore */
987 up->port.ignore_status_mask = 0;
988 if (termios->c_iflag & IGNPAR)
989 up->port.ignore_status_mask |= UART_LSR_PE | UART_LSR_FE;
990 if (termios->c_iflag & IGNBRK) {
991 up->port.ignore_status_mask |= UART_LSR_BI;
992 /*
993 * If we're ignoring parity and break indicators,
994 * ignore overruns too (for real raw support).
995 */
996 if (termios->c_iflag & IGNPAR)
997 up->port.ignore_status_mask |= UART_LSR_OE;
998 }
999
1000 /* Ignore all characters if CREAD is not set */
1001 if ((termios->c_cflag & CREAD) == 0)
1002 up->port.ignore_status_mask |= UART_LSR_DR;
1003
1004 /*
1005 * CTS flow control flag and modem status interrupts, disable
1006 * MSI by default
1007 */
1008 up->ier &= ~UART_IER_MSI;
1009 if (UART_ENABLE_MS(&up->port, termios->c_cflag))
1010 up->ier |= UART_IER_MSI;
1011
1012 serial_out(up, UART_IER, up->ier);
1013
1014 if (termios->c_cflag & CRTSCTS)
1015 up->mcr |= UART_MCR_AFE | UART_MCR_RTS;
1016 else
1017 up->mcr &= ~UART_MCR_AFE;
1018
1019 serial_out(up, UART_LCR, cval | UART_LCR_DLAB); /* set DLAB */
1020 serial_out(up, UART_DLL, quot & 0xff); /* LS of divisor */
1021 serial_out(up, UART_DLM, quot >> 8); /* MS of divisor */
1022 serial_out(up, UART_LCR, cval); /* reset DLAB */
1023 serial_out(up, UART_MUL, mul); /* set MUL */
1024 serial_out(up, UART_PS, ps); /* set PS */
1025 up->lcr = cval; /* Save LCR */
1026 serial_hsu_set_mctrl(&up->port, up->port.mctrl);
1027 serial_out(up, UART_FCR, fcr);
1028 spin_unlock_irqrestore(&up->port.lock, flags);
1029}
1030
1031static void
1032serial_hsu_pm(struct uart_port *port, unsigned int state,
1033 unsigned int oldstate)
1034{
1035}
1036
1037static void serial_hsu_release_port(struct uart_port *port)
1038{
1039}
1040
1041static int serial_hsu_request_port(struct uart_port *port)
1042{
1043 return 0;
1044}
1045
1046static void serial_hsu_config_port(struct uart_port *port, int flags)
1047{
1048 struct uart_hsu_port *up =
1049 container_of(port, struct uart_hsu_port, port);
1050 up->port.type = PORT_MFD;
1051}
1052
1053static int
1054serial_hsu_verify_port(struct uart_port *port, struct serial_struct *ser)
1055{
1056 /* We don't want the core code to modify any port params */
1057 return -EINVAL;
1058}
1059
1060static const char *
1061serial_hsu_type(struct uart_port *port)
1062{
1063 struct uart_hsu_port *up =
1064 container_of(port, struct uart_hsu_port, port);
1065 return up->name;
1066}
1067
1068/* Mainly for uart console use */
1069static struct uart_hsu_port *serial_hsu_ports[3];
1070static struct uart_driver serial_hsu_reg;
1071
1072#ifdef CONFIG_SERIAL_MFD_HSU_CONSOLE
1073
1074#define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
1075
1076/* Wait for transmitter & holding register to empty */
1077static inline void wait_for_xmitr(struct uart_hsu_port *up)
1078{
1079 unsigned int status, tmout = 1000;
1080
1081 /* Wait up to 1ms for the character to be sent. */
1082 do {
1083 status = serial_in(up, UART_LSR);
1084
1085 if (status & UART_LSR_BI)
1086 up->lsr_break_flag = UART_LSR_BI;
1087
1088 if (--tmout == 0)
1089 break;
1090 udelay(1);
1091 } while (!(status & BOTH_EMPTY));
1092
1093 /* Wait up to 1s for flow control if necessary */
1094 if (up->port.flags & UPF_CONS_FLOW) {
1095 tmout = 1000000;
1096 while (--tmout &&
1097 ((serial_in(up, UART_MSR) & UART_MSR_CTS) == 0))
1098 udelay(1);
1099 }
1100}
1101
1102static void serial_hsu_console_putchar(struct uart_port *port, int ch)
1103{
1104 struct uart_hsu_port *up =
1105 container_of(port, struct uart_hsu_port, port);
1106
1107 wait_for_xmitr(up);
1108 serial_out(up, UART_TX, ch);
1109}
1110
1111/*
1112 * Print a string to the serial port trying not to disturb
1113 * any possible real use of the port...
1114 *
1115 * The console_lock must be held when we get here.
1116 */
1117static void
1118serial_hsu_console_write(struct console *co, const char *s, unsigned int count)
1119{
1120 struct uart_hsu_port *up = serial_hsu_ports[co->index];
1121 unsigned long flags;
1122 unsigned int ier;
1123 int locked = 1;
1124
1125 local_irq_save(flags);
1126 if (up->port.sysrq)
1127 locked = 0;
1128 else if (oops_in_progress) {
1129 locked = spin_trylock(&up->port.lock);
1130 } else
1131 spin_lock(&up->port.lock);
1132
1133 /* First save the IER then disable the interrupts */
1134 ier = serial_in(up, UART_IER);
1135 serial_out(up, UART_IER, 0);
1136
1137 uart_console_write(&up->port, s, count, serial_hsu_console_putchar);
1138
1139 /*
1140 * Finally, wait for transmitter to become empty
1141 * and restore the IER
1142 */
1143 wait_for_xmitr(up);
1144 serial_out(up, UART_IER, ier);
1145
1146 if (locked)
1147 spin_unlock(&up->port.lock);
1148 local_irq_restore(flags);
1149}
1150
1151static struct console serial_hsu_console;
1152
1153static int __init
1154serial_hsu_console_setup(struct console *co, char *options)
1155{
1156 struct uart_hsu_port *up;
1157 int baud = 115200;
1158 int bits = 8;
1159 int parity = 'n';
1160 int flow = 'n';
1161 int ret;
1162
1163 if (co->index == -1 || co->index >= serial_hsu_reg.nr)
1164 co->index = 0;
1165 up = serial_hsu_ports[co->index];
1166 if (!up)
1167 return -ENODEV;
1168
1169 if (options)
1170 uart_parse_options(options, &baud, &parity, &bits, &flow);
1171
1172 ret = uart_set_options(&up->port, co, baud, parity, bits, flow);
1173
1174 return ret;
1175}
1176
1177static struct console serial_hsu_console = {
1178 .name = "ttyMFD",
1179 .write = serial_hsu_console_write,
1180 .device = uart_console_device,
1181 .setup = serial_hsu_console_setup,
1182 .flags = CON_PRINTBUFFER,
1183 .index = 2,
1184 .data = &serial_hsu_reg,
1185};
1186#endif
1187
1188struct uart_ops serial_hsu_pops = {
1189 .tx_empty = serial_hsu_tx_empty,
1190 .set_mctrl = serial_hsu_set_mctrl,
1191 .get_mctrl = serial_hsu_get_mctrl,
1192 .stop_tx = serial_hsu_stop_tx,
1193 .start_tx = serial_hsu_start_tx,
1194 .stop_rx = serial_hsu_stop_rx,
1195 .enable_ms = serial_hsu_enable_ms,
1196 .break_ctl = serial_hsu_break_ctl,
1197 .startup = serial_hsu_startup,
1198 .shutdown = serial_hsu_shutdown,
1199 .set_termios = serial_hsu_set_termios,
1200 .pm = serial_hsu_pm,
1201 .type = serial_hsu_type,
1202 .release_port = serial_hsu_release_port,
1203 .request_port = serial_hsu_request_port,
1204 .config_port = serial_hsu_config_port,
1205 .verify_port = serial_hsu_verify_port,
1206};
1207
1208static struct uart_driver serial_hsu_reg = {
1209 .owner = THIS_MODULE,
1210 .driver_name = "MFD serial",
1211 .dev_name = "ttyMFD",
1212 .major = TTY_MAJOR,
1213 .minor = 128,
1214 .nr = 3,
1215};
1216
1217#ifdef CONFIG_PM
1218static int serial_hsu_suspend(struct pci_dev *pdev, pm_message_t state)
1219{
1220 void *priv = pci_get_drvdata(pdev);
1221 struct uart_hsu_port *up;
1222
1223 /* Make sure this is not the internal dma controller */
1224 if (priv && (pdev->device != 0x081E)) {
1225 up = priv;
1226 uart_suspend_port(&serial_hsu_reg, &up->port);
1227 }
1228
1229 pci_save_state(pdev);
1230 pci_set_power_state(pdev, pci_choose_state(pdev, state));
1231 return 0;
1232}
1233
1234static int serial_hsu_resume(struct pci_dev *pdev)
1235{
1236 void *priv = pci_get_drvdata(pdev);
1237 struct uart_hsu_port *up;
1238 int ret;
1239
1240 pci_set_power_state(pdev, PCI_D0);
1241 pci_restore_state(pdev);
1242
1243 ret = pci_enable_device(pdev);
1244 if (ret)
1245 dev_warn(&pdev->dev,
1246 "HSU: can't re-enable device, try to continue\n");
1247
1248 if (priv && (pdev->device != 0x081E)) {
1249 up = priv;
1250 uart_resume_port(&serial_hsu_reg, &up->port);
1251 }
1252 return 0;
1253}
1254#else
1255#define serial_hsu_suspend NULL
1256#define serial_hsu_resume NULL
1257#endif
1258
1259/* temp global pointer before we settle down on using one or four PCI dev */
1260static struct hsu_port *phsu;
1261
1262static int serial_hsu_probe(struct pci_dev *pdev,
1263 const struct pci_device_id *ent)
1264{
1265 struct uart_hsu_port *uport;
1266 int index, ret;
1267
1268 printk(KERN_INFO "HSU: found PCI Serial controller(ID: %04x:%04x)\n",
1269 pdev->vendor, pdev->device);
1270
1271 switch (pdev->device) {
1272 case 0x081B:
1273 index = 0;
1274 break;
1275 case 0x081C:
1276 index = 1;
1277 break;
1278 case 0x081D:
1279 index = 2;
1280 break;
1281 case 0x081E:
1282 /* internal DMA controller */
1283 index = 3;
1284 break;
1285 default:
1286 dev_err(&pdev->dev, "HSU: out of index!");
1287 return -ENODEV;
1288 }
1289
1290 ret = pci_enable_device(pdev);
1291 if (ret)
1292 return ret;
1293
1294 if (index == 3) {
1295 /* DMA controller */
1296 ret = request_irq(pdev->irq, dma_irq, 0, "hsu_dma", phsu);
1297 if (ret) {
1298 dev_err(&pdev->dev, "can not get IRQ\n");
1299 goto err_disable;
1300 }
1301 pci_set_drvdata(pdev, phsu);
1302 } else {
1303 /* UART port 0~2 */
1304 uport = &phsu->port[index];
1305 uport->port.irq = pdev->irq;
1306 uport->port.dev = &pdev->dev;
1307 uport->dev = &pdev->dev;
1308
1309 ret = request_irq(pdev->irq, port_irq, 0, uport->name, uport);
1310 if (ret) {
1311 dev_err(&pdev->dev, "can not get IRQ\n");
1312 goto err_disable;
1313 }
1314 uart_add_one_port(&serial_hsu_reg, &uport->port);
1315
1316#ifdef CONFIG_SERIAL_MFD_HSU_CONSOLE
1317 if (index == 2) {
1318 register_console(&serial_hsu_console);
1319 uport->port.cons = &serial_hsu_console;
1320 }
1321#endif
1322 pci_set_drvdata(pdev, uport);
1323 }
1324
1325 return 0;
1326
1327err_disable:
1328 pci_disable_device(pdev);
1329 return ret;
1330}
1331
1332static void hsu_dma_rx_timeout(unsigned long data)
1333{
1334 struct hsu_dma_chan *chan = (void *)data;
1335 struct uart_hsu_port *up = chan->uport;
1336 struct hsu_dma_buffer *dbuf = &up->rxbuf;
1337 int count = 0;
1338 unsigned long flags;
1339
1340 spin_lock_irqsave(&up->port.lock, flags);
1341
1342 count = chan_readl(chan, HSU_CH_D0SAR) - dbuf->dma_addr;
1343
1344 if (!count) {
1345 mod_timer(&chan->rx_timer, jiffies + HSU_DMA_TIMEOUT_CHECK_FREQ);
1346 goto exit;
1347 }
1348
1349 hsu_dma_rx(up, 0);
1350exit:
1351 spin_unlock_irqrestore(&up->port.lock, flags);
1352}
1353
1354static void hsu_global_init(void)
1355{
1356 struct hsu_port *hsu;
1357 struct uart_hsu_port *uport;
1358 struct hsu_dma_chan *dchan;
1359 int i, ret;
1360
1361 hsu = kzalloc(sizeof(struct hsu_port), GFP_KERNEL);
1362 if (!hsu)
1363 return;
1364
1365 /* Get basic io resource and map it */
1366 hsu->paddr = 0xffa28000;
1367 hsu->iolen = 0x1000;
1368
1369 if (!(request_mem_region(hsu->paddr, hsu->iolen, "HSU global")))
1370 pr_warning("HSU: error in request mem region\n");
1371
1372 hsu->reg = ioremap_nocache((unsigned long)hsu->paddr, hsu->iolen);
1373 if (!hsu->reg) {
1374 pr_err("HSU: error in ioremap\n");
1375 ret = -ENOMEM;
1376 goto err_free_region;
1377 }
1378
1379 /* Initialise the 3 UART ports */
1380 uport = hsu->port;
1381 for (i = 0; i < 3; i++) {
1382 uport->port.type = PORT_MFD;
1383 uport->port.iotype = UPIO_MEM;
1384 uport->port.mapbase = (resource_size_t)hsu->paddr
1385 + HSU_PORT_REG_OFFSET
1386 + i * HSU_PORT_REG_LENGTH;
1387 uport->port.membase = hsu->reg + HSU_PORT_REG_OFFSET
1388 + i * HSU_PORT_REG_LENGTH;
1389
1390 sprintf(uport->name, "hsu_port%d", i);
1391 uport->port.fifosize = 64;
1392 uport->port.ops = &serial_hsu_pops;
1393 uport->port.line = i;
1394 uport->port.flags = UPF_IOREMAP;
1395 /* set the scalable maxim support rate to 2746800 bps */
1396 uport->port.uartclk = 115200 * 24 * 16;
1397
1398 uport->running = 0;
1399 uport->txc = &hsu->chans[i * 2];
1400 uport->rxc = &hsu->chans[i * 2 + 1];
1401
1402 serial_hsu_ports[i] = uport;
1403 uport->index = i;
1404 uport++;
1405 }
1406
1407 /* Initialise 6 dma channels */
1408 dchan = hsu->chans;
1409 for (i = 0; i < 6; i++) {
1410 dchan->id = i;
1411 dchan->dirt = (i & 0x1) ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
1412 dchan->uport = &hsu->port[i/2];
1413 dchan->reg = hsu->reg + HSU_DMA_CHANS_REG_OFFSET +
1414 i * HSU_DMA_CHANS_REG_LENGTH;
1415
1416 /* Work around for RX */
1417 if (dchan->dirt == DMA_FROM_DEVICE) {
1418 init_timer(&dchan->rx_timer);
1419 dchan->rx_timer.function = hsu_dma_rx_timeout;
1420 dchan->rx_timer.data = (unsigned long)dchan;
1421 }
1422 dchan++;
1423 }
1424
1425 phsu = hsu;
1426
1427 hsu_debugfs_init(hsu);
1428 return;
1429
1430err_free_region:
1431 release_mem_region(hsu->paddr, hsu->iolen);
1432 kfree(hsu);
1433 return;
1434}
1435
1436static void serial_hsu_remove(struct pci_dev *pdev)
1437{
1438 struct hsu_port *hsu;
1439 int i;
1440
1441 hsu = pci_get_drvdata(pdev);
1442 if (!hsu)
1443 return;
1444
1445 for (i = 0; i < 3; i++)
1446 uart_remove_one_port(&serial_hsu_reg, &hsu->port[i].port);
1447
1448 pci_set_drvdata(pdev, NULL);
1449 free_irq(hsu->irq, hsu);
1450 pci_disable_device(pdev);
1451}
1452
1453/* First 3 are UART ports, and the 4th is the DMA */
1454static const struct pci_device_id pci_ids[] __devinitdata = {
1455 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x081B) },
1456 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x081C) },
1457 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x081D) },
1458 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x081E) },
1459 {},
1460};
1461
1462static struct pci_driver hsu_pci_driver = {
1463 .name = "HSU serial",
1464 .id_table = pci_ids,
1465 .probe = serial_hsu_probe,
1466 .remove = __devexit_p(serial_hsu_remove),
1467 .suspend = serial_hsu_suspend,
1468 .resume = serial_hsu_resume,
1469};
1470
1471static int __init hsu_pci_init(void)
1472{
1473 int ret;
1474
1475 hsu_global_init();
1476
1477 ret = uart_register_driver(&serial_hsu_reg);
1478 if (ret)
1479 return ret;
1480
1481 return pci_register_driver(&hsu_pci_driver);
1482}
1483
1484static void __exit hsu_pci_exit(void)
1485{
1486 pci_unregister_driver(&hsu_pci_driver);
1487 uart_unregister_driver(&serial_hsu_reg);
1488
1489 hsu_debugfs_remove(phsu);
1490
1491 kfree(phsu);
1492}
1493
1494module_init(hsu_pci_init);
1495module_exit(hsu_pci_exit);
1496
1497MODULE_LICENSE("GPL v2");
1498MODULE_ALIAS("platform:medfield-hsu");
diff --git a/drivers/serial/mpc52xx_uart.c b/drivers/serial/mpc52xx_uart.c
index 1a88b363005c..8dedb266f143 100644
--- a/drivers/serial/mpc52xx_uart.c
+++ b/drivers/serial/mpc52xx_uart.c
@@ -1298,7 +1298,7 @@ static struct of_device_id mpc52xx_uart_of_match[] = {
1298}; 1298};
1299 1299
1300static int __devinit 1300static int __devinit
1301mpc52xx_uart_of_probe(struct of_device *op, const struct of_device_id *match) 1301mpc52xx_uart_of_probe(struct platform_device *op, const struct of_device_id *match)
1302{ 1302{
1303 int idx = -1; 1303 int idx = -1;
1304 unsigned int uartclk; 1304 unsigned int uartclk;
@@ -1369,7 +1369,7 @@ mpc52xx_uart_of_probe(struct of_device *op, const struct of_device_id *match)
1369} 1369}
1370 1370
1371static int 1371static int
1372mpc52xx_uart_of_remove(struct of_device *op) 1372mpc52xx_uart_of_remove(struct platform_device *op)
1373{ 1373{
1374 struct uart_port *port = dev_get_drvdata(&op->dev); 1374 struct uart_port *port = dev_get_drvdata(&op->dev);
1375 dev_set_drvdata(&op->dev, NULL); 1375 dev_set_drvdata(&op->dev, NULL);
@@ -1382,7 +1382,7 @@ mpc52xx_uart_of_remove(struct of_device *op)
1382 1382
1383#ifdef CONFIG_PM 1383#ifdef CONFIG_PM
1384static int 1384static int
1385mpc52xx_uart_of_suspend(struct of_device *op, pm_message_t state) 1385mpc52xx_uart_of_suspend(struct platform_device *op, pm_message_t state)
1386{ 1386{
1387 struct uart_port *port = (struct uart_port *) dev_get_drvdata(&op->dev); 1387 struct uart_port *port = (struct uart_port *) dev_get_drvdata(&op->dev);
1388 1388
@@ -1393,7 +1393,7 @@ mpc52xx_uart_of_suspend(struct of_device *op, pm_message_t state)
1393} 1393}
1394 1394
1395static int 1395static int
1396mpc52xx_uart_of_resume(struct of_device *op) 1396mpc52xx_uart_of_resume(struct platform_device *op)
1397{ 1397{
1398 struct uart_port *port = (struct uart_port *) dev_get_drvdata(&op->dev); 1398 struct uart_port *port = (struct uart_port *) dev_get_drvdata(&op->dev);
1399 1399
diff --git a/drivers/serial/mrst_max3110.c b/drivers/serial/mrst_max3110.c
new file mode 100644
index 000000000000..f6ad1ecbff79
--- /dev/null
+++ b/drivers/serial/mrst_max3110.c
@@ -0,0 +1,844 @@
1/*
2 * max3110.c - spi uart protocol driver for Maxim 3110 on Moorestown
3 *
4 * Copyright (C) Intel 2008 Feng Tang <feng.tang@intel.com>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20/*
21 * Note:
22 * 1. From Max3110 spec, the Rx FIFO has 8 words, while the Tx FIFO only has
23 * 1 word. If SPI master controller doesn't support sclk frequency change,
24 * then the char need be sent out one by one with some delay
25 *
26 * 2. Currently only RX availabe interrrupt is used, no need for waiting TXE
27 * interrupt for a low speed UART device
28 */
29
30#include <linux/module.h>
31#include <linux/ioport.h>
32#include <linux/init.h>
33#include <linux/console.h>
34#include <linux/sysrq.h>
35#include <linux/platform_device.h>
36#include <linux/tty.h>
37#include <linux/tty_flip.h>
38#include <linux/serial_core.h>
39#include <linux/serial_reg.h>
40
41#include <linux/kthread.h>
42#include <linux/delay.h>
43#include <asm/atomic.h>
44#include <linux/spi/spi.h>
45#include <linux/spi/dw_spi.h>
46
47#include "mrst_max3110.h"
48
49#define PR_FMT "mrst_max3110: "
50
51#define UART_TX_NEEDED 1
52#define CON_TX_NEEDED 2
53#define BIT_IRQ_PENDING 3
54
55struct uart_max3110 {
56 struct uart_port port;
57 struct spi_device *spi;
58 char *name;
59
60 wait_queue_head_t wq;
61 struct task_struct *main_thread;
62 struct task_struct *read_thread;
63 struct mutex thread_mutex;;
64
65 u32 baud;
66 u16 cur_conf;
67 u8 clock;
68 u8 parity, word_7bits;
69
70 unsigned long uart_flags;
71
72 /* console related */
73 struct circ_buf con_xmit;
74
75 /* irq related */
76 u16 irq;
77};
78
79/* global data structure, may need be removed */
80struct uart_max3110 *pmax;
81static inline void receive_char(struct uart_max3110 *max, u8 ch);
82static void receive_chars(struct uart_max3110 *max,
83 unsigned char *str, int len);
84static int max3110_read_multi(struct uart_max3110 *max, int len, u8 *buf);
85static void max3110_console_receive(struct uart_max3110 *max);
86
87int max3110_write_then_read(struct uart_max3110 *max,
88 const u8 *txbuf, u8 *rxbuf, unsigned len, int always_fast)
89{
90 struct spi_device *spi = max->spi;
91 struct spi_message message;
92 struct spi_transfer x;
93 int ret;
94
95 if (!txbuf || !rxbuf)
96 return -EINVAL;
97
98 spi_message_init(&message);
99 memset(&x, 0, sizeof x);
100 x.len = len;
101 x.tx_buf = txbuf;
102 x.rx_buf = rxbuf;
103 spi_message_add_tail(&x, &message);
104
105 if (always_fast)
106 x.speed_hz = 3125000;
107 else if (max->baud)
108 x.speed_hz = max->baud;
109
110 /* Do the i/o */
111 ret = spi_sync(spi, &message);
112 return ret;
113}
114
115/* Write a u16 to the device, and return one u16 read back */
116int max3110_out(struct uart_max3110 *max, const u16 out)
117{
118 u16 tmp;
119 int ret;
120
121 ret = max3110_write_then_read(max, (u8 *)&out, (u8 *)&tmp, 2, 1);
122 if (ret)
123 return ret;
124
125 /* If some valid data is read back */
126 if (tmp & MAX3110_READ_DATA_AVAILABLE)
127 receive_char(max, (tmp & 0xff));
128
129 return ret;
130}
131
132#define MAX_READ_LEN 20
133/*
134 * This is usually used to read data from SPIC RX FIFO, which doesn't
135 * need any delay like flushing character out. It returns how many
136 * valide bytes are read back
137 */
138static int max3110_read_multi(struct uart_max3110 *max, int len, u8 *buf)
139{
140 u16 out[MAX_READ_LEN], in[MAX_READ_LEN];
141 u8 *pbuf, valid_str[MAX_READ_LEN];
142 int i, j, bytelen;
143
144 if (len > MAX_READ_LEN) {
145 pr_err(PR_FMT "read len %d is too large\n", len);
146 return 0;
147 }
148
149 bytelen = len * 2;
150 memset(out, 0, bytelen);
151 memset(in, 0, bytelen);
152
153 if (max3110_write_then_read(max, (u8 *)out, (u8 *)in, bytelen, 1))
154 return 0;
155
156 /* If caller don't provide a buffer, then handle received char */
157 pbuf = buf ? buf : valid_str;
158
159 for (i = 0, j = 0; i < len; i++) {
160 if (in[i] & MAX3110_READ_DATA_AVAILABLE)
161 pbuf[j++] = (u8)(in[i] & 0xff);
162 }
163
164 if (j && (pbuf == valid_str))
165 receive_chars(max, valid_str, j);
166
167 return j;
168}
169
170static void serial_m3110_con_putchar(struct uart_port *port, int ch)
171{
172 struct uart_max3110 *max =
173 container_of(port, struct uart_max3110, port);
174 struct circ_buf *xmit = &max->con_xmit;
175
176 if (uart_circ_chars_free(xmit)) {
177 xmit->buf[xmit->head] = (char)ch;
178 xmit->head = (xmit->head + 1) & (PAGE_SIZE - 1);
179 }
180
181
182 if (!test_and_set_bit(CON_TX_NEEDED, &max->uart_flags))
183 wake_up_process(max->main_thread);
184}
185
186/*
187 * Print a string to the serial port trying not to disturb
188 * any possible real use of the port...
189 *
190 * The console_lock must be held when we get here.
191 */
192static void serial_m3110_con_write(struct console *co,
193 const char *s, unsigned int count)
194{
195 if (!pmax)
196 return;
197
198 uart_console_write(&pmax->port, s, count, serial_m3110_con_putchar);
199}
200
201static int __init
202serial_m3110_con_setup(struct console *co, char *options)
203{
204 struct uart_max3110 *max = pmax;
205 int baud = 115200;
206 int bits = 8;
207 int parity = 'n';
208 int flow = 'n';
209
210 pr_info(PR_FMT "setting up console\n");
211
212 if (!max) {
213 pr_err(PR_FMT "pmax is NULL, return");
214 return -ENODEV;
215 }
216
217 if (options)
218 uart_parse_options(options, &baud, &parity, &bits, &flow);
219
220 return uart_set_options(&max->port, co, baud, parity, bits, flow);
221}
222
223static struct tty_driver *serial_m3110_con_device(struct console *co,
224 int *index)
225{
226 struct uart_driver *p = co->data;
227 *index = co->index;
228 return p->tty_driver;
229}
230
231static struct uart_driver serial_m3110_reg;
232static struct console serial_m3110_console = {
233 .name = "ttyS",
234 .write = serial_m3110_con_write,
235 .device = serial_m3110_con_device,
236 .setup = serial_m3110_con_setup,
237 .flags = CON_PRINTBUFFER,
238 .index = -1,
239 .data = &serial_m3110_reg,
240};
241
242#define MRST_CONSOLE (&serial_m3110_console)
243
244static unsigned int serial_m3110_tx_empty(struct uart_port *port)
245{
246 return 1;
247}
248
249static void serial_m3110_stop_tx(struct uart_port *port)
250{
251 return;
252}
253
254/* stop_rx will be called in spin_lock env */
255static void serial_m3110_stop_rx(struct uart_port *port)
256{
257 return;
258}
259
260#define WORDS_PER_XFER 128
261static inline void send_circ_buf(struct uart_max3110 *max,
262 struct circ_buf *xmit)
263{
264 int len, left = 0;
265 u16 obuf[WORDS_PER_XFER], ibuf[WORDS_PER_XFER];
266 u8 valid_str[WORDS_PER_XFER];
267 int i, j;
268
269 while (!uart_circ_empty(xmit)) {
270 left = uart_circ_chars_pending(xmit);
271 while (left) {
272 len = (left >= WORDS_PER_XFER) ? WORDS_PER_XFER : left;
273
274 memset(obuf, 0, len * 2);
275 memset(ibuf, 0, len * 2);
276 for (i = 0; i < len; i++) {
277 obuf[i] = (u8)xmit->buf[xmit->tail] | WD_TAG;
278 xmit->tail = (xmit->tail + 1) &
279 (UART_XMIT_SIZE - 1);
280 }
281 max3110_write_then_read(max, (u8 *)obuf,
282 (u8 *)ibuf, len * 2, 0);
283
284 for (i = 0, j = 0; i < len; i++) {
285 if (ibuf[i] & MAX3110_READ_DATA_AVAILABLE)
286 valid_str[j++] = (u8)(ibuf[i] & 0xff);
287 }
288
289 if (j)
290 receive_chars(max, valid_str, j);
291
292 max->port.icount.tx += len;
293 left -= len;
294 }
295 }
296}
297
298static void transmit_char(struct uart_max3110 *max)
299{
300 struct uart_port *port = &max->port;
301 struct circ_buf *xmit = &port->state->xmit;
302
303 if (uart_circ_empty(xmit) || uart_tx_stopped(port))
304 return;
305
306 send_circ_buf(max, xmit);
307
308 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
309 uart_write_wakeup(port);
310
311 if (uart_circ_empty(xmit))
312 serial_m3110_stop_tx(port);
313}
314
315/* This will be called by uart_write() and tty_write, can't
316 * go to sleep */
317static void serial_m3110_start_tx(struct uart_port *port)
318{
319 struct uart_max3110 *max =
320 container_of(port, struct uart_max3110, port);
321
322 if (!test_and_set_bit(UART_TX_NEEDED, &max->uart_flags))
323 wake_up_process(max->main_thread);
324}
325
326static void receive_chars(struct uart_max3110 *max, unsigned char *str, int len)
327{
328 struct uart_port *port = &max->port;
329 struct tty_struct *tty;
330 int usable;
331
332 /* If uart is not opened, just return */
333 if (!port->state)
334 return;
335
336 tty = port->state->port.tty;
337 if (!tty)
338 return; /* receive some char before the tty is opened */
339
340 while (len) {
341 usable = tty_buffer_request_room(tty, len);
342 if (usable) {
343 tty_insert_flip_string(tty, str, usable);
344 str += usable;
345 port->icount.rx += usable;
346 tty_flip_buffer_push(tty);
347 }
348 len -= usable;
349 }
350}
351
352static inline void receive_char(struct uart_max3110 *max, u8 ch)
353{
354 receive_chars(max, &ch, 1);
355}
356
357static void max3110_console_receive(struct uart_max3110 *max)
358{
359 int loop = 1, num, total = 0;
360 u8 recv_buf[512], *pbuf;
361
362 pbuf = recv_buf;
363 do {
364 num = max3110_read_multi(max, 8, pbuf);
365
366 if (num) {
367 loop = 10;
368 pbuf += num;
369 total += num;
370
371 if (total >= 500) {
372 receive_chars(max, recv_buf, total);
373 pbuf = recv_buf;
374 total = 0;
375 }
376 }
377 } while (--loop);
378
379 if (total)
380 receive_chars(max, recv_buf, total);
381}
382
383static int max3110_main_thread(void *_max)
384{
385 struct uart_max3110 *max = _max;
386 wait_queue_head_t *wq = &max->wq;
387 int ret = 0;
388 struct circ_buf *xmit = &max->con_xmit;
389
390 init_waitqueue_head(wq);
391 pr_info(PR_FMT "start main thread\n");
392
393 do {
394 wait_event_interruptible(*wq, max->uart_flags || kthread_should_stop());
395
396 mutex_lock(&max->thread_mutex);
397
398 if (test_and_clear_bit(BIT_IRQ_PENDING, &max->uart_flags))
399 max3110_console_receive(max);
400
401 /* first handle console output */
402 if (test_and_clear_bit(CON_TX_NEEDED, &max->uart_flags))
403 send_circ_buf(max, xmit);
404
405 /* handle uart output */
406 if (test_and_clear_bit(UART_TX_NEEDED, &max->uart_flags))
407 transmit_char(max);
408
409 mutex_unlock(&max->thread_mutex);
410
411 } while (!kthread_should_stop());
412
413 return ret;
414}
415
416#ifdef CONFIG_MRST_MAX3110_IRQ
417static irqreturn_t serial_m3110_irq(int irq, void *dev_id)
418{
419 struct uart_max3110 *max = dev_id;
420
421 /* max3110's irq is a falling edge, not level triggered,
422 * so no need to disable the irq */
423 if (!test_and_set_bit(BIT_IRQ_PENDING, &max->uart_flags))
424 wake_up_process(max->main_thread);
425
426 return IRQ_HANDLED;
427}
428#else
429/* if don't use RX IRQ, then need a thread to polling read */
430static int max3110_read_thread(void *_max)
431{
432 struct uart_max3110 *max = _max;
433
434 pr_info(PR_FMT "start read thread\n");
435 do {
436 mutex_lock(&max->thread_mutex);
437 max3110_console_receive(max);
438 mutex_unlock(&max->thread_mutex);
439
440 set_current_state(TASK_INTERRUPTIBLE);
441 schedule_timeout(HZ / 20);
442 } while (!kthread_should_stop());
443
444 return 0;
445}
446#endif
447
448static int serial_m3110_startup(struct uart_port *port)
449{
450 struct uart_max3110 *max =
451 container_of(port, struct uart_max3110, port);
452 u16 config = 0;
453 int ret = 0;
454
455 if (port->line != 0)
456 pr_err(PR_FMT "uart port startup failed\n");
457
458 /* firstly disable all IRQ and config it to 115200, 8n1 */
459 config = WC_TAG | WC_FIFO_ENABLE
460 | WC_1_STOPBITS
461 | WC_8BIT_WORD
462 | WC_BAUD_DR2;
463 ret = max3110_out(max, config);
464
465 /* as we use thread to handle tx/rx, need set low latency */
466 port->state->port.tty->low_latency = 1;
467
468#ifdef CONFIG_MRST_MAX3110_IRQ
469 ret = request_irq(max->irq, serial_m3110_irq,
470 IRQ_TYPE_EDGE_FALLING, "max3110", max);
471 if (ret)
472 return ret;
473
474 /* enable RX IRQ only */
475 config |= WC_RXA_IRQ_ENABLE;
476 max3110_out(max, config);
477#else
478 /* if IRQ is disabled, start a read thread for input data */
479 max->read_thread =
480 kthread_run(max3110_read_thread, max, "max3110_read");
481#endif
482
483 max->cur_conf = config;
484 return 0;
485}
486
487static void serial_m3110_shutdown(struct uart_port *port)
488{
489 struct uart_max3110 *max =
490 container_of(port, struct uart_max3110, port);
491 u16 config;
492
493 if (max->read_thread) {
494 kthread_stop(max->read_thread);
495 max->read_thread = NULL;
496 }
497
498#ifdef CONFIG_MRST_MAX3110_IRQ
499 free_irq(max->irq, max);
500#endif
501
502 /* Disable interrupts from this port */
503 config = WC_TAG | WC_SW_SHDI;
504 max3110_out(max, config);
505}
506
507static void serial_m3110_release_port(struct uart_port *port)
508{
509}
510
511static int serial_m3110_request_port(struct uart_port *port)
512{
513 return 0;
514}
515
516static void serial_m3110_config_port(struct uart_port *port, int flags)
517{
518 /* give it fake type */
519 port->type = PORT_PXA;
520}
521
522static int
523serial_m3110_verify_port(struct uart_port *port, struct serial_struct *ser)
524{
525 /* we don't want the core code to modify any port params */
526 return -EINVAL;
527}
528
529
530static const char *serial_m3110_type(struct uart_port *port)
531{
532 struct uart_max3110 *max =
533 container_of(port, struct uart_max3110, port);
534 return max->name;
535}
536
537static void
538serial_m3110_set_termios(struct uart_port *port, struct ktermios *termios,
539 struct ktermios *old)
540{
541 struct uart_max3110 *max =
542 container_of(port, struct uart_max3110, port);
543 unsigned char cval;
544 unsigned int baud, parity = 0;
545 int clk_div = -1;
546 u16 new_conf = max->cur_conf;
547
548 switch (termios->c_cflag & CSIZE) {
549 case CS7:
550 cval = UART_LCR_WLEN7;
551 new_conf |= WC_7BIT_WORD;
552 break;
553 default:
554 case CS8:
555 cval = UART_LCR_WLEN8;
556 new_conf |= WC_8BIT_WORD;
557 break;
558 }
559
560 baud = uart_get_baud_rate(port, termios, old, 0, 230400);
561
562 /* first calc the div for 1.8MHZ clock case */
563 switch (baud) {
564 case 300:
565 clk_div = WC_BAUD_DR384;
566 break;
567 case 600:
568 clk_div = WC_BAUD_DR192;
569 break;
570 case 1200:
571 clk_div = WC_BAUD_DR96;
572 break;
573 case 2400:
574 clk_div = WC_BAUD_DR48;
575 break;
576 case 4800:
577 clk_div = WC_BAUD_DR24;
578 break;
579 case 9600:
580 clk_div = WC_BAUD_DR12;
581 break;
582 case 19200:
583 clk_div = WC_BAUD_DR6;
584 break;
585 case 38400:
586 clk_div = WC_BAUD_DR3;
587 break;
588 case 57600:
589 clk_div = WC_BAUD_DR2;
590 break;
591 case 115200:
592 clk_div = WC_BAUD_DR1;
593 break;
594 case 230400:
595 if (max->clock & MAX3110_HIGH_CLK)
596 break;
597 default:
598 /* pick the previous baud rate */
599 baud = max->baud;
600 clk_div = max->cur_conf & WC_BAUD_DIV_MASK;
601 tty_termios_encode_baud_rate(termios, baud, baud);
602 }
603
604 if (max->clock & MAX3110_HIGH_CLK) {
605 clk_div += 1;
606 /* high clk version max3110 doesn't support B300 */
607 if (baud == 300)
608 baud = 600;
609 if (baud == 230400)
610 clk_div = WC_BAUD_DR1;
611 tty_termios_encode_baud_rate(termios, baud, baud);
612 }
613
614 new_conf = (new_conf & ~WC_BAUD_DIV_MASK) | clk_div;
615 if (termios->c_cflag & CSTOPB)
616 new_conf |= WC_2_STOPBITS;
617 else
618 new_conf &= ~WC_2_STOPBITS;
619
620 if (termios->c_cflag & PARENB) {
621 new_conf |= WC_PARITY_ENABLE;
622 parity |= UART_LCR_PARITY;
623 } else
624 new_conf &= ~WC_PARITY_ENABLE;
625
626 if (!(termios->c_cflag & PARODD))
627 parity |= UART_LCR_EPAR;
628 max->parity = parity;
629
630 uart_update_timeout(port, termios->c_cflag, baud);
631
632 new_conf |= WC_TAG;
633 if (new_conf != max->cur_conf) {
634 max3110_out(max, new_conf);
635 max->cur_conf = new_conf;
636 max->baud = baud;
637 }
638}
639
640/* don't handle hw handshaking */
641static unsigned int serial_m3110_get_mctrl(struct uart_port *port)
642{
643 return TIOCM_DSR | TIOCM_CAR | TIOCM_DSR;
644}
645
646static void serial_m3110_set_mctrl(struct uart_port *port, unsigned int mctrl)
647{
648}
649
650static void serial_m3110_break_ctl(struct uart_port *port, int break_state)
651{
652}
653
654static void serial_m3110_pm(struct uart_port *port, unsigned int state,
655 unsigned int oldstate)
656{
657}
658
659static void serial_m3110_enable_ms(struct uart_port *port)
660{
661}
662
663struct uart_ops serial_m3110_ops = {
664 .tx_empty = serial_m3110_tx_empty,
665 .set_mctrl = serial_m3110_set_mctrl,
666 .get_mctrl = serial_m3110_get_mctrl,
667 .stop_tx = serial_m3110_stop_tx,
668 .start_tx = serial_m3110_start_tx,
669 .stop_rx = serial_m3110_stop_rx,
670 .enable_ms = serial_m3110_enable_ms,
671 .break_ctl = serial_m3110_break_ctl,
672 .startup = serial_m3110_startup,
673 .shutdown = serial_m3110_shutdown,
674 .set_termios = serial_m3110_set_termios, /* must have */
675 .pm = serial_m3110_pm,
676 .type = serial_m3110_type,
677 .release_port = serial_m3110_release_port,
678 .request_port = serial_m3110_request_port,
679 .config_port = serial_m3110_config_port,
680 .verify_port = serial_m3110_verify_port,
681};
682
683static struct uart_driver serial_m3110_reg = {
684 .owner = THIS_MODULE,
685 .driver_name = "MRST serial",
686 .dev_name = "ttyS",
687 .major = TTY_MAJOR,
688 .minor = 64,
689 .nr = 1,
690 .cons = MRST_CONSOLE,
691};
692
693static int serial_m3110_suspend(struct spi_device *spi, pm_message_t state)
694{
695 return 0;
696}
697
698static int serial_m3110_resume(struct spi_device *spi)
699{
700 return 0;
701}
702
703static struct dw_spi_chip spi0_uart = {
704 .poll_mode = 1,
705 .enable_dma = 0,
706 .type = SPI_FRF_SPI,
707};
708
709static int serial_m3110_probe(struct spi_device *spi)
710{
711 struct uart_max3110 *max;
712 int ret;
713 unsigned char *buffer;
714 u16 res;
715 max = kzalloc(sizeof(*max), GFP_KERNEL);
716 if (!max)
717 return -ENOMEM;
718
719 /* set spi info */
720 spi->mode = SPI_MODE_0;
721 spi->bits_per_word = 16;
722 max->clock = MAX3110_HIGH_CLK;
723 spi->controller_data = &spi0_uart;
724
725 spi_setup(spi);
726
727 max->port.type = PORT_PXA; /* need apply for a max3110 type */
728 max->port.fifosize = 2; /* only have 16b buffer */
729 max->port.ops = &serial_m3110_ops;
730 max->port.line = 0;
731 max->port.dev = &spi->dev;
732 max->port.uartclk = 115200;
733
734 max->spi = spi;
735 max->name = spi->modalias; /* use spi name as the name */
736 max->irq = (u16)spi->irq;
737
738 mutex_init(&max->thread_mutex);
739
740 max->word_7bits = 0;
741 max->parity = 0;
742 max->baud = 0;
743
744 max->cur_conf = 0;
745 max->uart_flags = 0;
746
747 /* Check if reading configuration register returns something sane */
748
749 res = RC_TAG;
750 ret = max3110_write_then_read(max, (u8 *)&res, (u8 *)&res, 2, 0);
751 if (ret < 0 || res == 0 || res == 0xffff) {
752 printk(KERN_ERR "MAX3111 deemed not present (conf reg %04x)",
753 res);
754 ret = -ENODEV;
755 goto err_get_page;
756 }
757 buffer = (unsigned char *)__get_free_page(GFP_KERNEL);
758 if (!buffer) {
759 ret = -ENOMEM;
760 goto err_get_page;
761 }
762 max->con_xmit.buf = (unsigned char *)buffer;
763 max->con_xmit.head = max->con_xmit.tail = 0;
764
765 max->main_thread = kthread_run(max3110_main_thread,
766 max, "max3110_main");
767 if (IS_ERR(max->main_thread)) {
768 ret = PTR_ERR(max->main_thread);
769 goto err_kthread;
770 }
771
772 pmax = max;
773 /* give membase a psudo value to pass serial_core's check */
774 max->port.membase = (void *)0xff110000;
775 uart_add_one_port(&serial_m3110_reg, &max->port);
776
777 return 0;
778
779err_kthread:
780 free_page((unsigned long)buffer);
781err_get_page:
782 pmax = NULL;
783 kfree(max);
784 return ret;
785}
786
787static int max3110_remove(struct spi_device *dev)
788{
789 struct uart_max3110 *max = pmax;
790
791 if (!pmax)
792 return 0;
793
794 pmax = NULL;
795 uart_remove_one_port(&serial_m3110_reg, &max->port);
796
797 free_page((unsigned long)max->con_xmit.buf);
798
799 if (max->main_thread)
800 kthread_stop(max->main_thread);
801
802 kfree(max);
803 return 0;
804}
805
806static struct spi_driver uart_max3110_driver = {
807 .driver = {
808 .name = "spi_max3111",
809 .bus = &spi_bus_type,
810 .owner = THIS_MODULE,
811 },
812 .probe = serial_m3110_probe,
813 .remove = __devexit_p(max3110_remove),
814 .suspend = serial_m3110_suspend,
815 .resume = serial_m3110_resume,
816};
817
818
819int __init serial_m3110_init(void)
820{
821 int ret = 0;
822
823 ret = uart_register_driver(&serial_m3110_reg);
824 if (ret)
825 return ret;
826
827 ret = spi_register_driver(&uart_max3110_driver);
828 if (ret)
829 uart_unregister_driver(&serial_m3110_reg);
830
831 return ret;
832}
833
834void __exit serial_m3110_exit(void)
835{
836 spi_unregister_driver(&uart_max3110_driver);
837 uart_unregister_driver(&serial_m3110_reg);
838}
839
840module_init(serial_m3110_init);
841module_exit(serial_m3110_exit);
842
843MODULE_LICENSE("GPL");
844MODULE_ALIAS("max3110-uart");
diff --git a/drivers/serial/mrst_max3110.h b/drivers/serial/mrst_max3110.h
new file mode 100644
index 000000000000..363478acb2c3
--- /dev/null
+++ b/drivers/serial/mrst_max3110.h
@@ -0,0 +1,59 @@
1#ifndef _MRST_MAX3110_H
2#define _MRST_MAX3110_H
3
4#define MAX3110_HIGH_CLK 0x1 /* 3.6864 MHZ */
5#define MAX3110_LOW_CLK 0x0 /* 1.8432 MHZ */
6
7/* status bits for all 4 MAX3110 operate modes */
8#define MAX3110_READ_DATA_AVAILABLE (1 << 15)
9#define MAX3110_WRITE_BUF_EMPTY (1 << 14)
10
11#define WC_TAG (3 << 14)
12#define RC_TAG (1 << 14)
13#define WD_TAG (2 << 14)
14#define RD_TAG (0 << 14)
15
16/* bits def for write configuration */
17#define WC_FIFO_ENABLE_MASK (1 << 13)
18#define WC_FIFO_ENABLE (0 << 13)
19
20#define WC_SW_SHDI (1 << 12)
21
22#define WC_IRQ_MASK (0xF << 8)
23#define WC_TXE_IRQ_ENABLE (1 << 11) /* TX empty irq */
24#define WC_RXA_IRQ_ENABLE (1 << 10) /* RX availabe irq */
25#define WC_PAR_HIGH_IRQ_ENABLE (1 << 9)
26#define WC_REC_ACT_IRQ_ENABLE (1 << 8)
27
28#define WC_IRDA_ENABLE (1 << 7)
29
30#define WC_STOPBITS_MASK (1 << 6)
31#define WC_2_STOPBITS (1 << 6)
32#define WC_1_STOPBITS (0 << 6)
33
34#define WC_PARITY_ENABLE_MASK (1 << 5)
35#define WC_PARITY_ENABLE (1 << 5)
36
37#define WC_WORDLEN_MASK (1 << 4)
38#define WC_7BIT_WORD (1 << 4)
39#define WC_8BIT_WORD (0 << 4)
40
41#define WC_BAUD_DIV_MASK (0xF)
42#define WC_BAUD_DR1 (0x0)
43#define WC_BAUD_DR2 (0x1)
44#define WC_BAUD_DR4 (0x2)
45#define WC_BAUD_DR8 (0x3)
46#define WC_BAUD_DR16 (0x4)
47#define WC_BAUD_DR32 (0x5)
48#define WC_BAUD_DR64 (0x6)
49#define WC_BAUD_DR128 (0x7)
50#define WC_BAUD_DR3 (0x8)
51#define WC_BAUD_DR6 (0x9)
52#define WC_BAUD_DR12 (0xA)
53#define WC_BAUD_DR24 (0xB)
54#define WC_BAUD_DR48 (0xC)
55#define WC_BAUD_DR96 (0xD)
56#define WC_BAUD_DR192 (0xE)
57#define WC_BAUD_DR384 (0xF)
58
59#endif
diff --git a/drivers/serial/nwpserial.c b/drivers/serial/nwpserial.c
index e65b0d9202a5..de173671e3d0 100644
--- a/drivers/serial/nwpserial.c
+++ b/drivers/serial/nwpserial.c
@@ -344,7 +344,7 @@ int nwpserial_register_port(struct uart_port *port)
344 344
345 mutex_lock(&nwpserial_mutex); 345 mutex_lock(&nwpserial_mutex);
346 346
347 dn = to_of_device(port->dev)->dev.of_node; 347 dn = port->dev->of_node;
348 if (dn == NULL) 348 if (dn == NULL)
349 goto out; 349 goto out;
350 350
diff --git a/drivers/serial/of_serial.c b/drivers/serial/of_serial.c
index a48d9080f552..659a695bdad6 100644
--- a/drivers/serial/of_serial.c
+++ b/drivers/serial/of_serial.c
@@ -27,7 +27,7 @@ struct of_serial_info {
27/* 27/*
28 * Fill a struct uart_port for a given device node 28 * Fill a struct uart_port for a given device node
29 */ 29 */
30static int __devinit of_platform_serial_setup(struct of_device *ofdev, 30static int __devinit of_platform_serial_setup(struct platform_device *ofdev,
31 int type, struct uart_port *port) 31 int type, struct uart_port *port)
32{ 32{
33 struct resource resource; 33 struct resource resource;
@@ -80,7 +80,7 @@ static int __devinit of_platform_serial_setup(struct of_device *ofdev,
80/* 80/*
81 * Try to register a serial port 81 * Try to register a serial port
82 */ 82 */
83static int __devinit of_platform_serial_probe(struct of_device *ofdev, 83static int __devinit of_platform_serial_probe(struct platform_device *ofdev,
84 const struct of_device_id *id) 84 const struct of_device_id *id)
85{ 85{
86 struct of_serial_info *info; 86 struct of_serial_info *info;
@@ -134,7 +134,7 @@ out:
134/* 134/*
135 * Release a line 135 * Release a line
136 */ 136 */
137static int of_platform_serial_remove(struct of_device *ofdev) 137static int of_platform_serial_remove(struct platform_device *ofdev)
138{ 138{
139 struct of_serial_info *info = dev_get_drvdata(&ofdev->dev); 139 struct of_serial_info *info = dev_get_drvdata(&ofdev->dev);
140 switch (info->type) { 140 switch (info->type) {
diff --git a/drivers/serial/s5pv210.c b/drivers/serial/s5pv210.c
index 4a789e5361a4..6ebccd70a707 100644
--- a/drivers/serial/s5pv210.c
+++ b/drivers/serial/s5pv210.c
@@ -28,8 +28,12 @@
28static int s5pv210_serial_setsource(struct uart_port *port, 28static int s5pv210_serial_setsource(struct uart_port *port,
29 struct s3c24xx_uart_clksrc *clk) 29 struct s3c24xx_uart_clksrc *clk)
30{ 30{
31 struct s3c2410_uartcfg *cfg = port->dev->platform_data;
31 unsigned long ucon = rd_regl(port, S3C2410_UCON); 32 unsigned long ucon = rd_regl(port, S3C2410_UCON);
32 33
34 if ((cfg->clocks_size) == 1)
35 return 0;
36
33 if (strcmp(clk->name, "pclk") == 0) 37 if (strcmp(clk->name, "pclk") == 0)
34 ucon &= ~S5PV210_UCON_CLKMASK; 38 ucon &= ~S5PV210_UCON_CLKMASK;
35 else if (strcmp(clk->name, "uclk1") == 0) 39 else if (strcmp(clk->name, "uclk1") == 0)
@@ -47,10 +51,14 @@ static int s5pv210_serial_setsource(struct uart_port *port,
47static int s5pv210_serial_getsource(struct uart_port *port, 51static int s5pv210_serial_getsource(struct uart_port *port,
48 struct s3c24xx_uart_clksrc *clk) 52 struct s3c24xx_uart_clksrc *clk)
49{ 53{
54 struct s3c2410_uartcfg *cfg = port->dev->platform_data;
50 u32 ucon = rd_regl(port, S3C2410_UCON); 55 u32 ucon = rd_regl(port, S3C2410_UCON);
51 56
52 clk->divisor = 1; 57 clk->divisor = 1;
53 58
59 if ((cfg->clocks_size) == 1)
60 return 0;
61
54 switch (ucon & S5PV210_UCON_CLKMASK) { 62 switch (ucon & S5PV210_UCON_CLKMASK) {
55 case S5PV210_UCON_PCLK: 63 case S5PV210_UCON_PCLK:
56 clk->name = "pclk"; 64 clk->name = "pclk";
diff --git a/drivers/serial/samsung.c b/drivers/serial/samsung.c
index a9d6c5626a0a..b1156ba8ad14 100644
--- a/drivers/serial/samsung.c
+++ b/drivers/serial/samsung.c
@@ -705,8 +705,13 @@ static void s3c24xx_serial_set_termios(struct uart_port *port,
705 if (ourport->info->has_divslot) { 705 if (ourport->info->has_divslot) {
706 unsigned int div = ourport->baudclk_rate / baud; 706 unsigned int div = ourport->baudclk_rate / baud;
707 707
708 udivslot = udivslot_table[div & 15]; 708 if (cfg->has_fracval) {
709 dbg("udivslot = %04x (div %d)\n", udivslot, div & 15); 709 udivslot = (div & 15);
710 dbg("fracval = %04x\n", udivslot);
711 } else {
712 udivslot = udivslot_table[div & 15];
713 dbg("udivslot = %04x (div %d)\n", udivslot, div & 15);
714 }
710 } 715 }
711 716
712 switch (termios->c_cflag & CSIZE) { 717 switch (termios->c_cflag & CSIZE) {
diff --git a/drivers/serial/serial_core.c b/drivers/serial/serial_core.c
index 7f2830709512..cd8511298bcb 100644
--- a/drivers/serial/serial_core.c
+++ b/drivers/serial/serial_core.c
@@ -58,9 +58,9 @@ static struct lock_class_key port_lock_key;
58#define uart_console(port) (0) 58#define uart_console(port) (0)
59#endif 59#endif
60 60
61static void uart_change_speed(struct uart_state *state, 61static void uart_change_speed(struct tty_struct *tty, struct uart_state *state,
62 struct ktermios *old_termios); 62 struct ktermios *old_termios);
63static void uart_wait_until_sent(struct tty_struct *tty, int timeout); 63static void __uart_wait_until_sent(struct uart_port *port, int timeout);
64static void uart_change_pm(struct uart_state *state, int pm_state); 64static void uart_change_pm(struct uart_state *state, int pm_state);
65 65
66/* 66/*
@@ -137,7 +137,7 @@ uart_update_mctrl(struct uart_port *port, unsigned int set, unsigned int clear)
137 * Startup the port. This will be called once per open. All calls 137 * Startup the port. This will be called once per open. All calls
138 * will be serialised by the per-port mutex. 138 * will be serialised by the per-port mutex.
139 */ 139 */
140static int uart_startup(struct uart_state *state, int init_hw) 140static int uart_startup(struct tty_struct *tty, struct uart_state *state, int init_hw)
141{ 141{
142 struct uart_port *uport = state->uart_port; 142 struct uart_port *uport = state->uart_port;
143 struct tty_port *port = &state->port; 143 struct tty_port *port = &state->port;
@@ -152,7 +152,7 @@ static int uart_startup(struct uart_state *state, int init_hw)
152 * once we have successfully opened the port. Also set 152 * once we have successfully opened the port. Also set
153 * up the tty->alt_speed kludge 153 * up the tty->alt_speed kludge
154 */ 154 */
155 set_bit(TTY_IO_ERROR, &port->tty->flags); 155 set_bit(TTY_IO_ERROR, &tty->flags);
156 156
157 if (uport->type == PORT_UNKNOWN) 157 if (uport->type == PORT_UNKNOWN)
158 return 0; 158 return 0;
@@ -177,26 +177,26 @@ static int uart_startup(struct uart_state *state, int init_hw)
177 /* 177 /*
178 * Initialise the hardware port settings. 178 * Initialise the hardware port settings.
179 */ 179 */
180 uart_change_speed(state, NULL); 180 uart_change_speed(tty, state, NULL);
181 181
182 /* 182 /*
183 * Setup the RTS and DTR signals once the 183 * Setup the RTS and DTR signals once the
184 * port is open and ready to respond. 184 * port is open and ready to respond.
185 */ 185 */
186 if (port->tty->termios->c_cflag & CBAUD) 186 if (tty->termios->c_cflag & CBAUD)
187 uart_set_mctrl(uport, TIOCM_RTS | TIOCM_DTR); 187 uart_set_mctrl(uport, TIOCM_RTS | TIOCM_DTR);
188 } 188 }
189 189
190 if (port->flags & ASYNC_CTS_FLOW) { 190 if (port->flags & ASYNC_CTS_FLOW) {
191 spin_lock_irq(&uport->lock); 191 spin_lock_irq(&uport->lock);
192 if (!(uport->ops->get_mctrl(uport) & TIOCM_CTS)) 192 if (!(uport->ops->get_mctrl(uport) & TIOCM_CTS))
193 port->tty->hw_stopped = 1; 193 tty->hw_stopped = 1;
194 spin_unlock_irq(&uport->lock); 194 spin_unlock_irq(&uport->lock);
195 } 195 }
196 196
197 set_bit(ASYNCB_INITIALIZED, &port->flags); 197 set_bit(ASYNCB_INITIALIZED, &port->flags);
198 198
199 clear_bit(TTY_IO_ERROR, &port->tty->flags); 199 clear_bit(TTY_IO_ERROR, &tty->flags);
200 } 200 }
201 201
202 if (retval && capable(CAP_SYS_ADMIN)) 202 if (retval && capable(CAP_SYS_ADMIN))
@@ -210,11 +210,10 @@ static int uart_startup(struct uart_state *state, int init_hw)
210 * DTR is dropped if the hangup on close termio flag is on. Calls to 210 * DTR is dropped if the hangup on close termio flag is on. Calls to
211 * uart_shutdown are serialised by the per-port semaphore. 211 * uart_shutdown are serialised by the per-port semaphore.
212 */ 212 */
213static void uart_shutdown(struct uart_state *state) 213static void uart_shutdown(struct tty_struct *tty, struct uart_state *state)
214{ 214{
215 struct uart_port *uport = state->uart_port; 215 struct uart_port *uport = state->uart_port;
216 struct tty_port *port = &state->port; 216 struct tty_port *port = &state->port;
217 struct tty_struct *tty = port->tty;
218 217
219 /* 218 /*
220 * Set the TTY IO error marker 219 * Set the TTY IO error marker
@@ -430,11 +429,10 @@ uart_get_divisor(struct uart_port *port, unsigned int baud)
430EXPORT_SYMBOL(uart_get_divisor); 429EXPORT_SYMBOL(uart_get_divisor);
431 430
432/* FIXME: Consistent locking policy */ 431/* FIXME: Consistent locking policy */
433static void 432static void uart_change_speed(struct tty_struct *tty, struct uart_state *state,
434uart_change_speed(struct uart_state *state, struct ktermios *old_termios) 433 struct ktermios *old_termios)
435{ 434{
436 struct tty_port *port = &state->port; 435 struct tty_port *port = &state->port;
437 struct tty_struct *tty = port->tty;
438 struct uart_port *uport = state->uart_port; 436 struct uart_port *uport = state->uart_port;
439 struct ktermios *termios; 437 struct ktermios *termios;
440 438
@@ -463,8 +461,8 @@ uart_change_speed(struct uart_state *state, struct ktermios *old_termios)
463 uport->ops->set_termios(uport, termios, old_termios); 461 uport->ops->set_termios(uport, termios, old_termios);
464} 462}
465 463
466static inline int 464static inline int __uart_put_char(struct uart_port *port,
467__uart_put_char(struct uart_port *port, struct circ_buf *circ, unsigned char c) 465 struct circ_buf *circ, unsigned char c)
468{ 466{
469 unsigned long flags; 467 unsigned long flags;
470 int ret = 0; 468 int ret = 0;
@@ -494,8 +492,8 @@ static void uart_flush_chars(struct tty_struct *tty)
494 uart_start(tty); 492 uart_start(tty);
495} 493}
496 494
497static int 495static int uart_write(struct tty_struct *tty,
498uart_write(struct tty_struct *tty, const unsigned char *buf, int count) 496 const unsigned char *buf, int count)
499{ 497{
500 struct uart_state *state = tty->driver_data; 498 struct uart_state *state = tty->driver_data;
501 struct uart_port *port; 499 struct uart_port *port;
@@ -675,7 +673,7 @@ static int uart_get_info(struct uart_state *state,
675 return 0; 673 return 0;
676} 674}
677 675
678static int uart_set_info(struct uart_state *state, 676static int uart_set_info(struct tty_struct *tty, struct uart_state *state,
679 struct serial_struct __user *newinfo) 677 struct serial_struct __user *newinfo)
680{ 678{
681 struct serial_struct new_serial; 679 struct serial_struct new_serial;
@@ -770,7 +768,7 @@ static int uart_set_info(struct uart_state *state,
770 * We need to shutdown the serial port at the old 768 * We need to shutdown the serial port at the old
771 * port/type/irq combination. 769 * port/type/irq combination.
772 */ 770 */
773 uart_shutdown(state); 771 uart_shutdown(tty, state);
774 } 772 }
775 773
776 if (change_port) { 774 if (change_port) {
@@ -869,25 +867,27 @@ static int uart_set_info(struct uart_state *state,
869 "is deprecated.\n", current->comm, 867 "is deprecated.\n", current->comm,
870 tty_name(port->tty, buf)); 868 tty_name(port->tty, buf));
871 } 869 }
872 uart_change_speed(state, NULL); 870 uart_change_speed(tty, state, NULL);
873 } 871 }
874 } else 872 } else
875 retval = uart_startup(state, 1); 873 retval = uart_startup(tty, state, 1);
876 exit: 874 exit:
877 mutex_unlock(&port->mutex); 875 mutex_unlock(&port->mutex);
878 return retval; 876 return retval;
879} 877}
880 878
881 879/**
882/* 880 * uart_get_lsr_info - get line status register info
883 * uart_get_lsr_info - get line status register info. 881 * @tty: tty associated with the UART
884 * Note: uart_ioctl protects us against hangups. 882 * @state: UART being queried
883 * @value: returned modem value
884 *
885 * Note: uart_ioctl protects us against hangups.
885 */ 886 */
886static int uart_get_lsr_info(struct uart_state *state, 887static int uart_get_lsr_info(struct tty_struct *tty,
887 unsigned int __user *value) 888 struct uart_state *state, unsigned int __user *value)
888{ 889{
889 struct uart_port *uport = state->uart_port; 890 struct uart_port *uport = state->uart_port;
890 struct tty_port *port = &state->port;
891 unsigned int result; 891 unsigned int result;
892 892
893 result = uport->ops->tx_empty(uport); 893 result = uport->ops->tx_empty(uport);
@@ -900,7 +900,7 @@ static int uart_get_lsr_info(struct uart_state *state,
900 */ 900 */
901 if (uport->x_char || 901 if (uport->x_char ||
902 ((uart_circ_chars_pending(&state->xmit) > 0) && 902 ((uart_circ_chars_pending(&state->xmit) > 0) &&
903 !port->tty->stopped && !port->tty->hw_stopped)) 903 !tty->stopped && !tty->hw_stopped))
904 result &= ~TIOCSER_TEMT; 904 result &= ~TIOCSER_TEMT;
905 905
906 return put_user(result, value); 906 return put_user(result, value);
@@ -961,7 +961,7 @@ static int uart_break_ctl(struct tty_struct *tty, int break_state)
961 return 0; 961 return 0;
962} 962}
963 963
964static int uart_do_autoconfig(struct uart_state *state) 964static int uart_do_autoconfig(struct tty_struct *tty,struct uart_state *state)
965{ 965{
966 struct uart_port *uport = state->uart_port; 966 struct uart_port *uport = state->uart_port;
967 struct tty_port *port = &state->port; 967 struct tty_port *port = &state->port;
@@ -980,7 +980,7 @@ static int uart_do_autoconfig(struct uart_state *state)
980 980
981 ret = -EBUSY; 981 ret = -EBUSY;
982 if (tty_port_users(port) == 1) { 982 if (tty_port_users(port) == 1) {
983 uart_shutdown(state); 983 uart_shutdown(tty, state);
984 984
985 /* 985 /*
986 * If we already have a port type configured, 986 * If we already have a port type configured,
@@ -999,7 +999,7 @@ static int uart_do_autoconfig(struct uart_state *state)
999 */ 999 */
1000 uport->ops->config_port(uport, flags); 1000 uport->ops->config_port(uport, flags);
1001 1001
1002 ret = uart_startup(state, 1); 1002 ret = uart_startup(tty, state, 1);
1003 } 1003 }
1004 mutex_unlock(&port->mutex); 1004 mutex_unlock(&port->mutex);
1005 return ret; 1005 return ret;
@@ -1122,11 +1122,11 @@ uart_ioctl(struct tty_struct *tty, struct file *filp, unsigned int cmd,
1122 break; 1122 break;
1123 1123
1124 case TIOCSSERIAL: 1124 case TIOCSSERIAL:
1125 ret = uart_set_info(state, uarg); 1125 ret = uart_set_info(tty, state, uarg);
1126 break; 1126 break;
1127 1127
1128 case TIOCSERCONFIG: 1128 case TIOCSERCONFIG:
1129 ret = uart_do_autoconfig(state); 1129 ret = uart_do_autoconfig(tty, state);
1130 break; 1130 break;
1131 1131
1132 case TIOCSERGWILD: /* obsolete */ 1132 case TIOCSERGWILD: /* obsolete */
@@ -1172,7 +1172,7 @@ uart_ioctl(struct tty_struct *tty, struct file *filp, unsigned int cmd,
1172 */ 1172 */
1173 switch (cmd) { 1173 switch (cmd) {
1174 case TIOCSERGETLSR: /* Get line status register */ 1174 case TIOCSERGETLSR: /* Get line status register */
1175 ret = uart_get_lsr_info(state, uarg); 1175 ret = uart_get_lsr_info(tty, state, uarg);
1176 break; 1176 break;
1177 1177
1178 default: { 1178 default: {
@@ -1194,7 +1194,7 @@ static void uart_set_ldisc(struct tty_struct *tty)
1194 struct uart_port *uport = state->uart_port; 1194 struct uart_port *uport = state->uart_port;
1195 1195
1196 if (uport->ops->set_ldisc) 1196 if (uport->ops->set_ldisc)
1197 uport->ops->set_ldisc(uport); 1197 uport->ops->set_ldisc(uport, tty->termios->c_line);
1198} 1198}
1199 1199
1200static void uart_set_termios(struct tty_struct *tty, 1200static void uart_set_termios(struct tty_struct *tty,
@@ -1219,7 +1219,7 @@ static void uart_set_termios(struct tty_struct *tty,
1219 return; 1219 return;
1220 } 1220 }
1221 1221
1222 uart_change_speed(state, old_termios); 1222 uart_change_speed(tty, state, old_termios);
1223 1223
1224 /* Handle transition to B0 status */ 1224 /* Handle transition to B0 status */
1225 if ((old_termios->c_cflag & CBAUD) && !(cflag & CBAUD)) 1225 if ((old_termios->c_cflag & CBAUD) && !(cflag & CBAUD))
@@ -1272,8 +1272,9 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
1272 struct uart_state *state = tty->driver_data; 1272 struct uart_state *state = tty->driver_data;
1273 struct tty_port *port; 1273 struct tty_port *port;
1274 struct uart_port *uport; 1274 struct uart_port *uport;
1275 unsigned long flags;
1275 1276
1276 BUG_ON(!kernel_locked()); 1277 BUG_ON(!tty_locked());
1277 1278
1278 if (!state) 1279 if (!state)
1279 return; 1280 return;
@@ -1284,9 +1285,12 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
1284 pr_debug("uart_close(%d) called\n", uport->line); 1285 pr_debug("uart_close(%d) called\n", uport->line);
1285 1286
1286 mutex_lock(&port->mutex); 1287 mutex_lock(&port->mutex);
1288 spin_lock_irqsave(&port->lock, flags);
1287 1289
1288 if (tty_hung_up_p(filp)) 1290 if (tty_hung_up_p(filp)) {
1291 spin_unlock_irqrestore(&port->lock, flags);
1289 goto done; 1292 goto done;
1293 }
1290 1294
1291 if ((tty->count == 1) && (port->count != 1)) { 1295 if ((tty->count == 1) && (port->count != 1)) {
1292 /* 1296 /*
@@ -1305,8 +1309,10 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
1305 tty->name, port->count); 1309 tty->name, port->count);
1306 port->count = 0; 1310 port->count = 0;
1307 } 1311 }
1308 if (port->count) 1312 if (port->count) {
1313 spin_unlock_irqrestore(&port->lock, flags);
1309 goto done; 1314 goto done;
1315 }
1310 1316
1311 /* 1317 /*
1312 * Now we wait for the transmit buffer to clear; and we notify 1318 * Now we wait for the transmit buffer to clear; and we notify
@@ -1314,9 +1320,18 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
1314 * setting tty->closing. 1320 * setting tty->closing.
1315 */ 1321 */
1316 tty->closing = 1; 1322 tty->closing = 1;
1323 spin_unlock_irqrestore(&port->lock, flags);
1317 1324
1318 if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE) 1325 if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE) {
1319 tty_wait_until_sent(tty, msecs_to_jiffies(port->closing_wait)); 1326 /*
1327 * hack: open-coded tty_wait_until_sent to avoid
1328 * recursive tty_lock
1329 */
1330 long timeout = msecs_to_jiffies(port->closing_wait);
1331 if (wait_event_interruptible_timeout(tty->write_wait,
1332 !tty_chars_in_buffer(tty), timeout) >= 0)
1333 __uart_wait_until_sent(uport, timeout);
1334 }
1320 1335
1321 /* 1336 /*
1322 * At this point, we stop accepting input. To do this, we 1337 * At this point, we stop accepting input. To do this, we
@@ -1332,45 +1347,47 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
1332 * has completely drained; this is especially 1347 * has completely drained; this is especially
1333 * important if there is a transmit FIFO! 1348 * important if there is a transmit FIFO!
1334 */ 1349 */
1335 uart_wait_until_sent(tty, uport->timeout); 1350 __uart_wait_until_sent(uport, uport->timeout);
1336 } 1351 }
1337 1352
1338 uart_shutdown(state); 1353 uart_shutdown(tty, state);
1339 uart_flush_buffer(tty); 1354 uart_flush_buffer(tty);
1340 1355
1341 tty_ldisc_flush(tty); 1356 tty_ldisc_flush(tty);
1342 1357
1343 tty->closing = 0;
1344 tty_port_tty_set(port, NULL); 1358 tty_port_tty_set(port, NULL);
1359 spin_lock_irqsave(&port->lock, flags);
1360 tty->closing = 0;
1345 1361
1346 if (port->blocked_open) { 1362 if (port->blocked_open) {
1363 spin_unlock_irqrestore(&port->lock, flags);
1347 if (port->close_delay) 1364 if (port->close_delay)
1348 msleep_interruptible(port->close_delay); 1365 msleep_interruptible(port->close_delay);
1366 spin_lock_irqsave(&port->lock, flags);
1349 } else if (!uart_console(uport)) { 1367 } else if (!uart_console(uport)) {
1368 spin_unlock_irqrestore(&port->lock, flags);
1350 uart_change_pm(state, 3); 1369 uart_change_pm(state, 3);
1370 spin_lock_irqsave(&port->lock, flags);
1351 } 1371 }
1352 1372
1353 /* 1373 /*
1354 * Wake up anyone trying to open this port. 1374 * Wake up anyone trying to open this port.
1355 */ 1375 */
1356 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags); 1376 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
1377 spin_unlock_irqrestore(&port->lock, flags);
1357 wake_up_interruptible(&port->open_wait); 1378 wake_up_interruptible(&port->open_wait);
1358 1379
1359done: 1380done:
1360 mutex_unlock(&port->mutex); 1381 mutex_unlock(&port->mutex);
1361} 1382}
1362 1383
1363static void uart_wait_until_sent(struct tty_struct *tty, int timeout) 1384static void __uart_wait_until_sent(struct uart_port *port, int timeout)
1364{ 1385{
1365 struct uart_state *state = tty->driver_data;
1366 struct uart_port *port = state->uart_port;
1367 unsigned long char_time, expire; 1386 unsigned long char_time, expire;
1368 1387
1369 if (port->type == PORT_UNKNOWN || port->fifosize == 0) 1388 if (port->type == PORT_UNKNOWN || port->fifosize == 0)
1370 return; 1389 return;
1371 1390
1372 lock_kernel();
1373
1374 /* 1391 /*
1375 * Set the check interval to be 1/5 of the estimated time to 1392 * Set the check interval to be 1/5 of the estimated time to
1376 * send a single character, and make it at least 1. The check 1393 * send a single character, and make it at least 1. The check
@@ -1416,7 +1433,16 @@ static void uart_wait_until_sent(struct tty_struct *tty, int timeout)
1416 break; 1433 break;
1417 } 1434 }
1418 set_current_state(TASK_RUNNING); /* might not be needed */ 1435 set_current_state(TASK_RUNNING); /* might not be needed */
1419 unlock_kernel(); 1436}
1437
1438static void uart_wait_until_sent(struct tty_struct *tty, int timeout)
1439{
1440 struct uart_state *state = tty->driver_data;
1441 struct uart_port *port = state->uart_port;
1442
1443 tty_lock();
1444 __uart_wait_until_sent(port, timeout);
1445 tty_unlock();
1420} 1446}
1421 1447
1422/* 1448/*
@@ -1429,16 +1455,19 @@ static void uart_hangup(struct tty_struct *tty)
1429{ 1455{
1430 struct uart_state *state = tty->driver_data; 1456 struct uart_state *state = tty->driver_data;
1431 struct tty_port *port = &state->port; 1457 struct tty_port *port = &state->port;
1458 unsigned long flags;
1432 1459
1433 BUG_ON(!kernel_locked()); 1460 BUG_ON(!tty_locked());
1434 pr_debug("uart_hangup(%d)\n", state->uart_port->line); 1461 pr_debug("uart_hangup(%d)\n", state->uart_port->line);
1435 1462
1436 mutex_lock(&port->mutex); 1463 mutex_lock(&port->mutex);
1437 if (port->flags & ASYNC_NORMAL_ACTIVE) { 1464 if (port->flags & ASYNC_NORMAL_ACTIVE) {
1438 uart_flush_buffer(tty); 1465 uart_flush_buffer(tty);
1439 uart_shutdown(state); 1466 uart_shutdown(tty, state);
1467 spin_lock_irqsave(&port->lock, flags);
1440 port->count = 0; 1468 port->count = 0;
1441 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags); 1469 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
1470 spin_unlock_irqrestore(&port->lock, flags);
1442 tty_port_tty_set(port, NULL); 1471 tty_port_tty_set(port, NULL);
1443 wake_up_interruptible(&port->open_wait); 1472 wake_up_interruptible(&port->open_wait);
1444 wake_up_interruptible(&port->delta_msr_wait); 1473 wake_up_interruptible(&port->delta_msr_wait);
@@ -1446,15 +1475,19 @@ static void uart_hangup(struct tty_struct *tty)
1446 mutex_unlock(&port->mutex); 1475 mutex_unlock(&port->mutex);
1447} 1476}
1448 1477
1449/* 1478/**
1450 * Copy across the serial console cflag setting into the termios settings 1479 * uart_update_termios - update the terminal hw settings
1451 * for the initial open of the port. This allows continuity between the 1480 * @tty: tty associated with UART
1452 * kernel settings, and the settings init adopts when it opens the port 1481 * @state: UART to update
1453 * for the first time. 1482 *
1483 * Copy across the serial console cflag setting into the termios settings
1484 * for the initial open of the port. This allows continuity between the
1485 * kernel settings, and the settings init adopts when it opens the port
1486 * for the first time.
1454 */ 1487 */
1455static void uart_update_termios(struct uart_state *state) 1488static void uart_update_termios(struct tty_struct *tty,
1489 struct uart_state *state)
1456{ 1490{
1457 struct tty_struct *tty = state->port.tty;
1458 struct uart_port *port = state->uart_port; 1491 struct uart_port *port = state->uart_port;
1459 1492
1460 if (uart_console(port) && port->cons->cflag) { 1493 if (uart_console(port) && port->cons->cflag) {
@@ -1471,7 +1504,7 @@ static void uart_update_termios(struct uart_state *state)
1471 /* 1504 /*
1472 * Make termios settings take effect. 1505 * Make termios settings take effect.
1473 */ 1506 */
1474 uart_change_speed(state, NULL); 1507 uart_change_speed(tty, state, NULL);
1475 1508
1476 /* 1509 /*
1477 * And finally enable the RTS and DTR signals. 1510 * And finally enable the RTS and DTR signals.
@@ -1481,90 +1514,37 @@ static void uart_update_termios(struct uart_state *state)
1481 } 1514 }
1482} 1515}
1483 1516
1484/* 1517static int uart_carrier_raised(struct tty_port *port)
1485 * Block the open until the port is ready. We must be called with
1486 * the per-port semaphore held.
1487 */
1488static int
1489uart_block_til_ready(struct file *filp, struct uart_state *state)
1490{ 1518{
1491 DECLARE_WAITQUEUE(wait, current); 1519 struct uart_state *state = container_of(port, struct uart_state, port);
1492 struct uart_port *uport = state->uart_port; 1520 struct uart_port *uport = state->uart_port;
1493 struct tty_port *port = &state->port; 1521 int mctrl;
1494 unsigned int mctrl; 1522 spin_lock_irq(&uport->lock);
1495 1523 uport->ops->enable_ms(uport);
1496 port->blocked_open++; 1524 mctrl = uport->ops->get_mctrl(uport);
1497 port->count--; 1525 spin_unlock_irq(&uport->lock);
1498 1526 if (mctrl & TIOCM_CAR)
1499 add_wait_queue(&port->open_wait, &wait); 1527 return 1;
1500 while (1) { 1528 return 0;
1501 set_current_state(TASK_INTERRUPTIBLE); 1529}
1502
1503 /*
1504 * If we have been hung up, tell userspace/restart open.
1505 */
1506 if (tty_hung_up_p(filp) || port->tty == NULL)
1507 break;
1508
1509 /*
1510 * If the port has been closed, tell userspace/restart open.
1511 */
1512 if (!(port->flags & ASYNC_INITIALIZED))
1513 break;
1514 1530
1515 /* 1531static void uart_dtr_rts(struct tty_port *port, int onoff)
1516 * If non-blocking mode is set, or CLOCAL mode is set, 1532{
1517 * we don't want to wait for the modem status lines to 1533 struct uart_state *state = container_of(port, struct uart_state, port);
1518 * indicate that the port is ready. 1534 struct uart_port *uport = state->uart_port;
1519 *
1520 * Also, if the port is not enabled/configured, we want
1521 * to allow the open to succeed here. Note that we will
1522 * have set TTY_IO_ERROR for a non-existant port.
1523 */
1524 if ((filp->f_flags & O_NONBLOCK) ||
1525 (port->tty->termios->c_cflag & CLOCAL) ||
1526 (port->tty->flags & (1 << TTY_IO_ERROR)))
1527 break;
1528 1535
1529 /* 1536 if (onoff) {
1530 * Set DTR to allow modem to know we're waiting. Do 1537 uart_set_mctrl(uport, TIOCM_DTR | TIOCM_RTS);
1531 * not set RTS here - we want to make sure we catch
1532 * the data from the modem.
1533 */
1534 if (port->tty->termios->c_cflag & CBAUD)
1535 uart_set_mctrl(uport, TIOCM_DTR);
1536 1538
1537 /* 1539 /*
1538 * and wait for the carrier to indicate that the 1540 * If this is the first open to succeed,
1539 * modem is ready for us. 1541 * adjust things to suit.
1540 */ 1542 */
1541 spin_lock_irq(&uport->lock); 1543 if (!test_and_set_bit(ASYNCB_NORMAL_ACTIVE, &port->flags))
1542 uport->ops->enable_ms(uport); 1544 uart_update_termios(port->tty, state);
1543 mctrl = uport->ops->get_mctrl(uport);
1544 spin_unlock_irq(&uport->lock);
1545 if (mctrl & TIOCM_CAR)
1546 break;
1547
1548 mutex_unlock(&port->mutex);
1549 schedule();
1550 mutex_lock(&port->mutex);
1551
1552 if (signal_pending(current))
1553 break;
1554 } 1545 }
1555 set_current_state(TASK_RUNNING); 1546 else
1556 remove_wait_queue(&port->open_wait, &wait); 1547 uart_clear_mctrl(uport, TIOCM_DTR | TIOCM_RTS);
1557
1558 port->count++;
1559 port->blocked_open--;
1560
1561 if (signal_pending(current))
1562 return -ERESTARTSYS;
1563
1564 if (!port->tty || tty_hung_up_p(filp))
1565 return -EAGAIN;
1566
1567 return 0;
1568} 1548}
1569 1549
1570static struct uart_state *uart_get(struct uart_driver *drv, int line) 1550static struct uart_state *uart_get(struct uart_driver *drv, int line)
@@ -1611,7 +1591,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
1611 struct tty_port *port; 1591 struct tty_port *port;
1612 int retval, line = tty->index; 1592 int retval, line = tty->index;
1613 1593
1614 BUG_ON(!kernel_locked()); 1594 BUG_ON(!tty_locked());
1615 pr_debug("uart_open(%d) called\n", line); 1595 pr_debug("uart_open(%d) called\n", line);
1616 1596
1617 /* 1597 /*
@@ -1668,23 +1648,14 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
1668 /* 1648 /*
1669 * Start up the serial port. 1649 * Start up the serial port.
1670 */ 1650 */
1671 retval = uart_startup(state, 0); 1651 retval = uart_startup(tty, state, 0);
1672 1652
1673 /* 1653 /*
1674 * If we succeeded, wait until the port is ready. 1654 * If we succeeded, wait until the port is ready.
1675 */ 1655 */
1676 if (retval == 0)
1677 retval = uart_block_til_ready(filp, state);
1678 mutex_unlock(&port->mutex); 1656 mutex_unlock(&port->mutex);
1679 1657 if (retval == 0)
1680 /* 1658 retval = tty_port_block_til_ready(port, tty, filp);
1681 * If this is the first open to succeed, adjust things to suit.
1682 */
1683 if (retval == 0 && !(port->flags & ASYNC_NORMAL_ACTIVE)) {
1684 set_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
1685
1686 uart_update_termios(state);
1687 }
1688 1659
1689fail: 1660fail:
1690 return retval; 1661 return retval;
@@ -2010,9 +1981,13 @@ int uart_suspend_port(struct uart_driver *drv, struct uart_port *uport)
2010 struct tty_port *port = &state->port; 1981 struct tty_port *port = &state->port;
2011 struct device *tty_dev; 1982 struct device *tty_dev;
2012 struct uart_match match = {uport, drv}; 1983 struct uart_match match = {uport, drv};
1984 struct tty_struct *tty;
2013 1985
2014 mutex_lock(&port->mutex); 1986 mutex_lock(&port->mutex);
2015 1987
1988 /* Must be inside the mutex lock until we convert to tty_port */
1989 tty = port->tty;
1990
2016 tty_dev = device_find_child(uport->dev, &match, serial_match_port); 1991 tty_dev = device_find_child(uport->dev, &match, serial_match_port);
2017 if (device_may_wakeup(tty_dev)) { 1992 if (device_may_wakeup(tty_dev)) {
2018 enable_irq_wake(uport->irq); 1993 enable_irq_wake(uport->irq);
@@ -2105,9 +2080,12 @@ int uart_resume_port(struct uart_driver *drv, struct uart_port *uport)
2105 ops->set_mctrl(uport, 0); 2080 ops->set_mctrl(uport, 0);
2106 spin_unlock_irq(&uport->lock); 2081 spin_unlock_irq(&uport->lock);
2107 if (console_suspend_enabled || !uart_console(uport)) { 2082 if (console_suspend_enabled || !uart_console(uport)) {
2083 /* Protected by port mutex for now */
2084 struct tty_struct *tty = port->tty;
2108 ret = ops->startup(uport); 2085 ret = ops->startup(uport);
2109 if (ret == 0) { 2086 if (ret == 0) {
2110 uart_change_speed(state, NULL); 2087 if (tty)
2088 uart_change_speed(tty, state, NULL);
2111 spin_lock_irq(&uport->lock); 2089 spin_lock_irq(&uport->lock);
2112 ops->set_mctrl(uport, uport->mctrl); 2090 ops->set_mctrl(uport, uport->mctrl);
2113 ops->start_tx(uport); 2091 ops->start_tx(uport);
@@ -2119,7 +2097,7 @@ int uart_resume_port(struct uart_driver *drv, struct uart_port *uport)
2119 * Clear the "initialized" flag so we won't try 2097 * Clear the "initialized" flag so we won't try
2120 * to call the low level drivers shutdown method. 2098 * to call the low level drivers shutdown method.
2121 */ 2099 */
2122 uart_shutdown(state); 2100 uart_shutdown(tty, state);
2123 } 2101 }
2124 } 2102 }
2125 2103
@@ -2312,6 +2290,11 @@ static const struct tty_operations uart_ops = {
2312#endif 2290#endif
2313}; 2291};
2314 2292
2293static const struct tty_port_operations uart_port_ops = {
2294 .carrier_raised = uart_carrier_raised,
2295 .dtr_rts = uart_dtr_rts,
2296};
2297
2315/** 2298/**
2316 * uart_register_driver - register a driver with the uart core layer 2299 * uart_register_driver - register a driver with the uart core layer
2317 * @drv: low level driver structure 2300 * @drv: low level driver structure
@@ -2368,6 +2351,7 @@ int uart_register_driver(struct uart_driver *drv)
2368 struct tty_port *port = &state->port; 2351 struct tty_port *port = &state->port;
2369 2352
2370 tty_port_init(port); 2353 tty_port_init(port);
2354 port->ops = &uart_port_ops;
2371 port->close_delay = 500; /* .5 seconds */ 2355 port->close_delay = 500; /* .5 seconds */
2372 port->closing_wait = 30000; /* 30 seconds */ 2356 port->closing_wait = 30000; /* 30 seconds */
2373 tasklet_init(&state->tlet, uart_tasklet_action, 2357 tasklet_init(&state->tlet, uart_tasklet_action,
diff --git a/drivers/serial/sh-sci.c b/drivers/serial/sh-sci.c
index 5f90fcd7d107..c291b3add1d2 100644
--- a/drivers/serial/sh-sci.c
+++ b/drivers/serial/sh-sci.c
@@ -346,6 +346,27 @@ static int scif_rxfill(struct uart_port *port)
346 return sci_in(port, SCFDR) & SCIF2_RFDC_MASK; 346 return sci_in(port, SCFDR) & SCIF2_RFDC_MASK;
347 } 347 }
348} 348}
349#elif defined(CONFIG_ARCH_SH7372)
350static int scif_txfill(struct uart_port *port)
351{
352 if (port->type == PORT_SCIFA)
353 return sci_in(port, SCFDR) >> 8;
354 else
355 return sci_in(port, SCTFDR);
356}
357
358static int scif_txroom(struct uart_port *port)
359{
360 return port->fifosize - scif_txfill(port);
361}
362
363static int scif_rxfill(struct uart_port *port)
364{
365 if (port->type == PORT_SCIFA)
366 return sci_in(port, SCFDR) & SCIF_RFDC_MASK;
367 else
368 return sci_in(port, SCRFDR);
369}
349#else 370#else
350static int scif_txfill(struct uart_port *port) 371static int scif_txfill(struct uart_port *port)
351{ 372{
@@ -683,7 +704,7 @@ static irqreturn_t sci_rx_interrupt(int irq, void *ptr)
683 u16 ssr = sci_in(port, SCxSR); 704 u16 ssr = sci_in(port, SCxSR);
684 705
685 /* Disable future Rx interrupts */ 706 /* Disable future Rx interrupts */
686 if (port->type == PORT_SCIFA) { 707 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) {
687 disable_irq_nosync(irq); 708 disable_irq_nosync(irq);
688 scr |= 0x4000; 709 scr |= 0x4000;
689 } else { 710 } else {
@@ -928,7 +949,7 @@ static void sci_dma_tx_complete(void *arg)
928 949
929 if (!uart_circ_empty(xmit)) { 950 if (!uart_circ_empty(xmit)) {
930 schedule_work(&s->work_tx); 951 schedule_work(&s->work_tx);
931 } else if (port->type == PORT_SCIFA) { 952 } else if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) {
932 u16 ctrl = sci_in(port, SCSCR); 953 u16 ctrl = sci_in(port, SCSCR);
933 sci_out(port, SCSCR, ctrl & ~SCI_CTRL_FLAGS_TIE); 954 sci_out(port, SCSCR, ctrl & ~SCI_CTRL_FLAGS_TIE);
934 } 955 }
@@ -1184,7 +1205,7 @@ static void sci_start_tx(struct uart_port *port)
1184 unsigned short ctrl; 1205 unsigned short ctrl;
1185 1206
1186#ifdef CONFIG_SERIAL_SH_SCI_DMA 1207#ifdef CONFIG_SERIAL_SH_SCI_DMA
1187 if (port->type == PORT_SCIFA) { 1208 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) {
1188 u16 new, scr = sci_in(port, SCSCR); 1209 u16 new, scr = sci_in(port, SCSCR);
1189 if (s->chan_tx) 1210 if (s->chan_tx)
1190 new = scr | 0x8000; 1211 new = scr | 0x8000;
@@ -1197,7 +1218,7 @@ static void sci_start_tx(struct uart_port *port)
1197 s->cookie_tx < 0) 1218 s->cookie_tx < 0)
1198 schedule_work(&s->work_tx); 1219 schedule_work(&s->work_tx);
1199#endif 1220#endif
1200 if (!s->chan_tx || port->type == PORT_SCIFA) { 1221 if (!s->chan_tx || port->type == PORT_SCIFA || port->type == PORT_SCIFB) {
1201 /* Set TIE (Transmit Interrupt Enable) bit in SCSCR */ 1222 /* Set TIE (Transmit Interrupt Enable) bit in SCSCR */
1202 ctrl = sci_in(port, SCSCR); 1223 ctrl = sci_in(port, SCSCR);
1203 sci_out(port, SCSCR, ctrl | SCI_CTRL_FLAGS_TIE); 1224 sci_out(port, SCSCR, ctrl | SCI_CTRL_FLAGS_TIE);
@@ -1210,7 +1231,7 @@ static void sci_stop_tx(struct uart_port *port)
1210 1231
1211 /* Clear TIE (Transmit Interrupt Enable) bit in SCSCR */ 1232 /* Clear TIE (Transmit Interrupt Enable) bit in SCSCR */
1212 ctrl = sci_in(port, SCSCR); 1233 ctrl = sci_in(port, SCSCR);
1213 if (port->type == PORT_SCIFA) 1234 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB)
1214 ctrl &= ~0x8000; 1235 ctrl &= ~0x8000;
1215 ctrl &= ~SCI_CTRL_FLAGS_TIE; 1236 ctrl &= ~SCI_CTRL_FLAGS_TIE;
1216 sci_out(port, SCSCR, ctrl); 1237 sci_out(port, SCSCR, ctrl);
@@ -1222,7 +1243,7 @@ static void sci_start_rx(struct uart_port *port)
1222 1243
1223 /* Set RIE (Receive Interrupt Enable) bit in SCSCR */ 1244 /* Set RIE (Receive Interrupt Enable) bit in SCSCR */
1224 ctrl |= sci_in(port, SCSCR); 1245 ctrl |= sci_in(port, SCSCR);
1225 if (port->type == PORT_SCIFA) 1246 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB)
1226 ctrl &= ~0x4000; 1247 ctrl &= ~0x4000;
1227 sci_out(port, SCSCR, ctrl); 1248 sci_out(port, SCSCR, ctrl);
1228} 1249}
@@ -1233,7 +1254,7 @@ static void sci_stop_rx(struct uart_port *port)
1233 1254
1234 /* Clear RIE (Receive Interrupt Enable) bit in SCSCR */ 1255 /* Clear RIE (Receive Interrupt Enable) bit in SCSCR */
1235 ctrl = sci_in(port, SCSCR); 1256 ctrl = sci_in(port, SCSCR);
1236 if (port->type == PORT_SCIFA) 1257 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB)
1237 ctrl &= ~0x4000; 1258 ctrl &= ~0x4000;
1238 ctrl &= ~(SCI_CTRL_FLAGS_RIE | SCI_CTRL_FLAGS_REIE); 1259 ctrl &= ~(SCI_CTRL_FLAGS_RIE | SCI_CTRL_FLAGS_REIE);
1239 sci_out(port, SCSCR, ctrl); 1260 sci_out(port, SCSCR, ctrl);
@@ -1271,7 +1292,7 @@ static void rx_timer_fn(unsigned long arg)
1271 struct uart_port *port = &s->port; 1292 struct uart_port *port = &s->port;
1272 u16 scr = sci_in(port, SCSCR); 1293 u16 scr = sci_in(port, SCSCR);
1273 1294
1274 if (port->type == PORT_SCIFA) { 1295 if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) {
1275 scr &= ~0x4000; 1296 scr &= ~0x4000;
1276 enable_irq(s->irqs[1]); 1297 enable_irq(s->irqs[1]);
1277 } 1298 }
@@ -1524,6 +1545,8 @@ static const char *sci_type(struct uart_port *port)
1524 return "scif"; 1545 return "scif";
1525 case PORT_SCIFA: 1546 case PORT_SCIFA:
1526 return "scifa"; 1547 return "scifa";
1548 case PORT_SCIFB:
1549 return "scifb";
1527 } 1550 }
1528 1551
1529 return NULL; 1552 return NULL;
@@ -1612,6 +1635,9 @@ static int __devinit sci_init_single(struct platform_device *dev,
1612 port->line = index; 1635 port->line = index;
1613 1636
1614 switch (p->type) { 1637 switch (p->type) {
1638 case PORT_SCIFB:
1639 port->fifosize = 256;
1640 break;
1615 case PORT_SCIFA: 1641 case PORT_SCIFA:
1616 port->fifosize = 64; 1642 port->fifosize = 64;
1617 break; 1643 break;
diff --git a/drivers/serial/sh-sci.h b/drivers/serial/sh-sci.h
index f70c49f915fa..9b52f77a9305 100644
--- a/drivers/serial/sh-sci.h
+++ b/drivers/serial/sh-sci.h
@@ -322,7 +322,7 @@
322#define CPU_SCIx_FNS(name, sci_offset, sci_size, scif_offset, scif_size)\ 322#define CPU_SCIx_FNS(name, sci_offset, sci_size, scif_offset, scif_size)\
323 static inline unsigned int sci_##name##_in(struct uart_port *port) \ 323 static inline unsigned int sci_##name##_in(struct uart_port *port) \
324 { \ 324 { \
325 if (port->type == PORT_SCIF) { \ 325 if (port->type == PORT_SCIF || port->type == PORT_SCIFB) { \
326 SCI_IN(scif_size, scif_offset) \ 326 SCI_IN(scif_size, scif_offset) \
327 } else { /* PORT_SCI or PORT_SCIFA */ \ 327 } else { /* PORT_SCI or PORT_SCIFA */ \
328 SCI_IN(sci_size, sci_offset); \ 328 SCI_IN(sci_size, sci_offset); \
@@ -330,7 +330,7 @@
330 } \ 330 } \
331 static inline void sci_##name##_out(struct uart_port *port, unsigned int value) \ 331 static inline void sci_##name##_out(struct uart_port *port, unsigned int value) \
332 { \ 332 { \
333 if (port->type == PORT_SCIF) { \ 333 if (port->type == PORT_SCIF || port->type == PORT_SCIFB) { \
334 SCI_OUT(scif_size, scif_offset, value) \ 334 SCI_OUT(scif_size, scif_offset, value) \
335 } else { /* PORT_SCI or PORT_SCIFA */ \ 335 } else { /* PORT_SCI or PORT_SCIFA */ \
336 SCI_OUT(sci_size, sci_offset, value); \ 336 SCI_OUT(sci_size, sci_offset, value); \
@@ -384,8 +384,12 @@
384 defined(CONFIG_CPU_SUBTYPE_SH7720) || \ 384 defined(CONFIG_CPU_SUBTYPE_SH7720) || \
385 defined(CONFIG_CPU_SUBTYPE_SH7721) || \ 385 defined(CONFIG_CPU_SUBTYPE_SH7721) || \
386 defined(CONFIG_ARCH_SH7367) || \ 386 defined(CONFIG_ARCH_SH7367) || \
387 defined(CONFIG_ARCH_SH7377) || \ 387 defined(CONFIG_ARCH_SH7377)
388 defined(CONFIG_ARCH_SH7372) 388#define SCIF_FNS(name, scif_offset, scif_size) \
389 CPU_SCIF_FNS(name, scif_offset, scif_size)
390#elif defined(CONFIG_ARCH_SH7372)
391#define SCIx_FNS(name, sh4_scifa_offset, sh4_scifa_size, sh4_scifb_offset, sh4_scifb_size) \
392 CPU_SCIx_FNS(name, sh4_scifa_offset, sh4_scifa_size, sh4_scifb_offset, sh4_scifb_size)
389#define SCIF_FNS(name, scif_offset, scif_size) \ 393#define SCIF_FNS(name, scif_offset, scif_size) \
390 CPU_SCIF_FNS(name, scif_offset, scif_size) 394 CPU_SCIF_FNS(name, scif_offset, scif_size)
391#else 395#else
@@ -422,8 +426,7 @@
422 defined(CONFIG_CPU_SUBTYPE_SH7720) || \ 426 defined(CONFIG_CPU_SUBTYPE_SH7720) || \
423 defined(CONFIG_CPU_SUBTYPE_SH7721) || \ 427 defined(CONFIG_CPU_SUBTYPE_SH7721) || \
424 defined(CONFIG_ARCH_SH7367) || \ 428 defined(CONFIG_ARCH_SH7367) || \
425 defined(CONFIG_ARCH_SH7377) || \ 429 defined(CONFIG_ARCH_SH7377)
426 defined(CONFIG_ARCH_SH7372)
427 430
428SCIF_FNS(SCSMR, 0x00, 16) 431SCIF_FNS(SCSMR, 0x00, 16)
429SCIF_FNS(SCBRR, 0x04, 8) 432SCIF_FNS(SCBRR, 0x04, 8)
@@ -436,6 +439,20 @@ SCIF_FNS(SCFDR, 0x1c, 16)
436SCIF_FNS(SCxTDR, 0x20, 8) 439SCIF_FNS(SCxTDR, 0x20, 8)
437SCIF_FNS(SCxRDR, 0x24, 8) 440SCIF_FNS(SCxRDR, 0x24, 8)
438SCIF_FNS(SCLSR, 0x00, 0) 441SCIF_FNS(SCLSR, 0x00, 0)
442#elif defined(CONFIG_ARCH_SH7372)
443SCIF_FNS(SCSMR, 0x00, 16)
444SCIF_FNS(SCBRR, 0x04, 8)
445SCIF_FNS(SCSCR, 0x08, 16)
446SCIF_FNS(SCTDSR, 0x0c, 16)
447SCIF_FNS(SCFER, 0x10, 16)
448SCIF_FNS(SCxSR, 0x14, 16)
449SCIF_FNS(SCFCR, 0x18, 16)
450SCIF_FNS(SCFDR, 0x1c, 16)
451SCIF_FNS(SCTFDR, 0x38, 16)
452SCIF_FNS(SCRFDR, 0x3c, 16)
453SCIx_FNS(SCxTDR, 0x20, 8, 0x40, 8)
454SCIx_FNS(SCxRDR, 0x24, 8, 0x60, 8)
455SCIF_FNS(SCLSR, 0x00, 0)
439#elif defined(CONFIG_CPU_SUBTYPE_SH7723) ||\ 456#elif defined(CONFIG_CPU_SUBTYPE_SH7723) ||\
440 defined(CONFIG_CPU_SUBTYPE_SH7724) 457 defined(CONFIG_CPU_SUBTYPE_SH7724)
441SCIx_FNS(SCSMR, 0x00, 16, 0x00, 16) 458SCIx_FNS(SCSMR, 0x00, 16, 0x00, 16)
diff --git a/drivers/serial/sunhv.c b/drivers/serial/sunhv.c
index a779e22d213e..c9014868297d 100644
--- a/drivers/serial/sunhv.c
+++ b/drivers/serial/sunhv.c
@@ -519,7 +519,7 @@ static struct console sunhv_console = {
519 .data = &sunhv_reg, 519 .data = &sunhv_reg,
520}; 520};
521 521
522static int __devinit hv_probe(struct of_device *op, const struct of_device_id *match) 522static int __devinit hv_probe(struct platform_device *op, const struct of_device_id *match)
523{ 523{
524 struct uart_port *port; 524 struct uart_port *port;
525 unsigned long minor; 525 unsigned long minor;
@@ -598,7 +598,7 @@ out_free_port:
598 return err; 598 return err;
599} 599}
600 600
601static int __devexit hv_remove(struct of_device *dev) 601static int __devexit hv_remove(struct platform_device *dev)
602{ 602{
603 struct uart_port *port = dev_get_drvdata(&dev->dev); 603 struct uart_port *port = dev_get_drvdata(&dev->dev);
604 604
diff --git a/drivers/serial/sunsab.c b/drivers/serial/sunsab.c
index 9845fb1cfb1f..5b246b18f42f 100644
--- a/drivers/serial/sunsab.c
+++ b/drivers/serial/sunsab.c
@@ -883,7 +883,7 @@ static int sunsab_console_setup(struct console *con, char *options)
883 printk("Console: ttyS%d (SAB82532)\n", 883 printk("Console: ttyS%d (SAB82532)\n",
884 (sunsab_reg.minor - 64) + con->index); 884 (sunsab_reg.minor - 64) + con->index);
885 885
886 sunserial_console_termios(con, to_of_device(up->port.dev)->dev.of_node); 886 sunserial_console_termios(con, up->port.dev->of_node);
887 887
888 switch (con->cflag & CBAUD) { 888 switch (con->cflag & CBAUD) {
889 case B150: baud = 150; break; 889 case B150: baud = 150; break;
@@ -954,7 +954,7 @@ static inline struct console *SUNSAB_CONSOLE(void)
954#endif 954#endif
955 955
956static int __devinit sunsab_init_one(struct uart_sunsab_port *up, 956static int __devinit sunsab_init_one(struct uart_sunsab_port *up,
957 struct of_device *op, 957 struct platform_device *op,
958 unsigned long offset, 958 unsigned long offset,
959 int line) 959 int line)
960{ 960{
@@ -1006,7 +1006,7 @@ static int __devinit sunsab_init_one(struct uart_sunsab_port *up,
1006 return 0; 1006 return 0;
1007} 1007}
1008 1008
1009static int __devinit sab_probe(struct of_device *op, const struct of_device_id *match) 1009static int __devinit sab_probe(struct platform_device *op, const struct of_device_id *match)
1010{ 1010{
1011 static int inst; 1011 static int inst;
1012 struct uart_sunsab_port *up; 1012 struct uart_sunsab_port *up;
@@ -1062,7 +1062,7 @@ out:
1062 return err; 1062 return err;
1063} 1063}
1064 1064
1065static int __devexit sab_remove(struct of_device *op) 1065static int __devexit sab_remove(struct platform_device *op)
1066{ 1066{
1067 struct uart_sunsab_port *up = dev_get_drvdata(&op->dev); 1067 struct uart_sunsab_port *up = dev_get_drvdata(&op->dev);
1068 1068
diff --git a/drivers/serial/sunsu.c b/drivers/serial/sunsu.c
index 3cdf74822db5..551ebfe3ccbb 100644
--- a/drivers/serial/sunsu.c
+++ b/drivers/serial/sunsu.c
@@ -1200,7 +1200,7 @@ static int __devinit sunsu_kbd_ms_init(struct uart_sunsu_port *up)
1200 return -ENODEV; 1200 return -ENODEV;
1201 1201
1202 printk("%s: %s port at %llx, irq %u\n", 1202 printk("%s: %s port at %llx, irq %u\n",
1203 to_of_device(up->port.dev)->dev.of_node->full_name, 1203 up->port.dev->of_node->full_name,
1204 (up->su_type == SU_PORT_KBD) ? "Keyboard" : "Mouse", 1204 (up->su_type == SU_PORT_KBD) ? "Keyboard" : "Mouse",
1205 (unsigned long long) up->port.mapbase, 1205 (unsigned long long) up->port.mapbase,
1206 up->port.irq); 1206 up->port.irq);
@@ -1352,7 +1352,7 @@ static int __init sunsu_console_setup(struct console *co, char *options)
1352 spin_lock_init(&port->lock); 1352 spin_lock_init(&port->lock);
1353 1353
1354 /* Get firmware console settings. */ 1354 /* Get firmware console settings. */
1355 sunserial_console_termios(co, to_of_device(port->dev)->dev.of_node); 1355 sunserial_console_termios(co, port->dev->of_node);
1356 1356
1357 memset(&termios, 0, sizeof(struct ktermios)); 1357 memset(&termios, 0, sizeof(struct ktermios));
1358 termios.c_cflag = co->cflag; 1358 termios.c_cflag = co->cflag;
@@ -1406,7 +1406,7 @@ static enum su_type __devinit su_get_type(struct device_node *dp)
1406 return SU_PORT_PORT; 1406 return SU_PORT_PORT;
1407} 1407}
1408 1408
1409static int __devinit su_probe(struct of_device *op, const struct of_device_id *match) 1409static int __devinit su_probe(struct platform_device *op, const struct of_device_id *match)
1410{ 1410{
1411 static int inst; 1411 static int inst;
1412 struct device_node *dp = op->dev.of_node; 1412 struct device_node *dp = op->dev.of_node;
@@ -1497,7 +1497,7 @@ out_unmap:
1497 return err; 1497 return err;
1498} 1498}
1499 1499
1500static int __devexit su_remove(struct of_device *op) 1500static int __devexit su_remove(struct platform_device *op)
1501{ 1501{
1502 struct uart_sunsu_port *up = dev_get_drvdata(&op->dev); 1502 struct uart_sunsu_port *up = dev_get_drvdata(&op->dev);
1503 bool kbdms = false; 1503 bool kbdms = false;
diff --git a/drivers/serial/sunzilog.c b/drivers/serial/sunzilog.c
index d1e6bcb59546..c1967ac1c07f 100644
--- a/drivers/serial/sunzilog.c
+++ b/drivers/serial/sunzilog.c
@@ -1230,7 +1230,7 @@ static int __init sunzilog_console_setup(struct console *con, char *options)
1230 (sunzilog_reg.minor - 64) + con->index, con->index); 1230 (sunzilog_reg.minor - 64) + con->index, con->index);
1231 1231
1232 /* Get firmware console settings. */ 1232 /* Get firmware console settings. */
1233 sunserial_console_termios(con, to_of_device(up->port.dev)->dev.of_node); 1233 sunserial_console_termios(con, up->port.dev->of_node);
1234 1234
1235 /* Firmware console speed is limited to 150-->38400 baud so 1235 /* Firmware console speed is limited to 150-->38400 baud so
1236 * this hackish cflag thing is OK. 1236 * this hackish cflag thing is OK.
@@ -1399,7 +1399,7 @@ static void __devinit sunzilog_init_hw(struct uart_sunzilog_port *up)
1399 1399
1400static int zilog_irq = -1; 1400static int zilog_irq = -1;
1401 1401
1402static int __devinit zs_probe(struct of_device *op, const struct of_device_id *match) 1402static int __devinit zs_probe(struct platform_device *op, const struct of_device_id *match)
1403{ 1403{
1404 static int kbm_inst, uart_inst; 1404 static int kbm_inst, uart_inst;
1405 int inst; 1405 int inst;
@@ -1516,7 +1516,7 @@ static void __devexit zs_remove_one(struct uart_sunzilog_port *up)
1516 uart_remove_one_port(&sunzilog_reg, &up->port); 1516 uart_remove_one_port(&sunzilog_reg, &up->port);
1517} 1517}
1518 1518
1519static int __devexit zs_remove(struct of_device *op) 1519static int __devexit zs_remove(struct platform_device *op)
1520{ 1520{
1521 struct uart_sunzilog_port *up = dev_get_drvdata(&op->dev); 1521 struct uart_sunzilog_port *up = dev_get_drvdata(&op->dev);
1522 struct zilog_layout __iomem *regs; 1522 struct zilog_layout __iomem *regs;
diff --git a/drivers/serial/timbuart.c b/drivers/serial/timbuart.c
index 67ca642713b8..1f36b7eb7351 100644
--- a/drivers/serial/timbuart.c
+++ b/drivers/serial/timbuart.c
@@ -423,7 +423,7 @@ static struct uart_driver timbuart_driver = {
423 .nr = 1 423 .nr = 1
424}; 424};
425 425
426static int timbuart_probe(struct platform_device *dev) 426static int __devinit timbuart_probe(struct platform_device *dev)
427{ 427{
428 int err, irq; 428 int err, irq;
429 struct timbuart_port *uart; 429 struct timbuart_port *uart;
@@ -489,7 +489,7 @@ err_mem:
489 return err; 489 return err;
490} 490}
491 491
492static int timbuart_remove(struct platform_device *dev) 492static int __devexit timbuart_remove(struct platform_device *dev)
493{ 493{
494 struct timbuart_port *uart = platform_get_drvdata(dev); 494 struct timbuart_port *uart = platform_get_drvdata(dev);
495 495
@@ -507,7 +507,7 @@ static struct platform_driver timbuart_platform_driver = {
507 .owner = THIS_MODULE, 507 .owner = THIS_MODULE,
508 }, 508 },
509 .probe = timbuart_probe, 509 .probe = timbuart_probe,
510 .remove = timbuart_remove, 510 .remove = __devexit_p(timbuart_remove),
511}; 511};
512 512
513/*--------------------------------------------------------------------------*/ 513/*--------------------------------------------------------------------------*/
diff --git a/drivers/serial/uartlite.c b/drivers/serial/uartlite.c
index caf085d3a76a..9b03d7b3e456 100644
--- a/drivers/serial/uartlite.c
+++ b/drivers/serial/uartlite.c
@@ -584,7 +584,7 @@ static struct platform_driver ulite_platform_driver = {
584 */ 584 */
585#if defined(CONFIG_OF) && (defined(CONFIG_PPC32) || defined(CONFIG_MICROBLAZE)) 585#if defined(CONFIG_OF) && (defined(CONFIG_PPC32) || defined(CONFIG_MICROBLAZE))
586static int __devinit 586static int __devinit
587ulite_of_probe(struct of_device *op, const struct of_device_id *match) 587ulite_of_probe(struct platform_device *op, const struct of_device_id *match)
588{ 588{
589 struct resource res; 589 struct resource res;
590 const unsigned int *id; 590 const unsigned int *id;
@@ -605,7 +605,7 @@ ulite_of_probe(struct of_device *op, const struct of_device_id *match)
605 return ulite_assign(&op->dev, id ? *id : -1, res.start, irq); 605 return ulite_assign(&op->dev, id ? *id : -1, res.start, irq);
606} 606}
607 607
608static int __devexit ulite_of_remove(struct of_device *op) 608static int __devexit ulite_of_remove(struct platform_device *op)
609{ 609{
610 return ulite_release(&op->dev); 610 return ulite_release(&op->dev);
611} 611}
diff --git a/drivers/serial/ucc_uart.c b/drivers/serial/ucc_uart.c
index 907b06f5c447..3f4848e2174a 100644
--- a/drivers/serial/ucc_uart.c
+++ b/drivers/serial/ucc_uart.c
@@ -1194,7 +1194,7 @@ static void uart_firmware_cont(const struct firmware *fw, void *context)
1194 release_firmware(fw); 1194 release_firmware(fw);
1195} 1195}
1196 1196
1197static int ucc_uart_probe(struct of_device *ofdev, 1197static int ucc_uart_probe(struct platform_device *ofdev,
1198 const struct of_device_id *match) 1198 const struct of_device_id *match)
1199{ 1199{
1200 struct device_node *np = ofdev->dev.of_node; 1200 struct device_node *np = ofdev->dev.of_node;
@@ -1462,7 +1462,7 @@ static int ucc_uart_probe(struct of_device *ofdev,
1462 return 0; 1462 return 0;
1463} 1463}
1464 1464
1465static int ucc_uart_remove(struct of_device *ofdev) 1465static int ucc_uart_remove(struct platform_device *ofdev)
1466{ 1466{
1467 struct uart_qe_port *qe_port = dev_get_drvdata(&ofdev->dev); 1467 struct uart_qe_port *qe_port = dev_get_drvdata(&ofdev->dev);
1468 1468
diff --git a/drivers/sh/Makefile b/drivers/sh/Makefile
index 78bb5127abd0..08fc653a825c 100644
--- a/drivers/sh/Makefile
+++ b/drivers/sh/Makefile
@@ -1,9 +1,10 @@
1# 1#
2# Makefile for the SuperH specific drivers. 2# Makefile for the SuperH specific drivers.
3# 3#
4obj-y := clk.o intc.o
5
4obj-$(CONFIG_SUPERHYWAY) += superhyway/ 6obj-$(CONFIG_SUPERHYWAY) += superhyway/
5obj-$(CONFIG_MAPLE) += maple/ 7obj-$(CONFIG_MAPLE) += maple/
8
6obj-$(CONFIG_GENERIC_GPIO) += pfc.o 9obj-$(CONFIG_GENERIC_GPIO) += pfc.o
7obj-$(CONFIG_SUPERH) += clk.o
8obj-$(CONFIG_SH_CLK_CPG) += clk-cpg.o 10obj-$(CONFIG_SH_CLK_CPG) += clk-cpg.o
9obj-y += intc.o
diff --git a/drivers/sh/clk-cpg.c b/drivers/sh/clk-cpg.c
index f5c80ba9ab1c..8c024b984ed8 100644
--- a/drivers/sh/clk-cpg.c
+++ b/drivers/sh/clk-cpg.c
@@ -68,6 +68,39 @@ static unsigned long sh_clk_div6_recalc(struct clk *clk)
68 return clk->freq_table[idx].frequency; 68 return clk->freq_table[idx].frequency;
69} 69}
70 70
71static int sh_clk_div6_set_parent(struct clk *clk, struct clk *parent)
72{
73 struct clk_div_mult_table *table = &sh_clk_div6_table;
74 u32 value;
75 int ret, i;
76
77 if (!clk->parent_table || !clk->parent_num)
78 return -EINVAL;
79
80 /* Search the parent */
81 for (i = 0; i < clk->parent_num; i++)
82 if (clk->parent_table[i] == parent)
83 break;
84
85 if (i == clk->parent_num)
86 return -ENODEV;
87
88 ret = clk_reparent(clk, parent);
89 if (ret < 0)
90 return ret;
91
92 value = __raw_readl(clk->enable_reg) &
93 ~(((1 << clk->src_width) - 1) << clk->src_shift);
94
95 __raw_writel(value | (i << clk->src_shift), clk->enable_reg);
96
97 /* Rebuild the frequency table */
98 clk_rate_table_build(clk, clk->freq_table, table->nr_divisors,
99 table, &clk->arch_flags);
100
101 return 0;
102}
103
71static int sh_clk_div6_set_rate(struct clk *clk, 104static int sh_clk_div6_set_rate(struct clk *clk,
72 unsigned long rate, int algo_id) 105 unsigned long rate, int algo_id)
73{ 106{
@@ -117,7 +150,17 @@ static struct clk_ops sh_clk_div6_clk_ops = {
117 .disable = sh_clk_div6_disable, 150 .disable = sh_clk_div6_disable,
118}; 151};
119 152
120int __init sh_clk_div6_register(struct clk *clks, int nr) 153static struct clk_ops sh_clk_div6_reparent_clk_ops = {
154 .recalc = sh_clk_div6_recalc,
155 .round_rate = sh_clk_div_round_rate,
156 .set_rate = sh_clk_div6_set_rate,
157 .enable = sh_clk_div6_enable,
158 .disable = sh_clk_div6_disable,
159 .set_parent = sh_clk_div6_set_parent,
160};
161
162static int __init sh_clk_div6_register_ops(struct clk *clks, int nr,
163 struct clk_ops *ops)
121{ 164{
122 struct clk *clkp; 165 struct clk *clkp;
123 void *freq_table; 166 void *freq_table;
@@ -136,7 +179,7 @@ int __init sh_clk_div6_register(struct clk *clks, int nr)
136 for (k = 0; !ret && (k < nr); k++) { 179 for (k = 0; !ret && (k < nr); k++) {
137 clkp = clks + k; 180 clkp = clks + k;
138 181
139 clkp->ops = &sh_clk_div6_clk_ops; 182 clkp->ops = ops;
140 clkp->id = -1; 183 clkp->id = -1;
141 clkp->freq_table = freq_table + (k * freq_table_size); 184 clkp->freq_table = freq_table + (k * freq_table_size);
142 clkp->freq_table[nr_divs].frequency = CPUFREQ_TABLE_END; 185 clkp->freq_table[nr_divs].frequency = CPUFREQ_TABLE_END;
@@ -147,6 +190,17 @@ int __init sh_clk_div6_register(struct clk *clks, int nr)
147 return ret; 190 return ret;
148} 191}
149 192
193int __init sh_clk_div6_register(struct clk *clks, int nr)
194{
195 return sh_clk_div6_register_ops(clks, nr, &sh_clk_div6_clk_ops);
196}
197
198int __init sh_clk_div6_reparent_register(struct clk *clks, int nr)
199{
200 return sh_clk_div6_register_ops(clks, nr,
201 &sh_clk_div6_reparent_clk_ops);
202}
203
150static unsigned long sh_clk_div4_recalc(struct clk *clk) 204static unsigned long sh_clk_div4_recalc(struct clk *clk)
151{ 205{
152 struct clk_div4_table *d4t = clk->priv; 206 struct clk_div4_table *d4t = clk->priv;
diff --git a/drivers/spi/amba-pl022.c b/drivers/spi/amba-pl022.c
index f0a1418ce660..acd35d1ebd12 100644
--- a/drivers/spi/amba-pl022.c
+++ b/drivers/spi/amba-pl022.c
@@ -1723,7 +1723,7 @@ static void pl022_cleanup(struct spi_device *spi)
1723} 1723}
1724 1724
1725 1725
1726static int __init 1726static int __devinit
1727pl022_probe(struct amba_device *adev, struct amba_id *id) 1727pl022_probe(struct amba_device *adev, struct amba_id *id)
1728{ 1728{
1729 struct device *dev = &adev->dev; 1729 struct device *dev = &adev->dev;
@@ -1838,7 +1838,7 @@ pl022_probe(struct amba_device *adev, struct amba_id *id)
1838 return status; 1838 return status;
1839} 1839}
1840 1840
1841static int __exit 1841static int __devexit
1842pl022_remove(struct amba_device *adev) 1842pl022_remove(struct amba_device *adev)
1843{ 1843{
1844 struct pl022 *pl022 = amba_get_drvdata(adev); 1844 struct pl022 *pl022 = amba_get_drvdata(adev);
@@ -1970,7 +1970,7 @@ static struct amba_driver pl022_driver = {
1970 }, 1970 },
1971 .id_table = pl022_ids, 1971 .id_table = pl022_ids,
1972 .probe = pl022_probe, 1972 .probe = pl022_probe,
1973 .remove = __exit_p(pl022_remove), 1973 .remove = __devexit_p(pl022_remove),
1974 .suspend = pl022_suspend, 1974 .suspend = pl022_suspend,
1975 .resume = pl022_resume, 1975 .resume = pl022_resume,
1976}; 1976};
diff --git a/drivers/spi/mpc512x_psc_spi.c b/drivers/spi/mpc512x_psc_spi.c
index 10baac3f8ea5..77d9e7ee8b27 100644
--- a/drivers/spi/mpc512x_psc_spi.c
+++ b/drivers/spi/mpc512x_psc_spi.c
@@ -406,9 +406,9 @@ static irqreturn_t mpc512x_psc_spi_isr(int irq, void *dev_id)
406} 406}
407 407
408/* bus_num is used only for the case dev->platform_data == NULL */ 408/* bus_num is used only for the case dev->platform_data == NULL */
409static int __init mpc512x_psc_spi_do_probe(struct device *dev, u32 regaddr, 409static int __devinit mpc512x_psc_spi_do_probe(struct device *dev, u32 regaddr,
410 u32 size, unsigned int irq, 410 u32 size, unsigned int irq,
411 s16 bus_num) 411 s16 bus_num)
412{ 412{
413 struct fsl_spi_platform_data *pdata = dev->platform_data; 413 struct fsl_spi_platform_data *pdata = dev->platform_data;
414 struct mpc512x_psc_spi *mps; 414 struct mpc512x_psc_spi *mps;
@@ -492,7 +492,7 @@ free_master:
492 return ret; 492 return ret;
493} 493}
494 494
495static int __exit mpc512x_psc_spi_do_remove(struct device *dev) 495static int __devexit mpc512x_psc_spi_do_remove(struct device *dev)
496{ 496{
497 struct spi_master *master = dev_get_drvdata(dev); 497 struct spi_master *master = dev_get_drvdata(dev);
498 struct mpc512x_psc_spi *mps = spi_master_get_devdata(master); 498 struct mpc512x_psc_spi *mps = spi_master_get_devdata(master);
@@ -507,8 +507,8 @@ static int __exit mpc512x_psc_spi_do_remove(struct device *dev)
507 return 0; 507 return 0;
508} 508}
509 509
510static int __init mpc512x_psc_spi_of_probe(struct of_device *op, 510static int __devinit mpc512x_psc_spi_of_probe(struct platform_device *op,
511 const struct of_device_id *match) 511 const struct of_device_id *match)
512{ 512{
513 const u32 *regaddr_p; 513 const u32 *regaddr_p;
514 u64 regaddr64, size64; 514 u64 regaddr64, size64;
@@ -539,7 +539,7 @@ static int __init mpc512x_psc_spi_of_probe(struct of_device *op,
539 irq_of_parse_and_map(op->dev.of_node, 0), id); 539 irq_of_parse_and_map(op->dev.of_node, 0), id);
540} 540}
541 541
542static int __exit mpc512x_psc_spi_of_remove(struct of_device *op) 542static int __devexit mpc512x_psc_spi_of_remove(struct platform_device *op)
543{ 543{
544 return mpc512x_psc_spi_do_remove(&op->dev); 544 return mpc512x_psc_spi_do_remove(&op->dev);
545} 545}
@@ -553,7 +553,7 @@ MODULE_DEVICE_TABLE(of, mpc512x_psc_spi_of_match);
553 553
554static struct of_platform_driver mpc512x_psc_spi_of_driver = { 554static struct of_platform_driver mpc512x_psc_spi_of_driver = {
555 .probe = mpc512x_psc_spi_of_probe, 555 .probe = mpc512x_psc_spi_of_probe,
556 .remove = __exit_p(mpc512x_psc_spi_of_remove), 556 .remove = __devexit_p(mpc512x_psc_spi_of_remove),
557 .driver = { 557 .driver = {
558 .name = "mpc512x-psc-spi", 558 .name = "mpc512x-psc-spi",
559 .owner = THIS_MODULE, 559 .owner = THIS_MODULE,
diff --git a/drivers/spi/mpc52xx_psc_spi.c b/drivers/spi/mpc52xx_psc_spi.c
index 66d170147dcc..983fbbfce76e 100644
--- a/drivers/spi/mpc52xx_psc_spi.c
+++ b/drivers/spi/mpc52xx_psc_spi.c
@@ -465,7 +465,7 @@ static int __exit mpc52xx_psc_spi_do_remove(struct device *dev)
465 return 0; 465 return 0;
466} 466}
467 467
468static int __init mpc52xx_psc_spi_of_probe(struct of_device *op, 468static int __init mpc52xx_psc_spi_of_probe(struct platform_device *op,
469 const struct of_device_id *match) 469 const struct of_device_id *match)
470{ 470{
471 const u32 *regaddr_p; 471 const u32 *regaddr_p;
@@ -495,7 +495,7 @@ static int __init mpc52xx_psc_spi_of_probe(struct of_device *op,
495 irq_of_parse_and_map(op->dev.of_node, 0), id); 495 irq_of_parse_and_map(op->dev.of_node, 0), id);
496} 496}
497 497
498static int __exit mpc52xx_psc_spi_of_remove(struct of_device *op) 498static int __exit mpc52xx_psc_spi_of_remove(struct platform_device *op)
499{ 499{
500 return mpc52xx_psc_spi_do_remove(&op->dev); 500 return mpc52xx_psc_spi_do_remove(&op->dev);
501} 501}
diff --git a/drivers/spi/mpc52xx_spi.c b/drivers/spi/mpc52xx_spi.c
index 56136ff00e01..ec9f0b1bf864 100644
--- a/drivers/spi/mpc52xx_spi.c
+++ b/drivers/spi/mpc52xx_spi.c
@@ -390,7 +390,7 @@ static int mpc52xx_spi_transfer(struct spi_device *spi, struct spi_message *m)
390/* 390/*
391 * OF Platform Bus Binding 391 * OF Platform Bus Binding
392 */ 392 */
393static int __devinit mpc52xx_spi_probe(struct of_device *op, 393static int __devinit mpc52xx_spi_probe(struct platform_device *op,
394 const struct of_device_id *match) 394 const struct of_device_id *match)
395{ 395{
396 struct spi_master *master; 396 struct spi_master *master;
@@ -530,7 +530,7 @@ static int __devinit mpc52xx_spi_probe(struct of_device *op,
530 return rc; 530 return rc;
531} 531}
532 532
533static int __devexit mpc52xx_spi_remove(struct of_device *op) 533static int __devexit mpc52xx_spi_remove(struct platform_device *op)
534{ 534{
535 struct spi_master *master = dev_get_drvdata(&op->dev); 535 struct spi_master *master = dev_get_drvdata(&op->dev);
536 struct mpc52xx_spi *ms = spi_master_get_devdata(master); 536 struct mpc52xx_spi *ms = spi_master_get_devdata(master);
diff --git a/drivers/spi/omap_spi_100k.c b/drivers/spi/omap_spi_100k.c
index 24668b30a52d..9bd1c92ad96e 100644
--- a/drivers/spi/omap_spi_100k.c
+++ b/drivers/spi/omap_spi_100k.c
@@ -141,7 +141,12 @@ static void spi100k_write_data(struct spi_master *master, int len, int data)
141{ 141{
142 struct omap1_spi100k *spi100k = spi_master_get_devdata(master); 142 struct omap1_spi100k *spi100k = spi_master_get_devdata(master);
143 143
144 /* write 16-bit word */ 144 /* write 16-bit word, shifting 8-bit data if necessary */
145 if (len <= 8) {
146 data <<= 8;
147 len = 16;
148 }
149
145 spi100k_enable_clock(master); 150 spi100k_enable_clock(master);
146 writew( data , spi100k->base + SPI_TX_MSB); 151 writew( data , spi100k->base + SPI_TX_MSB);
147 152
@@ -162,6 +167,10 @@ static int spi100k_read_data(struct spi_master *master, int len)
162 int dataH,dataL; 167 int dataH,dataL;
163 struct omap1_spi100k *spi100k = spi_master_get_devdata(master); 168 struct omap1_spi100k *spi100k = spi_master_get_devdata(master);
164 169
170 /* Always do at least 16 bits */
171 if (len <= 8)
172 len = 16;
173
165 spi100k_enable_clock(master); 174 spi100k_enable_clock(master);
166 writew(SPI_CTRL_SEN(0) | 175 writew(SPI_CTRL_SEN(0) |
167 SPI_CTRL_WORD_SIZE(len) | 176 SPI_CTRL_WORD_SIZE(len) |
@@ -214,10 +223,6 @@ omap1_spi100k_txrx_pio(struct spi_device *spi, struct spi_transfer *xfer)
214 c = count; 223 c = count;
215 word_len = cs->word_len; 224 word_len = cs->word_len;
216 225
217 /* RX_ONLY mode needs dummy data in TX reg */
218 if (xfer->tx_buf == NULL)
219 spi100k_write_data(spi->master,word_len, 0);
220
221 if (word_len <= 8) { 226 if (word_len <= 8) {
222 u8 *rx; 227 u8 *rx;
223 const u8 *tx; 228 const u8 *tx;
@@ -227,9 +232,9 @@ omap1_spi100k_txrx_pio(struct spi_device *spi, struct spi_transfer *xfer)
227 do { 232 do {
228 c-=1; 233 c-=1;
229 if (xfer->tx_buf != NULL) 234 if (xfer->tx_buf != NULL)
230 spi100k_write_data(spi->master,word_len, *tx); 235 spi100k_write_data(spi->master, word_len, *tx++);
231 if (xfer->rx_buf != NULL) 236 if (xfer->rx_buf != NULL)
232 *rx = spi100k_read_data(spi->master,word_len); 237 *rx++ = spi100k_read_data(spi->master, word_len);
233 } while(c); 238 } while(c);
234 } else if (word_len <= 16) { 239 } else if (word_len <= 16) {
235 u16 *rx; 240 u16 *rx;
@@ -380,10 +385,6 @@ static void omap1_spi100k_work(struct work_struct *work)
380 if (t->len) { 385 if (t->len) {
381 unsigned count; 386 unsigned count;
382 387
383 /* RX_ONLY mode needs dummy data in TX reg */
384 if (t->tx_buf == NULL)
385 spi100k_write_data(spi->master, 8, 0);
386
387 count = omap1_spi100k_txrx_pio(spi, t); 388 count = omap1_spi100k_txrx_pio(spi, t);
388 m->actual_length += count; 389 m->actual_length += count;
389 390
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 1bb1b88780ce..a9e5c79ae52a 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -528,6 +528,10 @@ int spi_register_master(struct spi_master *master)
528 dynamic = 1; 528 dynamic = 1;
529 } 529 }
530 530
531 spin_lock_init(&master->bus_lock_spinlock);
532 mutex_init(&master->bus_lock_mutex);
533 master->bus_lock_flag = 0;
534
531 /* register the device, then userspace will see it. 535 /* register the device, then userspace will see it.
532 * registration fails if the bus ID is in use. 536 * registration fails if the bus ID is in use.
533 */ 537 */
@@ -670,6 +674,35 @@ int spi_setup(struct spi_device *spi)
670} 674}
671EXPORT_SYMBOL_GPL(spi_setup); 675EXPORT_SYMBOL_GPL(spi_setup);
672 676
677static int __spi_async(struct spi_device *spi, struct spi_message *message)
678{
679 struct spi_master *master = spi->master;
680
681 /* Half-duplex links include original MicroWire, and ones with
682 * only one data pin like SPI_3WIRE (switches direction) or where
683 * either MOSI or MISO is missing. They can also be caused by
684 * software limitations.
685 */
686 if ((master->flags & SPI_MASTER_HALF_DUPLEX)
687 || (spi->mode & SPI_3WIRE)) {
688 struct spi_transfer *xfer;
689 unsigned flags = master->flags;
690
691 list_for_each_entry(xfer, &message->transfers, transfer_list) {
692 if (xfer->rx_buf && xfer->tx_buf)
693 return -EINVAL;
694 if ((flags & SPI_MASTER_NO_TX) && xfer->tx_buf)
695 return -EINVAL;
696 if ((flags & SPI_MASTER_NO_RX) && xfer->rx_buf)
697 return -EINVAL;
698 }
699 }
700
701 message->spi = spi;
702 message->status = -EINPROGRESS;
703 return master->transfer(spi, message);
704}
705
673/** 706/**
674 * spi_async - asynchronous SPI transfer 707 * spi_async - asynchronous SPI transfer
675 * @spi: device with which data will be exchanged 708 * @spi: device with which data will be exchanged
@@ -702,33 +735,68 @@ EXPORT_SYMBOL_GPL(spi_setup);
702int spi_async(struct spi_device *spi, struct spi_message *message) 735int spi_async(struct spi_device *spi, struct spi_message *message)
703{ 736{
704 struct spi_master *master = spi->master; 737 struct spi_master *master = spi->master;
738 int ret;
739 unsigned long flags;
705 740
706 /* Half-duplex links include original MicroWire, and ones with 741 spin_lock_irqsave(&master->bus_lock_spinlock, flags);
707 * only one data pin like SPI_3WIRE (switches direction) or where
708 * either MOSI or MISO is missing. They can also be caused by
709 * software limitations.
710 */
711 if ((master->flags & SPI_MASTER_HALF_DUPLEX)
712 || (spi->mode & SPI_3WIRE)) {
713 struct spi_transfer *xfer;
714 unsigned flags = master->flags;
715 742
716 list_for_each_entry(xfer, &message->transfers, transfer_list) { 743 if (master->bus_lock_flag)
717 if (xfer->rx_buf && xfer->tx_buf) 744 ret = -EBUSY;
718 return -EINVAL; 745 else
719 if ((flags & SPI_MASTER_NO_TX) && xfer->tx_buf) 746 ret = __spi_async(spi, message);
720 return -EINVAL;
721 if ((flags & SPI_MASTER_NO_RX) && xfer->rx_buf)
722 return -EINVAL;
723 }
724 }
725 747
726 message->spi = spi; 748 spin_unlock_irqrestore(&master->bus_lock_spinlock, flags);
727 message->status = -EINPROGRESS; 749
728 return master->transfer(spi, message); 750 return ret;
729} 751}
730EXPORT_SYMBOL_GPL(spi_async); 752EXPORT_SYMBOL_GPL(spi_async);
731 753
754/**
755 * spi_async_locked - version of spi_async with exclusive bus usage
756 * @spi: device with which data will be exchanged
757 * @message: describes the data transfers, including completion callback
758 * Context: any (irqs may be blocked, etc)
759 *
760 * This call may be used in_irq and other contexts which can't sleep,
761 * as well as from task contexts which can sleep.
762 *
763 * The completion callback is invoked in a context which can't sleep.
764 * Before that invocation, the value of message->status is undefined.
765 * When the callback is issued, message->status holds either zero (to
766 * indicate complete success) or a negative error code. After that
767 * callback returns, the driver which issued the transfer request may
768 * deallocate the associated memory; it's no longer in use by any SPI
769 * core or controller driver code.
770 *
771 * Note that although all messages to a spi_device are handled in
772 * FIFO order, messages may go to different devices in other orders.
773 * Some device might be higher priority, or have various "hard" access
774 * time requirements, for example.
775 *
776 * On detection of any fault during the transfer, processing of
777 * the entire message is aborted, and the device is deselected.
778 * Until returning from the associated message completion callback,
779 * no other spi_message queued to that device will be processed.
780 * (This rule applies equally to all the synchronous transfer calls,
781 * which are wrappers around this core asynchronous primitive.)
782 */
783int spi_async_locked(struct spi_device *spi, struct spi_message *message)
784{
785 struct spi_master *master = spi->master;
786 int ret;
787 unsigned long flags;
788
789 spin_lock_irqsave(&master->bus_lock_spinlock, flags);
790
791 ret = __spi_async(spi, message);
792
793 spin_unlock_irqrestore(&master->bus_lock_spinlock, flags);
794
795 return ret;
796
797}
798EXPORT_SYMBOL_GPL(spi_async_locked);
799
732 800
733/*-------------------------------------------------------------------------*/ 801/*-------------------------------------------------------------------------*/
734 802
@@ -742,6 +810,32 @@ static void spi_complete(void *arg)
742 complete(arg); 810 complete(arg);
743} 811}
744 812
813static int __spi_sync(struct spi_device *spi, struct spi_message *message,
814 int bus_locked)
815{
816 DECLARE_COMPLETION_ONSTACK(done);
817 int status;
818 struct spi_master *master = spi->master;
819
820 message->complete = spi_complete;
821 message->context = &done;
822
823 if (!bus_locked)
824 mutex_lock(&master->bus_lock_mutex);
825
826 status = spi_async_locked(spi, message);
827
828 if (!bus_locked)
829 mutex_unlock(&master->bus_lock_mutex);
830
831 if (status == 0) {
832 wait_for_completion(&done);
833 status = message->status;
834 }
835 message->context = NULL;
836 return status;
837}
838
745/** 839/**
746 * spi_sync - blocking/synchronous SPI data transfers 840 * spi_sync - blocking/synchronous SPI data transfers
747 * @spi: device with which data will be exchanged 841 * @spi: device with which data will be exchanged
@@ -765,21 +859,86 @@ static void spi_complete(void *arg)
765 */ 859 */
766int spi_sync(struct spi_device *spi, struct spi_message *message) 860int spi_sync(struct spi_device *spi, struct spi_message *message)
767{ 861{
768 DECLARE_COMPLETION_ONSTACK(done); 862 return __spi_sync(spi, message, 0);
769 int status;
770
771 message->complete = spi_complete;
772 message->context = &done;
773 status = spi_async(spi, message);
774 if (status == 0) {
775 wait_for_completion(&done);
776 status = message->status;
777 }
778 message->context = NULL;
779 return status;
780} 863}
781EXPORT_SYMBOL_GPL(spi_sync); 864EXPORT_SYMBOL_GPL(spi_sync);
782 865
866/**
867 * spi_sync_locked - version of spi_sync with exclusive bus usage
868 * @spi: device with which data will be exchanged
869 * @message: describes the data transfers
870 * Context: can sleep
871 *
872 * This call may only be used from a context that may sleep. The sleep
873 * is non-interruptible, and has no timeout. Low-overhead controller
874 * drivers may DMA directly into and out of the message buffers.
875 *
876 * This call should be used by drivers that require exclusive access to the
877 * SPI bus. It has to be preceeded by a spi_bus_lock call. The SPI bus must
878 * be released by a spi_bus_unlock call when the exclusive access is over.
879 *
880 * It returns zero on success, else a negative error code.
881 */
882int spi_sync_locked(struct spi_device *spi, struct spi_message *message)
883{
884 return __spi_sync(spi, message, 1);
885}
886EXPORT_SYMBOL_GPL(spi_sync_locked);
887
888/**
889 * spi_bus_lock - obtain a lock for exclusive SPI bus usage
890 * @master: SPI bus master that should be locked for exclusive bus access
891 * Context: can sleep
892 *
893 * This call may only be used from a context that may sleep. The sleep
894 * is non-interruptible, and has no timeout.
895 *
896 * This call should be used by drivers that require exclusive access to the
897 * SPI bus. The SPI bus must be released by a spi_bus_unlock call when the
898 * exclusive access is over. Data transfer must be done by spi_sync_locked
899 * and spi_async_locked calls when the SPI bus lock is held.
900 *
901 * It returns zero on success, else a negative error code.
902 */
903int spi_bus_lock(struct spi_master *master)
904{
905 unsigned long flags;
906
907 mutex_lock(&master->bus_lock_mutex);
908
909 spin_lock_irqsave(&master->bus_lock_spinlock, flags);
910 master->bus_lock_flag = 1;
911 spin_unlock_irqrestore(&master->bus_lock_spinlock, flags);
912
913 /* mutex remains locked until spi_bus_unlock is called */
914
915 return 0;
916}
917EXPORT_SYMBOL_GPL(spi_bus_lock);
918
919/**
920 * spi_bus_unlock - release the lock for exclusive SPI bus usage
921 * @master: SPI bus master that was locked for exclusive bus access
922 * Context: can sleep
923 *
924 * This call may only be used from a context that may sleep. The sleep
925 * is non-interruptible, and has no timeout.
926 *
927 * This call releases an SPI bus lock previously obtained by an spi_bus_lock
928 * call.
929 *
930 * It returns zero on success, else a negative error code.
931 */
932int spi_bus_unlock(struct spi_master *master)
933{
934 master->bus_lock_flag = 0;
935
936 mutex_unlock(&master->bus_lock_mutex);
937
938 return 0;
939}
940EXPORT_SYMBOL_GPL(spi_bus_unlock);
941
783/* portable code must never pass more than 32 bytes */ 942/* portable code must never pass more than 32 bytes */
784#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES) 943#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
785 944
diff --git a/drivers/spi/spi_bitbang.c b/drivers/spi/spi_bitbang.c
index 5265330a528f..8b55724d5f39 100644
--- a/drivers/spi/spi_bitbang.c
+++ b/drivers/spi/spi_bitbang.c
@@ -259,7 +259,6 @@ static void bitbang_work(struct work_struct *work)
259 struct spi_bitbang *bitbang = 259 struct spi_bitbang *bitbang =
260 container_of(work, struct spi_bitbang, work); 260 container_of(work, struct spi_bitbang, work);
261 unsigned long flags; 261 unsigned long flags;
262 int do_setup = -1;
263 int (*setup_transfer)(struct spi_device *, 262 int (*setup_transfer)(struct spi_device *,
264 struct spi_transfer *); 263 struct spi_transfer *);
265 264
@@ -275,6 +274,7 @@ static void bitbang_work(struct work_struct *work)
275 unsigned tmp; 274 unsigned tmp;
276 unsigned cs_change; 275 unsigned cs_change;
277 int status; 276 int status;
277 int do_setup = -1;
278 278
279 m = container_of(bitbang->queue.next, struct spi_message, 279 m = container_of(bitbang->queue.next, struct spi_message,
280 queue); 280 queue);
@@ -307,6 +307,8 @@ static void bitbang_work(struct work_struct *work)
307 status = setup_transfer(spi, t); 307 status = setup_transfer(spi, t);
308 if (status < 0) 308 if (status < 0)
309 break; 309 break;
310 if (do_setup == -1)
311 do_setup = 0;
310 } 312 }
311 313
312 /* set up default clock polarity, and activate chip; 314 /* set up default clock polarity, and activate chip;
@@ -367,11 +369,6 @@ static void bitbang_work(struct work_struct *work)
367 m->status = status; 369 m->status = status;
368 m->complete(m->context); 370 m->complete(m->context);
369 371
370 /* restore speed and wordsize if it was overridden */
371 if (do_setup == 1)
372 setup_transfer(spi, NULL);
373 do_setup = 0;
374
375 /* normally deactivate chipselect ... unless no error and 372 /* normally deactivate chipselect ... unless no error and
376 * cs_change has hinted that the next message will probably 373 * cs_change has hinted that the next message will probably
377 * be for this chip too. 374 * be for this chip too.
diff --git a/drivers/spi/spi_bitbang_txrx.h b/drivers/spi/spi_bitbang_txrx.h
index fc033bbf9180..c16bf853c3eb 100644
--- a/drivers/spi/spi_bitbang_txrx.h
+++ b/drivers/spi/spi_bitbang_txrx.h
@@ -44,7 +44,7 @@
44 44
45static inline u32 45static inline u32
46bitbang_txrx_be_cpha0(struct spi_device *spi, 46bitbang_txrx_be_cpha0(struct spi_device *spi,
47 unsigned nsecs, unsigned cpol, 47 unsigned nsecs, unsigned cpol, unsigned flags,
48 u32 word, u8 bits) 48 u32 word, u8 bits)
49{ 49{
50 /* if (cpol == 0) this is SPI_MODE_0; else this is SPI_MODE_2 */ 50 /* if (cpol == 0) this is SPI_MODE_0; else this is SPI_MODE_2 */
@@ -53,7 +53,8 @@ bitbang_txrx_be_cpha0(struct spi_device *spi,
53 for (word <<= (32 - bits); likely(bits); bits--) { 53 for (word <<= (32 - bits); likely(bits); bits--) {
54 54
55 /* setup MSB (to slave) on trailing edge */ 55 /* setup MSB (to slave) on trailing edge */
56 setmosi(spi, word & (1 << 31)); 56 if ((flags & SPI_MASTER_NO_TX) == 0)
57 setmosi(spi, word & (1 << 31));
57 spidelay(nsecs); /* T(setup) */ 58 spidelay(nsecs); /* T(setup) */
58 59
59 setsck(spi, !cpol); 60 setsck(spi, !cpol);
@@ -61,7 +62,8 @@ bitbang_txrx_be_cpha0(struct spi_device *spi,
61 62
62 /* sample MSB (from slave) on leading edge */ 63 /* sample MSB (from slave) on leading edge */
63 word <<= 1; 64 word <<= 1;
64 word |= getmiso(spi); 65 if ((flags & SPI_MASTER_NO_RX) == 0)
66 word |= getmiso(spi);
65 setsck(spi, cpol); 67 setsck(spi, cpol);
66 } 68 }
67 return word; 69 return word;
@@ -69,7 +71,7 @@ bitbang_txrx_be_cpha0(struct spi_device *spi,
69 71
70static inline u32 72static inline u32
71bitbang_txrx_be_cpha1(struct spi_device *spi, 73bitbang_txrx_be_cpha1(struct spi_device *spi,
72 unsigned nsecs, unsigned cpol, 74 unsigned nsecs, unsigned cpol, unsigned flags,
73 u32 word, u8 bits) 75 u32 word, u8 bits)
74{ 76{
75 /* if (cpol == 0) this is SPI_MODE_1; else this is SPI_MODE_3 */ 77 /* if (cpol == 0) this is SPI_MODE_1; else this is SPI_MODE_3 */
@@ -79,7 +81,8 @@ bitbang_txrx_be_cpha1(struct spi_device *spi,
79 81
80 /* setup MSB (to slave) on leading edge */ 82 /* setup MSB (to slave) on leading edge */
81 setsck(spi, !cpol); 83 setsck(spi, !cpol);
82 setmosi(spi, word & (1 << 31)); 84 if ((flags & SPI_MASTER_NO_TX) == 0)
85 setmosi(spi, word & (1 << 31));
83 spidelay(nsecs); /* T(setup) */ 86 spidelay(nsecs); /* T(setup) */
84 87
85 setsck(spi, cpol); 88 setsck(spi, cpol);
@@ -87,7 +90,8 @@ bitbang_txrx_be_cpha1(struct spi_device *spi,
87 90
88 /* sample MSB (from slave) on trailing edge */ 91 /* sample MSB (from slave) on trailing edge */
89 word <<= 1; 92 word <<= 1;
90 word |= getmiso(spi); 93 if ((flags & SPI_MASTER_NO_RX) == 0)
94 word |= getmiso(spi);
91 } 95 }
92 return word; 96 return word;
93} 97}
diff --git a/drivers/spi/spi_butterfly.c b/drivers/spi/spi_butterfly.c
index 8b5281281111..0d4ceba3b590 100644
--- a/drivers/spi/spi_butterfly.c
+++ b/drivers/spi/spi_butterfly.c
@@ -156,7 +156,7 @@ butterfly_txrx_word_mode0(struct spi_device *spi,
156 unsigned nsecs, 156 unsigned nsecs,
157 u32 word, u8 bits) 157 u32 word, u8 bits)
158{ 158{
159 return bitbang_txrx_be_cpha0(spi, nsecs, 0, word, bits); 159 return bitbang_txrx_be_cpha0(spi, nsecs, 0, 0, word, bits);
160} 160}
161 161
162/*----------------------------------------------------------------------*/ 162/*----------------------------------------------------------------------*/
diff --git a/drivers/spi/spi_gpio.c b/drivers/spi/spi_gpio.c
index 7edbd5807e0e..e24a63498acb 100644
--- a/drivers/spi/spi_gpio.c
+++ b/drivers/spi/spi_gpio.c
@@ -146,25 +146,63 @@ static inline int getmiso(const struct spi_device *spi)
146static u32 spi_gpio_txrx_word_mode0(struct spi_device *spi, 146static u32 spi_gpio_txrx_word_mode0(struct spi_device *spi,
147 unsigned nsecs, u32 word, u8 bits) 147 unsigned nsecs, u32 word, u8 bits)
148{ 148{
149 return bitbang_txrx_be_cpha0(spi, nsecs, 0, word, bits); 149 return bitbang_txrx_be_cpha0(spi, nsecs, 0, 0, word, bits);
150} 150}
151 151
152static u32 spi_gpio_txrx_word_mode1(struct spi_device *spi, 152static u32 spi_gpio_txrx_word_mode1(struct spi_device *spi,
153 unsigned nsecs, u32 word, u8 bits) 153 unsigned nsecs, u32 word, u8 bits)
154{ 154{
155 return bitbang_txrx_be_cpha1(spi, nsecs, 0, word, bits); 155 return bitbang_txrx_be_cpha1(spi, nsecs, 0, 0, word, bits);
156} 156}
157 157
158static u32 spi_gpio_txrx_word_mode2(struct spi_device *spi, 158static u32 spi_gpio_txrx_word_mode2(struct spi_device *spi,
159 unsigned nsecs, u32 word, u8 bits) 159 unsigned nsecs, u32 word, u8 bits)
160{ 160{
161 return bitbang_txrx_be_cpha0(spi, nsecs, 1, word, bits); 161 return bitbang_txrx_be_cpha0(spi, nsecs, 1, 0, word, bits);
162} 162}
163 163
164static u32 spi_gpio_txrx_word_mode3(struct spi_device *spi, 164static u32 spi_gpio_txrx_word_mode3(struct spi_device *spi,
165 unsigned nsecs, u32 word, u8 bits) 165 unsigned nsecs, u32 word, u8 bits)
166{ 166{
167 return bitbang_txrx_be_cpha1(spi, nsecs, 1, word, bits); 167 return bitbang_txrx_be_cpha1(spi, nsecs, 1, 0, word, bits);
168}
169
170/*
171 * These functions do not call setmosi or getmiso if respective flag
172 * (SPI_MASTER_NO_RX or SPI_MASTER_NO_TX) is set, so they are safe to
173 * call when such pin is not present or defined in the controller.
174 * A separate set of callbacks is defined to get highest possible
175 * speed in the generic case (when both MISO and MOSI lines are
176 * available), as optimiser will remove the checks when argument is
177 * constant.
178 */
179
180static u32 spi_gpio_spec_txrx_word_mode0(struct spi_device *spi,
181 unsigned nsecs, u32 word, u8 bits)
182{
183 unsigned flags = spi->master->flags;
184 return bitbang_txrx_be_cpha0(spi, nsecs, 0, flags, word, bits);
185}
186
187static u32 spi_gpio_spec_txrx_word_mode1(struct spi_device *spi,
188 unsigned nsecs, u32 word, u8 bits)
189{
190 unsigned flags = spi->master->flags;
191 return bitbang_txrx_be_cpha1(spi, nsecs, 0, flags, word, bits);
192}
193
194static u32 spi_gpio_spec_txrx_word_mode2(struct spi_device *spi,
195 unsigned nsecs, u32 word, u8 bits)
196{
197 unsigned flags = spi->master->flags;
198 return bitbang_txrx_be_cpha0(spi, nsecs, 1, flags, word, bits);
199}
200
201static u32 spi_gpio_spec_txrx_word_mode3(struct spi_device *spi,
202 unsigned nsecs, u32 word, u8 bits)
203{
204 unsigned flags = spi->master->flags;
205 return bitbang_txrx_be_cpha1(spi, nsecs, 1, flags, word, bits);
168} 206}
169 207
170/*----------------------------------------------------------------------*/ 208/*----------------------------------------------------------------------*/
@@ -232,19 +270,30 @@ static int __init spi_gpio_alloc(unsigned pin, const char *label, bool is_in)
232} 270}
233 271
234static int __init 272static int __init
235spi_gpio_request(struct spi_gpio_platform_data *pdata, const char *label) 273spi_gpio_request(struct spi_gpio_platform_data *pdata, const char *label,
274 u16 *res_flags)
236{ 275{
237 int value; 276 int value;
238 277
239 /* NOTE: SPI_*_GPIO symbols may reference "pdata" */ 278 /* NOTE: SPI_*_GPIO symbols may reference "pdata" */
240 279
241 value = spi_gpio_alloc(SPI_MOSI_GPIO, label, false); 280 if (SPI_MOSI_GPIO != SPI_GPIO_NO_MOSI) {
242 if (value) 281 value = spi_gpio_alloc(SPI_MOSI_GPIO, label, false);
243 goto done; 282 if (value)
283 goto done;
284 } else {
285 /* HW configuration without MOSI pin */
286 *res_flags |= SPI_MASTER_NO_TX;
287 }
244 288
245 value = spi_gpio_alloc(SPI_MISO_GPIO, label, true); 289 if (SPI_MISO_GPIO != SPI_GPIO_NO_MISO) {
246 if (value) 290 value = spi_gpio_alloc(SPI_MISO_GPIO, label, true);
247 goto free_mosi; 291 if (value)
292 goto free_mosi;
293 } else {
294 /* HW configuration without MISO pin */
295 *res_flags |= SPI_MASTER_NO_RX;
296 }
248 297
249 value = spi_gpio_alloc(SPI_SCK_GPIO, label, false); 298 value = spi_gpio_alloc(SPI_SCK_GPIO, label, false);
250 if (value) 299 if (value)
@@ -253,9 +302,11 @@ spi_gpio_request(struct spi_gpio_platform_data *pdata, const char *label)
253 goto done; 302 goto done;
254 303
255free_miso: 304free_miso:
256 gpio_free(SPI_MISO_GPIO); 305 if (SPI_MISO_GPIO != SPI_GPIO_NO_MISO)
306 gpio_free(SPI_MISO_GPIO);
257free_mosi: 307free_mosi:
258 gpio_free(SPI_MOSI_GPIO); 308 if (SPI_MOSI_GPIO != SPI_GPIO_NO_MOSI)
309 gpio_free(SPI_MOSI_GPIO);
259done: 310done:
260 return value; 311 return value;
261} 312}
@@ -266,6 +317,7 @@ static int __init spi_gpio_probe(struct platform_device *pdev)
266 struct spi_master *master; 317 struct spi_master *master;
267 struct spi_gpio *spi_gpio; 318 struct spi_gpio *spi_gpio;
268 struct spi_gpio_platform_data *pdata; 319 struct spi_gpio_platform_data *pdata;
320 u16 master_flags = 0;
269 321
270 pdata = pdev->dev.platform_data; 322 pdata = pdev->dev.platform_data;
271#ifdef GENERIC_BITBANG 323#ifdef GENERIC_BITBANG
@@ -273,7 +325,7 @@ static int __init spi_gpio_probe(struct platform_device *pdev)
273 return -ENODEV; 325 return -ENODEV;
274#endif 326#endif
275 327
276 status = spi_gpio_request(pdata, dev_name(&pdev->dev)); 328 status = spi_gpio_request(pdata, dev_name(&pdev->dev), &master_flags);
277 if (status < 0) 329 if (status < 0)
278 return status; 330 return status;
279 331
@@ -289,6 +341,7 @@ static int __init spi_gpio_probe(struct platform_device *pdev)
289 if (pdata) 341 if (pdata)
290 spi_gpio->pdata = *pdata; 342 spi_gpio->pdata = *pdata;
291 343
344 master->flags = master_flags;
292 master->bus_num = pdev->id; 345 master->bus_num = pdev->id;
293 master->num_chipselect = SPI_N_CHIPSEL; 346 master->num_chipselect = SPI_N_CHIPSEL;
294 master->setup = spi_gpio_setup; 347 master->setup = spi_gpio_setup;
@@ -296,10 +349,18 @@ static int __init spi_gpio_probe(struct platform_device *pdev)
296 349
297 spi_gpio->bitbang.master = spi_master_get(master); 350 spi_gpio->bitbang.master = spi_master_get(master);
298 spi_gpio->bitbang.chipselect = spi_gpio_chipselect; 351 spi_gpio->bitbang.chipselect = spi_gpio_chipselect;
299 spi_gpio->bitbang.txrx_word[SPI_MODE_0] = spi_gpio_txrx_word_mode0; 352
300 spi_gpio->bitbang.txrx_word[SPI_MODE_1] = spi_gpio_txrx_word_mode1; 353 if ((master_flags & (SPI_MASTER_NO_RX | SPI_MASTER_NO_RX)) == 0) {
301 spi_gpio->bitbang.txrx_word[SPI_MODE_2] = spi_gpio_txrx_word_mode2; 354 spi_gpio->bitbang.txrx_word[SPI_MODE_0] = spi_gpio_txrx_word_mode0;
302 spi_gpio->bitbang.txrx_word[SPI_MODE_3] = spi_gpio_txrx_word_mode3; 355 spi_gpio->bitbang.txrx_word[SPI_MODE_1] = spi_gpio_txrx_word_mode1;
356 spi_gpio->bitbang.txrx_word[SPI_MODE_2] = spi_gpio_txrx_word_mode2;
357 spi_gpio->bitbang.txrx_word[SPI_MODE_3] = spi_gpio_txrx_word_mode3;
358 } else {
359 spi_gpio->bitbang.txrx_word[SPI_MODE_0] = spi_gpio_spec_txrx_word_mode0;
360 spi_gpio->bitbang.txrx_word[SPI_MODE_1] = spi_gpio_spec_txrx_word_mode1;
361 spi_gpio->bitbang.txrx_word[SPI_MODE_2] = spi_gpio_spec_txrx_word_mode2;
362 spi_gpio->bitbang.txrx_word[SPI_MODE_3] = spi_gpio_spec_txrx_word_mode3;
363 }
303 spi_gpio->bitbang.setup_transfer = spi_bitbang_setup_transfer; 364 spi_gpio->bitbang.setup_transfer = spi_bitbang_setup_transfer;
304 spi_gpio->bitbang.flags = SPI_CS_HIGH; 365 spi_gpio->bitbang.flags = SPI_CS_HIGH;
305 366
@@ -307,8 +368,10 @@ static int __init spi_gpio_probe(struct platform_device *pdev)
307 if (status < 0) { 368 if (status < 0) {
308 spi_master_put(spi_gpio->bitbang.master); 369 spi_master_put(spi_gpio->bitbang.master);
309gpio_free: 370gpio_free:
310 gpio_free(SPI_MISO_GPIO); 371 if (SPI_MISO_GPIO != SPI_GPIO_NO_MISO)
311 gpio_free(SPI_MOSI_GPIO); 372 gpio_free(SPI_MISO_GPIO);
373 if (SPI_MOSI_GPIO != SPI_GPIO_NO_MOSI)
374 gpio_free(SPI_MOSI_GPIO);
312 gpio_free(SPI_SCK_GPIO); 375 gpio_free(SPI_SCK_GPIO);
313 spi_master_put(master); 376 spi_master_put(master);
314 } 377 }
@@ -331,8 +394,10 @@ static int __exit spi_gpio_remove(struct platform_device *pdev)
331 394
332 platform_set_drvdata(pdev, NULL); 395 platform_set_drvdata(pdev, NULL);
333 396
334 gpio_free(SPI_MISO_GPIO); 397 if (SPI_MISO_GPIO != SPI_GPIO_NO_MISO)
335 gpio_free(SPI_MOSI_GPIO); 398 gpio_free(SPI_MISO_GPIO);
399 if (SPI_MOSI_GPIO != SPI_GPIO_NO_MOSI)
400 gpio_free(SPI_MOSI_GPIO);
336 gpio_free(SPI_SCK_GPIO); 401 gpio_free(SPI_SCK_GPIO);
337 402
338 return status; 403 return status;
diff --git a/drivers/spi/spi_lm70llp.c b/drivers/spi/spi_lm70llp.c
index 86fb7b5993db..7746a41ab6d6 100644
--- a/drivers/spi/spi_lm70llp.c
+++ b/drivers/spi/spi_lm70llp.c
@@ -191,7 +191,7 @@ static void lm70_chipselect(struct spi_device *spi, int value)
191 */ 191 */
192static u32 lm70_txrx(struct spi_device *spi, unsigned nsecs, u32 word, u8 bits) 192static u32 lm70_txrx(struct spi_device *spi, unsigned nsecs, u32 word, u8 bits)
193{ 193{
194 return bitbang_txrx_be_cpha0(spi, nsecs, 0, word, bits); 194 return bitbang_txrx_be_cpha0(spi, nsecs, 0, 0, word, bits);
195} 195}
196 196
197static void spi_lm70llp_attach(struct parport *p) 197static void spi_lm70llp_attach(struct parport *p)
diff --git a/drivers/spi/spi_mpc8xxx.c b/drivers/spi/spi_mpc8xxx.c
index aad9ae1b9c69..d31b57f7baaf 100644
--- a/drivers/spi/spi_mpc8xxx.c
+++ b/drivers/spi/spi_mpc8xxx.c
@@ -1236,7 +1236,7 @@ static int of_mpc8xxx_spi_free_chipselects(struct device *dev)
1236 return 0; 1236 return 0;
1237} 1237}
1238 1238
1239static int __devinit of_mpc8xxx_spi_probe(struct of_device *ofdev, 1239static int __devinit of_mpc8xxx_spi_probe(struct platform_device *ofdev,
1240 const struct of_device_id *ofid) 1240 const struct of_device_id *ofid)
1241{ 1241{
1242 struct device *dev = &ofdev->dev; 1242 struct device *dev = &ofdev->dev;
@@ -1308,7 +1308,7 @@ err_clk:
1308 return ret; 1308 return ret;
1309} 1309}
1310 1310
1311static int __devexit of_mpc8xxx_spi_remove(struct of_device *ofdev) 1311static int __devexit of_mpc8xxx_spi_remove(struct platform_device *ofdev)
1312{ 1312{
1313 int ret; 1313 int ret;
1314 1314
diff --git a/drivers/spi/spi_ppc4xx.c b/drivers/spi/spi_ppc4xx.c
index 0f5fa7e2a550..80e172d3e72a 100644
--- a/drivers/spi/spi_ppc4xx.c
+++ b/drivers/spi/spi_ppc4xx.c
@@ -388,9 +388,9 @@ static void free_gpios(struct ppc4xx_spi *hw)
388} 388}
389 389
390/* 390/*
391 * of_device layer stuff... 391 * platform_device layer stuff...
392 */ 392 */
393static int __init spi_ppc4xx_of_probe(struct of_device *op, 393static int __init spi_ppc4xx_of_probe(struct platform_device *op,
394 const struct of_device_id *match) 394 const struct of_device_id *match)
395{ 395{
396 struct ppc4xx_spi *hw; 396 struct ppc4xx_spi *hw;
@@ -565,7 +565,7 @@ free_master:
565 return ret; 565 return ret;
566} 566}
567 567
568static int __exit spi_ppc4xx_of_remove(struct of_device *op) 568static int __exit spi_ppc4xx_of_remove(struct platform_device *op)
569{ 569{
570 struct spi_master *master = dev_get_drvdata(&op->dev); 570 struct spi_master *master = dev_get_drvdata(&op->dev);
571 struct ppc4xx_spi *hw = spi_master_get_devdata(master); 571 struct ppc4xx_spi *hw = spi_master_get_devdata(master);
diff --git a/drivers/spi/spi_s3c24xx_gpio.c b/drivers/spi/spi_s3c24xx_gpio.c
index 8979a75dbd7b..be991359bf92 100644
--- a/drivers/spi/spi_s3c24xx_gpio.c
+++ b/drivers/spi/spi_s3c24xx_gpio.c
@@ -64,25 +64,25 @@ static inline u32 getmiso(struct spi_device *dev)
64static u32 s3c2410_spigpio_txrx_mode0(struct spi_device *spi, 64static u32 s3c2410_spigpio_txrx_mode0(struct spi_device *spi,
65 unsigned nsecs, u32 word, u8 bits) 65 unsigned nsecs, u32 word, u8 bits)
66{ 66{
67 return bitbang_txrx_be_cpha0(spi, nsecs, 0, word, bits); 67 return bitbang_txrx_be_cpha0(spi, nsecs, 0, 0, word, bits);
68} 68}
69 69
70static u32 s3c2410_spigpio_txrx_mode1(struct spi_device *spi, 70static u32 s3c2410_spigpio_txrx_mode1(struct spi_device *spi,
71 unsigned nsecs, u32 word, u8 bits) 71 unsigned nsecs, u32 word, u8 bits)
72{ 72{
73 return bitbang_txrx_be_cpha1(spi, nsecs, 0, word, bits); 73 return bitbang_txrx_be_cpha1(spi, nsecs, 0, 0, word, bits);
74} 74}
75 75
76static u32 s3c2410_spigpio_txrx_mode2(struct spi_device *spi, 76static u32 s3c2410_spigpio_txrx_mode2(struct spi_device *spi,
77 unsigned nsecs, u32 word, u8 bits) 77 unsigned nsecs, u32 word, u8 bits)
78{ 78{
79 return bitbang_txrx_be_cpha0(spi, nsecs, 1, word, bits); 79 return bitbang_txrx_be_cpha0(spi, nsecs, 1, 0, word, bits);
80} 80}
81 81
82static u32 s3c2410_spigpio_txrx_mode3(struct spi_device *spi, 82static u32 s3c2410_spigpio_txrx_mode3(struct spi_device *spi,
83 unsigned nsecs, u32 word, u8 bits) 83 unsigned nsecs, u32 word, u8 bits)
84{ 84{
85 return bitbang_txrx_be_cpha1(spi, nsecs, 1, word, bits); 85 return bitbang_txrx_be_cpha1(spi, nsecs, 1, 0, word, bits);
86} 86}
87 87
88 88
diff --git a/drivers/spi/spi_sh_sci.c b/drivers/spi/spi_sh_sci.c
index a511be7961a0..5c6439161199 100644
--- a/drivers/spi/spi_sh_sci.c
+++ b/drivers/spi/spi_sh_sci.c
@@ -83,25 +83,25 @@ static inline u32 getmiso(struct spi_device *dev)
83static u32 sh_sci_spi_txrx_mode0(struct spi_device *spi, 83static u32 sh_sci_spi_txrx_mode0(struct spi_device *spi,
84 unsigned nsecs, u32 word, u8 bits) 84 unsigned nsecs, u32 word, u8 bits)
85{ 85{
86 return bitbang_txrx_be_cpha0(spi, nsecs, 0, word, bits); 86 return bitbang_txrx_be_cpha0(spi, nsecs, 0, 0, word, bits);
87} 87}
88 88
89static u32 sh_sci_spi_txrx_mode1(struct spi_device *spi, 89static u32 sh_sci_spi_txrx_mode1(struct spi_device *spi,
90 unsigned nsecs, u32 word, u8 bits) 90 unsigned nsecs, u32 word, u8 bits)
91{ 91{
92 return bitbang_txrx_be_cpha1(spi, nsecs, 0, word, bits); 92 return bitbang_txrx_be_cpha1(spi, nsecs, 0, 0, word, bits);
93} 93}
94 94
95static u32 sh_sci_spi_txrx_mode2(struct spi_device *spi, 95static u32 sh_sci_spi_txrx_mode2(struct spi_device *spi,
96 unsigned nsecs, u32 word, u8 bits) 96 unsigned nsecs, u32 word, u8 bits)
97{ 97{
98 return bitbang_txrx_be_cpha0(spi, nsecs, 1, word, bits); 98 return bitbang_txrx_be_cpha0(spi, nsecs, 1, 0, word, bits);
99} 99}
100 100
101static u32 sh_sci_spi_txrx_mode3(struct spi_device *spi, 101static u32 sh_sci_spi_txrx_mode3(struct spi_device *spi,
102 unsigned nsecs, u32 word, u8 bits) 102 unsigned nsecs, u32 word, u8 bits)
103{ 103{
104 return bitbang_txrx_be_cpha1(spi, nsecs, 1, word, bits); 104 return bitbang_txrx_be_cpha1(spi, nsecs, 1, 0, word, bits);
105} 105}
106 106
107static void sh_sci_spi_chipselect(struct spi_device *dev, int value) 107static void sh_sci_spi_chipselect(struct spi_device *dev, int value)
diff --git a/drivers/spi/xilinx_spi_of.c b/drivers/spi/xilinx_spi_of.c
index f53d3f6b9f61..b66c2dbf20a5 100644
--- a/drivers/spi/xilinx_spi_of.c
+++ b/drivers/spi/xilinx_spi_of.c
@@ -38,7 +38,7 @@
38#include "xilinx_spi.h" 38#include "xilinx_spi.h"
39 39
40 40
41static int __devinit xilinx_spi_of_probe(struct of_device *ofdev, 41static int __devinit xilinx_spi_of_probe(struct platform_device *ofdev,
42 const struct of_device_id *match) 42 const struct of_device_id *match)
43{ 43{
44 struct spi_master *master; 44 struct spi_master *master;
@@ -84,7 +84,7 @@ static int __devinit xilinx_spi_of_probe(struct of_device *ofdev,
84 return 0; 84 return 0;
85} 85}
86 86
87static int __devexit xilinx_spi_remove(struct of_device *ofdev) 87static int __devexit xilinx_spi_remove(struct platform_device *ofdev)
88{ 88{
89 xilinx_spi_deinit(dev_get_drvdata(&ofdev->dev)); 89 xilinx_spi_deinit(dev_get_drvdata(&ofdev->dev));
90 dev_set_drvdata(&ofdev->dev, 0); 90 dev_set_drvdata(&ofdev->dev, 0);
@@ -93,7 +93,7 @@ static int __devexit xilinx_spi_remove(struct of_device *ofdev)
93 return 0; 93 return 0;
94} 94}
95 95
96static int __exit xilinx_spi_of_remove(struct of_device *op) 96static int __exit xilinx_spi_of_remove(struct platform_device *op)
97{ 97{
98 return xilinx_spi_remove(op); 98 return xilinx_spi_remove(op);
99} 99}
diff --git a/drivers/staging/easycap/easycap.h b/drivers/staging/easycap/easycap.h
index ad836d2d26fe..f3c827eb0abe 100644
--- a/drivers/staging/easycap/easycap.h
+++ b/drivers/staging/easycap/easycap.h
@@ -463,15 +463,12 @@ struct data_buffer audio_buffer[];
463void easycap_complete(struct urb *); 463void easycap_complete(struct urb *);
464int easycap_open(struct inode *, struct file *); 464int easycap_open(struct inode *, struct file *);
465int easycap_release(struct inode *, struct file *); 465int easycap_release(struct inode *, struct file *);
466int easycap_ioctl(struct inode *, struct file *, \ 466long easycap_ioctl(struct file *, unsigned int, unsigned long);
467 unsigned int, unsigned long);
468 467
469/*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ 468/*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
470#if defined(EASYCAP_IS_VIDEODEV_CLIENT) 469#if defined(EASYCAP_IS_VIDEODEV_CLIENT)
471int easycap_open_noinode(struct file *); 470int easycap_open_noinode(struct file *);
472int easycap_release_noinode(struct file *); 471int easycap_release_noinode(struct file *);
473long easycap_ioctl_noinode(struct file *, \
474 unsigned int, unsigned long);
475int videodev_release(struct video_device *); 472int videodev_release(struct video_device *);
476#endif /*EASYCAP_IS_VIDEODEV_CLIENT*/ 473#endif /*EASYCAP_IS_VIDEODEV_CLIENT*/
477/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ 474/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
@@ -515,8 +512,7 @@ void easysnd_complete(struct urb *);
515ssize_t easysnd_read(struct file *, char __user *, size_t, loff_t *); 512ssize_t easysnd_read(struct file *, char __user *, size_t, loff_t *);
516int easysnd_open(struct inode *, struct file *); 513int easysnd_open(struct inode *, struct file *);
517int easysnd_release(struct inode *, struct file *); 514int easysnd_release(struct inode *, struct file *);
518int easysnd_ioctl(struct inode *, struct file *, \ 515long easysnd_ioctl(struct file *, unsigned int, unsigned long);
519 unsigned int, unsigned long);
520unsigned int easysnd_poll(struct file *, poll_table *); 516unsigned int easysnd_poll(struct file *, poll_table *);
521void easysnd_delete(struct kref *); 517void easysnd_delete(struct kref *);
522int submit_audio_urbs(struct easycap *); 518int submit_audio_urbs(struct easycap *);
diff --git a/drivers/staging/easycap/easycap_ioctl.c b/drivers/staging/easycap/easycap_ioctl.c
index 276b63dfe27e..9a42ae02cd5d 100644
--- a/drivers/staging/easycap/easycap_ioctl.c
+++ b/drivers/staging/easycap/easycap_ioctl.c
@@ -25,6 +25,7 @@
25*/ 25*/
26/*****************************************************************************/ 26/*****************************************************************************/
27 27
28#include <linux/smp_lock.h>
28#include "easycap.h" 29#include "easycap.h"
29#include "easycap_debug.h" 30#include "easycap_debug.h"
30#include "easycap_standard.h" 31#include "easycap_standard.h"
@@ -773,19 +774,10 @@ while (0xFFFFFFFF != easycap_control[i1].id) {
773SAY("WARNING: failed to adjust mute: control not found\n"); 774SAY("WARNING: failed to adjust mute: control not found\n");
774return -ENOENT; 775return -ENOENT;
775} 776}
776/****************************************************************************/ 777
777/*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
778#if defined(EASYCAP_IS_VIDEODEV_CLIENT)
779long
780easycap_ioctl_noinode(struct file *file, unsigned int cmd, unsigned long arg)\
781 {
782 return easycap_ioctl((struct inode *)NULL, file, cmd, arg);
783}
784#endif /*EASYCAP_IS_VIDEODEV_CLIENT*/
785/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
786/*--------------------------------------------------------------------------*/ 778/*--------------------------------------------------------------------------*/
787int easycap_ioctl(struct inode *inode, struct file *file, \ 779static int easycap_ioctl_bkl(struct inode *inode, struct file *file,
788 unsigned int cmd, unsigned long arg) 780 unsigned int cmd, unsigned long arg)
789{ 781{
790static struct easycap *peasycap; 782static struct easycap *peasycap;
791static struct usb_device *p; 783static struct usb_device *p;
@@ -1956,19 +1948,22 @@ default: {
1956} 1948}
1957return 0; 1949return 0;
1958} 1950}
1959/****************************************************************************/ 1951
1960/*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ 1952long easycap_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
1961#if defined(EASYCAP_IS_VIDEODEV_CLIENT)
1962long
1963easysnd_ioctl_noinode(struct file *file, unsigned int cmd, unsigned long arg)
1964{ 1953{
1965 return easysnd_ioctl((struct inode *)NULL, file, cmd, arg); 1954 struct inode *inode = file->f_dentry->d_inode;
1955 long ret;
1956
1957 lock_kernel();
1958 ret = easycap_ioctl_bkl(inode, file, cmd, arg);
1959 unlock_kernel();
1960
1961 return ret;
1966} 1962}
1967#endif /*EASYCAP_IS_VIDEODEV_CLIENT*/ 1963
1968/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
1969/*--------------------------------------------------------------------------*/ 1964/*--------------------------------------------------------------------------*/
1970int easysnd_ioctl(struct inode *inode, struct file *file, \ 1965static int easysnd_ioctl_bkl(struct inode *inode, struct file *file,
1971 unsigned int cmd, unsigned long arg) 1966 unsigned int cmd, unsigned long arg)
1972{ 1967{
1973struct easycap *peasycap; 1968struct easycap *peasycap;
1974struct usb_device *p; 1969struct usb_device *p;
@@ -2158,6 +2153,19 @@ default: {
2158} 2153}
2159return 0; 2154return 0;
2160} 2155}
2156
2157long easysnd_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
2158{
2159 struct inode *inode = file->f_dentry->d_inode;
2160 long ret;
2161
2162 lock_kernel();
2163 ret = easysnd_ioctl_bkl(inode, file, cmd, arg);
2164 unlock_kernel();
2165
2166 return ret;
2167}
2168
2161/*****************************************************************************/ 2169/*****************************************************************************/
2162int explain_ioctl(__u32 wot) 2170int explain_ioctl(__u32 wot)
2163{ 2171{
diff --git a/drivers/staging/easycap/easycap_main.c b/drivers/staging/easycap/easycap_main.c
index 09c194ce10a3..5a4bbd9b453f 100644
--- a/drivers/staging/easycap/easycap_main.c
+++ b/drivers/staging/easycap/easycap_main.c
@@ -60,13 +60,13 @@ struct usb_driver easycap_usb_driver = {
60 */ 60 */
61/*---------------------------------------------------------------------------*/ 61/*---------------------------------------------------------------------------*/
62const struct file_operations easycap_fops = { 62const struct file_operations easycap_fops = {
63.owner = THIS_MODULE, 63 .owner = THIS_MODULE,
64.open = easycap_open, 64 .open = easycap_open,
65.release = easycap_release, 65 .release = easycap_release,
66.ioctl = easycap_ioctl, 66 .unlocked_ioctl = easycap_ioctl,
67.poll = easycap_poll, 67 .poll = easycap_poll,
68.mmap = easycap_mmap, 68 .mmap = easycap_mmap,
69.llseek = no_llseek, 69 .llseek = no_llseek,
70}; 70};
71struct vm_operations_struct easycap_vm_ops = { 71struct vm_operations_struct easycap_vm_ops = {
72.open = easycap_vma_open, 72.open = easycap_vma_open,
@@ -83,12 +83,12 @@ struct usb_class_driver easycap_class = {
83#if defined(EASYCAP_IS_VIDEODEV_CLIENT) 83#if defined(EASYCAP_IS_VIDEODEV_CLIENT)
84#if defined(EASYCAP_NEEDS_V4L2_FOPS) 84#if defined(EASYCAP_NEEDS_V4L2_FOPS)
85const struct v4l2_file_operations v4l2_fops = { 85const struct v4l2_file_operations v4l2_fops = {
86.owner = THIS_MODULE, 86 .owner = THIS_MODULE,
87.open = easycap_open_noinode, 87 .open = easycap_open_noinode,
88.release = easycap_release_noinode, 88 .release = easycap_release_noinode,
89.ioctl = easycap_ioctl_noinode, 89 .unlocked_ioctl = easycap_ioctl,
90.poll = easycap_poll, 90 .poll = easycap_poll,
91.mmap = easycap_mmap, 91 .mmap = easycap_mmap,
92}; 92};
93#endif /*EASYCAP_NEEDS_V4L2_FOPS*/ 93#endif /*EASYCAP_NEEDS_V4L2_FOPS*/
94int video_device_many /*=0*/; 94int video_device_many /*=0*/;
@@ -102,12 +102,12 @@ struct video_device *pvideo_array[VIDEO_DEVICE_MANY], *pvideo_device;
102 */ 102 */
103/*--------------------------------------------------------------------------*/ 103/*--------------------------------------------------------------------------*/
104const struct file_operations easysnd_fops = { 104const struct file_operations easysnd_fops = {
105.owner = THIS_MODULE, 105 .owner = THIS_MODULE,
106.open = easysnd_open, 106 .open = easysnd_open,
107.release = easysnd_release, 107 .release = easysnd_release,
108.ioctl = easysnd_ioctl, 108 .unlocked_ioctl = easysnd_ioctl,
109.read = easysnd_read, 109 .read = easysnd_read,
110.llseek = no_llseek, 110 .llseek = no_llseek,
111}; 111};
112struct usb_class_driver easysnd_class = { 112struct usb_class_driver easysnd_class = {
113.name = "usb/easysnd%d", 113.name = "usb/easysnd%d",
diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c
index f7ea2a3efed7..ff1d24720f11 100644
--- a/drivers/staging/hv/blkvsc_drv.c
+++ b/drivers/staging/hv/blkvsc_drv.c
@@ -25,6 +25,7 @@
25#include <linux/major.h> 25#include <linux/major.h>
26#include <linux/delay.h> 26#include <linux/delay.h>
27#include <linux/hdreg.h> 27#include <linux/hdreg.h>
28#include <linux/smp_lock.h>
28#include <linux/slab.h> 29#include <linux/slab.h>
29#include <scsi/scsi.h> 30#include <scsi/scsi.h>
30#include <scsi/scsi_cmnd.h> 31#include <scsi/scsi_cmnd.h>
@@ -805,7 +806,8 @@ static void blkvsc_init_rw(struct blkvsc_request *blkvsc_req)
805 blkvsc_req->cmnd[0] = READ_16; 806 blkvsc_req->cmnd[0] = READ_16;
806 } 807 }
807 808
808 blkvsc_req->cmnd[1] |= blk_fua_rq(blkvsc_req->req) ? 0x8 : 0; 809 blkvsc_req->cmnd[1] |=
810 (blkvsc_req->req->cmd_flags & REQ_FUA) ? 0x8 : 0;
809 811
810 *(unsigned long long *)&blkvsc_req->cmnd[2] = 812 *(unsigned long long *)&blkvsc_req->cmnd[2] =
811 cpu_to_be64(blkvsc_req->sector_start); 813 cpu_to_be64(blkvsc_req->sector_start);
@@ -821,7 +823,8 @@ static void blkvsc_init_rw(struct blkvsc_request *blkvsc_req)
821 blkvsc_req->cmnd[0] = READ_10; 823 blkvsc_req->cmnd[0] = READ_10;
822 } 824 }
823 825
824 blkvsc_req->cmnd[1] |= blk_fua_rq(blkvsc_req->req) ? 0x8 : 0; 826 blkvsc_req->cmnd[1] |=
827 (blkvsc_req->req->cmd_flags & REQ_FUA) ? 0x8 : 0;
825 828
826 *(unsigned int *)&blkvsc_req->cmnd[2] = 829 *(unsigned int *)&blkvsc_req->cmnd[2] =
827 cpu_to_be32(blkvsc_req->sector_start); 830 cpu_to_be32(blkvsc_req->sector_start);
@@ -1268,7 +1271,7 @@ static void blkvsc_request(struct request_queue *queue)
1268 DPRINT_DBG(BLKVSC_DRV, "- req %p\n", req); 1271 DPRINT_DBG(BLKVSC_DRV, "- req %p\n", req);
1269 1272
1270 blkdev = req->rq_disk->private_data; 1273 blkdev = req->rq_disk->private_data;
1271 if (blkdev->shutting_down || !blk_fs_request(req) || 1274 if (blkdev->shutting_down || req->cmd_type != REQ_TYPE_FS ||
1272 blkdev->media_not_present) { 1275 blkdev->media_not_present) {
1273 __blk_end_request_cur(req, 0); 1276 __blk_end_request_cur(req, 0);
1274 continue; 1277 continue;
@@ -1306,6 +1309,7 @@ static int blkvsc_open(struct block_device *bdev, fmode_t mode)
1306 DPRINT_DBG(BLKVSC_DRV, "- users %d disk %s\n", blkdev->users, 1309 DPRINT_DBG(BLKVSC_DRV, "- users %d disk %s\n", blkdev->users,
1307 blkdev->gd->disk_name); 1310 blkdev->gd->disk_name);
1308 1311
1312 lock_kernel();
1309 spin_lock(&blkdev->lock); 1313 spin_lock(&blkdev->lock);
1310 1314
1311 if (!blkdev->users && blkdev->device_type == DVD_TYPE) { 1315 if (!blkdev->users && blkdev->device_type == DVD_TYPE) {
@@ -1317,6 +1321,7 @@ static int blkvsc_open(struct block_device *bdev, fmode_t mode)
1317 blkdev->users++; 1321 blkdev->users++;
1318 1322
1319 spin_unlock(&blkdev->lock); 1323 spin_unlock(&blkdev->lock);
1324 unlock_kernel();
1320 return 0; 1325 return 0;
1321} 1326}
1322 1327
@@ -1327,6 +1332,7 @@ static int blkvsc_release(struct gendisk *disk, fmode_t mode)
1327 DPRINT_DBG(BLKVSC_DRV, "- users %d disk %s\n", blkdev->users, 1332 DPRINT_DBG(BLKVSC_DRV, "- users %d disk %s\n", blkdev->users,
1328 blkdev->gd->disk_name); 1333 blkdev->gd->disk_name);
1329 1334
1335 lock_kernel();
1330 spin_lock(&blkdev->lock); 1336 spin_lock(&blkdev->lock);
1331 if (blkdev->users == 1) { 1337 if (blkdev->users == 1) {
1332 spin_unlock(&blkdev->lock); 1338 spin_unlock(&blkdev->lock);
@@ -1337,6 +1343,7 @@ static int blkvsc_release(struct gendisk *disk, fmode_t mode)
1337 blkdev->users--; 1343 blkdev->users--;
1338 1344
1339 spin_unlock(&blkdev->lock); 1345 spin_unlock(&blkdev->lock);
1346 unlock_kernel();
1340 return 0; 1347 return 0;
1341} 1348}
1342 1349
diff --git a/drivers/staging/lirc/Kconfig b/drivers/staging/lirc/Kconfig
index 968c2adee06b..100c4d4b8125 100644
--- a/drivers/staging/lirc/Kconfig
+++ b/drivers/staging/lirc/Kconfig
@@ -3,6 +3,7 @@
3# 3#
4menuconfig LIRC_STAGING 4menuconfig LIRC_STAGING
5 bool "Linux Infrared Remote Control IR receiver/transmitter drivers" 5 bool "Linux Infrared Remote Control IR receiver/transmitter drivers"
6 depends on LIRC
6 help 7 help
7 Say Y here, and all supported Linux Infrared Remote Control IR and 8 Say Y here, and all supported Linux Infrared Remote Control IR and
8 RF receiver and transmitter drivers will be displayed. When paired 9 RF receiver and transmitter drivers will be displayed. When paired
@@ -13,21 +14,13 @@ if LIRC_STAGING
13 14
14config LIRC_BT829 15config LIRC_BT829
15 tristate "BT829 based hardware" 16 tristate "BT829 based hardware"
16 depends on LIRC_STAGING 17 depends on LIRC_STAGING && PCI
17 help 18 help
18 Driver for the IR interface on BT829-based hardware 19 Driver for the IR interface on BT829-based hardware
19 20
20config LIRC_ENE0100
21 tristate "ENE KB3924/ENE0100 CIR Port Reciever"
22 depends on LIRC_STAGING
23 help
24 This is a driver for CIR port handled by ENE KB3924 embedded
25 controller found on some notebooks.
26 It appears on PNP list as ENE0100.
27
28config LIRC_I2C 21config LIRC_I2C
29 tristate "I2C Based IR Receivers" 22 tristate "I2C Based IR Receivers"
30 depends on LIRC_STAGING 23 depends on LIRC_STAGING && I2C
31 help 24 help
32 Driver for I2C-based IR receivers, such as those commonly 25 Driver for I2C-based IR receivers, such as those commonly
33 found onboard Hauppauge PVR-150/250/350 video capture cards 26 found onboard Hauppauge PVR-150/250/350 video capture cards
@@ -40,7 +33,7 @@ config LIRC_IGORPLUGUSB
40 33
41config LIRC_IMON 34config LIRC_IMON
42 tristate "Legacy SoundGraph iMON Receiver and Display" 35 tristate "Legacy SoundGraph iMON Receiver and Display"
43 depends on LIRC_STAGING 36 depends on LIRC_STAGING && USB
44 help 37 help
45 Driver for the original SoundGraph iMON IR Receiver and Display 38 Driver for the original SoundGraph iMON IR Receiver and Display
46 39
@@ -48,7 +41,7 @@ config LIRC_IMON
48 41
49config LIRC_IT87 42config LIRC_IT87
50 tristate "ITE IT87XX CIR Port Receiver" 43 tristate "ITE IT87XX CIR Port Receiver"
51 depends on LIRC_STAGING 44 depends on LIRC_STAGING && PNP
52 help 45 help
53 Driver for the ITE IT87xx IR Receiver 46 Driver for the ITE IT87xx IR Receiver
54 47
@@ -60,13 +53,13 @@ config LIRC_ITE8709
60 53
61config LIRC_PARALLEL 54config LIRC_PARALLEL
62 tristate "Homebrew Parallel Port Receiver" 55 tristate "Homebrew Parallel Port Receiver"
63 depends on LIRC_STAGING && !SMP 56 depends on LIRC_STAGING && PARPORT && !SMP
64 help 57 help
65 Driver for Homebrew Parallel Port Receivers 58 Driver for Homebrew Parallel Port Receivers
66 59
67config LIRC_SASEM 60config LIRC_SASEM
68 tristate "Sasem USB IR Remote" 61 tristate "Sasem USB IR Remote"
69 depends on LIRC_STAGING 62 depends on LIRC_STAGING && USB
70 help 63 help
71 Driver for the Sasem OnAir Remocon-V or Dign HV5 HTPC IR/VFD Module 64 Driver for the Sasem OnAir Remocon-V or Dign HV5 HTPC IR/VFD Module
72 65
@@ -89,12 +82,6 @@ config LIRC_SIR
89 help 82 help
90 Driver for the SIR IrDA port 83 Driver for the SIR IrDA port
91 84
92config LIRC_STREAMZAP
93 tristate "Streamzap PC Receiver"
94 depends on LIRC_STAGING
95 help
96 Driver for the Streamzap PC Receiver
97
98config LIRC_TTUSBIR 85config LIRC_TTUSBIR
99 tristate "Technotrend USB IR Receiver" 86 tristate "Technotrend USB IR Receiver"
100 depends on LIRC_STAGING && USB 87 depends on LIRC_STAGING && USB
@@ -103,7 +90,7 @@ config LIRC_TTUSBIR
103 90
104config LIRC_ZILOG 91config LIRC_ZILOG
105 tristate "Zilog/Hauppauge IR Transmitter" 92 tristate "Zilog/Hauppauge IR Transmitter"
106 depends on LIRC_STAGING 93 depends on LIRC_STAGING && I2C
107 help 94 help
108 Driver for the Zilog/Hauppauge IR Transmitter, found on 95 Driver for the Zilog/Hauppauge IR Transmitter, found on
109 PVR-150/500, HVR-1200/1250/1700/1800, HD-PVR and other cards 96 PVR-150/500, HVR-1200/1250/1700/1800, HD-PVR and other cards
diff --git a/drivers/staging/lirc/Makefile b/drivers/staging/lirc/Makefile
index a019182a7a38..4da1f3397a16 100644
--- a/drivers/staging/lirc/Makefile
+++ b/drivers/staging/lirc/Makefile
@@ -4,7 +4,6 @@
4# Each configuration option enables a list of files. 4# Each configuration option enables a list of files.
5 5
6obj-$(CONFIG_LIRC_BT829) += lirc_bt829.o 6obj-$(CONFIG_LIRC_BT829) += lirc_bt829.o
7obj-$(CONFIG_LIRC_ENE0100) += lirc_ene0100.o
8obj-$(CONFIG_LIRC_I2C) += lirc_i2c.o 7obj-$(CONFIG_LIRC_I2C) += lirc_i2c.o
9obj-$(CONFIG_LIRC_IGORPLUGUSB) += lirc_igorplugusb.o 8obj-$(CONFIG_LIRC_IGORPLUGUSB) += lirc_igorplugusb.o
10obj-$(CONFIG_LIRC_IMON) += lirc_imon.o 9obj-$(CONFIG_LIRC_IMON) += lirc_imon.o
@@ -14,6 +13,5 @@ obj-$(CONFIG_LIRC_PARALLEL) += lirc_parallel.o
14obj-$(CONFIG_LIRC_SASEM) += lirc_sasem.o 13obj-$(CONFIG_LIRC_SASEM) += lirc_sasem.o
15obj-$(CONFIG_LIRC_SERIAL) += lirc_serial.o 14obj-$(CONFIG_LIRC_SERIAL) += lirc_serial.o
16obj-$(CONFIG_LIRC_SIR) += lirc_sir.o 15obj-$(CONFIG_LIRC_SIR) += lirc_sir.o
17obj-$(CONFIG_LIRC_STREAMZAP) += lirc_streamzap.o
18obj-$(CONFIG_LIRC_TTUSBIR) += lirc_ttusbir.o 16obj-$(CONFIG_LIRC_TTUSBIR) += lirc_ttusbir.o
19obj-$(CONFIG_LIRC_ZILOG) += lirc_zilog.o 17obj-$(CONFIG_LIRC_ZILOG) += lirc_zilog.o
diff --git a/drivers/staging/lirc/lirc_ene0100.c b/drivers/staging/lirc/lirc_ene0100.c
deleted file mode 100644
index a152c52b0745..000000000000
--- a/drivers/staging/lirc/lirc_ene0100.c
+++ /dev/null
@@ -1,646 +0,0 @@
1/*
2 * driver for ENE KB3926 B/C/D CIR (also known as ENE0100)
3 *
4 * Copyright (C) 2009 Maxim Levitsky <maximlevitsky@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 * USA
20 */
21
22#include <linux/kernel.h>
23#include <linux/module.h>
24#include <linux/pnp.h>
25#include <linux/io.h>
26#include <linux/interrupt.h>
27#include <linux/sched.h>
28#include "lirc_ene0100.h"
29
30static int sample_period = 75;
31static int enable_idle = 1;
32static int enable_learning;
33
34static void ene_set_idle(struct ene_device *dev, int idle);
35static void ene_set_inputs(struct ene_device *dev, int enable);
36
37/* read a hardware register */
38static u8 ene_hw_read_reg(struct ene_device *dev, u16 reg)
39{
40 outb(reg >> 8, dev->hw_io + ENE_ADDR_HI);
41 outb(reg & 0xFF, dev->hw_io + ENE_ADDR_LO);
42 return inb(dev->hw_io + ENE_IO);
43}
44
45/* write a hardware register */
46static void ene_hw_write_reg(struct ene_device *dev, u16 reg, u8 value)
47{
48 outb(reg >> 8, dev->hw_io + ENE_ADDR_HI);
49 outb(reg & 0xFF, dev->hw_io + ENE_ADDR_LO);
50 outb(value, dev->hw_io + ENE_IO);
51}
52
53/* change specific bits in hardware register */
54static void ene_hw_write_reg_mask(struct ene_device *dev,
55 u16 reg, u8 value, u8 mask)
56{
57 u8 regvalue;
58
59 outb(reg >> 8, dev->hw_io + ENE_ADDR_HI);
60 outb(reg & 0xFF, dev->hw_io + ENE_ADDR_LO);
61
62 regvalue = inb(dev->hw_io + ENE_IO) & ~mask;
63 regvalue |= (value & mask);
64 outb(regvalue, dev->hw_io + ENE_IO);
65}
66
67/* read irq status and ack it */
68static int ene_hw_irq_status(struct ene_device *dev, int *buffer_pointer)
69{
70 u8 irq_status;
71 u8 fw_flags1, fw_flags2;
72
73 fw_flags2 = ene_hw_read_reg(dev, ENE_FW2);
74
75 if (buffer_pointer)
76 *buffer_pointer = 4 * (fw_flags2 & ENE_FW2_BUF_HIGH);
77
78 if (dev->hw_revision < ENE_HW_C) {
79 irq_status = ene_hw_read_reg(dev, ENEB_IRQ_STATUS);
80
81 if (!(irq_status & ENEB_IRQ_STATUS_IR))
82 return 0;
83 ene_hw_write_reg(dev, ENEB_IRQ_STATUS,
84 irq_status & ~ENEB_IRQ_STATUS_IR);
85
86 /* rev B support only recieving */
87 return ENE_IRQ_RX;
88 }
89
90 irq_status = ene_hw_read_reg(dev, ENEC_IRQ);
91
92 if (!(irq_status & ENEC_IRQ_STATUS))
93 return 0;
94
95 /* original driver does that twice - a workaround ? */
96 ene_hw_write_reg(dev, ENEC_IRQ, irq_status & ~ENEC_IRQ_STATUS);
97 ene_hw_write_reg(dev, ENEC_IRQ, irq_status & ~ENEC_IRQ_STATUS);
98
99 /* clear unknown flag in F8F9 */
100 if (fw_flags2 & ENE_FW2_IRQ_CLR)
101 ene_hw_write_reg(dev, ENE_FW2, fw_flags2 & ~ENE_FW2_IRQ_CLR);
102
103 /* check if this is a TX interrupt */
104 fw_flags1 = ene_hw_read_reg(dev, ENE_FW1);
105
106 if (fw_flags1 & ENE_FW1_TXIRQ) {
107 ene_hw_write_reg(dev, ENE_FW1, fw_flags1 & ~ENE_FW1_TXIRQ);
108 return ENE_IRQ_TX;
109 } else
110 return ENE_IRQ_RX;
111}
112
113static int ene_hw_detect(struct ene_device *dev)
114{
115 u8 chip_major, chip_minor;
116 u8 hw_revision, old_ver;
117 u8 tmp;
118 u8 fw_capabilities;
119
120 tmp = ene_hw_read_reg(dev, ENE_HW_UNK);
121 ene_hw_write_reg(dev, ENE_HW_UNK, tmp & ~ENE_HW_UNK_CLR);
122
123 chip_major = ene_hw_read_reg(dev, ENE_HW_VER_MAJOR);
124 chip_minor = ene_hw_read_reg(dev, ENE_HW_VER_MINOR);
125
126 ene_hw_write_reg(dev, ENE_HW_UNK, tmp);
127 hw_revision = ene_hw_read_reg(dev, ENE_HW_VERSION);
128 old_ver = ene_hw_read_reg(dev, ENE_HW_VER_OLD);
129
130 if (hw_revision == 0xFF) {
131
132 ene_printk(KERN_WARNING, "device seems to be disabled\n");
133 ene_printk(KERN_WARNING,
134 "send a mail to lirc-list@lists.sourceforge.net\n");
135 ene_printk(KERN_WARNING, "please attach output of acpidump\n");
136
137 return -ENODEV;
138 }
139
140 if (chip_major == 0x33) {
141 ene_printk(KERN_WARNING, "chips 0x33xx aren't supported yet\n");
142 return -ENODEV;
143 }
144
145 if (chip_major == 0x39 && chip_minor == 0x26 && hw_revision == 0xC0) {
146 dev->hw_revision = ENE_HW_C;
147 ene_printk(KERN_WARNING,
148 "KB3926C detected, driver support is not complete!\n");
149
150 } else if (old_ver == 0x24 && hw_revision == 0xC0) {
151 dev->hw_revision = ENE_HW_B;
152 ene_printk(KERN_NOTICE, "KB3926B detected\n");
153 } else {
154 dev->hw_revision = ENE_HW_D;
155 ene_printk(KERN_WARNING,
156 "unknown ENE chip detected, assuming KB3926D\n");
157 ene_printk(KERN_WARNING, "driver support incomplete");
158
159 }
160
161 ene_printk(KERN_DEBUG, "chip is 0x%02x%02x - 0x%02x, 0x%02x\n",
162 chip_major, chip_minor, old_ver, hw_revision);
163
164
165 /* detect features hardware supports */
166
167 if (dev->hw_revision < ENE_HW_C)
168 return 0;
169
170 fw_capabilities = ene_hw_read_reg(dev, ENE_FW2);
171
172 dev->hw_gpio40_learning = fw_capabilities & ENE_FW2_GP40_AS_LEARN;
173 dev->hw_learning_and_tx_capable = fw_capabilities & ENE_FW2_LEARNING;
174
175 dev->hw_fan_as_normal_input = dev->hw_learning_and_tx_capable &&
176 fw_capabilities & ENE_FW2_FAN_AS_NRML_IN;
177
178 ene_printk(KERN_NOTICE, "hardware features:\n");
179 ene_printk(KERN_NOTICE,
180 "learning and tx %s, gpio40_learn %s, fan_in %s\n",
181 dev->hw_learning_and_tx_capable ? "on" : "off",
182 dev->hw_gpio40_learning ? "on" : "off",
183 dev->hw_fan_as_normal_input ? "on" : "off");
184
185 if (!dev->hw_learning_and_tx_capable && enable_learning)
186 enable_learning = 0;
187
188 if (dev->hw_learning_and_tx_capable) {
189 ene_printk(KERN_WARNING,
190 "Device supports transmitting, but the driver doesn't\n");
191 ene_printk(KERN_WARNING,
192 "due to lack of hardware to test against.\n");
193 ene_printk(KERN_WARNING,
194 "Send a mail to: lirc-list@lists.sourceforge.net\n");
195 }
196 return 0;
197}
198
199/* hardware initialization */
200static int ene_hw_init(void *data)
201{
202 u8 reg_value;
203 struct ene_device *dev = (struct ene_device *)data;
204 dev->in_use = 1;
205
206 if (dev->hw_revision < ENE_HW_C) {
207 ene_hw_write_reg(dev, ENEB_IRQ, dev->irq << 1);
208 ene_hw_write_reg(dev, ENEB_IRQ_UNK1, 0x01);
209 } else {
210 reg_value = ene_hw_read_reg(dev, ENEC_IRQ) & 0xF0;
211 reg_value |= ENEC_IRQ_UNK_EN;
212 reg_value &= ~ENEC_IRQ_STATUS;
213 reg_value |= (dev->irq & ENEC_IRQ_MASK);
214 ene_hw_write_reg(dev, ENEC_IRQ, reg_value);
215 ene_hw_write_reg(dev, ENE_TX_UNK1, 0x63);
216 }
217
218 ene_hw_write_reg(dev, ENE_CIR_CONF2, 0x00);
219 ene_set_inputs(dev, enable_learning);
220
221 /* set sampling period */
222 ene_hw_write_reg(dev, ENE_CIR_SAMPLE_PERIOD, sample_period);
223
224 /* ack any pending irqs - just in case */
225 ene_hw_irq_status(dev, NULL);
226
227 /* enter idle mode */
228 ene_set_idle(dev, 1);
229
230 /* enable firmware bits */
231 ene_hw_write_reg_mask(dev, ENE_FW1,
232 ENE_FW1_ENABLE | ENE_FW1_IRQ,
233 ENE_FW1_ENABLE | ENE_FW1_IRQ);
234 /* clear stats */
235 dev->sample = 0;
236 return 0;
237}
238
239/* this enables gpio40 signal, used if connected to wide band input*/
240static void ene_enable_gpio40(struct ene_device *dev, int enable)
241{
242 ene_hw_write_reg_mask(dev, ENE_CIR_CONF1, enable ?
243 0 : ENE_CIR_CONF2_GPIO40DIS,
244 ENE_CIR_CONF2_GPIO40DIS);
245}
246
247/* this enables the classic sampler */
248static void ene_enable_normal_recieve(struct ene_device *dev, int enable)
249{
250 ene_hw_write_reg(dev, ENE_CIR_CONF1, enable ? ENE_CIR_CONF1_ADC_ON : 0);
251}
252
253/* this enables recieve via fan input */
254static void ene_enable_fan_recieve(struct ene_device *dev, int enable)
255{
256 if (!enable)
257 ene_hw_write_reg(dev, ENE_FAN_AS_IN1, 0);
258 else {
259 ene_hw_write_reg(dev, ENE_FAN_AS_IN1, ENE_FAN_AS_IN1_EN);
260 ene_hw_write_reg(dev, ENE_FAN_AS_IN2, ENE_FAN_AS_IN2_EN);
261 }
262 dev->fan_input_inuse = enable;
263}
264
265/* determine which input to use*/
266static void ene_set_inputs(struct ene_device *dev, int learning_enable)
267{
268 ene_enable_normal_recieve(dev, 1);
269
270 /* old hardware doesn't support learning mode for sure */
271 if (dev->hw_revision <= ENE_HW_B)
272 return;
273
274 /* reciever not learning capable, still set gpio40 correctly */
275 if (!dev->hw_learning_and_tx_capable) {
276 ene_enable_gpio40(dev, !dev->hw_gpio40_learning);
277 return;
278 }
279
280 /* enable learning mode */
281 if (learning_enable) {
282 ene_enable_gpio40(dev, dev->hw_gpio40_learning);
283
284 /* fan input is not used for learning */
285 if (dev->hw_fan_as_normal_input)
286 ene_enable_fan_recieve(dev, 0);
287
288 /* disable learning mode */
289 } else {
290 if (dev->hw_fan_as_normal_input) {
291 ene_enable_fan_recieve(dev, 1);
292 ene_enable_normal_recieve(dev, 0);
293 } else
294 ene_enable_gpio40(dev, !dev->hw_gpio40_learning);
295 }
296
297 /* set few additional settings for this mode */
298 ene_hw_write_reg_mask(dev, ENE_CIR_CONF1, learning_enable ?
299 ENE_CIR_CONF1_LEARN1 : 0, ENE_CIR_CONF1_LEARN1);
300
301 ene_hw_write_reg_mask(dev, ENE_CIR_CONF2, learning_enable ?
302 ENE_CIR_CONF2_LEARN2 : 0, ENE_CIR_CONF2_LEARN2);
303}
304
305/* deinitialization */
306static void ene_hw_deinit(void *data)
307{
308 struct ene_device *dev = (struct ene_device *)data;
309
310 /* disable samplers */
311 ene_enable_normal_recieve(dev, 0);
312
313 if (dev->hw_fan_as_normal_input)
314 ene_enable_fan_recieve(dev, 0);
315
316 /* disable hardware IRQ and firmware flag */
317 ene_hw_write_reg_mask(dev, ENE_FW1, 0, ENE_FW1_ENABLE | ENE_FW1_IRQ);
318
319 ene_set_idle(dev, 1);
320 dev->in_use = 0;
321}
322
323/* sends current sample to userspace */
324static void send_sample(struct ene_device *dev)
325{
326 int value = abs(dev->sample) & PULSE_MASK;
327
328 if (dev->sample > 0)
329 value |= PULSE_BIT;
330
331 if (!lirc_buffer_full(dev->lirc_driver->rbuf)) {
332 lirc_buffer_write(dev->lirc_driver->rbuf, (void *)&value);
333 wake_up(&dev->lirc_driver->rbuf->wait_poll);
334 }
335 dev->sample = 0;
336}
337
338/* this updates current sample */
339static void update_sample(struct ene_device *dev, int sample)
340{
341 if (!dev->sample)
342 dev->sample = sample;
343 else if (same_sign(dev->sample, sample))
344 dev->sample += sample;
345 else {
346 send_sample(dev);
347 dev->sample = sample;
348 }
349}
350
351/* enable or disable idle mode */
352static void ene_set_idle(struct ene_device *dev, int idle)
353{
354 struct timeval now;
355 int disable = idle && enable_idle && (dev->hw_revision < ENE_HW_C);
356
357 ene_hw_write_reg_mask(dev, ENE_CIR_SAMPLE_PERIOD,
358 disable ? 0 : ENE_CIR_SAMPLE_OVERFLOW,
359 ENE_CIR_SAMPLE_OVERFLOW);
360 dev->idle = idle;
361
362 /* remember when we have entered the idle mode */
363 if (idle) {
364 do_gettimeofday(&dev->gap_start);
365 return;
366 }
367
368 /* send the gap between keypresses now */
369 do_gettimeofday(&now);
370
371 if (now.tv_sec - dev->gap_start.tv_sec > 16)
372 dev->sample = space(PULSE_MASK);
373 else
374 dev->sample = dev->sample +
375 space(1000000ull * (now.tv_sec - dev->gap_start.tv_sec))
376 + space(now.tv_usec - dev->gap_start.tv_usec);
377
378 if (abs(dev->sample) > PULSE_MASK)
379 dev->sample = space(PULSE_MASK);
380 send_sample(dev);
381}
382
383/* interrupt handler */
384static irqreturn_t ene_hw_irq(int irq, void *data)
385{
386 u16 hw_value;
387 int i, hw_sample;
388 int space;
389 int buffer_pointer;
390 int irq_status;
391
392 struct ene_device *dev = (struct ene_device *)data;
393 irq_status = ene_hw_irq_status(dev, &buffer_pointer);
394
395 if (!irq_status)
396 return IRQ_NONE;
397
398 /* TODO: only RX for now */
399 if (irq_status == ENE_IRQ_TX)
400 return IRQ_HANDLED;
401
402 for (i = 0; i < ENE_SAMPLES_SIZE; i++) {
403
404 hw_value = ene_hw_read_reg(dev,
405 ENE_SAMPLE_BUFFER + buffer_pointer + i);
406
407 if (dev->fan_input_inuse) {
408 /* read high part of the sample */
409 hw_value |= ene_hw_read_reg(dev,
410 ENE_SAMPLE_BUFFER_FAN + buffer_pointer + i) << 8;
411
412 /* test for _space_ bit */
413 space = !(hw_value & ENE_FAN_SMPL_PULS_MSK);
414
415 /* clear space bit, and other unused bits */
416 hw_value &= ENE_FAN_VALUE_MASK;
417 hw_sample = hw_value * ENE_SAMPLE_PERIOD_FAN;
418
419 } else {
420 space = hw_value & ENE_SAMPLE_SPC_MASK;
421 hw_value &= ENE_SAMPLE_VALUE_MASK;
422 hw_sample = hw_value * sample_period;
423 }
424
425 /* no more data */
426 if (!(hw_value))
427 break;
428
429 if (space)
430 hw_sample *= -1;
431
432 /* overflow sample recieved, handle it */
433
434 if (!dev->fan_input_inuse && hw_value == ENE_SAMPLE_OVERFLOW) {
435
436 if (dev->idle)
437 continue;
438
439 if (dev->sample > 0 || abs(dev->sample) <= ENE_MAXGAP)
440 update_sample(dev, hw_sample);
441 else
442 ene_set_idle(dev, 1);
443
444 continue;
445 }
446
447 /* normal first sample recieved */
448 if (!dev->fan_input_inuse && dev->idle) {
449 ene_set_idle(dev, 0);
450
451 /* discard first recieved value, its random
452 since its the time signal was off before
453 first pulse if idle mode is enabled, HW
454 does that for us */
455
456 if (!enable_idle)
457 continue;
458 }
459 update_sample(dev, hw_sample);
460 send_sample(dev);
461 }
462 return IRQ_HANDLED;
463}
464
465static int ene_probe(struct pnp_dev *pnp_dev,
466 const struct pnp_device_id *dev_id)
467{
468 struct ene_device *dev;
469 struct lirc_driver *lirc_driver;
470 int error = -ENOMEM;
471
472 dev = kzalloc(sizeof(struct ene_device), GFP_KERNEL);
473
474 if (!dev)
475 goto err1;
476
477 dev->pnp_dev = pnp_dev;
478 pnp_set_drvdata(pnp_dev, dev);
479
480
481 /* prepare lirc interface */
482 error = -ENOMEM;
483 lirc_driver = kzalloc(sizeof(struct lirc_driver), GFP_KERNEL);
484
485 if (!lirc_driver)
486 goto err2;
487
488 dev->lirc_driver = lirc_driver;
489
490 strcpy(lirc_driver->name, ENE_DRIVER_NAME);
491 lirc_driver->minor = -1;
492 lirc_driver->code_length = sizeof(int) * 8;
493 lirc_driver->features = LIRC_CAN_REC_MODE2;
494 lirc_driver->data = dev;
495 lirc_driver->set_use_inc = ene_hw_init;
496 lirc_driver->set_use_dec = ene_hw_deinit;
497 lirc_driver->dev = &pnp_dev->dev;
498 lirc_driver->owner = THIS_MODULE;
499
500 lirc_driver->rbuf = kzalloc(sizeof(struct lirc_buffer), GFP_KERNEL);
501
502 if (!lirc_driver->rbuf)
503 goto err3;
504
505 if (lirc_buffer_init(lirc_driver->rbuf, sizeof(int), sizeof(int) * 256))
506 goto err4;
507
508 error = -ENODEV;
509 if (lirc_register_driver(lirc_driver))
510 goto err5;
511
512 /* validate resources */
513 if (!pnp_port_valid(pnp_dev, 0) ||
514 pnp_port_len(pnp_dev, 0) < ENE_MAX_IO)
515 goto err6;
516
517 if (!pnp_irq_valid(pnp_dev, 0))
518 goto err6;
519
520 dev->hw_io = pnp_port_start(pnp_dev, 0);
521 dev->irq = pnp_irq(pnp_dev, 0);
522
523 /* claim the resources */
524 error = -EBUSY;
525 if (!request_region(dev->hw_io, ENE_MAX_IO, ENE_DRIVER_NAME))
526 goto err6;
527
528 if (request_irq(dev->irq, ene_hw_irq,
529 IRQF_SHARED, ENE_DRIVER_NAME, (void *)dev))
530 goto err7;
531
532 /* detect hardware version and features */
533 error = ene_hw_detect(dev);
534 if (error)
535 goto err8;
536
537 ene_printk(KERN_NOTICE, "driver has been succesfully loaded\n");
538 return 0;
539
540err8:
541 free_irq(dev->irq, dev);
542err7:
543 release_region(dev->hw_io, ENE_MAX_IO);
544err6:
545 lirc_unregister_driver(lirc_driver->minor);
546err5:
547 lirc_buffer_free(lirc_driver->rbuf);
548err4:
549 kfree(lirc_driver->rbuf);
550err3:
551 kfree(lirc_driver);
552err2:
553 kfree(dev);
554err1:
555 return error;
556}
557
558static void ene_remove(struct pnp_dev *pnp_dev)
559{
560 struct ene_device *dev = pnp_get_drvdata(pnp_dev);
561 ene_hw_deinit(dev);
562 free_irq(dev->irq, dev);
563 release_region(dev->hw_io, ENE_MAX_IO);
564 lirc_unregister_driver(dev->lirc_driver->minor);
565 lirc_buffer_free(dev->lirc_driver->rbuf);
566 kfree(dev->lirc_driver);
567 kfree(dev);
568}
569
570#ifdef CONFIG_PM
571
572/* TODO: make 'wake on IR' configurable and add .shutdown */
573/* currently impossible due to lack of kernel support */
574
575static int ene_suspend(struct pnp_dev *pnp_dev, pm_message_t state)
576{
577 struct ene_device *dev = pnp_get_drvdata(pnp_dev);
578 ene_hw_write_reg_mask(dev, ENE_FW1, ENE_FW1_WAKE, ENE_FW1_WAKE);
579 return 0;
580}
581
582static int ene_resume(struct pnp_dev *pnp_dev)
583{
584 struct ene_device *dev = pnp_get_drvdata(pnp_dev);
585 if (dev->in_use)
586 ene_hw_init(dev);
587
588 ene_hw_write_reg_mask(dev, ENE_FW1, 0, ENE_FW1_WAKE);
589 return 0;
590}
591
592#endif
593
594static const struct pnp_device_id ene_ids[] = {
595 {.id = "ENE0100",},
596 {},
597};
598
599static struct pnp_driver ene_driver = {
600 .name = ENE_DRIVER_NAME,
601 .id_table = ene_ids,
602 .flags = PNP_DRIVER_RES_DO_NOT_CHANGE,
603
604 .probe = ene_probe,
605 .remove = __devexit_p(ene_remove),
606
607#ifdef CONFIG_PM
608 .suspend = ene_suspend,
609 .resume = ene_resume,
610#endif
611};
612
613static int __init ene_init(void)
614{
615 if (sample_period < 5) {
616 ene_printk(KERN_ERR, "sample period must be at\n");
617 ene_printk(KERN_ERR, "least 5 us, (at least 30 recommended)\n");
618 return -EINVAL;
619 }
620 return pnp_register_driver(&ene_driver);
621}
622
623static void ene_exit(void)
624{
625 pnp_unregister_driver(&ene_driver);
626}
627
628module_param(sample_period, int, S_IRUGO);
629MODULE_PARM_DESC(sample_period, "Hardware sample period (75 us default)");
630
631module_param(enable_idle, bool, S_IRUGO | S_IWUSR);
632MODULE_PARM_DESC(enable_idle,
633 "Enables turning off signal sampling after long inactivity time; "
634 "if disabled might help detecting input signal (default: enabled)");
635
636module_param(enable_learning, bool, S_IRUGO);
637MODULE_PARM_DESC(enable_learning, "Use wide band (learning) reciever");
638
639MODULE_DEVICE_TABLE(pnp, ene_ids);
640MODULE_DESCRIPTION
641 ("LIRC driver for KB3926B/KB3926C/KB3926D (aka ENE0100) CIR port");
642MODULE_AUTHOR("Maxim Levitsky");
643MODULE_LICENSE("GPL");
644
645module_init(ene_init);
646module_exit(ene_exit);
diff --git a/drivers/staging/lirc/lirc_it87.c b/drivers/staging/lirc/lirc_it87.c
index 09f36961c6d2..ec11c0e949a0 100644
--- a/drivers/staging/lirc/lirc_it87.c
+++ b/drivers/staging/lirc/lirc_it87.c
@@ -109,6 +109,7 @@ static DECLARE_WAIT_QUEUE_HEAD(lirc_read_queue);
109 109
110static DEFINE_SPINLOCK(hardware_lock); 110static DEFINE_SPINLOCK(hardware_lock);
111static DEFINE_SPINLOCK(dev_lock); 111static DEFINE_SPINLOCK(dev_lock);
112static bool device_open;
112 113
113static int rx_buf[RBUF_LEN]; 114static int rx_buf[RBUF_LEN];
114unsigned int rx_tail, rx_head; 115unsigned int rx_tail, rx_head;
@@ -147,10 +148,11 @@ static void drop_port(void);
147static int lirc_open(struct inode *inode, struct file *file) 148static int lirc_open(struct inode *inode, struct file *file)
148{ 149{
149 spin_lock(&dev_lock); 150 spin_lock(&dev_lock);
150 if (module_refcount(THIS_MODULE)) { 151 if (device_open) {
151 spin_unlock(&dev_lock); 152 spin_unlock(&dev_lock);
152 return -EBUSY; 153 return -EBUSY;
153 } 154 }
155 device_open = true;
154 spin_unlock(&dev_lock); 156 spin_unlock(&dev_lock);
155 return 0; 157 return 0;
156} 158}
@@ -158,6 +160,9 @@ static int lirc_open(struct inode *inode, struct file *file)
158 160
159static int lirc_close(struct inode *inode, struct file *file) 161static int lirc_close(struct inode *inode, struct file *file)
160{ 162{
163 spin_lock(&dev_lock);
164 device_open = false;
165 spin_unlock(&dev_lock);
161 return 0; 166 return 0;
162} 167}
163 168
@@ -363,7 +368,6 @@ static struct lirc_driver driver = {
363}; 368};
364 369
365 370
366#ifdef MODULE
367static int init_chrdev(void) 371static int init_chrdev(void)
368{ 372{
369 driver.minor = lirc_register_driver(&driver); 373 driver.minor = lirc_register_driver(&driver);
@@ -380,7 +384,6 @@ static void drop_chrdev(void)
380{ 384{
381 lirc_unregister_driver(driver.minor); 385 lirc_unregister_driver(driver.minor);
382} 386}
383#endif
384 387
385 388
386/* SECTION: Hardware */ 389/* SECTION: Hardware */
diff --git a/drivers/staging/lirc/lirc_parallel.c b/drivers/staging/lirc/lirc_parallel.c
index a1ebd071640f..6da4a8c6ebc3 100644
--- a/drivers/staging/lirc/lirc_parallel.c
+++ b/drivers/staging/lirc/lirc_parallel.c
@@ -240,7 +240,7 @@ static void irq_handler(void *blah)
240 unsigned int level, newlevel; 240 unsigned int level, newlevel;
241 unsigned int timeout; 241 unsigned int timeout;
242 242
243 if (!module_refcount(THIS_MODULE)) 243 if (!is_open)
244 return; 244 return;
245 245
246 if (!is_claimed) 246 if (!is_claimed)
@@ -515,7 +515,7 @@ static long lirc_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
515 515
516static int lirc_open(struct inode *node, struct file *filep) 516static int lirc_open(struct inode *node, struct file *filep)
517{ 517{
518 if (module_refcount(THIS_MODULE) || !lirc_claim()) 518 if (is_open || !lirc_claim())
519 return -EBUSY; 519 return -EBUSY;
520 520
521 parport_enable_irq(pport); 521 parport_enable_irq(pport);
diff --git a/drivers/staging/lirc/lirc_streamzap.c b/drivers/staging/lirc/lirc_streamzap.c
deleted file mode 100644
index be09c103f0c9..000000000000
--- a/drivers/staging/lirc/lirc_streamzap.c
+++ /dev/null
@@ -1,821 +0,0 @@
1/*
2 * Streamzap Remote Control driver
3 *
4 * Copyright (c) 2005 Christoph Bartelmus <lirc@bartelmus.de>
5 *
6 * This driver was based on the work of Greg Wickham and Adrian
7 * Dewhurst. It was substantially rewritten to support correct signal
8 * gaps and now maintains a delay buffer, which is used to present
9 * consistent timing behaviour to user space applications. Without the
10 * delay buffer an ugly hack would be required in lircd, which can
11 * cause sluggish signal decoding in certain situations.
12 *
13 * This driver is based on the USB skeleton driver packaged with the
14 * kernel; copyright (C) 2001-2003 Greg Kroah-Hartman (greg@kroah.com)
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 */
30
31#include <linux/kernel.h>
32#include <linux/errno.h>
33#include <linux/init.h>
34#include <linux/slab.h>
35#include <linux/module.h>
36#include <linux/smp_lock.h>
37#include <linux/completion.h>
38#include <linux/uaccess.h>
39#include <linux/usb.h>
40
41#include <media/lirc.h>
42#include <media/lirc_dev.h>
43
44#define DRIVER_VERSION "1.28"
45#define DRIVER_NAME "lirc_streamzap"
46#define DRIVER_DESC "Streamzap Remote Control driver"
47
48static int debug;
49
50#define USB_STREAMZAP_VENDOR_ID 0x0e9c
51#define USB_STREAMZAP_PRODUCT_ID 0x0000
52
53/* Use our own dbg macro */
54#define dprintk(fmt, args...) \
55 do { \
56 if (debug) \
57 printk(KERN_DEBUG DRIVER_NAME "[%d]: " \
58 fmt "\n", ## args); \
59 } while (0)
60
61/* table of devices that work with this driver */
62static struct usb_device_id streamzap_table[] = {
63 /* Streamzap Remote Control */
64 { USB_DEVICE(USB_STREAMZAP_VENDOR_ID, USB_STREAMZAP_PRODUCT_ID) },
65 /* Terminating entry */
66 { }
67};
68
69MODULE_DEVICE_TABLE(usb, streamzap_table);
70
71#define STREAMZAP_PULSE_MASK 0xf0
72#define STREAMZAP_SPACE_MASK 0x0f
73#define STREAMZAP_TIMEOUT 0xff
74#define STREAMZAP_RESOLUTION 256
75
76/* number of samples buffered */
77#define STREAMZAP_BUF_LEN 128
78
79enum StreamzapDecoderState {
80 PulseSpace,
81 FullPulse,
82 FullSpace,
83 IgnorePulse
84};
85
86/* Structure to hold all of our device specific stuff
87 *
88 * some remarks regarding locking:
89 * theoretically this struct can be accessed from three threads:
90 *
91 * - from lirc_dev through set_use_inc/set_use_dec
92 *
93 * - from the USB layer throuh probe/disconnect/irq
94 *
95 * Careful placement of lirc_register_driver/lirc_unregister_driver
96 * calls will prevent conflicts. lirc_dev makes sure that
97 * set_use_inc/set_use_dec are not being executed and will not be
98 * called after lirc_unregister_driver returns.
99 *
100 * - by the timer callback
101 *
102 * The timer is only running when the device is connected and the
103 * LIRC device is open. Making sure the timer is deleted by
104 * set_use_dec will make conflicts impossible.
105 */
106struct usb_streamzap {
107
108 /* usb */
109 /* save off the usb device pointer */
110 struct usb_device *udev;
111 /* the interface for this device */
112 struct usb_interface *interface;
113
114 /* buffer & dma */
115 unsigned char *buf_in;
116 dma_addr_t dma_in;
117 unsigned int buf_in_len;
118
119 struct usb_endpoint_descriptor *endpoint;
120
121 /* IRQ */
122 struct urb *urb_in;
123
124 /* lirc */
125 struct lirc_driver *driver;
126 struct lirc_buffer *delay_buf;
127
128 /* timer used to support delay buffering */
129 struct timer_list delay_timer;
130 int timer_running;
131 spinlock_t timer_lock;
132
133 /* tracks whether we are currently receiving some signal */
134 int idle;
135 /* sum of signal lengths received since signal start */
136 unsigned long sum;
137 /* start time of signal; necessary for gap tracking */
138 struct timeval signal_last;
139 struct timeval signal_start;
140 enum StreamzapDecoderState decoder_state;
141 struct timer_list flush_timer;
142 int flush;
143 int in_use;
144 int timeout_enabled;
145};
146
147
148/* local function prototypes */
149static int streamzap_probe(struct usb_interface *interface,
150 const struct usb_device_id *id);
151static void streamzap_disconnect(struct usb_interface *interface);
152static void usb_streamzap_irq(struct urb *urb);
153static int streamzap_use_inc(void *data);
154static void streamzap_use_dec(void *data);
155static long streamzap_ioctl(struct file *filep, unsigned int cmd,
156 unsigned long arg);
157static int streamzap_suspend(struct usb_interface *intf, pm_message_t message);
158static int streamzap_resume(struct usb_interface *intf);
159
160/* usb specific object needed to register this driver with the usb subsystem */
161
162static struct usb_driver streamzap_driver = {
163 .name = DRIVER_NAME,
164 .probe = streamzap_probe,
165 .disconnect = streamzap_disconnect,
166 .suspend = streamzap_suspend,
167 .resume = streamzap_resume,
168 .id_table = streamzap_table,
169};
170
171static void stop_timer(struct usb_streamzap *sz)
172{
173 unsigned long flags;
174
175 spin_lock_irqsave(&sz->timer_lock, flags);
176 if (sz->timer_running) {
177 sz->timer_running = 0;
178 spin_unlock_irqrestore(&sz->timer_lock, flags);
179 del_timer_sync(&sz->delay_timer);
180 } else {
181 spin_unlock_irqrestore(&sz->timer_lock, flags);
182 }
183}
184
185static void flush_timeout(unsigned long arg)
186{
187 struct usb_streamzap *sz = (struct usb_streamzap *) arg;
188
189 /* finally start accepting data */
190 sz->flush = 0;
191}
192static void delay_timeout(unsigned long arg)
193{
194 unsigned long flags;
195 /* deliver data every 10 ms */
196 static unsigned long timer_inc =
197 (10000/(1000000/HZ)) == 0 ? 1 : (10000/(1000000/HZ));
198 struct usb_streamzap *sz = (struct usb_streamzap *) arg;
199 int data;
200
201 spin_lock_irqsave(&sz->timer_lock, flags);
202
203 if (!lirc_buffer_empty(sz->delay_buf) &&
204 !lirc_buffer_full(sz->driver->rbuf)) {
205 lirc_buffer_read(sz->delay_buf, (unsigned char *) &data);
206 lirc_buffer_write(sz->driver->rbuf, (unsigned char *) &data);
207 }
208 if (!lirc_buffer_empty(sz->delay_buf)) {
209 while (lirc_buffer_available(sz->delay_buf) <
210 STREAMZAP_BUF_LEN / 2 &&
211 !lirc_buffer_full(sz->driver->rbuf)) {
212 lirc_buffer_read(sz->delay_buf,
213 (unsigned char *) &data);
214 lirc_buffer_write(sz->driver->rbuf,
215 (unsigned char *) &data);
216 }
217 if (sz->timer_running) {
218 sz->delay_timer.expires = jiffies + timer_inc;
219 add_timer(&sz->delay_timer);
220 }
221 } else {
222 sz->timer_running = 0;
223 }
224
225 if (!lirc_buffer_empty(sz->driver->rbuf))
226 wake_up(&sz->driver->rbuf->wait_poll);
227
228 spin_unlock_irqrestore(&sz->timer_lock, flags);
229}
230
231static void flush_delay_buffer(struct usb_streamzap *sz)
232{
233 int data;
234 int empty = 1;
235
236 while (!lirc_buffer_empty(sz->delay_buf)) {
237 empty = 0;
238 lirc_buffer_read(sz->delay_buf, (unsigned char *) &data);
239 if (!lirc_buffer_full(sz->driver->rbuf)) {
240 lirc_buffer_write(sz->driver->rbuf,
241 (unsigned char *) &data);
242 } else {
243 dprintk("buffer overflow", sz->driver->minor);
244 }
245 }
246 if (!empty)
247 wake_up(&sz->driver->rbuf->wait_poll);
248}
249
250static void push(struct usb_streamzap *sz, unsigned char *data)
251{
252 unsigned long flags;
253
254 spin_lock_irqsave(&sz->timer_lock, flags);
255 if (lirc_buffer_full(sz->delay_buf)) {
256 int read_data;
257
258 lirc_buffer_read(sz->delay_buf,
259 (unsigned char *) &read_data);
260 if (!lirc_buffer_full(sz->driver->rbuf)) {
261 lirc_buffer_write(sz->driver->rbuf,
262 (unsigned char *) &read_data);
263 } else {
264 dprintk("buffer overflow", sz->driver->minor);
265 }
266 }
267
268 lirc_buffer_write(sz->delay_buf, data);
269
270 if (!sz->timer_running) {
271 sz->delay_timer.expires = jiffies + HZ/10;
272 add_timer(&sz->delay_timer);
273 sz->timer_running = 1;
274 }
275
276 spin_unlock_irqrestore(&sz->timer_lock, flags);
277}
278
279static void push_full_pulse(struct usb_streamzap *sz,
280 unsigned char value)
281{
282 int pulse;
283
284 if (sz->idle) {
285 long deltv;
286 int tmp;
287
288 sz->signal_last = sz->signal_start;
289 do_gettimeofday(&sz->signal_start);
290
291 deltv = sz->signal_start.tv_sec-sz->signal_last.tv_sec;
292 if (deltv > 15) {
293 /* really long time */
294 tmp = LIRC_SPACE(LIRC_VALUE_MASK);
295 } else {
296 tmp = (int) (deltv*1000000+
297 sz->signal_start.tv_usec -
298 sz->signal_last.tv_usec);
299 tmp -= sz->sum;
300 tmp = LIRC_SPACE(tmp);
301 }
302 dprintk("ls %u", sz->driver->minor, tmp);
303 push(sz, (char *)&tmp);
304
305 sz->idle = 0;
306 sz->sum = 0;
307 }
308
309 pulse = ((int) value) * STREAMZAP_RESOLUTION;
310 pulse += STREAMZAP_RESOLUTION / 2;
311 sz->sum += pulse;
312 pulse = LIRC_PULSE(pulse);
313
314 dprintk("p %u", sz->driver->minor, pulse & PULSE_MASK);
315 push(sz, (char *)&pulse);
316}
317
318static void push_half_pulse(struct usb_streamzap *sz,
319 unsigned char value)
320{
321 push_full_pulse(sz, (value & STREAMZAP_PULSE_MASK)>>4);
322}
323
324static void push_full_space(struct usb_streamzap *sz,
325 unsigned char value)
326{
327 int space;
328
329 space = ((int) value)*STREAMZAP_RESOLUTION;
330 space += STREAMZAP_RESOLUTION/2;
331 sz->sum += space;
332 space = LIRC_SPACE(space);
333 dprintk("s %u", sz->driver->minor, space);
334 push(sz, (char *)&space);
335}
336
337static void push_half_space(struct usb_streamzap *sz,
338 unsigned char value)
339{
340 push_full_space(sz, value & STREAMZAP_SPACE_MASK);
341}
342
343/**
344 * usb_streamzap_irq - IRQ handler
345 *
346 * This procedure is invoked on reception of data from
347 * the usb remote.
348 */
349static void usb_streamzap_irq(struct urb *urb)
350{
351 struct usb_streamzap *sz;
352 int len;
353 unsigned int i = 0;
354
355 if (!urb)
356 return;
357
358 sz = urb->context;
359 len = urb->actual_length;
360
361 switch (urb->status) {
362 case -ECONNRESET:
363 case -ENOENT:
364 case -ESHUTDOWN:
365 /*
366 * this urb is terminated, clean up.
367 * sz might already be invalid at this point
368 */
369 dprintk("urb status: %d", -1, urb->status);
370 return;
371 default:
372 break;
373 }
374
375 dprintk("received %d", sz->driver->minor, urb->actual_length);
376 if (!sz->flush) {
377 for (i = 0; i < urb->actual_length; i++) {
378 dprintk("%d: %x", sz->driver->minor,
379 i, (unsigned char) sz->buf_in[i]);
380 switch (sz->decoder_state) {
381 case PulseSpace:
382 if ((sz->buf_in[i]&STREAMZAP_PULSE_MASK) ==
383 STREAMZAP_PULSE_MASK) {
384 sz->decoder_state = FullPulse;
385 continue;
386 } else if ((sz->buf_in[i]&STREAMZAP_SPACE_MASK)
387 == STREAMZAP_SPACE_MASK) {
388 push_half_pulse(sz, sz->buf_in[i]);
389 sz->decoder_state = FullSpace;
390 continue;
391 } else {
392 push_half_pulse(sz, sz->buf_in[i]);
393 push_half_space(sz, sz->buf_in[i]);
394 }
395 break;
396 case FullPulse:
397 push_full_pulse(sz, sz->buf_in[i]);
398 sz->decoder_state = IgnorePulse;
399 break;
400 case FullSpace:
401 if (sz->buf_in[i] == STREAMZAP_TIMEOUT) {
402 sz->idle = 1;
403 stop_timer(sz);
404 if (sz->timeout_enabled) {
405 int timeout =
406 LIRC_TIMEOUT
407 (STREAMZAP_TIMEOUT *
408 STREAMZAP_RESOLUTION);
409 push(sz, (char *)&timeout);
410 }
411 flush_delay_buffer(sz);
412 } else
413 push_full_space(sz, sz->buf_in[i]);
414 sz->decoder_state = PulseSpace;
415 break;
416 case IgnorePulse:
417 if ((sz->buf_in[i]&STREAMZAP_SPACE_MASK) ==
418 STREAMZAP_SPACE_MASK) {
419 sz->decoder_state = FullSpace;
420 continue;
421 }
422 push_half_space(sz, sz->buf_in[i]);
423 sz->decoder_state = PulseSpace;
424 break;
425 }
426 }
427 }
428
429 usb_submit_urb(urb, GFP_ATOMIC);
430
431 return;
432}
433
434static const struct file_operations streamzap_fops = {
435 .owner = THIS_MODULE,
436 .unlocked_ioctl = streamzap_ioctl,
437 .read = lirc_dev_fop_read,
438 .write = lirc_dev_fop_write,
439 .poll = lirc_dev_fop_poll,
440 .open = lirc_dev_fop_open,
441 .release = lirc_dev_fop_close,
442};
443
444
445/**
446 * streamzap_probe
447 *
448 * Called by usb-core to associated with a candidate device
449 * On any failure the return value is the ERROR
450 * On success return 0
451 */
452static int streamzap_probe(struct usb_interface *interface,
453 const struct usb_device_id *id)
454{
455 struct usb_device *udev = interface_to_usbdev(interface);
456 struct usb_host_interface *iface_host;
457 struct usb_streamzap *sz;
458 struct lirc_driver *driver;
459 struct lirc_buffer *lirc_buf;
460 struct lirc_buffer *delay_buf;
461 char buf[63], name[128] = "";
462 int retval = -ENOMEM;
463 int minor = 0;
464
465 /* Allocate space for device driver specific data */
466 sz = kzalloc(sizeof(struct usb_streamzap), GFP_KERNEL);
467 if (sz == NULL)
468 return -ENOMEM;
469
470 sz->udev = udev;
471 sz->interface = interface;
472
473 /* Check to ensure endpoint information matches requirements */
474 iface_host = interface->cur_altsetting;
475
476 if (iface_host->desc.bNumEndpoints != 1) {
477 err("%s: Unexpected desc.bNumEndpoints (%d)", __func__,
478 iface_host->desc.bNumEndpoints);
479 retval = -ENODEV;
480 goto free_sz;
481 }
482
483 sz->endpoint = &(iface_host->endpoint[0].desc);
484 if ((sz->endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK)
485 != USB_DIR_IN) {
486 err("%s: endpoint doesn't match input device 02%02x",
487 __func__, sz->endpoint->bEndpointAddress);
488 retval = -ENODEV;
489 goto free_sz;
490 }
491
492 if ((sz->endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
493 != USB_ENDPOINT_XFER_INT) {
494 err("%s: endpoint attributes don't match xfer 02%02x",
495 __func__, sz->endpoint->bmAttributes);
496 retval = -ENODEV;
497 goto free_sz;
498 }
499
500 if (sz->endpoint->wMaxPacketSize == 0) {
501 err("%s: endpoint message size==0? ", __func__);
502 retval = -ENODEV;
503 goto free_sz;
504 }
505
506 /* Allocate the USB buffer and IRQ URB */
507
508 sz->buf_in_len = sz->endpoint->wMaxPacketSize;
509 sz->buf_in = usb_alloc_coherent(sz->udev, sz->buf_in_len,
510 GFP_ATOMIC, &sz->dma_in);
511 if (sz->buf_in == NULL)
512 goto free_sz;
513
514 sz->urb_in = usb_alloc_urb(0, GFP_KERNEL);
515 if (sz->urb_in == NULL)
516 goto free_sz;
517
518 /* Connect this device to the LIRC sub-system */
519 driver = kzalloc(sizeof(struct lirc_driver), GFP_KERNEL);
520 if (!driver)
521 goto free_sz;
522
523 lirc_buf = kmalloc(sizeof(struct lirc_buffer), GFP_KERNEL);
524 if (!lirc_buf)
525 goto free_driver;
526 if (lirc_buffer_init(lirc_buf, sizeof(int), STREAMZAP_BUF_LEN))
527 goto kfree_lirc_buf;
528
529 delay_buf = kmalloc(sizeof(struct lirc_buffer), GFP_KERNEL);
530 if (!delay_buf)
531 goto free_lirc_buf;
532 if (lirc_buffer_init(delay_buf, sizeof(int), STREAMZAP_BUF_LEN))
533 goto kfree_delay_buf;
534
535 sz->driver = driver;
536 strcpy(sz->driver->name, DRIVER_NAME);
537 sz->driver->minor = -1;
538 sz->driver->sample_rate = 0;
539 sz->driver->code_length = sizeof(int) * 8;
540 sz->driver->features = LIRC_CAN_REC_MODE2 |
541 LIRC_CAN_GET_REC_RESOLUTION |
542 LIRC_CAN_SET_REC_TIMEOUT;
543 sz->driver->data = sz;
544 sz->driver->min_timeout = STREAMZAP_TIMEOUT * STREAMZAP_RESOLUTION;
545 sz->driver->max_timeout = STREAMZAP_TIMEOUT * STREAMZAP_RESOLUTION;
546 sz->driver->rbuf = lirc_buf;
547 sz->delay_buf = delay_buf;
548 sz->driver->set_use_inc = &streamzap_use_inc;
549 sz->driver->set_use_dec = &streamzap_use_dec;
550 sz->driver->fops = &streamzap_fops;
551 sz->driver->dev = &interface->dev;
552 sz->driver->owner = THIS_MODULE;
553
554 sz->idle = 1;
555 sz->decoder_state = PulseSpace;
556 init_timer(&sz->delay_timer);
557 sz->delay_timer.function = delay_timeout;
558 sz->delay_timer.data = (unsigned long) sz;
559 sz->timer_running = 0;
560 spin_lock_init(&sz->timer_lock);
561
562 init_timer(&sz->flush_timer);
563 sz->flush_timer.function = flush_timeout;
564 sz->flush_timer.data = (unsigned long) sz;
565 /* Complete final initialisations */
566
567 usb_fill_int_urb(sz->urb_in, udev,
568 usb_rcvintpipe(udev, sz->endpoint->bEndpointAddress),
569 sz->buf_in, sz->buf_in_len, usb_streamzap_irq, sz,
570 sz->endpoint->bInterval);
571 sz->urb_in->transfer_dma = sz->dma_in;
572 sz->urb_in->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
573
574 if (udev->descriptor.iManufacturer
575 && usb_string(udev, udev->descriptor.iManufacturer,
576 buf, sizeof(buf)) > 0)
577 strlcpy(name, buf, sizeof(name));
578
579 if (udev->descriptor.iProduct
580 && usb_string(udev, udev->descriptor.iProduct,
581 buf, sizeof(buf)) > 0)
582 snprintf(name + strlen(name), sizeof(name) - strlen(name),
583 " %s", buf);
584
585 minor = lirc_register_driver(driver);
586
587 if (minor < 0)
588 goto free_delay_buf;
589
590 sz->driver->minor = minor;
591
592 usb_set_intfdata(interface, sz);
593
594 printk(KERN_INFO DRIVER_NAME "[%d]: %s on usb%d:%d attached\n",
595 sz->driver->minor, name,
596 udev->bus->busnum, sz->udev->devnum);
597
598 return 0;
599
600free_delay_buf:
601 lirc_buffer_free(sz->delay_buf);
602kfree_delay_buf:
603 kfree(delay_buf);
604free_lirc_buf:
605 lirc_buffer_free(sz->driver->rbuf);
606kfree_lirc_buf:
607 kfree(lirc_buf);
608free_driver:
609 kfree(driver);
610free_sz:
611 if (retval == -ENOMEM)
612 err("Out of memory");
613
614 if (sz) {
615 usb_free_urb(sz->urb_in);
616 usb_free_coherent(udev, sz->buf_in_len, sz->buf_in, sz->dma_in);
617 kfree(sz);
618 }
619
620 return retval;
621}
622
623static int streamzap_use_inc(void *data)
624{
625 struct usb_streamzap *sz = data;
626
627 if (!sz) {
628 dprintk("%s called with no context", -1, __func__);
629 return -EINVAL;
630 }
631 dprintk("set use inc", sz->driver->minor);
632
633 lirc_buffer_clear(sz->driver->rbuf);
634 lirc_buffer_clear(sz->delay_buf);
635
636 sz->flush_timer.expires = jiffies + HZ;
637 sz->flush = 1;
638 add_timer(&sz->flush_timer);
639
640 sz->urb_in->dev = sz->udev;
641 if (usb_submit_urb(sz->urb_in, GFP_ATOMIC)) {
642 dprintk("open result = -EIO error submitting urb",
643 sz->driver->minor);
644 return -EIO;
645 }
646 sz->in_use++;
647
648 return 0;
649}
650
651static void streamzap_use_dec(void *data)
652{
653 struct usb_streamzap *sz = data;
654
655 if (!sz) {
656 dprintk("%s called with no context", -1, __func__);
657 return;
658 }
659 dprintk("set use dec", sz->driver->minor);
660
661 if (sz->flush) {
662 sz->flush = 0;
663 del_timer_sync(&sz->flush_timer);
664 }
665
666 usb_kill_urb(sz->urb_in);
667
668 stop_timer(sz);
669
670 sz->in_use--;
671}
672
673static long streamzap_ioctl(struct file *filep, unsigned int cmd,
674 unsigned long arg)
675{
676 int result = 0;
677 int val;
678 struct usb_streamzap *sz = lirc_get_pdata(filep);
679
680 switch (cmd) {
681 case LIRC_GET_REC_RESOLUTION:
682 result = put_user(STREAMZAP_RESOLUTION, (unsigned int *) arg);
683 break;
684 case LIRC_SET_REC_TIMEOUT:
685 result = get_user(val, (int *)arg);
686 if (result == 0) {
687 if (val == STREAMZAP_TIMEOUT * STREAMZAP_RESOLUTION)
688 sz->timeout_enabled = 1;
689 else if (val == 0)
690 sz->timeout_enabled = 0;
691 else
692 result = -EINVAL;
693 }
694 break;
695 default:
696 return lirc_dev_fop_ioctl(filep, cmd, arg);
697 }
698 return result;
699}
700
701/**
702 * streamzap_disconnect
703 *
704 * Called by the usb core when the device is removed from the system.
705 *
706 * This routine guarantees that the driver will not submit any more urbs
707 * by clearing dev->udev. It is also supposed to terminate any currently
708 * active urbs. Unfortunately, usb_bulk_msg(), used in streamzap_read(),
709 * does not provide any way to do this.
710 */
711static void streamzap_disconnect(struct usb_interface *interface)
712{
713 struct usb_streamzap *sz;
714 int errnum;
715 int minor;
716
717 sz = usb_get_intfdata(interface);
718
719 /* unregister from the LIRC sub-system */
720
721 errnum = lirc_unregister_driver(sz->driver->minor);
722 if (errnum != 0)
723 dprintk("error in lirc_unregister: (returned %d)",
724 sz->driver->minor, errnum);
725
726 lirc_buffer_free(sz->delay_buf);
727 lirc_buffer_free(sz->driver->rbuf);
728
729 /* unregister from the USB sub-system */
730
731 usb_free_urb(sz->urb_in);
732
733 usb_free_coherent(sz->udev, sz->buf_in_len, sz->buf_in, sz->dma_in);
734
735 minor = sz->driver->minor;
736 kfree(sz->driver->rbuf);
737 kfree(sz->driver);
738 kfree(sz->delay_buf);
739 kfree(sz);
740
741 printk(KERN_INFO DRIVER_NAME "[%d]: disconnected\n", minor);
742}
743
744static int streamzap_suspend(struct usb_interface *intf, pm_message_t message)
745{
746 struct usb_streamzap *sz = usb_get_intfdata(intf);
747
748 printk(KERN_INFO DRIVER_NAME "[%d]: suspend\n", sz->driver->minor);
749 if (sz->in_use) {
750 if (sz->flush) {
751 sz->flush = 0;
752 del_timer_sync(&sz->flush_timer);
753 }
754
755 stop_timer(sz);
756
757 usb_kill_urb(sz->urb_in);
758 }
759 return 0;
760}
761
762static int streamzap_resume(struct usb_interface *intf)
763{
764 struct usb_streamzap *sz = usb_get_intfdata(intf);
765
766 lirc_buffer_clear(sz->driver->rbuf);
767 lirc_buffer_clear(sz->delay_buf);
768
769 if (sz->in_use) {
770 sz->flush_timer.expires = jiffies + HZ;
771 sz->flush = 1;
772 add_timer(&sz->flush_timer);
773
774 sz->urb_in->dev = sz->udev;
775 if (usb_submit_urb(sz->urb_in, GFP_ATOMIC)) {
776 dprintk("open result = -EIO error submitting urb",
777 sz->driver->minor);
778 return -EIO;
779 }
780 }
781 return 0;
782}
783
784/**
785 * usb_streamzap_init
786 */
787static int __init usb_streamzap_init(void)
788{
789 int result;
790
791 /* register this driver with the USB subsystem */
792 result = usb_register(&streamzap_driver);
793
794 if (result) {
795 err("usb_register failed. Error number %d",
796 result);
797 return result;
798 }
799
800 printk(KERN_INFO DRIVER_NAME " " DRIVER_VERSION " registered\n");
801 return 0;
802}
803
804/**
805 * usb_streamzap_exit
806 */
807static void __exit usb_streamzap_exit(void)
808{
809 usb_deregister(&streamzap_driver);
810}
811
812
813module_init(usb_streamzap_init);
814module_exit(usb_streamzap_exit);
815
816MODULE_AUTHOR("Christoph Bartelmus, Greg Wickham, Adrian Dewhurst");
817MODULE_DESCRIPTION(DRIVER_DESC);
818MODULE_LICENSE("GPL");
819
820module_param(debug, bool, S_IRUGO | S_IWUSR);
821MODULE_PARM_DESC(debug, "Enable debugging messages");
diff --git a/drivers/staging/pohmelfs/inode.c b/drivers/staging/pohmelfs/inode.c
index bc1c6051a6f6..97dae297ca3c 100644
--- a/drivers/staging/pohmelfs/inode.c
+++ b/drivers/staging/pohmelfs/inode.c
@@ -968,12 +968,18 @@ int pohmelfs_setattr_raw(struct inode *inode, struct iattr *attr)
968 goto err_out_exit; 968 goto err_out_exit;
969 } 969 }
970 970
971 err = inode_setattr(inode, attr); 971 if ((attr->ia_valid & ATTR_SIZE) &&
972 if (err) { 972 attr->ia_size != i_size_read(inode)) {
973 dprintk("%s: ino: %llu, failed to set the attributes.\n", __func__, POHMELFS_I(inode)->ino); 973 err = vmtruncate(inode, attr->ia_size);
974 goto err_out_exit; 974 if (err) {
975 dprintk("%s: ino: %llu, failed to set the attributes.\n", __func__, POHMELFS_I(inode)->ino);
976 goto err_out_exit;
977 }
975 } 978 }
976 979
980 setattr_copy(inode, attr);
981 mark_inode_dirty(inode);
982
977 dprintk("%s: ino: %llu, mode: %o -> %o, uid: %u -> %u, gid: %u -> %u, size: %llu -> %llu.\n", 983 dprintk("%s: ino: %llu, mode: %o -> %o, uid: %u -> %u, gid: %u -> %u, size: %llu -> %llu.\n",
978 __func__, POHMELFS_I(inode)->ino, inode->i_mode, attr->ia_mode, 984 __func__, POHMELFS_I(inode)->ino, inode->i_mode, attr->ia_mode,
979 inode->i_uid, attr->ia_uid, inode->i_gid, attr->ia_gid, inode->i_size, attr->ia_size); 985 inode->i_uid, attr->ia_uid, inode->i_gid, attr->ia_gid, inode->i_size, attr->ia_size);
@@ -1217,7 +1223,7 @@ void pohmelfs_fill_inode(struct inode *inode, struct netfs_inode_info *info)
1217 } 1223 }
1218} 1224}
1219 1225
1220static void pohmelfs_drop_inode(struct inode *inode) 1226static int pohmelfs_drop_inode(struct inode *inode)
1221{ 1227{
1222 struct pohmelfs_sb *psb = POHMELFS_SB(inode->i_sb); 1228 struct pohmelfs_sb *psb = POHMELFS_SB(inode->i_sb);
1223 struct pohmelfs_inode *pi = POHMELFS_I(inode); 1229 struct pohmelfs_inode *pi = POHMELFS_I(inode);
@@ -1226,7 +1232,7 @@ static void pohmelfs_drop_inode(struct inode *inode)
1226 list_del_init(&pi->inode_entry); 1232 list_del_init(&pi->inode_entry);
1227 spin_unlock(&psb->ino_lock); 1233 spin_unlock(&psb->ino_lock);
1228 1234
1229 generic_drop_inode(inode); 1235 return generic_drop_inode(inode);
1230} 1236}
1231 1237
1232static struct pohmelfs_inode *pohmelfs_get_inode_from_list(struct pohmelfs_sb *psb, 1238static struct pohmelfs_inode *pohmelfs_get_inode_from_list(struct pohmelfs_sb *psb,
diff --git a/drivers/staging/rtl8187se/r8180_core.c b/drivers/staging/rtl8187se/r8180_core.c
index 49ab9fa9ffa7..ed7457bc24ea 100644
--- a/drivers/staging/rtl8187se/r8180_core.c
+++ b/drivers/staging/rtl8187se/r8180_core.c
@@ -61,7 +61,7 @@ static struct pci_device_id rtl8180_pci_id_tbl[] __devinitdata = {
61}; 61};
62 62
63 63
64static char *ifname = "wlan%d"; 64static char ifname[IFNAMSIZ] = "wlan%d";
65static int hwseqnum = 0; 65static int hwseqnum = 0;
66static int hwwep = 0; 66static int hwwep = 0;
67static int channels = 0x3fff; 67static int channels = 0x3fff;
@@ -72,7 +72,7 @@ MODULE_AUTHOR("Andrea Merello <andreamrl@tiscali.it>");
72MODULE_DESCRIPTION("Linux driver for Realtek RTL8180 / RTL8185 WiFi cards"); 72MODULE_DESCRIPTION("Linux driver for Realtek RTL8180 / RTL8185 WiFi cards");
73 73
74 74
75module_param(ifname, charp, S_IRUGO|S_IWUSR); 75module_param_string(ifname, ifname, sizeof(ifname), S_IRUGO|S_IWUSR);
76module_param(hwseqnum, int, S_IRUGO|S_IWUSR); 76module_param(hwseqnum, int, S_IRUGO|S_IWUSR);
77module_param(hwwep, int, S_IRUGO|S_IWUSR); 77module_param(hwwep, int, S_IRUGO|S_IWUSR);
78module_param(channels, int, S_IRUGO|S_IWUSR); 78module_param(channels, int, S_IRUGO|S_IWUSR);
@@ -3609,7 +3609,7 @@ static int __devinit rtl8180_pci_probe(struct pci_dev *pdev,
3609 3609
3610 if (dev_alloc_name(dev, ifname) < 0) { 3610 if (dev_alloc_name(dev, ifname) < 0) {
3611 DMESG("Oops: devname already taken! Trying wlan%%d...\n"); 3611 DMESG("Oops: devname already taken! Trying wlan%%d...\n");
3612 ifname = "wlan%d"; 3612 strcpy(ifname, "wlan%d");
3613 dev_alloc_name(dev, ifname); 3613 dev_alloc_name(dev, ifname);
3614 } 3614 }
3615 3615
diff --git a/drivers/staging/rtl8192e/r8192E_core.c b/drivers/staging/rtl8192e/r8192E_core.c
index 4cd071adf84b..17a806f9ee77 100644
--- a/drivers/staging/rtl8192e/r8192E_core.c
+++ b/drivers/staging/rtl8192e/r8192E_core.c
@@ -112,7 +112,7 @@ static const struct pci_device_id rtl8192_pci_id_tbl[] __devinitdata = {
112 {} 112 {}
113}; 113};
114 114
115static char* ifname = "wlan%d"; 115static char ifname[IFNAMSIZ] = "wlan%d";
116static int hwwep = 1; //default use hw. set 0 to use software security 116static int hwwep = 1; //default use hw. set 0 to use software security
117static int channels = 0x3fff; 117static int channels = 0x3fff;
118 118
@@ -123,7 +123,7 @@ MODULE_DEVICE_TABLE(pci, rtl8192_pci_id_tbl);
123MODULE_DESCRIPTION("Linux driver for Realtek RTL819x WiFi cards"); 123MODULE_DESCRIPTION("Linux driver for Realtek RTL819x WiFi cards");
124 124
125 125
126module_param(ifname, charp, S_IRUGO|S_IWUSR ); 126module_param_string(ifname, ifname, sizeof(ifname), S_IRUGO|S_IWUSR);
127//module_param(hwseqnum,int, S_IRUGO|S_IWUSR); 127//module_param(hwseqnum,int, S_IRUGO|S_IWUSR);
128module_param(hwwep,int, S_IRUGO|S_IWUSR); 128module_param(hwwep,int, S_IRUGO|S_IWUSR);
129module_param(channels,int, S_IRUGO|S_IWUSR); 129module_param(channels,int, S_IRUGO|S_IWUSR);
@@ -6446,7 +6446,7 @@ static int __devinit rtl8192_pci_probe(struct pci_dev *pdev,
6446 6446
6447 if (dev_alloc_name(dev, ifname) < 0){ 6447 if (dev_alloc_name(dev, ifname) < 0){
6448 RT_TRACE(COMP_INIT, "Oops: devname already taken! Trying wlan%%d...\n"); 6448 RT_TRACE(COMP_INIT, "Oops: devname already taken! Trying wlan%%d...\n");
6449 ifname = "wlan%d"; 6449 strcpy(ifname, "wlan%d");
6450 dev_alloc_name(dev, ifname); 6450 dev_alloc_name(dev, ifname);
6451 } 6451 }
6452 6452
diff --git a/drivers/staging/rtl8192su/r8192U_core.c b/drivers/staging/rtl8192su/r8192U_core.c
index 6970c97713d8..df5b52baf893 100644
--- a/drivers/staging/rtl8192su/r8192U_core.c
+++ b/drivers/staging/rtl8192su/r8192U_core.c
@@ -144,13 +144,13 @@ MODULE_VERSION("V 1.1");
144MODULE_DEVICE_TABLE(usb, rtl8192_usb_id_tbl); 144MODULE_DEVICE_TABLE(usb, rtl8192_usb_id_tbl);
145MODULE_DESCRIPTION("Linux driver for Realtek RTL8192 USB WiFi cards"); 145MODULE_DESCRIPTION("Linux driver for Realtek RTL8192 USB WiFi cards");
146 146
147static char* ifname = "wlan%d"; 147static char ifname[IFNAMSIZ] = "wlan%d";
148static int hwwep = 1; //default use hw. set 0 to use software security 148static int hwwep = 1; //default use hw. set 0 to use software security
149static int channels = 0x3fff; 149static int channels = 0x3fff;
150 150
151 151
152 152
153module_param(ifname, charp, S_IRUGO|S_IWUSR ); 153module_param_string(ifname, ifname, sizeof(ifname), S_IRUGO|S_IWUSR);
154//module_param(hwseqnum,int, S_IRUGO|S_IWUSR); 154//module_param(hwseqnum,int, S_IRUGO|S_IWUSR);
155module_param(hwwep,int, S_IRUGO|S_IWUSR); 155module_param(hwwep,int, S_IRUGO|S_IWUSR);
156module_param(channels,int, S_IRUGO|S_IWUSR); 156module_param(channels,int, S_IRUGO|S_IWUSR);
@@ -7406,7 +7406,7 @@ static int __devinit rtl8192_usb_probe(struct usb_interface *intf,
7406 7406
7407 if (dev_alloc_name(dev, ifname) < 0){ 7407 if (dev_alloc_name(dev, ifname) < 0){
7408 RT_TRACE(COMP_INIT, "Oops: devname already taken! Trying wlan%%d...\n"); 7408 RT_TRACE(COMP_INIT, "Oops: devname already taken! Trying wlan%%d...\n");
7409 ifname = "wlan%d"; 7409 strcpy(ifname, "wlan%d");
7410 dev_alloc_name(dev, ifname); 7410 dev_alloc_name(dev, ifname);
7411 } 7411 }
7412 7412
diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
index be5d8db98165..0574d848b900 100644
--- a/drivers/staging/usbip/vhci_hcd.c
+++ b/drivers/staging/usbip/vhci_hcd.c
@@ -215,7 +215,7 @@ static int vhci_hub_status(struct usb_hcd *hcd, char *buf)
215 vhci = hcd_to_vhci(hcd); 215 vhci = hcd_to_vhci(hcd);
216 216
217 spin_lock_irqsave(&vhci->lock, flags); 217 spin_lock_irqsave(&vhci->lock, flags);
218 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) { 218 if (!HCD_HW_ACCESSIBLE(hcd)) {
219 usbip_dbg_vhci_rh("hw accessible flag in on?\n"); 219 usbip_dbg_vhci_rh("hw accessible flag in on?\n");
220 goto done; 220 goto done;
221 } 221 }
@@ -269,7 +269,7 @@ static int vhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
269 269
270 u32 prev_port_status[VHCI_NPORTS]; 270 u32 prev_port_status[VHCI_NPORTS];
271 271
272 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) 272 if (!HCD_HW_ACCESSIBLE(hcd))
273 return -ETIMEDOUT; 273 return -ETIMEDOUT;
274 274
275 /* 275 /*
@@ -1041,7 +1041,7 @@ static int vhci_bus_resume(struct usb_hcd *hcd)
1041 dev_dbg(&hcd->self.root_hub->dev, "%s\n", __func__); 1041 dev_dbg(&hcd->self.root_hub->dev, "%s\n", __func__);
1042 1042
1043 spin_lock_irq(&vhci->lock); 1043 spin_lock_irq(&vhci->lock);
1044 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) { 1044 if (!HCD_HW_ACCESSIBLE(hcd)) {
1045 rc = -ESHUTDOWN; 1045 rc = -ESHUTDOWN;
1046 } else { 1046 } else {
1047 /* vhci->rh_state = DUMMY_RH_RUNNING; 1047 /* vhci->rh_state = DUMMY_RH_RUNNING;
diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile
index 80b4008c89ba..239f050efa35 100644
--- a/drivers/usb/Makefile
+++ b/drivers/usb/Makefile
@@ -41,7 +41,7 @@ obj-$(CONFIG_USB_MICROTEK) += image/
41obj-$(CONFIG_USB_SERIAL) += serial/ 41obj-$(CONFIG_USB_SERIAL) += serial/
42 42
43obj-$(CONFIG_USB) += misc/ 43obj-$(CONFIG_USB) += misc/
44obj-y += early/ 44obj-$(CONFIG_EARLY_PRINTK_DBGP) += early/
45 45
46obj-$(CONFIG_USB_ATM) += atm/ 46obj-$(CONFIG_USB_ATM) += atm/
47obj-$(CONFIG_USB_SPEEDTOUCH) += atm/ 47obj-$(CONFIG_USB_SPEEDTOUCH) += atm/
diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
index 101ffc965ee0..593fc5e2d2e6 100644
--- a/drivers/usb/atm/cxacru.c
+++ b/drivers/usb/atm/cxacru.c
@@ -564,7 +564,7 @@ static void cxacru_timeout_kill(unsigned long data)
564} 564}
565 565
566static int cxacru_start_wait_urb(struct urb *urb, struct completion *done, 566static int cxacru_start_wait_urb(struct urb *urb, struct completion *done,
567 int* actual_length) 567 int *actual_length)
568{ 568{
569 struct timer_list timer; 569 struct timer_list timer;
570 570
@@ -952,7 +952,7 @@ static int cxacru_fw(struct usb_device *usb_dev, enum cxacru_fw_request fw,
952 put_unaligned(cpu_to_le32(addr), (__le32 *)(buf + offb)); 952 put_unaligned(cpu_to_le32(addr), (__le32 *)(buf + offb));
953 offb += 4; 953 offb += 4;
954 addr += l; 954 addr += l;
955 if(l) 955 if (l)
956 memcpy(buf + offb, data + offd, l); 956 memcpy(buf + offb, data + offd, l);
957 if (l < stride) 957 if (l < stride)
958 memset(buf + offb + l, 0, stride - l); 958 memset(buf + offb + l, 0, stride - l);
@@ -967,7 +967,7 @@ static int cxacru_fw(struct usb_device *usb_dev, enum cxacru_fw_request fw,
967 } 967 }
968 offb = 0; 968 offb = 0;
969 } 969 }
970 } while(offd < size); 970 } while (offd < size);
971 dbg("sent fw %#x", fw); 971 dbg("sent fw %#x", fw);
972 972
973 ret = 0; 973 ret = 0;
@@ -1043,8 +1043,7 @@ static void cxacru_upload_firmware(struct cxacru_data *instance,
1043 if (instance->modem_type->boot_rom_patch) { 1043 if (instance->modem_type->boot_rom_patch) {
1044 val = cpu_to_le32(BR_ADDR); 1044 val = cpu_to_le32(BR_ADDR);
1045 ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, BR_STACK_ADDR, (u8 *) &val, 4); 1045 ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, BR_STACK_ADDR, (u8 *) &val, 4);
1046 } 1046 } else {
1047 else {
1048 ret = cxacru_fw(usb_dev, FW_GOTO_MEM, 0x0, 0x0, FW_ADDR, NULL, 0); 1047 ret = cxacru_fw(usb_dev, FW_GOTO_MEM, 0x0, 0x0, FW_ADDR, NULL, 0);
1049 } 1048 }
1050 if (ret) { 1049 if (ret) {
@@ -1068,7 +1067,7 @@ static void cxacru_upload_firmware(struct cxacru_data *instance,
1068} 1067}
1069 1068
1070static int cxacru_find_firmware(struct cxacru_data *instance, 1069static int cxacru_find_firmware(struct cxacru_data *instance,
1071 char* phase, const struct firmware **fw_p) 1070 char *phase, const struct firmware **fw_p)
1072{ 1071{
1073 struct usbatm_data *usbatm = instance->usbatm; 1072 struct usbatm_data *usbatm = instance->usbatm;
1074 struct device *dev = &usbatm->usb_intf->dev; 1073 struct device *dev = &usbatm->usb_intf->dev;
diff --git a/drivers/usb/atm/speedtch.c b/drivers/usb/atm/speedtch.c
index 80f9617d3a15..4716e707de59 100644
--- a/drivers/usb/atm/speedtch.c
+++ b/drivers/usb/atm/speedtch.c
@@ -753,11 +753,13 @@ static struct usb_driver speedtch_usb_driver = {
753 .id_table = speedtch_usb_ids 753 .id_table = speedtch_usb_ids
754}; 754};
755 755
756static void speedtch_release_interfaces(struct usb_device *usb_dev, int num_interfaces) { 756static void speedtch_release_interfaces(struct usb_device *usb_dev,
757 int num_interfaces)
758{
757 struct usb_interface *cur_intf; 759 struct usb_interface *cur_intf;
758 int i; 760 int i;
759 761
760 for(i = 0; i < num_interfaces; i++) 762 for (i = 0; i < num_interfaces; i++)
761 if ((cur_intf = usb_ifnum_to_if(usb_dev, i))) { 763 if ((cur_intf = usb_ifnum_to_if(usb_dev, i))) {
762 usb_set_intfdata(cur_intf, NULL); 764 usb_set_intfdata(cur_intf, NULL);
763 usb_driver_release_interface(&speedtch_usb_driver, cur_intf); 765 usb_driver_release_interface(&speedtch_usb_driver, cur_intf);
@@ -792,7 +794,7 @@ static int speedtch_bind(struct usbatm_data *usbatm,
792 794
793 /* claim all interfaces */ 795 /* claim all interfaces */
794 796
795 for (i=0; i < num_interfaces; i++) { 797 for (i = 0; i < num_interfaces; i++) {
796 cur_intf = usb_ifnum_to_if(usb_dev, i); 798 cur_intf = usb_ifnum_to_if(usb_dev, i);
797 799
798 if ((i != ifnum) && cur_intf) { 800 if ((i != ifnum) && cur_intf) {
@@ -842,7 +844,7 @@ static int speedtch_bind(struct usbatm_data *usbatm,
842 844
843 use_isoc = 0; /* fall back to bulk if endpoint not found */ 845 use_isoc = 0; /* fall back to bulk if endpoint not found */
844 846
845 for (i=0; i<desc->desc.bNumEndpoints; i++) { 847 for (i = 0; i < desc->desc.bNumEndpoints; i++) {
846 const struct usb_endpoint_descriptor *endpoint_desc = &desc->endpoint[i].desc; 848 const struct usb_endpoint_descriptor *endpoint_desc = &desc->endpoint[i].desc;
847 849
848 if ((endpoint_desc->bEndpointAddress == target_address)) { 850 if ((endpoint_desc->bEndpointAddress == target_address)) {
diff --git a/drivers/usb/atm/ueagle-atm.c b/drivers/usb/atm/ueagle-atm.c
index ebae94480140..ea071a5b6eee 100644
--- a/drivers/usb/atm/ueagle-atm.c
+++ b/drivers/usb/atm/ueagle-atm.c
@@ -67,6 +67,7 @@
67#include <linux/mutex.h> 67#include <linux/mutex.h>
68#include <linux/freezer.h> 68#include <linux/freezer.h>
69#include <linux/slab.h> 69#include <linux/slab.h>
70#include <linux/kernel.h>
70 71
71#include <asm/unaligned.h> 72#include <asm/unaligned.h>
72 73
@@ -1576,6 +1577,7 @@ static void cmvs_file_name(struct uea_softc *sc, char *const cmv_name, int ver)
1576 char file_arr[] = "CMVxy.bin"; 1577 char file_arr[] = "CMVxy.bin";
1577 char *file; 1578 char *file;
1578 1579
1580 kparam_block_sysfs_write(cmv_file);
1579 /* set proper name corresponding modem version and line type */ 1581 /* set proper name corresponding modem version and line type */
1580 if (cmv_file[sc->modem_index] == NULL) { 1582 if (cmv_file[sc->modem_index] == NULL) {
1581 if (UEA_CHIP_VERSION(sc) == ADI930) 1583 if (UEA_CHIP_VERSION(sc) == ADI930)
@@ -1594,6 +1596,7 @@ static void cmvs_file_name(struct uea_softc *sc, char *const cmv_name, int ver)
1594 strlcat(cmv_name, file, UEA_FW_NAME_MAX); 1596 strlcat(cmv_name, file, UEA_FW_NAME_MAX);
1595 if (ver == 2) 1597 if (ver == 2)
1596 strlcat(cmv_name, ".v2", UEA_FW_NAME_MAX); 1598 strlcat(cmv_name, ".v2", UEA_FW_NAME_MAX);
1599 kparam_unblock_sysfs_write(cmv_file);
1597} 1600}
1598 1601
1599static int request_cmvs_old(struct uea_softc *sc, 1602static int request_cmvs_old(struct uea_softc *sc,
@@ -2436,7 +2439,6 @@ UEA_ATTR(firmid, 0);
2436 2439
2437/* Retrieve the device End System Identifier (MAC) */ 2440/* Retrieve the device End System Identifier (MAC) */
2438 2441
2439#define htoi(x) (isdigit(x) ? x-'0' : toupper(x)-'A'+10)
2440static int uea_getesi(struct uea_softc *sc, u_char * esi) 2442static int uea_getesi(struct uea_softc *sc, u_char * esi)
2441{ 2443{
2442 unsigned char mac_str[2 * ETH_ALEN + 1]; 2444 unsigned char mac_str[2 * ETH_ALEN + 1];
@@ -2447,7 +2449,8 @@ static int uea_getesi(struct uea_softc *sc, u_char * esi)
2447 return 1; 2449 return 1;
2448 2450
2449 for (i = 0; i < ETH_ALEN; i++) 2451 for (i = 0; i < ETH_ALEN; i++)
2450 esi[i] = htoi(mac_str[2 * i]) * 16 + htoi(mac_str[2 * i + 1]); 2452 esi[i] = hex_to_bin(mac_str[2 * i]) * 16 +
2453 hex_to_bin(mac_str[2 * i + 1]);
2451 2454
2452 return 0; 2455 return 0;
2453} 2456}
diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
index 9b53e8df4648..05bf5a27b5b0 100644
--- a/drivers/usb/atm/usbatm.c
+++ b/drivers/usb/atm/usbatm.c
@@ -84,8 +84,8 @@
84 84
85#ifdef VERBOSE_DEBUG 85#ifdef VERBOSE_DEBUG
86static int usbatm_print_packet(const unsigned char *data, int len); 86static int usbatm_print_packet(const unsigned char *data, int len);
87#define PACKETDEBUG(arg...) usbatm_print_packet (arg) 87#define PACKETDEBUG(arg...) usbatm_print_packet(arg)
88#define vdbg(arg...) dbg (arg) 88#define vdbg(arg...) dbg(arg)
89#else 89#else
90#define PACKETDEBUG(arg...) 90#define PACKETDEBUG(arg...)
91#define vdbg(arg...) 91#define vdbg(arg...)
@@ -273,8 +273,7 @@ static void usbatm_complete(struct urb *urb)
273 273
274 if (unlikely(status) && 274 if (unlikely(status) &&
275 (!(channel->usbatm->flags & UDSL_IGNORE_EILSEQ) || 275 (!(channel->usbatm->flags & UDSL_IGNORE_EILSEQ) ||
276 status != -EILSEQ )) 276 status != -EILSEQ)) {
277 {
278 if (status == -ESHUTDOWN) 277 if (status == -ESHUTDOWN)
279 return; 278 return;
280 279
@@ -494,7 +493,7 @@ static unsigned int usbatm_write_cells(struct usbatm_data *instance,
494 ptr += data_len; 493 ptr += data_len;
495 __skb_pull(skb, data_len); 494 __skb_pull(skb, data_len);
496 495
497 if(!left) 496 if (!left)
498 continue; 497 continue;
499 498
500 memset(ptr, 0, left); 499 memset(ptr, 0, left);
@@ -506,7 +505,7 @@ static unsigned int usbatm_write_cells(struct usbatm_data *instance,
506 trailer[2] = ctrl->len >> 8; 505 trailer[2] = ctrl->len >> 8;
507 trailer[3] = ctrl->len; 506 trailer[3] = ctrl->len;
508 507
509 ctrl->crc = ~ crc32_be(ctrl->crc, ptr, left - 4); 508 ctrl->crc = ~crc32_be(ctrl->crc, ptr, left - 4);
510 509
511 trailer[4] = ctrl->crc >> 24; 510 trailer[4] = ctrl->crc >> 24;
512 trailer[5] = ctrl->crc >> 16; 511 trailer[5] = ctrl->crc >> 16;
@@ -516,8 +515,7 @@ static unsigned int usbatm_write_cells(struct usbatm_data *instance,
516 target[3] |= 0x2; /* adjust PTI */ 515 target[3] |= 0x2; /* adjust PTI */
517 516
518 ctrl->len = 0; /* tag this skb finished */ 517 ctrl->len = 0; /* tag this skb finished */
519 } 518 } else
520 else
521 ctrl->crc = crc32_be(ctrl->crc, ptr, left); 519 ctrl->crc = crc32_be(ctrl->crc, ptr, left);
522 } 520 }
523 521
@@ -1146,7 +1144,7 @@ int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id,
1146 instance->tx_channel.endpoint = usb_sndbulkpipe(usb_dev, driver->bulk_out); 1144 instance->tx_channel.endpoint = usb_sndbulkpipe(usb_dev, driver->bulk_out);
1147 1145
1148 /* tx buffer size must be a positive multiple of the stride */ 1146 /* tx buffer size must be a positive multiple of the stride */
1149 instance->tx_channel.buf_size = max (instance->tx_channel.stride, 1147 instance->tx_channel.buf_size = max(instance->tx_channel.stride,
1150 snd_buf_bytes - (snd_buf_bytes % instance->tx_channel.stride)); 1148 snd_buf_bytes - (snd_buf_bytes % instance->tx_channel.stride));
1151 1149
1152 /* rx buffer size must be a positive multiple of the endpoint maxpacket */ 1150 /* rx buffer size must be a positive multiple of the endpoint maxpacket */
@@ -1159,7 +1157,7 @@ int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id,
1159 goto fail_unbind; 1157 goto fail_unbind;
1160 } 1158 }
1161 1159
1162 num_packets = max (1U, (rcv_buf_bytes + maxpacket / 2) / maxpacket); /* round */ 1160 num_packets = max(1U, (rcv_buf_bytes + maxpacket / 2) / maxpacket); /* round */
1163 1161
1164 if (num_packets * maxpacket > UDSL_MAX_BUF_SIZE) 1162 if (num_packets * maxpacket > UDSL_MAX_BUF_SIZE)
1165 num_packets--; 1163 num_packets--;
@@ -1262,7 +1260,7 @@ int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id,
1262 usb_free_urb(instance->urbs[i]); 1260 usb_free_urb(instance->urbs[i]);
1263 } 1261 }
1264 1262
1265 kfree (instance); 1263 kfree(instance);
1266 1264
1267 return error; 1265 return error;
1268} 1266}
@@ -1390,9 +1388,8 @@ static int usbatm_print_packet(const unsigned char *data, int len)
1390 for (i = 0; i < len;) { 1388 for (i = 0; i < len;) {
1391 buffer[0] = '\0'; 1389 buffer[0] = '\0';
1392 sprintf(buffer, "%.3d :", i); 1390 sprintf(buffer, "%.3d :", i);
1393 for (j = 0; (j < 16) && (i < len); j++, i++) { 1391 for (j = 0; (j < 16) && (i < len); j++, i++)
1394 sprintf(buffer, "%s %2.2x", buffer, data[i]); 1392 sprintf(buffer, "%s %2.2x", buffer, data[i]);
1395 }
1396 dbg("%s", buffer); 1393 dbg("%s", buffer);
1397 } 1394 }
1398 return i; 1395 return i;
diff --git a/drivers/usb/atm/usbatm.h b/drivers/usb/atm/usbatm.h
index 0863f85fcc26..5fc489405217 100644
--- a/drivers/usb/atm/usbatm.h
+++ b/drivers/usb/atm/usbatm.h
@@ -48,7 +48,7 @@
48 dev_warn(&(instance)->usb_intf->dev, \ 48 dev_warn(&(instance)->usb_intf->dev, \
49 "failed assertion '%s' at line %d", \ 49 "failed assertion '%s' at line %d", \
50 __stringify(x), __LINE__); \ 50 __stringify(x), __LINE__); \
51 } while(0) 51 } while (0)
52#endif 52#endif
53 53
54#define usb_err(instance, format, arg...) \ 54#define usb_err(instance, format, arg...) \
@@ -59,7 +59,7 @@
59 dev_warn(&(instance)->usb_intf->dev , format , ## arg) 59 dev_warn(&(instance)->usb_intf->dev , format , ## arg)
60#ifdef DEBUG 60#ifdef DEBUG
61#define usb_dbg(instance, format, arg...) \ 61#define usb_dbg(instance, format, arg...) \
62 dev_printk(KERN_DEBUG , &(instance)->usb_intf->dev , format , ## arg) 62 dev_printk(KERN_DEBUG , &(instance)->usb_intf->dev , format , ## arg)
63#else 63#else
64#define usb_dbg(instance, format, arg...) \ 64#define usb_dbg(instance, format, arg...) \
65 do {} while (0) 65 do {} while (0)
@@ -104,21 +104,21 @@ struct usbatm_data;
104/* 104/*
105* Assuming all methods exist and succeed, they are called in this order: 105* Assuming all methods exist and succeed, they are called in this order:
106* 106*
107* bind, heavy_init, atm_start, ..., atm_stop, unbind 107* bind, heavy_init, atm_start, ..., atm_stop, unbind
108*/ 108*/
109 109
110struct usbatm_driver { 110struct usbatm_driver {
111 const char *driver_name; 111 const char *driver_name;
112 112
113 /* init device ... can sleep, or cause probe() failure */ 113 /* init device ... can sleep, or cause probe() failure */
114 int (*bind) (struct usbatm_data *, struct usb_interface *, 114 int (*bind) (struct usbatm_data *, struct usb_interface *,
115 const struct usb_device_id *id); 115 const struct usb_device_id *id);
116 116
117 /* additional device initialization that is too slow to be done in probe() */ 117 /* additional device initialization that is too slow to be done in probe() */
118 int (*heavy_init) (struct usbatm_data *, struct usb_interface *); 118 int (*heavy_init) (struct usbatm_data *, struct usb_interface *);
119 119
120 /* cleanup device ... can sleep, but can't fail */ 120 /* cleanup device ... can sleep, but can't fail */
121 void (*unbind) (struct usbatm_data *, struct usb_interface *); 121 void (*unbind) (struct usbatm_data *, struct usb_interface *);
122 122
123 /* init ATM device ... can sleep, or cause ATM initialization failure */ 123 /* init ATM device ... can sleep, or cause ATM initialization failure */
124 int (*atm_start) (struct usbatm_data *, struct atm_dev *); 124 int (*atm_start) (struct usbatm_data *, struct atm_dev *);
@@ -126,9 +126,9 @@ struct usbatm_driver {
126 /* cleanup ATM device ... can sleep, but can't fail */ 126 /* cleanup ATM device ... can sleep, but can't fail */
127 void (*atm_stop) (struct usbatm_data *, struct atm_dev *); 127 void (*atm_stop) (struct usbatm_data *, struct atm_dev *);
128 128
129 int bulk_in; /* bulk rx endpoint */ 129 int bulk_in; /* bulk rx endpoint */
130 int isoc_in; /* isochronous rx endpoint */ 130 int isoc_in; /* isochronous rx endpoint */
131 int bulk_out; /* bulk tx endpoint */ 131 int bulk_out; /* bulk tx endpoint */
132 132
133 unsigned rx_padding; 133 unsigned rx_padding;
134 unsigned tx_padding; 134 unsigned tx_padding;
@@ -156,7 +156,7 @@ struct usbatm_channel {
156struct usbatm_data { 156struct usbatm_data {
157 /****************** 157 /******************
158 * public fields * 158 * public fields *
159 ******************/ 159 ******************/
160 160
161 /* mini driver */ 161 /* mini driver */
162 struct usbatm_driver *driver; 162 struct usbatm_driver *driver;
@@ -174,7 +174,7 @@ struct usbatm_data {
174 174
175 /******************************** 175 /********************************
176 * private fields - do not use * 176 * private fields - do not use *
177 ********************************/ 177 ********************************/
178 178
179 struct kref refcount; 179 struct kref refcount;
180 struct mutex serialize; 180 struct mutex serialize;
diff --git a/drivers/usb/atm/xusbatm.c b/drivers/usb/atm/xusbatm.c
index 17d167bbd2dc..48ee0c5ff282 100644
--- a/drivers/usb/atm/xusbatm.c
+++ b/drivers/usb/atm/xusbatm.c
@@ -49,13 +49,13 @@ static struct usbatm_driver xusbatm_drivers[XUSBATM_DRIVERS_MAX];
49static struct usb_device_id xusbatm_usb_ids[XUSBATM_DRIVERS_MAX + 1]; 49static struct usb_device_id xusbatm_usb_ids[XUSBATM_DRIVERS_MAX + 1];
50static struct usb_driver xusbatm_usb_driver; 50static struct usb_driver xusbatm_usb_driver;
51 51
52static struct usb_interface *xusbatm_find_intf (struct usb_device *usb_dev, int altsetting, u8 ep) 52static struct usb_interface *xusbatm_find_intf(struct usb_device *usb_dev, int altsetting, u8 ep)
53{ 53{
54 struct usb_host_interface *alt; 54 struct usb_host_interface *alt;
55 struct usb_interface *intf; 55 struct usb_interface *intf;
56 int i, j; 56 int i, j;
57 57
58 for(i = 0; i < usb_dev->actconfig->desc.bNumInterfaces; i++) 58 for (i = 0; i < usb_dev->actconfig->desc.bNumInterfaces; i++)
59 if ((intf = usb_dev->actconfig->interface[i]) && (alt = usb_altnum_to_altsetting(intf, altsetting))) 59 if ((intf = usb_dev->actconfig->interface[i]) && (alt = usb_altnum_to_altsetting(intf, altsetting)))
60 for (j = 0; j < alt->desc.bNumEndpoints; j++) 60 for (j = 0; j < alt->desc.bNumEndpoints; j++)
61 if (alt->endpoint[j].desc.bEndpointAddress == ep) 61 if (alt->endpoint[j].desc.bEndpointAddress == ep)
@@ -63,7 +63,7 @@ static struct usb_interface *xusbatm_find_intf (struct usb_device *usb_dev, int
63 return NULL; 63 return NULL;
64} 64}
65 65
66static int xusbatm_capture_intf (struct usbatm_data *usbatm, struct usb_device *usb_dev, 66static int xusbatm_capture_intf(struct usbatm_data *usbatm, struct usb_device *usb_dev,
67 struct usb_interface *intf, int altsetting, int claim) 67 struct usb_interface *intf, int altsetting, int claim)
68{ 68{
69 int ifnum = intf->altsetting->desc.bInterfaceNumber; 69 int ifnum = intf->altsetting->desc.bInterfaceNumber;
@@ -80,7 +80,7 @@ static int xusbatm_capture_intf (struct usbatm_data *usbatm, struct usb_device *
80 return 0; 80 return 0;
81} 81}
82 82
83static void xusbatm_release_intf (struct usb_device *usb_dev, struct usb_interface *intf, int claimed) 83static void xusbatm_release_intf(struct usb_device *usb_dev, struct usb_interface *intf, int claimed)
84{ 84{
85 if (claimed) { 85 if (claimed) {
86 usb_set_intfdata(intf, NULL); 86 usb_set_intfdata(intf, NULL);
@@ -147,7 +147,7 @@ static void xusbatm_unbind(struct usbatm_data *usbatm,
147 147
148 usb_dbg(usbatm, "%s entered\n", __func__); 148 usb_dbg(usbatm, "%s entered\n", __func__);
149 149
150 for(i = 0; i < usb_dev->actconfig->desc.bNumInterfaces; i++) { 150 for (i = 0; i < usb_dev->actconfig->desc.bNumInterfaces; i++) {
151 struct usb_interface *cur_intf = usb_dev->actconfig->interface[i]; 151 struct usb_interface *cur_intf = usb_dev->actconfig->interface[i];
152 152
153 if (cur_intf && (usb_get_intfdata(cur_intf) == usbatm)) { 153 if (cur_intf && (usb_get_intfdata(cur_intf) == usbatm)) {
diff --git a/drivers/usb/c67x00/c67x00-hcd.c b/drivers/usb/c67x00/c67x00-hcd.c
index a22b887f4e9e..d3e1356d091e 100644
--- a/drivers/usb/c67x00/c67x00-hcd.c
+++ b/drivers/usb/c67x00/c67x00-hcd.c
@@ -264,7 +264,7 @@ static void c67x00_hcd_irq(struct c67x00_sie *sie, u16 int_status, u16 msg)
264 if (unlikely(hcd->state == HC_STATE_HALT)) 264 if (unlikely(hcd->state == HC_STATE_HALT))
265 return; 265 return;
266 266
267 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) 267 if (!HCD_HW_ACCESSIBLE(hcd))
268 return; 268 return;
269 269
270 /* Handle Start of frame events */ 270 /* Handle Start of frame events */
@@ -282,7 +282,7 @@ static int c67x00_hcd_start(struct usb_hcd *hcd)
282{ 282{
283 hcd->uses_new_polling = 1; 283 hcd->uses_new_polling = 1;
284 hcd->state = HC_STATE_RUNNING; 284 hcd->state = HC_STATE_RUNNING;
285 hcd->poll_rh = 1; 285 set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
286 286
287 return 0; 287 return 0;
288} 288}
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 89d260d6b031..1833b3a71515 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -636,19 +636,13 @@ static void acm_tty_unregister(struct acm *acm)
636 636
637static int acm_tty_chars_in_buffer(struct tty_struct *tty); 637static int acm_tty_chars_in_buffer(struct tty_struct *tty);
638 638
639static void acm_port_down(struct acm *acm, int drain) 639static void acm_port_down(struct acm *acm)
640{ 640{
641 int i, nr = acm->rx_buflimit; 641 int i, nr = acm->rx_buflimit;
642 mutex_lock(&open_mutex); 642 mutex_lock(&open_mutex);
643 if (acm->dev) { 643 if (acm->dev) {
644 usb_autopm_get_interface(acm->control); 644 usb_autopm_get_interface(acm->control);
645 acm_set_control(acm, acm->ctrlout = 0); 645 acm_set_control(acm, acm->ctrlout = 0);
646 /* try letting the last writes drain naturally */
647 if (drain) {
648 wait_event_interruptible_timeout(acm->drain_wait,
649 (ACM_NW == acm_wb_is_avail(acm)) || !acm->dev,
650 ACM_CLOSE_TIMEOUT * HZ);
651 }
652 usb_kill_urb(acm->ctrlurb); 646 usb_kill_urb(acm->ctrlurb);
653 for (i = 0; i < ACM_NW; i++) 647 for (i = 0; i < ACM_NW; i++)
654 usb_kill_urb(acm->wb[i].urb); 648 usb_kill_urb(acm->wb[i].urb);
@@ -664,7 +658,7 @@ static void acm_tty_hangup(struct tty_struct *tty)
664{ 658{
665 struct acm *acm = tty->driver_data; 659 struct acm *acm = tty->driver_data;
666 tty_port_hangup(&acm->port); 660 tty_port_hangup(&acm->port);
667 acm_port_down(acm, 0); 661 acm_port_down(acm);
668} 662}
669 663
670static void acm_tty_close(struct tty_struct *tty, struct file *filp) 664static void acm_tty_close(struct tty_struct *tty, struct file *filp)
@@ -685,7 +679,7 @@ static void acm_tty_close(struct tty_struct *tty, struct file *filp)
685 mutex_unlock(&open_mutex); 679 mutex_unlock(&open_mutex);
686 return; 680 return;
687 } 681 }
688 acm_port_down(acm, 0); 682 acm_port_down(acm);
689 tty_port_close_end(&acm->port, tty); 683 tty_port_close_end(&acm->port, tty);
690 tty_port_tty_set(&acm->port, NULL); 684 tty_port_tty_set(&acm->port, NULL);
691} 685}
diff --git a/drivers/usb/class/usblp.c b/drivers/usb/class/usblp.c
index 84f9e52327f2..e325162859b0 100644
--- a/drivers/usb/class/usblp.c
+++ b/drivers/usb/class/usblp.c
@@ -135,7 +135,7 @@ MFG:HEWLETT-PACKARD;MDL:DESKJET 970C;CMD:MLC,PCL,PML;CLASS:PRINTER;DESCRIPTION:H
135 * ->lock locks what interrupt accesses. 135 * ->lock locks what interrupt accesses.
136 */ 136 */
137struct usblp { 137struct usblp {
138 struct usb_device *dev; /* USB device */ 138 struct usb_device *dev; /* USB device */
139 struct mutex wmut; 139 struct mutex wmut;
140 struct mutex mut; 140 struct mutex mut;
141 spinlock_t lock; /* locks rcomplete, wcomplete */ 141 spinlock_t lock; /* locks rcomplete, wcomplete */
@@ -169,7 +169,8 @@ struct usblp {
169}; 169};
170 170
171#ifdef DEBUG 171#ifdef DEBUG
172static void usblp_dump(struct usblp *usblp) { 172static void usblp_dump(struct usblp *usblp)
173{
173 int p; 174 int p;
174 175
175 dbg("usblp=0x%p", usblp); 176 dbg("usblp=0x%p", usblp);
@@ -216,8 +217,8 @@ static const struct quirk_printer_struct quirk_printers[] = {
216 { 0x03f0, 0x0304, USBLP_QUIRK_BIDIR }, /* HP DeskJet 810C/812C */ 217 { 0x03f0, 0x0304, USBLP_QUIRK_BIDIR }, /* HP DeskJet 810C/812C */
217 { 0x03f0, 0x0404, USBLP_QUIRK_BIDIR }, /* HP DeskJet 830C */ 218 { 0x03f0, 0x0404, USBLP_QUIRK_BIDIR }, /* HP DeskJet 830C */
218 { 0x03f0, 0x0504, USBLP_QUIRK_BIDIR }, /* HP DeskJet 885C */ 219 { 0x03f0, 0x0504, USBLP_QUIRK_BIDIR }, /* HP DeskJet 885C */
219 { 0x03f0, 0x0604, USBLP_QUIRK_BIDIR }, /* HP DeskJet 840C */ 220 { 0x03f0, 0x0604, USBLP_QUIRK_BIDIR }, /* HP DeskJet 840C */
220 { 0x03f0, 0x0804, USBLP_QUIRK_BIDIR }, /* HP DeskJet 816C */ 221 { 0x03f0, 0x0804, USBLP_QUIRK_BIDIR }, /* HP DeskJet 816C */
221 { 0x03f0, 0x1104, USBLP_QUIRK_BIDIR }, /* HP Deskjet 959C */ 222 { 0x03f0, 0x1104, USBLP_QUIRK_BIDIR }, /* HP Deskjet 959C */
222 { 0x0409, 0xefbe, USBLP_QUIRK_BIDIR }, /* NEC Picty900 (HP OEM) */ 223 { 0x0409, 0xefbe, USBLP_QUIRK_BIDIR }, /* NEC Picty900 (HP OEM) */
223 { 0x0409, 0xbef4, USBLP_QUIRK_BIDIR }, /* NEC Picty760 (HP OEM) */ 224 { 0x0409, 0xbef4, USBLP_QUIRK_BIDIR }, /* NEC Picty760 (HP OEM) */
@@ -254,9 +255,8 @@ static int usblp_ctrl_msg(struct usblp *usblp, int request, int type, int dir, i
254 /* High byte has the interface index. 255 /* High byte has the interface index.
255 Low byte has the alternate setting. 256 Low byte has the alternate setting.
256 */ 257 */
257 if ((request == USBLP_REQ_GET_ID) && (type == USB_TYPE_CLASS)) { 258 if ((request == USBLP_REQ_GET_ID) && (type == USB_TYPE_CLASS))
258 index = (usblp->ifnum<<8)|usblp->protocol[usblp->current_protocol].alt_setting; 259 index = (usblp->ifnum<<8)|usblp->protocol[usblp->current_protocol].alt_setting;
259 }
260 260
261 retval = usb_control_msg(usblp->dev, 261 retval = usb_control_msg(usblp->dev,
262 dir ? usb_rcvctrlpipe(usblp->dev, 0) : usb_sndctrlpipe(usblp->dev, 0), 262 dir ? usb_rcvctrlpipe(usblp->dev, 0) : usb_sndctrlpipe(usblp->dev, 0),
@@ -372,7 +372,7 @@ static int usblp_check_status(struct usblp *usblp, int err)
372 return newerr; 372 return newerr;
373} 373}
374 374
375static int handle_bidir (struct usblp *usblp) 375static int handle_bidir(struct usblp *usblp)
376{ 376{
377 if (usblp->bidir && usblp->used) { 377 if (usblp->bidir && usblp->used) {
378 if (usblp_submit_read(usblp) < 0) 378 if (usblp_submit_read(usblp) < 0)
@@ -395,14 +395,13 @@ static int usblp_open(struct inode *inode, struct file *file)
395 if (minor < 0) 395 if (minor < 0)
396 return -ENODEV; 396 return -ENODEV;
397 397
398 mutex_lock (&usblp_mutex); 398 mutex_lock(&usblp_mutex);
399 399
400 retval = -ENODEV; 400 retval = -ENODEV;
401 intf = usb_find_interface(&usblp_driver, minor); 401 intf = usb_find_interface(&usblp_driver, minor);
402 if (!intf) { 402 if (!intf)
403 goto out; 403 goto out;
404 } 404 usblp = usb_get_intfdata(intf);
405 usblp = usb_get_intfdata (intf);
406 if (!usblp || !usblp->dev || !usblp->present) 405 if (!usblp || !usblp->dev || !usblp->present)
407 goto out; 406 goto out;
408 407
@@ -433,18 +432,18 @@ static int usblp_open(struct inode *inode, struct file *file)
433 retval = -EIO; 432 retval = -EIO;
434 } 433 }
435out: 434out:
436 mutex_unlock (&usblp_mutex); 435 mutex_unlock(&usblp_mutex);
437 return retval; 436 return retval;
438} 437}
439 438
440static void usblp_cleanup (struct usblp *usblp) 439static void usblp_cleanup(struct usblp *usblp)
441{ 440{
442 printk(KERN_INFO "usblp%d: removed\n", usblp->minor); 441 printk(KERN_INFO "usblp%d: removed\n", usblp->minor);
443 442
444 kfree(usblp->readbuf); 443 kfree(usblp->readbuf);
445 kfree (usblp->device_id_string); 444 kfree(usblp->device_id_string);
446 kfree (usblp->statusbuf); 445 kfree(usblp->statusbuf);
447 kfree (usblp); 446 kfree(usblp);
448} 447}
449 448
450static void usblp_unlink_urbs(struct usblp *usblp) 449static void usblp_unlink_urbs(struct usblp *usblp)
@@ -458,14 +457,14 @@ static int usblp_release(struct inode *inode, struct file *file)
458 457
459 usblp->flags &= ~LP_ABORT; 458 usblp->flags &= ~LP_ABORT;
460 459
461 mutex_lock (&usblp_mutex); 460 mutex_lock(&usblp_mutex);
462 usblp->used = 0; 461 usblp->used = 0;
463 if (usblp->present) { 462 if (usblp->present) {
464 usblp_unlink_urbs(usblp); 463 usblp_unlink_urbs(usblp);
465 usb_autopm_put_interface(usblp->intf); 464 usb_autopm_put_interface(usblp->intf);
466 } else /* finish cleanup from disconnect */ 465 } else /* finish cleanup from disconnect */
467 usblp_cleanup (usblp); 466 usblp_cleanup(usblp);
468 mutex_unlock (&usblp_mutex); 467 mutex_unlock(&usblp_mutex);
469 return 0; 468 return 0;
470} 469}
471 470
@@ -495,190 +494,190 @@ static long usblp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
495 int twoints[2]; 494 int twoints[2];
496 int retval = 0; 495 int retval = 0;
497 496
498 mutex_lock (&usblp->mut); 497 mutex_lock(&usblp->mut);
499 if (!usblp->present) { 498 if (!usblp->present) {
500 retval = -ENODEV; 499 retval = -ENODEV;
501 goto done; 500 goto done;
502 } 501 }
503 502
504 dbg("usblp_ioctl: cmd=0x%x (%c nr=%d len=%d dir=%d)", cmd, _IOC_TYPE(cmd), 503 dbg("usblp_ioctl: cmd=0x%x (%c nr=%d len=%d dir=%d)", cmd, _IOC_TYPE(cmd),
505 _IOC_NR(cmd), _IOC_SIZE(cmd), _IOC_DIR(cmd) ); 504 _IOC_NR(cmd), _IOC_SIZE(cmd), _IOC_DIR(cmd));
506 505
507 if (_IOC_TYPE(cmd) == 'P') /* new-style ioctl number */ 506 if (_IOC_TYPE(cmd) == 'P') /* new-style ioctl number */
508 507
509 switch (_IOC_NR(cmd)) { 508 switch (_IOC_NR(cmd)) {
510 509
511 case IOCNR_GET_DEVICE_ID: /* get the DEVICE_ID string */ 510 case IOCNR_GET_DEVICE_ID: /* get the DEVICE_ID string */
512 if (_IOC_DIR(cmd) != _IOC_READ) { 511 if (_IOC_DIR(cmd) != _IOC_READ) {
513 retval = -EINVAL; 512 retval = -EINVAL;
514 goto done; 513 goto done;
515 } 514 }
516 515
517 length = usblp_cache_device_id_string(usblp); 516 length = usblp_cache_device_id_string(usblp);
518 if (length < 0) { 517 if (length < 0) {
519 retval = length; 518 retval = length;
520 goto done; 519 goto done;
521 } 520 }
522 if (length > _IOC_SIZE(cmd)) 521 if (length > _IOC_SIZE(cmd))
523 length = _IOC_SIZE(cmd); /* truncate */ 522 length = _IOC_SIZE(cmd); /* truncate */
524 523
525 if (copy_to_user((void __user *) arg, 524 if (copy_to_user((void __user *) arg,
526 usblp->device_id_string, 525 usblp->device_id_string,
527 (unsigned long) length)) { 526 (unsigned long) length)) {
528 retval = -EFAULT; 527 retval = -EFAULT;
529 goto done; 528 goto done;
530 } 529 }
531 530
532 break; 531 break;
533 532
534 case IOCNR_GET_PROTOCOLS: 533 case IOCNR_GET_PROTOCOLS:
535 if (_IOC_DIR(cmd) != _IOC_READ || 534 if (_IOC_DIR(cmd) != _IOC_READ ||
536 _IOC_SIZE(cmd) < sizeof(twoints)) { 535 _IOC_SIZE(cmd) < sizeof(twoints)) {
537 retval = -EINVAL; 536 retval = -EINVAL;
538 goto done; 537 goto done;
539 } 538 }
540 539
541 twoints[0] = usblp->current_protocol; 540 twoints[0] = usblp->current_protocol;
542 twoints[1] = 0; 541 twoints[1] = 0;
543 for (i = USBLP_FIRST_PROTOCOL; 542 for (i = USBLP_FIRST_PROTOCOL;
544 i <= USBLP_LAST_PROTOCOL; i++) { 543 i <= USBLP_LAST_PROTOCOL; i++) {
545 if (usblp->protocol[i].alt_setting >= 0) 544 if (usblp->protocol[i].alt_setting >= 0)
546 twoints[1] |= (1<<i); 545 twoints[1] |= (1<<i);
547 } 546 }
548 547
549 if (copy_to_user((void __user *)arg, 548 if (copy_to_user((void __user *)arg,
550 (unsigned char *)twoints, 549 (unsigned char *)twoints,
551 sizeof(twoints))) { 550 sizeof(twoints))) {
552 retval = -EFAULT; 551 retval = -EFAULT;
553 goto done; 552 goto done;
554 } 553 }
555 554
556 break; 555 break;
557 556
558 case IOCNR_SET_PROTOCOL: 557 case IOCNR_SET_PROTOCOL:
559 if (_IOC_DIR(cmd) != _IOC_WRITE) { 558 if (_IOC_DIR(cmd) != _IOC_WRITE) {
560 retval = -EINVAL; 559 retval = -EINVAL;
561 goto done; 560 goto done;
562 } 561 }
563 562
564#ifdef DEBUG 563#ifdef DEBUG
565 if (arg == -10) { 564 if (arg == -10) {
566 usblp_dump(usblp); 565 usblp_dump(usblp);
567 break; 566 break;
568 } 567 }
569#endif 568#endif
570 569
571 usblp_unlink_urbs(usblp); 570 usblp_unlink_urbs(usblp);
572 retval = usblp_set_protocol(usblp, arg); 571 retval = usblp_set_protocol(usblp, arg);
573 if (retval < 0) { 572 if (retval < 0) {
574 usblp_set_protocol(usblp, 573 usblp_set_protocol(usblp,
575 usblp->current_protocol); 574 usblp->current_protocol);
576 } 575 }
577 break; 576 break;
578 577
579 case IOCNR_HP_SET_CHANNEL: 578 case IOCNR_HP_SET_CHANNEL:
580 if (_IOC_DIR(cmd) != _IOC_WRITE || 579 if (_IOC_DIR(cmd) != _IOC_WRITE ||
581 le16_to_cpu(usblp->dev->descriptor.idVendor) != 0x03F0 || 580 le16_to_cpu(usblp->dev->descriptor.idVendor) != 0x03F0 ||
582 usblp->quirks & USBLP_QUIRK_BIDIR) { 581 usblp->quirks & USBLP_QUIRK_BIDIR) {
583 retval = -EINVAL; 582 retval = -EINVAL;
584 goto done; 583 goto done;
585 } 584 }
586 585
587 err = usblp_hp_channel_change_request(usblp, 586 err = usblp_hp_channel_change_request(usblp,
588 arg, &newChannel); 587 arg, &newChannel);
589 if (err < 0) { 588 if (err < 0) {
590 dev_err(&usblp->dev->dev, 589 dev_err(&usblp->dev->dev,
591 "usblp%d: error = %d setting " 590 "usblp%d: error = %d setting "
592 "HP channel\n", 591 "HP channel\n",
593 usblp->minor, err); 592 usblp->minor, err);
594 retval = -EIO; 593 retval = -EIO;
595 goto done; 594 goto done;
596 } 595 }
597 596
598 dbg("usblp%d requested/got HP channel %ld/%d", 597 dbg("usblp%d requested/got HP channel %ld/%d",
599 usblp->minor, arg, newChannel); 598 usblp->minor, arg, newChannel);
600 break; 599 break;
601 600
602 case IOCNR_GET_BUS_ADDRESS: 601 case IOCNR_GET_BUS_ADDRESS:
603 if (_IOC_DIR(cmd) != _IOC_READ || 602 if (_IOC_DIR(cmd) != _IOC_READ ||
604 _IOC_SIZE(cmd) < sizeof(twoints)) { 603 _IOC_SIZE(cmd) < sizeof(twoints)) {
605 retval = -EINVAL; 604 retval = -EINVAL;
606 goto done; 605 goto done;
607 } 606 }
608 607
609 twoints[0] = usblp->dev->bus->busnum; 608 twoints[0] = usblp->dev->bus->busnum;
610 twoints[1] = usblp->dev->devnum; 609 twoints[1] = usblp->dev->devnum;
611 if (copy_to_user((void __user *)arg, 610 if (copy_to_user((void __user *)arg,
612 (unsigned char *)twoints, 611 (unsigned char *)twoints,
613 sizeof(twoints))) { 612 sizeof(twoints))) {
614 retval = -EFAULT; 613 retval = -EFAULT;
615 goto done; 614 goto done;
616 } 615 }
617 616
618 dbg("usblp%d is bus=%d, device=%d", 617 dbg("usblp%d is bus=%d, device=%d",
619 usblp->minor, twoints[0], twoints[1]); 618 usblp->minor, twoints[0], twoints[1]);
620 break; 619 break;
621 620
622 case IOCNR_GET_VID_PID: 621 case IOCNR_GET_VID_PID:
623 if (_IOC_DIR(cmd) != _IOC_READ || 622 if (_IOC_DIR(cmd) != _IOC_READ ||
624 _IOC_SIZE(cmd) < sizeof(twoints)) { 623 _IOC_SIZE(cmd) < sizeof(twoints)) {
625 retval = -EINVAL; 624 retval = -EINVAL;
626 goto done; 625 goto done;
627 } 626 }
628 627
629 twoints[0] = le16_to_cpu(usblp->dev->descriptor.idVendor); 628 twoints[0] = le16_to_cpu(usblp->dev->descriptor.idVendor);
630 twoints[1] = le16_to_cpu(usblp->dev->descriptor.idProduct); 629 twoints[1] = le16_to_cpu(usblp->dev->descriptor.idProduct);
631 if (copy_to_user((void __user *)arg, 630 if (copy_to_user((void __user *)arg,
632 (unsigned char *)twoints, 631 (unsigned char *)twoints,
633 sizeof(twoints))) { 632 sizeof(twoints))) {
634 retval = -EFAULT; 633 retval = -EFAULT;
635 goto done; 634 goto done;
636 } 635 }
637 636
638 dbg("usblp%d is VID=0x%4.4X, PID=0x%4.4X", 637 dbg("usblp%d is VID=0x%4.4X, PID=0x%4.4X",
639 usblp->minor, twoints[0], twoints[1]); 638 usblp->minor, twoints[0], twoints[1]);
640 break; 639 break;
641 640
642 case IOCNR_SOFT_RESET: 641 case IOCNR_SOFT_RESET:
643 if (_IOC_DIR(cmd) != _IOC_NONE) { 642 if (_IOC_DIR(cmd) != _IOC_NONE) {
644 retval = -EINVAL; 643 retval = -EINVAL;
645 goto done; 644 goto done;
646 } 645 }
647 retval = usblp_reset(usblp); 646 retval = usblp_reset(usblp);
648 break; 647 break;
649 default: 648 default:
650 retval = -ENOTTY; 649 retval = -ENOTTY;
651 } 650 }
652 else /* old-style ioctl value */ 651 else /* old-style ioctl value */
653 switch (cmd) { 652 switch (cmd) {
654 653
655 case LPGETSTATUS: 654 case LPGETSTATUS:
656 if ((retval = usblp_read_status(usblp, usblp->statusbuf))) { 655 if ((retval = usblp_read_status(usblp, usblp->statusbuf))) {
657 if (printk_ratelimit()) 656 if (printk_ratelimit())
658 printk(KERN_ERR "usblp%d:" 657 printk(KERN_ERR "usblp%d:"
659 "failed reading printer status (%d)\n", 658 "failed reading printer status (%d)\n",
660 usblp->minor, retval); 659 usblp->minor, retval);
661 retval = -EIO; 660 retval = -EIO;
662 goto done; 661 goto done;
663 } 662 }
664 status = *usblp->statusbuf; 663 status = *usblp->statusbuf;
665 if (copy_to_user ((void __user *)arg, &status, sizeof(int))) 664 if (copy_to_user((void __user *)arg, &status, sizeof(int)))
666 retval = -EFAULT; 665 retval = -EFAULT;
667 break; 666 break;
668 667
669 case LPABORT: 668 case LPABORT:
670 if (arg) 669 if (arg)
671 usblp->flags |= LP_ABORT; 670 usblp->flags |= LP_ABORT;
672 else 671 else
673 usblp->flags &= ~LP_ABORT; 672 usblp->flags &= ~LP_ABORT;
674 break; 673 break;
675 674
676 default: 675 default:
677 retval = -ENOTTY; 676 retval = -ENOTTY;
678 } 677 }
679 678
680done: 679done:
681 mutex_unlock (&usblp->mut); 680 mutex_unlock(&usblp->mut);
682 return retval; 681 return retval;
683} 682}
684 683
@@ -840,7 +839,7 @@ static ssize_t usblp_read(struct file *file, char __user *buffer, size_t len, lo
840 } 839 }
841 840
842done: 841done:
843 mutex_unlock (&usblp->mut); 842 mutex_unlock(&usblp->mut);
844 return count; 843 return count;
845} 844}
846 845
@@ -1023,7 +1022,7 @@ raise_urb:
1023 * while you are sending print data, and you don't try to query the 1022 * while you are sending print data, and you don't try to query the
1024 * printer status every couple of milliseconds, you will probably be OK. 1023 * printer status every couple of milliseconds, you will probably be OK.
1025 */ 1024 */
1026static unsigned int usblp_quirks (__u16 vendor, __u16 product) 1025static unsigned int usblp_quirks(__u16 vendor, __u16 product)
1027{ 1026{
1028 int i; 1027 int i;
1029 1028
@@ -1031,7 +1030,7 @@ static unsigned int usblp_quirks (__u16 vendor, __u16 product)
1031 if (vendor == quirk_printers[i].vendorId && 1030 if (vendor == quirk_printers[i].vendorId &&
1032 product == quirk_printers[i].productId) 1031 product == quirk_printers[i].productId)
1033 return quirk_printers[i].quirks; 1032 return quirk_printers[i].quirks;
1034 } 1033 }
1035 return 0; 1034 return 0;
1036} 1035}
1037 1036
@@ -1061,7 +1060,7 @@ static struct usb_class_driver usblp_class = {
1061static ssize_t usblp_show_ieee1284_id(struct device *dev, struct device_attribute *attr, char *buf) 1060static ssize_t usblp_show_ieee1284_id(struct device *dev, struct device_attribute *attr, char *buf)
1062{ 1061{
1063 struct usb_interface *intf = to_usb_interface(dev); 1062 struct usb_interface *intf = to_usb_interface(dev);
1064 struct usblp *usblp = usb_get_intfdata (intf); 1063 struct usblp *usblp = usb_get_intfdata(intf);
1065 1064
1066 if (usblp->device_id_string[0] == 0 && 1065 if (usblp->device_id_string[0] == 0 &&
1067 usblp->device_id_string[1] == 0) 1066 usblp->device_id_string[1] == 0)
@@ -1075,7 +1074,7 @@ static DEVICE_ATTR(ieee1284_id, S_IRUGO, usblp_show_ieee1284_id, NULL);
1075static int usblp_probe(struct usb_interface *intf, 1074static int usblp_probe(struct usb_interface *intf,
1076 const struct usb_device_id *id) 1075 const struct usb_device_id *id)
1077{ 1076{
1078 struct usb_device *dev = interface_to_usbdev (intf); 1077 struct usb_device *dev = interface_to_usbdev(intf);
1079 struct usblp *usblp; 1078 struct usblp *usblp;
1080 int protocol; 1079 int protocol;
1081 int retval; 1080 int retval;
@@ -1089,7 +1088,7 @@ static int usblp_probe(struct usb_interface *intf,
1089 } 1088 }
1090 usblp->dev = dev; 1089 usblp->dev = dev;
1091 mutex_init(&usblp->wmut); 1090 mutex_init(&usblp->wmut);
1092 mutex_init (&usblp->mut); 1091 mutex_init(&usblp->mut);
1093 spin_lock_init(&usblp->lock); 1092 spin_lock_init(&usblp->lock);
1094 init_waitqueue_head(&usblp->rwait); 1093 init_waitqueue_head(&usblp->rwait);
1095 init_waitqueue_head(&usblp->wwait); 1094 init_waitqueue_head(&usblp->wwait);
@@ -1153,7 +1152,7 @@ static int usblp_probe(struct usb_interface *intf,
1153 usblp_check_status(usblp, 0); 1152 usblp_check_status(usblp, 0);
1154#endif 1153#endif
1155 1154
1156 usb_set_intfdata (intf, usblp); 1155 usb_set_intfdata(intf, usblp);
1157 1156
1158 usblp->present = 1; 1157 usblp->present = 1;
1159 1158
@@ -1177,7 +1176,7 @@ static int usblp_probe(struct usb_interface *intf,
1177 return 0; 1176 return 0;
1178 1177
1179abort_intfdata: 1178abort_intfdata:
1180 usb_set_intfdata (intf, NULL); 1179 usb_set_intfdata(intf, NULL);
1181 device_remove_file(&intf->dev, &dev_attr_ieee1284_id); 1180 device_remove_file(&intf->dev, &dev_attr_ieee1284_id);
1182abort: 1181abort:
1183 kfree(usblp->readbuf); 1182 kfree(usblp->readbuf);
@@ -1340,35 +1339,35 @@ static int usblp_cache_device_id_string(struct usblp *usblp)
1340 1339
1341static void usblp_disconnect(struct usb_interface *intf) 1340static void usblp_disconnect(struct usb_interface *intf)
1342{ 1341{
1343 struct usblp *usblp = usb_get_intfdata (intf); 1342 struct usblp *usblp = usb_get_intfdata(intf);
1344 1343
1345 usb_deregister_dev(intf, &usblp_class); 1344 usb_deregister_dev(intf, &usblp_class);
1346 1345
1347 if (!usblp || !usblp->dev) { 1346 if (!usblp || !usblp->dev) {
1348 dev_err(&intf->dev, "bogus disconnect\n"); 1347 dev_err(&intf->dev, "bogus disconnect\n");
1349 BUG (); 1348 BUG();
1350 } 1349 }
1351 1350
1352 device_remove_file(&intf->dev, &dev_attr_ieee1284_id); 1351 device_remove_file(&intf->dev, &dev_attr_ieee1284_id);
1353 1352
1354 mutex_lock (&usblp_mutex); 1353 mutex_lock(&usblp_mutex);
1355 mutex_lock (&usblp->mut); 1354 mutex_lock(&usblp->mut);
1356 usblp->present = 0; 1355 usblp->present = 0;
1357 wake_up(&usblp->wwait); 1356 wake_up(&usblp->wwait);
1358 wake_up(&usblp->rwait); 1357 wake_up(&usblp->rwait);
1359 usb_set_intfdata (intf, NULL); 1358 usb_set_intfdata(intf, NULL);
1360 1359
1361 usblp_unlink_urbs(usblp); 1360 usblp_unlink_urbs(usblp);
1362 mutex_unlock (&usblp->mut); 1361 mutex_unlock(&usblp->mut);
1363 1362
1364 if (!usblp->used) 1363 if (!usblp->used)
1365 usblp_cleanup (usblp); 1364 usblp_cleanup(usblp);
1366 mutex_unlock (&usblp_mutex); 1365 mutex_unlock(&usblp_mutex);
1367} 1366}
1368 1367
1369static int usblp_suspend(struct usb_interface *intf, pm_message_t message) 1368static int usblp_suspend(struct usb_interface *intf, pm_message_t message)
1370{ 1369{
1371 struct usblp *usblp = usb_get_intfdata (intf); 1370 struct usblp *usblp = usb_get_intfdata(intf);
1372 1371
1373 usblp_unlink_urbs(usblp); 1372 usblp_unlink_urbs(usblp);
1374#if 0 /* XXX Do we want this? What if someone is reading, should we fail? */ 1373#if 0 /* XXX Do we want this? What if someone is reading, should we fail? */
@@ -1382,10 +1381,10 @@ static int usblp_suspend(struct usb_interface *intf, pm_message_t message)
1382 1381
1383static int usblp_resume(struct usb_interface *intf) 1382static int usblp_resume(struct usb_interface *intf)
1384{ 1383{
1385 struct usblp *usblp = usb_get_intfdata (intf); 1384 struct usblp *usblp = usb_get_intfdata(intf);
1386 int r; 1385 int r;
1387 1386
1388 r = handle_bidir (usblp); 1387 r = handle_bidir(usblp);
1389 1388
1390 return r; 1389 return r;
1391} 1390}
@@ -1401,7 +1400,7 @@ static const struct usb_device_id usblp_ids[] = {
1401 { } /* Terminating entry */ 1400 { } /* Terminating entry */
1402}; 1401};
1403 1402
1404MODULE_DEVICE_TABLE (usb, usblp_ids); 1403MODULE_DEVICE_TABLE(usb, usblp_ids);
1405 1404
1406static struct usb_driver usblp_driver = { 1405static struct usb_driver usblp_driver = {
1407 .name = "usblp", 1406 .name = "usblp",
@@ -1426,8 +1425,8 @@ static void __exit usblp_exit(void)
1426module_init(usblp_init); 1425module_init(usblp_init);
1427module_exit(usblp_exit); 1426module_exit(usblp_exit);
1428 1427
1429MODULE_AUTHOR( DRIVER_AUTHOR ); 1428MODULE_AUTHOR(DRIVER_AUTHOR);
1430MODULE_DESCRIPTION( DRIVER_DESC ); 1429MODULE_DESCRIPTION(DRIVER_DESC);
1431module_param(proto_bias, int, S_IRUGO | S_IWUSR); 1430module_param(proto_bias, int, S_IRUGO | S_IWUSR);
1432MODULE_PARM_DESC(proto_bias, "Favourite protocol number"); 1431MODULE_PARM_DESC(proto_bias, "Favourite protocol number");
1433MODULE_LICENSE("GPL"); 1432MODULE_LICENSE("GPL");
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index c2f62a3993d2..f1aaff6202a5 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -1668,13 +1668,10 @@ static int proc_ioctl(struct dev_state *ps, struct usbdevfs_ioctl *ctl)
1668 default: 1668 default:
1669 if (intf->dev.driver) 1669 if (intf->dev.driver)
1670 driver = to_usb_driver(intf->dev.driver); 1670 driver = to_usb_driver(intf->dev.driver);
1671 if (driver == NULL || driver->ioctl == NULL) { 1671 if (driver == NULL || driver->unlocked_ioctl == NULL) {
1672 retval = -ENOTTY; 1672 retval = -ENOTTY;
1673 } else { 1673 } else {
1674 /* keep API that guarantees BKL */ 1674 retval = driver->unlocked_ioctl(intf, ctl->ioctl_code, buf);
1675 lock_kernel();
1676 retval = driver->ioctl(intf, ctl->ioctl_code, buf);
1677 unlock_kernel();
1678 if (retval == -ENOIOCTLCMD) 1675 if (retval == -ENOIOCTLCMD)
1679 retval = -ENOTTY; 1676 retval = -ENOTTY;
1680 } 1677 }
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index a6bd53ace035..d7a4401ef019 100644
--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -1742,9 +1742,8 @@ static int usb_runtime_suspend(struct device *dev)
1742 } 1742 }
1743 1743
1744 /* Prevent the parent from suspending immediately after */ 1744 /* Prevent the parent from suspending immediately after */
1745 else if (udev->parent) { 1745 else if (udev->parent)
1746 udev->parent->last_busy = jiffies; 1746 udev->parent->last_busy = jiffies;
1747 }
1748 } 1747 }
1749 1748
1750 /* Runtime suspend for a USB interface doesn't mean anything. */ 1749 /* Runtime suspend for a USB interface doesn't mean anything. */
@@ -1786,21 +1785,19 @@ static int usb_runtime_idle(struct device *dev)
1786 return 0; 1785 return 0;
1787} 1786}
1788 1787
1789static struct dev_pm_ops usb_bus_pm_ops = { 1788static const struct dev_pm_ops usb_bus_pm_ops = {
1790 .runtime_suspend = usb_runtime_suspend, 1789 .runtime_suspend = usb_runtime_suspend,
1791 .runtime_resume = usb_runtime_resume, 1790 .runtime_resume = usb_runtime_resume,
1792 .runtime_idle = usb_runtime_idle, 1791 .runtime_idle = usb_runtime_idle,
1793}; 1792};
1794 1793
1795#else
1796
1797#define usb_bus_pm_ops (*(struct dev_pm_ops *) NULL)
1798
1799#endif /* CONFIG_USB_SUSPEND */ 1794#endif /* CONFIG_USB_SUSPEND */
1800 1795
1801struct bus_type usb_bus_type = { 1796struct bus_type usb_bus_type = {
1802 .name = "usb", 1797 .name = "usb",
1803 .match = usb_device_match, 1798 .match = usb_device_match,
1804 .uevent = usb_uevent, 1799 .uevent = usb_uevent,
1800#ifdef CONFIG_USB_SUSPEND
1805 .pm = &usb_bus_pm_ops, 1801 .pm = &usb_bus_pm_ops,
1802#endif
1806}; 1803};
diff --git a/drivers/usb/core/endpoint.c b/drivers/usb/core/endpoint.c
index 4f84a41ee7a8..3788e738e265 100644
--- a/drivers/usb/core/endpoint.c
+++ b/drivers/usb/core/endpoint.c
@@ -96,16 +96,21 @@ static ssize_t show_ep_interval(struct device *dev,
96 96
97 switch (usb_endpoint_type(ep->desc)) { 97 switch (usb_endpoint_type(ep->desc)) {
98 case USB_ENDPOINT_XFER_CONTROL: 98 case USB_ENDPOINT_XFER_CONTROL:
99 if (ep->udev->speed == USB_SPEED_HIGH) /* uframes per NAK */ 99 if (ep->udev->speed == USB_SPEED_HIGH)
100 /* uframes per NAK */
100 interval = ep->desc->bInterval; 101 interval = ep->desc->bInterval;
101 break; 102 break;
103
102 case USB_ENDPOINT_XFER_ISOC: 104 case USB_ENDPOINT_XFER_ISOC:
103 interval = 1 << (ep->desc->bInterval - 1); 105 interval = 1 << (ep->desc->bInterval - 1);
104 break; 106 break;
107
105 case USB_ENDPOINT_XFER_BULK: 108 case USB_ENDPOINT_XFER_BULK:
106 if (ep->udev->speed == USB_SPEED_HIGH && !in) /* uframes per NAK */ 109 if (ep->udev->speed == USB_SPEED_HIGH && !in)
110 /* uframes per NAK */
107 interval = ep->desc->bInterval; 111 interval = ep->desc->bInterval;
108 break; 112 break;
113
109 case USB_ENDPOINT_XFER_INT: 114 case USB_ENDPOINT_XFER_INT:
110 if (ep->udev->speed == USB_SPEED_HIGH) 115 if (ep->udev->speed == USB_SPEED_HIGH)
111 interval = 1 << (ep->desc->bInterval - 1); 116 interval = 1 << (ep->desc->bInterval - 1);
diff --git a/drivers/usb/core/generic.c b/drivers/usb/core/generic.c
index 9a34ccb0a1c0..69ecd3c92311 100644
--- a/drivers/usb/core/generic.c
+++ b/drivers/usb/core/generic.c
@@ -105,8 +105,10 @@ int usb_choose_configuration(struct usb_device *udev)
105 /* When the first config's first interface is one of Microsoft's 105 /* When the first config's first interface is one of Microsoft's
106 * pet nonstandard Ethernet-over-USB protocols, ignore it unless 106 * pet nonstandard Ethernet-over-USB protocols, ignore it unless
107 * this kernel has enabled the necessary host side driver. 107 * this kernel has enabled the necessary host side driver.
108 * But: Don't ignore it if it's the only config.
108 */ 109 */
109 if (i == 0 && desc && (is_rndis(desc) || is_activesync(desc))) { 110 if (i == 0 && num_configs > 1 && desc &&
111 (is_rndis(desc) || is_activesync(desc))) {
110#if !defined(CONFIG_USB_NET_RNDIS_HOST) && !defined(CONFIG_USB_NET_RNDIS_HOST_MODULE) 112#if !defined(CONFIG_USB_NET_RNDIS_HOST) && !defined(CONFIG_USB_NET_RNDIS_HOST_MODULE)
111 continue; 113 continue;
112#else 114#else
diff --git a/drivers/usb/core/hcd-pci.c b/drivers/usb/core/hcd-pci.c
index 1cf2d1e79a5c..c3f98543caaf 100644
--- a/drivers/usb/core/hcd-pci.c
+++ b/drivers/usb/core/hcd-pci.c
@@ -66,10 +66,7 @@ static void companion_common(struct pci_dev *pdev, struct usb_hcd *hcd,
66 * vice versa. 66 * vice versa.
67 */ 67 */
68 companion = NULL; 68 companion = NULL;
69 for (;;) { 69 for_each_pci_dev(companion) {
70 companion = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, companion);
71 if (!companion)
72 break;
73 if (companion->bus != pdev->bus || 70 if (companion->bus != pdev->bus ||
74 PCI_SLOT(companion->devfn) != slot) 71 PCI_SLOT(companion->devfn) != slot)
75 continue; 72 continue;
@@ -250,6 +247,9 @@ int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
250 if (retval != 0) 247 if (retval != 0)
251 goto err4; 248 goto err4;
252 set_hs_companion(dev, hcd); 249 set_hs_companion(dev, hcd);
250
251 if (pci_dev_run_wake(dev))
252 pm_runtime_put_noidle(&dev->dev);
253 return retval; 253 return retval;
254 254
255 err4: 255 err4:
@@ -292,6 +292,17 @@ void usb_hcd_pci_remove(struct pci_dev *dev)
292 if (!hcd) 292 if (!hcd)
293 return; 293 return;
294 294
295 if (pci_dev_run_wake(dev))
296 pm_runtime_get_noresume(&dev->dev);
297
298 /* Fake an interrupt request in order to give the driver a chance
299 * to test whether the controller hardware has been removed (e.g.,
300 * cardbus physical eject).
301 */
302 local_irq_disable();
303 usb_hcd_irq(0, hcd);
304 local_irq_enable();
305
295 usb_remove_hcd(hcd); 306 usb_remove_hcd(hcd);
296 if (hcd->driver->flags & HCD_MEMORY) { 307 if (hcd->driver->flags & HCD_MEMORY) {
297 iounmap(hcd->regs); 308 iounmap(hcd->regs);
@@ -317,12 +328,34 @@ void usb_hcd_pci_shutdown(struct pci_dev *dev)
317 if (!hcd) 328 if (!hcd)
318 return; 329 return;
319 330
320 if (hcd->driver->shutdown) 331 if (test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags) &&
332 hcd->driver->shutdown)
321 hcd->driver->shutdown(hcd); 333 hcd->driver->shutdown(hcd);
322} 334}
323EXPORT_SYMBOL_GPL(usb_hcd_pci_shutdown); 335EXPORT_SYMBOL_GPL(usb_hcd_pci_shutdown);
324 336
325#ifdef CONFIG_PM_SLEEP 337#ifdef CONFIG_PM_OPS
338
339#ifdef CONFIG_PPC_PMAC
340static void powermac_set_asic(struct pci_dev *pci_dev, int enable)
341{
342 /* Enanble or disable ASIC clocks for USB */
343 if (machine_is(powermac)) {
344 struct device_node *of_node;
345
346 of_node = pci_device_to_OF_node(pci_dev);
347 if (of_node)
348 pmac_call_feature(PMAC_FTR_USB_ENABLE,
349 of_node, 0, enable);
350 }
351}
352
353#else
354
355static inline void powermac_set_asic(struct pci_dev *pci_dev, int enable)
356{}
357
358#endif /* CONFIG_PPC_PMAC */
326 359
327static int check_root_hub_suspended(struct device *dev) 360static int check_root_hub_suspended(struct device *dev)
328{ 361{
@@ -337,7 +370,7 @@ static int check_root_hub_suspended(struct device *dev)
337 return 0; 370 return 0;
338} 371}
339 372
340static int hcd_pci_suspend(struct device *dev) 373static int suspend_common(struct device *dev, bool do_wakeup)
341{ 374{
342 struct pci_dev *pci_dev = to_pci_dev(dev); 375 struct pci_dev *pci_dev = to_pci_dev(dev);
343 struct usb_hcd *hcd = pci_get_drvdata(pci_dev); 376 struct usb_hcd *hcd = pci_get_drvdata(pci_dev);
@@ -352,13 +385,21 @@ static int hcd_pci_suspend(struct device *dev)
352 if (retval) 385 if (retval)
353 return retval; 386 return retval;
354 387
355 /* We might already be suspended (runtime PM -- not yet written) */
356 if (pci_dev->current_state != PCI_D0)
357 return retval;
358
359 if (hcd->driver->pci_suspend) { 388 if (hcd->driver->pci_suspend) {
360 retval = hcd->driver->pci_suspend(hcd); 389 /* Optimization: Don't suspend if a root-hub wakeup is
390 * pending and it would cause the HCD to wake up anyway.
391 */
392 if (do_wakeup && HCD_WAKEUP_PENDING(hcd))
393 return -EBUSY;
394 retval = hcd->driver->pci_suspend(hcd, do_wakeup);
361 suspend_report_result(hcd->driver->pci_suspend, retval); 395 suspend_report_result(hcd->driver->pci_suspend, retval);
396
397 /* Check again in case wakeup raced with pci_suspend */
398 if (retval == 0 && do_wakeup && HCD_WAKEUP_PENDING(hcd)) {
399 if (hcd->driver->pci_resume)
400 hcd->driver->pci_resume(hcd, false);
401 retval = -EBUSY;
402 }
362 if (retval) 403 if (retval)
363 return retval; 404 return retval;
364 } 405 }
@@ -374,6 +415,48 @@ static int hcd_pci_suspend(struct device *dev)
374 return retval; 415 return retval;
375} 416}
376 417
418static int resume_common(struct device *dev, int event)
419{
420 struct pci_dev *pci_dev = to_pci_dev(dev);
421 struct usb_hcd *hcd = pci_get_drvdata(pci_dev);
422 int retval;
423
424 if (hcd->state != HC_STATE_SUSPENDED) {
425 dev_dbg(dev, "can't resume, not suspended!\n");
426 return 0;
427 }
428
429 retval = pci_enable_device(pci_dev);
430 if (retval < 0) {
431 dev_err(dev, "can't re-enable after resume, %d!\n", retval);
432 return retval;
433 }
434
435 pci_set_master(pci_dev);
436
437 clear_bit(HCD_FLAG_SAW_IRQ, &hcd->flags);
438
439 if (hcd->driver->pci_resume) {
440 if (event != PM_EVENT_AUTO_RESUME)
441 wait_for_companions(pci_dev, hcd);
442
443 retval = hcd->driver->pci_resume(hcd,
444 event == PM_EVENT_RESTORE);
445 if (retval) {
446 dev_err(dev, "PCI post-resume error %d!\n", retval);
447 usb_hc_died(hcd);
448 }
449 }
450 return retval;
451}
452
453#ifdef CONFIG_PM_SLEEP
454
455static int hcd_pci_suspend(struct device *dev)
456{
457 return suspend_common(dev, device_may_wakeup(dev));
458}
459
377static int hcd_pci_suspend_noirq(struct device *dev) 460static int hcd_pci_suspend_noirq(struct device *dev)
378{ 461{
379 struct pci_dev *pci_dev = to_pci_dev(dev); 462 struct pci_dev *pci_dev = to_pci_dev(dev);
@@ -408,16 +491,7 @@ static int hcd_pci_suspend_noirq(struct device *dev)
408 return retval; 491 return retval;
409 } 492 }
410 493
411#ifdef CONFIG_PPC_PMAC 494 powermac_set_asic(pci_dev, 0);
412 /* Disable ASIC clocks for USB */
413 if (machine_is(powermac)) {
414 struct device_node *of_node;
415
416 of_node = pci_device_to_OF_node(pci_dev);
417 if (of_node)
418 pmac_call_feature(PMAC_FTR_USB_ENABLE, of_node, 0, 0);
419 }
420#endif
421 return retval; 495 return retval;
422} 496}
423 497
@@ -425,69 +499,63 @@ static int hcd_pci_resume_noirq(struct device *dev)
425{ 499{
426 struct pci_dev *pci_dev = to_pci_dev(dev); 500 struct pci_dev *pci_dev = to_pci_dev(dev);
427 501
428#ifdef CONFIG_PPC_PMAC 502 powermac_set_asic(pci_dev, 1);
429 /* Reenable ASIC clocks for USB */
430 if (machine_is(powermac)) {
431 struct device_node *of_node;
432
433 of_node = pci_device_to_OF_node(pci_dev);
434 if (of_node)
435 pmac_call_feature(PMAC_FTR_USB_ENABLE,
436 of_node, 0, 1);
437 }
438#endif
439 503
440 /* Go back to D0 and disable remote wakeup */ 504 /* Go back to D0 and disable remote wakeup */
441 pci_back_from_sleep(pci_dev); 505 pci_back_from_sleep(pci_dev);
442 return 0; 506 return 0;
443} 507}
444 508
445static int resume_common(struct device *dev, bool hibernated) 509static int hcd_pci_resume(struct device *dev)
446{ 510{
447 struct pci_dev *pci_dev = to_pci_dev(dev); 511 return resume_common(dev, PM_EVENT_RESUME);
448 struct usb_hcd *hcd = pci_get_drvdata(pci_dev); 512}
449 int retval;
450 513
451 if (hcd->state != HC_STATE_SUSPENDED) { 514static int hcd_pci_restore(struct device *dev)
452 dev_dbg(dev, "can't resume, not suspended!\n"); 515{
453 return 0; 516 return resume_common(dev, PM_EVENT_RESTORE);
454 } 517}
455 518
456 retval = pci_enable_device(pci_dev); 519#else
457 if (retval < 0) {
458 dev_err(dev, "can't re-enable after resume, %d!\n", retval);
459 return retval;
460 }
461 520
462 pci_set_master(pci_dev); 521#define hcd_pci_suspend NULL
522#define hcd_pci_suspend_noirq NULL
523#define hcd_pci_resume_noirq NULL
524#define hcd_pci_resume NULL
525#define hcd_pci_restore NULL
463 526
464 clear_bit(HCD_FLAG_SAW_IRQ, &hcd->flags); 527#endif /* CONFIG_PM_SLEEP */
465 528
466 if (hcd->driver->pci_resume) { 529#ifdef CONFIG_PM_RUNTIME
467 /* This call should be made only during system resume,
468 * not during runtime resume.
469 */
470 wait_for_companions(pci_dev, hcd);
471 530
472 retval = hcd->driver->pci_resume(hcd, hibernated); 531static int hcd_pci_runtime_suspend(struct device *dev)
473 if (retval) { 532{
474 dev_err(dev, "PCI post-resume error %d!\n", retval); 533 int retval;
475 usb_hc_died(hcd); 534
476 } 535 retval = suspend_common(dev, true);
477 } 536 if (retval == 0)
537 powermac_set_asic(to_pci_dev(dev), 0);
538 dev_dbg(dev, "hcd_pci_runtime_suspend: %d\n", retval);
478 return retval; 539 return retval;
479} 540}
480 541
481static int hcd_pci_resume(struct device *dev) 542static int hcd_pci_runtime_resume(struct device *dev)
482{ 543{
483 return resume_common(dev, false); 544 int retval;
484}
485 545
486static int hcd_pci_restore(struct device *dev) 546 powermac_set_asic(to_pci_dev(dev), 1);
487{ 547 retval = resume_common(dev, PM_EVENT_AUTO_RESUME);
488 return resume_common(dev, true); 548 dev_dbg(dev, "hcd_pci_runtime_resume: %d\n", retval);
549 return retval;
489} 550}
490 551
552#else
553
554#define hcd_pci_runtime_suspend NULL
555#define hcd_pci_runtime_resume NULL
556
557#endif /* CONFIG_PM_RUNTIME */
558
491const struct dev_pm_ops usb_hcd_pci_pm_ops = { 559const struct dev_pm_ops usb_hcd_pci_pm_ops = {
492 .suspend = hcd_pci_suspend, 560 .suspend = hcd_pci_suspend,
493 .suspend_noirq = hcd_pci_suspend_noirq, 561 .suspend_noirq = hcd_pci_suspend_noirq,
@@ -501,7 +569,9 @@ const struct dev_pm_ops usb_hcd_pci_pm_ops = {
501 .poweroff_noirq = hcd_pci_suspend_noirq, 569 .poweroff_noirq = hcd_pci_suspend_noirq,
502 .restore_noirq = hcd_pci_resume_noirq, 570 .restore_noirq = hcd_pci_resume_noirq,
503 .restore = hcd_pci_restore, 571 .restore = hcd_pci_restore,
572 .runtime_suspend = hcd_pci_runtime_suspend,
573 .runtime_resume = hcd_pci_runtime_resume,
504}; 574};
505EXPORT_SYMBOL_GPL(usb_hcd_pci_pm_ops); 575EXPORT_SYMBOL_GPL(usb_hcd_pci_pm_ops);
506 576
507#endif /* CONFIG_PM_SLEEP */ 577#endif /* CONFIG_PM_OPS */
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 12742f152f43..5cca00a6d09d 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -667,7 +667,7 @@ void usb_hcd_poll_rh_status(struct usb_hcd *hcd)
667 unsigned long flags; 667 unsigned long flags;
668 char buffer[6]; /* Any root hubs with > 31 ports? */ 668 char buffer[6]; /* Any root hubs with > 31 ports? */
669 669
670 if (unlikely(!hcd->rh_registered)) 670 if (unlikely(!hcd->rh_pollable))
671 return; 671 return;
672 if (!hcd->uses_new_polling && !hcd->status_urb) 672 if (!hcd->uses_new_polling && !hcd->status_urb)
673 return; 673 return;
@@ -679,7 +679,7 @@ void usb_hcd_poll_rh_status(struct usb_hcd *hcd)
679 spin_lock_irqsave(&hcd_root_hub_lock, flags); 679 spin_lock_irqsave(&hcd_root_hub_lock, flags);
680 urb = hcd->status_urb; 680 urb = hcd->status_urb;
681 if (urb) { 681 if (urb) {
682 hcd->poll_pending = 0; 682 clear_bit(HCD_FLAG_POLL_PENDING, &hcd->flags);
683 hcd->status_urb = NULL; 683 hcd->status_urb = NULL;
684 urb->actual_length = length; 684 urb->actual_length = length;
685 memcpy(urb->transfer_buffer, buffer, length); 685 memcpy(urb->transfer_buffer, buffer, length);
@@ -690,7 +690,7 @@ void usb_hcd_poll_rh_status(struct usb_hcd *hcd)
690 spin_lock(&hcd_root_hub_lock); 690 spin_lock(&hcd_root_hub_lock);
691 } else { 691 } else {
692 length = 0; 692 length = 0;
693 hcd->poll_pending = 1; 693 set_bit(HCD_FLAG_POLL_PENDING, &hcd->flags);
694 } 694 }
695 spin_unlock_irqrestore(&hcd_root_hub_lock, flags); 695 spin_unlock_irqrestore(&hcd_root_hub_lock, flags);
696 } 696 }
@@ -699,7 +699,7 @@ void usb_hcd_poll_rh_status(struct usb_hcd *hcd)
699 * exceed that limit if HZ is 100. The math is more clunky than 699 * exceed that limit if HZ is 100. The math is more clunky than
700 * maybe expected, this is to make sure that all timers for USB devices 700 * maybe expected, this is to make sure that all timers for USB devices
701 * fire at the same time to give the CPU a break inbetween */ 701 * fire at the same time to give the CPU a break inbetween */
702 if (hcd->uses_new_polling ? hcd->poll_rh : 702 if (hcd->uses_new_polling ? HCD_POLL_RH(hcd) :
703 (length == 0 && hcd->status_urb != NULL)) 703 (length == 0 && hcd->status_urb != NULL))
704 mod_timer (&hcd->rh_timer, (jiffies/(HZ/4) + 1) * (HZ/4)); 704 mod_timer (&hcd->rh_timer, (jiffies/(HZ/4) + 1) * (HZ/4));
705} 705}
@@ -736,7 +736,7 @@ static int rh_queue_status (struct usb_hcd *hcd, struct urb *urb)
736 mod_timer(&hcd->rh_timer, (jiffies/(HZ/4) + 1) * (HZ/4)); 736 mod_timer(&hcd->rh_timer, (jiffies/(HZ/4) + 1) * (HZ/4));
737 737
738 /* If a status change has already occurred, report it ASAP */ 738 /* If a status change has already occurred, report it ASAP */
739 else if (hcd->poll_pending) 739 else if (HCD_POLL_PENDING(hcd))
740 mod_timer(&hcd->rh_timer, jiffies); 740 mod_timer(&hcd->rh_timer, jiffies);
741 retval = 0; 741 retval = 0;
742 done: 742 done:
@@ -1150,8 +1150,7 @@ int usb_hcd_check_unlink_urb(struct usb_hcd *hcd, struct urb *urb,
1150 * finish unlinking the initial failed usb_set_address() 1150 * finish unlinking the initial failed usb_set_address()
1151 * or device descriptor fetch. 1151 * or device descriptor fetch.
1152 */ 1152 */
1153 if (!test_bit(HCD_FLAG_SAW_IRQ, &hcd->flags) && 1153 if (!HCD_SAW_IRQ(hcd) && !is_root_hub(urb->dev)) {
1154 !is_root_hub(urb->dev)) {
1155 dev_warn(hcd->self.controller, "Unlink after no-IRQ? " 1154 dev_warn(hcd->self.controller, "Unlink after no-IRQ? "
1156 "Controller is probably using the wrong IRQ.\n"); 1155 "Controller is probably using the wrong IRQ.\n");
1157 set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags); 1156 set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags);
@@ -1219,6 +1218,11 @@ static int hcd_alloc_coherent(struct usb_bus *bus,
1219{ 1218{
1220 unsigned char *vaddr; 1219 unsigned char *vaddr;
1221 1220
1221 if (*vaddr_handle == NULL) {
1222 WARN_ON_ONCE(1);
1223 return -EFAULT;
1224 }
1225
1222 vaddr = hcd_buffer_alloc(bus, size + sizeof(vaddr), 1226 vaddr = hcd_buffer_alloc(bus, size + sizeof(vaddr),
1223 mem_flags, dma_handle); 1227 mem_flags, dma_handle);
1224 if (!vaddr) 1228 if (!vaddr)
@@ -1941,6 +1945,7 @@ int hcd_bus_resume(struct usb_device *rhdev, pm_message_t msg)
1941 1945
1942 dev_dbg(&rhdev->dev, "usb %s%s\n", 1946 dev_dbg(&rhdev->dev, "usb %s%s\n",
1943 (msg.event & PM_EVENT_AUTO ? "auto-" : ""), "resume"); 1947 (msg.event & PM_EVENT_AUTO ? "auto-" : ""), "resume");
1948 clear_bit(HCD_FLAG_WAKEUP_PENDING, &hcd->flags);
1944 if (!hcd->driver->bus_resume) 1949 if (!hcd->driver->bus_resume)
1945 return -ENOENT; 1950 return -ENOENT;
1946 if (hcd->state == HC_STATE_RUNNING) 1951 if (hcd->state == HC_STATE_RUNNING)
@@ -1994,8 +1999,10 @@ void usb_hcd_resume_root_hub (struct usb_hcd *hcd)
1994 unsigned long flags; 1999 unsigned long flags;
1995 2000
1996 spin_lock_irqsave (&hcd_root_hub_lock, flags); 2001 spin_lock_irqsave (&hcd_root_hub_lock, flags);
1997 if (hcd->rh_registered) 2002 if (hcd->rh_registered) {
2003 set_bit(HCD_FLAG_WAKEUP_PENDING, &hcd->flags);
1998 queue_work(pm_wq, &hcd->wakeup_work); 2004 queue_work(pm_wq, &hcd->wakeup_work);
2005 }
1999 spin_unlock_irqrestore (&hcd_root_hub_lock, flags); 2006 spin_unlock_irqrestore (&hcd_root_hub_lock, flags);
2000} 2007}
2001EXPORT_SYMBOL_GPL(usb_hcd_resume_root_hub); 2008EXPORT_SYMBOL_GPL(usb_hcd_resume_root_hub);
@@ -2063,8 +2070,7 @@ irqreturn_t usb_hcd_irq (int irq, void *__hcd)
2063 */ 2070 */
2064 local_irq_save(flags); 2071 local_irq_save(flags);
2065 2072
2066 if (unlikely(hcd->state == HC_STATE_HALT || 2073 if (unlikely(hcd->state == HC_STATE_HALT || !HCD_HW_ACCESSIBLE(hcd))) {
2067 !test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags))) {
2068 rc = IRQ_NONE; 2074 rc = IRQ_NONE;
2069 } else if (hcd->driver->irq(hcd) == IRQ_NONE) { 2075 } else if (hcd->driver->irq(hcd) == IRQ_NONE) {
2070 rc = IRQ_NONE; 2076 rc = IRQ_NONE;
@@ -2079,6 +2085,7 @@ irqreturn_t usb_hcd_irq (int irq, void *__hcd)
2079 local_irq_restore(flags); 2085 local_irq_restore(flags);
2080 return rc; 2086 return rc;
2081} 2087}
2088EXPORT_SYMBOL_GPL(usb_hcd_irq);
2082 2089
2083/*-------------------------------------------------------------------------*/ 2090/*-------------------------------------------------------------------------*/
2084 2091
@@ -2098,7 +2105,7 @@ void usb_hc_died (struct usb_hcd *hcd)
2098 2105
2099 spin_lock_irqsave (&hcd_root_hub_lock, flags); 2106 spin_lock_irqsave (&hcd_root_hub_lock, flags);
2100 if (hcd->rh_registered) { 2107 if (hcd->rh_registered) {
2101 hcd->poll_rh = 0; 2108 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
2102 2109
2103 /* make khubd clean up old urbs and devices */ 2110 /* make khubd clean up old urbs and devices */
2104 usb_set_device_state (hcd->self.root_hub, 2111 usb_set_device_state (hcd->self.root_hub,
@@ -2217,6 +2224,7 @@ int usb_add_hcd(struct usb_hcd *hcd,
2217 retval = -ENOMEM; 2224 retval = -ENOMEM;
2218 goto err_allocate_root_hub; 2225 goto err_allocate_root_hub;
2219 } 2226 }
2227 hcd->self.root_hub = rhdev;
2220 2228
2221 switch (hcd->driver->flags & HCD_MASK) { 2229 switch (hcd->driver->flags & HCD_MASK) {
2222 case HCD_USB11: 2230 case HCD_USB11:
@@ -2229,9 +2237,8 @@ int usb_add_hcd(struct usb_hcd *hcd,
2229 rhdev->speed = USB_SPEED_SUPER; 2237 rhdev->speed = USB_SPEED_SUPER;
2230 break; 2238 break;
2231 default: 2239 default:
2232 goto err_allocate_root_hub; 2240 goto err_set_rh_speed;
2233 } 2241 }
2234 hcd->self.root_hub = rhdev;
2235 2242
2236 /* wakeup flag init defaults to "everything works" for root hubs, 2243 /* wakeup flag init defaults to "everything works" for root hubs,
2237 * but drivers can override it in reset() if needed, along with 2244 * but drivers can override it in reset() if needed, along with
@@ -2246,6 +2253,7 @@ int usb_add_hcd(struct usb_hcd *hcd,
2246 dev_err(hcd->self.controller, "can't setup\n"); 2253 dev_err(hcd->self.controller, "can't setup\n");
2247 goto err_hcd_driver_setup; 2254 goto err_hcd_driver_setup;
2248 } 2255 }
2256 hcd->rh_pollable = 1;
2249 2257
2250 /* NOTE: root hub and controller capabilities may not be the same */ 2258 /* NOTE: root hub and controller capabilities may not be the same */
2251 if (device_can_wakeup(hcd->self.controller) 2259 if (device_can_wakeup(hcd->self.controller)
@@ -2300,23 +2308,38 @@ int usb_add_hcd(struct usb_hcd *hcd,
2300 retval); 2308 retval);
2301 goto error_create_attr_group; 2309 goto error_create_attr_group;
2302 } 2310 }
2303 if (hcd->uses_new_polling && hcd->poll_rh) 2311 if (hcd->uses_new_polling && HCD_POLL_RH(hcd))
2304 usb_hcd_poll_rh_status(hcd); 2312 usb_hcd_poll_rh_status(hcd);
2305 return retval; 2313 return retval;
2306 2314
2307error_create_attr_group: 2315error_create_attr_group:
2316 if (HC_IS_RUNNING(hcd->state))
2317 hcd->state = HC_STATE_QUIESCING;
2318 spin_lock_irq(&hcd_root_hub_lock);
2319 hcd->rh_registered = 0;
2320 spin_unlock_irq(&hcd_root_hub_lock);
2321
2322#ifdef CONFIG_USB_SUSPEND
2323 cancel_work_sync(&hcd->wakeup_work);
2324#endif
2308 mutex_lock(&usb_bus_list_lock); 2325 mutex_lock(&usb_bus_list_lock);
2309 usb_disconnect(&hcd->self.root_hub); 2326 usb_disconnect(&rhdev); /* Sets rhdev to NULL */
2310 mutex_unlock(&usb_bus_list_lock); 2327 mutex_unlock(&usb_bus_list_lock);
2311err_register_root_hub: 2328err_register_root_hub:
2329 hcd->rh_pollable = 0;
2330 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
2331 del_timer_sync(&hcd->rh_timer);
2312 hcd->driver->stop(hcd); 2332 hcd->driver->stop(hcd);
2333 hcd->state = HC_STATE_HALT;
2334 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
2335 del_timer_sync(&hcd->rh_timer);
2313err_hcd_driver_start: 2336err_hcd_driver_start:
2314 if (hcd->irq >= 0) 2337 if (hcd->irq >= 0)
2315 free_irq(irqnum, hcd); 2338 free_irq(irqnum, hcd);
2316err_request_irq: 2339err_request_irq:
2317err_hcd_driver_setup: 2340err_hcd_driver_setup:
2318 hcd->self.root_hub = NULL; 2341err_set_rh_speed:
2319 usb_put_dev(rhdev); 2342 usb_put_dev(hcd->self.root_hub);
2320err_allocate_root_hub: 2343err_allocate_root_hub:
2321 usb_deregister_bus(&hcd->self); 2344 usb_deregister_bus(&hcd->self);
2322err_register_bus: 2345err_register_bus:
@@ -2335,8 +2358,13 @@ EXPORT_SYMBOL_GPL(usb_add_hcd);
2335 */ 2358 */
2336void usb_remove_hcd(struct usb_hcd *hcd) 2359void usb_remove_hcd(struct usb_hcd *hcd)
2337{ 2360{
2361 struct usb_device *rhdev = hcd->self.root_hub;
2362
2338 dev_info(hcd->self.controller, "remove, state %x\n", hcd->state); 2363 dev_info(hcd->self.controller, "remove, state %x\n", hcd->state);
2339 2364
2365 usb_get_dev(rhdev);
2366 sysfs_remove_group(&rhdev->dev.kobj, &usb_bus_attr_group);
2367
2340 if (HC_IS_RUNNING (hcd->state)) 2368 if (HC_IS_RUNNING (hcd->state))
2341 hcd->state = HC_STATE_QUIESCING; 2369 hcd->state = HC_STATE_QUIESCING;
2342 2370
@@ -2349,19 +2377,30 @@ void usb_remove_hcd(struct usb_hcd *hcd)
2349 cancel_work_sync(&hcd->wakeup_work); 2377 cancel_work_sync(&hcd->wakeup_work);
2350#endif 2378#endif
2351 2379
2352 sysfs_remove_group(&hcd->self.root_hub->dev.kobj, &usb_bus_attr_group);
2353 mutex_lock(&usb_bus_list_lock); 2380 mutex_lock(&usb_bus_list_lock);
2354 usb_disconnect(&hcd->self.root_hub); 2381 usb_disconnect(&rhdev); /* Sets rhdev to NULL */
2355 mutex_unlock(&usb_bus_list_lock); 2382 mutex_unlock(&usb_bus_list_lock);
2356 2383
2384 /* Prevent any more root-hub status calls from the timer.
2385 * The HCD might still restart the timer (if a port status change
2386 * interrupt occurs), but usb_hcd_poll_rh_status() won't invoke
2387 * the hub_status_data() callback.
2388 */
2389 hcd->rh_pollable = 0;
2390 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
2391 del_timer_sync(&hcd->rh_timer);
2392
2357 hcd->driver->stop(hcd); 2393 hcd->driver->stop(hcd);
2358 hcd->state = HC_STATE_HALT; 2394 hcd->state = HC_STATE_HALT;
2359 2395
2360 hcd->poll_rh = 0; 2396 /* In case the HCD restarted the timer, stop it again. */
2397 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
2361 del_timer_sync(&hcd->rh_timer); 2398 del_timer_sync(&hcd->rh_timer);
2362 2399
2363 if (hcd->irq >= 0) 2400 if (hcd->irq >= 0)
2364 free_irq(hcd->irq, hcd); 2401 free_irq(hcd->irq, hcd);
2402
2403 usb_put_dev(hcd->self.root_hub);
2365 usb_deregister_bus(&hcd->self); 2404 usb_deregister_bus(&hcd->self);
2366 hcd_buffer_destroy(hcd); 2405 hcd_buffer_destroy(hcd);
2367} 2406}
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 70cccc75a362..84c1897188d2 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -20,6 +20,7 @@
20#include <linux/usb.h> 20#include <linux/usb.h>
21#include <linux/usbdevice_fs.h> 21#include <linux/usbdevice_fs.h>
22#include <linux/usb/hcd.h> 22#include <linux/usb/hcd.h>
23#include <linux/usb/quirks.h>
23#include <linux/kthread.h> 24#include <linux/kthread.h>
24#include <linux/mutex.h> 25#include <linux/mutex.h>
25#include <linux/freezer.h> 26#include <linux/freezer.h>
@@ -1294,6 +1295,7 @@ descriptor_error:
1294 return -ENODEV; 1295 return -ENODEV;
1295} 1296}
1296 1297
1298/* No BKL needed */
1297static int 1299static int
1298hub_ioctl(struct usb_interface *intf, unsigned int code, void *user_data) 1300hub_ioctl(struct usb_interface *intf, unsigned int code, void *user_data)
1299{ 1301{
@@ -1801,7 +1803,6 @@ int usb_new_device(struct usb_device *udev)
1801 pm_runtime_set_active(&udev->dev); 1803 pm_runtime_set_active(&udev->dev);
1802 pm_runtime_enable(&udev->dev); 1804 pm_runtime_enable(&udev->dev);
1803 1805
1804 usb_detect_quirks(udev);
1805 err = usb_enumerate_device(udev); /* Read descriptors */ 1806 err = usb_enumerate_device(udev); /* Read descriptors */
1806 if (err < 0) 1807 if (err < 0)
1807 goto fail; 1808 goto fail;
@@ -2880,7 +2881,9 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
2880 } 2881 }
2881 2882
2882 retval = 0; 2883 retval = 0;
2883 2884 /* notify HCD that we have a device connected and addressed */
2885 if (hcd->driver->update_device)
2886 hcd->driver->update_device(hcd, udev);
2884fail: 2887fail:
2885 if (retval) { 2888 if (retval) {
2886 hub_port_disable(hub, port1, 0); 2889 hub_port_disable(hub, port1, 0);
@@ -3111,6 +3114,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
3111 if (status < 0) 3114 if (status < 0)
3112 goto loop; 3115 goto loop;
3113 3116
3117 usb_detect_quirks(udev);
3118 if (udev->quirks & USB_QUIRK_DELAY_INIT)
3119 msleep(1000);
3120
3114 /* consecutive bus-powered hubs aren't reliable; they can 3121 /* consecutive bus-powered hubs aren't reliable; they can
3115 * violate the voltage drop budget. if the new child has 3122 * violate the voltage drop budget. if the new child has
3116 * a "powered" LED, users should notice we didn't enable it 3123 * a "powered" LED, users should notice we didn't enable it
@@ -3463,7 +3470,7 @@ static struct usb_driver hub_driver = {
3463 .reset_resume = hub_reset_resume, 3470 .reset_resume = hub_reset_resume,
3464 .pre_reset = hub_pre_reset, 3471 .pre_reset = hub_pre_reset,
3465 .post_reset = hub_post_reset, 3472 .post_reset = hub_post_reset,
3466 .ioctl = hub_ioctl, 3473 .unlocked_ioctl = hub_ioctl,
3467 .id_table = hub_id_table, 3474 .id_table = hub_id_table,
3468 .supports_autosuspend = 1, 3475 .supports_autosuspend = 1,
3469}; 3476};
diff --git a/drivers/usb/core/inode.c b/drivers/usb/core/inode.c
index 1a27618b67d6..095fa5366690 100644
--- a/drivers/usb/core/inode.c
+++ b/drivers/usb/core/inode.c
@@ -265,13 +265,9 @@ static int remount(struct super_block *sb, int *flags, char *data)
265 return -EINVAL; 265 return -EINVAL;
266 } 266 }
267 267
268 lock_kernel();
269
270 if (usbfs_mount && usbfs_mount->mnt_sb) 268 if (usbfs_mount && usbfs_mount->mnt_sb)
271 update_sb(usbfs_mount->mnt_sb); 269 update_sb(usbfs_mount->mnt_sb);
272 270
273 unlock_kernel();
274
275 return 0; 271 return 0;
276} 272}
277 273
diff --git a/drivers/usb/core/quirks.c b/drivers/usb/core/quirks.c
index db99c084df92..25719da45e33 100644
--- a/drivers/usb/core/quirks.c
+++ b/drivers/usb/core/quirks.c
@@ -38,6 +38,9 @@ static const struct usb_device_id usb_quirk_list[] = {
38 /* Creative SB Audigy 2 NX */ 38 /* Creative SB Audigy 2 NX */
39 { USB_DEVICE(0x041e, 0x3020), .driver_info = USB_QUIRK_RESET_RESUME }, 39 { USB_DEVICE(0x041e, 0x3020), .driver_info = USB_QUIRK_RESET_RESUME },
40 40
41 /* Logitech Harmony 700-series */
42 { USB_DEVICE(0x046d, 0xc122), .driver_info = USB_QUIRK_DELAY_INIT },
43
41 /* Philips PSC805 audio device */ 44 /* Philips PSC805 audio device */
42 { USB_DEVICE(0x0471, 0x0155), .driver_info = USB_QUIRK_RESET_RESUME }, 45 { USB_DEVICE(0x0471, 0x0155), .driver_info = USB_QUIRK_RESET_RESUME },
43 46
diff --git a/drivers/usb/core/urb.c b/drivers/usb/core/urb.c
index 7c0555548ac8..419e6b34e2fe 100644
--- a/drivers/usb/core/urb.c
+++ b/drivers/usb/core/urb.c
@@ -137,6 +137,16 @@ void usb_anchor_urb(struct urb *urb, struct usb_anchor *anchor)
137} 137}
138EXPORT_SYMBOL_GPL(usb_anchor_urb); 138EXPORT_SYMBOL_GPL(usb_anchor_urb);
139 139
140/* Callers must hold anchor->lock */
141static void __usb_unanchor_urb(struct urb *urb, struct usb_anchor *anchor)
142{
143 urb->anchor = NULL;
144 list_del(&urb->anchor_list);
145 usb_put_urb(urb);
146 if (list_empty(&anchor->urb_list))
147 wake_up(&anchor->wait);
148}
149
140/** 150/**
141 * usb_unanchor_urb - unanchors an URB 151 * usb_unanchor_urb - unanchors an URB
142 * @urb: pointer to the urb to anchor 152 * @urb: pointer to the urb to anchor
@@ -156,17 +166,14 @@ void usb_unanchor_urb(struct urb *urb)
156 return; 166 return;
157 167
158 spin_lock_irqsave(&anchor->lock, flags); 168 spin_lock_irqsave(&anchor->lock, flags);
159 if (unlikely(anchor != urb->anchor)) { 169 /*
160 /* we've lost the race to another thread */ 170 * At this point, we could be competing with another thread which
161 spin_unlock_irqrestore(&anchor->lock, flags); 171 * has the same intention. To protect the urb from being unanchored
162 return; 172 * twice, only the winner of the race gets the job.
163 } 173 */
164 urb->anchor = NULL; 174 if (likely(anchor == urb->anchor))
165 list_del(&urb->anchor_list); 175 __usb_unanchor_urb(urb, anchor);
166 spin_unlock_irqrestore(&anchor->lock, flags); 176 spin_unlock_irqrestore(&anchor->lock, flags);
167 usb_put_urb(urb);
168 if (list_empty(&anchor->urb_list))
169 wake_up(&anchor->wait);
170} 177}
171EXPORT_SYMBOL_GPL(usb_unanchor_urb); 178EXPORT_SYMBOL_GPL(usb_unanchor_urb);
172 179
@@ -749,20 +756,11 @@ EXPORT_SYMBOL_GPL(usb_unpoison_anchored_urbs);
749void usb_unlink_anchored_urbs(struct usb_anchor *anchor) 756void usb_unlink_anchored_urbs(struct usb_anchor *anchor)
750{ 757{
751 struct urb *victim; 758 struct urb *victim;
752 unsigned long flags;
753 759
754 spin_lock_irqsave(&anchor->lock, flags); 760 while ((victim = usb_get_from_anchor(anchor)) != NULL) {
755 while (!list_empty(&anchor->urb_list)) {
756 victim = list_entry(anchor->urb_list.prev, struct urb,
757 anchor_list);
758 usb_get_urb(victim);
759 spin_unlock_irqrestore(&anchor->lock, flags);
760 /* this will unanchor the URB */
761 usb_unlink_urb(victim); 761 usb_unlink_urb(victim);
762 usb_put_urb(victim); 762 usb_put_urb(victim);
763 spin_lock_irqsave(&anchor->lock, flags);
764 } 763 }
765 spin_unlock_irqrestore(&anchor->lock, flags);
766} 764}
767EXPORT_SYMBOL_GPL(usb_unlink_anchored_urbs); 765EXPORT_SYMBOL_GPL(usb_unlink_anchored_urbs);
768 766
@@ -799,12 +797,11 @@ struct urb *usb_get_from_anchor(struct usb_anchor *anchor)
799 victim = list_entry(anchor->urb_list.next, struct urb, 797 victim = list_entry(anchor->urb_list.next, struct urb,
800 anchor_list); 798 anchor_list);
801 usb_get_urb(victim); 799 usb_get_urb(victim);
802 spin_unlock_irqrestore(&anchor->lock, flags); 800 __usb_unanchor_urb(victim, anchor);
803 usb_unanchor_urb(victim);
804 } else { 801 } else {
805 spin_unlock_irqrestore(&anchor->lock, flags);
806 victim = NULL; 802 victim = NULL;
807 } 803 }
804 spin_unlock_irqrestore(&anchor->lock, flags);
808 805
809 return victim; 806 return victim;
810} 807}
@@ -826,12 +823,7 @@ void usb_scuttle_anchored_urbs(struct usb_anchor *anchor)
826 while (!list_empty(&anchor->urb_list)) { 823 while (!list_empty(&anchor->urb_list)) {
827 victim = list_entry(anchor->urb_list.prev, struct urb, 824 victim = list_entry(anchor->urb_list.prev, struct urb,
828 anchor_list); 825 anchor_list);
829 usb_get_urb(victim); 826 __usb_unanchor_urb(victim, anchor);
830 spin_unlock_irqrestore(&anchor->lock, flags);
831 /* this may free the URB */
832 usb_unanchor_urb(victim);
833 usb_put_urb(victim);
834 spin_lock_irqsave(&anchor->lock, flags);
835 } 827 }
836 spin_unlock_irqrestore(&anchor->lock, flags); 828 spin_unlock_irqrestore(&anchor->lock, flags);
837} 829}
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index 5ae14f6c1e7a..fdd4130fbb7d 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -317,10 +317,6 @@ static const struct dev_pm_ops usb_device_pm_ops = {
317 .restore = usb_dev_restore, 317 .restore = usb_dev_restore,
318}; 318};
319 319
320#else
321
322#define usb_device_pm_ops (*(struct dev_pm_ops *) NULL)
323
324#endif /* CONFIG_PM */ 320#endif /* CONFIG_PM */
325 321
326 322
@@ -338,7 +334,9 @@ struct device_type usb_device_type = {
338 .release = usb_release_dev, 334 .release = usb_release_dev,
339 .uevent = usb_dev_uevent, 335 .uevent = usb_dev_uevent,
340 .devnode = usb_devnode, 336 .devnode = usb_devnode,
337#ifdef CONFIG_PM
341 .pm = &usb_device_pm_ops, 338 .pm = &usb_device_pm_ops,
339#endif
342}; 340};
343 341
344 342
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 591ae9fde199..cd27f9bde2c8 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -714,6 +714,7 @@ config USB_GADGETFS
714config USB_FUNCTIONFS 714config USB_FUNCTIONFS
715 tristate "Function Filesystem (EXPERIMENTAL)" 715 tristate "Function Filesystem (EXPERIMENTAL)"
716 depends on EXPERIMENTAL 716 depends on EXPERIMENTAL
717 select USB_FUNCTIONFS_GENERIC if !(USB_FUNCTIONFS_ETH || USB_FUNCTIONFS_RNDIS)
717 help 718 help
718 The Function Filesystem (FunctioFS) lets one create USB 719 The Function Filesystem (FunctioFS) lets one create USB
719 composite functions in user space in the same way as GadgetFS 720 composite functions in user space in the same way as GadgetFS
@@ -722,31 +723,31 @@ config USB_FUNCTIONFS
722 implemented in kernel space (for instance Ethernet, serial or 723 implemented in kernel space (for instance Ethernet, serial or
723 mass storage) and other are implemented in user space. 724 mass storage) and other are implemented in user space.
724 725
726 If you say "y" or "m" here you will be able what kind of
727 configurations the gadget will provide.
728
725 Say "y" to link the driver statically, or "m" to build 729 Say "y" to link the driver statically, or "m" to build
726 a dynamically linked module called "g_ffs". 730 a dynamically linked module called "g_ffs".
727 731
728config USB_FUNCTIONFS_ETH 732config USB_FUNCTIONFS_ETH
729 bool "Include CDC ECM (Ethernet) function" 733 bool "Include configuration with CDC ECM (Ethernet)"
730 depends on USB_FUNCTIONFS && NET 734 depends on USB_FUNCTIONFS && NET
731 help 735 help
732 Include an CDC ECM (Ethernet) funcion in the CDC ECM (Funcion) 736 Include a configuration with CDC ECM funcion (Ethernet) and the
733 Filesystem. If you also say "y" to the RNDIS query below the 737 Funcion Filesystem.
734 gadget will have two configurations.
735 738
736config USB_FUNCTIONFS_RNDIS 739config USB_FUNCTIONFS_RNDIS
737 bool "Include RNDIS (Ethernet) function" 740 bool "Include configuration with RNDIS (Ethernet)"
738 depends on USB_FUNCTIONFS && NET 741 depends on USB_FUNCTIONFS && NET
739 help 742 help
740 Include an RNDIS (Ethernet) funcion in the Funcion Filesystem. 743 Include a configuration with RNDIS funcion (Ethernet) and the Filesystem.
741 If you also say "y" to the CDC ECM query above the gadget will
742 have two configurations.
743 744
744config USB_FUNCTIONFS_GENERIC 745config USB_FUNCTIONFS_GENERIC
745 bool "Include 'pure' configuration" 746 bool "Include 'pure' configuration"
746 depends on USB_FUNCTIONFS && (USB_FUNCTIONFS_ETH || USB_FUNCTIONFS_RNDIS) 747 depends on USB_FUNCTIONFS
747 help 748 help
748 Include a configuration with FunctionFS and no Ethernet 749 Include a configuration with the Function Filesystem alone with
749 configuration. 750 no Ethernet interface.
750 751
751config USB_FILE_STORAGE 752config USB_FILE_STORAGE
752 tristate "File-backed Storage Gadget" 753 tristate "File-backed Storage Gadget"
@@ -863,6 +864,7 @@ config USB_G_NOKIA
863config USB_G_MULTI 864config USB_G_MULTI
864 tristate "Multifunction Composite Gadget (EXPERIMENTAL)" 865 tristate "Multifunction Composite Gadget (EXPERIMENTAL)"
865 depends on BLOCK && NET 866 depends on BLOCK && NET
867 select USB_G_MULTI_CDC if !USB_G_MULTI_RNDIS
866 help 868 help
867 The Multifunction Composite Gadget provides Ethernet (RNDIS 869 The Multifunction Composite Gadget provides Ethernet (RNDIS
868 and/or CDC Ethernet), mass storage and ACM serial link 870 and/or CDC Ethernet), mass storage and ACM serial link
@@ -913,6 +915,34 @@ config USB_G_HID
913 Say "y" to link the driver statically, or "m" to build a 915 Say "y" to link the driver statically, or "m" to build a
914 dynamically linked module called "g_hid". 916 dynamically linked module called "g_hid".
915 917
918config USB_G_DBGP
919 tristate "EHCI Debug Device Gadget"
920 help
921 This gadget emulates an EHCI Debug device. This is useful when you want
922 to interact with an EHCI Debug Port.
923
924 Say "y" to link the driver statically, or "m" to build a
925 dynamically linked module called "g_dbgp".
926
927if USB_G_DBGP
928choice
929 prompt "EHCI Debug Device mode"
930 default USB_G_DBGP_SERIAL
931
932config USB_G_DBGP_PRINTK
933 depends on USB_G_DBGP
934 bool "printk"
935 help
936 Directly printk() received data. No interaction.
937
938config USB_G_DBGP_SERIAL
939 depends on USB_G_DBGP
940 bool "serial"
941 help
942 Userland can interact using /dev/ttyGSxxx.
943endchoice
944endif
945
916# put drivers that need isochronous transfer support (for audio 946# put drivers that need isochronous transfer support (for audio
917# or video class gadget drivers), or specific hardware, here. 947# or video class gadget drivers), or specific hardware, here.
918config USB_G_WEBCAM 948config USB_G_WEBCAM
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
index 9bcde110feb1..27283df37d09 100644
--- a/drivers/usb/gadget/Makefile
+++ b/drivers/usb/gadget/Makefile
@@ -44,6 +44,7 @@ g_printer-objs := printer.o
44g_cdc-objs := cdc2.o 44g_cdc-objs := cdc2.o
45g_multi-objs := multi.o 45g_multi-objs := multi.o
46g_hid-objs := hid.o 46g_hid-objs := hid.o
47g_dbgp-objs := dbgp.o
47g_nokia-objs := nokia.o 48g_nokia-objs := nokia.o
48g_webcam-objs := webcam.o 49g_webcam-objs := webcam.o
49 50
@@ -52,7 +53,6 @@ obj-$(CONFIG_USB_AUDIO) += g_audio.o
52obj-$(CONFIG_USB_ETH) += g_ether.o 53obj-$(CONFIG_USB_ETH) += g_ether.o
53obj-$(CONFIG_USB_GADGETFS) += gadgetfs.o 54obj-$(CONFIG_USB_GADGETFS) += gadgetfs.o
54obj-$(CONFIG_USB_FUNCTIONFS) += g_ffs.o 55obj-$(CONFIG_USB_FUNCTIONFS) += g_ffs.o
55obj-$(CONFIG_USB_ETH_FUNCTIONFS) += g_eth_ffs.o
56obj-$(CONFIG_USB_FILE_STORAGE) += g_file_storage.o 56obj-$(CONFIG_USB_FILE_STORAGE) += g_file_storage.o
57obj-$(CONFIG_USB_MASS_STORAGE) += g_mass_storage.o 57obj-$(CONFIG_USB_MASS_STORAGE) += g_mass_storage.o
58obj-$(CONFIG_USB_G_SERIAL) += g_serial.o 58obj-$(CONFIG_USB_G_SERIAL) += g_serial.o
@@ -60,6 +60,7 @@ obj-$(CONFIG_USB_G_PRINTER) += g_printer.o
60obj-$(CONFIG_USB_MIDI_GADGET) += g_midi.o 60obj-$(CONFIG_USB_MIDI_GADGET) += g_midi.o
61obj-$(CONFIG_USB_CDC_COMPOSITE) += g_cdc.o 61obj-$(CONFIG_USB_CDC_COMPOSITE) += g_cdc.o
62obj-$(CONFIG_USB_G_HID) += g_hid.o 62obj-$(CONFIG_USB_G_HID) += g_hid.o
63obj-$(CONFIG_USB_G_DBGP) += g_dbgp.o
63obj-$(CONFIG_USB_G_MULTI) += g_multi.o 64obj-$(CONFIG_USB_G_MULTI) += g_multi.o
64obj-$(CONFIG_USB_G_NOKIA) += g_nokia.o 65obj-$(CONFIG_USB_G_NOKIA) += g_nokia.o
65obj-$(CONFIG_USB_G_WEBCAM) += g_webcam.o 66obj-$(CONFIG_USB_G_WEBCAM) += g_webcam.o
diff --git a/drivers/usb/gadget/audio.c b/drivers/usb/gadget/audio.c
index a62af7b59094..b744ccd0f34d 100644
--- a/drivers/usb/gadget/audio.c
+++ b/drivers/usb/gadget/audio.c
@@ -89,7 +89,7 @@ static const struct usb_descriptor_header *otg_desc[] = {
89 89
90/*-------------------------------------------------------------------------*/ 90/*-------------------------------------------------------------------------*/
91 91
92static int __init audio_do_config(struct usb_configuration *c) 92static int __ref audio_do_config(struct usb_configuration *c)
93{ 93{
94 /* FIXME alloc iConfiguration string, set it in c->strings */ 94 /* FIXME alloc iConfiguration string, set it in c->strings */
95 95
@@ -113,7 +113,7 @@ static struct usb_configuration audio_config_driver = {
113 113
114/*-------------------------------------------------------------------------*/ 114/*-------------------------------------------------------------------------*/
115 115
116static int __init audio_bind(struct usb_composite_dev *cdev) 116static int __ref audio_bind(struct usb_composite_dev *cdev)
117{ 117{
118 int gcnum; 118 int gcnum;
119 int status; 119 int status;
diff --git a/drivers/usb/gadget/cdc2.c b/drivers/usb/gadget/cdc2.c
index 928137d3dbdc..1f5ba2fd4c1f 100644
--- a/drivers/usb/gadget/cdc2.c
+++ b/drivers/usb/gadget/cdc2.c
@@ -129,7 +129,7 @@ static u8 hostaddr[ETH_ALEN];
129/* 129/*
130 * We _always_ have both CDC ECM and CDC ACM functions. 130 * We _always_ have both CDC ECM and CDC ACM functions.
131 */ 131 */
132static int __init cdc_do_config(struct usb_configuration *c) 132static int __ref cdc_do_config(struct usb_configuration *c)
133{ 133{
134 int status; 134 int status;
135 135
@@ -159,7 +159,7 @@ static struct usb_configuration cdc_config_driver = {
159 159
160/*-------------------------------------------------------------------------*/ 160/*-------------------------------------------------------------------------*/
161 161
162static int __init cdc_bind(struct usb_composite_dev *cdev) 162static int __ref cdc_bind(struct usb_composite_dev *cdev)
163{ 163{
164 int gcnum; 164 int gcnum;
165 struct usb_gadget *gadget = cdev->gadget; 165 struct usb_gadget *gadget = cdev->gadget;
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 391d169f8d07..e483f80822d2 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -673,20 +673,83 @@ static int get_string(struct usb_composite_dev *cdev,
673 * string IDs. Drivers for functions, configurations, or gadgets will 673 * string IDs. Drivers for functions, configurations, or gadgets will
674 * then store that ID in the appropriate descriptors and string table. 674 * then store that ID in the appropriate descriptors and string table.
675 * 675 *
676 * All string identifier should be allocated using this routine, to 676 * All string identifier should be allocated using this,
677 * ensure that for example different functions don't wrongly assign 677 * @usb_string_ids_tab() or @usb_string_ids_n() routine, to ensure
678 * different meanings to the same identifier. 678 * that for example different functions don't wrongly assign different
679 * meanings to the same identifier.
679 */ 680 */
680int usb_string_id(struct usb_composite_dev *cdev) 681int usb_string_id(struct usb_composite_dev *cdev)
681{ 682{
682 if (cdev->next_string_id < 254) { 683 if (cdev->next_string_id < 254) {
683 /* string id 0 is reserved */ 684 /* string id 0 is reserved by USB spec for list of
685 * supported languages */
686 /* 255 reserved as well? -- mina86 */
684 cdev->next_string_id++; 687 cdev->next_string_id++;
685 return cdev->next_string_id; 688 return cdev->next_string_id;
686 } 689 }
687 return -ENODEV; 690 return -ENODEV;
688} 691}
689 692
693/**
694 * usb_string_ids() - allocate unused string IDs in batch
695 * @cdev: the device whose string descriptor IDs are being allocated
696 * @str: an array of usb_string objects to assign numbers to
697 * Context: single threaded during gadget setup
698 *
699 * @usb_string_ids() is called from bind() callbacks to allocate
700 * string IDs. Drivers for functions, configurations, or gadgets will
701 * then copy IDs from the string table to the appropriate descriptors
702 * and string table for other languages.
703 *
704 * All string identifier should be allocated using this,
705 * @usb_string_id() or @usb_string_ids_n() routine, to ensure that for
706 * example different functions don't wrongly assign different meanings
707 * to the same identifier.
708 */
709int usb_string_ids_tab(struct usb_composite_dev *cdev, struct usb_string *str)
710{
711 int next = cdev->next_string_id;
712
713 for (; str->s; ++str) {
714 if (unlikely(next >= 254))
715 return -ENODEV;
716 str->id = ++next;
717 }
718
719 cdev->next_string_id = next;
720
721 return 0;
722}
723
724/**
725 * usb_string_ids_n() - allocate unused string IDs in batch
726 * @cdev: the device whose string descriptor IDs are being allocated
727 * @n: number of string IDs to allocate
728 * Context: single threaded during gadget setup
729 *
730 * Returns the first requested ID. This ID and next @n-1 IDs are now
731 * valid IDs. At least providind that @n is non zore because if it
732 * is, returns last requested ID which is now very useful information.
733 *
734 * @usb_string_ids_n() is called from bind() callbacks to allocate
735 * string IDs. Drivers for functions, configurations, or gadgets will
736 * then store that ID in the appropriate descriptors and string table.
737 *
738 * All string identifier should be allocated using this,
739 * @usb_string_id() or @usb_string_ids_n() routine, to ensure that for
740 * example different functions don't wrongly assign different meanings
741 * to the same identifier.
742 */
743int usb_string_ids_n(struct usb_composite_dev *c, unsigned n)
744{
745 unsigned next = c->next_string_id;
746 if (unlikely(n > 254 || (unsigned)next + n > 254))
747 return -ENODEV;
748 c->next_string_id += n;
749 return next + 1;
750}
751
752
690/*-------------------------------------------------------------------------*/ 753/*-------------------------------------------------------------------------*/
691 754
692static void composite_setup_complete(struct usb_ep *ep, struct usb_request *req) 755static void composite_setup_complete(struct usb_ep *ep, struct usb_request *req)
@@ -893,6 +956,8 @@ static void composite_disconnect(struct usb_gadget *gadget)
893 spin_lock_irqsave(&cdev->lock, flags); 956 spin_lock_irqsave(&cdev->lock, flags);
894 if (cdev->config) 957 if (cdev->config)
895 reset_config(cdev); 958 reset_config(cdev);
959 if (composite->disconnect)
960 composite->disconnect(cdev);
896 spin_unlock_irqrestore(&cdev->lock, flags); 961 spin_unlock_irqrestore(&cdev->lock, flags);
897} 962}
898 963
diff --git a/drivers/usb/gadget/dbgp.c b/drivers/usb/gadget/dbgp.c
new file mode 100644
index 000000000000..0ed50a2c0a36
--- /dev/null
+++ b/drivers/usb/gadget/dbgp.c
@@ -0,0 +1,434 @@
1/*
2 * dbgp.c -- EHCI Debug Port device gadget
3 *
4 * Copyright (C) 2010 Stephane Duverger
5 *
6 * Released under the GPLv2.
7 *
8 */
9
10/* verbose messages */
11#include <linux/kernel.h>
12#include <linux/device.h>
13#include <linux/usb/ch9.h>
14#include <linux/usb/gadget.h>
15
16/* See comments in "zero.c" */
17#include "epautoconf.c"
18
19#ifdef CONFIG_USB_G_DBGP_SERIAL
20#include "u_serial.c"
21#endif
22
23#define DRIVER_VENDOR_ID 0x0525 /* NetChip */
24#define DRIVER_PRODUCT_ID 0xc0de /* undefined */
25
26#define USB_DEBUG_MAX_PACKET_SIZE 8
27#define DBGP_REQ_EP0_LEN 128
28#define DBGP_REQ_LEN 512
29
30static struct dbgp {
31 struct usb_gadget *gadget;
32 struct usb_request *req;
33 struct usb_ep *i_ep;
34 struct usb_ep *o_ep;
35#ifdef CONFIG_USB_G_DBGP_SERIAL
36 struct gserial *serial;
37#endif
38} dbgp;
39
40static struct usb_device_descriptor device_desc = {
41 .bLength = sizeof device_desc,
42 .bDescriptorType = USB_DT_DEVICE,
43 .bcdUSB = __constant_cpu_to_le16(0x0200),
44 .bDeviceClass = USB_CLASS_VENDOR_SPEC,
45 .idVendor = __constant_cpu_to_le16(DRIVER_VENDOR_ID),
46 .idProduct = __constant_cpu_to_le16(DRIVER_PRODUCT_ID),
47 .bNumConfigurations = 1,
48};
49
50static struct usb_debug_descriptor dbg_desc = {
51 .bLength = sizeof dbg_desc,
52 .bDescriptorType = USB_DT_DEBUG,
53};
54
55static struct usb_endpoint_descriptor i_desc = {
56 .bLength = USB_DT_ENDPOINT_SIZE,
57 .bDescriptorType = USB_DT_ENDPOINT,
58 .bmAttributes = USB_ENDPOINT_XFER_BULK,
59 .bEndpointAddress = USB_DIR_IN,
60};
61
62static struct usb_endpoint_descriptor o_desc = {
63 .bLength = USB_DT_ENDPOINT_SIZE,
64 .bDescriptorType = USB_DT_ENDPOINT,
65 .bmAttributes = USB_ENDPOINT_XFER_BULK,
66 .bEndpointAddress = USB_DIR_OUT,
67};
68
69#ifdef CONFIG_USB_G_DBGP_PRINTK
70static int dbgp_consume(char *buf, unsigned len)
71{
72 char c;
73
74 if (!len)
75 return 0;
76
77 c = buf[len-1];
78 if (c != 0)
79 buf[len-1] = 0;
80
81 printk(KERN_NOTICE "%s%c", buf, c);
82 return 0;
83}
84
85static void __disable_ep(struct usb_ep *ep)
86{
87 if (ep && ep->driver_data == dbgp.gadget) {
88 usb_ep_disable(ep);
89 ep->driver_data = NULL;
90 }
91}
92
93static void dbgp_disable_ep(void)
94{
95 __disable_ep(dbgp.i_ep);
96 __disable_ep(dbgp.o_ep);
97}
98
99static void dbgp_complete(struct usb_ep *ep, struct usb_request *req)
100{
101 int stp;
102 int err = 0;
103 int status = req->status;
104
105 if (ep == dbgp.i_ep) {
106 stp = 1;
107 goto fail;
108 }
109
110 if (status != 0) {
111 stp = 2;
112 goto release_req;
113 }
114
115 dbgp_consume(req->buf, req->actual);
116
117 req->length = DBGP_REQ_LEN;
118 err = usb_ep_queue(ep, req, GFP_ATOMIC);
119 if (err < 0) {
120 stp = 3;
121 goto release_req;
122 }
123
124 return;
125
126release_req:
127 kfree(req->buf);
128 usb_ep_free_request(dbgp.o_ep, req);
129 dbgp_disable_ep();
130fail:
131 dev_dbg(&dbgp.gadget->dev,
132 "complete: failure (%d:%d) ==> %d\n", stp, err, status);
133}
134
135static int dbgp_enable_ep_req(struct usb_ep *ep)
136{
137 int err, stp;
138 struct usb_request *req;
139
140 req = usb_ep_alloc_request(ep, GFP_KERNEL);
141 if (!req) {
142 err = -ENOMEM;
143 stp = 1;
144 goto fail_1;
145 }
146
147 req->buf = kmalloc(DBGP_REQ_LEN, GFP_KERNEL);
148 if (!req->buf) {
149 err = -ENOMEM;
150 stp = 2;
151 goto fail_2;
152 }
153
154 req->complete = dbgp_complete;
155 req->length = DBGP_REQ_LEN;
156 err = usb_ep_queue(ep, req, GFP_ATOMIC);
157 if (err < 0) {
158 stp = 3;
159 goto fail_3;
160 }
161
162 return 0;
163
164fail_3:
165 kfree(req->buf);
166fail_2:
167 usb_ep_free_request(dbgp.o_ep, req);
168fail_1:
169 dev_dbg(&dbgp.gadget->dev,
170 "enable ep req: failure (%d:%d)\n", stp, err);
171 return err;
172}
173
174static int __enable_ep(struct usb_ep *ep, struct usb_endpoint_descriptor *desc)
175{
176 int err = usb_ep_enable(ep, desc);
177 ep->driver_data = dbgp.gadget;
178 return err;
179}
180
181static int dbgp_enable_ep(void)
182{
183 int err, stp;
184
185 err = __enable_ep(dbgp.i_ep, &i_desc);
186 if (err < 0) {
187 stp = 1;
188 goto fail_1;
189 }
190
191 err = __enable_ep(dbgp.o_ep, &o_desc);
192 if (err < 0) {
193 stp = 2;
194 goto fail_2;
195 }
196
197 err = dbgp_enable_ep_req(dbgp.o_ep);
198 if (err < 0) {
199 stp = 3;
200 goto fail_3;
201 }
202
203 return 0;
204
205fail_3:
206 __disable_ep(dbgp.o_ep);
207fail_2:
208 __disable_ep(dbgp.i_ep);
209fail_1:
210 dev_dbg(&dbgp.gadget->dev, "enable ep: failure (%d:%d)\n", stp, err);
211 return err;
212}
213#endif
214
215static void dbgp_disconnect(struct usb_gadget *gadget)
216{
217#ifdef CONFIG_USB_G_DBGP_PRINTK
218 dbgp_disable_ep();
219#else
220 gserial_disconnect(dbgp.serial);
221#endif
222}
223
224static void dbgp_unbind(struct usb_gadget *gadget)
225{
226#ifdef CONFIG_USB_G_DBGP_SERIAL
227 kfree(dbgp.serial);
228#endif
229 if (dbgp.req) {
230 kfree(dbgp.req->buf);
231 usb_ep_free_request(gadget->ep0, dbgp.req);
232 }
233
234 gadget->ep0->driver_data = NULL;
235}
236
237static int __init dbgp_configure_endpoints(struct usb_gadget *gadget)
238{
239 int stp;
240
241 usb_ep_autoconfig_reset(gadget);
242
243 dbgp.i_ep = usb_ep_autoconfig(gadget, &i_desc);
244 if (!dbgp.i_ep) {
245 stp = 1;
246 goto fail_1;
247 }
248
249 dbgp.i_ep->driver_data = gadget;
250 i_desc.wMaxPacketSize =
251 __constant_cpu_to_le16(USB_DEBUG_MAX_PACKET_SIZE);
252
253 dbgp.o_ep = usb_ep_autoconfig(gadget, &o_desc);
254 if (!dbgp.o_ep) {
255 dbgp.i_ep->driver_data = NULL;
256 stp = 2;
257 goto fail_2;
258 }
259
260 dbgp.o_ep->driver_data = gadget;
261 o_desc.wMaxPacketSize =
262 __constant_cpu_to_le16(USB_DEBUG_MAX_PACKET_SIZE);
263
264 dbg_desc.bDebugInEndpoint = i_desc.bEndpointAddress & 0x7f;
265 dbg_desc.bDebugOutEndpoint = o_desc.bEndpointAddress & 0x7f;
266
267#ifdef CONFIG_USB_G_DBGP_SERIAL
268 dbgp.serial->in = dbgp.i_ep;
269 dbgp.serial->out = dbgp.o_ep;
270
271 dbgp.serial->in_desc = &i_desc;
272 dbgp.serial->out_desc = &o_desc;
273
274 if (gserial_setup(gadget, 1) < 0) {
275 stp = 3;
276 goto fail_3;
277 }
278
279 return 0;
280
281fail_3:
282 dbgp.o_ep->driver_data = NULL;
283#else
284 return 0;
285#endif
286fail_2:
287 dbgp.i_ep->driver_data = NULL;
288fail_1:
289 dev_dbg(&dbgp.gadget->dev, "ep config: failure (%d)\n", stp);
290 return -ENODEV;
291}
292
293static int __init dbgp_bind(struct usb_gadget *gadget)
294{
295 int err, stp;
296
297 dbgp.gadget = gadget;
298
299 dbgp.req = usb_ep_alloc_request(gadget->ep0, GFP_KERNEL);
300 if (!dbgp.req) {
301 err = -ENOMEM;
302 stp = 1;
303 goto fail;
304 }
305
306 dbgp.req->buf = kmalloc(DBGP_REQ_EP0_LEN, GFP_KERNEL);
307 if (!dbgp.req->buf) {
308 err = -ENOMEM;
309 stp = 2;
310 goto fail;
311 }
312
313 dbgp.req->length = DBGP_REQ_EP0_LEN;
314 gadget->ep0->driver_data = gadget;
315
316#ifdef CONFIG_USB_G_DBGP_SERIAL
317 dbgp.serial = kzalloc(sizeof(struct gserial), GFP_KERNEL);
318 if (!dbgp.serial) {
319 stp = 3;
320 err = -ENOMEM;
321 goto fail;
322 }
323#endif
324 err = dbgp_configure_endpoints(gadget);
325 if (err < 0) {
326 stp = 4;
327 goto fail;
328 }
329
330 dev_dbg(&dbgp.gadget->dev, "bind: success\n");
331 return 0;
332
333fail:
334 dev_dbg(&gadget->dev, "bind: failure (%d:%d)\n", stp, err);
335 dbgp_unbind(gadget);
336 return err;
337}
338
339static void dbgp_setup_complete(struct usb_ep *ep,
340 struct usb_request *req)
341{
342 dev_dbg(&dbgp.gadget->dev, "setup complete: %d, %d/%d\n",
343 req->status, req->actual, req->length);
344}
345
346static int dbgp_setup(struct usb_gadget *gadget,
347 const struct usb_ctrlrequest *ctrl)
348{
349 struct usb_request *req = dbgp.req;
350 u8 request = ctrl->bRequest;
351 u16 value = le16_to_cpu(ctrl->wValue);
352 u16 length = le16_to_cpu(ctrl->wLength);
353 int err = 0;
354 void *data;
355 u16 len;
356
357 gadget->ep0->driver_data = gadget;
358
359 if (request == USB_REQ_GET_DESCRIPTOR) {
360 switch (value>>8) {
361 case USB_DT_DEVICE:
362 dev_dbg(&dbgp.gadget->dev, "setup: desc device\n");
363 len = sizeof device_desc;
364 data = &device_desc;
365 break;
366 case USB_DT_DEBUG:
367 dev_dbg(&dbgp.gadget->dev, "setup: desc debug\n");
368 len = sizeof dbg_desc;
369 data = &dbg_desc;
370 break;
371 default:
372 goto fail;
373 }
374 } else if (request == USB_REQ_SET_FEATURE &&
375 value == USB_DEVICE_DEBUG_MODE) {
376 len = 0;
377 data = NULL;
378 dev_dbg(&dbgp.gadget->dev, "setup: feat debug\n");
379#ifdef CONFIG_USB_G_DBGP_PRINTK
380 err = dbgp_enable_ep();
381#else
382 err = gserial_connect(dbgp.serial, 0);
383#endif
384 if (err < 0)
385 goto fail;
386 } else
387 goto fail;
388
389 if (len >= 0) {
390 req->length = min(length, len);
391 req->zero = len < req->length;
392 if (data && req->length)
393 memcpy(req->buf, data, req->length);
394
395 req->complete = dbgp_setup_complete;
396 return usb_ep_queue(gadget->ep0, req, GFP_ATOMIC);
397 }
398
399fail:
400 dev_dbg(&dbgp.gadget->dev,
401 "setup: failure req %x v %x\n", request, value);
402 return err;
403}
404
405static struct usb_gadget_driver dbgp_driver = {
406 .function = "dbgp",
407 .speed = USB_SPEED_HIGH,
408 .bind = dbgp_bind,
409 .unbind = dbgp_unbind,
410 .setup = dbgp_setup,
411 .disconnect = dbgp_disconnect,
412 .driver = {
413 .owner = THIS_MODULE,
414 .name = "dbgp"
415 },
416};
417
418static int __init dbgp_init(void)
419{
420 return usb_gadget_register_driver(&dbgp_driver);
421}
422
423static void __exit dbgp_exit(void)
424{
425 usb_gadget_unregister_driver(&dbgp_driver);
426#ifdef CONFIG_USB_G_DBGP_SERIAL
427 gserial_cleanup();
428#endif
429}
430
431MODULE_AUTHOR("Stephane Duverger");
432MODULE_LICENSE("GPL");
433module_init(dbgp_init);
434module_exit(dbgp_exit);
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c
index 4f9e578cde9d..dc6546248ed9 100644
--- a/drivers/usb/gadget/dummy_hcd.c
+++ b/drivers/usb/gadget/dummy_hcd.c
@@ -1542,7 +1542,7 @@ static int dummy_hub_status (struct usb_hcd *hcd, char *buf)
1542 dum = hcd_to_dummy (hcd); 1542 dum = hcd_to_dummy (hcd);
1543 1543
1544 spin_lock_irqsave (&dum->lock, flags); 1544 spin_lock_irqsave (&dum->lock, flags);
1545 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) 1545 if (!HCD_HW_ACCESSIBLE(hcd))
1546 goto done; 1546 goto done;
1547 1547
1548 if (dum->resuming && time_after_eq (jiffies, dum->re_timeout)) { 1548 if (dum->resuming && time_after_eq (jiffies, dum->re_timeout)) {
@@ -1588,7 +1588,7 @@ static int dummy_hub_control (
1588 int retval = 0; 1588 int retval = 0;
1589 unsigned long flags; 1589 unsigned long flags;
1590 1590
1591 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) 1591 if (!HCD_HW_ACCESSIBLE(hcd))
1592 return -ETIMEDOUT; 1592 return -ETIMEDOUT;
1593 1593
1594 dum = hcd_to_dummy (hcd); 1594 dum = hcd_to_dummy (hcd);
@@ -1739,7 +1739,7 @@ static int dummy_bus_resume (struct usb_hcd *hcd)
1739 dev_dbg (&hcd->self.root_hub->dev, "%s\n", __func__); 1739 dev_dbg (&hcd->self.root_hub->dev, "%s\n", __func__);
1740 1740
1741 spin_lock_irq (&dum->lock); 1741 spin_lock_irq (&dum->lock);
1742 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) { 1742 if (!HCD_HW_ACCESSIBLE(hcd)) {
1743 rc = -ESHUTDOWN; 1743 rc = -ESHUTDOWN;
1744 } else { 1744 } else {
1745 dum->rh_state = DUMMY_RH_RUNNING; 1745 dum->rh_state = DUMMY_RH_RUNNING;
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index 400f80372d93..114fa024c22c 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -237,7 +237,7 @@ static u8 hostaddr[ETH_ALEN];
237 * the first one present. That's to make Microsoft's drivers happy, 237 * the first one present. That's to make Microsoft's drivers happy,
238 * and to follow DOCSIS 1.0 (cable modem standard). 238 * and to follow DOCSIS 1.0 (cable modem standard).
239 */ 239 */
240static int __init rndis_do_config(struct usb_configuration *c) 240static int __ref rndis_do_config(struct usb_configuration *c)
241{ 241{
242 /* FIXME alloc iConfiguration string, set it in c->strings */ 242 /* FIXME alloc iConfiguration string, set it in c->strings */
243 243
@@ -270,7 +270,7 @@ MODULE_PARM_DESC(use_eem, "use CDC EEM mode");
270/* 270/*
271 * We _always_ have an ECM, CDC Subset, or EEM configuration. 271 * We _always_ have an ECM, CDC Subset, or EEM configuration.
272 */ 272 */
273static int __init eth_do_config(struct usb_configuration *c) 273static int __ref eth_do_config(struct usb_configuration *c)
274{ 274{
275 /* FIXME alloc iConfiguration string, set it in c->strings */ 275 /* FIXME alloc iConfiguration string, set it in c->strings */
276 276
@@ -297,7 +297,7 @@ static struct usb_configuration eth_config_driver = {
297 297
298/*-------------------------------------------------------------------------*/ 298/*-------------------------------------------------------------------------*/
299 299
300static int __init eth_bind(struct usb_composite_dev *cdev) 300static int __ref eth_bind(struct usb_composite_dev *cdev)
301{ 301{
302 int gcnum; 302 int gcnum;
303 struct usb_gadget *gadget = cdev->gadget; 303 struct usb_gadget *gadget = cdev->gadget;
diff --git a/drivers/usb/gadget/f_fs.c b/drivers/usb/gadget/f_fs.c
index 2aaa0f75c6cf..e4f595055208 100644
--- a/drivers/usb/gadget/f_fs.c
+++ b/drivers/usb/gadget/f_fs.c
@@ -714,9 +714,7 @@ static long ffs_ep0_ioctl(struct file *file, unsigned code, unsigned long value)
714 struct ffs_function *func = ffs->func; 714 struct ffs_function *func = ffs->func;
715 ret = func ? ffs_func_revmap_intf(func, value) : -ENODEV; 715 ret = func ? ffs_func_revmap_intf(func, value) : -ENODEV;
716 } else if (gadget->ops->ioctl) { 716 } else if (gadget->ops->ioctl) {
717 lock_kernel();
718 ret = gadget->ops->ioctl(gadget, code, value); 717 ret = gadget->ops->ioctl(gadget, code, value);
719 unlock_kernel();
720 } else { 718 } else {
721 ret = -ENOTTY; 719 ret = -ENOTTY;
722 } 720 }
@@ -1377,7 +1375,8 @@ static void ffs_data_reset(struct ffs_data *ffs)
1377 1375
1378static int functionfs_bind(struct ffs_data *ffs, struct usb_composite_dev *cdev) 1376static int functionfs_bind(struct ffs_data *ffs, struct usb_composite_dev *cdev)
1379{ 1377{
1380 unsigned i, count; 1378 struct usb_gadget_strings **lang;
1379 int first_id;
1381 1380
1382 ENTER(); 1381 ENTER();
1383 1382
@@ -1385,7 +1384,9 @@ static int functionfs_bind(struct ffs_data *ffs, struct usb_composite_dev *cdev)
1385 || test_and_set_bit(FFS_FL_BOUND, &ffs->flags))) 1384 || test_and_set_bit(FFS_FL_BOUND, &ffs->flags)))
1386 return -EBADFD; 1385 return -EBADFD;
1387 1386
1388 ffs_data_get(ffs); 1387 first_id = usb_string_ids_n(cdev, ffs->strings_count);
1388 if (unlikely(first_id < 0))
1389 return first_id;
1389 1390
1390 ffs->ep0req = usb_ep_alloc_request(cdev->gadget->ep0, GFP_KERNEL); 1391 ffs->ep0req = usb_ep_alloc_request(cdev->gadget->ep0, GFP_KERNEL);
1391 if (unlikely(!ffs->ep0req)) 1392 if (unlikely(!ffs->ep0req))
@@ -1393,25 +1394,16 @@ static int functionfs_bind(struct ffs_data *ffs, struct usb_composite_dev *cdev)
1393 ffs->ep0req->complete = ffs_ep0_complete; 1394 ffs->ep0req->complete = ffs_ep0_complete;
1394 ffs->ep0req->context = ffs; 1395 ffs->ep0req->context = ffs;
1395 1396
1396 /* Get strings identifiers */ 1397 lang = ffs->stringtabs;
1397 for (count = ffs->strings_count, i = 0; i < count; ++i) { 1398 for (lang = ffs->stringtabs; *lang; ++lang) {
1398 struct usb_gadget_strings **lang; 1399 struct usb_string *str = (*lang)->strings;
1399 1400 int id = first_id;
1400 int id = usb_string_id(cdev); 1401 for (; str->s; ++id, ++str)
1401 if (unlikely(id < 0)) { 1402 str->id = id;
1402 usb_ep_free_request(cdev->gadget->ep0, ffs->ep0req);
1403 ffs->ep0req = NULL;
1404 return id;
1405 }
1406
1407 lang = ffs->stringtabs;
1408 do {
1409 (*lang)->strings[i].id = id;
1410 ++lang;
1411 } while (*lang);
1412 } 1403 }
1413 1404
1414 ffs->gadget = cdev->gadget; 1405 ffs->gadget = cdev->gadget;
1406 ffs_data_get(ffs);
1415 return 0; 1407 return 0;
1416} 1408}
1417 1409
@@ -1480,9 +1472,9 @@ static void ffs_epfiles_destroy(struct ffs_epfile *epfiles, unsigned count)
1480} 1472}
1481 1473
1482 1474
1483static int functionfs_add(struct usb_composite_dev *cdev, 1475static int functionfs_bind_config(struct usb_composite_dev *cdev,
1484 struct usb_configuration *c, 1476 struct usb_configuration *c,
1485 struct ffs_data *ffs) 1477 struct ffs_data *ffs)
1486{ 1478{
1487 struct ffs_function *func; 1479 struct ffs_function *func;
1488 int ret; 1480 int ret;
diff --git a/drivers/usb/gadget/f_hid.c b/drivers/usb/gadget/f_hid.c
index 1e00ff9866af..53e120208e99 100644
--- a/drivers/usb/gadget/f_hid.c
+++ b/drivers/usb/gadget/f_hid.c
@@ -142,7 +142,7 @@ static struct usb_descriptor_header *hidg_fs_descriptors[] = {
142static ssize_t f_hidg_read(struct file *file, char __user *buffer, 142static ssize_t f_hidg_read(struct file *file, char __user *buffer,
143 size_t count, loff_t *ptr) 143 size_t count, loff_t *ptr)
144{ 144{
145 struct f_hidg *hidg = (struct f_hidg *)file->private_data; 145 struct f_hidg *hidg = file->private_data;
146 char *tmp_buff = NULL; 146 char *tmp_buff = NULL;
147 unsigned long flags; 147 unsigned long flags;
148 148
@@ -200,7 +200,7 @@ static void f_hidg_req_complete(struct usb_ep *ep, struct usb_request *req)
200static ssize_t f_hidg_write(struct file *file, const char __user *buffer, 200static ssize_t f_hidg_write(struct file *file, const char __user *buffer,
201 size_t count, loff_t *offp) 201 size_t count, loff_t *offp)
202{ 202{
203 struct f_hidg *hidg = (struct f_hidg *)file->private_data; 203 struct f_hidg *hidg = file->private_data;
204 ssize_t status = -ENOMEM; 204 ssize_t status = -ENOMEM;
205 205
206 if (!access_ok(VERIFY_READ, buffer, count)) 206 if (!access_ok(VERIFY_READ, buffer, count))
@@ -257,7 +257,7 @@ static ssize_t f_hidg_write(struct file *file, const char __user *buffer,
257 257
258static unsigned int f_hidg_poll(struct file *file, poll_table *wait) 258static unsigned int f_hidg_poll(struct file *file, poll_table *wait)
259{ 259{
260 struct f_hidg *hidg = (struct f_hidg *)file->private_data; 260 struct f_hidg *hidg = file->private_data;
261 unsigned int ret = 0; 261 unsigned int ret = 0;
262 262
263 poll_wait(file, &hidg->read_queue, wait); 263 poll_wait(file, &hidg->read_queue, wait);
diff --git a/drivers/usb/gadget/f_loopback.c b/drivers/usb/gadget/f_loopback.c
index e91d1b16d9be..43225879c3cd 100644
--- a/drivers/usb/gadget/f_loopback.c
+++ b/drivers/usb/gadget/f_loopback.c
@@ -324,7 +324,7 @@ static void loopback_disable(struct usb_function *f)
324 324
325/*-------------------------------------------------------------------------*/ 325/*-------------------------------------------------------------------------*/
326 326
327static int __init loopback_bind_config(struct usb_configuration *c) 327static int __ref loopback_bind_config(struct usb_configuration *c)
328{ 328{
329 struct f_loopback *loop; 329 struct f_loopback *loop;
330 int status; 330 int status;
@@ -346,7 +346,7 @@ static int __init loopback_bind_config(struct usb_configuration *c)
346 return status; 346 return status;
347} 347}
348 348
349static struct usb_configuration loopback_driver = { 349static struct usb_configuration loopback_driver = {
350 .label = "loopback", 350 .label = "loopback",
351 .strings = loopback_strings, 351 .strings = loopback_strings,
352 .bind = loopback_bind_config, 352 .bind = loopback_bind_config,
diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c
index 4ce899c9b165..32cce029f65c 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -316,6 +316,27 @@ static const char fsg_string_interface[] = "Mass Storage";
316/*-------------------------------------------------------------------------*/ 316/*-------------------------------------------------------------------------*/
317 317
318struct fsg_dev; 318struct fsg_dev;
319struct fsg_common;
320
321/* FSF callback functions */
322struct fsg_operations {
323 /* Callback function to call when thread exits. If no
324 * callback is set or it returns value lower then zero MSF
325 * will force eject all LUNs it operates on (including those
326 * marked as non-removable or with prevent_medium_removal flag
327 * set). */
328 int (*thread_exits)(struct fsg_common *common);
329
330 /* Called prior to ejection. Negative return means error,
331 * zero means to continue with ejection, positive means not to
332 * eject. */
333 int (*pre_eject)(struct fsg_common *common,
334 struct fsg_lun *lun, int num);
335 /* Called after ejection. Negative return means error, zero
336 * or positive is just a success. */
337 int (*post_eject)(struct fsg_common *common,
338 struct fsg_lun *lun, int num);
339};
319 340
320 341
321/* Data shared by all the FSG instances. */ 342/* Data shared by all the FSG instances. */
@@ -333,7 +354,6 @@ struct fsg_common {
333 struct usb_ep *ep0; /* Copy of gadget->ep0 */ 354 struct usb_ep *ep0; /* Copy of gadget->ep0 */
334 struct usb_request *ep0req; /* Copy of cdev->req */ 355 struct usb_request *ep0req; /* Copy of cdev->req */
335 unsigned int ep0_req_tag; 356 unsigned int ep0_req_tag;
336 const char *ep0req_name;
337 357
338 struct fsg_buffhd *next_buffhd_to_fill; 358 struct fsg_buffhd *next_buffhd_to_fill;
339 struct fsg_buffhd *next_buffhd_to_drain; 359 struct fsg_buffhd *next_buffhd_to_drain;
@@ -369,8 +389,8 @@ struct fsg_common {
369 struct completion thread_notifier; 389 struct completion thread_notifier;
370 struct task_struct *thread_task; 390 struct task_struct *thread_task;
371 391
372 /* Callback function to call when thread exits. */ 392 /* Callback functions. */
373 int (*thread_exits)(struct fsg_common *common); 393 const struct fsg_operations *ops;
374 /* Gadget's private data. */ 394 /* Gadget's private data. */
375 void *private_data; 395 void *private_data;
376 396
@@ -394,12 +414,8 @@ struct fsg_config {
394 const char *lun_name_format; 414 const char *lun_name_format;
395 const char *thread_name; 415 const char *thread_name;
396 416
397 /* Callback function to call when thread exits. If no 417 /* Callback functions. */
398 * callback is set or it returns value lower then zero MSF 418 const struct fsg_operations *ops;
399 * will force eject all LUNs it operates on (including those
400 * marked as non-removable or with prevent_medium_removal flag
401 * set). */
402 int (*thread_exits)(struct fsg_common *common);
403 /* Gadget's private data. */ 419 /* Gadget's private data. */
404 void *private_data; 420 void *private_data;
405 421
@@ -435,6 +451,7 @@ static inline int __fsg_is_set(struct fsg_common *common,
435 if (common->fsg) 451 if (common->fsg)
436 return 1; 452 return 1;
437 ERROR(common, "common->fsg is NULL in %s at %u\n", func, line); 453 ERROR(common, "common->fsg is NULL in %s at %u\n", func, line);
454 WARN_ON(1);
438 return 0; 455 return 0;
439} 456}
440 457
@@ -623,8 +640,6 @@ static int fsg_setup(struct usb_function *f,
623 640
624 /* Respond with data/status */ 641 /* Respond with data/status */
625 req->length = min((u16)1, w_length); 642 req->length = min((u16)1, w_length);
626 fsg->common->ep0req_name =
627 ctrl->bRequestType & USB_DIR_IN ? "ep0-in" : "ep0-out";
628 return ep0_queue(fsg->common); 643 return ep0_queue(fsg->common);
629 } 644 }
630 645
@@ -1395,43 +1410,55 @@ static int do_start_stop(struct fsg_common *common)
1395 } else if (!curlun->removable) { 1410 } else if (!curlun->removable) {
1396 curlun->sense_data = SS_INVALID_COMMAND; 1411 curlun->sense_data = SS_INVALID_COMMAND;
1397 return -EINVAL; 1412 return -EINVAL;
1398 } 1413 } else if ((common->cmnd[1] & ~0x01) != 0 || /* Mask away Immed */
1399 1414 (common->cmnd[4] & ~0x03) != 0) { /* Mask LoEj, Start */
1400 loej = common->cmnd[4] & 0x02;
1401 start = common->cmnd[4] & 0x01;
1402
1403 /* eject code from file_storage.c:do_start_stop() */
1404
1405 if ((common->cmnd[1] & ~0x01) != 0 || /* Mask away Immed */
1406 (common->cmnd[4] & ~0x03) != 0) { /* Mask LoEj, Start */
1407 curlun->sense_data = SS_INVALID_FIELD_IN_CDB; 1415 curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
1408 return -EINVAL; 1416 return -EINVAL;
1409 } 1417 }
1410 1418
1411 if (!start) { 1419 loej = common->cmnd[4] & 0x02;
1412 /* Are we allowed to unload the media? */ 1420 start = common->cmnd[4] & 0x01;
1413 if (curlun->prevent_medium_removal) {
1414 LDBG(curlun, "unload attempt prevented\n");
1415 curlun->sense_data = SS_MEDIUM_REMOVAL_PREVENTED;
1416 return -EINVAL;
1417 }
1418 if (loej) { /* Simulate an unload/eject */
1419 up_read(&common->filesem);
1420 down_write(&common->filesem);
1421 fsg_lun_close(curlun);
1422 up_write(&common->filesem);
1423 down_read(&common->filesem);
1424 }
1425 } else {
1426 1421
1427 /* Our emulation doesn't support mounting; the medium is 1422 /* Our emulation doesn't support mounting; the medium is
1428 * available for use as soon as it is loaded. */ 1423 * available for use as soon as it is loaded. */
1424 if (start) {
1429 if (!fsg_lun_is_open(curlun)) { 1425 if (!fsg_lun_is_open(curlun)) {
1430 curlun->sense_data = SS_MEDIUM_NOT_PRESENT; 1426 curlun->sense_data = SS_MEDIUM_NOT_PRESENT;
1431 return -EINVAL; 1427 return -EINVAL;
1432 } 1428 }
1429 return 0;
1433 } 1430 }
1434 return 0; 1431
1432 /* Are we allowed to unload the media? */
1433 if (curlun->prevent_medium_removal) {
1434 LDBG(curlun, "unload attempt prevented\n");
1435 curlun->sense_data = SS_MEDIUM_REMOVAL_PREVENTED;
1436 return -EINVAL;
1437 }
1438
1439 if (!loej)
1440 return 0;
1441
1442 /* Simulate an unload/eject */
1443 if (common->ops && common->ops->pre_eject) {
1444 int r = common->ops->pre_eject(common, curlun,
1445 curlun - common->luns);
1446 if (unlikely(r < 0))
1447 return r;
1448 else if (r)
1449 return 0;
1450 }
1451
1452 up_read(&common->filesem);
1453 down_write(&common->filesem);
1454 fsg_lun_close(curlun);
1455 up_write(&common->filesem);
1456 down_read(&common->filesem);
1457
1458 return common->ops && common->ops->post_eject
1459 ? min(0, common->ops->post_eject(common, curlun,
1460 curlun - common->luns))
1461 : 0;
1435} 1462}
1436 1463
1437 1464
@@ -2610,7 +2637,8 @@ static int fsg_main_thread(void *common_)
2610 common->thread_task = NULL; 2637 common->thread_task = NULL;
2611 spin_unlock_irq(&common->lock); 2638 spin_unlock_irq(&common->lock);
2612 2639
2613 if (!common->thread_exits || common->thread_exits(common) < 0) { 2640 if (!common->ops || !common->ops->thread_exits
2641 || common->ops->thread_exits(common) < 0) {
2614 struct fsg_lun *curlun = common->luns; 2642 struct fsg_lun *curlun = common->luns;
2615 unsigned i = common->nluns; 2643 unsigned i = common->nluns;
2616 2644
@@ -2686,6 +2714,7 @@ static struct fsg_common *fsg_common_init(struct fsg_common *common,
2686 common->free_storage_on_release = 0; 2714 common->free_storage_on_release = 0;
2687 } 2715 }
2688 2716
2717 common->ops = cfg->ops;
2689 common->private_data = cfg->private_data; 2718 common->private_data = cfg->private_data;
2690 2719
2691 common->gadget = gadget; 2720 common->gadget = gadget;
@@ -2807,7 +2836,6 @@ buffhds_first_it:
2807 2836
2808 2837
2809 /* Tell the thread to start working */ 2838 /* Tell the thread to start working */
2810 common->thread_exits = cfg->thread_exits;
2811 common->thread_task = 2839 common->thread_task =
2812 kthread_create(fsg_main_thread, common, 2840 kthread_create(fsg_main_thread, common,
2813 OR(cfg->thread_name, "file-storage")); 2841 OR(cfg->thread_name, "file-storage"));
@@ -2990,9 +3018,9 @@ static struct usb_gadget_strings *fsg_strings_array[] = {
2990 NULL, 3018 NULL,
2991}; 3019};
2992 3020
2993static int fsg_add(struct usb_composite_dev *cdev, 3021static int fsg_bind_config(struct usb_composite_dev *cdev,
2994 struct usb_configuration *c, 3022 struct usb_configuration *c,
2995 struct fsg_common *common) 3023 struct fsg_common *common)
2996{ 3024{
2997 struct fsg_dev *fsg; 3025 struct fsg_dev *fsg;
2998 int rc; 3026 int rc;
@@ -3024,6 +3052,13 @@ static int fsg_add(struct usb_composite_dev *cdev,
3024 return rc; 3052 return rc;
3025} 3053}
3026 3054
3055static inline int __deprecated __maybe_unused
3056fsg_add(struct usb_composite_dev *cdev,
3057 struct usb_configuration *c,
3058 struct fsg_common *common)
3059{
3060 return fsg_bind_config(cdev, c, common);
3061}
3027 3062
3028 3063
3029/************************* Module parameters *************************/ 3064/************************* Module parameters *************************/
@@ -3096,8 +3131,8 @@ fsg_config_from_params(struct fsg_config *cfg,
3096 cfg->product_name = 0; 3131 cfg->product_name = 0;
3097 cfg->release = 0xffff; 3132 cfg->release = 0xffff;
3098 3133
3099 cfg->thread_exits = 0; 3134 cfg->ops = NULL;
3100 cfg->private_data = 0; 3135 cfg->private_data = NULL;
3101 3136
3102 /* Finalise */ 3137 /* Finalise */
3103 cfg->can_stall = params->stall; 3138 cfg->can_stall = params->stall;
diff --git a/drivers/usb/gadget/f_sourcesink.c b/drivers/usb/gadget/f_sourcesink.c
index 6d3cc443d914..685d768f336e 100644
--- a/drivers/usb/gadget/f_sourcesink.c
+++ b/drivers/usb/gadget/f_sourcesink.c
@@ -404,7 +404,7 @@ static void sourcesink_disable(struct usb_function *f)
404 404
405/*-------------------------------------------------------------------------*/ 405/*-------------------------------------------------------------------------*/
406 406
407static int __init sourcesink_bind_config(struct usb_configuration *c) 407static int __ref sourcesink_bind_config(struct usb_configuration *c)
408{ 408{
409 struct f_sourcesink *ss; 409 struct f_sourcesink *ss;
410 int status; 410 int status;
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c
index b49d86e3e45b..a857b7ac238c 100644
--- a/drivers/usb/gadget/file_storage.c
+++ b/drivers/usb/gadget/file_storage.c
@@ -56,7 +56,7 @@
56 * following protocols: RBC (0x01), ATAPI or SFF-8020i (0x02), QIC-157 (0c03), 56 * following protocols: RBC (0x01), ATAPI or SFF-8020i (0x02), QIC-157 (0c03),
57 * UFI (0x04), SFF-8070i (0x05), and transparent SCSI (0x06), selected by 57 * UFI (0x04), SFF-8070i (0x05), and transparent SCSI (0x06), selected by
58 * the optional "protocol" module parameter. In addition, the default 58 * the optional "protocol" module parameter. In addition, the default
59 * Vendor ID, Product ID, and release number can be overridden. 59 * Vendor ID, Product ID, release number and serial number can be overridden.
60 * 60 *
61 * There is support for multiple logical units (LUNs), each of which has 61 * There is support for multiple logical units (LUNs), each of which has
62 * its own backing file. The number of LUNs can be set using the optional 62 * its own backing file. The number of LUNs can be set using the optional
@@ -93,6 +93,8 @@
93 * removable Default false, boolean for removable media 93 * removable Default false, boolean for removable media
94 * luns=N Default N = number of filenames, number of 94 * luns=N Default N = number of filenames, number of
95 * LUNs to support 95 * LUNs to support
96 * nofua=b[,b...] Default false, booleans for ignore FUA flag
97 * in SCSI WRITE(10,12) commands
96 * stall Default determined according to the type of 98 * stall Default determined according to the type of
97 * USB device controller (usually true), 99 * USB device controller (usually true),
98 * boolean to permit the driver to halt 100 * boolean to permit the driver to halt
@@ -106,17 +108,18 @@
106 * vendor=0xVVVV Default 0x0525 (NetChip), USB Vendor ID 108 * vendor=0xVVVV Default 0x0525 (NetChip), USB Vendor ID
107 * product=0xPPPP Default 0xa4a5 (FSG), USB Product ID 109 * product=0xPPPP Default 0xa4a5 (FSG), USB Product ID
108 * release=0xRRRR Override the USB release number (bcdDevice) 110 * release=0xRRRR Override the USB release number (bcdDevice)
111 * serial=HHHH... Override serial number (string of hex chars)
109 * buflen=N Default N=16384, buffer size used (will be 112 * buflen=N Default N=16384, buffer size used (will be
110 * rounded down to a multiple of 113 * rounded down to a multiple of
111 * PAGE_CACHE_SIZE) 114 * PAGE_CACHE_SIZE)
112 * 115 *
113 * If CONFIG_USB_FILE_STORAGE_TEST is not set, only the "file", "ro", 116 * If CONFIG_USB_FILE_STORAGE_TEST is not set, only the "file", "ro",
114 * "removable", "luns", "stall", and "cdrom" options are available; default 117 * "removable", "luns", "nofua", "stall", and "cdrom" options are available;
115 * values are used for everything else. 118 * default values are used for everything else.
116 * 119 *
117 * The pathnames of the backing files and the ro settings are available in 120 * The pathnames of the backing files and the ro settings are available in
118 * the attribute files "file" and "ro" in the lun<n> subdirectory of the 121 * the attribute files "file", "nofua", and "ro" in the lun<n> subdirectory of
119 * gadget's sysfs directory. If the "removable" option is set, writing to 122 * the gadget's sysfs directory. If the "removable" option is set, writing to
120 * these files will simulate ejecting/loading the medium (writing an empty 123 * these files will simulate ejecting/loading the medium (writing an empty
121 * line means eject) and adjusting a write-enable tab. Changes to the ro 124 * line means eject) and adjusting a write-enable tab. Changes to the ro
122 * setting are not allowed when the medium is loaded or if CD-ROM emulation 125 * setting are not allowed when the medium is loaded or if CD-ROM emulation
@@ -270,6 +273,8 @@
270 273
271#define DRIVER_DESC "File-backed Storage Gadget" 274#define DRIVER_DESC "File-backed Storage Gadget"
272#define DRIVER_NAME "g_file_storage" 275#define DRIVER_NAME "g_file_storage"
276/* DRIVER_VERSION must be at least 6 characters long, as it is used
277 * to generate a fallback serial number. */
273#define DRIVER_VERSION "20 November 2008" 278#define DRIVER_VERSION "20 November 2008"
274 279
275static char fsg_string_manufacturer[64]; 280static char fsg_string_manufacturer[64];
@@ -301,8 +306,10 @@ MODULE_LICENSE("Dual BSD/GPL");
301static struct { 306static struct {
302 char *file[FSG_MAX_LUNS]; 307 char *file[FSG_MAX_LUNS];
303 int ro[FSG_MAX_LUNS]; 308 int ro[FSG_MAX_LUNS];
309 int nofua[FSG_MAX_LUNS];
304 unsigned int num_filenames; 310 unsigned int num_filenames;
305 unsigned int num_ros; 311 unsigned int num_ros;
312 unsigned int num_nofuas;
306 unsigned int nluns; 313 unsigned int nluns;
307 314
308 int removable; 315 int removable;
@@ -314,6 +321,7 @@ static struct {
314 unsigned short vendor; 321 unsigned short vendor;
315 unsigned short product; 322 unsigned short product;
316 unsigned short release; 323 unsigned short release;
324 char *serial;
317 unsigned int buflen; 325 unsigned int buflen;
318 326
319 int transport_type; 327 int transport_type;
@@ -341,6 +349,10 @@ MODULE_PARM_DESC(file, "names of backing files or devices");
341module_param_array_named(ro, mod_data.ro, bool, &mod_data.num_ros, S_IRUGO); 349module_param_array_named(ro, mod_data.ro, bool, &mod_data.num_ros, S_IRUGO);
342MODULE_PARM_DESC(ro, "true to force read-only"); 350MODULE_PARM_DESC(ro, "true to force read-only");
343 351
352module_param_array_named(nofua, mod_data.nofua, bool, &mod_data.num_nofuas,
353 S_IRUGO);
354MODULE_PARM_DESC(nofua, "true to ignore SCSI WRITE(10,12) FUA bit");
355
344module_param_named(luns, mod_data.nluns, uint, S_IRUGO); 356module_param_named(luns, mod_data.nluns, uint, S_IRUGO);
345MODULE_PARM_DESC(luns, "number of LUNs"); 357MODULE_PARM_DESC(luns, "number of LUNs");
346 358
@@ -353,6 +365,8 @@ MODULE_PARM_DESC(stall, "false to prevent bulk stalls");
353module_param_named(cdrom, mod_data.cdrom, bool, S_IRUGO); 365module_param_named(cdrom, mod_data.cdrom, bool, S_IRUGO);
354MODULE_PARM_DESC(cdrom, "true to emulate cdrom instead of disk"); 366MODULE_PARM_DESC(cdrom, "true to emulate cdrom instead of disk");
355 367
368module_param_named(serial, mod_data.serial, charp, S_IRUGO);
369MODULE_PARM_DESC(serial, "USB serial number");
356 370
357/* In the non-TEST version, only the module parameters listed above 371/* In the non-TEST version, only the module parameters listed above
358 * are available. */ 372 * are available. */
@@ -1272,7 +1286,8 @@ static int do_write(struct fsg_dev *fsg)
1272 curlun->sense_data = SS_INVALID_FIELD_IN_CDB; 1286 curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
1273 return -EINVAL; 1287 return -EINVAL;
1274 } 1288 }
1275 if (fsg->cmnd[1] & 0x08) { // FUA 1289 /* FUA */
1290 if (!curlun->nofua && (fsg->cmnd[1] & 0x08)) {
1276 spin_lock(&curlun->filp->f_lock); 1291 spin_lock(&curlun->filp->f_lock);
1277 curlun->filp->f_flags |= O_DSYNC; 1292 curlun->filp->f_flags |= O_DSYNC;
1278 spin_unlock(&curlun->filp->f_lock); 1293 spin_unlock(&curlun->filp->f_lock);
@@ -3126,6 +3141,7 @@ static int fsg_main_thread(void *fsg_)
3126 3141
3127/* The write permissions and store_xxx pointers are set in fsg_bind() */ 3142/* The write permissions and store_xxx pointers are set in fsg_bind() */
3128static DEVICE_ATTR(ro, 0444, fsg_show_ro, NULL); 3143static DEVICE_ATTR(ro, 0444, fsg_show_ro, NULL);
3144static DEVICE_ATTR(nofua, 0644, fsg_show_nofua, NULL);
3129static DEVICE_ATTR(file, 0444, fsg_show_file, NULL); 3145static DEVICE_ATTR(file, 0444, fsg_show_file, NULL);
3130 3146
3131 3147
@@ -3197,6 +3213,7 @@ static int __init check_parameters(struct fsg_dev *fsg)
3197{ 3213{
3198 int prot; 3214 int prot;
3199 int gcnum; 3215 int gcnum;
3216 int i;
3200 3217
3201 /* Store the default values */ 3218 /* Store the default values */
3202 mod_data.transport_type = USB_PR_BULK; 3219 mod_data.transport_type = USB_PR_BULK;
@@ -3272,13 +3289,65 @@ static int __init check_parameters(struct fsg_dev *fsg)
3272 ERROR(fsg, "invalid buflen\n"); 3289 ERROR(fsg, "invalid buflen\n");
3273 return -ETOOSMALL; 3290 return -ETOOSMALL;
3274 } 3291 }
3292
3275#endif /* CONFIG_USB_FILE_STORAGE_TEST */ 3293#endif /* CONFIG_USB_FILE_STORAGE_TEST */
3276 3294
3295 /* Serial string handling.
3296 * On a real device, the serial string would be loaded
3297 * from permanent storage. */
3298 if (mod_data.serial) {
3299 const char *ch;
3300 unsigned len = 0;
3301
3302 /* Sanity check :
3303 * The CB[I] specification limits the serial string to
3304 * 12 uppercase hexadecimal characters.
3305 * BBB need at least 12 uppercase hexadecimal characters,
3306 * with a maximum of 126. */
3307 for (ch = mod_data.serial; *ch; ++ch) {
3308 ++len;
3309 if ((*ch < '0' || *ch > '9') &&
3310 (*ch < 'A' || *ch > 'F')) { /* not uppercase hex */
3311 WARNING(fsg,
3312 "Invalid serial string character: %c; "
3313 "Failing back to default\n",
3314 *ch);
3315 goto fill_serial;
3316 }
3317 }
3318 if (len > 126 ||
3319 (mod_data.transport_type == USB_PR_BULK && len < 12) ||
3320 (mod_data.transport_type != USB_PR_BULK && len > 12)) {
3321 WARNING(fsg,
3322 "Invalid serial string length; "
3323 "Failing back to default\n");
3324 goto fill_serial;
3325 }
3326 fsg_strings[FSG_STRING_SERIAL - 1].s = mod_data.serial;
3327 } else {
3328 WARNING(fsg,
3329 "Userspace failed to provide serial number; "
3330 "Failing back to default\n");
3331fill_serial:
3332 /* Serial number not specified or invalid, make our own.
3333 * We just encode it from the driver version string,
3334 * 12 characters to comply with both CB[I] and BBB spec.
3335 * Warning : Two devices running the same kernel will have
3336 * the same fallback serial number. */
3337 for (i = 0; i < 12; i += 2) {
3338 unsigned char c = DRIVER_VERSION[i / 2];
3339
3340 if (!c)
3341 break;
3342 sprintf(&fsg_string_serial[i], "%02X", c);
3343 }
3344 }
3345
3277 return 0; 3346 return 0;
3278} 3347}
3279 3348
3280 3349
3281static int __init fsg_bind(struct usb_gadget *gadget) 3350static int __ref fsg_bind(struct usb_gadget *gadget)
3282{ 3351{
3283 struct fsg_dev *fsg = the_fsg; 3352 struct fsg_dev *fsg = the_fsg;
3284 int rc; 3353 int rc;
@@ -3305,6 +3374,10 @@ static int __init fsg_bind(struct usb_gadget *gadget)
3305 } 3374 }
3306 } 3375 }
3307 3376
3377 /* Only for removable media? */
3378 dev_attr_nofua.attr.mode = 0644;
3379 dev_attr_nofua.store = fsg_store_nofua;
3380
3308 /* Find out how many LUNs there should be */ 3381 /* Find out how many LUNs there should be */
3309 i = mod_data.nluns; 3382 i = mod_data.nluns;
3310 if (i == 0) 3383 if (i == 0)
@@ -3330,6 +3403,7 @@ static int __init fsg_bind(struct usb_gadget *gadget)
3330 curlun->ro = mod_data.cdrom || mod_data.ro[i]; 3403 curlun->ro = mod_data.cdrom || mod_data.ro[i];
3331 curlun->initially_ro = curlun->ro; 3404 curlun->initially_ro = curlun->ro;
3332 curlun->removable = mod_data.removable; 3405 curlun->removable = mod_data.removable;
3406 curlun->nofua = mod_data.nofua[i];
3333 curlun->dev.release = lun_release; 3407 curlun->dev.release = lun_release;
3334 curlun->dev.parent = &gadget->dev; 3408 curlun->dev.parent = &gadget->dev;
3335 curlun->dev.driver = &fsg_driver.driver; 3409 curlun->dev.driver = &fsg_driver.driver;
@@ -3344,6 +3418,8 @@ static int __init fsg_bind(struct usb_gadget *gadget)
3344 if ((rc = device_create_file(&curlun->dev, 3418 if ((rc = device_create_file(&curlun->dev,
3345 &dev_attr_ro)) != 0 || 3419 &dev_attr_ro)) != 0 ||
3346 (rc = device_create_file(&curlun->dev, 3420 (rc = device_create_file(&curlun->dev,
3421 &dev_attr_nofua)) != 0 ||
3422 (rc = device_create_file(&curlun->dev,
3347 &dev_attr_file)) != 0) { 3423 &dev_attr_file)) != 0) {
3348 device_unregister(&curlun->dev); 3424 device_unregister(&curlun->dev);
3349 goto out; 3425 goto out;
@@ -3447,16 +3523,6 @@ static int __init fsg_bind(struct usb_gadget *gadget)
3447 init_utsname()->sysname, init_utsname()->release, 3523 init_utsname()->sysname, init_utsname()->release,
3448 gadget->name); 3524 gadget->name);
3449 3525
3450 /* On a real device, serial[] would be loaded from permanent
3451 * storage. We just encode it from the driver version string. */
3452 for (i = 0; i < sizeof fsg_string_serial - 2; i += 2) {
3453 unsigned char c = DRIVER_VERSION[i / 2];
3454
3455 if (!c)
3456 break;
3457 sprintf(&fsg_string_serial[i], "%02X", c);
3458 }
3459
3460 fsg->thread_task = kthread_create(fsg_main_thread, fsg, 3526 fsg->thread_task = kthread_create(fsg_main_thread, fsg,
3461 "file-storage-gadget"); 3527 "file-storage-gadget");
3462 if (IS_ERR(fsg->thread_task)) { 3528 if (IS_ERR(fsg->thread_task)) {
@@ -3478,8 +3544,8 @@ static int __init fsg_bind(struct usb_gadget *gadget)
3478 if (IS_ERR(p)) 3544 if (IS_ERR(p))
3479 p = NULL; 3545 p = NULL;
3480 } 3546 }
3481 LINFO(curlun, "ro=%d, file: %s\n", 3547 LINFO(curlun, "ro=%d, nofua=%d, file: %s\n",
3482 curlun->ro, (p ? p : "(error)")); 3548 curlun->ro, curlun->nofua, (p ? p : "(error)"));
3483 } 3549 }
3484 } 3550 }
3485 kfree(pathbuf); 3551 kfree(pathbuf);
diff --git a/drivers/usb/gadget/fsl_qe_udc.c b/drivers/usb/gadget/fsl_qe_udc.c
index 9648b75f0283..a5ea2c1d8c93 100644
--- a/drivers/usb/gadget/fsl_qe_udc.c
+++ b/drivers/usb/gadget/fsl_qe_udc.c
@@ -2398,7 +2398,7 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
2398EXPORT_SYMBOL(usb_gadget_unregister_driver); 2398EXPORT_SYMBOL(usb_gadget_unregister_driver);
2399 2399
2400/* udc structure's alloc and setup, include ep-param alloc */ 2400/* udc structure's alloc and setup, include ep-param alloc */
2401static struct qe_udc __devinit *qe_udc_config(struct of_device *ofdev) 2401static struct qe_udc __devinit *qe_udc_config(struct platform_device *ofdev)
2402{ 2402{
2403 struct qe_udc *udc; 2403 struct qe_udc *udc;
2404 struct device_node *np = ofdev->dev.of_node; 2404 struct device_node *np = ofdev->dev.of_node;
@@ -2523,7 +2523,7 @@ static void qe_udc_release(struct device *dev)
2523} 2523}
2524 2524
2525/* Driver probe functions */ 2525/* Driver probe functions */
2526static int __devinit qe_udc_probe(struct of_device *ofdev, 2526static int __devinit qe_udc_probe(struct platform_device *ofdev,
2527 const struct of_device_id *match) 2527 const struct of_device_id *match)
2528{ 2528{
2529 struct device_node *np = ofdev->dev.of_node; 2529 struct device_node *np = ofdev->dev.of_node;
@@ -2679,18 +2679,18 @@ err1:
2679} 2679}
2680 2680
2681#ifdef CONFIG_PM 2681#ifdef CONFIG_PM
2682static int qe_udc_suspend(struct of_device *dev, pm_message_t state) 2682static int qe_udc_suspend(struct platform_device *dev, pm_message_t state)
2683{ 2683{
2684 return -ENOTSUPP; 2684 return -ENOTSUPP;
2685} 2685}
2686 2686
2687static int qe_udc_resume(struct of_device *dev) 2687static int qe_udc_resume(struct platform_device *dev)
2688{ 2688{
2689 return -ENOTSUPP; 2689 return -ENOTSUPP;
2690} 2690}
2691#endif 2691#endif
2692 2692
2693static int __devexit qe_udc_remove(struct of_device *ofdev) 2693static int __devexit qe_udc_remove(struct platform_device *ofdev)
2694{ 2694{
2695 struct qe_ep *ep; 2695 struct qe_ep *ep;
2696 unsigned int size; 2696 unsigned int size;
diff --git a/drivers/usb/gadget/g_ffs.c b/drivers/usb/gadget/g_ffs.c
index d1af253a9105..a9474f8d5325 100644
--- a/drivers/usb/gadget/g_ffs.c
+++ b/drivers/usb/gadget/g_ffs.c
@@ -32,12 +32,13 @@
32# include "u_ether.c" 32# include "u_ether.c"
33 33
34static u8 gfs_hostaddr[ETH_ALEN]; 34static u8 gfs_hostaddr[ETH_ALEN];
35#else 35# ifdef CONFIG_USB_FUNCTIONFS_ETH
36# if !defined CONFIG_USB_FUNCTIONFS_GENERIC 36static int eth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]);
37# define CONFIG_USB_FUNCTIONFS_GENERIC
38# endif 37# endif
38#else
39# define gether_cleanup() do { } while (0) 39# define gether_cleanup() do { } while (0)
40# define gether_setup(gadget, hostaddr) ((int)0) 40# define gether_setup(gadget, hostaddr) ((int)0)
41# define gfs_hostaddr NULL
41#endif 42#endif
42 43
43#include "f_fs.c" 44#include "f_fs.c"
@@ -107,15 +108,7 @@ static const struct usb_descriptor_header *gfs_otg_desc[] = {
107enum { 108enum {
108 GFS_STRING_MANUFACTURER_IDX, 109 GFS_STRING_MANUFACTURER_IDX,
109 GFS_STRING_PRODUCT_IDX, 110 GFS_STRING_PRODUCT_IDX,
110#ifdef CONFIG_USB_FUNCTIONFS_RNDIS 111 GFS_STRING_FIRST_CONFIG_IDX,
111 GFS_STRING_RNDIS_CONFIG_IDX,
112#endif
113#ifdef CONFIG_USB_FUNCTIONFS_ETH
114 GFS_STRING_ECM_CONFIG_IDX,
115#endif
116#ifdef CONFIG_USB_FUNCTIONFS_GENERIC
117 GFS_STRING_GENERIC_CONFIG_IDX,
118#endif
119}; 112};
120 113
121static char gfs_manufacturer[50]; 114static char gfs_manufacturer[50];
@@ -126,13 +119,13 @@ static struct usb_string gfs_strings[] = {
126 [GFS_STRING_MANUFACTURER_IDX].s = gfs_manufacturer, 119 [GFS_STRING_MANUFACTURER_IDX].s = gfs_manufacturer,
127 [GFS_STRING_PRODUCT_IDX].s = gfs_driver_desc, 120 [GFS_STRING_PRODUCT_IDX].s = gfs_driver_desc,
128#ifdef CONFIG_USB_FUNCTIONFS_RNDIS 121#ifdef CONFIG_USB_FUNCTIONFS_RNDIS
129 [GFS_STRING_RNDIS_CONFIG_IDX].s = "FunctionFS + RNDIS", 122 { .s = "FunctionFS + RNDIS" },
130#endif 123#endif
131#ifdef CONFIG_USB_FUNCTIONFS_ETH 124#ifdef CONFIG_USB_FUNCTIONFS_ETH
132 [GFS_STRING_ECM_CONFIG_IDX].s = "FunctionFS + ECM", 125 { .s = "FunctionFS + ECM" },
133#endif 126#endif
134#ifdef CONFIG_USB_FUNCTIONFS_GENERIC 127#ifdef CONFIG_USB_FUNCTIONFS_GENERIC
135 [GFS_STRING_GENERIC_CONFIG_IDX].s = "FunctionFS", 128 { .s = "FunctionFS" },
136#endif 129#endif
137 { } /* end of list */ 130 { } /* end of list */
138}; 131};
@@ -146,59 +139,33 @@ static struct usb_gadget_strings *gfs_dev_strings[] = {
146}; 139};
147 140
148 141
142
143struct gfs_configuration {
144 struct usb_configuration c;
145 int (*eth)(struct usb_configuration *c, u8 *ethaddr);
146} gfs_configurations[] = {
149#ifdef CONFIG_USB_FUNCTIONFS_RNDIS 147#ifdef CONFIG_USB_FUNCTIONFS_RNDIS
150static int gfs_do_rndis_config(struct usb_configuration *c); 148 {
151 149 .eth = rndis_bind_config,
152static struct usb_configuration gfs_rndis_config_driver = { 150 },
153 .label = "FunctionFS + RNDIS",
154 .bind = gfs_do_rndis_config,
155 .bConfigurationValue = 1,
156 /* .iConfiguration = DYNAMIC */
157 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
158};
159# define gfs_add_rndis_config(cdev) \
160 usb_add_config(cdev, &gfs_rndis_config_driver)
161#else
162# define gfs_add_rndis_config(cdev) 0
163#endif 151#endif
164 152
165
166#ifdef CONFIG_USB_FUNCTIONFS_ETH 153#ifdef CONFIG_USB_FUNCTIONFS_ETH
167static int gfs_do_ecm_config(struct usb_configuration *c); 154 {
168 155 .eth = eth_bind_config,
169static struct usb_configuration gfs_ecm_config_driver = { 156 },
170 .label = "FunctionFS + ECM",
171 .bind = gfs_do_ecm_config,
172 .bConfigurationValue = 1,
173 /* .iConfiguration = DYNAMIC */
174 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
175};
176# define gfs_add_ecm_config(cdev) \
177 usb_add_config(cdev, &gfs_ecm_config_driver)
178#else
179# define gfs_add_ecm_config(cdev) 0
180#endif 157#endif
181 158
182
183#ifdef CONFIG_USB_FUNCTIONFS_GENERIC 159#ifdef CONFIG_USB_FUNCTIONFS_GENERIC
184static int gfs_do_generic_config(struct usb_configuration *c); 160 {
185 161 },
186static struct usb_configuration gfs_generic_config_driver = {
187 .label = "FunctionFS",
188 .bind = gfs_do_generic_config,
189 .bConfigurationValue = 2,
190 /* .iConfiguration = DYNAMIC */
191 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
192};
193# define gfs_add_generic_config(cdev) \
194 usb_add_config(cdev, &gfs_generic_config_driver)
195#else
196# define gfs_add_generic_config(cdev) 0
197#endif 162#endif
163};
198 164
199 165
200static int gfs_bind(struct usb_composite_dev *cdev); 166static int gfs_bind(struct usb_composite_dev *cdev);
201static int gfs_unbind(struct usb_composite_dev *cdev); 167static int gfs_unbind(struct usb_composite_dev *cdev);
168static int gfs_do_config(struct usb_configuration *c);
202 169
203static struct usb_composite_driver gfs_driver = { 170static struct usb_composite_driver gfs_driver = {
204 .name = gfs_short_name, 171 .name = gfs_short_name,
@@ -267,7 +234,7 @@ static int functionfs_check_dev_callback(const char *dev_name)
267 234
268static int gfs_bind(struct usb_composite_dev *cdev) 235static int gfs_bind(struct usb_composite_dev *cdev)
269{ 236{
270 int ret; 237 int ret, i;
271 238
272 ENTER(); 239 ENTER();
273 240
@@ -284,57 +251,32 @@ static int gfs_bind(struct usb_composite_dev *cdev)
284 snprintf(gfs_manufacturer, sizeof gfs_manufacturer, "%s %s with %s", 251 snprintf(gfs_manufacturer, sizeof gfs_manufacturer, "%s %s with %s",
285 init_utsname()->sysname, init_utsname()->release, 252 init_utsname()->sysname, init_utsname()->release,
286 cdev->gadget->name); 253 cdev->gadget->name);
287 ret = usb_string_id(cdev);
288 if (unlikely(ret < 0))
289 goto error;
290 gfs_strings[GFS_STRING_MANUFACTURER_IDX].id = ret;
291 gfs_dev_desc.iManufacturer = ret;
292
293 ret = usb_string_id(cdev);
294 if (unlikely(ret < 0))
295 goto error;
296 gfs_strings[GFS_STRING_PRODUCT_IDX].id = ret;
297 gfs_dev_desc.iProduct = ret;
298
299#ifdef CONFIG_USB_FUNCTIONFS_RNDIS
300 ret = usb_string_id(cdev);
301 if (unlikely(ret < 0))
302 goto error;
303 gfs_strings[GFS_STRING_RNDIS_CONFIG_IDX].id = ret;
304 gfs_rndis_config_driver.iConfiguration = ret;
305#endif
306 254
307#ifdef CONFIG_USB_FUNCTIONFS_ETH 255 ret = usb_string_ids_tab(cdev, gfs_strings);
308 ret = usb_string_id(cdev);
309 if (unlikely(ret < 0)) 256 if (unlikely(ret < 0))
310 goto error; 257 goto error;
311 gfs_strings[GFS_STRING_ECM_CONFIG_IDX].id = ret;
312 gfs_ecm_config_driver.iConfiguration = ret;
313#endif
314 258
315#ifdef CONFIG_USB_FUNCTIONFS_GENERIC 259 gfs_dev_desc.iManufacturer = gfs_strings[GFS_STRING_MANUFACTURER_IDX].id;
316 ret = usb_string_id(cdev); 260 gfs_dev_desc.iProduct = gfs_strings[GFS_STRING_PRODUCT_IDX].id;
317 if (unlikely(ret < 0))
318 goto error;
319 gfs_strings[GFS_STRING_GENERIC_CONFIG_IDX].id = ret;
320 gfs_generic_config_driver.iConfiguration = ret;
321#endif
322 261
323 ret = functionfs_bind(gfs_ffs_data, cdev); 262 ret = functionfs_bind(gfs_ffs_data, cdev);
324 if (unlikely(ret < 0)) 263 if (unlikely(ret < 0))
325 goto error; 264 goto error;
326 265
327 ret = gfs_add_rndis_config(cdev); 266 for (i = 0; i < ARRAY_SIZE(gfs_configurations); ++i) {
328 if (unlikely(ret < 0)) 267 struct gfs_configuration *c = gfs_configurations + i;
329 goto error_unbind;
330 268
331 ret = gfs_add_ecm_config(cdev); 269 ret = GFS_STRING_FIRST_CONFIG_IDX + i;
332 if (unlikely(ret < 0)) 270 c->c.label = gfs_strings[ret].s;
333 goto error_unbind; 271 c->c.iConfiguration = gfs_strings[ret].id;
272 c->c.bind = gfs_do_config;
273 c->c.bConfigurationValue = 1 + i;
274 c->c.bmAttributes = USB_CONFIG_ATT_SELFPOWER;
334 275
335 ret = gfs_add_generic_config(cdev); 276 ret = usb_add_config(cdev, &c->c);
336 if (unlikely(ret < 0)) 277 if (unlikely(ret < 0))
337 goto error_unbind; 278 goto error_unbind;
279 }
338 280
339 return 0; 281 return 0;
340 282
@@ -368,10 +310,10 @@ static int gfs_unbind(struct usb_composite_dev *cdev)
368} 310}
369 311
370 312
371static int __gfs_do_config(struct usb_configuration *c, 313static int gfs_do_config(struct usb_configuration *c)
372 int (*eth)(struct usb_configuration *c, u8 *ethaddr),
373 u8 *ethaddr)
374{ 314{
315 struct gfs_configuration *gc =
316 container_of(c, struct gfs_configuration, c);
375 int ret; 317 int ret;
376 318
377 if (WARN_ON(!gfs_ffs_data)) 319 if (WARN_ON(!gfs_ffs_data))
@@ -382,13 +324,13 @@ static int __gfs_do_config(struct usb_configuration *c,
382 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; 324 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
383 } 325 }
384 326
385 if (eth) { 327 if (gc->eth) {
386 ret = eth(c, ethaddr); 328 ret = gc->eth(c, gfs_hostaddr);
387 if (unlikely(ret < 0)) 329 if (unlikely(ret < 0))
388 return ret; 330 return ret;
389 } 331 }
390 332
391 ret = functionfs_add(c->cdev, c, gfs_ffs_data); 333 ret = functionfs_bind_config(c->cdev, c, gfs_ffs_data);
392 if (unlikely(ret < 0)) 334 if (unlikely(ret < 0))
393 return ret; 335 return ret;
394 336
@@ -406,32 +348,12 @@ static int __gfs_do_config(struct usb_configuration *c,
406 return 0; 348 return 0;
407} 349}
408 350
409#ifdef CONFIG_USB_FUNCTIONFS_RNDIS
410static int gfs_do_rndis_config(struct usb_configuration *c)
411{
412 ENTER();
413
414 return __gfs_do_config(c, rndis_bind_config, gfs_hostaddr);
415}
416#endif
417 351
418#ifdef CONFIG_USB_FUNCTIONFS_ETH 352#ifdef CONFIG_USB_FUNCTIONFS_ETH
419static int gfs_do_ecm_config(struct usb_configuration *c) 353static int eth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN])
420{
421 ENTER();
422
423 return __gfs_do_config(c,
424 can_support_ecm(c->cdev->gadget)
425 ? ecm_bind_config : geth_bind_config,
426 gfs_hostaddr);
427}
428#endif
429
430#ifdef CONFIG_USB_FUNCTIONFS_GENERIC
431static int gfs_do_generic_config(struct usb_configuration *c)
432{ 354{
433 ENTER(); 355 return can_support_ecm(c->cdev->gadget)
434 356 ? ecm_bind_config(c, ethaddr)
435 return __gfs_do_config(c, NULL, NULL); 357 : geth_bind_config(c, ethaddr);
436} 358}
437#endif 359#endif
diff --git a/drivers/usb/gadget/gmidi.c b/drivers/usb/gadget/gmidi.c
index b7bf88019b06..1b413a5cc3f6 100644
--- a/drivers/usb/gadget/gmidi.c
+++ b/drivers/usb/gadget/gmidi.c
@@ -1157,7 +1157,7 @@ fail:
1157/* 1157/*
1158 * Creates an output endpoint, and initializes output ports. 1158 * Creates an output endpoint, and initializes output ports.
1159 */ 1159 */
1160static int __init gmidi_bind(struct usb_gadget *gadget) 1160static int __ref gmidi_bind(struct usb_gadget *gadget)
1161{ 1161{
1162 struct gmidi_device *dev; 1162 struct gmidi_device *dev;
1163 struct usb_ep *in_ep, *out_ep; 1163 struct usb_ep *in_ep, *out_ep;
diff --git a/drivers/usb/gadget/hid.c b/drivers/usb/gadget/hid.c
index 775722686ed8..735495bf8411 100644
--- a/drivers/usb/gadget/hid.c
+++ b/drivers/usb/gadget/hid.c
@@ -127,7 +127,7 @@ static struct usb_gadget_strings *dev_strings[] = {
127 127
128/****************************** Configurations ******************************/ 128/****************************** Configurations ******************************/
129 129
130static int __init do_config(struct usb_configuration *c) 130static int __ref do_config(struct usb_configuration *c)
131{ 131{
132 struct hidg_func_node *e; 132 struct hidg_func_node *e;
133 int func = 0, status = 0; 133 int func = 0, status = 0;
@@ -156,7 +156,7 @@ static struct usb_configuration config_driver = {
156 156
157/****************************** Gadget Bind ******************************/ 157/****************************** Gadget Bind ******************************/
158 158
159static int __init hid_bind(struct usb_composite_dev *cdev) 159static int __ref hid_bind(struct usb_composite_dev *cdev)
160{ 160{
161 struct usb_gadget *gadget = cdev->gadget; 161 struct usb_gadget *gadget = cdev->gadget;
162 struct list_head *tmp; 162 struct list_head *tmp;
diff --git a/drivers/usb/gadget/inode.c b/drivers/usb/gadget/inode.c
index de8a83803505..fc35406fc80c 100644
--- a/drivers/usb/gadget/inode.c
+++ b/drivers/usb/gadget/inode.c
@@ -1299,11 +1299,9 @@ static long dev_ioctl (struct file *fd, unsigned code, unsigned long value)
1299 struct usb_gadget *gadget = dev->gadget; 1299 struct usb_gadget *gadget = dev->gadget;
1300 long ret = -ENOTTY; 1300 long ret = -ENOTTY;
1301 1301
1302 if (gadget->ops->ioctl) { 1302 if (gadget->ops->ioctl)
1303 lock_kernel();
1304 ret = gadget->ops->ioctl (gadget, code, value); 1303 ret = gadget->ops->ioctl (gadget, code, value);
1305 unlock_kernel(); 1304
1306 }
1307 return ret; 1305 return ret;
1308} 1306}
1309 1307
@@ -1867,13 +1865,9 @@ dev_config (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
1867 buf += 4; 1865 buf += 4;
1868 length -= 4; 1866 length -= 4;
1869 1867
1870 kbuf = kmalloc (length, GFP_KERNEL); 1868 kbuf = memdup_user(buf, length);
1871 if (!kbuf) 1869 if (IS_ERR(kbuf))
1872 return -ENOMEM; 1870 return PTR_ERR(kbuf);
1873 if (copy_from_user (kbuf, buf, length)) {
1874 kfree (kbuf);
1875 return -EFAULT;
1876 }
1877 1871
1878 spin_lock_irq (&dev->lock); 1872 spin_lock_irq (&dev->lock);
1879 value = -EINVAL; 1873 value = -EINVAL;
diff --git a/drivers/usb/gadget/langwell_udc.c b/drivers/usb/gadget/langwell_udc.c
index a3913519fd58..c2d2a201f84b 100644
--- a/drivers/usb/gadget/langwell_udc.c
+++ b/drivers/usb/gadget/langwell_udc.c
@@ -842,9 +842,9 @@ static int langwell_ep_queue(struct usb_ep *_ep, struct usb_request *_req,
842 VDBG(dev, "req->mapped = 0\n"); 842 VDBG(dev, "req->mapped = 0\n");
843 } 843 }
844 844
845 DBG(dev, "%s queue req %p, len %u, buf %p, dma 0x%08x\n", 845 DBG(dev, "%s queue req %p, len %u, buf %p, dma 0x%08llx\n",
846 _ep->name, 846 _ep->name,
847 _req, _req->length, _req->buf, _req->dma); 847 _req, _req->length, _req->buf, (unsigned long long)_req->dma);
848 848
849 _req->status = -EINPROGRESS; 849 _req->status = -EINPROGRESS;
850 _req->actual = 0; 850 _req->actual = 0;
diff --git a/drivers/usb/gadget/mass_storage.c b/drivers/usb/gadget/mass_storage.c
index 705cc1f76327..585f2559484d 100644
--- a/drivers/usb/gadget/mass_storage.c
+++ b/drivers/usb/gadget/mass_storage.c
@@ -141,9 +141,14 @@ static int msg_thread_exits(struct fsg_common *common)
141 return 0; 141 return 0;
142} 142}
143 143
144static int __init msg_do_config(struct usb_configuration *c) 144static int __ref msg_do_config(struct usb_configuration *c)
145{ 145{
146 struct fsg_common *common; 146 static const struct fsg_operations ops = {
147 .thread_exits = msg_thread_exits,
148 };
149 static struct fsg_common common;
150
151 struct fsg_common *retp;
147 struct fsg_config config; 152 struct fsg_config config;
148 int ret; 153 int ret;
149 154
@@ -153,13 +158,14 @@ static int __init msg_do_config(struct usb_configuration *c)
153 } 158 }
154 159
155 fsg_config_from_params(&config, &mod_data); 160 fsg_config_from_params(&config, &mod_data);
156 config.thread_exits = msg_thread_exits; 161 config.ops = &ops;
157 common = fsg_common_init(0, c->cdev, &config); 162
158 if (IS_ERR(common)) 163 retp = fsg_common_init(&common, c->cdev, &config);
159 return PTR_ERR(common); 164 if (IS_ERR(retp))
165 return PTR_ERR(retp);
160 166
161 ret = fsg_add(c->cdev, c, common); 167 ret = fsg_bind_config(c->cdev, c, &common);
162 fsg_common_put(common); 168 fsg_common_put(&common);
163 return ret; 169 return ret;
164} 170}
165 171
@@ -176,7 +182,7 @@ static struct usb_configuration msg_config_driver = {
176/****************************** Gadget Bind ******************************/ 182/****************************** Gadget Bind ******************************/
177 183
178 184
179static int __init msg_bind(struct usb_composite_dev *cdev) 185static int __ref msg_bind(struct usb_composite_dev *cdev)
180{ 186{
181 struct usb_gadget *gadget = cdev->gadget; 187 struct usb_gadget *gadget = cdev->gadget;
182 int status; 188 int status;
diff --git a/drivers/usb/gadget/multi.c b/drivers/usb/gadget/multi.c
index a930d7fd7e7a..795d76232167 100644
--- a/drivers/usb/gadget/multi.c
+++ b/drivers/usb/gadget/multi.c
@@ -24,6 +24,7 @@
24 24
25#include <linux/kernel.h> 25#include <linux/kernel.h>
26#include <linux/utsname.h> 26#include <linux/utsname.h>
27#include <linux/module.h>
27 28
28 29
29#if defined USB_ETH_RNDIS 30#if defined USB_ETH_RNDIS
@@ -35,14 +36,13 @@
35 36
36 37
37#define DRIVER_DESC "Multifunction Composite Gadget" 38#define DRIVER_DESC "Multifunction Composite Gadget"
38#define DRIVER_VERSION "2009/07/21"
39 39
40/*-------------------------------------------------------------------------*/ 40MODULE_DESCRIPTION(DRIVER_DESC);
41MODULE_AUTHOR("Michal Nazarewicz");
42MODULE_LICENSE("GPL");
41 43
42#define MULTI_VENDOR_NUM 0x0525 /* XXX NetChip */
43#define MULTI_PRODUCT_NUM 0xa4ab /* XXX */
44 44
45/*-------------------------------------------------------------------------*/ 45/***************************** All the files... *****************************/
46 46
47/* 47/*
48 * kbuild is not very cooperative with respect to linking separately 48 * kbuild is not very cooperative with respect to linking separately
@@ -57,6 +57,8 @@
57#include "config.c" 57#include "config.c"
58#include "epautoconf.c" 58#include "epautoconf.c"
59 59
60#include "f_mass_storage.c"
61
60#include "u_serial.c" 62#include "u_serial.c"
61#include "f_acm.c" 63#include "f_acm.c"
62 64
@@ -68,13 +70,24 @@
68#endif 70#endif
69#include "u_ether.c" 71#include "u_ether.c"
70 72
71#undef DBG /* u_ether.c has broken idea about macros */
72#undef VDBG /* so clean up after it */
73#undef ERROR
74#undef INFO
75#include "f_mass_storage.c"
76 73
77/*-------------------------------------------------------------------------*/ 74
75/***************************** Device Descriptor ****************************/
76
77#define MULTI_VENDOR_NUM 0x0525 /* XXX NetChip */
78#define MULTI_PRODUCT_NUM 0xa4ab /* XXX */
79
80
81enum {
82 __MULTI_NO_CONFIG,
83#ifdef CONFIG_USB_G_MULTI_RNDIS
84 MULTI_RNDIS_CONFIG_NUM,
85#endif
86#ifdef CONFIG_USB_G_MULTI_CDC
87 MULTI_CDC_CONFIG_NUM,
88#endif
89};
90
78 91
79static struct usb_device_descriptor device_desc = { 92static struct usb_device_descriptor device_desc = {
80 .bLength = sizeof device_desc, 93 .bLength = sizeof device_desc,
@@ -82,80 +95,82 @@ static struct usb_device_descriptor device_desc = {
82 95
83 .bcdUSB = cpu_to_le16(0x0200), 96 .bcdUSB = cpu_to_le16(0x0200),
84 97
85 /* .bDeviceClass = USB_CLASS_COMM, */ 98 .bDeviceClass = USB_CLASS_MISC /* 0xEF */,
86 /* .bDeviceSubClass = 0, */
87 /* .bDeviceProtocol = 0, */
88 .bDeviceClass = 0xEF,
89 .bDeviceSubClass = 2, 99 .bDeviceSubClass = 2,
90 .bDeviceProtocol = 1, 100 .bDeviceProtocol = 1,
91 /* .bMaxPacketSize0 = f(hardware) */
92 101
93 /* Vendor and product id can be overridden by module parameters. */ 102 /* Vendor and product id can be overridden by module parameters. */
94 .idVendor = cpu_to_le16(MULTI_VENDOR_NUM), 103 .idVendor = cpu_to_le16(MULTI_VENDOR_NUM),
95 .idProduct = cpu_to_le16(MULTI_PRODUCT_NUM), 104 .idProduct = cpu_to_le16(MULTI_PRODUCT_NUM),
96 /* .bcdDevice = f(hardware) */
97 /* .iManufacturer = DYNAMIC */
98 /* .iProduct = DYNAMIC */
99 /* NO SERIAL NUMBER */
100 .bNumConfigurations = 1,
101}; 105};
102 106
103static struct usb_otg_descriptor otg_descriptor = {
104 .bLength = sizeof otg_descriptor,
105 .bDescriptorType = USB_DT_OTG,
106
107 /* REVISIT SRP-only hardware is possible, although
108 * it would not be called "OTG" ...
109 */
110 .bmAttributes = USB_OTG_SRP | USB_OTG_HNP,
111};
112 107
113static const struct usb_descriptor_header *otg_desc[] = { 108static const struct usb_descriptor_header *otg_desc[] = {
114 (struct usb_descriptor_header *) &otg_descriptor, 109 (struct usb_descriptor_header *) &(struct usb_otg_descriptor){
110 .bLength = sizeof(struct usb_otg_descriptor),
111 .bDescriptorType = USB_DT_OTG,
112
113 /*
114 * REVISIT SRP-only hardware is possible, although
115 * it would not be called "OTG" ...
116 */
117 .bmAttributes = USB_OTG_SRP | USB_OTG_HNP,
118 },
115 NULL, 119 NULL,
116}; 120};
117 121
118 122
119/* string IDs are assigned dynamically */ 123enum {
120 124 MULTI_STRING_MANUFACTURER_IDX,
121#define STRING_MANUFACTURER_IDX 0 125 MULTI_STRING_PRODUCT_IDX,
122#define STRING_PRODUCT_IDX 1 126#ifdef CONFIG_USB_G_MULTI_RNDIS
127 MULTI_STRING_RNDIS_CONFIG_IDX,
128#endif
129#ifdef CONFIG_USB_G_MULTI_CDC
130 MULTI_STRING_CDC_CONFIG_IDX,
131#endif
132};
123 133
124static char manufacturer[50]; 134static char manufacturer[50];
125 135
126static struct usb_string strings_dev[] = { 136static struct usb_string strings_dev[] = {
127 [STRING_MANUFACTURER_IDX].s = manufacturer, 137 [MULTI_STRING_MANUFACTURER_IDX].s = manufacturer,
128 [STRING_PRODUCT_IDX].s = DRIVER_DESC, 138 [MULTI_STRING_PRODUCT_IDX].s = DRIVER_DESC,
139#ifdef CONFIG_USB_G_MULTI_RNDIS
140 [MULTI_STRING_RNDIS_CONFIG_IDX].s = "Multifunction with RNDIS",
141#endif
142#ifdef CONFIG_USB_G_MULTI_CDC
143 [MULTI_STRING_CDC_CONFIG_IDX].s = "Multifunction with CDC ECM",
144#endif
129 { } /* end of list */ 145 { } /* end of list */
130}; 146};
131 147
132static struct usb_gadget_strings stringtab_dev = {
133 .language = 0x0409, /* en-us */
134 .strings = strings_dev,
135};
136
137static struct usb_gadget_strings *dev_strings[] = { 148static struct usb_gadget_strings *dev_strings[] = {
138 &stringtab_dev, 149 &(struct usb_gadget_strings){
150 .language = 0x0409, /* en-us */
151 .strings = strings_dev,
152 },
139 NULL, 153 NULL,
140}; 154};
141 155
142static u8 hostaddr[ETH_ALEN];
143 156
144 157
145 158
146/****************************** Configurations ******************************/ 159/****************************** Configurations ******************************/
147 160
148static struct fsg_module_parameters mod_data = { 161static struct fsg_module_parameters fsg_mod_data = { .stall = 1 };
149 .stall = 1 162FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data);
150}; 163
151FSG_MODULE_PARAMETERS(/* no prefix */, mod_data); 164static struct fsg_common fsg_common;
165
166static u8 hostaddr[ETH_ALEN];
152 167
153static struct fsg_common *fsg_common;
154 168
169/********** RNDIS **********/
155 170
156#ifdef USB_ETH_RNDIS 171#ifdef USB_ETH_RNDIS
157 172
158static int __init rndis_do_config(struct usb_configuration *c) 173static __ref int rndis_do_config(struct usb_configuration *c)
159{ 174{
160 int ret; 175 int ret;
161 176
@@ -172,26 +187,42 @@ static int __init rndis_do_config(struct usb_configuration *c)
172 if (ret < 0) 187 if (ret < 0)
173 return ret; 188 return ret;
174 189
175 ret = fsg_add(c->cdev, c, fsg_common); 190 ret = fsg_bind_config(c->cdev, c, &fsg_common);
176 if (ret < 0) 191 if (ret < 0)
177 return ret; 192 return ret;
178 193
179 return 0; 194 return 0;
180} 195}
181 196
182static struct usb_configuration rndis_config_driver = { 197static int rndis_config_register(struct usb_composite_dev *cdev)
183 .label = "Multifunction Composite (RNDIS + MS + ACM)", 198{
184 .bind = rndis_do_config, 199 static struct usb_configuration config = {
185 .bConfigurationValue = 2, 200 .bind = rndis_do_config,
186 /* .iConfiguration = DYNAMIC */ 201 .bConfigurationValue = MULTI_RNDIS_CONFIG_NUM,
187 .bmAttributes = USB_CONFIG_ATT_SELFPOWER, 202 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
188}; 203 };
204
205 config.label = strings_dev[MULTI_STRING_RNDIS_CONFIG_IDX].s;
206 config.iConfiguration = strings_dev[MULTI_STRING_RNDIS_CONFIG_IDX].id;
207
208 return usb_add_config(cdev, &config);
209}
210
211#else
212
213static int rndis_config_register(struct usb_composite_dev *cdev)
214{
215 return 0;
216}
189 217
190#endif 218#endif
191 219
220
221/********** CDC ECM **********/
222
192#ifdef CONFIG_USB_G_MULTI_CDC 223#ifdef CONFIG_USB_G_MULTI_CDC
193 224
194static int __init cdc_do_config(struct usb_configuration *c) 225static __ref int cdc_do_config(struct usb_configuration *c)
195{ 226{
196 int ret; 227 int ret;
197 228
@@ -208,20 +239,33 @@ static int __init cdc_do_config(struct usb_configuration *c)
208 if (ret < 0) 239 if (ret < 0)
209 return ret; 240 return ret;
210 241
211 ret = fsg_add(c->cdev, c, fsg_common); 242 ret = fsg_bind_config(c->cdev, c, &fsg_common);
212 if (ret < 0) 243 if (ret < 0)
213 return ret; 244 return ret;
214 245
215 return 0; 246 return 0;
216} 247}
217 248
218static struct usb_configuration cdc_config_driver = { 249static int cdc_config_register(struct usb_composite_dev *cdev)
219 .label = "Multifunction Composite (CDC + MS + ACM)", 250{
220 .bind = cdc_do_config, 251 static struct usb_configuration config = {
221 .bConfigurationValue = 1, 252 .bind = cdc_do_config,
222 /* .iConfiguration = DYNAMIC */ 253 .bConfigurationValue = MULTI_CDC_CONFIG_NUM,
223 .bmAttributes = USB_CONFIG_ATT_SELFPOWER, 254 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
224}; 255 };
256
257 config.label = strings_dev[MULTI_STRING_CDC_CONFIG_IDX].s;
258 config.iConfiguration = strings_dev[MULTI_STRING_CDC_CONFIG_IDX].id;
259
260 return usb_add_config(cdev, &config);
261}
262
263#else
264
265static int cdc_config_register(struct usb_composite_dev *cdev)
266{
267 return 0;
268}
225 269
226#endif 270#endif
227 271
@@ -230,7 +274,7 @@ static struct usb_configuration cdc_config_driver = {
230/****************************** Gadget Bind ******************************/ 274/****************************** Gadget Bind ******************************/
231 275
232 276
233static int __init multi_bind(struct usb_composite_dev *cdev) 277static int __ref multi_bind(struct usb_composite_dev *cdev)
234{ 278{
235 struct usb_gadget *gadget = cdev->gadget; 279 struct usb_gadget *gadget = cdev->gadget;
236 int status, gcnum; 280 int status, gcnum;
@@ -252,67 +296,56 @@ static int __init multi_bind(struct usb_composite_dev *cdev)
252 goto fail0; 296 goto fail0;
253 297
254 /* set up mass storage function */ 298 /* set up mass storage function */
255 fsg_common = fsg_common_from_params(0, cdev, &mod_data); 299 {
256 if (IS_ERR(fsg_common)) { 300 void *retp;
257 status = PTR_ERR(fsg_common); 301 retp = fsg_common_from_params(&fsg_common, cdev, &fsg_mod_data);
258 goto fail1; 302 if (IS_ERR(retp)) {
303 status = PTR_ERR(retp);
304 goto fail1;
305 }
259 } 306 }
260 307
261 308 /* set bcdDevice */
262 gcnum = usb_gadget_controller_number(gadget); 309 gcnum = usb_gadget_controller_number(gadget);
263 if (gcnum >= 0) 310 if (gcnum >= 0) {
264 device_desc.bcdDevice = cpu_to_le16(0x0300 | gcnum); 311 device_desc.bcdDevice = cpu_to_le16(0x0300 | gcnum);
265 else { 312 } else {
266 /* We assume that can_support_ecm() tells the truth; 313 WARNING(cdev, "controller '%s' not recognized\n", gadget->name);
267 * but if the controller isn't recognized at all then
268 * that assumption is a bit more likely to be wrong.
269 */
270 WARNING(cdev, "controller '%s' not recognized\n",
271 gadget->name);
272 device_desc.bcdDevice = cpu_to_le16(0x0300 | 0x0099); 314 device_desc.bcdDevice = cpu_to_le16(0x0300 | 0x0099);
273 } 315 }
274 316
275 317 /* allocate string descriptor numbers */
276 /* Allocate string descriptor numbers ... note that string
277 * contents can be overridden by the composite_dev glue.
278 */
279
280 /* device descriptor strings: manufacturer, product */
281 snprintf(manufacturer, sizeof manufacturer, "%s %s with %s", 318 snprintf(manufacturer, sizeof manufacturer, "%s %s with %s",
282 init_utsname()->sysname, init_utsname()->release, 319 init_utsname()->sysname, init_utsname()->release,
283 gadget->name); 320 gadget->name);
284 status = usb_string_id(cdev);
285 if (status < 0)
286 goto fail2;
287 strings_dev[STRING_MANUFACTURER_IDX].id = status;
288 device_desc.iManufacturer = status;
289 321
290 status = usb_string_id(cdev); 322 status = usb_string_ids_tab(cdev, strings_dev);
291 if (status < 0) 323 if (unlikely(status < 0))
292 goto fail2; 324 goto fail2;
293 strings_dev[STRING_PRODUCT_IDX].id = status;
294 device_desc.iProduct = status;
295 325
296#ifdef USB_ETH_RNDIS 326 device_desc.iManufacturer =
297 /* register our first configuration */ 327 strings_dev[MULTI_STRING_MANUFACTURER_IDX].id;
298 status = usb_add_config(cdev, &rndis_config_driver); 328 device_desc.iProduct =
299 if (status < 0) 329 strings_dev[MULTI_STRING_PRODUCT_IDX].id;
330
331 /* register configurations */
332 status = rndis_config_register(cdev);
333 if (unlikely(status < 0))
300 goto fail2; 334 goto fail2;
301#endif
302 335
303#ifdef CONFIG_USB_G_MULTI_CDC 336 status = cdc_config_register(cdev);
304 /* register our second configuration */ 337 if (unlikely(status < 0))
305 status = usb_add_config(cdev, &cdc_config_driver);
306 if (status < 0)
307 goto fail2; 338 goto fail2;
308#endif
309 339
310 dev_info(&gadget->dev, DRIVER_DESC ", version: " DRIVER_VERSION "\n"); 340 /* we're done */
311 fsg_common_put(fsg_common); 341 dev_info(&gadget->dev, DRIVER_DESC "\n");
342 fsg_common_put(&fsg_common);
312 return 0; 343 return 0;
313 344
345
346 /* error recovery */
314fail2: 347fail2:
315 fsg_common_put(fsg_common); 348 fsg_common_put(&fsg_common);
316fail1: 349fail1:
317 gserial_cleanup(); 350 gserial_cleanup();
318fail0: 351fail0:
@@ -339,18 +372,15 @@ static struct usb_composite_driver multi_driver = {
339 .unbind = __exit_p(multi_unbind), 372 .unbind = __exit_p(multi_unbind),
340}; 373};
341 374
342MODULE_DESCRIPTION(DRIVER_DESC);
343MODULE_AUTHOR("Michal Nazarewicz");
344MODULE_LICENSE("GPL");
345 375
346static int __init g_multi_init(void) 376static int __init multi_init(void)
347{ 377{
348 return usb_composite_register(&multi_driver); 378 return usb_composite_register(&multi_driver);
349} 379}
350module_init(g_multi_init); 380module_init(multi_init);
351 381
352static void __exit g_multi_cleanup(void) 382static void __exit multi_exit(void)
353{ 383{
354 usb_composite_unregister(&multi_driver); 384 usb_composite_unregister(&multi_driver);
355} 385}
356module_exit(g_multi_cleanup); 386module_exit(multi_exit);
diff --git a/drivers/usb/gadget/printer.c b/drivers/usb/gadget/printer.c
index 4c3ac5c42237..cf241c371a71 100644
--- a/drivers/usb/gadget/printer.c
+++ b/drivers/usb/gadget/printer.c
@@ -25,7 +25,7 @@
25#include <linux/ioport.h> 25#include <linux/ioport.h>
26#include <linux/sched.h> 26#include <linux/sched.h>
27#include <linux/slab.h> 27#include <linux/slab.h>
28#include <linux/smp_lock.h> 28#include <linux/mutex.h>
29#include <linux/errno.h> 29#include <linux/errno.h>
30#include <linux/init.h> 30#include <linux/init.h>
31#include <linux/timer.h> 31#include <linux/timer.h>
@@ -70,6 +70,7 @@
70#define DRIVER_DESC "Printer Gadget" 70#define DRIVER_DESC "Printer Gadget"
71#define DRIVER_VERSION "2007 OCT 06" 71#define DRIVER_VERSION "2007 OCT 06"
72 72
73static DEFINE_MUTEX(printer_mutex);
73static const char shortname [] = "printer"; 74static const char shortname [] = "printer";
74static const char driver_desc [] = DRIVER_DESC; 75static const char driver_desc [] = DRIVER_DESC;
75 76
@@ -476,7 +477,7 @@ printer_open(struct inode *inode, struct file *fd)
476 unsigned long flags; 477 unsigned long flags;
477 int ret = -EBUSY; 478 int ret = -EBUSY;
478 479
479 lock_kernel(); 480 mutex_lock(&printer_mutex);
480 dev = container_of(inode->i_cdev, struct printer_dev, printer_cdev); 481 dev = container_of(inode->i_cdev, struct printer_dev, printer_cdev);
481 482
482 spin_lock_irqsave(&dev->lock, flags); 483 spin_lock_irqsave(&dev->lock, flags);
@@ -492,7 +493,7 @@ printer_open(struct inode *inode, struct file *fd)
492 spin_unlock_irqrestore(&dev->lock, flags); 493 spin_unlock_irqrestore(&dev->lock, flags);
493 494
494 DBG(dev, "printer_open returned %x\n", ret); 495 DBG(dev, "printer_open returned %x\n", ret);
495 unlock_kernel(); 496 mutex_unlock(&printer_mutex);
496 return ret; 497 return ret;
497} 498}
498 499
@@ -1346,7 +1347,7 @@ printer_unbind(struct usb_gadget *gadget)
1346 set_gadget_data(gadget, NULL); 1347 set_gadget_data(gadget, NULL);
1347} 1348}
1348 1349
1349static int __init 1350static int __ref
1350printer_bind(struct usb_gadget *gadget) 1351printer_bind(struct usb_gadget *gadget)
1351{ 1352{
1352 struct printer_dev *dev; 1353 struct printer_dev *dev;
diff --git a/drivers/usb/gadget/s3c-hsotg.c b/drivers/usb/gadget/s3c-hsotg.c
index 26193eceb323..521ebed0118d 100644
--- a/drivers/usb/gadget/s3c-hsotg.c
+++ b/drivers/usb/gadget/s3c-hsotg.c
@@ -12,6 +12,8 @@
12 * published by the Free Software Foundation. 12 * published by the Free Software Foundation.
13*/ 13*/
14 14
15#define DEBUG
16
15#include <linux/kernel.h> 17#include <linux/kernel.h>
16#include <linux/module.h> 18#include <linux/module.h>
17#include <linux/spinlock.h> 19#include <linux/spinlock.h>
@@ -23,6 +25,7 @@
23#include <linux/delay.h> 25#include <linux/delay.h>
24#include <linux/io.h> 26#include <linux/io.h>
25#include <linux/slab.h> 27#include <linux/slab.h>
28#include <linux/clk.h>
26 29
27#include <linux/usb/ch9.h> 30#include <linux/usb/ch9.h>
28#include <linux/usb/gadget.h> 31#include <linux/usb/gadget.h>
@@ -33,6 +36,7 @@
33#include <plat/regs-usb-hsotg.h> 36#include <plat/regs-usb-hsotg.h>
34#include <mach/regs-sys.h> 37#include <mach/regs-sys.h>
35#include <plat/udc-hs.h> 38#include <plat/udc-hs.h>
39#include <plat/cpu.h>
36 40
37#define DMA_ADDR_INVALID (~((dma_addr_t)0)) 41#define DMA_ADDR_INVALID (~((dma_addr_t)0))
38 42
@@ -91,7 +95,9 @@ struct s3c_hsotg_req;
91 * For periodic IN endpoints, we have fifo_size and fifo_load to try 95 * For periodic IN endpoints, we have fifo_size and fifo_load to try
92 * and keep track of the amount of data in the periodic FIFO for each 96 * and keep track of the amount of data in the periodic FIFO for each
93 * of these as we don't have a status register that tells us how much 97 * of these as we don't have a status register that tells us how much
94 * is in each of them. 98 * is in each of them. (note, this may actually be useless information
99 * as in shared-fifo mode periodic in acts like a single-frame packet
100 * buffer than a fifo)
95 */ 101 */
96struct s3c_hsotg_ep { 102struct s3c_hsotg_ep {
97 struct usb_ep ep; 103 struct usb_ep ep;
@@ -128,6 +134,7 @@ struct s3c_hsotg_ep {
128 * @regs: The memory area mapped for accessing registers. 134 * @regs: The memory area mapped for accessing registers.
129 * @regs_res: The resource that was allocated when claiming register space. 135 * @regs_res: The resource that was allocated when claiming register space.
130 * @irq: The IRQ number we are using 136 * @irq: The IRQ number we are using
137 * @dedicated_fifos: Set if the hardware has dedicated IN-EP fifos.
131 * @debug_root: root directrory for debugfs. 138 * @debug_root: root directrory for debugfs.
132 * @debug_file: main status file for debugfs. 139 * @debug_file: main status file for debugfs.
133 * @debug_fifo: FIFO status file for debugfs. 140 * @debug_fifo: FIFO status file for debugfs.
@@ -145,6 +152,9 @@ struct s3c_hsotg {
145 void __iomem *regs; 152 void __iomem *regs;
146 struct resource *regs_res; 153 struct resource *regs_res;
147 int irq; 154 int irq;
155 struct clk *clk;
156
157 unsigned int dedicated_fifos:1;
148 158
149 struct dentry *debug_root; 159 struct dentry *debug_root;
150 struct dentry *debug_file; 160 struct dentry *debug_file;
@@ -310,11 +320,11 @@ static void s3c_hsotg_init_fifo(struct s3c_hsotg *hsotg)
310 hsotg->regs + S3C_GNPTXFSIZ); 320 hsotg->regs + S3C_GNPTXFSIZ);
311 */ 321 */
312 322
313 /* set FIFO sizes to 2048/0x1C0 */ 323 /* set FIFO sizes to 2048/1024 */
314 324
315 writel(2048, hsotg->regs + S3C_GRXFSIZ); 325 writel(2048, hsotg->regs + S3C_GRXFSIZ);
316 writel(S3C_GNPTXFSIZ_NPTxFStAddr(2048) | 326 writel(S3C_GNPTXFSIZ_NPTxFStAddr(2048) |
317 S3C_GNPTXFSIZ_NPTxFDep(0x1C0), 327 S3C_GNPTXFSIZ_NPTxFDep(1024),
318 hsotg->regs + S3C_GNPTXFSIZ); 328 hsotg->regs + S3C_GNPTXFSIZ);
319 329
320 /* arange all the rest of the TX FIFOs, as some versions of this 330 /* arange all the rest of the TX FIFOs, as some versions of this
@@ -464,7 +474,7 @@ static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg,
464 if (to_write == 0) 474 if (to_write == 0)
465 return 0; 475 return 0;
466 476
467 if (periodic) { 477 if (periodic && !hsotg->dedicated_fifos) {
468 u32 epsize = readl(hsotg->regs + S3C_DIEPTSIZ(hs_ep->index)); 478 u32 epsize = readl(hsotg->regs + S3C_DIEPTSIZ(hs_ep->index));
469 int size_left; 479 int size_left;
470 int size_done; 480 int size_done;
@@ -474,6 +484,14 @@ static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg,
474 484
475 size_left = S3C_DxEPTSIZ_XferSize_GET(epsize); 485 size_left = S3C_DxEPTSIZ_XferSize_GET(epsize);
476 486
487 /* if shared fifo, we cannot write anything until the
488 * previous data has been completely sent.
489 */
490 if (hs_ep->fifo_load != 0) {
491 s3c_hsotg_en_gsint(hsotg, S3C_GINTSTS_PTxFEmp);
492 return -ENOSPC;
493 }
494
477 dev_dbg(hsotg->dev, "%s: left=%d, load=%d, fifo=%d, size %d\n", 495 dev_dbg(hsotg->dev, "%s: left=%d, load=%d, fifo=%d, size %d\n",
478 __func__, size_left, 496 __func__, size_left,
479 hs_ep->size_loaded, hs_ep->fifo_load, hs_ep->fifo_size); 497 hs_ep->size_loaded, hs_ep->fifo_load, hs_ep->fifo_size);
@@ -494,6 +512,11 @@ static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg,
494 s3c_hsotg_en_gsint(hsotg, S3C_GINTSTS_PTxFEmp); 512 s3c_hsotg_en_gsint(hsotg, S3C_GINTSTS_PTxFEmp);
495 return -ENOSPC; 513 return -ENOSPC;
496 } 514 }
515 } else if (hsotg->dedicated_fifos && hs_ep->index != 0) {
516 can_write = readl(hsotg->regs + S3C_DTXFSTS(hs_ep->index));
517
518 can_write &= 0xffff;
519 can_write *= 4;
497 } else { 520 } else {
498 if (S3C_GNPTXSTS_NPTxQSpcAvail_GET(gnptxsts) == 0) { 521 if (S3C_GNPTXSTS_NPTxQSpcAvail_GET(gnptxsts) == 0) {
499 dev_dbg(hsotg->dev, 522 dev_dbg(hsotg->dev,
@@ -505,6 +528,7 @@ static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg,
505 } 528 }
506 529
507 can_write = S3C_GNPTXSTS_NPTxFSpcAvail_GET(gnptxsts); 530 can_write = S3C_GNPTXSTS_NPTxFSpcAvail_GET(gnptxsts);
531 can_write *= 4; /* fifo size is in 32bit quantities. */
508 } 532 }
509 533
510 dev_dbg(hsotg->dev, "%s: GNPTXSTS=%08x, can=%d, to=%d, mps %d\n", 534 dev_dbg(hsotg->dev, "%s: GNPTXSTS=%08x, can=%d, to=%d, mps %d\n",
@@ -517,6 +541,17 @@ static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg,
517 if (can_write > 512) 541 if (can_write > 512)
518 can_write = 512; 542 can_write = 512;
519 543
544 /* limit the write to one max-packet size worth of data, but allow
545 * the transfer to return that it did not run out of fifo space
546 * doing it. */
547 if (to_write > hs_ep->ep.maxpacket) {
548 to_write = hs_ep->ep.maxpacket;
549
550 s3c_hsotg_en_gsint(hsotg,
551 periodic ? S3C_GINTSTS_PTxFEmp :
552 S3C_GINTSTS_NPTxFEmp);
553 }
554
520 /* see if we can write data */ 555 /* see if we can write data */
521 556
522 if (to_write > can_write) { 557 if (to_write > can_write) {
@@ -579,12 +614,10 @@ static unsigned get_ep_limit(struct s3c_hsotg_ep *hs_ep)
579 maxsize = S3C_DxEPTSIZ_XferSize_LIMIT + 1; 614 maxsize = S3C_DxEPTSIZ_XferSize_LIMIT + 1;
580 maxpkt = S3C_DxEPTSIZ_PktCnt_LIMIT + 1; 615 maxpkt = S3C_DxEPTSIZ_PktCnt_LIMIT + 1;
581 } else { 616 } else {
617 maxsize = 64+64;
582 if (hs_ep->dir_in) { 618 if (hs_ep->dir_in) {
583 /* maxsize = S3C_DIEPTSIZ0_XferSize_LIMIT + 1; */
584 maxsize = 64+64+1;
585 maxpkt = S3C_DIEPTSIZ0_PktCnt_LIMIT + 1; 619 maxpkt = S3C_DIEPTSIZ0_PktCnt_LIMIT + 1;
586 } else { 620 } else {
587 maxsize = 0x3f;
588 maxpkt = 2; 621 maxpkt = 2;
589 } 622 }
590 } 623 }
@@ -1353,6 +1386,9 @@ static void s3c_hsotg_rx_data(struct s3c_hsotg *hsotg, int ep_idx, int size)
1353 read_ptr = hs_req->req.actual; 1386 read_ptr = hs_req->req.actual;
1354 max_req = hs_req->req.length - read_ptr; 1387 max_req = hs_req->req.length - read_ptr;
1355 1388
1389 dev_dbg(hsotg->dev, "%s: read %d/%d, done %d/%d\n",
1390 __func__, to_read, max_req, read_ptr, hs_req->req.length);
1391
1356 if (to_read > max_req) { 1392 if (to_read > max_req) {
1357 /* more data appeared than we where willing 1393 /* more data appeared than we where willing
1358 * to deal with in this request. 1394 * to deal with in this request.
@@ -1362,9 +1398,6 @@ static void s3c_hsotg_rx_data(struct s3c_hsotg *hsotg, int ep_idx, int size)
1362 WARN_ON_ONCE(1); 1398 WARN_ON_ONCE(1);
1363 } 1399 }
1364 1400
1365 dev_dbg(hsotg->dev, "%s: read %d/%d, done %d/%d\n",
1366 __func__, to_read, max_req, read_ptr, hs_req->req.length);
1367
1368 hs_ep->total_data += to_read; 1401 hs_ep->total_data += to_read;
1369 hs_req->req.actual += to_read; 1402 hs_req->req.actual += to_read;
1370 to_read = DIV_ROUND_UP(to_read, 4); 1403 to_read = DIV_ROUND_UP(to_read, 4);
@@ -1433,9 +1466,11 @@ static void s3c_hsotg_send_zlp(struct s3c_hsotg *hsotg,
1433static void s3c_hsotg_handle_outdone(struct s3c_hsotg *hsotg, 1466static void s3c_hsotg_handle_outdone(struct s3c_hsotg *hsotg,
1434 int epnum, bool was_setup) 1467 int epnum, bool was_setup)
1435{ 1468{
1469 u32 epsize = readl(hsotg->regs + S3C_DOEPTSIZ(epnum));
1436 struct s3c_hsotg_ep *hs_ep = &hsotg->eps[epnum]; 1470 struct s3c_hsotg_ep *hs_ep = &hsotg->eps[epnum];
1437 struct s3c_hsotg_req *hs_req = hs_ep->req; 1471 struct s3c_hsotg_req *hs_req = hs_ep->req;
1438 struct usb_request *req = &hs_req->req; 1472 struct usb_request *req = &hs_req->req;
1473 unsigned size_left = S3C_DxEPTSIZ_XferSize_GET(epsize);
1439 int result = 0; 1474 int result = 0;
1440 1475
1441 if (!hs_req) { 1476 if (!hs_req) {
@@ -1444,9 +1479,7 @@ static void s3c_hsotg_handle_outdone(struct s3c_hsotg *hsotg,
1444 } 1479 }
1445 1480
1446 if (using_dma(hsotg)) { 1481 if (using_dma(hsotg)) {
1447 u32 epsize = readl(hsotg->regs + S3C_DOEPTSIZ(epnum));
1448 unsigned size_done; 1482 unsigned size_done;
1449 unsigned size_left;
1450 1483
1451 /* Calculate the size of the transfer by checking how much 1484 /* Calculate the size of the transfer by checking how much
1452 * is left in the endpoint size register and then working it 1485 * is left in the endpoint size register and then working it
@@ -1456,14 +1489,18 @@ static void s3c_hsotg_handle_outdone(struct s3c_hsotg *hsotg,
1456 * so may overshoot/undershoot the transfer. 1489 * so may overshoot/undershoot the transfer.
1457 */ 1490 */
1458 1491
1459 size_left = S3C_DxEPTSIZ_XferSize_GET(epsize);
1460
1461 size_done = hs_ep->size_loaded - size_left; 1492 size_done = hs_ep->size_loaded - size_left;
1462 size_done += hs_ep->last_load; 1493 size_done += hs_ep->last_load;
1463 1494
1464 req->actual = size_done; 1495 req->actual = size_done;
1465 } 1496 }
1466 1497
1498 /* if there is more request to do, schedule new transfer */
1499 if (req->actual < req->length && size_left == 0) {
1500 s3c_hsotg_start_req(hsotg, hs_ep, hs_req, true);
1501 return;
1502 }
1503
1467 if (req->actual < req->length && req->short_not_ok) { 1504 if (req->actual < req->length && req->short_not_ok) {
1468 dev_dbg(hsotg->dev, "%s: got %d/%d (short not ok) => error\n", 1505 dev_dbg(hsotg->dev, "%s: got %d/%d (short not ok) => error\n",
1469 __func__, req->actual, req->length); 1506 __func__, req->actual, req->length);
@@ -1758,7 +1795,7 @@ static void s3c_hsotg_epint(struct s3c_hsotg *hsotg, unsigned int idx,
1758 if (dir_in) { 1795 if (dir_in) {
1759 s3c_hsotg_complete_in(hsotg, hs_ep); 1796 s3c_hsotg_complete_in(hsotg, hs_ep);
1760 1797
1761 if (idx == 0) 1798 if (idx == 0 && !hs_ep->req)
1762 s3c_hsotg_enqueue_setup(hsotg); 1799 s3c_hsotg_enqueue_setup(hsotg);
1763 } else if (using_dma(hsotg)) { 1800 } else if (using_dma(hsotg)) {
1764 /* We're using DMA, we need to fire an OutDone here 1801 /* We're using DMA, we need to fire an OutDone here
@@ -1818,6 +1855,15 @@ static void s3c_hsotg_epint(struct s3c_hsotg *hsotg, unsigned int idx,
1818 __func__, idx); 1855 __func__, idx);
1819 clear |= S3C_DIEPMSK_INTknEPMisMsk; 1856 clear |= S3C_DIEPMSK_INTknEPMisMsk;
1820 } 1857 }
1858
1859 /* FIFO has space or is empty (see GAHBCFG) */
1860 if (hsotg->dedicated_fifos &&
1861 ints & S3C_DIEPMSK_TxFIFOEmpty) {
1862 dev_dbg(hsotg->dev, "%s: ep%d: TxFIFOEmpty\n",
1863 __func__, idx);
1864 s3c_hsotg_trytx(hsotg, hs_ep);
1865 clear |= S3C_DIEPMSK_TxFIFOEmpty;
1866 }
1821 } 1867 }
1822 1868
1823 writel(clear, hsotg->regs + epint_reg); 1869 writel(clear, hsotg->regs + epint_reg);
@@ -2071,17 +2117,12 @@ irq_retry:
2071 kill_all_requests(hsotg, &hsotg->eps[0], -ECONNRESET, true); 2117 kill_all_requests(hsotg, &hsotg->eps[0], -ECONNRESET, true);
2072 2118
2073 /* it seems after a reset we can end up with a situation 2119 /* it seems after a reset we can end up with a situation
2074 * where the TXFIFO still has data in it... try flushing 2120 * where the TXFIFO still has data in it... the docs
2075 * it to remove anything that may still be in it. 2121 * suggest resetting all the fifos, so use the init_fifo
2122 * code to relayout and flush the fifos.
2076 */ 2123 */
2077 2124
2078 if (1) { 2125 s3c_hsotg_init_fifo(hsotg);
2079 writel(S3C_GRSTCTL_TxFNum(0) | S3C_GRSTCTL_TxFFlsh,
2080 hsotg->regs + S3C_GRSTCTL);
2081
2082 dev_info(hsotg->dev, "GNPTXSTS=%08x\n",
2083 readl(hsotg->regs + S3C_GNPTXSTS));
2084 }
2085 2126
2086 s3c_hsotg_enqueue_setup(hsotg); 2127 s3c_hsotg_enqueue_setup(hsotg);
2087 2128
@@ -2274,6 +2315,12 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep,
2274 break; 2315 break;
2275 } 2316 }
2276 2317
2318 /* if the hardware has dedicated fifos, we must give each IN EP
2319 * a unique tx-fifo even if it is non-periodic.
2320 */
2321 if (dir_in && hsotg->dedicated_fifos)
2322 epctrl |= S3C_DxEPCTL_TxFNum(index);
2323
2277 /* for non control endpoints, set PID to D0 */ 2324 /* for non control endpoints, set PID to D0 */
2278 if (index) 2325 if (index)
2279 epctrl |= S3C_DxEPCTL_SetD0PID; 2326 epctrl |= S3C_DxEPCTL_SetD0PID;
@@ -2563,7 +2610,8 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
2563 2610
2564 writel(S3C_DIEPMSK_TimeOUTMsk | S3C_DIEPMSK_AHBErrMsk | 2611 writel(S3C_DIEPMSK_TimeOUTMsk | S3C_DIEPMSK_AHBErrMsk |
2565 S3C_DIEPMSK_INTknEPMisMsk | 2612 S3C_DIEPMSK_INTknEPMisMsk |
2566 S3C_DIEPMSK_EPDisbldMsk | S3C_DIEPMSK_XferComplMsk, 2613 S3C_DIEPMSK_EPDisbldMsk | S3C_DIEPMSK_XferComplMsk |
2614 ((hsotg->dedicated_fifos) ? S3C_DIEPMSK_TxFIFOEmpty : 0),
2567 hsotg->regs + S3C_DIEPMSK); 2615 hsotg->regs + S3C_DIEPMSK);
2568 2616
2569 /* don't need XferCompl, we get that from RXFIFO in slave mode. In 2617 /* don't need XferCompl, we get that from RXFIFO in slave mode. In
@@ -2732,7 +2780,7 @@ static void __devinit s3c_hsotg_initep(struct s3c_hsotg *hsotg,
2732 */ 2780 */
2733 2781
2734 ptxfifo = readl(hsotg->regs + S3C_DPTXFSIZn(epnum)); 2782 ptxfifo = readl(hsotg->regs + S3C_DPTXFSIZn(epnum));
2735 hs_ep->fifo_size = S3C_DPTXFSIZn_DPTxFSize_GET(ptxfifo); 2783 hs_ep->fifo_size = S3C_DPTXFSIZn_DPTxFSize_GET(ptxfifo) * 4;
2736 2784
2737 /* if we're using dma, we need to set the next-endpoint pointer 2785 /* if we're using dma, we need to set the next-endpoint pointer
2738 * to be something valid. 2786 * to be something valid.
@@ -2753,13 +2801,33 @@ static void __devinit s3c_hsotg_initep(struct s3c_hsotg *hsotg,
2753 */ 2801 */
2754static void s3c_hsotg_otgreset(struct s3c_hsotg *hsotg) 2802static void s3c_hsotg_otgreset(struct s3c_hsotg *hsotg)
2755{ 2803{
2756 u32 osc; 2804 struct clk *xusbxti;
2805 u32 pwr, osc;
2757 2806
2758 writel(0, S3C_PHYPWR); 2807 pwr = readl(S3C_PHYPWR);
2808 pwr &= ~0x19;
2809 writel(pwr, S3C_PHYPWR);
2759 mdelay(1); 2810 mdelay(1);
2760 2811
2761 osc = hsotg->plat->is_osc ? S3C_PHYCLK_EXT_OSC : 0; 2812 osc = hsotg->plat->is_osc ? S3C_PHYCLK_EXT_OSC : 0;
2762 2813
2814 xusbxti = clk_get(hsotg->dev, "xusbxti");
2815 if (xusbxti && !IS_ERR(xusbxti)) {
2816 switch (clk_get_rate(xusbxti)) {
2817 case 12*MHZ:
2818 osc |= S3C_PHYCLK_CLKSEL_12M;
2819 break;
2820 case 24*MHZ:
2821 osc |= S3C_PHYCLK_CLKSEL_24M;
2822 break;
2823 default:
2824 case 48*MHZ:
2825 /* default reference clock */
2826 break;
2827 }
2828 clk_put(xusbxti);
2829 }
2830
2763 writel(osc | 0x10, S3C_PHYCLK); 2831 writel(osc | 0x10, S3C_PHYCLK);
2764 2832
2765 /* issue a full set of resets to the otg and core */ 2833 /* issue a full set of resets to the otg and core */
@@ -2772,6 +2840,8 @@ static void s3c_hsotg_otgreset(struct s3c_hsotg *hsotg)
2772 2840
2773static void s3c_hsotg_init(struct s3c_hsotg *hsotg) 2841static void s3c_hsotg_init(struct s3c_hsotg *hsotg)
2774{ 2842{
2843 u32 cfg4;
2844
2775 /* unmask subset of endpoint interrupts */ 2845 /* unmask subset of endpoint interrupts */
2776 2846
2777 writel(S3C_DIEPMSK_TimeOUTMsk | S3C_DIEPMSK_AHBErrMsk | 2847 writel(S3C_DIEPMSK_TimeOUTMsk | S3C_DIEPMSK_AHBErrMsk |
@@ -2807,6 +2877,14 @@ static void s3c_hsotg_init(struct s3c_hsotg *hsotg)
2807 2877
2808 writel(using_dma(hsotg) ? S3C_GAHBCFG_DMAEn : 0x0, 2878 writel(using_dma(hsotg) ? S3C_GAHBCFG_DMAEn : 0x0,
2809 hsotg->regs + S3C_GAHBCFG); 2879 hsotg->regs + S3C_GAHBCFG);
2880
2881 /* check hardware configuration */
2882
2883 cfg4 = readl(hsotg->regs + 0x50);
2884 hsotg->dedicated_fifos = (cfg4 >> 25) & 1;
2885
2886 dev_info(hsotg->dev, "%s fifos\n",
2887 hsotg->dedicated_fifos ? "dedicated" : "shared");
2810} 2888}
2811 2889
2812static void s3c_hsotg_dump(struct s3c_hsotg *hsotg) 2890static void s3c_hsotg_dump(struct s3c_hsotg *hsotg)
@@ -3181,13 +3259,20 @@ static int __devinit s3c_hsotg_probe(struct platform_device *pdev)
3181 hsotg->dev = dev; 3259 hsotg->dev = dev;
3182 hsotg->plat = plat; 3260 hsotg->plat = plat;
3183 3261
3262 hsotg->clk = clk_get(&pdev->dev, "otg");
3263 if (IS_ERR(hsotg->clk)) {
3264 dev_err(dev, "cannot get otg clock\n");
3265 ret = -EINVAL;
3266 goto err_mem;
3267 }
3268
3184 platform_set_drvdata(pdev, hsotg); 3269 platform_set_drvdata(pdev, hsotg);
3185 3270
3186 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 3271 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
3187 if (!res) { 3272 if (!res) {
3188 dev_err(dev, "cannot find register resource 0\n"); 3273 dev_err(dev, "cannot find register resource 0\n");
3189 ret = -EINVAL; 3274 ret = -EINVAL;
3190 goto err_mem; 3275 goto err_clk;
3191 } 3276 }
3192 3277
3193 hsotg->regs_res = request_mem_region(res->start, resource_size(res), 3278 hsotg->regs_res = request_mem_region(res->start, resource_size(res),
@@ -3195,7 +3280,7 @@ static int __devinit s3c_hsotg_probe(struct platform_device *pdev)
3195 if (!hsotg->regs_res) { 3280 if (!hsotg->regs_res) {
3196 dev_err(dev, "cannot reserve registers\n"); 3281 dev_err(dev, "cannot reserve registers\n");
3197 ret = -ENOENT; 3282 ret = -ENOENT;
3198 goto err_mem; 3283 goto err_clk;
3199 } 3284 }
3200 3285
3201 hsotg->regs = ioremap(res->start, resource_size(res)); 3286 hsotg->regs = ioremap(res->start, resource_size(res));
@@ -3248,6 +3333,8 @@ static int __devinit s3c_hsotg_probe(struct platform_device *pdev)
3248 3333
3249 /* reset the system */ 3334 /* reset the system */
3250 3335
3336 clk_enable(hsotg->clk);
3337
3251 s3c_hsotg_gate(pdev, true); 3338 s3c_hsotg_gate(pdev, true);
3252 3339
3253 s3c_hsotg_otgreset(hsotg); 3340 s3c_hsotg_otgreset(hsotg);
@@ -3271,7 +3358,8 @@ err_regs:
3271err_regs_res: 3358err_regs_res:
3272 release_resource(hsotg->regs_res); 3359 release_resource(hsotg->regs_res);
3273 kfree(hsotg->regs_res); 3360 kfree(hsotg->regs_res);
3274 3361err_clk:
3362 clk_put(hsotg->clk);
3275err_mem: 3363err_mem:
3276 kfree(hsotg); 3364 kfree(hsotg);
3277 return ret; 3365 return ret;
@@ -3293,6 +3381,9 @@ static int __devexit s3c_hsotg_remove(struct platform_device *pdev)
3293 3381
3294 s3c_hsotg_gate(pdev, false); 3382 s3c_hsotg_gate(pdev, false);
3295 3383
3384 clk_disable(hsotg->clk);
3385 clk_put(hsotg->clk);
3386
3296 kfree(hsotg); 3387 kfree(hsotg);
3297 return 0; 3388 return 0;
3298} 3389}
diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c
index f46a60962dab..b22eedbc7dc5 100644
--- a/drivers/usb/gadget/serial.c
+++ b/drivers/usb/gadget/serial.c
@@ -137,7 +137,7 @@ MODULE_PARM_DESC(n_ports, "number of ports to create, default=1");
137 137
138/*-------------------------------------------------------------------------*/ 138/*-------------------------------------------------------------------------*/
139 139
140static int __init serial_bind_config(struct usb_configuration *c) 140static int __ref serial_bind_config(struct usb_configuration *c)
141{ 141{
142 unsigned i; 142 unsigned i;
143 int status = 0; 143 int status = 0;
@@ -161,7 +161,7 @@ static struct usb_configuration serial_config_driver = {
161 .bmAttributes = USB_CONFIG_ATT_SELFPOWER, 161 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
162}; 162};
163 163
164static int __init gs_bind(struct usb_composite_dev *cdev) 164static int __ref gs_bind(struct usb_composite_dev *cdev)
165{ 165{
166 int gcnum; 166 int gcnum;
167 struct usb_gadget *gadget = cdev->gadget; 167 struct usb_gadget *gadget = cdev->gadget;
diff --git a/drivers/usb/gadget/storage_common.c b/drivers/usb/gadget/storage_common.c
index 04c462ff0ea6..484acfb1a7c5 100644
--- a/drivers/usb/gadget/storage_common.c
+++ b/drivers/usb/gadget/storage_common.c
@@ -57,10 +57,12 @@
57#include <asm/unaligned.h> 57#include <asm/unaligned.h>
58 58
59 59
60/* Thanks to NetChip Technologies for donating this product ID. 60/*
61 * Thanks to NetChip Technologies for donating this product ID.
61 * 62 *
62 * DO NOT REUSE THESE IDs with any other driver!! Ever!! 63 * DO NOT REUSE THESE IDs with any other driver!! Ever!!
63 * Instead: allocate your own, using normal USB-IF procedures. */ 64 * Instead: allocate your own, using normal USB-IF procedures.
65 */
64#define FSG_VENDOR_ID 0x0525 /* NetChip */ 66#define FSG_VENDOR_ID 0x0525 /* NetChip */
65#define FSG_PRODUCT_ID 0xa4a5 /* Linux-USB File-backed Storage Gadget */ 67#define FSG_PRODUCT_ID 0xa4a5 /* Linux-USB File-backed Storage Gadget */
66 68
@@ -84,14 +86,27 @@
84#define LWARN(lun, fmt, args...) dev_warn(&(lun)->dev, fmt, ## args) 86#define LWARN(lun, fmt, args...) dev_warn(&(lun)->dev, fmt, ## args)
85#define LINFO(lun, fmt, args...) dev_info(&(lun)->dev, fmt, ## args) 87#define LINFO(lun, fmt, args...) dev_info(&(lun)->dev, fmt, ## args)
86 88
87/* Keep those macros in sync with thos in 89/*
88 * include/linux/ubs/composite.h or else GCC will complain. If they 90 * Keep those macros in sync with those in
91 * include/linux/usb/composite.h or else GCC will complain. If they
89 * are identical (the same names of arguments, white spaces in the 92 * are identical (the same names of arguments, white spaces in the
90 * same places) GCC will allow redefinition otherwise (even if some 93 * same places) GCC will allow redefinition otherwise (even if some
91 * white space is removed or added) warning will be issued. No 94 * white space is removed or added) warning will be issued.
92 * checking if those symbols is defined is performed because warning 95 *
93 * is desired when those macros were defined by someone else to mean 96 * Those macros are needed here because File Storage Gadget does not
94 * something else. */ 97 * include the composite.h header. For composite gadgets those macros
98 * are redundant since composite.h is included any way.
99 *
100 * One could check whether those macros are already defined (which
101 * would indicate composite.h had been included) or not (which would
102 * indicate we were in FSG) but this is not done because a warning is
103 * desired if definitions here differ from the ones in composite.h.
104 *
105 * We want the definitions to match and be the same in File Storage
106 * Gadget as well as Mass Storage Function (and so composite gadgets
107 * using MSF). If someone changes them in composite.h it will produce
108 * a warning in this file when building MSF.
109 */
95#define DBG(d, fmt, args...) dev_dbg(&(d)->gadget->dev , fmt , ## args) 110#define DBG(d, fmt, args...) dev_dbg(&(d)->gadget->dev , fmt , ## args)
96#define VDBG(d, fmt, args...) dev_vdbg(&(d)->gadget->dev , fmt , ## args) 111#define VDBG(d, fmt, args...) dev_vdbg(&(d)->gadget->dev , fmt , ## args)
97#define ERROR(d, fmt, args...) dev_err(&(d)->gadget->dev , fmt , ## args) 112#define ERROR(d, fmt, args...) dev_err(&(d)->gadget->dev , fmt , ## args)
@@ -269,6 +284,7 @@ struct fsg_lun {
269 unsigned int prevent_medium_removal:1; 284 unsigned int prevent_medium_removal:1;
270 unsigned int registered:1; 285 unsigned int registered:1;
271 unsigned int info_valid:1; 286 unsigned int info_valid:1;
287 unsigned int nofua:1;
272 288
273 u32 sense_data; 289 u32 sense_data;
274 u32 sense_data_info; 290 u32 sense_data_info;
@@ -313,9 +329,11 @@ struct fsg_buffhd {
313 enum fsg_buffer_state state; 329 enum fsg_buffer_state state;
314 struct fsg_buffhd *next; 330 struct fsg_buffhd *next;
315 331
316 /* The NetChip 2280 is faster, and handles some protocol faults 332 /*
333 * The NetChip 2280 is faster, and handles some protocol faults
317 * better, if we don't submit any short bulk-out read requests. 334 * better, if we don't submit any short bulk-out read requests.
318 * So we will record the intended request length here. */ 335 * So we will record the intended request length here.
336 */
319 unsigned int bulk_out_intended_length; 337 unsigned int bulk_out_intended_length;
320 338
321 struct usb_request *inreq; 339 struct usb_request *inreq;
@@ -395,8 +413,10 @@ fsg_intf_desc = {
395 .iInterface = FSG_STRING_INTERFACE, 413 .iInterface = FSG_STRING_INTERFACE,
396}; 414};
397 415
398/* Three full-speed endpoint descriptors: bulk-in, bulk-out, 416/*
399 * and interrupt-in. */ 417 * Three full-speed endpoint descriptors: bulk-in, bulk-out, and
418 * interrupt-in.
419 */
400 420
401static struct usb_endpoint_descriptor 421static struct usb_endpoint_descriptor
402fsg_fs_bulk_in_desc = { 422fsg_fs_bulk_in_desc = {
@@ -459,7 +479,7 @@ static struct usb_descriptor_header *fsg_fs_function[] = {
459 * 479 *
460 * That means alternate endpoint descriptors (bigger packets) 480 * That means alternate endpoint descriptors (bigger packets)
461 * and a "device qualifier" ... plus more construction options 481 * and a "device qualifier" ... plus more construction options
462 * for the config descriptor. 482 * for the configuration descriptor.
463 */ 483 */
464static struct usb_endpoint_descriptor 484static struct usb_endpoint_descriptor
465fsg_hs_bulk_in_desc = { 485fsg_hs_bulk_in_desc = {
@@ -547,8 +567,10 @@ static struct usb_gadget_strings fsg_stringtab = {
547 567
548 /*-------------------------------------------------------------------------*/ 568 /*-------------------------------------------------------------------------*/
549 569
550/* If the next two routines are called while the gadget is registered, 570/*
551 * the caller must own fsg->filesem for writing. */ 571 * If the next two routines are called while the gadget is registered,
572 * the caller must own fsg->filesem for writing.
573 */
552 574
553static int fsg_lun_open(struct fsg_lun *curlun, const char *filename) 575static int fsg_lun_open(struct fsg_lun *curlun, const char *filename)
554{ 576{
@@ -587,8 +609,10 @@ static int fsg_lun_open(struct fsg_lun *curlun, const char *filename)
587 goto out; 609 goto out;
588 } 610 }
589 611
590 /* If we can't read the file, it's no good. 612 /*
591 * If we can't write the file, use it read-only. */ 613 * If we can't read the file, it's no good.
614 * If we can't write the file, use it read-only.
615 */
592 if (!filp->f_op || !(filp->f_op->read || filp->f_op->aio_read)) { 616 if (!filp->f_op || !(filp->f_op->read || filp->f_op->aio_read)) {
593 LINFO(curlun, "file not readable: %s\n", filename); 617 LINFO(curlun, "file not readable: %s\n", filename);
594 goto out; 618 goto out;
@@ -646,8 +670,10 @@ static void fsg_lun_close(struct fsg_lun *curlun)
646 670
647/*-------------------------------------------------------------------------*/ 671/*-------------------------------------------------------------------------*/
648 672
649/* Sync the file data, don't bother with the metadata. 673/*
650 * This code was copied from fs/buffer.c:sys_fdatasync(). */ 674 * Sync the file data, don't bother with the metadata.
675 * This code was copied from fs/buffer.c:sys_fdatasync().
676 */
651static int fsg_lun_fsync_sub(struct fsg_lun *curlun) 677static int fsg_lun_fsync_sub(struct fsg_lun *curlun)
652{ 678{
653 struct file *filp = curlun->filp; 679 struct file *filp = curlun->filp;
@@ -689,6 +715,14 @@ static ssize_t fsg_show_ro(struct device *dev, struct device_attribute *attr,
689 : curlun->initially_ro); 715 : curlun->initially_ro);
690} 716}
691 717
718static ssize_t fsg_show_nofua(struct device *dev, struct device_attribute *attr,
719 char *buf)
720{
721 struct fsg_lun *curlun = fsg_lun_from_dev(dev);
722
723 return sprintf(buf, "%u\n", curlun->nofua);
724}
725
692static ssize_t fsg_show_file(struct device *dev, struct device_attribute *attr, 726static ssize_t fsg_show_file(struct device *dev, struct device_attribute *attr,
693 char *buf) 727 char *buf)
694{ 728{
@@ -723,26 +757,47 @@ static ssize_t fsg_store_ro(struct device *dev, struct device_attribute *attr,
723 ssize_t rc = count; 757 ssize_t rc = count;
724 struct fsg_lun *curlun = fsg_lun_from_dev(dev); 758 struct fsg_lun *curlun = fsg_lun_from_dev(dev);
725 struct rw_semaphore *filesem = dev_get_drvdata(dev); 759 struct rw_semaphore *filesem = dev_get_drvdata(dev);
726 int i; 760 unsigned long ro;
727 761
728 if (sscanf(buf, "%d", &i) != 1) 762 if (strict_strtoul(buf, 2, &ro))
729 return -EINVAL; 763 return -EINVAL;
730 764
731 /* Allow the write-enable status to change only while the backing file 765 /*
732 * is closed. */ 766 * Allow the write-enable status to change only while the
767 * backing file is closed.
768 */
733 down_read(filesem); 769 down_read(filesem);
734 if (fsg_lun_is_open(curlun)) { 770 if (fsg_lun_is_open(curlun)) {
735 LDBG(curlun, "read-only status change prevented\n"); 771 LDBG(curlun, "read-only status change prevented\n");
736 rc = -EBUSY; 772 rc = -EBUSY;
737 } else { 773 } else {
738 curlun->ro = !!i; 774 curlun->ro = ro;
739 curlun->initially_ro = !!i; 775 curlun->initially_ro = ro;
740 LDBG(curlun, "read-only status set to %d\n", curlun->ro); 776 LDBG(curlun, "read-only status set to %d\n", curlun->ro);
741 } 777 }
742 up_read(filesem); 778 up_read(filesem);
743 return rc; 779 return rc;
744} 780}
745 781
782static ssize_t fsg_store_nofua(struct device *dev,
783 struct device_attribute *attr,
784 const char *buf, size_t count)
785{
786 struct fsg_lun *curlun = fsg_lun_from_dev(dev);
787 unsigned long nofua;
788
789 if (strict_strtoul(buf, 2, &nofua))
790 return -EINVAL;
791
792 /* Sync data when switching from async mode to sync */
793 if (!nofua && curlun->nofua)
794 fsg_lun_fsync_sub(curlun);
795
796 curlun->nofua = nofua;
797
798 return count;
799}
800
746static ssize_t fsg_store_file(struct device *dev, struct device_attribute *attr, 801static ssize_t fsg_store_file(struct device *dev, struct device_attribute *attr,
747 const char *buf, size_t count) 802 const char *buf, size_t count)
748{ 803{
diff --git a/drivers/usb/gadget/u_ether.c b/drivers/usb/gadget/u_ether.c
index 1da755a1c855..6bb876d65252 100644
--- a/drivers/usb/gadget/u_ether.c
+++ b/drivers/usb/gadget/u_ether.c
@@ -704,17 +704,6 @@ static char *host_addr;
704module_param(host_addr, charp, S_IRUGO); 704module_param(host_addr, charp, S_IRUGO);
705MODULE_PARM_DESC(host_addr, "Host Ethernet Address"); 705MODULE_PARM_DESC(host_addr, "Host Ethernet Address");
706 706
707
708static u8 __init nibble(unsigned char c)
709{
710 if (isdigit(c))
711 return c - '0';
712 c = toupper(c);
713 if (isxdigit(c))
714 return 10 + c - 'A';
715 return 0;
716}
717
718static int get_ether_addr(const char *str, u8 *dev_addr) 707static int get_ether_addr(const char *str, u8 *dev_addr)
719{ 708{
720 if (str) { 709 if (str) {
@@ -725,8 +714,8 @@ static int get_ether_addr(const char *str, u8 *dev_addr)
725 714
726 if ((*str == '.') || (*str == ':')) 715 if ((*str == '.') || (*str == ':'))
727 str++; 716 str++;
728 num = nibble(*str++) << 4; 717 num = hex_to_bin(*str++) << 4;
729 num |= (nibble(*str++)); 718 num |= hex_to_bin(*str++);
730 dev_addr [i] = num; 719 dev_addr [i] = num;
731 } 720 }
732 if (is_valid_ether_addr(dev_addr)) 721 if (is_valid_ether_addr(dev_addr))
diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
index 3e8dcb5455e3..01e5354a4c20 100644
--- a/drivers/usb/gadget/u_serial.c
+++ b/drivers/usb/gadget/u_serial.c
@@ -18,6 +18,7 @@
18/* #define VERBOSE_DEBUG */ 18/* #define VERBOSE_DEBUG */
19 19
20#include <linux/kernel.h> 20#include <linux/kernel.h>
21#include <linux/sched.h>
21#include <linux/interrupt.h> 22#include <linux/interrupt.h>
22#include <linux/device.h> 23#include <linux/device.h>
23#include <linux/delay.h> 24#include <linux/delay.h>
diff --git a/drivers/usb/gadget/webcam.c b/drivers/usb/gadget/webcam.c
index 288d21155abe..de1deb7a3c63 100644
--- a/drivers/usb/gadget/webcam.c
+++ b/drivers/usb/gadget/webcam.c
@@ -308,7 +308,7 @@ static const struct uvc_descriptor_header * const uvc_hs_streaming_cls[] = {
308 * USB configuration 308 * USB configuration
309 */ 309 */
310 310
311static int __init 311static int __ref
312webcam_config_bind(struct usb_configuration *c) 312webcam_config_bind(struct usb_configuration *c)
313{ 313{
314 return uvc_bind_config(c, uvc_control_cls, uvc_fs_streaming_cls, 314 return uvc_bind_config(c, uvc_control_cls, uvc_fs_streaming_cls,
@@ -330,7 +330,7 @@ webcam_unbind(struct usb_composite_dev *cdev)
330 return 0; 330 return 0;
331} 331}
332 332
333static int __init 333static int __ref
334webcam_bind(struct usb_composite_dev *cdev) 334webcam_bind(struct usb_composite_dev *cdev)
335{ 335{
336 int ret; 336 int ret;
diff --git a/drivers/usb/gadget/zero.c b/drivers/usb/gadget/zero.c
index 807280d069f9..cf353920bb1c 100644
--- a/drivers/usb/gadget/zero.c
+++ b/drivers/usb/gadget/zero.c
@@ -264,7 +264,7 @@ static void zero_resume(struct usb_composite_dev *cdev)
264 264
265/*-------------------------------------------------------------------------*/ 265/*-------------------------------------------------------------------------*/
266 266
267static int __init zero_bind(struct usb_composite_dev *cdev) 267static int __ref zero_bind(struct usb_composite_dev *cdev)
268{ 268{
269 int gcnum; 269 int gcnum;
270 struct usb_gadget *gadget = cdev->gadget; 270 struct usb_gadget *gadget = cdev->gadget;
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index f865be2276d4..2d926cec0725 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -72,8 +72,9 @@ config USB_EHCI_ROOT_HUB_TT
72 from ARC, and has since changed hands a few times. 72 from ARC, and has since changed hands a few times.
73 73
74config USB_EHCI_TT_NEWSCHED 74config USB_EHCI_TT_NEWSCHED
75 bool "Improved Transaction Translator scheduling (EXPERIMENTAL)" 75 bool "Improved Transaction Translator scheduling"
76 depends on USB_EHCI_HCD && EXPERIMENTAL 76 depends on USB_EHCI_HCD
77 default y
77 ---help--- 78 ---help---
78 This changes the periodic scheduling code to fill more of the low 79 This changes the periodic scheduling code to fill more of the low
79 and full speed bandwidth available from the Transaction Translator 80 and full speed bandwidth available from the Transaction Translator
@@ -84,9 +85,11 @@ config USB_EHCI_TT_NEWSCHED
84 If you have multiple periodic low/fullspeed devices connected to a 85 If you have multiple periodic low/fullspeed devices connected to a
85 highspeed USB hub which is connected to a highspeed USB Host 86 highspeed USB hub which is connected to a highspeed USB Host
86 Controller, and some of those devices will not work correctly 87 Controller, and some of those devices will not work correctly
87 (possibly due to "ENOSPC" or "-28" errors), say Y. 88 (possibly due to "ENOSPC" or "-28" errors), say Y. Conversely, if
89 you have only one such device and it doesn't work, you could try
90 saying N.
88 91
89 If unsure, say N. 92 If unsure, say Y.
90 93
91config USB_EHCI_BIG_ENDIAN_MMIO 94config USB_EHCI_BIG_ENDIAN_MMIO
92 bool 95 bool
diff --git a/drivers/usb/host/ehci-au1xxx.c b/drivers/usb/host/ehci-au1xxx.c
index faa61748db70..2baf8a849086 100644
--- a/drivers/usb/host/ehci-au1xxx.c
+++ b/drivers/usb/host/ehci-au1xxx.c
@@ -228,7 +228,7 @@ static int ehci_hcd_au1xxx_drv_suspend(struct device *dev)
228 * the root hub is either suspended or stopped. 228 * the root hub is either suspended or stopped.
229 */ 229 */
230 spin_lock_irqsave(&ehci->lock, flags); 230 spin_lock_irqsave(&ehci->lock, flags);
231 ehci_prepare_ports_for_controller_suspend(ehci); 231 ehci_prepare_ports_for_controller_suspend(ehci, device_may_wakeup(dev));
232 ehci_writel(ehci, 0, &ehci->regs->intr_enable); 232 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
233 (void)ehci_readl(ehci, &ehci->regs->intr_enable); 233 (void)ehci_readl(ehci, &ehci->regs->intr_enable);
234 234
diff --git a/drivers/usb/host/ehci-dbg.c b/drivers/usb/host/ehci-dbg.c
index 874d2000bf92..76b7fd2d838a 100644
--- a/drivers/usb/host/ehci-dbg.c
+++ b/drivers/usb/host/ehci-dbg.c
@@ -98,13 +98,18 @@ static void dbg_hcc_params (struct ehci_hcd *ehci, char *label)
98 HCC_64BIT_ADDR(params) ? " 64 bit addr" : ""); 98 HCC_64BIT_ADDR(params) ? " 64 bit addr" : "");
99 } else { 99 } else {
100 ehci_dbg (ehci, 100 ehci_dbg (ehci,
101 "%s hcc_params %04x thresh %d uframes %s%s%s\n", 101 "%s hcc_params %04x thresh %d uframes %s%s%s%s%s%s%s\n",
102 label, 102 label,
103 params, 103 params,
104 HCC_ISOC_THRES(params), 104 HCC_ISOC_THRES(params),
105 HCC_PGM_FRAMELISTLEN(params) ? "256/512/1024" : "1024", 105 HCC_PGM_FRAMELISTLEN(params) ? "256/512/1024" : "1024",
106 HCC_CANPARK(params) ? " park" : "", 106 HCC_CANPARK(params) ? " park" : "",
107 HCC_64BIT_ADDR(params) ? " 64 bit addr" : ""); 107 HCC_64BIT_ADDR(params) ? " 64 bit addr" : "",
108 HCC_LPM(params) ? " LPM" : "",
109 HCC_PER_PORT_CHANGE_EVENT(params) ? " ppce" : "",
110 HCC_HW_PREFETCH(params) ? " hw prefetch" : "",
111 HCC_32FRAME_PERIODIC_LIST(params) ?
112 " 32 peridic list" : "");
108 } 113 }
109} 114}
110#else 115#else
@@ -191,8 +196,9 @@ static int __maybe_unused
191dbg_status_buf (char *buf, unsigned len, const char *label, u32 status) 196dbg_status_buf (char *buf, unsigned len, const char *label, u32 status)
192{ 197{
193 return scnprintf (buf, len, 198 return scnprintf (buf, len,
194 "%s%sstatus %04x%s%s%s%s%s%s%s%s%s%s", 199 "%s%sstatus %04x%s%s%s%s%s%s%s%s%s%s%s",
195 label, label [0] ? " " : "", status, 200 label, label [0] ? " " : "", status,
201 (status & STS_PPCE_MASK) ? " PPCE" : "",
196 (status & STS_ASS) ? " Async" : "", 202 (status & STS_ASS) ? " Async" : "",
197 (status & STS_PSS) ? " Periodic" : "", 203 (status & STS_PSS) ? " Periodic" : "",
198 (status & STS_RECL) ? " Recl" : "", 204 (status & STS_RECL) ? " Recl" : "",
@@ -210,8 +216,9 @@ static int __maybe_unused
210dbg_intr_buf (char *buf, unsigned len, const char *label, u32 enable) 216dbg_intr_buf (char *buf, unsigned len, const char *label, u32 enable)
211{ 217{
212 return scnprintf (buf, len, 218 return scnprintf (buf, len,
213 "%s%sintrenable %02x%s%s%s%s%s%s", 219 "%s%sintrenable %02x%s%s%s%s%s%s%s",
214 label, label [0] ? " " : "", enable, 220 label, label [0] ? " " : "", enable,
221 (enable & STS_PPCE_MASK) ? " PPCE" : "",
215 (enable & STS_IAA) ? " IAA" : "", 222 (enable & STS_IAA) ? " IAA" : "",
216 (enable & STS_FATAL) ? " FATAL" : "", 223 (enable & STS_FATAL) ? " FATAL" : "",
217 (enable & STS_FLR) ? " FLR" : "", 224 (enable & STS_FLR) ? " FLR" : "",
@@ -228,9 +235,15 @@ static int
228dbg_command_buf (char *buf, unsigned len, const char *label, u32 command) 235dbg_command_buf (char *buf, unsigned len, const char *label, u32 command)
229{ 236{
230 return scnprintf (buf, len, 237 return scnprintf (buf, len,
231 "%s%scommand %06x %s=%d ithresh=%d%s%s%s%s period=%s%s %s", 238 "%s%scommand %07x %s%s%s%s%s%s=%d ithresh=%d%s%s%s%s "
239 "period=%s%s %s",
232 label, label [0] ? " " : "", command, 240 label, label [0] ? " " : "", command,
233 (command & CMD_PARK) ? "park" : "(park)", 241 (command & CMD_HIRD) ? " HIRD" : "",
242 (command & CMD_PPCEE) ? " PPCEE" : "",
243 (command & CMD_FSP) ? " FSP" : "",
244 (command & CMD_ASPE) ? " ASPE" : "",
245 (command & CMD_PSPE) ? " PSPE" : "",
246 (command & CMD_PARK) ? " park" : "(park)",
234 CMD_PARK_CNT (command), 247 CMD_PARK_CNT (command),
235 (command >> 16) & 0x3f, 248 (command >> 16) & 0x3f,
236 (command & CMD_LRESET) ? " LReset" : "", 249 (command & CMD_LRESET) ? " LReset" : "",
@@ -257,11 +270,22 @@ dbg_port_buf (char *buf, unsigned len, const char *label, int port, u32 status)
257 } 270 }
258 271
259 return scnprintf (buf, len, 272 return scnprintf (buf, len,
260 "%s%sport %d status %06x%s%s sig=%s%s%s%s%s%s%s%s%s%s", 273 "%s%sport:%d status %06x %d %s%s%s%s%s%s "
274 "sig=%s%s%s%s%s%s%s%s%s%s%s",
261 label, label [0] ? " " : "", port, status, 275 label, label [0] ? " " : "", port, status,
276 status>>25,/*device address */
277 (status & PORT_SSTS)>>23 == PORTSC_SUSPEND_STS_ACK ?
278 " ACK" : "",
279 (status & PORT_SSTS)>>23 == PORTSC_SUSPEND_STS_NYET ?
280 " NYET" : "",
281 (status & PORT_SSTS)>>23 == PORTSC_SUSPEND_STS_STALL ?
282 " STALL" : "",
283 (status & PORT_SSTS)>>23 == PORTSC_SUSPEND_STS_ERR ?
284 " ERR" : "",
262 (status & PORT_POWER) ? " POWER" : "", 285 (status & PORT_POWER) ? " POWER" : "",
263 (status & PORT_OWNER) ? " OWNER" : "", 286 (status & PORT_OWNER) ? " OWNER" : "",
264 sig, 287 sig,
288 (status & PORT_LPM) ? " LPM" : "",
265 (status & PORT_RESET) ? " RESET" : "", 289 (status & PORT_RESET) ? " RESET" : "",
266 (status & PORT_SUSPEND) ? " SUSPEND" : "", 290 (status & PORT_SUSPEND) ? " SUSPEND" : "",
267 (status & PORT_RESUME) ? " RESUME" : "", 291 (status & PORT_RESUME) ? " RESUME" : "",
@@ -330,6 +354,13 @@ static int debug_async_open(struct inode *, struct file *);
330static int debug_periodic_open(struct inode *, struct file *); 354static int debug_periodic_open(struct inode *, struct file *);
331static int debug_registers_open(struct inode *, struct file *); 355static int debug_registers_open(struct inode *, struct file *);
332static int debug_async_open(struct inode *, struct file *); 356static int debug_async_open(struct inode *, struct file *);
357static int debug_lpm_open(struct inode *, struct file *);
358static ssize_t debug_lpm_read(struct file *file, char __user *user_buf,
359 size_t count, loff_t *ppos);
360static ssize_t debug_lpm_write(struct file *file, const char __user *buffer,
361 size_t count, loff_t *ppos);
362static int debug_lpm_close(struct inode *inode, struct file *file);
363
333static ssize_t debug_output(struct file*, char __user*, size_t, loff_t*); 364static ssize_t debug_output(struct file*, char __user*, size_t, loff_t*);
334static int debug_close(struct inode *, struct file *); 365static int debug_close(struct inode *, struct file *);
335 366
@@ -351,6 +382,13 @@ static const struct file_operations debug_registers_fops = {
351 .read = debug_output, 382 .read = debug_output,
352 .release = debug_close, 383 .release = debug_close,
353}; 384};
385static const struct file_operations debug_lpm_fops = {
386 .owner = THIS_MODULE,
387 .open = debug_lpm_open,
388 .read = debug_lpm_read,
389 .write = debug_lpm_write,
390 .release = debug_lpm_close,
391};
354 392
355static struct dentry *ehci_debug_root; 393static struct dentry *ehci_debug_root;
356 394
@@ -674,7 +712,7 @@ static ssize_t fill_registers_buffer(struct debug_buffer *buf)
674 712
675 spin_lock_irqsave (&ehci->lock, flags); 713 spin_lock_irqsave (&ehci->lock, flags);
676 714
677 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) { 715 if (!HCD_HW_ACCESSIBLE(hcd)) {
678 size = scnprintf (next, size, 716 size = scnprintf (next, size,
679 "bus %s, device %s\n" 717 "bus %s, device %s\n"
680 "%s\n" 718 "%s\n"
@@ -917,51 +955,127 @@ static int debug_registers_open(struct inode *inode, struct file *file)
917 return file->private_data ? 0 : -ENOMEM; 955 return file->private_data ? 0 : -ENOMEM;
918} 956}
919 957
958static int debug_lpm_open(struct inode *inode, struct file *file)
959{
960 file->private_data = inode->i_private;
961 return 0;
962}
963
964static int debug_lpm_close(struct inode *inode, struct file *file)
965{
966 return 0;
967}
968
969static ssize_t debug_lpm_read(struct file *file, char __user *user_buf,
970 size_t count, loff_t *ppos)
971{
972 /* TODO: show lpm stats */
973 return 0;
974}
975
976static ssize_t debug_lpm_write(struct file *file, const char __user *user_buf,
977 size_t count, loff_t *ppos)
978{
979 struct usb_hcd *hcd;
980 struct ehci_hcd *ehci;
981 char buf[50];
982 size_t len;
983 u32 temp;
984 unsigned long port;
985 u32 __iomem *portsc ;
986 u32 params;
987
988 hcd = bus_to_hcd(file->private_data);
989 ehci = hcd_to_ehci(hcd);
990
991 len = min(count, sizeof(buf) - 1);
992 if (copy_from_user(buf, user_buf, len))
993 return -EFAULT;
994 buf[len] = '\0';
995 if (len > 0 && buf[len - 1] == '\n')
996 buf[len - 1] = '\0';
997
998 if (strncmp(buf, "enable", 5) == 0) {
999 if (strict_strtoul(buf + 7, 10, &port))
1000 return -EINVAL;
1001 params = ehci_readl(ehci, &ehci->caps->hcs_params);
1002 if (port > HCS_N_PORTS(params)) {
1003 ehci_dbg(ehci, "ERR: LPM on bad port %lu\n", port);
1004 return -ENODEV;
1005 }
1006 portsc = &ehci->regs->port_status[port-1];
1007 temp = ehci_readl(ehci, portsc);
1008 if (!(temp & PORT_DEV_ADDR)) {
1009 ehci_dbg(ehci, "LPM: no device attached\n");
1010 return -ENODEV;
1011 }
1012 temp |= PORT_LPM;
1013 ehci_writel(ehci, temp, portsc);
1014 printk(KERN_INFO "force enable LPM for port %lu\n", port);
1015 } else if (strncmp(buf, "hird=", 5) == 0) {
1016 unsigned long hird;
1017 if (strict_strtoul(buf + 5, 16, &hird))
1018 return -EINVAL;
1019 printk(KERN_INFO "setting hird %s %lu\n", buf + 6, hird);
1020 temp = ehci_readl(ehci, &ehci->regs->command);
1021 temp &= ~CMD_HIRD;
1022 temp |= hird << 24;
1023 ehci_writel(ehci, temp, &ehci->regs->command);
1024 } else if (strncmp(buf, "disable", 7) == 0) {
1025 if (strict_strtoul(buf + 8, 10, &port))
1026 return -EINVAL;
1027 params = ehci_readl(ehci, &ehci->caps->hcs_params);
1028 if (port > HCS_N_PORTS(params)) {
1029 ehci_dbg(ehci, "ERR: LPM off bad port %lu\n", port);
1030 return -ENODEV;
1031 }
1032 portsc = &ehci->regs->port_status[port-1];
1033 temp = ehci_readl(ehci, portsc);
1034 if (!(temp & PORT_DEV_ADDR)) {
1035 ehci_dbg(ehci, "ERR: no device attached\n");
1036 return -ENODEV;
1037 }
1038 temp &= ~PORT_LPM;
1039 ehci_writel(ehci, temp, portsc);
1040 printk(KERN_INFO "disabled LPM for port %lu\n", port);
1041 } else
1042 return -EOPNOTSUPP;
1043 return count;
1044}
1045
920static inline void create_debug_files (struct ehci_hcd *ehci) 1046static inline void create_debug_files (struct ehci_hcd *ehci)
921{ 1047{
922 struct usb_bus *bus = &ehci_to_hcd(ehci)->self; 1048 struct usb_bus *bus = &ehci_to_hcd(ehci)->self;
923 1049
924 ehci->debug_dir = debugfs_create_dir(bus->bus_name, ehci_debug_root); 1050 ehci->debug_dir = debugfs_create_dir(bus->bus_name, ehci_debug_root);
925 if (!ehci->debug_dir) 1051 if (!ehci->debug_dir)
926 goto dir_error; 1052 return;
927 1053
928 ehci->debug_async = debugfs_create_file("async", S_IRUGO, 1054 if (!debugfs_create_file("async", S_IRUGO, ehci->debug_dir, bus,
929 ehci->debug_dir, bus, 1055 &debug_async_fops))
930 &debug_async_fops); 1056 goto file_error;
931 if (!ehci->debug_async) 1057
932 goto async_error; 1058 if (!debugfs_create_file("periodic", S_IRUGO, ehci->debug_dir, bus,
933 1059 &debug_periodic_fops))
934 ehci->debug_periodic = debugfs_create_file("periodic", S_IRUGO, 1060 goto file_error;
935 ehci->debug_dir, bus, 1061
936 &debug_periodic_fops); 1062 if (!debugfs_create_file("registers", S_IRUGO, ehci->debug_dir, bus,
937 if (!ehci->debug_periodic) 1063 &debug_registers_fops))
938 goto periodic_error; 1064 goto file_error;
939 1065
940 ehci->debug_registers = debugfs_create_file("registers", S_IRUGO, 1066 if (!debugfs_create_file("lpm", S_IRUGO|S_IWUGO, ehci->debug_dir, bus,
941 ehci->debug_dir, bus, 1067 &debug_lpm_fops))
942 &debug_registers_fops); 1068 goto file_error;
943 if (!ehci->debug_registers) 1069
944 goto registers_error;
945 return; 1070 return;
946 1071
947registers_error: 1072file_error:
948 debugfs_remove(ehci->debug_periodic); 1073 debugfs_remove_recursive(ehci->debug_dir);
949periodic_error:
950 debugfs_remove(ehci->debug_async);
951async_error:
952 debugfs_remove(ehci->debug_dir);
953dir_error:
954 ehci->debug_periodic = NULL;
955 ehci->debug_async = NULL;
956 ehci->debug_dir = NULL;
957} 1074}
958 1075
959static inline void remove_debug_files (struct ehci_hcd *ehci) 1076static inline void remove_debug_files (struct ehci_hcd *ehci)
960{ 1077{
961 debugfs_remove(ehci->debug_registers); 1078 debugfs_remove_recursive(ehci->debug_dir);
962 debugfs_remove(ehci->debug_periodic);
963 debugfs_remove(ehci->debug_async);
964 debugfs_remove(ehci->debug_dir);
965} 1079}
966 1080
967#endif /* STUB_DEBUG_FILES */ 1081#endif /* STUB_DEBUG_FILES */
diff --git a/drivers/usb/host/ehci-fsl.c b/drivers/usb/host/ehci-fsl.c
index 5cd967d28938..a416421abfa2 100644
--- a/drivers/usb/host/ehci-fsl.c
+++ b/drivers/usb/host/ehci-fsl.c
@@ -313,7 +313,8 @@ static int ehci_fsl_drv_suspend(struct device *dev)
313 struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd); 313 struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd);
314 void __iomem *non_ehci = hcd->regs; 314 void __iomem *non_ehci = hcd->regs;
315 315
316 ehci_prepare_ports_for_controller_suspend(hcd_to_ehci(hcd)); 316 ehci_prepare_ports_for_controller_suspend(hcd_to_ehci(hcd),
317 device_may_wakeup(dev));
317 if (!fsl_deep_sleep()) 318 if (!fsl_deep_sleep())
318 return 0; 319 return 0;
319 320
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index a3ef2a9d9dc2..34a928d3b7d2 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -36,6 +36,7 @@
36#include <linux/dma-mapping.h> 36#include <linux/dma-mapping.h>
37#include <linux/debugfs.h> 37#include <linux/debugfs.h>
38#include <linux/slab.h> 38#include <linux/slab.h>
39#include <linux/uaccess.h>
39 40
40#include <asm/byteorder.h> 41#include <asm/byteorder.h>
41#include <asm/io.h> 42#include <asm/io.h>
@@ -78,7 +79,13 @@ static const char hcd_name [] = "ehci_hcd";
78#define EHCI_TUNE_RL_TT 0 79#define EHCI_TUNE_RL_TT 0
79#define EHCI_TUNE_MULT_HS 1 /* 1-3 transactions/uframe; 4.10.3 */ 80#define EHCI_TUNE_MULT_HS 1 /* 1-3 transactions/uframe; 4.10.3 */
80#define EHCI_TUNE_MULT_TT 1 81#define EHCI_TUNE_MULT_TT 1
81#define EHCI_TUNE_FLS 2 /* (small) 256 frame schedule */ 82/*
83 * Some drivers think it's safe to schedule isochronous transfers more than
84 * 256 ms into the future (partly as a result of an old bug in the scheduling
85 * code). In an attempt to avoid trouble, we will use a minimum scheduling
86 * length of 512 frames instead of 256.
87 */
88#define EHCI_TUNE_FLS 1 /* (medium) 512-frame schedule */
82 89
83#define EHCI_IAA_MSECS 10 /* arbitrary */ 90#define EHCI_IAA_MSECS 10 /* arbitrary */
84#define EHCI_IO_JIFFIES (HZ/10) /* io watchdog > irq_thresh */ 91#define EHCI_IO_JIFFIES (HZ/10) /* io watchdog > irq_thresh */
@@ -100,6 +107,11 @@ static int ignore_oc = 0;
100module_param (ignore_oc, bool, S_IRUGO); 107module_param (ignore_oc, bool, S_IRUGO);
101MODULE_PARM_DESC (ignore_oc, "ignore bogus hardware overcurrent indications"); 108MODULE_PARM_DESC (ignore_oc, "ignore bogus hardware overcurrent indications");
102 109
110/* for link power management(LPM) feature */
111static unsigned int hird;
112module_param(hird, int, S_IRUGO);
113MODULE_PARM_DESC(hird, "host initiated resume duration, +1 for each 75us\n");
114
103#define INTR_MASK (STS_IAA | STS_FATAL | STS_PCD | STS_ERR | STS_INT) 115#define INTR_MASK (STS_IAA | STS_FATAL | STS_PCD | STS_ERR | STS_INT)
104 116
105/*-------------------------------------------------------------------------*/ 117/*-------------------------------------------------------------------------*/
@@ -304,6 +316,7 @@ static void end_unlink_async(struct ehci_hcd *ehci);
304static void ehci_work(struct ehci_hcd *ehci); 316static void ehci_work(struct ehci_hcd *ehci);
305 317
306#include "ehci-hub.c" 318#include "ehci-hub.c"
319#include "ehci-lpm.c"
307#include "ehci-mem.c" 320#include "ehci-mem.c"
308#include "ehci-q.c" 321#include "ehci-q.c"
309#include "ehci-sched.c" 322#include "ehci-sched.c"
@@ -577,6 +590,11 @@ static int ehci_init(struct usb_hcd *hcd)
577 if (log2_irq_thresh < 0 || log2_irq_thresh > 6) 590 if (log2_irq_thresh < 0 || log2_irq_thresh > 6)
578 log2_irq_thresh = 0; 591 log2_irq_thresh = 0;
579 temp = 1 << (16 + log2_irq_thresh); 592 temp = 1 << (16 + log2_irq_thresh);
593 if (HCC_PER_PORT_CHANGE_EVENT(hcc_params)) {
594 ehci->has_ppcd = 1;
595 ehci_dbg(ehci, "enable per-port change event\n");
596 temp |= CMD_PPCEE;
597 }
580 if (HCC_CANPARK(hcc_params)) { 598 if (HCC_CANPARK(hcc_params)) {
581 /* HW default park == 3, on hardware that supports it (like 599 /* HW default park == 3, on hardware that supports it (like
582 * NVidia and ALI silicon), maximizes throughput on the async 600 * NVidia and ALI silicon), maximizes throughput on the async
@@ -603,10 +621,22 @@ static int ehci_init(struct usb_hcd *hcd)
603 default: BUG(); 621 default: BUG();
604 } 622 }
605 } 623 }
624 if (HCC_LPM(hcc_params)) {
625 /* support link power management EHCI 1.1 addendum */
626 ehci_dbg(ehci, "support lpm\n");
627 ehci->has_lpm = 1;
628 if (hird > 0xf) {
629 ehci_dbg(ehci, "hird %d invalid, use default 0",
630 hird);
631 hird = 0;
632 }
633 temp |= hird << 24;
634 }
606 ehci->command = temp; 635 ehci->command = temp;
607 636
608 /* Accept arbitrarily long scatter-gather lists */ 637 /* Accept arbitrarily long scatter-gather lists */
609 hcd->self.sg_tablesize = ~0; 638 if (!(hcd->driver->flags & HCD_LOCAL_MEM))
639 hcd->self.sg_tablesize = ~0;
610 return 0; 640 return 0;
611} 641}
612 642
@@ -619,7 +649,6 @@ static int ehci_run (struct usb_hcd *hcd)
619 u32 hcc_params; 649 u32 hcc_params;
620 650
621 hcd->uses_new_polling = 1; 651 hcd->uses_new_polling = 1;
622 hcd->poll_rh = 0;
623 652
624 /* EHCI spec section 4.1 */ 653 /* EHCI spec section 4.1 */
625 if ((retval = ehci_reset(ehci)) != 0) { 654 if ((retval = ehci_reset(ehci)) != 0) {
@@ -764,6 +793,7 @@ static irqreturn_t ehci_irq (struct usb_hcd *hcd)
764 /* remote wakeup [4.3.1] */ 793 /* remote wakeup [4.3.1] */
765 if (status & STS_PCD) { 794 if (status & STS_PCD) {
766 unsigned i = HCS_N_PORTS (ehci->hcs_params); 795 unsigned i = HCS_N_PORTS (ehci->hcs_params);
796 u32 ppcd = 0;
767 797
768 /* kick root hub later */ 798 /* kick root hub later */
769 pcd_status = status; 799 pcd_status = status;
@@ -772,9 +802,18 @@ static irqreturn_t ehci_irq (struct usb_hcd *hcd)
772 if (!(cmd & CMD_RUN)) 802 if (!(cmd & CMD_RUN))
773 usb_hcd_resume_root_hub(hcd); 803 usb_hcd_resume_root_hub(hcd);
774 804
805 /* get per-port change detect bits */
806 if (ehci->has_ppcd)
807 ppcd = status >> 16;
808
775 while (i--) { 809 while (i--) {
776 int pstatus = ehci_readl(ehci, 810 int pstatus;
777 &ehci->regs->port_status [i]); 811
812 /* leverage per-port change bits feature */
813 if (ehci->has_ppcd && !(ppcd & (1 << i)))
814 continue;
815 pstatus = ehci_readl(ehci,
816 &ehci->regs->port_status[i]);
778 817
779 if (pstatus & PORT_OWNER) 818 if (pstatus & PORT_OWNER)
780 continue; 819 continue;
diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
index e7d3d8def282..796ea0c8900f 100644
--- a/drivers/usb/host/ehci-hub.c
+++ b/drivers/usb/host/ehci-hub.c
@@ -107,7 +107,7 @@ static void ehci_handover_companion_ports(struct ehci_hcd *ehci)
107} 107}
108 108
109static void ehci_adjust_port_wakeup_flags(struct ehci_hcd *ehci, 109static void ehci_adjust_port_wakeup_flags(struct ehci_hcd *ehci,
110 bool suspending) 110 bool suspending, bool do_wakeup)
111{ 111{
112 int port; 112 int port;
113 u32 temp; 113 u32 temp;
@@ -117,8 +117,7 @@ static void ehci_adjust_port_wakeup_flags(struct ehci_hcd *ehci,
117 * when the controller is suspended or resumed. In all other 117 * when the controller is suspended or resumed. In all other
118 * cases they don't need to be changed. 118 * cases they don't need to be changed.
119 */ 119 */
120 if (!ehci_to_hcd(ehci)->self.root_hub->do_remote_wakeup || 120 if (!ehci_to_hcd(ehci)->self.root_hub->do_remote_wakeup || do_wakeup)
121 device_may_wakeup(ehci_to_hcd(ehci)->self.controller))
122 return; 121 return;
123 122
124 /* clear phy low-power mode before changing wakeup flags */ 123 /* clear phy low-power mode before changing wakeup flags */
@@ -167,6 +166,10 @@ static void ehci_adjust_port_wakeup_flags(struct ehci_hcd *ehci,
167 ehci_writel(ehci, temp | HOSTPC_PHCD, hostpc_reg); 166 ehci_writel(ehci, temp | HOSTPC_PHCD, hostpc_reg);
168 } 167 }
169 } 168 }
169
170 /* Does the root hub have a port wakeup pending? */
171 if (!suspending && (ehci_readl(ehci, &ehci->regs->status) & STS_PCD))
172 usb_hcd_resume_root_hub(ehci_to_hcd(ehci));
170} 173}
171 174
172static int ehci_bus_suspend (struct usb_hcd *hcd) 175static int ehci_bus_suspend (struct usb_hcd *hcd)
@@ -316,7 +319,7 @@ static int ehci_bus_resume (struct usb_hcd *hcd)
316 if (time_before (jiffies, ehci->next_statechange)) 319 if (time_before (jiffies, ehci->next_statechange))
317 msleep(5); 320 msleep(5);
318 spin_lock_irq (&ehci->lock); 321 spin_lock_irq (&ehci->lock);
319 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) { 322 if (!HCD_HW_ACCESSIBLE(hcd)) {
320 spin_unlock_irq(&ehci->lock); 323 spin_unlock_irq(&ehci->lock);
321 return -ESHUTDOWN; 324 return -ESHUTDOWN;
322 } 325 }
@@ -603,6 +606,7 @@ ehci_hub_status_data (struct usb_hcd *hcd, char *buf)
603 u32 mask; 606 u32 mask;
604 int ports, i, retval = 1; 607 int ports, i, retval = 1;
605 unsigned long flags; 608 unsigned long flags;
609 u32 ppcd = 0;
606 610
607 /* if !USB_SUSPEND, root hub timers won't get shut down ... */ 611 /* if !USB_SUSPEND, root hub timers won't get shut down ... */
608 if (!HC_IS_RUNNING(hcd->state)) 612 if (!HC_IS_RUNNING(hcd->state))
@@ -632,7 +636,15 @@ ehci_hub_status_data (struct usb_hcd *hcd, char *buf)
632 636
633 /* port N changes (bit N)? */ 637 /* port N changes (bit N)? */
634 spin_lock_irqsave (&ehci->lock, flags); 638 spin_lock_irqsave (&ehci->lock, flags);
639
640 /* get per-port change detect bits */
641 if (ehci->has_ppcd)
642 ppcd = ehci_readl(ehci, &ehci->regs->status) >> 16;
643
635 for (i = 0; i < ports; i++) { 644 for (i = 0; i < ports; i++) {
645 /* leverage per-port change bits feature */
646 if (ehci->has_ppcd && !(ppcd & (1 << i)))
647 continue;
636 temp = ehci_readl(ehci, &ehci->regs->port_status [i]); 648 temp = ehci_readl(ehci, &ehci->regs->port_status [i]);
637 649
638 /* 650 /*
@@ -790,6 +802,11 @@ static int ehci_hub_control (
790 status_reg); 802 status_reg);
791 break; 803 break;
792 case USB_PORT_FEAT_C_CONNECTION: 804 case USB_PORT_FEAT_C_CONNECTION:
805 if (ehci->has_lpm) {
806 /* clear PORTSC bits on disconnect */
807 temp &= ~PORT_LPM;
808 temp &= ~PORT_DEV_ADDR;
809 }
793 ehci_writel(ehci, (temp & ~PORT_RWC_BITS) | PORT_CSC, 810 ehci_writel(ehci, (temp & ~PORT_RWC_BITS) | PORT_CSC,
794 status_reg); 811 status_reg);
795 break; 812 break;
diff --git a/drivers/usb/host/ehci-lpm.c b/drivers/usb/host/ehci-lpm.c
new file mode 100644
index 000000000000..b4d4d63c13ed
--- /dev/null
+++ b/drivers/usb/host/ehci-lpm.c
@@ -0,0 +1,83 @@
1/* ehci-lpm.c EHCI HCD LPM support code
2 * Copyright (c) 2008 - 2010, Intel Corporation.
3 * Author: Jacob Pan <jacob.jun.pan@intel.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17*/
18
19/* this file is part of ehci-hcd.c */
20static int ehci_lpm_set_da(struct ehci_hcd *ehci, int dev_addr, int port_num)
21{
22 u32 __iomem portsc;
23
24 ehci_dbg(ehci, "set dev address %d for port %d\n", dev_addr, port_num);
25 if (port_num > HCS_N_PORTS(ehci->hcs_params)) {
26 ehci_dbg(ehci, "invalid port number %d\n", port_num);
27 return -ENODEV;
28 }
29 portsc = ehci_readl(ehci, &ehci->regs->port_status[port_num-1]);
30 portsc &= ~PORT_DEV_ADDR;
31 portsc |= dev_addr<<25;
32 ehci_writel(ehci, portsc, &ehci->regs->port_status[port_num-1]);
33 return 0;
34}
35
36/*
37 * this function is used to check if the device support LPM
38 * if yes, mark the PORTSC register with PORT_LPM bit
39 */
40static int ehci_lpm_check(struct ehci_hcd *ehci, int port)
41{
42 u32 __iomem *portsc ;
43 u32 val32;
44 int retval;
45
46 portsc = &ehci->regs->port_status[port-1];
47 val32 = ehci_readl(ehci, portsc);
48 if (!(val32 & PORT_DEV_ADDR)) {
49 ehci_dbg(ehci, "LPM: no device attached\n");
50 return -ENODEV;
51 }
52 val32 |= PORT_LPM;
53 ehci_writel(ehci, val32, portsc);
54 msleep(5);
55 val32 |= PORT_SUSPEND;
56 ehci_dbg(ehci, "Sending LPM 0x%08x to port %d\n", val32, port);
57 ehci_writel(ehci, val32, portsc);
58 /* wait for ACK */
59 msleep(10);
60 retval = handshake(ehci, &ehci->regs->port_status[port-1], PORT_SSTS,
61 PORTSC_SUSPEND_STS_ACK, 125);
62 dbg_port(ehci, "LPM", port, val32);
63 if (retval != -ETIMEDOUT) {
64 ehci_dbg(ehci, "LPM: device ACK for LPM\n");
65 val32 |= PORT_LPM;
66 /*
67 * now device should be in L1 sleep, let's wake up the device
68 * so that we can complete enumeration.
69 */
70 ehci_writel(ehci, val32, portsc);
71 msleep(10);
72 val32 |= PORT_RESUME;
73 ehci_writel(ehci, val32, portsc);
74 } else {
75 ehci_dbg(ehci, "LPM: device does not ACK, disable LPM %d\n",
76 retval);
77 val32 &= ~PORT_LPM;
78 retval = -ETIMEDOUT;
79 ehci_writel(ehci, val32, portsc);
80 }
81
82 return retval;
83}
diff --git a/drivers/usb/host/ehci-omap.c b/drivers/usb/host/ehci-omap.c
index 5450e628157f..116ae280053a 100644
--- a/drivers/usb/host/ehci-omap.c
+++ b/drivers/usb/host/ehci-omap.c
@@ -38,6 +38,7 @@
38#include <linux/gpio.h> 38#include <linux/gpio.h>
39#include <linux/regulator/consumer.h> 39#include <linux/regulator/consumer.h>
40#include <linux/slab.h> 40#include <linux/slab.h>
41#include <linux/usb/ulpi.h>
41#include <plat/usb.h> 42#include <plat/usb.h>
42 43
43/* 44/*
@@ -236,6 +237,35 @@ static void omap_usb_utmi_init(struct ehci_hcd_omap *omap, u8 tll_channel_mask)
236 237
237/*-------------------------------------------------------------------------*/ 238/*-------------------------------------------------------------------------*/
238 239
240static void omap_ehci_soft_phy_reset(struct ehci_hcd_omap *omap, u8 port)
241{
242 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
243 unsigned reg = 0;
244
245 reg = ULPI_FUNC_CTRL_RESET
246 /* FUNCTION_CTRL_SET register */
247 | (ULPI_SET(ULPI_FUNC_CTRL) << EHCI_INSNREG05_ULPI_REGADD_SHIFT)
248 /* Write */
249 | (2 << EHCI_INSNREG05_ULPI_OPSEL_SHIFT)
250 /* PORTn */
251 | ((port + 1) << EHCI_INSNREG05_ULPI_PORTSEL_SHIFT)
252 /* start ULPI access*/
253 | (1 << EHCI_INSNREG05_ULPI_CONTROL_SHIFT);
254
255 ehci_omap_writel(omap->ehci_base, EHCI_INSNREG05_ULPI, reg);
256
257 /* Wait for ULPI access completion */
258 while ((ehci_omap_readl(omap->ehci_base, EHCI_INSNREG05_ULPI)
259 & (1 << EHCI_INSNREG05_ULPI_CONTROL_SHIFT))) {
260 cpu_relax();
261
262 if (time_after(jiffies, timeout)) {
263 dev_dbg(omap->dev, "phy reset operation timed out\n");
264 break;
265 }
266 }
267}
268
239/* omap_start_ehc 269/* omap_start_ehc
240 * - Start the TI USBHOST controller 270 * - Start the TI USBHOST controller
241 */ 271 */
@@ -425,6 +455,12 @@ static int omap_start_ehc(struct ehci_hcd_omap *omap, struct usb_hcd *hcd)
425 gpio_set_value(omap->reset_gpio_port[1], 1); 455 gpio_set_value(omap->reset_gpio_port[1], 1);
426 } 456 }
427 457
458 /* Soft reset the PHY using PHY reset command over ULPI */
459 if (omap->port_mode[0] == EHCI_HCD_OMAP_MODE_PHY)
460 omap_ehci_soft_phy_reset(omap, 0);
461 if (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_PHY)
462 omap_ehci_soft_phy_reset(omap, 1);
463
428 return 0; 464 return 0;
429 465
430err_sys_status: 466err_sys_status:
diff --git a/drivers/usb/host/ehci-pci.c b/drivers/usb/host/ehci-pci.c
index d43d176161aa..58b72d741d93 100644
--- a/drivers/usb/host/ehci-pci.c
+++ b/drivers/usb/host/ehci-pci.c
@@ -114,6 +114,7 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
114 break; 114 break;
115 case PCI_VENDOR_ID_INTEL: 115 case PCI_VENDOR_ID_INTEL:
116 ehci->need_io_watchdog = 0; 116 ehci->need_io_watchdog = 0;
117 ehci->fs_i_thresh = 1;
117 if (pdev->device == 0x27cc) { 118 if (pdev->device == 0x27cc) {
118 ehci->broken_periodic = 1; 119 ehci->broken_periodic = 1;
119 ehci_info(ehci, "using broken periodic workaround\n"); 120 ehci_info(ehci, "using broken periodic workaround\n");
@@ -277,7 +278,7 @@ done:
277 * Also they depend on separate root hub suspend/resume. 278 * Also they depend on separate root hub suspend/resume.
278 */ 279 */
279 280
280static int ehci_pci_suspend(struct usb_hcd *hcd) 281static int ehci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup)
281{ 282{
282 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 283 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
283 unsigned long flags; 284 unsigned long flags;
@@ -291,7 +292,7 @@ static int ehci_pci_suspend(struct usb_hcd *hcd)
291 * the root hub is either suspended or stopped. 292 * the root hub is either suspended or stopped.
292 */ 293 */
293 spin_lock_irqsave (&ehci->lock, flags); 294 spin_lock_irqsave (&ehci->lock, flags);
294 ehci_prepare_ports_for_controller_suspend(ehci); 295 ehci_prepare_ports_for_controller_suspend(ehci, do_wakeup);
295 ehci_writel(ehci, 0, &ehci->regs->intr_enable); 296 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
296 (void)ehci_readl(ehci, &ehci->regs->intr_enable); 297 (void)ehci_readl(ehci, &ehci->regs->intr_enable);
297 298
@@ -361,6 +362,22 @@ static int ehci_pci_resume(struct usb_hcd *hcd, bool hibernated)
361} 362}
362#endif 363#endif
363 364
365static int ehci_update_device(struct usb_hcd *hcd, struct usb_device *udev)
366{
367 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
368 int rc = 0;
369
370 if (!udev->parent) /* udev is root hub itself, impossible */
371 rc = -1;
372 /* we only support lpm device connected to root hub yet */
373 if (ehci->has_lpm && !udev->parent->parent) {
374 rc = ehci_lpm_set_da(ehci, udev->devnum, udev->portnum);
375 if (!rc)
376 rc = ehci_lpm_check(ehci, udev->portnum);
377 }
378 return rc;
379}
380
364static const struct hc_driver ehci_pci_hc_driver = { 381static const struct hc_driver ehci_pci_hc_driver = {
365 .description = hcd_name, 382 .description = hcd_name,
366 .product_desc = "EHCI Host Controller", 383 .product_desc = "EHCI Host Controller",
@@ -407,6 +424,11 @@ static const struct hc_driver ehci_pci_hc_driver = {
407 .relinquish_port = ehci_relinquish_port, 424 .relinquish_port = ehci_relinquish_port,
408 .port_handed_over = ehci_port_handed_over, 425 .port_handed_over = ehci_port_handed_over,
409 426
427 /*
428 * call back when device connected and addressed
429 */
430 .update_device = ehci_update_device,
431
410 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, 432 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
411}; 433};
412 434
diff --git a/drivers/usb/host/ehci-ppc-of.c b/drivers/usb/host/ehci-ppc-of.c
index 5aec92866ab3..335ee699fd85 100644
--- a/drivers/usb/host/ehci-ppc-of.c
+++ b/drivers/usb/host/ehci-ppc-of.c
@@ -106,7 +106,7 @@ ppc44x_enable_bmt(struct device_node *dn)
106 106
107 107
108static int __devinit 108static int __devinit
109ehci_hcd_ppc_of_probe(struct of_device *op, const struct of_device_id *match) 109ehci_hcd_ppc_of_probe(struct platform_device *op, const struct of_device_id *match)
110{ 110{
111 struct device_node *dn = op->dev.of_node; 111 struct device_node *dn = op->dev.of_node;
112 struct usb_hcd *hcd; 112 struct usb_hcd *hcd;
@@ -210,7 +210,7 @@ err_rmr:
210} 210}
211 211
212 212
213static int ehci_hcd_ppc_of_remove(struct of_device *op) 213static int ehci_hcd_ppc_of_remove(struct platform_device *op)
214{ 214{
215 struct usb_hcd *hcd = dev_get_drvdata(&op->dev); 215 struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
216 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 216 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
@@ -253,7 +253,7 @@ static int ehci_hcd_ppc_of_remove(struct of_device *op)
253} 253}
254 254
255 255
256static int ehci_hcd_ppc_of_shutdown(struct of_device *op) 256static int ehci_hcd_ppc_of_shutdown(struct platform_device *op)
257{ 257{
258 struct usb_hcd *hcd = dev_get_drvdata(&op->dev); 258 struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
259 259
diff --git a/drivers/usb/host/ehci-q.c b/drivers/usb/host/ehci-q.c
index 11a79c4f4a9d..233c288e3f93 100644
--- a/drivers/usb/host/ehci-q.c
+++ b/drivers/usb/host/ehci-q.c
@@ -1126,8 +1126,7 @@ submit_async (
1126#endif 1126#endif
1127 1127
1128 spin_lock_irqsave (&ehci->lock, flags); 1128 spin_lock_irqsave (&ehci->lock, flags);
1129 if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, 1129 if (unlikely(!HCD_HW_ACCESSIBLE(ehci_to_hcd(ehci)))) {
1130 &ehci_to_hcd(ehci)->flags))) {
1131 rc = -ESHUTDOWN; 1130 rc = -ESHUTDOWN;
1132 goto done; 1131 goto done;
1133 } 1132 }
diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
index 805ec633a652..a92526d6e5ae 100644
--- a/drivers/usb/host/ehci-sched.c
+++ b/drivers/usb/host/ehci-sched.c
@@ -880,8 +880,7 @@ static int intr_submit (
880 880
881 spin_lock_irqsave (&ehci->lock, flags); 881 spin_lock_irqsave (&ehci->lock, flags);
882 882
883 if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, 883 if (unlikely(!HCD_HW_ACCESSIBLE(ehci_to_hcd(ehci)))) {
884 &ehci_to_hcd(ehci)->flags))) {
885 status = -ESHUTDOWN; 884 status = -ESHUTDOWN;
886 goto done_not_linked; 885 goto done_not_linked;
887 } 886 }
@@ -1075,15 +1074,6 @@ iso_stream_put(struct ehci_hcd *ehci, struct ehci_iso_stream *stream)
1075 if (stream->ep) 1074 if (stream->ep)
1076 stream->ep->hcpriv = NULL; 1075 stream->ep->hcpriv = NULL;
1077 1076
1078 if (stream->rescheduled) {
1079 ehci_info (ehci, "ep%d%s-iso rescheduled "
1080 "%lu times in %lu seconds\n",
1081 stream->bEndpointAddress, is_in ? "in" : "out",
1082 stream->rescheduled,
1083 ((jiffies - stream->start)/HZ)
1084 );
1085 }
1086
1087 kfree(stream); 1077 kfree(stream);
1088 } 1078 }
1089} 1079}
@@ -1396,30 +1386,25 @@ iso_stream_schedule (
1396 struct ehci_iso_stream *stream 1386 struct ehci_iso_stream *stream
1397) 1387)
1398{ 1388{
1399 u32 now, next, start, period; 1389 u32 now, next, start, period, span;
1400 int status; 1390 int status;
1401 unsigned mod = ehci->periodic_size << 3; 1391 unsigned mod = ehci->periodic_size << 3;
1402 struct ehci_iso_sched *sched = urb->hcpriv; 1392 struct ehci_iso_sched *sched = urb->hcpriv;
1403 struct pci_dev *pdev;
1404 1393
1405 if (sched->span > (mod - SCHEDULE_SLOP)) { 1394 period = urb->interval;
1406 ehci_dbg (ehci, "iso request %p too long\n", urb); 1395 span = sched->span;
1407 status = -EFBIG; 1396 if (!stream->highspeed) {
1408 goto fail; 1397 period <<= 3;
1398 span <<= 3;
1409 } 1399 }
1410 1400
1411 if ((stream->depth + sched->span) > mod) { 1401 if (span > mod - SCHEDULE_SLOP) {
1412 ehci_dbg (ehci, "request %p would overflow (%d+%d>%d)\n", 1402 ehci_dbg (ehci, "iso request %p too long\n", urb);
1413 urb, stream->depth, sched->span, mod);
1414 status = -EFBIG; 1403 status = -EFBIG;
1415 goto fail; 1404 goto fail;
1416 } 1405 }
1417 1406
1418 period = urb->interval; 1407 now = ehci_readl(ehci, &ehci->regs->frame_index) & (mod - 1);
1419 if (!stream->highspeed)
1420 period <<= 3;
1421
1422 now = ehci_readl(ehci, &ehci->regs->frame_index) % mod;
1423 1408
1424 /* Typical case: reuse current schedule, stream is still active. 1409 /* Typical case: reuse current schedule, stream is still active.
1425 * Hopefully there are no gaps from the host falling behind 1410 * Hopefully there are no gaps from the host falling behind
@@ -1427,34 +1412,35 @@ iso_stream_schedule (
1427 * slot in the schedule, implicitly assuming URB_ISO_ASAP. 1412 * slot in the schedule, implicitly assuming URB_ISO_ASAP.
1428 */ 1413 */
1429 if (likely (!list_empty (&stream->td_list))) { 1414 if (likely (!list_empty (&stream->td_list))) {
1430 pdev = to_pci_dev(ehci_to_hcd(ehci)->self.controller); 1415 u32 excess;
1431 start = stream->next_uframe;
1432 1416
1433 /* For high speed devices, allow scheduling within the 1417 /* For high speed devices, allow scheduling within the
1434 * isochronous scheduling threshold. For full speed devices, 1418 * isochronous scheduling threshold. For full speed devices
1435 * don't. (Work around for Intel ICH9 bug.) 1419 * and Intel PCI-based controllers, don't (work around for
1420 * Intel ICH9 bug).
1436 */ 1421 */
1437 if (!stream->highspeed && 1422 if (!stream->highspeed && ehci->fs_i_thresh)
1438 pdev->vendor == PCI_VENDOR_ID_INTEL)
1439 next = now + ehci->i_thresh; 1423 next = now + ehci->i_thresh;
1440 else 1424 else
1441 next = now; 1425 next = now;
1442 1426
1443 /* Fell behind (by up to twice the slop amount)? */ 1427 /* Fell behind (by up to twice the slop amount)?
1444 if (((start - next) & (mod - 1)) >= 1428 * We decide based on the time of the last currently-scheduled
1445 mod - 2 * SCHEDULE_SLOP) 1429 * slot, not the time of the next available slot.
1446 start += period * DIV_ROUND_UP( 1430 */
1447 (next - start) & (mod - 1), 1431 excess = (stream->next_uframe - period - next) & (mod - 1);
1448 period); 1432 if (excess >= mod - 2 * SCHEDULE_SLOP)
1449 1433 start = next + excess - mod + period *
1450 /* Tried to schedule too far into the future? */ 1434 DIV_ROUND_UP(mod - excess, period);
1451 if (unlikely(((start - now) & (mod - 1)) + sched->span 1435 else
1452 >= mod - 2 * SCHEDULE_SLOP)) { 1436 start = next + excess + period;
1437 if (start - now >= mod) {
1438 ehci_dbg(ehci, "request %p would overflow (%d+%d >= %d)\n",
1439 urb, start - now - period, period,
1440 mod);
1453 status = -EFBIG; 1441 status = -EFBIG;
1454 goto fail; 1442 goto fail;
1455 } 1443 }
1456 stream->next_uframe = start;
1457 goto ready;
1458 } 1444 }
1459 1445
1460 /* need to schedule; when's the next (u)frame we could start? 1446 /* need to schedule; when's the next (u)frame we could start?
@@ -1463,51 +1449,60 @@ iso_stream_schedule (
1463 * can also help high bandwidth if the dma and irq loads don't 1449 * can also help high bandwidth if the dma and irq loads don't
1464 * jump until after the queue is primed. 1450 * jump until after the queue is primed.
1465 */ 1451 */
1466 start = SCHEDULE_SLOP + (now & ~0x07); 1452 else {
1467 start %= mod; 1453 start = SCHEDULE_SLOP + (now & ~0x07);
1468 stream->next_uframe = start; 1454
1469 1455 /* NOTE: assumes URB_ISO_ASAP, to limit complexity/bugs */
1470 /* NOTE: assumes URB_ISO_ASAP, to limit complexity/bugs */ 1456
1471 1457 /* find a uframe slot with enough bandwidth */
1472 /* find a uframe slot with enough bandwidth */ 1458 next = start + period;
1473 for (; start < (stream->next_uframe + period); start++) { 1459 for (; start < next; start++) {
1474 int enough_space; 1460
1475 1461 /* check schedule: enough space? */
1476 /* check schedule: enough space? */ 1462 if (stream->highspeed) {
1477 if (stream->highspeed) 1463 if (itd_slot_ok(ehci, mod, start,
1478 enough_space = itd_slot_ok (ehci, mod, start, 1464 stream->usecs, period))
1479 stream->usecs, period); 1465 break;
1480 else { 1466 } else {
1481 if ((start % 8) >= 6) 1467 if ((start % 8) >= 6)
1482 continue; 1468 continue;
1483 enough_space = sitd_slot_ok (ehci, mod, stream, 1469 if (sitd_slot_ok(ehci, mod, stream,
1484 start, sched, period); 1470 start, sched, period))
1471 break;
1472 }
1485 } 1473 }
1486 1474
1487 /* schedule it here if there's enough bandwidth */ 1475 /* no room in the schedule */
1488 if (enough_space) { 1476 if (start == next) {
1489 stream->next_uframe = start % mod; 1477 ehci_dbg(ehci, "iso resched full %p (now %d max %d)\n",
1490 goto ready; 1478 urb, now, now + mod);
1479 status = -ENOSPC;
1480 goto fail;
1491 } 1481 }
1492 } 1482 }
1493 1483
1494 /* no room in the schedule */ 1484 /* Tried to schedule too far into the future? */
1495 ehci_dbg (ehci, "iso %ssched full %p (now %d max %d)\n", 1485 if (unlikely(start - now + span - period
1496 list_empty (&stream->td_list) ? "" : "re", 1486 >= mod - 2 * SCHEDULE_SLOP)) {
1497 urb, now, now + mod); 1487 ehci_dbg(ehci, "request %p would overflow (%d+%d >= %d)\n",
1498 status = -ENOSPC; 1488 urb, start - now, span - period,
1489 mod - 2 * SCHEDULE_SLOP);
1490 status = -EFBIG;
1491 goto fail;
1492 }
1499 1493
1500fail: 1494 stream->next_uframe = start & (mod - 1);
1501 iso_sched_free (stream, sched);
1502 urb->hcpriv = NULL;
1503 return status;
1504 1495
1505ready:
1506 /* report high speed start in uframes; full speed, in frames */ 1496 /* report high speed start in uframes; full speed, in frames */
1507 urb->start_frame = stream->next_uframe; 1497 urb->start_frame = stream->next_uframe;
1508 if (!stream->highspeed) 1498 if (!stream->highspeed)
1509 urb->start_frame >>= 3; 1499 urb->start_frame >>= 3;
1510 return 0; 1500 return 0;
1501
1502 fail:
1503 iso_sched_free(stream, sched);
1504 urb->hcpriv = NULL;
1505 return status;
1511} 1506}
1512 1507
1513/*-------------------------------------------------------------------------*/ 1508/*-------------------------------------------------------------------------*/
@@ -1602,7 +1597,7 @@ itd_link_urb (
1602 struct ehci_iso_sched *iso_sched = urb->hcpriv; 1597 struct ehci_iso_sched *iso_sched = urb->hcpriv;
1603 struct ehci_itd *itd; 1598 struct ehci_itd *itd;
1604 1599
1605 next_uframe = stream->next_uframe % mod; 1600 next_uframe = stream->next_uframe & (mod - 1);
1606 1601
1607 if (unlikely (list_empty(&stream->td_list))) { 1602 if (unlikely (list_empty(&stream->td_list))) {
1608 ehci_to_hcd(ehci)->self.bandwidth_allocated 1603 ehci_to_hcd(ehci)->self.bandwidth_allocated
@@ -1613,7 +1608,6 @@ itd_link_urb (
1613 (stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out", 1608 (stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out",
1614 urb->interval, 1609 urb->interval,
1615 next_uframe >> 3, next_uframe & 0x7); 1610 next_uframe >> 3, next_uframe & 0x7);
1616 stream->start = jiffies;
1617 } 1611 }
1618 ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs++; 1612 ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs++;
1619 1613
@@ -1639,14 +1633,13 @@ itd_link_urb (
1639 itd_patch(ehci, itd, iso_sched, packet, uframe); 1633 itd_patch(ehci, itd, iso_sched, packet, uframe);
1640 1634
1641 next_uframe += stream->interval; 1635 next_uframe += stream->interval;
1642 stream->depth += stream->interval; 1636 next_uframe &= mod - 1;
1643 next_uframe %= mod;
1644 packet++; 1637 packet++;
1645 1638
1646 /* link completed itds into the schedule */ 1639 /* link completed itds into the schedule */
1647 if (((next_uframe >> 3) != frame) 1640 if (((next_uframe >> 3) != frame)
1648 || packet == urb->number_of_packets) { 1641 || packet == urb->number_of_packets) {
1649 itd_link (ehci, frame % ehci->periodic_size, itd); 1642 itd_link(ehci, frame & (ehci->periodic_size - 1), itd);
1650 itd = NULL; 1643 itd = NULL;
1651 } 1644 }
1652 } 1645 }
@@ -1695,7 +1688,6 @@ itd_complete (
1695 1688
1696 t = hc32_to_cpup(ehci, &itd->hw_transaction [uframe]); 1689 t = hc32_to_cpup(ehci, &itd->hw_transaction [uframe]);
1697 itd->hw_transaction [uframe] = 0; 1690 itd->hw_transaction [uframe] = 0;
1698 stream->depth -= stream->interval;
1699 1691
1700 /* report transfer status */ 1692 /* report transfer status */
1701 if (unlikely (t & ISO_ERRS)) { 1693 if (unlikely (t & ISO_ERRS)) {
@@ -1815,8 +1807,7 @@ static int itd_submit (struct ehci_hcd *ehci, struct urb *urb,
1815 1807
1816 /* schedule ... need to lock */ 1808 /* schedule ... need to lock */
1817 spin_lock_irqsave (&ehci->lock, flags); 1809 spin_lock_irqsave (&ehci->lock, flags);
1818 if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, 1810 if (unlikely(!HCD_HW_ACCESSIBLE(ehci_to_hcd(ehci)))) {
1819 &ehci_to_hcd(ehci)->flags))) {
1820 status = -ESHUTDOWN; 1811 status = -ESHUTDOWN;
1821 goto done_not_linked; 1812 goto done_not_linked;
1822 } 1813 }
@@ -2024,9 +2015,8 @@ sitd_link_urb (
2024 "sched devp %s ep%d%s-iso [%d] %dms/%04x\n", 2015 "sched devp %s ep%d%s-iso [%d] %dms/%04x\n",
2025 urb->dev->devpath, stream->bEndpointAddress & 0x0f, 2016 urb->dev->devpath, stream->bEndpointAddress & 0x0f,
2026 (stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out", 2017 (stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out",
2027 (next_uframe >> 3) % ehci->periodic_size, 2018 (next_uframe >> 3) & (ehci->periodic_size - 1),
2028 stream->interval, hc32_to_cpu(ehci, stream->splits)); 2019 stream->interval, hc32_to_cpu(ehci, stream->splits));
2029 stream->start = jiffies;
2030 } 2020 }
2031 ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs++; 2021 ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs++;
2032 2022
@@ -2047,13 +2037,12 @@ sitd_link_urb (
2047 sitd->urb = urb; 2037 sitd->urb = urb;
2048 2038
2049 sitd_patch(ehci, stream, sitd, sched, packet); 2039 sitd_patch(ehci, stream, sitd, sched, packet);
2050 sitd_link (ehci, (next_uframe >> 3) % ehci->periodic_size, 2040 sitd_link(ehci, (next_uframe >> 3) & (ehci->periodic_size - 1),
2051 sitd); 2041 sitd);
2052 2042
2053 next_uframe += stream->interval << 3; 2043 next_uframe += stream->interval << 3;
2054 stream->depth += stream->interval << 3;
2055 } 2044 }
2056 stream->next_uframe = next_uframe % mod; 2045 stream->next_uframe = next_uframe & (mod - 1);
2057 2046
2058 /* don't need that schedule data any more */ 2047 /* don't need that schedule data any more */
2059 iso_sched_free (stream, sched); 2048 iso_sched_free (stream, sched);
@@ -2111,7 +2100,6 @@ sitd_complete (
2111 desc->actual_length = desc->length - SITD_LENGTH(t); 2100 desc->actual_length = desc->length - SITD_LENGTH(t);
2112 urb->actual_length += desc->actual_length; 2101 urb->actual_length += desc->actual_length;
2113 } 2102 }
2114 stream->depth -= stream->interval << 3;
2115 2103
2116 /* handle completion now? */ 2104 /* handle completion now? */
2117 if ((urb_index + 1) != urb->number_of_packets) 2105 if ((urb_index + 1) != urb->number_of_packets)
@@ -2201,8 +2189,7 @@ static int sitd_submit (struct ehci_hcd *ehci, struct urb *urb,
2201 2189
2202 /* schedule ... need to lock */ 2190 /* schedule ... need to lock */
2203 spin_lock_irqsave (&ehci->lock, flags); 2191 spin_lock_irqsave (&ehci->lock, flags);
2204 if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, 2192 if (unlikely(!HCD_HW_ACCESSIBLE(ehci_to_hcd(ehci)))) {
2205 &ehci_to_hcd(ehci)->flags))) {
2206 status = -ESHUTDOWN; 2193 status = -ESHUTDOWN;
2207 goto done_not_linked; 2194 goto done_not_linked;
2208 } 2195 }
@@ -2263,7 +2250,7 @@ scan_periodic (struct ehci_hcd *ehci)
2263 now_uframe = ehci->next_uframe; 2250 now_uframe = ehci->next_uframe;
2264 if (HC_IS_RUNNING(ehci_to_hcd(ehci)->state)) { 2251 if (HC_IS_RUNNING(ehci_to_hcd(ehci)->state)) {
2265 clock = ehci_readl(ehci, &ehci->regs->frame_index); 2252 clock = ehci_readl(ehci, &ehci->regs->frame_index);
2266 clock_frame = (clock >> 3) % ehci->periodic_size; 2253 clock_frame = (clock >> 3) & (ehci->periodic_size - 1);
2267 } else { 2254 } else {
2268 clock = now_uframe + mod - 1; 2255 clock = now_uframe + mod - 1;
2269 clock_frame = -1; 2256 clock_frame = -1;
@@ -2272,7 +2259,7 @@ scan_periodic (struct ehci_hcd *ehci)
2272 free_cached_lists(ehci); 2259 free_cached_lists(ehci);
2273 ehci->clock_frame = clock_frame; 2260 ehci->clock_frame = clock_frame;
2274 } 2261 }
2275 clock %= mod; 2262 clock &= mod - 1;
2276 clock_frame = clock >> 3; 2263 clock_frame = clock >> 3;
2277 2264
2278 for (;;) { 2265 for (;;) {
@@ -2361,7 +2348,7 @@ restart:
2361 * frame is current. 2348 * frame is current.
2362 */ 2349 */
2363 if (((frame == clock_frame) || 2350 if (((frame == clock_frame) ||
2364 (((frame + 1) % ehci->periodic_size) 2351 (((frame + 1) & (ehci->periodic_size - 1))
2365 == clock_frame)) 2352 == clock_frame))
2366 && live 2353 && live
2367 && (q.sitd->hw_results & 2354 && (q.sitd->hw_results &
@@ -2428,7 +2415,8 @@ restart:
2428 || ehci->periodic_sched == 0) 2415 || ehci->periodic_sched == 0)
2429 break; 2416 break;
2430 ehci->next_uframe = now_uframe; 2417 ehci->next_uframe = now_uframe;
2431 now = ehci_readl(ehci, &ehci->regs->frame_index) % mod; 2418 now = ehci_readl(ehci, &ehci->regs->frame_index) &
2419 (mod - 1);
2432 if (now_uframe == now) 2420 if (now_uframe == now)
2433 break; 2421 break;
2434 2422
@@ -2441,7 +2429,7 @@ restart:
2441 } 2429 }
2442 } else { 2430 } else {
2443 now_uframe++; 2431 now_uframe++;
2444 now_uframe %= mod; 2432 now_uframe &= mod - 1;
2445 } 2433 }
2446 } 2434 }
2447} 2435}
diff --git a/drivers/usb/host/ehci-xilinx-of.c b/drivers/usb/host/ehci-xilinx-of.c
index 4899f451add9..6c8076ad821d 100644
--- a/drivers/usb/host/ehci-xilinx-of.c
+++ b/drivers/usb/host/ehci-xilinx-of.c
@@ -140,7 +140,7 @@ static const struct hc_driver ehci_xilinx_of_hc_driver = {
140 140
141/** 141/**
142 * ehci_hcd_xilinx_of_probe - Probe method for the USB host controller 142 * ehci_hcd_xilinx_of_probe - Probe method for the USB host controller
143 * @op: pointer to the of_device to which the host controller bound 143 * @op: pointer to the platform_device bound to the host controller
144 * @match: pointer to of_device_id structure, not used 144 * @match: pointer to of_device_id structure, not used
145 * 145 *
146 * This function requests resources and sets up appropriate properties for the 146 * This function requests resources and sets up appropriate properties for the
@@ -149,7 +149,7 @@ static const struct hc_driver ehci_xilinx_of_hc_driver = {
149 * entry, and sets an appropriate value for hcd->has_tt. 149 * entry, and sets an appropriate value for hcd->has_tt.
150 */ 150 */
151static int __devinit 151static int __devinit
152ehci_hcd_xilinx_of_probe(struct of_device *op, const struct of_device_id *match) 152ehci_hcd_xilinx_of_probe(struct platform_device *op, const struct of_device_id *match)
153{ 153{
154 struct device_node *dn = op->dev.of_node; 154 struct device_node *dn = op->dev.of_node;
155 struct usb_hcd *hcd; 155 struct usb_hcd *hcd;
@@ -242,12 +242,12 @@ err_rmr:
242 242
243/** 243/**
244 * ehci_hcd_xilinx_of_remove - shutdown hcd and release resources 244 * ehci_hcd_xilinx_of_remove - shutdown hcd and release resources
245 * @op: pointer to of_device structure that is to be removed 245 * @op: pointer to platform_device structure that is to be removed
246 * 246 *
247 * Remove the hcd structure, and release resources that has been requested 247 * Remove the hcd structure, and release resources that has been requested
248 * during probe. 248 * during probe.
249 */ 249 */
250static int ehci_hcd_xilinx_of_remove(struct of_device *op) 250static int ehci_hcd_xilinx_of_remove(struct platform_device *op)
251{ 251{
252 struct usb_hcd *hcd = dev_get_drvdata(&op->dev); 252 struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
253 dev_set_drvdata(&op->dev, NULL); 253 dev_set_drvdata(&op->dev, NULL);
@@ -266,11 +266,11 @@ static int ehci_hcd_xilinx_of_remove(struct of_device *op)
266 266
267/** 267/**
268 * ehci_hcd_xilinx_of_shutdown - shutdown the hcd 268 * ehci_hcd_xilinx_of_shutdown - shutdown the hcd
269 * @op: pointer to of_device structure that is to be removed 269 * @op: pointer to platform_device structure that is to be removed
270 * 270 *
271 * Properly shutdown the hcd, call driver's shutdown routine. 271 * Properly shutdown the hcd, call driver's shutdown routine.
272 */ 272 */
273static int ehci_hcd_xilinx_of_shutdown(struct of_device *op) 273static int ehci_hcd_xilinx_of_shutdown(struct platform_device *op)
274{ 274{
275 struct usb_hcd *hcd = dev_get_drvdata(&op->dev); 275 struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
276 276
diff --git a/drivers/usb/host/ehci.h b/drivers/usb/host/ehci.h
index 650a687f2854..bde823f704e9 100644
--- a/drivers/usb/host/ehci.h
+++ b/drivers/usb/host/ehci.h
@@ -130,6 +130,7 @@ struct ehci_hcd { /* one per controller */
130 unsigned has_amcc_usb23:1; 130 unsigned has_amcc_usb23:1;
131 unsigned need_io_watchdog:1; 131 unsigned need_io_watchdog:1;
132 unsigned broken_periodic:1; 132 unsigned broken_periodic:1;
133 unsigned fs_i_thresh:1; /* Intel iso scheduling */
133 134
134 /* required for usb32 quirk */ 135 /* required for usb32 quirk */
135 #define OHCI_CTRL_HCFS (3 << 6) 136 #define OHCI_CTRL_HCFS (3 << 6)
@@ -140,7 +141,8 @@ struct ehci_hcd { /* one per controller */
140 #define OHCI_HCCTRL_LEN 0x4 141 #define OHCI_HCCTRL_LEN 0x4
141 __hc32 *ohci_hcctrl_reg; 142 __hc32 *ohci_hcctrl_reg;
142 unsigned has_hostpc:1; 143 unsigned has_hostpc:1;
143 144 unsigned has_lpm:1; /* support link power management */
145 unsigned has_ppcd:1; /* support per-port change bits */
144 u8 sbrn; /* packed release number */ 146 u8 sbrn; /* packed release number */
145 147
146 /* irq statistics */ 148 /* irq statistics */
@@ -154,9 +156,6 @@ struct ehci_hcd { /* one per controller */
154 /* debug files */ 156 /* debug files */
155#ifdef DEBUG 157#ifdef DEBUG
156 struct dentry *debug_dir; 158 struct dentry *debug_dir;
157 struct dentry *debug_async;
158 struct dentry *debug_periodic;
159 struct dentry *debug_registers;
160#endif 159#endif
161}; 160};
162 161
@@ -401,15 +400,12 @@ struct ehci_iso_stream {
401 u32 refcount; 400 u32 refcount;
402 u8 bEndpointAddress; 401 u8 bEndpointAddress;
403 u8 highspeed; 402 u8 highspeed;
404 u16 depth; /* depth in uframes */
405 struct list_head td_list; /* queued itds/sitds */ 403 struct list_head td_list; /* queued itds/sitds */
406 struct list_head free_list; /* list of unused itds/sitds */ 404 struct list_head free_list; /* list of unused itds/sitds */
407 struct usb_device *udev; 405 struct usb_device *udev;
408 struct usb_host_endpoint *ep; 406 struct usb_host_endpoint *ep;
409 407
410 /* output of (re)scheduling */ 408 /* output of (re)scheduling */
411 unsigned long start; /* jiffies */
412 unsigned long rescheduled;
413 int next_uframe; 409 int next_uframe;
414 __hc32 splits; 410 __hc32 splits;
415 411
@@ -538,11 +534,11 @@ struct ehci_fstn {
538 534
539/* Prepare the PORTSC wakeup flags during controller suspend/resume */ 535/* Prepare the PORTSC wakeup flags during controller suspend/resume */
540 536
541#define ehci_prepare_ports_for_controller_suspend(ehci) \ 537#define ehci_prepare_ports_for_controller_suspend(ehci, do_wakeup) \
542 ehci_adjust_port_wakeup_flags(ehci, true); 538 ehci_adjust_port_wakeup_flags(ehci, true, do_wakeup);
543 539
544#define ehci_prepare_ports_for_controller_resume(ehci) \ 540#define ehci_prepare_ports_for_controller_resume(ehci) \
545 ehci_adjust_port_wakeup_flags(ehci, false); 541 ehci_adjust_port_wakeup_flags(ehci, false, false);
546 542
547/*-------------------------------------------------------------------------*/ 543/*-------------------------------------------------------------------------*/
548 544
diff --git a/drivers/usb/host/fhci-hcd.c b/drivers/usb/host/fhci-hcd.c
index c7c8392a88b9..20092a27a1e8 100644
--- a/drivers/usb/host/fhci-hcd.c
+++ b/drivers/usb/host/fhci-hcd.c
@@ -561,7 +561,7 @@ static const struct hc_driver fhci_driver = {
561 .hub_control = fhci_hub_control, 561 .hub_control = fhci_hub_control,
562}; 562};
563 563
564static int __devinit of_fhci_probe(struct of_device *ofdev, 564static int __devinit of_fhci_probe(struct platform_device *ofdev,
565 const struct of_device_id *ofid) 565 const struct of_device_id *ofid)
566{ 566{
567 struct device *dev = &ofdev->dev; 567 struct device *dev = &ofdev->dev;
@@ -801,7 +801,7 @@ static int __devexit fhci_remove(struct device *dev)
801 return 0; 801 return 0;
802} 802}
803 803
804static int __devexit of_fhci_remove(struct of_device *ofdev) 804static int __devexit of_fhci_remove(struct platform_device *ofdev)
805{ 805{
806 return fhci_remove(&ofdev->dev); 806 return fhci_remove(&ofdev->dev);
807} 807}
diff --git a/drivers/usb/host/hwa-hc.c b/drivers/usb/host/hwa-hc.c
index 35742f8c7cda..9bfac657572e 100644
--- a/drivers/usb/host/hwa-hc.c
+++ b/drivers/usb/host/hwa-hc.c
@@ -159,7 +159,7 @@ static int hwahc_op_start(struct usb_hcd *usb_hcd)
159 goto error_set_cluster_id; 159 goto error_set_cluster_id;
160 160
161 usb_hcd->uses_new_polling = 1; 161 usb_hcd->uses_new_polling = 1;
162 usb_hcd->poll_rh = 1; 162 set_bit(HCD_FLAG_POLL_RH, &usb_hcd->flags);
163 usb_hcd->state = HC_STATE_RUNNING; 163 usb_hcd->state = HC_STATE_RUNNING;
164 result = 0; 164 result = 0;
165out: 165out:
@@ -776,7 +776,7 @@ static int hwahc_probe(struct usb_interface *usb_iface,
776 goto error_alloc; 776 goto error_alloc;
777 } 777 }
778 usb_hcd->wireless = 1; 778 usb_hcd->wireless = 1;
779 usb_hcd->flags |= HCD_FLAG_SAW_IRQ; 779 set_bit(HCD_FLAG_SAW_IRQ, &usb_hcd->flags);
780 wusbhc = usb_hcd_to_wusbhc(usb_hcd); 780 wusbhc = usb_hcd_to_wusbhc(usb_hcd);
781 hwahc = container_of(wusbhc, struct hwahc, wusbhc); 781 hwahc = container_of(wusbhc, struct hwahc, wusbhc);
782 hwahc_init(hwahc); 782 hwahc_init(hwahc);
diff --git a/drivers/usb/host/imx21-hcd.c b/drivers/usb/host/imx21-hcd.c
index ca0e98d8e1f4..3e5630369c31 100644
--- a/drivers/usb/host/imx21-hcd.c
+++ b/drivers/usb/host/imx21-hcd.c
@@ -1521,7 +1521,7 @@ static int imx21_hc_reset(struct usb_hcd *hcd)
1521 return -ETIMEDOUT; 1521 return -ETIMEDOUT;
1522 } 1522 }
1523 spin_unlock_irq(&imx21->lock); 1523 spin_unlock_irq(&imx21->lock);
1524 schedule_timeout(1); 1524 schedule_timeout_uninterruptible(1);
1525 spin_lock_irq(&imx21->lock); 1525 spin_lock_irq(&imx21->lock);
1526 } 1526 }
1527 spin_unlock_irqrestore(&imx21->lock, flags); 1527 spin_unlock_irqrestore(&imx21->lock, flags);
diff --git a/drivers/usb/host/isp1362.h b/drivers/usb/host/isp1362.h
index d995351f9bed..0f97820e65be 100644
--- a/drivers/usb/host/isp1362.h
+++ b/drivers/usb/host/isp1362.h
@@ -8,29 +8,7 @@
8/* 8/*
9 * Platform specific compile time options 9 * Platform specific compile time options
10 */ 10 */
11#if defined(CONFIG_ARCH_KARO) 11#if defined(CONFIG_BLACKFIN)
12#include <asm/arch/hardware.h>
13#include <asm/arch/pxa-regs.h>
14#include <asm/arch/karo.h>
15
16#define USE_32BIT 1
17
18
19/* These options are mutually eclusive */
20#define USE_PLATFORM_DELAY 1
21#define USE_NDELAY 0
22/*
23 * MAX_ROOT_PORTS: Number of downstream ports
24 *
25 * The chip has two USB ports, one of which can be configured as
26 * an USB device port, so the value of this constant is implementation
27 * specific.
28 */
29#define MAX_ROOT_PORTS 2
30#define DUMMY_DELAY_ACCESS do {} while (0)
31
32/* insert platform specific definitions for other machines here */
33#elif defined(CONFIG_BLACKFIN)
34 12
35#include <linux/io.h> 13#include <linux/io.h>
36#define USE_32BIT 0 14#define USE_32BIT 0
diff --git a/drivers/usb/host/isp1760-hcd.c b/drivers/usb/host/isp1760-hcd.c
index dbcafa29c775..d1a3dfc9a408 100644
--- a/drivers/usb/host/isp1760-hcd.c
+++ b/drivers/usb/host/isp1760-hcd.c
@@ -482,7 +482,6 @@ static int isp1760_run(struct usb_hcd *hcd)
482 u32 chipid; 482 u32 chipid;
483 483
484 hcd->uses_new_polling = 1; 484 hcd->uses_new_polling = 1;
485 hcd->poll_rh = 0;
486 485
487 hcd->state = HC_STATE_RUNNING; 486 hcd->state = HC_STATE_RUNNING;
488 isp1760_enable_interrupts(hcd); 487 isp1760_enable_interrupts(hcd);
@@ -1450,7 +1449,7 @@ static int isp1760_prepare_enqueue(struct isp1760_hcd *priv, struct urb *urb,
1450 epnum = urb->ep->desc.bEndpointAddress; 1449 epnum = urb->ep->desc.bEndpointAddress;
1451 1450
1452 spin_lock_irqsave(&priv->lock, flags); 1451 spin_lock_irqsave(&priv->lock, flags);
1453 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &priv_to_hcd(priv)->flags)) { 1452 if (!HCD_HW_ACCESSIBLE(priv_to_hcd(priv))) {
1454 rc = -ESHUTDOWN; 1453 rc = -ESHUTDOWN;
1455 goto done; 1454 goto done;
1456 } 1455 }
diff --git a/drivers/usb/host/isp1760-if.c b/drivers/usb/host/isp1760-if.c
index ec85d0c3cc3e..3b28dbfca058 100644
--- a/drivers/usb/host/isp1760-if.c
+++ b/drivers/usb/host/isp1760-if.c
@@ -27,7 +27,7 @@
27#endif 27#endif
28 28
29#ifdef CONFIG_PPC_OF 29#ifdef CONFIG_PPC_OF
30static int of_isp1760_probe(struct of_device *dev, 30static int of_isp1760_probe(struct platform_device *dev,
31 const struct of_device_id *match) 31 const struct of_device_id *match)
32{ 32{
33 struct usb_hcd *hcd; 33 struct usb_hcd *hcd;
@@ -95,7 +95,7 @@ release_reg:
95 return ret; 95 return ret;
96} 96}
97 97
98static int of_isp1760_remove(struct of_device *dev) 98static int of_isp1760_remove(struct platform_device *dev)
99{ 99{
100 struct usb_hcd *hcd = dev_get_drvdata(&dev->dev); 100 struct usb_hcd *hcd = dev_get_drvdata(&dev->dev);
101 101
diff --git a/drivers/usb/host/ohci-dbg.c b/drivers/usb/host/ohci-dbg.c
index 8ad2441b0284..36abd2baa3ea 100644
--- a/drivers/usb/host/ohci-dbg.c
+++ b/drivers/usb/host/ohci-dbg.c
@@ -645,7 +645,7 @@ static ssize_t fill_registers_buffer(struct debug_buffer *buf)
645 hcd->product_desc, 645 hcd->product_desc,
646 hcd_name); 646 hcd_name);
647 647
648 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) { 648 if (!HCD_HW_ACCESSIBLE(hcd)) {
649 size -= scnprintf (next, size, 649 size -= scnprintf (next, size,
650 "SUSPENDED (no register access)\n"); 650 "SUSPENDED (no register access)\n");
651 goto done; 651 goto done;
@@ -687,7 +687,7 @@ static ssize_t fill_registers_buffer(struct debug_buffer *buf)
687 next += temp; 687 next += temp;
688 688
689 temp = scnprintf (next, size, "hub poll timer %s\n", 689 temp = scnprintf (next, size, "hub poll timer %s\n",
690 ohci_to_hcd(ohci)->poll_rh ? "ON" : "off"); 690 HCD_POLL_RH(ohci_to_hcd(ohci)) ? "ON" : "off");
691 size -= temp; 691 size -= temp;
692 next += temp; 692 next += temp;
693 693
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index 02864a237a2c..c3b4ccc7337b 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -212,7 +212,7 @@ static int ohci_urb_enqueue (
212 spin_lock_irqsave (&ohci->lock, flags); 212 spin_lock_irqsave (&ohci->lock, flags);
213 213
214 /* don't submit to a dead HC */ 214 /* don't submit to a dead HC */
215 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) { 215 if (!HCD_HW_ACCESSIBLE(hcd)) {
216 retval = -ENODEV; 216 retval = -ENODEV;
217 goto fail; 217 goto fail;
218 } 218 }
@@ -685,7 +685,7 @@ retry:
685 } 685 }
686 686
687 /* use rhsc irqs after khubd is fully initialized */ 687 /* use rhsc irqs after khubd is fully initialized */
688 hcd->poll_rh = 1; 688 set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
689 hcd->uses_new_polling = 1; 689 hcd->uses_new_polling = 1;
690 690
691 /* start controller operations */ 691 /* start controller operations */
@@ -822,7 +822,7 @@ static irqreturn_t ohci_irq (struct usb_hcd *hcd)
822 else if (ints & OHCI_INTR_RD) { 822 else if (ints & OHCI_INTR_RD) {
823 ohci_vdbg(ohci, "resume detect\n"); 823 ohci_vdbg(ohci, "resume detect\n");
824 ohci_writel(ohci, OHCI_INTR_RD, &regs->intrstatus); 824 ohci_writel(ohci, OHCI_INTR_RD, &regs->intrstatus);
825 hcd->poll_rh = 1; 825 set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
826 if (ohci->autostop) { 826 if (ohci->autostop) {
827 spin_lock (&ohci->lock); 827 spin_lock (&ohci->lock);
828 ohci_rh_resume (ohci); 828 ohci_rh_resume (ohci);
diff --git a/drivers/usb/host/ohci-hub.c b/drivers/usb/host/ohci-hub.c
index 65cac8cc8921..cddcda95b579 100644
--- a/drivers/usb/host/ohci-hub.c
+++ b/drivers/usb/host/ohci-hub.c
@@ -284,7 +284,7 @@ static int ohci_bus_suspend (struct usb_hcd *hcd)
284 284
285 spin_lock_irq (&ohci->lock); 285 spin_lock_irq (&ohci->lock);
286 286
287 if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags))) 287 if (unlikely(!HCD_HW_ACCESSIBLE(hcd)))
288 rc = -ESHUTDOWN; 288 rc = -ESHUTDOWN;
289 else 289 else
290 rc = ohci_rh_suspend (ohci, 0); 290 rc = ohci_rh_suspend (ohci, 0);
@@ -302,7 +302,7 @@ static int ohci_bus_resume (struct usb_hcd *hcd)
302 302
303 spin_lock_irq (&ohci->lock); 303 spin_lock_irq (&ohci->lock);
304 304
305 if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags))) 305 if (unlikely(!HCD_HW_ACCESSIBLE(hcd)))
306 rc = -ESHUTDOWN; 306 rc = -ESHUTDOWN;
307 else 307 else
308 rc = ohci_rh_resume (ohci); 308 rc = ohci_rh_resume (ohci);
@@ -355,6 +355,11 @@ static void ohci_finish_controller_resume(struct usb_hcd *hcd)
355 ohci_readl(ohci, &ohci->regs->intrenable); 355 ohci_readl(ohci, &ohci->regs->intrenable);
356 msleep(20); 356 msleep(20);
357 } 357 }
358
359 /* Does the root hub have a port wakeup pending? */
360 if (ohci_readl(ohci, &ohci->regs->intrstatus) &
361 (OHCI_INTR_RD | OHCI_INTR_RHSC))
362 usb_hcd_resume_root_hub(hcd);
358} 363}
359 364
360/* Carry out polling-, autostop-, and autoresume-related state changes */ 365/* Carry out polling-, autostop-, and autoresume-related state changes */
@@ -364,7 +369,7 @@ static int ohci_root_hub_state_changes(struct ohci_hcd *ohci, int changed,
364 int poll_rh = 1; 369 int poll_rh = 1;
365 int rhsc_enable; 370 int rhsc_enable;
366 371
367 /* Some broken controllers never turn off RHCS in the interrupt 372 /* Some broken controllers never turn off RHSC in the interrupt
368 * status register. For their sake we won't re-enable RHSC 373 * status register. For their sake we won't re-enable RHSC
369 * interrupts if the interrupt bit is already active. 374 * interrupts if the interrupt bit is already active.
370 */ 375 */
@@ -489,7 +494,7 @@ ohci_hub_status_data (struct usb_hcd *hcd, char *buf)
489 unsigned long flags; 494 unsigned long flags;
490 495
491 spin_lock_irqsave (&ohci->lock, flags); 496 spin_lock_irqsave (&ohci->lock, flags);
492 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) 497 if (!HCD_HW_ACCESSIBLE(hcd))
493 goto done; 498 goto done;
494 499
495 /* undocumented erratum seen on at least rev D */ 500 /* undocumented erratum seen on at least rev D */
@@ -533,8 +538,12 @@ ohci_hub_status_data (struct usb_hcd *hcd, char *buf)
533 } 538 }
534 } 539 }
535 540
536 hcd->poll_rh = ohci_root_hub_state_changes(ohci, changed, 541 if (ohci_root_hub_state_changes(ohci, changed,
537 any_connected, rhsc_status); 542 any_connected, rhsc_status))
543 set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
544 else
545 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
546
538 547
539done: 548done:
540 spin_unlock_irqrestore (&ohci->lock, flags); 549 spin_unlock_irqrestore (&ohci->lock, flags);
@@ -701,7 +710,7 @@ static int ohci_hub_control (
701 u32 temp; 710 u32 temp;
702 int retval = 0; 711 int retval = 0;
703 712
704 if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags))) 713 if (unlikely(!HCD_HW_ACCESSIBLE(hcd)))
705 return -ESHUTDOWN; 714 return -ESHUTDOWN;
706 715
707 switch (typeReq) { 716 switch (typeReq) {
diff --git a/drivers/usb/host/ohci-pci.c b/drivers/usb/host/ohci-pci.c
index b8a1148f248e..6bdc8b25a6a1 100644
--- a/drivers/usb/host/ohci-pci.c
+++ b/drivers/usb/host/ohci-pci.c
@@ -392,7 +392,7 @@ static int __devinit ohci_pci_start (struct usb_hcd *hcd)
392 392
393#ifdef CONFIG_PM 393#ifdef CONFIG_PM
394 394
395static int ohci_pci_suspend(struct usb_hcd *hcd) 395static int ohci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup)
396{ 396{
397 struct ohci_hcd *ohci = hcd_to_ohci (hcd); 397 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
398 unsigned long flags; 398 unsigned long flags;
diff --git a/drivers/usb/host/ohci-pnx4008.c b/drivers/usb/host/ohci-pnx4008.c
index cd74bbdd007c..653d6a60edb5 100644
--- a/drivers/usb/host/ohci-pnx4008.c
+++ b/drivers/usb/host/ohci-pnx4008.c
@@ -329,7 +329,7 @@ static int __devinit usb_hcd_pnx4008_probe(struct platform_device *pdev)
329 memset(&i2c_info, 0, sizeof(struct i2c_board_info)); 329 memset(&i2c_info, 0, sizeof(struct i2c_board_info));
330 strlcpy(i2c_info.type, "isp1301_pnx", I2C_NAME_SIZE); 330 strlcpy(i2c_info.type, "isp1301_pnx", I2C_NAME_SIZE);
331 isp1301_i2c_client = i2c_new_probed_device(i2c_adap, &i2c_info, 331 isp1301_i2c_client = i2c_new_probed_device(i2c_adap, &i2c_info,
332 normal_i2c); 332 normal_i2c, NULL);
333 i2c_put_adapter(i2c_adap); 333 i2c_put_adapter(i2c_adap);
334 if (!isp1301_i2c_client) { 334 if (!isp1301_i2c_client) {
335 err("failed to connect I2C to ISP1301 USB Transceiver"); 335 err("failed to connect I2C to ISP1301 USB Transceiver");
diff --git a/drivers/usb/host/ohci-ppc-of.c b/drivers/usb/host/ohci-ppc-of.c
index df165917412a..b2c2dbf08766 100644
--- a/drivers/usb/host/ohci-ppc-of.c
+++ b/drivers/usb/host/ohci-ppc-of.c
@@ -81,7 +81,7 @@ static const struct hc_driver ohci_ppc_of_hc_driver = {
81 81
82 82
83static int __devinit 83static int __devinit
84ohci_hcd_ppc_of_probe(struct of_device *op, const struct of_device_id *match) 84ohci_hcd_ppc_of_probe(struct platform_device *op, const struct of_device_id *match)
85{ 85{
86 struct device_node *dn = op->dev.of_node; 86 struct device_node *dn = op->dev.of_node;
87 struct usb_hcd *hcd; 87 struct usb_hcd *hcd;
@@ -183,7 +183,7 @@ err_rmr:
183 return rv; 183 return rv;
184} 184}
185 185
186static int ohci_hcd_ppc_of_remove(struct of_device *op) 186static int ohci_hcd_ppc_of_remove(struct platform_device *op)
187{ 187{
188 struct usb_hcd *hcd = dev_get_drvdata(&op->dev); 188 struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
189 dev_set_drvdata(&op->dev, NULL); 189 dev_set_drvdata(&op->dev, NULL);
@@ -201,7 +201,7 @@ static int ohci_hcd_ppc_of_remove(struct of_device *op)
201 return 0; 201 return 0;
202} 202}
203 203
204static int ohci_hcd_ppc_of_shutdown(struct of_device *op) 204static int ohci_hcd_ppc_of_shutdown(struct platform_device *op)
205{ 205{
206 struct usb_hcd *hcd = dev_get_drvdata(&op->dev); 206 struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
207 207
diff --git a/drivers/usb/host/ohci-ssb.c b/drivers/usb/host/ohci-ssb.c
index 23fd6a886bdd..48ee6943bf35 100644
--- a/drivers/usb/host/ohci-ssb.c
+++ b/drivers/usb/host/ohci-ssb.c
@@ -93,8 +93,11 @@ static void ssb_ohci_detach(struct ssb_device *dev)
93{ 93{
94 struct usb_hcd *hcd = ssb_get_drvdata(dev); 94 struct usb_hcd *hcd = ssb_get_drvdata(dev);
95 95
96 if (hcd->driver->shutdown)
97 hcd->driver->shutdown(hcd);
96 usb_remove_hcd(hcd); 98 usb_remove_hcd(hcd);
97 iounmap(hcd->regs); 99 iounmap(hcd->regs);
100 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
98 usb_put_hcd(hcd); 101 usb_put_hcd(hcd);
99 ssb_device_disable(dev, 0); 102 ssb_device_disable(dev, 0);
100} 103}
@@ -106,10 +109,52 @@ static int ssb_ohci_attach(struct ssb_device *dev)
106 int err = -ENOMEM; 109 int err = -ENOMEM;
107 u32 tmp, flags = 0; 110 u32 tmp, flags = 0;
108 111
109 if (dev->id.coreid == SSB_DEV_USB11_HOSTDEV) 112 if (dma_set_mask(dev->dma_dev, DMA_BIT_MASK(32)) ||
110 flags |= SSB_OHCI_TMSLOW_HOSTMODE; 113 dma_set_coherent_mask(dev->dma_dev, DMA_BIT_MASK(32)))
114 return -EOPNOTSUPP;
111 115
112 ssb_device_enable(dev, flags); 116 if (dev->id.coreid == SSB_DEV_USB11_HOSTDEV) {
117 /* Put the device into host-mode. */
118 flags |= SSB_OHCI_TMSLOW_HOSTMODE;
119 ssb_device_enable(dev, flags);
120 } else if (dev->id.coreid == SSB_DEV_USB20_HOST) {
121 /*
122 * USB 2.0 special considerations:
123 *
124 * In addition to the standard SSB reset sequence, the Host
125 * Control Register must be programmed to bring the USB core
126 * and various phy components out of reset.
127 */
128 ssb_device_enable(dev, 0);
129 ssb_write32(dev, 0x200, 0x7ff);
130
131 /* Change Flush control reg */
132 tmp = ssb_read32(dev, 0x400);
133 tmp &= ~8;
134 ssb_write32(dev, 0x400, tmp);
135 tmp = ssb_read32(dev, 0x400);
136
137 /* Change Shim control reg */
138 tmp = ssb_read32(dev, 0x304);
139 tmp &= ~0x100;
140 ssb_write32(dev, 0x304, tmp);
141 tmp = ssb_read32(dev, 0x304);
142
143 udelay(1);
144
145 /* Work around for 5354 failures */
146 if (dev->id.revision == 2 && dev->bus->chip_id == 0x5354) {
147 /* Change syn01 reg */
148 tmp = 0x00fe00fe;
149 ssb_write32(dev, 0x894, tmp);
150
151 /* Change syn03 reg */
152 tmp = ssb_read32(dev, 0x89c);
153 tmp |= 0x1;
154 ssb_write32(dev, 0x89c, tmp);
155 }
156 } else
157 ssb_device_enable(dev, 0);
113 158
114 hcd = usb_create_hcd(&ssb_ohci_hc_driver, dev->dev, 159 hcd = usb_create_hcd(&ssb_ohci_hc_driver, dev->dev,
115 dev_name(dev->dev)); 160 dev_name(dev->dev));
@@ -200,6 +245,7 @@ static int ssb_ohci_resume(struct ssb_device *dev)
200static const struct ssb_device_id ssb_ohci_table[] = { 245static const struct ssb_device_id ssb_ohci_table[] = {
201 SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_USB11_HOSTDEV, SSB_ANY_REV), 246 SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_USB11_HOSTDEV, SSB_ANY_REV),
202 SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_USB11_HOST, SSB_ANY_REV), 247 SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_USB11_HOST, SSB_ANY_REV),
248 SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_USB20_HOST, SSB_ANY_REV),
203 SSB_DEVTABLE_END 249 SSB_DEVTABLE_END
204}; 250};
205MODULE_DEVICE_TABLE(ssb, ssb_ohci_table); 251MODULE_DEVICE_TABLE(ssb, ssb_ohci_table);
diff --git a/drivers/usb/host/oxu210hp-hcd.c b/drivers/usb/host/oxu210hp-hcd.c
index f608dfd09a8a..d9c85a292737 100644
--- a/drivers/usb/host/oxu210hp-hcd.c
+++ b/drivers/usb/host/oxu210hp-hcd.c
@@ -1641,8 +1641,7 @@ static int submit_async(struct oxu_hcd *oxu, struct urb *urb,
1641#endif 1641#endif
1642 1642
1643 spin_lock_irqsave(&oxu->lock, flags); 1643 spin_lock_irqsave(&oxu->lock, flags);
1644 if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, 1644 if (unlikely(!HCD_HW_ACCESSIBLE(oxu_to_hcd(oxu)))) {
1645 &oxu_to_hcd(oxu)->flags))) {
1646 rc = -ESHUTDOWN; 1645 rc = -ESHUTDOWN;
1647 goto done; 1646 goto done;
1648 } 1647 }
@@ -2209,8 +2208,7 @@ static int intr_submit(struct oxu_hcd *oxu, struct urb *urb,
2209 2208
2210 spin_lock_irqsave(&oxu->lock, flags); 2209 spin_lock_irqsave(&oxu->lock, flags);
2211 2210
2212 if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, 2211 if (unlikely(!HCD_HW_ACCESSIBLE(oxu_to_hcd(oxu)))) {
2213 &oxu_to_hcd(oxu)->flags))) {
2214 status = -ESHUTDOWN; 2212 status = -ESHUTDOWN;
2215 goto done; 2213 goto done;
2216 } 2214 }
@@ -2715,7 +2713,6 @@ static int oxu_run(struct usb_hcd *hcd)
2715 u32 temp, hcc_params; 2713 u32 temp, hcc_params;
2716 2714
2717 hcd->uses_new_polling = 1; 2715 hcd->uses_new_polling = 1;
2718 hcd->poll_rh = 0;
2719 2716
2720 /* EHCI spec section 4.1 */ 2717 /* EHCI spec section 4.1 */
2721 retval = ehci_reset(oxu); 2718 retval = ehci_reset(oxu);
diff --git a/drivers/usb/host/sl811-hcd.c b/drivers/usb/host/sl811-hcd.c
index bcf9f0e809de..990f06b89eaa 100644
--- a/drivers/usb/host/sl811-hcd.c
+++ b/drivers/usb/host/sl811-hcd.c
@@ -813,8 +813,11 @@ static int sl811h_urb_enqueue(
813#endif 813#endif
814 814
815 /* avoid all allocations within spinlocks */ 815 /* avoid all allocations within spinlocks */
816 if (!hep->hcpriv) 816 if (!hep->hcpriv) {
817 ep = kzalloc(sizeof *ep, mem_flags); 817 ep = kzalloc(sizeof *ep, mem_flags);
818 if (ep == NULL)
819 return -ENOMEM;
820 }
818 821
819 spin_lock_irqsave(&sl811->lock, flags); 822 spin_lock_irqsave(&sl811->lock, flags);
820 823
diff --git a/drivers/usb/host/uhci-debug.c b/drivers/usb/host/uhci-debug.c
index 98cf0b26b968..6e7fb5f38db6 100644
--- a/drivers/usb/host/uhci-debug.c
+++ b/drivers/usb/host/uhci-debug.c
@@ -17,7 +17,6 @@
17 17
18#include "uhci-hcd.h" 18#include "uhci-hcd.h"
19 19
20#define uhci_debug_operations (* (const struct file_operations *) NULL)
21static struct dentry *uhci_debugfs_root; 20static struct dentry *uhci_debugfs_root;
22 21
23#ifdef DEBUG 22#ifdef DEBUG
@@ -495,18 +494,16 @@ static int uhci_debug_open(struct inode *inode, struct file *file)
495{ 494{
496 struct uhci_hcd *uhci = inode->i_private; 495 struct uhci_hcd *uhci = inode->i_private;
497 struct uhci_debug *up; 496 struct uhci_debug *up;
498 int ret = -ENOMEM;
499 unsigned long flags; 497 unsigned long flags;
500 498
501 lock_kernel();
502 up = kmalloc(sizeof(*up), GFP_KERNEL); 499 up = kmalloc(sizeof(*up), GFP_KERNEL);
503 if (!up) 500 if (!up)
504 goto out; 501 return -ENOMEM;
505 502
506 up->data = kmalloc(MAX_OUTPUT, GFP_KERNEL); 503 up->data = kmalloc(MAX_OUTPUT, GFP_KERNEL);
507 if (!up->data) { 504 if (!up->data) {
508 kfree(up); 505 kfree(up);
509 goto out; 506 return -ENOMEM;
510 } 507 }
511 508
512 up->size = 0; 509 up->size = 0;
@@ -517,10 +514,7 @@ static int uhci_debug_open(struct inode *inode, struct file *file)
517 514
518 file->private_data = up; 515 file->private_data = up;
519 516
520 ret = 0; 517 return 0;
521out:
522 unlock_kernel();
523 return ret;
524} 518}
525 519
526static loff_t uhci_debug_lseek(struct file *file, loff_t off, int whence) 520static loff_t uhci_debug_lseek(struct file *file, loff_t off, int whence)
@@ -528,9 +522,9 @@ static loff_t uhci_debug_lseek(struct file *file, loff_t off, int whence)
528 struct uhci_debug *up; 522 struct uhci_debug *up;
529 loff_t new = -1; 523 loff_t new = -1;
530 524
531 lock_kernel();
532 up = file->private_data; 525 up = file->private_data;
533 526
527 /* XXX: atomic 64bit seek access, but that needs to be fixed in the VFS */
534 switch (whence) { 528 switch (whence) {
535 case 0: 529 case 0:
536 new = off; 530 new = off;
@@ -539,11 +533,10 @@ static loff_t uhci_debug_lseek(struct file *file, loff_t off, int whence)
539 new = file->f_pos + off; 533 new = file->f_pos + off;
540 break; 534 break;
541 } 535 }
542 if (new < 0 || new > up->size) { 536
543 unlock_kernel(); 537 if (new < 0 || new > up->size)
544 return -EINVAL; 538 return -EINVAL;
545 } 539
546 unlock_kernel();
547 return (file->f_pos = new); 540 return (file->f_pos = new);
548} 541}
549 542
@@ -564,7 +557,6 @@ static int uhci_debug_release(struct inode *inode, struct file *file)
564 return 0; 557 return 0;
565} 558}
566 559
567#undef uhci_debug_operations
568static const struct file_operations uhci_debug_operations = { 560static const struct file_operations uhci_debug_operations = {
569 .owner = THIS_MODULE, 561 .owner = THIS_MODULE,
570 .open = uhci_debug_open, 562 .open = uhci_debug_open,
@@ -572,6 +564,7 @@ static const struct file_operations uhci_debug_operations = {
572 .read = uhci_debug_read, 564 .read = uhci_debug_read,
573 .release = uhci_debug_release, 565 .release = uhci_debug_release,
574}; 566};
567#define UHCI_DEBUG_OPS
575 568
576#endif /* CONFIG_DEBUG_FS */ 569#endif /* CONFIG_DEBUG_FS */
577 570
diff --git a/drivers/usb/host/uhci-hcd.c b/drivers/usb/host/uhci-hcd.c
index 6637e52736dd..f52d04db28f4 100644
--- a/drivers/usb/host/uhci-hcd.c
+++ b/drivers/usb/host/uhci-hcd.c
@@ -140,7 +140,7 @@ static void finish_reset(struct uhci_hcd *uhci)
140 uhci->rh_state = UHCI_RH_RESET; 140 uhci->rh_state = UHCI_RH_RESET;
141 uhci->is_stopped = UHCI_IS_STOPPED; 141 uhci->is_stopped = UHCI_IS_STOPPED;
142 uhci_to_hcd(uhci)->state = HC_STATE_HALT; 142 uhci_to_hcd(uhci)->state = HC_STATE_HALT;
143 uhci_to_hcd(uhci)->poll_rh = 0; 143 clear_bit(HCD_FLAG_POLL_RH, &uhci_to_hcd(uhci)->flags);
144 144
145 uhci->dead = 0; /* Full reset resurrects the controller */ 145 uhci->dead = 0; /* Full reset resurrects the controller */
146} 146}
@@ -176,6 +176,8 @@ static void check_and_reset_hc(struct uhci_hcd *uhci)
176 */ 176 */
177static void configure_hc(struct uhci_hcd *uhci) 177static void configure_hc(struct uhci_hcd *uhci)
178{ 178{
179 struct pci_dev *pdev = to_pci_dev(uhci_dev(uhci));
180
179 /* Set the frame length to the default: 1 ms exactly */ 181 /* Set the frame length to the default: 1 ms exactly */
180 outb(USBSOF_DEFAULT, uhci->io_addr + USBSOF); 182 outb(USBSOF_DEFAULT, uhci->io_addr + USBSOF);
181 183
@@ -191,8 +193,11 @@ static void configure_hc(struct uhci_hcd *uhci)
191 mb(); 193 mb();
192 194
193 /* Enable PIRQ */ 195 /* Enable PIRQ */
194 pci_write_config_word(to_pci_dev(uhci_dev(uhci)), USBLEGSUP, 196 pci_write_config_word(pdev, USBLEGSUP, USBLEGSUP_DEFAULT);
195 USBLEGSUP_DEFAULT); 197
198 /* Disable platform-specific non-PME# wakeup */
199 if (pdev->vendor == PCI_VENDOR_ID_INTEL)
200 pci_write_config_byte(pdev, USBRES_INTEL, 0);
196} 201}
197 202
198 203
@@ -344,7 +349,10 @@ __acquires(uhci->lock)
344 /* If interrupts don't work and remote wakeup is enabled then 349 /* If interrupts don't work and remote wakeup is enabled then
345 * the suspended root hub needs to be polled. 350 * the suspended root hub needs to be polled.
346 */ 351 */
347 uhci_to_hcd(uhci)->poll_rh = (!int_enable && wakeup_enable); 352 if (!int_enable && wakeup_enable)
353 set_bit(HCD_FLAG_POLL_RH, &uhci_to_hcd(uhci)->flags);
354 else
355 clear_bit(HCD_FLAG_POLL_RH, &uhci_to_hcd(uhci)->flags);
348 356
349 uhci_scan_schedule(uhci); 357 uhci_scan_schedule(uhci);
350 uhci_fsbr_off(uhci); 358 uhci_fsbr_off(uhci);
@@ -363,7 +371,7 @@ static void start_rh(struct uhci_hcd *uhci)
363 uhci->io_addr + USBINTR); 371 uhci->io_addr + USBINTR);
364 mb(); 372 mb();
365 uhci->rh_state = UHCI_RH_RUNNING; 373 uhci->rh_state = UHCI_RH_RUNNING;
366 uhci_to_hcd(uhci)->poll_rh = 1; 374 set_bit(HCD_FLAG_POLL_RH, &uhci_to_hcd(uhci)->flags);
367} 375}
368 376
369static void wakeup_rh(struct uhci_hcd *uhci) 377static void wakeup_rh(struct uhci_hcd *uhci)
@@ -589,7 +597,7 @@ static int uhci_start(struct usb_hcd *hcd)
589 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 597 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
590 int retval = -EBUSY; 598 int retval = -EBUSY;
591 int i; 599 int i;
592 struct dentry *dentry; 600 struct dentry __maybe_unused *dentry;
593 601
594 hcd->uses_new_polling = 1; 602 hcd->uses_new_polling = 1;
595 603
@@ -599,18 +607,16 @@ static int uhci_start(struct usb_hcd *hcd)
599 INIT_LIST_HEAD(&uhci->idle_qh_list); 607 INIT_LIST_HEAD(&uhci->idle_qh_list);
600 init_waitqueue_head(&uhci->waitqh); 608 init_waitqueue_head(&uhci->waitqh);
601 609
602 if (DEBUG_CONFIGURED) { 610#ifdef UHCI_DEBUG_OPS
603 dentry = debugfs_create_file(hcd->self.bus_name, 611 dentry = debugfs_create_file(hcd->self.bus_name,
604 S_IFREG|S_IRUGO|S_IWUSR, uhci_debugfs_root, 612 S_IFREG|S_IRUGO|S_IWUSR, uhci_debugfs_root,
605 uhci, &uhci_debug_operations); 613 uhci, &uhci_debug_operations);
606 if (!dentry) { 614 if (!dentry) {
607 dev_err(uhci_dev(uhci), "couldn't create uhci " 615 dev_err(uhci_dev(uhci), "couldn't create uhci debugfs entry\n");
608 "debugfs entry\n"); 616 return -ENOMEM;
609 retval = -ENOMEM;
610 goto err_create_debug_entry;
611 }
612 uhci->dentry = dentry;
613 } 617 }
618 uhci->dentry = dentry;
619#endif
614 620
615 uhci->frame = dma_alloc_coherent(uhci_dev(uhci), 621 uhci->frame = dma_alloc_coherent(uhci_dev(uhci),
616 UHCI_NUMFRAMES * sizeof(*uhci->frame), 622 UHCI_NUMFRAMES * sizeof(*uhci->frame),
@@ -691,7 +697,9 @@ static int uhci_start(struct usb_hcd *hcd)
691 697
692 configure_hc(uhci); 698 configure_hc(uhci);
693 uhci->is_initialized = 1; 699 uhci->is_initialized = 1;
700 spin_lock_irq(&uhci->lock);
694 start_rh(uhci); 701 start_rh(uhci);
702 spin_unlock_irq(&uhci->lock);
695 return 0; 703 return 0;
696 704
697/* 705/*
@@ -722,7 +730,6 @@ err_alloc_frame_cpu:
722err_alloc_frame: 730err_alloc_frame:
723 debugfs_remove(uhci->dentry); 731 debugfs_remove(uhci->dentry);
724 732
725err_create_debug_entry:
726 return retval; 733 return retval;
727} 734}
728 735
@@ -731,7 +738,7 @@ static void uhci_stop(struct usb_hcd *hcd)
731 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 738 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
732 739
733 spin_lock_irq(&uhci->lock); 740 spin_lock_irq(&uhci->lock);
734 if (test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags) && !uhci->dead) 741 if (HCD_HW_ACCESSIBLE(hcd) && !uhci->dead)
735 uhci_hc_died(uhci); 742 uhci_hc_died(uhci);
736 uhci_scan_schedule(uhci); 743 uhci_scan_schedule(uhci);
737 spin_unlock_irq(&uhci->lock); 744 spin_unlock_irq(&uhci->lock);
@@ -748,7 +755,7 @@ static int uhci_rh_suspend(struct usb_hcd *hcd)
748 int rc = 0; 755 int rc = 0;
749 756
750 spin_lock_irq(&uhci->lock); 757 spin_lock_irq(&uhci->lock);
751 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) 758 if (!HCD_HW_ACCESSIBLE(hcd))
752 rc = -ESHUTDOWN; 759 rc = -ESHUTDOWN;
753 else if (uhci->dead) 760 else if (uhci->dead)
754 ; /* Dead controllers tell no tales */ 761 ; /* Dead controllers tell no tales */
@@ -775,7 +782,7 @@ static int uhci_rh_resume(struct usb_hcd *hcd)
775 int rc = 0; 782 int rc = 0;
776 783
777 spin_lock_irq(&uhci->lock); 784 spin_lock_irq(&uhci->lock);
778 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) 785 if (!HCD_HW_ACCESSIBLE(hcd))
779 rc = -ESHUTDOWN; 786 rc = -ESHUTDOWN;
780 else if (!uhci->dead) 787 else if (!uhci->dead)
781 wakeup_rh(uhci); 788 wakeup_rh(uhci);
@@ -783,15 +790,16 @@ static int uhci_rh_resume(struct usb_hcd *hcd)
783 return rc; 790 return rc;
784} 791}
785 792
786static int uhci_pci_suspend(struct usb_hcd *hcd) 793static int uhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup)
787{ 794{
788 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 795 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
796 struct pci_dev *pdev = to_pci_dev(uhci_dev(uhci));
789 int rc = 0; 797 int rc = 0;
790 798
791 dev_dbg(uhci_dev(uhci), "%s\n", __func__); 799 dev_dbg(uhci_dev(uhci), "%s\n", __func__);
792 800
793 spin_lock_irq(&uhci->lock); 801 spin_lock_irq(&uhci->lock);
794 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags) || uhci->dead) 802 if (!HCD_HW_ACCESSIBLE(hcd) || uhci->dead)
795 goto done_okay; /* Already suspended or dead */ 803 goto done_okay; /* Already suspended or dead */
796 804
797 if (uhci->rh_state > UHCI_RH_SUSPENDED) { 805 if (uhci->rh_state > UHCI_RH_SUSPENDED) {
@@ -803,11 +811,15 @@ static int uhci_pci_suspend(struct usb_hcd *hcd)
803 /* All PCI host controllers are required to disable IRQ generation 811 /* All PCI host controllers are required to disable IRQ generation
804 * at the source, so we must turn off PIRQ. 812 * at the source, so we must turn off PIRQ.
805 */ 813 */
806 pci_write_config_word(to_pci_dev(uhci_dev(uhci)), USBLEGSUP, 0); 814 pci_write_config_word(pdev, USBLEGSUP, 0);
807 mb(); 815 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
808 hcd->poll_rh = 0; 816
809 817 /* Enable platform-specific non-PME# wakeup */
810 /* FIXME: Enable non-PME# remote wakeup? */ 818 if (do_wakeup) {
819 if (pdev->vendor == PCI_VENDOR_ID_INTEL)
820 pci_write_config_byte(pdev, USBRES_INTEL,
821 USBPORT1EN | USBPORT2EN);
822 }
811 823
812done_okay: 824done_okay:
813 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); 825 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
@@ -826,7 +838,6 @@ static int uhci_pci_resume(struct usb_hcd *hcd, bool hibernated)
826 * even if the controller was dead. 838 * even if the controller was dead.
827 */ 839 */
828 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); 840 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
829 mb();
830 841
831 spin_lock_irq(&uhci->lock); 842 spin_lock_irq(&uhci->lock);
832 843
@@ -834,8 +845,6 @@ static int uhci_pci_resume(struct usb_hcd *hcd, bool hibernated)
834 if (hibernated) 845 if (hibernated)
835 uhci_hc_died(uhci); 846 uhci_hc_died(uhci);
836 847
837 /* FIXME: Disable non-PME# remote wakeup? */
838
839 /* The firmware or a boot kernel may have changed the controller 848 /* The firmware or a boot kernel may have changed the controller
840 * settings during a system wakeup. Check it and reconfigure 849 * settings during a system wakeup. Check it and reconfigure
841 * to avoid problems. 850 * to avoid problems.
@@ -845,22 +854,20 @@ static int uhci_pci_resume(struct usb_hcd *hcd, bool hibernated)
845 /* If the controller was dead before, it's back alive now */ 854 /* If the controller was dead before, it's back alive now */
846 configure_hc(uhci); 855 configure_hc(uhci);
847 856
848 if (uhci->rh_state == UHCI_RH_RESET) { 857 /* Tell the core if the controller had to be reset */
849 858 if (uhci->rh_state == UHCI_RH_RESET)
850 /* The controller had to be reset */
851 usb_root_hub_lost_power(hcd->self.root_hub); 859 usb_root_hub_lost_power(hcd->self.root_hub);
852 suspend_rh(uhci, UHCI_RH_SUSPENDED);
853 }
854 860
855 spin_unlock_irq(&uhci->lock); 861 spin_unlock_irq(&uhci->lock);
856 862
857 /* If interrupts don't work and remote wakeup is enabled then 863 /* If interrupts don't work and remote wakeup is enabled then
858 * the suspended root hub needs to be polled. 864 * the suspended root hub needs to be polled.
859 */ 865 */
860 if (!uhci->RD_enable && hcd->self.root_hub->do_remote_wakeup) { 866 if (!uhci->RD_enable && hcd->self.root_hub->do_remote_wakeup)
861 hcd->poll_rh = 1; 867 set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
862 usb_hcd_poll_rh_status(hcd); 868
863 } 869 /* Does the root hub have a port wakeup pending? */
870 usb_hcd_poll_rh_status(hcd);
864 return 0; 871 return 0;
865} 872}
866#endif 873#endif
diff --git a/drivers/usb/host/uhci-hcd.h b/drivers/usb/host/uhci-hcd.h
index 26bd1b2bcbfc..49bf2790f9c2 100644
--- a/drivers/usb/host/uhci-hcd.h
+++ b/drivers/usb/host/uhci-hcd.h
@@ -67,12 +67,17 @@
67#define USBPORTSC_RES3 0x4000 /* reserved, write zeroes */ 67#define USBPORTSC_RES3 0x4000 /* reserved, write zeroes */
68#define USBPORTSC_RES4 0x8000 /* reserved, write zeroes */ 68#define USBPORTSC_RES4 0x8000 /* reserved, write zeroes */
69 69
70/* Legacy support register */ 70/* PCI legacy support register */
71#define USBLEGSUP 0xc0 71#define USBLEGSUP 0xc0
72#define USBLEGSUP_DEFAULT 0x2000 /* only PIRQ enable set */ 72#define USBLEGSUP_DEFAULT 0x2000 /* only PIRQ enable set */
73#define USBLEGSUP_RWC 0x8f00 /* the R/WC bits */ 73#define USBLEGSUP_RWC 0x8f00 /* the R/WC bits */
74#define USBLEGSUP_RO 0x5040 /* R/O and reserved bits */ 74#define USBLEGSUP_RO 0x5040 /* R/O and reserved bits */
75 75
76/* PCI Intel-specific resume-enable register */
77#define USBRES_INTEL 0xc4
78#define USBPORT1EN 0x01
79#define USBPORT2EN 0x02
80
76#define UHCI_PTR_BITS cpu_to_le32(0x000F) 81#define UHCI_PTR_BITS cpu_to_le32(0x000F)
77#define UHCI_PTR_TERM cpu_to_le32(0x0001) 82#define UHCI_PTR_TERM cpu_to_le32(0x0001)
78#define UHCI_PTR_QH cpu_to_le32(0x0002) 83#define UHCI_PTR_QH cpu_to_le32(0x0002)
diff --git a/drivers/usb/host/uhci-hub.c b/drivers/usb/host/uhci-hub.c
index 8270055848ca..6d59c0f77f25 100644
--- a/drivers/usb/host/uhci-hub.c
+++ b/drivers/usb/host/uhci-hub.c
@@ -190,7 +190,7 @@ static int uhci_hub_status_data(struct usb_hcd *hcd, char *buf)
190 spin_lock_irqsave(&uhci->lock, flags); 190 spin_lock_irqsave(&uhci->lock, flags);
191 191
192 uhci_scan_schedule(uhci); 192 uhci_scan_schedule(uhci);
193 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags) || uhci->dead) 193 if (!HCD_HW_ACCESSIBLE(hcd) || uhci->dead)
194 goto done; 194 goto done;
195 uhci_check_ports(uhci); 195 uhci_check_ports(uhci);
196 196
@@ -200,7 +200,7 @@ static int uhci_hub_status_data(struct usb_hcd *hcd, char *buf)
200 case UHCI_RH_SUSPENDING: 200 case UHCI_RH_SUSPENDING:
201 case UHCI_RH_SUSPENDED: 201 case UHCI_RH_SUSPENDED:
202 /* if port change, ask to be resumed */ 202 /* if port change, ask to be resumed */
203 if (status) 203 if (status || uhci->resuming_ports)
204 usb_hcd_resume_root_hub(hcd); 204 usb_hcd_resume_root_hub(hcd);
205 break; 205 break;
206 206
@@ -246,7 +246,7 @@ static int uhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
246 u16 wPortChange, wPortStatus; 246 u16 wPortChange, wPortStatus;
247 unsigned long flags; 247 unsigned long flags;
248 248
249 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags) || uhci->dead) 249 if (!HCD_HW_ACCESSIBLE(hcd) || uhci->dead)
250 return -ETIMEDOUT; 250 return -ETIMEDOUT;
251 251
252 spin_lock_irqsave(&uhci->lock, flags); 252 spin_lock_irqsave(&uhci->lock, flags);
diff --git a/drivers/usb/host/uhci-q.c b/drivers/usb/host/uhci-q.c
index acd582c02802..d3ade4018487 100644
--- a/drivers/usb/host/uhci-q.c
+++ b/drivers/usb/host/uhci-q.c
@@ -565,7 +565,7 @@ static void uhci_unlink_qh(struct uhci_hcd *uhci, struct uhci_qh *qh)
565 qh->unlink_frame = uhci->frame_number; 565 qh->unlink_frame = uhci->frame_number;
566 566
567 /* Force an interrupt so we know when the QH is fully unlinked */ 567 /* Force an interrupt so we know when the QH is fully unlinked */
568 if (list_empty(&uhci->skel_unlink_qh->node)) 568 if (list_empty(&uhci->skel_unlink_qh->node) || uhci->is_stopped)
569 uhci_set_next_interrupt(uhci); 569 uhci_set_next_interrupt(uhci);
570 570
571 /* Move the QH from its old list to the end of the unlinking list */ 571 /* Move the QH from its old list to the end of the unlinking list */
@@ -1667,7 +1667,7 @@ static int uhci_advance_check(struct uhci_hcd *uhci, struct uhci_qh *qh)
1667 qh->advance_jiffies = jiffies; 1667 qh->advance_jiffies = jiffies;
1668 goto done; 1668 goto done;
1669 } 1669 }
1670 ret = 0; 1670 ret = uhci->is_stopped;
1671 } 1671 }
1672 1672
1673 /* The queue hasn't advanced; check for timeout */ 1673 /* The queue hasn't advanced; check for timeout */
diff --git a/drivers/usb/host/whci/hcd.c b/drivers/usb/host/whci/hcd.c
index e0d3401285c8..72b6892fda67 100644
--- a/drivers/usb/host/whci/hcd.c
+++ b/drivers/usb/host/whci/hcd.c
@@ -68,7 +68,7 @@ static int whc_start(struct usb_hcd *usb_hcd)
68 whc_write_wusbcmd(whc, WUSBCMD_RUN, WUSBCMD_RUN); 68 whc_write_wusbcmd(whc, WUSBCMD_RUN, WUSBCMD_RUN);
69 69
70 usb_hcd->uses_new_polling = 1; 70 usb_hcd->uses_new_polling = 1;
71 usb_hcd->poll_rh = 1; 71 set_bit(HCD_FLAG_POLL_RH, &usb_hcd->flags);
72 usb_hcd->state = HC_STATE_RUNNING; 72 usb_hcd->state = HC_STATE_RUNNING;
73 73
74out: 74out:
diff --git a/drivers/usb/host/whci/qset.c b/drivers/usb/host/whci/qset.c
index ab5a14fbfeeb..dc0ab8382f5d 100644
--- a/drivers/usb/host/whci/qset.c
+++ b/drivers/usb/host/whci/qset.c
@@ -475,7 +475,7 @@ static int qset_add_urb_sg(struct whc *whc, struct whc_qset *qset, struct urb *u
475 || (prev_end & (WHCI_PAGE_SIZE-1)) 475 || (prev_end & (WHCI_PAGE_SIZE-1))
476 || (dma_addr & (WHCI_PAGE_SIZE-1)) 476 || (dma_addr & (WHCI_PAGE_SIZE-1))
477 || std->len + WHCI_PAGE_SIZE > QTD_MAX_XFER_SIZE) { 477 || std->len + WHCI_PAGE_SIZE > QTD_MAX_XFER_SIZE) {
478 if (std->len % qset->max_packet != 0) 478 if (std && std->len % qset->max_packet != 0)
479 return -EINVAL; 479 return -EINVAL;
480 std = qset_new_std(whc, qset, urb, mem_flags); 480 std = qset_new_std(whc, qset, urb, mem_flags);
481 if (std == NULL) { 481 if (std == NULL) {
diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 2eb658d26394..4e51343ddffc 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -391,49 +391,6 @@ struct xhci_ring *xhci_stream_id_to_ring(
391 return ep->stream_info->stream_rings[stream_id]; 391 return ep->stream_info->stream_rings[stream_id];
392} 392}
393 393
394struct xhci_ring *xhci_triad_to_transfer_ring(struct xhci_hcd *xhci,
395 unsigned int slot_id, unsigned int ep_index,
396 unsigned int stream_id)
397{
398 struct xhci_virt_ep *ep;
399
400 ep = &xhci->devs[slot_id]->eps[ep_index];
401 /* Common case: no streams */
402 if (!(ep->ep_state & EP_HAS_STREAMS))
403 return ep->ring;
404
405 if (stream_id == 0) {
406 xhci_warn(xhci,
407 "WARN: Slot ID %u, ep index %u has streams, "
408 "but URB has no stream ID.\n",
409 slot_id, ep_index);
410 return NULL;
411 }
412
413 if (stream_id < ep->stream_info->num_streams)
414 return ep->stream_info->stream_rings[stream_id];
415
416 xhci_warn(xhci,
417 "WARN: Slot ID %u, ep index %u has "
418 "stream IDs 1 to %u allocated, "
419 "but stream ID %u is requested.\n",
420 slot_id, ep_index,
421 ep->stream_info->num_streams - 1,
422 stream_id);
423 return NULL;
424}
425
426/* Get the right ring for the given URB.
427 * If the endpoint supports streams, boundary check the URB's stream ID.
428 * If the endpoint doesn't support streams, return the singular endpoint ring.
429 */
430struct xhci_ring *xhci_urb_to_transfer_ring(struct xhci_hcd *xhci,
431 struct urb *urb)
432{
433 return xhci_triad_to_transfer_ring(xhci, urb->dev->slot_id,
434 xhci_get_endpoint_index(&urb->ep->desc), urb->stream_id);
435}
436
437#ifdef CONFIG_USB_XHCI_HCD_DEBUGGING 394#ifdef CONFIG_USB_XHCI_HCD_DEBUGGING
438static int xhci_test_radix_tree(struct xhci_hcd *xhci, 395static int xhci_test_radix_tree(struct xhci_hcd *xhci,
439 unsigned int num_streams, 396 unsigned int num_streams,
@@ -1112,8 +1069,18 @@ int xhci_endpoint_init(struct xhci_hcd *xhci,
1112 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index); 1069 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index);
1113 1070
1114 /* Set up the endpoint ring */ 1071 /* Set up the endpoint ring */
1115 virt_dev->eps[ep_index].new_ring = 1072 /*
1116 xhci_ring_alloc(xhci, 1, true, mem_flags); 1073 * Isochronous endpoint ring needs bigger size because one isoc URB
1074 * carries multiple packets and it will insert multiple tds to the
1075 * ring.
1076 * This should be replaced with dynamic ring resizing in the future.
1077 */
1078 if (usb_endpoint_xfer_isoc(&ep->desc))
1079 virt_dev->eps[ep_index].new_ring =
1080 xhci_ring_alloc(xhci, 8, true, mem_flags);
1081 else
1082 virt_dev->eps[ep_index].new_ring =
1083 xhci_ring_alloc(xhci, 1, true, mem_flags);
1117 if (!virt_dev->eps[ep_index].new_ring) { 1084 if (!virt_dev->eps[ep_index].new_ring) {
1118 /* Attempt to use the ring cache */ 1085 /* Attempt to use the ring cache */
1119 if (virt_dev->num_rings_cached == 0) 1086 if (virt_dev->num_rings_cached == 0)
@@ -1124,6 +1091,7 @@ int xhci_endpoint_init(struct xhci_hcd *xhci,
1124 virt_dev->num_rings_cached--; 1091 virt_dev->num_rings_cached--;
1125 xhci_reinit_cached_ring(xhci, virt_dev->eps[ep_index].new_ring); 1092 xhci_reinit_cached_ring(xhci, virt_dev->eps[ep_index].new_ring);
1126 } 1093 }
1094 virt_dev->eps[ep_index].skip = false;
1127 ep_ring = virt_dev->eps[ep_index].new_ring; 1095 ep_ring = virt_dev->eps[ep_index].new_ring;
1128 ep_ctx->deq = ep_ring->first_seg->dma | ep_ring->cycle_state; 1096 ep_ctx->deq = ep_ring->first_seg->dma | ep_ring->cycle_state;
1129 1097
@@ -1389,6 +1357,22 @@ struct xhci_command *xhci_alloc_command(struct xhci_hcd *xhci,
1389 return command; 1357 return command;
1390} 1358}
1391 1359
1360void xhci_urb_free_priv(struct xhci_hcd *xhci, struct urb_priv *urb_priv)
1361{
1362 int last;
1363
1364 if (!urb_priv)
1365 return;
1366
1367 last = urb_priv->length - 1;
1368 if (last >= 0) {
1369 int i;
1370 for (i = 0; i <= last; i++)
1371 kfree(urb_priv->td[i]);
1372 }
1373 kfree(urb_priv);
1374}
1375
1392void xhci_free_command(struct xhci_hcd *xhci, 1376void xhci_free_command(struct xhci_hcd *xhci,
1393 struct xhci_command *command) 1377 struct xhci_command *command)
1394{ 1378{
@@ -1588,7 +1572,7 @@ static int xhci_check_trb_in_td_math(struct xhci_hcd *xhci, gfp_t mem_flags)
1588 unsigned int num_tests; 1572 unsigned int num_tests;
1589 int i, ret; 1573 int i, ret;
1590 1574
1591 num_tests = sizeof(simple_test_vector) / sizeof(simple_test_vector[0]); 1575 num_tests = ARRAY_SIZE(simple_test_vector);
1592 for (i = 0; i < num_tests; i++) { 1576 for (i = 0; i < num_tests; i++) {
1593 ret = xhci_test_trb_in_td(xhci, 1577 ret = xhci_test_trb_in_td(xhci,
1594 xhci->event_ring->first_seg, 1578 xhci->event_ring->first_seg,
@@ -1601,7 +1585,7 @@ static int xhci_check_trb_in_td_math(struct xhci_hcd *xhci, gfp_t mem_flags)
1601 return ret; 1585 return ret;
1602 } 1586 }
1603 1587
1604 num_tests = sizeof(complex_test_vector) / sizeof(complex_test_vector[0]); 1588 num_tests = ARRAY_SIZE(complex_test_vector);
1605 for (i = 0; i < num_tests; i++) { 1589 for (i = 0; i < num_tests; i++) {
1606 ret = xhci_test_trb_in_td(xhci, 1590 ret = xhci_test_trb_in_td(xhci,
1607 complex_test_vector[i].input_seg, 1591 complex_test_vector[i].input_seg,
@@ -1617,6 +1601,29 @@ static int xhci_check_trb_in_td_math(struct xhci_hcd *xhci, gfp_t mem_flags)
1617 return 0; 1601 return 0;
1618} 1602}
1619 1603
1604static void xhci_set_hc_event_deq(struct xhci_hcd *xhci)
1605{
1606 u64 temp;
1607 dma_addr_t deq;
1608
1609 deq = xhci_trb_virt_to_dma(xhci->event_ring->deq_seg,
1610 xhci->event_ring->dequeue);
1611 if (deq == 0 && !in_interrupt())
1612 xhci_warn(xhci, "WARN something wrong with SW event ring "
1613 "dequeue ptr.\n");
1614 /* Update HC event ring dequeue pointer */
1615 temp = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue);
1616 temp &= ERST_PTR_MASK;
1617 /* Don't clear the EHB bit (which is RW1C) because
1618 * there might be more events to service.
1619 */
1620 temp &= ~ERST_EHB;
1621 xhci_dbg(xhci, "// Write event ring dequeue pointer, "
1622 "preserving EHB bit\n");
1623 xhci_write_64(xhci, ((u64) deq & (u64) ~ERST_PTR_MASK) | temp,
1624 &xhci->ir_set->erst_dequeue);
1625}
1626
1620 1627
1621int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) 1628int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
1622{ 1629{
diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
index 11482b6b9381..f7efe025beda 100644
--- a/drivers/usb/host/xhci-pci.c
+++ b/drivers/usb/host/xhci-pci.c
@@ -53,6 +53,7 @@ static int xhci_pci_setup(struct usb_hcd *hcd)
53 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 53 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
54 struct pci_dev *pdev = to_pci_dev(hcd->self.controller); 54 struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
55 int retval; 55 int retval;
56 u32 temp;
56 57
57 hcd->self.sg_tablesize = TRBS_PER_SEGMENT - 2; 58 hcd->self.sg_tablesize = TRBS_PER_SEGMENT - 2;
58 59
@@ -93,6 +94,14 @@ static int xhci_pci_setup(struct usb_hcd *hcd)
93 return retval; 94 return retval;
94 xhci_dbg(xhci, "Reset complete\n"); 95 xhci_dbg(xhci, "Reset complete\n");
95 96
97 temp = xhci_readl(xhci, &xhci->cap_regs->hcc_params);
98 if (HCC_64BIT_ADDR(temp)) {
99 xhci_dbg(xhci, "Enabling 64-bit DMA addresses.\n");
100 dma_set_mask(hcd->self.controller, DMA_BIT_MASK(64));
101 } else {
102 dma_set_mask(hcd->self.controller, DMA_BIT_MASK(32));
103 }
104
96 xhci_dbg(xhci, "Calling HCD init\n"); 105 xhci_dbg(xhci, "Calling HCD init\n");
97 /* Initialize HCD and host controller data structures. */ 106 /* Initialize HCD and host controller data structures. */
98 retval = xhci_init(hcd); 107 retval = xhci_init(hcd);
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index bfc99a939455..bc3f4f427065 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -301,28 +301,6 @@ static int room_on_ring(struct xhci_hcd *xhci, struct xhci_ring *ring,
301 return 1; 301 return 1;
302} 302}
303 303
304void xhci_set_hc_event_deq(struct xhci_hcd *xhci)
305{
306 u64 temp;
307 dma_addr_t deq;
308
309 deq = xhci_trb_virt_to_dma(xhci->event_ring->deq_seg,
310 xhci->event_ring->dequeue);
311 if (deq == 0 && !in_interrupt())
312 xhci_warn(xhci, "WARN something wrong with SW event ring "
313 "dequeue ptr.\n");
314 /* Update HC event ring dequeue pointer */
315 temp = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue);
316 temp &= ERST_PTR_MASK;
317 /* Don't clear the EHB bit (which is RW1C) because
318 * there might be more events to service.
319 */
320 temp &= ~ERST_EHB;
321 xhci_dbg(xhci, "// Write event ring dequeue pointer, preserving EHB bit\n");
322 xhci_write_64(xhci, ((u64) deq & (u64) ~ERST_PTR_MASK) | temp,
323 &xhci->ir_set->erst_dequeue);
324}
325
326/* Ring the host controller doorbell after placing a command on the ring */ 304/* Ring the host controller doorbell after placing a command on the ring */
327void xhci_ring_cmd_db(struct xhci_hcd *xhci) 305void xhci_ring_cmd_db(struct xhci_hcd *xhci)
328{ 306{
@@ -359,11 +337,6 @@ static void ring_ep_doorbell(struct xhci_hcd *xhci,
359 field = xhci_readl(xhci, db_addr) & DB_MASK; 337 field = xhci_readl(xhci, db_addr) & DB_MASK;
360 field |= EPI_TO_DB(ep_index) | STREAM_ID_TO_DB(stream_id); 338 field |= EPI_TO_DB(ep_index) | STREAM_ID_TO_DB(stream_id);
361 xhci_writel(xhci, field, db_addr); 339 xhci_writel(xhci, field, db_addr);
362 /* Flush PCI posted writes - FIXME Matthew Wilcox says this
363 * isn't time-critical and we shouldn't make the CPU wait for
364 * the flush.
365 */
366 xhci_readl(xhci, db_addr);
367 } 340 }
368} 341}
369 342
@@ -419,6 +392,50 @@ static struct xhci_segment *find_trb_seg(
419 return cur_seg; 392 return cur_seg;
420} 393}
421 394
395
396static struct xhci_ring *xhci_triad_to_transfer_ring(struct xhci_hcd *xhci,
397 unsigned int slot_id, unsigned int ep_index,
398 unsigned int stream_id)
399{
400 struct xhci_virt_ep *ep;
401
402 ep = &xhci->devs[slot_id]->eps[ep_index];
403 /* Common case: no streams */
404 if (!(ep->ep_state & EP_HAS_STREAMS))
405 return ep->ring;
406
407 if (stream_id == 0) {
408 xhci_warn(xhci,
409 "WARN: Slot ID %u, ep index %u has streams, "
410 "but URB has no stream ID.\n",
411 slot_id, ep_index);
412 return NULL;
413 }
414
415 if (stream_id < ep->stream_info->num_streams)
416 return ep->stream_info->stream_rings[stream_id];
417
418 xhci_warn(xhci,
419 "WARN: Slot ID %u, ep index %u has "
420 "stream IDs 1 to %u allocated, "
421 "but stream ID %u is requested.\n",
422 slot_id, ep_index,
423 ep->stream_info->num_streams - 1,
424 stream_id);
425 return NULL;
426}
427
428/* Get the right ring for the given URB.
429 * If the endpoint supports streams, boundary check the URB's stream ID.
430 * If the endpoint doesn't support streams, return the singular endpoint ring.
431 */
432static struct xhci_ring *xhci_urb_to_transfer_ring(struct xhci_hcd *xhci,
433 struct urb *urb)
434{
435 return xhci_triad_to_transfer_ring(xhci, urb->dev->slot_id,
436 xhci_get_endpoint_index(&urb->ep->desc), urb->stream_id);
437}
438
422/* 439/*
423 * Move the xHC's endpoint ring dequeue pointer past cur_td. 440 * Move the xHC's endpoint ring dequeue pointer past cur_td.
424 * Record the new state of the xHC's endpoint ring dequeue segment, 441 * Record the new state of the xHC's endpoint ring dequeue segment,
@@ -578,16 +595,24 @@ static void xhci_giveback_urb_in_irq(struct xhci_hcd *xhci,
578 struct xhci_td *cur_td, int status, char *adjective) 595 struct xhci_td *cur_td, int status, char *adjective)
579{ 596{
580 struct usb_hcd *hcd = xhci_to_hcd(xhci); 597 struct usb_hcd *hcd = xhci_to_hcd(xhci);
598 struct urb *urb;
599 struct urb_priv *urb_priv;
581 600
582 cur_td->urb->hcpriv = NULL; 601 urb = cur_td->urb;
583 usb_hcd_unlink_urb_from_ep(hcd, cur_td->urb); 602 urb_priv = urb->hcpriv;
584 xhci_dbg(xhci, "Giveback %s URB %p\n", adjective, cur_td->urb); 603 urb_priv->td_cnt++;
585 604
586 spin_unlock(&xhci->lock); 605 /* Only giveback urb when this is the last td in urb */
587 usb_hcd_giveback_urb(hcd, cur_td->urb, status); 606 if (urb_priv->td_cnt == urb_priv->length) {
588 kfree(cur_td); 607 usb_hcd_unlink_urb_from_ep(hcd, urb);
589 spin_lock(&xhci->lock); 608 xhci_dbg(xhci, "Giveback %s URB %p\n", adjective, urb);
590 xhci_dbg(xhci, "%s URB given back\n", adjective); 609
610 spin_unlock(&xhci->lock);
611 usb_hcd_giveback_urb(hcd, urb, status);
612 xhci_urb_free_priv(xhci, urb_priv);
613 spin_lock(&xhci->lock);
614 xhci_dbg(xhci, "%s URB given back\n", adjective);
615 }
591} 616}
592 617
593/* 618/*
@@ -1132,7 +1157,6 @@ static void handle_port_status(struct xhci_hcd *xhci,
1132 1157
1133 /* Update event ring dequeue pointer before dropping the lock */ 1158 /* Update event ring dequeue pointer before dropping the lock */
1134 inc_deq(xhci, xhci->event_ring, true); 1159 inc_deq(xhci, xhci->event_ring, true);
1135 xhci_set_hc_event_deq(xhci);
1136 1160
1137 spin_unlock(&xhci->lock); 1161 spin_unlock(&xhci->lock);
1138 /* Pass this up to the core */ 1162 /* Pass this up to the core */
@@ -1258,6 +1282,421 @@ int xhci_is_vendor_info_code(struct xhci_hcd *xhci, unsigned int trb_comp_code)
1258} 1282}
1259 1283
1260/* 1284/*
1285 * Finish the td processing, remove the td from td list;
1286 * Return 1 if the urb can be given back.
1287 */
1288static int finish_td(struct xhci_hcd *xhci, struct xhci_td *td,
1289 union xhci_trb *event_trb, struct xhci_transfer_event *event,
1290 struct xhci_virt_ep *ep, int *status, bool skip)
1291{
1292 struct xhci_virt_device *xdev;
1293 struct xhci_ring *ep_ring;
1294 unsigned int slot_id;
1295 int ep_index;
1296 struct urb *urb = NULL;
1297 struct xhci_ep_ctx *ep_ctx;
1298 int ret = 0;
1299 struct urb_priv *urb_priv;
1300 u32 trb_comp_code;
1301
1302 slot_id = TRB_TO_SLOT_ID(event->flags);
1303 xdev = xhci->devs[slot_id];
1304 ep_index = TRB_TO_EP_ID(event->flags) - 1;
1305 ep_ring = xhci_dma_to_transfer_ring(ep, event->buffer);
1306 ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index);
1307 trb_comp_code = GET_COMP_CODE(event->transfer_len);
1308
1309 if (skip)
1310 goto td_cleanup;
1311
1312 if (trb_comp_code == COMP_STOP_INVAL ||
1313 trb_comp_code == COMP_STOP) {
1314 /* The Endpoint Stop Command completion will take care of any
1315 * stopped TDs. A stopped TD may be restarted, so don't update
1316 * the ring dequeue pointer or take this TD off any lists yet.
1317 */
1318 ep->stopped_td = td;
1319 ep->stopped_trb = event_trb;
1320 return 0;
1321 } else {
1322 if (trb_comp_code == COMP_STALL) {
1323 /* The transfer is completed from the driver's
1324 * perspective, but we need to issue a set dequeue
1325 * command for this stalled endpoint to move the dequeue
1326 * pointer past the TD. We can't do that here because
1327 * the halt condition must be cleared first. Let the
1328 * USB class driver clear the stall later.
1329 */
1330 ep->stopped_td = td;
1331 ep->stopped_trb = event_trb;
1332 ep->stopped_stream = ep_ring->stream_id;
1333 } else if (xhci_requires_manual_halt_cleanup(xhci,
1334 ep_ctx, trb_comp_code)) {
1335 /* Other types of errors halt the endpoint, but the
1336 * class driver doesn't call usb_reset_endpoint() unless
1337 * the error is -EPIPE. Clear the halted status in the
1338 * xHCI hardware manually.
1339 */
1340 xhci_cleanup_halted_endpoint(xhci,
1341 slot_id, ep_index, ep_ring->stream_id,
1342 td, event_trb);
1343 } else {
1344 /* Update ring dequeue pointer */
1345 while (ep_ring->dequeue != td->last_trb)
1346 inc_deq(xhci, ep_ring, false);
1347 inc_deq(xhci, ep_ring, false);
1348 }
1349
1350td_cleanup:
1351 /* Clean up the endpoint's TD list */
1352 urb = td->urb;
1353 urb_priv = urb->hcpriv;
1354
1355 /* Do one last check of the actual transfer length.
1356 * If the host controller said we transferred more data than
1357 * the buffer length, urb->actual_length will be a very big
1358 * number (since it's unsigned). Play it safe and say we didn't
1359 * transfer anything.
1360 */
1361 if (urb->actual_length > urb->transfer_buffer_length) {
1362 xhci_warn(xhci, "URB transfer length is wrong, "
1363 "xHC issue? req. len = %u, "
1364 "act. len = %u\n",
1365 urb->transfer_buffer_length,
1366 urb->actual_length);
1367 urb->actual_length = 0;
1368 if (td->urb->transfer_flags & URB_SHORT_NOT_OK)
1369 *status = -EREMOTEIO;
1370 else
1371 *status = 0;
1372 }
1373 list_del(&td->td_list);
1374 /* Was this TD slated to be cancelled but completed anyway? */
1375 if (!list_empty(&td->cancelled_td_list))
1376 list_del(&td->cancelled_td_list);
1377
1378 urb_priv->td_cnt++;
1379 /* Giveback the urb when all the tds are completed */
1380 if (urb_priv->td_cnt == urb_priv->length)
1381 ret = 1;
1382 }
1383
1384 return ret;
1385}
1386
1387/*
1388 * Process control tds, update urb status and actual_length.
1389 */
1390static int process_ctrl_td(struct xhci_hcd *xhci, struct xhci_td *td,
1391 union xhci_trb *event_trb, struct xhci_transfer_event *event,
1392 struct xhci_virt_ep *ep, int *status)
1393{
1394 struct xhci_virt_device *xdev;
1395 struct xhci_ring *ep_ring;
1396 unsigned int slot_id;
1397 int ep_index;
1398 struct xhci_ep_ctx *ep_ctx;
1399 u32 trb_comp_code;
1400
1401 slot_id = TRB_TO_SLOT_ID(event->flags);
1402 xdev = xhci->devs[slot_id];
1403 ep_index = TRB_TO_EP_ID(event->flags) - 1;
1404 ep_ring = xhci_dma_to_transfer_ring(ep, event->buffer);
1405 ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index);
1406 trb_comp_code = GET_COMP_CODE(event->transfer_len);
1407
1408 xhci_debug_trb(xhci, xhci->event_ring->dequeue);
1409 switch (trb_comp_code) {
1410 case COMP_SUCCESS:
1411 if (event_trb == ep_ring->dequeue) {
1412 xhci_warn(xhci, "WARN: Success on ctrl setup TRB "
1413 "without IOC set??\n");
1414 *status = -ESHUTDOWN;
1415 } else if (event_trb != td->last_trb) {
1416 xhci_warn(xhci, "WARN: Success on ctrl data TRB "
1417 "without IOC set??\n");
1418 *status = -ESHUTDOWN;
1419 } else {
1420 xhci_dbg(xhci, "Successful control transfer!\n");
1421 *status = 0;
1422 }
1423 break;
1424 case COMP_SHORT_TX:
1425 xhci_warn(xhci, "WARN: short transfer on control ep\n");
1426 if (td->urb->transfer_flags & URB_SHORT_NOT_OK)
1427 *status = -EREMOTEIO;
1428 else
1429 *status = 0;
1430 break;
1431 default:
1432 if (!xhci_requires_manual_halt_cleanup(xhci,
1433 ep_ctx, trb_comp_code))
1434 break;
1435 xhci_dbg(xhci, "TRB error code %u, "
1436 "halted endpoint index = %u\n",
1437 trb_comp_code, ep_index);
1438 /* else fall through */
1439 case COMP_STALL:
1440 /* Did we transfer part of the data (middle) phase? */
1441 if (event_trb != ep_ring->dequeue &&
1442 event_trb != td->last_trb)
1443 td->urb->actual_length =
1444 td->urb->transfer_buffer_length
1445 - TRB_LEN(event->transfer_len);
1446 else
1447 td->urb->actual_length = 0;
1448
1449 xhci_cleanup_halted_endpoint(xhci,
1450 slot_id, ep_index, 0, td, event_trb);
1451 return finish_td(xhci, td, event_trb, event, ep, status, true);
1452 }
1453 /*
1454 * Did we transfer any data, despite the errors that might have
1455 * happened? I.e. did we get past the setup stage?
1456 */
1457 if (event_trb != ep_ring->dequeue) {
1458 /* The event was for the status stage */
1459 if (event_trb == td->last_trb) {
1460 if (td->urb->actual_length != 0) {
1461 /* Don't overwrite a previously set error code
1462 */
1463 if ((*status == -EINPROGRESS || *status == 0) &&
1464 (td->urb->transfer_flags
1465 & URB_SHORT_NOT_OK))
1466 /* Did we already see a short data
1467 * stage? */
1468 *status = -EREMOTEIO;
1469 } else {
1470 td->urb->actual_length =
1471 td->urb->transfer_buffer_length;
1472 }
1473 } else {
1474 /* Maybe the event was for the data stage? */
1475 if (trb_comp_code != COMP_STOP_INVAL) {
1476 /* We didn't stop on a link TRB in the middle */
1477 td->urb->actual_length =
1478 td->urb->transfer_buffer_length -
1479 TRB_LEN(event->transfer_len);
1480 xhci_dbg(xhci, "Waiting for status "
1481 "stage event\n");
1482 return 0;
1483 }
1484 }
1485 }
1486
1487 return finish_td(xhci, td, event_trb, event, ep, status, false);
1488}
1489
1490/*
1491 * Process isochronous tds, update urb packet status and actual_length.
1492 */
1493static int process_isoc_td(struct xhci_hcd *xhci, struct xhci_td *td,
1494 union xhci_trb *event_trb, struct xhci_transfer_event *event,
1495 struct xhci_virt_ep *ep, int *status)
1496{
1497 struct xhci_ring *ep_ring;
1498 struct urb_priv *urb_priv;
1499 int idx;
1500 int len = 0;
1501 int skip_td = 0;
1502 union xhci_trb *cur_trb;
1503 struct xhci_segment *cur_seg;
1504 u32 trb_comp_code;
1505
1506 ep_ring = xhci_dma_to_transfer_ring(ep, event->buffer);
1507 trb_comp_code = GET_COMP_CODE(event->transfer_len);
1508 urb_priv = td->urb->hcpriv;
1509 idx = urb_priv->td_cnt;
1510
1511 if (ep->skip) {
1512 /* The transfer is partly done */
1513 *status = -EXDEV;
1514 td->urb->iso_frame_desc[idx].status = -EXDEV;
1515 } else {
1516 /* handle completion code */
1517 switch (trb_comp_code) {
1518 case COMP_SUCCESS:
1519 td->urb->iso_frame_desc[idx].status = 0;
1520 xhci_dbg(xhci, "Successful isoc transfer!\n");
1521 break;
1522 case COMP_SHORT_TX:
1523 if (td->urb->transfer_flags & URB_SHORT_NOT_OK)
1524 td->urb->iso_frame_desc[idx].status =
1525 -EREMOTEIO;
1526 else
1527 td->urb->iso_frame_desc[idx].status = 0;
1528 break;
1529 case COMP_BW_OVER:
1530 td->urb->iso_frame_desc[idx].status = -ECOMM;
1531 skip_td = 1;
1532 break;
1533 case COMP_BUFF_OVER:
1534 case COMP_BABBLE:
1535 td->urb->iso_frame_desc[idx].status = -EOVERFLOW;
1536 skip_td = 1;
1537 break;
1538 case COMP_STALL:
1539 td->urb->iso_frame_desc[idx].status = -EPROTO;
1540 skip_td = 1;
1541 break;
1542 case COMP_STOP:
1543 case COMP_STOP_INVAL:
1544 break;
1545 default:
1546 td->urb->iso_frame_desc[idx].status = -1;
1547 break;
1548 }
1549 }
1550
1551 /* calc actual length */
1552 if (ep->skip) {
1553 td->urb->iso_frame_desc[idx].actual_length = 0;
1554 return finish_td(xhci, td, event_trb, event, ep, status, true);
1555 }
1556
1557 if (trb_comp_code == COMP_SUCCESS || skip_td == 1) {
1558 td->urb->iso_frame_desc[idx].actual_length =
1559 td->urb->iso_frame_desc[idx].length;
1560 td->urb->actual_length +=
1561 td->urb->iso_frame_desc[idx].length;
1562 } else {
1563 for (cur_trb = ep_ring->dequeue,
1564 cur_seg = ep_ring->deq_seg; cur_trb != event_trb;
1565 next_trb(xhci, ep_ring, &cur_seg, &cur_trb)) {
1566 if ((cur_trb->generic.field[3] &
1567 TRB_TYPE_BITMASK) != TRB_TYPE(TRB_TR_NOOP) &&
1568 (cur_trb->generic.field[3] &
1569 TRB_TYPE_BITMASK) != TRB_TYPE(TRB_LINK))
1570 len +=
1571 TRB_LEN(cur_trb->generic.field[2]);
1572 }
1573 len += TRB_LEN(cur_trb->generic.field[2]) -
1574 TRB_LEN(event->transfer_len);
1575
1576 if (trb_comp_code != COMP_STOP_INVAL) {
1577 td->urb->iso_frame_desc[idx].actual_length = len;
1578 td->urb->actual_length += len;
1579 }
1580 }
1581
1582 if ((idx == urb_priv->length - 1) && *status == -EINPROGRESS)
1583 *status = 0;
1584
1585 return finish_td(xhci, td, event_trb, event, ep, status, false);
1586}
1587
1588/*
1589 * Process bulk and interrupt tds, update urb status and actual_length.
1590 */
1591static int process_bulk_intr_td(struct xhci_hcd *xhci, struct xhci_td *td,
1592 union xhci_trb *event_trb, struct xhci_transfer_event *event,
1593 struct xhci_virt_ep *ep, int *status)
1594{
1595 struct xhci_ring *ep_ring;
1596 union xhci_trb *cur_trb;
1597 struct xhci_segment *cur_seg;
1598 u32 trb_comp_code;
1599
1600 ep_ring = xhci_dma_to_transfer_ring(ep, event->buffer);
1601 trb_comp_code = GET_COMP_CODE(event->transfer_len);
1602
1603 switch (trb_comp_code) {
1604 case COMP_SUCCESS:
1605 /* Double check that the HW transferred everything. */
1606 if (event_trb != td->last_trb) {
1607 xhci_warn(xhci, "WARN Successful completion "
1608 "on short TX\n");
1609 if (td->urb->transfer_flags & URB_SHORT_NOT_OK)
1610 *status = -EREMOTEIO;
1611 else
1612 *status = 0;
1613 } else {
1614 if (usb_endpoint_xfer_bulk(&td->urb->ep->desc))
1615 xhci_dbg(xhci, "Successful bulk "
1616 "transfer!\n");
1617 else
1618 xhci_dbg(xhci, "Successful interrupt "
1619 "transfer!\n");
1620 *status = 0;
1621 }
1622 break;
1623 case COMP_SHORT_TX:
1624 if (td->urb->transfer_flags & URB_SHORT_NOT_OK)
1625 *status = -EREMOTEIO;
1626 else
1627 *status = 0;
1628 break;
1629 default:
1630 /* Others already handled above */
1631 break;
1632 }
1633 dev_dbg(&td->urb->dev->dev,
1634 "ep %#x - asked for %d bytes, "
1635 "%d bytes untransferred\n",
1636 td->urb->ep->desc.bEndpointAddress,
1637 td->urb->transfer_buffer_length,
1638 TRB_LEN(event->transfer_len));
1639 /* Fast path - was this the last TRB in the TD for this URB? */
1640 if (event_trb == td->last_trb) {
1641 if (TRB_LEN(event->transfer_len) != 0) {
1642 td->urb->actual_length =
1643 td->urb->transfer_buffer_length -
1644 TRB_LEN(event->transfer_len);
1645 if (td->urb->transfer_buffer_length <
1646 td->urb->actual_length) {
1647 xhci_warn(xhci, "HC gave bad length "
1648 "of %d bytes left\n",
1649 TRB_LEN(event->transfer_len));
1650 td->urb->actual_length = 0;
1651 if (td->urb->transfer_flags & URB_SHORT_NOT_OK)
1652 *status = -EREMOTEIO;
1653 else
1654 *status = 0;
1655 }
1656 /* Don't overwrite a previously set error code */
1657 if (*status == -EINPROGRESS) {
1658 if (td->urb->transfer_flags & URB_SHORT_NOT_OK)
1659 *status = -EREMOTEIO;
1660 else
1661 *status = 0;
1662 }
1663 } else {
1664 td->urb->actual_length =
1665 td->urb->transfer_buffer_length;
1666 /* Ignore a short packet completion if the
1667 * untransferred length was zero.
1668 */
1669 if (*status == -EREMOTEIO)
1670 *status = 0;
1671 }
1672 } else {
1673 /* Slow path - walk the list, starting from the dequeue
1674 * pointer, to get the actual length transferred.
1675 */
1676 td->urb->actual_length = 0;
1677 for (cur_trb = ep_ring->dequeue, cur_seg = ep_ring->deq_seg;
1678 cur_trb != event_trb;
1679 next_trb(xhci, ep_ring, &cur_seg, &cur_trb)) {
1680 if ((cur_trb->generic.field[3] &
1681 TRB_TYPE_BITMASK) != TRB_TYPE(TRB_TR_NOOP) &&
1682 (cur_trb->generic.field[3] &
1683 TRB_TYPE_BITMASK) != TRB_TYPE(TRB_LINK))
1684 td->urb->actual_length +=
1685 TRB_LEN(cur_trb->generic.field[2]);
1686 }
1687 /* If the ring didn't stop on a Link or No-op TRB, add
1688 * in the actual bytes transferred from the Normal TRB
1689 */
1690 if (trb_comp_code != COMP_STOP_INVAL)
1691 td->urb->actual_length +=
1692 TRB_LEN(cur_trb->generic.field[2]) -
1693 TRB_LEN(event->transfer_len);
1694 }
1695
1696 return finish_td(xhci, td, event_trb, event, ep, status, false);
1697}
1698
1699/*
1261 * If this function returns an error condition, it means it got a Transfer 1700 * If this function returns an error condition, it means it got a Transfer
1262 * event with a corrupted Slot ID, Endpoint ID, or TRB DMA address. 1701 * event with a corrupted Slot ID, Endpoint ID, or TRB DMA address.
1263 * At this point, the host controller is probably hosed and should be reset. 1702 * At this point, the host controller is probably hosed and should be reset.
@@ -1276,10 +1715,11 @@ static int handle_tx_event(struct xhci_hcd *xhci,
1276 union xhci_trb *event_trb; 1715 union xhci_trb *event_trb;
1277 struct urb *urb = NULL; 1716 struct urb *urb = NULL;
1278 int status = -EINPROGRESS; 1717 int status = -EINPROGRESS;
1718 struct urb_priv *urb_priv;
1279 struct xhci_ep_ctx *ep_ctx; 1719 struct xhci_ep_ctx *ep_ctx;
1280 u32 trb_comp_code; 1720 u32 trb_comp_code;
1721 int ret = 0;
1281 1722
1282 xhci_dbg(xhci, "In %s\n", __func__);
1283 slot_id = TRB_TO_SLOT_ID(event->flags); 1723 slot_id = TRB_TO_SLOT_ID(event->flags);
1284 xdev = xhci->devs[slot_id]; 1724 xdev = xhci->devs[slot_id];
1285 if (!xdev) { 1725 if (!xdev) {
@@ -1293,51 +1733,16 @@ static int handle_tx_event(struct xhci_hcd *xhci,
1293 ep = &xdev->eps[ep_index]; 1733 ep = &xdev->eps[ep_index];
1294 ep_ring = xhci_dma_to_transfer_ring(ep, event->buffer); 1734 ep_ring = xhci_dma_to_transfer_ring(ep, event->buffer);
1295 ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index); 1735 ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index);
1296 if (!ep_ring || (ep_ctx->ep_info & EP_STATE_MASK) == EP_STATE_DISABLED) { 1736 if (!ep_ring ||
1737 (ep_ctx->ep_info & EP_STATE_MASK) == EP_STATE_DISABLED) {
1297 xhci_err(xhci, "ERROR Transfer event for disabled endpoint " 1738 xhci_err(xhci, "ERROR Transfer event for disabled endpoint "
1298 "or incorrect stream ring\n"); 1739 "or incorrect stream ring\n");
1299 return -ENODEV; 1740 return -ENODEV;
1300 } 1741 }
1301 1742
1302 event_dma = event->buffer; 1743 event_dma = event->buffer;
1303 /* This TRB should be in the TD at the head of this ring's TD list */
1304 xhci_dbg(xhci, "%s - checking for list empty\n", __func__);
1305 if (list_empty(&ep_ring->td_list)) {
1306 xhci_warn(xhci, "WARN Event TRB for slot %d ep %d with no TDs queued?\n",
1307 TRB_TO_SLOT_ID(event->flags), ep_index);
1308 xhci_dbg(xhci, "Event TRB with TRB type ID %u\n",
1309 (unsigned int) (event->flags & TRB_TYPE_BITMASK)>>10);
1310 xhci_print_trb_offsets(xhci, (union xhci_trb *) event);
1311 urb = NULL;
1312 goto cleanup;
1313 }
1314 xhci_dbg(xhci, "%s - getting list entry\n", __func__);
1315 td = list_entry(ep_ring->td_list.next, struct xhci_td, td_list);
1316
1317 /* Is this a TRB in the currently executing TD? */
1318 xhci_dbg(xhci, "%s - looking for TD\n", __func__);
1319 event_seg = trb_in_td(ep_ring->deq_seg, ep_ring->dequeue,
1320 td->last_trb, event_dma);
1321 xhci_dbg(xhci, "%s - found event_seg = %p\n", __func__, event_seg);
1322 if (!event_seg) {
1323 /* HC is busted, give up! */
1324 xhci_err(xhci, "ERROR Transfer event TRB DMA ptr not part of current TD\n");
1325 return -ESHUTDOWN;
1326 }
1327 event_trb = &event_seg->trbs[(event_dma - event_seg->dma) / sizeof(*event_trb)];
1328 xhci_dbg(xhci, "Event TRB with TRB type ID %u\n",
1329 (unsigned int) (event->flags & TRB_TYPE_BITMASK)>>10);
1330 xhci_dbg(xhci, "Offset 0x00 (buffer lo) = 0x%x\n",
1331 lower_32_bits(event->buffer));
1332 xhci_dbg(xhci, "Offset 0x04 (buffer hi) = 0x%x\n",
1333 upper_32_bits(event->buffer));
1334 xhci_dbg(xhci, "Offset 0x08 (transfer length) = 0x%x\n",
1335 (unsigned int) event->transfer_len);
1336 xhci_dbg(xhci, "Offset 0x0C (flags) = 0x%x\n",
1337 (unsigned int) event->flags);
1338
1339 /* Look for common error cases */
1340 trb_comp_code = GET_COMP_CODE(event->transfer_len); 1744 trb_comp_code = GET_COMP_CODE(event->transfer_len);
1745 /* Look for common error cases */
1341 switch (trb_comp_code) { 1746 switch (trb_comp_code) {
1342 /* Skip codes that require special handling depending on 1747 /* Skip codes that require special handling depending on
1343 * transfer type 1748 * transfer type
@@ -1373,278 +1778,156 @@ static int handle_tx_event(struct xhci_hcd *xhci,
1373 xhci_warn(xhci, "WARN: HC couldn't access mem fast enough\n"); 1778 xhci_warn(xhci, "WARN: HC couldn't access mem fast enough\n");
1374 status = -ENOSR; 1779 status = -ENOSR;
1375 break; 1780 break;
1781 case COMP_BW_OVER:
1782 xhci_warn(xhci, "WARN: bandwidth overrun event on endpoint\n");
1783 break;
1784 case COMP_BUFF_OVER:
1785 xhci_warn(xhci, "WARN: buffer overrun event on endpoint\n");
1786 break;
1787 case COMP_UNDERRUN:
1788 /*
1789 * When the Isoch ring is empty, the xHC will generate
1790 * a Ring Overrun Event for IN Isoch endpoint or Ring
1791 * Underrun Event for OUT Isoch endpoint.
1792 */
1793 xhci_dbg(xhci, "underrun event on endpoint\n");
1794 if (!list_empty(&ep_ring->td_list))
1795 xhci_dbg(xhci, "Underrun Event for slot %d ep %d "
1796 "still with TDs queued?\n",
1797 TRB_TO_SLOT_ID(event->flags), ep_index);
1798 goto cleanup;
1799 case COMP_OVERRUN:
1800 xhci_dbg(xhci, "overrun event on endpoint\n");
1801 if (!list_empty(&ep_ring->td_list))
1802 xhci_dbg(xhci, "Overrun Event for slot %d ep %d "
1803 "still with TDs queued?\n",
1804 TRB_TO_SLOT_ID(event->flags), ep_index);
1805 goto cleanup;
1806 case COMP_MISSED_INT:
1807 /*
1808 * When encounter missed service error, one or more isoc tds
1809 * may be missed by xHC.
1810 * Set skip flag of the ep_ring; Complete the missed tds as
1811 * short transfer when process the ep_ring next time.
1812 */
1813 ep->skip = true;
1814 xhci_dbg(xhci, "Miss service interval error, set skip flag\n");
1815 goto cleanup;
1376 default: 1816 default:
1377 if (xhci_is_vendor_info_code(xhci, trb_comp_code)) { 1817 if (xhci_is_vendor_info_code(xhci, trb_comp_code)) {
1378 status = 0; 1818 status = 0;
1379 break; 1819 break;
1380 } 1820 }
1381 xhci_warn(xhci, "ERROR Unknown event condition, HC probably busted\n"); 1821 xhci_warn(xhci, "ERROR Unknown event condition, HC probably "
1382 urb = NULL; 1822 "busted\n");
1383 goto cleanup; 1823 goto cleanup;
1384 } 1824 }
1385 /* Now update the urb's actual_length and give back to the core */
1386 /* Was this a control transfer? */
1387 if (usb_endpoint_xfer_control(&td->urb->ep->desc)) {
1388 xhci_debug_trb(xhci, xhci->event_ring->dequeue);
1389 switch (trb_comp_code) {
1390 case COMP_SUCCESS:
1391 if (event_trb == ep_ring->dequeue) {
1392 xhci_warn(xhci, "WARN: Success on ctrl setup TRB without IOC set??\n");
1393 status = -ESHUTDOWN;
1394 } else if (event_trb != td->last_trb) {
1395 xhci_warn(xhci, "WARN: Success on ctrl data TRB without IOC set??\n");
1396 status = -ESHUTDOWN;
1397 } else {
1398 xhci_dbg(xhci, "Successful control transfer!\n");
1399 status = 0;
1400 }
1401 break;
1402 case COMP_SHORT_TX:
1403 xhci_warn(xhci, "WARN: short transfer on control ep\n");
1404 if (td->urb->transfer_flags & URB_SHORT_NOT_OK)
1405 status = -EREMOTEIO;
1406 else
1407 status = 0;
1408 break;
1409 1825
1410 default: 1826 do {
1411 if (!xhci_requires_manual_halt_cleanup(xhci, 1827 /* This TRB should be in the TD at the head of this ring's
1412 ep_ctx, trb_comp_code)) 1828 * TD list.
1413 break;
1414 xhci_dbg(xhci, "TRB error code %u, "
1415 "halted endpoint index = %u\n",
1416 trb_comp_code, ep_index);
1417 /* else fall through */
1418 case COMP_STALL:
1419 /* Did we transfer part of the data (middle) phase? */
1420 if (event_trb != ep_ring->dequeue &&
1421 event_trb != td->last_trb)
1422 td->urb->actual_length =
1423 td->urb->transfer_buffer_length
1424 - TRB_LEN(event->transfer_len);
1425 else
1426 td->urb->actual_length = 0;
1427
1428 xhci_cleanup_halted_endpoint(xhci,
1429 slot_id, ep_index, 0, td, event_trb);
1430 goto td_cleanup;
1431 }
1432 /*
1433 * Did we transfer any data, despite the errors that might have
1434 * happened? I.e. did we get past the setup stage?
1435 */ 1829 */
1436 if (event_trb != ep_ring->dequeue) { 1830 if (list_empty(&ep_ring->td_list)) {
1437 /* The event was for the status stage */ 1831 xhci_warn(xhci, "WARN Event TRB for slot %d ep %d "
1438 if (event_trb == td->last_trb) { 1832 "with no TDs queued?\n",
1439 if (td->urb->actual_length != 0) { 1833 TRB_TO_SLOT_ID(event->flags), ep_index);
1440 /* Don't overwrite a previously set error code */ 1834 xhci_dbg(xhci, "Event TRB with TRB type ID %u\n",
1441 if ((status == -EINPROGRESS || 1835 (unsigned int) (event->flags & TRB_TYPE_BITMASK)>>10);
1442 status == 0) && 1836 xhci_print_trb_offsets(xhci, (union xhci_trb *) event);
1443 (td->urb->transfer_flags 1837 if (ep->skip) {
1444 & URB_SHORT_NOT_OK)) 1838 ep->skip = false;
1445 /* Did we already see a short data stage? */ 1839 xhci_dbg(xhci, "td_list is empty while skip "
1446 status = -EREMOTEIO; 1840 "flag set. Clear skip flag.\n");
1447 } else {
1448 td->urb->actual_length =
1449 td->urb->transfer_buffer_length;
1450 }
1451 } else {
1452 /* Maybe the event was for the data stage? */
1453 if (trb_comp_code != COMP_STOP_INVAL) {
1454 /* We didn't stop on a link TRB in the middle */
1455 td->urb->actual_length =
1456 td->urb->transfer_buffer_length -
1457 TRB_LEN(event->transfer_len);
1458 xhci_dbg(xhci, "Waiting for status stage event\n");
1459 urb = NULL;
1460 goto cleanup;
1461 }
1462 } 1841 }
1842 ret = 0;
1843 goto cleanup;
1463 } 1844 }
1464 } else { 1845
1465 switch (trb_comp_code) { 1846 td = list_entry(ep_ring->td_list.next, struct xhci_td, td_list);
1466 case COMP_SUCCESS: 1847 /* Is this a TRB in the currently executing TD? */
1467 /* Double check that the HW transferred everything. */ 1848 event_seg = trb_in_td(ep_ring->deq_seg, ep_ring->dequeue,
1468 if (event_trb != td->last_trb) { 1849 td->last_trb, event_dma);
1469 xhci_warn(xhci, "WARN Successful completion " 1850 if (event_seg && ep->skip) {
1470 "on short TX\n"); 1851 xhci_dbg(xhci, "Found td. Clear skip flag.\n");
1471 if (td->urb->transfer_flags & URB_SHORT_NOT_OK) 1852 ep->skip = false;
1472 status = -EREMOTEIO; 1853 }
1473 else 1854 if (!event_seg &&
1474 status = 0; 1855 (!ep->skip || !usb_endpoint_xfer_isoc(&td->urb->ep->desc))) {
1475 } else { 1856 /* HC is busted, give up! */
1476 if (usb_endpoint_xfer_bulk(&td->urb->ep->desc)) 1857 xhci_err(xhci, "ERROR Transfer event TRB DMA ptr not "
1477 xhci_dbg(xhci, "Successful bulk " 1858 "part of current TD\n");
1478 "transfer!\n"); 1859 return -ESHUTDOWN;
1479 else
1480 xhci_dbg(xhci, "Successful interrupt "
1481 "transfer!\n");
1482 status = 0;
1483 }
1484 break;
1485 case COMP_SHORT_TX:
1486 if (td->urb->transfer_flags & URB_SHORT_NOT_OK)
1487 status = -EREMOTEIO;
1488 else
1489 status = 0;
1490 break;
1491 default:
1492 /* Others already handled above */
1493 break;
1494 } 1860 }
1495 dev_dbg(&td->urb->dev->dev,
1496 "ep %#x - asked for %d bytes, "
1497 "%d bytes untransferred\n",
1498 td->urb->ep->desc.bEndpointAddress,
1499 td->urb->transfer_buffer_length,
1500 TRB_LEN(event->transfer_len));
1501 /* Fast path - was this the last TRB in the TD for this URB? */
1502 if (event_trb == td->last_trb) {
1503 if (TRB_LEN(event->transfer_len) != 0) {
1504 td->urb->actual_length =
1505 td->urb->transfer_buffer_length -
1506 TRB_LEN(event->transfer_len);
1507 if (td->urb->transfer_buffer_length <
1508 td->urb->actual_length) {
1509 xhci_warn(xhci, "HC gave bad length "
1510 "of %d bytes left\n",
1511 TRB_LEN(event->transfer_len));
1512 td->urb->actual_length = 0;
1513 if (td->urb->transfer_flags &
1514 URB_SHORT_NOT_OK)
1515 status = -EREMOTEIO;
1516 else
1517 status = 0;
1518 }
1519 /* Don't overwrite a previously set error code */
1520 if (status == -EINPROGRESS) {
1521 if (td->urb->transfer_flags & URB_SHORT_NOT_OK)
1522 status = -EREMOTEIO;
1523 else
1524 status = 0;
1525 }
1526 } else {
1527 td->urb->actual_length = td->urb->transfer_buffer_length;
1528 /* Ignore a short packet completion if the
1529 * untransferred length was zero.
1530 */
1531 if (status == -EREMOTEIO)
1532 status = 0;
1533 }
1534 } else {
1535 /* Slow path - walk the list, starting from the dequeue
1536 * pointer, to get the actual length transferred.
1537 */
1538 union xhci_trb *cur_trb;
1539 struct xhci_segment *cur_seg;
1540 1861
1541 td->urb->actual_length = 0; 1862 if (event_seg) {
1542 for (cur_trb = ep_ring->dequeue, cur_seg = ep_ring->deq_seg; 1863 event_trb = &event_seg->trbs[(event_dma -
1543 cur_trb != event_trb; 1864 event_seg->dma) / sizeof(*event_trb)];
1544 next_trb(xhci, ep_ring, &cur_seg, &cur_trb)) { 1865 /*
1545 if ((cur_trb->generic.field[3] & 1866 * No-op TRB should not trigger interrupts.
1546 TRB_TYPE_BITMASK) != TRB_TYPE(TRB_TR_NOOP) && 1867 * If event_trb is a no-op TRB, it means the
1547 (cur_trb->generic.field[3] & 1868 * corresponding TD has been cancelled. Just ignore
1548 TRB_TYPE_BITMASK) != TRB_TYPE(TRB_LINK)) 1869 * the TD.
1549 td->urb->actual_length +=
1550 TRB_LEN(cur_trb->generic.field[2]);
1551 }
1552 /* If the ring didn't stop on a Link or No-op TRB, add
1553 * in the actual bytes transferred from the Normal TRB
1554 */ 1870 */
1555 if (trb_comp_code != COMP_STOP_INVAL) 1871 if ((event_trb->generic.field[3] & TRB_TYPE_BITMASK)
1556 td->urb->actual_length += 1872 == TRB_TYPE(TRB_TR_NOOP)) {
1557 TRB_LEN(cur_trb->generic.field[2]) - 1873 xhci_dbg(xhci, "event_trb is a no-op TRB. "
1558 TRB_LEN(event->transfer_len); 1874 "Skip it\n");
1875 goto cleanup;
1876 }
1559 } 1877 }
1560 } 1878
1561 if (trb_comp_code == COMP_STOP_INVAL || 1879 /* Now update the urb's actual_length and give back to
1562 trb_comp_code == COMP_STOP) { 1880 * the core
1563 /* The Endpoint Stop Command completion will take care of any
1564 * stopped TDs. A stopped TD may be restarted, so don't update
1565 * the ring dequeue pointer or take this TD off any lists yet.
1566 */ 1881 */
1567 ep->stopped_td = td; 1882 if (usb_endpoint_xfer_control(&td->urb->ep->desc))
1568 ep->stopped_trb = event_trb; 1883 ret = process_ctrl_td(xhci, td, event_trb, event, ep,
1569 } else { 1884 &status);
1570 if (trb_comp_code == COMP_STALL) { 1885 else if (usb_endpoint_xfer_isoc(&td->urb->ep->desc))
1571 /* The transfer is completed from the driver's 1886 ret = process_isoc_td(xhci, td, event_trb, event, ep,
1572 * perspective, but we need to issue a set dequeue 1887 &status);
1573 * command for this stalled endpoint to move the dequeue 1888 else
1574 * pointer past the TD. We can't do that here because 1889 ret = process_bulk_intr_td(xhci, td, event_trb, event,
1575 * the halt condition must be cleared first. Let the 1890 ep, &status);
1576 * USB class driver clear the stall later.
1577 */
1578 ep->stopped_td = td;
1579 ep->stopped_trb = event_trb;
1580 ep->stopped_stream = ep_ring->stream_id;
1581 } else if (xhci_requires_manual_halt_cleanup(xhci,
1582 ep_ctx, trb_comp_code)) {
1583 /* Other types of errors halt the endpoint, but the
1584 * class driver doesn't call usb_reset_endpoint() unless
1585 * the error is -EPIPE. Clear the halted status in the
1586 * xHCI hardware manually.
1587 */
1588 xhci_cleanup_halted_endpoint(xhci,
1589 slot_id, ep_index, ep_ring->stream_id, td, event_trb);
1590 } else {
1591 /* Update ring dequeue pointer */
1592 while (ep_ring->dequeue != td->last_trb)
1593 inc_deq(xhci, ep_ring, false);
1594 inc_deq(xhci, ep_ring, false);
1595 }
1596 1891
1597td_cleanup: 1892cleanup:
1598 /* Clean up the endpoint's TD list */ 1893 /*
1599 urb = td->urb; 1894 * Do not update event ring dequeue pointer if ep->skip is set.
1600 /* Do one last check of the actual transfer length. 1895 * Will roll back to continue process missed tds.
1601 * If the host controller said we transferred more data than
1602 * the buffer length, urb->actual_length will be a very big
1603 * number (since it's unsigned). Play it safe and say we didn't
1604 * transfer anything.
1605 */ 1896 */
1606 if (urb->actual_length > urb->transfer_buffer_length) { 1897 if (trb_comp_code == COMP_MISSED_INT || !ep->skip) {
1607 xhci_warn(xhci, "URB transfer length is wrong, " 1898 inc_deq(xhci, xhci->event_ring, true);
1608 "xHC issue? req. len = %u, "
1609 "act. len = %u\n",
1610 urb->transfer_buffer_length,
1611 urb->actual_length);
1612 urb->actual_length = 0;
1613 if (td->urb->transfer_flags & URB_SHORT_NOT_OK)
1614 status = -EREMOTEIO;
1615 else
1616 status = 0;
1617 } 1899 }
1618 list_del(&td->td_list);
1619 /* Was this TD slated to be cancelled but completed anyway? */
1620 if (!list_empty(&td->cancelled_td_list))
1621 list_del(&td->cancelled_td_list);
1622 1900
1623 /* Leave the TD around for the reset endpoint function to use 1901 if (ret) {
1624 * (but only if it's not a control endpoint, since we already 1902 urb = td->urb;
1625 * queued the Set TR dequeue pointer command for stalled 1903 urb_priv = urb->hcpriv;
1626 * control endpoints). 1904 /* Leave the TD around for the reset endpoint function
1627 */ 1905 * to use(but only if it's not a control endpoint,
1628 if (usb_endpoint_xfer_control(&urb->ep->desc) || 1906 * since we already queued the Set TR dequeue pointer
1629 (trb_comp_code != COMP_STALL && 1907 * command for stalled control endpoints).
1630 trb_comp_code != COMP_BABBLE)) { 1908 */
1631 kfree(td); 1909 if (usb_endpoint_xfer_control(&urb->ep->desc) ||
1910 (trb_comp_code != COMP_STALL &&
1911 trb_comp_code != COMP_BABBLE))
1912 xhci_urb_free_priv(xhci, urb_priv);
1913
1914 usb_hcd_unlink_urb_from_ep(xhci_to_hcd(xhci), urb);
1915 xhci_dbg(xhci, "Giveback URB %p, len = %d, "
1916 "status = %d\n",
1917 urb, urb->actual_length, status);
1918 spin_unlock(&xhci->lock);
1919 usb_hcd_giveback_urb(xhci_to_hcd(xhci), urb, status);
1920 spin_lock(&xhci->lock);
1632 } 1921 }
1633 urb->hcpriv = NULL;
1634 }
1635cleanup:
1636 inc_deq(xhci, xhci->event_ring, true);
1637 xhci_set_hc_event_deq(xhci);
1638 1922
1639 /* FIXME for multi-TD URBs (who have buffers bigger than 64MB) */ 1923 /*
1640 if (urb) { 1924 * If ep->skip is set, it means there are missed tds on the
1641 usb_hcd_unlink_urb_from_ep(xhci_to_hcd(xhci), urb); 1925 * endpoint ring need to take care of.
1642 xhci_dbg(xhci, "Giveback URB %p, len = %d, status = %d\n", 1926 * Process them as short transfer until reach the td pointed by
1643 urb, urb->actual_length, status); 1927 * the event.
1644 spin_unlock(&xhci->lock); 1928 */
1645 usb_hcd_giveback_urb(xhci_to_hcd(xhci), urb, status); 1929 } while (ep->skip && trb_comp_code != COMP_MISSED_INT);
1646 spin_lock(&xhci->lock); 1930
1647 }
1648 return 0; 1931 return 0;
1649} 1932}
1650 1933
@@ -1652,7 +1935,7 @@ cleanup:
1652 * This function handles all OS-owned events on the event ring. It may drop 1935 * This function handles all OS-owned events on the event ring. It may drop
1653 * xhci->lock between event processing (e.g. to pass up port status changes). 1936 * xhci->lock between event processing (e.g. to pass up port status changes).
1654 */ 1937 */
1655void xhci_handle_event(struct xhci_hcd *xhci) 1938static void xhci_handle_event(struct xhci_hcd *xhci)
1656{ 1939{
1657 union xhci_trb *event; 1940 union xhci_trb *event;
1658 int update_ptrs = 1; 1941 int update_ptrs = 1;
@@ -1710,15 +1993,130 @@ void xhci_handle_event(struct xhci_hcd *xhci)
1710 return; 1993 return;
1711 } 1994 }
1712 1995
1713 if (update_ptrs) { 1996 if (update_ptrs)
1714 /* Update SW and HC event ring dequeue pointer */ 1997 /* Update SW event ring dequeue pointer */
1715 inc_deq(xhci, xhci->event_ring, true); 1998 inc_deq(xhci, xhci->event_ring, true);
1716 xhci_set_hc_event_deq(xhci); 1999
1717 }
1718 /* Are there more items on the event ring? */ 2000 /* Are there more items on the event ring? */
1719 xhci_handle_event(xhci); 2001 xhci_handle_event(xhci);
1720} 2002}
1721 2003
2004/*
2005 * xHCI spec says we can get an interrupt, and if the HC has an error condition,
2006 * we might get bad data out of the event ring. Section 4.10.2.7 has a list of
2007 * indicators of an event TRB error, but we check the status *first* to be safe.
2008 */
2009irqreturn_t xhci_irq(struct usb_hcd *hcd)
2010{
2011 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
2012 u32 status;
2013 union xhci_trb *trb;
2014 u64 temp_64;
2015 union xhci_trb *event_ring_deq;
2016 dma_addr_t deq;
2017
2018 spin_lock(&xhci->lock);
2019 trb = xhci->event_ring->dequeue;
2020 /* Check if the xHC generated the interrupt, or the irq is shared */
2021 status = xhci_readl(xhci, &xhci->op_regs->status);
2022 if (status == 0xffffffff)
2023 goto hw_died;
2024
2025 if (!(status & STS_EINT)) {
2026 spin_unlock(&xhci->lock);
2027 xhci_warn(xhci, "Spurious interrupt.\n");
2028 return IRQ_NONE;
2029 }
2030 xhci_dbg(xhci, "op reg status = %08x\n", status);
2031 xhci_dbg(xhci, "Event ring dequeue ptr:\n");
2032 xhci_dbg(xhci, "@%llx %08x %08x %08x %08x\n",
2033 (unsigned long long)
2034 xhci_trb_virt_to_dma(xhci->event_ring->deq_seg, trb),
2035 lower_32_bits(trb->link.segment_ptr),
2036 upper_32_bits(trb->link.segment_ptr),
2037 (unsigned int) trb->link.intr_target,
2038 (unsigned int) trb->link.control);
2039
2040 if (status & STS_FATAL) {
2041 xhci_warn(xhci, "WARNING: Host System Error\n");
2042 xhci_halt(xhci);
2043hw_died:
2044 xhci_to_hcd(xhci)->state = HC_STATE_HALT;
2045 spin_unlock(&xhci->lock);
2046 return -ESHUTDOWN;
2047 }
2048
2049 /*
2050 * Clear the op reg interrupt status first,
2051 * so we can receive interrupts from other MSI-X interrupters.
2052 * Write 1 to clear the interrupt status.
2053 */
2054 status |= STS_EINT;
2055 xhci_writel(xhci, status, &xhci->op_regs->status);
2056 /* FIXME when MSI-X is supported and there are multiple vectors */
2057 /* Clear the MSI-X event interrupt status */
2058
2059 if (hcd->irq != -1) {
2060 u32 irq_pending;
2061 /* Acknowledge the PCI interrupt */
2062 irq_pending = xhci_readl(xhci, &xhci->ir_set->irq_pending);
2063 irq_pending |= 0x3;
2064 xhci_writel(xhci, irq_pending, &xhci->ir_set->irq_pending);
2065 }
2066
2067 if (xhci->xhc_state & XHCI_STATE_DYING) {
2068 xhci_dbg(xhci, "xHCI dying, ignoring interrupt. "
2069 "Shouldn't IRQs be disabled?\n");
2070 /* Clear the event handler busy flag (RW1C);
2071 * the event ring should be empty.
2072 */
2073 temp_64 = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue);
2074 xhci_write_64(xhci, temp_64 | ERST_EHB,
2075 &xhci->ir_set->erst_dequeue);
2076 spin_unlock(&xhci->lock);
2077
2078 return IRQ_HANDLED;
2079 }
2080
2081 event_ring_deq = xhci->event_ring->dequeue;
2082 /* FIXME this should be a delayed service routine
2083 * that clears the EHB.
2084 */
2085 xhci_handle_event(xhci);
2086
2087 temp_64 = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue);
2088 /* If necessary, update the HW's version of the event ring deq ptr. */
2089 if (event_ring_deq != xhci->event_ring->dequeue) {
2090 deq = xhci_trb_virt_to_dma(xhci->event_ring->deq_seg,
2091 xhci->event_ring->dequeue);
2092 if (deq == 0)
2093 xhci_warn(xhci, "WARN something wrong with SW event "
2094 "ring dequeue ptr.\n");
2095 /* Update HC event ring dequeue pointer */
2096 temp_64 &= ERST_PTR_MASK;
2097 temp_64 |= ((u64) deq & (u64) ~ERST_PTR_MASK);
2098 }
2099
2100 /* Clear the event handler busy flag (RW1C); event ring is empty. */
2101 temp_64 |= ERST_EHB;
2102 xhci_write_64(xhci, temp_64, &xhci->ir_set->erst_dequeue);
2103
2104 spin_unlock(&xhci->lock);
2105
2106 return IRQ_HANDLED;
2107}
2108
2109irqreturn_t xhci_msi_irq(int irq, struct usb_hcd *hcd)
2110{
2111 irqreturn_t ret;
2112
2113 set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags);
2114
2115 ret = xhci_irq(hcd);
2116
2117 return ret;
2118}
2119
1722/**** Endpoint Ring Operations ****/ 2120/**** Endpoint Ring Operations ****/
1723 2121
1724/* 2122/*
@@ -1827,10 +2225,12 @@ static int prepare_transfer(struct xhci_hcd *xhci,
1827 unsigned int stream_id, 2225 unsigned int stream_id,
1828 unsigned int num_trbs, 2226 unsigned int num_trbs,
1829 struct urb *urb, 2227 struct urb *urb,
1830 struct xhci_td **td, 2228 unsigned int td_index,
1831 gfp_t mem_flags) 2229 gfp_t mem_flags)
1832{ 2230{
1833 int ret; 2231 int ret;
2232 struct urb_priv *urb_priv;
2233 struct xhci_td *td;
1834 struct xhci_ring *ep_ring; 2234 struct xhci_ring *ep_ring;
1835 struct xhci_ep_ctx *ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index); 2235 struct xhci_ep_ctx *ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index);
1836 2236
@@ -1846,24 +2246,29 @@ static int prepare_transfer(struct xhci_hcd *xhci,
1846 num_trbs, mem_flags); 2246 num_trbs, mem_flags);
1847 if (ret) 2247 if (ret)
1848 return ret; 2248 return ret;
1849 *td = kzalloc(sizeof(struct xhci_td), mem_flags);
1850 if (!*td)
1851 return -ENOMEM;
1852 INIT_LIST_HEAD(&(*td)->td_list);
1853 INIT_LIST_HEAD(&(*td)->cancelled_td_list);
1854 2249
1855 ret = usb_hcd_link_urb_to_ep(xhci_to_hcd(xhci), urb); 2250 urb_priv = urb->hcpriv;
1856 if (unlikely(ret)) { 2251 td = urb_priv->td[td_index];
1857 kfree(*td); 2252
1858 return ret; 2253 INIT_LIST_HEAD(&td->td_list);
2254 INIT_LIST_HEAD(&td->cancelled_td_list);
2255
2256 if (td_index == 0) {
2257 ret = usb_hcd_link_urb_to_ep(xhci_to_hcd(xhci), urb);
2258 if (unlikely(ret)) {
2259 xhci_urb_free_priv(xhci, urb_priv);
2260 urb->hcpriv = NULL;
2261 return ret;
2262 }
1859 } 2263 }
1860 2264
1861 (*td)->urb = urb; 2265 td->urb = urb;
1862 urb->hcpriv = (void *) (*td);
1863 /* Add this TD to the tail of the endpoint ring's TD list */ 2266 /* Add this TD to the tail of the endpoint ring's TD list */
1864 list_add_tail(&(*td)->td_list, &ep_ring->td_list); 2267 list_add_tail(&td->td_list, &ep_ring->td_list);
1865 (*td)->start_seg = ep_ring->enq_seg; 2268 td->start_seg = ep_ring->enq_seg;
1866 (*td)->first_trb = ep_ring->enqueue; 2269 td->first_trb = ep_ring->enqueue;
2270
2271 urb_priv->td[td_index] = td;
1867 2272
1868 return 0; 2273 return 0;
1869} 2274}
@@ -2002,6 +2407,7 @@ static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2002{ 2407{
2003 struct xhci_ring *ep_ring; 2408 struct xhci_ring *ep_ring;
2004 unsigned int num_trbs; 2409 unsigned int num_trbs;
2410 struct urb_priv *urb_priv;
2005 struct xhci_td *td; 2411 struct xhci_td *td;
2006 struct scatterlist *sg; 2412 struct scatterlist *sg;
2007 int num_sgs; 2413 int num_sgs;
@@ -2022,9 +2428,13 @@ static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2022 2428
2023 trb_buff_len = prepare_transfer(xhci, xhci->devs[slot_id], 2429 trb_buff_len = prepare_transfer(xhci, xhci->devs[slot_id],
2024 ep_index, urb->stream_id, 2430 ep_index, urb->stream_id,
2025 num_trbs, urb, &td, mem_flags); 2431 num_trbs, urb, 0, mem_flags);
2026 if (trb_buff_len < 0) 2432 if (trb_buff_len < 0)
2027 return trb_buff_len; 2433 return trb_buff_len;
2434
2435 urb_priv = urb->hcpriv;
2436 td = urb_priv->td[0];
2437
2028 /* 2438 /*
2029 * Don't give the first TRB to the hardware (by toggling the cycle bit) 2439 * Don't give the first TRB to the hardware (by toggling the cycle bit)
2030 * until we've finished creating all the other TRBs. The ring's cycle 2440 * until we've finished creating all the other TRBs. The ring's cycle
@@ -2145,6 +2555,7 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2145 struct urb *urb, int slot_id, unsigned int ep_index) 2555 struct urb *urb, int slot_id, unsigned int ep_index)
2146{ 2556{
2147 struct xhci_ring *ep_ring; 2557 struct xhci_ring *ep_ring;
2558 struct urb_priv *urb_priv;
2148 struct xhci_td *td; 2559 struct xhci_td *td;
2149 int num_trbs; 2560 int num_trbs;
2150 struct xhci_generic_trb *start_trb; 2561 struct xhci_generic_trb *start_trb;
@@ -2190,10 +2601,13 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2190 2601
2191 ret = prepare_transfer(xhci, xhci->devs[slot_id], 2602 ret = prepare_transfer(xhci, xhci->devs[slot_id],
2192 ep_index, urb->stream_id, 2603 ep_index, urb->stream_id,
2193 num_trbs, urb, &td, mem_flags); 2604 num_trbs, urb, 0, mem_flags);
2194 if (ret < 0) 2605 if (ret < 0)
2195 return ret; 2606 return ret;
2196 2607
2608 urb_priv = urb->hcpriv;
2609 td = urb_priv->td[0];
2610
2197 /* 2611 /*
2198 * Don't give the first TRB to the hardware (by toggling the cycle bit) 2612 * Don't give the first TRB to the hardware (by toggling the cycle bit)
2199 * until we've finished creating all the other TRBs. The ring's cycle 2613 * until we've finished creating all the other TRBs. The ring's cycle
@@ -2279,6 +2693,7 @@ int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2279 struct xhci_generic_trb *start_trb; 2693 struct xhci_generic_trb *start_trb;
2280 int start_cycle; 2694 int start_cycle;
2281 u32 field, length_field; 2695 u32 field, length_field;
2696 struct urb_priv *urb_priv;
2282 struct xhci_td *td; 2697 struct xhci_td *td;
2283 2698
2284 ep_ring = xhci_urb_to_transfer_ring(xhci, urb); 2699 ep_ring = xhci_urb_to_transfer_ring(xhci, urb);
@@ -2306,10 +2721,13 @@ int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2306 num_trbs++; 2721 num_trbs++;
2307 ret = prepare_transfer(xhci, xhci->devs[slot_id], 2722 ret = prepare_transfer(xhci, xhci->devs[slot_id],
2308 ep_index, urb->stream_id, 2723 ep_index, urb->stream_id,
2309 num_trbs, urb, &td, mem_flags); 2724 num_trbs, urb, 0, mem_flags);
2310 if (ret < 0) 2725 if (ret < 0)
2311 return ret; 2726 return ret;
2312 2727
2728 urb_priv = urb->hcpriv;
2729 td = urb_priv->td[0];
2730
2313 /* 2731 /*
2314 * Don't give the first TRB to the hardware (by toggling the cycle bit) 2732 * Don't give the first TRB to the hardware (by toggling the cycle bit)
2315 * until we've finished creating all the other TRBs. The ring's cycle 2733 * until we've finished creating all the other TRBs. The ring's cycle
@@ -2366,6 +2784,224 @@ int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2366 return 0; 2784 return 0;
2367} 2785}
2368 2786
2787static int count_isoc_trbs_needed(struct xhci_hcd *xhci,
2788 struct urb *urb, int i)
2789{
2790 int num_trbs = 0;
2791 u64 addr, td_len, running_total;
2792
2793 addr = (u64) (urb->transfer_dma + urb->iso_frame_desc[i].offset);
2794 td_len = urb->iso_frame_desc[i].length;
2795
2796 running_total = TRB_MAX_BUFF_SIZE -
2797 (addr & ((1 << TRB_MAX_BUFF_SHIFT) - 1));
2798 if (running_total != 0)
2799 num_trbs++;
2800
2801 while (running_total < td_len) {
2802 num_trbs++;
2803 running_total += TRB_MAX_BUFF_SIZE;
2804 }
2805
2806 return num_trbs;
2807}
2808
2809/* This is for isoc transfer */
2810static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2811 struct urb *urb, int slot_id, unsigned int ep_index)
2812{
2813 struct xhci_ring *ep_ring;
2814 struct urb_priv *urb_priv;
2815 struct xhci_td *td;
2816 int num_tds, trbs_per_td;
2817 struct xhci_generic_trb *start_trb;
2818 bool first_trb;
2819 int start_cycle;
2820 u32 field, length_field;
2821 int running_total, trb_buff_len, td_len, td_remain_len, ret;
2822 u64 start_addr, addr;
2823 int i, j;
2824
2825 ep_ring = xhci->devs[slot_id]->eps[ep_index].ring;
2826
2827 num_tds = urb->number_of_packets;
2828 if (num_tds < 1) {
2829 xhci_dbg(xhci, "Isoc URB with zero packets?\n");
2830 return -EINVAL;
2831 }
2832
2833 if (!in_interrupt())
2834 dev_dbg(&urb->dev->dev, "ep %#x - urb len = %#x (%d),"
2835 " addr = %#llx, num_tds = %d\n",
2836 urb->ep->desc.bEndpointAddress,
2837 urb->transfer_buffer_length,
2838 urb->transfer_buffer_length,
2839 (unsigned long long)urb->transfer_dma,
2840 num_tds);
2841
2842 start_addr = (u64) urb->transfer_dma;
2843 start_trb = &ep_ring->enqueue->generic;
2844 start_cycle = ep_ring->cycle_state;
2845
2846 /* Queue the first TRB, even if it's zero-length */
2847 for (i = 0; i < num_tds; i++) {
2848 first_trb = true;
2849
2850 running_total = 0;
2851 addr = start_addr + urb->iso_frame_desc[i].offset;
2852 td_len = urb->iso_frame_desc[i].length;
2853 td_remain_len = td_len;
2854
2855 trbs_per_td = count_isoc_trbs_needed(xhci, urb, i);
2856
2857 ret = prepare_transfer(xhci, xhci->devs[slot_id], ep_index,
2858 urb->stream_id, trbs_per_td, urb, i, mem_flags);
2859 if (ret < 0)
2860 return ret;
2861
2862 urb_priv = urb->hcpriv;
2863 td = urb_priv->td[i];
2864
2865 for (j = 0; j < trbs_per_td; j++) {
2866 u32 remainder = 0;
2867 field = 0;
2868
2869 if (first_trb) {
2870 /* Queue the isoc TRB */
2871 field |= TRB_TYPE(TRB_ISOC);
2872 /* Assume URB_ISO_ASAP is set */
2873 field |= TRB_SIA;
2874 if (i > 0)
2875 field |= ep_ring->cycle_state;
2876 first_trb = false;
2877 } else {
2878 /* Queue other normal TRBs */
2879 field |= TRB_TYPE(TRB_NORMAL);
2880 field |= ep_ring->cycle_state;
2881 }
2882
2883 /* Chain all the TRBs together; clear the chain bit in
2884 * the last TRB to indicate it's the last TRB in the
2885 * chain.
2886 */
2887 if (j < trbs_per_td - 1) {
2888 field |= TRB_CHAIN;
2889 } else {
2890 td->last_trb = ep_ring->enqueue;
2891 field |= TRB_IOC;
2892 }
2893
2894 /* Calculate TRB length */
2895 trb_buff_len = TRB_MAX_BUFF_SIZE -
2896 (addr & ((1 << TRB_MAX_BUFF_SHIFT) - 1));
2897 if (trb_buff_len > td_remain_len)
2898 trb_buff_len = td_remain_len;
2899
2900 remainder = xhci_td_remainder(td_len - running_total);
2901 length_field = TRB_LEN(trb_buff_len) |
2902 remainder |
2903 TRB_INTR_TARGET(0);
2904 queue_trb(xhci, ep_ring, false, false,
2905 lower_32_bits(addr),
2906 upper_32_bits(addr),
2907 length_field,
2908 /* We always want to know if the TRB was short,
2909 * or we won't get an event when it completes.
2910 * (Unless we use event data TRBs, which are a
2911 * waste of space and HC resources.)
2912 */
2913 field | TRB_ISP);
2914 running_total += trb_buff_len;
2915
2916 addr += trb_buff_len;
2917 td_remain_len -= trb_buff_len;
2918 }
2919
2920 /* Check TD length */
2921 if (running_total != td_len) {
2922 xhci_err(xhci, "ISOC TD length unmatch\n");
2923 return -EINVAL;
2924 }
2925 }
2926
2927 wmb();
2928 start_trb->field[3] |= start_cycle;
2929
2930 ring_ep_doorbell(xhci, slot_id, ep_index, urb->stream_id);
2931 return 0;
2932}
2933
2934/*
2935 * Check transfer ring to guarantee there is enough room for the urb.
2936 * Update ISO URB start_frame and interval.
2937 * Update interval as xhci_queue_intr_tx does. Just use xhci frame_index to
2938 * update the urb->start_frame by now.
2939 * Always assume URB_ISO_ASAP set, and NEVER use urb->start_frame as input.
2940 */
2941int xhci_queue_isoc_tx_prepare(struct xhci_hcd *xhci, gfp_t mem_flags,
2942 struct urb *urb, int slot_id, unsigned int ep_index)
2943{
2944 struct xhci_virt_device *xdev;
2945 struct xhci_ring *ep_ring;
2946 struct xhci_ep_ctx *ep_ctx;
2947 int start_frame;
2948 int xhci_interval;
2949 int ep_interval;
2950 int num_tds, num_trbs, i;
2951 int ret;
2952
2953 xdev = xhci->devs[slot_id];
2954 ep_ring = xdev->eps[ep_index].ring;
2955 ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index);
2956
2957 num_trbs = 0;
2958 num_tds = urb->number_of_packets;
2959 for (i = 0; i < num_tds; i++)
2960 num_trbs += count_isoc_trbs_needed(xhci, urb, i);
2961
2962 /* Check the ring to guarantee there is enough room for the whole urb.
2963 * Do not insert any td of the urb to the ring if the check failed.
2964 */
2965 ret = prepare_ring(xhci, ep_ring, ep_ctx->ep_info & EP_STATE_MASK,
2966 num_trbs, mem_flags);
2967 if (ret)
2968 return ret;
2969
2970 start_frame = xhci_readl(xhci, &xhci->run_regs->microframe_index);
2971 start_frame &= 0x3fff;
2972
2973 urb->start_frame = start_frame;
2974 if (urb->dev->speed == USB_SPEED_LOW ||
2975 urb->dev->speed == USB_SPEED_FULL)
2976 urb->start_frame >>= 3;
2977
2978 xhci_interval = EP_INTERVAL_TO_UFRAMES(ep_ctx->ep_info);
2979 ep_interval = urb->interval;
2980 /* Convert to microframes */
2981 if (urb->dev->speed == USB_SPEED_LOW ||
2982 urb->dev->speed == USB_SPEED_FULL)
2983 ep_interval *= 8;
2984 /* FIXME change this to a warning and a suggestion to use the new API
2985 * to set the polling interval (once the API is added).
2986 */
2987 if (xhci_interval != ep_interval) {
2988 if (!printk_ratelimit())
2989 dev_dbg(&urb->dev->dev, "Driver uses different interval"
2990 " (%d microframe%s) than xHCI "
2991 "(%d microframe%s)\n",
2992 ep_interval,
2993 ep_interval == 1 ? "" : "s",
2994 xhci_interval,
2995 xhci_interval == 1 ? "" : "s");
2996 urb->interval = xhci_interval;
2997 /* Convert back to frames for LS/FS devices */
2998 if (urb->dev->speed == USB_SPEED_LOW ||
2999 urb->dev->speed == USB_SPEED_FULL)
3000 urb->interval /= 8;
3001 }
3002 return xhci_queue_isoc_tx(xhci, GFP_ATOMIC, urb, slot_id, ep_index);
3003}
3004
2369/**** Command Ring Operations ****/ 3005/**** Command Ring Operations ****/
2370 3006
2371/* Generic function for queueing a command TRB on the command ring. 3007/* Generic function for queueing a command TRB on the command ring.
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 3998f72cd0c4..d5c550ea3e68 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -20,6 +20,7 @@
20 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */ 21 */
22 22
23#include <linux/pci.h>
23#include <linux/irq.h> 24#include <linux/irq.h>
24#include <linux/log2.h> 25#include <linux/log2.h>
25#include <linux/module.h> 26#include <linux/module.h>
@@ -171,22 +172,84 @@ int xhci_reset(struct xhci_hcd *xhci)
171 return handshake(xhci, &xhci->op_regs->status, STS_CNR, 0, 250 * 1000); 172 return handshake(xhci, &xhci->op_regs->status, STS_CNR, 0, 250 * 1000);
172} 173}
173 174
175/*
176 * Free IRQs
177 * free all IRQs request
178 */
179static void xhci_free_irq(struct xhci_hcd *xhci)
180{
181 int i;
182 struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller);
174 183
175#if 0 184 /* return if using legacy interrupt */
176/* Set up MSI-X table for entry 0 (may claim other entries later) */ 185 if (xhci_to_hcd(xhci)->irq >= 0)
177static int xhci_setup_msix(struct xhci_hcd *xhci) 186 return;
187
188 if (xhci->msix_entries) {
189 for (i = 0; i < xhci->msix_count; i++)
190 if (xhci->msix_entries[i].vector)
191 free_irq(xhci->msix_entries[i].vector,
192 xhci_to_hcd(xhci));
193 } else if (pdev->irq >= 0)
194 free_irq(pdev->irq, xhci_to_hcd(xhci));
195
196 return;
197}
198
199/*
200 * Set up MSI
201 */
202static int xhci_setup_msi(struct xhci_hcd *xhci)
178{ 203{
179 int ret; 204 int ret;
205 struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller);
206
207 ret = pci_enable_msi(pdev);
208 if (ret) {
209 xhci_err(xhci, "failed to allocate MSI entry\n");
210 return ret;
211 }
212
213 ret = request_irq(pdev->irq, (irq_handler_t)xhci_msi_irq,
214 0, "xhci_hcd", xhci_to_hcd(xhci));
215 if (ret) {
216 xhci_err(xhci, "disable MSI interrupt\n");
217 pci_disable_msi(pdev);
218 }
219
220 return ret;
221}
222
223/*
224 * Set up MSI-X
225 */
226static int xhci_setup_msix(struct xhci_hcd *xhci)
227{
228 int i, ret = 0;
180 struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); 229 struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller);
181 230
182 xhci->msix_count = 0; 231 /*
183 /* XXX: did I do this right? ixgbe does kcalloc for more than one */ 232 * calculate number of msi-x vectors supported.
184 xhci->msix_entries = kmalloc(sizeof(struct msix_entry), GFP_KERNEL); 233 * - HCS_MAX_INTRS: the max number of interrupts the host can handle,
234 * with max number of interrupters based on the xhci HCSPARAMS1.
235 * - num_online_cpus: maximum msi-x vectors per CPUs core.
236 * Add additional 1 vector to ensure always available interrupt.
237 */
238 xhci->msix_count = min(num_online_cpus() + 1,
239 HCS_MAX_INTRS(xhci->hcs_params1));
240
241 xhci->msix_entries =
242 kmalloc((sizeof(struct msix_entry))*xhci->msix_count,
243 GFP_KERNEL);
185 if (!xhci->msix_entries) { 244 if (!xhci->msix_entries) {
186 xhci_err(xhci, "Failed to allocate MSI-X entries\n"); 245 xhci_err(xhci, "Failed to allocate MSI-X entries\n");
187 return -ENOMEM; 246 return -ENOMEM;
188 } 247 }
189 xhci->msix_entries[0].entry = 0; 248
249 for (i = 0; i < xhci->msix_count; i++) {
250 xhci->msix_entries[i].entry = i;
251 xhci->msix_entries[i].vector = 0;
252 }
190 253
191 ret = pci_enable_msix(pdev, xhci->msix_entries, xhci->msix_count); 254 ret = pci_enable_msix(pdev, xhci->msix_entries, xhci->msix_count);
192 if (ret) { 255 if (ret) {
@@ -194,20 +257,19 @@ static int xhci_setup_msix(struct xhci_hcd *xhci)
194 goto free_entries; 257 goto free_entries;
195 } 258 }
196 259
197 /* 260 for (i = 0; i < xhci->msix_count; i++) {
198 * Pass the xhci pointer value as the request_irq "cookie". 261 ret = request_irq(xhci->msix_entries[i].vector,
199 * If more irqs are added, this will need to be unique for each one. 262 (irq_handler_t)xhci_msi_irq,
200 */ 263 0, "xhci_hcd", xhci_to_hcd(xhci));
201 ret = request_irq(xhci->msix_entries[0].vector, &xhci_irq, 0, 264 if (ret)
202 "xHCI", xhci_to_hcd(xhci)); 265 goto disable_msix;
203 if (ret) {
204 xhci_err(xhci, "Failed to allocate MSI-X interrupt\n");
205 goto disable_msix;
206 } 266 }
207 xhci_dbg(xhci, "Finished setting up MSI-X\n"); 267
208 return 0; 268 return ret;
209 269
210disable_msix: 270disable_msix:
271 xhci_err(xhci, "disable MSI-X interrupt\n");
272 xhci_free_irq(xhci);
211 pci_disable_msix(pdev); 273 pci_disable_msix(pdev);
212free_entries: 274free_entries:
213 kfree(xhci->msix_entries); 275 kfree(xhci->msix_entries);
@@ -215,21 +277,23 @@ free_entries:
215 return ret; 277 return ret;
216} 278}
217 279
218/* XXX: code duplication; can xhci_setup_msix call this? */
219/* Free any IRQs and disable MSI-X */ 280/* Free any IRQs and disable MSI-X */
220static void xhci_cleanup_msix(struct xhci_hcd *xhci) 281static void xhci_cleanup_msix(struct xhci_hcd *xhci)
221{ 282{
222 struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); 283 struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller);
223 if (!xhci->msix_entries)
224 return;
225 284
226 free_irq(xhci->msix_entries[0].vector, xhci); 285 xhci_free_irq(xhci);
227 pci_disable_msix(pdev); 286
228 kfree(xhci->msix_entries); 287 if (xhci->msix_entries) {
229 xhci->msix_entries = NULL; 288 pci_disable_msix(pdev);
230 xhci_dbg(xhci, "Finished cleaning up MSI-X\n"); 289 kfree(xhci->msix_entries);
290 xhci->msix_entries = NULL;
291 } else {
292 pci_disable_msi(pdev);
293 }
294
295 return;
231} 296}
232#endif
233 297
234/* 298/*
235 * Initialize memory for HCD and xHC (one-time init). 299 * Initialize memory for HCD and xHC (one-time init).
@@ -257,100 +321,8 @@ int xhci_init(struct usb_hcd *hcd)
257 return retval; 321 return retval;
258} 322}
259 323
260/*
261 * Called in interrupt context when there might be work
262 * queued on the event ring
263 *
264 * xhci->lock must be held by caller.
265 */
266static void xhci_work(struct xhci_hcd *xhci)
267{
268 u32 temp;
269 u64 temp_64;
270
271 /*
272 * Clear the op reg interrupt status first,
273 * so we can receive interrupts from other MSI-X interrupters.
274 * Write 1 to clear the interrupt status.
275 */
276 temp = xhci_readl(xhci, &xhci->op_regs->status);
277 temp |= STS_EINT;
278 xhci_writel(xhci, temp, &xhci->op_regs->status);
279 /* FIXME when MSI-X is supported and there are multiple vectors */
280 /* Clear the MSI-X event interrupt status */
281
282 /* Acknowledge the interrupt */
283 temp = xhci_readl(xhci, &xhci->ir_set->irq_pending);
284 temp |= 0x3;
285 xhci_writel(xhci, temp, &xhci->ir_set->irq_pending);
286 /* Flush posted writes */
287 xhci_readl(xhci, &xhci->ir_set->irq_pending);
288
289 if (xhci->xhc_state & XHCI_STATE_DYING)
290 xhci_dbg(xhci, "xHCI dying, ignoring interrupt. "
291 "Shouldn't IRQs be disabled?\n");
292 else
293 /* FIXME this should be a delayed service routine
294 * that clears the EHB.
295 */
296 xhci_handle_event(xhci);
297
298 /* Clear the event handler busy flag (RW1C); the event ring should be empty. */
299 temp_64 = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue);
300 xhci_write_64(xhci, temp_64 | ERST_EHB, &xhci->ir_set->erst_dequeue);
301 /* Flush posted writes -- FIXME is this necessary? */
302 xhci_readl(xhci, &xhci->ir_set->irq_pending);
303}
304
305/*-------------------------------------------------------------------------*/ 324/*-------------------------------------------------------------------------*/
306 325
307/*
308 * xHCI spec says we can get an interrupt, and if the HC has an error condition,
309 * we might get bad data out of the event ring. Section 4.10.2.7 has a list of
310 * indicators of an event TRB error, but we check the status *first* to be safe.
311 */
312irqreturn_t xhci_irq(struct usb_hcd *hcd)
313{
314 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
315 u32 temp, temp2;
316 union xhci_trb *trb;
317
318 spin_lock(&xhci->lock);
319 trb = xhci->event_ring->dequeue;
320 /* Check if the xHC generated the interrupt, or the irq is shared */
321 temp = xhci_readl(xhci, &xhci->op_regs->status);
322 temp2 = xhci_readl(xhci, &xhci->ir_set->irq_pending);
323 if (temp == 0xffffffff && temp2 == 0xffffffff)
324 goto hw_died;
325
326 if (!(temp & STS_EINT) && !ER_IRQ_PENDING(temp2)) {
327 spin_unlock(&xhci->lock);
328 return IRQ_NONE;
329 }
330 xhci_dbg(xhci, "op reg status = %08x\n", temp);
331 xhci_dbg(xhci, "ir set irq_pending = %08x\n", temp2);
332 xhci_dbg(xhci, "Event ring dequeue ptr:\n");
333 xhci_dbg(xhci, "@%llx %08x %08x %08x %08x\n",
334 (unsigned long long)xhci_trb_virt_to_dma(xhci->event_ring->deq_seg, trb),
335 lower_32_bits(trb->link.segment_ptr),
336 upper_32_bits(trb->link.segment_ptr),
337 (unsigned int) trb->link.intr_target,
338 (unsigned int) trb->link.control);
339
340 if (temp & STS_FATAL) {
341 xhci_warn(xhci, "WARNING: Host System Error\n");
342 xhci_halt(xhci);
343hw_died:
344 xhci_to_hcd(xhci)->state = HC_STATE_HALT;
345 spin_unlock(&xhci->lock);
346 return -ESHUTDOWN;
347 }
348
349 xhci_work(xhci);
350 spin_unlock(&xhci->lock);
351
352 return IRQ_HANDLED;
353}
354 326
355#ifdef CONFIG_USB_XHCI_HCD_DEBUGGING 327#ifdef CONFIG_USB_XHCI_HCD_DEBUGGING
356void xhci_event_ring_work(unsigned long arg) 328void xhci_event_ring_work(unsigned long arg)
@@ -423,21 +395,36 @@ int xhci_run(struct usb_hcd *hcd)
423{ 395{
424 u32 temp; 396 u32 temp;
425 u64 temp_64; 397 u64 temp_64;
398 u32 ret;
426 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 399 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
400 struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller);
427 void (*doorbell)(struct xhci_hcd *) = NULL; 401 void (*doorbell)(struct xhci_hcd *) = NULL;
428 402
429 hcd->uses_new_polling = 1; 403 hcd->uses_new_polling = 1;
430 hcd->poll_rh = 0;
431 404
432 xhci_dbg(xhci, "xhci_run\n"); 405 xhci_dbg(xhci, "xhci_run\n");
433#if 0 /* FIXME: MSI not setup yet */ 406 /* unregister the legacy interrupt */
434 /* Do this at the very last minute */ 407 if (hcd->irq)
408 free_irq(hcd->irq, hcd);
409 hcd->irq = -1;
410
435 ret = xhci_setup_msix(xhci); 411 ret = xhci_setup_msix(xhci);
436 if (!ret) 412 if (ret)
437 return ret; 413 /* fall back to msi*/
414 ret = xhci_setup_msi(xhci);
415
416 if (ret) {
417 /* fall back to legacy interrupt*/
418 ret = request_irq(pdev->irq, &usb_hcd_irq, IRQF_SHARED,
419 hcd->irq_descr, hcd);
420 if (ret) {
421 xhci_err(xhci, "request interrupt %d failed\n",
422 pdev->irq);
423 return ret;
424 }
425 hcd->irq = pdev->irq;
426 }
438 427
439 return -ENOSYS;
440#endif
441#ifdef CONFIG_USB_XHCI_HCD_DEBUGGING 428#ifdef CONFIG_USB_XHCI_HCD_DEBUGGING
442 init_timer(&xhci->event_ring_timer); 429 init_timer(&xhci->event_ring_timer);
443 xhci->event_ring_timer.data = (unsigned long) xhci; 430 xhci->event_ring_timer.data = (unsigned long) xhci;
@@ -495,7 +482,6 @@ int xhci_run(struct usb_hcd *hcd)
495 return -ENODEV; 482 return -ENODEV;
496 } 483 }
497 484
498 xhci_dbg(xhci, "// @%p = 0x%x\n", &xhci->op_regs->command, temp);
499 if (doorbell) 485 if (doorbell)
500 (*doorbell)(xhci); 486 (*doorbell)(xhci);
501 if (xhci->quirks & XHCI_NEC_HOST) 487 if (xhci->quirks & XHCI_NEC_HOST)
@@ -522,11 +508,9 @@ void xhci_stop(struct usb_hcd *hcd)
522 spin_lock_irq(&xhci->lock); 508 spin_lock_irq(&xhci->lock);
523 xhci_halt(xhci); 509 xhci_halt(xhci);
524 xhci_reset(xhci); 510 xhci_reset(xhci);
511 xhci_cleanup_msix(xhci);
525 spin_unlock_irq(&xhci->lock); 512 spin_unlock_irq(&xhci->lock);
526 513
527#if 0 /* No MSI yet */
528 xhci_cleanup_msix(xhci);
529#endif
530#ifdef CONFIG_USB_XHCI_HCD_DEBUGGING 514#ifdef CONFIG_USB_XHCI_HCD_DEBUGGING
531 /* Tell the event ring poll function not to reschedule */ 515 /* Tell the event ring poll function not to reschedule */
532 xhci->zombie = 1; 516 xhci->zombie = 1;
@@ -560,11 +544,8 @@ void xhci_shutdown(struct usb_hcd *hcd)
560 544
561 spin_lock_irq(&xhci->lock); 545 spin_lock_irq(&xhci->lock);
562 xhci_halt(xhci); 546 xhci_halt(xhci);
563 spin_unlock_irq(&xhci->lock);
564
565#if 0
566 xhci_cleanup_msix(xhci); 547 xhci_cleanup_msix(xhci);
567#endif 548 spin_unlock_irq(&xhci->lock);
568 549
569 xhci_dbg(xhci, "xhci_shutdown completed - status = %x\n", 550 xhci_dbg(xhci, "xhci_shutdown completed - status = %x\n",
570 xhci_readl(xhci, &xhci->op_regs->status)); 551 xhci_readl(xhci, &xhci->op_regs->status));
@@ -720,7 +701,8 @@ int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags)
720 unsigned long flags; 701 unsigned long flags;
721 int ret = 0; 702 int ret = 0;
722 unsigned int slot_id, ep_index; 703 unsigned int slot_id, ep_index;
723 704 struct urb_priv *urb_priv;
705 int size, i;
724 706
725 if (!urb || xhci_check_args(hcd, urb->dev, urb->ep, true, __func__) <= 0) 707 if (!urb || xhci_check_args(hcd, urb->dev, urb->ep, true, __func__) <= 0)
726 return -EINVAL; 708 return -EINVAL;
@@ -734,12 +716,36 @@ int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags)
734 ret = -EINVAL; 716 ret = -EINVAL;
735 goto exit; 717 goto exit;
736 } 718 }
737 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) { 719 if (!HCD_HW_ACCESSIBLE(hcd)) {
738 if (!in_interrupt()) 720 if (!in_interrupt())
739 xhci_dbg(xhci, "urb submitted during PCI suspend\n"); 721 xhci_dbg(xhci, "urb submitted during PCI suspend\n");
740 ret = -ESHUTDOWN; 722 ret = -ESHUTDOWN;
741 goto exit; 723 goto exit;
742 } 724 }
725
726 if (usb_endpoint_xfer_isoc(&urb->ep->desc))
727 size = urb->number_of_packets;
728 else
729 size = 1;
730
731 urb_priv = kzalloc(sizeof(struct urb_priv) +
732 size * sizeof(struct xhci_td *), mem_flags);
733 if (!urb_priv)
734 return -ENOMEM;
735
736 for (i = 0; i < size; i++) {
737 urb_priv->td[i] = kzalloc(sizeof(struct xhci_td), mem_flags);
738 if (!urb_priv->td[i]) {
739 urb_priv->length = i;
740 xhci_urb_free_priv(xhci, urb_priv);
741 return -ENOMEM;
742 }
743 }
744
745 urb_priv->length = size;
746 urb_priv->td_cnt = 0;
747 urb->hcpriv = urb_priv;
748
743 if (usb_endpoint_xfer_control(&urb->ep->desc)) { 749 if (usb_endpoint_xfer_control(&urb->ep->desc)) {
744 /* Check to see if the max packet size for the default control 750 /* Check to see if the max packet size for the default control
745 * endpoint changed during FS device enumeration 751 * endpoint changed during FS device enumeration
@@ -788,11 +794,18 @@ int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags)
788 slot_id, ep_index); 794 slot_id, ep_index);
789 spin_unlock_irqrestore(&xhci->lock, flags); 795 spin_unlock_irqrestore(&xhci->lock, flags);
790 } else { 796 } else {
791 ret = -EINVAL; 797 spin_lock_irqsave(&xhci->lock, flags);
798 if (xhci->xhc_state & XHCI_STATE_DYING)
799 goto dying;
800 ret = xhci_queue_isoc_tx_prepare(xhci, GFP_ATOMIC, urb,
801 slot_id, ep_index);
802 spin_unlock_irqrestore(&xhci->lock, flags);
792 } 803 }
793exit: 804exit:
794 return ret; 805 return ret;
795dying: 806dying:
807 xhci_urb_free_priv(xhci, urb_priv);
808 urb->hcpriv = NULL;
796 xhci_dbg(xhci, "Ep 0x%x: URB %p submitted for " 809 xhci_dbg(xhci, "Ep 0x%x: URB %p submitted for "
797 "non-responsive xHCI host.\n", 810 "non-responsive xHCI host.\n",
798 urb->ep->desc.bEndpointAddress, urb); 811 urb->ep->desc.bEndpointAddress, urb);
@@ -800,6 +813,47 @@ dying:
800 return -ESHUTDOWN; 813 return -ESHUTDOWN;
801} 814}
802 815
816/* Get the right ring for the given URB.
817 * If the endpoint supports streams, boundary check the URB's stream ID.
818 * If the endpoint doesn't support streams, return the singular endpoint ring.
819 */
820static struct xhci_ring *xhci_urb_to_transfer_ring(struct xhci_hcd *xhci,
821 struct urb *urb)
822{
823 unsigned int slot_id;
824 unsigned int ep_index;
825 unsigned int stream_id;
826 struct xhci_virt_ep *ep;
827
828 slot_id = urb->dev->slot_id;
829 ep_index = xhci_get_endpoint_index(&urb->ep->desc);
830 stream_id = urb->stream_id;
831 ep = &xhci->devs[slot_id]->eps[ep_index];
832 /* Common case: no streams */
833 if (!(ep->ep_state & EP_HAS_STREAMS))
834 return ep->ring;
835
836 if (stream_id == 0) {
837 xhci_warn(xhci,
838 "WARN: Slot ID %u, ep index %u has streams, "
839 "but URB has no stream ID.\n",
840 slot_id, ep_index);
841 return NULL;
842 }
843
844 if (stream_id < ep->stream_info->num_streams)
845 return ep->stream_info->stream_rings[stream_id];
846
847 xhci_warn(xhci,
848 "WARN: Slot ID %u, ep index %u has "
849 "stream IDs 1 to %u allocated, "
850 "but stream ID %u is requested.\n",
851 slot_id, ep_index,
852 ep->stream_info->num_streams - 1,
853 stream_id);
854 return NULL;
855}
856
803/* 857/*
804 * Remove the URB's TD from the endpoint ring. This may cause the HC to stop 858 * Remove the URB's TD from the endpoint ring. This may cause the HC to stop
805 * USB transfers, potentially stopping in the middle of a TRB buffer. The HC 859 * USB transfers, potentially stopping in the middle of a TRB buffer. The HC
@@ -834,9 +888,10 @@ dying:
834int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) 888int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
835{ 889{
836 unsigned long flags; 890 unsigned long flags;
837 int ret; 891 int ret, i;
838 u32 temp; 892 u32 temp;
839 struct xhci_hcd *xhci; 893 struct xhci_hcd *xhci;
894 struct urb_priv *urb_priv;
840 struct xhci_td *td; 895 struct xhci_td *td;
841 unsigned int ep_index; 896 unsigned int ep_index;
842 struct xhci_ring *ep_ring; 897 struct xhci_ring *ep_ring;
@@ -851,12 +906,12 @@ int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
851 temp = xhci_readl(xhci, &xhci->op_regs->status); 906 temp = xhci_readl(xhci, &xhci->op_regs->status);
852 if (temp == 0xffffffff) { 907 if (temp == 0xffffffff) {
853 xhci_dbg(xhci, "HW died, freeing TD.\n"); 908 xhci_dbg(xhci, "HW died, freeing TD.\n");
854 td = (struct xhci_td *) urb->hcpriv; 909 urb_priv = urb->hcpriv;
855 910
856 usb_hcd_unlink_urb_from_ep(hcd, urb); 911 usb_hcd_unlink_urb_from_ep(hcd, urb);
857 spin_unlock_irqrestore(&xhci->lock, flags); 912 spin_unlock_irqrestore(&xhci->lock, flags);
858 usb_hcd_giveback_urb(xhci_to_hcd(xhci), urb, -ESHUTDOWN); 913 usb_hcd_giveback_urb(xhci_to_hcd(xhci), urb, -ESHUTDOWN);
859 kfree(td); 914 xhci_urb_free_priv(xhci, urb_priv);
860 return ret; 915 return ret;
861 } 916 }
862 if (xhci->xhc_state & XHCI_STATE_DYING) { 917 if (xhci->xhc_state & XHCI_STATE_DYING) {
@@ -884,9 +939,14 @@ int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
884 939
885 xhci_dbg(xhci, "Endpoint ring:\n"); 940 xhci_dbg(xhci, "Endpoint ring:\n");
886 xhci_debug_ring(xhci, ep_ring); 941 xhci_debug_ring(xhci, ep_ring);
887 td = (struct xhci_td *) urb->hcpriv;
888 942
889 list_add_tail(&td->cancelled_td_list, &ep->cancelled_td_list); 943 urb_priv = urb->hcpriv;
944
945 for (i = urb_priv->td_cnt; i < urb_priv->length; i++) {
946 td = urb_priv->td[i];
947 list_add_tail(&td->cancelled_td_list, &ep->cancelled_td_list);
948 }
949
890 /* Queue a stop endpoint command, but only if this is 950 /* Queue a stop endpoint command, but only if this is
891 * the first cancellation to be handled. 951 * the first cancellation to be handled.
892 */ 952 */
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index 6c7e3430ec93..34a60d9f056a 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -720,6 +720,14 @@ struct xhci_virt_ep {
720 struct timer_list stop_cmd_timer; 720 struct timer_list stop_cmd_timer;
721 int stop_cmds_pending; 721 int stop_cmds_pending;
722 struct xhci_hcd *xhci; 722 struct xhci_hcd *xhci;
723 /*
724 * Sometimes the xHC can not process isochronous endpoint ring quickly
725 * enough, and it will miss some isoc tds on the ring and generate
726 * a Missed Service Error Event.
727 * Set skip flag when receive a Missed Service Error Event and
728 * process the missed tds on the endpoint ring.
729 */
730 bool skip;
723}; 731};
724 732
725struct xhci_virt_device { 733struct xhci_virt_device {
@@ -911,6 +919,9 @@ struct xhci_event_cmd {
911/* Control transfer TRB specific fields */ 919/* Control transfer TRB specific fields */
912#define TRB_DIR_IN (1<<16) 920#define TRB_DIR_IN (1<<16)
913 921
922/* Isochronous TRB specific fields */
923#define TRB_SIA (1<<31)
924
914struct xhci_generic_trb { 925struct xhci_generic_trb {
915 u32 field[4]; 926 u32 field[4];
916}; 927};
@@ -1082,6 +1093,12 @@ struct xhci_scratchpad {
1082 dma_addr_t *sp_dma_buffers; 1093 dma_addr_t *sp_dma_buffers;
1083}; 1094};
1084 1095
1096struct urb_priv {
1097 int length;
1098 int td_cnt;
1099 struct xhci_td *td[0];
1100};
1101
1085/* 1102/*
1086 * Each segment table entry is 4*32bits long. 1K seems like an ok size: 1103 * Each segment table entry is 4*32bits long. 1K seems like an ok size:
1087 * (1K bytes * 8bytes/bit) / (4*32 bits) = 64 segment entries in the table, 1104 * (1K bytes * 8bytes/bit) / (4*32 bits) = 64 segment entries in the table,
@@ -1130,7 +1147,7 @@ struct xhci_hcd {
1130 int page_size; 1147 int page_size;
1131 /* Valid values are 12 to 20, inclusive */ 1148 /* Valid values are 12 to 20, inclusive */
1132 int page_shift; 1149 int page_shift;
1133 /* only one MSI vector for now, but might need more later */ 1150 /* msi-x vectors */
1134 int msix_count; 1151 int msix_count;
1135 struct msix_entry *msix_entries; 1152 struct msix_entry *msix_entries;
1136 /* data structures */ 1153 /* data structures */
@@ -1327,11 +1344,6 @@ void xhci_setup_no_streams_ep_input_ctx(struct xhci_hcd *xhci,
1327struct xhci_ring *xhci_dma_to_transfer_ring( 1344struct xhci_ring *xhci_dma_to_transfer_ring(
1328 struct xhci_virt_ep *ep, 1345 struct xhci_virt_ep *ep,
1329 u64 address); 1346 u64 address);
1330struct xhci_ring *xhci_urb_to_transfer_ring(struct xhci_hcd *xhci,
1331 struct urb *urb);
1332struct xhci_ring *xhci_triad_to_transfer_ring(struct xhci_hcd *xhci,
1333 unsigned int slot_id, unsigned int ep_index,
1334 unsigned int stream_id);
1335struct xhci_ring *xhci_stream_id_to_ring( 1347struct xhci_ring *xhci_stream_id_to_ring(
1336 struct xhci_virt_device *dev, 1348 struct xhci_virt_device *dev,
1337 unsigned int ep_index, 1349 unsigned int ep_index,
@@ -1339,6 +1351,7 @@ struct xhci_ring *xhci_stream_id_to_ring(
1339struct xhci_command *xhci_alloc_command(struct xhci_hcd *xhci, 1351struct xhci_command *xhci_alloc_command(struct xhci_hcd *xhci,
1340 bool allocate_in_ctx, bool allocate_completion, 1352 bool allocate_in_ctx, bool allocate_completion,
1341 gfp_t mem_flags); 1353 gfp_t mem_flags);
1354void xhci_urb_free_priv(struct xhci_hcd *xhci, struct urb_priv *urb_priv);
1342void xhci_free_command(struct xhci_hcd *xhci, 1355void xhci_free_command(struct xhci_hcd *xhci,
1343 struct xhci_command *command); 1356 struct xhci_command *command);
1344 1357
@@ -1358,6 +1371,7 @@ void xhci_stop(struct usb_hcd *hcd);
1358void xhci_shutdown(struct usb_hcd *hcd); 1371void xhci_shutdown(struct usb_hcd *hcd);
1359int xhci_get_frame(struct usb_hcd *hcd); 1372int xhci_get_frame(struct usb_hcd *hcd);
1360irqreturn_t xhci_irq(struct usb_hcd *hcd); 1373irqreturn_t xhci_irq(struct usb_hcd *hcd);
1374irqreturn_t xhci_msi_irq(int irq, struct usb_hcd *hcd);
1361int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev); 1375int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev);
1362void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev); 1376void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev);
1363int xhci_alloc_streams(struct usb_hcd *hcd, struct usb_device *udev, 1377int xhci_alloc_streams(struct usb_hcd *hcd, struct usb_device *udev,
@@ -1386,8 +1400,6 @@ struct xhci_segment *trb_in_td(struct xhci_segment *start_seg,
1386int xhci_is_vendor_info_code(struct xhci_hcd *xhci, unsigned int trb_comp_code); 1400int xhci_is_vendor_info_code(struct xhci_hcd *xhci, unsigned int trb_comp_code);
1387void xhci_ring_cmd_db(struct xhci_hcd *xhci); 1401void xhci_ring_cmd_db(struct xhci_hcd *xhci);
1388void *xhci_setup_one_noop(struct xhci_hcd *xhci); 1402void *xhci_setup_one_noop(struct xhci_hcd *xhci);
1389void xhci_handle_event(struct xhci_hcd *xhci);
1390void xhci_set_hc_event_deq(struct xhci_hcd *xhci);
1391int xhci_queue_slot_control(struct xhci_hcd *xhci, u32 trb_type, u32 slot_id); 1403int xhci_queue_slot_control(struct xhci_hcd *xhci, u32 trb_type, u32 slot_id);
1392int xhci_queue_address_device(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr, 1404int xhci_queue_address_device(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr,
1393 u32 slot_id); 1405 u32 slot_id);
@@ -1401,6 +1413,8 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags, struct urb *urb,
1401 int slot_id, unsigned int ep_index); 1413 int slot_id, unsigned int ep_index);
1402int xhci_queue_intr_tx(struct xhci_hcd *xhci, gfp_t mem_flags, struct urb *urb, 1414int xhci_queue_intr_tx(struct xhci_hcd *xhci, gfp_t mem_flags, struct urb *urb,
1403 int slot_id, unsigned int ep_index); 1415 int slot_id, unsigned int ep_index);
1416int xhci_queue_isoc_tx_prepare(struct xhci_hcd *xhci, gfp_t mem_flags,
1417 struct urb *urb, int slot_id, unsigned int ep_index);
1404int xhci_queue_configure_endpoint(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr, 1418int xhci_queue_configure_endpoint(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr,
1405 u32 slot_id, bool command_must_succeed); 1419 u32 slot_id, bool command_must_succeed);
1406int xhci_queue_evaluate_context(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr, 1420int xhci_queue_evaluate_context(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr,
diff --git a/drivers/usb/misc/ftdi-elan.c b/drivers/usb/misc/ftdi-elan.c
index 82e16630a78b..aecf380f6ecc 100644
--- a/drivers/usb/misc/ftdi-elan.c
+++ b/drivers/usb/misc/ftdi-elan.c
@@ -650,7 +650,7 @@ static int ftdi_elan_open(struct inode *inode, struct file *file)
650 650
651static int ftdi_elan_release(struct inode *inode, struct file *file) 651static int ftdi_elan_release(struct inode *inode, struct file *file)
652{ 652{
653 struct usb_ftdi *ftdi = (struct usb_ftdi *)file->private_data; 653 struct usb_ftdi *ftdi = file->private_data;
654 if (ftdi == NULL) 654 if (ftdi == NULL)
655 return -ENODEV; 655 return -ENODEV;
656 up(&ftdi->sw_lock); /* decrement the count on our device */ 656 up(&ftdi->sw_lock); /* decrement the count on our device */
@@ -673,7 +673,7 @@ static ssize_t ftdi_elan_read(struct file *file, char __user *buffer,
673 int bytes_read = 0; 673 int bytes_read = 0;
674 int retry_on_empty = 10; 674 int retry_on_empty = 10;
675 int retry_on_timeout = 5; 675 int retry_on_timeout = 5;
676 struct usb_ftdi *ftdi = (struct usb_ftdi *)file->private_data; 676 struct usb_ftdi *ftdi = file->private_data;
677 if (ftdi->disconnected > 0) { 677 if (ftdi->disconnected > 0) {
678 return -ENODEV; 678 return -ENODEV;
679 } 679 }
diff --git a/drivers/usb/misc/iowarrior.c b/drivers/usb/misc/iowarrior.c
index 7dc9d3c69984..2de49c8887c5 100644
--- a/drivers/usb/misc/iowarrior.c
+++ b/drivers/usb/misc/iowarrior.c
@@ -18,7 +18,7 @@
18#include <linux/init.h> 18#include <linux/init.h>
19#include <linux/slab.h> 19#include <linux/slab.h>
20#include <linux/sched.h> 20#include <linux/sched.h>
21#include <linux/smp_lock.h> 21#include <linux/mutex.h>
22#include <linux/poll.h> 22#include <linux/poll.h>
23#include <linux/usb/iowarrior.h> 23#include <linux/usb/iowarrior.h>
24 24
@@ -61,6 +61,7 @@ MODULE_DESCRIPTION(DRIVER_DESC);
61MODULE_LICENSE("GPL"); 61MODULE_LICENSE("GPL");
62 62
63/* Module parameters */ 63/* Module parameters */
64static DEFINE_MUTEX(iowarrior_mutex);
64static int debug = 0; 65static int debug = 0;
65module_param(debug, bool, 0644); 66module_param(debug, bool, 0644);
66MODULE_PARM_DESC(debug, "debug=1 enables debugging messages"); 67MODULE_PARM_DESC(debug, "debug=1 enables debugging messages");
@@ -282,7 +283,7 @@ static ssize_t iowarrior_read(struct file *file, char __user *buffer,
282 int read_idx; 283 int read_idx;
283 int offset; 284 int offset;
284 285
285 dev = (struct iowarrior *)file->private_data; 286 dev = file->private_data;
286 287
287 /* verify that the device wasn't unplugged */ 288 /* verify that the device wasn't unplugged */
288 if (dev == NULL || !dev->present) 289 if (dev == NULL || !dev->present)
@@ -348,7 +349,7 @@ static ssize_t iowarrior_write(struct file *file,
348 char *buf = NULL; /* for IOW24 and IOW56 we need a buffer */ 349 char *buf = NULL; /* for IOW24 and IOW56 we need a buffer */
349 struct urb *int_out_urb = NULL; 350 struct urb *int_out_urb = NULL;
350 351
351 dev = (struct iowarrior *)file->private_data; 352 dev = file->private_data;
352 353
353 mutex_lock(&dev->mutex); 354 mutex_lock(&dev->mutex);
354 /* verify that the device wasn't unplugged */ 355 /* verify that the device wasn't unplugged */
@@ -483,7 +484,7 @@ static long iowarrior_ioctl(struct file *file, unsigned int cmd,
483 int retval; 484 int retval;
484 int io_res; /* checks for bytes read/written and copy_to/from_user results */ 485 int io_res; /* checks for bytes read/written and copy_to/from_user results */
485 486
486 dev = (struct iowarrior *)file->private_data; 487 dev = file->private_data;
487 if (dev == NULL) { 488 if (dev == NULL) {
488 return -ENODEV; 489 return -ENODEV;
489 } 490 }
@@ -493,7 +494,7 @@ static long iowarrior_ioctl(struct file *file, unsigned int cmd,
493 return -ENOMEM; 494 return -ENOMEM;
494 495
495 /* lock this object */ 496 /* lock this object */
496 lock_kernel(); 497 mutex_lock(&iowarrior_mutex);
497 mutex_lock(&dev->mutex); 498 mutex_lock(&dev->mutex);
498 499
499 /* verify that the device wasn't unplugged */ 500 /* verify that the device wasn't unplugged */
@@ -585,7 +586,7 @@ static long iowarrior_ioctl(struct file *file, unsigned int cmd,
585error_out: 586error_out:
586 /* unlock the device */ 587 /* unlock the device */
587 mutex_unlock(&dev->mutex); 588 mutex_unlock(&dev->mutex);
588 unlock_kernel(); 589 mutex_unlock(&iowarrior_mutex);
589 kfree(buffer); 590 kfree(buffer);
590 return retval; 591 return retval;
591} 592}
@@ -602,12 +603,12 @@ static int iowarrior_open(struct inode *inode, struct file *file)
602 603
603 dbg("%s", __func__); 604 dbg("%s", __func__);
604 605
605 lock_kernel(); 606 mutex_lock(&iowarrior_mutex);
606 subminor = iminor(inode); 607 subminor = iminor(inode);
607 608
608 interface = usb_find_interface(&iowarrior_driver, subminor); 609 interface = usb_find_interface(&iowarrior_driver, subminor);
609 if (!interface) { 610 if (!interface) {
610 unlock_kernel(); 611 mutex_unlock(&iowarrior_mutex);
611 err("%s - error, can't find device for minor %d", __func__, 612 err("%s - error, can't find device for minor %d", __func__,
612 subminor); 613 subminor);
613 return -ENODEV; 614 return -ENODEV;
@@ -617,7 +618,7 @@ static int iowarrior_open(struct inode *inode, struct file *file)
617 dev = usb_get_intfdata(interface); 618 dev = usb_get_intfdata(interface);
618 if (!dev) { 619 if (!dev) {
619 mutex_unlock(&iowarrior_open_disc_lock); 620 mutex_unlock(&iowarrior_open_disc_lock);
620 unlock_kernel(); 621 mutex_unlock(&iowarrior_mutex);
621 return -ENODEV; 622 return -ENODEV;
622 } 623 }
623 624
@@ -644,7 +645,7 @@ static int iowarrior_open(struct inode *inode, struct file *file)
644 645
645out: 646out:
646 mutex_unlock(&dev->mutex); 647 mutex_unlock(&dev->mutex);
647 unlock_kernel(); 648 mutex_unlock(&iowarrior_mutex);
648 return retval; 649 return retval;
649} 650}
650 651
@@ -656,7 +657,7 @@ static int iowarrior_release(struct inode *inode, struct file *file)
656 struct iowarrior *dev; 657 struct iowarrior *dev;
657 int retval = 0; 658 int retval = 0;
658 659
659 dev = (struct iowarrior *)file->private_data; 660 dev = file->private_data;
660 if (dev == NULL) { 661 if (dev == NULL) {
661 return -ENODEV; 662 return -ENODEV;
662 } 663 }
diff --git a/drivers/usb/misc/legousbtower.c b/drivers/usb/misc/legousbtower.c
index 8547bf9e3175..6482c6e2e6bd 100644
--- a/drivers/usb/misc/legousbtower.c
+++ b/drivers/usb/misc/legousbtower.c
@@ -448,7 +448,7 @@ static int tower_release (struct inode *inode, struct file *file)
448 448
449 dbg(2, "%s: enter", __func__); 449 dbg(2, "%s: enter", __func__);
450 450
451 dev = (struct lego_usb_tower *)file->private_data; 451 dev = file->private_data;
452 452
453 if (dev == NULL) { 453 if (dev == NULL) {
454 dbg(1, "%s: object is NULL", __func__); 454 dbg(1, "%s: object is NULL", __func__);
@@ -597,7 +597,7 @@ static ssize_t tower_read (struct file *file, char __user *buffer, size_t count,
597 597
598 dbg(2, "%s: enter, count = %Zd", __func__, count); 598 dbg(2, "%s: enter, count = %Zd", __func__, count);
599 599
600 dev = (struct lego_usb_tower *)file->private_data; 600 dev = file->private_data;
601 601
602 /* lock this object */ 602 /* lock this object */
603 if (mutex_lock_interruptible(&dev->lock)) { 603 if (mutex_lock_interruptible(&dev->lock)) {
@@ -686,7 +686,7 @@ static ssize_t tower_write (struct file *file, const char __user *buffer, size_t
686 686
687 dbg(2, "%s: enter, count = %Zd", __func__, count); 687 dbg(2, "%s: enter, count = %Zd", __func__, count);
688 688
689 dev = (struct lego_usb_tower *)file->private_data; 689 dev = file->private_data;
690 690
691 /* lock this object */ 691 /* lock this object */
692 if (mutex_lock_interruptible(&dev->lock)) { 692 if (mutex_lock_interruptible(&dev->lock)) {
diff --git a/drivers/usb/misc/rio500.c b/drivers/usb/misc/rio500.c
index a85771b1563d..cc13ae61712a 100644
--- a/drivers/usb/misc/rio500.c
+++ b/drivers/usb/misc/rio500.c
@@ -32,7 +32,7 @@
32#include <linux/kernel.h> 32#include <linux/kernel.h>
33#include <linux/signal.h> 33#include <linux/signal.h>
34#include <linux/sched.h> 34#include <linux/sched.h>
35#include <linux/smp_lock.h> 35#include <linux/mutex.h>
36#include <linux/errno.h> 36#include <linux/errno.h>
37#include <linux/random.h> 37#include <linux/random.h>
38#include <linux/poll.h> 38#include <linux/poll.h>
@@ -72,6 +72,7 @@ struct rio_usb_data {
72 struct mutex lock; /* general race avoidance */ 72 struct mutex lock; /* general race avoidance */
73}; 73};
74 74
75static DEFINE_MUTEX(rio500_mutex);
75static struct rio_usb_data rio_instance; 76static struct rio_usb_data rio_instance;
76 77
77static int open_rio(struct inode *inode, struct file *file) 78static int open_rio(struct inode *inode, struct file *file)
@@ -79,12 +80,12 @@ static int open_rio(struct inode *inode, struct file *file)
79 struct rio_usb_data *rio = &rio_instance; 80 struct rio_usb_data *rio = &rio_instance;
80 81
81 /* against disconnect() */ 82 /* against disconnect() */
82 lock_kernel(); 83 mutex_lock(&rio500_mutex);
83 mutex_lock(&(rio->lock)); 84 mutex_lock(&(rio->lock));
84 85
85 if (rio->isopen || !rio->present) { 86 if (rio->isopen || !rio->present) {
86 mutex_unlock(&(rio->lock)); 87 mutex_unlock(&(rio->lock));
87 unlock_kernel(); 88 mutex_unlock(&rio500_mutex);
88 return -EBUSY; 89 return -EBUSY;
89 } 90 }
90 rio->isopen = 1; 91 rio->isopen = 1;
@@ -94,7 +95,7 @@ static int open_rio(struct inode *inode, struct file *file)
94 mutex_unlock(&(rio->lock)); 95 mutex_unlock(&(rio->lock));
95 96
96 dev_info(&rio->rio_dev->dev, "Rio opened.\n"); 97 dev_info(&rio->rio_dev->dev, "Rio opened.\n");
97 unlock_kernel(); 98 mutex_unlock(&rio500_mutex);
98 99
99 return 0; 100 return 0;
100} 101}
@@ -491,7 +492,7 @@ static void disconnect_rio(struct usb_interface *intf)
491 struct rio_usb_data *rio = usb_get_intfdata (intf); 492 struct rio_usb_data *rio = usb_get_intfdata (intf);
492 493
493 usb_set_intfdata (intf, NULL); 494 usb_set_intfdata (intf, NULL);
494 lock_kernel(); 495 mutex_lock(&rio500_mutex);
495 if (rio) { 496 if (rio) {
496 usb_deregister_dev(intf, &usb_rio_class); 497 usb_deregister_dev(intf, &usb_rio_class);
497 498
@@ -501,7 +502,7 @@ static void disconnect_rio(struct usb_interface *intf)
501 /* better let it finish - the release will do whats needed */ 502 /* better let it finish - the release will do whats needed */
502 rio->rio_dev = NULL; 503 rio->rio_dev = NULL;
503 mutex_unlock(&(rio->lock)); 504 mutex_unlock(&(rio->lock));
504 unlock_kernel(); 505 mutex_unlock(&rio500_mutex);
505 return; 506 return;
506 } 507 }
507 kfree(rio->ibuf); 508 kfree(rio->ibuf);
@@ -512,7 +513,7 @@ static void disconnect_rio(struct usb_interface *intf)
512 rio->present = 0; 513 rio->present = 0;
513 mutex_unlock(&(rio->lock)); 514 mutex_unlock(&(rio->lock));
514 } 515 }
515 unlock_kernel(); 516 mutex_unlock(&rio500_mutex);
516} 517}
517 518
518static const struct usb_device_id rio_table[] = { 519static const struct usb_device_id rio_table[] = {
diff --git a/drivers/usb/misc/sisusbvga/sisusb.c b/drivers/usb/misc/sisusbvga/sisusb.c
index d25814c172b2..70d00e99a4b4 100644
--- a/drivers/usb/misc/sisusbvga/sisusb.c
+++ b/drivers/usb/misc/sisusbvga/sisusb.c
@@ -2487,7 +2487,7 @@ sisusb_release(struct inode *inode, struct file *file)
2487{ 2487{
2488 struct sisusb_usb_data *sisusb; 2488 struct sisusb_usb_data *sisusb;
2489 2489
2490 if (!(sisusb = (struct sisusb_usb_data *)file->private_data)) 2490 if (!(sisusb = file->private_data))
2491 return -ENODEV; 2491 return -ENODEV;
2492 2492
2493 mutex_lock(&sisusb->lock); 2493 mutex_lock(&sisusb->lock);
@@ -2519,7 +2519,7 @@ sisusb_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
2519 u16 buf16; 2519 u16 buf16;
2520 u32 buf32, address; 2520 u32 buf32, address;
2521 2521
2522 if (!(sisusb = (struct sisusb_usb_data *)file->private_data)) 2522 if (!(sisusb = file->private_data))
2523 return -ENODEV; 2523 return -ENODEV;
2524 2524
2525 mutex_lock(&sisusb->lock); 2525 mutex_lock(&sisusb->lock);
@@ -2661,7 +2661,7 @@ sisusb_write(struct file *file, const char __user *buffer, size_t count,
2661 u16 buf16; 2661 u16 buf16;
2662 u32 buf32, address; 2662 u32 buf32, address;
2663 2663
2664 if (!(sisusb = (struct sisusb_usb_data *)file->private_data)) 2664 if (!(sisusb = file->private_data))
2665 return -ENODEV; 2665 return -ENODEV;
2666 2666
2667 mutex_lock(&sisusb->lock); 2667 mutex_lock(&sisusb->lock);
@@ -2804,7 +2804,7 @@ sisusb_lseek(struct file *file, loff_t offset, int orig)
2804 struct sisusb_usb_data *sisusb; 2804 struct sisusb_usb_data *sisusb;
2805 loff_t ret; 2805 loff_t ret;
2806 2806
2807 if (!(sisusb = (struct sisusb_usb_data *)file->private_data)) 2807 if (!(sisusb = file->private_data))
2808 return -ENODEV; 2808 return -ENODEV;
2809 2809
2810 mutex_lock(&sisusb->lock); 2810 mutex_lock(&sisusb->lock);
@@ -2969,7 +2969,7 @@ sisusb_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
2969 long retval = 0; 2969 long retval = 0;
2970 u32 __user *argp = (u32 __user *)arg; 2970 u32 __user *argp = (u32 __user *)arg;
2971 2971
2972 if (!(sisusb = (struct sisusb_usb_data *)file->private_data)) 2972 if (!(sisusb = file->private_data))
2973 return -ENODEV; 2973 return -ENODEV;
2974 2974
2975 mutex_lock(&sisusb->lock); 2975 mutex_lock(&sisusb->lock);
diff --git a/drivers/usb/misc/usblcd.c b/drivers/usb/misc/usblcd.c
index 7828c764b323..d00dde19194c 100644
--- a/drivers/usb/misc/usblcd.c
+++ b/drivers/usb/misc/usblcd.c
@@ -16,7 +16,6 @@
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/init.h> 17#include <linux/init.h>
18#include <linux/slab.h> 18#include <linux/slab.h>
19#include <linux/smp_lock.h>
20#include <linux/errno.h> 19#include <linux/errno.h>
21#include <linux/mutex.h> 20#include <linux/mutex.h>
22#include <asm/uaccess.h> 21#include <asm/uaccess.h>
@@ -30,6 +29,7 @@
30#define IOCTL_GET_DRV_VERSION 2 29#define IOCTL_GET_DRV_VERSION 2
31 30
32 31
32static DEFINE_MUTEX(lcd_mutex);
33static const struct usb_device_id id_table[] = { 33static const struct usb_device_id id_table[] = {
34 { .idVendor = 0x10D2, .match_flags = USB_DEVICE_ID_MATCH_VENDOR, }, 34 { .idVendor = 0x10D2, .match_flags = USB_DEVICE_ID_MATCH_VENDOR, },
35 { }, 35 { },
@@ -74,12 +74,12 @@ static int lcd_open(struct inode *inode, struct file *file)
74 struct usb_interface *interface; 74 struct usb_interface *interface;
75 int subminor, r; 75 int subminor, r;
76 76
77 lock_kernel(); 77 mutex_lock(&lcd_mutex);
78 subminor = iminor(inode); 78 subminor = iminor(inode);
79 79
80 interface = usb_find_interface(&lcd_driver, subminor); 80 interface = usb_find_interface(&lcd_driver, subminor);
81 if (!interface) { 81 if (!interface) {
82 unlock_kernel(); 82 mutex_unlock(&lcd_mutex);
83 err ("USBLCD: %s - error, can't find device for minor %d", 83 err ("USBLCD: %s - error, can't find device for minor %d",
84 __func__, subminor); 84 __func__, subminor);
85 return -ENODEV; 85 return -ENODEV;
@@ -89,7 +89,7 @@ static int lcd_open(struct inode *inode, struct file *file)
89 dev = usb_get_intfdata(interface); 89 dev = usb_get_intfdata(interface);
90 if (!dev) { 90 if (!dev) {
91 mutex_unlock(&open_disc_mutex); 91 mutex_unlock(&open_disc_mutex);
92 unlock_kernel(); 92 mutex_unlock(&lcd_mutex);
93 return -ENODEV; 93 return -ENODEV;
94 } 94 }
95 95
@@ -101,13 +101,13 @@ static int lcd_open(struct inode *inode, struct file *file)
101 r = usb_autopm_get_interface(interface); 101 r = usb_autopm_get_interface(interface);
102 if (r < 0) { 102 if (r < 0) {
103 kref_put(&dev->kref, lcd_delete); 103 kref_put(&dev->kref, lcd_delete);
104 unlock_kernel(); 104 mutex_unlock(&lcd_mutex);
105 return r; 105 return r;
106 } 106 }
107 107
108 /* save our object in the file's private structure */ 108 /* save our object in the file's private structure */
109 file->private_data = dev; 109 file->private_data = dev;
110 unlock_kernel(); 110 mutex_unlock(&lcd_mutex);
111 111
112 return 0; 112 return 0;
113} 113}
@@ -116,7 +116,7 @@ static int lcd_release(struct inode *inode, struct file *file)
116{ 116{
117 struct usb_lcd *dev; 117 struct usb_lcd *dev;
118 118
119 dev = (struct usb_lcd *)file->private_data; 119 dev = file->private_data;
120 if (dev == NULL) 120 if (dev == NULL)
121 return -ENODEV; 121 return -ENODEV;
122 122
@@ -132,7 +132,7 @@ static ssize_t lcd_read(struct file *file, char __user * buffer, size_t count, l
132 int retval = 0; 132 int retval = 0;
133 int bytes_read; 133 int bytes_read;
134 134
135 dev = (struct usb_lcd *)file->private_data; 135 dev = file->private_data;
136 136
137 /* do a blocking bulk read to get data from the device */ 137 /* do a blocking bulk read to get data from the device */
138 retval = usb_bulk_msg(dev->udev, 138 retval = usb_bulk_msg(dev->udev,
@@ -158,20 +158,20 @@ static long lcd_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
158 u16 bcdDevice; 158 u16 bcdDevice;
159 char buf[30]; 159 char buf[30];
160 160
161 dev = (struct usb_lcd *)file->private_data; 161 dev = file->private_data;
162 if (dev == NULL) 162 if (dev == NULL)
163 return -ENODEV; 163 return -ENODEV;
164 164
165 switch (cmd) { 165 switch (cmd) {
166 case IOCTL_GET_HARD_VERSION: 166 case IOCTL_GET_HARD_VERSION:
167 lock_kernel(); 167 mutex_lock(&lcd_mutex);
168 bcdDevice = le16_to_cpu((dev->udev)->descriptor.bcdDevice); 168 bcdDevice = le16_to_cpu((dev->udev)->descriptor.bcdDevice);
169 sprintf(buf,"%1d%1d.%1d%1d", 169 sprintf(buf,"%1d%1d.%1d%1d",
170 (bcdDevice & 0xF000)>>12, 170 (bcdDevice & 0xF000)>>12,
171 (bcdDevice & 0xF00)>>8, 171 (bcdDevice & 0xF00)>>8,
172 (bcdDevice & 0xF0)>>4, 172 (bcdDevice & 0xF0)>>4,
173 (bcdDevice & 0xF)); 173 (bcdDevice & 0xF));
174 unlock_kernel(); 174 mutex_unlock(&lcd_mutex);
175 if (copy_to_user((void __user *)arg,buf,strlen(buf))!=0) 175 if (copy_to_user((void __user *)arg,buf,strlen(buf))!=0)
176 return -EFAULT; 176 return -EFAULT;
177 break; 177 break;
@@ -217,7 +217,7 @@ static ssize_t lcd_write(struct file *file, const char __user * user_buffer, siz
217 struct urb *urb = NULL; 217 struct urb *urb = NULL;
218 char *buf = NULL; 218 char *buf = NULL;
219 219
220 dev = (struct usb_lcd *)file->private_data; 220 dev = file->private_data;
221 221
222 /* verify that we actually have some data to write */ 222 /* verify that we actually have some data to write */
223 if (count == 0) 223 if (count == 0)
diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c
index 16dffe99d9f1..eef370eb7a54 100644
--- a/drivers/usb/misc/usbtest.c
+++ b/drivers/usb/misc/usbtest.c
@@ -136,7 +136,7 @@ try_iso:
136 iso_out = e; 136 iso_out = e;
137 } 137 }
138 } 138 }
139 if ((in && out) || (iso_in && iso_out)) 139 if ((in && out) || iso_in || iso_out)
140 goto found; 140 goto found;
141 } 141 }
142 return -EINVAL; 142 return -EINVAL;
@@ -162,6 +162,9 @@ found:
162 dev->in_iso_pipe = usb_rcvisocpipe (udev, 162 dev->in_iso_pipe = usb_rcvisocpipe (udev,
163 iso_in->desc.bEndpointAddress 163 iso_in->desc.bEndpointAddress
164 & USB_ENDPOINT_NUMBER_MASK); 164 & USB_ENDPOINT_NUMBER_MASK);
165 }
166
167 if (iso_out) {
165 dev->iso_out = &iso_out->desc; 168 dev->iso_out = &iso_out->desc;
166 dev->out_iso_pipe = usb_sndisocpipe (udev, 169 dev->out_iso_pipe = usb_sndisocpipe (udev,
167 iso_out->desc.bEndpointAddress 170 iso_out->desc.bEndpointAddress
@@ -1378,7 +1381,6 @@ static void iso_callback (struct urb *urb)
1378 break; 1381 break;
1379 } 1382 }
1380 } 1383 }
1381 simple_free_urb (urb);
1382 1384
1383 ctx->pending--; 1385 ctx->pending--;
1384 if (ctx->pending == 0) { 1386 if (ctx->pending == 0) {
@@ -1495,6 +1497,7 @@ test_iso_queue (struct usbtest_dev *dev, struct usbtest_param *param,
1495 } 1497 }
1496 1498
1497 simple_free_urb (urbs [i]); 1499 simple_free_urb (urbs [i]);
1500 urbs[i] = NULL;
1498 context.pending--; 1501 context.pending--;
1499 context.submit_error = 1; 1502 context.submit_error = 1;
1500 break; 1503 break;
@@ -1504,6 +1507,10 @@ test_iso_queue (struct usbtest_dev *dev, struct usbtest_param *param,
1504 1507
1505 wait_for_completion (&context.done); 1508 wait_for_completion (&context.done);
1506 1509
1510 for (i = 0; i < param->sglen; i++) {
1511 if (urbs[i])
1512 simple_free_urb(urbs[i]);
1513 }
1507 /* 1514 /*
1508 * Isochronous transfers are expected to fail sometimes. As an 1515 * Isochronous transfers are expected to fail sometimes. As an
1509 * arbitrary limit, we will report an error if any submissions 1516 * arbitrary limit, we will report an error if any submissions
@@ -1548,6 +1555,7 @@ fail:
1548 * off just killing the userspace task and waiting for it to exit. 1555 * off just killing the userspace task and waiting for it to exit.
1549 */ 1556 */
1550 1557
1558/* No BKL needed */
1551static int 1559static int
1552usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf) 1560usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1553{ 1561{
@@ -2170,7 +2178,7 @@ static struct usb_driver usbtest_driver = {
2170 .name = "usbtest", 2178 .name = "usbtest",
2171 .id_table = id_table, 2179 .id_table = id_table,
2172 .probe = usbtest_probe, 2180 .probe = usbtest_probe,
2173 .ioctl = usbtest_ioctl, 2181 .unlocked_ioctl = usbtest_ioctl,
2174 .disconnect = usbtest_disconnect, 2182 .disconnect = usbtest_disconnect,
2175 .suspend = usbtest_suspend, 2183 .suspend = usbtest_suspend,
2176 .resume = usbtest_resume, 2184 .resume = usbtest_resume,
diff --git a/drivers/usb/mon/mon_bin.c b/drivers/usb/mon/mon_bin.c
index 61c76b13f0f1..44cb37b5a4dc 100644
--- a/drivers/usb/mon/mon_bin.c
+++ b/drivers/usb/mon/mon_bin.c
@@ -646,17 +646,14 @@ static int mon_bin_open(struct inode *inode, struct file *file)
646 size_t size; 646 size_t size;
647 int rc; 647 int rc;
648 648
649 lock_kernel();
650 mutex_lock(&mon_lock); 649 mutex_lock(&mon_lock);
651 if ((mbus = mon_bus_lookup(iminor(inode))) == NULL) { 650 if ((mbus = mon_bus_lookup(iminor(inode))) == NULL) {
652 mutex_unlock(&mon_lock); 651 mutex_unlock(&mon_lock);
653 unlock_kernel();
654 return -ENODEV; 652 return -ENODEV;
655 } 653 }
656 if (mbus != &mon_bus0 && mbus->u_bus == NULL) { 654 if (mbus != &mon_bus0 && mbus->u_bus == NULL) {
657 printk(KERN_ERR TAG ": consistency error on open\n"); 655 printk(KERN_ERR TAG ": consistency error on open\n");
658 mutex_unlock(&mon_lock); 656 mutex_unlock(&mon_lock);
659 unlock_kernel();
660 return -ENODEV; 657 return -ENODEV;
661 } 658 }
662 659
@@ -689,7 +686,6 @@ static int mon_bin_open(struct inode *inode, struct file *file)
689 686
690 file->private_data = rp; 687 file->private_data = rp;
691 mutex_unlock(&mon_lock); 688 mutex_unlock(&mon_lock);
692 unlock_kernel();
693 return 0; 689 return 0;
694 690
695err_allocbuff: 691err_allocbuff:
@@ -698,7 +694,6 @@ err_allocvec:
698 kfree(rp); 694 kfree(rp);
699err_alloc: 695err_alloc:
700 mutex_unlock(&mon_lock); 696 mutex_unlock(&mon_lock);
701 unlock_kernel();
702 return rc; 697 return rc;
703} 698}
704 699
@@ -954,7 +949,7 @@ static int mon_bin_queued(struct mon_reader_bin *rp)
954 949
955/* 950/*
956 */ 951 */
957static int mon_bin_ioctl(struct file *file, unsigned int cmd, unsigned long arg) 952static long mon_bin_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
958{ 953{
959 struct mon_reader_bin *rp = file->private_data; 954 struct mon_reader_bin *rp = file->private_data;
960 // struct mon_bus* mbus = rp->r.m_bus; 955 // struct mon_bus* mbus = rp->r.m_bus;
@@ -1009,7 +1004,7 @@ static int mon_bin_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
1009 1004
1010 mutex_lock(&rp->fetch_lock); 1005 mutex_lock(&rp->fetch_lock);
1011 spin_lock_irqsave(&rp->b_lock, flags); 1006 spin_lock_irqsave(&rp->b_lock, flags);
1012 mon_free_buff(rp->b_vec, size/CHUNK_SIZE); 1007 mon_free_buff(rp->b_vec, rp->b_size/CHUNK_SIZE);
1013 kfree(rp->b_vec); 1008 kfree(rp->b_vec);
1014 rp->b_vec = vec; 1009 rp->b_vec = vec;
1015 rp->b_size = size; 1010 rp->b_size = size;
@@ -1094,19 +1089,6 @@ static int mon_bin_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
1094 return ret; 1089 return ret;
1095} 1090}
1096 1091
1097static long mon_bin_unlocked_ioctl(struct file *file, unsigned int cmd,
1098 unsigned long arg)
1099{
1100 int ret;
1101
1102 lock_kernel();
1103 ret = mon_bin_ioctl(file, cmd, arg);
1104 unlock_kernel();
1105
1106 return ret;
1107}
1108
1109
1110#ifdef CONFIG_COMPAT 1092#ifdef CONFIG_COMPAT
1111static long mon_bin_compat_ioctl(struct file *file, 1093static long mon_bin_compat_ioctl(struct file *file,
1112 unsigned int cmd, unsigned long arg) 1094 unsigned int cmd, unsigned long arg)
@@ -1250,7 +1232,7 @@ static const struct file_operations mon_fops_binary = {
1250 .read = mon_bin_read, 1232 .read = mon_bin_read,
1251 /* .write = mon_text_write, */ 1233 /* .write = mon_text_write, */
1252 .poll = mon_bin_poll, 1234 .poll = mon_bin_poll,
1253 .unlocked_ioctl = mon_bin_unlocked_ioctl, 1235 .unlocked_ioctl = mon_bin_ioctl,
1254#ifdef CONFIG_COMPAT 1236#ifdef CONFIG_COMPAT
1255 .compat_ioctl = mon_bin_compat_ioctl, 1237 .compat_ioctl = mon_bin_compat_ioctl,
1256#endif 1238#endif
diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 3b795c56221f..540c766c4f86 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -704,7 +704,6 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
704#ifdef CONFIG_USB_MUSB_HDRC_HCD 704#ifdef CONFIG_USB_MUSB_HDRC_HCD
705 if (int_usb & MUSB_INTR_CONNECT) { 705 if (int_usb & MUSB_INTR_CONNECT) {
706 struct usb_hcd *hcd = musb_to_hcd(musb); 706 struct usb_hcd *hcd = musb_to_hcd(musb);
707 void __iomem *mbase = musb->mregs;
708 707
709 handled = IRQ_HANDLED; 708 handled = IRQ_HANDLED;
710 musb->is_active = 1; 709 musb->is_active = 1;
@@ -717,9 +716,9 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
717 if (is_peripheral_active(musb)) { 716 if (is_peripheral_active(musb)) {
718 /* REVISIT HNP; just force disconnect */ 717 /* REVISIT HNP; just force disconnect */
719 } 718 }
720 musb_writew(mbase, MUSB_INTRTXE, musb->epmask); 719 musb_writew(musb->mregs, MUSB_INTRTXE, musb->epmask);
721 musb_writew(mbase, MUSB_INTRRXE, musb->epmask & 0xfffe); 720 musb_writew(musb->mregs, MUSB_INTRRXE, musb->epmask & 0xfffe);
722 musb_writeb(mbase, MUSB_INTRUSBE, 0xf7); 721 musb_writeb(musb->mregs, MUSB_INTRUSBE, 0xf7);
723#endif 722#endif
724 musb->port1_status &= ~(USB_PORT_STAT_LOW_SPEED 723 musb->port1_status &= ~(USB_PORT_STAT_LOW_SPEED
725 |USB_PORT_STAT_HIGH_SPEED 724 |USB_PORT_STAT_HIGH_SPEED
diff --git a/drivers/usb/musb/musb_debugfs.c b/drivers/usb/musb/musb_debugfs.c
index bba76af0c0c6..c79a5e30d437 100644
--- a/drivers/usb/musb/musb_debugfs.c
+++ b/drivers/usb/musb/musb_debugfs.c
@@ -92,29 +92,29 @@ static const struct musb_register_map musb_regmap[] = {
92 { "LS_EOF1", 0x7E, 8 }, 92 { "LS_EOF1", 0x7E, 8 },
93 { "SOFT_RST", 0x7F, 8 }, 93 { "SOFT_RST", 0x7F, 8 },
94 { "DMA_CNTLch0", 0x204, 16 }, 94 { "DMA_CNTLch0", 0x204, 16 },
95 { "DMA_ADDRch0", 0x208, 16 }, 95 { "DMA_ADDRch0", 0x208, 32 },
96 { "DMA_COUNTch0", 0x20C, 16 }, 96 { "DMA_COUNTch0", 0x20C, 32 },
97 { "DMA_CNTLch1", 0x214, 16 }, 97 { "DMA_CNTLch1", 0x214, 16 },
98 { "DMA_ADDRch1", 0x218, 16 }, 98 { "DMA_ADDRch1", 0x218, 32 },
99 { "DMA_COUNTch1", 0x21C, 16 }, 99 { "DMA_COUNTch1", 0x21C, 32 },
100 { "DMA_CNTLch2", 0x224, 16 }, 100 { "DMA_CNTLch2", 0x224, 16 },
101 { "DMA_ADDRch2", 0x228, 16 }, 101 { "DMA_ADDRch2", 0x228, 32 },
102 { "DMA_COUNTch2", 0x22C, 16 }, 102 { "DMA_COUNTch2", 0x22C, 32 },
103 { "DMA_CNTLch3", 0x234, 16 }, 103 { "DMA_CNTLch3", 0x234, 16 },
104 { "DMA_ADDRch3", 0x238, 16 }, 104 { "DMA_ADDRch3", 0x238, 32 },
105 { "DMA_COUNTch3", 0x23C, 16 }, 105 { "DMA_COUNTch3", 0x23C, 32 },
106 { "DMA_CNTLch4", 0x244, 16 }, 106 { "DMA_CNTLch4", 0x244, 16 },
107 { "DMA_ADDRch4", 0x248, 16 }, 107 { "DMA_ADDRch4", 0x248, 32 },
108 { "DMA_COUNTch4", 0x24C, 16 }, 108 { "DMA_COUNTch4", 0x24C, 32 },
109 { "DMA_CNTLch5", 0x254, 16 }, 109 { "DMA_CNTLch5", 0x254, 16 },
110 { "DMA_ADDRch5", 0x258, 16 }, 110 { "DMA_ADDRch5", 0x258, 32 },
111 { "DMA_COUNTch5", 0x25C, 16 }, 111 { "DMA_COUNTch5", 0x25C, 32 },
112 { "DMA_CNTLch6", 0x264, 16 }, 112 { "DMA_CNTLch6", 0x264, 16 },
113 { "DMA_ADDRch6", 0x268, 16 }, 113 { "DMA_ADDRch6", 0x268, 32 },
114 { "DMA_COUNTch6", 0x26C, 16 }, 114 { "DMA_COUNTch6", 0x26C, 32 },
115 { "DMA_CNTLch7", 0x274, 16 }, 115 { "DMA_CNTLch7", 0x274, 16 },
116 { "DMA_ADDRch7", 0x278, 16 }, 116 { "DMA_ADDRch7", 0x278, 32 },
117 { "DMA_COUNTch7", 0x27C, 16 }, 117 { "DMA_COUNTch7", 0x27C, 32 },
118 { } /* Terminating Entry */ 118 { } /* Terminating Entry */
119}; 119};
120 120
diff --git a/drivers/usb/musb/musb_gadget_ep0.c b/drivers/usb/musb/musb_gadget_ep0.c
index 21b9788d0243..59bef8f3a358 100644
--- a/drivers/usb/musb/musb_gadget_ep0.c
+++ b/drivers/usb/musb/musb_gadget_ep0.c
@@ -402,6 +402,9 @@ __acquires(musb->lock)
402 musb->g.a_alt_hnp_support = 1; 402 musb->g.a_alt_hnp_support = 1;
403 break; 403 break;
404#endif 404#endif
405 case USB_DEVICE_DEBUG_MODE:
406 handled = 0;
407 break;
405stall: 408stall:
406 default: 409 default:
407 handled = -EINVAL; 410 handled = -EINVAL;
diff --git a/drivers/usb/musb/musb_virthub.c b/drivers/usb/musb/musb_virthub.c
index 92e85e027cfb..43233c397b6e 100644
--- a/drivers/usb/musb/musb_virthub.c
+++ b/drivers/usb/musb/musb_virthub.c
@@ -244,7 +244,7 @@ int musb_hub_control(
244 244
245 spin_lock_irqsave(&musb->lock, flags); 245 spin_lock_irqsave(&musb->lock, flags);
246 246
247 if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags))) { 247 if (unlikely(!HCD_HW_ACCESSIBLE(hcd))) {
248 spin_unlock_irqrestore(&musb->lock, flags); 248 spin_unlock_irqrestore(&musb->lock, flags);
249 return -ESHUTDOWN; 249 return -ESHUTDOWN;
250 } 250 }
diff --git a/drivers/usb/musb/musbhsdma.c b/drivers/usb/musb/musbhsdma.c
index dc66e4376d49..6dc107f25245 100644
--- a/drivers/usb/musb/musbhsdma.c
+++ b/drivers/usb/musb/musbhsdma.c
@@ -173,10 +173,7 @@ static int dma_channel_program(struct dma_channel *channel,
173 musb_channel->max_packet_sz = packet_sz; 173 musb_channel->max_packet_sz = packet_sz;
174 channel->status = MUSB_DMA_STATUS_BUSY; 174 channel->status = MUSB_DMA_STATUS_BUSY;
175 175
176 if ((mode == 1) && (len >= packet_sz)) 176 configure_channel(channel, packet_sz, mode, dma_addr, len);
177 configure_channel(channel, packet_sz, 1, dma_addr, len);
178 else
179 configure_channel(channel, packet_sz, 0, dma_addr, len);
180 177
181 return true; 178 return true;
182} 179}
diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c
index e06d65e36bf7..2111a241dd03 100644
--- a/drivers/usb/musb/omap2430.c
+++ b/drivers/usb/musb/omap2430.c
@@ -32,8 +32,6 @@
32#include <linux/clk.h> 32#include <linux/clk.h>
33#include <linux/io.h> 33#include <linux/io.h>
34 34
35#include <plat/mux.h>
36
37#include "musb_core.h" 35#include "musb_core.h"
38#include "omap2430.h" 36#include "omap2430.h"
39 37
@@ -194,10 +192,6 @@ int __init musb_platform_init(struct musb *musb, void *board_data)
194 u32 l; 192 u32 l;
195 struct omap_musb_board_data *data = board_data; 193 struct omap_musb_board_data *data = board_data;
196 194
197#if defined(CONFIG_ARCH_OMAP2430)
198 omap_cfg_reg(AE5_2430_USB0HS_STP);
199#endif
200
201 /* We require some kind of external transceiver, hooked 195 /* We require some kind of external transceiver, hooked
202 * up through ULPI. TWL4030-family PMICs include one, 196 * up through ULPI. TWL4030-family PMICs include one,
203 * which needs a driver, drivers aren't always needed. 197 * which needs a driver, drivers aren't always needed.
diff --git a/drivers/usb/otg/Kconfig b/drivers/usb/otg/Kconfig
index 3d2d3e549bd1..3b1289572d72 100644
--- a/drivers/usb/otg/Kconfig
+++ b/drivers/usb/otg/Kconfig
@@ -49,8 +49,6 @@ config USB_ULPI
49 Enable this to support ULPI connected USB OTG transceivers which 49 Enable this to support ULPI connected USB OTG transceivers which
50 are likely found on embedded boards. 50 are likely found on embedded boards.
51 51
52 The only chip currently supported is NXP's ISP1504
53
54config TWL4030_USB 52config TWL4030_USB
55 tristate "TWL4030 USB Transceiver Driver" 53 tristate "TWL4030 USB Transceiver Driver"
56 depends on TWL4030_CORE && REGULATOR_TWL4030 54 depends on TWL4030_CORE && REGULATOR_TWL4030
diff --git a/drivers/usb/otg/ulpi.c b/drivers/usb/otg/ulpi.c
index d331b222ad21..ccc81950822b 100644
--- a/drivers/usb/otg/ulpi.c
+++ b/drivers/usb/otg/ulpi.c
@@ -31,30 +31,110 @@
31 31
32#define ULPI_ID(vendor, product) (((vendor) << 16) | (product)) 32#define ULPI_ID(vendor, product) (((vendor) << 16) | (product))
33 33
34#define TR_FLAG(flags, a, b) (((flags) & a) ? b : 0)
35
36/* ULPI hardcoded IDs, used for probing */ 34/* ULPI hardcoded IDs, used for probing */
37static unsigned int ulpi_ids[] = { 35static unsigned int ulpi_ids[] = {
38 ULPI_ID(0x04cc, 0x1504), /* NXP ISP1504 */ 36 ULPI_ID(0x04cc, 0x1504), /* NXP ISP1504 */
37 ULPI_ID(0x0424, 0x0006), /* SMSC USB3319 */
39}; 38};
40 39
41static int ulpi_set_flags(struct otg_transceiver *otg) 40static int ulpi_set_otg_flags(struct otg_transceiver *otg)
42{ 41{
43 unsigned int flags = 0; 42 unsigned int flags = ULPI_OTG_CTRL_DP_PULLDOWN |
43 ULPI_OTG_CTRL_DM_PULLDOWN;
44 44
45 if (otg->flags & USB_OTG_PULLUP_ID) 45 if (otg->flags & ULPI_OTG_ID_PULLUP)
46 flags |= ULPI_OTG_CTRL_ID_PULLUP; 46 flags |= ULPI_OTG_CTRL_ID_PULLUP;
47 47
48 if (otg->flags & USB_OTG_PULLDOWN_DM) 48 /*
49 flags |= ULPI_OTG_CTRL_DM_PULLDOWN; 49 * ULPI Specification rev.1.1 default
50 * for Dp/DmPulldown is enabled.
51 */
52 if (otg->flags & ULPI_OTG_DP_PULLDOWN_DIS)
53 flags &= ~ULPI_OTG_CTRL_DP_PULLDOWN;
50 54
51 if (otg->flags & USB_OTG_PULLDOWN_DP) 55 if (otg->flags & ULPI_OTG_DM_PULLDOWN_DIS)
52 flags |= ULPI_OTG_CTRL_DP_PULLDOWN; 56 flags &= ~ULPI_OTG_CTRL_DM_PULLDOWN;
53 57
54 if (otg->flags & USB_OTG_EXT_VBUS_INDICATOR) 58 if (otg->flags & ULPI_OTG_EXTVBUSIND)
55 flags |= ULPI_OTG_CTRL_EXTVBUSIND; 59 flags |= ULPI_OTG_CTRL_EXTVBUSIND;
56 60
57 return otg_io_write(otg, flags, ULPI_SET(ULPI_OTG_CTRL)); 61 return otg_io_write(otg, flags, ULPI_OTG_CTRL);
62}
63
64static int ulpi_set_fc_flags(struct otg_transceiver *otg)
65{
66 unsigned int flags = 0;
67
68 /*
69 * ULPI Specification rev.1.1 default
70 * for XcvrSelect is Full Speed.
71 */
72 if (otg->flags & ULPI_FC_HS)
73 flags |= ULPI_FUNC_CTRL_HIGH_SPEED;
74 else if (otg->flags & ULPI_FC_LS)
75 flags |= ULPI_FUNC_CTRL_LOW_SPEED;
76 else if (otg->flags & ULPI_FC_FS4LS)
77 flags |= ULPI_FUNC_CTRL_FS4LS;
78 else
79 flags |= ULPI_FUNC_CTRL_FULL_SPEED;
80
81 if (otg->flags & ULPI_FC_TERMSEL)
82 flags |= ULPI_FUNC_CTRL_TERMSELECT;
83
84 /*
85 * ULPI Specification rev.1.1 default
86 * for OpMode is Normal Operation.
87 */
88 if (otg->flags & ULPI_FC_OP_NODRV)
89 flags |= ULPI_FUNC_CTRL_OPMODE_NONDRIVING;
90 else if (otg->flags & ULPI_FC_OP_DIS_NRZI)
91 flags |= ULPI_FUNC_CTRL_OPMODE_DISABLE_NRZI;
92 else if (otg->flags & ULPI_FC_OP_NSYNC_NEOP)
93 flags |= ULPI_FUNC_CTRL_OPMODE_NOSYNC_NOEOP;
94 else
95 flags |= ULPI_FUNC_CTRL_OPMODE_NORMAL;
96
97 /*
98 * ULPI Specification rev.1.1 default
99 * for SuspendM is Powered.
100 */
101 flags |= ULPI_FUNC_CTRL_SUSPENDM;
102
103 return otg_io_write(otg, flags, ULPI_FUNC_CTRL);
104}
105
106static int ulpi_set_ic_flags(struct otg_transceiver *otg)
107{
108 unsigned int flags = 0;
109
110 if (otg->flags & ULPI_IC_AUTORESUME)
111 flags |= ULPI_IFC_CTRL_AUTORESUME;
112
113 if (otg->flags & ULPI_IC_EXTVBUS_INDINV)
114 flags |= ULPI_IFC_CTRL_EXTERNAL_VBUS;
115
116 if (otg->flags & ULPI_IC_IND_PASSTHRU)
117 flags |= ULPI_IFC_CTRL_PASSTHRU;
118
119 if (otg->flags & ULPI_IC_PROTECT_DIS)
120 flags |= ULPI_IFC_CTRL_PROTECT_IFC_DISABLE;
121
122 return otg_io_write(otg, flags, ULPI_IFC_CTRL);
123}
124
125static int ulpi_set_flags(struct otg_transceiver *otg)
126{
127 int ret;
128
129 ret = ulpi_set_otg_flags(otg);
130 if (ret)
131 return ret;
132
133 ret = ulpi_set_ic_flags(otg);
134 if (ret)
135 return ret;
136
137 return ulpi_set_fc_flags(otg);
58} 138}
59 139
60static int ulpi_init(struct otg_transceiver *otg) 140static int ulpi_init(struct otg_transceiver *otg)
@@ -81,6 +161,31 @@ static int ulpi_init(struct otg_transceiver *otg)
81 return -ENODEV; 161 return -ENODEV;
82} 162}
83 163
164static int ulpi_set_host(struct otg_transceiver *otg, struct usb_bus *host)
165{
166 unsigned int flags = otg_io_read(otg, ULPI_IFC_CTRL);
167
168 if (!host) {
169 otg->host = NULL;
170 return 0;
171 }
172
173 otg->host = host;
174
175 flags &= ~(ULPI_IFC_CTRL_6_PIN_SERIAL_MODE |
176 ULPI_IFC_CTRL_3_PIN_SERIAL_MODE |
177 ULPI_IFC_CTRL_CARKITMODE);
178
179 if (otg->flags & ULPI_IC_6PIN_SERIAL)
180 flags |= ULPI_IFC_CTRL_6_PIN_SERIAL_MODE;
181 else if (otg->flags & ULPI_IC_3PIN_SERIAL)
182 flags |= ULPI_IFC_CTRL_3_PIN_SERIAL_MODE;
183 else if (otg->flags & ULPI_IC_CARKIT)
184 flags |= ULPI_IFC_CTRL_CARKITMODE;
185
186 return otg_io_write(otg, flags, ULPI_IFC_CTRL);
187}
188
84static int ulpi_set_vbus(struct otg_transceiver *otg, bool on) 189static int ulpi_set_vbus(struct otg_transceiver *otg, bool on)
85{ 190{
86 unsigned int flags = otg_io_read(otg, ULPI_OTG_CTRL); 191 unsigned int flags = otg_io_read(otg, ULPI_OTG_CTRL);
@@ -88,14 +193,14 @@ static int ulpi_set_vbus(struct otg_transceiver *otg, bool on)
88 flags &= ~(ULPI_OTG_CTRL_DRVVBUS | ULPI_OTG_CTRL_DRVVBUS_EXT); 193 flags &= ~(ULPI_OTG_CTRL_DRVVBUS | ULPI_OTG_CTRL_DRVVBUS_EXT);
89 194
90 if (on) { 195 if (on) {
91 if (otg->flags & USB_OTG_DRV_VBUS) 196 if (otg->flags & ULPI_OTG_DRVVBUS)
92 flags |= ULPI_OTG_CTRL_DRVVBUS; 197 flags |= ULPI_OTG_CTRL_DRVVBUS;
93 198
94 if (otg->flags & USB_OTG_DRV_VBUS_EXT) 199 if (otg->flags & ULPI_OTG_DRVVBUS_EXT)
95 flags |= ULPI_OTG_CTRL_DRVVBUS_EXT; 200 flags |= ULPI_OTG_CTRL_DRVVBUS_EXT;
96 } 201 }
97 202
98 return otg_io_write(otg, flags, ULPI_SET(ULPI_OTG_CTRL)); 203 return otg_io_write(otg, flags, ULPI_OTG_CTRL);
99} 204}
100 205
101struct otg_transceiver * 206struct otg_transceiver *
@@ -112,6 +217,7 @@ otg_ulpi_create(struct otg_io_access_ops *ops,
112 otg->flags = flags; 217 otg->flags = flags;
113 otg->io_ops = ops; 218 otg->io_ops = ops;
114 otg->init = ulpi_init; 219 otg->init = ulpi_init;
220 otg->set_host = ulpi_set_host;
115 otg->set_vbus = ulpi_set_vbus; 221 otg->set_vbus = ulpi_set_vbus;
116 222
117 return otg; 223 return otg;
diff --git a/drivers/usb/serial/Kconfig b/drivers/usb/serial/Kconfig
index bd8aab0ef1cf..916b2b6d765f 100644
--- a/drivers/usb/serial/Kconfig
+++ b/drivers/usb/serial/Kconfig
@@ -642,6 +642,15 @@ config USB_SERIAL_ZIO
642 To compile this driver as a module, choose M here: the 642 To compile this driver as a module, choose M here: the
643 module will be called zio. 643 module will be called zio.
644 644
645config USB_SERIAL_SSU100
646 tristate "USB Quatech SSU-100 Single Port Serial Driver"
647 help
648 Say Y here if you want to use the Quatech SSU-100 single
649 port usb to serial adapter.
650
651 To compile this driver as a module, choose M here: the
652 module will be called ssu100.
653
645config USB_SERIAL_DEBUG 654config USB_SERIAL_DEBUG
646 tristate "USB Debugging Device" 655 tristate "USB Debugging Device"
647 help 656 help
diff --git a/drivers/usb/serial/Makefile b/drivers/usb/serial/Makefile
index e54c728c016e..40ebe17b6ea8 100644
--- a/drivers/usb/serial/Makefile
+++ b/drivers/usb/serial/Makefile
@@ -51,6 +51,7 @@ obj-$(CONFIG_USB_SERIAL_SAFE) += safe_serial.o
51obj-$(CONFIG_USB_SERIAL_SIEMENS_MPI) += siemens_mpi.o 51obj-$(CONFIG_USB_SERIAL_SIEMENS_MPI) += siemens_mpi.o
52obj-$(CONFIG_USB_SERIAL_SIERRAWIRELESS) += sierra.o 52obj-$(CONFIG_USB_SERIAL_SIERRAWIRELESS) += sierra.o
53obj-$(CONFIG_USB_SERIAL_SPCP8X5) += spcp8x5.o 53obj-$(CONFIG_USB_SERIAL_SPCP8X5) += spcp8x5.o
54obj-$(CONFIG_USB_SERIAL_SSU100) += ssu100.o
54obj-$(CONFIG_USB_SERIAL_SYMBOL) += symbolserial.o 55obj-$(CONFIG_USB_SERIAL_SYMBOL) += symbolserial.o
55obj-$(CONFIG_USB_SERIAL_WWAN) += usb_wwan.o 56obj-$(CONFIG_USB_SERIAL_WWAN) += usb_wwan.o
56obj-$(CONFIG_USB_SERIAL_TI) += ti_usb_3410_5052.o 57obj-$(CONFIG_USB_SERIAL_TI) += ti_usb_3410_5052.o
diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
index 8b8c7976b4c0..2bef4415c19c 100644
--- a/drivers/usb/serial/cp210x.c
+++ b/drivers/usb/serial/cp210x.c
@@ -126,6 +126,10 @@ static const struct usb_device_id id_table[] = {
126 { USB_DEVICE(0x1843, 0x0200) }, /* Vaisala USB Instrument Cable */ 126 { USB_DEVICE(0x1843, 0x0200) }, /* Vaisala USB Instrument Cable */
127 { USB_DEVICE(0x18EF, 0xE00F) }, /* ELV USB-I2C-Interface */ 127 { USB_DEVICE(0x18EF, 0xE00F) }, /* ELV USB-I2C-Interface */
128 { USB_DEVICE(0x413C, 0x9500) }, /* DW700 GPS USB interface */ 128 { USB_DEVICE(0x413C, 0x9500) }, /* DW700 GPS USB interface */
129 { USB_DEVICE(0x16DC, 0x0010) }, /* W-IE-NE-R Plein & Baus GmbH PL512 Power Supply */
130 { USB_DEVICE(0x16DC, 0x0011) }, /* W-IE-NE-R Plein & Baus GmbH RCM Remote Control for MARATON Power Supply */
131 { USB_DEVICE(0x16DC, 0x0012) }, /* W-IE-NE-R Plein & Baus GmbH MPOD Multi Channel Power Supply */
132 { USB_DEVICE(0x16DC, 0x0015) }, /* W-IE-NE-R Plein & Baus GmbH CML Control, Monitoring and Data Logger */
129 { } /* Terminating Entry */ 133 { } /* Terminating Entry */
130}; 134};
131 135
diff --git a/drivers/usb/serial/digi_acceleport.c b/drivers/usb/serial/digi_acceleport.c
index fd35f73b5721..b92070c103cd 100644
--- a/drivers/usb/serial/digi_acceleport.c
+++ b/drivers/usb/serial/digi_acceleport.c
@@ -609,8 +609,10 @@ static void digi_wakeup_write_lock(struct work_struct *work)
609static void digi_wakeup_write(struct usb_serial_port *port) 609static void digi_wakeup_write(struct usb_serial_port *port)
610{ 610{
611 struct tty_struct *tty = tty_port_tty_get(&port->port); 611 struct tty_struct *tty = tty_port_tty_get(&port->port);
612 tty_wakeup(tty); 612 if (tty) {
613 tty_kref_put(tty); 613 tty_wakeup(tty);
614 tty_kref_put(tty);
615 }
614} 616}
615 617
616 618
@@ -1682,7 +1684,7 @@ static int digi_read_inb_callback(struct urb *urb)
1682 priv->dp_throttle_restart = 1; 1684 priv->dp_throttle_restart = 1;
1683 1685
1684 /* receive data */ 1686 /* receive data */
1685 if (opcode == DIGI_CMD_RECEIVE_DATA) { 1687 if (tty && opcode == DIGI_CMD_RECEIVE_DATA) {
1686 /* get flag from port_status */ 1688 /* get flag from port_status */
1687 flag = 0; 1689 flag = 0;
1688 1690
@@ -1763,10 +1765,12 @@ static int digi_read_oob_callback(struct urb *urb)
1763 return -1; 1765 return -1;
1764 1766
1765 tty = tty_port_tty_get(&port->port); 1767 tty = tty_port_tty_get(&port->port);
1768
1766 rts = 0; 1769 rts = 0;
1767 rts = tty->termios->c_cflag & CRTSCTS; 1770 if (tty)
1771 rts = tty->termios->c_cflag & CRTSCTS;
1768 1772
1769 if (opcode == DIGI_CMD_READ_INPUT_SIGNALS) { 1773 if (tty && opcode == DIGI_CMD_READ_INPUT_SIGNALS) {
1770 spin_lock(&priv->dp_port_lock); 1774 spin_lock(&priv->dp_port_lock);
1771 /* convert from digi flags to termiox flags */ 1775 /* convert from digi flags to termiox flags */
1772 if (val & DIGI_READ_INPUT_SIGNALS_CTS) { 1776 if (val & DIGI_READ_INPUT_SIGNALS_CTS) {
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index e298dc4baed7..eb12d9b096b4 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -157,6 +157,9 @@ static struct usb_device_id id_table_combined [] = {
157 { USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_5_PID) }, 157 { USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_5_PID) },
158 { USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_6_PID) }, 158 { USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_6_PID) },
159 { USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_7_PID) }, 159 { USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_7_PID) },
160 { USB_DEVICE(FTDI_VID, FTDI_USINT_CAT_PID) },
161 { USB_DEVICE(FTDI_VID, FTDI_USINT_WKEY_PID) },
162 { USB_DEVICE(FTDI_VID, FTDI_USINT_RS232_PID) },
160 { USB_DEVICE(FTDI_VID, FTDI_ACTZWAVE_PID) }, 163 { USB_DEVICE(FTDI_VID, FTDI_ACTZWAVE_PID) },
161 { USB_DEVICE(FTDI_VID, FTDI_IRTRANS_PID) }, 164 { USB_DEVICE(FTDI_VID, FTDI_IRTRANS_PID) },
162 { USB_DEVICE(FTDI_VID, FTDI_IPLUS_PID) }, 165 { USB_DEVICE(FTDI_VID, FTDI_IPLUS_PID) },
@@ -746,6 +749,7 @@ static struct usb_device_id id_table_combined [] = {
746 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, 749 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
747 { USB_DEVICE(FTDI_VID, XVERVE_SIGNALYZER_SH4_PID), 750 { USB_DEVICE(FTDI_VID, XVERVE_SIGNALYZER_SH4_PID),
748 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, 751 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
752 { USB_DEVICE(FTDI_VID, SEGWAY_RMP200_PID) },
749 { }, /* Optional parameter entry */ 753 { }, /* Optional parameter entry */
750 { } /* Terminating entry */ 754 { } /* Terminating entry */
751}; 755};
diff --git a/drivers/usb/serial/ftdi_sio_ids.h b/drivers/usb/serial/ftdi_sio_ids.h
index d01946db8fac..6e612c52e763 100644
--- a/drivers/usb/serial/ftdi_sio_ids.h
+++ b/drivers/usb/serial/ftdi_sio_ids.h
@@ -40,6 +40,11 @@
40 40
41#define FTDI_NXTCAM_PID 0xABB8 /* NXTCam for Mindstorms NXT */ 41#define FTDI_NXTCAM_PID 0xABB8 /* NXTCam for Mindstorms NXT */
42 42
43/* US Interface Navigator (http://www.usinterface.com/) */
44#define FTDI_USINT_CAT_PID 0xb810 /* Navigator CAT and 2nd PTT lines */
45#define FTDI_USINT_WKEY_PID 0xb811 /* Navigator WKEY and FSK lines */
46#define FTDI_USINT_RS232_PID 0xb812 /* Navigator RS232 and CONFIG lines */
47
43/* OOCDlink by Joern Kaipf <joernk@web.de> 48/* OOCDlink by Joern Kaipf <joernk@web.de>
44 * (http://www.joernonline.de/dw/doku.php?id=start&idx=projects:oocdlink) */ 49 * (http://www.joernonline.de/dw/doku.php?id=start&idx=projects:oocdlink) */
45#define FTDI_OOCDLINK_PID 0xbaf8 /* Amontec JTAGkey */ 50#define FTDI_OOCDLINK_PID 0xbaf8 /* Amontec JTAGkey */
@@ -1032,3 +1037,8 @@
1032#define XVERVE_SIGNALYZER_SH2_PID 0xBCA2 1037#define XVERVE_SIGNALYZER_SH2_PID 0xBCA2
1033#define XVERVE_SIGNALYZER_SH4_PID 0xBCA4 1038#define XVERVE_SIGNALYZER_SH4_PID 0xBCA4
1034 1039
1040/*
1041 * Segway Robotic Mobility Platform USB interface (using VID 0x0403)
1042 * Submitted by John G. Rogers
1043 */
1044#define SEGWAY_RMP200_PID 0xe729
diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c
index a817ced82835..ca92f67747cc 100644
--- a/drivers/usb/serial/generic.c
+++ b/drivers/usb/serial/generic.c
@@ -208,18 +208,23 @@ retry:
208 urb->transfer_buffer_length = count; 208 urb->transfer_buffer_length = count;
209 usb_serial_debug_data(debug, &port->dev, __func__, count, 209 usb_serial_debug_data(debug, &port->dev, __func__, count,
210 urb->transfer_buffer); 210 urb->transfer_buffer);
211 spin_lock_irqsave(&port->lock, flags);
212 port->tx_bytes += count;
213 spin_unlock_irqrestore(&port->lock, flags);
214
215 clear_bit(i, &port->write_urbs_free);
211 result = usb_submit_urb(urb, GFP_ATOMIC); 216 result = usb_submit_urb(urb, GFP_ATOMIC);
212 if (result) { 217 if (result) {
213 dev_err(&port->dev, "%s - error submitting urb: %d\n", 218 dev_err(&port->dev, "%s - error submitting urb: %d\n",
214 __func__, result); 219 __func__, result);
220 set_bit(i, &port->write_urbs_free);
221 spin_lock_irqsave(&port->lock, flags);
222 port->tx_bytes -= count;
223 spin_unlock_irqrestore(&port->lock, flags);
224
215 clear_bit_unlock(USB_SERIAL_WRITE_BUSY, &port->flags); 225 clear_bit_unlock(USB_SERIAL_WRITE_BUSY, &port->flags);
216 return result; 226 return result;
217 } 227 }
218 clear_bit(i, &port->write_urbs_free);
219
220 spin_lock_irqsave(&port->lock, flags);
221 port->tx_bytes += count;
222 spin_unlock_irqrestore(&port->lock, flags);
223 228
224 /* Try sending off another urb, unless in irq context (in which case 229 /* Try sending off another urb, unless in irq context (in which case
225 * there will be no free urb). */ 230 * there will be no free urb). */
diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c
index 0fca2659206f..dc47f986df57 100644
--- a/drivers/usb/serial/io_ti.c
+++ b/drivers/usb/serial/io_ti.c
@@ -1298,7 +1298,7 @@ static int download_fw(struct edgeport_serial *serial)
1298 kfree(header); 1298 kfree(header);
1299 kfree(rom_desc); 1299 kfree(rom_desc);
1300 kfree(ti_manuf_desc); 1300 kfree(ti_manuf_desc);
1301 return status; 1301 return -EINVAL;
1302 } 1302 }
1303 1303
1304 /* verify the write -- must do this in order for 1304 /* verify the write -- must do this in order for
@@ -1321,7 +1321,7 @@ static int download_fw(struct edgeport_serial *serial)
1321 kfree(header); 1321 kfree(header);
1322 kfree(rom_desc); 1322 kfree(rom_desc);
1323 kfree(ti_manuf_desc); 1323 kfree(ti_manuf_desc);
1324 return status; 1324 return -EINVAL;
1325 } 1325 }
1326 1326
1327 kfree(vheader); 1327 kfree(vheader);
diff --git a/drivers/usb/serial/ipaq.c b/drivers/usb/serial/ipaq.c
index 28913fa95fb7..4735931b4c7b 100644
--- a/drivers/usb/serial/ipaq.c
+++ b/drivers/usb/serial/ipaq.c
@@ -534,7 +534,6 @@ static struct usb_device_id ipaq_id_table [] = {
534 { USB_DEVICE(0x413C, 0x4009) }, /* Dell Axim USB Sync */ 534 { USB_DEVICE(0x413C, 0x4009) }, /* Dell Axim USB Sync */
535 { USB_DEVICE(0x4505, 0x0010) }, /* Smartphone */ 535 { USB_DEVICE(0x4505, 0x0010) }, /* Smartphone */
536 { USB_DEVICE(0x5E04, 0xCE00) }, /* SAGEM Wireless Assistant */ 536 { USB_DEVICE(0x5E04, 0xCE00) }, /* SAGEM Wireless Assistant */
537 { USB_DEVICE(0x0BB4, 0x00CF) }, /* HTC smartphone modems */
538 { } /* Terminating entry */ 537 { } /* Terminating entry */
539}; 538};
540 539
diff --git a/drivers/usb/serial/iuu_phoenix.c b/drivers/usb/serial/iuu_phoenix.c
index 74551cb2e8ee..efc72113216b 100644
--- a/drivers/usb/serial/iuu_phoenix.c
+++ b/drivers/usb/serial/iuu_phoenix.c
@@ -1,6 +1,8 @@
1/* 1/*
2 * Infinity Unlimited USB Phoenix driver 2 * Infinity Unlimited USB Phoenix driver
3 * 3 *
4 * Copyright (C) 2010 James Courtier-Dutton (James@superbug.co.uk)
5
4 * Copyright (C) 2007 Alain Degreffe (eczema@ecze.com) 6 * Copyright (C) 2007 Alain Degreffe (eczema@ecze.com)
5 * 7 *
6 * Original code taken from iuutool (Copyright (C) 2006 Juan Carlos Borrás) 8 * Original code taken from iuutool (Copyright (C) 2006 Juan Carlos Borrás)
@@ -40,7 +42,7 @@ static int debug;
40/* 42/*
41 * Version Information 43 * Version Information
42 */ 44 */
43#define DRIVER_VERSION "v0.11" 45#define DRIVER_VERSION "v0.12"
44#define DRIVER_DESC "Infinity USB Unlimited Phoenix driver" 46#define DRIVER_DESC "Infinity USB Unlimited Phoenix driver"
45 47
46static const struct usb_device_id id_table[] = { 48static const struct usb_device_id id_table[] = {
@@ -81,6 +83,9 @@ struct iuu_private {
81 u8 *dbgbuf; /* debug buffer */ 83 u8 *dbgbuf; /* debug buffer */
82 u8 len; 84 u8 len;
83 int vcc; /* vcc (either 3 or 5 V) */ 85 int vcc; /* vcc (either 3 or 5 V) */
86 u32 baud;
87 u32 boost;
88 u32 clk;
84}; 89};
85 90
86 91
@@ -157,13 +162,14 @@ static int iuu_tiocmset(struct tty_struct *tty, struct file *file,
157 port->number, set, clear); 162 port->number, set, clear);
158 163
159 spin_lock_irqsave(&priv->lock, flags); 164 spin_lock_irqsave(&priv->lock, flags);
160 if (set & TIOCM_RTS)
161 priv->tiostatus = TIOCM_RTS;
162 165
163 if (!(set & TIOCM_RTS) && priv->tiostatus == TIOCM_RTS) { 166 if ((set & TIOCM_RTS) && !(priv->tiostatus == TIOCM_RTS)) {
164 dbg("%s TIOCMSET RESET called !!!", __func__); 167 dbg("%s TIOCMSET RESET called !!!", __func__);
165 priv->reset = 1; 168 priv->reset = 1;
166 } 169 }
170 if (set & TIOCM_RTS)
171 priv->tiostatus = TIOCM_RTS;
172
167 spin_unlock_irqrestore(&priv->lock, flags); 173 spin_unlock_irqrestore(&priv->lock, flags);
168 return 0; 174 return 0;
169} 175}
@@ -851,20 +857,24 @@ static int iuu_uart_off(struct usb_serial_port *port)
851 return status; 857 return status;
852} 858}
853 859
854static int iuu_uart_baud(struct usb_serial_port *port, u32 baud, 860static int iuu_uart_baud(struct usb_serial_port *port, u32 baud_base,
855 u32 *actual, u8 parity) 861 u32 *actual, u8 parity)
856{ 862{
857 int status; 863 int status;
864 u32 baud;
858 u8 *dataout; 865 u8 *dataout;
859 u8 DataCount = 0; 866 u8 DataCount = 0;
860 u8 T1Frekvens = 0; 867 u8 T1Frekvens = 0;
861 u8 T1reload = 0; 868 u8 T1reload = 0;
862 unsigned int T1FrekvensHZ = 0; 869 unsigned int T1FrekvensHZ = 0;
863 870
871 dbg("%s - enter baud_base=%d", __func__, baud_base);
864 dataout = kmalloc(sizeof(u8) * 5, GFP_KERNEL); 872 dataout = kmalloc(sizeof(u8) * 5, GFP_KERNEL);
865 873
866 if (!dataout) 874 if (!dataout)
867 return -ENOMEM; 875 return -ENOMEM;
876 /*baud = (((priv->clk / 35) * baud_base) / 100000); */
877 baud = baud_base;
868 878
869 if (baud < 1200 || baud > 230400) { 879 if (baud < 1200 || baud > 230400) {
870 kfree(dataout); 880 kfree(dataout);
@@ -948,15 +958,20 @@ static void iuu_set_termios(struct tty_struct *tty,
948 struct usb_serial_port *port, struct ktermios *old_termios) 958 struct usb_serial_port *port, struct ktermios *old_termios)
949{ 959{
950 const u32 supported_mask = CMSPAR|PARENB|PARODD; 960 const u32 supported_mask = CMSPAR|PARENB|PARODD;
951 961 struct iuu_private *priv = usb_get_serial_port_data(port);
952 unsigned int cflag = tty->termios->c_cflag; 962 unsigned int cflag = tty->termios->c_cflag;
953 int status; 963 int status;
954 u32 actual; 964 u32 actual;
955 u32 parity; 965 u32 parity;
956 int csize = CS7; 966 int csize = CS7;
957 int baud = 9600; /* Fixed for the moment */ 967 int baud;
958 u32 newval = cflag & supported_mask; 968 u32 newval = cflag & supported_mask;
959 969
970 /* Just use the ospeed. ispeed should be the same. */
971 baud = tty->termios->c_ospeed;
972
973 dbg("%s - enter c_ospeed or baud=%d", __func__, baud);
974
960 /* compute the parity parameter */ 975 /* compute the parity parameter */
961 parity = 0; 976 parity = 0;
962 if (cflag & CMSPAR) { /* Using mark space */ 977 if (cflag & CMSPAR) { /* Using mark space */
@@ -976,15 +991,15 @@ static void iuu_set_termios(struct tty_struct *tty,
976 991
977 /* set it */ 992 /* set it */
978 status = iuu_uart_baud(port, 993 status = iuu_uart_baud(port,
979 (clockmode == 2) ? 16457 : 9600 * boost / 100, 994 baud * priv->boost / 100,
980 &actual, parity); 995 &actual, parity);
981 996
982 /* set the termios value to the real one, so the user now what has 997 /* set the termios value to the real one, so the user now what has
983 * changed. We support few fields so its easies to copy the old hw 998 * changed. We support few fields so its easies to copy the old hw
984 * settings back over and then adjust them 999 * settings back over and then adjust them
985 */ 1000 */
986 if (old_termios) 1001 if (old_termios)
987 tty_termios_copy_hw(tty->termios, old_termios); 1002 tty_termios_copy_hw(tty->termios, old_termios);
988 if (status != 0) /* Set failed - return old bits */ 1003 if (status != 0) /* Set failed - return old bits */
989 return; 1004 return;
990 /* Re-encode speed, parity and csize */ 1005 /* Re-encode speed, parity and csize */
@@ -1018,6 +1033,7 @@ static void iuu_close(struct usb_serial_port *port)
1018 1033
1019static void iuu_init_termios(struct tty_struct *tty) 1034static void iuu_init_termios(struct tty_struct *tty)
1020{ 1035{
1036 dbg("%s - enter", __func__);
1021 *(tty->termios) = tty_std_termios; 1037 *(tty->termios) = tty_std_termios;
1022 tty->termios->c_cflag = CLOCAL | CREAD | CS8 | B9600 1038 tty->termios->c_cflag = CLOCAL | CREAD | CS8 | B9600
1023 | TIOCM_CTS | CSTOPB | PARENB; 1039 | TIOCM_CTS | CSTOPB | PARENB;
@@ -1033,10 +1049,16 @@ static int iuu_open(struct tty_struct *tty, struct usb_serial_port *port)
1033 struct usb_serial *serial = port->serial; 1049 struct usb_serial *serial = port->serial;
1034 u8 *buf; 1050 u8 *buf;
1035 int result; 1051 int result;
1052 int baud;
1036 u32 actual; 1053 u32 actual;
1037 struct iuu_private *priv = usb_get_serial_port_data(port); 1054 struct iuu_private *priv = usb_get_serial_port_data(port);
1038 1055
1039 dbg("%s - port %d", __func__, port->number); 1056 baud = tty->termios->c_ospeed;
1057 tty->termios->c_ispeed = baud;
1058 /* Re-encode speed */
1059 tty_encode_baud_rate(tty, baud, baud);
1060
1061 dbg("%s - port %d, baud %d", __func__, port->number, baud);
1040 usb_clear_halt(serial->dev, port->write_urb->pipe); 1062 usb_clear_halt(serial->dev, port->write_urb->pipe);
1041 usb_clear_halt(serial->dev, port->read_urb->pipe); 1063 usb_clear_halt(serial->dev, port->read_urb->pipe);
1042 1064
@@ -1071,23 +1093,29 @@ static int iuu_open(struct tty_struct *tty, struct usb_serial_port *port)
1071 iuu_uart_on(port); 1093 iuu_uart_on(port);
1072 if (boost < 100) 1094 if (boost < 100)
1073 boost = 100; 1095 boost = 100;
1096 priv->boost = boost;
1097 priv->baud = baud;
1074 switch (clockmode) { 1098 switch (clockmode) {
1075 case 2: /* 3.680 Mhz */ 1099 case 2: /* 3.680 Mhz */
1100 priv->clk = IUU_CLK_3680000;
1076 iuu_clk(port, IUU_CLK_3680000 * boost / 100); 1101 iuu_clk(port, IUU_CLK_3680000 * boost / 100);
1077 result = 1102 result =
1078 iuu_uart_baud(port, 9600 * boost / 100, &actual, 1103 iuu_uart_baud(port, baud * boost / 100, &actual,
1079 IUU_PARITY_EVEN); 1104 IUU_PARITY_EVEN);
1080 break; 1105 break;
1081 case 3: /* 6.00 Mhz */ 1106 case 3: /* 6.00 Mhz */
1082 iuu_clk(port, IUU_CLK_6000000 * boost / 100); 1107 iuu_clk(port, IUU_CLK_6000000 * boost / 100);
1108 priv->clk = IUU_CLK_6000000;
1109 /* Ratio of 6000000 to 3500000 for baud 9600 */
1083 result = 1110 result =
1084 iuu_uart_baud(port, 16457 * boost / 100, &actual, 1111 iuu_uart_baud(port, 16457 * boost / 100, &actual,
1085 IUU_PARITY_EVEN); 1112 IUU_PARITY_EVEN);
1086 break; 1113 break;
1087 default: /* 3.579 Mhz */ 1114 default: /* 3.579 Mhz */
1088 iuu_clk(port, IUU_CLK_3579000 * boost / 100); 1115 iuu_clk(port, IUU_CLK_3579000 * boost / 100);
1116 priv->clk = IUU_CLK_3579000;
1089 result = 1117 result =
1090 iuu_uart_baud(port, 9600 * boost / 100, &actual, 1118 iuu_uart_baud(port, baud * boost / 100, &actual,
1091 IUU_PARITY_EVEN); 1119 IUU_PARITY_EVEN);
1092 } 1120 }
1093 1121
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
index 5cd30e4345c6..9fc6ea2c681f 100644
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -145,7 +145,10 @@ static void option_instat_callback(struct urb *urb);
145#define HUAWEI_PRODUCT_E143D 0x143D 145#define HUAWEI_PRODUCT_E143D 0x143D
146#define HUAWEI_PRODUCT_E143E 0x143E 146#define HUAWEI_PRODUCT_E143E 0x143E
147#define HUAWEI_PRODUCT_E143F 0x143F 147#define HUAWEI_PRODUCT_E143F 0x143F
148#define HUAWEI_PRODUCT_K4505 0x1464
149#define HUAWEI_PRODUCT_K3765 0x1465
148#define HUAWEI_PRODUCT_E14AC 0x14AC 150#define HUAWEI_PRODUCT_E14AC 0x14AC
151#define HUAWEI_PRODUCT_ETS1220 0x1803
149 152
150#define QUANTA_VENDOR_ID 0x0408 153#define QUANTA_VENDOR_ID 0x0408
151#define QUANTA_PRODUCT_Q101 0xEA02 154#define QUANTA_PRODUCT_Q101 0xEA02
@@ -264,9 +267,6 @@ static void option_instat_callback(struct urb *urb);
264#define BANDRICH_PRODUCT_1011 0x1011 267#define BANDRICH_PRODUCT_1011 0x1011
265#define BANDRICH_PRODUCT_1012 0x1012 268#define BANDRICH_PRODUCT_1012 0x1012
266 269
267#define AMOI_VENDOR_ID 0x1614
268#define AMOI_PRODUCT_9508 0x0800
269
270#define QUALCOMM_VENDOR_ID 0x05C6 270#define QUALCOMM_VENDOR_ID 0x05C6
271 271
272#define CMOTECH_VENDOR_ID 0x16d8 272#define CMOTECH_VENDOR_ID 0x16d8
@@ -482,8 +482,10 @@ static const struct usb_device_id option_ids[] = {
482 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E143D, 0xff, 0xff, 0xff) }, 482 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E143D, 0xff, 0xff, 0xff) },
483 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E143E, 0xff, 0xff, 0xff) }, 483 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E143E, 0xff, 0xff, 0xff) },
484 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E143F, 0xff, 0xff, 0xff) }, 484 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E143F, 0xff, 0xff, 0xff) },
485 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K4505, 0xff, 0xff, 0xff) },
486 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K3765, 0xff, 0xff, 0xff) },
487 { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_ETS1220, 0xff, 0xff, 0xff) },
485 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E14AC) }, 488 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E14AC) },
486 { USB_DEVICE(AMOI_VENDOR_ID, AMOI_PRODUCT_9508) },
487 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_V640) }, /* Novatel Merlin V640/XV620 */ 489 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_V640) }, /* Novatel Merlin V640/XV620 */
488 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_V620) }, /* Novatel Merlin V620/S620 */ 490 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_V620) }, /* Novatel Merlin V620/S620 */
489 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_V740) }, /* Novatel Merlin EX720/V740/X720 */ 491 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_V740) }, /* Novatel Merlin EX720/V740/X720 */
@@ -1017,6 +1019,13 @@ static int option_probe(struct usb_serial *serial,
1017 serial->interface->cur_altsetting->desc.bInterfaceClass != 0xff) 1019 serial->interface->cur_altsetting->desc.bInterfaceClass != 0xff)
1018 return -ENODEV; 1020 return -ENODEV;
1019 1021
1022 /* Don't bind network interfaces on Huawei K3765 & K4505 */
1023 if (serial->dev->descriptor.idVendor == HUAWEI_VENDOR_ID &&
1024 (serial->dev->descriptor.idProduct == HUAWEI_PRODUCT_K3765 ||
1025 serial->dev->descriptor.idProduct == HUAWEI_PRODUCT_K4505) &&
1026 serial->interface->cur_altsetting->desc.bInterfaceNumber == 1)
1027 return -ENODEV;
1028
1020 data = serial->private = kzalloc(sizeof(struct usb_wwan_intf_private), GFP_KERNEL); 1029 data = serial->private = kzalloc(sizeof(struct usb_wwan_intf_private), GFP_KERNEL);
1021 1030
1022 if (!data) 1031 if (!data)
diff --git a/drivers/usb/serial/ssu100.c b/drivers/usb/serial/ssu100.c
new file mode 100644
index 000000000000..6e82d4f54bc8
--- /dev/null
+++ b/drivers/usb/serial/ssu100.c
@@ -0,0 +1,698 @@
1/*
2 * usb-serial driver for Quatech SSU-100
3 *
4 * based on ftdi_sio.c and the original serqt_usb.c from Quatech
5 *
6 */
7
8#include <linux/errno.h>
9#include <linux/init.h>
10#include <linux/slab.h>
11#include <linux/tty.h>
12#include <linux/tty_driver.h>
13#include <linux/tty_flip.h>
14#include <linux/module.h>
15#include <linux/serial.h>
16#include <linux/usb.h>
17#include <linux/usb/serial.h>
18#include <linux/uaccess.h>
19
20#define QT_OPEN_CLOSE_CHANNEL 0xca
21#define QT_SET_GET_DEVICE 0xc2
22#define QT_SET_GET_REGISTER 0xc0
23#define QT_GET_SET_PREBUF_TRIG_LVL 0xcc
24#define QT_SET_ATF 0xcd
25#define QT_GET_SET_UART 0xc1
26#define QT_TRANSFER_IN 0xc0
27#define QT_HW_FLOW_CONTROL_MASK 0xc5
28#define QT_SW_FLOW_CONTROL_MASK 0xc6
29
30#define MODEM_CTL_REGISTER 0x04
31#define MODEM_STATUS_REGISTER 0x06
32
33
34#define SERIAL_LSR_OE 0x02
35#define SERIAL_LSR_PE 0x04
36#define SERIAL_LSR_FE 0x08
37#define SERIAL_LSR_BI 0x10
38
39#define SERIAL_LSR_TEMT 0x40
40
41#define SERIAL_MCR_DTR 0x01
42#define SERIAL_MCR_RTS 0x02
43#define SERIAL_MCR_LOOP 0x10
44
45#define SERIAL_MSR_CTS 0x10
46#define SERIAL_MSR_CD 0x80
47#define SERIAL_MSR_RI 0x40
48#define SERIAL_MSR_DSR 0x20
49#define SERIAL_MSR_MASK 0xf0
50
51#define SERIAL_CRTSCTS ((SERIAL_MCR_RTS << 8) | SERIAL_MSR_CTS)
52
53#define SERIAL_8_DATA 0x03
54#define SERIAL_7_DATA 0x02
55#define SERIAL_6_DATA 0x01
56#define SERIAL_5_DATA 0x00
57
58#define SERIAL_ODD_PARITY 0X08
59#define SERIAL_EVEN_PARITY 0X18
60
61#define MAX_BAUD_RATE 460800
62
63#define ATC_DISABLED 0x00
64#define DUPMODE_BITS 0xc0
65#define RR_BITS 0x03
66#define LOOPMODE_BITS 0x41
67#define RS232_MODE 0x00
68#define RTSCTS_TO_CONNECTOR 0x40
69#define CLKS_X4 0x02
70#define FULLPWRBIT 0x00000080
71#define NEXT_BOARD_POWER_BIT 0x00000004
72
73static int debug = 1;
74
75/* Version Information */
76#define DRIVER_VERSION "v0.1"
77#define DRIVER_DESC "Quatech SSU-100 USB to Serial Driver"
78
79#define USB_VENDOR_ID_QUATECH 0x061d /* Quatech VID */
80#define QUATECH_SSU100 0xC020 /* SSU100 */
81
82static const struct usb_device_id id_table[] = {
83 {USB_DEVICE(USB_VENDOR_ID_QUATECH, QUATECH_SSU100)},
84 {} /* Terminating entry */
85};
86
87MODULE_DEVICE_TABLE(usb, id_table);
88
89
90static struct usb_driver ssu100_driver = {
91 .name = "ssu100",
92 .probe = usb_serial_probe,
93 .disconnect = usb_serial_disconnect,
94 .id_table = id_table,
95 .suspend = usb_serial_suspend,
96 .resume = usb_serial_resume,
97 .no_dynamic_id = 1,
98 .supports_autosuspend = 1,
99};
100
101struct ssu100_port_private {
102 u8 shadowLSR;
103 u8 shadowMSR;
104 wait_queue_head_t delta_msr_wait; /* Used for TIOCMIWAIT */
105 unsigned short max_packet_size;
106};
107
108static void ssu100_release(struct usb_serial *serial)
109{
110 struct ssu100_port_private *priv = usb_get_serial_port_data(*serial->port);
111
112 dbg("%s", __func__);
113 kfree(priv);
114}
115
116static inline int ssu100_control_msg(struct usb_device *dev,
117 u8 request, u16 data, u16 index)
118{
119 return usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
120 request, 0x40, data, index,
121 NULL, 0, 300);
122}
123
124static inline int ssu100_setdevice(struct usb_device *dev, u8 *data)
125{
126 u16 x = ((u16)(data[1] << 8) | (u16)(data[0]));
127
128 return ssu100_control_msg(dev, QT_SET_GET_DEVICE, x, 0);
129}
130
131
132static inline int ssu100_getdevice(struct usb_device *dev, u8 *data)
133{
134 return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
135 QT_SET_GET_DEVICE, 0xc0, 0, 0,
136 data, 3, 300);
137}
138
139static inline int ssu100_getregister(struct usb_device *dev,
140 unsigned short uart,
141 unsigned short reg,
142 u8 *data)
143{
144 return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
145 QT_SET_GET_REGISTER, 0xc0, reg,
146 uart, data, sizeof(*data), 300);
147
148}
149
150
151static inline int ssu100_setregister(struct usb_device *dev,
152 unsigned short uart,
153 u16 data)
154{
155 u16 value = (data << 8) | MODEM_CTL_REGISTER;
156
157 return usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
158 QT_SET_GET_REGISTER, 0x40, value, uart,
159 NULL, 0, 300);
160
161}
162
163#define set_mctrl(dev, set) update_mctrl((dev), (set), 0)
164#define clear_mctrl(dev, clear) update_mctrl((dev), 0, (clear))
165
166/* these do not deal with device that have more than 1 port */
167static inline int update_mctrl(struct usb_device *dev, unsigned int set,
168 unsigned int clear)
169{
170 unsigned urb_value;
171 int result;
172
173 if (((set | clear) & (TIOCM_DTR | TIOCM_RTS)) == 0) {
174 dbg("%s - DTR|RTS not being set|cleared", __func__);
175 return 0; /* no change */
176 }
177
178 clear &= ~set; /* 'set' takes precedence over 'clear' */
179 urb_value = 0;
180 if (set & TIOCM_DTR)
181 urb_value |= SERIAL_MCR_DTR;
182 if (set & TIOCM_RTS)
183 urb_value |= SERIAL_MCR_RTS;
184
185 result = ssu100_setregister(dev, 0, urb_value);
186 if (result < 0)
187 dbg("%s Error from MODEM_CTRL urb", __func__);
188
189 return result;
190}
191
192static int ssu100_initdevice(struct usb_device *dev)
193{
194 u8 *data;
195 int result = 0;
196
197 dbg("%s", __func__);
198
199 data = kzalloc(3, GFP_KERNEL);
200 if (!data)
201 return -ENOMEM;
202
203 result = ssu100_getdevice(dev, data);
204 if (result < 0) {
205 dbg("%s - get_device failed %i", __func__, result);
206 goto out;
207 }
208
209 data[1] &= ~FULLPWRBIT;
210
211 result = ssu100_setdevice(dev, data);
212 if (result < 0) {
213 dbg("%s - setdevice failed %i", __func__, result);
214 goto out;
215 }
216
217 result = ssu100_control_msg(dev, QT_GET_SET_PREBUF_TRIG_LVL, 128, 0);
218 if (result < 0) {
219 dbg("%s - set prebuffer level failed %i", __func__, result);
220 goto out;
221 }
222
223 result = ssu100_control_msg(dev, QT_SET_ATF, ATC_DISABLED, 0);
224 if (result < 0) {
225 dbg("%s - set ATFprebuffer level failed %i", __func__, result);
226 goto out;
227 }
228
229 result = ssu100_getdevice(dev, data);
230 if (result < 0) {
231 dbg("%s - get_device failed %i", __func__, result);
232 goto out;
233 }
234
235 data[0] &= ~(RR_BITS | DUPMODE_BITS);
236 data[0] |= CLKS_X4;
237 data[1] &= ~(LOOPMODE_BITS);
238 data[1] |= RS232_MODE;
239
240 result = ssu100_setdevice(dev, data);
241 if (result < 0) {
242 dbg("%s - setdevice failed %i", __func__, result);
243 goto out;
244 }
245
246out: kfree(data);
247 return result;
248
249}
250
251
252static void ssu100_set_termios(struct tty_struct *tty,
253 struct usb_serial_port *port,
254 struct ktermios *old_termios)
255{
256 struct usb_device *dev = port->serial->dev;
257 struct ktermios *termios = tty->termios;
258 u16 baud, divisor, remainder;
259 unsigned int cflag = termios->c_cflag;
260 u16 urb_value = 0; /* will hold the new flags */
261 int result;
262
263 dbg("%s", __func__);
264
265 if (cflag & PARENB) {
266 if (cflag & PARODD)
267 urb_value |= SERIAL_ODD_PARITY;
268 else
269 urb_value |= SERIAL_EVEN_PARITY;
270 }
271
272 switch (cflag & CSIZE) {
273 case CS5:
274 urb_value |= SERIAL_5_DATA;
275 break;
276 case CS6:
277 urb_value |= SERIAL_6_DATA;
278 break;
279 case CS7:
280 urb_value |= SERIAL_7_DATA;
281 break;
282 default:
283 case CS8:
284 urb_value |= SERIAL_8_DATA;
285 break;
286 }
287
288 baud = tty_get_baud_rate(tty);
289 if (!baud)
290 baud = 9600;
291
292 dbg("%s - got baud = %d\n", __func__, baud);
293
294
295 divisor = MAX_BAUD_RATE / baud;
296 remainder = MAX_BAUD_RATE % baud;
297 if (((remainder * 2) >= baud) && (baud != 110))
298 divisor++;
299
300 urb_value = urb_value << 8;
301
302 result = ssu100_control_msg(dev, QT_GET_SET_UART, divisor, urb_value);
303 if (result < 0)
304 dbg("%s - set uart failed", __func__);
305
306 if (cflag & CRTSCTS)
307 result = ssu100_control_msg(dev, QT_HW_FLOW_CONTROL_MASK,
308 SERIAL_CRTSCTS, 0);
309 else
310 result = ssu100_control_msg(dev, QT_HW_FLOW_CONTROL_MASK,
311 0, 0);
312 if (result < 0)
313 dbg("%s - set HW flow control failed", __func__);
314
315 if (I_IXOFF(tty) || I_IXON(tty)) {
316 u16 x = ((u16)(START_CHAR(tty) << 8) | (u16)(STOP_CHAR(tty)));
317
318 result = ssu100_control_msg(dev, QT_SW_FLOW_CONTROL_MASK,
319 x, 0);
320 } else
321 result = ssu100_control_msg(dev, QT_SW_FLOW_CONTROL_MASK,
322 0, 0);
323
324 if (result < 0)
325 dbg("%s - set SW flow control failed", __func__);
326
327}
328
329
330static int ssu100_open(struct tty_struct *tty, struct usb_serial_port *port)
331{
332 struct usb_device *dev = port->serial->dev;
333 struct ssu100_port_private *priv = usb_get_serial_port_data(port);
334 u8 *data;
335 int result;
336
337 dbg("%s - port %d", __func__, port->number);
338
339 data = kzalloc(2, GFP_KERNEL);
340 if (!data)
341 return -ENOMEM;
342
343 result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
344 QT_OPEN_CLOSE_CHANNEL,
345 QT_TRANSFER_IN, 0x01,
346 0, data, 2, 300);
347 if (result < 0) {
348 dbg("%s - open failed %i", __func__, result);
349 kfree(data);
350 return result;
351 }
352
353 priv->shadowLSR = data[0] & (SERIAL_LSR_OE | SERIAL_LSR_PE |
354 SERIAL_LSR_FE | SERIAL_LSR_BI);
355
356 priv->shadowMSR = data[1] & (SERIAL_MSR_CTS | SERIAL_MSR_DSR |
357 SERIAL_MSR_RI | SERIAL_MSR_CD);
358
359 kfree(data);
360
361/* set to 9600 */
362 result = ssu100_control_msg(dev, QT_GET_SET_UART, 0x30, 0x0300);
363 if (result < 0)
364 dbg("%s - set uart failed", __func__);
365
366 if (tty)
367 ssu100_set_termios(tty, port, tty->termios);
368
369 return usb_serial_generic_open(tty, port);
370}
371
372static void ssu100_close(struct usb_serial_port *port)
373{
374 dbg("%s", __func__);
375 usb_serial_generic_close(port);
376}
377
378static int get_serial_info(struct usb_serial_port *port,
379 struct serial_struct __user *retinfo)
380{
381 struct serial_struct tmp;
382
383 if (!retinfo)
384 return -EFAULT;
385
386 memset(&tmp, 0, sizeof(tmp));
387 tmp.line = port->serial->minor;
388 tmp.port = 0;
389 tmp.irq = 0;
390 tmp.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ;
391 tmp.xmit_fifo_size = port->bulk_out_size;
392 tmp.baud_base = 9600;
393 tmp.close_delay = 5*HZ;
394 tmp.closing_wait = 30*HZ;
395
396 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
397 return -EFAULT;
398 return 0;
399}
400
401static int ssu100_ioctl(struct tty_struct *tty, struct file *file,
402 unsigned int cmd, unsigned long arg)
403{
404 struct usb_serial_port *port = tty->driver_data;
405 struct ssu100_port_private *priv = usb_get_serial_port_data(port);
406
407 dbg("%s cmd 0x%04x", __func__, cmd);
408
409 switch (cmd) {
410 case TIOCGSERIAL:
411 return get_serial_info(port,
412 (struct serial_struct __user *) arg);
413
414 case TIOCMIWAIT:
415 while (priv != NULL) {
416 u8 prevMSR = priv->shadowMSR & SERIAL_MSR_MASK;
417 interruptible_sleep_on(&priv->delta_msr_wait);
418 /* see if a signal did it */
419 if (signal_pending(current))
420 return -ERESTARTSYS;
421 else {
422 u8 diff = (priv->shadowMSR & SERIAL_MSR_MASK) ^ prevMSR;
423 if (!diff)
424 return -EIO; /* no change => error */
425
426 /* Return 0 if caller wanted to know about
427 these bits */
428
429 if (((arg & TIOCM_RNG) && (diff & SERIAL_MSR_RI)) ||
430 ((arg & TIOCM_DSR) && (diff & SERIAL_MSR_DSR)) ||
431 ((arg & TIOCM_CD) && (diff & SERIAL_MSR_CD)) ||
432 ((arg & TIOCM_CTS) && (diff & SERIAL_MSR_CTS)))
433 return 0;
434 }
435 }
436 return 0;
437
438 default:
439 break;
440 }
441
442 dbg("%s arg not supported", __func__);
443
444 return -ENOIOCTLCMD;
445}
446
447static void ssu100_set_max_packet_size(struct usb_serial_port *port)
448{
449 struct ssu100_port_private *priv = usb_get_serial_port_data(port);
450 struct usb_serial *serial = port->serial;
451 struct usb_device *udev = serial->dev;
452
453 struct usb_interface *interface = serial->interface;
454 struct usb_endpoint_descriptor *ep_desc = &interface->cur_altsetting->endpoint[1].desc;
455
456 unsigned num_endpoints;
457 int i;
458
459 num_endpoints = interface->cur_altsetting->desc.bNumEndpoints;
460 dev_info(&udev->dev, "Number of endpoints %d\n", num_endpoints);
461
462 for (i = 0; i < num_endpoints; i++) {
463 dev_info(&udev->dev, "Endpoint %d MaxPacketSize %d\n", i+1,
464 interface->cur_altsetting->endpoint[i].desc.wMaxPacketSize);
465 ep_desc = &interface->cur_altsetting->endpoint[i].desc;
466 }
467
468 /* set max packet size based on descriptor */
469 priv->max_packet_size = ep_desc->wMaxPacketSize;
470
471 dev_info(&udev->dev, "Setting MaxPacketSize %d\n", priv->max_packet_size);
472}
473
474static int ssu100_attach(struct usb_serial *serial)
475{
476 struct ssu100_port_private *priv;
477 struct usb_serial_port *port = *serial->port;
478
479 dbg("%s", __func__);
480
481 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
482 if (!priv) {
483 dev_err(&port->dev, "%s- kmalloc(%Zd) failed.\n", __func__,
484 sizeof(*priv));
485 return -ENOMEM;
486 }
487
488 init_waitqueue_head(&priv->delta_msr_wait);
489 usb_set_serial_port_data(port, priv);
490
491 ssu100_set_max_packet_size(port);
492
493 return ssu100_initdevice(serial->dev);
494}
495
496static int ssu100_tiocmget(struct tty_struct *tty, struct file *file)
497{
498 struct usb_serial_port *port = tty->driver_data;
499 struct usb_device *dev = port->serial->dev;
500 u8 *d;
501 int r;
502
503 dbg("%s\n", __func__);
504
505 d = kzalloc(2, GFP_KERNEL);
506 if (!d)
507 return -ENOMEM;
508
509 r = ssu100_getregister(dev, 0, MODEM_CTL_REGISTER, d);
510 if (r < 0)
511 goto mget_out;
512
513 r = ssu100_getregister(dev, 0, MODEM_STATUS_REGISTER, d+1);
514 if (r < 0)
515 goto mget_out;
516
517 r = (d[0] & SERIAL_MCR_DTR ? TIOCM_DTR : 0) |
518 (d[0] & SERIAL_MCR_RTS ? TIOCM_RTS : 0) |
519 (d[1] & SERIAL_MSR_CTS ? TIOCM_CTS : 0) |
520 (d[1] & SERIAL_MSR_CD ? TIOCM_CAR : 0) |
521 (d[1] & SERIAL_MSR_RI ? TIOCM_RI : 0) |
522 (d[1] & SERIAL_MSR_DSR ? TIOCM_DSR : 0);
523
524mget_out:
525 kfree(d);
526 return r;
527}
528
529static int ssu100_tiocmset(struct tty_struct *tty, struct file *file,
530 unsigned int set, unsigned int clear)
531{
532 struct usb_serial_port *port = tty->driver_data;
533 struct usb_device *dev = port->serial->dev;
534
535 dbg("%s\n", __func__);
536 return update_mctrl(dev, set, clear);
537}
538
539static void ssu100_dtr_rts(struct usb_serial_port *port, int on)
540{
541 struct usb_device *dev = port->serial->dev;
542
543 dbg("%s\n", __func__);
544
545 mutex_lock(&port->serial->disc_mutex);
546 if (!port->serial->disconnected) {
547 /* Disable flow control */
548 if (!on &&
549 ssu100_setregister(dev, 0, 0) < 0)
550 dev_err(&port->dev, "error from flowcontrol urb\n");
551 /* drop RTS and DTR */
552 if (on)
553 set_mctrl(dev, TIOCM_DTR | TIOCM_RTS);
554 else
555 clear_mctrl(dev, TIOCM_DTR | TIOCM_RTS);
556 }
557 mutex_unlock(&port->serial->disc_mutex);
558}
559
560static int ssu100_process_packet(struct tty_struct *tty,
561 struct usb_serial_port *port,
562 struct ssu100_port_private *priv,
563 char *packet, int len)
564{
565 int i;
566 char flag;
567 char *ch;
568
569 dbg("%s - port %d", __func__, port->number);
570
571 if (len < 4) {
572 dbg("%s - malformed packet", __func__);
573 return 0;
574 }
575
576 if ((packet[0] == 0x1b) && (packet[1] == 0x1b) &&
577 ((packet[2] == 0x00) || (packet[2] == 0x01))) {
578 if (packet[2] == 0x00)
579 priv->shadowLSR = packet[3] & (SERIAL_LSR_OE |
580 SERIAL_LSR_PE |
581 SERIAL_LSR_FE |
582 SERIAL_LSR_BI);
583
584 if (packet[2] == 0x01) {
585 priv->shadowMSR = packet[3];
586 wake_up_interruptible(&priv->delta_msr_wait);
587 }
588
589 len -= 4;
590 ch = packet + 4;
591 } else
592 ch = packet;
593
594 if (!len)
595 return 0; /* status only */
596
597 if (port->port.console && port->sysrq) {
598 for (i = 0; i < len; i++, ch++) {
599 if (!usb_serial_handle_sysrq_char(tty, port, *ch))
600 tty_insert_flip_char(tty, *ch, flag);
601 }
602 } else
603 tty_insert_flip_string_fixed_flag(tty, ch, flag, len);
604
605 return len;
606}
607
608static void ssu100_process_read_urb(struct urb *urb)
609{
610 struct usb_serial_port *port = urb->context;
611 struct ssu100_port_private *priv = usb_get_serial_port_data(port);
612 char *data = (char *)urb->transfer_buffer;
613 struct tty_struct *tty;
614 int count = 0;
615 int i;
616 int len;
617
618 dbg("%s", __func__);
619
620 tty = tty_port_tty_get(&port->port);
621 if (!tty)
622 return;
623
624 for (i = 0; i < urb->actual_length; i += priv->max_packet_size) {
625 len = min_t(int, urb->actual_length - i, priv->max_packet_size);
626 count += ssu100_process_packet(tty, port, priv, &data[i], len);
627 }
628
629 if (count)
630 tty_flip_buffer_push(tty);
631 tty_kref_put(tty);
632}
633
634
635static struct usb_serial_driver ssu100_device = {
636 .driver = {
637 .owner = THIS_MODULE,
638 .name = "ssu100",
639 },
640 .description = DRIVER_DESC,
641 .id_table = id_table,
642 .usb_driver = &ssu100_driver,
643 .num_ports = 1,
644 .bulk_in_size = 256,
645 .bulk_out_size = 256,
646 .open = ssu100_open,
647 .close = ssu100_close,
648 .attach = ssu100_attach,
649 .release = ssu100_release,
650 .dtr_rts = ssu100_dtr_rts,
651 .process_read_urb = ssu100_process_read_urb,
652 .tiocmget = ssu100_tiocmget,
653 .tiocmset = ssu100_tiocmset,
654 .ioctl = ssu100_ioctl,
655 .set_termios = ssu100_set_termios,
656};
657
658static int __init ssu100_init(void)
659{
660 int retval;
661
662 dbg("%s", __func__);
663
664 /* register with usb-serial */
665 retval = usb_serial_register(&ssu100_device);
666
667 if (retval)
668 goto failed_usb_sio_register;
669
670 retval = usb_register(&ssu100_driver);
671 if (retval)
672 goto failed_usb_register;
673
674 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
675 DRIVER_DESC "\n");
676
677 return 0;
678
679failed_usb_register:
680 usb_serial_deregister(&ssu100_device);
681failed_usb_sio_register:
682 return retval;
683}
684
685static void __exit ssu100_exit(void)
686{
687 usb_deregister(&ssu100_driver);
688 usb_serial_deregister(&ssu100_device);
689}
690
691module_init(ssu100_init);
692module_exit(ssu100_exit);
693
694MODULE_DESCRIPTION(DRIVER_DESC);
695MODULE_LICENSE("GPL");
696
697module_param(debug, bool, S_IRUGO | S_IWUSR);
698MODULE_PARM_DESC(debug, "Debug enabled or not");
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index 941c2d409f85..2a982e62963b 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -653,6 +653,7 @@ exit:
653 return id; 653 return id;
654} 654}
655 655
656/* Caller must hold table_lock */
656static struct usb_serial_driver *search_serial_device( 657static struct usb_serial_driver *search_serial_device(
657 struct usb_interface *iface) 658 struct usb_interface *iface)
658{ 659{
@@ -718,17 +719,23 @@ int usb_serial_probe(struct usb_interface *interface,
718 int num_ports = 0; 719 int num_ports = 0;
719 int max_endpoints; 720 int max_endpoints;
720 721
721 lock_kernel(); /* guard against unloading a serial driver module */ 722 mutex_lock(&table_lock);
722 type = search_serial_device(interface); 723 type = search_serial_device(interface);
723 if (!type) { 724 if (!type) {
724 unlock_kernel(); 725 mutex_unlock(&table_lock);
725 dbg("none matched"); 726 dbg("none matched");
726 return -ENODEV; 727 return -ENODEV;
727 } 728 }
728 729
730 if (!try_module_get(type->driver.owner)) {
731 mutex_unlock(&table_lock);
732 dev_err(&interface->dev, "module get failed, exiting\n");
733 return -EIO;
734 }
735 mutex_unlock(&table_lock);
736
729 serial = create_serial(dev, interface, type); 737 serial = create_serial(dev, interface, type);
730 if (!serial) { 738 if (!serial) {
731 unlock_kernel();
732 dev_err(&interface->dev, "%s - out of memory\n", __func__); 739 dev_err(&interface->dev, "%s - out of memory\n", __func__);
733 return -ENOMEM; 740 return -ENOMEM;
734 } 741 }
@@ -737,20 +744,11 @@ int usb_serial_probe(struct usb_interface *interface,
737 if (type->probe) { 744 if (type->probe) {
738 const struct usb_device_id *id; 745 const struct usb_device_id *id;
739 746
740 if (!try_module_get(type->driver.owner)) {
741 unlock_kernel();
742 dev_err(&interface->dev,
743 "module get failed, exiting\n");
744 kfree(serial);
745 return -EIO;
746 }
747
748 id = get_iface_id(type, interface); 747 id = get_iface_id(type, interface);
749 retval = type->probe(serial, id); 748 retval = type->probe(serial, id);
750 module_put(type->driver.owner); 749 module_put(type->driver.owner);
751 750
752 if (retval) { 751 if (retval) {
753 unlock_kernel();
754 dbg("sub driver rejected device"); 752 dbg("sub driver rejected device");
755 kfree(serial); 753 kfree(serial);
756 return retval; 754 return retval;
@@ -822,7 +820,6 @@ int usb_serial_probe(struct usb_interface *interface,
822 * properly during a later invocation of usb_serial_probe 820 * properly during a later invocation of usb_serial_probe
823 */ 821 */
824 if (num_bulk_in == 0 || num_bulk_out == 0) { 822 if (num_bulk_in == 0 || num_bulk_out == 0) {
825 unlock_kernel();
826 dev_info(&interface->dev, "PL-2303 hack: descriptors matched but endpoints did not\n"); 823 dev_info(&interface->dev, "PL-2303 hack: descriptors matched but endpoints did not\n");
827 kfree(serial); 824 kfree(serial);
828 return -ENODEV; 825 return -ENODEV;
@@ -835,7 +832,6 @@ int usb_serial_probe(struct usb_interface *interface,
835 if (type == &usb_serial_generic_device) { 832 if (type == &usb_serial_generic_device) {
836 num_ports = num_bulk_out; 833 num_ports = num_bulk_out;
837 if (num_ports == 0) { 834 if (num_ports == 0) {
838 unlock_kernel();
839 dev_err(&interface->dev, 835 dev_err(&interface->dev,
840 "Generic device with no bulk out, not allowed.\n"); 836 "Generic device with no bulk out, not allowed.\n");
841 kfree(serial); 837 kfree(serial);
@@ -847,7 +843,6 @@ int usb_serial_probe(struct usb_interface *interface,
847 /* if this device type has a calc_num_ports function, call it */ 843 /* if this device type has a calc_num_ports function, call it */
848 if (type->calc_num_ports) { 844 if (type->calc_num_ports) {
849 if (!try_module_get(type->driver.owner)) { 845 if (!try_module_get(type->driver.owner)) {
850 unlock_kernel();
851 dev_err(&interface->dev, 846 dev_err(&interface->dev,
852 "module get failed, exiting\n"); 847 "module get failed, exiting\n");
853 kfree(serial); 848 kfree(serial);
@@ -878,7 +873,6 @@ int usb_serial_probe(struct usb_interface *interface,
878 max_endpoints = max(max_endpoints, num_interrupt_out); 873 max_endpoints = max(max_endpoints, num_interrupt_out);
879 max_endpoints = max(max_endpoints, (int)serial->num_ports); 874 max_endpoints = max(max_endpoints, (int)serial->num_ports);
880 serial->num_port_pointers = max_endpoints; 875 serial->num_port_pointers = max_endpoints;
881 unlock_kernel();
882 876
883 dbg("%s - setting up %d port structures for this device", 877 dbg("%s - setting up %d port structures for this device",
884 __func__, max_endpoints); 878 __func__, max_endpoints);
@@ -1077,6 +1071,8 @@ int usb_serial_probe(struct usb_interface *interface,
1077 dev_set_name(&port->dev, "ttyUSB%d", port->number); 1071 dev_set_name(&port->dev, "ttyUSB%d", port->number);
1078 dbg ("%s - registering %s", __func__, dev_name(&port->dev)); 1072 dbg ("%s - registering %s", __func__, dev_name(&port->dev));
1079 port->dev_state = PORT_REGISTERING; 1073 port->dev_state = PORT_REGISTERING;
1074 device_enable_async_suspend(&port->dev);
1075
1080 retval = device_add(&port->dev); 1076 retval = device_add(&port->dev);
1081 if (retval) { 1077 if (retval) {
1082 dev_err(&port->dev, "Error registering port device, " 1078 dev_err(&port->dev, "Error registering port device, "
@@ -1349,6 +1345,7 @@ int usb_serial_register(struct usb_serial_driver *driver)
1349 driver->description = driver->driver.name; 1345 driver->description = driver->driver.name;
1350 1346
1351 /* Add this device to our list of devices */ 1347 /* Add this device to our list of devices */
1348 mutex_lock(&table_lock);
1352 list_add(&driver->driver_list, &usb_serial_driver_list); 1349 list_add(&driver->driver_list, &usb_serial_driver_list);
1353 1350
1354 retval = usb_serial_bus_register(driver); 1351 retval = usb_serial_bus_register(driver);
@@ -1360,6 +1357,7 @@ int usb_serial_register(struct usb_serial_driver *driver)
1360 printk(KERN_INFO "USB Serial support registered for %s\n", 1357 printk(KERN_INFO "USB Serial support registered for %s\n",
1361 driver->description); 1358 driver->description);
1362 1359
1360 mutex_unlock(&table_lock);
1363 return retval; 1361 return retval;
1364} 1362}
1365EXPORT_SYMBOL_GPL(usb_serial_register); 1363EXPORT_SYMBOL_GPL(usb_serial_register);
@@ -1370,8 +1368,10 @@ void usb_serial_deregister(struct usb_serial_driver *device)
1370 /* must be called with BKL held */ 1368 /* must be called with BKL held */
1371 printk(KERN_INFO "USB Serial deregistering driver %s\n", 1369 printk(KERN_INFO "USB Serial deregistering driver %s\n",
1372 device->description); 1370 device->description);
1371 mutex_lock(&table_lock);
1373 list_del(&device->driver_list); 1372 list_del(&device->driver_list);
1374 usb_serial_bus_deregister(device); 1373 usb_serial_bus_deregister(device);
1374 mutex_unlock(&table_lock);
1375} 1375}
1376EXPORT_SYMBOL_GPL(usb_serial_deregister); 1376EXPORT_SYMBOL_GPL(usb_serial_deregister);
1377 1377
diff --git a/drivers/usb/storage/freecom.c b/drivers/usb/storage/freecom.c
index 54cc94277acb..6542ca40d505 100644
--- a/drivers/usb/storage/freecom.c
+++ b/drivers/usb/storage/freecom.c
@@ -269,7 +269,7 @@ static int freecom_transport(struct scsi_cmnd *srb, struct us_data *us)
269 /* The firmware will time-out commands after 20 seconds. Some commands 269 /* The firmware will time-out commands after 20 seconds. Some commands
270 * can legitimately take longer than this, so we use a different 270 * can legitimately take longer than this, so we use a different
271 * command that only waits for the interrupt and then sends status, 271 * command that only waits for the interrupt and then sends status,
272 * without having to send a new ATAPI command to the device. 272 * without having to send a new ATAPI command to the device.
273 * 273 *
274 * NOTE: There is some indication that a data transfer after a timeout 274 * NOTE: There is some indication that a data transfer after a timeout
275 * may not work, but that is a condition that should never happen. 275 * may not work, but that is a condition that should never happen.
@@ -324,14 +324,14 @@ static int freecom_transport(struct scsi_cmnd *srb, struct us_data *us)
324 324
325 /* Find the length we desire to read. */ 325 /* Find the length we desire to read. */
326 switch (srb->cmnd[0]) { 326 switch (srb->cmnd[0]) {
327 case INQUIRY: 327 case INQUIRY:
328 case REQUEST_SENSE: /* 16 or 18 bytes? spec says 18, lots of devices only have 16 */ 328 case REQUEST_SENSE: /* 16 or 18 bytes? spec says 18, lots of devices only have 16 */
329 case MODE_SENSE: 329 case MODE_SENSE:
330 case MODE_SENSE_10: 330 case MODE_SENSE_10:
331 length = le16_to_cpu(fst->Count); 331 length = le16_to_cpu(fst->Count);
332 break; 332 break;
333 default: 333 default:
334 length = scsi_bufflen(srb); 334 length = scsi_bufflen(srb);
335 } 335 }
336 336
337 /* verify that this amount is legal */ 337 /* verify that this amount is legal */
@@ -414,7 +414,7 @@ static int freecom_transport(struct scsi_cmnd *srb, struct us_data *us)
414 /* should never hit here -- filtered in usb.c */ 414 /* should never hit here -- filtered in usb.c */
415 US_DEBUGP ("freecom unimplemented direction: %d\n", 415 US_DEBUGP ("freecom unimplemented direction: %d\n",
416 us->srb->sc_data_direction); 416 us->srb->sc_data_direction);
417 // Return fail, SCSI seems to handle this better. 417 /* Return fail, SCSI seems to handle this better. */
418 return USB_STOR_TRANSPORT_FAILED; 418 return USB_STOR_TRANSPORT_FAILED;
419 break; 419 break;
420 } 420 }
@@ -494,8 +494,7 @@ static void pdump (void *ibuffer, int length)
494 offset = 0; 494 offset = 0;
495 } 495 }
496 offset += sprintf (line+offset, "%08x:", i); 496 offset += sprintf (line+offset, "%08x:", i);
497 } 497 } else if ((i & 7) == 0) {
498 else if ((i & 7) == 0) {
499 offset += sprintf (line+offset, " -"); 498 offset += sprintf (line+offset, " -");
500 } 499 }
501 offset += sprintf (line+offset, " %02x", buffer[i] & 0xff); 500 offset += sprintf (line+offset, " %02x", buffer[i] & 0xff);
diff --git a/drivers/usb/storage/isd200.c b/drivers/usb/storage/isd200.c
index e9cbc1467f76..6b9982cd5423 100644
--- a/drivers/usb/storage/isd200.c
+++ b/drivers/usb/storage/isd200.c
@@ -1456,8 +1456,7 @@ static int isd200_init_info(struct us_data *us)
1456 int retStatus = ISD200_GOOD; 1456 int retStatus = ISD200_GOOD;
1457 struct isd200_info *info; 1457 struct isd200_info *info;
1458 1458
1459 info = (struct isd200_info *) 1459 info = kzalloc(sizeof(struct isd200_info), GFP_KERNEL);
1460 kzalloc(sizeof(struct isd200_info), GFP_KERNEL);
1461 if (!info) 1460 if (!info)
1462 retStatus = ISD200_ERROR; 1461 retStatus = ISD200_ERROR;
1463 else { 1462 else {
diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c
index a7d0bf9d92a7..90bb0175a152 100644
--- a/drivers/usb/storage/usb.c
+++ b/drivers/usb/storage/usb.c
@@ -336,6 +336,7 @@ static int usb_stor_control_thread(void * __us)
336 else { 336 else {
337 US_DEBUG(usb_stor_show_command(us->srb)); 337 US_DEBUG(usb_stor_show_command(us->srb));
338 us->proto_handler(us->srb, us); 338 us->proto_handler(us->srb, us);
339 usb_mark_last_busy(us->pusb_dev);
339 } 340 }
340 341
341 /* lock access to the state */ 342 /* lock access to the state */
@@ -845,6 +846,7 @@ static int usb_stor_scan_thread(void * __us)
845 /* Should we unbind if no devices were detected? */ 846 /* Should we unbind if no devices were detected? */
846 } 847 }
847 848
849 usb_autopm_put_interface(us->pusb_intf);
848 complete_and_exit(&us->scanning_done, 0); 850 complete_and_exit(&us->scanning_done, 0);
849} 851}
850 852
@@ -968,6 +970,7 @@ int usb_stor_probe2(struct us_data *us)
968 goto BadDevice; 970 goto BadDevice;
969 } 971 }
970 972
973 usb_autopm_get_interface_no_resume(us->pusb_intf);
971 wake_up_process(th); 974 wake_up_process(th);
972 975
973 return 0; 976 return 0;
@@ -1040,6 +1043,7 @@ static struct usb_driver usb_storage_driver = {
1040 .pre_reset = usb_stor_pre_reset, 1043 .pre_reset = usb_stor_pre_reset,
1041 .post_reset = usb_stor_post_reset, 1044 .post_reset = usb_stor_post_reset,
1042 .id_table = usb_storage_usb_ids, 1045 .id_table = usb_storage_usb_ids,
1046 .supports_autosuspend = 1,
1043 .soft_unbind = 1, 1047 .soft_unbind = 1,
1044}; 1048};
1045 1049
diff --git a/drivers/usb/usb-skeleton.c b/drivers/usb/usb-skeleton.c
index d110588b56f1..552679b8dbd1 100644
--- a/drivers/usb/usb-skeleton.c
+++ b/drivers/usb/usb-skeleton.c
@@ -142,7 +142,7 @@ static int skel_release(struct inode *inode, struct file *file)
142{ 142{
143 struct usb_skel *dev; 143 struct usb_skel *dev;
144 144
145 dev = (struct usb_skel *)file->private_data; 145 dev = file->private_data;
146 if (dev == NULL) 146 if (dev == NULL)
147 return -ENODEV; 147 return -ENODEV;
148 148
@@ -162,7 +162,7 @@ static int skel_flush(struct file *file, fl_owner_t id)
162 struct usb_skel *dev; 162 struct usb_skel *dev;
163 int res; 163 int res;
164 164
165 dev = (struct usb_skel *)file->private_data; 165 dev = file->private_data;
166 if (dev == NULL) 166 if (dev == NULL)
167 return -ENODEV; 167 return -ENODEV;
168 168
@@ -246,7 +246,7 @@ static ssize_t skel_read(struct file *file, char *buffer, size_t count,
246 int rv; 246 int rv;
247 bool ongoing_io; 247 bool ongoing_io;
248 248
249 dev = (struct usb_skel *)file->private_data; 249 dev = file->private_data;
250 250
251 /* if we cannot read at all, return EOF */ 251 /* if we cannot read at all, return EOF */
252 if (!dev->bulk_in_urb || !count) 252 if (!dev->bulk_in_urb || !count)
@@ -401,7 +401,7 @@ static ssize_t skel_write(struct file *file, const char *user_buffer,
401 char *buf = NULL; 401 char *buf = NULL;
402 size_t writesize = min(count, (size_t)MAX_TRANSFER); 402 size_t writesize = min(count, (size_t)MAX_TRANSFER);
403 403
404 dev = (struct usb_skel *)file->private_data; 404 dev = file->private_data;
405 405
406 /* verify that we actually have some data to write */ 406 /* verify that we actually have some data to write */
407 if (count == 0) 407 if (count == 0)
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 7b11ea68c80e..8b31fdfefc98 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -1505,7 +1505,7 @@ config FB_SIS_315
1505 1505
1506config FB_VIA 1506config FB_VIA
1507 tristate "VIA UniChrome (Pro) and Chrome9 display support" 1507 tristate "VIA UniChrome (Pro) and Chrome9 display support"
1508 depends on FB && PCI 1508 depends on FB && PCI && X86
1509 select FB_CFB_FILLRECT 1509 select FB_CFB_FILLRECT
1510 select FB_CFB_COPYAREA 1510 select FB_CFB_COPYAREA
1511 select FB_CFB_IMAGEBLIT 1511 select FB_CFB_IMAGEBLIT
@@ -1896,6 +1896,13 @@ config FB_W100
1896 1896
1897 If unsure, say N. 1897 If unsure, say N.
1898 1898
1899config SH_MIPI_DSI
1900 tristate
1901 depends on (SUPERH || ARCH_SHMOBILE) && HAVE_CLK
1902
1903config SH_LCD_MIPI_DSI
1904 bool
1905
1899config FB_SH_MOBILE_LCDC 1906config FB_SH_MOBILE_LCDC
1900 tristate "SuperH Mobile LCDC framebuffer support" 1907 tristate "SuperH Mobile LCDC framebuffer support"
1901 depends on FB && (SUPERH || ARCH_SHMOBILE) && HAVE_CLK 1908 depends on FB && (SUPERH || ARCH_SHMOBILE) && HAVE_CLK
@@ -1904,9 +1911,17 @@ config FB_SH_MOBILE_LCDC
1904 select FB_SYS_IMAGEBLIT 1911 select FB_SYS_IMAGEBLIT
1905 select FB_SYS_FOPS 1912 select FB_SYS_FOPS
1906 select FB_DEFERRED_IO 1913 select FB_DEFERRED_IO
1914 select SH_MIPI_DSI if SH_LCD_MIPI_DSI
1907 ---help--- 1915 ---help---
1908 Frame buffer driver for the on-chip SH-Mobile LCD controller. 1916 Frame buffer driver for the on-chip SH-Mobile LCD controller.
1909 1917
1918config FB_SH_MOBILE_HDMI
1919 tristate "SuperH Mobile HDMI controller support"
1920 depends on FB_SH_MOBILE_LCDC
1921 select FB_MODE_HELPERS
1922 ---help---
1923 Driver for the on-chip SH-Mobile HDMI controller.
1924
1910config FB_TMIO 1925config FB_TMIO
1911 tristate "Toshiba Mobile IO FrameBuffer support" 1926 tristate "Toshiba Mobile IO FrameBuffer support"
1912 depends on FB && MFD_CORE 1927 depends on FB && MFD_CORE
@@ -1931,7 +1946,7 @@ config FB_TMIO_ACCELL
1931 1946
1932config FB_S3C 1947config FB_S3C
1933 tristate "Samsung S3C framebuffer support" 1948 tristate "Samsung S3C framebuffer support"
1934 depends on FB && ARCH_S3C64XX 1949 depends on FB && S3C_DEV_FB
1935 select FB_CFB_FILLRECT 1950 select FB_CFB_FILLRECT
1936 select FB_CFB_COPYAREA 1951 select FB_CFB_COPYAREA
1937 select FB_CFB_IMAGEBLIT 1952 select FB_CFB_IMAGEBLIT
diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index f56a9cae2157..485e8ed1318c 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -123,6 +123,8 @@ obj-$(CONFIG_FB_IBM_GXT4500) += gxt4500.o
123obj-$(CONFIG_FB_PS3) += ps3fb.o 123obj-$(CONFIG_FB_PS3) += ps3fb.o
124obj-$(CONFIG_FB_SM501) += sm501fb.o 124obj-$(CONFIG_FB_SM501) += sm501fb.o
125obj-$(CONFIG_FB_XILINX) += xilinxfb.o 125obj-$(CONFIG_FB_XILINX) += xilinxfb.o
126obj-$(CONFIG_SH_MIPI_DSI) += sh_mipi_dsi.o
127obj-$(CONFIG_FB_SH_MOBILE_HDMI) += sh_mobile_hdmi.o
126obj-$(CONFIG_FB_SH_MOBILE_LCDC) += sh_mobile_lcdcfb.o 128obj-$(CONFIG_FB_SH_MOBILE_LCDC) += sh_mobile_lcdcfb.o
127obj-$(CONFIG_FB_OMAP) += omap/ 129obj-$(CONFIG_FB_OMAP) += omap/
128obj-y += omap2/ 130obj-y += omap2/
diff --git a/drivers/video/bw2.c b/drivers/video/bw2.c
index c7796637bafd..4dc13467281d 100644
--- a/drivers/video/bw2.c
+++ b/drivers/video/bw2.c
@@ -273,7 +273,7 @@ static int __devinit bw2_do_default_mode(struct bw2_par *par,
273 return 0; 273 return 0;
274} 274}
275 275
276static int __devinit bw2_probe(struct of_device *op, const struct of_device_id *match) 276static int __devinit bw2_probe(struct platform_device *op, const struct of_device_id *match)
277{ 277{
278 struct device_node *dp = op->dev.of_node; 278 struct device_node *dp = op->dev.of_node;
279 struct fb_info *info; 279 struct fb_info *info;
@@ -350,7 +350,7 @@ out_err:
350 return err; 350 return err;
351} 351}
352 352
353static int __devexit bw2_remove(struct of_device *op) 353static int __devexit bw2_remove(struct platform_device *op)
354{ 354{
355 struct fb_info *info = dev_get_drvdata(&op->dev); 355 struct fb_info *info = dev_get_drvdata(&op->dev);
356 struct bw2_par *par = info->par; 356 struct bw2_par *par = info->par;
diff --git a/drivers/video/cg14.c b/drivers/video/cg14.c
index d09fde8beb69..24249535ac86 100644
--- a/drivers/video/cg14.c
+++ b/drivers/video/cg14.c
@@ -446,7 +446,7 @@ static struct sbus_mmap_map __cg14_mmap_map[CG14_MMAP_ENTRIES] __devinitdata = {
446 { .size = 0 } 446 { .size = 0 }
447}; 447};
448 448
449static void cg14_unmap_regs(struct of_device *op, struct fb_info *info, 449static void cg14_unmap_regs(struct platform_device *op, struct fb_info *info,
450 struct cg14_par *par) 450 struct cg14_par *par)
451{ 451{
452 if (par->regs) 452 if (par->regs)
@@ -463,7 +463,7 @@ static void cg14_unmap_regs(struct of_device *op, struct fb_info *info,
463 info->screen_base, info->fix.smem_len); 463 info->screen_base, info->fix.smem_len);
464} 464}
465 465
466static int __devinit cg14_probe(struct of_device *op, const struct of_device_id *match) 466static int __devinit cg14_probe(struct platform_device *op, const struct of_device_id *match)
467{ 467{
468 struct device_node *dp = op->dev.of_node; 468 struct device_node *dp = op->dev.of_node;
469 struct fb_info *info; 469 struct fb_info *info;
@@ -570,7 +570,7 @@ out_err:
570 return err; 570 return err;
571} 571}
572 572
573static int __devexit cg14_remove(struct of_device *op) 573static int __devexit cg14_remove(struct platform_device *op)
574{ 574{
575 struct fb_info *info = dev_get_drvdata(&op->dev); 575 struct fb_info *info = dev_get_drvdata(&op->dev);
576 struct cg14_par *par = info->par; 576 struct cg14_par *par = info->par;
diff --git a/drivers/video/cg3.c b/drivers/video/cg3.c
index 64aa29809fb9..09c0c3c42482 100644
--- a/drivers/video/cg3.c
+++ b/drivers/video/cg3.c
@@ -346,7 +346,7 @@ static int __devinit cg3_do_default_mode(struct cg3_par *par)
346 return 0; 346 return 0;
347} 347}
348 348
349static int __devinit cg3_probe(struct of_device *op, 349static int __devinit cg3_probe(struct platform_device *op,
350 const struct of_device_id *match) 350 const struct of_device_id *match)
351{ 351{
352 struct device_node *dp = op->dev.of_node; 352 struct device_node *dp = op->dev.of_node;
@@ -433,7 +433,7 @@ out_err:
433 return err; 433 return err;
434} 434}
435 435
436static int __devexit cg3_remove(struct of_device *op) 436static int __devexit cg3_remove(struct platform_device *op)
437{ 437{
438 struct fb_info *info = dev_get_drvdata(&op->dev); 438 struct fb_info *info = dev_get_drvdata(&op->dev);
439 struct cg3_par *par = info->par; 439 struct cg3_par *par = info->par;
diff --git a/drivers/video/cg6.c b/drivers/video/cg6.c
index 2389a719dcc7..2b5a97058b08 100644
--- a/drivers/video/cg6.c
+++ b/drivers/video/cg6.c
@@ -718,7 +718,7 @@ static void __devinit cg6_chip_init(struct fb_info *info)
718 sbus_writel(info->var.yres - 1, &fbc->clipmaxy); 718 sbus_writel(info->var.yres - 1, &fbc->clipmaxy);
719} 719}
720 720
721static void cg6_unmap_regs(struct of_device *op, struct fb_info *info, 721static void cg6_unmap_regs(struct platform_device *op, struct fb_info *info,
722 struct cg6_par *par) 722 struct cg6_par *par)
723{ 723{
724 if (par->fbc) 724 if (par->fbc)
@@ -737,7 +737,7 @@ static void cg6_unmap_regs(struct of_device *op, struct fb_info *info,
737 info->fix.smem_len); 737 info->fix.smem_len);
738} 738}
739 739
740static int __devinit cg6_probe(struct of_device *op, 740static int __devinit cg6_probe(struct platform_device *op,
741 const struct of_device_id *match) 741 const struct of_device_id *match)
742{ 742{
743 struct device_node *dp = op->dev.of_node; 743 struct device_node *dp = op->dev.of_node;
@@ -827,7 +827,7 @@ out_err:
827 return err; 827 return err;
828} 828}
829 829
830static int __devexit cg6_remove(struct of_device *op) 830static int __devexit cg6_remove(struct platform_device *op)
831{ 831{
832 struct fb_info *info = dev_get_drvdata(&op->dev); 832 struct fb_info *info = dev_get_drvdata(&op->dev);
833 struct cg6_par *par = info->par; 833 struct cg6_par *par = info->par;
diff --git a/drivers/video/console/Kconfig b/drivers/video/console/Kconfig
index 8e8f18d29d7a..5a35f22372b9 100644
--- a/drivers/video/console/Kconfig
+++ b/drivers/video/console/Kconfig
@@ -6,7 +6,7 @@ menu "Console display driver support"
6 6
7config VGA_CONSOLE 7config VGA_CONSOLE
8 bool "VGA text console" if EMBEDDED || !X86 8 bool "VGA text console" if EMBEDDED || !X86
9 depends on !ARCH_ACORN && !ARCH_EBSA110 && !4xx && !8xx && !SPARC && !M68K && !PARISC && !FRV && !ARCH_VERSATILE && !SUPERH && !BLACKFIN && !AVR32 && !MN10300 9 depends on !4xx && !8xx && !SPARC && !M68K && !PARISC && !FRV && !SUPERH && !BLACKFIN && !AVR32 && !MN10300 && (!ARM || ARCH_FOOTBRIDGE || ARCH_INTEGRATOR || ARCH_NETWINDER)
10 default y 10 default y
11 help 11 help
12 Saying Y here will allow you to use Linux in text mode through a 12 Saying Y here will allow you to use Linux in text mode through a
diff --git a/drivers/video/console/bitblit.c b/drivers/video/console/bitblit.c
index af88651b0735..28b1a834906b 100644
--- a/drivers/video/console/bitblit.c
+++ b/drivers/video/console/bitblit.c
@@ -22,7 +22,7 @@
22/* 22/*
23 * Accelerated handlers. 23 * Accelerated handlers.
24 */ 24 */
25static inline void update_attr(u8 *dst, u8 *src, int attribute, 25static void update_attr(u8 *dst, u8 *src, int attribute,
26 struct vc_data *vc) 26 struct vc_data *vc)
27{ 27{
28 int i, offset = (vc->vc_font.height < 10) ? 1 : 2; 28 int i, offset = (vc->vc_font.height < 10) ? 1 : 2;
diff --git a/drivers/video/console/fbcon.c b/drivers/video/console/fbcon.c
index 3b3f5749af92..84f842331dfa 100644
--- a/drivers/video/console/fbcon.c
+++ b/drivers/video/console/fbcon.c
@@ -283,10 +283,11 @@ static inline int fbcon_is_inactive(struct vc_data *vc, struct fb_info *info)
283 struct fbcon_ops *ops = info->fbcon_par; 283 struct fbcon_ops *ops = info->fbcon_par;
284 284
285 return (info->state != FBINFO_STATE_RUNNING || 285 return (info->state != FBINFO_STATE_RUNNING ||
286 vc->vc_mode != KD_TEXT || ops->graphics); 286 vc->vc_mode != KD_TEXT || ops->graphics) &&
287 !vt_force_oops_output(vc);
287} 288}
288 289
289static inline int get_color(struct vc_data *vc, struct fb_info *info, 290static int get_color(struct vc_data *vc, struct fb_info *info,
290 u16 c, int is_fg) 291 u16 c, int is_fg)
291{ 292{
292 int depth = fb_get_color_depth(&info->var, &info->fix); 293 int depth = fb_get_color_depth(&info->var, &info->fix);
@@ -1073,6 +1074,7 @@ static void fbcon_init(struct vc_data *vc, int init)
1073 if (p->userfont) 1074 if (p->userfont)
1074 charcnt = FNTCHARCNT(p->fontdata); 1075 charcnt = FNTCHARCNT(p->fontdata);
1075 1076
1077 vc->vc_panic_force_write = !!(info->flags & FBINFO_CAN_FORCE_OUTPUT);
1076 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1); 1078 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1077 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800; 1079 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1078 if (charcnt == 256) { 1080 if (charcnt == 256) {
diff --git a/drivers/video/console/fbcon_ccw.c b/drivers/video/console/fbcon_ccw.c
index d135671d9961..41b32ae23dac 100644
--- a/drivers/video/console/fbcon_ccw.c
+++ b/drivers/video/console/fbcon_ccw.c
@@ -22,7 +22,7 @@
22 * Rotation 270 degrees 22 * Rotation 270 degrees
23 */ 23 */
24 24
25static inline void ccw_update_attr(u8 *dst, u8 *src, int attribute, 25static void ccw_update_attr(u8 *dst, u8 *src, int attribute,
26 struct vc_data *vc) 26 struct vc_data *vc)
27{ 27{
28 int i, j, offset = (vc->vc_font.height < 10) ? 1 : 2; 28 int i, j, offset = (vc->vc_font.height < 10) ? 1 : 2;
diff --git a/drivers/video/console/fbcon_cw.c b/drivers/video/console/fbcon_cw.c
index 126110f8454f..6a737827beb1 100644
--- a/drivers/video/console/fbcon_cw.c
+++ b/drivers/video/console/fbcon_cw.c
@@ -22,7 +22,7 @@
22 * Rotation 90 degrees 22 * Rotation 90 degrees
23 */ 23 */
24 24
25static inline void cw_update_attr(u8 *dst, u8 *src, int attribute, 25static void cw_update_attr(u8 *dst, u8 *src, int attribute,
26 struct vc_data *vc) 26 struct vc_data *vc)
27{ 27{
28 int i, j, offset = (vc->vc_font.height < 10) ? 1 : 2; 28 int i, j, offset = (vc->vc_font.height < 10) ? 1 : 2;
diff --git a/drivers/video/console/fbcon_ud.c b/drivers/video/console/fbcon_ud.c
index 93a3e7381b50..ff0872c0498b 100644
--- a/drivers/video/console/fbcon_ud.c
+++ b/drivers/video/console/fbcon_ud.c
@@ -22,7 +22,7 @@
22 * Rotation 180 degrees 22 * Rotation 180 degrees
23 */ 23 */
24 24
25static inline void ud_update_attr(u8 *dst, u8 *src, int attribute, 25static void ud_update_attr(u8 *dst, u8 *src, int attribute,
26 struct vc_data *vc) 26 struct vc_data *vc)
27{ 27{
28 int i, offset = (vc->vc_font.height < 10) ? 1 : 2; 28 int i, offset = (vc->vc_font.height < 10) ? 1 : 2;
diff --git a/drivers/video/console/vgacon.c b/drivers/video/console/vgacon.c
index 182dd6f8aadd..54e32c513610 100644
--- a/drivers/video/console/vgacon.c
+++ b/drivers/video/console/vgacon.c
@@ -1108,7 +1108,6 @@ static int vgacon_do_font_op(struct vgastate *state,char *arg,int set,int ch512)
1108 charmap += 4 * cmapsz; 1108 charmap += 4 * cmapsz;
1109#endif 1109#endif
1110 1110
1111 unlock_kernel();
1112 spin_lock_irq(&vga_lock); 1111 spin_lock_irq(&vga_lock);
1113 /* First, the Sequencer */ 1112 /* First, the Sequencer */
1114 vga_wseq(state->vgabase, VGA_SEQ_RESET, 0x1); 1113 vga_wseq(state->vgabase, VGA_SEQ_RESET, 0x1);
@@ -1192,7 +1191,6 @@ static int vgacon_do_font_op(struct vgastate *state,char *arg,int set,int ch512)
1192 vga_wattr(state->vgabase, VGA_AR_ENABLE_DISPLAY, 0); 1191 vga_wattr(state->vgabase, VGA_AR_ENABLE_DISPLAY, 0);
1193 } 1192 }
1194 spin_unlock_irq(&vga_lock); 1193 spin_unlock_irq(&vga_lock);
1195 lock_kernel();
1196 return 0; 1194 return 0;
1197} 1195}
1198 1196
diff --git a/drivers/video/efifb.c b/drivers/video/efifb.c
index 4a56f46af40a..815f84b07933 100644
--- a/drivers/video/efifb.c
+++ b/drivers/video/efifb.c
@@ -16,7 +16,7 @@
16 16
17#include <video/vga.h> 17#include <video/vga.h>
18 18
19static struct fb_var_screeninfo efifb_defined __initdata = { 19static struct fb_var_screeninfo efifb_defined __devinitdata = {
20 .activate = FB_ACTIVATE_NOW, 20 .activate = FB_ACTIVATE_NOW,
21 .height = -1, 21 .height = -1,
22 .width = -1, 22 .width = -1,
@@ -27,7 +27,7 @@ static struct fb_var_screeninfo efifb_defined __initdata = {
27 .vmode = FB_VMODE_NONINTERLACED, 27 .vmode = FB_VMODE_NONINTERLACED,
28}; 28};
29 29
30static struct fb_fix_screeninfo efifb_fix __initdata = { 30static struct fb_fix_screeninfo efifb_fix __devinitdata = {
31 .id = "EFI VGA", 31 .id = "EFI VGA",
32 .type = FB_TYPE_PACKED_PIXELS, 32 .type = FB_TYPE_PACKED_PIXELS,
33 .accel = FB_ACCEL_NONE, 33 .accel = FB_ACCEL_NONE,
@@ -59,7 +59,7 @@ static struct efifb_dmi_info {
59 int stride; 59 int stride;
60 int width; 60 int width;
61 int height; 61 int height;
62} dmi_list[] = { 62} dmi_list[] __initdata = {
63 [M_I17] = { "i17", 0x80010000, 1472 * 4, 1440, 900 }, 63 [M_I17] = { "i17", 0x80010000, 1472 * 4, 1440, 900 },
64 [M_I20] = { "i20", 0x80010000, 1728 * 4, 1680, 1050 }, /* guess */ 64 [M_I20] = { "i20", 0x80010000, 1728 * 4, 1680, 1050 }, /* guess */
65 [M_I20_SR] = { "imac7", 0x40010000, 1728 * 4, 1680, 1050 }, 65 [M_I20_SR] = { "imac7", 0x40010000, 1728 * 4, 1680, 1050 },
@@ -83,7 +83,7 @@ static int set_system(const struct dmi_system_id *id);
83 DMI_MATCH(DMI_PRODUCT_NAME, name) }, \ 83 DMI_MATCH(DMI_PRODUCT_NAME, name) }, \
84 &dmi_list[enumid] } 84 &dmi_list[enumid] }
85 85
86static struct dmi_system_id __initdata dmi_system_table[] = { 86static const struct dmi_system_id dmi_system_table[] __initconst = {
87 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "iMac4,1", M_I17), 87 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "iMac4,1", M_I17),
88 /* At least one of these two will be right; maybe both? */ 88 /* At least one of these two will be right; maybe both? */
89 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "iMac5,1", M_I20), 89 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "iMac5,1", M_I20),
diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
index 731fce64df9d..b06647517c0e 100644
--- a/drivers/video/fbmem.c
+++ b/drivers/video/fbmem.c
@@ -1362,6 +1362,7 @@ fb_mmap(struct file *file, struct vm_area_struct * vma)
1362 vma->vm_pgoff = off >> PAGE_SHIFT; 1362 vma->vm_pgoff = off >> PAGE_SHIFT;
1363 /* This is an IO map - tell maydump to skip this VMA */ 1363 /* This is an IO map - tell maydump to skip this VMA */
1364 vma->vm_flags |= VM_IO | VM_RESERVED; 1364 vma->vm_flags |= VM_IO | VM_RESERVED;
1365 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
1365 fb_pgprotect(file, vma, off); 1366 fb_pgprotect(file, vma, off);
1366 if (io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT, 1367 if (io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT,
1367 vma->vm_end - vma->vm_start, vma->vm_page_prot)) 1368 vma->vm_end - vma->vm_start, vma->vm_page_prot))
@@ -1786,7 +1787,7 @@ static int ofonly __read_mostly;
1786int fb_get_options(char *name, char **option) 1787int fb_get_options(char *name, char **option)
1787{ 1788{
1788 char *opt, *options = NULL; 1789 char *opt, *options = NULL;
1789 int opt_len, retval = 0; 1790 int retval = 0;
1790 int name_len = strlen(name), i; 1791 int name_len = strlen(name), i;
1791 1792
1792 if (name_len && ofonly && strncmp(name, "offb", 4)) 1793 if (name_len && ofonly && strncmp(name, "offb", 4))
@@ -1796,8 +1797,7 @@ int fb_get_options(char *name, char **option)
1796 for (i = 0; i < FB_MAX; i++) { 1797 for (i = 0; i < FB_MAX; i++) {
1797 if (video_options[i] == NULL) 1798 if (video_options[i] == NULL)
1798 continue; 1799 continue;
1799 opt_len = strlen(video_options[i]); 1800 if (!video_options[i][0])
1800 if (!opt_len)
1801 continue; 1801 continue;
1802 opt = video_options[i]; 1802 opt = video_options[i];
1803 if (!strncmp(name, opt, name_len) && 1803 if (!strncmp(name, opt, name_len) &&
diff --git a/drivers/video/ffb.c b/drivers/video/ffb.c
index f6ecfab296d3..6739b2af3bc0 100644
--- a/drivers/video/ffb.c
+++ b/drivers/video/ffb.c
@@ -893,7 +893,7 @@ static void ffb_init_fix(struct fb_info *info)
893 info->fix.accel = FB_ACCEL_SUN_CREATOR; 893 info->fix.accel = FB_ACCEL_SUN_CREATOR;
894} 894}
895 895
896static int __devinit ffb_probe(struct of_device *op, 896static int __devinit ffb_probe(struct platform_device *op,
897 const struct of_device_id *match) 897 const struct of_device_id *match)
898{ 898{
899 struct device_node *dp = op->dev.of_node; 899 struct device_node *dp = op->dev.of_node;
@@ -1023,7 +1023,7 @@ out_err:
1023 return err; 1023 return err;
1024} 1024}
1025 1025
1026static int __devexit ffb_remove(struct of_device *op) 1026static int __devexit ffb_remove(struct platform_device *op)
1027{ 1027{
1028 struct fb_info *info = dev_get_drvdata(&op->dev); 1028 struct fb_info *info = dev_get_drvdata(&op->dev);
1029 struct ffb_par *par = info->par; 1029 struct ffb_par *par = info->par;
diff --git a/drivers/video/fsl-diu-fb.c b/drivers/video/fsl-diu-fb.c
index e38ad2224540..8bbbf08fa3ce 100644
--- a/drivers/video/fsl-diu-fb.c
+++ b/drivers/video/fsl-diu-fb.c
@@ -1393,7 +1393,7 @@ static void free_irq_local(int irq)
1393 * Power management hooks. Note that we won't be called from IRQ context, 1393 * Power management hooks. Note that we won't be called from IRQ context,
1394 * unlike the blank functions above, so we may sleep. 1394 * unlike the blank functions above, so we may sleep.
1395 */ 1395 */
1396static int fsl_diu_suspend(struct of_device *ofdev, pm_message_t state) 1396static int fsl_diu_suspend(struct platform_device *ofdev, pm_message_t state)
1397{ 1397{
1398 struct fsl_diu_data *machine_data; 1398 struct fsl_diu_data *machine_data;
1399 1399
@@ -1403,7 +1403,7 @@ static int fsl_diu_suspend(struct of_device *ofdev, pm_message_t state)
1403 return 0; 1403 return 0;
1404} 1404}
1405 1405
1406static int fsl_diu_resume(struct of_device *ofdev) 1406static int fsl_diu_resume(struct platform_device *ofdev)
1407{ 1407{
1408 struct fsl_diu_data *machine_data; 1408 struct fsl_diu_data *machine_data;
1409 1409
@@ -1487,7 +1487,7 @@ static ssize_t show_monitor(struct device *device,
1487 return diu_ops.show_monitor_port(machine_data->monitor_port, buf); 1487 return diu_ops.show_monitor_port(machine_data->monitor_port, buf);
1488} 1488}
1489 1489
1490static int __devinit fsl_diu_probe(struct of_device *ofdev, 1490static int __devinit fsl_diu_probe(struct platform_device *ofdev,
1491 const struct of_device_id *match) 1491 const struct of_device_id *match)
1492{ 1492{
1493 struct device_node *np = ofdev->dev.of_node; 1493 struct device_node *np = ofdev->dev.of_node;
@@ -1667,7 +1667,7 @@ error2:
1667} 1667}
1668 1668
1669 1669
1670static int fsl_diu_remove(struct of_device *ofdev) 1670static int fsl_diu_remove(struct platform_device *ofdev)
1671{ 1671{
1672 struct fsl_diu_data *machine_data; 1672 struct fsl_diu_data *machine_data;
1673 int i; 1673 int i;
diff --git a/drivers/video/igafb.c b/drivers/video/igafb.c
index 15d200109446..d885c770eb84 100644
--- a/drivers/video/igafb.c
+++ b/drivers/video/igafb.c
@@ -368,7 +368,7 @@ static int __init iga_init(struct fb_info *info, struct iga_par *par)
368 return 1; 368 return 1;
369} 369}
370 370
371int __init igafb_init(void) 371static int __init igafb_init(void)
372{ 372{
373 struct fb_info *info; 373 struct fb_info *info;
374 struct pci_dev *pdev; 374 struct pci_dev *pdev;
@@ -531,6 +531,7 @@ int __init igafb_init(void)
531 iounmap(info->screen_base); 531 iounmap(info->screen_base);
532 kfree(par->mmap_map); 532 kfree(par->mmap_map);
533 kfree(info); 533 kfree(info);
534 return -ENODEV;
534 } 535 }
535 536
536#ifdef CONFIG_SPARC 537#ifdef CONFIG_SPARC
@@ -556,7 +557,7 @@ int __init igafb_init(void)
556 return 0; 557 return 0;
557} 558}
558 559
559int __init igafb_setup(char *options) 560static int __init igafb_setup(char *options)
560{ 561{
561 char *this_opt; 562 char *this_opt;
562 563
diff --git a/drivers/video/imxfb.c b/drivers/video/imxfb.c
index 43f0639b1c10..5c363d026f64 100644
--- a/drivers/video/imxfb.c
+++ b/drivers/video/imxfb.c
@@ -40,6 +40,12 @@
40 */ 40 */
41#define DEBUG_VAR 1 41#define DEBUG_VAR 1
42 42
43#if defined(CONFIG_BACKLIGHT_CLASS_DEVICE) || \
44 (defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE) && \
45 defined(CONFIG_FB_IMX_MODULE))
46#define PWMR_BACKLIGHT_AVAILABLE
47#endif
48
43#define DRIVER_NAME "imx-fb" 49#define DRIVER_NAME "imx-fb"
44 50
45#define LCDC_SSA 0x00 51#define LCDC_SSA 0x00
@@ -175,7 +181,9 @@ struct imxfb_info {
175 181
176 struct imx_fb_videomode *mode; 182 struct imx_fb_videomode *mode;
177 int num_modes; 183 int num_modes;
184#ifdef PWMR_BACKLIGHT_AVAILABLE
178 struct backlight_device *bl; 185 struct backlight_device *bl;
186#endif
179 187
180 void (*lcd_power)(int); 188 void (*lcd_power)(int);
181 void (*backlight_power)(int); 189 void (*backlight_power)(int);
@@ -450,8 +458,7 @@ static int imxfb_set_par(struct fb_info *info)
450 return 0; 458 return 0;
451} 459}
452 460
453 461#ifdef PWMR_BACKLIGHT_AVAILABLE
454
455static int imxfb_bl_get_brightness(struct backlight_device *bl) 462static int imxfb_bl_get_brightness(struct backlight_device *bl)
456{ 463{
457 struct imxfb_info *fbi = bl_get_data(bl); 464 struct imxfb_info *fbi = bl_get_data(bl);
@@ -516,6 +523,7 @@ static void imxfb_exit_backlight(struct imxfb_info *fbi)
516 if (fbi->bl) 523 if (fbi->bl)
517 backlight_device_unregister(fbi->bl); 524 backlight_device_unregister(fbi->bl);
518} 525}
526#endif
519 527
520static void imxfb_enable_controller(struct imxfb_info *fbi) 528static void imxfb_enable_controller(struct imxfb_info *fbi)
521{ 529{
@@ -647,6 +655,9 @@ static int imxfb_activate_var(struct fb_var_screeninfo *var, struct fb_info *inf
647 fbi->regs + LCDC_SIZE); 655 fbi->regs + LCDC_SIZE);
648 656
649 writel(fbi->pcr, fbi->regs + LCDC_PCR); 657 writel(fbi->pcr, fbi->regs + LCDC_PCR);
658#ifndef PWMR_BACKLIGHT_AVAILABLE
659 writel(fbi->pwmr, fbi->regs + LCDC_PWMR);
660#endif
650 writel(fbi->lscr1, fbi->regs + LCDC_LSCR1); 661 writel(fbi->lscr1, fbi->regs + LCDC_LSCR1);
651 writel(fbi->dmacr, fbi->regs + LCDC_DMACR); 662 writel(fbi->dmacr, fbi->regs + LCDC_DMACR);
652 663
@@ -847,7 +858,9 @@ static int __init imxfb_probe(struct platform_device *pdev)
847 858
848 imxfb_enable_controller(fbi); 859 imxfb_enable_controller(fbi);
849 fbi->pdev = pdev; 860 fbi->pdev = pdev;
861#ifdef PWMR_BACKLIGHT_AVAILABLE
850 imxfb_init_backlight(fbi); 862 imxfb_init_backlight(fbi);
863#endif
851 864
852 return 0; 865 return 0;
853 866
@@ -885,7 +898,9 @@ static int __devexit imxfb_remove(struct platform_device *pdev)
885 898
886 imxfb_disable_controller(fbi); 899 imxfb_disable_controller(fbi);
887 900
901#ifdef PWMR_BACKLIGHT_AVAILABLE
888 imxfb_exit_backlight(fbi); 902 imxfb_exit_backlight(fbi);
903#endif
889 unregister_framebuffer(info); 904 unregister_framebuffer(info);
890 905
891 pdata = pdev->dev.platform_data; 906 pdata = pdev->dev.platform_data;
diff --git a/drivers/video/leo.c b/drivers/video/leo.c
index ad677637ffbb..b599e5e36ced 100644
--- a/drivers/video/leo.c
+++ b/drivers/video/leo.c
@@ -529,7 +529,7 @@ static void leo_fixup_var_rgb(struct fb_var_screeninfo *var)
529 var->transp.length = 0; 529 var->transp.length = 0;
530} 530}
531 531
532static void leo_unmap_regs(struct of_device *op, struct fb_info *info, 532static void leo_unmap_regs(struct platform_device *op, struct fb_info *info,
533 struct leo_par *par) 533 struct leo_par *par)
534{ 534{
535 if (par->lc_ss0_usr) 535 if (par->lc_ss0_usr)
@@ -547,7 +547,7 @@ static void leo_unmap_regs(struct of_device *op, struct fb_info *info,
547 of_iounmap(&op->resource[0], info->screen_base, 0x800000); 547 of_iounmap(&op->resource[0], info->screen_base, 0x800000);
548} 548}
549 549
550static int __devinit leo_probe(struct of_device *op, 550static int __devinit leo_probe(struct platform_device *op,
551 const struct of_device_id *match) 551 const struct of_device_id *match)
552{ 552{
553 struct device_node *dp = op->dev.of_node; 553 struct device_node *dp = op->dev.of_node;
@@ -637,7 +637,7 @@ out_err:
637 return err; 637 return err;
638} 638}
639 639
640static int __devexit leo_remove(struct of_device *op) 640static int __devexit leo_remove(struct platform_device *op)
641{ 641{
642 struct fb_info *info = dev_get_drvdata(&op->dev); 642 struct fb_info *info = dev_get_drvdata(&op->dev);
643 struct leo_par *par = info->par; 643 struct leo_par *par = info->par;
diff --git a/drivers/video/matrox/i2c-matroxfb.c b/drivers/video/matrox/i2c-matroxfb.c
index 403b14445a78..0fb280ead3dc 100644
--- a/drivers/video/matrox/i2c-matroxfb.c
+++ b/drivers/video/matrox/i2c-matroxfb.c
@@ -191,7 +191,7 @@ static void* i2c_matroxfb_probe(struct matrox_fb_info* minfo) {
191 }; 191 };
192 192
193 i2c_new_probed_device(&m2info->maven.adapter, 193 i2c_new_probed_device(&m2info->maven.adapter,
194 &maven_info, addr_list); 194 &maven_info, addr_list, NULL);
195 } 195 }
196 } 196 }
197 return m2info; 197 return m2info;
diff --git a/drivers/video/mb862xx/mb862xxfb.c b/drivers/video/mb862xx/mb862xxfb.c
index 4e2b8cc3d460..b1c4374cf940 100644
--- a/drivers/video/mb862xx/mb862xxfb.c
+++ b/drivers/video/mb862xx/mb862xxfb.c
@@ -550,7 +550,7 @@ static int mb862xx_gdc_init(struct mb862xxfb_par *par)
550 return 0; 550 return 0;
551} 551}
552 552
553static int __devinit of_platform_mb862xx_probe(struct of_device *ofdev, 553static int __devinit of_platform_mb862xx_probe(struct platform_device *ofdev,
554 const struct of_device_id *id) 554 const struct of_device_id *id)
555{ 555{
556 struct device_node *np = ofdev->dev.of_node; 556 struct device_node *np = ofdev->dev.of_node;
@@ -669,7 +669,7 @@ fbrel:
669 return ret; 669 return ret;
670} 670}
671 671
672static int __devexit of_platform_mb862xx_remove(struct of_device *ofdev) 672static int __devexit of_platform_mb862xx_remove(struct platform_device *ofdev)
673{ 673{
674 struct fb_info *fbi = dev_get_drvdata(&ofdev->dev); 674 struct fb_info *fbi = dev_get_drvdata(&ofdev->dev);
675 struct mb862xxfb_par *par = fbi->par; 675 struct mb862xxfb_par *par = fbi->par;
diff --git a/drivers/video/msm/mddi.c b/drivers/video/msm/mddi.c
index c1ff271017a9..7c316c34dfca 100644
--- a/drivers/video/msm/mddi.c
+++ b/drivers/video/msm/mddi.c
@@ -187,10 +187,8 @@ static void mddi_wait_interrupt(struct mddi_info *mddi, uint32_t intmask);
187 187
188static void mddi_handle_rev_data_avail(struct mddi_info *mddi) 188static void mddi_handle_rev_data_avail(struct mddi_info *mddi)
189{ 189{
190 union mddi_rev *rev = mddi->rev_data;
191 uint32_t rev_data_count; 190 uint32_t rev_data_count;
192 uint32_t rev_crc_err_count; 191 uint32_t rev_crc_err_count;
193 int i;
194 struct reg_read_info *ri; 192 struct reg_read_info *ri;
195 size_t prev_offset; 193 size_t prev_offset;
196 uint16_t length; 194 uint16_t length;
@@ -670,7 +668,7 @@ static int __init mddi_rev_data_setup(struct mddi_info *mddi)
670 return 0; 668 return 0;
671} 669}
672 670
673static int __init mddi_probe(struct platform_device *pdev) 671static int __devinit mddi_probe(struct platform_device *pdev)
674{ 672{
675 struct msm_mddi_platform_data *pdata = pdev->dev.platform_data; 673 struct msm_mddi_platform_data *pdata = pdev->dev.platform_data;
676 struct mddi_info *mddi = &mddi_info[pdev->id]; 674 struct mddi_info *mddi = &mddi_info[pdev->id];
diff --git a/drivers/video/msm/mdp.c b/drivers/video/msm/mdp.c
index 19c01c6208e8..3c28db03ad39 100644
--- a/drivers/video/msm/mdp.c
+++ b/drivers/video/msm/mdp.c
@@ -258,7 +258,6 @@ int get_img(struct mdp_img *img, struct fb_info *info,
258{ 258{
259 int put_needed, ret = 0; 259 int put_needed, ret = 0;
260 struct file *file; 260 struct file *file;
261 unsigned long vstart;
262 261
263 file = fget_light(img->memory_id, &put_needed); 262 file = fget_light(img->memory_id, &put_needed);
264 if (file == NULL) 263 if (file == NULL)
diff --git a/drivers/video/omap/lcd_apollon.c b/drivers/video/omap/lcd_apollon.c
index 2be94eb3bbf5..10459d8bd9a0 100644
--- a/drivers/video/omap/lcd_apollon.c
+++ b/drivers/video/omap/lcd_apollon.c
@@ -25,7 +25,6 @@
25#include <linux/platform_device.h> 25#include <linux/platform_device.h>
26 26
27#include <mach/gpio.h> 27#include <mach/gpio.h>
28#include <plat/mux.h>
29 28
30#include "omapfb.h" 29#include "omapfb.h"
31 30
@@ -34,8 +33,6 @@
34static int apollon_panel_init(struct lcd_panel *panel, 33static int apollon_panel_init(struct lcd_panel *panel,
35 struct omapfb_device *fbdev) 34 struct omapfb_device *fbdev)
36{ 35{
37 /* configure LCD PWR_EN */
38 omap_cfg_reg(M21_242X_GPIO11);
39 return 0; 36 return 0;
40} 37}
41 38
diff --git a/drivers/video/omap2/displays/panel-taal.c b/drivers/video/omap2/displays/panel-taal.c
index aaf5d308a046..e1c765d11419 100644
--- a/drivers/video/omap2/displays/panel-taal.c
+++ b/drivers/video/omap2/displays/panel-taal.c
@@ -28,12 +28,13 @@
28#include <linux/fb.h> 28#include <linux/fb.h>
29#include <linux/interrupt.h> 29#include <linux/interrupt.h>
30#include <linux/gpio.h> 30#include <linux/gpio.h>
31#include <linux/completion.h>
32#include <linux/workqueue.h> 31#include <linux/workqueue.h>
33#include <linux/slab.h> 32#include <linux/slab.h>
33#include <linux/regulator/consumer.h>
34#include <linux/mutex.h> 34#include <linux/mutex.h>
35 35
36#include <plat/display.h> 36#include <plat/display.h>
37#include <plat/nokia-dsi-panel.h>
37 38
38/* DSI Virtual channel. Hardcoded for now. */ 39/* DSI Virtual channel. Hardcoded for now. */
39#define TCH 0 40#define TCH 0
@@ -62,11 +63,136 @@
62#define DCS_GET_ID2 0xdb 63#define DCS_GET_ID2 0xdb
63#define DCS_GET_ID3 0xdc 64#define DCS_GET_ID3 0xdc
64 65
65/* #define TAAL_USE_ESD_CHECK */
66#define TAAL_ESD_CHECK_PERIOD msecs_to_jiffies(5000) 66#define TAAL_ESD_CHECK_PERIOD msecs_to_jiffies(5000)
67 67
68static irqreturn_t taal_te_isr(int irq, void *data);
69static void taal_te_timeout_work_callback(struct work_struct *work);
68static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable); 70static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable);
69 71
72struct panel_regulator {
73 struct regulator *regulator;
74 const char *name;
75 int min_uV;
76 int max_uV;
77};
78
79static void free_regulators(struct panel_regulator *regulators, int n)
80{
81 int i;
82
83 for (i = 0; i < n; i++) {
84 /* disable/put in reverse order */
85 regulator_disable(regulators[n - i - 1].regulator);
86 regulator_put(regulators[n - i - 1].regulator);
87 }
88}
89
90static int init_regulators(struct omap_dss_device *dssdev,
91 struct panel_regulator *regulators, int n)
92{
93 int r, i, v;
94
95 for (i = 0; i < n; i++) {
96 struct regulator *reg;
97
98 reg = regulator_get(&dssdev->dev, regulators[i].name);
99 if (IS_ERR(reg)) {
100 dev_err(&dssdev->dev, "failed to get regulator %s\n",
101 regulators[i].name);
102 r = PTR_ERR(reg);
103 goto err;
104 }
105
106 /* FIXME: better handling of fixed vs. variable regulators */
107 v = regulator_get_voltage(reg);
108 if (v < regulators[i].min_uV || v > regulators[i].max_uV) {
109 r = regulator_set_voltage(reg, regulators[i].min_uV,
110 regulators[i].max_uV);
111 if (r) {
112 dev_err(&dssdev->dev,
113 "failed to set regulator %s voltage\n",
114 regulators[i].name);
115 regulator_put(reg);
116 goto err;
117 }
118 }
119
120 r = regulator_enable(reg);
121 if (r) {
122 dev_err(&dssdev->dev, "failed to enable regulator %s\n",
123 regulators[i].name);
124 regulator_put(reg);
125 goto err;
126 }
127
128 regulators[i].regulator = reg;
129 }
130
131 return 0;
132
133err:
134 free_regulators(regulators, i);
135
136 return r;
137}
138
139/**
140 * struct panel_config - panel configuration
141 * @name: panel name
142 * @type: panel type
143 * @timings: panel resolution
144 * @sleep: various panel specific delays, passed to msleep() if non-zero
145 * @reset_sequence: reset sequence timings, passed to udelay() if non-zero
146 * @regulators: array of panel regulators
147 * @num_regulators: number of regulators in the array
148 */
149struct panel_config {
150 const char *name;
151 int type;
152
153 struct omap_video_timings timings;
154
155 struct {
156 unsigned int sleep_in;
157 unsigned int sleep_out;
158 unsigned int hw_reset;
159 unsigned int enable_te;
160 } sleep;
161
162 struct {
163 unsigned int high;
164 unsigned int low;
165 } reset_sequence;
166
167 struct panel_regulator *regulators;
168 int num_regulators;
169};
170
171enum {
172 PANEL_TAAL,
173};
174
175static struct panel_config panel_configs[] = {
176 {
177 .name = "taal",
178 .type = PANEL_TAAL,
179 .timings = {
180 .x_res = 864,
181 .y_res = 480,
182 },
183 .sleep = {
184 .sleep_in = 5,
185 .sleep_out = 5,
186 .hw_reset = 5,
187 .enable_te = 100, /* possible panel bug */
188 },
189 .reset_sequence = {
190 .high = 10,
191 .low = 10,
192 },
193 },
194};
195
70struct taal_data { 196struct taal_data {
71 struct mutex lock; 197 struct mutex lock;
72 198
@@ -84,8 +210,15 @@ struct taal_data {
84 bool mirror; 210 bool mirror;
85 211
86 bool te_enabled; 212 bool te_enabled;
87 bool use_ext_te; 213
88 struct completion te_completion; 214 atomic_t do_update;
215 struct {
216 u16 x;
217 u16 y;
218 u16 w;
219 u16 h;
220 } update_region;
221 struct delayed_work te_timeout_work;
89 222
90 bool use_dsi_bl; 223 bool use_dsi_bl;
91 224
@@ -96,8 +229,16 @@ struct taal_data {
96 229
97 struct workqueue_struct *esd_wq; 230 struct workqueue_struct *esd_wq;
98 struct delayed_work esd_work; 231 struct delayed_work esd_work;
232
233 struct panel_config *panel_config;
99}; 234};
100 235
236static inline struct nokia_dsi_panel_data
237*get_panel_data(const struct omap_dss_device *dssdev)
238{
239 return (struct nokia_dsi_panel_data *) dssdev->data;
240}
241
101static void taal_esd_work(struct work_struct *work); 242static void taal_esd_work(struct work_struct *work);
102 243
103static void hw_guard_start(struct taal_data *td, int guard_msec) 244static void hw_guard_start(struct taal_data *td, int guard_msec)
@@ -159,7 +300,8 @@ static int taal_sleep_in(struct taal_data *td)
159 300
160 hw_guard_start(td, 120); 301 hw_guard_start(td, 120);
161 302
162 msleep(5); 303 if (td->panel_config->sleep.sleep_in)
304 msleep(td->panel_config->sleep.sleep_in);
163 305
164 return 0; 306 return 0;
165} 307}
@@ -176,7 +318,8 @@ static int taal_sleep_out(struct taal_data *td)
176 318
177 hw_guard_start(td, 120); 319 hw_guard_start(td, 120);
178 320
179 msleep(5); 321 if (td->panel_config->sleep.sleep_out)
322 msleep(td->panel_config->sleep.sleep_out);
180 323
181 return 0; 324 return 0;
182} 325}
@@ -279,6 +422,7 @@ static int taal_bl_update_status(struct backlight_device *dev)
279{ 422{
280 struct omap_dss_device *dssdev = dev_get_drvdata(&dev->dev); 423 struct omap_dss_device *dssdev = dev_get_drvdata(&dev->dev);
281 struct taal_data *td = dev_get_drvdata(&dssdev->dev); 424 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
425 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
282 int r; 426 int r;
283 int level; 427 int level;
284 428
@@ -290,24 +434,26 @@ static int taal_bl_update_status(struct backlight_device *dev)
290 434
291 dev_dbg(&dssdev->dev, "update brightness to %d\n", level); 435 dev_dbg(&dssdev->dev, "update brightness to %d\n", level);
292 436
437 mutex_lock(&td->lock);
438
293 if (td->use_dsi_bl) { 439 if (td->use_dsi_bl) {
294 if (td->enabled) { 440 if (td->enabled) {
295 dsi_bus_lock(); 441 dsi_bus_lock();
296 r = taal_dcs_write_1(DCS_BRIGHTNESS, level); 442 r = taal_dcs_write_1(DCS_BRIGHTNESS, level);
297 dsi_bus_unlock(); 443 dsi_bus_unlock();
298 if (r) 444 } else {
299 return r; 445 r = 0;
300 } 446 }
301 } else { 447 } else {
302 if (!dssdev->set_backlight) 448 if (!panel_data->set_backlight)
303 return -EINVAL; 449 r = -EINVAL;
304 450 else
305 r = dssdev->set_backlight(dssdev, level); 451 r = panel_data->set_backlight(dssdev, level);
306 if (r)
307 return r;
308 } 452 }
309 453
310 return 0; 454 mutex_unlock(&td->lock);
455
456 return r;
311} 457}
312 458
313static int taal_bl_get_intensity(struct backlight_device *dev) 459static int taal_bl_get_intensity(struct backlight_device *dev)
@@ -344,16 +490,6 @@ static void taal_get_resolution(struct omap_dss_device *dssdev,
344 } 490 }
345} 491}
346 492
347static irqreturn_t taal_te_isr(int irq, void *data)
348{
349 struct omap_dss_device *dssdev = data;
350 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
351
352 complete_all(&td->te_completion);
353
354 return IRQ_HANDLED;
355}
356
357static ssize_t taal_num_errors_show(struct device *dev, 493static ssize_t taal_num_errors_show(struct device *dev,
358 struct device_attribute *attr, char *buf) 494 struct device_attribute *attr, char *buf)
359{ 495{
@@ -362,6 +498,8 @@ static ssize_t taal_num_errors_show(struct device *dev,
362 u8 errors; 498 u8 errors;
363 int r; 499 int r;
364 500
501 mutex_lock(&td->lock);
502
365 if (td->enabled) { 503 if (td->enabled) {
366 dsi_bus_lock(); 504 dsi_bus_lock();
367 r = taal_dcs_read_1(DCS_READ_NUM_ERRORS, &errors); 505 r = taal_dcs_read_1(DCS_READ_NUM_ERRORS, &errors);
@@ -370,6 +508,8 @@ static ssize_t taal_num_errors_show(struct device *dev,
370 r = -ENODEV; 508 r = -ENODEV;
371 } 509 }
372 510
511 mutex_unlock(&td->lock);
512
373 if (r) 513 if (r)
374 return r; 514 return r;
375 515
@@ -384,6 +524,8 @@ static ssize_t taal_hw_revision_show(struct device *dev,
384 u8 id1, id2, id3; 524 u8 id1, id2, id3;
385 int r; 525 int r;
386 526
527 mutex_lock(&td->lock);
528
387 if (td->enabled) { 529 if (td->enabled) {
388 dsi_bus_lock(); 530 dsi_bus_lock();
389 r = taal_get_id(&id1, &id2, &id3); 531 r = taal_get_id(&id1, &id2, &id3);
@@ -392,6 +534,8 @@ static ssize_t taal_hw_revision_show(struct device *dev,
392 r = -ENODEV; 534 r = -ENODEV;
393 } 535 }
394 536
537 mutex_unlock(&td->lock);
538
395 if (r) 539 if (r)
396 return r; 540 return r;
397 541
@@ -441,6 +585,8 @@ static ssize_t store_cabc_mode(struct device *dev,
441 if (i == ARRAY_SIZE(cabc_modes)) 585 if (i == ARRAY_SIZE(cabc_modes))
442 return -EINVAL; 586 return -EINVAL;
443 587
588 mutex_lock(&td->lock);
589
444 if (td->enabled) { 590 if (td->enabled) {
445 dsi_bus_lock(); 591 dsi_bus_lock();
446 if (!td->cabc_broken) 592 if (!td->cabc_broken)
@@ -450,6 +596,8 @@ static ssize_t store_cabc_mode(struct device *dev,
450 596
451 td->cabc_mode = i; 597 td->cabc_mode = i;
452 598
599 mutex_unlock(&td->lock);
600
453 return count; 601 return count;
454} 602}
455 603
@@ -488,47 +636,93 @@ static struct attribute_group taal_attr_group = {
488 .attrs = taal_attrs, 636 .attrs = taal_attrs,
489}; 637};
490 638
639static void taal_hw_reset(struct omap_dss_device *dssdev)
640{
641 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
642 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
643
644 if (panel_data->reset_gpio == -1)
645 return;
646
647 gpio_set_value(panel_data->reset_gpio, 1);
648 if (td->panel_config->reset_sequence.high)
649 udelay(td->panel_config->reset_sequence.high);
650 /* reset the panel */
651 gpio_set_value(panel_data->reset_gpio, 0);
652 /* assert reset */
653 if (td->panel_config->reset_sequence.low)
654 udelay(td->panel_config->reset_sequence.low);
655 gpio_set_value(panel_data->reset_gpio, 1);
656 /* wait after releasing reset */
657 if (td->panel_config->sleep.hw_reset)
658 msleep(td->panel_config->sleep.hw_reset);
659}
660
491static int taal_probe(struct omap_dss_device *dssdev) 661static int taal_probe(struct omap_dss_device *dssdev)
492{ 662{
493 struct backlight_properties props; 663 struct backlight_properties props;
494 struct taal_data *td; 664 struct taal_data *td;
495 struct backlight_device *bldev; 665 struct backlight_device *bldev;
496 int r; 666 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
497 667 struct panel_config *panel_config = NULL;
498 const struct omap_video_timings taal_panel_timings = { 668 int r, i;
499 .x_res = 864,
500 .y_res = 480,
501 };
502 669
503 dev_dbg(&dssdev->dev, "probe\n"); 670 dev_dbg(&dssdev->dev, "probe\n");
504 671
672 if (!panel_data || !panel_data->name) {
673 r = -EINVAL;
674 goto err;
675 }
676
677 for (i = 0; i < ARRAY_SIZE(panel_configs); i++) {
678 if (strcmp(panel_data->name, panel_configs[i].name) == 0) {
679 panel_config = &panel_configs[i];
680 break;
681 }
682 }
683
684 if (!panel_config) {
685 r = -EINVAL;
686 goto err;
687 }
688
505 dssdev->panel.config = OMAP_DSS_LCD_TFT; 689 dssdev->panel.config = OMAP_DSS_LCD_TFT;
506 dssdev->panel.timings = taal_panel_timings; 690 dssdev->panel.timings = panel_config->timings;
507 dssdev->ctrl.pixel_size = 24; 691 dssdev->ctrl.pixel_size = 24;
508 692
509 td = kzalloc(sizeof(*td), GFP_KERNEL); 693 td = kzalloc(sizeof(*td), GFP_KERNEL);
510 if (!td) { 694 if (!td) {
511 r = -ENOMEM; 695 r = -ENOMEM;
512 goto err0; 696 goto err;
513 } 697 }
514 td->dssdev = dssdev; 698 td->dssdev = dssdev;
699 td->panel_config = panel_config;
515 700
516 mutex_init(&td->lock); 701 mutex_init(&td->lock);
517 702
703 atomic_set(&td->do_update, 0);
704
705 r = init_regulators(dssdev, panel_config->regulators,
706 panel_config->num_regulators);
707 if (r)
708 goto err_reg;
709
518 td->esd_wq = create_singlethread_workqueue("taal_esd"); 710 td->esd_wq = create_singlethread_workqueue("taal_esd");
519 if (td->esd_wq == NULL) { 711 if (td->esd_wq == NULL) {
520 dev_err(&dssdev->dev, "can't create ESD workqueue\n"); 712 dev_err(&dssdev->dev, "can't create ESD workqueue\n");
521 r = -ENOMEM; 713 r = -ENOMEM;
522 goto err1; 714 goto err_wq;
523 } 715 }
524 INIT_DELAYED_WORK_DEFERRABLE(&td->esd_work, taal_esd_work); 716 INIT_DELAYED_WORK_DEFERRABLE(&td->esd_work, taal_esd_work);
525 717
526 dev_set_drvdata(&dssdev->dev, td); 718 dev_set_drvdata(&dssdev->dev, td);
527 719
720 taal_hw_reset(dssdev);
721
528 /* if no platform set_backlight() defined, presume DSI backlight 722 /* if no platform set_backlight() defined, presume DSI backlight
529 * control */ 723 * control */
530 memset(&props, 0, sizeof(struct backlight_properties)); 724 memset(&props, 0, sizeof(struct backlight_properties));
531 if (!dssdev->set_backlight) 725 if (!panel_data->set_backlight)
532 td->use_dsi_bl = true; 726 td->use_dsi_bl = true;
533 727
534 if (td->use_dsi_bl) 728 if (td->use_dsi_bl)
@@ -539,7 +733,7 @@ static int taal_probe(struct omap_dss_device *dssdev)
539 &taal_bl_ops, &props); 733 &taal_bl_ops, &props);
540 if (IS_ERR(bldev)) { 734 if (IS_ERR(bldev)) {
541 r = PTR_ERR(bldev); 735 r = PTR_ERR(bldev);
542 goto err2; 736 goto err_bl;
543 } 737 }
544 738
545 td->bldev = bldev; 739 td->bldev = bldev;
@@ -553,13 +747,13 @@ static int taal_probe(struct omap_dss_device *dssdev)
553 747
554 taal_bl_update_status(bldev); 748 taal_bl_update_status(bldev);
555 749
556 if (dssdev->phy.dsi.ext_te) { 750 if (panel_data->use_ext_te) {
557 int gpio = dssdev->phy.dsi.ext_te_gpio; 751 int gpio = panel_data->ext_te_gpio;
558 752
559 r = gpio_request(gpio, "taal irq"); 753 r = gpio_request(gpio, "taal irq");
560 if (r) { 754 if (r) {
561 dev_err(&dssdev->dev, "GPIO request failed\n"); 755 dev_err(&dssdev->dev, "GPIO request failed\n");
562 goto err3; 756 goto err_gpio;
563 } 757 }
564 758
565 gpio_direction_input(gpio); 759 gpio_direction_input(gpio);
@@ -571,49 +765,52 @@ static int taal_probe(struct omap_dss_device *dssdev)
571 if (r) { 765 if (r) {
572 dev_err(&dssdev->dev, "IRQ request failed\n"); 766 dev_err(&dssdev->dev, "IRQ request failed\n");
573 gpio_free(gpio); 767 gpio_free(gpio);
574 goto err3; 768 goto err_irq;
575 } 769 }
576 770
577 init_completion(&td->te_completion); 771 INIT_DELAYED_WORK_DEFERRABLE(&td->te_timeout_work,
772 taal_te_timeout_work_callback);
578 773
579 td->use_ext_te = true; 774 dev_dbg(&dssdev->dev, "Using GPIO TE\n");
580 } 775 }
581 776
582 r = sysfs_create_group(&dssdev->dev.kobj, &taal_attr_group); 777 r = sysfs_create_group(&dssdev->dev.kobj, &taal_attr_group);
583 if (r) { 778 if (r) {
584 dev_err(&dssdev->dev, "failed to create sysfs files\n"); 779 dev_err(&dssdev->dev, "failed to create sysfs files\n");
585 goto err4; 780 goto err_sysfs;
586 } 781 }
587 782
588 return 0; 783 return 0;
589err4: 784err_sysfs:
590 if (td->use_ext_te) { 785 if (panel_data->use_ext_te)
591 int gpio = dssdev->phy.dsi.ext_te_gpio; 786 free_irq(gpio_to_irq(panel_data->ext_te_gpio), dssdev);
592 free_irq(gpio_to_irq(gpio), dssdev); 787err_irq:
593 gpio_free(gpio); 788 if (panel_data->use_ext_te)
594 } 789 gpio_free(panel_data->ext_te_gpio);
595err3: 790err_gpio:
596 backlight_device_unregister(bldev); 791 backlight_device_unregister(bldev);
597err2: 792err_bl:
598 cancel_delayed_work_sync(&td->esd_work);
599 destroy_workqueue(td->esd_wq); 793 destroy_workqueue(td->esd_wq);
600err1: 794err_wq:
795 free_regulators(panel_config->regulators, panel_config->num_regulators);
796err_reg:
601 kfree(td); 797 kfree(td);
602err0: 798err:
603 return r; 799 return r;
604} 800}
605 801
606static void taal_remove(struct omap_dss_device *dssdev) 802static void taal_remove(struct omap_dss_device *dssdev)
607{ 803{
608 struct taal_data *td = dev_get_drvdata(&dssdev->dev); 804 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
805 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
609 struct backlight_device *bldev; 806 struct backlight_device *bldev;
610 807
611 dev_dbg(&dssdev->dev, "remove\n"); 808 dev_dbg(&dssdev->dev, "remove\n");
612 809
613 sysfs_remove_group(&dssdev->dev.kobj, &taal_attr_group); 810 sysfs_remove_group(&dssdev->dev.kobj, &taal_attr_group);
614 811
615 if (td->use_ext_te) { 812 if (panel_data->use_ext_te) {
616 int gpio = dssdev->phy.dsi.ext_te_gpio; 813 int gpio = panel_data->ext_te_gpio;
617 free_irq(gpio_to_irq(gpio), dssdev); 814 free_irq(gpio_to_irq(gpio), dssdev);
618 gpio_free(gpio); 815 gpio_free(gpio);
619 } 816 }
@@ -623,9 +820,15 @@ static void taal_remove(struct omap_dss_device *dssdev)
623 taal_bl_update_status(bldev); 820 taal_bl_update_status(bldev);
624 backlight_device_unregister(bldev); 821 backlight_device_unregister(bldev);
625 822
626 cancel_delayed_work_sync(&td->esd_work); 823 cancel_delayed_work(&td->esd_work);
627 destroy_workqueue(td->esd_wq); 824 destroy_workqueue(td->esd_wq);
628 825
826 /* reset, to be sure that the panel is in a valid state */
827 taal_hw_reset(dssdev);
828
829 free_regulators(td->panel_config->regulators,
830 td->panel_config->num_regulators);
831
629 kfree(td); 832 kfree(td);
630} 833}
631 834
@@ -635,23 +838,14 @@ static int taal_power_on(struct omap_dss_device *dssdev)
635 u8 id1, id2, id3; 838 u8 id1, id2, id3;
636 int r; 839 int r;
637 840
638 if (dssdev->platform_enable) {
639 r = dssdev->platform_enable(dssdev);
640 if (r)
641 return r;
642 }
643
644 /* it seems we have to wait a bit until taal is ready */
645 msleep(5);
646
647 dsi_bus_lock();
648
649 r = omapdss_dsi_display_enable(dssdev); 841 r = omapdss_dsi_display_enable(dssdev);
650 if (r) { 842 if (r) {
651 dev_err(&dssdev->dev, "failed to enable DSI\n"); 843 dev_err(&dssdev->dev, "failed to enable DSI\n");
652 goto err0; 844 goto err0;
653 } 845 }
654 846
847 taal_hw_reset(dssdev);
848
655 omapdss_dsi_vc_enable_hs(TCH, false); 849 omapdss_dsi_vc_enable_hs(TCH, false);
656 850
657 r = taal_sleep_out(td); 851 r = taal_sleep_out(td);
@@ -662,34 +856,47 @@ static int taal_power_on(struct omap_dss_device *dssdev)
662 if (r) 856 if (r)
663 goto err; 857 goto err;
664 858
665 /* on early revisions CABC is broken */ 859 /* on early Taal revisions CABC is broken */
666 if (id2 == 0x00 || id2 == 0xff || id2 == 0x81) 860 if (td->panel_config->type == PANEL_TAAL &&
861 (id2 == 0x00 || id2 == 0xff || id2 == 0x81))
667 td->cabc_broken = true; 862 td->cabc_broken = true;
668 863
669 taal_dcs_write_1(DCS_BRIGHTNESS, 0xff); 864 r = taal_dcs_write_1(DCS_BRIGHTNESS, 0xff);
670 taal_dcs_write_1(DCS_CTRL_DISPLAY, (1<<2) | (1<<5)); /* BL | BCTRL */ 865 if (r)
866 goto err;
867
868 r = taal_dcs_write_1(DCS_CTRL_DISPLAY,
869 (1<<2) | (1<<5)); /* BL | BCTRL */
870 if (r)
871 goto err;
872
873 r = taal_dcs_write_1(DCS_PIXEL_FORMAT, 0x7); /* 24bit/pixel */
874 if (r)
875 goto err;
671 876
672 taal_dcs_write_1(DCS_PIXEL_FORMAT, 0x7); /* 24bit/pixel */ 877 r = taal_set_addr_mode(td->rotate, td->mirror);
878 if (r)
879 goto err;
673 880
674 taal_set_addr_mode(td->rotate, td->mirror); 881 if (!td->cabc_broken) {
675 if (!td->cabc_broken) 882 r = taal_dcs_write_1(DCS_WRITE_CABC, td->cabc_mode);
676 taal_dcs_write_1(DCS_WRITE_CABC, td->cabc_mode); 883 if (r)
884 goto err;
885 }
677 886
678 taal_dcs_write_0(DCS_DISPLAY_ON); 887 r = taal_dcs_write_0(DCS_DISPLAY_ON);
888 if (r)
889 goto err;
679 890
680 r = _taal_enable_te(dssdev, td->te_enabled); 891 r = _taal_enable_te(dssdev, td->te_enabled);
681 if (r) 892 if (r)
682 goto err; 893 goto err;
683 894
684#ifdef TAAL_USE_ESD_CHECK
685 queue_delayed_work(td->esd_wq, &td->esd_work, TAAL_ESD_CHECK_PERIOD);
686#endif
687
688 td->enabled = 1; 895 td->enabled = 1;
689 896
690 if (!td->intro_printed) { 897 if (!td->intro_printed) {
691 dev_info(&dssdev->dev, "revision %02x.%02x.%02x\n", 898 dev_info(&dssdev->dev, "%s panel revision %02x.%02x.%02x\n",
692 id1, id2, id3); 899 td->panel_config->name, id1, id2, id3);
693 if (td->cabc_broken) 900 if (td->cabc_broken)
694 dev_info(&dssdev->dev, 901 dev_info(&dssdev->dev,
695 "old Taal version, CABC disabled\n"); 902 "old Taal version, CABC disabled\n");
@@ -698,46 +905,44 @@ static int taal_power_on(struct omap_dss_device *dssdev)
698 905
699 omapdss_dsi_vc_enable_hs(TCH, true); 906 omapdss_dsi_vc_enable_hs(TCH, true);
700 907
701 dsi_bus_unlock();
702
703 return 0; 908 return 0;
704err: 909err:
910 dev_err(&dssdev->dev, "error while enabling panel, issuing HW reset\n");
911
912 taal_hw_reset(dssdev);
913
705 omapdss_dsi_display_disable(dssdev); 914 omapdss_dsi_display_disable(dssdev);
706err0: 915err0:
707 dsi_bus_unlock();
708 if (dssdev->platform_disable)
709 dssdev->platform_disable(dssdev);
710
711 return r; 916 return r;
712} 917}
713 918
714static void taal_power_off(struct omap_dss_device *dssdev) 919static void taal_power_off(struct omap_dss_device *dssdev)
715{ 920{
716 struct taal_data *td = dev_get_drvdata(&dssdev->dev); 921 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
922 int r;
717 923
718 dsi_bus_lock(); 924 r = taal_dcs_write_0(DCS_DISPLAY_OFF);
719 925 if (!r) {
720 cancel_delayed_work(&td->esd_work); 926 r = taal_sleep_in(td);
721 927 /* HACK: wait a bit so that the message goes through */
722 taal_dcs_write_0(DCS_DISPLAY_OFF); 928 msleep(10);
723 taal_sleep_in(td); 929 }
724 930
725 /* wait a bit so that the message goes through */ 931 if (r) {
726 msleep(10); 932 dev_err(&dssdev->dev,
933 "error disabling panel, issuing HW reset\n");
934 taal_hw_reset(dssdev);
935 }
727 936
728 omapdss_dsi_display_disable(dssdev); 937 omapdss_dsi_display_disable(dssdev);
729 938
730 if (dssdev->platform_disable)
731 dssdev->platform_disable(dssdev);
732
733 td->enabled = 0; 939 td->enabled = 0;
734
735 dsi_bus_unlock();
736} 940}
737 941
738static int taal_enable(struct omap_dss_device *dssdev) 942static int taal_enable(struct omap_dss_device *dssdev)
739{ 943{
740 struct taal_data *td = dev_get_drvdata(&dssdev->dev); 944 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
945 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
741 int r; 946 int r;
742 947
743 dev_dbg(&dssdev->dev, "enable\n"); 948 dev_dbg(&dssdev->dev, "enable\n");
@@ -749,10 +954,19 @@ static int taal_enable(struct omap_dss_device *dssdev)
749 goto err; 954 goto err;
750 } 955 }
751 956
957 dsi_bus_lock();
958
752 r = taal_power_on(dssdev); 959 r = taal_power_on(dssdev);
960
961 dsi_bus_unlock();
962
753 if (r) 963 if (r)
754 goto err; 964 goto err;
755 965
966 if (panel_data->use_esd_check)
967 queue_delayed_work(td->esd_wq, &td->esd_work,
968 TAAL_ESD_CHECK_PERIOD);
969
756 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE; 970 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
757 971
758 mutex_unlock(&td->lock); 972 mutex_unlock(&td->lock);
@@ -772,9 +986,15 @@ static void taal_disable(struct omap_dss_device *dssdev)
772 986
773 mutex_lock(&td->lock); 987 mutex_lock(&td->lock);
774 988
989 cancel_delayed_work(&td->esd_work);
990
991 dsi_bus_lock();
992
775 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) 993 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
776 taal_power_off(dssdev); 994 taal_power_off(dssdev);
777 995
996 dsi_bus_unlock();
997
778 dssdev->state = OMAP_DSS_DISPLAY_DISABLED; 998 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
779 999
780 mutex_unlock(&td->lock); 1000 mutex_unlock(&td->lock);
@@ -794,7 +1014,14 @@ static int taal_suspend(struct omap_dss_device *dssdev)
794 goto err; 1014 goto err;
795 } 1015 }
796 1016
1017 cancel_delayed_work(&td->esd_work);
1018
1019 dsi_bus_lock();
1020
797 taal_power_off(dssdev); 1021 taal_power_off(dssdev);
1022
1023 dsi_bus_unlock();
1024
798 dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED; 1025 dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
799 1026
800 mutex_unlock(&td->lock); 1027 mutex_unlock(&td->lock);
@@ -808,6 +1035,7 @@ err:
808static int taal_resume(struct omap_dss_device *dssdev) 1035static int taal_resume(struct omap_dss_device *dssdev)
809{ 1036{
810 struct taal_data *td = dev_get_drvdata(&dssdev->dev); 1037 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1038 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
811 int r; 1039 int r;
812 1040
813 dev_dbg(&dssdev->dev, "resume\n"); 1041 dev_dbg(&dssdev->dev, "resume\n");
@@ -819,8 +1047,20 @@ static int taal_resume(struct omap_dss_device *dssdev)
819 goto err; 1047 goto err;
820 } 1048 }
821 1049
1050 dsi_bus_lock();
1051
822 r = taal_power_on(dssdev); 1052 r = taal_power_on(dssdev);
823 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE; 1053
1054 dsi_bus_unlock();
1055
1056 if (r) {
1057 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
1058 } else {
1059 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
1060 if (panel_data->use_esd_check)
1061 queue_delayed_work(td->esd_wq, &td->esd_work,
1062 TAAL_ESD_CHECK_PERIOD);
1063 }
824 1064
825 mutex_unlock(&td->lock); 1065 mutex_unlock(&td->lock);
826 1066
@@ -837,10 +1077,52 @@ static void taal_framedone_cb(int err, void *data)
837 dsi_bus_unlock(); 1077 dsi_bus_unlock();
838} 1078}
839 1079
1080static irqreturn_t taal_te_isr(int irq, void *data)
1081{
1082 struct omap_dss_device *dssdev = data;
1083 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1084 int old;
1085 int r;
1086
1087 old = atomic_cmpxchg(&td->do_update, 1, 0);
1088
1089 if (old) {
1090 cancel_delayed_work(&td->te_timeout_work);
1091
1092 r = omap_dsi_update(dssdev, TCH,
1093 td->update_region.x,
1094 td->update_region.y,
1095 td->update_region.w,
1096 td->update_region.h,
1097 taal_framedone_cb, dssdev);
1098 if (r)
1099 goto err;
1100 }
1101
1102 return IRQ_HANDLED;
1103err:
1104 dev_err(&dssdev->dev, "start update failed\n");
1105 dsi_bus_unlock();
1106 return IRQ_HANDLED;
1107}
1108
1109static void taal_te_timeout_work_callback(struct work_struct *work)
1110{
1111 struct taal_data *td = container_of(work, struct taal_data,
1112 te_timeout_work.work);
1113 struct omap_dss_device *dssdev = td->dssdev;
1114
1115 dev_err(&dssdev->dev, "TE not received for 250ms!\n");
1116
1117 atomic_set(&td->do_update, 0);
1118 dsi_bus_unlock();
1119}
1120
840static int taal_update(struct omap_dss_device *dssdev, 1121static int taal_update(struct omap_dss_device *dssdev,
841 u16 x, u16 y, u16 w, u16 h) 1122 u16 x, u16 y, u16 w, u16 h)
842{ 1123{
843 struct taal_data *td = dev_get_drvdata(&dssdev->dev); 1124 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1125 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
844 int r; 1126 int r;
845 1127
846 dev_dbg(&dssdev->dev, "update %d, %d, %d x %d\n", x, y, w, h); 1128 dev_dbg(&dssdev->dev, "update %d, %d, %d x %d\n", x, y, w, h);
@@ -853,7 +1135,7 @@ static int taal_update(struct omap_dss_device *dssdev,
853 goto err; 1135 goto err;
854 } 1136 }
855 1137
856 r = omap_dsi_prepare_update(dssdev, &x, &y, &w, &h); 1138 r = omap_dsi_prepare_update(dssdev, &x, &y, &w, &h, true);
857 if (r) 1139 if (r)
858 goto err; 1140 goto err;
859 1141
@@ -861,10 +1143,21 @@ static int taal_update(struct omap_dss_device *dssdev,
861 if (r) 1143 if (r)
862 goto err; 1144 goto err;
863 1145
864 r = omap_dsi_update(dssdev, TCH, x, y, w, h, 1146 if (td->te_enabled && panel_data->use_ext_te) {
865 taal_framedone_cb, dssdev); 1147 td->update_region.x = x;
866 if (r) 1148 td->update_region.y = y;
867 goto err; 1149 td->update_region.w = w;
1150 td->update_region.h = h;
1151 barrier();
1152 schedule_delayed_work(&td->te_timeout_work,
1153 msecs_to_jiffies(250));
1154 atomic_set(&td->do_update, 1);
1155 } else {
1156 r = omap_dsi_update(dssdev, TCH, x, y, w, h,
1157 taal_framedone_cb, dssdev);
1158 if (r)
1159 goto err;
1160 }
868 1161
869 /* note: no bus_unlock here. unlock is in framedone_cb */ 1162 /* note: no bus_unlock here. unlock is in framedone_cb */
870 mutex_unlock(&td->lock); 1163 mutex_unlock(&td->lock);
@@ -894,20 +1187,19 @@ static int taal_sync(struct omap_dss_device *dssdev)
894static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable) 1187static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable)
895{ 1188{
896 struct taal_data *td = dev_get_drvdata(&dssdev->dev); 1189 struct taal_data *td = dev_get_drvdata(&dssdev->dev);
1190 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
897 int r; 1191 int r;
898 1192
899 td->te_enabled = enable;
900
901 if (enable) 1193 if (enable)
902 r = taal_dcs_write_1(DCS_TEAR_ON, 0); 1194 r = taal_dcs_write_1(DCS_TEAR_ON, 0);
903 else 1195 else
904 r = taal_dcs_write_0(DCS_TEAR_OFF); 1196 r = taal_dcs_write_0(DCS_TEAR_OFF);
905 1197
906 omapdss_dsi_enable_te(dssdev, enable); 1198 if (!panel_data->use_ext_te)
1199 omapdss_dsi_enable_te(dssdev, enable);
907 1200
908 /* XXX for some reason, DSI TE breaks if we don't wait here. 1201 if (td->panel_config->sleep.enable_te)
909 * Panel bug? Needs more studying */ 1202 msleep(td->panel_config->sleep.enable_te);
910 msleep(100);
911 1203
912 return r; 1204 return r;
913} 1205}
@@ -918,10 +1210,26 @@ static int taal_enable_te(struct omap_dss_device *dssdev, bool enable)
918 int r; 1210 int r;
919 1211
920 mutex_lock(&td->lock); 1212 mutex_lock(&td->lock);
1213
1214 if (td->te_enabled == enable)
1215 goto end;
1216
921 dsi_bus_lock(); 1217 dsi_bus_lock();
922 1218
923 r = _taal_enable_te(dssdev, enable); 1219 if (td->enabled) {
1220 r = _taal_enable_te(dssdev, enable);
1221 if (r)
1222 goto err;
1223 }
1224
1225 td->te_enabled = enable;
1226
1227 dsi_bus_unlock();
1228end:
1229 mutex_unlock(&td->lock);
924 1230
1231 return 0;
1232err:
925 dsi_bus_unlock(); 1233 dsi_bus_unlock();
926 mutex_unlock(&td->lock); 1234 mutex_unlock(&td->lock);
927 1235
@@ -948,6 +1256,10 @@ static int taal_rotate(struct omap_dss_device *dssdev, u8 rotate)
948 dev_dbg(&dssdev->dev, "rotate %d\n", rotate); 1256 dev_dbg(&dssdev->dev, "rotate %d\n", rotate);
949 1257
950 mutex_lock(&td->lock); 1258 mutex_lock(&td->lock);
1259
1260 if (td->rotate == rotate)
1261 goto end;
1262
951 dsi_bus_lock(); 1263 dsi_bus_lock();
952 1264
953 if (td->enabled) { 1265 if (td->enabled) {
@@ -959,6 +1271,7 @@ static int taal_rotate(struct omap_dss_device *dssdev, u8 rotate)
959 td->rotate = rotate; 1271 td->rotate = rotate;
960 1272
961 dsi_bus_unlock(); 1273 dsi_bus_unlock();
1274end:
962 mutex_unlock(&td->lock); 1275 mutex_unlock(&td->lock);
963 return 0; 1276 return 0;
964err: 1277err:
@@ -987,6 +1300,10 @@ static int taal_mirror(struct omap_dss_device *dssdev, bool enable)
987 dev_dbg(&dssdev->dev, "mirror %d\n", enable); 1300 dev_dbg(&dssdev->dev, "mirror %d\n", enable);
988 1301
989 mutex_lock(&td->lock); 1302 mutex_lock(&td->lock);
1303
1304 if (td->mirror == enable)
1305 goto end;
1306
990 dsi_bus_lock(); 1307 dsi_bus_lock();
991 if (td->enabled) { 1308 if (td->enabled) {
992 r = taal_set_addr_mode(td->rotate, enable); 1309 r = taal_set_addr_mode(td->rotate, enable);
@@ -997,6 +1314,7 @@ static int taal_mirror(struct omap_dss_device *dssdev, bool enable)
997 td->mirror = enable; 1314 td->mirror = enable;
998 1315
999 dsi_bus_unlock(); 1316 dsi_bus_unlock();
1317end:
1000 mutex_unlock(&td->lock); 1318 mutex_unlock(&td->lock);
1001 return 0; 1319 return 0;
1002err: 1320err:
@@ -1024,23 +1342,30 @@ static int taal_run_test(struct omap_dss_device *dssdev, int test_num)
1024 int r; 1342 int r;
1025 1343
1026 mutex_lock(&td->lock); 1344 mutex_lock(&td->lock);
1345
1346 if (!td->enabled) {
1347 r = -ENODEV;
1348 goto err1;
1349 }
1350
1027 dsi_bus_lock(); 1351 dsi_bus_lock();
1028 1352
1029 r = taal_dcs_read_1(DCS_GET_ID1, &id1); 1353 r = taal_dcs_read_1(DCS_GET_ID1, &id1);
1030 if (r) 1354 if (r)
1031 goto err; 1355 goto err2;
1032 r = taal_dcs_read_1(DCS_GET_ID2, &id2); 1356 r = taal_dcs_read_1(DCS_GET_ID2, &id2);
1033 if (r) 1357 if (r)
1034 goto err; 1358 goto err2;
1035 r = taal_dcs_read_1(DCS_GET_ID3, &id3); 1359 r = taal_dcs_read_1(DCS_GET_ID3, &id3);
1036 if (r) 1360 if (r)
1037 goto err; 1361 goto err2;
1038 1362
1039 dsi_bus_unlock(); 1363 dsi_bus_unlock();
1040 mutex_unlock(&td->lock); 1364 mutex_unlock(&td->lock);
1041 return 0; 1365 return 0;
1042err: 1366err2:
1043 dsi_bus_unlock(); 1367 dsi_bus_unlock();
1368err1:
1044 mutex_unlock(&td->lock); 1369 mutex_unlock(&td->lock);
1045 return r; 1370 return r;
1046} 1371}
@@ -1128,6 +1453,7 @@ static void taal_esd_work(struct work_struct *work)
1128 struct taal_data *td = container_of(work, struct taal_data, 1453 struct taal_data *td = container_of(work, struct taal_data,
1129 esd_work.work); 1454 esd_work.work);
1130 struct omap_dss_device *dssdev = td->dssdev; 1455 struct omap_dss_device *dssdev = td->dssdev;
1456 struct nokia_dsi_panel_data *panel_data = get_panel_data(dssdev);
1131 u8 state1, state2; 1457 u8 state1, state2;
1132 int r; 1458 int r;
1133 1459
@@ -1168,7 +1494,7 @@ static void taal_esd_work(struct work_struct *work)
1168 } 1494 }
1169 /* Self-diagnostics result is also shown on TE GPIO line. We need 1495 /* Self-diagnostics result is also shown on TE GPIO line. We need
1170 * to re-enable TE after self diagnostics */ 1496 * to re-enable TE after self diagnostics */
1171 if (td->use_ext_te && td->te_enabled) { 1497 if (td->te_enabled && panel_data->use_ext_te) {
1172 r = taal_dcs_write_1(DCS_TEAR_ON, 0); 1498 r = taal_dcs_write_1(DCS_TEAR_ON, 0);
1173 if (r) 1499 if (r)
1174 goto err; 1500 goto err;
@@ -1184,6 +1510,7 @@ err:
1184 dev_err(&dssdev->dev, "performing LCD reset\n"); 1510 dev_err(&dssdev->dev, "performing LCD reset\n");
1185 1511
1186 taal_power_off(dssdev); 1512 taal_power_off(dssdev);
1513 taal_hw_reset(dssdev);
1187 taal_power_on(dssdev); 1514 taal_power_on(dssdev);
1188 1515
1189 dsi_bus_unlock(); 1516 dsi_bus_unlock();
diff --git a/drivers/video/omap2/displays/panel-toppoly-tdo35s.c b/drivers/video/omap2/displays/panel-toppoly-tdo35s.c
index fa434ca6e4b7..e320e67d06f3 100644
--- a/drivers/video/omap2/displays/panel-toppoly-tdo35s.c
+++ b/drivers/video/omap2/displays/panel-toppoly-tdo35s.c
@@ -73,8 +73,12 @@ static void toppoly_tdo_panel_power_off(struct omap_dss_device *dssdev)
73 73
74static int toppoly_tdo_panel_probe(struct omap_dss_device *dssdev) 74static int toppoly_tdo_panel_probe(struct omap_dss_device *dssdev)
75{ 75{
76 dssdev->panel.config = OMAP_DSS_LCD_TFT | OMAP_DSS_LCD_IVS | 76 dssdev->panel.config = OMAP_DSS_LCD_TFT |
77 OMAP_DSS_LCD_IHS; 77 OMAP_DSS_LCD_IVS |
78 OMAP_DSS_LCD_IHS |
79 OMAP_DSS_LCD_IPC |
80 OMAP_DSS_LCD_ONOFF;
81
78 dssdev->panel.timings = toppoly_tdo_panel_timings; 82 dssdev->panel.timings = toppoly_tdo_panel_timings;
79 83
80 return 0; 84 return 0;
diff --git a/drivers/video/omap2/dss/dispc.c b/drivers/video/omap2/dss/dispc.c
index e777e352dbcd..5ecdc0004094 100644
--- a/drivers/video/omap2/dss/dispc.c
+++ b/drivers/video/omap2/dss/dispc.c
@@ -31,6 +31,7 @@
31#include <linux/seq_file.h> 31#include <linux/seq_file.h>
32#include <linux/delay.h> 32#include <linux/delay.h>
33#include <linux/workqueue.h> 33#include <linux/workqueue.h>
34#include <linux/hardirq.h>
34 35
35#include <plat/sram.h> 36#include <plat/sram.h>
36#include <plat/clock.h> 37#include <plat/clock.h>
@@ -335,7 +336,7 @@ void dispc_save_context(void)
335void dispc_restore_context(void) 336void dispc_restore_context(void)
336{ 337{
337 RR(SYSCONFIG); 338 RR(SYSCONFIG);
338 RR(IRQENABLE); 339 /*RR(IRQENABLE);*/
339 /*RR(CONTROL);*/ 340 /*RR(CONTROL);*/
340 RR(CONFIG); 341 RR(CONFIG);
341 RR(DEFAULT_COLOR0); 342 RR(DEFAULT_COLOR0);
@@ -472,6 +473,15 @@ void dispc_restore_context(void)
472 473
473 /* enable last, because LCD & DIGIT enable are here */ 474 /* enable last, because LCD & DIGIT enable are here */
474 RR(CONTROL); 475 RR(CONTROL);
476
477 /* clear spurious SYNC_LOST_DIGIT interrupts */
478 dispc_write_reg(DISPC_IRQSTATUS, DISPC_IRQ_SYNC_LOST_DIGIT);
479
480 /*
481 * enable last so IRQs won't trigger before
482 * the context is fully restored
483 */
484 RR(IRQENABLE);
475} 485}
476 486
477#undef SR 487#undef SR
@@ -3019,7 +3029,7 @@ void dispc_fake_vsync_irq(void)
3019 u32 irqstatus = DISPC_IRQ_VSYNC; 3029 u32 irqstatus = DISPC_IRQ_VSYNC;
3020 int i; 3030 int i;
3021 3031
3022 local_irq_disable(); 3032 WARN_ON(!in_interrupt());
3023 3033
3024 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) { 3034 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
3025 struct omap_dispc_isr_data *isr_data; 3035 struct omap_dispc_isr_data *isr_data;
@@ -3031,8 +3041,6 @@ void dispc_fake_vsync_irq(void)
3031 if (isr_data->mask & irqstatus) 3041 if (isr_data->mask & irqstatus)
3032 isr_data->isr(isr_data->arg, irqstatus); 3042 isr_data->isr(isr_data->arg, irqstatus);
3033 } 3043 }
3034
3035 local_irq_enable();
3036} 3044}
3037#endif 3045#endif
3038 3046
diff --git a/drivers/video/omap2/dss/display.c b/drivers/video/omap2/dss/display.c
index ef8c8529dda2..22dd7a474f79 100644
--- a/drivers/video/omap2/dss/display.c
+++ b/drivers/video/omap2/dss/display.c
@@ -82,6 +82,9 @@ static ssize_t display_upd_mode_store(struct device *dev,
82 int val, r; 82 int val, r;
83 enum omap_dss_update_mode mode; 83 enum omap_dss_update_mode mode;
84 84
85 if (!dssdev->driver->set_update_mode)
86 return -EINVAL;
87
85 val = simple_strtoul(buf, NULL, 10); 88 val = simple_strtoul(buf, NULL, 10);
86 89
87 switch (val) { 90 switch (val) {
@@ -343,7 +346,6 @@ int omapdss_default_get_recommended_bpp(struct omap_dss_device *dssdev)
343 case OMAP_DISPLAY_TYPE_VENC: 346 case OMAP_DISPLAY_TYPE_VENC:
344 case OMAP_DISPLAY_TYPE_SDI: 347 case OMAP_DISPLAY_TYPE_SDI:
345 return 24; 348 return 24;
346 return 24;
347 default: 349 default:
348 BUG(); 350 BUG();
349 } 351 }
diff --git a/drivers/video/omap2/dss/dsi.c b/drivers/video/omap2/dss/dsi.c
index 3af207b2bde3..b3fa3a7db911 100644
--- a/drivers/video/omap2/dss/dsi.c
+++ b/drivers/video/omap2/dss/dsi.c
@@ -165,6 +165,14 @@ struct dsi_reg { u16 idx; };
165#define DSI_CIO_IRQ_ERRCONTENTIONLP1_3 (1 << 25) 165#define DSI_CIO_IRQ_ERRCONTENTIONLP1_3 (1 << 25)
166#define DSI_CIO_IRQ_ULPSACTIVENOT_ALL0 (1 << 30) 166#define DSI_CIO_IRQ_ULPSACTIVENOT_ALL0 (1 << 30)
167#define DSI_CIO_IRQ_ULPSACTIVENOT_ALL1 (1 << 31) 167#define DSI_CIO_IRQ_ULPSACTIVENOT_ALL1 (1 << 31)
168#define DSI_CIO_IRQ_ERROR_MASK \
169 (DSI_CIO_IRQ_ERRSYNCESC1 | DSI_CIO_IRQ_ERRSYNCESC2 | \
170 DSI_CIO_IRQ_ERRSYNCESC3 | DSI_CIO_IRQ_ERRESC1 | DSI_CIO_IRQ_ERRESC2 | \
171 DSI_CIO_IRQ_ERRESC3 | DSI_CIO_IRQ_ERRCONTROL1 | \
172 DSI_CIO_IRQ_ERRCONTROL2 | DSI_CIO_IRQ_ERRCONTROL3 | \
173 DSI_CIO_IRQ_ERRCONTENTIONLP0_1 | DSI_CIO_IRQ_ERRCONTENTIONLP1_1 | \
174 DSI_CIO_IRQ_ERRCONTENTIONLP0_2 | DSI_CIO_IRQ_ERRCONTENTIONLP1_2 | \
175 DSI_CIO_IRQ_ERRCONTENTIONLP0_3 | DSI_CIO_IRQ_ERRCONTENTIONLP1_3)
168 176
169#define DSI_DT_DCS_SHORT_WRITE_0 0x05 177#define DSI_DT_DCS_SHORT_WRITE_0 0x05
170#define DSI_DT_DCS_SHORT_WRITE_1 0x15 178#define DSI_DT_DCS_SHORT_WRITE_1 0x15
@@ -232,13 +240,15 @@ static struct
232 unsigned pll_locked; 240 unsigned pll_locked;
233 241
234 struct completion bta_completion; 242 struct completion bta_completion;
243 void (*bta_callback)(void);
235 244
236 int update_channel; 245 int update_channel;
237 struct dsi_update_region update_region; 246 struct dsi_update_region update_region;
238 247
239 bool te_enabled; 248 bool te_enabled;
240 249
241 struct work_struct framedone_work; 250 struct workqueue_struct *workqueue;
251
242 void (*framedone_callback)(int, void *); 252 void (*framedone_callback)(int, void *);
243 void *framedone_data; 253 void *framedone_data;
244 254
@@ -509,9 +519,13 @@ void dsi_irq_handler(void)
509 dss_collect_irq_stats(vcstatus, dsi.irq_stats.vc_irqs[i]); 519 dss_collect_irq_stats(vcstatus, dsi.irq_stats.vc_irqs[i]);
510#endif 520#endif
511 521
512 if (vcstatus & DSI_VC_IRQ_BTA) 522 if (vcstatus & DSI_VC_IRQ_BTA) {
513 complete(&dsi.bta_completion); 523 complete(&dsi.bta_completion);
514 524
525 if (dsi.bta_callback)
526 dsi.bta_callback();
527 }
528
515 if (vcstatus & DSI_VC_IRQ_ERROR_MASK) { 529 if (vcstatus & DSI_VC_IRQ_ERROR_MASK) {
516 DSSERR("DSI VC(%d) error, vc irqstatus %x\n", 530 DSSERR("DSI VC(%d) error, vc irqstatus %x\n",
517 i, vcstatus); 531 i, vcstatus);
@@ -536,8 +550,12 @@ void dsi_irq_handler(void)
536 /* flush posted write */ 550 /* flush posted write */
537 dsi_read_reg(DSI_COMPLEXIO_IRQ_STATUS); 551 dsi_read_reg(DSI_COMPLEXIO_IRQ_STATUS);
538 552
539 DSSERR("DSI CIO error, cio irqstatus %x\n", ciostatus); 553 if (ciostatus & DSI_CIO_IRQ_ERROR_MASK) {
540 print_irq_status_cio(ciostatus); 554 DSSERR("DSI CIO error, cio irqstatus %x\n", ciostatus);
555 print_irq_status_cio(ciostatus);
556 } else if (debug_irq) {
557 print_irq_status_cio(ciostatus);
558 }
541 } 559 }
542 560
543 dsi_write_reg(DSI_IRQSTATUS, irqstatus & ~DSI_IRQ_CHANNEL_MASK); 561 dsi_write_reg(DSI_IRQSTATUS, irqstatus & ~DSI_IRQ_CHANNEL_MASK);
@@ -584,11 +602,8 @@ static void _dsi_initialize_irq(void)
584 for (i = 0; i < 4; ++i) 602 for (i = 0; i < 4; ++i)
585 dsi_write_reg(DSI_VC_IRQENABLE(i), l); 603 dsi_write_reg(DSI_VC_IRQENABLE(i), l);
586 604
587 /* XXX zonda responds incorrectly, causing control error: 605 l = DSI_CIO_IRQ_ERROR_MASK;
588 Exit from LP-ESC mode to LP11 uses wrong transition states on the 606 dsi_write_reg(DSI_COMPLEXIO_IRQ_ENABLE, l);
589 data lines LP0 and LN0. */
590 dsi_write_reg(DSI_COMPLEXIO_IRQ_ENABLE,
591 -1 & (~DSI_CIO_IRQ_ERRCONTROL2));
592} 607}
593 608
594static u32 dsi_get_errors(void) 609static u32 dsi_get_errors(void)
@@ -1098,6 +1113,7 @@ int dsi_pll_init(struct omap_dss_device *dssdev, bool enable_hsclk,
1098 if (wait_for_bit_change(DSI_PLL_STATUS, 0, 1) != 1) { 1113 if (wait_for_bit_change(DSI_PLL_STATUS, 0, 1) != 1) {
1099 DSSERR("PLL not coming out of reset.\n"); 1114 DSSERR("PLL not coming out of reset.\n");
1100 r = -ENODEV; 1115 r = -ENODEV;
1116 dispc_pck_free_enable(0);
1101 goto err1; 1117 goto err1;
1102 } 1118 }
1103 1119
@@ -1740,42 +1756,52 @@ static void dsi_vc_initial_config(int channel)
1740 dsi.vc[channel].mode = DSI_VC_MODE_L4; 1756 dsi.vc[channel].mode = DSI_VC_MODE_L4;
1741} 1757}
1742 1758
1743static void dsi_vc_config_l4(int channel) 1759static int dsi_vc_config_l4(int channel)
1744{ 1760{
1745 if (dsi.vc[channel].mode == DSI_VC_MODE_L4) 1761 if (dsi.vc[channel].mode == DSI_VC_MODE_L4)
1746 return; 1762 return 0;
1747 1763
1748 DSSDBGF("%d", channel); 1764 DSSDBGF("%d", channel);
1749 1765
1750 dsi_vc_enable(channel, 0); 1766 dsi_vc_enable(channel, 0);
1751 1767
1752 if (REG_GET(DSI_VC_CTRL(channel), 15, 15)) /* VC_BUSY */ 1768 /* VC_BUSY */
1769 if (wait_for_bit_change(DSI_VC_CTRL(channel), 15, 0) != 0) {
1753 DSSERR("vc(%d) busy when trying to config for L4\n", channel); 1770 DSSERR("vc(%d) busy when trying to config for L4\n", channel);
1771 return -EIO;
1772 }
1754 1773
1755 REG_FLD_MOD(DSI_VC_CTRL(channel), 0, 1, 1); /* SOURCE, 0 = L4 */ 1774 REG_FLD_MOD(DSI_VC_CTRL(channel), 0, 1, 1); /* SOURCE, 0 = L4 */
1756 1775
1757 dsi_vc_enable(channel, 1); 1776 dsi_vc_enable(channel, 1);
1758 1777
1759 dsi.vc[channel].mode = DSI_VC_MODE_L4; 1778 dsi.vc[channel].mode = DSI_VC_MODE_L4;
1779
1780 return 0;
1760} 1781}
1761 1782
1762static void dsi_vc_config_vp(int channel) 1783static int dsi_vc_config_vp(int channel)
1763{ 1784{
1764 if (dsi.vc[channel].mode == DSI_VC_MODE_VP) 1785 if (dsi.vc[channel].mode == DSI_VC_MODE_VP)
1765 return; 1786 return 0;
1766 1787
1767 DSSDBGF("%d", channel); 1788 DSSDBGF("%d", channel);
1768 1789
1769 dsi_vc_enable(channel, 0); 1790 dsi_vc_enable(channel, 0);
1770 1791
1771 if (REG_GET(DSI_VC_CTRL(channel), 15, 15)) /* VC_BUSY */ 1792 /* VC_BUSY */
1793 if (wait_for_bit_change(DSI_VC_CTRL(channel), 15, 0) != 0) {
1772 DSSERR("vc(%d) busy when trying to config for VP\n", channel); 1794 DSSERR("vc(%d) busy when trying to config for VP\n", channel);
1795 return -EIO;
1796 }
1773 1797
1774 REG_FLD_MOD(DSI_VC_CTRL(channel), 1, 1, 1); /* SOURCE, 1 = video port */ 1798 REG_FLD_MOD(DSI_VC_CTRL(channel), 1, 1, 1); /* SOURCE, 1 = video port */
1775 1799
1776 dsi_vc_enable(channel, 1); 1800 dsi_vc_enable(channel, 1);
1777 1801
1778 dsi.vc[channel].mode = DSI_VC_MODE_VP; 1802 dsi.vc[channel].mode = DSI_VC_MODE_VP;
1803
1804 return 0;
1779} 1805}
1780 1806
1781 1807
@@ -1854,19 +1880,19 @@ static u16 dsi_vc_flush_receive_data(int channel)
1854 u32 val; 1880 u32 val;
1855 u8 dt; 1881 u8 dt;
1856 val = dsi_read_reg(DSI_VC_SHORT_PACKET_HEADER(channel)); 1882 val = dsi_read_reg(DSI_VC_SHORT_PACKET_HEADER(channel));
1857 DSSDBG("\trawval %#08x\n", val); 1883 DSSERR("\trawval %#08x\n", val);
1858 dt = FLD_GET(val, 5, 0); 1884 dt = FLD_GET(val, 5, 0);
1859 if (dt == DSI_DT_RX_ACK_WITH_ERR) { 1885 if (dt == DSI_DT_RX_ACK_WITH_ERR) {
1860 u16 err = FLD_GET(val, 23, 8); 1886 u16 err = FLD_GET(val, 23, 8);
1861 dsi_show_rx_ack_with_err(err); 1887 dsi_show_rx_ack_with_err(err);
1862 } else if (dt == DSI_DT_RX_SHORT_READ_1) { 1888 } else if (dt == DSI_DT_RX_SHORT_READ_1) {
1863 DSSDBG("\tDCS short response, 1 byte: %#x\n", 1889 DSSERR("\tDCS short response, 1 byte: %#x\n",
1864 FLD_GET(val, 23, 8)); 1890 FLD_GET(val, 23, 8));
1865 } else if (dt == DSI_DT_RX_SHORT_READ_2) { 1891 } else if (dt == DSI_DT_RX_SHORT_READ_2) {
1866 DSSDBG("\tDCS short response, 2 byte: %#x\n", 1892 DSSERR("\tDCS short response, 2 byte: %#x\n",
1867 FLD_GET(val, 23, 8)); 1893 FLD_GET(val, 23, 8));
1868 } else if (dt == DSI_DT_RX_DCS_LONG_READ) { 1894 } else if (dt == DSI_DT_RX_DCS_LONG_READ) {
1869 DSSDBG("\tDCS long response, len %d\n", 1895 DSSERR("\tDCS long response, len %d\n",
1870 FLD_GET(val, 23, 8)); 1896 FLD_GET(val, 23, 8));
1871 dsi_vc_flush_long_data(channel); 1897 dsi_vc_flush_long_data(channel);
1872 } else { 1898 } else {
@@ -2087,6 +2113,13 @@ int dsi_vc_dcs_write(int channel, u8 *data, int len)
2087 if (r) 2113 if (r)
2088 goto err; 2114 goto err;
2089 2115
2116 if (REG_GET(DSI_VC_CTRL(channel), 20, 20)) { /* RX_FIFO_NOT_EMPTY */
2117 DSSERR("rx fifo not empty after write, dumping data:\n");
2118 dsi_vc_flush_receive_data(channel);
2119 r = -EIO;
2120 goto err;
2121 }
2122
2090 return 0; 2123 return 0;
2091err: 2124err:
2092 DSSERR("dsi_vc_dcs_write(ch %d, cmd 0x%02x, len %d) failed\n", 2125 DSSERR("dsi_vc_dcs_write(ch %d, cmd 0x%02x, len %d) failed\n",
@@ -2233,11 +2266,12 @@ int dsi_vc_dcs_read_1(int channel, u8 dcs_cmd, u8 *data)
2233} 2266}
2234EXPORT_SYMBOL(dsi_vc_dcs_read_1); 2267EXPORT_SYMBOL(dsi_vc_dcs_read_1);
2235 2268
2236int dsi_vc_dcs_read_2(int channel, u8 dcs_cmd, u16 *data) 2269int dsi_vc_dcs_read_2(int channel, u8 dcs_cmd, u8 *data1, u8 *data2)
2237{ 2270{
2271 u8 buf[2];
2238 int r; 2272 int r;
2239 2273
2240 r = dsi_vc_dcs_read(channel, dcs_cmd, (u8 *)data, 2); 2274 r = dsi_vc_dcs_read(channel, dcs_cmd, buf, 2);
2241 2275
2242 if (r < 0) 2276 if (r < 0)
2243 return r; 2277 return r;
@@ -2245,231 +2279,122 @@ int dsi_vc_dcs_read_2(int channel, u8 dcs_cmd, u16 *data)
2245 if (r != 2) 2279 if (r != 2)
2246 return -EIO; 2280 return -EIO;
2247 2281
2282 *data1 = buf[0];
2283 *data2 = buf[1];
2284
2248 return 0; 2285 return 0;
2249} 2286}
2250EXPORT_SYMBOL(dsi_vc_dcs_read_2); 2287EXPORT_SYMBOL(dsi_vc_dcs_read_2);
2251 2288
2252int dsi_vc_set_max_rx_packet_size(int channel, u16 len) 2289int dsi_vc_set_max_rx_packet_size(int channel, u16 len)
2253{ 2290{
2254 int r; 2291 return dsi_vc_send_short(channel, DSI_DT_SET_MAX_RET_PKG_SIZE,
2255 r = dsi_vc_send_short(channel, DSI_DT_SET_MAX_RET_PKG_SIZE,
2256 len, 0); 2292 len, 0);
2257
2258 if (r)
2259 return r;
2260
2261 r = dsi_vc_send_bta_sync(channel);
2262
2263 return r;
2264} 2293}
2265EXPORT_SYMBOL(dsi_vc_set_max_rx_packet_size); 2294EXPORT_SYMBOL(dsi_vc_set_max_rx_packet_size);
2266 2295
2267static void dsi_set_lp_rx_timeout(unsigned long ns) 2296static void dsi_set_lp_rx_timeout(unsigned ticks, bool x4, bool x16)
2268{ 2297{
2269 u32 r;
2270 unsigned x4, x16;
2271 unsigned long fck; 2298 unsigned long fck;
2272 unsigned long ticks; 2299 unsigned long total_ticks;
2300 u32 r;
2273 2301
2274 /* ticks in DSI_FCK */ 2302 BUG_ON(ticks > 0x1fff);
2275 2303
2304 /* ticks in DSI_FCK */
2276 fck = dsi_fclk_rate(); 2305 fck = dsi_fclk_rate();
2277 ticks = (fck / 1000 / 1000) * ns / 1000;
2278 x4 = 0;
2279 x16 = 0;
2280
2281 if (ticks > 0x1fff) {
2282 ticks = (fck / 1000 / 1000) * ns / 1000 / 4;
2283 x4 = 1;
2284 x16 = 0;
2285 }
2286
2287 if (ticks > 0x1fff) {
2288 ticks = (fck / 1000 / 1000) * ns / 1000 / 16;
2289 x4 = 0;
2290 x16 = 1;
2291 }
2292
2293 if (ticks > 0x1fff) {
2294 ticks = (fck / 1000 / 1000) * ns / 1000 / (4 * 16);
2295 x4 = 1;
2296 x16 = 1;
2297 }
2298
2299 if (ticks > 0x1fff) {
2300 DSSWARN("LP_TX_TO over limit, setting it to max\n");
2301 ticks = 0x1fff;
2302 x4 = 1;
2303 x16 = 1;
2304 }
2305 2306
2306 r = dsi_read_reg(DSI_TIMING2); 2307 r = dsi_read_reg(DSI_TIMING2);
2307 r = FLD_MOD(r, 1, 15, 15); /* LP_RX_TO */ 2308 r = FLD_MOD(r, 1, 15, 15); /* LP_RX_TO */
2308 r = FLD_MOD(r, x16, 14, 14); /* LP_RX_TO_X16 */ 2309 r = FLD_MOD(r, x16 ? 1 : 0, 14, 14); /* LP_RX_TO_X16 */
2309 r = FLD_MOD(r, x4, 13, 13); /* LP_RX_TO_X4 */ 2310 r = FLD_MOD(r, x4 ? 1 : 0, 13, 13); /* LP_RX_TO_X4 */
2310 r = FLD_MOD(r, ticks, 12, 0); /* LP_RX_COUNTER */ 2311 r = FLD_MOD(r, ticks, 12, 0); /* LP_RX_COUNTER */
2311 dsi_write_reg(DSI_TIMING2, r); 2312 dsi_write_reg(DSI_TIMING2, r);
2312 2313
2313 DSSDBG("LP_RX_TO %lu ns (%#lx ticks%s%s)\n", 2314 total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
2314 (ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1) * 1000) / 2315
2315 (fck / 1000 / 1000), 2316 DSSDBG("LP_RX_TO %lu ticks (%#x%s%s) = %lu ns\n",
2316 ticks, x4 ? " x4" : "", x16 ? " x16" : ""); 2317 total_ticks,
2318 ticks, x4 ? " x4" : "", x16 ? " x16" : "",
2319 (total_ticks * 1000) / (fck / 1000 / 1000));
2317} 2320}
2318 2321
2319static void dsi_set_ta_timeout(unsigned long ns) 2322static void dsi_set_ta_timeout(unsigned ticks, bool x8, bool x16)
2320{ 2323{
2321 u32 r;
2322 unsigned x8, x16;
2323 unsigned long fck; 2324 unsigned long fck;
2324 unsigned long ticks; 2325 unsigned long total_ticks;
2326 u32 r;
2327
2328 BUG_ON(ticks > 0x1fff);
2325 2329
2326 /* ticks in DSI_FCK */ 2330 /* ticks in DSI_FCK */
2327 fck = dsi_fclk_rate(); 2331 fck = dsi_fclk_rate();
2328 ticks = (fck / 1000 / 1000) * ns / 1000;
2329 x8 = 0;
2330 x16 = 0;
2331
2332 if (ticks > 0x1fff) {
2333 ticks = (fck / 1000 / 1000) * ns / 1000 / 8;
2334 x8 = 1;
2335 x16 = 0;
2336 }
2337
2338 if (ticks > 0x1fff) {
2339 ticks = (fck / 1000 / 1000) * ns / 1000 / 16;
2340 x8 = 0;
2341 x16 = 1;
2342 }
2343
2344 if (ticks > 0x1fff) {
2345 ticks = (fck / 1000 / 1000) * ns / 1000 / (8 * 16);
2346 x8 = 1;
2347 x16 = 1;
2348 }
2349
2350 if (ticks > 0x1fff) {
2351 DSSWARN("TA_TO over limit, setting it to max\n");
2352 ticks = 0x1fff;
2353 x8 = 1;
2354 x16 = 1;
2355 }
2356 2332
2357 r = dsi_read_reg(DSI_TIMING1); 2333 r = dsi_read_reg(DSI_TIMING1);
2358 r = FLD_MOD(r, 1, 31, 31); /* TA_TO */ 2334 r = FLD_MOD(r, 1, 31, 31); /* TA_TO */
2359 r = FLD_MOD(r, x16, 30, 30); /* TA_TO_X16 */ 2335 r = FLD_MOD(r, x16 ? 1 : 0, 30, 30); /* TA_TO_X16 */
2360 r = FLD_MOD(r, x8, 29, 29); /* TA_TO_X8 */ 2336 r = FLD_MOD(r, x8 ? 1 : 0, 29, 29); /* TA_TO_X8 */
2361 r = FLD_MOD(r, ticks, 28, 16); /* TA_TO_COUNTER */ 2337 r = FLD_MOD(r, ticks, 28, 16); /* TA_TO_COUNTER */
2362 dsi_write_reg(DSI_TIMING1, r); 2338 dsi_write_reg(DSI_TIMING1, r);
2363 2339
2364 DSSDBG("TA_TO %lu ns (%#lx ticks%s%s)\n", 2340 total_ticks = ticks * (x16 ? 16 : 1) * (x8 ? 8 : 1);
2365 (ticks * (x16 ? 16 : 1) * (x8 ? 8 : 1) * 1000) / 2341
2366 (fck / 1000 / 1000), 2342 DSSDBG("TA_TO %lu ticks (%#x%s%s) = %lu ns\n",
2367 ticks, x8 ? " x8" : "", x16 ? " x16" : ""); 2343 total_ticks,
2344 ticks, x8 ? " x8" : "", x16 ? " x16" : "",
2345 (total_ticks * 1000) / (fck / 1000 / 1000));
2368} 2346}
2369 2347
2370static void dsi_set_stop_state_counter(unsigned long ns) 2348static void dsi_set_stop_state_counter(unsigned ticks, bool x4, bool x16)
2371{ 2349{
2372 u32 r;
2373 unsigned x4, x16;
2374 unsigned long fck; 2350 unsigned long fck;
2375 unsigned long ticks; 2351 unsigned long total_ticks;
2352 u32 r;
2376 2353
2377 /* ticks in DSI_FCK */ 2354 BUG_ON(ticks > 0x1fff);
2378 2355
2356 /* ticks in DSI_FCK */
2379 fck = dsi_fclk_rate(); 2357 fck = dsi_fclk_rate();
2380 ticks = (fck / 1000 / 1000) * ns / 1000;
2381 x4 = 0;
2382 x16 = 0;
2383
2384 if (ticks > 0x1fff) {
2385 ticks = (fck / 1000 / 1000) * ns / 1000 / 4;
2386 x4 = 1;
2387 x16 = 0;
2388 }
2389
2390 if (ticks > 0x1fff) {
2391 ticks = (fck / 1000 / 1000) * ns / 1000 / 16;
2392 x4 = 0;
2393 x16 = 1;
2394 }
2395
2396 if (ticks > 0x1fff) {
2397 ticks = (fck / 1000 / 1000) * ns / 1000 / (4 * 16);
2398 x4 = 1;
2399 x16 = 1;
2400 }
2401
2402 if (ticks > 0x1fff) {
2403 DSSWARN("STOP_STATE_COUNTER_IO over limit, "
2404 "setting it to max\n");
2405 ticks = 0x1fff;
2406 x4 = 1;
2407 x16 = 1;
2408 }
2409 2358
2410 r = dsi_read_reg(DSI_TIMING1); 2359 r = dsi_read_reg(DSI_TIMING1);
2411 r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */ 2360 r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
2412 r = FLD_MOD(r, x16, 14, 14); /* STOP_STATE_X16_IO */ 2361 r = FLD_MOD(r, x16 ? 1 : 0, 14, 14); /* STOP_STATE_X16_IO */
2413 r = FLD_MOD(r, x4, 13, 13); /* STOP_STATE_X4_IO */ 2362 r = FLD_MOD(r, x4 ? 1 : 0, 13, 13); /* STOP_STATE_X4_IO */
2414 r = FLD_MOD(r, ticks, 12, 0); /* STOP_STATE_COUNTER_IO */ 2363 r = FLD_MOD(r, ticks, 12, 0); /* STOP_STATE_COUNTER_IO */
2415 dsi_write_reg(DSI_TIMING1, r); 2364 dsi_write_reg(DSI_TIMING1, r);
2416 2365
2417 DSSDBG("STOP_STATE_COUNTER %lu ns (%#lx ticks%s%s)\n", 2366 total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
2418 (ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1) * 1000) / 2367
2419 (fck / 1000 / 1000), 2368 DSSDBG("STOP_STATE_COUNTER %lu ticks (%#x%s%s) = %lu ns\n",
2420 ticks, x4 ? " x4" : "", x16 ? " x16" : ""); 2369 total_ticks,
2370 ticks, x4 ? " x4" : "", x16 ? " x16" : "",
2371 (total_ticks * 1000) / (fck / 1000 / 1000));
2421} 2372}
2422 2373
2423static void dsi_set_hs_tx_timeout(unsigned long ns) 2374static void dsi_set_hs_tx_timeout(unsigned ticks, bool x4, bool x16)
2424{ 2375{
2425 u32 r;
2426 unsigned x4, x16;
2427 unsigned long fck; 2376 unsigned long fck;
2428 unsigned long ticks; 2377 unsigned long total_ticks;
2378 u32 r;
2429 2379
2430 /* ticks in TxByteClkHS */ 2380 BUG_ON(ticks > 0x1fff);
2431 2381
2382 /* ticks in TxByteClkHS */
2432 fck = dsi_get_txbyteclkhs(); 2383 fck = dsi_get_txbyteclkhs();
2433 ticks = (fck / 1000 / 1000) * ns / 1000;
2434 x4 = 0;
2435 x16 = 0;
2436
2437 if (ticks > 0x1fff) {
2438 ticks = (fck / 1000 / 1000) * ns / 1000 / 4;
2439 x4 = 1;
2440 x16 = 0;
2441 }
2442
2443 if (ticks > 0x1fff) {
2444 ticks = (fck / 1000 / 1000) * ns / 1000 / 16;
2445 x4 = 0;
2446 x16 = 1;
2447 }
2448
2449 if (ticks > 0x1fff) {
2450 ticks = (fck / 1000 / 1000) * ns / 1000 / (4 * 16);
2451 x4 = 1;
2452 x16 = 1;
2453 }
2454
2455 if (ticks > 0x1fff) {
2456 DSSWARN("HS_TX_TO over limit, setting it to max\n");
2457 ticks = 0x1fff;
2458 x4 = 1;
2459 x16 = 1;
2460 }
2461 2384
2462 r = dsi_read_reg(DSI_TIMING2); 2385 r = dsi_read_reg(DSI_TIMING2);
2463 r = FLD_MOD(r, 1, 31, 31); /* HS_TX_TO */ 2386 r = FLD_MOD(r, 1, 31, 31); /* HS_TX_TO */
2464 r = FLD_MOD(r, x16, 30, 30); /* HS_TX_TO_X16 */ 2387 r = FLD_MOD(r, x16 ? 1 : 0, 30, 30); /* HS_TX_TO_X16 */
2465 r = FLD_MOD(r, x4, 29, 29); /* HS_TX_TO_X8 (4 really) */ 2388 r = FLD_MOD(r, x4 ? 1 : 0, 29, 29); /* HS_TX_TO_X8 (4 really) */
2466 r = FLD_MOD(r, ticks, 28, 16); /* HS_TX_TO_COUNTER */ 2389 r = FLD_MOD(r, ticks, 28, 16); /* HS_TX_TO_COUNTER */
2467 dsi_write_reg(DSI_TIMING2, r); 2390 dsi_write_reg(DSI_TIMING2, r);
2468 2391
2469 DSSDBG("HS_TX_TO %lu ns (%#lx ticks%s%s)\n", 2392 total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
2470 (ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1) * 1000) / 2393
2471 (fck / 1000 / 1000), 2394 DSSDBG("HS_TX_TO %lu ticks (%#x%s%s) = %lu ns\n",
2472 ticks, x4 ? " x4" : "", x16 ? " x16" : ""); 2395 total_ticks,
2396 ticks, x4 ? " x4" : "", x16 ? " x16" : "",
2397 (total_ticks * 1000) / (fck / 1000 / 1000));
2473} 2398}
2474static int dsi_proto_config(struct omap_dss_device *dssdev) 2399static int dsi_proto_config(struct omap_dss_device *dssdev)
2475{ 2400{
@@ -2487,10 +2412,10 @@ static int dsi_proto_config(struct omap_dss_device *dssdev)
2487 DSI_FIFO_SIZE_32); 2412 DSI_FIFO_SIZE_32);
2488 2413
2489 /* XXX what values for the timeouts? */ 2414 /* XXX what values for the timeouts? */
2490 dsi_set_stop_state_counter(1000); 2415 dsi_set_stop_state_counter(0x1000, false, false);
2491 dsi_set_ta_timeout(6400000); 2416 dsi_set_ta_timeout(0x1fff, true, true);
2492 dsi_set_lp_rx_timeout(48000); 2417 dsi_set_lp_rx_timeout(0x1fff, true, true);
2493 dsi_set_hs_tx_timeout(1000000); 2418 dsi_set_hs_tx_timeout(0x1fff, true, true);
2494 2419
2495 switch (dssdev->ctrl.pixel_size) { 2420 switch (dssdev->ctrl.pixel_size) {
2496 case 16: 2421 case 16:
@@ -2759,6 +2684,7 @@ static void dsi_update_screen_dispc(struct omap_dss_device *dssdev,
2759 unsigned packet_payload; 2684 unsigned packet_payload;
2760 unsigned packet_len; 2685 unsigned packet_len;
2761 u32 l; 2686 u32 l;
2687 int r;
2762 const unsigned channel = dsi.update_channel; 2688 const unsigned channel = dsi.update_channel;
2763 /* line buffer is 1024 x 24bits */ 2689 /* line buffer is 1024 x 24bits */
2764 /* XXX: for some reason using full buffer size causes considerable TX 2690 /* XXX: for some reason using full buffer size causes considerable TX
@@ -2809,8 +2735,9 @@ static void dsi_update_screen_dispc(struct omap_dss_device *dssdev,
2809 2735
2810 dsi_perf_mark_start(); 2736 dsi_perf_mark_start();
2811 2737
2812 schedule_delayed_work(&dsi.framedone_timeout_work, 2738 r = queue_delayed_work(dsi.workqueue, &dsi.framedone_timeout_work,
2813 msecs_to_jiffies(250)); 2739 msecs_to_jiffies(250));
2740 BUG_ON(r == 0);
2814 2741
2815 dss_start_update(dssdev); 2742 dss_start_update(dssdev);
2816 2743
@@ -2834,62 +2761,70 @@ static void dsi_te_timeout(unsigned long arg)
2834} 2761}
2835#endif 2762#endif
2836 2763
2837static void dsi_framedone_timeout_work_callback(struct work_struct *work) 2764static void dsi_handle_framedone(int error)
2838{ 2765{
2839 int r;
2840 const int channel = dsi.update_channel; 2766 const int channel = dsi.update_channel;
2841 2767
2842 DSSERR("Framedone not received for 250ms!\n"); 2768 cancel_delayed_work(&dsi.framedone_timeout_work);
2769
2770 dsi_vc_disable_bta_irq(channel);
2843 2771
2844 /* SIDLEMODE back to smart-idle */ 2772 /* SIDLEMODE back to smart-idle */
2845 dispc_enable_sidle(); 2773 dispc_enable_sidle();
2846 2774
2775 dsi.bta_callback = NULL;
2776
2847 if (dsi.te_enabled) { 2777 if (dsi.te_enabled) {
2848 /* enable LP_RX_TO again after the TE */ 2778 /* enable LP_RX_TO again after the TE */
2849 REG_FLD_MOD(DSI_TIMING2, 1, 15, 15); /* LP_RX_TO */ 2779 REG_FLD_MOD(DSI_TIMING2, 1, 15, 15); /* LP_RX_TO */
2850 } 2780 }
2851 2781
2852 /* Send BTA after the frame. We need this for the TE to work, as TE
2853 * trigger is only sent for BTAs without preceding packet. Thus we need
2854 * to BTA after the pixel packets so that next BTA will cause TE
2855 * trigger.
2856 *
2857 * This is not needed when TE is not in use, but we do it anyway to
2858 * make sure that the transfer has been completed. It would be more
2859 * optimal, but more complex, to wait only just before starting next
2860 * transfer. */
2861 r = dsi_vc_send_bta_sync(channel);
2862 if (r)
2863 DSSERR("BTA after framedone failed\n");
2864
2865 /* RX_FIFO_NOT_EMPTY */ 2782 /* RX_FIFO_NOT_EMPTY */
2866 if (REG_GET(DSI_VC_CTRL(channel), 20, 20)) { 2783 if (REG_GET(DSI_VC_CTRL(channel), 20, 20)) {
2867 DSSERR("Received error during frame transfer:\n"); 2784 DSSERR("Received error during frame transfer:\n");
2868 dsi_vc_flush_receive_data(channel); 2785 dsi_vc_flush_receive_data(channel);
2786 if (!error)
2787 error = -EIO;
2869 } 2788 }
2870 2789
2871 dsi.framedone_callback(-ETIMEDOUT, dsi.framedone_data); 2790 dsi.framedone_callback(error, dsi.framedone_data);
2791
2792 if (!error)
2793 dsi_perf_show("DISPC");
2872} 2794}
2873 2795
2874static void dsi_framedone_irq_callback(void *data, u32 mask) 2796static void dsi_framedone_timeout_work_callback(struct work_struct *work)
2875{ 2797{
2876 /* Note: We get FRAMEDONE when DISPC has finished sending pixels and 2798 /* XXX While extremely unlikely, we could get FRAMEDONE interrupt after
2877 * turns itself off. However, DSI still has the pixels in its buffers, 2799 * 250ms which would conflict with this timeout work. What should be
2878 * and is sending the data. 2800 * done is first cancel the transfer on the HW, and then cancel the
2879 */ 2801 * possibly scheduled framedone work. However, cancelling the transfer
2802 * on the HW is buggy, and would probably require resetting the whole
2803 * DSI */
2880 2804
2881 /* SIDLEMODE back to smart-idle */ 2805 DSSERR("Framedone not received for 250ms!\n");
2882 dispc_enable_sidle();
2883 2806
2884 schedule_work(&dsi.framedone_work); 2807 dsi_handle_framedone(-ETIMEDOUT);
2885} 2808}
2886 2809
2887static void dsi_handle_framedone(void) 2810static void dsi_framedone_bta_callback(void)
2811{
2812 dsi_handle_framedone(0);
2813
2814#ifdef CONFIG_OMAP2_DSS_FAKE_VSYNC
2815 dispc_fake_vsync_irq();
2816#endif
2817}
2818
2819static void dsi_framedone_irq_callback(void *data, u32 mask)
2888{ 2820{
2889 int r;
2890 const int channel = dsi.update_channel; 2821 const int channel = dsi.update_channel;
2822 int r;
2891 2823
2892 DSSDBG("FRAMEDONE\n"); 2824 /* Note: We get FRAMEDONE when DISPC has finished sending pixels and
2825 * turns itself off. However, DSI still has the pixels in its buffers,
2826 * and is sending the data.
2827 */
2893 2828
2894 if (dsi.te_enabled) { 2829 if (dsi.te_enabled) {
2895 /* enable LP_RX_TO again after the TE */ 2830 /* enable LP_RX_TO again after the TE */
@@ -2904,37 +2839,30 @@ static void dsi_handle_framedone(void)
2904 * This is not needed when TE is not in use, but we do it anyway to 2839 * This is not needed when TE is not in use, but we do it anyway to
2905 * make sure that the transfer has been completed. It would be more 2840 * make sure that the transfer has been completed. It would be more
2906 * optimal, but more complex, to wait only just before starting next 2841 * optimal, but more complex, to wait only just before starting next
2907 * transfer. */ 2842 * transfer.
2908 r = dsi_vc_send_bta_sync(channel); 2843 *
2909 if (r) 2844 * Also, as there's no interrupt telling when the transfer has been
2910 DSSERR("BTA after framedone failed\n"); 2845 * done and the channel could be reconfigured, the only way is to
2911 2846 * busyloop until TE_SIZE is zero. With BTA we can do this
2912 /* RX_FIFO_NOT_EMPTY */ 2847 * asynchronously.
2913 if (REG_GET(DSI_VC_CTRL(channel), 20, 20)) { 2848 * */
2914 DSSERR("Received error during frame transfer:\n");
2915 dsi_vc_flush_receive_data(channel);
2916 }
2917
2918#ifdef CONFIG_OMAP2_DSS_FAKE_VSYNC
2919 dispc_fake_vsync_irq();
2920#endif
2921}
2922
2923static void dsi_framedone_work_callback(struct work_struct *work)
2924{
2925 DSSDBGF();
2926 2849
2927 cancel_delayed_work_sync(&dsi.framedone_timeout_work); 2850 dsi.bta_callback = dsi_framedone_bta_callback;
2928 2851
2929 dsi_handle_framedone(); 2852 barrier();
2930 2853
2931 dsi_perf_show("DISPC"); 2854 dsi_vc_enable_bta_irq(channel);
2932 2855
2933 dsi.framedone_callback(0, dsi.framedone_data); 2856 r = dsi_vc_send_bta(channel);
2857 if (r) {
2858 DSSERR("BTA after framedone failed\n");
2859 dsi_handle_framedone(-EIO);
2860 }
2934} 2861}
2935 2862
2936int omap_dsi_prepare_update(struct omap_dss_device *dssdev, 2863int omap_dsi_prepare_update(struct omap_dss_device *dssdev,
2937 u16 *x, u16 *y, u16 *w, u16 *h) 2864 u16 *x, u16 *y, u16 *w, u16 *h,
2865 bool enlarge_update_area)
2938{ 2866{
2939 u16 dw, dh; 2867 u16 dw, dh;
2940 2868
@@ -2958,7 +2886,8 @@ int omap_dsi_prepare_update(struct omap_dss_device *dssdev,
2958 dsi_perf_mark_setup(); 2886 dsi_perf_mark_setup();
2959 2887
2960 if (dssdev->manager->caps & OMAP_DSS_OVL_MGR_CAP_DISPC) { 2888 if (dssdev->manager->caps & OMAP_DSS_OVL_MGR_CAP_DISPC) {
2961 dss_setup_partial_planes(dssdev, x, y, w, h); 2889 dss_setup_partial_planes(dssdev, x, y, w, h,
2890 enlarge_update_area);
2962 dispc_set_lcd_size(*w, *h); 2891 dispc_set_lcd_size(*w, *h);
2963 } 2892 }
2964 2893
@@ -2973,6 +2902,12 @@ int omap_dsi_update(struct omap_dss_device *dssdev,
2973{ 2902{
2974 dsi.update_channel = channel; 2903 dsi.update_channel = channel;
2975 2904
2905 /* OMAP DSS cannot send updates of odd widths.
2906 * omap_dsi_prepare_update() makes the widths even, but add a BUG_ON
2907 * here to make sure we catch erroneous updates. Otherwise we'll only
2908 * see rather obscure HW error happening, as DSS halts. */
2909 BUG_ON(x % 2 == 1);
2910
2976 if (dssdev->manager->caps & OMAP_DSS_OVL_MGR_CAP_DISPC) { 2911 if (dssdev->manager->caps & OMAP_DSS_OVL_MGR_CAP_DISPC) {
2977 dsi.framedone_callback = callback; 2912 dsi.framedone_callback = callback;
2978 dsi.framedone_data = data; 2913 dsi.framedone_data = data;
@@ -2985,7 +2920,12 @@ int omap_dsi_update(struct omap_dss_device *dssdev,
2985 2920
2986 dsi_update_screen_dispc(dssdev, x, y, w, h); 2921 dsi_update_screen_dispc(dssdev, x, y, w, h);
2987 } else { 2922 } else {
2988 dsi_update_screen_l4(dssdev, x, y, w, h); 2923 int r;
2924
2925 r = dsi_update_screen_l4(dssdev, x, y, w, h);
2926 if (r)
2927 return r;
2928
2989 dsi_perf_show("L4"); 2929 dsi_perf_show("L4");
2990 callback(0, data); 2930 callback(0, data);
2991 } 2931 }
@@ -3048,8 +2988,10 @@ static int dsi_configure_dsi_clocks(struct omap_dss_device *dssdev)
3048 cinfo.regm3 = dssdev->phy.dsi.div.regm3; 2988 cinfo.regm3 = dssdev->phy.dsi.div.regm3;
3049 cinfo.regm4 = dssdev->phy.dsi.div.regm4; 2989 cinfo.regm4 = dssdev->phy.dsi.div.regm4;
3050 r = dsi_calc_clock_rates(&cinfo); 2990 r = dsi_calc_clock_rates(&cinfo);
3051 if (r) 2991 if (r) {
2992 DSSERR("Failed to calc dsi clocks\n");
3052 return r; 2993 return r;
2994 }
3053 2995
3054 r = dsi_pll_set_clock_div(&cinfo); 2996 r = dsi_pll_set_clock_div(&cinfo);
3055 if (r) { 2997 if (r) {
@@ -3147,6 +3089,13 @@ err0:
3147 3089
3148static void dsi_display_uninit_dsi(struct omap_dss_device *dssdev) 3090static void dsi_display_uninit_dsi(struct omap_dss_device *dssdev)
3149{ 3091{
3092 /* disable interface */
3093 dsi_if_enable(0);
3094 dsi_vc_enable(0, 0);
3095 dsi_vc_enable(1, 0);
3096 dsi_vc_enable(2, 0);
3097 dsi_vc_enable(3, 0);
3098
3150 dss_select_dispc_clk_source(DSS_SRC_DSS1_ALWON_FCLK); 3099 dss_select_dispc_clk_source(DSS_SRC_DSS1_ALWON_FCLK);
3151 dss_select_dsi_clk_source(DSS_SRC_DSS1_ALWON_FCLK); 3100 dss_select_dsi_clk_source(DSS_SRC_DSS1_ALWON_FCLK);
3152 dsi_complexio_uninit(); 3101 dsi_complexio_uninit();
@@ -3257,7 +3206,7 @@ void dsi_get_overlay_fifo_thresholds(enum omap_plane plane,
3257 burst_size_bytes = 16 * 32 / 8; 3206 burst_size_bytes = 16 * 32 / 8;
3258 3207
3259 *fifo_high = fifo_size - burst_size_bytes; 3208 *fifo_high = fifo_size - burst_size_bytes;
3260 *fifo_low = fifo_size - burst_size_bytes * 8; 3209 *fifo_low = fifo_size - burst_size_bytes * 2;
3261} 3210}
3262 3211
3263int dsi_init_display(struct omap_dss_device *dssdev) 3212int dsi_init_display(struct omap_dss_device *dssdev)
@@ -3274,6 +3223,18 @@ int dsi_init_display(struct omap_dss_device *dssdev)
3274 return 0; 3223 return 0;
3275} 3224}
3276 3225
3226void dsi_wait_dsi1_pll_active(void)
3227{
3228 if (wait_for_bit_change(DSI_PLL_STATUS, 7, 1) != 1)
3229 DSSERR("DSI1 PLL clock not active\n");
3230}
3231
3232void dsi_wait_dsi2_pll_active(void)
3233{
3234 if (wait_for_bit_change(DSI_PLL_STATUS, 8, 1) != 1)
3235 DSSERR("DSI2 PLL clock not active\n");
3236}
3237
3277int dsi_init(struct platform_device *pdev) 3238int dsi_init(struct platform_device *pdev)
3278{ 3239{
3279 u32 rev; 3240 u32 rev;
@@ -3292,7 +3253,10 @@ int dsi_init(struct platform_device *pdev)
3292 mutex_init(&dsi.lock); 3253 mutex_init(&dsi.lock);
3293 sema_init(&dsi.bus_lock, 1); 3254 sema_init(&dsi.bus_lock, 1);
3294 3255
3295 INIT_WORK(&dsi.framedone_work, dsi_framedone_work_callback); 3256 dsi.workqueue = create_singlethread_workqueue("dsi");
3257 if (dsi.workqueue == NULL)
3258 return -ENOMEM;
3259
3296 INIT_DELAYED_WORK_DEFERRABLE(&dsi.framedone_timeout_work, 3260 INIT_DELAYED_WORK_DEFERRABLE(&dsi.framedone_timeout_work,
3297 dsi_framedone_timeout_work_callback); 3261 dsi_framedone_timeout_work_callback);
3298 3262
@@ -3328,6 +3292,7 @@ int dsi_init(struct platform_device *pdev)
3328err2: 3292err2:
3329 iounmap(dsi.base); 3293 iounmap(dsi.base);
3330err1: 3294err1:
3295 destroy_workqueue(dsi.workqueue);
3331 return r; 3296 return r;
3332} 3297}
3333 3298
@@ -3335,6 +3300,8 @@ void dsi_exit(void)
3335{ 3300{
3336 iounmap(dsi.base); 3301 iounmap(dsi.base);
3337 3302
3303 destroy_workqueue(dsi.workqueue);
3304
3338 DSSDBG("omap_dsi_exit\n"); 3305 DSSDBG("omap_dsi_exit\n");
3339} 3306}
3340 3307
diff --git a/drivers/video/omap2/dss/dss.c b/drivers/video/omap2/dss/dss.c
index 24b18258654f..77c3621c9171 100644
--- a/drivers/video/omap2/dss/dss.c
+++ b/drivers/video/omap2/dss/dss.c
@@ -265,6 +265,9 @@ void dss_select_dispc_clk_source(enum dss_clk_source clk_src)
265 265
266 b = clk_src == DSS_SRC_DSS1_ALWON_FCLK ? 0 : 1; 266 b = clk_src == DSS_SRC_DSS1_ALWON_FCLK ? 0 : 1;
267 267
268 if (clk_src == DSS_SRC_DSI1_PLL_FCLK)
269 dsi_wait_dsi1_pll_active();
270
268 REG_FLD_MOD(DSS_CONTROL, b, 0, 0); /* DISPC_CLK_SWITCH */ 271 REG_FLD_MOD(DSS_CONTROL, b, 0, 0); /* DISPC_CLK_SWITCH */
269 272
270 dss.dispc_clk_source = clk_src; 273 dss.dispc_clk_source = clk_src;
@@ -279,6 +282,9 @@ void dss_select_dsi_clk_source(enum dss_clk_source clk_src)
279 282
280 b = clk_src == DSS_SRC_DSS1_ALWON_FCLK ? 0 : 1; 283 b = clk_src == DSS_SRC_DSS1_ALWON_FCLK ? 0 : 1;
281 284
285 if (clk_src == DSS_SRC_DSI2_PLL_FCLK)
286 dsi_wait_dsi2_pll_active();
287
282 REG_FLD_MOD(DSS_CONTROL, b, 1, 1); /* DSI_CLK_SWITCH */ 288 REG_FLD_MOD(DSS_CONTROL, b, 1, 1); /* DSI_CLK_SWITCH */
283 289
284 dss.dsi_clk_source = clk_src; 290 dss.dsi_clk_source = clk_src;
diff --git a/drivers/video/omap2/dss/dss.h b/drivers/video/omap2/dss/dss.h
index 786f433fd571..5c7940d5f282 100644
--- a/drivers/video/omap2/dss/dss.h
+++ b/drivers/video/omap2/dss/dss.h
@@ -199,7 +199,8 @@ int dss_init_overlay_managers(struct platform_device *pdev);
199void dss_uninit_overlay_managers(struct platform_device *pdev); 199void dss_uninit_overlay_managers(struct platform_device *pdev);
200int dss_mgr_wait_for_go_ovl(struct omap_overlay *ovl); 200int dss_mgr_wait_for_go_ovl(struct omap_overlay *ovl);
201void dss_setup_partial_planes(struct omap_dss_device *dssdev, 201void dss_setup_partial_planes(struct omap_dss_device *dssdev,
202 u16 *x, u16 *y, u16 *w, u16 *h); 202 u16 *x, u16 *y, u16 *w, u16 *h,
203 bool enlarge_update_area);
203void dss_start_update(struct omap_dss_device *dssdev); 204void dss_start_update(struct omap_dss_device *dssdev);
204 205
205/* overlay */ 206/* overlay */
@@ -281,6 +282,8 @@ void dsi_pll_uninit(void);
281void dsi_get_overlay_fifo_thresholds(enum omap_plane plane, 282void dsi_get_overlay_fifo_thresholds(enum omap_plane plane,
282 u32 fifo_size, enum omap_burst_size *burst_size, 283 u32 fifo_size, enum omap_burst_size *burst_size,
283 u32 *fifo_low, u32 *fifo_high); 284 u32 *fifo_low, u32 *fifo_high);
285void dsi_wait_dsi1_pll_active(void);
286void dsi_wait_dsi2_pll_active(void);
284#else 287#else
285static inline int dsi_init(struct platform_device *pdev) 288static inline int dsi_init(struct platform_device *pdev)
286{ 289{
@@ -289,6 +292,12 @@ static inline int dsi_init(struct platform_device *pdev)
289static inline void dsi_exit(void) 292static inline void dsi_exit(void)
290{ 293{
291} 294}
295static inline void dsi_wait_dsi1_pll_active(void)
296{
297}
298static inline void dsi_wait_dsi2_pll_active(void)
299{
300}
292#endif 301#endif
293 302
294/* DPI */ 303/* DPI */
diff --git a/drivers/video/omap2/dss/manager.c b/drivers/video/omap2/dss/manager.c
index 9e1fbe531bf0..6a649ab5539e 100644
--- a/drivers/video/omap2/dss/manager.c
+++ b/drivers/video/omap2/dss/manager.c
@@ -440,6 +440,10 @@ struct manager_cache_data {
440 440
441 /* manual update region */ 441 /* manual update region */
442 u16 x, y, w, h; 442 u16 x, y, w, h;
443
444 /* enlarge the update area if the update area contains scaled
445 * overlays */
446 bool enlarge_update_area;
443}; 447};
444 448
445static struct { 449static struct {
@@ -525,7 +529,7 @@ static int dss_mgr_wait_for_go(struct omap_overlay_manager *mgr)
525 int i; 529 int i;
526 struct omap_dss_device *dssdev = mgr->device; 530 struct omap_dss_device *dssdev = mgr->device;
527 531
528 if (!dssdev) 532 if (!dssdev || dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
529 return 0; 533 return 0;
530 534
531 if (dssdev->type == OMAP_DISPLAY_TYPE_VENC) { 535 if (dssdev->type == OMAP_DISPLAY_TYPE_VENC) {
@@ -596,11 +600,14 @@ int dss_mgr_wait_for_go_ovl(struct omap_overlay *ovl)
596 int r; 600 int r;
597 int i; 601 int i;
598 602
599 if (!ovl->manager || !ovl->manager->device) 603 if (!ovl->manager)
600 return 0; 604 return 0;
601 605
602 dssdev = ovl->manager->device; 606 dssdev = ovl->manager->device;
603 607
608 if (!dssdev || dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
609 return 0;
610
604 if (dssdev->type == OMAP_DISPLAY_TYPE_VENC) { 611 if (dssdev->type == OMAP_DISPLAY_TYPE_VENC) {
605 irq = DISPC_IRQ_EVSYNC_ODD | DISPC_IRQ_EVSYNC_EVEN; 612 irq = DISPC_IRQ_EVSYNC_ODD | DISPC_IRQ_EVSYNC_EVEN;
606 channel = OMAP_DSS_CHANNEL_DIGIT; 613 channel = OMAP_DSS_CHANNEL_DIGIT;
@@ -718,6 +725,7 @@ static int configure_overlay(enum omap_plane plane)
718 u16 x, y, w, h; 725 u16 x, y, w, h;
719 u32 paddr; 726 u32 paddr;
720 int r; 727 int r;
728 u16 orig_w, orig_h, orig_outw, orig_outh;
721 729
722 DSSDBGF("%d", plane); 730 DSSDBGF("%d", plane);
723 731
@@ -738,8 +746,16 @@ static int configure_overlay(enum omap_plane plane)
738 outh = c->out_height == 0 ? c->height : c->out_height; 746 outh = c->out_height == 0 ? c->height : c->out_height;
739 paddr = c->paddr; 747 paddr = c->paddr;
740 748
749 orig_w = w;
750 orig_h = h;
751 orig_outw = outw;
752 orig_outh = outh;
753
741 if (c->manual_update && mc->do_manual_update) { 754 if (c->manual_update && mc->do_manual_update) {
742 unsigned bpp; 755 unsigned bpp;
756 unsigned scale_x_m = w, scale_x_d = outw;
757 unsigned scale_y_m = h, scale_y_d = outh;
758
743 /* If the overlay is outside the update region, disable it */ 759 /* If the overlay is outside the update region, disable it */
744 if (!rectangle_intersects(mc->x, mc->y, mc->w, mc->h, 760 if (!rectangle_intersects(mc->x, mc->y, mc->w, mc->h,
745 x, y, outw, outh)) { 761 x, y, outw, outh)) {
@@ -770,38 +786,47 @@ static int configure_overlay(enum omap_plane plane)
770 BUG(); 786 BUG();
771 } 787 }
772 788
773 if (dispc_is_overlay_scaled(c)) { 789 if (mc->x > c->pos_x) {
774 /* If the overlay is scaled, the update area has 790 x = 0;
775 * already been enlarged to cover the whole overlay. We 791 outw -= (mc->x - c->pos_x);
776 * only need to adjust x/y here */ 792 paddr += (mc->x - c->pos_x) *
777 x = c->pos_x - mc->x; 793 scale_x_m / scale_x_d * bpp / 8;
778 y = c->pos_y - mc->y;
779 } else { 794 } else {
780 if (mc->x > c->pos_x) { 795 x = c->pos_x - mc->x;
781 x = 0; 796 }
782 w -= (mc->x - c->pos_x);
783 paddr += (mc->x - c->pos_x) * bpp / 8;
784 } else {
785 x = c->pos_x - mc->x;
786 }
787
788 if (mc->y > c->pos_y) {
789 y = 0;
790 h -= (mc->y - c->pos_y);
791 paddr += (mc->y - c->pos_y) * c->screen_width *
792 bpp / 8;
793 } else {
794 y = c->pos_y - mc->y;
795 }
796
797 if (mc->w < (x+w))
798 w -= (x+w) - (mc->w);
799 797
800 if (mc->h < (y+h)) 798 if (mc->y > c->pos_y) {
801 h -= (y+h) - (mc->h); 799 y = 0;
800 outh -= (mc->y - c->pos_y);
801 paddr += (mc->y - c->pos_y) *
802 scale_y_m / scale_y_d *
803 c->screen_width * bpp / 8;
804 } else {
805 y = c->pos_y - mc->y;
806 }
802 807
803 outw = w; 808 if (mc->w < (x + outw))
804 outh = h; 809 outw -= (x + outw) - (mc->w);
810
811 if (mc->h < (y + outh))
812 outh -= (y + outh) - (mc->h);
813
814 w = w * outw / orig_outw;
815 h = h * outh / orig_outh;
816
817 /* YUV mode overlay's input width has to be even and the
818 * algorithm above may adjust the width to be odd.
819 *
820 * Here we adjust the width if needed, preferring to increase
821 * the width if the original width was bigger.
822 */
823 if ((w & 1) &&
824 (c->color_mode == OMAP_DSS_COLOR_YUV2 ||
825 c->color_mode == OMAP_DSS_COLOR_UYVY)) {
826 if (orig_w > w)
827 w += 1;
828 else
829 w -= 1;
805 } 830 }
806 } 831 }
807 832
@@ -960,7 +985,7 @@ static void make_even(u16 *x, u16 *w)
960/* Configure dispc for partial update. Return possibly modified update 985/* Configure dispc for partial update. Return possibly modified update
961 * area */ 986 * area */
962void dss_setup_partial_planes(struct omap_dss_device *dssdev, 987void dss_setup_partial_planes(struct omap_dss_device *dssdev,
963 u16 *xi, u16 *yi, u16 *wi, u16 *hi) 988 u16 *xi, u16 *yi, u16 *wi, u16 *hi, bool enlarge_update_area)
964{ 989{
965 struct overlay_cache_data *oc; 990 struct overlay_cache_data *oc;
966 struct manager_cache_data *mc; 991 struct manager_cache_data *mc;
@@ -969,6 +994,7 @@ void dss_setup_partial_planes(struct omap_dss_device *dssdev,
969 int i; 994 int i;
970 u16 x, y, w, h; 995 u16 x, y, w, h;
971 unsigned long flags; 996 unsigned long flags;
997 bool area_changed;
972 998
973 x = *xi; 999 x = *xi;
974 y = *yi; 1000 y = *yi;
@@ -989,73 +1015,91 @@ void dss_setup_partial_planes(struct omap_dss_device *dssdev,
989 1015
990 spin_lock_irqsave(&dss_cache.lock, flags); 1016 spin_lock_irqsave(&dss_cache.lock, flags);
991 1017
992 /* We need to show the whole overlay if it is scaled. So look for 1018 /*
993 * those, and make the update area larger if found. 1019 * Execute the outer loop until the inner loop has completed
994 * Also mark the overlay cache dirty */ 1020 * once without increasing the update area. This will ensure that
995 for (i = 0; i < num_ovls; ++i) { 1021 * all scaled overlays end up completely within the update area.
996 unsigned x1, y1, x2, y2; 1022 */
997 unsigned outw, outh; 1023 do {
1024 area_changed = false;
998 1025
999 oc = &dss_cache.overlay_cache[i]; 1026 /* We need to show the whole overlay if it is scaled. So look
1027 * for those, and make the update area larger if found.
1028 * Also mark the overlay cache dirty */
1029 for (i = 0; i < num_ovls; ++i) {
1030 unsigned x1, y1, x2, y2;
1031 unsigned outw, outh;
1000 1032
1001 if (oc->channel != mgr->id) 1033 oc = &dss_cache.overlay_cache[i];
1002 continue;
1003 1034
1004 oc->dirty = true; 1035 if (oc->channel != mgr->id)
1036 continue;
1005 1037
1006 if (!oc->enabled) 1038 oc->dirty = true;
1007 continue;
1008 1039
1009 if (!dispc_is_overlay_scaled(oc)) 1040 if (!enlarge_update_area)
1010 continue; 1041 continue;
1011 1042
1012 outw = oc->out_width == 0 ? oc->width : oc->out_width; 1043 if (!oc->enabled)
1013 outh = oc->out_height == 0 ? oc->height : oc->out_height; 1044 continue;
1014 1045
1015 /* is the overlay outside the update region? */ 1046 if (!dispc_is_overlay_scaled(oc))
1016 if (!rectangle_intersects(x, y, w, h, 1047 continue;
1017 oc->pos_x, oc->pos_y,
1018 outw, outh))
1019 continue;
1020 1048
1021 /* if the overlay totally inside the update region? */ 1049 outw = oc->out_width == 0 ?
1022 if (rectangle_subset(oc->pos_x, oc->pos_y, outw, outh, 1050 oc->width : oc->out_width;
1023 x, y, w, h)) 1051 outh = oc->out_height == 0 ?
1024 continue; 1052 oc->height : oc->out_height;
1053
1054 /* is the overlay outside the update region? */
1055 if (!rectangle_intersects(x, y, w, h,
1056 oc->pos_x, oc->pos_y,
1057 outw, outh))
1058 continue;
1025 1059
1026 if (x > oc->pos_x) 1060 /* if the overlay totally inside the update region? */
1027 x1 = oc->pos_x; 1061 if (rectangle_subset(oc->pos_x, oc->pos_y, outw, outh,
1028 else 1062 x, y, w, h))
1029 x1 = x; 1063 continue;
1030 1064
1031 if (y > oc->pos_y) 1065 if (x > oc->pos_x)
1032 y1 = oc->pos_y; 1066 x1 = oc->pos_x;
1033 else 1067 else
1034 y1 = y; 1068 x1 = x;
1035 1069
1036 if ((x + w) < (oc->pos_x + outw)) 1070 if (y > oc->pos_y)
1037 x2 = oc->pos_x + outw; 1071 y1 = oc->pos_y;
1038 else 1072 else
1039 x2 = x + w; 1073 y1 = y;
1040 1074
1041 if ((y + h) < (oc->pos_y + outh)) 1075 if ((x + w) < (oc->pos_x + outw))
1042 y2 = oc->pos_y + outh; 1076 x2 = oc->pos_x + outw;
1043 else 1077 else
1044 y2 = y + h; 1078 x2 = x + w;
1045 1079
1046 x = x1; 1080 if ((y + h) < (oc->pos_y + outh))
1047 y = y1; 1081 y2 = oc->pos_y + outh;
1048 w = x2 - x1; 1082 else
1049 h = y2 - y1; 1083 y2 = y + h;
1050 1084
1051 make_even(&x, &w); 1085 x = x1;
1086 y = y1;
1087 w = x2 - x1;
1088 h = y2 - y1;
1052 1089
1053 DSSDBG("changing upd area due to ovl(%d) scaling %d,%d %dx%d\n", 1090 make_even(&x, &w);
1091
1092 DSSDBG("changing upd area due to ovl(%d) "
1093 "scaling %d,%d %dx%d\n",
1054 i, x, y, w, h); 1094 i, x, y, w, h);
1055 } 1095
1096 area_changed = true;
1097 }
1098 } while (area_changed);
1056 1099
1057 mc = &dss_cache.manager_cache[mgr->id]; 1100 mc = &dss_cache.manager_cache[mgr->id];
1058 mc->do_manual_update = true; 1101 mc->do_manual_update = true;
1102 mc->enlarge_update_area = enlarge_update_area;
1059 mc->x = x; 1103 mc->x = x;
1060 mc->y = y; 1104 mc->y = y;
1061 mc->w = w; 1105 mc->w = w;
diff --git a/drivers/video/omap2/dss/overlay.c b/drivers/video/omap2/dss/overlay.c
index 82336583adef..244dca81a399 100644
--- a/drivers/video/omap2/dss/overlay.c
+++ b/drivers/video/omap2/dss/overlay.c
@@ -65,7 +65,7 @@ static ssize_t overlay_manager_store(struct omap_overlay *ovl, const char *buf,
65 for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) { 65 for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) {
66 mgr = omap_dss_get_overlay_manager(i); 66 mgr = omap_dss_get_overlay_manager(i);
67 67
68 if (strncmp(buf, mgr->name, len) == 0) 68 if (sysfs_streq(buf, mgr->name))
69 break; 69 break;
70 70
71 mgr = NULL; 71 mgr = NULL;
diff --git a/drivers/video/omap2/dss/rfbi.c b/drivers/video/omap2/dss/rfbi.c
index cc23f53cc62d..bbe62464e92d 100644
--- a/drivers/video/omap2/dss/rfbi.c
+++ b/drivers/video/omap2/dss/rfbi.c
@@ -886,7 +886,7 @@ int omap_rfbi_prepare_update(struct omap_dss_device *dssdev,
886 return -EINVAL; 886 return -EINVAL;
887 887
888 if (dssdev->manager->caps & OMAP_DSS_OVL_MGR_CAP_DISPC) { 888 if (dssdev->manager->caps & OMAP_DSS_OVL_MGR_CAP_DISPC) {
889 dss_setup_partial_planes(dssdev, x, y, w, h); 889 dss_setup_partial_planes(dssdev, x, y, w, h, true);
890 dispc_set_lcd_size(*w, *h); 890 dispc_set_lcd_size(*w, *h);
891 } 891 }
892 892
diff --git a/drivers/video/omap2/omapfb/omapfb-ioctl.c b/drivers/video/omap2/omapfb/omapfb-ioctl.c
index 9c7361871d78..6f435450987e 100644
--- a/drivers/video/omap2/omapfb/omapfb-ioctl.c
+++ b/drivers/video/omap2/omapfb/omapfb-ioctl.c
@@ -34,12 +34,37 @@
34 34
35#include "omapfb.h" 35#include "omapfb.h"
36 36
37static u8 get_mem_idx(struct omapfb_info *ofbi)
38{
39 if (ofbi->id == ofbi->region->id)
40 return 0;
41
42 return OMAPFB_MEM_IDX_ENABLED | ofbi->region->id;
43}
44
45static struct omapfb2_mem_region *get_mem_region(struct omapfb_info *ofbi,
46 u8 mem_idx)
47{
48 struct omapfb2_device *fbdev = ofbi->fbdev;
49
50 if (mem_idx & OMAPFB_MEM_IDX_ENABLED)
51 mem_idx &= OMAPFB_MEM_IDX_MASK;
52 else
53 mem_idx = ofbi->id;
54
55 if (mem_idx >= fbdev->num_fbs)
56 return NULL;
57
58 return &fbdev->regions[mem_idx];
59}
60
37static int omapfb_setup_plane(struct fb_info *fbi, struct omapfb_plane_info *pi) 61static int omapfb_setup_plane(struct fb_info *fbi, struct omapfb_plane_info *pi)
38{ 62{
39 struct omapfb_info *ofbi = FB2OFB(fbi); 63 struct omapfb_info *ofbi = FB2OFB(fbi);
40 struct omapfb2_device *fbdev = ofbi->fbdev; 64 struct omapfb2_device *fbdev = ofbi->fbdev;
41 struct omap_overlay *ovl; 65 struct omap_overlay *ovl;
42 struct omap_overlay_info info; 66 struct omap_overlay_info old_info;
67 struct omapfb2_mem_region *old_rg, *new_rg;
43 int r = 0; 68 int r = 0;
44 69
45 DBG("omapfb_setup_plane\n"); 70 DBG("omapfb_setup_plane\n");
@@ -52,36 +77,106 @@ static int omapfb_setup_plane(struct fb_info *fbi, struct omapfb_plane_info *pi)
52 /* XXX uses only the first overlay */ 77 /* XXX uses only the first overlay */
53 ovl = ofbi->overlays[0]; 78 ovl = ofbi->overlays[0];
54 79
55 if (pi->enabled && !ofbi->region.size) { 80 old_rg = ofbi->region;
81 new_rg = get_mem_region(ofbi, pi->mem_idx);
82 if (!new_rg) {
83 r = -EINVAL;
84 goto out;
85 }
86
87 /* Take the locks in a specific order to keep lockdep happy */
88 if (old_rg->id < new_rg->id) {
89 omapfb_get_mem_region(old_rg);
90 omapfb_get_mem_region(new_rg);
91 } else if (new_rg->id < old_rg->id) {
92 omapfb_get_mem_region(new_rg);
93 omapfb_get_mem_region(old_rg);
94 } else
95 omapfb_get_mem_region(old_rg);
96
97 if (pi->enabled && !new_rg->size) {
56 /* 98 /*
57 * This plane's memory was freed, can't enable it 99 * This plane's memory was freed, can't enable it
58 * until it's reallocated. 100 * until it's reallocated.
59 */ 101 */
60 r = -EINVAL; 102 r = -EINVAL;
61 goto out; 103 goto put_mem;
62 } 104 }
63 105
64 ovl->get_overlay_info(ovl, &info); 106 ovl->get_overlay_info(ovl, &old_info);
65 107
66 info.pos_x = pi->pos_x; 108 if (old_rg != new_rg) {
67 info.pos_y = pi->pos_y; 109 ofbi->region = new_rg;
68 info.out_width = pi->out_width; 110 set_fb_fix(fbi);
69 info.out_height = pi->out_height; 111 }
70 info.enabled = pi->enabled;
71 112
72 r = ovl->set_overlay_info(ovl, &info); 113 if (pi->enabled) {
73 if (r) 114 struct omap_overlay_info info;
74 goto out;
75 115
76 if (ovl->manager) { 116 r = omapfb_setup_overlay(fbi, ovl, pi->pos_x, pi->pos_y,
77 r = ovl->manager->apply(ovl->manager); 117 pi->out_width, pi->out_height);
78 if (r) 118 if (r)
79 goto out; 119 goto undo;
120
121 ovl->get_overlay_info(ovl, &info);
122
123 if (!info.enabled) {
124 info.enabled = pi->enabled;
125 r = ovl->set_overlay_info(ovl, &info);
126 if (r)
127 goto undo;
128 }
129 } else {
130 struct omap_overlay_info info;
131
132 ovl->get_overlay_info(ovl, &info);
133
134 info.enabled = pi->enabled;
135 info.pos_x = pi->pos_x;
136 info.pos_y = pi->pos_y;
137 info.out_width = pi->out_width;
138 info.out_height = pi->out_height;
139
140 r = ovl->set_overlay_info(ovl, &info);
141 if (r)
142 goto undo;
80 } 143 }
81 144
82out: 145 if (ovl->manager)
83 if (r) 146 ovl->manager->apply(ovl->manager);
84 dev_err(fbdev->dev, "setup_plane failed\n"); 147
148 /* Release the locks in a specific order to keep lockdep happy */
149 if (old_rg->id > new_rg->id) {
150 omapfb_put_mem_region(old_rg);
151 omapfb_put_mem_region(new_rg);
152 } else if (new_rg->id > old_rg->id) {
153 omapfb_put_mem_region(new_rg);
154 omapfb_put_mem_region(old_rg);
155 } else
156 omapfb_put_mem_region(old_rg);
157
158 return 0;
159
160 undo:
161 if (old_rg != new_rg) {
162 ofbi->region = old_rg;
163 set_fb_fix(fbi);
164 }
165
166 ovl->set_overlay_info(ovl, &old_info);
167 put_mem:
168 /* Release the locks in a specific order to keep lockdep happy */
169 if (old_rg->id > new_rg->id) {
170 omapfb_put_mem_region(old_rg);
171 omapfb_put_mem_region(new_rg);
172 } else if (new_rg->id > old_rg->id) {
173 omapfb_put_mem_region(new_rg);
174 omapfb_put_mem_region(old_rg);
175 } else
176 omapfb_put_mem_region(old_rg);
177 out:
178 dev_err(fbdev->dev, "setup_plane failed\n");
179
85 return r; 180 return r;
86} 181}
87 182
@@ -92,8 +187,8 @@ static int omapfb_query_plane(struct fb_info *fbi, struct omapfb_plane_info *pi)
92 if (ofbi->num_overlays != 1) { 187 if (ofbi->num_overlays != 1) {
93 memset(pi, 0, sizeof(*pi)); 188 memset(pi, 0, sizeof(*pi));
94 } else { 189 } else {
95 struct omap_overlay_info *ovli;
96 struct omap_overlay *ovl; 190 struct omap_overlay *ovl;
191 struct omap_overlay_info *ovli;
97 192
98 ovl = ofbi->overlays[0]; 193 ovl = ofbi->overlays[0];
99 ovli = &ovl->info; 194 ovli = &ovl->info;
@@ -103,6 +198,7 @@ static int omapfb_query_plane(struct fb_info *fbi, struct omapfb_plane_info *pi)
103 pi->enabled = ovli->enabled; 198 pi->enabled = ovli->enabled;
104 pi->channel_out = 0; /* xxx */ 199 pi->channel_out = 0; /* xxx */
105 pi->mirror = 0; 200 pi->mirror = 0;
201 pi->mem_idx = get_mem_idx(ofbi);
106 pi->out_width = ovli->out_width; 202 pi->out_width = ovli->out_width;
107 pi->out_height = ovli->out_height; 203 pi->out_height = ovli->out_height;
108 } 204 }
@@ -115,7 +211,7 @@ static int omapfb_setup_mem(struct fb_info *fbi, struct omapfb_mem_info *mi)
115 struct omapfb_info *ofbi = FB2OFB(fbi); 211 struct omapfb_info *ofbi = FB2OFB(fbi);
116 struct omapfb2_device *fbdev = ofbi->fbdev; 212 struct omapfb2_device *fbdev = ofbi->fbdev;
117 struct omapfb2_mem_region *rg; 213 struct omapfb2_mem_region *rg;
118 int r, i; 214 int r = 0, i;
119 size_t size; 215 size_t size;
120 216
121 if (mi->type > OMAPFB_MEMTYPE_MAX) 217 if (mi->type > OMAPFB_MEMTYPE_MAX)
@@ -123,22 +219,44 @@ static int omapfb_setup_mem(struct fb_info *fbi, struct omapfb_mem_info *mi)
123 219
124 size = PAGE_ALIGN(mi->size); 220 size = PAGE_ALIGN(mi->size);
125 221
126 rg = &ofbi->region; 222 rg = ofbi->region;
127 223
128 for (i = 0; i < ofbi->num_overlays; i++) { 224 down_write_nested(&rg->lock, rg->id);
129 if (ofbi->overlays[i]->info.enabled) 225 atomic_inc(&rg->lock_count);
130 return -EBUSY; 226
227 if (atomic_read(&rg->map_count)) {
228 r = -EBUSY;
229 goto out;
230 }
231
232 for (i = 0; i < fbdev->num_fbs; i++) {
233 struct omapfb_info *ofbi2 = FB2OFB(fbdev->fbs[i]);
234 int j;
235
236 if (ofbi2->region != rg)
237 continue;
238
239 for (j = 0; j < ofbi2->num_overlays; j++) {
240 if (ofbi2->overlays[j]->info.enabled) {
241 r = -EBUSY;
242 goto out;
243 }
244 }
131 } 245 }
132 246
133 if (rg->size != size || rg->type != mi->type) { 247 if (rg->size != size || rg->type != mi->type) {
134 r = omapfb_realloc_fbmem(fbi, size, mi->type); 248 r = omapfb_realloc_fbmem(fbi, size, mi->type);
135 if (r) { 249 if (r) {
136 dev_err(fbdev->dev, "realloc fbmem failed\n"); 250 dev_err(fbdev->dev, "realloc fbmem failed\n");
137 return r; 251 goto out;
138 } 252 }
139 } 253 }
140 254
141 return 0; 255 out:
256 atomic_dec(&rg->lock_count);
257 up_write(&rg->lock);
258
259 return r;
142} 260}
143 261
144static int omapfb_query_mem(struct fb_info *fbi, struct omapfb_mem_info *mi) 262static int omapfb_query_mem(struct fb_info *fbi, struct omapfb_mem_info *mi)
@@ -146,12 +264,14 @@ static int omapfb_query_mem(struct fb_info *fbi, struct omapfb_mem_info *mi)
146 struct omapfb_info *ofbi = FB2OFB(fbi); 264 struct omapfb_info *ofbi = FB2OFB(fbi);
147 struct omapfb2_mem_region *rg; 265 struct omapfb2_mem_region *rg;
148 266
149 rg = &ofbi->region; 267 rg = omapfb_get_mem_region(ofbi->region);
150 memset(mi, 0, sizeof(*mi)); 268 memset(mi, 0, sizeof(*mi));
151 269
152 mi->size = rg->size; 270 mi->size = rg->size;
153 mi->type = rg->type; 271 mi->type = rg->type;
154 272
273 omapfb_put_mem_region(rg);
274
155 return 0; 275 return 0;
156} 276}
157 277
@@ -490,6 +610,7 @@ int omapfb_ioctl(struct fb_info *fbi, unsigned int cmd, unsigned long arg)
490 struct omapfb_vram_info vram_info; 610 struct omapfb_vram_info vram_info;
491 struct omapfb_tearsync_info tearsync_info; 611 struct omapfb_tearsync_info tearsync_info;
492 struct omapfb_display_info display_info; 612 struct omapfb_display_info display_info;
613 u32 crt;
493 } p; 614 } p;
494 615
495 int r = 0; 616 int r = 0;
@@ -648,6 +769,17 @@ int omapfb_ioctl(struct fb_info *fbi, unsigned int cmd, unsigned long arg)
648 r = -EFAULT; 769 r = -EFAULT;
649 break; 770 break;
650 771
772 case FBIO_WAITFORVSYNC:
773 if (get_user(p.crt, (__u32 __user *)arg)) {
774 r = -EFAULT;
775 break;
776 }
777 if (p.crt != 0) {
778 r = -ENODEV;
779 break;
780 }
781 /* FALLTHROUGH */
782
651 case OMAPFB_WAITFORVSYNC: 783 case OMAPFB_WAITFORVSYNC:
652 DBG("ioctl WAITFORVSYNC\n"); 784 DBG("ioctl WAITFORVSYNC\n");
653 if (!display) { 785 if (!display) {
@@ -738,7 +870,7 @@ int omapfb_ioctl(struct fb_info *fbi, unsigned int cmd, unsigned long arg)
738 break; 870 break;
739 } 871 }
740 872
741 if (!display->driver->enable_te) { 873 if (!display || !display->driver->enable_te) {
742 r = -ENODEV; 874 r = -ENODEV;
743 break; 875 break;
744 } 876 }
diff --git a/drivers/video/omap2/omapfb/omapfb-main.c b/drivers/video/omap2/omapfb/omapfb-main.c
index 4b4506da96da..04034d410d6d 100644
--- a/drivers/video/omap2/omapfb/omapfb-main.c
+++ b/drivers/video/omap2/omapfb/omapfb-main.c
@@ -157,7 +157,7 @@ static void fill_fb(struct fb_info *fbi)
157 157
158static unsigned omapfb_get_vrfb_offset(const struct omapfb_info *ofbi, int rot) 158static unsigned omapfb_get_vrfb_offset(const struct omapfb_info *ofbi, int rot)
159{ 159{
160 const struct vrfb *vrfb = &ofbi->region.vrfb; 160 const struct vrfb *vrfb = &ofbi->region->vrfb;
161 unsigned offset; 161 unsigned offset;
162 162
163 switch (rot) { 163 switch (rot) {
@@ -185,27 +185,27 @@ static unsigned omapfb_get_vrfb_offset(const struct omapfb_info *ofbi, int rot)
185static u32 omapfb_get_region_rot_paddr(const struct omapfb_info *ofbi, int rot) 185static u32 omapfb_get_region_rot_paddr(const struct omapfb_info *ofbi, int rot)
186{ 186{
187 if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB) { 187 if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB) {
188 return ofbi->region.vrfb.paddr[rot] 188 return ofbi->region->vrfb.paddr[rot]
189 + omapfb_get_vrfb_offset(ofbi, rot); 189 + omapfb_get_vrfb_offset(ofbi, rot);
190 } else { 190 } else {
191 return ofbi->region.paddr; 191 return ofbi->region->paddr;
192 } 192 }
193} 193}
194 194
195static u32 omapfb_get_region_paddr(const struct omapfb_info *ofbi) 195static u32 omapfb_get_region_paddr(const struct omapfb_info *ofbi)
196{ 196{
197 if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB) 197 if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB)
198 return ofbi->region.vrfb.paddr[0]; 198 return ofbi->region->vrfb.paddr[0];
199 else 199 else
200 return ofbi->region.paddr; 200 return ofbi->region->paddr;
201} 201}
202 202
203static void __iomem *omapfb_get_region_vaddr(const struct omapfb_info *ofbi) 203static void __iomem *omapfb_get_region_vaddr(const struct omapfb_info *ofbi)
204{ 204{
205 if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB) 205 if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB)
206 return ofbi->region.vrfb.vaddr[0]; 206 return ofbi->region->vrfb.vaddr[0];
207 else 207 else
208 return ofbi->region.vaddr; 208 return ofbi->region->vaddr;
209} 209}
210 210
211static struct omapfb_colormode omapfb_colormodes[] = { 211static struct omapfb_colormode omapfb_colormodes[] = {
@@ -450,7 +450,7 @@ static int check_vrfb_fb_size(unsigned long region_size,
450static int check_fb_size(const struct omapfb_info *ofbi, 450static int check_fb_size(const struct omapfb_info *ofbi,
451 struct fb_var_screeninfo *var) 451 struct fb_var_screeninfo *var)
452{ 452{
453 unsigned long max_frame_size = ofbi->region.size; 453 unsigned long max_frame_size = ofbi->region->size;
454 int bytespp = var->bits_per_pixel >> 3; 454 int bytespp = var->bits_per_pixel >> 3;
455 unsigned long line_size = var->xres_virtual * bytespp; 455 unsigned long line_size = var->xres_virtual * bytespp;
456 456
@@ -497,7 +497,7 @@ static int check_fb_size(const struct omapfb_info *ofbi,
497static int setup_vrfb_rotation(struct fb_info *fbi) 497static int setup_vrfb_rotation(struct fb_info *fbi)
498{ 498{
499 struct omapfb_info *ofbi = FB2OFB(fbi); 499 struct omapfb_info *ofbi = FB2OFB(fbi);
500 struct omapfb2_mem_region *rg = &ofbi->region; 500 struct omapfb2_mem_region *rg = ofbi->region;
501 struct vrfb *vrfb = &rg->vrfb; 501 struct vrfb *vrfb = &rg->vrfb;
502 struct fb_var_screeninfo *var = &fbi->var; 502 struct fb_var_screeninfo *var = &fbi->var;
503 struct fb_fix_screeninfo *fix = &fbi->fix; 503 struct fb_fix_screeninfo *fix = &fbi->fix;
@@ -558,9 +558,9 @@ static int setup_vrfb_rotation(struct fb_info *fbi)
558 return r; 558 return r;
559 559
560 /* used by open/write in fbmem.c */ 560 /* used by open/write in fbmem.c */
561 fbi->screen_base = ofbi->region.vrfb.vaddr[0]; 561 fbi->screen_base = ofbi->region->vrfb.vaddr[0];
562 562
563 fix->smem_start = ofbi->region.vrfb.paddr[0]; 563 fix->smem_start = ofbi->region->vrfb.paddr[0];
564 564
565 switch (var->nonstd) { 565 switch (var->nonstd) {
566 case OMAPFB_COLOR_YUV422: 566 case OMAPFB_COLOR_YUV422:
@@ -599,7 +599,7 @@ void set_fb_fix(struct fb_info *fbi)
599 struct fb_fix_screeninfo *fix = &fbi->fix; 599 struct fb_fix_screeninfo *fix = &fbi->fix;
600 struct fb_var_screeninfo *var = &fbi->var; 600 struct fb_var_screeninfo *var = &fbi->var;
601 struct omapfb_info *ofbi = FB2OFB(fbi); 601 struct omapfb_info *ofbi = FB2OFB(fbi);
602 struct omapfb2_mem_region *rg = &ofbi->region; 602 struct omapfb2_mem_region *rg = ofbi->region;
603 603
604 DBG("set_fb_fix\n"); 604 DBG("set_fb_fix\n");
605 605
@@ -668,8 +668,7 @@ int check_fb_var(struct fb_info *fbi, struct fb_var_screeninfo *var)
668 668
669 DBG("check_fb_var %d\n", ofbi->id); 669 DBG("check_fb_var %d\n", ofbi->id);
670 670
671 if (ofbi->region.size == 0) 671 WARN_ON(!atomic_read(&ofbi->region->lock_count));
672 return 0;
673 672
674 r = fb_mode_to_dss_mode(var, &mode); 673 r = fb_mode_to_dss_mode(var, &mode);
675 if (r) { 674 if (r) {
@@ -684,13 +683,14 @@ int check_fb_var(struct fb_info *fbi, struct fb_var_screeninfo *var)
684 } 683 }
685 } 684 }
686 685
687 if (var->rotate < 0 || var->rotate > 3) 686 if (var->rotate > 3)
688 return -EINVAL; 687 return -EINVAL;
689 688
690 if (check_fb_res_bounds(var)) 689 if (check_fb_res_bounds(var))
691 return -EINVAL; 690 return -EINVAL;
692 691
693 if (check_fb_size(ofbi, var)) 692 /* When no memory is allocated ignore the size check */
693 if (ofbi->region->size != 0 && check_fb_size(ofbi, var))
694 return -EINVAL; 694 return -EINVAL;
695 695
696 if (var->xres + var->xoffset > var->xres_virtual) 696 if (var->xres + var->xoffset > var->xres_virtual)
@@ -822,9 +822,43 @@ static unsigned calc_rotation_offset_vrfb(const struct fb_var_screeninfo *var,
822 return offset; 822 return offset;
823} 823}
824 824
825static void omapfb_calc_addr(const struct omapfb_info *ofbi,
826 const struct fb_var_screeninfo *var,
827 const struct fb_fix_screeninfo *fix,
828 int rotation, u32 *paddr, void __iomem **vaddr)
829{
830 u32 data_start_p;
831 void __iomem *data_start_v;
832 int offset;
833
834 if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB) {
835 data_start_p = omapfb_get_region_rot_paddr(ofbi, rotation);
836 data_start_v = NULL;
837 } else {
838 data_start_p = omapfb_get_region_paddr(ofbi);
839 data_start_v = omapfb_get_region_vaddr(ofbi);
840 }
841
842 if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB)
843 offset = calc_rotation_offset_vrfb(var, fix, rotation);
844 else
845 offset = calc_rotation_offset_dma(var, fix, rotation);
846
847 data_start_p += offset;
848 data_start_v += offset;
849
850 if (offset)
851 DBG("offset %d, %d = %d\n",
852 var->xoffset, var->yoffset, offset);
853
854 DBG("paddr %x, vaddr %p\n", data_start_p, data_start_v);
855
856 *paddr = data_start_p;
857 *vaddr = data_start_v;
858}
825 859
826/* setup overlay according to the fb */ 860/* setup overlay according to the fb */
827static int omapfb_setup_overlay(struct fb_info *fbi, struct omap_overlay *ovl, 861int omapfb_setup_overlay(struct fb_info *fbi, struct omap_overlay *ovl,
828 u16 posx, u16 posy, u16 outw, u16 outh) 862 u16 posx, u16 posy, u16 outw, u16 outh)
829{ 863{
830 int r = 0; 864 int r = 0;
@@ -832,9 +866,8 @@ static int omapfb_setup_overlay(struct fb_info *fbi, struct omap_overlay *ovl,
832 struct fb_var_screeninfo *var = &fbi->var; 866 struct fb_var_screeninfo *var = &fbi->var;
833 struct fb_fix_screeninfo *fix = &fbi->fix; 867 struct fb_fix_screeninfo *fix = &fbi->fix;
834 enum omap_color_mode mode = 0; 868 enum omap_color_mode mode = 0;
835 int offset; 869 u32 data_start_p = 0;
836 u32 data_start_p; 870 void __iomem *data_start_v = NULL;
837 void __iomem *data_start_v;
838 struct omap_overlay_info info; 871 struct omap_overlay_info info;
839 int xres, yres; 872 int xres, yres;
840 int screen_width; 873 int screen_width;
@@ -842,6 +875,8 @@ static int omapfb_setup_overlay(struct fb_info *fbi, struct omap_overlay *ovl,
842 int rotation = var->rotate; 875 int rotation = var->rotate;
843 int i; 876 int i;
844 877
878 WARN_ON(!atomic_read(&ofbi->region->lock_count));
879
845 for (i = 0; i < ofbi->num_overlays; i++) { 880 for (i = 0; i < ofbi->num_overlays; i++) {
846 if (ovl != ofbi->overlays[i]) 881 if (ovl != ofbi->overlays[i])
847 continue; 882 continue;
@@ -861,28 +896,9 @@ static int omapfb_setup_overlay(struct fb_info *fbi, struct omap_overlay *ovl,
861 yres = var->yres; 896 yres = var->yres;
862 } 897 }
863 898
864 899 if (ofbi->region->size)
865 if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB) { 900 omapfb_calc_addr(ofbi, var, fix, rotation,
866 data_start_p = omapfb_get_region_rot_paddr(ofbi, rotation); 901 &data_start_p, &data_start_v);
867 data_start_v = NULL;
868 } else {
869 data_start_p = omapfb_get_region_paddr(ofbi);
870 data_start_v = omapfb_get_region_vaddr(ofbi);
871 }
872
873 if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB)
874 offset = calc_rotation_offset_vrfb(var, fix, rotation);
875 else
876 offset = calc_rotation_offset_dma(var, fix, rotation);
877
878 data_start_p += offset;
879 data_start_v += offset;
880
881 if (offset)
882 DBG("offset %d, %d = %d\n",
883 var->xoffset, var->yoffset, offset);
884
885 DBG("paddr %x, vaddr %p\n", data_start_p, data_start_v);
886 902
887 r = fb_mode_to_dss_mode(var, &mode); 903 r = fb_mode_to_dss_mode(var, &mode);
888 if (r) { 904 if (r) {
@@ -954,12 +970,14 @@ int omapfb_apply_changes(struct fb_info *fbi, int init)
954 fill_fb(fbi); 970 fill_fb(fbi);
955#endif 971#endif
956 972
973 WARN_ON(!atomic_read(&ofbi->region->lock_count));
974
957 for (i = 0; i < ofbi->num_overlays; i++) { 975 for (i = 0; i < ofbi->num_overlays; i++) {
958 ovl = ofbi->overlays[i]; 976 ovl = ofbi->overlays[i];
959 977
960 DBG("apply_changes, fb %d, ovl %d\n", ofbi->id, ovl->id); 978 DBG("apply_changes, fb %d, ovl %d\n", ofbi->id, ovl->id);
961 979
962 if (ofbi->region.size == 0) { 980 if (ofbi->region->size == 0) {
963 /* the fb is not available. disable the overlay */ 981 /* the fb is not available. disable the overlay */
964 omapfb_overlay_enable(ovl, 0); 982 omapfb_overlay_enable(ovl, 0);
965 if (!init && ovl->manager) 983 if (!init && ovl->manager)
@@ -1007,36 +1025,48 @@ err:
1007 * DO NOT MODIFY PAR */ 1025 * DO NOT MODIFY PAR */
1008static int omapfb_check_var(struct fb_var_screeninfo *var, struct fb_info *fbi) 1026static int omapfb_check_var(struct fb_var_screeninfo *var, struct fb_info *fbi)
1009{ 1027{
1028 struct omapfb_info *ofbi = FB2OFB(fbi);
1010 int r; 1029 int r;
1011 1030
1012 DBG("check_var(%d)\n", FB2OFB(fbi)->id); 1031 DBG("check_var(%d)\n", FB2OFB(fbi)->id);
1013 1032
1033 omapfb_get_mem_region(ofbi->region);
1034
1014 r = check_fb_var(fbi, var); 1035 r = check_fb_var(fbi, var);
1015 1036
1037 omapfb_put_mem_region(ofbi->region);
1038
1016 return r; 1039 return r;
1017} 1040}
1018 1041
1019/* set the video mode according to info->var */ 1042/* set the video mode according to info->var */
1020static int omapfb_set_par(struct fb_info *fbi) 1043static int omapfb_set_par(struct fb_info *fbi)
1021{ 1044{
1045 struct omapfb_info *ofbi = FB2OFB(fbi);
1022 int r; 1046 int r;
1023 1047
1024 DBG("set_par(%d)\n", FB2OFB(fbi)->id); 1048 DBG("set_par(%d)\n", FB2OFB(fbi)->id);
1025 1049
1050 omapfb_get_mem_region(ofbi->region);
1051
1026 set_fb_fix(fbi); 1052 set_fb_fix(fbi);
1027 1053
1028 r = setup_vrfb_rotation(fbi); 1054 r = setup_vrfb_rotation(fbi);
1029 if (r) 1055 if (r)
1030 return r; 1056 goto out;
1031 1057
1032 r = omapfb_apply_changes(fbi, 0); 1058 r = omapfb_apply_changes(fbi, 0);
1033 1059
1060 out:
1061 omapfb_put_mem_region(ofbi->region);
1062
1034 return r; 1063 return r;
1035} 1064}
1036 1065
1037static int omapfb_pan_display(struct fb_var_screeninfo *var, 1066static int omapfb_pan_display(struct fb_var_screeninfo *var,
1038 struct fb_info *fbi) 1067 struct fb_info *fbi)
1039{ 1068{
1069 struct omapfb_info *ofbi = FB2OFB(fbi);
1040 struct fb_var_screeninfo new_var; 1070 struct fb_var_screeninfo new_var;
1041 int r; 1071 int r;
1042 1072
@@ -1052,23 +1082,31 @@ static int omapfb_pan_display(struct fb_var_screeninfo *var,
1052 1082
1053 fbi->var = new_var; 1083 fbi->var = new_var;
1054 1084
1085 omapfb_get_mem_region(ofbi->region);
1086
1055 r = omapfb_apply_changes(fbi, 0); 1087 r = omapfb_apply_changes(fbi, 0);
1056 1088
1089 omapfb_put_mem_region(ofbi->region);
1090
1057 return r; 1091 return r;
1058} 1092}
1059 1093
1060static void mmap_user_open(struct vm_area_struct *vma) 1094static void mmap_user_open(struct vm_area_struct *vma)
1061{ 1095{
1062 struct omapfb_info *ofbi = (struct omapfb_info *)vma->vm_private_data; 1096 struct omapfb2_mem_region *rg = vma->vm_private_data;
1063 1097
1064 atomic_inc(&ofbi->map_count); 1098 omapfb_get_mem_region(rg);
1099 atomic_inc(&rg->map_count);
1100 omapfb_put_mem_region(rg);
1065} 1101}
1066 1102
1067static void mmap_user_close(struct vm_area_struct *vma) 1103static void mmap_user_close(struct vm_area_struct *vma)
1068{ 1104{
1069 struct omapfb_info *ofbi = (struct omapfb_info *)vma->vm_private_data; 1105 struct omapfb2_mem_region *rg = vma->vm_private_data;
1070 1106
1071 atomic_dec(&ofbi->map_count); 1107 omapfb_get_mem_region(rg);
1108 atomic_dec(&rg->map_count);
1109 omapfb_put_mem_region(rg);
1072} 1110}
1073 1111
1074static struct vm_operations_struct mmap_user_ops = { 1112static struct vm_operations_struct mmap_user_ops = {
@@ -1080,9 +1118,11 @@ static int omapfb_mmap(struct fb_info *fbi, struct vm_area_struct *vma)
1080{ 1118{
1081 struct omapfb_info *ofbi = FB2OFB(fbi); 1119 struct omapfb_info *ofbi = FB2OFB(fbi);
1082 struct fb_fix_screeninfo *fix = &fbi->fix; 1120 struct fb_fix_screeninfo *fix = &fbi->fix;
1121 struct omapfb2_mem_region *rg;
1083 unsigned long off; 1122 unsigned long off;
1084 unsigned long start; 1123 unsigned long start;
1085 u32 len; 1124 u32 len;
1125 int r = -EINVAL;
1086 1126
1087 if (vma->vm_end - vma->vm_start == 0) 1127 if (vma->vm_end - vma->vm_start == 0)
1088 return 0; 1128 return 0;
@@ -1090,12 +1130,14 @@ static int omapfb_mmap(struct fb_info *fbi, struct vm_area_struct *vma)
1090 return -EINVAL; 1130 return -EINVAL;
1091 off = vma->vm_pgoff << PAGE_SHIFT; 1131 off = vma->vm_pgoff << PAGE_SHIFT;
1092 1132
1133 rg = omapfb_get_mem_region(ofbi->region);
1134
1093 start = omapfb_get_region_paddr(ofbi); 1135 start = omapfb_get_region_paddr(ofbi);
1094 len = fix->smem_len; 1136 len = fix->smem_len;
1095 if (off >= len) 1137 if (off >= len)
1096 return -EINVAL; 1138 goto error;
1097 if ((vma->vm_end - vma->vm_start + off) > len) 1139 if ((vma->vm_end - vma->vm_start + off) > len)
1098 return -EINVAL; 1140 goto error;
1099 1141
1100 off += start; 1142 off += start;
1101 1143
@@ -1105,13 +1147,25 @@ static int omapfb_mmap(struct fb_info *fbi, struct vm_area_struct *vma)
1105 vma->vm_flags |= VM_IO | VM_RESERVED; 1147 vma->vm_flags |= VM_IO | VM_RESERVED;
1106 vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot); 1148 vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
1107 vma->vm_ops = &mmap_user_ops; 1149 vma->vm_ops = &mmap_user_ops;
1108 vma->vm_private_data = ofbi; 1150 vma->vm_private_data = rg;
1109 if (io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT, 1151 if (io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT,
1110 vma->vm_end - vma->vm_start, vma->vm_page_prot)) 1152 vma->vm_end - vma->vm_start,
1111 return -EAGAIN; 1153 vma->vm_page_prot)) {
1154 r = -EAGAIN;
1155 goto error;
1156 }
1157
1112 /* vm_ops.open won't be called for mmap itself. */ 1158 /* vm_ops.open won't be called for mmap itself. */
1113 atomic_inc(&ofbi->map_count); 1159 atomic_inc(&rg->map_count);
1160
1161 omapfb_put_mem_region(rg);
1162
1114 return 0; 1163 return 0;
1164
1165 error:
1166 omapfb_put_mem_region(ofbi->region);
1167
1168 return r;
1115} 1169}
1116 1170
1117/* Store a single color palette entry into a pseudo palette or the hardware 1171/* Store a single color palette entry into a pseudo palette or the hardware
@@ -1154,11 +1208,6 @@ static int _setcolreg(struct fb_info *fbi, u_int regno, u_int red, u_int green,
1154 if (r != 0) 1208 if (r != 0)
1155 break; 1209 break;
1156 1210
1157 if (regno < 0) {
1158 r = -EINVAL;
1159 break;
1160 }
1161
1162 if (regno < 16) { 1211 if (regno < 16) {
1163 u16 pal; 1212 u16 pal;
1164 pal = ((red >> (16 - var->red.length)) << 1213 pal = ((red >> (16 - var->red.length)) <<
@@ -1217,6 +1266,9 @@ static int omapfb_blank(int blank, struct fb_info *fbi)
1217 int do_update = 0; 1266 int do_update = 0;
1218 int r = 0; 1267 int r = 0;
1219 1268
1269 if (!display)
1270 return -EINVAL;
1271
1220 omapfb_lock(fbdev); 1272 omapfb_lock(fbdev);
1221 1273
1222 switch (blank) { 1274 switch (blank) {
@@ -1300,7 +1352,9 @@ static void omapfb_free_fbmem(struct fb_info *fbi)
1300 struct omapfb2_device *fbdev = ofbi->fbdev; 1352 struct omapfb2_device *fbdev = ofbi->fbdev;
1301 struct omapfb2_mem_region *rg; 1353 struct omapfb2_mem_region *rg;
1302 1354
1303 rg = &ofbi->region; 1355 rg = ofbi->region;
1356
1357 WARN_ON(atomic_read(&rg->map_count));
1304 1358
1305 if (rg->paddr) 1359 if (rg->paddr)
1306 if (omap_vram_free(rg->paddr, rg->size)) 1360 if (omap_vram_free(rg->paddr, rg->size))
@@ -1355,8 +1409,15 @@ static int omapfb_alloc_fbmem(struct fb_info *fbi, unsigned long size,
1355 void __iomem *vaddr; 1409 void __iomem *vaddr;
1356 int r; 1410 int r;
1357 1411
1358 rg = &ofbi->region; 1412 rg = ofbi->region;
1359 memset(rg, 0, sizeof(*rg)); 1413
1414 rg->paddr = 0;
1415 rg->vaddr = NULL;
1416 memset(&rg->vrfb, 0, sizeof rg->vrfb);
1417 rg->size = 0;
1418 rg->type = 0;
1419 rg->alloc = false;
1420 rg->map = false;
1360 1421
1361 size = PAGE_ALIGN(size); 1422 size = PAGE_ALIGN(size);
1362 1423
@@ -1609,7 +1670,7 @@ static int omapfb_allocate_all_fbs(struct omapfb2_device *fbdev)
1609 for (i = 0; i < fbdev->num_fbs; i++) { 1670 for (i = 0; i < fbdev->num_fbs; i++) {
1610 struct omapfb_info *ofbi = FB2OFB(fbdev->fbs[i]); 1671 struct omapfb_info *ofbi = FB2OFB(fbdev->fbs[i]);
1611 struct omapfb2_mem_region *rg; 1672 struct omapfb2_mem_region *rg;
1612 rg = &ofbi->region; 1673 rg = ofbi->region;
1613 1674
1614 DBG("region%d phys %08x virt %p size=%lu\n", 1675 DBG("region%d phys %08x virt %p size=%lu\n",
1615 i, 1676 i,
@@ -1626,7 +1687,7 @@ int omapfb_realloc_fbmem(struct fb_info *fbi, unsigned long size, int type)
1626 struct omapfb_info *ofbi = FB2OFB(fbi); 1687 struct omapfb_info *ofbi = FB2OFB(fbi);
1627 struct omapfb2_device *fbdev = ofbi->fbdev; 1688 struct omapfb2_device *fbdev = ofbi->fbdev;
1628 struct omap_dss_device *display = fb2display(fbi); 1689 struct omap_dss_device *display = fb2display(fbi);
1629 struct omapfb2_mem_region *rg = &ofbi->region; 1690 struct omapfb2_mem_region *rg = ofbi->region;
1630 unsigned long old_size = rg->size; 1691 unsigned long old_size = rg->size;
1631 unsigned long old_paddr = rg->paddr; 1692 unsigned long old_paddr = rg->paddr;
1632 int old_type = rg->type; 1693 int old_type = rg->type;
@@ -1709,7 +1770,7 @@ static int omapfb_fb_init(struct omapfb2_device *fbdev, struct fb_info *fbi)
1709 fbi->flags = FBINFO_FLAG_DEFAULT; 1770 fbi->flags = FBINFO_FLAG_DEFAULT;
1710 fbi->pseudo_palette = fbdev->pseudo_palette; 1771 fbi->pseudo_palette = fbdev->pseudo_palette;
1711 1772
1712 if (ofbi->region.size == 0) { 1773 if (ofbi->region->size == 0) {
1713 clear_fb_info(fbi); 1774 clear_fb_info(fbi);
1714 return 0; 1775 return 0;
1715 } 1776 }
@@ -1871,6 +1932,10 @@ static int omapfb_create_framebuffers(struct omapfb2_device *fbdev)
1871 ofbi->fbdev = fbdev; 1932 ofbi->fbdev = fbdev;
1872 ofbi->id = i; 1933 ofbi->id = i;
1873 1934
1935 ofbi->region = &fbdev->regions[i];
1936 ofbi->region->id = i;
1937 init_rwsem(&ofbi->region->lock);
1938
1874 /* assign these early, so that fb alloc can use them */ 1939 /* assign these early, so that fb alloc can use them */
1875 ofbi->rotation_type = def_vrfb ? OMAP_DSS_ROT_VRFB : 1940 ofbi->rotation_type = def_vrfb ? OMAP_DSS_ROT_VRFB :
1876 OMAP_DSS_ROT_DMA; 1941 OMAP_DSS_ROT_DMA;
@@ -1900,7 +1965,13 @@ static int omapfb_create_framebuffers(struct omapfb2_device *fbdev)
1900 1965
1901 /* setup fb_infos */ 1966 /* setup fb_infos */
1902 for (i = 0; i < fbdev->num_fbs; i++) { 1967 for (i = 0; i < fbdev->num_fbs; i++) {
1903 r = omapfb_fb_init(fbdev, fbdev->fbs[i]); 1968 struct fb_info *fbi = fbdev->fbs[i];
1969 struct omapfb_info *ofbi = FB2OFB(fbi);
1970
1971 omapfb_get_mem_region(ofbi->region);
1972 r = omapfb_fb_init(fbdev, fbi);
1973 omapfb_put_mem_region(ofbi->region);
1974
1904 if (r) { 1975 if (r) {
1905 dev_err(fbdev->dev, "failed to setup fb_info\n"); 1976 dev_err(fbdev->dev, "failed to setup fb_info\n");
1906 return r; 1977 return r;
@@ -1921,20 +1992,19 @@ static int omapfb_create_framebuffers(struct omapfb2_device *fbdev)
1921 DBG("framebuffers registered\n"); 1992 DBG("framebuffers registered\n");
1922 1993
1923 for (i = 0; i < fbdev->num_fbs; i++) { 1994 for (i = 0; i < fbdev->num_fbs; i++) {
1924 r = omapfb_apply_changes(fbdev->fbs[i], 1); 1995 struct fb_info *fbi = fbdev->fbs[i];
1996 struct omapfb_info *ofbi = FB2OFB(fbi);
1997
1998 omapfb_get_mem_region(ofbi->region);
1999 r = omapfb_apply_changes(fbi, 1);
2000 omapfb_put_mem_region(ofbi->region);
2001
1925 if (r) { 2002 if (r) {
1926 dev_err(fbdev->dev, "failed to change mode\n"); 2003 dev_err(fbdev->dev, "failed to change mode\n");
1927 return r; 2004 return r;
1928 } 2005 }
1929 } 2006 }
1930 2007
1931 DBG("create sysfs for fbs\n");
1932 r = omapfb_create_sysfs(fbdev);
1933 if (r) {
1934 dev_err(fbdev->dev, "failed to create sysfs entries\n");
1935 return r;
1936 }
1937
1938 /* Enable fb0 */ 2008 /* Enable fb0 */
1939 if (fbdev->num_fbs > 0) { 2009 if (fbdev->num_fbs > 0) {
1940 struct omapfb_info *ofbi = FB2OFB(fbdev->fbs[0]); 2010 struct omapfb_info *ofbi = FB2OFB(fbdev->fbs[0]);
@@ -1968,11 +2038,11 @@ static int omapfb_mode_to_timings(const char *mode_str,
1968#ifdef CONFIG_OMAP2_DSS_VENC 2038#ifdef CONFIG_OMAP2_DSS_VENC
1969 if (strcmp(mode_str, "pal") == 0) { 2039 if (strcmp(mode_str, "pal") == 0) {
1970 *timings = omap_dss_pal_timings; 2040 *timings = omap_dss_pal_timings;
1971 *bpp = 0; 2041 *bpp = 24;
1972 return 0; 2042 return 0;
1973 } else if (strcmp(mode_str, "ntsc") == 0) { 2043 } else if (strcmp(mode_str, "ntsc") == 0) {
1974 *timings = omap_dss_ntsc_timings; 2044 *timings = omap_dss_ntsc_timings;
1975 *bpp = 0; 2045 *bpp = 24;
1976 return 0; 2046 return 0;
1977 } 2047 }
1978#endif 2048#endif
@@ -2220,6 +2290,13 @@ static int omapfb_probe(struct platform_device *pdev)
2220 } 2290 }
2221 } 2291 }
2222 2292
2293 DBG("create sysfs for fbs\n");
2294 r = omapfb_create_sysfs(fbdev);
2295 if (r) {
2296 dev_err(fbdev->dev, "failed to create sysfs entries\n");
2297 goto cleanup;
2298 }
2299
2223 return 0; 2300 return 0;
2224 2301
2225cleanup: 2302cleanup:
diff --git a/drivers/video/omap2/omapfb/omapfb-sysfs.c b/drivers/video/omap2/omapfb/omapfb-sysfs.c
index 5179219128bd..6f9c72cd6bb0 100644
--- a/drivers/video/omap2/omapfb/omapfb-sysfs.c
+++ b/drivers/video/omap2/omapfb/omapfb-sysfs.c
@@ -49,6 +49,7 @@ static ssize_t store_rotate_type(struct device *dev,
49{ 49{
50 struct fb_info *fbi = dev_get_drvdata(dev); 50 struct fb_info *fbi = dev_get_drvdata(dev);
51 struct omapfb_info *ofbi = FB2OFB(fbi); 51 struct omapfb_info *ofbi = FB2OFB(fbi);
52 struct omapfb2_mem_region *rg;
52 enum omap_dss_rotation_type rot_type; 53 enum omap_dss_rotation_type rot_type;
53 int r; 54 int r;
54 55
@@ -64,9 +65,11 @@ static ssize_t store_rotate_type(struct device *dev,
64 if (rot_type == ofbi->rotation_type) 65 if (rot_type == ofbi->rotation_type)
65 goto out; 66 goto out;
66 67
67 if (ofbi->region.size) { 68 rg = omapfb_get_mem_region(ofbi->region);
69
70 if (rg->size) {
68 r = -EBUSY; 71 r = -EBUSY;
69 goto out; 72 goto put_region;
70 } 73 }
71 74
72 ofbi->rotation_type = rot_type; 75 ofbi->rotation_type = rot_type;
@@ -75,6 +78,8 @@ static ssize_t store_rotate_type(struct device *dev,
75 * Since the VRAM for this FB is not allocated at the moment we don't 78 * Since the VRAM for this FB is not allocated at the moment we don't
76 * need to do any further parameter checking at this point. 79 * need to do any further parameter checking at this point.
77 */ 80 */
81put_region:
82 omapfb_put_mem_region(rg);
78out: 83out:
79 unlock_fb_info(fbi); 84 unlock_fb_info(fbi);
80 85
@@ -97,7 +102,7 @@ static ssize_t store_mirror(struct device *dev,
97{ 102{
98 struct fb_info *fbi = dev_get_drvdata(dev); 103 struct fb_info *fbi = dev_get_drvdata(dev);
99 struct omapfb_info *ofbi = FB2OFB(fbi); 104 struct omapfb_info *ofbi = FB2OFB(fbi);
100 bool mirror; 105 unsigned long mirror;
101 int r; 106 int r;
102 struct fb_var_screeninfo new_var; 107 struct fb_var_screeninfo new_var;
103 108
@@ -111,6 +116,8 @@ static ssize_t store_mirror(struct device *dev,
111 116
112 ofbi->mirror = mirror; 117 ofbi->mirror = mirror;
113 118
119 omapfb_get_mem_region(ofbi->region);
120
114 memcpy(&new_var, &fbi->var, sizeof(new_var)); 121 memcpy(&new_var, &fbi->var, sizeof(new_var));
115 r = check_fb_var(fbi, &new_var); 122 r = check_fb_var(fbi, &new_var);
116 if (r) 123 if (r)
@@ -125,6 +132,8 @@ static ssize_t store_mirror(struct device *dev,
125 132
126 r = count; 133 r = count;
127out: 134out:
135 omapfb_put_mem_region(ofbi->region);
136
128 unlock_fb_info(fbi); 137 unlock_fb_info(fbi);
129 138
130 return r; 139 return r;
@@ -263,11 +272,15 @@ static ssize_t store_overlays(struct device *dev, struct device_attribute *attr,
263 272
264 DBG("detaching %d\n", ofbi->overlays[i]->id); 273 DBG("detaching %d\n", ofbi->overlays[i]->id);
265 274
275 omapfb_get_mem_region(ofbi->region);
276
266 omapfb_overlay_enable(ovl, 0); 277 omapfb_overlay_enable(ovl, 0);
267 278
268 if (ovl->manager) 279 if (ovl->manager)
269 ovl->manager->apply(ovl->manager); 280 ovl->manager->apply(ovl->manager);
270 281
282 omapfb_put_mem_region(ofbi->region);
283
271 for (t = i + 1; t < ofbi->num_overlays; t++) { 284 for (t = i + 1; t < ofbi->num_overlays; t++) {
272 ofbi->rotation[t-1] = ofbi->rotation[t]; 285 ofbi->rotation[t-1] = ofbi->rotation[t];
273 ofbi->overlays[t-1] = ofbi->overlays[t]; 286 ofbi->overlays[t-1] = ofbi->overlays[t];
@@ -300,7 +313,12 @@ static ssize_t store_overlays(struct device *dev, struct device_attribute *attr,
300 } 313 }
301 314
302 if (added) { 315 if (added) {
316 omapfb_get_mem_region(ofbi->region);
317
303 r = omapfb_apply_changes(fbi, 0); 318 r = omapfb_apply_changes(fbi, 0);
319
320 omapfb_put_mem_region(ofbi->region);
321
304 if (r) 322 if (r)
305 goto out; 323 goto out;
306 } 324 }
@@ -388,7 +406,12 @@ static ssize_t store_overlays_rotate(struct device *dev,
388 for (i = 0; i < num_ovls; ++i) 406 for (i = 0; i < num_ovls; ++i)
389 ofbi->rotation[i] = rotation[i]; 407 ofbi->rotation[i] = rotation[i];
390 408
409 omapfb_get_mem_region(ofbi->region);
410
391 r = omapfb_apply_changes(fbi, 0); 411 r = omapfb_apply_changes(fbi, 0);
412
413 omapfb_put_mem_region(ofbi->region);
414
392 if (r) 415 if (r)
393 goto out; 416 goto out;
394 417
@@ -408,7 +431,7 @@ static ssize_t show_size(struct device *dev,
408 struct fb_info *fbi = dev_get_drvdata(dev); 431 struct fb_info *fbi = dev_get_drvdata(dev);
409 struct omapfb_info *ofbi = FB2OFB(fbi); 432 struct omapfb_info *ofbi = FB2OFB(fbi);
410 433
411 return snprintf(buf, PAGE_SIZE, "%lu\n", ofbi->region.size); 434 return snprintf(buf, PAGE_SIZE, "%lu\n", ofbi->region->size);
412} 435}
413 436
414static ssize_t store_size(struct device *dev, struct device_attribute *attr, 437static ssize_t store_size(struct device *dev, struct device_attribute *attr,
@@ -416,6 +439,8 @@ static ssize_t store_size(struct device *dev, struct device_attribute *attr,
416{ 439{
417 struct fb_info *fbi = dev_get_drvdata(dev); 440 struct fb_info *fbi = dev_get_drvdata(dev);
418 struct omapfb_info *ofbi = FB2OFB(fbi); 441 struct omapfb_info *ofbi = FB2OFB(fbi);
442 struct omapfb2_device *fbdev = ofbi->fbdev;
443 struct omapfb2_mem_region *rg;
419 unsigned long size; 444 unsigned long size;
420 int r; 445 int r;
421 int i; 446 int i;
@@ -425,15 +450,33 @@ static ssize_t store_size(struct device *dev, struct device_attribute *attr,
425 if (!lock_fb_info(fbi)) 450 if (!lock_fb_info(fbi))
426 return -ENODEV; 451 return -ENODEV;
427 452
428 for (i = 0; i < ofbi->num_overlays; i++) { 453 rg = ofbi->region;
429 if (ofbi->overlays[i]->info.enabled) { 454
430 r = -EBUSY; 455 down_write_nested(&rg->lock, rg->id);
431 goto out; 456 atomic_inc(&rg->lock_count);
457
458 if (atomic_read(&rg->map_count)) {
459 r = -EBUSY;
460 goto out;
461 }
462
463 for (i = 0; i < fbdev->num_fbs; i++) {
464 struct omapfb_info *ofbi2 = FB2OFB(fbdev->fbs[i]);
465 int j;
466
467 if (ofbi2->region != rg)
468 continue;
469
470 for (j = 0; j < ofbi2->num_overlays; j++) {
471 if (ofbi2->overlays[j]->info.enabled) {
472 r = -EBUSY;
473 goto out;
474 }
432 } 475 }
433 } 476 }
434 477
435 if (size != ofbi->region.size) { 478 if (size != ofbi->region->size) {
436 r = omapfb_realloc_fbmem(fbi, size, ofbi->region.type); 479 r = omapfb_realloc_fbmem(fbi, size, ofbi->region->type);
437 if (r) { 480 if (r) {
438 dev_err(dev, "realloc fbmem failed\n"); 481 dev_err(dev, "realloc fbmem failed\n");
439 goto out; 482 goto out;
@@ -442,6 +485,9 @@ static ssize_t store_size(struct device *dev, struct device_attribute *attr,
442 485
443 r = count; 486 r = count;
444out: 487out:
488 atomic_dec(&rg->lock_count);
489 up_write(&rg->lock);
490
445 unlock_fb_info(fbi); 491 unlock_fb_info(fbi);
446 492
447 return r; 493 return r;
@@ -453,7 +499,7 @@ static ssize_t show_phys(struct device *dev,
453 struct fb_info *fbi = dev_get_drvdata(dev); 499 struct fb_info *fbi = dev_get_drvdata(dev);
454 struct omapfb_info *ofbi = FB2OFB(fbi); 500 struct omapfb_info *ofbi = FB2OFB(fbi);
455 501
456 return snprintf(buf, PAGE_SIZE, "%0x\n", ofbi->region.paddr); 502 return snprintf(buf, PAGE_SIZE, "%0x\n", ofbi->region->paddr);
457} 503}
458 504
459static ssize_t show_virt(struct device *dev, 505static ssize_t show_virt(struct device *dev,
@@ -462,7 +508,7 @@ static ssize_t show_virt(struct device *dev,
462 struct fb_info *fbi = dev_get_drvdata(dev); 508 struct fb_info *fbi = dev_get_drvdata(dev);
463 struct omapfb_info *ofbi = FB2OFB(fbi); 509 struct omapfb_info *ofbi = FB2OFB(fbi);
464 510
465 return snprintf(buf, PAGE_SIZE, "%p\n", ofbi->region.vaddr); 511 return snprintf(buf, PAGE_SIZE, "%p\n", ofbi->region->vaddr);
466} 512}
467 513
468static struct device_attribute omapfb_attrs[] = { 514static struct device_attribute omapfb_attrs[] = {
diff --git a/drivers/video/omap2/omapfb/omapfb.h b/drivers/video/omap2/omapfb/omapfb.h
index cd54fdbfd8bb..1305fc9880ba 100644
--- a/drivers/video/omap2/omapfb/omapfb.h
+++ b/drivers/video/omap2/omapfb/omapfb.h
@@ -27,6 +27,8 @@
27#define DEBUG 27#define DEBUG
28#endif 28#endif
29 29
30#include <linux/rwsem.h>
31
30#include <plat/display.h> 32#include <plat/display.h>
31 33
32#ifdef DEBUG 34#ifdef DEBUG
@@ -44,6 +46,7 @@ extern unsigned int omapfb_debug;
44#define OMAPFB_MAX_OVL_PER_FB 3 46#define OMAPFB_MAX_OVL_PER_FB 3
45 47
46struct omapfb2_mem_region { 48struct omapfb2_mem_region {
49 int id;
47 u32 paddr; 50 u32 paddr;
48 void __iomem *vaddr; 51 void __iomem *vaddr;
49 struct vrfb vrfb; 52 struct vrfb vrfb;
@@ -51,13 +54,15 @@ struct omapfb2_mem_region {
51 u8 type; /* OMAPFB_PLANE_MEM_* */ 54 u8 type; /* OMAPFB_PLANE_MEM_* */
52 bool alloc; /* allocated by the driver */ 55 bool alloc; /* allocated by the driver */
53 bool map; /* kernel mapped by the driver */ 56 bool map; /* kernel mapped by the driver */
57 atomic_t map_count;
58 struct rw_semaphore lock;
59 atomic_t lock_count;
54}; 60};
55 61
56/* appended to fb_info */ 62/* appended to fb_info */
57struct omapfb_info { 63struct omapfb_info {
58 int id; 64 int id;
59 struct omapfb2_mem_region region; 65 struct omapfb2_mem_region *region;
60 atomic_t map_count;
61 int num_overlays; 66 int num_overlays;
62 struct omap_overlay *overlays[OMAPFB_MAX_OVL_PER_FB]; 67 struct omap_overlay *overlays[OMAPFB_MAX_OVL_PER_FB];
63 struct omapfb2_device *fbdev; 68 struct omapfb2_device *fbdev;
@@ -76,6 +81,7 @@ struct omapfb2_device {
76 81
77 unsigned num_fbs; 82 unsigned num_fbs;
78 struct fb_info *fbs[10]; 83 struct fb_info *fbs[10];
84 struct omapfb2_mem_region regions[10];
79 85
80 unsigned num_displays; 86 unsigned num_displays;
81 struct omap_dss_device *displays[10]; 87 struct omap_dss_device *displays[10];
@@ -117,6 +123,9 @@ int omapfb_update_window(struct fb_info *fbi,
117int dss_mode_to_fb_mode(enum omap_color_mode dssmode, 123int dss_mode_to_fb_mode(enum omap_color_mode dssmode,
118 struct fb_var_screeninfo *var); 124 struct fb_var_screeninfo *var);
119 125
126int omapfb_setup_overlay(struct fb_info *fbi, struct omap_overlay *ovl,
127 u16 posx, u16 posy, u16 outw, u16 outh);
128
120/* find the display connected to this fb, if any */ 129/* find the display connected to this fb, if any */
121static inline struct omap_dss_device *fb2display(struct fb_info *fbi) 130static inline struct omap_dss_device *fb2display(struct fb_info *fbi)
122{ 131{
@@ -148,8 +157,24 @@ static inline int omapfb_overlay_enable(struct omap_overlay *ovl,
148 struct omap_overlay_info info; 157 struct omap_overlay_info info;
149 158
150 ovl->get_overlay_info(ovl, &info); 159 ovl->get_overlay_info(ovl, &info);
160 if (info.enabled == enable)
161 return 0;
151 info.enabled = enable; 162 info.enabled = enable;
152 return ovl->set_overlay_info(ovl, &info); 163 return ovl->set_overlay_info(ovl, &info);
153} 164}
154 165
166static inline struct omapfb2_mem_region *
167omapfb_get_mem_region(struct omapfb2_mem_region *rg)
168{
169 down_read_nested(&rg->lock, rg->id);
170 atomic_inc(&rg->lock_count);
171 return rg;
172}
173
174static inline void omapfb_put_mem_region(struct omapfb2_mem_region *rg)
175{
176 atomic_dec(&rg->lock_count);
177 up_read(&rg->lock);
178}
179
155#endif 180#endif
diff --git a/drivers/video/p9100.c b/drivers/video/p9100.c
index 688b055abab2..b6c3fc2db632 100644
--- a/drivers/video/p9100.c
+++ b/drivers/video/p9100.c
@@ -249,7 +249,7 @@ static void p9100_init_fix(struct fb_info *info, int linebytes, struct device_no
249 info->fix.accel = FB_ACCEL_SUN_CGTHREE; 249 info->fix.accel = FB_ACCEL_SUN_CGTHREE;
250} 250}
251 251
252static int __devinit p9100_probe(struct of_device *op, const struct of_device_id *match) 252static int __devinit p9100_probe(struct platform_device *op, const struct of_device_id *match)
253{ 253{
254 struct device_node *dp = op->dev.of_node; 254 struct device_node *dp = op->dev.of_node;
255 struct fb_info *info; 255 struct fb_info *info;
@@ -326,7 +326,7 @@ out_err:
326 return err; 326 return err;
327} 327}
328 328
329static int __devexit p9100_remove(struct of_device *op) 329static int __devexit p9100_remove(struct platform_device *op)
330{ 330{
331 struct fb_info *info = dev_get_drvdata(&op->dev); 331 struct fb_info *info = dev_get_drvdata(&op->dev);
332 struct p9100_par *par = info->par; 332 struct p9100_par *par = info->par;
diff --git a/drivers/video/platinumfb.c b/drivers/video/platinumfb.c
index 72a1f4c04732..a50e1977b316 100644
--- a/drivers/video/platinumfb.c
+++ b/drivers/video/platinumfb.c
@@ -533,7 +533,7 @@ static int __init platinumfb_setup(char *options)
533#define invalidate_cache(addr) 533#define invalidate_cache(addr)
534#endif 534#endif
535 535
536static int __devinit platinumfb_probe(struct of_device* odev, 536static int __devinit platinumfb_probe(struct platform_device* odev,
537 const struct of_device_id *match) 537 const struct of_device_id *match)
538{ 538{
539 struct device_node *dp = odev->dev.of_node; 539 struct device_node *dp = odev->dev.of_node;
@@ -646,7 +646,7 @@ static int __devinit platinumfb_probe(struct of_device* odev,
646 return rc; 646 return rc;
647} 647}
648 648
649static int __devexit platinumfb_remove(struct of_device* odev) 649static int __devexit platinumfb_remove(struct platform_device* odev)
650{ 650{
651 struct fb_info *info = dev_get_drvdata(&odev->dev); 651 struct fb_info *info = dev_get_drvdata(&odev->dev);
652 struct fb_info_platinum *pinfo = info->par; 652 struct fb_info_platinum *pinfo = info->par;
diff --git a/drivers/video/s3c-fb.c b/drivers/video/s3c-fb.c
index 9682ecc60e12..f9aca9d13d1b 100644
--- a/drivers/video/s3c-fb.c
+++ b/drivers/video/s3c-fb.c
@@ -1,7 +1,7 @@
1/* linux/drivers/video/s3c-fb.c 1/* linux/drivers/video/s3c-fb.c
2 * 2 *
3 * Copyright 2008 Openmoko Inc. 3 * Copyright 2008 Openmoko Inc.
4 * Copyright 2008 Simtec Electronics 4 * Copyright 2008-2010 Simtec Electronics
5 * Ben Dooks <ben@simtec.co.uk> 5 * Ben Dooks <ben@simtec.co.uk>
6 * http://armlinux.simtec.co.uk/ 6 * http://armlinux.simtec.co.uk/
7 * 7 *
@@ -9,7 +9,7 @@
9 * 9 *
10 * This program is free software; you can redistribute it and/or modify 10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as 11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation. 12 * published by the Free Software FoundatIon.
13*/ 13*/
14 14
15#include <linux/kernel.h> 15#include <linux/kernel.h>
@@ -21,9 +21,11 @@
21#include <linux/clk.h> 21#include <linux/clk.h>
22#include <linux/fb.h> 22#include <linux/fb.h>
23#include <linux/io.h> 23#include <linux/io.h>
24#include <linux/uaccess.h>
25#include <linux/interrupt.h>
24 26
25#include <mach/map.h> 27#include <mach/map.h>
26#include <mach/regs-fb.h> 28#include <plat/regs-fb-v4.h>
27#include <plat/fb.h> 29#include <plat/fb.h>
28 30
29/* This driver will export a number of framebuffer interfaces depending 31/* This driver will export a number of framebuffer interfaces depending
@@ -36,9 +38,9 @@
36 * output timings and as the control for the output power-down state. 38 * output timings and as the control for the output power-down state.
37*/ 39*/
38 40
39/* note, some of the functions that get called are derived from including 41/* note, the previous use of <mach/regs-fb.h> to get platform specific data
40 * <mach/regs-fb.h> as they are specific to the architecture that the code 42 * has been replaced by using the platform device name to pick the correct
41 * is being built for. 43 * configuration data for the system.
42*/ 44*/
43 45
44#ifdef CONFIG_FB_S3C_DEBUG_REGWRITE 46#ifdef CONFIG_FB_S3C_DEBUG_REGWRITE
@@ -48,13 +50,108 @@
48 __raw_writel(v, r); } while(0) 50 __raw_writel(v, r); } while(0)
49#endif /* FB_S3C_DEBUG_REGWRITE */ 51#endif /* FB_S3C_DEBUG_REGWRITE */
50 52
53/* irq_flags bits */
54#define S3C_FB_VSYNC_IRQ_EN 0
55
56#define VSYNC_TIMEOUT_MSEC 50
57
51struct s3c_fb; 58struct s3c_fb;
52 59
60#define VALID_BPP(x) (1 << ((x) - 1))
61
62#define OSD_BASE(win, variant) ((variant).osd + ((win) * (variant).osd_stride))
63#define VIDOSD_A(win, variant) (OSD_BASE(win, variant) + 0x00)
64#define VIDOSD_B(win, variant) (OSD_BASE(win, variant) + 0x04)
65#define VIDOSD_C(win, variant) (OSD_BASE(win, variant) + 0x08)
66#define VIDOSD_D(win, variant) (OSD_BASE(win, variant) + 0x0C)
67
68/**
69 * struct s3c_fb_variant - fb variant information
70 * @is_2443: Set if S3C2443/S3C2416 style hardware.
71 * @nr_windows: The number of windows.
72 * @vidtcon: The base for the VIDTCONx registers
73 * @wincon: The base for the WINxCON registers.
74 * @winmap: The base for the WINxMAP registers.
75 * @keycon: The abse for the WxKEYCON registers.
76 * @buf_start: Offset of buffer start registers.
77 * @buf_size: Offset of buffer size registers.
78 * @buf_end: Offset of buffer end registers.
79 * @osd: The base for the OSD registers.
80 * @palette: Address of palette memory, or 0 if none.
81 * @has_prtcon: Set if has PRTCON register.
82 * @has_shadowcon: Set if has SHADOWCON register.
83 */
84struct s3c_fb_variant {
85 unsigned int is_2443:1;
86 unsigned short nr_windows;
87 unsigned short vidtcon;
88 unsigned short wincon;
89 unsigned short winmap;
90 unsigned short keycon;
91 unsigned short buf_start;
92 unsigned short buf_end;
93 unsigned short buf_size;
94 unsigned short osd;
95 unsigned short osd_stride;
96 unsigned short palette[S3C_FB_MAX_WIN];
97
98 unsigned int has_prtcon:1;
99 unsigned int has_shadowcon:1;
100};
101
102/**
103 * struct s3c_fb_win_variant
104 * @has_osd_c: Set if has OSD C register.
105 * @has_osd_d: Set if has OSD D register.
106 * @has_osd_alpha: Set if can change alpha transparency for a window.
107 * @palette_sz: Size of palette in entries.
108 * @palette_16bpp: Set if palette is 16bits wide.
109 * @osd_size_off: If != 0, supports setting up OSD for a window; the appropriate
110 * register is located at the given offset from OSD_BASE.
111 * @valid_bpp: 1 bit per BPP setting to show valid bits-per-pixel.
112 *
113 * valid_bpp bit x is set if (x+1)BPP is supported.
114 */
115struct s3c_fb_win_variant {
116 unsigned int has_osd_c:1;
117 unsigned int has_osd_d:1;
118 unsigned int has_osd_alpha:1;
119 unsigned int palette_16bpp:1;
120 unsigned short osd_size_off;
121 unsigned short palette_sz;
122 u32 valid_bpp;
123};
124
125/**
126 * struct s3c_fb_driverdata - per-device type driver data for init time.
127 * @variant: The variant information for this driver.
128 * @win: The window information for each window.
129 */
130struct s3c_fb_driverdata {
131 struct s3c_fb_variant variant;
132 struct s3c_fb_win_variant *win[S3C_FB_MAX_WIN];
133};
134
135/**
136 * struct s3c_fb_palette - palette information
137 * @r: Red bitfield.
138 * @g: Green bitfield.
139 * @b: Blue bitfield.
140 * @a: Alpha bitfield.
141 */
142struct s3c_fb_palette {
143 struct fb_bitfield r;
144 struct fb_bitfield g;
145 struct fb_bitfield b;
146 struct fb_bitfield a;
147};
148
53/** 149/**
54 * struct s3c_fb_win - per window private data for each framebuffer. 150 * struct s3c_fb_win - per window private data for each framebuffer.
55 * @windata: The platform data supplied for the window configuration. 151 * @windata: The platform data supplied for the window configuration.
56 * @parent: The hardware that this window is part of. 152 * @parent: The hardware that this window is part of.
57 * @fbinfo: Pointer pack to the framebuffer info for this window. 153 * @fbinfo: Pointer pack to the framebuffer info for this window.
154 * @varint: The variant information for this window.
58 * @palette_buffer: Buffer/cache to hold palette entries. 155 * @palette_buffer: Buffer/cache to hold palette entries.
59 * @pseudo_palette: For use in TRUECOLOUR modes for entries 0..15/ 156 * @pseudo_palette: For use in TRUECOLOUR modes for entries 0..15/
60 * @index: The window number of this window. 157 * @index: The window number of this window.
@@ -65,6 +162,7 @@ struct s3c_fb_win {
65 struct s3c_fb *parent; 162 struct s3c_fb *parent;
66 struct fb_info *fbinfo; 163 struct fb_info *fbinfo;
67 struct s3c_fb_palette palette; 164 struct s3c_fb_palette palette;
165 struct s3c_fb_win_variant variant;
68 166
69 u32 *palette_buffer; 167 u32 *palette_buffer;
70 u32 pseudo_palette[16]; 168 u32 pseudo_palette[16];
@@ -72,37 +170,54 @@ struct s3c_fb_win {
72}; 170};
73 171
74/** 172/**
173 * struct s3c_fb_vsync - vsync information
174 * @wait: a queue for processes waiting for vsync
175 * @count: vsync interrupt count
176 */
177struct s3c_fb_vsync {
178 wait_queue_head_t wait;
179 unsigned int count;
180};
181
182/**
75 * struct s3c_fb - overall hardware state of the hardware 183 * struct s3c_fb - overall hardware state of the hardware
76 * @dev: The device that we bound to, for printing, etc. 184 * @dev: The device that we bound to, for printing, etc.
77 * @regs_res: The resource we claimed for the IO registers. 185 * @regs_res: The resource we claimed for the IO registers.
78 * @bus_clk: The clk (hclk) feeding our interface and possibly pixclk. 186 * @bus_clk: The clk (hclk) feeding our interface and possibly pixclk.
79 * @regs: The mapped hardware registers. 187 * @regs: The mapped hardware registers.
188 * @variant: Variant information for this hardware.
80 * @enabled: A bitmask of enabled hardware windows. 189 * @enabled: A bitmask of enabled hardware windows.
81 * @pdata: The platform configuration data passed with the device. 190 * @pdata: The platform configuration data passed with the device.
82 * @windows: The hardware windows that have been claimed. 191 * @windows: The hardware windows that have been claimed.
192 * @irq_no: IRQ line number
193 * @irq_flags: irq flags
194 * @vsync_info: VSYNC-related information (count, queues...)
83 */ 195 */
84struct s3c_fb { 196struct s3c_fb {
85 struct device *dev; 197 struct device *dev;
86 struct resource *regs_res; 198 struct resource *regs_res;
87 struct clk *bus_clk; 199 struct clk *bus_clk;
88 void __iomem *regs; 200 void __iomem *regs;
201 struct s3c_fb_variant variant;
89 202
90 unsigned char enabled; 203 unsigned char enabled;
91 204
92 struct s3c_fb_platdata *pdata; 205 struct s3c_fb_platdata *pdata;
93 struct s3c_fb_win *windows[S3C_FB_MAX_WIN]; 206 struct s3c_fb_win *windows[S3C_FB_MAX_WIN];
207
208 int irq_no;
209 unsigned long irq_flags;
210 struct s3c_fb_vsync vsync_info;
94}; 211};
95 212
96/** 213/**
97 * s3c_fb_win_has_palette() - determine if a mode has a palette 214 * s3c_fb_validate_win_bpp - validate the bits-per-pixel for this mode.
98 * @win: The window number being queried. 215 * @win: The device window.
99 * @bpp: The number of bits per pixel to test. 216 * @bpp: The bit depth.
100 *
101 * Work out if the given window supports palletised data at the specified bpp.
102 */ 217 */
103static int s3c_fb_win_has_palette(unsigned int win, unsigned int bpp) 218static bool s3c_fb_validate_win_bpp(struct s3c_fb_win *win, unsigned int bpp)
104{ 219{
105 return s3c_fb_win_pal_size(win) <= (1 << bpp); 220 return win->variant.valid_bpp & VALID_BPP(bpp);
106} 221}
107 222
108/** 223/**
@@ -125,7 +240,7 @@ static int s3c_fb_check_var(struct fb_var_screeninfo *var,
125 var->xres_virtual = max((unsigned int)windata->virtual_x, var->xres); 240 var->xres_virtual = max((unsigned int)windata->virtual_x, var->xres);
126 var->yres_virtual = max((unsigned int)windata->virtual_y, var->yres); 241 var->yres_virtual = max((unsigned int)windata->virtual_y, var->yres);
127 242
128 if (!s3c_fb_validate_win_bpp(win->index, var->bits_per_pixel)) { 243 if (!s3c_fb_validate_win_bpp(win, var->bits_per_pixel)) {
129 dev_dbg(sfb->dev, "win %d: unsupported bpp %d\n", 244 dev_dbg(sfb->dev, "win %d: unsupported bpp %d\n",
130 win->index, var->bits_per_pixel); 245 win->index, var->bits_per_pixel);
131 return -EINVAL; 246 return -EINVAL;
@@ -140,7 +255,7 @@ static int s3c_fb_check_var(struct fb_var_screeninfo *var,
140 case 2: 255 case 2:
141 case 4: 256 case 4:
142 case 8: 257 case 8:
143 if (!s3c_fb_win_has_palette(win->index, var->bits_per_pixel)) { 258 if (sfb->variant.palette[win->index] != 0) {
144 /* non palletised, A:1,R:2,G:3,B:2 mode */ 259 /* non palletised, A:1,R:2,G:3,B:2 mode */
145 var->red.offset = 4; 260 var->red.offset = 4;
146 var->green.offset = 2; 261 var->green.offset = 2;
@@ -255,6 +370,66 @@ static int s3c_fb_align_word(unsigned int bpp, unsigned int pix)
255} 370}
256 371
257/** 372/**
373 * vidosd_set_size() - set OSD size for a window
374 *
375 * @win: the window to set OSD size for
376 * @size: OSD size register value
377 */
378static void vidosd_set_size(struct s3c_fb_win *win, u32 size)
379{
380 struct s3c_fb *sfb = win->parent;
381
382 /* OSD can be set up if osd_size_off != 0 for this window */
383 if (win->variant.osd_size_off)
384 writel(size, sfb->regs + OSD_BASE(win->index, sfb->variant)
385 + win->variant.osd_size_off);
386}
387
388/**
389 * vidosd_set_alpha() - set alpha transparency for a window
390 *
391 * @win: the window to set OSD size for
392 * @alpha: alpha register value
393 */
394static void vidosd_set_alpha(struct s3c_fb_win *win, u32 alpha)
395{
396 struct s3c_fb *sfb = win->parent;
397
398 if (win->variant.has_osd_alpha)
399 writel(alpha, sfb->regs + VIDOSD_C(win->index, sfb->variant));
400}
401
402/**
403 * shadow_protect_win() - disable updating values from shadow registers at vsync
404 *
405 * @win: window to protect registers for
406 * @protect: 1 to protect (disable updates)
407 */
408static void shadow_protect_win(struct s3c_fb_win *win, bool protect)
409{
410 struct s3c_fb *sfb = win->parent;
411 u32 reg;
412
413 if (protect) {
414 if (sfb->variant.has_prtcon) {
415 writel(PRTCON_PROTECT, sfb->regs + PRTCON);
416 } else if (sfb->variant.has_shadowcon) {
417 reg = readl(sfb->regs + SHADOWCON);
418 writel(reg | SHADOWCON_WINx_PROTECT(win->index),
419 sfb->regs + SHADOWCON);
420 }
421 } else {
422 if (sfb->variant.has_prtcon) {
423 writel(0, sfb->regs + PRTCON);
424 } else if (sfb->variant.has_shadowcon) {
425 reg = readl(sfb->regs + SHADOWCON);
426 writel(reg & ~SHADOWCON_WINx_PROTECT(win->index),
427 sfb->regs + SHADOWCON);
428 }
429 }
430}
431
432/**
258 * s3c_fb_set_par() - framebuffer request to set new framebuffer state. 433 * s3c_fb_set_par() - framebuffer request to set new framebuffer state.
259 * @info: The framebuffer to change. 434 * @info: The framebuffer to change.
260 * 435 *
@@ -266,14 +441,17 @@ static int s3c_fb_set_par(struct fb_info *info)
266 struct s3c_fb_win *win = info->par; 441 struct s3c_fb_win *win = info->par;
267 struct s3c_fb *sfb = win->parent; 442 struct s3c_fb *sfb = win->parent;
268 void __iomem *regs = sfb->regs; 443 void __iomem *regs = sfb->regs;
444 void __iomem *buf = regs;
269 int win_no = win->index; 445 int win_no = win->index;
270 u32 osdc_data = 0; 446 u32 alpha = 0;
271 u32 data; 447 u32 data;
272 u32 pagewidth; 448 u32 pagewidth;
273 int clkdiv; 449 int clkdiv;
274 450
275 dev_dbg(sfb->dev, "setting framebuffer parameters\n"); 451 dev_dbg(sfb->dev, "setting framebuffer parameters\n");
276 452
453 shadow_protect_win(win, 1);
454
277 switch (var->bits_per_pixel) { 455 switch (var->bits_per_pixel) {
278 case 32: 456 case 32:
279 case 24: 457 case 24:
@@ -282,7 +460,7 @@ static int s3c_fb_set_par(struct fb_info *info)
282 info->fix.visual = FB_VISUAL_TRUECOLOR; 460 info->fix.visual = FB_VISUAL_TRUECOLOR;
283 break; 461 break;
284 case 8: 462 case 8:
285 if (s3c_fb_win_has_palette(win_no, 8)) 463 if (win->variant.palette_sz >= 256)
286 info->fix.visual = FB_VISUAL_PSEUDOCOLOR; 464 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
287 else 465 else
288 info->fix.visual = FB_VISUAL_TRUECOLOR; 466 info->fix.visual = FB_VISUAL_TRUECOLOR;
@@ -297,12 +475,15 @@ static int s3c_fb_set_par(struct fb_info *info)
297 475
298 info->fix.line_length = (var->xres_virtual * var->bits_per_pixel) / 8; 476 info->fix.line_length = (var->xres_virtual * var->bits_per_pixel) / 8;
299 477
478 info->fix.xpanstep = info->var.xres_virtual > info->var.xres ? 1 : 0;
479 info->fix.ypanstep = info->var.yres_virtual > info->var.yres ? 1 : 0;
480
300 /* disable the window whilst we update it */ 481 /* disable the window whilst we update it */
301 writel(0, regs + WINCON(win_no)); 482 writel(0, regs + WINCON(win_no));
302 483
303 /* use window 0 as the basis for the lcd output timings */ 484 /* use platform specified window as the basis for the lcd timings */
304 485
305 if (win_no == 0) { 486 if (win_no == sfb->pdata->default_win) {
306 clkdiv = s3c_fb_calc_pixclk(sfb, var->pixclock); 487 clkdiv = s3c_fb_calc_pixclk(sfb, var->pixclock);
307 488
308 data = sfb->pdata->vidcon0; 489 data = sfb->pdata->vidcon0;
@@ -315,6 +496,9 @@ static int s3c_fb_set_par(struct fb_info *info)
315 496
316 /* write the timing data to the panel */ 497 /* write the timing data to the panel */
317 498
499 if (sfb->variant.is_2443)
500 data |= (1 << 5);
501
318 data |= VIDCON0_ENVID | VIDCON0_ENVID_F; 502 data |= VIDCON0_ENVID | VIDCON0_ENVID_F;
319 writel(data, regs + VIDCON0); 503 writel(data, regs + VIDCON0);
320 504
@@ -322,53 +506,54 @@ static int s3c_fb_set_par(struct fb_info *info)
322 VIDTCON0_VFPD(var->lower_margin - 1) | 506 VIDTCON0_VFPD(var->lower_margin - 1) |
323 VIDTCON0_VSPW(var->vsync_len - 1); 507 VIDTCON0_VSPW(var->vsync_len - 1);
324 508
325 writel(data, regs + VIDTCON0); 509 writel(data, regs + sfb->variant.vidtcon);
326 510
327 data = VIDTCON1_HBPD(var->left_margin - 1) | 511 data = VIDTCON1_HBPD(var->left_margin - 1) |
328 VIDTCON1_HFPD(var->right_margin - 1) | 512 VIDTCON1_HFPD(var->right_margin - 1) |
329 VIDTCON1_HSPW(var->hsync_len - 1); 513 VIDTCON1_HSPW(var->hsync_len - 1);
330 514
331 writel(data, regs + VIDTCON1); 515 /* VIDTCON1 */
516 writel(data, regs + sfb->variant.vidtcon + 4);
332 517
333 data = VIDTCON2_LINEVAL(var->yres - 1) | 518 data = VIDTCON2_LINEVAL(var->yres - 1) |
334 VIDTCON2_HOZVAL(var->xres - 1); 519 VIDTCON2_HOZVAL(var->xres - 1);
335 writel(data, regs + VIDTCON2); 520 writel(data, regs +sfb->variant.vidtcon + 8 );
336 } 521 }
337 522
338 /* write the buffer address */ 523 /* write the buffer address */
339 524
340 writel(info->fix.smem_start, regs + VIDW_BUF_START(win_no)); 525 /* start and end registers stride is 8 */
526 buf = regs + win_no * 8;
527
528 writel(info->fix.smem_start, buf + sfb->variant.buf_start);
341 529
342 data = info->fix.smem_start + info->fix.line_length * var->yres; 530 data = info->fix.smem_start + info->fix.line_length * var->yres;
343 writel(data, regs + VIDW_BUF_END(win_no)); 531 writel(data, buf + sfb->variant.buf_end);
344 532
345 pagewidth = (var->xres * var->bits_per_pixel) >> 3; 533 pagewidth = (var->xres * var->bits_per_pixel) >> 3;
346 data = VIDW_BUF_SIZE_OFFSET(info->fix.line_length - pagewidth) | 534 data = VIDW_BUF_SIZE_OFFSET(info->fix.line_length - pagewidth) |
347 VIDW_BUF_SIZE_PAGEWIDTH(pagewidth); 535 VIDW_BUF_SIZE_PAGEWIDTH(pagewidth);
348 writel(data, regs + VIDW_BUF_SIZE(win_no)); 536 writel(data, regs + sfb->variant.buf_size + (win_no * 4));
349 537
350 /* write 'OSD' registers to control position of framebuffer */ 538 /* write 'OSD' registers to control position of framebuffer */
351 539
352 data = VIDOSDxA_TOPLEFT_X(0) | VIDOSDxA_TOPLEFT_Y(0); 540 data = VIDOSDxA_TOPLEFT_X(0) | VIDOSDxA_TOPLEFT_Y(0);
353 writel(data, regs + VIDOSD_A(win_no)); 541 writel(data, regs + VIDOSD_A(win_no, sfb->variant));
354 542
355 data = VIDOSDxB_BOTRIGHT_X(s3c_fb_align_word(var->bits_per_pixel, 543 data = VIDOSDxB_BOTRIGHT_X(s3c_fb_align_word(var->bits_per_pixel,
356 var->xres - 1)) | 544 var->xres - 1)) |
357 VIDOSDxB_BOTRIGHT_Y(var->yres - 1); 545 VIDOSDxB_BOTRIGHT_Y(var->yres - 1);
358 546
359 writel(data, regs + VIDOSD_B(win_no)); 547 writel(data, regs + VIDOSD_B(win_no, sfb->variant));
360 548
361 data = var->xres * var->yres; 549 data = var->xres * var->yres;
362 550
363 osdc_data = VIDISD14C_ALPHA1_R(0xf) | 551 alpha = VIDISD14C_ALPHA1_R(0xf) |
364 VIDISD14C_ALPHA1_G(0xf) | 552 VIDISD14C_ALPHA1_G(0xf) |
365 VIDISD14C_ALPHA1_B(0xf); 553 VIDISD14C_ALPHA1_B(0xf);
366 554
367 if (s3c_fb_has_osd_d(win_no)) { 555 vidosd_set_alpha(win, alpha);
368 writel(data, regs + VIDOSD_D(win_no)); 556 vidosd_set_size(win, data);
369 writel(osdc_data, regs + VIDOSD_C(win_no));
370 } else
371 writel(data, regs + VIDOSD_C(win_no));
372 557
373 data = WINCONx_ENWIN; 558 data = WINCONx_ENWIN;
374 559
@@ -424,13 +609,15 @@ static int s3c_fb_set_par(struct fb_info *info)
424 else 609 else
425 data |= WINCON0_BPPMODE_24BPP_888; 610 data |= WINCON0_BPPMODE_24BPP_888;
426 611
612 data |= WINCONx_WSWP;
427 data |= WINCONx_BURSTLEN_16WORD; 613 data |= WINCONx_BURSTLEN_16WORD;
428 break; 614 break;
429 } 615 }
430 616
431 /* It has no color key control register for window0 */ 617 /* Enable the colour keying for the window below this one */
432 if (win_no > 0) { 618 if (win_no > 0) {
433 u32 keycon0_data = 0, keycon1_data = 0; 619 u32 keycon0_data = 0, keycon1_data = 0;
620 void __iomem *keycon = regs + sfb->variant.keycon;
434 621
435 keycon0_data = ~(WxKEYCON0_KEYBL_EN | 622 keycon0_data = ~(WxKEYCON0_KEYBL_EN |
436 WxKEYCON0_KEYEN_F | 623 WxKEYCON0_KEYEN_F |
@@ -438,12 +625,23 @@ static int s3c_fb_set_par(struct fb_info *info)
438 625
439 keycon1_data = WxKEYCON1_COLVAL(0xffffff); 626 keycon1_data = WxKEYCON1_COLVAL(0xffffff);
440 627
441 writel(keycon0_data, regs + WxKEYCONy(win_no-1, 0)); 628 keycon += (win_no - 1) * 8;
442 writel(keycon1_data, regs + WxKEYCONy(win_no-1, 1)); 629
630 writel(keycon0_data, keycon + WKEYCON0);
631 writel(keycon1_data, keycon + WKEYCON1);
632 }
633
634 writel(data, regs + sfb->variant.wincon + (win_no * 4));
635 writel(0x0, regs + sfb->variant.winmap + (win_no * 4));
636
637 /* Enable DMA channel for this window */
638 if (sfb->variant.has_shadowcon) {
639 data = readl(sfb->regs + SHADOWCON);
640 data |= SHADOWCON_CHx_ENABLE(win_no);
641 writel(data, sfb->regs + SHADOWCON);
443 } 642 }
444 643
445 writel(data, regs + WINCON(win_no)); 644 shadow_protect_win(win, 0);
446 writel(0x0, regs + WINxMAP(win_no));
447 645
448 return 0; 646 return 0;
449} 647}
@@ -470,7 +668,7 @@ static void s3c_fb_update_palette(struct s3c_fb *sfb,
470 void __iomem *palreg; 668 void __iomem *palreg;
471 u32 palcon; 669 u32 palcon;
472 670
473 palreg = sfb->regs + s3c_fb_pal_reg(win->index, reg); 671 palreg = sfb->regs + sfb->variant.palette[win->index];
474 672
475 dev_dbg(sfb->dev, "%s: win %d, reg %d (%p): %08x\n", 673 dev_dbg(sfb->dev, "%s: win %d, reg %d (%p): %08x\n",
476 __func__, win->index, reg, palreg, value); 674 __func__, win->index, reg, palreg, value);
@@ -480,10 +678,10 @@ static void s3c_fb_update_palette(struct s3c_fb *sfb,
480 palcon = readl(sfb->regs + WPALCON); 678 palcon = readl(sfb->regs + WPALCON);
481 writel(palcon | WPALCON_PAL_UPDATE, sfb->regs + WPALCON); 679 writel(palcon | WPALCON_PAL_UPDATE, sfb->regs + WPALCON);
482 680
483 if (s3c_fb_pal_is16(win->index)) 681 if (win->variant.palette_16bpp)
484 writew(value, palreg); 682 writew(value, palreg + (reg * 2));
485 else 683 else
486 writel(value, palreg); 684 writel(value, palreg + (reg * 4));
487 685
488 writel(palcon, sfb->regs + WPALCON); 686 writel(palcon, sfb->regs + WPALCON);
489} 687}
@@ -532,7 +730,7 @@ static int s3c_fb_setcolreg(unsigned regno,
532 break; 730 break;
533 731
534 case FB_VISUAL_PSEUDOCOLOR: 732 case FB_VISUAL_PSEUDOCOLOR:
535 if (regno < s3c_fb_win_pal_size(win->index)) { 733 if (regno < win->variant.palette_sz) {
536 val = chan_to_field(red, &win->palette.r); 734 val = chan_to_field(red, &win->palette.r);
537 val |= chan_to_field(green, &win->palette.g); 735 val |= chan_to_field(green, &win->palette.g);
538 val |= chan_to_field(blue, &win->palette.b); 736 val |= chan_to_field(blue, &win->palette.b);
@@ -591,7 +789,7 @@ static int s3c_fb_blank(int blank_mode, struct fb_info *info)
591 789
592 dev_dbg(sfb->dev, "blank mode %d\n", blank_mode); 790 dev_dbg(sfb->dev, "blank mode %d\n", blank_mode);
593 791
594 wincon = readl(sfb->regs + WINCON(index)); 792 wincon = readl(sfb->regs + sfb->variant.wincon + (index * 4));
595 793
596 switch (blank_mode) { 794 switch (blank_mode) {
597 case FB_BLANK_POWERDOWN: 795 case FB_BLANK_POWERDOWN:
@@ -602,11 +800,11 @@ static int s3c_fb_blank(int blank_mode, struct fb_info *info)
602 case FB_BLANK_NORMAL: 800 case FB_BLANK_NORMAL:
603 /* disable the DMA and display 0x0 (black) */ 801 /* disable the DMA and display 0x0 (black) */
604 writel(WINxMAP_MAP | WINxMAP_MAP_COLOUR(0x0), 802 writel(WINxMAP_MAP | WINxMAP_MAP_COLOUR(0x0),
605 sfb->regs + WINxMAP(index)); 803 sfb->regs + sfb->variant.winmap + (index * 4));
606 break; 804 break;
607 805
608 case FB_BLANK_UNBLANK: 806 case FB_BLANK_UNBLANK:
609 writel(0x0, sfb->regs + WINxMAP(index)); 807 writel(0x0, sfb->regs + sfb->variant.winmap + (index * 4));
610 wincon |= WINCONx_ENWIN; 808 wincon |= WINCONx_ENWIN;
611 sfb->enabled |= (1 << index); 809 sfb->enabled |= (1 << index);
612 break; 810 break;
@@ -617,7 +815,7 @@ static int s3c_fb_blank(int blank_mode, struct fb_info *info)
617 return 1; 815 return 1;
618 } 816 }
619 817
620 writel(wincon, sfb->regs + WINCON(index)); 818 writel(wincon, sfb->regs + sfb->variant.wincon + (index * 4));
621 819
622 /* Check the enabled state to see if we need to be running the 820 /* Check the enabled state to see if we need to be running the
623 * main LCD interface, as if there are no active windows then 821 * main LCD interface, as if there are no active windows then
@@ -636,12 +834,185 @@ static int s3c_fb_blank(int blank_mode, struct fb_info *info)
636 /* we're stuck with this until we can do something about overriding 834 /* we're stuck with this until we can do something about overriding
637 * the power control using the blanking event for a single fb. 835 * the power control using the blanking event for a single fb.
638 */ 836 */
639 if (index == 0) 837 if (index == sfb->pdata->default_win)
640 s3c_fb_enable(sfb, blank_mode != FB_BLANK_POWERDOWN ? 1 : 0); 838 s3c_fb_enable(sfb, blank_mode != FB_BLANK_POWERDOWN ? 1 : 0);
641 839
642 return 0; 840 return 0;
643} 841}
644 842
843/**
844 * s3c_fb_pan_display() - Pan the display.
845 *
846 * Note that the offsets can be written to the device at any time, as their
847 * values are latched at each vsync automatically. This also means that only
848 * the last call to this function will have any effect on next vsync, but
849 * there is no need to sleep waiting for it to prevent tearing.
850 *
851 * @var: The screen information to verify.
852 * @info: The framebuffer device.
853 */
854static int s3c_fb_pan_display(struct fb_var_screeninfo *var,
855 struct fb_info *info)
856{
857 struct s3c_fb_win *win = info->par;
858 struct s3c_fb *sfb = win->parent;
859 void __iomem *buf = sfb->regs + win->index * 8;
860 unsigned int start_boff, end_boff;
861
862 /* Offset in bytes to the start of the displayed area */
863 start_boff = var->yoffset * info->fix.line_length;
864 /* X offset depends on the current bpp */
865 if (info->var.bits_per_pixel >= 8) {
866 start_boff += var->xoffset * (info->var.bits_per_pixel >> 3);
867 } else {
868 switch (info->var.bits_per_pixel) {
869 case 4:
870 start_boff += var->xoffset >> 1;
871 break;
872 case 2:
873 start_boff += var->xoffset >> 2;
874 break;
875 case 1:
876 start_boff += var->xoffset >> 3;
877 break;
878 default:
879 dev_err(sfb->dev, "invalid bpp\n");
880 return -EINVAL;
881 }
882 }
883 /* Offset in bytes to the end of the displayed area */
884 end_boff = start_boff + var->yres * info->fix.line_length;
885
886 /* Temporarily turn off per-vsync update from shadow registers until
887 * both start and end addresses are updated to prevent corruption */
888 shadow_protect_win(win, 1);
889
890 writel(info->fix.smem_start + start_boff, buf + sfb->variant.buf_start);
891 writel(info->fix.smem_start + end_boff, buf + sfb->variant.buf_end);
892
893 shadow_protect_win(win, 0);
894
895 return 0;
896}
897
898/**
899 * s3c_fb_enable_irq() - enable framebuffer interrupts
900 * @sfb: main hardware state
901 */
902static void s3c_fb_enable_irq(struct s3c_fb *sfb)
903{
904 void __iomem *regs = sfb->regs;
905 u32 irq_ctrl_reg;
906
907 if (!test_and_set_bit(S3C_FB_VSYNC_IRQ_EN, &sfb->irq_flags)) {
908 /* IRQ disabled, enable it */
909 irq_ctrl_reg = readl(regs + VIDINTCON0);
910
911 irq_ctrl_reg |= VIDINTCON0_INT_ENABLE;
912 irq_ctrl_reg |= VIDINTCON0_INT_FRAME;
913
914 irq_ctrl_reg &= ~VIDINTCON0_FRAMESEL0_MASK;
915 irq_ctrl_reg |= VIDINTCON0_FRAMESEL0_VSYNC;
916 irq_ctrl_reg &= ~VIDINTCON0_FRAMESEL1_MASK;
917 irq_ctrl_reg |= VIDINTCON0_FRAMESEL1_NONE;
918
919 writel(irq_ctrl_reg, regs + VIDINTCON0);
920 }
921}
922
923/**
924 * s3c_fb_disable_irq() - disable framebuffer interrupts
925 * @sfb: main hardware state
926 */
927static void s3c_fb_disable_irq(struct s3c_fb *sfb)
928{
929 void __iomem *regs = sfb->regs;
930 u32 irq_ctrl_reg;
931
932 if (test_and_clear_bit(S3C_FB_VSYNC_IRQ_EN, &sfb->irq_flags)) {
933 /* IRQ enabled, disable it */
934 irq_ctrl_reg = readl(regs + VIDINTCON0);
935
936 irq_ctrl_reg &= ~VIDINTCON0_INT_FRAME;
937 irq_ctrl_reg &= ~VIDINTCON0_INT_ENABLE;
938
939 writel(irq_ctrl_reg, regs + VIDINTCON0);
940 }
941}
942
943static irqreturn_t s3c_fb_irq(int irq, void *dev_id)
944{
945 struct s3c_fb *sfb = dev_id;
946 void __iomem *regs = sfb->regs;
947 u32 irq_sts_reg;
948
949 irq_sts_reg = readl(regs + VIDINTCON1);
950
951 if (irq_sts_reg & VIDINTCON1_INT_FRAME) {
952
953 /* VSYNC interrupt, accept it */
954 writel(VIDINTCON1_INT_FRAME, regs + VIDINTCON1);
955
956 sfb->vsync_info.count++;
957 wake_up_interruptible(&sfb->vsync_info.wait);
958 }
959
960 /* We only support waiting for VSYNC for now, so it's safe
961 * to always disable irqs here.
962 */
963 s3c_fb_disable_irq(sfb);
964
965 return IRQ_HANDLED;
966}
967
968/**
969 * s3c_fb_wait_for_vsync() - sleep until next VSYNC interrupt or timeout
970 * @sfb: main hardware state
971 * @crtc: head index.
972 */
973static int s3c_fb_wait_for_vsync(struct s3c_fb *sfb, u32 crtc)
974{
975 unsigned long count;
976 int ret;
977
978 if (crtc != 0)
979 return -ENODEV;
980
981 count = sfb->vsync_info.count;
982 s3c_fb_enable_irq(sfb);
983 ret = wait_event_interruptible_timeout(sfb->vsync_info.wait,
984 count != sfb->vsync_info.count,
985 msecs_to_jiffies(VSYNC_TIMEOUT_MSEC));
986 if (ret == 0)
987 return -ETIMEDOUT;
988
989 return 0;
990}
991
992static int s3c_fb_ioctl(struct fb_info *info, unsigned int cmd,
993 unsigned long arg)
994{
995 struct s3c_fb_win *win = info->par;
996 struct s3c_fb *sfb = win->parent;
997 int ret;
998 u32 crtc;
999
1000 switch (cmd) {
1001 case FBIO_WAITFORVSYNC:
1002 if (get_user(crtc, (u32 __user *)arg)) {
1003 ret = -EFAULT;
1004 break;
1005 }
1006
1007 ret = s3c_fb_wait_for_vsync(sfb, crtc);
1008 break;
1009 default:
1010 ret = -ENOTTY;
1011 }
1012
1013 return ret;
1014}
1015
645static struct fb_ops s3c_fb_ops = { 1016static struct fb_ops s3c_fb_ops = {
646 .owner = THIS_MODULE, 1017 .owner = THIS_MODULE,
647 .fb_check_var = s3c_fb_check_var, 1018 .fb_check_var = s3c_fb_check_var,
@@ -651,9 +1022,33 @@ static struct fb_ops s3c_fb_ops = {
651 .fb_fillrect = cfb_fillrect, 1022 .fb_fillrect = cfb_fillrect,
652 .fb_copyarea = cfb_copyarea, 1023 .fb_copyarea = cfb_copyarea,
653 .fb_imageblit = cfb_imageblit, 1024 .fb_imageblit = cfb_imageblit,
1025 .fb_pan_display = s3c_fb_pan_display,
1026 .fb_ioctl = s3c_fb_ioctl,
654}; 1027};
655 1028
656/** 1029/**
1030 * s3c_fb_missing_pixclock() - calculates pixel clock
1031 * @mode: The video mode to change.
1032 *
1033 * Calculate the pixel clock when none has been given through platform data.
1034 */
1035static void __devinit s3c_fb_missing_pixclock(struct fb_videomode *mode)
1036{
1037 u64 pixclk = 1000000000000ULL;
1038 u32 div;
1039
1040 div = mode->left_margin + mode->hsync_len + mode->right_margin +
1041 mode->xres;
1042 div *= mode->upper_margin + mode->vsync_len + mode->lower_margin +
1043 mode->yres;
1044 div *= mode->refresh ? : 60;
1045
1046 do_div(pixclk, div);
1047
1048 mode->pixclock = pixclk;
1049}
1050
1051/**
657 * s3c_fb_alloc_memory() - allocate display memory for framebuffer window 1052 * s3c_fb_alloc_memory() - allocate display memory for framebuffer window
658 * @sfb: The base resources for the hardware. 1053 * @sfb: The base resources for the hardware.
659 * @win: The window to initialise memory for. 1054 * @win: The window to initialise memory for.
@@ -711,7 +1106,8 @@ static void s3c_fb_free_memory(struct s3c_fb *sfb, struct s3c_fb_win *win)
711{ 1106{
712 struct fb_info *fbi = win->fbinfo; 1107 struct fb_info *fbi = win->fbinfo;
713 1108
714 dma_free_writecombine(sfb->dev, PAGE_ALIGN(fbi->fix.smem_len), 1109 if (fbi->screen_base)
1110 dma_free_writecombine(sfb->dev, PAGE_ALIGN(fbi->fix.smem_len),
715 fbi->screen_base, fbi->fix.smem_start); 1111 fbi->screen_base, fbi->fix.smem_start);
716} 1112}
717 1113
@@ -724,9 +1120,18 @@ static void s3c_fb_free_memory(struct s3c_fb *sfb, struct s3c_fb_win *win)
724 */ 1120 */
725static void s3c_fb_release_win(struct s3c_fb *sfb, struct s3c_fb_win *win) 1121static void s3c_fb_release_win(struct s3c_fb *sfb, struct s3c_fb_win *win)
726{ 1122{
1123 u32 data;
1124
727 if (win->fbinfo) { 1125 if (win->fbinfo) {
1126 if (sfb->variant.has_shadowcon) {
1127 data = readl(sfb->regs + SHADOWCON);
1128 data &= ~SHADOWCON_CHx_ENABLE(win->index);
1129 data &= ~SHADOWCON_CHx_LOCAL_ENABLE(win->index);
1130 writel(data, sfb->regs + SHADOWCON);
1131 }
728 unregister_framebuffer(win->fbinfo); 1132 unregister_framebuffer(win->fbinfo);
729 fb_dealloc_cmap(&win->fbinfo->cmap); 1133 if (win->fbinfo->cmap.len)
1134 fb_dealloc_cmap(&win->fbinfo->cmap);
730 s3c_fb_free_memory(sfb, win); 1135 s3c_fb_free_memory(sfb, win);
731 framebuffer_release(win->fbinfo); 1136 framebuffer_release(win->fbinfo);
732 } 1137 }
@@ -735,12 +1140,14 @@ static void s3c_fb_release_win(struct s3c_fb *sfb, struct s3c_fb_win *win)
735/** 1140/**
736 * s3c_fb_probe_win() - register an hardware window 1141 * s3c_fb_probe_win() - register an hardware window
737 * @sfb: The base resources for the hardware 1142 * @sfb: The base resources for the hardware
1143 * @variant: The variant information for this window.
738 * @res: Pointer to where to place the resultant window. 1144 * @res: Pointer to where to place the resultant window.
739 * 1145 *
740 * Allocate and do the basic initialisation for one of the hardware's graphics 1146 * Allocate and do the basic initialisation for one of the hardware's graphics
741 * windows. 1147 * windows.
742 */ 1148 */
743static int __devinit s3c_fb_probe_win(struct s3c_fb *sfb, unsigned int win_no, 1149static int __devinit s3c_fb_probe_win(struct s3c_fb *sfb, unsigned int win_no,
1150 struct s3c_fb_win_variant *variant,
744 struct s3c_fb_win **res) 1151 struct s3c_fb_win **res)
745{ 1152{
746 struct fb_var_screeninfo *var; 1153 struct fb_var_screeninfo *var;
@@ -751,9 +1158,11 @@ static int __devinit s3c_fb_probe_win(struct s3c_fb *sfb, unsigned int win_no,
751 int palette_size; 1158 int palette_size;
752 int ret; 1159 int ret;
753 1160
754 dev_dbg(sfb->dev, "probing window %d\n", win_no); 1161 dev_dbg(sfb->dev, "probing window %d, variant %p\n", win_no, variant);
1162
1163 init_waitqueue_head(&sfb->vsync_info.wait);
755 1164
756 palette_size = s3c_fb_win_pal_size(win_no); 1165 palette_size = variant->palette_sz * 4;
757 1166
758 fbinfo = framebuffer_alloc(sizeof(struct s3c_fb_win) + 1167 fbinfo = framebuffer_alloc(sizeof(struct s3c_fb_win) +
759 palette_size * sizeof(u32), sfb->dev); 1168 palette_size * sizeof(u32), sfb->dev);
@@ -770,7 +1179,9 @@ static int __devinit s3c_fb_probe_win(struct s3c_fb *sfb, unsigned int win_no,
770 WARN_ON(windata->win_mode.yres == 0); 1179 WARN_ON(windata->win_mode.yres == 0);
771 1180
772 win = fbinfo->par; 1181 win = fbinfo->par;
1182 *res = win;
773 var = &fbinfo->var; 1183 var = &fbinfo->var;
1184 win->variant = *variant;
774 win->fbinfo = fbinfo; 1185 win->fbinfo = fbinfo;
775 win->parent = sfb; 1186 win->parent = sfb;
776 win->windata = windata; 1187 win->windata = windata;
@@ -784,7 +1195,24 @@ static int __devinit s3c_fb_probe_win(struct s3c_fb *sfb, unsigned int win_no,
784 } 1195 }
785 1196
786 /* setup the r/b/g positions for the window's palette */ 1197 /* setup the r/b/g positions for the window's palette */
787 s3c_fb_init_palette(win_no, &win->palette); 1198 if (win->variant.palette_16bpp) {
1199 /* Set RGB 5:6:5 as default */
1200 win->palette.r.offset = 11;
1201 win->palette.r.length = 5;
1202 win->palette.g.offset = 5;
1203 win->palette.g.length = 6;
1204 win->palette.b.offset = 0;
1205 win->palette.b.length = 5;
1206
1207 } else {
1208 /* Set 8bpp or 8bpp and 1bit alpha */
1209 win->palette.r.offset = 16;
1210 win->palette.r.length = 8;
1211 win->palette.g.offset = 8;
1212 win->palette.g.length = 8;
1213 win->palette.b.offset = 0;
1214 win->palette.b.length = 8;
1215 }
788 1216
789 /* setup the initial video mode from the window */ 1217 /* setup the initial video mode from the window */
790 fb_videomode_to_var(&fbinfo->var, initmode); 1218 fb_videomode_to_var(&fbinfo->var, initmode);
@@ -808,7 +1236,7 @@ static int __devinit s3c_fb_probe_win(struct s3c_fb *sfb, unsigned int win_no,
808 1236
809 /* create initial colour map */ 1237 /* create initial colour map */
810 1238
811 ret = fb_alloc_cmap(&fbinfo->cmap, s3c_fb_win_pal_size(win_no), 1); 1239 ret = fb_alloc_cmap(&fbinfo->cmap, win->variant.palette_sz, 1);
812 if (ret == 0) 1240 if (ret == 0)
813 fb_set_cmap(&fbinfo->cmap, fbinfo); 1241 fb_set_cmap(&fbinfo->cmap, fbinfo);
814 else 1242 else
@@ -826,7 +1254,6 @@ static int __devinit s3c_fb_probe_win(struct s3c_fb *sfb, unsigned int win_no,
826 return ret; 1254 return ret;
827 } 1255 }
828 1256
829 *res = win;
830 dev_info(sfb->dev, "window %d: fb %s\n", win_no, fbinfo->fix.id); 1257 dev_info(sfb->dev, "window %d: fb %s\n", win_no, fbinfo->fix.id);
831 1258
832 return 0; 1259 return 0;
@@ -842,18 +1269,19 @@ static int __devinit s3c_fb_probe_win(struct s3c_fb *sfb, unsigned int win_no,
842static void s3c_fb_clear_win(struct s3c_fb *sfb, int win) 1269static void s3c_fb_clear_win(struct s3c_fb *sfb, int win)
843{ 1270{
844 void __iomem *regs = sfb->regs; 1271 void __iomem *regs = sfb->regs;
845 1272 u32 reg;
846 writel(0, regs + WINCON(win)); 1273
847 writel(0xffffff, regs + WxKEYCONy(win, 0)); 1274 writel(0, regs + sfb->variant.wincon + (win * 4));
848 writel(0xffffff, regs + WxKEYCONy(win, 1)); 1275 writel(0, regs + VIDOSD_A(win, sfb->variant));
849 1276 writel(0, regs + VIDOSD_B(win, sfb->variant));
850 writel(0, regs + VIDOSD_A(win)); 1277 writel(0, regs + VIDOSD_C(win, sfb->variant));
851 writel(0, regs + VIDOSD_B(win)); 1278 reg = readl(regs + SHADOWCON);
852 writel(0, regs + VIDOSD_C(win)); 1279 writel(reg & ~SHADOWCON_WINx_PROTECT(win), regs + SHADOWCON);
853} 1280}
854 1281
855static int __devinit s3c_fb_probe(struct platform_device *pdev) 1282static int __devinit s3c_fb_probe(struct platform_device *pdev)
856{ 1283{
1284 struct s3c_fb_driverdata *fbdrv;
857 struct device *dev = &pdev->dev; 1285 struct device *dev = &pdev->dev;
858 struct s3c_fb_platdata *pd; 1286 struct s3c_fb_platdata *pd;
859 struct s3c_fb *sfb; 1287 struct s3c_fb *sfb;
@@ -861,6 +1289,13 @@ static int __devinit s3c_fb_probe(struct platform_device *pdev)
861 int win; 1289 int win;
862 int ret = 0; 1290 int ret = 0;
863 1291
1292 fbdrv = (struct s3c_fb_driverdata *)platform_get_device_id(pdev)->driver_data;
1293
1294 if (fbdrv->variant.nr_windows > S3C_FB_MAX_WIN) {
1295 dev_err(dev, "too many windows, cannot attach\n");
1296 return -EINVAL;
1297 }
1298
864 pd = pdev->dev.platform_data; 1299 pd = pdev->dev.platform_data;
865 if (!pd) { 1300 if (!pd) {
866 dev_err(dev, "no platform data specified\n"); 1301 dev_err(dev, "no platform data specified\n");
@@ -873,8 +1308,11 @@ static int __devinit s3c_fb_probe(struct platform_device *pdev)
873 return -ENOMEM; 1308 return -ENOMEM;
874 } 1309 }
875 1310
1311 dev_dbg(dev, "allocate new framebuffer %p\n", sfb);
1312
876 sfb->dev = dev; 1313 sfb->dev = dev;
877 sfb->pdata = pd; 1314 sfb->pdata = pd;
1315 sfb->variant = fbdrv->variant;
878 1316
879 sfb->bus_clk = clk_get(dev, "lcd"); 1317 sfb->bus_clk = clk_get(dev, "lcd");
880 if (IS_ERR(sfb->bus_clk)) { 1318 if (IS_ERR(sfb->bus_clk)) {
@@ -906,6 +1344,20 @@ static int __devinit s3c_fb_probe(struct platform_device *pdev)
906 goto err_req_region; 1344 goto err_req_region;
907 } 1345 }
908 1346
1347 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
1348 if (!res) {
1349 dev_err(dev, "failed to acquire irq resource\n");
1350 ret = -ENOENT;
1351 goto err_ioremap;
1352 }
1353 sfb->irq_no = res->start;
1354 ret = request_irq(sfb->irq_no, s3c_fb_irq,
1355 0, "s3c_fb", sfb);
1356 if (ret) {
1357 dev_err(dev, "irq request failed\n");
1358 goto err_ioremap;
1359 }
1360
909 dev_dbg(dev, "got resources (regs %p), probing windows\n", sfb->regs); 1361 dev_dbg(dev, "got resources (regs %p), probing windows\n", sfb->regs);
910 1362
911 /* setup gpio and output polarity controls */ 1363 /* setup gpio and output polarity controls */
@@ -916,21 +1368,34 @@ static int __devinit s3c_fb_probe(struct platform_device *pdev)
916 1368
917 /* zero all windows before we do anything */ 1369 /* zero all windows before we do anything */
918 1370
919 for (win = 0; win < S3C_FB_MAX_WIN; win++) 1371 for (win = 0; win < fbdrv->variant.nr_windows; win++)
920 s3c_fb_clear_win(sfb, win); 1372 s3c_fb_clear_win(sfb, win);
921 1373
1374 /* initialise colour key controls */
1375 for (win = 0; win < (fbdrv->variant.nr_windows - 1); win++) {
1376 void __iomem *regs = sfb->regs + sfb->variant.keycon;
1377
1378 regs += (win * 8);
1379 writel(0xffffff, regs + WKEYCON0);
1380 writel(0xffffff, regs + WKEYCON1);
1381 }
1382
922 /* we have the register setup, start allocating framebuffers */ 1383 /* we have the register setup, start allocating framebuffers */
923 1384
924 for (win = 0; win < S3C_FB_MAX_WIN; win++) { 1385 for (win = 0; win < fbdrv->variant.nr_windows; win++) {
925 if (!pd->win[win]) 1386 if (!pd->win[win])
926 continue; 1387 continue;
927 1388
928 ret = s3c_fb_probe_win(sfb, win, &sfb->windows[win]); 1389 if (!pd->win[win]->win_mode.pixclock)
1390 s3c_fb_missing_pixclock(&pd->win[win]->win_mode);
1391
1392 ret = s3c_fb_probe_win(sfb, win, fbdrv->win[win],
1393 &sfb->windows[win]);
929 if (ret < 0) { 1394 if (ret < 0) {
930 dev_err(dev, "failed to create window %d\n", win); 1395 dev_err(dev, "failed to create window %d\n", win);
931 for (; win >= 0; win--) 1396 for (; win >= 0; win--)
932 s3c_fb_release_win(sfb, sfb->windows[win]); 1397 s3c_fb_release_win(sfb, sfb->windows[win]);
933 goto err_ioremap; 1398 goto err_irq;
934 } 1399 }
935 } 1400 }
936 1401
@@ -938,6 +1403,9 @@ static int __devinit s3c_fb_probe(struct platform_device *pdev)
938 1403
939 return 0; 1404 return 0;
940 1405
1406err_irq:
1407 free_irq(sfb->irq_no, sfb);
1408
941err_ioremap: 1409err_ioremap:
942 iounmap(sfb->regs); 1410 iounmap(sfb->regs);
943 1411
@@ -970,6 +1438,8 @@ static int __devexit s3c_fb_remove(struct platform_device *pdev)
970 if (sfb->windows[win]) 1438 if (sfb->windows[win])
971 s3c_fb_release_win(sfb, sfb->windows[win]); 1439 s3c_fb_release_win(sfb, sfb->windows[win]);
972 1440
1441 free_irq(sfb->irq_no, sfb);
1442
973 iounmap(sfb->regs); 1443 iounmap(sfb->regs);
974 1444
975 clk_disable(sfb->bus_clk); 1445 clk_disable(sfb->bus_clk);
@@ -1016,9 +1486,17 @@ static int s3c_fb_resume(struct platform_device *pdev)
1016 writel(pd->vidcon1, sfb->regs + VIDCON1); 1486 writel(pd->vidcon1, sfb->regs + VIDCON1);
1017 1487
1018 /* zero all windows before we do anything */ 1488 /* zero all windows before we do anything */
1019 for (win_no = 0; win_no < S3C_FB_MAX_WIN; win_no++) 1489 for (win_no = 0; win_no < sfb->variant.nr_windows; win_no++)
1020 s3c_fb_clear_win(sfb, win_no); 1490 s3c_fb_clear_win(sfb, win_no);
1021 1491
1492 for (win_no = 0; win_no < sfb->variant.nr_windows - 1; win_no++) {
1493 void __iomem *regs = sfb->regs + sfb->variant.keycon;
1494
1495 regs += (win_no * 8);
1496 writel(0xffffff, regs + WKEYCON0);
1497 writel(0xffffff, regs + WKEYCON1);
1498 }
1499
1022 /* restore framebuffers */ 1500 /* restore framebuffers */
1023 for (win_no = 0; win_no < S3C_FB_MAX_WIN; win_no++) { 1501 for (win_no = 0; win_no < S3C_FB_MAX_WIN; win_no++) {
1024 win = sfb->windows[win_no]; 1502 win = sfb->windows[win_no];
@@ -1036,11 +1514,208 @@ static int s3c_fb_resume(struct platform_device *pdev)
1036#define s3c_fb_resume NULL 1514#define s3c_fb_resume NULL
1037#endif 1515#endif
1038 1516
1517
1518#define VALID_BPP124 (VALID_BPP(1) | VALID_BPP(2) | VALID_BPP(4))
1519#define VALID_BPP1248 (VALID_BPP124 | VALID_BPP(8))
1520
1521static struct s3c_fb_win_variant s3c_fb_data_64xx_wins[] = {
1522 [0] = {
1523 .has_osd_c = 1,
1524 .osd_size_off = 0x8,
1525 .palette_sz = 256,
1526 .valid_bpp = VALID_BPP1248 | VALID_BPP(16) | VALID_BPP(24),
1527 },
1528 [1] = {
1529 .has_osd_c = 1,
1530 .has_osd_d = 1,
1531 .osd_size_off = 0x12,
1532 .has_osd_alpha = 1,
1533 .palette_sz = 256,
1534 .valid_bpp = (VALID_BPP1248 | VALID_BPP(16) |
1535 VALID_BPP(18) | VALID_BPP(19) |
1536 VALID_BPP(24) | VALID_BPP(25)),
1537 },
1538 [2] = {
1539 .has_osd_c = 1,
1540 .has_osd_d = 1,
1541 .osd_size_off = 0x12,
1542 .has_osd_alpha = 1,
1543 .palette_sz = 16,
1544 .palette_16bpp = 1,
1545 .valid_bpp = (VALID_BPP1248 | VALID_BPP(16) |
1546 VALID_BPP(18) | VALID_BPP(19) |
1547 VALID_BPP(24) | VALID_BPP(25)),
1548 },
1549 [3] = {
1550 .has_osd_c = 1,
1551 .has_osd_alpha = 1,
1552 .palette_sz = 16,
1553 .palette_16bpp = 1,
1554 .valid_bpp = (VALID_BPP124 | VALID_BPP(16) |
1555 VALID_BPP(18) | VALID_BPP(19) |
1556 VALID_BPP(24) | VALID_BPP(25)),
1557 },
1558 [4] = {
1559 .has_osd_c = 1,
1560 .has_osd_alpha = 1,
1561 .palette_sz = 4,
1562 .palette_16bpp = 1,
1563 .valid_bpp = (VALID_BPP(1) | VALID_BPP(2) |
1564 VALID_BPP(16) | VALID_BPP(18) |
1565 VALID_BPP(24) | VALID_BPP(25)),
1566 },
1567};
1568
1569static struct s3c_fb_driverdata s3c_fb_data_64xx = {
1570 .variant = {
1571 .nr_windows = 5,
1572 .vidtcon = VIDTCON0,
1573 .wincon = WINCON(0),
1574 .winmap = WINxMAP(0),
1575 .keycon = WKEYCON,
1576 .osd = VIDOSD_BASE,
1577 .osd_stride = 16,
1578 .buf_start = VIDW_BUF_START(0),
1579 .buf_size = VIDW_BUF_SIZE(0),
1580 .buf_end = VIDW_BUF_END(0),
1581
1582 .palette = {
1583 [0] = 0x400,
1584 [1] = 0x800,
1585 [2] = 0x300,
1586 [3] = 0x320,
1587 [4] = 0x340,
1588 },
1589
1590 .has_prtcon = 1,
1591 },
1592 .win[0] = &s3c_fb_data_64xx_wins[0],
1593 .win[1] = &s3c_fb_data_64xx_wins[1],
1594 .win[2] = &s3c_fb_data_64xx_wins[2],
1595 .win[3] = &s3c_fb_data_64xx_wins[3],
1596 .win[4] = &s3c_fb_data_64xx_wins[4],
1597};
1598
1599static struct s3c_fb_driverdata s3c_fb_data_s5pc100 = {
1600 .variant = {
1601 .nr_windows = 5,
1602 .vidtcon = VIDTCON0,
1603 .wincon = WINCON(0),
1604 .winmap = WINxMAP(0),
1605 .keycon = WKEYCON,
1606 .osd = VIDOSD_BASE,
1607 .osd_stride = 16,
1608 .buf_start = VIDW_BUF_START(0),
1609 .buf_size = VIDW_BUF_SIZE(0),
1610 .buf_end = VIDW_BUF_END(0),
1611
1612 .palette = {
1613 [0] = 0x2400,
1614 [1] = 0x2800,
1615 [2] = 0x2c00,
1616 [3] = 0x3000,
1617 [4] = 0x3400,
1618 },
1619
1620 .has_prtcon = 1,
1621 },
1622 .win[0] = &s3c_fb_data_64xx_wins[0],
1623 .win[1] = &s3c_fb_data_64xx_wins[1],
1624 .win[2] = &s3c_fb_data_64xx_wins[2],
1625 .win[3] = &s3c_fb_data_64xx_wins[3],
1626 .win[4] = &s3c_fb_data_64xx_wins[4],
1627};
1628
1629static struct s3c_fb_driverdata s3c_fb_data_s5pv210 = {
1630 .variant = {
1631 .nr_windows = 5,
1632 .vidtcon = VIDTCON0,
1633 .wincon = WINCON(0),
1634 .winmap = WINxMAP(0),
1635 .keycon = WKEYCON,
1636 .osd = VIDOSD_BASE,
1637 .osd_stride = 16,
1638 .buf_start = VIDW_BUF_START(0),
1639 .buf_size = VIDW_BUF_SIZE(0),
1640 .buf_end = VIDW_BUF_END(0),
1641
1642 .palette = {
1643 [0] = 0x2400,
1644 [1] = 0x2800,
1645 [2] = 0x2c00,
1646 [3] = 0x3000,
1647 [4] = 0x3400,
1648 },
1649
1650 .has_shadowcon = 1,
1651 },
1652 .win[0] = &s3c_fb_data_64xx_wins[0],
1653 .win[1] = &s3c_fb_data_64xx_wins[1],
1654 .win[2] = &s3c_fb_data_64xx_wins[2],
1655 .win[3] = &s3c_fb_data_64xx_wins[3],
1656 .win[4] = &s3c_fb_data_64xx_wins[4],
1657};
1658
1659/* S3C2443/S3C2416 style hardware */
1660static struct s3c_fb_driverdata s3c_fb_data_s3c2443 = {
1661 .variant = {
1662 .nr_windows = 2,
1663 .is_2443 = 1,
1664
1665 .vidtcon = 0x08,
1666 .wincon = 0x14,
1667 .winmap = 0xd0,
1668 .keycon = 0xb0,
1669 .osd = 0x28,
1670 .osd_stride = 12,
1671 .buf_start = 0x64,
1672 .buf_size = 0x94,
1673 .buf_end = 0x7c,
1674
1675 .palette = {
1676 [0] = 0x400,
1677 [1] = 0x800,
1678 },
1679 },
1680 .win[0] = &(struct s3c_fb_win_variant) {
1681 .palette_sz = 256,
1682 .valid_bpp = VALID_BPP1248 | VALID_BPP(16) | VALID_BPP(24),
1683 },
1684 .win[1] = &(struct s3c_fb_win_variant) {
1685 .has_osd_c = 1,
1686 .has_osd_alpha = 1,
1687 .palette_sz = 256,
1688 .valid_bpp = (VALID_BPP1248 | VALID_BPP(16) |
1689 VALID_BPP(18) | VALID_BPP(19) |
1690 VALID_BPP(24) | VALID_BPP(25) |
1691 VALID_BPP(28)),
1692 },
1693};
1694
1695static struct platform_device_id s3c_fb_driver_ids[] = {
1696 {
1697 .name = "s3c-fb",
1698 .driver_data = (unsigned long)&s3c_fb_data_64xx,
1699 }, {
1700 .name = "s5pc100-fb",
1701 .driver_data = (unsigned long)&s3c_fb_data_s5pc100,
1702 }, {
1703 .name = "s5pv210-fb",
1704 .driver_data = (unsigned long)&s3c_fb_data_s5pv210,
1705 }, {
1706 .name = "s3c2443-fb",
1707 .driver_data = (unsigned long)&s3c_fb_data_s3c2443,
1708 },
1709 {},
1710};
1711MODULE_DEVICE_TABLE(platform, s3c_fb_driver_ids);
1712
1039static struct platform_driver s3c_fb_driver = { 1713static struct platform_driver s3c_fb_driver = {
1040 .probe = s3c_fb_probe, 1714 .probe = s3c_fb_probe,
1041 .remove = __devexit_p(s3c_fb_remove), 1715 .remove = __devexit_p(s3c_fb_remove),
1042 .suspend = s3c_fb_suspend, 1716 .suspend = s3c_fb_suspend,
1043 .resume = s3c_fb_resume, 1717 .resume = s3c_fb_resume,
1718 .id_table = s3c_fb_driver_ids,
1044 .driver = { 1719 .driver = {
1045 .name = "s3c-fb", 1720 .name = "s3c-fb",
1046 .owner = THIS_MODULE, 1721 .owner = THIS_MODULE,
diff --git a/drivers/video/sh_mipi_dsi.c b/drivers/video/sh_mipi_dsi.c
new file mode 100644
index 000000000000..5699ce0c1780
--- /dev/null
+++ b/drivers/video/sh_mipi_dsi.c
@@ -0,0 +1,505 @@
1/*
2 * Renesas SH-mobile MIPI DSI support
3 *
4 * Copyright (C) 2010 Guennadi Liakhovetski <g.liakhovetski@gmx.de>
5 *
6 * This is free software; you can redistribute it and/or modify
7 * it under the terms of version 2 of the GNU General Public License as
8 * published by the Free Software Foundation.
9 */
10
11#include <linux/clk.h>
12#include <linux/delay.h>
13#include <linux/init.h>
14#include <linux/io.h>
15#include <linux/platform_device.h>
16#include <linux/slab.h>
17#include <linux/string.h>
18#include <linux/types.h>
19
20#include <video/mipi_display.h>
21#include <video/sh_mipi_dsi.h>
22#include <video/sh_mobile_lcdc.h>
23
24#define CMTSRTCTR 0x80d0
25#define CMTSRTREQ 0x8070
26
27#define DSIINTE 0x0060
28
29/* E.g., sh7372 has 2 MIPI-DSIs - one for each LCDC */
30#define MAX_SH_MIPI_DSI 2
31
32struct sh_mipi {
33 void __iomem *base;
34 struct clk *dsit_clk;
35 struct clk *dsip_clk;
36};
37
38static struct sh_mipi *mipi_dsi[MAX_SH_MIPI_DSI];
39
40/* Protect the above array */
41static DEFINE_MUTEX(array_lock);
42
43static struct sh_mipi *sh_mipi_by_handle(int handle)
44{
45 if (handle >= ARRAY_SIZE(mipi_dsi) || handle < 0)
46 return NULL;
47
48 return mipi_dsi[handle];
49}
50
51static int sh_mipi_send_short(struct sh_mipi *mipi, u8 dsi_cmd,
52 u8 cmd, u8 param)
53{
54 u32 data = (dsi_cmd << 24) | (cmd << 16) | (param << 8);
55 int cnt = 100;
56
57 /* transmit a short packet to LCD panel */
58 iowrite32(1 | data, mipi->base + 0x80d0); /* CMTSRTCTR */
59 iowrite32(1, mipi->base + 0x8070); /* CMTSRTREQ */
60
61 while ((ioread32(mipi->base + 0x8070) & 1) && --cnt)
62 udelay(1);
63
64 return cnt ? 0 : -ETIMEDOUT;
65}
66
67#define LCD_CHAN2MIPI(c) ((c) < LCDC_CHAN_MAINLCD || (c) > LCDC_CHAN_SUBLCD ? \
68 -EINVAL : (c) - 1)
69
70static int sh_mipi_dcs(int handle, u8 cmd)
71{
72 struct sh_mipi *mipi = sh_mipi_by_handle(LCD_CHAN2MIPI(handle));
73 if (!mipi)
74 return -ENODEV;
75 return sh_mipi_send_short(mipi, MIPI_DSI_DCS_SHORT_WRITE, cmd, 0);
76}
77
78static int sh_mipi_dcs_param(int handle, u8 cmd, u8 param)
79{
80 struct sh_mipi *mipi = sh_mipi_by_handle(LCD_CHAN2MIPI(handle));
81 if (!mipi)
82 return -ENODEV;
83 return sh_mipi_send_short(mipi, MIPI_DSI_DCS_SHORT_WRITE_PARAM, cmd,
84 param);
85}
86
87static void sh_mipi_dsi_enable(struct sh_mipi *mipi, bool enable)
88{
89 /*
90 * enable LCDC data tx, transition to LPS after completion of each HS
91 * packet
92 */
93 iowrite32(0x00000002 | enable, mipi->base + 0x8000); /* DTCTR */
94}
95
96static void sh_mipi_shutdown(struct platform_device *pdev)
97{
98 struct sh_mipi *mipi = platform_get_drvdata(pdev);
99
100 sh_mipi_dsi_enable(mipi, false);
101}
102
103static void mipi_display_on(void *arg, struct fb_info *info)
104{
105 struct sh_mipi *mipi = arg;
106
107 sh_mipi_dsi_enable(mipi, true);
108}
109
110static void mipi_display_off(void *arg)
111{
112 struct sh_mipi *mipi = arg;
113
114 sh_mipi_dsi_enable(mipi, false);
115}
116
117static int __init sh_mipi_setup(struct sh_mipi *mipi,
118 struct sh_mipi_dsi_info *pdata)
119{
120 void __iomem *base = mipi->base;
121 struct sh_mobile_lcdc_chan_cfg *ch = pdata->lcd_chan;
122 u32 pctype, datatype, pixfmt;
123 u32 linelength;
124 bool yuv;
125
126 /* Select data format */
127 switch (pdata->data_format) {
128 case MIPI_RGB888:
129 pctype = 0;
130 datatype = MIPI_DSI_PACKED_PIXEL_STREAM_24;
131 pixfmt = MIPI_DCS_PIXEL_FMT_24BIT;
132 linelength = ch->lcd_cfg.xres * 3;
133 yuv = false;
134 break;
135 case MIPI_RGB565:
136 pctype = 1;
137 datatype = MIPI_DSI_PACKED_PIXEL_STREAM_16;
138 pixfmt = MIPI_DCS_PIXEL_FMT_16BIT;
139 linelength = ch->lcd_cfg.xres * 2;
140 yuv = false;
141 break;
142 case MIPI_RGB666_LP:
143 pctype = 2;
144 datatype = MIPI_DSI_PIXEL_STREAM_3BYTE_18;
145 pixfmt = MIPI_DCS_PIXEL_FMT_24BIT;
146 linelength = ch->lcd_cfg.xres * 3;
147 yuv = false;
148 break;
149 case MIPI_RGB666:
150 pctype = 3;
151 datatype = MIPI_DSI_PACKED_PIXEL_STREAM_18;
152 pixfmt = MIPI_DCS_PIXEL_FMT_18BIT;
153 linelength = (ch->lcd_cfg.xres * 18 + 7) / 8;
154 yuv = false;
155 break;
156 case MIPI_BGR888:
157 pctype = 8;
158 datatype = MIPI_DSI_PACKED_PIXEL_STREAM_24;
159 pixfmt = MIPI_DCS_PIXEL_FMT_24BIT;
160 linelength = ch->lcd_cfg.xres * 3;
161 yuv = false;
162 break;
163 case MIPI_BGR565:
164 pctype = 9;
165 datatype = MIPI_DSI_PACKED_PIXEL_STREAM_16;
166 pixfmt = MIPI_DCS_PIXEL_FMT_16BIT;
167 linelength = ch->lcd_cfg.xres * 2;
168 yuv = false;
169 break;
170 case MIPI_BGR666_LP:
171 pctype = 0xa;
172 datatype = MIPI_DSI_PIXEL_STREAM_3BYTE_18;
173 pixfmt = MIPI_DCS_PIXEL_FMT_24BIT;
174 linelength = ch->lcd_cfg.xres * 3;
175 yuv = false;
176 break;
177 case MIPI_BGR666:
178 pctype = 0xb;
179 datatype = MIPI_DSI_PACKED_PIXEL_STREAM_18;
180 pixfmt = MIPI_DCS_PIXEL_FMT_18BIT;
181 linelength = (ch->lcd_cfg.xres * 18 + 7) / 8;
182 yuv = false;
183 break;
184 case MIPI_YUYV:
185 pctype = 4;
186 datatype = MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR16;
187 pixfmt = MIPI_DCS_PIXEL_FMT_16BIT;
188 linelength = ch->lcd_cfg.xres * 2;
189 yuv = true;
190 break;
191 case MIPI_UYVY:
192 pctype = 5;
193 datatype = MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR16;
194 pixfmt = MIPI_DCS_PIXEL_FMT_16BIT;
195 linelength = ch->lcd_cfg.xres * 2;
196 yuv = true;
197 break;
198 case MIPI_YUV420_L:
199 pctype = 6;
200 datatype = MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR12;
201 pixfmt = MIPI_DCS_PIXEL_FMT_12BIT;
202 linelength = (ch->lcd_cfg.xres * 12 + 7) / 8;
203 yuv = true;
204 break;
205 case MIPI_YUV420:
206 pctype = 7;
207 datatype = MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR12;
208 pixfmt = MIPI_DCS_PIXEL_FMT_12BIT;
209 /* Length of U/V line */
210 linelength = (ch->lcd_cfg.xres + 1) / 2;
211 yuv = true;
212 break;
213 default:
214 return -EINVAL;
215 }
216
217 if ((yuv && ch->interface_type != YUV422) ||
218 (!yuv && ch->interface_type != RGB24))
219 return -EINVAL;
220
221 /* reset DSI link */
222 iowrite32(0x00000001, base); /* SYSCTRL */
223 /* Hold reset for 100 cycles of the slowest of bus, HS byte and LP clock */
224 udelay(50);
225 iowrite32(0x00000000, base); /* SYSCTRL */
226
227 /* setup DSI link */
228
229 /*
230 * Default = ULPS enable |
231 * Contention detection enabled |
232 * EoT packet transmission enable |
233 * CRC check enable |
234 * ECC check enable
235 * additionally enable first two lanes
236 */
237 iowrite32(0x00003703, base + 0x04); /* SYSCONF */
238 /*
239 * T_wakeup = 0x7000
240 * T_hs-trail = 3
241 * T_hs-prepare = 3
242 * T_clk-trail = 3
243 * T_clk-prepare = 2
244 */
245 iowrite32(0x70003332, base + 0x08); /* TIMSET */
246 /* no responses requested */
247 iowrite32(0x00000000, base + 0x18); /* RESREQSET0 */
248 /* request response to packets of type 0x28 */
249 iowrite32(0x00000100, base + 0x1c); /* RESREQSET1 */
250 /* High-speed transmission timeout, default 0xffffffff */
251 iowrite32(0x0fffffff, base + 0x20); /* HSTTOVSET */
252 /* LP reception timeout, default 0xffffffff */
253 iowrite32(0x0fffffff, base + 0x24); /* LPRTOVSET */
254 /* Turn-around timeout, default 0xffffffff */
255 iowrite32(0x0fffffff, base + 0x28); /* TATOVSET */
256 /* Peripheral reset timeout, default 0xffffffff */
257 iowrite32(0x0fffffff, base + 0x2c); /* PRTOVSET */
258 /* Enable timeout counters */
259 iowrite32(0x00000f00, base + 0x30); /* DSICTRL */
260 /* Interrupts not used, disable all */
261 iowrite32(0, base + DSIINTE);
262 /* DSI-Tx bias on */
263 iowrite32(0x00000001, base + 0x70); /* PHYCTRL */
264 udelay(200);
265 /* Deassert resets, power on, set multiplier */
266 iowrite32(0x03070b01, base + 0x70); /* PHYCTRL */
267
268 /* setup l-bridge */
269
270 /*
271 * Enable transmission of all packets,
272 * transmit LPS after each HS packet completion
273 */
274 iowrite32(0x00000006, base + 0x8000); /* DTCTR */
275 /* VSYNC width = 2 (<< 17) */
276 iowrite32(0x00040000 | (pctype << 12) | datatype, base + 0x8020); /* VMCTR1 */
277 /*
278 * Non-burst mode with sync pulses: VSE and HSE are output,
279 * HSA period allowed, no commands in LP
280 */
281 iowrite32(0x00e00000, base + 0x8024); /* VMCTR2 */
282 /*
283 * 0x660 = 1632 bytes per line (RGB24, 544 pixels: see
284 * sh_mobile_lcdc_info.ch[0].lcd_cfg.xres), HSALEN = 1 - default
285 * (unused, since VMCTR2[HSABM] = 0)
286 */
287 iowrite32(1 | (linelength << 16), base + 0x8028); /* VMLEN1 */
288
289 msleep(5);
290
291 /* setup LCD panel */
292
293 /* cf. drivers/video/omap/lcd_mipid.c */
294 sh_mipi_dcs(ch->chan, MIPI_DCS_EXIT_SLEEP_MODE);
295 msleep(120);
296 /*
297 * [7] - Page Address Mode
298 * [6] - Column Address Mode
299 * [5] - Page / Column Address Mode
300 * [4] - Display Device Line Refresh Order
301 * [3] - RGB/BGR Order
302 * [2] - Display Data Latch Data Order
303 * [1] - Flip Horizontal
304 * [0] - Flip Vertical
305 */
306 sh_mipi_dcs_param(ch->chan, MIPI_DCS_SET_ADDRESS_MODE, 0x00);
307 /* cf. set_data_lines() */
308 sh_mipi_dcs_param(ch->chan, MIPI_DCS_SET_PIXEL_FORMAT,
309 pixfmt << 4);
310 sh_mipi_dcs(ch->chan, MIPI_DCS_SET_DISPLAY_ON);
311
312 return 0;
313}
314
315static int __init sh_mipi_probe(struct platform_device *pdev)
316{
317 struct sh_mipi *mipi;
318 struct sh_mipi_dsi_info *pdata = pdev->dev.platform_data;
319 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
320 unsigned long rate, f_current;
321 int idx = pdev->id, ret;
322 char dsip_clk[] = "dsi.p_clk";
323
324 if (!res || idx >= ARRAY_SIZE(mipi_dsi) || !pdata)
325 return -ENODEV;
326
327 mutex_lock(&array_lock);
328 if (idx < 0)
329 for (idx = 0; idx < ARRAY_SIZE(mipi_dsi) && mipi_dsi[idx]; idx++)
330 ;
331
332 if (idx == ARRAY_SIZE(mipi_dsi)) {
333 ret = -EBUSY;
334 goto efindslot;
335 }
336
337 mipi = kzalloc(sizeof(*mipi), GFP_KERNEL);
338 if (!mipi) {
339 ret = -ENOMEM;
340 goto ealloc;
341 }
342
343 if (!request_mem_region(res->start, resource_size(res), pdev->name)) {
344 dev_err(&pdev->dev, "MIPI register region already claimed\n");
345 ret = -EBUSY;
346 goto ereqreg;
347 }
348
349 mipi->base = ioremap(res->start, resource_size(res));
350 if (!mipi->base) {
351 ret = -ENOMEM;
352 goto emap;
353 }
354
355 mipi->dsit_clk = clk_get(&pdev->dev, "dsit_clk");
356 if (IS_ERR(mipi->dsit_clk)) {
357 ret = PTR_ERR(mipi->dsit_clk);
358 goto eclktget;
359 }
360
361 f_current = clk_get_rate(mipi->dsit_clk);
362 /* 80MHz required by the datasheet */
363 rate = clk_round_rate(mipi->dsit_clk, 80000000);
364 if (rate > 0 && rate != f_current)
365 ret = clk_set_rate(mipi->dsit_clk, rate);
366 else
367 ret = rate;
368 if (ret < 0)
369 goto esettrate;
370
371 dev_dbg(&pdev->dev, "DSI-T clk %lu -> %lu\n", f_current, rate);
372
373 sprintf(dsip_clk, "dsi%1.1dp_clk", idx);
374 mipi->dsip_clk = clk_get(&pdev->dev, dsip_clk);
375 if (IS_ERR(mipi->dsip_clk)) {
376 ret = PTR_ERR(mipi->dsip_clk);
377 goto eclkpget;
378 }
379
380 f_current = clk_get_rate(mipi->dsip_clk);
381 /* Between 10 and 50MHz */
382 rate = clk_round_rate(mipi->dsip_clk, 24000000);
383 if (rate > 0 && rate != f_current)
384 ret = clk_set_rate(mipi->dsip_clk, rate);
385 else
386 ret = rate;
387 if (ret < 0)
388 goto esetprate;
389
390 dev_dbg(&pdev->dev, "DSI-P clk %lu -> %lu\n", f_current, rate);
391
392 msleep(10);
393
394 ret = clk_enable(mipi->dsit_clk);
395 if (ret < 0)
396 goto eclkton;
397
398 ret = clk_enable(mipi->dsip_clk);
399 if (ret < 0)
400 goto eclkpon;
401
402 mipi_dsi[idx] = mipi;
403
404 ret = sh_mipi_setup(mipi, pdata);
405 if (ret < 0)
406 goto emipisetup;
407
408 mutex_unlock(&array_lock);
409 platform_set_drvdata(pdev, mipi);
410
411 /* Set up LCDC callbacks */
412 pdata->lcd_chan->board_cfg.board_data = mipi;
413 pdata->lcd_chan->board_cfg.display_on = mipi_display_on;
414 pdata->lcd_chan->board_cfg.display_off = mipi_display_off;
415
416 return 0;
417
418emipisetup:
419 mipi_dsi[idx] = NULL;
420 clk_disable(mipi->dsip_clk);
421eclkpon:
422 clk_disable(mipi->dsit_clk);
423eclkton:
424esetprate:
425 clk_put(mipi->dsip_clk);
426eclkpget:
427esettrate:
428 clk_put(mipi->dsit_clk);
429eclktget:
430 iounmap(mipi->base);
431emap:
432 release_mem_region(res->start, resource_size(res));
433ereqreg:
434 kfree(mipi);
435ealloc:
436efindslot:
437 mutex_unlock(&array_lock);
438
439 return ret;
440}
441
442static int __exit sh_mipi_remove(struct platform_device *pdev)
443{
444 struct sh_mipi_dsi_info *pdata = pdev->dev.platform_data;
445 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
446 struct sh_mipi *mipi = platform_get_drvdata(pdev);
447 int i, ret;
448
449 mutex_lock(&array_lock);
450
451 for (i = 0; i < ARRAY_SIZE(mipi_dsi) && mipi_dsi[i] != mipi; i++)
452 ;
453
454 if (i == ARRAY_SIZE(mipi_dsi)) {
455 ret = -EINVAL;
456 } else {
457 ret = 0;
458 mipi_dsi[i] = NULL;
459 }
460
461 mutex_unlock(&array_lock);
462
463 if (ret < 0)
464 return ret;
465
466 pdata->lcd_chan->board_cfg.display_on = NULL;
467 pdata->lcd_chan->board_cfg.display_off = NULL;
468 pdata->lcd_chan->board_cfg.board_data = NULL;
469
470 clk_disable(mipi->dsip_clk);
471 clk_disable(mipi->dsit_clk);
472 clk_put(mipi->dsit_clk);
473 clk_put(mipi->dsip_clk);
474 iounmap(mipi->base);
475 if (res)
476 release_mem_region(res->start, resource_size(res));
477 platform_set_drvdata(pdev, NULL);
478 kfree(mipi);
479
480 return 0;
481}
482
483static struct platform_driver sh_mipi_driver = {
484 .remove = __exit_p(sh_mipi_remove),
485 .shutdown = sh_mipi_shutdown,
486 .driver = {
487 .name = "sh-mipi-dsi",
488 },
489};
490
491static int __init sh_mipi_init(void)
492{
493 return platform_driver_probe(&sh_mipi_driver, sh_mipi_probe);
494}
495module_init(sh_mipi_init);
496
497static void __exit sh_mipi_exit(void)
498{
499 platform_driver_unregister(&sh_mipi_driver);
500}
501module_exit(sh_mipi_exit);
502
503MODULE_AUTHOR("Guennadi Liakhovetski <g.liakhovetski@gmx.de>");
504MODULE_DESCRIPTION("SuperH / ARM-shmobile MIPI DSI driver");
505MODULE_LICENSE("GPL v2");
diff --git a/drivers/video/sh_mobile_hdmi.c b/drivers/video/sh_mobile_hdmi.c
new file mode 100644
index 000000000000..2fde08cc66bf
--- /dev/null
+++ b/drivers/video/sh_mobile_hdmi.c
@@ -0,0 +1,1028 @@
1/*
2 * SH-Mobile High-Definition Multimedia Interface (HDMI) driver
3 * for SLISHDMI13T and SLIPHDMIT IP cores
4 *
5 * Copyright (C) 2010, Guennadi Liakhovetski <g.liakhovetski@gmx.de>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/clk.h>
13#include <linux/console.h>
14#include <linux/delay.h>
15#include <linux/err.h>
16#include <linux/init.h>
17#include <linux/interrupt.h>
18#include <linux/io.h>
19#include <linux/module.h>
20#include <linux/platform_device.h>
21#include <linux/pm_runtime.h>
22#include <linux/slab.h>
23#include <linux/types.h>
24#include <linux/workqueue.h>
25
26#include <video/sh_mobile_hdmi.h>
27#include <video/sh_mobile_lcdc.h>
28
29#define HDMI_SYSTEM_CTRL 0x00 /* System control */
30#define HDMI_L_R_DATA_SWAP_CTRL_RPKT 0x01 /* L/R data swap control,
31 bits 19..16 of 20-bit N for Audio Clock Regeneration packet */
32#define HDMI_20_BIT_N_FOR_AUDIO_RPKT_15_8 0x02 /* bits 15..8 of 20-bit N for Audio Clock Regeneration packet */
33#define HDMI_20_BIT_N_FOR_AUDIO_RPKT_7_0 0x03 /* bits 7..0 of 20-bit N for Audio Clock Regeneration packet */
34#define HDMI_SPDIF_AUDIO_SAMP_FREQ_CTS 0x04 /* SPDIF audio sampling frequency,
35 bits 19..16 of Internal CTS */
36#define HDMI_INTERNAL_CTS_15_8 0x05 /* bits 15..8 of Internal CTS */
37#define HDMI_INTERNAL_CTS_7_0 0x06 /* bits 7..0 of Internal CTS */
38#define HDMI_EXTERNAL_CTS_19_16 0x07 /* External CTS */
39#define HDMI_EXTERNAL_CTS_15_8 0x08 /* External CTS */
40#define HDMI_EXTERNAL_CTS_7_0 0x09 /* External CTS */
41#define HDMI_AUDIO_SETTING_1 0x0A /* Audio setting.1 */
42#define HDMI_AUDIO_SETTING_2 0x0B /* Audio setting.2 */
43#define HDMI_I2S_AUDIO_SET 0x0C /* I2S audio setting */
44#define HDMI_DSD_AUDIO_SET 0x0D /* DSD audio setting */
45#define HDMI_DEBUG_MONITOR_1 0x0E /* Debug monitor.1 */
46#define HDMI_DEBUG_MONITOR_2 0x0F /* Debug monitor.2 */
47#define HDMI_I2S_INPUT_PIN_SWAP 0x10 /* I2S input pin swap */
48#define HDMI_AUDIO_STATUS_BITS_SETTING_1 0x11 /* Audio status bits setting.1 */
49#define HDMI_AUDIO_STATUS_BITS_SETTING_2 0x12 /* Audio status bits setting.2 */
50#define HDMI_CATEGORY_CODE 0x13 /* Category code */
51#define HDMI_SOURCE_NUM_AUDIO_WORD_LEN 0x14 /* Source number/Audio word length */
52#define HDMI_AUDIO_VIDEO_SETTING_1 0x15 /* Audio/Video setting.1 */
53#define HDMI_VIDEO_SETTING_1 0x16 /* Video setting.1 */
54#define HDMI_DEEP_COLOR_MODES 0x17 /* Deep Color Modes */
55
56/* 12 16- and 10-bit Color space conversion parameters: 0x18..0x2f */
57#define HDMI_COLOR_SPACE_CONVERSION_PARAMETERS 0x18
58
59#define HDMI_EXTERNAL_VIDEO_PARAM_SETTINGS 0x30 /* External video parameter settings */
60#define HDMI_EXTERNAL_H_TOTAL_7_0 0x31 /* External horizontal total (LSB) */
61#define HDMI_EXTERNAL_H_TOTAL_11_8 0x32 /* External horizontal total (MSB) */
62#define HDMI_EXTERNAL_H_BLANK_7_0 0x33 /* External horizontal blank (LSB) */
63#define HDMI_EXTERNAL_H_BLANK_9_8 0x34 /* External horizontal blank (MSB) */
64#define HDMI_EXTERNAL_H_DELAY_7_0 0x35 /* External horizontal delay (LSB) */
65#define HDMI_EXTERNAL_H_DELAY_9_8 0x36 /* External horizontal delay (MSB) */
66#define HDMI_EXTERNAL_H_DURATION_7_0 0x37 /* External horizontal duration (LSB) */
67#define HDMI_EXTERNAL_H_DURATION_9_8 0x38 /* External horizontal duration (MSB) */
68#define HDMI_EXTERNAL_V_TOTAL_7_0 0x39 /* External vertical total (LSB) */
69#define HDMI_EXTERNAL_V_TOTAL_9_8 0x3A /* External vertical total (MSB) */
70#define HDMI_AUDIO_VIDEO_SETTING_2 0x3B /* Audio/Video setting.2 */
71#define HDMI_EXTERNAL_V_BLANK 0x3D /* External vertical blank */
72#define HDMI_EXTERNAL_V_DELAY 0x3E /* External vertical delay */
73#define HDMI_EXTERNAL_V_DURATION 0x3F /* External vertical duration */
74#define HDMI_CTRL_PKT_MANUAL_SEND_CONTROL 0x40 /* Control packet manual send control */
75#define HDMI_CTRL_PKT_AUTO_SEND 0x41 /* Control packet auto send with VSYNC control */
76#define HDMI_AUTO_CHECKSUM_OPTION 0x42 /* Auto checksum option */
77#define HDMI_VIDEO_SETTING_2 0x45 /* Video setting.2 */
78#define HDMI_OUTPUT_OPTION 0x46 /* Output option */
79#define HDMI_SLIPHDMIT_PARAM_OPTION 0x51 /* SLIPHDMIT parameter option */
80#define HDMI_HSYNC_PMENT_AT_EMB_7_0 0x52 /* HSYNC placement at embedded sync (LSB) */
81#define HDMI_HSYNC_PMENT_AT_EMB_15_8 0x53 /* HSYNC placement at embedded sync (MSB) */
82#define HDMI_VSYNC_PMENT_AT_EMB_7_0 0x54 /* VSYNC placement at embedded sync (LSB) */
83#define HDMI_VSYNC_PMENT_AT_EMB_14_8 0x55 /* VSYNC placement at embedded sync (MSB) */
84#define HDMI_SLIPHDMIT_PARAM_SETTINGS_1 0x56 /* SLIPHDMIT parameter settings.1 */
85#define HDMI_SLIPHDMIT_PARAM_SETTINGS_2 0x57 /* SLIPHDMIT parameter settings.2 */
86#define HDMI_SLIPHDMIT_PARAM_SETTINGS_3 0x58 /* SLIPHDMIT parameter settings.3 */
87#define HDMI_SLIPHDMIT_PARAM_SETTINGS_5 0x59 /* SLIPHDMIT parameter settings.5 */
88#define HDMI_SLIPHDMIT_PARAM_SETTINGS_6 0x5A /* SLIPHDMIT parameter settings.6 */
89#define HDMI_SLIPHDMIT_PARAM_SETTINGS_7 0x5B /* SLIPHDMIT parameter settings.7 */
90#define HDMI_SLIPHDMIT_PARAM_SETTINGS_8 0x5C /* SLIPHDMIT parameter settings.8 */
91#define HDMI_SLIPHDMIT_PARAM_SETTINGS_9 0x5D /* SLIPHDMIT parameter settings.9 */
92#define HDMI_SLIPHDMIT_PARAM_SETTINGS_10 0x5E /* SLIPHDMIT parameter settings.10 */
93#define HDMI_CTRL_PKT_BUF_INDEX 0x5F /* Control packet buffer index */
94#define HDMI_CTRL_PKT_BUF_ACCESS_HB0 0x60 /* Control packet data buffer access window - HB0 */
95#define HDMI_CTRL_PKT_BUF_ACCESS_HB1 0x61 /* Control packet data buffer access window - HB1 */
96#define HDMI_CTRL_PKT_BUF_ACCESS_HB2 0x62 /* Control packet data buffer access window - HB2 */
97#define HDMI_CTRL_PKT_BUF_ACCESS_PB0 0x63 /* Control packet data buffer access window - PB0 */
98#define HDMI_CTRL_PKT_BUF_ACCESS_PB1 0x64 /* Control packet data buffer access window - PB1 */
99#define HDMI_CTRL_PKT_BUF_ACCESS_PB2 0x65 /* Control packet data buffer access window - PB2 */
100#define HDMI_CTRL_PKT_BUF_ACCESS_PB3 0x66 /* Control packet data buffer access window - PB3 */
101#define HDMI_CTRL_PKT_BUF_ACCESS_PB4 0x67 /* Control packet data buffer access window - PB4 */
102#define HDMI_CTRL_PKT_BUF_ACCESS_PB5 0x68 /* Control packet data buffer access window - PB5 */
103#define HDMI_CTRL_PKT_BUF_ACCESS_PB6 0x69 /* Control packet data buffer access window - PB6 */
104#define HDMI_CTRL_PKT_BUF_ACCESS_PB7 0x6A /* Control packet data buffer access window - PB7 */
105#define HDMI_CTRL_PKT_BUF_ACCESS_PB8 0x6B /* Control packet data buffer access window - PB8 */
106#define HDMI_CTRL_PKT_BUF_ACCESS_PB9 0x6C /* Control packet data buffer access window - PB9 */
107#define HDMI_CTRL_PKT_BUF_ACCESS_PB10 0x6D /* Control packet data buffer access window - PB10 */
108#define HDMI_CTRL_PKT_BUF_ACCESS_PB11 0x6E /* Control packet data buffer access window - PB11 */
109#define HDMI_CTRL_PKT_BUF_ACCESS_PB12 0x6F /* Control packet data buffer access window - PB12 */
110#define HDMI_CTRL_PKT_BUF_ACCESS_PB13 0x70 /* Control packet data buffer access window - PB13 */
111#define HDMI_CTRL_PKT_BUF_ACCESS_PB14 0x71 /* Control packet data buffer access window - PB14 */
112#define HDMI_CTRL_PKT_BUF_ACCESS_PB15 0x72 /* Control packet data buffer access window - PB15 */
113#define HDMI_CTRL_PKT_BUF_ACCESS_PB16 0x73 /* Control packet data buffer access window - PB16 */
114#define HDMI_CTRL_PKT_BUF_ACCESS_PB17 0x74 /* Control packet data buffer access window - PB17 */
115#define HDMI_CTRL_PKT_BUF_ACCESS_PB18 0x75 /* Control packet data buffer access window - PB18 */
116#define HDMI_CTRL_PKT_BUF_ACCESS_PB19 0x76 /* Control packet data buffer access window - PB19 */
117#define HDMI_CTRL_PKT_BUF_ACCESS_PB20 0x77 /* Control packet data buffer access window - PB20 */
118#define HDMI_CTRL_PKT_BUF_ACCESS_PB21 0x78 /* Control packet data buffer access window - PB21 */
119#define HDMI_CTRL_PKT_BUF_ACCESS_PB22 0x79 /* Control packet data buffer access window - PB22 */
120#define HDMI_CTRL_PKT_BUF_ACCESS_PB23 0x7A /* Control packet data buffer access window - PB23 */
121#define HDMI_CTRL_PKT_BUF_ACCESS_PB24 0x7B /* Control packet data buffer access window - PB24 */
122#define HDMI_CTRL_PKT_BUF_ACCESS_PB25 0x7C /* Control packet data buffer access window - PB25 */
123#define HDMI_CTRL_PKT_BUF_ACCESS_PB26 0x7D /* Control packet data buffer access window - PB26 */
124#define HDMI_CTRL_PKT_BUF_ACCESS_PB27 0x7E /* Control packet data buffer access window - PB27 */
125#define HDMI_EDID_KSV_FIFO_ACCESS_WINDOW 0x80 /* EDID/KSV FIFO access window */
126#define HDMI_DDC_BUS_ACCESS_FREQ_CTRL_7_0 0x81 /* DDC bus access frequency control (LSB) */
127#define HDMI_DDC_BUS_ACCESS_FREQ_CTRL_15_8 0x82 /* DDC bus access frequency control (MSB) */
128#define HDMI_INTERRUPT_MASK_1 0x92 /* Interrupt mask.1 */
129#define HDMI_INTERRUPT_MASK_2 0x93 /* Interrupt mask.2 */
130#define HDMI_INTERRUPT_STATUS_1 0x94 /* Interrupt status.1 */
131#define HDMI_INTERRUPT_STATUS_2 0x95 /* Interrupt status.2 */
132#define HDMI_INTERRUPT_MASK_3 0x96 /* Interrupt mask.3 */
133#define HDMI_INTERRUPT_MASK_4 0x97 /* Interrupt mask.4 */
134#define HDMI_INTERRUPT_STATUS_3 0x98 /* Interrupt status.3 */
135#define HDMI_INTERRUPT_STATUS_4 0x99 /* Interrupt status.4 */
136#define HDMI_SOFTWARE_HDCP_CONTROL_1 0x9A /* Software HDCP control.1 */
137#define HDMI_FRAME_COUNTER 0x9C /* Frame counter */
138#define HDMI_FRAME_COUNTER_FOR_RI_CHECK 0x9D /* Frame counter for Ri check */
139#define HDMI_HDCP_CONTROL 0xAF /* HDCP control */
140#define HDMI_RI_FRAME_COUNT_REGISTER 0xB2 /* Ri frame count register */
141#define HDMI_DDC_BUS_CONTROL 0xB7 /* DDC bus control */
142#define HDMI_HDCP_STATUS 0xB8 /* HDCP status */
143#define HDMI_SHA0 0xB9 /* sha0 */
144#define HDMI_SHA1 0xBA /* sha1 */
145#define HDMI_SHA2 0xBB /* sha2 */
146#define HDMI_SHA3 0xBC /* sha3 */
147#define HDMI_SHA4 0xBD /* sha4 */
148#define HDMI_BCAPS_READ 0xBE /* BCAPS read / debug */
149#define HDMI_AKSV_BKSV_7_0_MONITOR 0xBF /* AKSV/BKSV[7:0] monitor */
150#define HDMI_AKSV_BKSV_15_8_MONITOR 0xC0 /* AKSV/BKSV[15:8] monitor */
151#define HDMI_AKSV_BKSV_23_16_MONITOR 0xC1 /* AKSV/BKSV[23:16] monitor */
152#define HDMI_AKSV_BKSV_31_24_MONITOR 0xC2 /* AKSV/BKSV[31:24] monitor */
153#define HDMI_AKSV_BKSV_39_32_MONITOR 0xC3 /* AKSV/BKSV[39:32] monitor */
154#define HDMI_EDID_SEGMENT_POINTER 0xC4 /* EDID segment pointer */
155#define HDMI_EDID_WORD_ADDRESS 0xC5 /* EDID word address */
156#define HDMI_EDID_DATA_FIFO_ADDRESS 0xC6 /* EDID data FIFO address */
157#define HDMI_NUM_OF_HDMI_DEVICES 0xC7 /* Number of HDMI devices */
158#define HDMI_HDCP_ERROR_CODE 0xC8 /* HDCP error code */
159#define HDMI_100MS_TIMER_SET 0xC9 /* 100ms timer setting */
160#define HDMI_5SEC_TIMER_SET 0xCA /* 5sec timer setting */
161#define HDMI_RI_READ_COUNT 0xCB /* Ri read count */
162#define HDMI_AN_SEED 0xCC /* An seed */
163#define HDMI_MAX_NUM_OF_RCIVRS_ALLOWED 0xCD /* Maximum number of receivers allowed */
164#define HDMI_HDCP_MEMORY_ACCESS_CONTROL_1 0xCE /* HDCP memory access control.1 */
165#define HDMI_HDCP_MEMORY_ACCESS_CONTROL_2 0xCF /* HDCP memory access control.2 */
166#define HDMI_HDCP_CONTROL_2 0xD0 /* HDCP Control 2 */
167#define HDMI_HDCP_KEY_MEMORY_CONTROL 0xD2 /* HDCP Key Memory Control */
168#define HDMI_COLOR_SPACE_CONV_CONFIG_1 0xD3 /* Color space conversion configuration.1 */
169#define HDMI_VIDEO_SETTING_3 0xD4 /* Video setting.3 */
170#define HDMI_RI_7_0 0xD5 /* Ri[7:0] */
171#define HDMI_RI_15_8 0xD6 /* Ri[15:8] */
172#define HDMI_PJ 0xD7 /* Pj */
173#define HDMI_SHA_RD 0xD8 /* sha_rd */
174#define HDMI_RI_7_0_SAVED 0xD9 /* Ri[7:0] saved */
175#define HDMI_RI_15_8_SAVED 0xDA /* Ri[15:8] saved */
176#define HDMI_PJ_SAVED 0xDB /* Pj saved */
177#define HDMI_NUM_OF_DEVICES 0xDC /* Number of devices */
178#define HDMI_HOT_PLUG_MSENS_STATUS 0xDF /* Hot plug/MSENS status */
179#define HDMI_BCAPS_WRITE 0xE0 /* bcaps */
180#define HDMI_BSTAT_7_0 0xE1 /* bstat[7:0] */
181#define HDMI_BSTAT_15_8 0xE2 /* bstat[15:8] */
182#define HDMI_BKSV_7_0 0xE3 /* bksv[7:0] */
183#define HDMI_BKSV_15_8 0xE4 /* bksv[15:8] */
184#define HDMI_BKSV_23_16 0xE5 /* bksv[23:16] */
185#define HDMI_BKSV_31_24 0xE6 /* bksv[31:24] */
186#define HDMI_BKSV_39_32 0xE7 /* bksv[39:32] */
187#define HDMI_AN_7_0 0xE8 /* An[7:0] */
188#define HDMI_AN_15_8 0xE9 /* An [15:8] */
189#define HDMI_AN_23_16 0xEA /* An [23:16] */
190#define HDMI_AN_31_24 0xEB /* An [31:24] */
191#define HDMI_AN_39_32 0xEC /* An [39:32] */
192#define HDMI_AN_47_40 0xED /* An [47:40] */
193#define HDMI_AN_55_48 0xEE /* An [55:48] */
194#define HDMI_AN_63_56 0xEF /* An [63:56] */
195#define HDMI_PRODUCT_ID 0xF0 /* Product ID */
196#define HDMI_REVISION_ID 0xF1 /* Revision ID */
197#define HDMI_TEST_MODE 0xFE /* Test mode */
198
199enum hotplug_state {
200 HDMI_HOTPLUG_DISCONNECTED,
201 HDMI_HOTPLUG_CONNECTED,
202 HDMI_HOTPLUG_EDID_DONE,
203};
204
205struct sh_hdmi {
206 void __iomem *base;
207 enum hotplug_state hp_state;
208 struct clk *hdmi_clk;
209 struct device *dev;
210 struct fb_info *info;
211 struct delayed_work edid_work;
212 struct fb_var_screeninfo var;
213};
214
215static void hdmi_write(struct sh_hdmi *hdmi, u8 data, u8 reg)
216{
217 iowrite8(data, hdmi->base + reg);
218}
219
220static u8 hdmi_read(struct sh_hdmi *hdmi, u8 reg)
221{
222 return ioread8(hdmi->base + reg);
223}
224
225/* External video parameter settings */
226static void hdmi_external_video_param(struct sh_hdmi *hdmi)
227{
228 struct fb_var_screeninfo *var = &hdmi->var;
229 u16 htotal, hblank, hdelay, vtotal, vblank, vdelay, voffset;
230 u8 sync = 0;
231
232 htotal = var->xres + var->right_margin + var->left_margin + var->hsync_len;
233
234 hdelay = var->hsync_len + var->left_margin;
235 hblank = var->right_margin + hdelay;
236
237 /*
238 * Vertical timing looks a bit different in Figure 18,
239 * but let's try the same first by setting offset = 0
240 */
241 vtotal = var->yres + var->upper_margin + var->lower_margin + var->vsync_len;
242
243 vdelay = var->vsync_len + var->upper_margin;
244 vblank = var->lower_margin + vdelay;
245 voffset = min(var->upper_margin / 2, 6U);
246
247 /*
248 * [3]: VSYNC polarity: Positive
249 * [2]: HSYNC polarity: Positive
250 * [1]: Interlace/Progressive: Progressive
251 * [0]: External video settings enable: used.
252 */
253 if (var->sync & FB_SYNC_HOR_HIGH_ACT)
254 sync |= 4;
255 if (var->sync & FB_SYNC_VERT_HIGH_ACT)
256 sync |= 8;
257
258 pr_debug("H: %u, %u, %u, %u; V: %u, %u, %u, %u; sync 0x%x\n",
259 htotal, hblank, hdelay, var->hsync_len,
260 vtotal, vblank, vdelay, var->vsync_len, sync);
261
262 hdmi_write(hdmi, sync | (voffset << 4), HDMI_EXTERNAL_VIDEO_PARAM_SETTINGS);
263
264 hdmi_write(hdmi, htotal, HDMI_EXTERNAL_H_TOTAL_7_0);
265 hdmi_write(hdmi, htotal >> 8, HDMI_EXTERNAL_H_TOTAL_11_8);
266
267 hdmi_write(hdmi, hblank, HDMI_EXTERNAL_H_BLANK_7_0);
268 hdmi_write(hdmi, hblank >> 8, HDMI_EXTERNAL_H_BLANK_9_8);
269
270 hdmi_write(hdmi, hdelay, HDMI_EXTERNAL_H_DELAY_7_0);
271 hdmi_write(hdmi, hdelay >> 8, HDMI_EXTERNAL_H_DELAY_9_8);
272
273 hdmi_write(hdmi, var->hsync_len, HDMI_EXTERNAL_H_DURATION_7_0);
274 hdmi_write(hdmi, var->hsync_len >> 8, HDMI_EXTERNAL_H_DURATION_9_8);
275
276 hdmi_write(hdmi, vtotal, HDMI_EXTERNAL_V_TOTAL_7_0);
277 hdmi_write(hdmi, vtotal >> 8, HDMI_EXTERNAL_V_TOTAL_9_8);
278
279 hdmi_write(hdmi, vblank, HDMI_EXTERNAL_V_BLANK);
280
281 hdmi_write(hdmi, vdelay, HDMI_EXTERNAL_V_DELAY);
282
283 hdmi_write(hdmi, var->vsync_len, HDMI_EXTERNAL_V_DURATION);
284
285 /* Set bit 0 of HDMI_EXTERNAL_VIDEO_PARAM_SETTINGS here for manual mode */
286}
287
288/**
289 * sh_hdmi_video_config()
290 */
291static void sh_hdmi_video_config(struct sh_hdmi *hdmi)
292{
293 /*
294 * [7:4]: Audio sampling frequency: 48kHz
295 * [3:1]: Input video format: RGB and YCbCr 4:4:4 (Y on Green)
296 * [0]: Internal/External DE select: internal
297 */
298 hdmi_write(hdmi, 0x20, HDMI_AUDIO_VIDEO_SETTING_1);
299
300 /*
301 * [7:6]: Video output format: RGB 4:4:4
302 * [5:4]: Input video data width: 8 bit
303 * [3:1]: EAV/SAV location: channel 1
304 * [0]: Video input color space: RGB
305 */
306 hdmi_write(hdmi, 0x34, HDMI_VIDEO_SETTING_1);
307
308 /*
309 * [7:6]: Together with bit [6] of HDMI_AUDIO_VIDEO_SETTING_2, which is
310 * left at 0 by default, this configures 24bpp and sets the Color Depth
311 * (CD) field in the General Control Packet
312 */
313 hdmi_write(hdmi, 0x20, HDMI_DEEP_COLOR_MODES);
314}
315
316/**
317 * sh_hdmi_audio_config()
318 */
319static void sh_hdmi_audio_config(struct sh_hdmi *hdmi)
320{
321 /*
322 * [7:4] L/R data swap control
323 * [3:0] appropriate N[19:16]
324 */
325 hdmi_write(hdmi, 0x00, HDMI_L_R_DATA_SWAP_CTRL_RPKT);
326 /* appropriate N[15:8] */
327 hdmi_write(hdmi, 0x18, HDMI_20_BIT_N_FOR_AUDIO_RPKT_15_8);
328 /* appropriate N[7:0] */
329 hdmi_write(hdmi, 0x00, HDMI_20_BIT_N_FOR_AUDIO_RPKT_7_0);
330
331 /* [7:4] 48 kHz SPDIF not used */
332 hdmi_write(hdmi, 0x20, HDMI_SPDIF_AUDIO_SAMP_FREQ_CTS);
333
334 /*
335 * [6:5] set required down sampling rate if required
336 * [4:3] set required audio source
337 */
338 hdmi_write(hdmi, 0x00, HDMI_AUDIO_SETTING_1);
339
340 /* [3:0] set sending channel number for channel status */
341 hdmi_write(hdmi, 0x40, HDMI_AUDIO_SETTING_2);
342
343 /*
344 * [5:2] set valid I2S source input pin
345 * [1:0] set input I2S source mode
346 */
347 hdmi_write(hdmi, 0x04, HDMI_I2S_AUDIO_SET);
348
349 /* [7:4] set valid DSD source input pin */
350 hdmi_write(hdmi, 0x00, HDMI_DSD_AUDIO_SET);
351
352 /* [7:0] set appropriate I2S input pin swap settings if required */
353 hdmi_write(hdmi, 0x00, HDMI_I2S_INPUT_PIN_SWAP);
354
355 /*
356 * [7] set validity bit for channel status
357 * [3:0] set original sample frequency for channel status
358 */
359 hdmi_write(hdmi, 0x00, HDMI_AUDIO_STATUS_BITS_SETTING_1);
360
361 /*
362 * [7] set value for channel status
363 * [6] set value for channel status
364 * [5] set copyright bit for channel status
365 * [4:2] set additional information for channel status
366 * [1:0] set clock accuracy for channel status
367 */
368 hdmi_write(hdmi, 0x00, HDMI_AUDIO_STATUS_BITS_SETTING_2);
369
370 /* [7:0] set category code for channel status */
371 hdmi_write(hdmi, 0x00, HDMI_CATEGORY_CODE);
372
373 /*
374 * [7:4] set source number for channel status
375 * [3:0] set word length for channel status
376 */
377 hdmi_write(hdmi, 0x00, HDMI_SOURCE_NUM_AUDIO_WORD_LEN);
378
379 /* [7:4] set sample frequency for channel status */
380 hdmi_write(hdmi, 0x20, HDMI_AUDIO_VIDEO_SETTING_1);
381}
382
383/**
384 * sh_hdmi_phy_config()
385 */
386static void sh_hdmi_phy_config(struct sh_hdmi *hdmi)
387{
388 /* 720p, 8bit, 74.25MHz. Might need to be adjusted for other formats */
389 hdmi_write(hdmi, 0x19, HDMI_SLIPHDMIT_PARAM_SETTINGS_1);
390 hdmi_write(hdmi, 0x00, HDMI_SLIPHDMIT_PARAM_SETTINGS_2);
391 hdmi_write(hdmi, 0x00, HDMI_SLIPHDMIT_PARAM_SETTINGS_3);
392 /* PLLA_CONFIG[7:0]: VCO gain, VCO offset, LPF resistance[0] */
393 hdmi_write(hdmi, 0x44, HDMI_SLIPHDMIT_PARAM_SETTINGS_5);
394 hdmi_write(hdmi, 0x32, HDMI_SLIPHDMIT_PARAM_SETTINGS_6);
395 hdmi_write(hdmi, 0x4A, HDMI_SLIPHDMIT_PARAM_SETTINGS_7);
396 hdmi_write(hdmi, 0x0E, HDMI_SLIPHDMIT_PARAM_SETTINGS_8);
397 hdmi_write(hdmi, 0x25, HDMI_SLIPHDMIT_PARAM_SETTINGS_9);
398 hdmi_write(hdmi, 0x04, HDMI_SLIPHDMIT_PARAM_SETTINGS_10);
399}
400
401/**
402 * sh_hdmi_avi_infoframe_setup() - Auxiliary Video Information InfoFrame CONTROL PACKET
403 */
404static void sh_hdmi_avi_infoframe_setup(struct sh_hdmi *hdmi)
405{
406 /* AVI InfoFrame */
407 hdmi_write(hdmi, 0x06, HDMI_CTRL_PKT_BUF_INDEX);
408
409 /* Packet Type = 0x82 */
410 hdmi_write(hdmi, 0x82, HDMI_CTRL_PKT_BUF_ACCESS_HB0);
411
412 /* Version = 0x02 */
413 hdmi_write(hdmi, 0x02, HDMI_CTRL_PKT_BUF_ACCESS_HB1);
414
415 /* Length = 13 (0x0D) */
416 hdmi_write(hdmi, 0x0D, HDMI_CTRL_PKT_BUF_ACCESS_HB2);
417
418 /* N. A. Checksum */
419 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB0);
420
421 /*
422 * Y = RGB
423 * A0 = No Data
424 * B = Bar Data not valid
425 * S = No Data
426 */
427 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB1);
428
429 /*
430 * C = No Data
431 * M = 16:9 Picture Aspect Ratio
432 * R = Same as picture aspect ratio
433 */
434 hdmi_write(hdmi, 0x28, HDMI_CTRL_PKT_BUF_ACCESS_PB2);
435
436 /*
437 * ITC = No Data
438 * EC = xvYCC601
439 * Q = Default (depends on video format)
440 * SC = No Known non_uniform Scaling
441 */
442 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB3);
443
444 /*
445 * VIC = 1280 x 720p: ignored if external config is used
446 * Send 2 for 720 x 480p, 16 for 1080p
447 */
448 hdmi_write(hdmi, 4, HDMI_CTRL_PKT_BUF_ACCESS_PB4);
449
450 /* PR = No Repetition */
451 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB5);
452
453 /* Line Number of End of Top Bar (lower 8 bits) */
454 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB6);
455
456 /* Line Number of End of Top Bar (upper 8 bits) */
457 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB7);
458
459 /* Line Number of Start of Bottom Bar (lower 8 bits) */
460 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB8);
461
462 /* Line Number of Start of Bottom Bar (upper 8 bits) */
463 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB9);
464
465 /* Pixel Number of End of Left Bar (lower 8 bits) */
466 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB10);
467
468 /* Pixel Number of End of Left Bar (upper 8 bits) */
469 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB11);
470
471 /* Pixel Number of Start of Right Bar (lower 8 bits) */
472 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB12);
473
474 /* Pixel Number of Start of Right Bar (upper 8 bits) */
475 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB13);
476}
477
478/**
479 * sh_hdmi_audio_infoframe_setup() - Audio InfoFrame of CONTROL PACKET
480 */
481static void sh_hdmi_audio_infoframe_setup(struct sh_hdmi *hdmi)
482{
483 /* Audio InfoFrame */
484 hdmi_write(hdmi, 0x08, HDMI_CTRL_PKT_BUF_INDEX);
485
486 /* Packet Type = 0x84 */
487 hdmi_write(hdmi, 0x84, HDMI_CTRL_PKT_BUF_ACCESS_HB0);
488
489 /* Version Number = 0x01 */
490 hdmi_write(hdmi, 0x01, HDMI_CTRL_PKT_BUF_ACCESS_HB1);
491
492 /* 0 Length = 10 (0x0A) */
493 hdmi_write(hdmi, 0x0A, HDMI_CTRL_PKT_BUF_ACCESS_HB2);
494
495 /* n. a. Checksum */
496 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB0);
497
498 /* Audio Channel Count = Refer to Stream Header */
499 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB1);
500
501 /* Refer to Stream Header */
502 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB2);
503
504 /* Format depends on coding type (i.e. CT0...CT3) */
505 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB3);
506
507 /* Speaker Channel Allocation = Front Right + Front Left */
508 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB4);
509
510 /* Level Shift Value = 0 dB, Down - mix is permitted or no information */
511 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB5);
512
513 /* Reserved (0) */
514 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB6);
515 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB7);
516 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB8);
517 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB9);
518 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB10);
519}
520
521/**
522 * sh_hdmi_gamut_metadata_setup() - Gamut Metadata Packet of CONTROL PACKET
523 */
524static void sh_hdmi_gamut_metadata_setup(struct sh_hdmi *hdmi)
525{
526 int i;
527
528 /* Gamut Metadata Packet */
529 hdmi_write(hdmi, 0x04, HDMI_CTRL_PKT_BUF_INDEX);
530
531 /* Packet Type = 0x0A */
532 hdmi_write(hdmi, 0x0A, HDMI_CTRL_PKT_BUF_ACCESS_HB0);
533 /* Gamut Packet is not used, so default value */
534 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_HB1);
535 /* Gamut Packet is not used, so default value */
536 hdmi_write(hdmi, 0x10, HDMI_CTRL_PKT_BUF_ACCESS_HB2);
537
538 /* GBD bytes 0 through 27 */
539 for (i = 0; i <= 27; i++)
540 /* HDMI_CTRL_PKT_BUF_ACCESS_PB0_63H - PB27_7EH */
541 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB0 + i);
542}
543
544/**
545 * sh_hdmi_acp_setup() - Audio Content Protection Packet (ACP)
546 */
547static void sh_hdmi_acp_setup(struct sh_hdmi *hdmi)
548{
549 int i;
550
551 /* Audio Content Protection Packet (ACP) */
552 hdmi_write(hdmi, 0x01, HDMI_CTRL_PKT_BUF_INDEX);
553
554 /* Packet Type = 0x04 */
555 hdmi_write(hdmi, 0x04, HDMI_CTRL_PKT_BUF_ACCESS_HB0);
556 /* ACP_Type */
557 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_HB1);
558 /* Reserved (0) */
559 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_HB2);
560
561 /* GBD bytes 0 through 27 */
562 for (i = 0; i <= 27; i++)
563 /* HDMI_CTRL_PKT_BUF_ACCESS_PB0 - PB27 */
564 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB0 + i);
565}
566
567/**
568 * sh_hdmi_isrc1_setup() - ISRC1 Packet
569 */
570static void sh_hdmi_isrc1_setup(struct sh_hdmi *hdmi)
571{
572 int i;
573
574 /* ISRC1 Packet */
575 hdmi_write(hdmi, 0x02, HDMI_CTRL_PKT_BUF_INDEX);
576
577 /* Packet Type = 0x05 */
578 hdmi_write(hdmi, 0x05, HDMI_CTRL_PKT_BUF_ACCESS_HB0);
579 /* ISRC_Cont, ISRC_Valid, Reserved (0), ISRC_Status */
580 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_HB1);
581 /* Reserved (0) */
582 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_HB2);
583
584 /* PB0 UPC_EAN_ISRC_0-15 */
585 /* Bytes PB16-PB27 shall be set to a value of 0. */
586 for (i = 0; i <= 27; i++)
587 /* HDMI_CTRL_PKT_BUF_ACCESS_PB0 - PB27 */
588 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB0 + i);
589}
590
591/**
592 * sh_hdmi_isrc2_setup() - ISRC2 Packet
593 */
594static void sh_hdmi_isrc2_setup(struct sh_hdmi *hdmi)
595{
596 int i;
597
598 /* ISRC2 Packet */
599 hdmi_write(hdmi, 0x03, HDMI_CTRL_PKT_BUF_INDEX);
600
601 /* HB0 Packet Type = 0x06 */
602 hdmi_write(hdmi, 0x06, HDMI_CTRL_PKT_BUF_ACCESS_HB0);
603 /* Reserved (0) */
604 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_HB1);
605 /* Reserved (0) */
606 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_HB2);
607
608 /* PB0 UPC_EAN_ISRC_16-31 */
609 /* Bytes PB16-PB27 shall be set to a value of 0. */
610 for (i = 0; i <= 27; i++)
611 /* HDMI_CTRL_PKT_BUF_ACCESS_PB0 - PB27 */
612 hdmi_write(hdmi, 0x00, HDMI_CTRL_PKT_BUF_ACCESS_PB0 + i);
613}
614
615/**
616 * sh_hdmi_configure() - Initialise HDMI for output
617 */
618static void sh_hdmi_configure(struct sh_hdmi *hdmi)
619{
620 /* Configure video format */
621 sh_hdmi_video_config(hdmi);
622
623 /* Configure audio format */
624 sh_hdmi_audio_config(hdmi);
625
626 /* Configure PHY */
627 sh_hdmi_phy_config(hdmi);
628
629 /* Auxiliary Video Information (AVI) InfoFrame */
630 sh_hdmi_avi_infoframe_setup(hdmi);
631
632 /* Audio InfoFrame */
633 sh_hdmi_audio_infoframe_setup(hdmi);
634
635 /* Gamut Metadata packet */
636 sh_hdmi_gamut_metadata_setup(hdmi);
637
638 /* Audio Content Protection (ACP) Packet */
639 sh_hdmi_acp_setup(hdmi);
640
641 /* ISRC1 Packet */
642 sh_hdmi_isrc1_setup(hdmi);
643
644 /* ISRC2 Packet */
645 sh_hdmi_isrc2_setup(hdmi);
646
647 /*
648 * Control packet auto send with VSYNC control: auto send
649 * General control, Gamut metadata, ISRC, and ACP packets
650 */
651 hdmi_write(hdmi, 0x8E, HDMI_CTRL_PKT_AUTO_SEND);
652
653 /* FIXME */
654 msleep(10);
655
656 /* PS mode b->d, reset PLLA and PLLB */
657 hdmi_write(hdmi, 0x4C, HDMI_SYSTEM_CTRL);
658
659 udelay(10);
660
661 hdmi_write(hdmi, 0x40, HDMI_SYSTEM_CTRL);
662}
663
664static void sh_hdmi_read_edid(struct sh_hdmi *hdmi)
665{
666 struct fb_var_screeninfo *var = &hdmi->var;
667 struct sh_mobile_hdmi_info *pdata = hdmi->dev->platform_data;
668 struct fb_videomode *lcd_cfg = &pdata->lcd_chan->lcd_cfg;
669 unsigned long height = var->height, width = var->width;
670 int i;
671 u8 edid[128];
672
673 /* Read EDID */
674 pr_debug("Read back EDID code:");
675 for (i = 0; i < 128; i++) {
676 edid[i] = hdmi_read(hdmi, HDMI_EDID_KSV_FIFO_ACCESS_WINDOW);
677#ifdef DEBUG
678 if ((i % 16) == 0) {
679 printk(KERN_CONT "\n");
680 printk(KERN_DEBUG "%02X | %02X", i, edid[i]);
681 } else {
682 printk(KERN_CONT " %02X", edid[i]);
683 }
684#endif
685 }
686#ifdef DEBUG
687 printk(KERN_CONT "\n");
688#endif
689 fb_parse_edid(edid, var);
690 pr_debug("%u-%u-%u-%u x %u-%u-%u-%u @ %lu kHz monitor detected\n",
691 var->left_margin, var->xres, var->right_margin, var->hsync_len,
692 var->upper_margin, var->yres, var->lower_margin, var->vsync_len,
693 PICOS2KHZ(var->pixclock));
694
695 /* FIXME: Use user-provided configuration instead of EDID */
696 var->width = width;
697 var->xres = lcd_cfg->xres;
698 var->xres_virtual = lcd_cfg->xres;
699 var->left_margin = lcd_cfg->left_margin;
700 var->right_margin = lcd_cfg->right_margin;
701 var->hsync_len = lcd_cfg->hsync_len;
702 var->height = height;
703 var->yres = lcd_cfg->yres;
704 var->yres_virtual = lcd_cfg->yres * 2;
705 var->upper_margin = lcd_cfg->upper_margin;
706 var->lower_margin = lcd_cfg->lower_margin;
707 var->vsync_len = lcd_cfg->vsync_len;
708 var->sync = lcd_cfg->sync;
709 var->pixclock = lcd_cfg->pixclock;
710
711 hdmi_external_video_param(hdmi);
712}
713
714static irqreturn_t sh_hdmi_hotplug(int irq, void *dev_id)
715{
716 struct sh_hdmi *hdmi = dev_id;
717 u8 status1, status2, mask1, mask2;
718
719 /* mode_b and PLLA and PLLB reset */
720 hdmi_write(hdmi, 0x2C, HDMI_SYSTEM_CTRL);
721
722 /* How long shall reset be held? */
723 udelay(10);
724
725 /* mode_b and PLLA and PLLB reset release */
726 hdmi_write(hdmi, 0x20, HDMI_SYSTEM_CTRL);
727
728 status1 = hdmi_read(hdmi, HDMI_INTERRUPT_STATUS_1);
729 status2 = hdmi_read(hdmi, HDMI_INTERRUPT_STATUS_2);
730
731 mask1 = hdmi_read(hdmi, HDMI_INTERRUPT_MASK_1);
732 mask2 = hdmi_read(hdmi, HDMI_INTERRUPT_MASK_2);
733
734 /* Correct would be to ack only set bits, but the datasheet requires 0xff */
735 hdmi_write(hdmi, 0xFF, HDMI_INTERRUPT_STATUS_1);
736 hdmi_write(hdmi, 0xFF, HDMI_INTERRUPT_STATUS_2);
737
738 if (printk_ratelimit())
739 pr_debug("IRQ #%d: Status #1: 0x%x & 0x%x, #2: 0x%x & 0x%x\n",
740 irq, status1, mask1, status2, mask2);
741
742 if (!((status1 & mask1) | (status2 & mask2))) {
743 return IRQ_NONE;
744 } else if (status1 & 0xc0) {
745 u8 msens;
746
747 /* Datasheet specifies 10ms... */
748 udelay(500);
749
750 msens = hdmi_read(hdmi, HDMI_HOT_PLUG_MSENS_STATUS);
751 pr_debug("MSENS 0x%x\n", msens);
752 /* Check, if hot plug & MSENS pin status are both high */
753 if ((msens & 0xC0) == 0xC0) {
754 /* Display plug in */
755 hdmi->hp_state = HDMI_HOTPLUG_CONNECTED;
756
757 /* Set EDID word address */
758 hdmi_write(hdmi, 0x00, HDMI_EDID_WORD_ADDRESS);
759 /* Set EDID segment pointer */
760 hdmi_write(hdmi, 0x00, HDMI_EDID_SEGMENT_POINTER);
761 /* Enable EDID interrupt */
762 hdmi_write(hdmi, 0xC6, HDMI_INTERRUPT_MASK_1);
763 } else if (!(status1 & 0x80)) {
764 /* Display unplug, beware multiple interrupts */
765 if (hdmi->hp_state != HDMI_HOTPLUG_DISCONNECTED)
766 schedule_delayed_work(&hdmi->edid_work, 0);
767
768 hdmi->hp_state = HDMI_HOTPLUG_DISCONNECTED;
769 /* display_off will switch back to mode_a */
770 }
771 } else if (status1 & 2) {
772 /* EDID error interrupt: retry */
773 /* Set EDID word address */
774 hdmi_write(hdmi, 0x00, HDMI_EDID_WORD_ADDRESS);
775 /* Set EDID segment pointer */
776 hdmi_write(hdmi, 0x00, HDMI_EDID_SEGMENT_POINTER);
777 } else if (status1 & 4) {
778 /* Disable EDID interrupt */
779 hdmi_write(hdmi, 0xC0, HDMI_INTERRUPT_MASK_1);
780 hdmi->hp_state = HDMI_HOTPLUG_EDID_DONE;
781 schedule_delayed_work(&hdmi->edid_work, msecs_to_jiffies(10));
782 }
783
784 return IRQ_HANDLED;
785}
786
787static void hdmi_display_on(void *arg, struct fb_info *info)
788{
789 struct sh_hdmi *hdmi = arg;
790 struct sh_mobile_hdmi_info *pdata = hdmi->dev->platform_data;
791
792 if (info->var.xres != 1280 || info->var.yres != 720) {
793 dev_warn(info->device, "Unsupported framebuffer geometry %ux%u\n",
794 info->var.xres, info->var.yres);
795 return;
796 }
797
798 pr_debug("%s(%p): state %x\n", __func__, pdata->lcd_dev, info->state);
799 /*
800 * FIXME: not a good place to store fb_info. And we cannot nullify it
801 * even on monitor disconnect. What should the lifecycle be?
802 */
803 hdmi->info = info;
804 switch (hdmi->hp_state) {
805 case HDMI_HOTPLUG_EDID_DONE:
806 /* PS mode d->e. All functions are active */
807 hdmi_write(hdmi, 0x80, HDMI_SYSTEM_CTRL);
808 pr_debug("HDMI running\n");
809 break;
810 case HDMI_HOTPLUG_DISCONNECTED:
811 info->state = FBINFO_STATE_SUSPENDED;
812 default:
813 hdmi->var = info->var;
814 }
815}
816
817static void hdmi_display_off(void *arg)
818{
819 struct sh_hdmi *hdmi = arg;
820 struct sh_mobile_hdmi_info *pdata = hdmi->dev->platform_data;
821
822 pr_debug("%s(%p)\n", __func__, pdata->lcd_dev);
823 /* PS mode e->a */
824 hdmi_write(hdmi, 0x10, HDMI_SYSTEM_CTRL);
825}
826
827/* Hotplug interrupt occurred, read EDID */
828static void edid_work_fn(struct work_struct *work)
829{
830 struct sh_hdmi *hdmi = container_of(work, struct sh_hdmi, edid_work.work);
831 struct sh_mobile_hdmi_info *pdata = hdmi->dev->platform_data;
832
833 pr_debug("%s(%p): begin, hotplug status %d\n", __func__,
834 pdata->lcd_dev, hdmi->hp_state);
835
836 if (!pdata->lcd_dev)
837 return;
838
839 if (hdmi->hp_state == HDMI_HOTPLUG_EDID_DONE) {
840 pm_runtime_get_sync(hdmi->dev);
841 /* A device has been plugged in */
842 sh_hdmi_read_edid(hdmi);
843 msleep(10);
844 sh_hdmi_configure(hdmi);
845 /* Switched to another (d) power-save mode */
846 msleep(10);
847
848 if (!hdmi->info)
849 return;
850
851 acquire_console_sem();
852
853 /* HDMI plug in */
854 hdmi->info->var = hdmi->var;
855 if (hdmi->info->state != FBINFO_STATE_RUNNING)
856 fb_set_suspend(hdmi->info, 0);
857 else
858 hdmi_display_on(hdmi, hdmi->info);
859
860 release_console_sem();
861 } else {
862 if (!hdmi->info)
863 return;
864
865 acquire_console_sem();
866
867 /* HDMI disconnect */
868 fb_set_suspend(hdmi->info, 1);
869
870 release_console_sem();
871 pm_runtime_put(hdmi->dev);
872 }
873
874 pr_debug("%s(%p): end\n", __func__, pdata->lcd_dev);
875}
876
877static int __init sh_hdmi_probe(struct platform_device *pdev)
878{
879 struct sh_mobile_hdmi_info *pdata = pdev->dev.platform_data;
880 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
881 int irq = platform_get_irq(pdev, 0), ret;
882 struct sh_hdmi *hdmi;
883 long rate;
884
885 if (!res || !pdata || irq < 0)
886 return -ENODEV;
887
888 hdmi = kzalloc(sizeof(*hdmi), GFP_KERNEL);
889 if (!hdmi) {
890 dev_err(&pdev->dev, "Cannot allocate device data\n");
891 return -ENOMEM;
892 }
893
894 hdmi->dev = &pdev->dev;
895
896 hdmi->hdmi_clk = clk_get(&pdev->dev, "ick");
897 if (IS_ERR(hdmi->hdmi_clk)) {
898 ret = PTR_ERR(hdmi->hdmi_clk);
899 dev_err(&pdev->dev, "Unable to get clock: %d\n", ret);
900 goto egetclk;
901 }
902
903 rate = PICOS2KHZ(pdata->lcd_chan->lcd_cfg.pixclock) * 1000;
904
905 rate = clk_round_rate(hdmi->hdmi_clk, rate);
906 if (rate < 0) {
907 ret = rate;
908 dev_err(&pdev->dev, "Cannot get suitable rate: %ld\n", rate);
909 goto erate;
910 }
911
912 ret = clk_set_rate(hdmi->hdmi_clk, rate);
913 if (ret < 0) {
914 dev_err(&pdev->dev, "Cannot set rate %ld: %d\n", rate, ret);
915 goto erate;
916 }
917
918 pr_debug("HDMI set frequency %lu\n", rate);
919
920 ret = clk_enable(hdmi->hdmi_clk);
921 if (ret < 0) {
922 dev_err(&pdev->dev, "Cannot enable clock: %d\n", ret);
923 goto eclkenable;
924 }
925
926 dev_info(&pdev->dev, "Enabled HDMI clock at %luHz\n", rate);
927
928 if (!request_mem_region(res->start, resource_size(res), dev_name(&pdev->dev))) {
929 dev_err(&pdev->dev, "HDMI register region already claimed\n");
930 ret = -EBUSY;
931 goto ereqreg;
932 }
933
934 hdmi->base = ioremap(res->start, resource_size(res));
935 if (!hdmi->base) {
936 dev_err(&pdev->dev, "HDMI register region already claimed\n");
937 ret = -ENOMEM;
938 goto emap;
939 }
940
941 platform_set_drvdata(pdev, hdmi);
942
943#if 1
944 /* Product and revision IDs are 0 in sh-mobile version */
945 dev_info(&pdev->dev, "Detected HDMI controller 0x%x:0x%x\n",
946 hdmi_read(hdmi, HDMI_PRODUCT_ID), hdmi_read(hdmi, HDMI_REVISION_ID));
947#endif
948
949 /* Set up LCDC callbacks */
950 pdata->lcd_chan->board_cfg.board_data = hdmi;
951 pdata->lcd_chan->board_cfg.display_on = hdmi_display_on;
952 pdata->lcd_chan->board_cfg.display_off = hdmi_display_off;
953
954 INIT_DELAYED_WORK(&hdmi->edid_work, edid_work_fn);
955
956 pm_runtime_enable(&pdev->dev);
957 pm_runtime_resume(&pdev->dev);
958
959 ret = request_irq(irq, sh_hdmi_hotplug, 0,
960 dev_name(&pdev->dev), hdmi);
961 if (ret < 0) {
962 dev_err(&pdev->dev, "Unable to request irq: %d\n", ret);
963 goto ereqirq;
964 }
965
966 return 0;
967
968ereqirq:
969 pm_runtime_disable(&pdev->dev);
970 iounmap(hdmi->base);
971emap:
972 release_mem_region(res->start, resource_size(res));
973ereqreg:
974 clk_disable(hdmi->hdmi_clk);
975eclkenable:
976erate:
977 clk_put(hdmi->hdmi_clk);
978egetclk:
979 kfree(hdmi);
980
981 return ret;
982}
983
984static int __exit sh_hdmi_remove(struct platform_device *pdev)
985{
986 struct sh_mobile_hdmi_info *pdata = pdev->dev.platform_data;
987 struct sh_hdmi *hdmi = platform_get_drvdata(pdev);
988 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
989 int irq = platform_get_irq(pdev, 0);
990
991 pdata->lcd_chan->board_cfg.display_on = NULL;
992 pdata->lcd_chan->board_cfg.display_off = NULL;
993 pdata->lcd_chan->board_cfg.board_data = NULL;
994
995 free_irq(irq, hdmi);
996 pm_runtime_disable(&pdev->dev);
997 cancel_delayed_work_sync(&hdmi->edid_work);
998 clk_disable(hdmi->hdmi_clk);
999 clk_put(hdmi->hdmi_clk);
1000 iounmap(hdmi->base);
1001 release_mem_region(res->start, resource_size(res));
1002 kfree(hdmi);
1003
1004 return 0;
1005}
1006
1007static struct platform_driver sh_hdmi_driver = {
1008 .remove = __exit_p(sh_hdmi_remove),
1009 .driver = {
1010 .name = "sh-mobile-hdmi",
1011 },
1012};
1013
1014static int __init sh_hdmi_init(void)
1015{
1016 return platform_driver_probe(&sh_hdmi_driver, sh_hdmi_probe);
1017}
1018module_init(sh_hdmi_init);
1019
1020static void __exit sh_hdmi_exit(void)
1021{
1022 platform_driver_unregister(&sh_hdmi_driver);
1023}
1024module_exit(sh_hdmi_exit);
1025
1026MODULE_AUTHOR("Guennadi Liakhovetski <g.liakhovetski@gmx.de>");
1027MODULE_DESCRIPTION("SuperH / ARM-shmobile HDMI driver");
1028MODULE_LICENSE("GPL v2");
diff --git a/drivers/video/sh_mobile_lcdcfb.c b/drivers/video/sh_mobile_lcdcfb.c
index 12c451a711e9..d72075a9f01c 100644
--- a/drivers/video/sh_mobile_lcdcfb.c
+++ b/drivers/video/sh_mobile_lcdcfb.c
@@ -56,6 +56,7 @@ static int lcdc_shared_regs[] = {
56/* per-channel registers */ 56/* per-channel registers */
57enum { LDDCKPAT1R, LDDCKPAT2R, LDMT1R, LDMT2R, LDMT3R, LDDFR, LDSM1R, 57enum { LDDCKPAT1R, LDDCKPAT2R, LDMT1R, LDMT2R, LDMT3R, LDDFR, LDSM1R,
58 LDSM2R, LDSA1R, LDMLSR, LDHCNR, LDHSYNR, LDVLNR, LDVSYNR, LDPMR, 58 LDSM2R, LDSA1R, LDMLSR, LDHCNR, LDHSYNR, LDVLNR, LDVSYNR, LDPMR,
59 LDHAJR,
59 NR_CH_REGS }; 60 NR_CH_REGS };
60 61
61static unsigned long lcdc_offs_mainlcd[NR_CH_REGS] = { 62static unsigned long lcdc_offs_mainlcd[NR_CH_REGS] = {
@@ -74,6 +75,7 @@ static unsigned long lcdc_offs_mainlcd[NR_CH_REGS] = {
74 [LDVLNR] = 0x450, 75 [LDVLNR] = 0x450,
75 [LDVSYNR] = 0x454, 76 [LDVSYNR] = 0x454,
76 [LDPMR] = 0x460, 77 [LDPMR] = 0x460,
78 [LDHAJR] = 0x4a0,
77}; 79};
78 80
79static unsigned long lcdc_offs_sublcd[NR_CH_REGS] = { 81static unsigned long lcdc_offs_sublcd[NR_CH_REGS] = {
@@ -137,6 +139,7 @@ struct sh_mobile_lcdc_priv {
137 struct clk *dot_clk; 139 struct clk *dot_clk;
138 unsigned long lddckr; 140 unsigned long lddckr;
139 struct sh_mobile_lcdc_chan ch[2]; 141 struct sh_mobile_lcdc_chan ch[2];
142 struct notifier_block notifier;
140 unsigned long saved_shared_regs[NR_SHARED_REGS]; 143 unsigned long saved_shared_regs[NR_SHARED_REGS];
141 int started; 144 int started;
142}; 145};
@@ -404,6 +407,56 @@ static void sh_mobile_lcdc_start_stop(struct sh_mobile_lcdc_priv *priv,
404 lcdc_write(priv, _LDDCKSTPR, 1); /* stop dotclock */ 407 lcdc_write(priv, _LDDCKSTPR, 1); /* stop dotclock */
405} 408}
406 409
410static void sh_mobile_lcdc_geometry(struct sh_mobile_lcdc_chan *ch)
411{
412 struct fb_var_screeninfo *var = &ch->info->var;
413 unsigned long h_total, hsync_pos;
414 u32 tmp;
415
416 tmp = ch->ldmt1r_value;
417 tmp |= (var->sync & FB_SYNC_VERT_HIGH_ACT) ? 0 : 1 << 28;
418 tmp |= (var->sync & FB_SYNC_HOR_HIGH_ACT) ? 0 : 1 << 27;
419 tmp |= (ch->cfg.flags & LCDC_FLAGS_DWPOL) ? 1 << 26 : 0;
420 tmp |= (ch->cfg.flags & LCDC_FLAGS_DIPOL) ? 1 << 25 : 0;
421 tmp |= (ch->cfg.flags & LCDC_FLAGS_DAPOL) ? 1 << 24 : 0;
422 tmp |= (ch->cfg.flags & LCDC_FLAGS_HSCNT) ? 1 << 17 : 0;
423 tmp |= (ch->cfg.flags & LCDC_FLAGS_DWCNT) ? 1 << 16 : 0;
424 lcdc_write_chan(ch, LDMT1R, tmp);
425
426 /* setup SYS bus */
427 lcdc_write_chan(ch, LDMT2R, ch->cfg.sys_bus_cfg.ldmt2r);
428 lcdc_write_chan(ch, LDMT3R, ch->cfg.sys_bus_cfg.ldmt3r);
429
430 /* horizontal configuration */
431 h_total = var->xres + var->hsync_len +
432 var->left_margin + var->right_margin;
433 tmp = h_total / 8; /* HTCN */
434 tmp |= (var->xres / 8) << 16; /* HDCN */
435 lcdc_write_chan(ch, LDHCNR, tmp);
436
437 hsync_pos = var->xres + var->right_margin;
438 tmp = hsync_pos / 8; /* HSYNP */
439 tmp |= (var->hsync_len / 8) << 16; /* HSYNW */
440 lcdc_write_chan(ch, LDHSYNR, tmp);
441
442 /* vertical configuration */
443 tmp = var->yres + var->vsync_len +
444 var->upper_margin + var->lower_margin; /* VTLN */
445 tmp |= var->yres << 16; /* VDLN */
446 lcdc_write_chan(ch, LDVLNR, tmp);
447
448 tmp = var->yres + var->lower_margin; /* VSYNP */
449 tmp |= var->vsync_len << 16; /* VSYNW */
450 lcdc_write_chan(ch, LDVSYNR, tmp);
451
452 /* Adjust horizontal synchronisation for HDMI */
453 tmp = ((var->xres & 7) << 24) |
454 ((h_total & 7) << 16) |
455 ((var->hsync_len & 7) << 8) |
456 hsync_pos;
457 lcdc_write_chan(ch, LDHAJR, tmp);
458}
459
407static int sh_mobile_lcdc_start(struct sh_mobile_lcdc_priv *priv) 460static int sh_mobile_lcdc_start(struct sh_mobile_lcdc_priv *priv)
408{ 461{
409 struct sh_mobile_lcdc_chan *ch; 462 struct sh_mobile_lcdc_chan *ch;
@@ -470,49 +523,11 @@ static int sh_mobile_lcdc_start(struct sh_mobile_lcdc_priv *priv)
470 if (!ch->enabled) 523 if (!ch->enabled)
471 continue; 524 continue;
472 525
473 tmp = ch->ldmt1r_value; 526 sh_mobile_lcdc_geometry(ch);
474 tmp |= (lcd_cfg->sync & FB_SYNC_VERT_HIGH_ACT) ? 0 : 1 << 28;
475 tmp |= (lcd_cfg->sync & FB_SYNC_HOR_HIGH_ACT) ? 0 : 1 << 27;
476 tmp |= (ch->cfg.flags & LCDC_FLAGS_DWPOL) ? 1 << 26 : 0;
477 tmp |= (ch->cfg.flags & LCDC_FLAGS_DIPOL) ? 1 << 25 : 0;
478 tmp |= (ch->cfg.flags & LCDC_FLAGS_DAPOL) ? 1 << 24 : 0;
479 tmp |= (ch->cfg.flags & LCDC_FLAGS_HSCNT) ? 1 << 17 : 0;
480 tmp |= (ch->cfg.flags & LCDC_FLAGS_DWCNT) ? 1 << 16 : 0;
481 lcdc_write_chan(ch, LDMT1R, tmp);
482
483 /* setup SYS bus */
484 lcdc_write_chan(ch, LDMT2R, ch->cfg.sys_bus_cfg.ldmt2r);
485 lcdc_write_chan(ch, LDMT3R, ch->cfg.sys_bus_cfg.ldmt3r);
486
487 /* horizontal configuration */
488 tmp = lcd_cfg->xres + lcd_cfg->hsync_len;
489 tmp += lcd_cfg->left_margin;
490 tmp += lcd_cfg->right_margin;
491 tmp /= 8; /* HTCN */
492 tmp |= (lcd_cfg->xres / 8) << 16; /* HDCN */
493 lcdc_write_chan(ch, LDHCNR, tmp);
494
495 tmp = lcd_cfg->xres;
496 tmp += lcd_cfg->right_margin;
497 tmp /= 8; /* HSYNP */
498 tmp |= (lcd_cfg->hsync_len / 8) << 16; /* HSYNW */
499 lcdc_write_chan(ch, LDHSYNR, tmp);
500 527
501 /* power supply */ 528 /* power supply */
502 lcdc_write_chan(ch, LDPMR, 0); 529 lcdc_write_chan(ch, LDPMR, 0);
503 530
504 /* vertical configuration */
505 tmp = lcd_cfg->yres + lcd_cfg->vsync_len;
506 tmp += lcd_cfg->upper_margin;
507 tmp += lcd_cfg->lower_margin; /* VTLN */
508 tmp |= lcd_cfg->yres << 16; /* VDLN */
509 lcdc_write_chan(ch, LDVLNR, tmp);
510
511 tmp = lcd_cfg->yres;
512 tmp += lcd_cfg->lower_margin; /* VSYNP */
513 tmp |= lcd_cfg->vsync_len << 16; /* VSYNW */
514 lcdc_write_chan(ch, LDVSYNR, tmp);
515
516 board_cfg = &ch->cfg.board_cfg; 531 board_cfg = &ch->cfg.board_cfg;
517 if (board_cfg->setup_sys) 532 if (board_cfg->setup_sys)
518 ret = board_cfg->setup_sys(board_cfg->board_data, ch, 533 ret = board_cfg->setup_sys(board_cfg->board_data, ch,
@@ -577,7 +592,7 @@ static int sh_mobile_lcdc_start(struct sh_mobile_lcdc_priv *priv)
577 592
578 board_cfg = &ch->cfg.board_cfg; 593 board_cfg = &ch->cfg.board_cfg;
579 if (board_cfg->display_on) 594 if (board_cfg->display_on)
580 board_cfg->display_on(board_cfg->board_data); 595 board_cfg->display_on(board_cfg->board_data, ch->info);
581 } 596 }
582 597
583 return 0; 598 return 0;
@@ -943,6 +958,62 @@ static const struct dev_pm_ops sh_mobile_lcdc_dev_pm_ops = {
943 .runtime_resume = sh_mobile_lcdc_runtime_resume, 958 .runtime_resume = sh_mobile_lcdc_runtime_resume,
944}; 959};
945 960
961static int sh_mobile_lcdc_notify(struct notifier_block *nb,
962 unsigned long action, void *data)
963{
964 struct fb_event *event = data;
965 struct fb_info *info = event->info;
966 struct sh_mobile_lcdc_chan *ch = info->par;
967 struct sh_mobile_lcdc_board_cfg *board_cfg = &ch->cfg.board_cfg;
968 struct fb_var_screeninfo *var;
969
970 if (&ch->lcdc->notifier != nb)
971 return 0;
972
973 dev_dbg(info->dev, "%s(): action = %lu, data = %p\n",
974 __func__, action, event->data);
975
976 switch(action) {
977 case FB_EVENT_SUSPEND:
978 if (board_cfg->display_off)
979 board_cfg->display_off(board_cfg->board_data);
980 pm_runtime_put(info->device);
981 break;
982 case FB_EVENT_RESUME:
983 var = &info->var;
984
985 /* HDMI must be enabled before LCDC configuration */
986 if (board_cfg->display_on)
987 board_cfg->display_on(board_cfg->board_data, ch->info);
988
989 /* Check if the new display is not in our modelist */
990 if (ch->info->modelist.next &&
991 !fb_match_mode(var, &ch->info->modelist)) {
992 struct fb_videomode mode;
993 int ret;
994
995 /* Can we handle this display? */
996 if (var->xres > ch->cfg.lcd_cfg.xres ||
997 var->yres > ch->cfg.lcd_cfg.yres)
998 return -ENOMEM;
999
1000 /* Add to the modelist */
1001 fb_var_to_videomode(&mode, var);
1002 ret = fb_add_videomode(&mode, &ch->info->modelist);
1003 if (ret < 0)
1004 return ret;
1005 }
1006
1007 pm_runtime_get_sync(info->device);
1008
1009 sh_mobile_lcdc_geometry(ch);
1010
1011 break;
1012 }
1013
1014 return 0;
1015}
1016
946static int sh_mobile_lcdc_remove(struct platform_device *pdev); 1017static int sh_mobile_lcdc_remove(struct platform_device *pdev);
947 1018
948static int __devinit sh_mobile_lcdc_probe(struct platform_device *pdev) 1019static int __devinit sh_mobile_lcdc_probe(struct platform_device *pdev)
@@ -1020,15 +1091,19 @@ static int __devinit sh_mobile_lcdc_probe(struct platform_device *pdev)
1020 goto err1; 1091 goto err1;
1021 } 1092 }
1022 1093
1094 priv->base = ioremap_nocache(res->start, resource_size(res));
1095 if (!priv->base)
1096 goto err1;
1097
1023 error = sh_mobile_lcdc_setup_clocks(pdev, pdata->clock_source, priv); 1098 error = sh_mobile_lcdc_setup_clocks(pdev, pdata->clock_source, priv);
1024 if (error) { 1099 if (error) {
1025 dev_err(&pdev->dev, "unable to setup clocks\n"); 1100 dev_err(&pdev->dev, "unable to setup clocks\n");
1026 goto err1; 1101 goto err1;
1027 } 1102 }
1028 1103
1029 priv->base = ioremap_nocache(res->start, (res->end - res->start) + 1);
1030
1031 for (i = 0; i < j; i++) { 1104 for (i = 0; i < j; i++) {
1105 struct fb_var_screeninfo *var;
1106 struct fb_videomode *lcd_cfg;
1032 cfg = &priv->ch[i].cfg; 1107 cfg = &priv->ch[i].cfg;
1033 1108
1034 priv->ch[i].info = framebuffer_alloc(0, &pdev->dev); 1109 priv->ch[i].info = framebuffer_alloc(0, &pdev->dev);
@@ -1039,22 +1114,33 @@ static int __devinit sh_mobile_lcdc_probe(struct platform_device *pdev)
1039 } 1114 }
1040 1115
1041 info = priv->ch[i].info; 1116 info = priv->ch[i].info;
1117 var = &info->var;
1118 lcd_cfg = &cfg->lcd_cfg;
1042 info->fbops = &sh_mobile_lcdc_ops; 1119 info->fbops = &sh_mobile_lcdc_ops;
1043 info->var.xres = info->var.xres_virtual = cfg->lcd_cfg.xres; 1120 var->xres = var->xres_virtual = lcd_cfg->xres;
1044 info->var.yres = cfg->lcd_cfg.yres; 1121 var->yres = lcd_cfg->yres;
1045 /* Default Y virtual resolution is 2x panel size */ 1122 /* Default Y virtual resolution is 2x panel size */
1046 info->var.yres_virtual = info->var.yres * 2; 1123 var->yres_virtual = var->yres * 2;
1047 info->var.width = cfg->lcd_size_cfg.width; 1124 var->width = cfg->lcd_size_cfg.width;
1048 info->var.height = cfg->lcd_size_cfg.height; 1125 var->height = cfg->lcd_size_cfg.height;
1049 info->var.activate = FB_ACTIVATE_NOW; 1126 var->activate = FB_ACTIVATE_NOW;
1050 error = sh_mobile_lcdc_set_bpp(&info->var, cfg->bpp); 1127 var->left_margin = lcd_cfg->left_margin;
1128 var->right_margin = lcd_cfg->right_margin;
1129 var->upper_margin = lcd_cfg->upper_margin;
1130 var->lower_margin = lcd_cfg->lower_margin;
1131 var->hsync_len = lcd_cfg->hsync_len;
1132 var->vsync_len = lcd_cfg->vsync_len;
1133 var->sync = lcd_cfg->sync;
1134 var->pixclock = lcd_cfg->pixclock;
1135
1136 error = sh_mobile_lcdc_set_bpp(var, cfg->bpp);
1051 if (error) 1137 if (error)
1052 break; 1138 break;
1053 1139
1054 info->fix = sh_mobile_lcdc_fix; 1140 info->fix = sh_mobile_lcdc_fix;
1055 info->fix.line_length = cfg->lcd_cfg.xres * (cfg->bpp / 8); 1141 info->fix.line_length = lcd_cfg->xres * (cfg->bpp / 8);
1056 info->fix.smem_len = info->fix.line_length * 1142 info->fix.smem_len = info->fix.line_length *
1057 info->var.yres_virtual; 1143 var->yres_virtual;
1058 1144
1059 buf = dma_alloc_coherent(&pdev->dev, info->fix.smem_len, 1145 buf = dma_alloc_coherent(&pdev->dev, info->fix.smem_len,
1060 &priv->ch[i].dma_handle, GFP_KERNEL); 1146 &priv->ch[i].dma_handle, GFP_KERNEL);
@@ -1119,10 +1205,14 @@ static int __devinit sh_mobile_lcdc_probe(struct platform_device *pdev)
1119 ch->cfg.bpp); 1205 ch->cfg.bpp);
1120 1206
1121 /* deferred io mode: disable clock to save power */ 1207 /* deferred io mode: disable clock to save power */
1122 if (info->fbdefio) 1208 if (info->fbdefio || info->state == FBINFO_STATE_SUSPENDED)
1123 sh_mobile_lcdc_clk_off(priv); 1209 sh_mobile_lcdc_clk_off(priv);
1124 } 1210 }
1125 1211
1212 /* Failure ignored */
1213 priv->notifier.notifier_call = sh_mobile_lcdc_notify;
1214 fb_register_client(&priv->notifier);
1215
1126 return 0; 1216 return 0;
1127err1: 1217err1:
1128 sh_mobile_lcdc_remove(pdev); 1218 sh_mobile_lcdc_remove(pdev);
@@ -1136,6 +1226,8 @@ static int sh_mobile_lcdc_remove(struct platform_device *pdev)
1136 struct fb_info *info; 1226 struct fb_info *info;
1137 int i; 1227 int i;
1138 1228
1229 fb_unregister_client(&priv->notifier);
1230
1139 for (i = 0; i < ARRAY_SIZE(priv->ch); i++) 1231 for (i = 0; i < ARRAY_SIZE(priv->ch); i++)
1140 if (priv->ch[i].info && priv->ch[i].info->dev) 1232 if (priv->ch[i].info && priv->ch[i].info->dev)
1141 unregister_framebuffer(priv->ch[i].info); 1233 unregister_framebuffer(priv->ch[i].info);
diff --git a/drivers/video/sunxvr1000.c b/drivers/video/sunxvr1000.c
index 7288934c0d49..5dbe06af2226 100644
--- a/drivers/video/sunxvr1000.c
+++ b/drivers/video/sunxvr1000.c
@@ -111,7 +111,7 @@ static int __devinit gfb_set_fbinfo(struct gfb_info *gp)
111 return 0; 111 return 0;
112} 112}
113 113
114static int __devinit gfb_probe(struct of_device *op, 114static int __devinit gfb_probe(struct platform_device *op,
115 const struct of_device_id *match) 115 const struct of_device_id *match)
116{ 116{
117 struct device_node *dp = op->dev.of_node; 117 struct device_node *dp = op->dev.of_node;
@@ -172,7 +172,7 @@ err_out:
172 return err; 172 return err;
173} 173}
174 174
175static int __devexit gfb_remove(struct of_device *op) 175static int __devexit gfb_remove(struct platform_device *op)
176{ 176{
177 struct fb_info *info = dev_get_drvdata(&op->dev); 177 struct fb_info *info = dev_get_drvdata(&op->dev);
178 struct gfb_info *gp = info->par; 178 struct gfb_info *gp = info->par;
diff --git a/drivers/video/tcx.c b/drivers/video/tcx.c
index f375e0db6776..77ad27955cf0 100644
--- a/drivers/video/tcx.c
+++ b/drivers/video/tcx.c
@@ -342,7 +342,7 @@ tcx_init_fix(struct fb_info *info, int linebytes)
342 info->fix.accel = FB_ACCEL_SUN_TCX; 342 info->fix.accel = FB_ACCEL_SUN_TCX;
343} 343}
344 344
345static void tcx_unmap_regs(struct of_device *op, struct fb_info *info, 345static void tcx_unmap_regs(struct platform_device *op, struct fb_info *info,
346 struct tcx_par *par) 346 struct tcx_par *par)
347{ 347{
348 if (par->tec) 348 if (par->tec)
@@ -362,7 +362,7 @@ static void tcx_unmap_regs(struct of_device *op, struct fb_info *info,
362 info->screen_base, info->fix.smem_len); 362 info->screen_base, info->fix.smem_len);
363} 363}
364 364
365static int __devinit tcx_probe(struct of_device *op, 365static int __devinit tcx_probe(struct platform_device *op,
366 const struct of_device_id *match) 366 const struct of_device_id *match)
367{ 367{
368 struct device_node *dp = op->dev.of_node; 368 struct device_node *dp = op->dev.of_node;
@@ -486,7 +486,7 @@ out_err:
486 return err; 486 return err;
487} 487}
488 488
489static int __devexit tcx_remove(struct of_device *op) 489static int __devexit tcx_remove(struct platform_device *op)
490{ 490{
491 struct fb_info *info = dev_get_drvdata(&op->dev); 491 struct fb_info *info = dev_get_drvdata(&op->dev);
492 struct tcx_par *par = info->par; 492 struct tcx_par *par = info->par;
diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
index 7b8839ebf3c4..52ec0959d462 100644
--- a/drivers/video/uvesafb.c
+++ b/drivers/video/uvesafb.c
@@ -1977,8 +1977,7 @@ static void __devexit uvesafb_exit(void)
1977 1977
1978module_exit(uvesafb_exit); 1978module_exit(uvesafb_exit);
1979 1979
1980#define param_get_scroll NULL 1980static int param_set_scroll(const char *val, const struct kernel_param *kp)
1981static int param_set_scroll(const char *val, struct kernel_param *kp)
1982{ 1981{
1983 ypan = 0; 1982 ypan = 0;
1984 1983
@@ -1993,7 +1992,9 @@ static int param_set_scroll(const char *val, struct kernel_param *kp)
1993 1992
1994 return 0; 1993 return 0;
1995} 1994}
1996 1995static struct kernel_param_ops param_ops_scroll = {
1996 .set = param_set_scroll,
1997};
1997#define param_check_scroll(name, p) __param_check(name, p, void) 1998#define param_check_scroll(name, p) __param_check(name, p, void)
1998 1999
1999module_param_named(scroll, ypan, scroll, 0); 2000module_param_named(scroll, ypan, scroll, 0);
diff --git a/drivers/video/via/chip.h b/drivers/video/via/chip.h
index d9b6e06e0700..ef1f3de2e052 100644
--- a/drivers/video/via/chip.h
+++ b/drivers/video/via/chip.h
@@ -160,7 +160,6 @@ struct lvds_setting_information {
160 int v_active; 160 int v_active;
161 int bpp; 161 int bpp;
162 int refresh_rate; 162 int refresh_rate;
163 int get_lcd_size_method;
164 int lcd_panel_id; 163 int lcd_panel_id;
165 int lcd_panel_hres; 164 int lcd_panel_hres;
166 int lcd_panel_vres; 165 int lcd_panel_vres;
diff --git a/drivers/video/via/hw.c b/drivers/video/via/hw.c
index b996803ae2c1..7dcb4d5bb9c3 100644
--- a/drivers/video/via/hw.c
+++ b/drivers/video/via/hw.c
@@ -23,143 +23,341 @@
23#include "global.h" 23#include "global.h"
24 24
25static struct pll_map pll_value[] = { 25static struct pll_map pll_value[] = {
26 {CLK_25_175M, CLE266_PLL_25_175M, K800_PLL_25_175M, 26 {25175000,
27 CX700_25_175M, VX855_25_175M}, 27 {99, 7, 3},
28 {CLK_29_581M, CLE266_PLL_29_581M, K800_PLL_29_581M, 28 {85, 3, 4}, /* ignoring bit difference: 0x00008000 */
29 CX700_29_581M, VX855_29_581M}, 29 {141, 5, 4},
30 {CLK_26_880M, CLE266_PLL_26_880M, K800_PLL_26_880M, 30 {141, 5, 4} },
31 CX700_26_880M, VX855_26_880M}, 31 {29581000,
32 {CLK_31_490M, CLE266_PLL_31_490M, K800_PLL_31_490M, 32 {33, 4, 2},
33 CX700_31_490M, VX855_31_490M}, 33 {66, 2, 4}, /* ignoring bit difference: 0x00808000 */
34 {CLK_31_500M, CLE266_PLL_31_500M, K800_PLL_31_500M, 34 {166, 5, 4}, /* ignoring bit difference: 0x00008000 */
35 CX700_31_500M, VX855_31_500M}, 35 {165, 5, 4} },
36 {CLK_31_728M, CLE266_PLL_31_728M, K800_PLL_31_728M, 36 {26880000,
37 CX700_31_728M, VX855_31_728M}, 37 {15, 4, 1},
38 {CLK_32_668M, CLE266_PLL_32_668M, K800_PLL_32_668M, 38 {30, 2, 3}, /* ignoring bit difference: 0x00808000 */
39 CX700_32_668M, VX855_32_668M}, 39 {150, 5, 4},
40 {CLK_36_000M, CLE266_PLL_36_000M, K800_PLL_36_000M, 40 {150, 5, 4} },
41 CX700_36_000M, VX855_36_000M}, 41 {31500000,
42 {CLK_40_000M, CLE266_PLL_40_000M, K800_PLL_40_000M, 42 {53, 3, 3}, /* ignoring bit difference: 0x00008000 */
43 CX700_40_000M, VX855_40_000M}, 43 {141, 4, 4}, /* ignoring bit difference: 0x00008000 */
44 {CLK_41_291M, CLE266_PLL_41_291M, K800_PLL_41_291M, 44 {176, 5, 4},
45 CX700_41_291M, VX855_41_291M}, 45 {176, 5, 4} },
46 {CLK_43_163M, CLE266_PLL_43_163M, K800_PLL_43_163M, 46 {31728000,
47 CX700_43_163M, VX855_43_163M}, 47 {31, 7, 1},
48 {CLK_45_250M, CLE266_PLL_45_250M, K800_PLL_45_250M, 48 {177, 5, 4}, /* ignoring bit difference: 0x00008000 */
49 CX700_45_250M, VX855_45_250M}, 49 {177, 5, 4},
50 {CLK_46_000M, CLE266_PLL_46_000M, K800_PLL_46_000M, 50 {142, 4, 4} },
51 CX700_46_000M, VX855_46_000M}, 51 {32688000,
52 {CLK_46_996M, CLE266_PLL_46_996M, K800_PLL_46_996M, 52 {73, 4, 3},
53 CX700_46_996M, VX855_46_996M}, 53 {146, 4, 4}, /* ignoring bit difference: 0x00008000 */
54 {CLK_48_000M, CLE266_PLL_48_000M, K800_PLL_48_000M, 54 {183, 5, 4},
55 CX700_48_000M, VX855_48_000M}, 55 {146, 4, 4} },
56 {CLK_48_875M, CLE266_PLL_48_875M, K800_PLL_48_875M, 56 {36000000,
57 CX700_48_875M, VX855_48_875M}, 57 {101, 5, 3}, /* ignoring bit difference: 0x00008000 */
58 {CLK_49_500M, CLE266_PLL_49_500M, K800_PLL_49_500M, 58 {161, 4, 4}, /* ignoring bit difference: 0x00008000 */
59 CX700_49_500M, VX855_49_500M}, 59 {202, 5, 4},
60 {CLK_52_406M, CLE266_PLL_52_406M, K800_PLL_52_406M, 60 {161, 4, 4} },
61 CX700_52_406M, VX855_52_406M}, 61 {40000000,
62 {CLK_52_977M, CLE266_PLL_52_977M, K800_PLL_52_977M, 62 {89, 4, 3},
63 CX700_52_977M, VX855_52_977M}, 63 {89, 4, 3}, /* ignoring bit difference: 0x00008000 */
64 {CLK_56_250M, CLE266_PLL_56_250M, K800_PLL_56_250M, 64 {112, 5, 3},
65 CX700_56_250M, VX855_56_250M}, 65 {112, 5, 3} },
66 {CLK_57_275M, 0, 0, 0, VX855_57_275M}, 66 {41291000,
67 {CLK_60_466M, CLE266_PLL_60_466M, K800_PLL_60_466M, 67 {23, 4, 1},
68 CX700_60_466M, VX855_60_466M}, 68 {69, 3, 3}, /* ignoring bit difference: 0x00008000 */
69 {CLK_61_500M, CLE266_PLL_61_500M, K800_PLL_61_500M, 69 {115, 5, 3},
70 CX700_61_500M, VX855_61_500M}, 70 {115, 5, 3} },
71 {CLK_65_000M, CLE266_PLL_65_000M, K800_PLL_65_000M, 71 {43163000,
72 CX700_65_000M, VX855_65_000M}, 72 {121, 5, 3},
73 {CLK_65_178M, CLE266_PLL_65_178M, K800_PLL_65_178M, 73 {121, 5, 3}, /* ignoring bit difference: 0x00008000 */
74 CX700_65_178M, VX855_65_178M}, 74 {121, 5, 3},
75 {CLK_66_750M, CLE266_PLL_66_750M, K800_PLL_66_750M, 75 {121, 5, 3} },
76 CX700_66_750M, VX855_66_750M}, 76 {45250000,
77 {CLK_68_179M, CLE266_PLL_68_179M, K800_PLL_68_179M, 77 {127, 5, 3},
78 CX700_68_179M, VX855_68_179M}, 78 {127, 5, 3}, /* ignoring bit difference: 0x00808000 */
79 {CLK_69_924M, CLE266_PLL_69_924M, K800_PLL_69_924M, 79 {127, 5, 3},
80 CX700_69_924M, VX855_69_924M}, 80 {127, 5, 3} },
81 {CLK_70_159M, CLE266_PLL_70_159M, K800_PLL_70_159M, 81 {46000000,
82 CX700_70_159M, VX855_70_159M}, 82 {90, 7, 2},
83 {CLK_72_000M, CLE266_PLL_72_000M, K800_PLL_72_000M, 83 {103, 4, 3}, /* ignoring bit difference: 0x00008000 */
84 CX700_72_000M, VX855_72_000M}, 84 {129, 5, 3},
85 {CLK_78_750M, CLE266_PLL_78_750M, K800_PLL_78_750M, 85 {103, 4, 3} },
86 CX700_78_750M, VX855_78_750M}, 86 {46996000,
87 {CLK_80_136M, CLE266_PLL_80_136M, K800_PLL_80_136M, 87 {105, 4, 3}, /* ignoring bit difference: 0x00008000 */
88 CX700_80_136M, VX855_80_136M}, 88 {131, 5, 3}, /* ignoring bit difference: 0x00808000 */
89 {CLK_83_375M, CLE266_PLL_83_375M, K800_PLL_83_375M, 89 {131, 5, 3}, /* ignoring bit difference: 0x00808000 */
90 CX700_83_375M, VX855_83_375M}, 90 {105, 4, 3} },
91 {CLK_83_950M, CLE266_PLL_83_950M, K800_PLL_83_950M, 91 {48000000,
92 CX700_83_950M, VX855_83_950M}, 92 {67, 20, 0},
93 {CLK_84_750M, CLE266_PLL_84_750M, K800_PLL_84_750M, 93 {134, 5, 3}, /* ignoring bit difference: 0x00808000 */
94 CX700_84_750M, VX855_84_750M}, 94 {134, 5, 3},
95 {CLK_85_860M, CLE266_PLL_85_860M, K800_PLL_85_860M, 95 {134, 5, 3} },
96 CX700_85_860M, VX855_85_860M}, 96 {48875000,
97 {CLK_88_750M, CLE266_PLL_88_750M, K800_PLL_88_750M, 97 {99, 29, 0},
98 CX700_88_750M, VX855_88_750M}, 98 {82, 3, 3}, /* ignoring bit difference: 0x00808000 */
99 {CLK_94_500M, CLE266_PLL_94_500M, K800_PLL_94_500M, 99 {82, 3, 3}, /* ignoring bit difference: 0x00808000 */
100 CX700_94_500M, VX855_94_500M}, 100 {137, 5, 3} },
101 {CLK_97_750M, CLE266_PLL_97_750M, K800_PLL_97_750M, 101 {49500000,
102 CX700_97_750M, VX855_97_750M}, 102 {83, 6, 2},
103 {CLK_101_000M, CLE266_PLL_101_000M, K800_PLL_101_000M, 103 {83, 3, 3}, /* ignoring bit difference: 0x00008000 */
104 CX700_101_000M, VX855_101_000M}, 104 {138, 5, 3},
105 {CLK_106_500M, CLE266_PLL_106_500M, K800_PLL_106_500M, 105 {83, 3, 3} },
106 CX700_106_500M, VX855_106_500M}, 106 {52406000,
107 {CLK_108_000M, CLE266_PLL_108_000M, K800_PLL_108_000M, 107 {117, 4, 3},
108 CX700_108_000M, VX855_108_000M}, 108 {117, 4, 3}, /* ignoring bit difference: 0x00008000 */
109 {CLK_113_309M, CLE266_PLL_113_309M, K800_PLL_113_309M, 109 {117, 4, 3},
110 CX700_113_309M, VX855_113_309M}, 110 {88, 3, 3} },
111 {CLK_118_840M, CLE266_PLL_118_840M, K800_PLL_118_840M, 111 {52977000,
112 CX700_118_840M, VX855_118_840M}, 112 {37, 5, 1},
113 {CLK_119_000M, CLE266_PLL_119_000M, K800_PLL_119_000M, 113 {148, 5, 3}, /* ignoring bit difference: 0x00808000 */
114 CX700_119_000M, VX855_119_000M}, 114 {148, 5, 3},
115 {CLK_121_750M, CLE266_PLL_121_750M, K800_PLL_121_750M, 115 {148, 5, 3} },
116 CX700_121_750M, 0}, 116 {56250000,
117 {CLK_125_104M, CLE266_PLL_125_104M, K800_PLL_125_104M, 117 {55, 7, 1}, /* ignoring bit difference: 0x00008000 */
118 CX700_125_104M, 0}, 118 {126, 4, 3}, /* ignoring bit difference: 0x00008000 */
119 {CLK_133_308M, CLE266_PLL_133_308M, K800_PLL_133_308M, 119 {157, 5, 3},
120 CX700_133_308M, 0}, 120 {157, 5, 3} },
121 {CLK_135_000M, CLE266_PLL_135_000M, K800_PLL_135_000M, 121 {57275000,
122 CX700_135_000M, VX855_135_000M}, 122 {0, 0, 0},
123 {CLK_136_700M, CLE266_PLL_136_700M, K800_PLL_136_700M, 123 {2, 2, 0},
124 CX700_136_700M, VX855_136_700M}, 124 {2, 2, 0},
125 {CLK_138_400M, CLE266_PLL_138_400M, K800_PLL_138_400M, 125 {157, 5, 3} }, /* ignoring bit difference: 0x00808000 */
126 CX700_138_400M, VX855_138_400M}, 126 {60466000,
127 {CLK_146_760M, CLE266_PLL_146_760M, K800_PLL_146_760M, 127 {76, 9, 1},
128 CX700_146_760M, VX855_146_760M}, 128 {169, 5, 3}, /* ignoring bit difference: 0x00808000 */
129 {CLK_153_920M, CLE266_PLL_153_920M, K800_PLL_153_920M, 129 {169, 5, 3}, /* FIXED: old = {72, 2, 3} */
130 CX700_153_920M, VX855_153_920M}, 130 {169, 5, 3} },
131 {CLK_156_000M, CLE266_PLL_156_000M, K800_PLL_156_000M, 131 {61500000,
132 CX700_156_000M, VX855_156_000M}, 132 {86, 20, 0},
133 {CLK_157_500M, CLE266_PLL_157_500M, K800_PLL_157_500M, 133 {172, 5, 3}, /* ignoring bit difference: 0x00808000 */
134 CX700_157_500M, VX855_157_500M}, 134 {172, 5, 3},
135 {CLK_162_000M, CLE266_PLL_162_000M, K800_PLL_162_000M, 135 {172, 5, 3} },
136 CX700_162_000M, VX855_162_000M}, 136 {65000000,
137 {CLK_187_000M, CLE266_PLL_187_000M, K800_PLL_187_000M, 137 {109, 6, 2}, /* ignoring bit difference: 0x00008000 */
138 CX700_187_000M, VX855_187_000M}, 138 {109, 3, 3}, /* ignoring bit difference: 0x00008000 */
139 {CLK_193_295M, CLE266_PLL_193_295M, K800_PLL_193_295M, 139 {109, 3, 3},
140 CX700_193_295M, VX855_193_295M}, 140 {109, 3, 3} },
141 {CLK_202_500M, CLE266_PLL_202_500M, K800_PLL_202_500M, 141 {65178000,
142 CX700_202_500M, VX855_202_500M}, 142 {91, 5, 2},
143 {CLK_204_000M, CLE266_PLL_204_000M, K800_PLL_204_000M, 143 {182, 5, 3}, /* ignoring bit difference: 0x00808000 */
144 CX700_204_000M, VX855_204_000M}, 144 {109, 3, 3},
145 {CLK_218_500M, CLE266_PLL_218_500M, K800_PLL_218_500M, 145 {182, 5, 3} },
146 CX700_218_500M, VX855_218_500M}, 146 {66750000,
147 {CLK_234_000M, CLE266_PLL_234_000M, K800_PLL_234_000M, 147 {75, 4, 2},
148 CX700_234_000M, VX855_234_000M}, 148 {150, 4, 3}, /* ignoring bit difference: 0x00808000 */
149 {CLK_267_250M, CLE266_PLL_267_250M, K800_PLL_267_250M, 149 {150, 4, 3},
150 CX700_267_250M, VX855_267_250M}, 150 {112, 3, 3} },
151 {CLK_297_500M, CLE266_PLL_297_500M, K800_PLL_297_500M, 151 {68179000,
152 CX700_297_500M, VX855_297_500M}, 152 {19, 4, 0},
153 {CLK_74_481M, CLE266_PLL_74_481M, K800_PLL_74_481M, 153 {114, 3, 3}, /* ignoring bit difference: 0x00008000 */
154 CX700_74_481M, VX855_74_481M}, 154 {190, 5, 3},
155 {CLK_172_798M, CLE266_PLL_172_798M, K800_PLL_172_798M, 155 {191, 5, 3} },
156 CX700_172_798M, VX855_172_798M}, 156 {69924000,
157 {CLK_122_614M, CLE266_PLL_122_614M, K800_PLL_122_614M, 157 {83, 17, 0},
158 CX700_122_614M, VX855_122_614M}, 158 {195, 5, 3}, /* ignoring bit difference: 0x00808000 */
159 {CLK_74_270M, CLE266_PLL_74_270M, K800_PLL_74_270M, 159 {195, 5, 3},
160 CX700_74_270M, 0}, 160 {195, 5, 3} },
161 {CLK_148_500M, CLE266_PLL_148_500M, K800_PLL_148_500M, 161 {70159000,
162 CX700_148_500M, VX855_148_500M} 162 {98, 20, 0},
163 {196, 5, 3}, /* ignoring bit difference: 0x00808000 */
164 {196, 5, 3},
165 {195, 5, 3} },
166 {72000000,
167 {121, 24, 0},
168 {161, 4, 3}, /* ignoring bit difference: 0x00808000 */
169 {161, 4, 3},
170 {161, 4, 3} },
171 {78750000,
172 {33, 3, 1},
173 {66, 3, 2}, /* ignoring bit difference: 0x00008000 */
174 {110, 5, 2},
175 {110, 5, 2} },
176 {80136000,
177 {28, 5, 0},
178 {68, 3, 2}, /* ignoring bit difference: 0x00008000 */
179 {112, 5, 2},
180 {112, 5, 2} },
181 {83375000,
182 {93, 2, 3},
183 {93, 4, 2}, /* ignoring bit difference: 0x00800000 */
184 {93, 4, 2}, /* ignoring bit difference: 0x00800000 */
185 {117, 5, 2} },
186 {83950000,
187 {41, 7, 0},
188 {117, 5, 2}, /* ignoring bit difference: 0x00008000 */
189 {117, 5, 2},
190 {117, 5, 2} },
191 {84750000,
192 {118, 5, 2},
193 {118, 5, 2}, /* ignoring bit difference: 0x00808000 */
194 {118, 5, 2},
195 {118, 5, 2} },
196 {85860000,
197 {84, 7, 1},
198 {120, 5, 2}, /* ignoring bit difference: 0x00808000 */
199 {120, 5, 2},
200 {118, 5, 2} },
201 {88750000,
202 {31, 5, 0},
203 {124, 5, 2}, /* ignoring bit difference: 0x00808000 */
204 {174, 7, 2}, /* ignoring bit difference: 0x00808000 */
205 {124, 5, 2} },
206 {94500000,
207 {33, 5, 0},
208 {132, 5, 2}, /* ignoring bit difference: 0x00008000 */
209 {132, 5, 2},
210 {132, 5, 2} },
211 {97750000,
212 {82, 6, 1},
213 {137, 5, 2}, /* ignoring bit difference: 0x00808000 */
214 {137, 5, 2},
215 {137, 5, 2} },
216 {101000000,
217 {127, 9, 1},
218 {141, 5, 2}, /* ignoring bit difference: 0x00808000 */
219 {141, 5, 2},
220 {141, 5, 2} },
221 {106500000,
222 {119, 4, 2},
223 {119, 4, 2}, /* ignoring bit difference: 0x00808000 */
224 {119, 4, 2},
225 {149, 5, 2} },
226 {108000000,
227 {121, 4, 2},
228 {121, 4, 2}, /* ignoring bit difference: 0x00808000 */
229 {151, 5, 2},
230 {151, 5, 2} },
231 {113309000,
232 {95, 12, 0},
233 {95, 3, 2}, /* ignoring bit difference: 0x00808000 */
234 {95, 3, 2},
235 {159, 5, 2} },
236 {118840000,
237 {83, 5, 1},
238 {166, 5, 2}, /* ignoring bit difference: 0x00808000 */
239 {166, 5, 2},
240 {166, 5, 2} },
241 {119000000,
242 {108, 13, 0},
243 {133, 4, 2}, /* ignoring bit difference: 0x00808000 */
244 {133, 4, 2},
245 {167, 5, 2} },
246 {121750000,
247 {85, 5, 1},
248 {170, 5, 2}, /* ignoring bit difference: 0x00808000 */
249 {68, 2, 2},
250 {0, 0, 0} },
251 {125104000,
252 {53, 6, 0}, /* ignoring bit difference: 0x00008000 */
253 {106, 3, 2}, /* ignoring bit difference: 0x00008000 */
254 {175, 5, 2},
255 {0, 0, 0} },
256 {135000000,
257 {94, 5, 1},
258 {28, 3, 0}, /* ignoring bit difference: 0x00804000 */
259 {151, 4, 2},
260 {189, 5, 2} },
261 {136700000,
262 {115, 12, 0},
263 {191, 5, 2}, /* ignoring bit difference: 0x00808000 */
264 {191, 5, 2},
265 {191, 5, 2} },
266 {138400000,
267 {87, 9, 0},
268 {116, 3, 2}, /* ignoring bit difference: 0x00808000 */
269 {116, 3, 2},
270 {194, 5, 2} },
271 {146760000,
272 {103, 5, 1},
273 {206, 5, 2}, /* ignoring bit difference: 0x00808000 */
274 {206, 5, 2},
275 {206, 5, 2} },
276 {153920000,
277 {86, 8, 0},
278 {86, 4, 1}, /* ignoring bit difference: 0x00808000 */
279 {86, 4, 1},
280 {86, 4, 1} }, /* FIXED: old = {84, 2, 1} */
281 {156000000,
282 {109, 5, 1},
283 {109, 5, 1}, /* ignoring bit difference: 0x00808000 */
284 {109, 5, 1},
285 {108, 5, 1} },
286 {157500000,
287 {55, 5, 0}, /* ignoring bit difference: 0x00008000 */
288 {22, 2, 0}, /* ignoring bit difference: 0x00802000 */
289 {110, 5, 1},
290 {110, 5, 1} },
291 {162000000,
292 {113, 5, 1},
293 {113, 5, 1}, /* ignoring bit difference: 0x00808000 */
294 {113, 5, 1},
295 {113, 5, 1} },
296 {187000000,
297 {118, 9, 0},
298 {131, 5, 1}, /* ignoring bit difference: 0x00808000 */
299 {131, 5, 1},
300 {131, 5, 1} },
301 {193295000,
302 {108, 8, 0},
303 {81, 3, 1}, /* ignoring bit difference: 0x00808000 */
304 {135, 5, 1},
305 {135, 5, 1} },
306 {202500000,
307 {99, 7, 0},
308 {85, 3, 1}, /* ignoring bit difference: 0x00808000 */
309 {142, 5, 1},
310 {142, 5, 1} },
311 {204000000,
312 {100, 7, 0},
313 {143, 5, 1}, /* ignoring bit difference: 0x00808000 */
314 {143, 5, 1},
315 {143, 5, 1} },
316 {218500000,
317 {92, 6, 0},
318 {153, 5, 1}, /* ignoring bit difference: 0x00808000 */
319 {153, 5, 1},
320 {153, 5, 1} },
321 {234000000,
322 {98, 6, 0},
323 {98, 3, 1}, /* ignoring bit difference: 0x00008000 */
324 {98, 3, 1},
325 {164, 5, 1} },
326 {267250000,
327 {112, 6, 0},
328 {112, 3, 1}, /* ignoring bit difference: 0x00808000 */
329 {187, 5, 1},
330 {187, 5, 1} },
331 {297500000,
332 {102, 5, 0}, /* ignoring bit difference: 0x00008000 */
333 {166, 4, 1}, /* ignoring bit difference: 0x00008000 */
334 {208, 5, 1},
335 {208, 5, 1} },
336 {74481000,
337 {26, 5, 0},
338 {125, 3, 3}, /* ignoring bit difference: 0x00808000 */
339 {208, 5, 3},
340 {209, 5, 3} },
341 {172798000,
342 {121, 5, 1},
343 {121, 5, 1}, /* ignoring bit difference: 0x00808000 */
344 {121, 5, 1},
345 {121, 5, 1} },
346 {122614000,
347 {60, 7, 0},
348 {137, 4, 2}, /* ignoring bit difference: 0x00808000 */
349 {137, 4, 2},
350 {172, 5, 2} },
351 {74270000,
352 {83, 8, 1},
353 {208, 5, 3},
354 {208, 5, 3},
355 {0, 0, 0} },
356 {148500000,
357 {83, 8, 0},
358 {208, 5, 2},
359 {166, 4, 2},
360 {208, 5, 2} }
163}; 361};
164 362
165static struct fifo_depth_select display_fifo_depth_reg = { 363static struct fifo_depth_select display_fifo_depth_reg = {
@@ -1360,40 +1558,70 @@ void viafb_load_FIFO_reg(int set_iga, int hor_active, int ver_active)
1360 1558
1361} 1559}
1362 1560
1561static u32 cle266_encode_pll(struct pll_config pll)
1562{
1563 return (pll.multiplier << 8)
1564 | (pll.rshift << 6)
1565 | pll.divisor;
1566}
1567
1568static u32 k800_encode_pll(struct pll_config pll)
1569{
1570 return ((pll.divisor - 2) << 16)
1571 | (pll.rshift << 10)
1572 | (pll.multiplier - 2);
1573}
1574
1575static u32 vx855_encode_pll(struct pll_config pll)
1576{
1577 return (pll.divisor << 16)
1578 | (pll.rshift << 10)
1579 | pll.multiplier;
1580}
1581
1363u32 viafb_get_clk_value(int clk) 1582u32 viafb_get_clk_value(int clk)
1364{ 1583{
1365 int i; 1584 u32 value = 0;
1585 int i = 0;
1366 1586
1367 for (i = 0; i < NUM_TOTAL_PLL_TABLE; i++) { 1587 while (i < NUM_TOTAL_PLL_TABLE && clk != pll_value[i].clk)
1368 if (clk == pll_value[i].clk) { 1588 i++;
1369 switch (viaparinfo->chip_info->gfx_chip_name) { 1589
1370 case UNICHROME_CLE266: 1590 if (i == NUM_TOTAL_PLL_TABLE) {
1371 case UNICHROME_K400: 1591 printk(KERN_WARNING "viafb_get_clk_value: PLL lookup failed!");
1372 return pll_value[i].cle266_pll; 1592 } else {
1373 1593 switch (viaparinfo->chip_info->gfx_chip_name) {
1374 case UNICHROME_K800: 1594 case UNICHROME_CLE266:
1375 case UNICHROME_PM800: 1595 case UNICHROME_K400:
1376 case UNICHROME_CN700: 1596 value = cle266_encode_pll(pll_value[i].cle266_pll);
1377 return pll_value[i].k800_pll; 1597 break;
1378 1598
1379 case UNICHROME_CX700: 1599 case UNICHROME_K800:
1380 case UNICHROME_K8M890: 1600 case UNICHROME_PM800:
1381 case UNICHROME_P4M890: 1601 case UNICHROME_CN700:
1382 case UNICHROME_P4M900: 1602 value = k800_encode_pll(pll_value[i].k800_pll);
1383 case UNICHROME_VX800: 1603 break;
1384 return pll_value[i].cx700_pll; 1604
1385 case UNICHROME_VX855: 1605 case UNICHROME_CX700:
1386 return pll_value[i].vx855_pll; 1606 case UNICHROME_CN750:
1387 } 1607 case UNICHROME_K8M890:
1608 case UNICHROME_P4M890:
1609 case UNICHROME_P4M900:
1610 case UNICHROME_VX800:
1611 value = k800_encode_pll(pll_value[i].cx700_pll);
1612 break;
1613
1614 case UNICHROME_VX855:
1615 value = vx855_encode_pll(pll_value[i].vx855_pll);
1616 break;
1388 } 1617 }
1389 } 1618 }
1390 1619
1391 DEBUG_MSG(KERN_INFO "Can't find match PLL value\n\n"); 1620 return value;
1392 return 0;
1393} 1621}
1394 1622
1395/* Set VCLK*/ 1623/* Set VCLK*/
1396void viafb_set_vclock(u32 CLK, int set_iga) 1624void viafb_set_vclock(u32 clk, int set_iga)
1397{ 1625{
1398 /* H.W. Reset : ON */ 1626 /* H.W. Reset : ON */
1399 viafb_write_reg_mask(CR17, VIACR, 0x00, BIT7); 1627 viafb_write_reg_mask(CR17, VIACR, 0x00, BIT7);
@@ -1403,26 +1631,23 @@ void viafb_set_vclock(u32 CLK, int set_iga)
1403 switch (viaparinfo->chip_info->gfx_chip_name) { 1631 switch (viaparinfo->chip_info->gfx_chip_name) {
1404 case UNICHROME_CLE266: 1632 case UNICHROME_CLE266:
1405 case UNICHROME_K400: 1633 case UNICHROME_K400:
1406 viafb_write_reg(SR46, VIASR, CLK / 0x100); 1634 via_write_reg(VIASR, SR46, (clk & 0x00FF));
1407 viafb_write_reg(SR47, VIASR, CLK % 0x100); 1635 via_write_reg(VIASR, SR47, (clk & 0xFF00) >> 8);
1408 break; 1636 break;
1409 1637
1410 case UNICHROME_K800: 1638 case UNICHROME_K800:
1411 case UNICHROME_PM800: 1639 case UNICHROME_PM800:
1412 case UNICHROME_CN700: 1640 case UNICHROME_CN700:
1413 case UNICHROME_CX700: 1641 case UNICHROME_CX700:
1642 case UNICHROME_CN750:
1414 case UNICHROME_K8M890: 1643 case UNICHROME_K8M890:
1415 case UNICHROME_P4M890: 1644 case UNICHROME_P4M890:
1416 case UNICHROME_P4M900: 1645 case UNICHROME_P4M900:
1417 case UNICHROME_VX800: 1646 case UNICHROME_VX800:
1418 case UNICHROME_VX855: 1647 case UNICHROME_VX855:
1419 viafb_write_reg(SR44, VIASR, CLK / 0x10000); 1648 via_write_reg(VIASR, SR44, (clk & 0x0000FF));
1420 DEBUG_MSG(KERN_INFO "\nSR44=%x", CLK / 0x10000); 1649 via_write_reg(VIASR, SR45, (clk & 0x00FF00) >> 8);
1421 viafb_write_reg(SR45, VIASR, (CLK & 0xFFFF) / 0x100); 1650 via_write_reg(VIASR, SR46, (clk & 0xFF0000) >> 16);
1422 DEBUG_MSG(KERN_INFO "\nSR45=%x",
1423 (CLK & 0xFFFF) / 0x100);
1424 viafb_write_reg(SR46, VIASR, CLK % 0x100);
1425 DEBUG_MSG(KERN_INFO "\nSR46=%x", CLK % 0x100);
1426 break; 1651 break;
1427 } 1652 }
1428 } 1653 }
@@ -1432,22 +1657,23 @@ void viafb_set_vclock(u32 CLK, int set_iga)
1432 switch (viaparinfo->chip_info->gfx_chip_name) { 1657 switch (viaparinfo->chip_info->gfx_chip_name) {
1433 case UNICHROME_CLE266: 1658 case UNICHROME_CLE266:
1434 case UNICHROME_K400: 1659 case UNICHROME_K400:
1435 viafb_write_reg(SR44, VIASR, CLK / 0x100); 1660 via_write_reg(VIASR, SR44, (clk & 0x00FF));
1436 viafb_write_reg(SR45, VIASR, CLK % 0x100); 1661 via_write_reg(VIASR, SR45, (clk & 0xFF00) >> 8);
1437 break; 1662 break;
1438 1663
1439 case UNICHROME_K800: 1664 case UNICHROME_K800:
1440 case UNICHROME_PM800: 1665 case UNICHROME_PM800:
1441 case UNICHROME_CN700: 1666 case UNICHROME_CN700:
1442 case UNICHROME_CX700: 1667 case UNICHROME_CX700:
1668 case UNICHROME_CN750:
1443 case UNICHROME_K8M890: 1669 case UNICHROME_K8M890:
1444 case UNICHROME_P4M890: 1670 case UNICHROME_P4M890:
1445 case UNICHROME_P4M900: 1671 case UNICHROME_P4M900:
1446 case UNICHROME_VX800: 1672 case UNICHROME_VX800:
1447 case UNICHROME_VX855: 1673 case UNICHROME_VX855:
1448 viafb_write_reg(SR4A, VIASR, CLK / 0x10000); 1674 via_write_reg(VIASR, SR4A, (clk & 0x0000FF));
1449 viafb_write_reg(SR4B, VIASR, (CLK & 0xFFFF) / 0x100); 1675 via_write_reg(VIASR, SR4B, (clk & 0x00FF00) >> 8);
1450 viafb_write_reg(SR4C, VIASR, CLK % 0x100); 1676 via_write_reg(VIASR, SR4C, (clk & 0xFF0000) >> 16);
1451 break; 1677 break;
1452 } 1678 }
1453 } 1679 }
@@ -1791,8 +2017,6 @@ void viafb_init_chip_info(int chip_type)
1791 viafb_set_iga_path(); 2017 viafb_set_iga_path();
1792 2018
1793 viaparinfo->lvds_setting_info->display_method = viafb_lcd_dsp_method; 2019 viaparinfo->lvds_setting_info->display_method = viafb_lcd_dsp_method;
1794 viaparinfo->lvds_setting_info->get_lcd_size_method =
1795 GET_LCD_SIZE_BY_USER_SETTING;
1796 viaparinfo->lvds_setting_info->lcd_mode = viafb_lcd_mode; 2020 viaparinfo->lvds_setting_info->lcd_mode = viafb_lcd_mode;
1797 viaparinfo->lvds_setting_info2->display_method = 2021 viaparinfo->lvds_setting_info2->display_method =
1798 viaparinfo->lvds_setting_info->display_method; 2022 viaparinfo->lvds_setting_info->display_method;
@@ -1946,13 +2170,6 @@ static void init_tmds_chip_info(void)
1946 2170
1947static void init_lvds_chip_info(void) 2171static void init_lvds_chip_info(void)
1948{ 2172{
1949 if (viafb_lcd_panel_id > LCD_PANEL_ID_MAXIMUM)
1950 viaparinfo->lvds_setting_info->get_lcd_size_method =
1951 GET_LCD_SIZE_BY_VGA_BIOS;
1952 else
1953 viaparinfo->lvds_setting_info->get_lcd_size_method =
1954 GET_LCD_SIZE_BY_USER_SETTING;
1955
1956 viafb_lvds_trasmitter_identify(); 2173 viafb_lvds_trasmitter_identify();
1957 viafb_init_lcd_size(); 2174 viafb_init_lcd_size();
1958 viafb_init_lvds_output_interface(&viaparinfo->chip_info->lvds_chip_info, 2175 viafb_init_lvds_output_interface(&viaparinfo->chip_info->lvds_chip_info,
diff --git a/drivers/video/via/hw.h b/drivers/video/via/hw.h
index a109de379816..c44399895294 100644
--- a/drivers/video/via/hw.h
+++ b/drivers/video/via/hw.h
@@ -700,12 +700,18 @@ struct _lcd_scaling_factor {
700 struct _lcd_ver_scaling_factor lcd_ver_scaling_factor; 700 struct _lcd_ver_scaling_factor lcd_ver_scaling_factor;
701}; 701};
702 702
703struct pll_config {
704 u16 multiplier;
705 u8 divisor;
706 u8 rshift;
707};
708
703struct pll_map { 709struct pll_map {
704 u32 clk; 710 u32 clk;
705 u32 cle266_pll; 711 struct pll_config cle266_pll;
706 u32 k800_pll; 712 struct pll_config k800_pll;
707 u32 cx700_pll; 713 struct pll_config cx700_pll;
708 u32 vx855_pll; 714 struct pll_config vx855_pll;
709}; 715};
710 716
711struct rgbLUT { 717struct rgbLUT {
diff --git a/drivers/video/via/ioctl.h b/drivers/video/via/ioctl.h
index c430fa23008a..6010d10b59e8 100644
--- a/drivers/video/via/ioctl.h
+++ b/drivers/video/via/ioctl.h
@@ -35,11 +35,9 @@
35#define VIAFB_GET_SAMM_INFO 0x56494107 /* 'VIA\07' */ 35#define VIAFB_GET_SAMM_INFO 0x56494107 /* 'VIA\07' */
36#define VIAFB_TURN_ON_OUTPUT_DEVICE 0x56494108 /* 'VIA\08' */ 36#define VIAFB_TURN_ON_OUTPUT_DEVICE 0x56494108 /* 'VIA\08' */
37#define VIAFB_TURN_OFF_OUTPUT_DEVICE 0x56494109 /* 'VIA\09' */ 37#define VIAFB_TURN_OFF_OUTPUT_DEVICE 0x56494109 /* 'VIA\09' */
38#define VIAFB_SET_DEVICE 0x5649410A
39#define VIAFB_GET_DEVICE 0x5649410B 38#define VIAFB_GET_DEVICE 0x5649410B
40#define VIAFB_GET_DRIVER_VERSION 0x56494112 /* 'VIA\12' */ 39#define VIAFB_GET_DRIVER_VERSION 0x56494112 /* 'VIA\12' */
41#define VIAFB_GET_CHIP_INFO 0x56494113 /* 'VIA\13' */ 40#define VIAFB_GET_CHIP_INFO 0x56494113 /* 'VIA\13' */
42#define VIAFB_SET_DEVICE_INFO 0x56494114
43#define VIAFB_GET_DEVICE_INFO 0x56494115 41#define VIAFB_GET_DEVICE_INFO 0x56494115
44 42
45#define VIAFB_GET_DEVICE_SUPPORT 0x56494118 43#define VIAFB_GET_DEVICE_SUPPORT 0x56494118
@@ -50,7 +48,6 @@
50#define VIAFB_GET_GAMMA_LUT 0x56494124 48#define VIAFB_GET_GAMMA_LUT 0x56494124
51#define VIAFB_SET_GAMMA_LUT 0x56494125 49#define VIAFB_SET_GAMMA_LUT 0x56494125
52#define VIAFB_GET_GAMMA_SUPPORT_STATE 0x56494126 50#define VIAFB_GET_GAMMA_SUPPORT_STATE 0x56494126
53#define VIAFB_SET_SECOND_MODE 0x56494129
54#define VIAFB_SYNC_SURFACE 0x56494130 51#define VIAFB_SYNC_SURFACE 0x56494130
55#define VIAFB_GET_DRIVER_CAPS 0x56494131 52#define VIAFB_GET_DRIVER_CAPS 0x56494131
56#define VIAFB_GET_IGA_SCALING_INFO 0x56494132 53#define VIAFB_GET_IGA_SCALING_INFO 0x56494132
diff --git a/drivers/video/via/lcd.c b/drivers/video/via/lcd.c
index 2ab0f156439a..fc25ae30c5f6 100644
--- a/drivers/video/via/lcd.c
+++ b/drivers/video/via/lcd.c
@@ -75,8 +75,6 @@ static void check_diport_of_integrated_lvds(
75static struct display_timing lcd_centering_timging(struct display_timing 75static struct display_timing lcd_centering_timging(struct display_timing
76 mode_crt_reg, 76 mode_crt_reg,
77 struct display_timing panel_crt_reg); 77 struct display_timing panel_crt_reg);
78static void viafb_load_scaling_factor_for_p4m900(int set_hres,
79 int set_vres, int panel_hres, int panel_vres);
80 78
81static int check_lvds_chip(int device_id_subaddr, int device_id) 79static int check_lvds_chip(int device_id_subaddr, int device_id)
82{ 80{
@@ -89,33 +87,8 @@ static int check_lvds_chip(int device_id_subaddr, int device_id)
89void viafb_init_lcd_size(void) 87void viafb_init_lcd_size(void)
90{ 88{
91 DEBUG_MSG(KERN_INFO "viafb_init_lcd_size()\n"); 89 DEBUG_MSG(KERN_INFO "viafb_init_lcd_size()\n");
92 DEBUG_MSG(KERN_INFO
93 "viaparinfo->lvds_setting_info->get_lcd_size_method %d\n",
94 viaparinfo->lvds_setting_info->get_lcd_size_method);
95 90
96 switch (viaparinfo->lvds_setting_info->get_lcd_size_method) { 91 fp_id_to_vindex(viafb_lcd_panel_id);
97 case GET_LCD_SIZE_BY_SYSTEM_BIOS:
98 break;
99 case GET_LCD_SZIE_BY_HW_STRAPPING:
100 break;
101 case GET_LCD_SIZE_BY_VGA_BIOS:
102 DEBUG_MSG(KERN_INFO "Get LCD Size method by VGA BIOS !!\n");
103 fp_id_to_vindex(viafb_lcd_panel_id);
104 DEBUG_MSG(KERN_INFO "LCD Panel_ID = %d\n",
105 viaparinfo->lvds_setting_info->lcd_panel_id);
106 break;
107 case GET_LCD_SIZE_BY_USER_SETTING:
108 DEBUG_MSG(KERN_INFO "Get LCD Size method by user setting !!\n");
109 fp_id_to_vindex(viafb_lcd_panel_id);
110 DEBUG_MSG(KERN_INFO "LCD Panel_ID = %d\n",
111 viaparinfo->lvds_setting_info->lcd_panel_id);
112 break;
113 default:
114 DEBUG_MSG(KERN_INFO "viafb_init_lcd_size fail\n");
115 viaparinfo->lvds_setting_info->lcd_panel_id =
116 LCD_PANEL_ID1_800X600;
117 fp_id_to_vindex(LCD_PANEL_ID1_800X600);
118 }
119 viaparinfo->lvds_setting_info2->lcd_panel_id = 92 viaparinfo->lvds_setting_info2->lcd_panel_id =
120 viaparinfo->lvds_setting_info->lcd_panel_id; 93 viaparinfo->lvds_setting_info->lcd_panel_id;
121 viaparinfo->lvds_setting_info2->lcd_panel_hres = 94 viaparinfo->lvds_setting_info2->lcd_panel_hres =
@@ -437,14 +410,9 @@ static void load_lcd_scaling(int set_hres, int set_vres, int panel_hres,
437 410
438 /* LCD Scaling Enable */ 411 /* LCD Scaling Enable */
439 viafb_write_reg_mask(CR79, VIACR, 0x07, BIT0 + BIT1 + BIT2); 412 viafb_write_reg_mask(CR79, VIACR, 0x07, BIT0 + BIT1 + BIT2);
440 if (UNICHROME_P4M900 == viaparinfo->chip_info->gfx_chip_name) {
441 viafb_load_scaling_factor_for_p4m900(set_hres, set_vres,
442 panel_hres, panel_vres);
443 return;
444 }
445 413
446 /* Check if expansion for horizontal */ 414 /* Check if expansion for horizontal */
447 if (set_hres != panel_hres) { 415 if (set_hres < panel_hres) {
448 /* Load Horizontal Scaling Factor */ 416 /* Load Horizontal Scaling Factor */
449 switch (viaparinfo->chip_info->gfx_chip_name) { 417 switch (viaparinfo->chip_info->gfx_chip_name) {
450 case UNICHROME_CLE266: 418 case UNICHROME_CLE266:
@@ -464,6 +432,10 @@ static void load_lcd_scaling(int set_hres, int set_vres, int panel_hres,
464 case UNICHROME_CX700: 432 case UNICHROME_CX700:
465 case UNICHROME_K8M890: 433 case UNICHROME_K8M890:
466 case UNICHROME_P4M890: 434 case UNICHROME_P4M890:
435 case UNICHROME_P4M900:
436 case UNICHROME_CN750:
437 case UNICHROME_VX800:
438 case UNICHROME_VX855:
467 reg_value = 439 reg_value =
468 K800_LCD_HOR_SCF_FORMULA(set_hres, panel_hres); 440 K800_LCD_HOR_SCF_FORMULA(set_hres, panel_hres);
469 /* Horizontal scaling enabled */ 441 /* Horizontal scaling enabled */
@@ -483,7 +455,7 @@ static void load_lcd_scaling(int set_hres, int set_vres, int panel_hres,
483 } 455 }
484 456
485 /* Check if expansion for vertical */ 457 /* Check if expansion for vertical */
486 if (set_vres != panel_vres) { 458 if (set_vres < panel_vres) {
487 /* Load Vertical Scaling Factor */ 459 /* Load Vertical Scaling Factor */
488 switch (viaparinfo->chip_info->gfx_chip_name) { 460 switch (viaparinfo->chip_info->gfx_chip_name) {
489 case UNICHROME_CLE266: 461 case UNICHROME_CLE266:
@@ -503,6 +475,10 @@ static void load_lcd_scaling(int set_hres, int set_vres, int panel_hres,
503 case UNICHROME_CX700: 475 case UNICHROME_CX700:
504 case UNICHROME_K8M890: 476 case UNICHROME_K8M890:
505 case UNICHROME_P4M890: 477 case UNICHROME_P4M890:
478 case UNICHROME_P4M900:
479 case UNICHROME_CN750:
480 case UNICHROME_VX800:
481 case UNICHROME_VX855:
506 reg_value = 482 reg_value =
507 K800_LCD_VER_SCF_FORMULA(set_vres, panel_vres); 483 K800_LCD_VER_SCF_FORMULA(set_vres, panel_vres);
508 /* Vertical scaling enabled */ 484 /* Vertical scaling enabled */
@@ -648,9 +624,8 @@ void viafb_lcd_set_mode(struct crt_mode_table *mode_crt_table,
648 (mode_crt_reg, panel_crt_reg), IGA1); 624 (mode_crt_reg, panel_crt_reg), IGA1);
649 } else { 625 } else {
650 /* Expansion */ 626 /* Expansion */
651 if ((plvds_setting_info->display_method == 627 if (plvds_setting_info->display_method == LCD_EXPANDSION
652 LCD_EXPANDSION) & ((set_hres != panel_hres) 628 && (set_hres < panel_hres || set_vres < panel_vres)) {
653 || (set_vres != panel_vres))) {
654 /* expansion timing IGA2 loaded panel set timing*/ 629 /* expansion timing IGA2 loaded panel set timing*/
655 viafb_load_crtc_timing(panel_crt_reg, IGA2); 630 viafb_load_crtc_timing(panel_crt_reg, IGA2);
656 DEBUG_MSG(KERN_INFO "viafb_load_crtc_timing!!\n"); 631 DEBUG_MSG(KERN_INFO "viafb_load_crtc_timing!!\n");
@@ -1139,69 +1114,3 @@ bool viafb_lcd_get_mobile_state(bool *mobile)
1139 return false; 1114 return false;
1140 } 1115 }
1141} 1116}
1142
1143static void viafb_load_scaling_factor_for_p4m900(int set_hres,
1144 int set_vres, int panel_hres, int panel_vres)
1145{
1146 int h_scaling_factor;
1147 int v_scaling_factor;
1148 u8 cra2 = 0;
1149 u8 cr77 = 0;
1150 u8 cr78 = 0;
1151 u8 cr79 = 0;
1152 u8 cr9f = 0;
1153 /* Check if expansion for horizontal */
1154 if (set_hres < panel_hres) {
1155 /* Load Horizontal Scaling Factor */
1156
1157 /* For VIA_K8M800 or later chipsets. */
1158 h_scaling_factor =
1159 K800_LCD_HOR_SCF_FORMULA(set_hres, panel_hres);
1160 /* HSCaleFactor[1:0] at CR9F[1:0] */
1161 cr9f = h_scaling_factor & 0x0003;
1162 /* HSCaleFactor[9:2] at CR77[7:0] */
1163 cr77 = (h_scaling_factor & 0x03FC) >> 2;
1164 /* HSCaleFactor[11:10] at CR79[5:4] */
1165 cr79 = (h_scaling_factor & 0x0C00) >> 10;
1166 cr79 <<= 4;
1167
1168 /* Horizontal scaling enabled */
1169 cra2 = 0xC0;
1170
1171 DEBUG_MSG(KERN_INFO "Horizontal Scaling value = %d\n",
1172 h_scaling_factor);
1173 } else {
1174 /* Horizontal scaling disabled */
1175 cra2 = 0x00;
1176 }
1177
1178 /* Check if expansion for vertical */
1179 if (set_vres < panel_vres) {
1180 /* Load Vertical Scaling Factor */
1181
1182 /* For VIA_K8M800 or later chipsets. */
1183 v_scaling_factor =
1184 K800_LCD_VER_SCF_FORMULA(set_vres, panel_vres);
1185
1186 /* Vertical scaling enabled */
1187 cra2 |= 0x08;
1188 /* VSCaleFactor[0] at CR79[3] */
1189 cr79 |= ((v_scaling_factor & 0x0001) << 3);
1190 /* VSCaleFactor[8:1] at CR78[7:0] */
1191 cr78 |= (v_scaling_factor & 0x01FE) >> 1;
1192 /* VSCaleFactor[10:9] at CR79[7:6] */
1193 cr79 |= ((v_scaling_factor & 0x0600) >> 9) << 6;
1194
1195 DEBUG_MSG(KERN_INFO "Vertical Scaling value = %d\n",
1196 v_scaling_factor);
1197 } else {
1198 /* Vertical scaling disabled */
1199 cra2 |= 0x00;
1200 }
1201
1202 viafb_write_reg_mask(CRA2, VIACR, cra2, BIT3 + BIT6 + BIT7);
1203 viafb_write_reg_mask(CR77, VIACR, cr77, 0xFF);
1204 viafb_write_reg_mask(CR78, VIACR, cr78, 0xFF);
1205 viafb_write_reg_mask(CR79, VIACR, cr79, 0xF8);
1206 viafb_write_reg_mask(CR9F, VIACR, cr9f, BIT0 + BIT1);
1207}
diff --git a/drivers/video/via/lcd.h b/drivers/video/via/lcd.h
index 9762ec62b495..b348efc360b8 100644
--- a/drivers/video/via/lcd.h
+++ b/drivers/video/via/lcd.h
@@ -28,11 +28,6 @@
28#define VT3271_DEVICE_ID_REG 0x02 28#define VT3271_DEVICE_ID_REG 0x02
29#define VT3271_DEVICE_ID 0x71 29#define VT3271_DEVICE_ID 0x71
30 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*/ 31/* Definition DVI Panel ID*/
37/* Resolution: 640x480, Channel: single, Dithering: Enable */ 32/* Resolution: 640x480, Channel: single, Dithering: Enable */
38#define LCD_PANEL_ID0_640X480 0x00 33#define LCD_PANEL_ID0_640X480 0x00
diff --git a/drivers/video/via/share.h b/drivers/video/via/share.h
index 7f0de7f006ad..2cbe1031b421 100644
--- a/drivers/video/via/share.h
+++ b/drivers/video/via/share.h
@@ -631,7 +631,6 @@
631#define CLK_25_175M 25175000 631#define CLK_25_175M 25175000
632#define CLK_26_880M 26880000 632#define CLK_26_880M 26880000
633#define CLK_29_581M 29581000 633#define CLK_29_581M 29581000
634#define CLK_31_490M 31490000
635#define CLK_31_500M 31500000 634#define CLK_31_500M 31500000
636#define CLK_31_728M 31728000 635#define CLK_31_728M 31728000
637#define CLK_32_668M 32688000 636#define CLK_32_668M 32688000
@@ -676,7 +675,6 @@
676#define CLK_119_000M 119000000 675#define CLK_119_000M 119000000
677#define CLK_121_750M 121750000 /* 121.704MHz */ 676#define CLK_121_750M 121750000 /* 121.704MHz */
678#define CLK_125_104M 125104000 677#define CLK_125_104M 125104000
679#define CLK_133_308M 133308000
680#define CLK_135_000M 135000000 678#define CLK_135_000M 135000000
681#define CLK_136_700M 136700000 679#define CLK_136_700M 136700000
682#define CLK_138_400M 138400000 680#define CLK_138_400M 138400000
@@ -699,313 +697,6 @@
699#define CLK_172_798M 172798000 697#define CLK_172_798M 172798000
700#define CLK_122_614M 122614000 698#define CLK_122_614M 122614000
701 699
702/* CLE266 PLL value
703*/
704#define CLE266_PLL_25_175M 0x0000C763
705#define CLE266_PLL_26_880M 0x0000440F
706#define CLE266_PLL_29_581M 0x00008421
707#define CLE266_PLL_31_490M 0x00004721
708#define CLE266_PLL_31_500M 0x0000C3B5
709#define CLE266_PLL_31_728M 0x0000471F
710#define CLE266_PLL_32_668M 0x0000C449
711#define CLE266_PLL_36_000M 0x0000C5E5
712#define CLE266_PLL_40_000M 0x0000C459
713#define CLE266_PLL_41_291M 0x00004417
714#define CLE266_PLL_43_163M 0x0000C579
715#define CLE266_PLL_45_250M 0x0000C57F /* 45.46MHz */
716#define CLE266_PLL_46_000M 0x0000875A
717#define CLE266_PLL_46_996M 0x0000C4E9
718#define CLE266_PLL_48_000M 0x00001443
719#define CLE266_PLL_48_875M 0x00001D63
720#define CLE266_PLL_49_500M 0x00008653
721#define CLE266_PLL_52_406M 0x0000C475
722#define CLE266_PLL_52_977M 0x00004525
723#define CLE266_PLL_56_250M 0x000047B7
724#define CLE266_PLL_60_466M 0x0000494C
725#define CLE266_PLL_61_500M 0x00001456
726#define CLE266_PLL_65_000M 0x000086ED
727#define CLE266_PLL_65_178M 0x0000855B
728#define CLE266_PLL_66_750M 0x0000844B /* 67.116MHz */
729#define CLE266_PLL_68_179M 0x00000413
730#define CLE266_PLL_69_924M 0x00001153
731#define CLE266_PLL_70_159M 0x00001462
732#define CLE266_PLL_72_000M 0x00001879
733#define CLE266_PLL_74_270M 0x00004853
734#define CLE266_PLL_78_750M 0x00004321
735#define CLE266_PLL_80_136M 0x0000051C
736#define CLE266_PLL_83_375M 0x0000C25D
737#define CLE266_PLL_83_950M 0x00000729
738#define CLE266_PLL_84_750M 0x00008576 /* 84.537MHz */
739#define CLE266_PLL_85_860M 0x00004754
740#define CLE266_PLL_88_750M 0x0000051F
741#define CLE266_PLL_94_500M 0x00000521
742#define CLE266_PLL_97_750M 0x00004652
743#define CLE266_PLL_101_000M 0x0000497F
744#define CLE266_PLL_106_500M 0x00008477 /* 106.491463 MHz */
745#define CLE266_PLL_108_000M 0x00008479
746#define CLE266_PLL_113_309M 0x00000C5F
747#define CLE266_PLL_118_840M 0x00004553
748#define CLE266_PLL_119_000M 0x00000D6C
749#define CLE266_PLL_121_750M 0x00004555 /* 121.704MHz */
750#define CLE266_PLL_125_104M 0x000006B5
751#define CLE266_PLL_133_308M 0x0000465F
752#define CLE266_PLL_135_000M 0x0000455E
753#define CLE266_PLL_136_700M 0x00000C73
754#define CLE266_PLL_138_400M 0x00000957
755#define CLE266_PLL_146_760M 0x00004567
756#define CLE266_PLL_148_500M 0x00000853
757#define CLE266_PLL_153_920M 0x00000856
758#define CLE266_PLL_156_000M 0x0000456D
759#define CLE266_PLL_157_500M 0x000005B7
760#define CLE266_PLL_162_000M 0x00004571
761#define CLE266_PLL_187_000M 0x00000976
762#define CLE266_PLL_193_295M 0x0000086C
763#define CLE266_PLL_202_500M 0x00000763
764#define CLE266_PLL_204_000M 0x00000764
765#define CLE266_PLL_218_500M 0x0000065C
766#define CLE266_PLL_234_000M 0x00000662
767#define CLE266_PLL_267_250M 0x00000670
768#define CLE266_PLL_297_500M 0x000005E6
769#define CLE266_PLL_74_481M 0x0000051A
770#define CLE266_PLL_172_798M 0x00004579
771#define CLE266_PLL_122_614M 0x0000073C
772
773/* K800 PLL value
774*/
775#define K800_PLL_25_175M 0x00539001
776#define K800_PLL_26_880M 0x001C8C80
777#define K800_PLL_29_581M 0x00409080
778#define K800_PLL_31_490M 0x006F9001
779#define K800_PLL_31_500M 0x008B9002
780#define K800_PLL_31_728M 0x00AF9003
781#define K800_PLL_32_668M 0x00909002
782#define K800_PLL_36_000M 0x009F9002
783#define K800_PLL_40_000M 0x00578C02
784#define K800_PLL_41_291M 0x00438C01
785#define K800_PLL_43_163M 0x00778C03
786#define K800_PLL_45_250M 0x007D8C83 /* 45.46MHz */
787#define K800_PLL_46_000M 0x00658C02
788#define K800_PLL_46_996M 0x00818C83
789#define K800_PLL_48_000M 0x00848C83
790#define K800_PLL_48_875M 0x00508C81
791#define K800_PLL_49_500M 0x00518C01
792#define K800_PLL_52_406M 0x00738C02
793#define K800_PLL_52_977M 0x00928C83
794#define K800_PLL_56_250M 0x007C8C02
795#define K800_PLL_60_466M 0x00A78C83
796#define K800_PLL_61_500M 0x00AA8C83
797#define K800_PLL_65_000M 0x006B8C01
798#define K800_PLL_65_178M 0x00B48C83
799#define K800_PLL_66_750M 0x00948C82 /* 67.116MHz */
800#define K800_PLL_68_179M 0x00708C01
801#define K800_PLL_69_924M 0x00C18C83
802#define K800_PLL_70_159M 0x00C28C83
803#define K800_PLL_72_000M 0x009F8C82
804#define K800_PLL_74_270M 0x00ce0c03
805#define K800_PLL_78_750M 0x00408801
806#define K800_PLL_80_136M 0x00428801
807#define K800_PLL_83_375M 0x005B0882
808#define K800_PLL_83_950M 0x00738803
809#define K800_PLL_84_750M 0x00748883 /* 84.477MHz */
810#define K800_PLL_85_860M 0x00768883
811#define K800_PLL_88_750M 0x007A8883
812#define K800_PLL_94_500M 0x00828803
813#define K800_PLL_97_750M 0x00878883
814#define K800_PLL_101_000M 0x008B8883
815#define K800_PLL_106_500M 0x00758882 /* 106.491463 MHz */
816#define K800_PLL_108_000M 0x00778882
817#define K800_PLL_113_309M 0x005D8881
818#define K800_PLL_118_840M 0x00A48883
819#define K800_PLL_119_000M 0x00838882
820#define K800_PLL_121_750M 0x00A88883 /* 121.704MHz */
821#define K800_PLL_125_104M 0x00688801
822#define K800_PLL_133_308M 0x005D8801
823#define K800_PLL_135_000M 0x001A4081
824#define K800_PLL_136_700M 0x00BD8883
825#define K800_PLL_138_400M 0x00728881
826#define K800_PLL_146_760M 0x00CC8883
827#define K800_PLL_148_500M 0x00ce0803
828#define K800_PLL_153_920M 0x00548482
829#define K800_PLL_156_000M 0x006B8483
830#define K800_PLL_157_500M 0x00142080
831#define K800_PLL_162_000M 0x006F8483
832#define K800_PLL_187_000M 0x00818483
833#define K800_PLL_193_295M 0x004F8481
834#define K800_PLL_202_500M 0x00538481
835#define K800_PLL_204_000M 0x008D8483
836#define K800_PLL_218_500M 0x00978483
837#define K800_PLL_234_000M 0x00608401
838#define K800_PLL_267_250M 0x006E8481
839#define K800_PLL_297_500M 0x00A48402
840#define K800_PLL_74_481M 0x007B8C81
841#define K800_PLL_172_798M 0x00778483
842#define K800_PLL_122_614M 0x00878882
843
844/* PLL for VT3324 */
845#define CX700_25_175M 0x008B1003
846#define CX700_26_719M 0x00931003
847#define CX700_26_880M 0x00941003
848#define CX700_29_581M 0x00A49003
849#define CX700_31_490M 0x00AE1003
850#define CX700_31_500M 0x00AE1003
851#define CX700_31_728M 0x00AF1003
852#define CX700_32_668M 0x00B51003
853#define CX700_36_000M 0x00C81003
854#define CX700_40_000M 0x006E0C03
855#define CX700_41_291M 0x00710C03
856#define CX700_43_163M 0x00770C03
857#define CX700_45_250M 0x007D0C03 /* 45.46MHz */
858#define CX700_46_000M 0x007F0C03
859#define CX700_46_996M 0x00818C83
860#define CX700_48_000M 0x00840C03
861#define CX700_48_875M 0x00508C81
862#define CX700_49_500M 0x00880C03
863#define CX700_52_406M 0x00730C02
864#define CX700_52_977M 0x00920C03
865#define CX700_56_250M 0x009B0C03
866#define CX700_60_466M 0x00460C00
867#define CX700_61_500M 0x00AA0C03
868#define CX700_65_000M 0x006B0C01
869#define CX700_65_178M 0x006B0C01
870#define CX700_66_750M 0x00940C02 /*67.116MHz */
871#define CX700_68_179M 0x00BC0C03
872#define CX700_69_924M 0x00C10C03
873#define CX700_70_159M 0x00C20C03
874#define CX700_72_000M 0x009F0C02
875#define CX700_74_270M 0x00CE0C03
876#define CX700_74_481M 0x00CE0C03
877#define CX700_78_750M 0x006C0803
878#define CX700_80_136M 0x006E0803
879#define CX700_83_375M 0x005B0882
880#define CX700_83_950M 0x00730803
881#define CX700_84_750M 0x00740803 /* 84.537Mhz */
882#define CX700_85_860M 0x00760803
883#define CX700_88_750M 0x00AC8885
884#define CX700_94_500M 0x00820803
885#define CX700_97_750M 0x00870803
886#define CX700_101_000M 0x008B0803
887#define CX700_106_500M 0x00750802
888#define CX700_108_000M 0x00950803
889#define CX700_113_309M 0x005D0801
890#define CX700_118_840M 0x00A40803
891#define CX700_119_000M 0x00830802
892#define CX700_121_750M 0x00420800 /* 121.704MHz */
893#define CX700_125_104M 0x00AD0803
894#define CX700_133_308M 0x00930802
895#define CX700_135_000M 0x00950802
896#define CX700_136_700M 0x00BD0803
897#define CX700_138_400M 0x00720801
898#define CX700_146_760M 0x00CC0803
899#define CX700_148_500M 0x00a40802
900#define CX700_153_920M 0x00540402
901#define CX700_156_000M 0x006B0403
902#define CX700_157_500M 0x006C0403
903#define CX700_162_000M 0x006F0403
904#define CX700_172_798M 0x00770403
905#define CX700_187_000M 0x00810403
906#define CX700_193_295M 0x00850403
907#define CX700_202_500M 0x008C0403
908#define CX700_204_000M 0x008D0403
909#define CX700_218_500M 0x00970403
910#define CX700_234_000M 0x00600401
911#define CX700_267_250M 0x00B90403
912#define CX700_297_500M 0x00CE0403
913#define CX700_122_614M 0x00870802
914
915/* PLL for VX855 */
916#define VX855_22_000M 0x007B1005
917#define VX855_25_175M 0x008D1005
918#define VX855_26_719M 0x00961005
919#define VX855_26_880M 0x00961005
920#define VX855_27_000M 0x00971005
921#define VX855_29_581M 0x00A51005
922#define VX855_29_829M 0x00641003
923#define VX855_31_490M 0x00B01005
924#define VX855_31_500M 0x00B01005
925#define VX855_31_728M 0x008E1004
926#define VX855_32_668M 0x00921004
927#define VX855_36_000M 0x00A11004
928#define VX855_40_000M 0x00700C05
929#define VX855_41_291M 0x00730C05
930#define VX855_43_163M 0x00790C05
931#define VX855_45_250M 0x007F0C05 /* 45.46MHz */
932#define VX855_46_000M 0x00670C04
933#define VX855_46_996M 0x00690C04
934#define VX855_48_000M 0x00860C05
935#define VX855_48_875M 0x00890C05
936#define VX855_49_500M 0x00530C03
937#define VX855_52_406M 0x00580C03
938#define VX855_52_977M 0x00940C05
939#define VX855_56_250M 0x009D0C05
940#define VX855_57_275M 0x009D8C85 /* Used by XO panel */
941#define VX855_60_466M 0x00A90C05
942#define VX855_61_500M 0x00AC0C05
943#define VX855_65_000M 0x006D0C03
944#define VX855_65_178M 0x00B60C05
945#define VX855_66_750M 0x00700C03 /*67.116MHz */
946#define VX855_67_295M 0x00BC0C05
947#define VX855_68_179M 0x00BF0C05
948#define VX855_68_369M 0x00BF0C05
949#define VX855_69_924M 0x00C30C05
950#define VX855_70_159M 0x00C30C05
951#define VX855_72_000M 0x00A10C04
952#define VX855_73_023M 0x00CC0C05
953#define VX855_74_481M 0x00D10C05
954#define VX855_78_750M 0x006E0805
955#define VX855_79_466M 0x006F0805
956#define VX855_80_136M 0x00700805
957#define VX855_81_627M 0x00720805
958#define VX855_83_375M 0x00750805
959#define VX855_83_527M 0x00750805
960#define VX855_83_950M 0x00750805
961#define VX855_84_537M 0x00760805
962#define VX855_84_750M 0x00760805 /* 84.537Mhz */
963#define VX855_85_500M 0x00760805 /* 85.909080 MHz*/
964#define VX855_85_860M 0x00760805
965#define VX855_85_909M 0x00760805
966#define VX855_88_750M 0x007C0805
967#define VX855_89_489M 0x007D0805
968#define VX855_94_500M 0x00840805
969#define VX855_96_648M 0x00870805
970#define VX855_97_750M 0x00890805
971#define VX855_101_000M 0x008D0805
972#define VX855_106_500M 0x00950805
973#define VX855_108_000M 0x00970805
974#define VX855_110_125M 0x00990805
975#define VX855_112_000M 0x009D0805
976#define VX855_113_309M 0x009F0805
977#define VX855_115_000M 0x00A10805
978#define VX855_118_840M 0x00A60805
979#define VX855_119_000M 0x00A70805
980#define VX855_121_750M 0x00AA0805 /* 121.704MHz */
981#define VX855_122_614M 0x00AC0805
982#define VX855_126_266M 0x00B10805
983#define VX855_130_250M 0x00B60805 /* 130.250 */
984#define VX855_135_000M 0x00BD0805
985#define VX855_136_700M 0x00BF0805
986#define VX855_137_750M 0x00C10805
987#define VX855_138_400M 0x00C20805
988#define VX855_144_300M 0x00CA0805
989#define VX855_146_760M 0x00CE0805
990#define VX855_148_500M 0x00D00805
991#define VX855_153_920M 0x00540402
992#define VX855_156_000M 0x006C0405
993#define VX855_156_867M 0x006E0405
994#define VX855_157_500M 0x006E0405
995#define VX855_162_000M 0x00710405
996#define VX855_172_798M 0x00790405
997#define VX855_187_000M 0x00830405
998#define VX855_193_295M 0x00870405
999#define VX855_202_500M 0x008E0405
1000#define VX855_204_000M 0x008F0405
1001#define VX855_218_500M 0x00990405
1002#define VX855_229_500M 0x00A10405
1003#define VX855_234_000M 0x00A40405
1004#define VX855_267_250M 0x00BB0405
1005#define VX855_297_500M 0x00D00405
1006#define VX855_339_500M 0x00770005
1007#define VX855_340_772M 0x00770005
1008
1009 700
1010/* Definition CRTC Timing Index */ 701/* Definition CRTC Timing Index */
1011#define H_TOTAL_INDEX 0 702#define H_TOTAL_INDEX 0
diff --git a/drivers/video/via/via-core.c b/drivers/video/via/via-core.c
index e8cfe8392110..66f403033111 100644
--- a/drivers/video/via/via-core.c
+++ b/drivers/video/via/via-core.c
@@ -64,7 +64,7 @@ static inline int viafb_mmio_read(int reg)
64 */ 64 */
65static u32 viafb_enabled_ints; 65static u32 viafb_enabled_ints;
66 66
67static void viafb_int_init(void) 67static void __devinit viafb_int_init(void)
68{ 68{
69 viafb_enabled_ints = 0; 69 viafb_enabled_ints = 0;
70 70
@@ -489,7 +489,7 @@ out_unmap:
489 return ret; 489 return ret;
490} 490}
491 491
492static void __devexit via_pci_teardown_mmio(struct viafb_dev *vdev) 492static void via_pci_teardown_mmio(struct viafb_dev *vdev)
493{ 493{
494 iounmap(vdev->fbmem); 494 iounmap(vdev->fbmem);
495 iounmap(vdev->engine_mmio); 495 iounmap(vdev->engine_mmio);
@@ -548,7 +548,7 @@ static int __devinit via_setup_subdevs(struct viafb_dev *vdev)
548 return 0; 548 return 0;
549} 549}
550 550
551static void __devexit via_teardown_subdevs(void) 551static void via_teardown_subdevs(void)
552{ 552{
553 int i; 553 int i;
554 554
@@ -613,22 +613,24 @@ static void __devexit via_pci_remove(struct pci_dev *pdev)
613static struct pci_device_id via_pci_table[] __devinitdata = { 613static struct pci_device_id via_pci_table[] __devinitdata = {
614 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_CLE266_DID), 614 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_CLE266_DID),
615 .driver_data = UNICHROME_CLE266 }, 615 .driver_data = UNICHROME_CLE266 },
616 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_PM800_DID),
617 .driver_data = UNICHROME_PM800 },
618 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_K400_DID), 616 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_K400_DID),
619 .driver_data = UNICHROME_K400 }, 617 .driver_data = UNICHROME_K400 },
620 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_K800_DID), 618 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_K800_DID),
621 .driver_data = UNICHROME_K800 }, 619 .driver_data = UNICHROME_K800 },
622 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_P4M890_DID), 620 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_PM800_DID),
621 .driver_data = UNICHROME_PM800 },
622 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_CN700_DID),
623 .driver_data = UNICHROME_CN700 }, 623 .driver_data = UNICHROME_CN700 },
624 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_K8M890_DID),
625 .driver_data = UNICHROME_K8M890 },
626 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_CX700_DID), 624 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_CX700_DID),
627 .driver_data = UNICHROME_CX700 }, 625 .driver_data = UNICHROME_CX700 },
628 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_P4M900_DID),
629 .driver_data = UNICHROME_P4M900 },
630 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_CN750_DID), 626 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_CN750_DID),
631 .driver_data = UNICHROME_CN750 }, 627 .driver_data = UNICHROME_CN750 },
628 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_K8M890_DID),
629 .driver_data = UNICHROME_K8M890 },
630 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_P4M890_DID),
631 .driver_data = UNICHROME_P4M890 },
632 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_P4M900_DID),
633 .driver_data = UNICHROME_P4M900 },
632 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_VX800_DID), 634 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_VX800_DID),
633 .driver_data = UNICHROME_VX800 }, 635 .driver_data = UNICHROME_VX800 },
634 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_VX855_DID), 636 { PCI_DEVICE(PCI_VENDOR_ID_VIA, UNICHROME_VX855_DID),
diff --git a/drivers/video/via/via-gpio.c b/drivers/video/via/via-gpio.c
index 595516aea691..39acb37e7a1d 100644
--- a/drivers/video/via/via-gpio.c
+++ b/drivers/video/via/via-gpio.c
@@ -73,7 +73,7 @@ struct viafb_gpio_cfg {
73 struct gpio_chip gpio_chip; 73 struct gpio_chip gpio_chip;
74 struct viafb_dev *vdev; 74 struct viafb_dev *vdev;
75 struct viafb_gpio *active_gpios[VIAFB_NUM_GPIOS]; 75 struct viafb_gpio *active_gpios[VIAFB_NUM_GPIOS];
76 char *gpio_names[VIAFB_NUM_GPIOS]; 76 const char *gpio_names[VIAFB_NUM_GPIOS];
77}; 77};
78 78
79/* 79/*
diff --git a/drivers/video/via/viafbdev.c b/drivers/video/via/viafbdev.c
index 1082541358f0..bdd0e4130f4e 100644
--- a/drivers/video/via/viafbdev.c
+++ b/drivers/video/via/viafbdev.c
@@ -49,11 +49,6 @@ char *viafb_active_dev;
49char *viafb_lcd_port = ""; 49char *viafb_lcd_port = "";
50char *viafb_dvi_port = ""; 50char *viafb_dvi_port = "";
51 51
52static void viafb_set_device(struct device_t active_dev);
53static int apply_device_setting(struct viafb_ioctl_setting setting_info,
54 struct fb_info *info);
55static void apply_second_mode_setting(struct fb_var_screeninfo
56 *sec_var);
57static void retrieve_device_setting(struct viafb_ioctl_setting 52static void retrieve_device_setting(struct viafb_ioctl_setting
58 *setting_info); 53 *setting_info);
59static int viafb_pan_display(struct fb_var_screeninfo *var, 54static int viafb_pan_display(struct fb_var_screeninfo *var,
@@ -221,9 +216,9 @@ static int viafb_check_var(struct fb_var_screeninfo *var,
221 216
222 /* Adjust var according to our driver's own table */ 217 /* Adjust var according to our driver's own table */
223 viafb_fill_var_timing_info(var, viafb_refresh, vmode_entry); 218 viafb_fill_var_timing_info(var, viafb_refresh, vmode_entry);
224 if (info->var.accel_flags & FB_ACCELF_TEXT && 219 if (var->accel_flags & FB_ACCELF_TEXT &&
225 !ppar->shared->vdev->engine_mmio) 220 !ppar->shared->vdev->engine_mmio)
226 info->var.accel_flags = 0; 221 var->accel_flags = 0;
227 222
228 return 0; 223 return 0;
229} 224}
@@ -234,6 +229,7 @@ static int viafb_set_par(struct fb_info *info)
234 struct VideoModeTable *vmode_entry, *vmode_entry1 = NULL; 229 struct VideoModeTable *vmode_entry, *vmode_entry1 = NULL;
235 DEBUG_MSG(KERN_INFO "viafb_set_par!\n"); 230 DEBUG_MSG(KERN_INFO "viafb_set_par!\n");
236 231
232 viafb_update_fix(info);
237 viapar->depth = fb_get_color_depth(&info->var, &info->fix); 233 viapar->depth = fb_get_color_depth(&info->var, &info->fix);
238 viafb_update_device_setting(viafbinfo->var.xres, viafbinfo->var.yres, 234 viafb_update_device_setting(viafbinfo->var.xres, viafbinfo->var.yres,
239 viafbinfo->var.bits_per_pixel, viafb_refresh, 0); 235 viafbinfo->var.bits_per_pixel, viafb_refresh, 0);
@@ -257,7 +253,6 @@ static int viafb_set_par(struct fb_info *info)
257 } 253 }
258 254
259 if (vmode_entry) { 255 if (vmode_entry) {
260 viafb_update_fix(info);
261 if (viafb_dual_fb && viapar->iga_path == IGA2) 256 if (viafb_dual_fb && viapar->iga_path == IGA2)
262 viafb_bpp1 = info->var.bits_per_pixel; 257 viafb_bpp1 = info->var.bits_per_pixel;
263 else 258 else
@@ -478,13 +473,6 @@ static int viafb_ioctl(struct fb_info *info, u_int cmd, u_long arg)
478 if (gpu32 & LCD_Device) 473 if (gpu32 & LCD_Device)
479 viafb_lcd_disable(); 474 viafb_lcd_disable();
480 break; 475 break;
481 case VIAFB_SET_DEVICE:
482 if (copy_from_user(&u.active_dev, (void *)argp,
483 sizeof(u.active_dev)))
484 return -EFAULT;
485 viafb_set_device(u.active_dev);
486 viafb_set_par(info);
487 break;
488 case VIAFB_GET_DEVICE: 476 case VIAFB_GET_DEVICE:
489 u.active_dev.crt = viafb_CRT_ON; 477 u.active_dev.crt = viafb_CRT_ON;
490 u.active_dev.dvi = viafb_DVI_ON; 478 u.active_dev.dvi = viafb_DVI_ON;
@@ -527,21 +515,6 @@ static int viafb_ioctl(struct fb_info *info, u_int cmd, u_long arg)
527 515
528 break; 516 break;
529 517
530 case VIAFB_SET_DEVICE_INFO:
531 if (copy_from_user(&u.viafb_setting,
532 argp, sizeof(u.viafb_setting)))
533 return -EFAULT;
534 if (apply_device_setting(u.viafb_setting, info) < 0)
535 return -EINVAL;
536
537 break;
538
539 case VIAFB_SET_SECOND_MODE:
540 if (copy_from_user(&u.sec_var, argp, sizeof(u.sec_var)))
541 return -EFAULT;
542 apply_second_mode_setting(&u.sec_var);
543 break;
544
545 case VIAFB_GET_DEVICE_INFO: 518 case VIAFB_GET_DEVICE_INFO:
546 519
547 retrieve_device_setting(&u.viafb_setting); 520 retrieve_device_setting(&u.viafb_setting);
@@ -913,112 +886,6 @@ static int viafb_sync(struct fb_info *info)
913 return 0; 886 return 0;
914} 887}
915 888
916static void check_available_device_to_enable(int device_id)
917{
918 int device_num = 0;
919
920 /* Initialize: */
921 viafb_CRT_ON = STATE_OFF;
922 viafb_DVI_ON = STATE_OFF;
923 viafb_LCD_ON = STATE_OFF;
924 viafb_LCD2_ON = STATE_OFF;
925 viafb_DeviceStatus = None_Device;
926
927 if ((device_id & CRT_Device) && (device_num < MAX_ACTIVE_DEV_NUM)) {
928 viafb_CRT_ON = STATE_ON;
929 device_num++;
930 viafb_DeviceStatus |= CRT_Device;
931 }
932
933 if ((device_id & DVI_Device) && (device_num < MAX_ACTIVE_DEV_NUM)) {
934 viafb_DVI_ON = STATE_ON;
935 device_num++;
936 viafb_DeviceStatus |= DVI_Device;
937 }
938
939 if ((device_id & LCD_Device) && (device_num < MAX_ACTIVE_DEV_NUM)) {
940 viafb_LCD_ON = STATE_ON;
941 device_num++;
942 viafb_DeviceStatus |= LCD_Device;
943 }
944
945 if ((device_id & LCD2_Device) && (device_num < MAX_ACTIVE_DEV_NUM)) {
946 viafb_LCD2_ON = STATE_ON;
947 device_num++;
948 viafb_DeviceStatus |= LCD2_Device;
949 }
950
951 if (viafb_DeviceStatus == None_Device) {
952 /* Use CRT as default active device: */
953 viafb_CRT_ON = STATE_ON;
954 viafb_DeviceStatus = CRT_Device;
955 }
956 DEBUG_MSG(KERN_INFO "Device Status:%x", viafb_DeviceStatus);
957}
958
959static void viafb_set_device(struct device_t active_dev)
960{
961 /* Check available device to enable: */
962 int device_id = None_Device;
963 if (active_dev.crt)
964 device_id |= CRT_Device;
965 if (active_dev.dvi)
966 device_id |= DVI_Device;
967 if (active_dev.lcd)
968 device_id |= LCD_Device;
969
970 check_available_device_to_enable(device_id);
971
972 /* Check property of LCD: */
973 if (viafb_LCD_ON) {
974 if (active_dev.lcd_dsp_cent) {
975 viaparinfo->lvds_setting_info->display_method =
976 viafb_lcd_dsp_method = LCD_CENTERING;
977 } else {
978 viaparinfo->lvds_setting_info->display_method =
979 viafb_lcd_dsp_method = LCD_EXPANDSION;
980 }
981
982 if (active_dev.lcd_mode == LCD_SPWG) {
983 viaparinfo->lvds_setting_info->lcd_mode =
984 viafb_lcd_mode = LCD_SPWG;
985 } else {
986 viaparinfo->lvds_setting_info->lcd_mode =
987 viafb_lcd_mode = LCD_OPENLDI;
988 }
989
990 if (active_dev.lcd_panel_id <= LCD_PANEL_ID_MAXIMUM) {
991 viafb_lcd_panel_id = active_dev.lcd_panel_id;
992 viafb_init_lcd_size();
993 }
994 }
995
996 /* Check property of mode: */
997 if (!active_dev.xres1)
998 viafb_second_xres = 640;
999 else
1000 viafb_second_xres = active_dev.xres1;
1001 if (!active_dev.yres1)
1002 viafb_second_yres = 480;
1003 else
1004 viafb_second_yres = active_dev.yres1;
1005 if (active_dev.bpp != 0)
1006 viafb_bpp = active_dev.bpp;
1007 if (active_dev.bpp1 != 0)
1008 viafb_bpp1 = active_dev.bpp1;
1009 if (active_dev.refresh != 0)
1010 viafb_refresh = active_dev.refresh;
1011 if (active_dev.refresh1 != 0)
1012 viafb_refresh1 = active_dev.refresh1;
1013 if ((active_dev.samm == STATE_OFF) || (active_dev.samm == STATE_ON))
1014 viafb_SAMM_ON = active_dev.samm;
1015 viafb_primary_dev = active_dev.primary_dev;
1016
1017 via_set_primary_address(0);
1018 via_set_secondary_address(viafb_SAMM_ON ? viafb_second_offset : 0);
1019 viafb_set_iga_path();
1020}
1021
1022static int get_primary_device(void) 889static int get_primary_device(void)
1023{ 890{
1024 int primary_device = 0; 891 int primary_device = 0;
@@ -1060,124 +927,6 @@ static int get_primary_device(void)
1060 return primary_device; 927 return primary_device;
1061} 928}
1062 929
1063static void apply_second_mode_setting(struct fb_var_screeninfo
1064 *sec_var)
1065{
1066 u32 htotal, vtotal, long_refresh;
1067
1068 htotal = sec_var->xres + sec_var->left_margin +
1069 sec_var->right_margin + sec_var->hsync_len;
1070 vtotal = sec_var->yres + sec_var->upper_margin +
1071 sec_var->lower_margin + sec_var->vsync_len;
1072 if ((sec_var->xres_virtual * (sec_var->bits_per_pixel >> 3)) & 0x1F) {
1073 /*Is 32 bytes alignment? */
1074 /*32 pixel alignment */
1075 sec_var->xres_virtual = (sec_var->xres_virtual + 31) & ~31;
1076 }
1077
1078 htotal = sec_var->xres + sec_var->left_margin +
1079 sec_var->right_margin + sec_var->hsync_len;
1080 vtotal = sec_var->yres + sec_var->upper_margin +
1081 sec_var->lower_margin + sec_var->vsync_len;
1082 long_refresh = 1000000000UL / sec_var->pixclock * 1000;
1083 long_refresh /= (htotal * vtotal);
1084
1085 viafb_second_xres = sec_var->xres;
1086 viafb_second_yres = sec_var->yres;
1087 viafb_second_virtual_xres = sec_var->xres_virtual;
1088 viafb_second_virtual_yres = sec_var->yres_virtual;
1089 viafb_bpp1 = sec_var->bits_per_pixel;
1090 viafb_refresh1 = viafb_get_refresh(sec_var->xres, sec_var->yres,
1091 long_refresh);
1092}
1093
1094static int apply_device_setting(struct viafb_ioctl_setting setting_info,
1095 struct fb_info *info)
1096{
1097 int need_set_mode = 0;
1098 DEBUG_MSG(KERN_INFO "apply_device_setting\n");
1099
1100 if (setting_info.device_flag) {
1101 need_set_mode = 1;
1102 check_available_device_to_enable(setting_info.device_status);
1103 }
1104
1105 /* Unlock LCD's operation according to LCD flag
1106 and check if the setting value is valid. */
1107 /* If the value is valid, apply the new setting value to the device. */
1108 if (viafb_LCD_ON) {
1109 if (setting_info.lcd_operation_flag & OP_LCD_CENTERING) {
1110 need_set_mode = 1;
1111 if (setting_info.lcd_attributes.display_center) {
1112 /* Centering */
1113 viaparinfo->lvds_setting_info->display_method =
1114 LCD_CENTERING;
1115 viafb_lcd_dsp_method = LCD_CENTERING;
1116 viaparinfo->lvds_setting_info2->display_method =
1117 viafb_lcd_dsp_method = LCD_CENTERING;
1118 } else {
1119 /* expandsion */
1120 viaparinfo->lvds_setting_info->display_method =
1121 LCD_EXPANDSION;
1122 viafb_lcd_dsp_method = LCD_EXPANDSION;
1123 viaparinfo->lvds_setting_info2->display_method =
1124 LCD_EXPANDSION;
1125 viafb_lcd_dsp_method = LCD_EXPANDSION;
1126 }
1127 }
1128
1129 if (setting_info.lcd_operation_flag & OP_LCD_MODE) {
1130 need_set_mode = 1;
1131 if (setting_info.lcd_attributes.lcd_mode ==
1132 LCD_SPWG) {
1133 viaparinfo->lvds_setting_info->lcd_mode =
1134 viafb_lcd_mode = LCD_SPWG;
1135 } else {
1136 viaparinfo->lvds_setting_info->lcd_mode =
1137 viafb_lcd_mode = LCD_OPENLDI;
1138 }
1139 viaparinfo->lvds_setting_info2->lcd_mode =
1140 viaparinfo->lvds_setting_info->lcd_mode;
1141 }
1142
1143 if (setting_info.lcd_operation_flag & OP_LCD_PANEL_ID) {
1144 need_set_mode = 1;
1145 if (setting_info.lcd_attributes.panel_id <=
1146 LCD_PANEL_ID_MAXIMUM) {
1147 viafb_lcd_panel_id =
1148 setting_info.lcd_attributes.panel_id;
1149 viafb_init_lcd_size();
1150 }
1151 }
1152 }
1153
1154 if (0 != (setting_info.samm_status & OP_SAMM)) {
1155 setting_info.samm_status =
1156 setting_info.samm_status & (~OP_SAMM);
1157 if (setting_info.samm_status == 0
1158 || setting_info.samm_status == 1) {
1159 viafb_SAMM_ON = setting_info.samm_status;
1160
1161 if (viafb_SAMM_ON)
1162 viafb_primary_dev = setting_info.primary_device;
1163
1164 via_set_primary_address(0);
1165 via_set_secondary_address(viafb_SAMM_ON ?
1166 viafb_second_offset : 0);
1167 viafb_set_iga_path();
1168 }
1169 need_set_mode = 1;
1170 }
1171
1172 if (!need_set_mode) {
1173 ;
1174 } else {
1175 viafb_set_iga_path();
1176 viafb_set_par(info);
1177 }
1178 return true;
1179}
1180
1181static void retrieve_device_setting(struct viafb_ioctl_setting 930static void retrieve_device_setting(struct viafb_ioctl_setting
1182 *setting_info) 931 *setting_info)
1183{ 932{
@@ -1776,10 +1525,6 @@ int __devinit via_fb_pci_probe(struct viafb_dev *vdev)
1776 parse_lcd_port(); 1525 parse_lcd_port();
1777 parse_dvi_port(); 1526 parse_dvi_port();
1778 1527
1779 /* for dual-fb must viafb_SAMM_ON=1 and viafb_dual_fb=1 */
1780 if (!viafb_SAMM_ON)
1781 viafb_dual_fb = 0;
1782
1783 viafb_init_chip_info(vdev->chip_type); 1528 viafb_init_chip_info(vdev->chip_type);
1784 /* 1529 /*
1785 * The framebuffer will have been successfully mapped by 1530 * The framebuffer will have been successfully mapped by
@@ -1823,30 +1568,13 @@ int __devinit via_fb_pci_probe(struct viafb_dev *vdev)
1823 parse_mode(viafb_mode1, &viafb_second_xres, 1568 parse_mode(viafb_mode1, &viafb_second_xres,
1824 &viafb_second_yres); 1569 &viafb_second_yres);
1825 1570
1826 if (0 == viafb_second_virtual_xres) { 1571 viafb_second_virtual_xres = viafb_second_xres;
1827 switch (viafb_second_xres) { 1572 viafb_second_virtual_yres = viafb_second_yres;
1828 case 1400:
1829 viafb_second_virtual_xres = 1408;
1830 break;
1831 default:
1832 viafb_second_virtual_xres = viafb_second_xres;
1833 break;
1834 }
1835 }
1836 if (0 == viafb_second_virtual_yres)
1837 viafb_second_virtual_yres = viafb_second_yres;
1838 } 1573 }
1839 1574
1840 default_var.xres = default_xres; 1575 default_var.xres = default_xres;
1841 default_var.yres = default_yres; 1576 default_var.yres = default_yres;
1842 switch (default_xres) { 1577 default_var.xres_virtual = default_xres;
1843 case 1400:
1844 default_var.xres_virtual = 1408;
1845 break;
1846 default:
1847 default_var.xres_virtual = default_xres;
1848 break;
1849 }
1850 default_var.yres_virtual = default_yres; 1578 default_var.yres_virtual = default_yres;
1851 default_var.bits_per_pixel = viafb_bpp; 1579 default_var.bits_per_pixel = viafb_bpp;
1852 default_var.pixclock = 1580 default_var.pixclock =
diff --git a/drivers/video/vt8623fb.c b/drivers/video/vt8623fb.c
index d31dc96f838a..85d76ec4c63e 100644
--- a/drivers/video/vt8623fb.c
+++ b/drivers/video/vt8623fb.c
@@ -726,7 +726,9 @@ static int __devinit vt8623_pci_probe(struct pci_dev *dev, const struct pci_devi
726 726
727 /* Prepare startup mode */ 727 /* Prepare startup mode */
728 728
729 kparam_block_sysfs_write(mode_option);
729 rc = fb_find_mode(&(info->var), info, mode_option, NULL, 0, NULL, 8); 730 rc = fb_find_mode(&(info->var), info, mode_option, NULL, 0, NULL, 8);
731 kparam_unblock_sysfs_write(mode_option);
730 if (! ((rc == 1) || (rc == 2))) { 732 if (! ((rc == 1) || (rc == 2))) {
731 rc = -EINVAL; 733 rc = -EINVAL;
732 dev_err(info->device, "mode %s not found\n", mode_option); 734 dev_err(info->device, "mode %s not found\n", mode_option);
diff --git a/drivers/video/w100fb.c b/drivers/video/w100fb.c
index e66b8b19ce5d..d8b12c32e3ef 100644
--- a/drivers/video/w100fb.c
+++ b/drivers/video/w100fb.c
@@ -858,9 +858,9 @@ unsigned long w100fb_gpio_read(int port)
858void w100fb_gpio_write(int port, unsigned long value) 858void w100fb_gpio_write(int port, unsigned long value)
859{ 859{
860 if (port==W100_GPIO_PORT_A) 860 if (port==W100_GPIO_PORT_A)
861 value = writel(value, remapped_regs + mmGPIO_DATA); 861 writel(value, remapped_regs + mmGPIO_DATA);
862 else 862 else
863 value = writel(value, remapped_regs + mmGPIO_DATA2); 863 writel(value, remapped_regs + mmGPIO_DATA2);
864} 864}
865EXPORT_SYMBOL(w100fb_gpio_read); 865EXPORT_SYMBOL(w100fb_gpio_read);
866EXPORT_SYMBOL(w100fb_gpio_write); 866EXPORT_SYMBOL(w100fb_gpio_write);
diff --git a/drivers/video/xilinxfb.c b/drivers/video/xilinxfb.c
index 29b5daacc217..0c9ce88e95e8 100644
--- a/drivers/video/xilinxfb.c
+++ b/drivers/video/xilinxfb.c
@@ -397,7 +397,7 @@ static int xilinxfb_release(struct device *dev)
397 */ 397 */
398 398
399static int __devinit 399static int __devinit
400xilinxfb_of_probe(struct of_device *op, const struct of_device_id *match) 400xilinxfb_of_probe(struct platform_device *op, const struct of_device_id *match)
401{ 401{
402 const u32 *prop; 402 const u32 *prop;
403 u32 *p; 403 u32 *p;
@@ -477,7 +477,7 @@ xilinxfb_of_probe(struct of_device *op, const struct of_device_id *match)
477 return -ENODEV; 477 return -ENODEV;
478} 478}
479 479
480static int __devexit xilinxfb_of_remove(struct of_device *op) 480static int __devexit xilinxfb_of_remove(struct platform_device *op)
481{ 481{
482 return xilinxfb_release(&op->dev); 482 return xilinxfb_release(&op->dev);
483} 483}
diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index b04b18468932..b036677df8c4 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -73,6 +73,13 @@ config WM8350_WATCHDOG
73 73
74# ARM Architecture 74# ARM Architecture
75 75
76config ARM_SP805_WATCHDOG
77 tristate "ARM SP805 Watchdog"
78 depends on ARM_AMBA
79 help
80 ARM Primecell SP805 Watchdog timer. This will reboot your system when
81 the timeout is reached.
82
76config AT91RM9200_WATCHDOG 83config AT91RM9200_WATCHDOG
77 tristate "AT91RM9200 watchdog" 84 tristate "AT91RM9200 watchdog"
78 depends on ARCH_AT91RM9200 85 depends on ARCH_AT91RM9200
@@ -401,6 +408,17 @@ config ALIM7101_WDT
401 408
402 Most people will say N. 409 Most people will say N.
403 410
411config F71808E_WDT
412 tristate "Fintek F71808E and F71882FG Watchdog"
413 depends on X86 && EXPERIMENTAL
414 help
415 This is the driver for the hardware watchdog on the Fintek
416 F71808E and F71882FG Super I/O controllers.
417
418 You can compile this driver directly into the kernel, or use
419 it as a module. The module will be called f71808e_wdt.
420
421
404config GEODE_WDT 422config GEODE_WDT
405 tristate "AMD Geode CS5535/CS5536 Watchdog" 423 tristate "AMD Geode CS5535/CS5536 Watchdog"
406 depends on CS5535_MFGPT 424 depends on CS5535_MFGPT
@@ -556,16 +574,21 @@ config IT87_WDT
556 be called it87_wdt. 574 be called it87_wdt.
557 575
558config HP_WATCHDOG 576config HP_WATCHDOG
559 tristate "HP Proliant iLO 2 Hardware Watchdog Timer" 577 tristate "HP Proliant iLO2+ Hardware Watchdog Timer"
560 depends on X86 578 depends on X86
561 help 579 help
562 A software monitoring watchdog and NMI sourcing driver. This driver 580 A software monitoring watchdog and NMI sourcing driver. This driver
563 will detect lockups and provide stack trace. Also, when an NMI 581 will detect lockups and provide a stack trace. This is a driver that
564 occurs this driver will make the necessary BIOS calls to log 582 will only load on a HP ProLiant system with a minimum of iLO2 support.
565 the cause of the NMI. This is a driver that will only load on a 583 To compile this driver as a module, choose M here: the module will be
566 HP ProLiant system with a minimum of iLO2 support. 584 called hpwdt.
567 To compile this driver as a module, choose M here: the 585
568 module will be called hpwdt. 586config HPWDT_NMI_DECODING
587 bool "NMI decoding support for the HP ProLiant iLO2+ Hardware Watchdog Timer"
588 depends on HP_WATCHDOG
589 help
590 When an NMI occurs this feature will make the necessary BIOS calls to
591 log the cause of the NMI.
569 592
570config SC1200_WDT 593config SC1200_WDT
571 tristate "National Semiconductor PC87307/PC97307 (ala SC1200) Watchdog" 594 tristate "National Semiconductor PC87307/PC97307 (ala SC1200) Watchdog"
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index e30289a5e367..8374503fcc6a 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -25,6 +25,7 @@ obj-$(CONFIG_USBPCWATCHDOG) += pcwd_usb.o
25# ALPHA Architecture 25# ALPHA Architecture
26 26
27# ARM Architecture 27# ARM Architecture
28obj-$(CONFIG_ARM_SP805_WATCHDOG) += sp805_wdt.o
28obj-$(CONFIG_AT91RM9200_WATCHDOG) += at91rm9200_wdt.o 29obj-$(CONFIG_AT91RM9200_WATCHDOG) += at91rm9200_wdt.o
29obj-$(CONFIG_AT91SAM9X_WATCHDOG) += at91sam9_wdt.o 30obj-$(CONFIG_AT91SAM9X_WATCHDOG) += at91sam9_wdt.o
30obj-$(CONFIG_OMAP_WATCHDOG) += omap_wdt.o 31obj-$(CONFIG_OMAP_WATCHDOG) += omap_wdt.o
@@ -66,6 +67,7 @@ obj-$(CONFIG_ACQUIRE_WDT) += acquirewdt.o
66obj-$(CONFIG_ADVANTECH_WDT) += advantechwdt.o 67obj-$(CONFIG_ADVANTECH_WDT) += advantechwdt.o
67obj-$(CONFIG_ALIM1535_WDT) += alim1535_wdt.o 68obj-$(CONFIG_ALIM1535_WDT) += alim1535_wdt.o
68obj-$(CONFIG_ALIM7101_WDT) += alim7101_wdt.o 69obj-$(CONFIG_ALIM7101_WDT) += alim7101_wdt.o
70obj-$(CONFIG_F71808E_WDT) += f71808e_wdt.o
69obj-$(CONFIG_GEODE_WDT) += geodewdt.o 71obj-$(CONFIG_GEODE_WDT) += geodewdt.o
70obj-$(CONFIG_SC520_WDT) += sc520_wdt.o 72obj-$(CONFIG_SC520_WDT) += sc520_wdt.o
71obj-$(CONFIG_SBC_FITPC2_WATCHDOG) += sbc_fitpc2_wdt.o 73obj-$(CONFIG_SBC_FITPC2_WATCHDOG) += sbc_fitpc2_wdt.o
diff --git a/drivers/watchdog/cpwd.c b/drivers/watchdog/cpwd.c
index 30a2512fd52e..566343b3c131 100644
--- a/drivers/watchdog/cpwd.c
+++ b/drivers/watchdog/cpwd.c
@@ -526,7 +526,7 @@ static const struct file_operations cpwd_fops = {
526 .release = cpwd_release, 526 .release = cpwd_release,
527}; 527};
528 528
529static int __devinit cpwd_probe(struct of_device *op, 529static int __devinit cpwd_probe(struct platform_device *op,
530 const struct of_device_id *match) 530 const struct of_device_id *match)
531{ 531{
532 struct device_node *options; 532 struct device_node *options;
@@ -639,7 +639,7 @@ out_free:
639 goto out; 639 goto out;
640} 640}
641 641
642static int __devexit cpwd_remove(struct of_device *op) 642static int __devexit cpwd_remove(struct platform_device *op)
643{ 643{
644 struct cpwd *p = dev_get_drvdata(&op->dev); 644 struct cpwd *p = dev_get_drvdata(&op->dev);
645 int i; 645 int i;
diff --git a/drivers/watchdog/f71808e_wdt.c b/drivers/watchdog/f71808e_wdt.c
new file mode 100644
index 000000000000..7e5c266cda48
--- /dev/null
+++ b/drivers/watchdog/f71808e_wdt.c
@@ -0,0 +1,768 @@
1/***************************************************************************
2 * Copyright (C) 2006 by Hans Edgington <hans@edgington.nl> *
3 * Copyright (C) 2007-2009 Hans de Goede <hdegoede@redhat.com> *
4 * Copyright (C) 2010 Giel van Schijndel <me@mortis.eu> *
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 *
18 * Free Software Foundation, Inc., *
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20 ***************************************************************************/
21
22#include <linux/err.h>
23#include <linux/fs.h>
24#include <linux/init.h>
25#include <linux/io.h>
26#include <linux/ioport.h>
27#include <linux/miscdevice.h>
28#include <linux/module.h>
29#include <linux/mutex.h>
30#include <linux/notifier.h>
31#include <linux/reboot.h>
32#include <linux/uaccess.h>
33#include <linux/watchdog.h>
34
35#define DRVNAME "f71808e_wdt"
36
37#define SIO_F71808FG_LD_WDT 0x07 /* Watchdog timer logical device */
38#define SIO_UNLOCK_KEY 0x87 /* Key to enable Super-I/O */
39#define SIO_LOCK_KEY 0xAA /* Key to diasble Super-I/O */
40
41#define SIO_REG_LDSEL 0x07 /* Logical device select */
42#define SIO_REG_DEVID 0x20 /* Device ID (2 bytes) */
43#define SIO_REG_DEVREV 0x22 /* Device revision */
44#define SIO_REG_MANID 0x23 /* Fintek ID (2 bytes) */
45#define SIO_REG_ENABLE 0x30 /* Logical device enable */
46#define SIO_REG_ADDR 0x60 /* Logical device address (2 bytes) */
47
48#define SIO_FINTEK_ID 0x1934 /* Manufacturers ID */
49#define SIO_F71808_ID 0x0901 /* Chipset ID */
50#define SIO_F71858_ID 0x0507 /* Chipset ID */
51#define SIO_F71862_ID 0x0601 /* Chipset ID */
52#define SIO_F71882_ID 0x0541 /* Chipset ID */
53#define SIO_F71889_ID 0x0723 /* Chipset ID */
54
55#define F71882FG_REG_START 0x01
56
57#define F71808FG_REG_WDO_CONF 0xf0
58#define F71808FG_REG_WDT_CONF 0xf5
59#define F71808FG_REG_WD_TIME 0xf6
60
61#define F71808FG_FLAG_WDOUT_EN 7
62
63#define F71808FG_FLAG_WDTMOUT_STS 5
64#define F71808FG_FLAG_WD_EN 5
65#define F71808FG_FLAG_WD_PULSE 4
66#define F71808FG_FLAG_WD_UNIT 3
67
68/* Default values */
69#define WATCHDOG_TIMEOUT 60 /* 1 minute default timeout */
70#define WATCHDOG_MAX_TIMEOUT (60 * 255)
71#define WATCHDOG_PULSE_WIDTH 125 /* 125 ms, default pulse width for
72 watchdog signal */
73
74static unsigned short force_id;
75module_param(force_id, ushort, 0);
76MODULE_PARM_DESC(force_id, "Override the detected device ID");
77
78static const int max_timeout = WATCHDOG_MAX_TIMEOUT;
79static int timeout = 60; /* default timeout in seconds */
80module_param(timeout, int, 0);
81MODULE_PARM_DESC(timeout,
82 "Watchdog timeout in seconds. 1<= timeout <="
83 __MODULE_STRING(WATCHDOG_MAX_TIMEOUT) " (default="
84 __MODULE_STRING(WATCHDOG_TIMEOUT) ")");
85
86static unsigned int pulse_width = WATCHDOG_PULSE_WIDTH;
87module_param(pulse_width, uint, 0);
88MODULE_PARM_DESC(pulse_width,
89 "Watchdog signal pulse width. 0(=level), 1 ms, 25 ms, 125 ms or 5000 ms"
90 " (default=" __MODULE_STRING(WATCHDOG_PULSE_WIDTH) ")");
91
92static int nowayout = WATCHDOG_NOWAYOUT;
93module_param(nowayout, bool, 0444);
94MODULE_PARM_DESC(nowayout, "Disable watchdog shutdown on close");
95
96static unsigned int start_withtimeout;
97module_param(start_withtimeout, uint, 0);
98MODULE_PARM_DESC(start_withtimeout, "Start watchdog timer on module load with"
99 " given initial timeout. Zero (default) disables this feature.");
100
101enum chips { f71808fg, f71858fg, f71862fg, f71882fg, f71889fg };
102
103static const char *f71808e_names[] = {
104 "f71808fg",
105 "f71858fg",
106 "f71862fg",
107 "f71882fg",
108 "f71889fg",
109};
110
111/* Super-I/O Function prototypes */
112static inline int superio_inb(int base, int reg);
113static inline int superio_inw(int base, int reg);
114static inline void superio_outb(int base, int reg, u8 val);
115static inline void superio_set_bit(int base, int reg, int bit);
116static inline void superio_clear_bit(int base, int reg, int bit);
117static inline int superio_enter(int base);
118static inline void superio_select(int base, int ld);
119static inline void superio_exit(int base);
120
121struct watchdog_data {
122 unsigned short sioaddr;
123 enum chips type;
124 unsigned long opened;
125 struct mutex lock;
126 char expect_close;
127 struct watchdog_info ident;
128
129 unsigned short timeout;
130 u8 timer_val; /* content for the wd_time register */
131 char minutes_mode;
132 u8 pulse_val; /* pulse width flag */
133 char pulse_mode; /* enable pulse output mode? */
134 char caused_reboot; /* last reboot was by the watchdog */
135};
136
137static struct watchdog_data watchdog = {
138 .lock = __MUTEX_INITIALIZER(watchdog.lock),
139};
140
141/* Super I/O functions */
142static inline int superio_inb(int base, int reg)
143{
144 outb(reg, base);
145 return inb(base + 1);
146}
147
148static int superio_inw(int base, int reg)
149{
150 int val;
151 val = superio_inb(base, reg) << 8;
152 val |= superio_inb(base, reg + 1);
153 return val;
154}
155
156static inline void superio_outb(int base, int reg, u8 val)
157{
158 outb(reg, base);
159 outb(val, base + 1);
160}
161
162static inline void superio_set_bit(int base, int reg, int bit)
163{
164 unsigned long val = superio_inb(base, reg);
165 __set_bit(bit, &val);
166 superio_outb(base, reg, val);
167}
168
169static inline void superio_clear_bit(int base, int reg, int bit)
170{
171 unsigned long val = superio_inb(base, reg);
172 __clear_bit(bit, &val);
173 superio_outb(base, reg, val);
174}
175
176static inline int superio_enter(int base)
177{
178 /* Don't step on other drivers' I/O space by accident */
179 if (!request_muxed_region(base, 2, DRVNAME)) {
180 printk(KERN_ERR DRVNAME ": I/O address 0x%04x already in use\n",
181 (int)base);
182 return -EBUSY;
183 }
184
185 /* according to the datasheet the key must be send twice! */
186 outb(SIO_UNLOCK_KEY, base);
187 outb(SIO_UNLOCK_KEY, base);
188
189 return 0;
190}
191
192static inline void superio_select(int base, int ld)
193{
194 outb(SIO_REG_LDSEL, base);
195 outb(ld, base + 1);
196}
197
198static inline void superio_exit(int base)
199{
200 outb(SIO_LOCK_KEY, base);
201 release_region(base, 2);
202}
203
204static int watchdog_set_timeout(int timeout)
205{
206 if (timeout <= 0
207 || timeout > max_timeout) {
208 printk(KERN_ERR DRVNAME ": watchdog timeout out of range\n");
209 return -EINVAL;
210 }
211
212 mutex_lock(&watchdog.lock);
213
214 watchdog.timeout = timeout;
215 if (timeout > 0xff) {
216 watchdog.timer_val = DIV_ROUND_UP(timeout, 60);
217 watchdog.minutes_mode = true;
218 } else {
219 watchdog.timer_val = timeout;
220 watchdog.minutes_mode = false;
221 }
222
223 mutex_unlock(&watchdog.lock);
224
225 return 0;
226}
227
228static int watchdog_set_pulse_width(unsigned int pw)
229{
230 int err = 0;
231
232 mutex_lock(&watchdog.lock);
233
234 if (pw <= 1) {
235 watchdog.pulse_val = 0;
236 } else if (pw <= 25) {
237 watchdog.pulse_val = 1;
238 } else if (pw <= 125) {
239 watchdog.pulse_val = 2;
240 } else if (pw <= 5000) {
241 watchdog.pulse_val = 3;
242 } else {
243 printk(KERN_ERR DRVNAME ": pulse width out of range\n");
244 err = -EINVAL;
245 goto exit_unlock;
246 }
247
248 watchdog.pulse_mode = pw;
249
250exit_unlock:
251 mutex_unlock(&watchdog.lock);
252 return err;
253}
254
255static int watchdog_keepalive(void)
256{
257 int err = 0;
258
259 mutex_lock(&watchdog.lock);
260 err = superio_enter(watchdog.sioaddr);
261 if (err)
262 goto exit_unlock;
263 superio_select(watchdog.sioaddr, SIO_F71808FG_LD_WDT);
264
265 if (watchdog.minutes_mode)
266 /* select minutes for timer units */
267 superio_set_bit(watchdog.sioaddr, F71808FG_REG_WDT_CONF,
268 F71808FG_FLAG_WD_UNIT);
269 else
270 /* select seconds for timer units */
271 superio_clear_bit(watchdog.sioaddr, F71808FG_REG_WDT_CONF,
272 F71808FG_FLAG_WD_UNIT);
273
274 /* Set timer value */
275 superio_outb(watchdog.sioaddr, F71808FG_REG_WD_TIME,
276 watchdog.timer_val);
277
278 superio_exit(watchdog.sioaddr);
279
280exit_unlock:
281 mutex_unlock(&watchdog.lock);
282 return err;
283}
284
285static int watchdog_start(void)
286{
287 /* Make sure we don't die as soon as the watchdog is enabled below */
288 int err = watchdog_keepalive();
289 if (err)
290 return err;
291
292 mutex_lock(&watchdog.lock);
293 err = superio_enter(watchdog.sioaddr);
294 if (err)
295 goto exit_unlock;
296 superio_select(watchdog.sioaddr, SIO_F71808FG_LD_WDT);
297
298 /* Watchdog pin configuration */
299 switch (watchdog.type) {
300 case f71808fg:
301 /* Set pin 21 to GPIO23/WDTRST#, then to WDTRST# */
302 superio_clear_bit(watchdog.sioaddr, 0x2a, 3);
303 superio_clear_bit(watchdog.sioaddr, 0x2b, 3);
304 break;
305
306 case f71882fg:
307 /* Set pin 56 to WDTRST# */
308 superio_set_bit(watchdog.sioaddr, 0x29, 1);
309 break;
310
311 default:
312 /*
313 * 'default' label to shut up the compiler and catch
314 * programmer errors
315 */
316 err = -ENODEV;
317 goto exit_superio;
318 }
319
320 superio_select(watchdog.sioaddr, SIO_F71808FG_LD_WDT);
321 superio_set_bit(watchdog.sioaddr, SIO_REG_ENABLE, 0);
322 superio_set_bit(watchdog.sioaddr, F71808FG_REG_WDO_CONF,
323 F71808FG_FLAG_WDOUT_EN);
324
325 superio_set_bit(watchdog.sioaddr, F71808FG_REG_WDT_CONF,
326 F71808FG_FLAG_WD_EN);
327
328 if (watchdog.pulse_mode) {
329 /* Select "pulse" output mode with given duration */
330 u8 wdt_conf = superio_inb(watchdog.sioaddr,
331 F71808FG_REG_WDT_CONF);
332
333 /* Set WD_PSWIDTH bits (1:0) */
334 wdt_conf = (wdt_conf & 0xfc) | (watchdog.pulse_val & 0x03);
335 /* Set WD_PULSE to "pulse" mode */
336 wdt_conf |= BIT(F71808FG_FLAG_WD_PULSE);
337
338 superio_outb(watchdog.sioaddr, F71808FG_REG_WDT_CONF,
339 wdt_conf);
340 } else {
341 /* Select "level" output mode */
342 superio_clear_bit(watchdog.sioaddr, F71808FG_REG_WDT_CONF,
343 F71808FG_FLAG_WD_PULSE);
344 }
345
346exit_superio:
347 superio_exit(watchdog.sioaddr);
348exit_unlock:
349 mutex_unlock(&watchdog.lock);
350
351 return err;
352}
353
354static int watchdog_stop(void)
355{
356 int err = 0;
357
358 mutex_lock(&watchdog.lock);
359 err = superio_enter(watchdog.sioaddr);
360 if (err)
361 goto exit_unlock;
362 superio_select(watchdog.sioaddr, SIO_F71808FG_LD_WDT);
363
364 superio_clear_bit(watchdog.sioaddr, F71808FG_REG_WDT_CONF,
365 F71808FG_FLAG_WD_EN);
366
367 superio_exit(watchdog.sioaddr);
368
369exit_unlock:
370 mutex_unlock(&watchdog.lock);
371
372 return err;
373}
374
375static int watchdog_get_status(void)
376{
377 int status = 0;
378
379 mutex_lock(&watchdog.lock);
380 status = (watchdog.caused_reboot) ? WDIOF_CARDRESET : 0;
381 mutex_unlock(&watchdog.lock);
382
383 return status;
384}
385
386static bool watchdog_is_running(void)
387{
388 /*
389 * if we fail to determine the watchdog's status assume it to be
390 * running to be on the safe side
391 */
392 bool is_running = true;
393
394 mutex_lock(&watchdog.lock);
395 if (superio_enter(watchdog.sioaddr))
396 goto exit_unlock;
397 superio_select(watchdog.sioaddr, SIO_F71808FG_LD_WDT);
398
399 is_running = (superio_inb(watchdog.sioaddr, SIO_REG_ENABLE) & BIT(0))
400 && (superio_inb(watchdog.sioaddr, F71808FG_REG_WDT_CONF)
401 & F71808FG_FLAG_WD_EN);
402
403 superio_exit(watchdog.sioaddr);
404
405exit_unlock:
406 mutex_unlock(&watchdog.lock);
407 return is_running;
408}
409
410/* /dev/watchdog api */
411
412static int watchdog_open(struct inode *inode, struct file *file)
413{
414 int err;
415
416 /* If the watchdog is alive we don't need to start it again */
417 if (test_and_set_bit(0, &watchdog.opened))
418 return -EBUSY;
419
420 err = watchdog_start();
421 if (err) {
422 clear_bit(0, &watchdog.opened);
423 return err;
424 }
425
426 if (nowayout)
427 __module_get(THIS_MODULE);
428
429 watchdog.expect_close = 0;
430 return nonseekable_open(inode, file);
431}
432
433static int watchdog_release(struct inode *inode, struct file *file)
434{
435 clear_bit(0, &watchdog.opened);
436
437 if (!watchdog.expect_close) {
438 watchdog_keepalive();
439 printk(KERN_CRIT DRVNAME
440 ": Unexpected close, not stopping watchdog!\n");
441 } else if (!nowayout) {
442 watchdog_stop();
443 }
444 return 0;
445}
446
447/*
448 * watchdog_write:
449 * @file: file handle to the watchdog
450 * @buf: buffer to write
451 * @count: count of bytes
452 * @ppos: pointer to the position to write. No seeks allowed
453 *
454 * A write to a watchdog device is defined as a keepalive signal. Any
455 * write of data will do, as we we don't define content meaning.
456 */
457
458static ssize_t watchdog_write(struct file *file, const char __user *buf,
459 size_t count, loff_t *ppos)
460{
461 if (count) {
462 if (!nowayout) {
463 size_t i;
464
465 /* In case it was set long ago */
466 bool expect_close = false;
467
468 for (i = 0; i != count; i++) {
469 char c;
470 if (get_user(c, buf + i))
471 return -EFAULT;
472 expect_close = (c == 'V');
473 }
474
475 /* Properly order writes across fork()ed processes */
476 mutex_lock(&watchdog.lock);
477 watchdog.expect_close = expect_close;
478 mutex_unlock(&watchdog.lock);
479 }
480
481 /* someone wrote to us, we should restart timer */
482 watchdog_keepalive();
483 }
484 return count;
485}
486
487/*
488 * watchdog_ioctl:
489 * @inode: inode of the device
490 * @file: file handle to the device
491 * @cmd: watchdog command
492 * @arg: argument pointer
493 *
494 * The watchdog API defines a common set of functions for all watchdogs
495 * according to their available features.
496 */
497static long watchdog_ioctl(struct file *file, unsigned int cmd,
498 unsigned long arg)
499{
500 int status;
501 int new_options;
502 int new_timeout;
503 union {
504 struct watchdog_info __user *ident;
505 int __user *i;
506 } uarg;
507
508 uarg.i = (int __user *)arg;
509
510 switch (cmd) {
511 case WDIOC_GETSUPPORT:
512 return copy_to_user(uarg.ident, &watchdog.ident,
513 sizeof(watchdog.ident)) ? -EFAULT : 0;
514
515 case WDIOC_GETSTATUS:
516 status = watchdog_get_status();
517 if (status < 0)
518 return status;
519 return put_user(status, uarg.i);
520
521 case WDIOC_GETBOOTSTATUS:
522 return put_user(0, uarg.i);
523
524 case WDIOC_SETOPTIONS:
525 if (get_user(new_options, uarg.i))
526 return -EFAULT;
527
528 if (new_options & WDIOS_DISABLECARD)
529 watchdog_stop();
530
531 if (new_options & WDIOS_ENABLECARD)
532 return watchdog_start();
533
534
535 case WDIOC_KEEPALIVE:
536 watchdog_keepalive();
537 return 0;
538
539 case WDIOC_SETTIMEOUT:
540 if (get_user(new_timeout, uarg.i))
541 return -EFAULT;
542
543 if (watchdog_set_timeout(new_timeout))
544 return -EINVAL;
545
546 watchdog_keepalive();
547 /* Fall */
548
549 case WDIOC_GETTIMEOUT:
550 return put_user(watchdog.timeout, uarg.i);
551
552 default:
553 return -ENOTTY;
554
555 }
556}
557
558static int watchdog_notify_sys(struct notifier_block *this, unsigned long code,
559 void *unused)
560{
561 if (code == SYS_DOWN || code == SYS_HALT)
562 watchdog_stop();
563 return NOTIFY_DONE;
564}
565
566static const struct file_operations watchdog_fops = {
567 .owner = THIS_MODULE,
568 .llseek = no_llseek,
569 .open = watchdog_open,
570 .release = watchdog_release,
571 .write = watchdog_write,
572 .unlocked_ioctl = watchdog_ioctl,
573};
574
575static struct miscdevice watchdog_miscdev = {
576 .minor = WATCHDOG_MINOR,
577 .name = "watchdog",
578 .fops = &watchdog_fops,
579};
580
581static struct notifier_block watchdog_notifier = {
582 .notifier_call = watchdog_notify_sys,
583};
584
585static int __init watchdog_init(int sioaddr)
586{
587 int wdt_conf, err = 0;
588
589 /* No need to lock watchdog.lock here because no entry points
590 * into the module have been registered yet.
591 */
592 watchdog.sioaddr = sioaddr;
593 watchdog.ident.options = WDIOC_SETTIMEOUT
594 | WDIOF_MAGICCLOSE
595 | WDIOF_KEEPALIVEPING;
596
597 snprintf(watchdog.ident.identity,
598 sizeof(watchdog.ident.identity), "%s watchdog",
599 f71808e_names[watchdog.type]);
600
601 err = superio_enter(sioaddr);
602 if (err)
603 return err;
604 superio_select(watchdog.sioaddr, SIO_F71808FG_LD_WDT);
605
606 wdt_conf = superio_inb(sioaddr, F71808FG_REG_WDT_CONF);
607 watchdog.caused_reboot = wdt_conf & F71808FG_FLAG_WDTMOUT_STS;
608
609 superio_exit(sioaddr);
610
611 err = watchdog_set_timeout(timeout);
612 if (err)
613 return err;
614 err = watchdog_set_pulse_width(pulse_width);
615 if (err)
616 return err;
617
618 err = register_reboot_notifier(&watchdog_notifier);
619 if (err)
620 return err;
621
622 err = misc_register(&watchdog_miscdev);
623 if (err) {
624 printk(KERN_ERR DRVNAME
625 ": cannot register miscdev on minor=%d\n",
626 watchdog_miscdev.minor);
627 goto exit_reboot;
628 }
629
630 if (start_withtimeout) {
631 if (start_withtimeout <= 0
632 || start_withtimeout > max_timeout) {
633 printk(KERN_ERR DRVNAME
634 ": starting timeout out of range\n");
635 err = -EINVAL;
636 goto exit_miscdev;
637 }
638
639 err = watchdog_start();
640 if (err) {
641 printk(KERN_ERR DRVNAME
642 ": cannot start watchdog timer\n");
643 goto exit_miscdev;
644 }
645
646 mutex_lock(&watchdog.lock);
647 err = superio_enter(sioaddr);
648 if (err)
649 goto exit_unlock;
650 superio_select(watchdog.sioaddr, SIO_F71808FG_LD_WDT);
651
652 if (start_withtimeout > 0xff) {
653 /* select minutes for timer units */
654 superio_set_bit(sioaddr, F71808FG_REG_WDT_CONF,
655 F71808FG_FLAG_WD_UNIT);
656 superio_outb(sioaddr, F71808FG_REG_WD_TIME,
657 DIV_ROUND_UP(start_withtimeout, 60));
658 } else {
659 /* select seconds for timer units */
660 superio_clear_bit(sioaddr, F71808FG_REG_WDT_CONF,
661 F71808FG_FLAG_WD_UNIT);
662 superio_outb(sioaddr, F71808FG_REG_WD_TIME,
663 start_withtimeout);
664 }
665
666 superio_exit(sioaddr);
667 mutex_unlock(&watchdog.lock);
668
669 if (nowayout)
670 __module_get(THIS_MODULE);
671
672 printk(KERN_INFO DRVNAME
673 ": watchdog started with initial timeout of %u sec\n",
674 start_withtimeout);
675 }
676
677 return 0;
678
679exit_unlock:
680 mutex_unlock(&watchdog.lock);
681exit_miscdev:
682 misc_deregister(&watchdog_miscdev);
683exit_reboot:
684 unregister_reboot_notifier(&watchdog_notifier);
685
686 return err;
687}
688
689static int __init f71808e_find(int sioaddr)
690{
691 u16 devid;
692 int err = superio_enter(sioaddr);
693 if (err)
694 return err;
695
696 devid = superio_inw(sioaddr, SIO_REG_MANID);
697 if (devid != SIO_FINTEK_ID) {
698 pr_debug(DRVNAME ": Not a Fintek device\n");
699 err = -ENODEV;
700 goto exit;
701 }
702
703 devid = force_id ? force_id : superio_inw(sioaddr, SIO_REG_DEVID);
704 switch (devid) {
705 case SIO_F71808_ID:
706 watchdog.type = f71808fg;
707 break;
708 case SIO_F71882_ID:
709 watchdog.type = f71882fg;
710 break;
711 case SIO_F71862_ID:
712 case SIO_F71889_ID:
713 /* These have a watchdog, though it isn't implemented (yet). */
714 err = -ENOSYS;
715 goto exit;
716 case SIO_F71858_ID:
717 /* Confirmed (by datasheet) not to have a watchdog. */
718 err = -ENODEV;
719 goto exit;
720 default:
721 printk(KERN_INFO DRVNAME ": Unrecognized Fintek device: %04x\n",
722 (unsigned int)devid);
723 err = -ENODEV;
724 goto exit;
725 }
726
727 printk(KERN_INFO DRVNAME ": Found %s watchdog chip, revision %d\n",
728 f71808e_names[watchdog.type],
729 (int)superio_inb(sioaddr, SIO_REG_DEVREV));
730exit:
731 superio_exit(sioaddr);
732 return err;
733}
734
735static int __init f71808e_init(void)
736{
737 static const unsigned short addrs[] = { 0x2e, 0x4e };
738 int err = -ENODEV;
739 int i;
740
741 for (i = 0; i < ARRAY_SIZE(addrs); i++) {
742 err = f71808e_find(addrs[i]);
743 if (err == 0)
744 break;
745 }
746 if (i == ARRAY_SIZE(addrs))
747 return err;
748
749 return watchdog_init(addrs[i]);
750}
751
752static void __exit f71808e_exit(void)
753{
754 if (watchdog_is_running()) {
755 printk(KERN_WARNING DRVNAME
756 ": Watchdog timer still running, stopping it\n");
757 watchdog_stop();
758 }
759 misc_deregister(&watchdog_miscdev);
760 unregister_reboot_notifier(&watchdog_notifier);
761}
762
763MODULE_DESCRIPTION("F71808E Watchdog Driver");
764MODULE_AUTHOR("Giel van Schijndel <me@mortis.eu>");
765MODULE_LICENSE("GPL");
766
767module_init(f71808e_init);
768module_exit(f71808e_exit);
diff --git a/drivers/watchdog/gef_wdt.c b/drivers/watchdog/gef_wdt.c
index 1df284f9c2a1..9c21d19043a6 100644
--- a/drivers/watchdog/gef_wdt.c
+++ b/drivers/watchdog/gef_wdt.c
@@ -260,7 +260,7 @@ static struct miscdevice gef_wdt_miscdev = {
260}; 260};
261 261
262 262
263static int __devinit gef_wdt_probe(struct of_device *dev, 263static int __devinit gef_wdt_probe(struct platform_device *dev,
264 const struct of_device_id *match) 264 const struct of_device_id *match)
265{ 265{
266 int timeout = 10; 266 int timeout = 10;
diff --git a/drivers/watchdog/hpwdt.c b/drivers/watchdog/hpwdt.c
index 809e7167a624..3d77116e4634 100644
--- a/drivers/watchdog/hpwdt.c
+++ b/drivers/watchdog/hpwdt.c
@@ -16,38 +16,55 @@
16#include <linux/device.h> 16#include <linux/device.h>
17#include <linux/fs.h> 17#include <linux/fs.h>
18#include <linux/init.h> 18#include <linux/init.h>
19#include <linux/interrupt.h>
20#include <linux/io.h> 19#include <linux/io.h>
21#include <linux/irq.h> 20#include <linux/bitops.h>
22#include <linux/nmi.h>
23#include <linux/kernel.h> 21#include <linux/kernel.h>
24#include <linux/miscdevice.h> 22#include <linux/miscdevice.h>
25#include <linux/mm.h>
26#include <linux/module.h> 23#include <linux/module.h>
27#include <linux/kdebug.h>
28#include <linux/moduleparam.h> 24#include <linux/moduleparam.h>
29#include <linux/notifier.h>
30#include <linux/pci.h> 25#include <linux/pci.h>
31#include <linux/pci_ids.h> 26#include <linux/pci_ids.h>
32#include <linux/reboot.h>
33#include <linux/sched.h>
34#include <linux/timer.h>
35#include <linux/types.h> 27#include <linux/types.h>
36#include <linux/uaccess.h> 28#include <linux/uaccess.h>
37#include <linux/watchdog.h> 29#include <linux/watchdog.h>
30#ifdef CONFIG_HPWDT_NMI_DECODING
38#include <linux/dmi.h> 31#include <linux/dmi.h>
39#include <linux/efi.h> 32#include <linux/spinlock.h>
40#include <linux/string.h> 33#include <linux/nmi.h>
41#include <linux/bootmem.h> 34#include <linux/kdebug.h>
42#include <asm/desc.h> 35#include <linux/notifier.h>
43#include <asm/cacheflush.h> 36#include <asm/cacheflush.h>
37#endif /* CONFIG_HPWDT_NMI_DECODING */
38
39#define HPWDT_VERSION "1.2.0"
40#define SECS_TO_TICKS(secs) ((secs) * 1000 / 128)
41#define TICKS_TO_SECS(ticks) ((ticks) * 128 / 1000)
42#define HPWDT_MAX_TIMER TICKS_TO_SECS(65535)
43#define DEFAULT_MARGIN 30
44
45static unsigned int soft_margin = DEFAULT_MARGIN; /* in seconds */
46static unsigned int reload; /* the computed soft_margin */
47static int nowayout = WATCHDOG_NOWAYOUT;
48static char expect_release;
49static unsigned long hpwdt_is_open;
50
51static void __iomem *pci_mem_addr; /* the PCI-memory address */
52static unsigned long __iomem *hpwdt_timer_reg;
53static unsigned long __iomem *hpwdt_timer_con;
44 54
55static struct pci_device_id hpwdt_devices[] = {
56 { PCI_DEVICE(PCI_VENDOR_ID_COMPAQ, 0xB203) }, /* iLO2 */
57 { PCI_DEVICE(PCI_VENDOR_ID_HP, 0x3306) }, /* iLO3 */
58 {0}, /* terminate list */
59};
60MODULE_DEVICE_TABLE(pci, hpwdt_devices);
61
62#ifdef CONFIG_HPWDT_NMI_DECODING
45#define PCI_BIOS32_SD_VALUE 0x5F32335F /* "_32_" */ 63#define PCI_BIOS32_SD_VALUE 0x5F32335F /* "_32_" */
46#define CRU_BIOS_SIGNATURE_VALUE 0x55524324 64#define CRU_BIOS_SIGNATURE_VALUE 0x55524324
47#define PCI_BIOS32_PARAGRAPH_LEN 16 65#define PCI_BIOS32_PARAGRAPH_LEN 16
48#define PCI_ROM_BASE1 0x000F0000 66#define PCI_ROM_BASE1 0x000F0000
49#define ROM_SIZE 0x10000 67#define ROM_SIZE 0x10000
50#define HPWDT_VERSION "1.1.1"
51 68
52struct bios32_service_dir { 69struct bios32_service_dir {
53 u32 signature; 70 u32 signature;
@@ -112,37 +129,17 @@ struct cmn_registers {
112 u32 reflags; 129 u32 reflags;
113} __attribute__((packed)); 130} __attribute__((packed));
114 131
115#define DEFAULT_MARGIN 30 132static unsigned int hpwdt_nmi_decoding;
116static unsigned int soft_margin = DEFAULT_MARGIN; /* in seconds */
117static unsigned int reload; /* the computed soft_margin */
118static int nowayout = WATCHDOG_NOWAYOUT;
119static char expect_release;
120static unsigned long hpwdt_is_open;
121static unsigned int allow_kdump; 133static unsigned int allow_kdump;
122static unsigned int hpwdt_nmi_sourcing;
123static unsigned int priority; /* hpwdt at end of die_notify list */ 134static unsigned int priority; /* hpwdt at end of die_notify list */
124
125static void __iomem *pci_mem_addr; /* the PCI-memory address */
126static unsigned long __iomem *hpwdt_timer_reg;
127static unsigned long __iomem *hpwdt_timer_con;
128
129static DEFINE_SPINLOCK(rom_lock); 135static DEFINE_SPINLOCK(rom_lock);
130
131static void *cru_rom_addr; 136static void *cru_rom_addr;
132
133static struct cmn_registers cmn_regs; 137static struct cmn_registers cmn_regs;
134 138
135static struct pci_device_id hpwdt_devices[] = {
136 { PCI_DEVICE(PCI_VENDOR_ID_COMPAQ, 0xB203) },
137 { PCI_DEVICE(PCI_VENDOR_ID_HP, 0x3306) },
138 {0}, /* terminate list */
139};
140MODULE_DEVICE_TABLE(pci, hpwdt_devices);
141
142extern asmlinkage void asminline_call(struct cmn_registers *pi86Regs, 139extern asmlinkage void asminline_call(struct cmn_registers *pi86Regs,
143 unsigned long *pRomEntry); 140 unsigned long *pRomEntry);
144 141
145#ifndef CONFIG_X86_64 142#ifdef CONFIG_X86_32
146/* --32 Bit Bios------------------------------------------------------------ */ 143/* --32 Bit Bios------------------------------------------------------------ */
147 144
148#define HPWDT_ARCH 32 145#define HPWDT_ARCH 32
@@ -246,8 +243,8 @@ static int __devinit cru_detect(unsigned long map_entry,
246 physical_bios_offset); 243 physical_bios_offset);
247 printk(KERN_DEBUG "hpwdt: CRU Length: 0x%lx\n", 244 printk(KERN_DEBUG "hpwdt: CRU Length: 0x%lx\n",
248 cru_length); 245 cru_length);
249 printk(KERN_DEBUG "hpwdt: CRU Mapped Address: 0x%x\n", 246 printk(KERN_DEBUG "hpwdt: CRU Mapped Address: %p\n",
250 (unsigned int)&cru_rom_addr); 247 &cru_rom_addr);
251 } 248 }
252 iounmap(bios32_map); 249 iounmap(bios32_map);
253 return retval; 250 return retval;
@@ -331,8 +328,9 @@ static int __devinit detect_cru_service(void)
331 iounmap(p); 328 iounmap(p);
332 return rc; 329 return rc;
333} 330}
334 331/* ------------------------------------------------------------------------- */
335#else 332#endif /* CONFIG_X86_32 */
333#ifdef CONFIG_X86_64
336/* --64 Bit Bios------------------------------------------------------------ */ 334/* --64 Bit Bios------------------------------------------------------------ */
337 335
338#define HPWDT_ARCH 64 336#define HPWDT_ARCH 64
@@ -410,17 +408,16 @@ static int __devinit detect_cru_service(void)
410 /* if cru_rom_addr has been set then we found a CRU service */ 408 /* if cru_rom_addr has been set then we found a CRU service */
411 return ((cru_rom_addr != NULL) ? 0 : -ENODEV); 409 return ((cru_rom_addr != NULL) ? 0 : -ENODEV);
412} 410}
413
414/* ------------------------------------------------------------------------- */ 411/* ------------------------------------------------------------------------- */
415 412#endif /* CONFIG_X86_64 */
416#endif 413#endif /* CONFIG_HPWDT_NMI_DECODING */
417 414
418/* 415/*
419 * Watchdog operations 416 * Watchdog operations
420 */ 417 */
421static void hpwdt_start(void) 418static void hpwdt_start(void)
422{ 419{
423 reload = (soft_margin * 1000) / 128; 420 reload = SECS_TO_TICKS(soft_margin);
424 iowrite16(reload, hpwdt_timer_reg); 421 iowrite16(reload, hpwdt_timer_reg);
425 iowrite16(0x85, hpwdt_timer_con); 422 iowrite16(0x85, hpwdt_timer_con);
426} 423}
@@ -441,8 +438,7 @@ static void hpwdt_ping(void)
441 438
442static int hpwdt_change_timer(int new_margin) 439static int hpwdt_change_timer(int new_margin)
443{ 440{
444 /* Arbitrary, can't find the card's limits */ 441 if (new_margin < 1 || new_margin > HPWDT_MAX_TIMER) {
445 if (new_margin < 5 || new_margin > 600) {
446 printk(KERN_WARNING 442 printk(KERN_WARNING
447 "hpwdt: New value passed in is invalid: %d seconds.\n", 443 "hpwdt: New value passed in is invalid: %d seconds.\n",
448 new_margin); 444 new_margin);
@@ -453,11 +449,17 @@ static int hpwdt_change_timer(int new_margin)
453 printk(KERN_DEBUG 449 printk(KERN_DEBUG
454 "hpwdt: New timer passed in is %d seconds.\n", 450 "hpwdt: New timer passed in is %d seconds.\n",
455 new_margin); 451 new_margin);
456 reload = (soft_margin * 1000) / 128; 452 reload = SECS_TO_TICKS(soft_margin);
457 453
458 return 0; 454 return 0;
459} 455}
460 456
457static int hpwdt_time_left(void)
458{
459 return TICKS_TO_SECS(ioread16(hpwdt_timer_reg));
460}
461
462#ifdef CONFIG_HPWDT_NMI_DECODING
461/* 463/*
462 * NMI Handler 464 * NMI Handler
463 */ 465 */
@@ -468,26 +470,29 @@ static int hpwdt_pretimeout(struct notifier_block *nb, unsigned long ulReason,
468 static int die_nmi_called; 470 static int die_nmi_called;
469 471
470 if (ulReason != DIE_NMI && ulReason != DIE_NMI_IPI) 472 if (ulReason != DIE_NMI && ulReason != DIE_NMI_IPI)
471 return NOTIFY_OK; 473 goto out;
472 474
473 if (hpwdt_nmi_sourcing) { 475 if (!hpwdt_nmi_decoding)
474 spin_lock_irqsave(&rom_lock, rom_pl); 476 goto out;
475 if (!die_nmi_called) 477
476 asminline_call(&cmn_regs, cru_rom_addr); 478 spin_lock_irqsave(&rom_lock, rom_pl);
477 die_nmi_called = 1; 479 if (!die_nmi_called)
478 spin_unlock_irqrestore(&rom_lock, rom_pl); 480 asminline_call(&cmn_regs, cru_rom_addr);
479 if (cmn_regs.u1.ral == 0) { 481 die_nmi_called = 1;
480 printk(KERN_WARNING "hpwdt: An NMI occurred, " 482 spin_unlock_irqrestore(&rom_lock, rom_pl);
481 "but unable to determine source.\n"); 483 if (cmn_regs.u1.ral == 0) {
482 } else { 484 printk(KERN_WARNING "hpwdt: An NMI occurred, "
483 if (allow_kdump) 485 "but unable to determine source.\n");
484 hpwdt_stop(); 486 } else {
485 panic("An NMI occurred, please see the Integrated " 487 if (allow_kdump)
486 "Management Log for details.\n"); 488 hpwdt_stop();
487 } 489 panic("An NMI occurred, please see the Integrated "
490 "Management Log for details.\n");
488 } 491 }
492out:
489 return NOTIFY_OK; 493 return NOTIFY_OK;
490} 494}
495#endif /* CONFIG_HPWDT_NMI_DECODING */
491 496
492/* 497/*
493 * /dev/watchdog handling 498 * /dev/watchdog handling
@@ -557,7 +562,7 @@ static const struct watchdog_info ident = {
557 .options = WDIOF_SETTIMEOUT | 562 .options = WDIOF_SETTIMEOUT |
558 WDIOF_KEEPALIVEPING | 563 WDIOF_KEEPALIVEPING |
559 WDIOF_MAGICCLOSE, 564 WDIOF_MAGICCLOSE,
560 .identity = "HP iLO2 HW Watchdog Timer", 565 .identity = "HP iLO2+ HW Watchdog Timer",
561}; 566};
562 567
563static long hpwdt_ioctl(struct file *file, unsigned int cmd, 568static long hpwdt_ioctl(struct file *file, unsigned int cmd,
@@ -599,6 +604,10 @@ static long hpwdt_ioctl(struct file *file, unsigned int cmd,
599 case WDIOC_GETTIMEOUT: 604 case WDIOC_GETTIMEOUT:
600 ret = put_user(soft_margin, p); 605 ret = put_user(soft_margin, p);
601 break; 606 break;
607
608 case WDIOC_GETTIMELEFT:
609 ret = put_user(hpwdt_time_left(), p);
610 break;
602 } 611 }
603 return ret; 612 return ret;
604} 613}
@@ -621,80 +630,45 @@ static struct miscdevice hpwdt_miscdev = {
621 .fops = &hpwdt_fops, 630 .fops = &hpwdt_fops,
622}; 631};
623 632
633#ifdef CONFIG_HPWDT_NMI_DECODING
624static struct notifier_block die_notifier = { 634static struct notifier_block die_notifier = {
625 .notifier_call = hpwdt_pretimeout, 635 .notifier_call = hpwdt_pretimeout,
626 .priority = 0, 636 .priority = 0,
627}; 637};
638#endif /* CONFIG_HPWDT_NMI_DECODING */
628 639
629/* 640/*
630 * Init & Exit 641 * Init & Exit
631 */ 642 */
632 643
644#ifdef CONFIG_HPWDT_NMI_DECODING
633#ifdef ARCH_HAS_NMI_WATCHDOG 645#ifdef ARCH_HAS_NMI_WATCHDOG
634static void __devinit hpwdt_check_nmi_sourcing(struct pci_dev *dev) 646static void __devinit hpwdt_check_nmi_decoding(struct pci_dev *dev)
635{ 647{
636 /* 648 /*
637 * If nmi_watchdog is turned off then we can turn on 649 * If nmi_watchdog is turned off then we can turn on
638 * our nmi sourcing capability. 650 * our nmi decoding capability.
639 */ 651 */
640 if (!nmi_watchdog_active()) 652 if (!nmi_watchdog_active())
641 hpwdt_nmi_sourcing = 1; 653 hpwdt_nmi_decoding = 1;
642 else 654 else
643 dev_warn(&dev->dev, "NMI sourcing is disabled. To enable this " 655 dev_warn(&dev->dev, "NMI decoding is disabled. To enable this "
644 "functionality you must reboot with nmi_watchdog=0 " 656 "functionality you must reboot with nmi_watchdog=0 "
645 "and load the hpwdt driver with priority=1.\n"); 657 "and load the hpwdt driver with priority=1.\n");
646} 658}
647#else 659#else
648static void __devinit hpwdt_check_nmi_sourcing(struct pci_dev *dev) 660static void __devinit hpwdt_check_nmi_decoding(struct pci_dev *dev)
649{ 661{
650 dev_warn(&dev->dev, "NMI sourcing is disabled. " 662 dev_warn(&dev->dev, "NMI decoding is disabled. "
651 "Your kernel does not support a NMI Watchdog.\n"); 663 "Your kernel does not support a NMI Watchdog.\n");
652} 664}
653#endif 665#endif /* ARCH_HAS_NMI_WATCHDOG */
654 666
655static int __devinit hpwdt_init_one(struct pci_dev *dev, 667static int __devinit hpwdt_init_nmi_decoding(struct pci_dev *dev)
656 const struct pci_device_id *ent)
657{ 668{
658 int retval; 669 int retval;
659 670
660 /* 671 /*
661 * Check if we can do NMI sourcing or not
662 */
663 hpwdt_check_nmi_sourcing(dev);
664
665 /*
666 * First let's find out if we are on an iLO2 server. We will
667 * not run on a legacy ASM box.
668 * So we only support the G5 ProLiant servers and higher.
669 */
670 if (dev->subsystem_vendor != PCI_VENDOR_ID_HP) {
671 dev_warn(&dev->dev,
672 "This server does not have an iLO2 ASIC.\n");
673 return -ENODEV;
674 }
675
676 if (pci_enable_device(dev)) {
677 dev_warn(&dev->dev,
678 "Not possible to enable PCI Device: 0x%x:0x%x.\n",
679 ent->vendor, ent->device);
680 return -ENODEV;
681 }
682
683 pci_mem_addr = pci_iomap(dev, 1, 0x80);
684 if (!pci_mem_addr) {
685 dev_warn(&dev->dev,
686 "Unable to detect the iLO2 server memory.\n");
687 retval = -ENOMEM;
688 goto error_pci_iomap;
689 }
690 hpwdt_timer_reg = pci_mem_addr + 0x70;
691 hpwdt_timer_con = pci_mem_addr + 0x72;
692
693 /* Make sure that we have a valid soft_margin */
694 if (hpwdt_change_timer(soft_margin))
695 hpwdt_change_timer(DEFAULT_MARGIN);
696
697 /*
698 * We need to map the ROM to get the CRU service. 672 * We need to map the ROM to get the CRU service.
699 * For 32 bit Operating Systems we need to go through the 32 Bit 673 * For 32 bit Operating Systems we need to go through the 32 Bit
700 * BIOS Service Directory 674 * BIOS Service Directory
@@ -705,7 +679,7 @@ static int __devinit hpwdt_init_one(struct pci_dev *dev,
705 dev_warn(&dev->dev, 679 dev_warn(&dev->dev,
706 "Unable to detect the %d Bit CRU Service.\n", 680 "Unable to detect the %d Bit CRU Service.\n",
707 HPWDT_ARCH); 681 HPWDT_ARCH);
708 goto error_get_cru; 682 return retval;
709 } 683 }
710 684
711 /* 685 /*
@@ -728,9 +702,87 @@ static int __devinit hpwdt_init_one(struct pci_dev *dev,
728 dev_warn(&dev->dev, 702 dev_warn(&dev->dev,
729 "Unable to register a die notifier (err=%d).\n", 703 "Unable to register a die notifier (err=%d).\n",
730 retval); 704 retval);
731 goto error_die_notifier; 705 if (cru_rom_addr)
706 iounmap(cru_rom_addr);
732 } 707 }
733 708
709 dev_info(&dev->dev,
710 "HP Watchdog Timer Driver: NMI decoding initialized"
711 ", allow kernel dump: %s (default = 0/OFF)"
712 ", priority: %s (default = 0/LAST).\n",
713 (allow_kdump == 0) ? "OFF" : "ON",
714 (priority == 0) ? "LAST" : "FIRST");
715 return 0;
716}
717
718static void __devexit hpwdt_exit_nmi_decoding(void)
719{
720 unregister_die_notifier(&die_notifier);
721 if (cru_rom_addr)
722 iounmap(cru_rom_addr);
723}
724#else /* !CONFIG_HPWDT_NMI_DECODING */
725static void __devinit hpwdt_check_nmi_decoding(struct pci_dev *dev)
726{
727}
728
729static int __devinit hpwdt_init_nmi_decoding(struct pci_dev *dev)
730{
731 return 0;
732}
733
734static void __devexit hpwdt_exit_nmi_decoding(void)
735{
736}
737#endif /* CONFIG_HPWDT_NMI_DECODING */
738
739static int __devinit hpwdt_init_one(struct pci_dev *dev,
740 const struct pci_device_id *ent)
741{
742 int retval;
743
744 /*
745 * Check if we can do NMI decoding or not
746 */
747 hpwdt_check_nmi_decoding(dev);
748
749 /*
750 * First let's find out if we are on an iLO2+ server. We will
751 * not run on a legacy ASM box.
752 * So we only support the G5 ProLiant servers and higher.
753 */
754 if (dev->subsystem_vendor != PCI_VENDOR_ID_HP) {
755 dev_warn(&dev->dev,
756 "This server does not have an iLO2+ ASIC.\n");
757 return -ENODEV;
758 }
759
760 if (pci_enable_device(dev)) {
761 dev_warn(&dev->dev,
762 "Not possible to enable PCI Device: 0x%x:0x%x.\n",
763 ent->vendor, ent->device);
764 return -ENODEV;
765 }
766
767 pci_mem_addr = pci_iomap(dev, 1, 0x80);
768 if (!pci_mem_addr) {
769 dev_warn(&dev->dev,
770 "Unable to detect the iLO2+ server memory.\n");
771 retval = -ENOMEM;
772 goto error_pci_iomap;
773 }
774 hpwdt_timer_reg = pci_mem_addr + 0x70;
775 hpwdt_timer_con = pci_mem_addr + 0x72;
776
777 /* Make sure that we have a valid soft_margin */
778 if (hpwdt_change_timer(soft_margin))
779 hpwdt_change_timer(DEFAULT_MARGIN);
780
781 /* Initialize NMI Decoding functionality */
782 retval = hpwdt_init_nmi_decoding(dev);
783 if (retval != 0)
784 goto error_init_nmi_decoding;
785
734 retval = misc_register(&hpwdt_miscdev); 786 retval = misc_register(&hpwdt_miscdev);
735 if (retval < 0) { 787 if (retval < 0) {
736 dev_warn(&dev->dev, 788 dev_warn(&dev->dev,
@@ -739,23 +791,14 @@ static int __devinit hpwdt_init_one(struct pci_dev *dev,
739 goto error_misc_register; 791 goto error_misc_register;
740 } 792 }
741 793
742 printk(KERN_INFO 794 dev_info(&dev->dev, "HP Watchdog Timer Driver: %s"
743 "hp Watchdog Timer Driver: %s" 795 ", timer margin: %d seconds (nowayout=%d).\n",
744 ", timer margin: %d seconds (nowayout=%d)" 796 HPWDT_VERSION, soft_margin, nowayout);
745 ", allow kernel dump: %s (default = 0/OFF)"
746 ", priority: %s (default = 0/LAST).\n",
747 HPWDT_VERSION, soft_margin, nowayout,
748 (allow_kdump == 0) ? "OFF" : "ON",
749 (priority == 0) ? "LAST" : "FIRST");
750
751 return 0; 797 return 0;
752 798
753error_misc_register: 799error_misc_register:
754 unregister_die_notifier(&die_notifier); 800 hpwdt_exit_nmi_decoding();
755error_die_notifier: 801error_init_nmi_decoding:
756 if (cru_rom_addr)
757 iounmap(cru_rom_addr);
758error_get_cru:
759 pci_iounmap(dev, pci_mem_addr); 802 pci_iounmap(dev, pci_mem_addr);
760error_pci_iomap: 803error_pci_iomap:
761 pci_disable_device(dev); 804 pci_disable_device(dev);
@@ -768,10 +811,7 @@ static void __devexit hpwdt_exit(struct pci_dev *dev)
768 hpwdt_stop(); 811 hpwdt_stop();
769 812
770 misc_deregister(&hpwdt_miscdev); 813 misc_deregister(&hpwdt_miscdev);
771 unregister_die_notifier(&die_notifier); 814 hpwdt_exit_nmi_decoding();
772
773 if (cru_rom_addr)
774 iounmap(cru_rom_addr);
775 pci_iounmap(dev, pci_mem_addr); 815 pci_iounmap(dev, pci_mem_addr);
776 pci_disable_device(dev); 816 pci_disable_device(dev);
777} 817}
@@ -802,16 +842,18 @@ MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
802module_param(soft_margin, int, 0); 842module_param(soft_margin, int, 0);
803MODULE_PARM_DESC(soft_margin, "Watchdog timeout in seconds"); 843MODULE_PARM_DESC(soft_margin, "Watchdog timeout in seconds");
804 844
805module_param(allow_kdump, int, 0);
806MODULE_PARM_DESC(allow_kdump, "Start a kernel dump after NMI occurs");
807
808module_param(nowayout, int, 0); 845module_param(nowayout, int, 0);
809MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" 846MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
810 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); 847 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
811 848
849#ifdef CONFIG_HPWDT_NMI_DECODING
850module_param(allow_kdump, int, 0);
851MODULE_PARM_DESC(allow_kdump, "Start a kernel dump after NMI occurs");
852
812module_param(priority, int, 0); 853module_param(priority, int, 0);
813MODULE_PARM_DESC(priority, "The hpwdt driver handles NMIs first or last" 854MODULE_PARM_DESC(priority, "The hpwdt driver handles NMIs first or last"
814 " (default = 0/Last)\n"); 855 " (default = 0/Last)\n");
856#endif /* !CONFIG_HPWDT_NMI_DECODING */
815 857
816module_init(hpwdt_init); 858module_init(hpwdt_init);
817module_exit(hpwdt_cleanup); 859module_exit(hpwdt_cleanup);
diff --git a/drivers/watchdog/mpc8xxx_wdt.c b/drivers/watchdog/mpc8xxx_wdt.c
index 4cda64dd309c..8fa213cdb499 100644
--- a/drivers/watchdog/mpc8xxx_wdt.c
+++ b/drivers/watchdog/mpc8xxx_wdt.c
@@ -185,7 +185,7 @@ static struct miscdevice mpc8xxx_wdt_miscdev = {
185 .fops = &mpc8xxx_wdt_fops, 185 .fops = &mpc8xxx_wdt_fops,
186}; 186};
187 187
188static int __devinit mpc8xxx_wdt_probe(struct of_device *ofdev, 188static int __devinit mpc8xxx_wdt_probe(struct platform_device *ofdev,
189 const struct of_device_id *match) 189 const struct of_device_id *match)
190{ 190{
191 int ret; 191 int ret;
@@ -238,7 +238,7 @@ err_unmap:
238 return ret; 238 return ret;
239} 239}
240 240
241static int __devexit mpc8xxx_wdt_remove(struct of_device *ofdev) 241static int __devexit mpc8xxx_wdt_remove(struct platform_device *ofdev)
242{ 242{
243 mpc8xxx_wdt_pr_warn("watchdog removed"); 243 mpc8xxx_wdt_pr_warn("watchdog removed");
244 del_timer_sync(&wdt_timer); 244 del_timer_sync(&wdt_timer);
diff --git a/drivers/watchdog/riowd.c b/drivers/watchdog/riowd.c
index 4082b4ace1fc..3faee1ae64bd 100644
--- a/drivers/watchdog/riowd.c
+++ b/drivers/watchdog/riowd.c
@@ -172,7 +172,7 @@ static struct miscdevice riowd_miscdev = {
172 .fops = &riowd_fops 172 .fops = &riowd_fops
173}; 173};
174 174
175static int __devinit riowd_probe(struct of_device *op, 175static int __devinit riowd_probe(struct platform_device *op,
176 const struct of_device_id *match) 176 const struct of_device_id *match)
177{ 177{
178 struct riowd *p; 178 struct riowd *p;
@@ -219,7 +219,7 @@ out:
219 return err; 219 return err;
220} 220}
221 221
222static int __devexit riowd_remove(struct of_device *op) 222static int __devexit riowd_remove(struct platform_device *op)
223{ 223{
224 struct riowd *p = dev_get_drvdata(&op->dev); 224 struct riowd *p = dev_get_drvdata(&op->dev);
225 225
diff --git a/drivers/watchdog/s3c2410_wdt.c b/drivers/watchdog/s3c2410_wdt.c
index 300932580ded..ae53662c29bc 100644
--- a/drivers/watchdog/s3c2410_wdt.c
+++ b/drivers/watchdog/s3c2410_wdt.c
@@ -532,21 +532,22 @@ static int __devinit s3c2410wdt_probe(struct platform_device *pdev)
532 532
533static int __devexit s3c2410wdt_remove(struct platform_device *dev) 533static int __devexit s3c2410wdt_remove(struct platform_device *dev)
534{ 534{
535 s3c2410wdt_cpufreq_deregister(); 535 misc_deregister(&s3c2410wdt_miscdev);
536
537 release_resource(wdt_mem);
538 kfree(wdt_mem);
539 wdt_mem = NULL;
540 536
541 free_irq(wdt_irq->start, dev); 537 s3c2410wdt_cpufreq_deregister();
542 wdt_irq = NULL;
543 538
544 clk_disable(wdt_clock); 539 clk_disable(wdt_clock);
545 clk_put(wdt_clock); 540 clk_put(wdt_clock);
546 wdt_clock = NULL; 541 wdt_clock = NULL;
547 542
543 free_irq(wdt_irq->start, dev);
544 wdt_irq = NULL;
545
548 iounmap(wdt_base); 546 iounmap(wdt_base);
549 misc_deregister(&s3c2410wdt_miscdev); 547
548 release_resource(wdt_mem);
549 kfree(wdt_mem);
550 wdt_mem = NULL;
550 return 0; 551 return 0;
551} 552}
552 553
diff --git a/drivers/watchdog/sch311x_wdt.c b/drivers/watchdog/sch311x_wdt.c
index 9c40f48804f5..0461858e07d0 100644
--- a/drivers/watchdog/sch311x_wdt.c
+++ b/drivers/watchdog/sch311x_wdt.c
@@ -425,6 +425,8 @@ static int __devinit sch311x_wdt_probe(struct platform_device *pdev)
425 val = therm_trip ? 0x06 : 0x04; 425 val = therm_trip ? 0x06 : 0x04;
426 outb(val, sch311x_wdt_data.runtime_reg + RESGEN); 426 outb(val, sch311x_wdt_data.runtime_reg + RESGEN);
427 427
428 sch311x_wdt_miscdev.parent = dev;
429
428 err = misc_register(&sch311x_wdt_miscdev); 430 err = misc_register(&sch311x_wdt_miscdev);
429 if (err != 0) { 431 if (err != 0) {
430 dev_err(dev, "cannot register miscdev on minor=%d (err=%d)\n", 432 dev_err(dev, "cannot register miscdev on minor=%d (err=%d)\n",
@@ -432,8 +434,6 @@ static int __devinit sch311x_wdt_probe(struct platform_device *pdev)
432 goto exit_release_region3; 434 goto exit_release_region3;
433 } 435 }
434 436
435 sch311x_wdt_miscdev.parent = dev;
436
437 dev_info(dev, 437 dev_info(dev,
438 "SMSC SCH311x WDT initialized. timeout=%d sec (nowayout=%d)\n", 438 "SMSC SCH311x WDT initialized. timeout=%d sec (nowayout=%d)\n",
439 timeout, nowayout); 439 timeout, nowayout);
diff --git a/drivers/watchdog/sp805_wdt.c b/drivers/watchdog/sp805_wdt.c
new file mode 100644
index 000000000000..9127eda2145b
--- /dev/null
+++ b/drivers/watchdog/sp805_wdt.c
@@ -0,0 +1,387 @@
1/*
2 * drivers/char/watchdog/sp805-wdt.c
3 *
4 * Watchdog driver for ARM SP805 watchdog module
5 *
6 * Copyright (C) 2010 ST Microelectronics
7 * Viresh Kumar<viresh.kumar@st.com>
8 *
9 * This file is licensed under the terms of the GNU General Public
10 * License version 2 or later. This program is licensed "as is" without any
11 * warranty of any kind, whether express or implied.
12 */
13
14#include <linux/device.h>
15#include <linux/resource.h>
16#include <linux/amba/bus.h>
17#include <linux/bitops.h>
18#include <linux/clk.h>
19#include <linux/fs.h>
20#include <linux/init.h>
21#include <linux/io.h>
22#include <linux/ioport.h>
23#include <linux/kernel.h>
24#include <linux/math64.h>
25#include <linux/miscdevice.h>
26#include <linux/module.h>
27#include <linux/moduleparam.h>
28#include <linux/slab.h>
29#include <linux/spinlock.h>
30#include <linux/types.h>
31#include <linux/uaccess.h>
32#include <linux/watchdog.h>
33
34/* default timeout in seconds */
35#define DEFAULT_TIMEOUT 60
36
37#define MODULE_NAME "sp805-wdt"
38
39/* watchdog register offsets and masks */
40#define WDTLOAD 0x000
41 #define LOAD_MIN 0x00000001
42 #define LOAD_MAX 0xFFFFFFFF
43#define WDTVALUE 0x004
44#define WDTCONTROL 0x008
45 /* control register masks */
46 #define INT_ENABLE (1 << 0)
47 #define RESET_ENABLE (1 << 1)
48#define WDTINTCLR 0x00C
49#define WDTRIS 0x010
50#define WDTMIS 0x014
51 #define INT_MASK (1 << 0)
52#define WDTLOCK 0xC00
53 #define UNLOCK 0x1ACCE551
54 #define LOCK 0x00000001
55
56/**
57 * struct sp805_wdt: sp805 wdt device structure
58 *
59 * lock: spin lock protecting dev structure and io access
60 * base: base address of wdt
61 * clk: clock structure of wdt
62 * dev: amba device structure of wdt
63 * status: current status of wdt
64 * load_val: load value to be set for current timeout
65 * timeout: current programmed timeout
66 */
67struct sp805_wdt {
68 spinlock_t lock;
69 void __iomem *base;
70 struct clk *clk;
71 struct amba_device *adev;
72 unsigned long status;
73 #define WDT_BUSY 0
74 #define WDT_CAN_BE_CLOSED 1
75 unsigned int load_val;
76 unsigned int timeout;
77};
78
79/* local variables */
80static struct sp805_wdt *wdt;
81static int nowayout = WATCHDOG_NOWAYOUT;
82
83/* This routine finds load value that will reset system in required timout */
84static void wdt_setload(unsigned int timeout)
85{
86 u64 load, rate;
87
88 rate = clk_get_rate(wdt->clk);
89
90 /*
91 * sp805 runs counter with given value twice, after the end of first
92 * counter it gives an interrupt and then starts counter again. If
93 * interrupt already occured then it resets the system. This is why
94 * load is half of what should be required.
95 */
96 load = div_u64(rate, 2) * timeout - 1;
97
98 load = (load > LOAD_MAX) ? LOAD_MAX : load;
99 load = (load < LOAD_MIN) ? LOAD_MIN : load;
100
101 spin_lock(&wdt->lock);
102 wdt->load_val = load;
103 /* roundup timeout to closest positive integer value */
104 wdt->timeout = div_u64((load + 1) * 2 + (rate / 2), rate);
105 spin_unlock(&wdt->lock);
106}
107
108/* returns number of seconds left for reset to occur */
109static u32 wdt_timeleft(void)
110{
111 u64 load, rate;
112
113 rate = clk_get_rate(wdt->clk);
114
115 spin_lock(&wdt->lock);
116 load = readl(wdt->base + WDTVALUE);
117
118 /*If the interrupt is inactive then time left is WDTValue + WDTLoad. */
119 if (!(readl(wdt->base + WDTRIS) & INT_MASK))
120 load += wdt->load_val + 1;
121 spin_unlock(&wdt->lock);
122
123 return div_u64(load, rate);
124}
125
126/* enables watchdog timers reset */
127static void wdt_enable(void)
128{
129 spin_lock(&wdt->lock);
130
131 writel(UNLOCK, wdt->base + WDTLOCK);
132 writel(wdt->load_val, wdt->base + WDTLOAD);
133 writel(INT_MASK, wdt->base + WDTINTCLR);
134 writel(INT_ENABLE | RESET_ENABLE, wdt->base + WDTCONTROL);
135 writel(LOCK, wdt->base + WDTLOCK);
136
137 spin_unlock(&wdt->lock);
138}
139
140/* disables watchdog timers reset */
141static void wdt_disable(void)
142{
143 spin_lock(&wdt->lock);
144
145 writel(UNLOCK, wdt->base + WDTLOCK);
146 writel(0, wdt->base + WDTCONTROL);
147 writel(0, wdt->base + WDTLOAD);
148 writel(LOCK, wdt->base + WDTLOCK);
149
150 spin_unlock(&wdt->lock);
151}
152
153static ssize_t sp805_wdt_write(struct file *file, const char *data,
154 size_t len, loff_t *ppos)
155{
156 if (len) {
157 if (!nowayout) {
158 size_t i;
159
160 clear_bit(WDT_CAN_BE_CLOSED, &wdt->status);
161
162 for (i = 0; i != len; i++) {
163 char c;
164
165 if (get_user(c, data + i))
166 return -EFAULT;
167 /* Check for Magic Close character */
168 if (c == 'V') {
169 set_bit(WDT_CAN_BE_CLOSED,
170 &wdt->status);
171 break;
172 }
173 }
174 }
175 wdt_enable();
176 }
177 return len;
178}
179
180static const struct watchdog_info ident = {
181 .options = WDIOF_MAGICCLOSE | WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING,
182 .identity = MODULE_NAME,
183};
184
185static long sp805_wdt_ioctl(struct file *file, unsigned int cmd,
186 unsigned long arg)
187{
188 int ret = -ENOTTY;
189 unsigned int timeout;
190
191 switch (cmd) {
192 case WDIOC_GETSUPPORT:
193 ret = copy_to_user((struct watchdog_info *)arg, &ident,
194 sizeof(ident)) ? -EFAULT : 0;
195 break;
196
197 case WDIOC_GETSTATUS:
198 ret = put_user(0, (int *)arg);
199 break;
200
201 case WDIOC_KEEPALIVE:
202 wdt_enable();
203 ret = 0;
204 break;
205
206 case WDIOC_SETTIMEOUT:
207 ret = get_user(timeout, (unsigned int *)arg);
208 if (ret)
209 break;
210
211 wdt_setload(timeout);
212
213 wdt_enable();
214 /* Fall through */
215
216 case WDIOC_GETTIMEOUT:
217 ret = put_user(wdt->timeout, (unsigned int *)arg);
218 break;
219 case WDIOC_GETTIMELEFT:
220 ret = put_user(wdt_timeleft(), (unsigned int *)arg);
221 break;
222 }
223 return ret;
224}
225
226static int sp805_wdt_open(struct inode *inode, struct file *file)
227{
228 int ret = 0;
229
230 if (test_and_set_bit(WDT_BUSY, &wdt->status))
231 return -EBUSY;
232
233 ret = clk_enable(wdt->clk);
234 if (ret) {
235 dev_err(&wdt->adev->dev, "clock enable fail");
236 goto err;
237 }
238
239 wdt_enable();
240
241 /* can not be closed, once enabled */
242 clear_bit(WDT_CAN_BE_CLOSED, &wdt->status);
243 return nonseekable_open(inode, file);
244
245err:
246 clear_bit(WDT_BUSY, &wdt->status);
247 return ret;
248}
249
250static int sp805_wdt_release(struct inode *inode, struct file *file)
251{
252 if (!test_bit(WDT_CAN_BE_CLOSED, &wdt->status)) {
253 clear_bit(WDT_BUSY, &wdt->status);
254 dev_warn(&wdt->adev->dev, "Device closed unexpectedly\n");
255 return 0;
256 }
257
258 wdt_disable();
259 clk_disable(wdt->clk);
260 clear_bit(WDT_BUSY, &wdt->status);
261
262 return 0;
263}
264
265static const struct file_operations sp805_wdt_fops = {
266 .owner = THIS_MODULE,
267 .llseek = no_llseek,
268 .write = sp805_wdt_write,
269 .unlocked_ioctl = sp805_wdt_ioctl,
270 .open = sp805_wdt_open,
271 .release = sp805_wdt_release,
272};
273
274static struct miscdevice sp805_wdt_miscdev = {
275 .minor = WATCHDOG_MINOR,
276 .name = "watchdog",
277 .fops = &sp805_wdt_fops,
278};
279
280static int __devinit
281sp805_wdt_probe(struct amba_device *adev, struct amba_id *id)
282{
283 int ret = 0;
284
285 if (!request_mem_region(adev->res.start, resource_size(&adev->res),
286 "sp805_wdt")) {
287 dev_warn(&adev->dev, "Failed to get memory region resource\n");
288 ret = -ENOENT;
289 goto err;
290 }
291
292 wdt = kzalloc(sizeof(*wdt), GFP_KERNEL);
293 if (!wdt) {
294 dev_warn(&adev->dev, "Kzalloc failed\n");
295 ret = -ENOMEM;
296 goto err_kzalloc;
297 }
298
299 wdt->clk = clk_get(&adev->dev, NULL);
300 if (IS_ERR(wdt->clk)) {
301 dev_warn(&adev->dev, "Clock not found\n");
302 ret = PTR_ERR(wdt->clk);
303 goto err_clk_get;
304 }
305
306 wdt->base = ioremap(adev->res.start, resource_size(&adev->res));
307 if (!wdt->base) {
308 ret = -ENOMEM;
309 dev_warn(&adev->dev, "ioremap fail\n");
310 goto err_ioremap;
311 }
312
313 wdt->adev = adev;
314 spin_lock_init(&wdt->lock);
315 wdt_setload(DEFAULT_TIMEOUT);
316
317 ret = misc_register(&sp805_wdt_miscdev);
318 if (ret < 0) {
319 dev_warn(&adev->dev, "cannot register misc device\n");
320 goto err_misc_register;
321 }
322
323 dev_info(&adev->dev, "registration successful\n");
324 return 0;
325
326err_misc_register:
327 iounmap(wdt->base);
328err_ioremap:
329 clk_put(wdt->clk);
330err_clk_get:
331 kfree(wdt);
332 wdt = NULL;
333err_kzalloc:
334 release_mem_region(adev->res.start, resource_size(&adev->res));
335err:
336 dev_err(&adev->dev, "Probe Failed!!!\n");
337 return ret;
338}
339
340static int __devexit sp805_wdt_remove(struct amba_device *adev)
341{
342 misc_deregister(&sp805_wdt_miscdev);
343 iounmap(wdt->base);
344 clk_put(wdt->clk);
345 kfree(wdt);
346 release_mem_region(adev->res.start, resource_size(&adev->res));
347
348 return 0;
349}
350
351static struct amba_id sp805_wdt_ids[] __initdata = {
352 {
353 .id = 0x00141805,
354 .mask = 0x00ffffff,
355 },
356 { 0, 0 },
357};
358
359static struct amba_driver sp805_wdt_driver = {
360 .drv = {
361 .name = MODULE_NAME,
362 },
363 .id_table = sp805_wdt_ids,
364 .probe = sp805_wdt_probe,
365 .remove = __devexit_p(sp805_wdt_remove),
366};
367
368static int __init sp805_wdt_init(void)
369{
370 return amba_driver_register(&sp805_wdt_driver);
371}
372module_init(sp805_wdt_init);
373
374static void __exit sp805_wdt_exit(void)
375{
376 amba_driver_unregister(&sp805_wdt_driver);
377}
378module_exit(sp805_wdt_exit);
379
380module_param(nowayout, int, 0);
381MODULE_PARM_DESC(nowayout,
382 "Set to 1 to keep watchdog running after device release");
383
384MODULE_AUTHOR("Viresh Kumar <viresh.kumar@st.com>");
385MODULE_DESCRIPTION("ARM SP805 Watchdog Driver");
386MODULE_LICENSE("GPL");
387MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/watchdog/wdt_pci.c b/drivers/watchdog/wdt_pci.c
index 7b22e3cdbc81..6130c88fa5ac 100644
--- a/drivers/watchdog/wdt_pci.c
+++ b/drivers/watchdog/wdt_pci.c
@@ -60,19 +60,6 @@
60 60
61#define PFX "wdt_pci: " 61#define PFX "wdt_pci: "
62 62
63/*
64 * Until Access I/O gets their application for a PCI vendor ID approved,
65 * I don't think that it's appropriate to move these constants into the
66 * regular pci_ids.h file. -- JPN 2000/01/18
67 */
68
69#ifndef PCI_VENDOR_ID_ACCESSIO
70#define PCI_VENDOR_ID_ACCESSIO 0x494f
71#endif
72#ifndef PCI_DEVICE_ID_WDG_CSM
73#define PCI_DEVICE_ID_WDG_CSM 0x22c0
74#endif
75
76/* We can only use 1 card due to the /dev/watchdog restriction */ 63/* We can only use 1 card due to the /dev/watchdog restriction */
77static int dev_count; 64static int dev_count;
78 65
@@ -743,7 +730,7 @@ static void __devexit wdtpci_remove_one(struct pci_dev *pdev)
743static struct pci_device_id wdtpci_pci_tbl[] = { 730static struct pci_device_id wdtpci_pci_tbl[] = {
744 { 731 {
745 .vendor = PCI_VENDOR_ID_ACCESSIO, 732 .vendor = PCI_VENDOR_ID_ACCESSIO,
746 .device = PCI_DEVICE_ID_WDG_CSM, 733 .device = PCI_DEVICE_ID_ACCESSIO_WDG_CSM,
747 .subvendor = PCI_ANY_ID, 734 .subvendor = PCI_ANY_ID,
748 .subdevice = PCI_ANY_ID, 735 .subdevice = PCI_ANY_ID,
749 }, 736 },
diff --git a/drivers/xen/Kconfig b/drivers/xen/Kconfig
index 0a8826936639..60d71e9abe9f 100644
--- a/drivers/xen/Kconfig
+++ b/drivers/xen/Kconfig
@@ -71,4 +71,9 @@ config XEN_PLATFORM_PCI
71 initializing xenbus and grant_table when running in a Xen HVM 71 initializing xenbus and grant_table when running in a Xen HVM
72 domain. As a consequence this driver is required to run any Xen PV 72 domain. As a consequence this driver is required to run any Xen PV
73 frontend on Xen HVM. 73 frontend on Xen HVM.
74
75config SWIOTLB_XEN
76 def_bool y
77 depends on SWIOTLB
78
74endmenu 79endmenu
diff --git a/drivers/xen/Makefile b/drivers/xen/Makefile
index e392fb776af3..fcaf838f54be 100644
--- a/drivers/xen/Makefile
+++ b/drivers/xen/Makefile
@@ -11,3 +11,4 @@ obj-$(CONFIG_XEN_DEV_EVTCHN) += evtchn.o
11obj-$(CONFIG_XENFS) += xenfs/ 11obj-$(CONFIG_XENFS) += xenfs/
12obj-$(CONFIG_XEN_SYS_HYPERVISOR) += sys-hypervisor.o 12obj-$(CONFIG_XEN_SYS_HYPERVISOR) += sys-hypervisor.o
13obj-$(CONFIG_XEN_PLATFORM_PCI) += platform-pci.o 13obj-$(CONFIG_XEN_PLATFORM_PCI) += platform-pci.o
14obj-$(CONFIG_SWIOTLB_XEN) += swiotlb-xen.o
diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c
index 1a0d8c2a0354..500290b150bb 100644
--- a/drivers/xen/balloon.c
+++ b/drivers/xen/balloon.c
@@ -85,13 +85,6 @@ static struct sys_device balloon_sysdev;
85 85
86static int register_balloon(struct sys_device *sysdev); 86static int register_balloon(struct sys_device *sysdev);
87 87
88/*
89 * Protects atomic reservation decrease/increase against concurrent increases.
90 * Also protects non-atomic updates of current_pages and driver_pages, and
91 * balloon lists.
92 */
93static DEFINE_SPINLOCK(balloon_lock);
94
95static struct balloon_stats balloon_stats; 88static struct balloon_stats balloon_stats;
96 89
97/* We increase/decrease in batches which fit in a page */ 90/* We increase/decrease in batches which fit in a page */
@@ -210,7 +203,7 @@ static int increase_reservation(unsigned long nr_pages)
210 if (nr_pages > ARRAY_SIZE(frame_list)) 203 if (nr_pages > ARRAY_SIZE(frame_list))
211 nr_pages = ARRAY_SIZE(frame_list); 204 nr_pages = ARRAY_SIZE(frame_list);
212 205
213 spin_lock_irqsave(&balloon_lock, flags); 206 spin_lock_irqsave(&xen_reservation_lock, flags);
214 207
215 page = balloon_first_page(); 208 page = balloon_first_page();
216 for (i = 0; i < nr_pages; i++) { 209 for (i = 0; i < nr_pages; i++) {
@@ -254,7 +247,7 @@ static int increase_reservation(unsigned long nr_pages)
254 balloon_stats.current_pages += rc; 247 balloon_stats.current_pages += rc;
255 248
256 out: 249 out:
257 spin_unlock_irqrestore(&balloon_lock, flags); 250 spin_unlock_irqrestore(&xen_reservation_lock, flags);
258 251
259 return rc < 0 ? rc : rc != nr_pages; 252 return rc < 0 ? rc : rc != nr_pages;
260} 253}
@@ -299,7 +292,7 @@ static int decrease_reservation(unsigned long nr_pages)
299 kmap_flush_unused(); 292 kmap_flush_unused();
300 flush_tlb_all(); 293 flush_tlb_all();
301 294
302 spin_lock_irqsave(&balloon_lock, flags); 295 spin_lock_irqsave(&xen_reservation_lock, flags);
303 296
304 /* No more mappings: invalidate P2M and add to balloon. */ 297 /* No more mappings: invalidate P2M and add to balloon. */
305 for (i = 0; i < nr_pages; i++) { 298 for (i = 0; i < nr_pages; i++) {
@@ -315,7 +308,7 @@ static int decrease_reservation(unsigned long nr_pages)
315 308
316 balloon_stats.current_pages -= nr_pages; 309 balloon_stats.current_pages -= nr_pages;
317 310
318 spin_unlock_irqrestore(&balloon_lock, flags); 311 spin_unlock_irqrestore(&xen_reservation_lock, flags);
319 312
320 return need_sleep; 313 return need_sleep;
321} 314}
diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
new file mode 100644
index 000000000000..54469c3eeacd
--- /dev/null
+++ b/drivers/xen/swiotlb-xen.c
@@ -0,0 +1,515 @@
1/*
2 * Copyright 2010
3 * by Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
4 *
5 * This code provides a IOMMU for Xen PV guests with PCI passthrough.
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 v2.0 as published by
9 * the Free Software Foundation
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * PV guests under Xen are running in an non-contiguous memory architecture.
17 *
18 * When PCI pass-through is utilized, this necessitates an IOMMU for
19 * translating bus (DMA) to virtual and vice-versa and also providing a
20 * mechanism to have contiguous pages for device drivers operations (say DMA
21 * operations).
22 *
23 * Specifically, under Xen the Linux idea of pages is an illusion. It
24 * assumes that pages start at zero and go up to the available memory. To
25 * help with that, the Linux Xen MMU provides a lookup mechanism to
26 * translate the page frame numbers (PFN) to machine frame numbers (MFN)
27 * and vice-versa. The MFN are the "real" frame numbers. Furthermore
28 * memory is not contiguous. Xen hypervisor stitches memory for guests
29 * from different pools, which means there is no guarantee that PFN==MFN
30 * and PFN+1==MFN+1. Lastly with Xen 4.0, pages (in debug mode) are
31 * allocated in descending order (high to low), meaning the guest might
32 * never get any MFN's under the 4GB mark.
33 *
34 */
35
36#include <linux/bootmem.h>
37#include <linux/dma-mapping.h>
38#include <xen/swiotlb-xen.h>
39#include <xen/page.h>
40#include <xen/xen-ops.h>
41/*
42 * Used to do a quick range check in swiotlb_tbl_unmap_single and
43 * swiotlb_tbl_sync_single_*, to see if the memory was in fact allocated by this
44 * API.
45 */
46
47static char *xen_io_tlb_start, *xen_io_tlb_end;
48static unsigned long xen_io_tlb_nslabs;
49/*
50 * Quick lookup value of the bus address of the IOTLB.
51 */
52
53u64 start_dma_addr;
54
55static dma_addr_t xen_phys_to_bus(phys_addr_t paddr)
56{
57 return phys_to_machine(XPADDR(paddr)).maddr;;
58}
59
60static phys_addr_t xen_bus_to_phys(dma_addr_t baddr)
61{
62 return machine_to_phys(XMADDR(baddr)).paddr;
63}
64
65static dma_addr_t xen_virt_to_bus(void *address)
66{
67 return xen_phys_to_bus(virt_to_phys(address));
68}
69
70static int check_pages_physically_contiguous(unsigned long pfn,
71 unsigned int offset,
72 size_t length)
73{
74 unsigned long next_mfn;
75 int i;
76 int nr_pages;
77
78 next_mfn = pfn_to_mfn(pfn);
79 nr_pages = (offset + length + PAGE_SIZE-1) >> PAGE_SHIFT;
80
81 for (i = 1; i < nr_pages; i++) {
82 if (pfn_to_mfn(++pfn) != ++next_mfn)
83 return 0;
84 }
85 return 1;
86}
87
88static int range_straddles_page_boundary(phys_addr_t p, size_t size)
89{
90 unsigned long pfn = PFN_DOWN(p);
91 unsigned int offset = p & ~PAGE_MASK;
92
93 if (offset + size <= PAGE_SIZE)
94 return 0;
95 if (check_pages_physically_contiguous(pfn, offset, size))
96 return 0;
97 return 1;
98}
99
100static int is_xen_swiotlb_buffer(dma_addr_t dma_addr)
101{
102 unsigned long mfn = PFN_DOWN(dma_addr);
103 unsigned long pfn = mfn_to_local_pfn(mfn);
104 phys_addr_t paddr;
105
106 /* If the address is outside our domain, it CAN
107 * have the same virtual address as another address
108 * in our domain. Therefore _only_ check address within our domain.
109 */
110 if (pfn_valid(pfn)) {
111 paddr = PFN_PHYS(pfn);
112 return paddr >= virt_to_phys(xen_io_tlb_start) &&
113 paddr < virt_to_phys(xen_io_tlb_end);
114 }
115 return 0;
116}
117
118static int max_dma_bits = 32;
119
120static int
121xen_swiotlb_fixup(void *buf, size_t size, unsigned long nslabs)
122{
123 int i, rc;
124 int dma_bits;
125
126 dma_bits = get_order(IO_TLB_SEGSIZE << IO_TLB_SHIFT) + PAGE_SHIFT;
127
128 i = 0;
129 do {
130 int slabs = min(nslabs - i, (unsigned long)IO_TLB_SEGSIZE);
131
132 do {
133 rc = xen_create_contiguous_region(
134 (unsigned long)buf + (i << IO_TLB_SHIFT),
135 get_order(slabs << IO_TLB_SHIFT),
136 dma_bits);
137 } while (rc && dma_bits++ < max_dma_bits);
138 if (rc)
139 return rc;
140
141 i += slabs;
142 } while (i < nslabs);
143 return 0;
144}
145
146void __init xen_swiotlb_init(int verbose)
147{
148 unsigned long bytes;
149 int rc;
150
151 xen_io_tlb_nslabs = (64 * 1024 * 1024 >> IO_TLB_SHIFT);
152 xen_io_tlb_nslabs = ALIGN(xen_io_tlb_nslabs, IO_TLB_SEGSIZE);
153
154 bytes = xen_io_tlb_nslabs << IO_TLB_SHIFT;
155
156 /*
157 * Get IO TLB memory from any location.
158 */
159 xen_io_tlb_start = alloc_bootmem(bytes);
160 if (!xen_io_tlb_start)
161 panic("Cannot allocate SWIOTLB buffer");
162
163 xen_io_tlb_end = xen_io_tlb_start + bytes;
164 /*
165 * And replace that memory with pages under 4GB.
166 */
167 rc = xen_swiotlb_fixup(xen_io_tlb_start,
168 bytes,
169 xen_io_tlb_nslabs);
170 if (rc)
171 goto error;
172
173 start_dma_addr = xen_virt_to_bus(xen_io_tlb_start);
174 swiotlb_init_with_tbl(xen_io_tlb_start, xen_io_tlb_nslabs, verbose);
175
176 return;
177error:
178 panic("DMA(%d): Failed to exchange pages allocated for DMA with Xen! "\
179 "We either don't have the permission or you do not have enough"\
180 "free memory under 4GB!\n", rc);
181}
182
183void *
184xen_swiotlb_alloc_coherent(struct device *hwdev, size_t size,
185 dma_addr_t *dma_handle, gfp_t flags)
186{
187 void *ret;
188 int order = get_order(size);
189 u64 dma_mask = DMA_BIT_MASK(32);
190 unsigned long vstart;
191
192 /*
193 * Ignore region specifiers - the kernel's ideas of
194 * pseudo-phys memory layout has nothing to do with the
195 * machine physical layout. We can't allocate highmem
196 * because we can't return a pointer to it.
197 */
198 flags &= ~(__GFP_DMA | __GFP_HIGHMEM);
199
200 if (dma_alloc_from_coherent(hwdev, size, dma_handle, &ret))
201 return ret;
202
203 vstart = __get_free_pages(flags, order);
204 ret = (void *)vstart;
205
206 if (hwdev && hwdev->coherent_dma_mask)
207 dma_mask = dma_alloc_coherent_mask(hwdev, flags);
208
209 if (ret) {
210 if (xen_create_contiguous_region(vstart, order,
211 fls64(dma_mask)) != 0) {
212 free_pages(vstart, order);
213 return NULL;
214 }
215 memset(ret, 0, size);
216 *dma_handle = virt_to_machine(ret).maddr;
217 }
218 return ret;
219}
220EXPORT_SYMBOL_GPL(xen_swiotlb_alloc_coherent);
221
222void
223xen_swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
224 dma_addr_t dev_addr)
225{
226 int order = get_order(size);
227
228 if (dma_release_from_coherent(hwdev, order, vaddr))
229 return;
230
231 xen_destroy_contiguous_region((unsigned long)vaddr, order);
232 free_pages((unsigned long)vaddr, order);
233}
234EXPORT_SYMBOL_GPL(xen_swiotlb_free_coherent);
235
236
237/*
238 * Map a single buffer of the indicated size for DMA in streaming mode. The
239 * physical address to use is returned.
240 *
241 * Once the device is given the dma address, the device owns this memory until
242 * either xen_swiotlb_unmap_page or xen_swiotlb_dma_sync_single is performed.
243 */
244dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page,
245 unsigned long offset, size_t size,
246 enum dma_data_direction dir,
247 struct dma_attrs *attrs)
248{
249 phys_addr_t phys = page_to_phys(page) + offset;
250 dma_addr_t dev_addr = xen_phys_to_bus(phys);
251 void *map;
252
253 BUG_ON(dir == DMA_NONE);
254 /*
255 * If the address happens to be in the device's DMA window,
256 * we can safely return the device addr and not worry about bounce
257 * buffering it.
258 */
259 if (dma_capable(dev, dev_addr, size) &&
260 !range_straddles_page_boundary(phys, size) && !swiotlb_force)
261 return dev_addr;
262
263 /*
264 * Oh well, have to allocate and map a bounce buffer.
265 */
266 map = swiotlb_tbl_map_single(dev, start_dma_addr, phys, size, dir);
267 if (!map)
268 return DMA_ERROR_CODE;
269
270 dev_addr = xen_virt_to_bus(map);
271
272 /*
273 * Ensure that the address returned is DMA'ble
274 */
275 if (!dma_capable(dev, dev_addr, size))
276 panic("map_single: bounce buffer is not DMA'ble");
277
278 return dev_addr;
279}
280EXPORT_SYMBOL_GPL(xen_swiotlb_map_page);
281
282/*
283 * Unmap a single streaming mode DMA translation. The dma_addr and size must
284 * match what was provided for in a previous xen_swiotlb_map_page call. All
285 * other usages are undefined.
286 *
287 * After this call, reads by the cpu to the buffer are guaranteed to see
288 * whatever the device wrote there.
289 */
290static void xen_unmap_single(struct device *hwdev, dma_addr_t dev_addr,
291 size_t size, enum dma_data_direction dir)
292{
293 phys_addr_t paddr = xen_bus_to_phys(dev_addr);
294
295 BUG_ON(dir == DMA_NONE);
296
297 /* NOTE: We use dev_addr here, not paddr! */
298 if (is_xen_swiotlb_buffer(dev_addr)) {
299 swiotlb_tbl_unmap_single(hwdev, phys_to_virt(paddr), size, dir);
300 return;
301 }
302
303 if (dir != DMA_FROM_DEVICE)
304 return;
305
306 /*
307 * phys_to_virt doesn't work with hihgmem page but we could
308 * call dma_mark_clean() with hihgmem page here. However, we
309 * are fine since dma_mark_clean() is null on POWERPC. We can
310 * make dma_mark_clean() take a physical address if necessary.
311 */
312 dma_mark_clean(phys_to_virt(paddr), size);
313}
314
315void xen_swiotlb_unmap_page(struct device *hwdev, dma_addr_t dev_addr,
316 size_t size, enum dma_data_direction dir,
317 struct dma_attrs *attrs)
318{
319 xen_unmap_single(hwdev, dev_addr, size, dir);
320}
321EXPORT_SYMBOL_GPL(xen_swiotlb_unmap_page);
322
323/*
324 * Make physical memory consistent for a single streaming mode DMA translation
325 * after a transfer.
326 *
327 * If you perform a xen_swiotlb_map_page() but wish to interrogate the buffer
328 * using the cpu, yet do not wish to teardown the dma mapping, you must
329 * call this function before doing so. At the next point you give the dma
330 * address back to the card, you must first perform a
331 * xen_swiotlb_dma_sync_for_device, and then the device again owns the buffer
332 */
333static void
334xen_swiotlb_sync_single(struct device *hwdev, dma_addr_t dev_addr,
335 size_t size, enum dma_data_direction dir,
336 enum dma_sync_target target)
337{
338 phys_addr_t paddr = xen_bus_to_phys(dev_addr);
339
340 BUG_ON(dir == DMA_NONE);
341
342 /* NOTE: We use dev_addr here, not paddr! */
343 if (is_xen_swiotlb_buffer(dev_addr)) {
344 swiotlb_tbl_sync_single(hwdev, phys_to_virt(paddr), size, dir,
345 target);
346 return;
347 }
348
349 if (dir != DMA_FROM_DEVICE)
350 return;
351
352 dma_mark_clean(phys_to_virt(paddr), size);
353}
354
355void
356xen_swiotlb_sync_single_for_cpu(struct device *hwdev, dma_addr_t dev_addr,
357 size_t size, enum dma_data_direction dir)
358{
359 xen_swiotlb_sync_single(hwdev, dev_addr, size, dir, SYNC_FOR_CPU);
360}
361EXPORT_SYMBOL_GPL(xen_swiotlb_sync_single_for_cpu);
362
363void
364xen_swiotlb_sync_single_for_device(struct device *hwdev, dma_addr_t dev_addr,
365 size_t size, enum dma_data_direction dir)
366{
367 xen_swiotlb_sync_single(hwdev, dev_addr, size, dir, SYNC_FOR_DEVICE);
368}
369EXPORT_SYMBOL_GPL(xen_swiotlb_sync_single_for_device);
370
371/*
372 * Map a set of buffers described by scatterlist in streaming mode for DMA.
373 * This is the scatter-gather version of the above xen_swiotlb_map_page
374 * interface. Here the scatter gather list elements are each tagged with the
375 * appropriate dma address and length. They are obtained via
376 * sg_dma_{address,length}(SG).
377 *
378 * NOTE: An implementation may be able to use a smaller number of
379 * DMA address/length pairs than there are SG table elements.
380 * (for example via virtual mapping capabilities)
381 * The routine returns the number of addr/length pairs actually
382 * used, at most nents.
383 *
384 * Device ownership issues as mentioned above for xen_swiotlb_map_page are the
385 * same here.
386 */
387int
388xen_swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl,
389 int nelems, enum dma_data_direction dir,
390 struct dma_attrs *attrs)
391{
392 struct scatterlist *sg;
393 int i;
394
395 BUG_ON(dir == DMA_NONE);
396
397 for_each_sg(sgl, sg, nelems, i) {
398 phys_addr_t paddr = sg_phys(sg);
399 dma_addr_t dev_addr = xen_phys_to_bus(paddr);
400
401 if (swiotlb_force ||
402 !dma_capable(hwdev, dev_addr, sg->length) ||
403 range_straddles_page_boundary(paddr, sg->length)) {
404 void *map = swiotlb_tbl_map_single(hwdev,
405 start_dma_addr,
406 sg_phys(sg),
407 sg->length, dir);
408 if (!map) {
409 /* Don't panic here, we expect map_sg users
410 to do proper error handling. */
411 xen_swiotlb_unmap_sg_attrs(hwdev, sgl, i, dir,
412 attrs);
413 sgl[0].dma_length = 0;
414 return DMA_ERROR_CODE;
415 }
416 sg->dma_address = xen_virt_to_bus(map);
417 } else
418 sg->dma_address = dev_addr;
419 sg->dma_length = sg->length;
420 }
421 return nelems;
422}
423EXPORT_SYMBOL_GPL(xen_swiotlb_map_sg_attrs);
424
425int
426xen_swiotlb_map_sg(struct device *hwdev, struct scatterlist *sgl, int nelems,
427 enum dma_data_direction dir)
428{
429 return xen_swiotlb_map_sg_attrs(hwdev, sgl, nelems, dir, NULL);
430}
431EXPORT_SYMBOL_GPL(xen_swiotlb_map_sg);
432
433/*
434 * Unmap a set of streaming mode DMA translations. Again, cpu read rules
435 * concerning calls here are the same as for swiotlb_unmap_page() above.
436 */
437void
438xen_swiotlb_unmap_sg_attrs(struct device *hwdev, struct scatterlist *sgl,
439 int nelems, enum dma_data_direction dir,
440 struct dma_attrs *attrs)
441{
442 struct scatterlist *sg;
443 int i;
444
445 BUG_ON(dir == DMA_NONE);
446
447 for_each_sg(sgl, sg, nelems, i)
448 xen_unmap_single(hwdev, sg->dma_address, sg->dma_length, dir);
449
450}
451EXPORT_SYMBOL_GPL(xen_swiotlb_unmap_sg_attrs);
452
453void
454xen_swiotlb_unmap_sg(struct device *hwdev, struct scatterlist *sgl, int nelems,
455 enum dma_data_direction dir)
456{
457 return xen_swiotlb_unmap_sg_attrs(hwdev, sgl, nelems, dir, NULL);
458}
459EXPORT_SYMBOL_GPL(xen_swiotlb_unmap_sg);
460
461/*
462 * Make physical memory consistent for a set of streaming mode DMA translations
463 * after a transfer.
464 *
465 * The same as swiotlb_sync_single_* but for a scatter-gather list, same rules
466 * and usage.
467 */
468static void
469xen_swiotlb_sync_sg(struct device *hwdev, struct scatterlist *sgl,
470 int nelems, enum dma_data_direction dir,
471 enum dma_sync_target target)
472{
473 struct scatterlist *sg;
474 int i;
475
476 for_each_sg(sgl, sg, nelems, i)
477 xen_swiotlb_sync_single(hwdev, sg->dma_address,
478 sg->dma_length, dir, target);
479}
480
481void
482xen_swiotlb_sync_sg_for_cpu(struct device *hwdev, struct scatterlist *sg,
483 int nelems, enum dma_data_direction dir)
484{
485 xen_swiotlb_sync_sg(hwdev, sg, nelems, dir, SYNC_FOR_CPU);
486}
487EXPORT_SYMBOL_GPL(xen_swiotlb_sync_sg_for_cpu);
488
489void
490xen_swiotlb_sync_sg_for_device(struct device *hwdev, struct scatterlist *sg,
491 int nelems, enum dma_data_direction dir)
492{
493 xen_swiotlb_sync_sg(hwdev, sg, nelems, dir, SYNC_FOR_DEVICE);
494}
495EXPORT_SYMBOL_GPL(xen_swiotlb_sync_sg_for_device);
496
497int
498xen_swiotlb_dma_mapping_error(struct device *hwdev, dma_addr_t dma_addr)
499{
500 return !dma_addr;
501}
502EXPORT_SYMBOL_GPL(xen_swiotlb_dma_mapping_error);
503
504/*
505 * Return whether the given device DMA address mask can be supported
506 * properly. For example, if your device can only drive the low 24-bits
507 * during bus mastering, then you would pass 0x00ffffff as the mask to
508 * this function.
509 */
510int
511xen_swiotlb_dma_supported(struct device *hwdev, u64 mask)
512{
513 return xen_virt_to_bus(xen_io_tlb_end - 1) <= mask;
514}
515EXPORT_SYMBOL_GPL(xen_swiotlb_dma_supported);
diff --git a/drivers/xen/xenbus/xenbus_client.c b/drivers/xen/xenbus/xenbus_client.c
index 7b3e973a1aee..7e49527189b6 100644
--- a/drivers/xen/xenbus/xenbus_client.c
+++ b/drivers/xen/xenbus/xenbus_client.c
@@ -133,17 +133,12 @@ int xenbus_watch_pathfmt(struct xenbus_device *dev,
133} 133}
134EXPORT_SYMBOL_GPL(xenbus_watch_pathfmt); 134EXPORT_SYMBOL_GPL(xenbus_watch_pathfmt);
135 135
136static void xenbus_switch_fatal(struct xenbus_device *, int, int,
137 const char *, ...);
136 138
137/** 139static int
138 * xenbus_switch_state 140__xenbus_switch_state(struct xenbus_device *dev,
139 * @dev: xenbus device 141 enum xenbus_state state, int depth)
140 * @state: new state
141 *
142 * Advertise in the store a change of the given driver to the given new_state.
143 * Return 0 on success, or -errno on error. On error, the device will switch
144 * to XenbusStateClosing, and the error will be saved in the store.
145 */
146int xenbus_switch_state(struct xenbus_device *dev, enum xenbus_state state)
147{ 142{
148 /* We check whether the state is currently set to the given value, and 143 /* We check whether the state is currently set to the given value, and
149 if not, then the state is set. We don't want to unconditionally 144 if not, then the state is set. We don't want to unconditionally
@@ -152,35 +147,65 @@ int xenbus_switch_state(struct xenbus_device *dev, enum xenbus_state state)
152 to it, as the device will be tearing down, and we don't want to 147 to it, as the device will be tearing down, and we don't want to
153 resurrect that directory. 148 resurrect that directory.
154 149
155 Note that, because of this cached value of our state, this function 150 Note that, because of this cached value of our state, this
156 will not work inside a Xenstore transaction (something it was 151 function will not take a caller's Xenstore transaction
157 trying to in the past) because dev->state would not get reset if 152 (something it was trying to in the past) because dev->state
158 the transaction was aborted. 153 would not get reset if the transaction was aborted.
159
160 */ 154 */
161 155
156 struct xenbus_transaction xbt;
162 int current_state; 157 int current_state;
163 int err; 158 int err, abort;
164 159
165 if (state == dev->state) 160 if (state == dev->state)
166 return 0; 161 return 0;
167 162
168 err = xenbus_scanf(XBT_NIL, dev->nodename, "state", "%d", 163again:
169 &current_state); 164 abort = 1;
170 if (err != 1) 165
166 err = xenbus_transaction_start(&xbt);
167 if (err) {
168 xenbus_switch_fatal(dev, depth, err, "starting transaction");
171 return 0; 169 return 0;
170 }
171
172 err = xenbus_scanf(xbt, dev->nodename, "state", "%d", &current_state);
173 if (err != 1)
174 goto abort;
172 175
173 err = xenbus_printf(XBT_NIL, dev->nodename, "state", "%d", state); 176 err = xenbus_printf(xbt, dev->nodename, "state", "%d", state);
174 if (err) { 177 if (err) {
175 if (state != XenbusStateClosing) /* Avoid looping */ 178 xenbus_switch_fatal(dev, depth, err, "writing new state");
176 xenbus_dev_fatal(dev, err, "writing new state"); 179 goto abort;
177 return err;
178 } 180 }
179 181
180 dev->state = state; 182 abort = 0;
183abort:
184 err = xenbus_transaction_end(xbt, abort);
185 if (err) {
186 if (err == -EAGAIN && !abort)
187 goto again;
188 xenbus_switch_fatal(dev, depth, err, "ending transaction");
189 } else
190 dev->state = state;
181 191
182 return 0; 192 return 0;
183} 193}
194
195/**
196 * xenbus_switch_state
197 * @dev: xenbus device
198 * @state: new state
199 *
200 * Advertise in the store a change of the given driver to the given new_state.
201 * Return 0 on success, or -errno on error. On error, the device will switch
202 * to XenbusStateClosing, and the error will be saved in the store.
203 */
204int xenbus_switch_state(struct xenbus_device *dev, enum xenbus_state state)
205{
206 return __xenbus_switch_state(dev, state, 0);
207}
208
184EXPORT_SYMBOL_GPL(xenbus_switch_state); 209EXPORT_SYMBOL_GPL(xenbus_switch_state);
185 210
186int xenbus_frontend_closed(struct xenbus_device *dev) 211int xenbus_frontend_closed(struct xenbus_device *dev)
@@ -284,6 +309,23 @@ void xenbus_dev_fatal(struct xenbus_device *dev, int err, const char *fmt, ...)
284EXPORT_SYMBOL_GPL(xenbus_dev_fatal); 309EXPORT_SYMBOL_GPL(xenbus_dev_fatal);
285 310
286/** 311/**
312 * Equivalent to xenbus_dev_fatal(dev, err, fmt, args), but helps
313 * avoiding recursion within xenbus_switch_state.
314 */
315static void xenbus_switch_fatal(struct xenbus_device *dev, int depth, int err,
316 const char *fmt, ...)
317{
318 va_list ap;
319
320 va_start(ap, fmt);
321 xenbus_va_dev_error(dev, err, fmt, ap);
322 va_end(ap);
323
324 if (!depth)
325 __xenbus_switch_state(dev, XenbusStateClosing, 1);
326}
327
328/**
287 * xenbus_grant_ring 329 * xenbus_grant_ring
288 * @dev: xenbus device 330 * @dev: xenbus device
289 * @ring_mfn: mfn of ring to grant 331 * @ring_mfn: mfn of ring to grant
diff --git a/drivers/zorro/proc.c b/drivers/zorro/proc.c
index 3c7046d79654..cafc50454292 100644
--- a/drivers/zorro/proc.c
+++ b/drivers/zorro/proc.c
@@ -22,8 +22,9 @@ static loff_t
22proc_bus_zorro_lseek(struct file *file, loff_t off, int whence) 22proc_bus_zorro_lseek(struct file *file, loff_t off, int whence)
23{ 23{
24 loff_t new = -1; 24 loff_t new = -1;
25 struct inode *inode = file->f_path.dentry->d_inode;
25 26
26 lock_kernel(); 27 mutex_lock(&inode->i_mutex);
27 switch (whence) { 28 switch (whence) {
28 case 0: 29 case 0:
29 new = off; 30 new = off;
@@ -35,12 +36,12 @@ proc_bus_zorro_lseek(struct file *file, loff_t off, int whence)
35 new = sizeof(struct ConfigDev) + off; 36 new = sizeof(struct ConfigDev) + off;
36 break; 37 break;
37 } 38 }
38 if (new < 0 || new > sizeof(struct ConfigDev)) { 39 if (new < 0 || new > sizeof(struct ConfigDev))
39 unlock_kernel(); 40 new = -EINVAL;
40 return -EINVAL; 41 else
41 } 42 file->f_pos = new;
42 unlock_kernel(); 43 mutex_unlock(&inode->i_mutex);
43 return (file->f_pos = new); 44 return new;
44} 45}
45 46
46static ssize_t 47static ssize_t
@@ -67,7 +68,7 @@ proc_bus_zorro_read(struct file *file, char __user *buf, size_t nbytes, loff_t *
67 cd.cd_BoardAddr = (void *)zorro_resource_start(z); 68 cd.cd_BoardAddr = (void *)zorro_resource_start(z);
68 cd.cd_BoardSize = zorro_resource_len(z); 69 cd.cd_BoardSize = zorro_resource_len(z);
69 70
70 if (copy_to_user(buf, &cd, nbytes)) 71 if (copy_to_user(buf, (void *)&cd + pos, nbytes))
71 return -EFAULT; 72 return -EFAULT;
72 *ppos += nbytes; 73 *ppos += nbytes;
73 74